3

I'm currently developing an Android application for my university research project. This app should be able to read the RSSI levels of the nearby GSM base stations. I coded the following function which succesfully reads the RSSI levels of the nearby cells. I'm calling this function every 200 ms but the RSSI values almost don't change over time. I suspect the baseband processor only update these values each x s but I can't find anything about the refresh rate. Does anybody know how fast the info in getAllCellInfo() is refreshed? The reason I want to know this is because timing is realy important for my set-up. In the lab we enable and disable a jammer at a certain frequency (greater than 1 Hz). When the jammer is enabled the RSSI value will drop. So I would like to know how fast the RSSI can be refreshed to detect this signal drops if the jammer is enabled and disabled at for example 10 hz.

public HashMap<Integer,Integer> RSSI_values() {

    HashMap<Integer,Integer> result = new HashMap<Integer,Integer>();

    TelephonyManager telephonyManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
    telephonyManager.getNetworkType();
    List<CellInfo> CellInfo_list = telephonyManager.getAllCellInfo();
    if(telephonyManager.getNetworkType() == TelephonyManager.NETWORK_TYPE_EDGE) {
        for (int i = 0; i < CellInfo_list.size(); i++) {
            CellInfoGsm cellinfogsm = (CellInfoGsm) CellInfo_list.get(i);

            int cid = cellinfogsm.getCellIdentity().getCid();

            CellSignalStrengthGsm cellSignalStrengthGsm = cellinfogsm.getCellSignalStrength();
            int rssi = cellSignalStrengthGsm.getDbm();

            result.put(cid,rssi);
        }
    } 
    return result;
}

In case this refresh rate is device specific I'm on a nexus 5 android 6.0.1

mvanderreek
  • 31
  • 1
  • 4

1 Answers1

2

I think you can use a better approach on this implementation.

Instead of use a defined interval to consult the Cell Info, you can register a listener which will be called everytime that a cell info changes.

This way, you don't need to worry about a ideal value and also, you don't waste resources checking a information that may not be changed yet.

You can use a PhoneStateListener. You create it and register it to receive cell info changes. When it is not longer needed (activity in background or destroyed) you must unregister it.

Below is an example. I did not test. But it may help you to get the idea.

public class MainActivity extends Activity {

    private PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
        @Override
        public void onCellInfoChanged(List<CellInfo> cellInfoList) {
            // This callback method will be called automatically by Android OS
            // Every time a cell info changed (if you are registered)
            // Here, you will receive a cellInfoList....
            // Same list that you will receive in RSSI_values() method that you created
            // You can maybe move your whole code to here....
        }
    };

    @Override
    public void onStart() {
        super.onStart();

        // Code below register your mPhoneStateListener will start to be called everytime cell info changed.
        // If you update any UI element, be sure that they were created already (since they are created during "onCreate".. and not at onStart)
        // I added LISTEN_CELL_LOCATION.. But I think that PhoneStateListener.LISTEN_CELL_INFO is enough
        TelephonyManager mTelephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
        mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CELL_LOCATION | PhoneStateListener.LISTEN_CELL_INFO);
    }

    @Override
    public void onStop() {
        // Code below unregister your listener... You will not receive any cell info change notification anymore
        TelephonyManager mTelephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
        mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
        super.onStop();
    }
}

Hope I could help you.

guipivoto
  • 18,327
  • 9
  • 60
  • 75
  • Hi @GuilhermeP thanks for your reply. Unfortunatly timing is realy important for my set-up. In the lab we enable and disable a jammer at a certain frequency (greater than 1 Hz). When the jammer is enabled the RSSI value will drop. So I would like to know how fast the RSSI can be refreshed to detect this signal drops if the jammer is enabled and disabled at for example 10 hz. – mvanderreek May 26 '16 at 21:04
  • 2
    @mvanderreek Initially, I believe that RSSI is not updated that fast. Usually, CP (modem) would not inform the AP side (Android) any RSSI fluctuation.. this can drastically impact current consumption and decrease battery life. Implementation above notify you as soon as RSSI value is updated. Any rssi checking before a new notification should return same status. Maybe, you should search how to force a RSSI updating via some RIL request to CP side. I hope you find a better solution. – guipivoto May 27 '16 at 00:21