1

I am working on 3G and 4G networks monitoring. I try to show cell infos like RSRP, RSSI and SINR for 4G (RSCP, RSSI, EcNo for 3G). I've found that the method getAllCellInfo() can do the work for me since it contains all what I need but its value is always null. Here is the code for 3G cell infos:

 protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

        if (tm.getNetworkType() == 3 || tm.getNetworkType() == 8 || tm.getNetworkType() == 9 || tm.getNetworkType() == 10
        || tm.getNetworkType() == 15) {
            // Network Type is 3G
            setContentView(R.layout.report_val_layout_3g);

            sigLevTextView = (TextView) findViewById(R.id.sigLevTextView);
            rssiTextView = (TextView) findViewById(R.id.rssiTextView);
            sigQualTextView = (TextView) findViewById(R.id.sigQualTextView);
            cellIDTextView = (TextView) findViewById(R.id.cellIDTextView);

            signalStrengthListener = new SignalStrengthListener();

            ((TelephonyManager)getSystemService(TELEPHONY_SERVICE)).listen(signalStrengthListener, SignalStrengthListener.LISTEN_SIGNAL_STRENGTHS);
            tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        }

    try {
                    cellInfoList = tm.getAllCellInfo();
                } catch (Exception e) {
                    Log.d("SignalStrength", "+++++++++++++++++++++++++++++++++++++++++ null array spot 1: " + e);
                }

try {
            cellInfoList = tm.getAllCellInfo();
            for (CellInfo cellInfo : cellInfoList) {
                if (cellInfo instanceof CellInfoWcdma){
                    sigLev = ((CellInfoWcdma) cellInfo).getCellSignalStrength().getDbm();
                    asu = ((CellInfoWcdma) cellInfo).getCellSignalStrength().getAsuLevel();
                    rssi = -113 + 2 * asu;
                    sigQual = 10 * Math.log10(sigLev / rssi); //EcNo
                    cellID = ((CellInfoWcdma) cellInfo).getCellIdentity().getCid();

                }
            }
        } catch  (Exception e) {
            Log.d("SignalStrength", "+++++++++++++++++++++++++++++++ null array spot 2: " + e);
        }

 @Override
    protected void onPause() {
        super.onPause();

        try{
            if(signalStrengthListener != null){tm.listen(signalStrengthListener, SignalStrengthListener.LISTEN_NONE);}
        }catch(Exception e){
            e.printStackTrace();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        try{
            if(signalStrengthListener != null){tm.listen(signalStrengthListener, SignalStrengthListener.LISTEN_NONE);}
        }catch(Exception e){
            e.printStackTrace();
        }
    }

    public class SignalStrengthListener extends PhoneStateListener{

        @Override
        public void onSignalStrengthsChanged(SignalStrength signalStrength) {

            ((TelephonyManager)getSystemService(TELEPHONY_SERVICE)).listen(signalStrengthListener, SignalStrengthListener.LISTEN_SIGNAL_STRENGTHS);
            tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);


            try {
                cellInfoList = tm.getAllCellInfo();
               for (CellInfo cellInfo : cellInfoList) {
                   if (cellInfo instanceof CellInfoWcdma) {
                       sigLev = ((CellInfoWcdma)cellInfo).getCellSignalStrength().getDbm();
                       asu = ((CellInfoWcdma)cellInfo).getCellSignalStrength().getAsuLevel();
                       rssi = -113 + 2 * asu;
                       sigQual = 10 * Math.log10(sigLev / rssi);
                       cellID = ((CellInfoWcdma)cellInfo).getCellIdentity().getCid();
                   }
               }

        }catch  (Exception e) {
            Log.d("SignalStrength", "+++++++++++++++++++++++++++++++ null array spot 3: " + e);
        }

            sigLevTextView.setText(String.valueOf(sigLev));
            rssiTextView.setText(String.valueOf(rssi));
            sigQualTextView.setText(String.valueOf(sigQual));
            cellIDTextView.setText(String.valueOf(cellID));

            super.onSignalStrengthsChanged(signalStrength);
        }
    }

In the manifest file, I used 3 permissions: ACCESS_COARSE_LOCATION, ACCESS_NETWORK_STATE and READ_PHONE_STATE. It seems that the code stops in exception n°3, here is the log:

   23316-23316/com.test.a3g.a3gtest E/dalvikvm: Could not find class 'android.util.ArrayMap', referenced from method com.android.tools.fd.runtime.MonkeyPatcher.monkeyPatchExistingResources
07-18 16:16:06.865 23316-23316/com.test.a3g.a3gtest W/dalvikvm: VFY: unable to resolve check-cast 1798 (Landroid/util/ArrayMap;) in Lcom/android/tools/fd/runtime/MonkeyPatcher;
07-18 16:16:06.865 23316-23316/com.test.a3g.a3gtest D/dalvikvm: VFY: replacing opcode 0x1f at 0x0258
07-18 16:16:06.865 23316-23316/com.test.a3g.a3gtest E/dalvikvm: Could not find class 'android.util.ArrayMap', referenced from method com.android.tools.fd.runtime.MonkeyPatcher.pruneResourceCache
07-18 16:16:06.865 23316-23316/com.test.a3g.a3gtest W/dalvikvm: VFY: unable to resolve const-class 1798 (Landroid/util/ArrayMap;) in Lcom/android/tools/fd/runtime/MonkeyPatcher;
07-18 16:16:06.865 23316-23316/com.test.a3g.a3gtest D/dalvikvm: VFY: replacing opcode 0x1c at 0x0058
07-18 16:16:06.885 23316-23316/com.test.a3g.a3gtest I/dalvikvm: Could not find method android.content.Context.getSystemService, referenced from method com.test.a3g.a3gtest.MainActivity.access$super
07-18 16:16:06.885 23316-23316/com.test.a3g.a3gtest W/dalvikvm: VFY: unable to resolve virtual method 442: Landroid/content/Context;.getSystemService (Ljava/lang/Class;)Ljava/lang/Object;
07-18 16:16:06.885 23316-23316/com.test.a3g.a3gtest D/dalvikvm: VFY: replacing opcode 0x6f at 0x004b
07-18 16:16:06.885 23316-23316/com.test.a3g.a3gtest I/dalvikvm: Could not find method android.app.Activity.stopLockTask, referenced from method com.test.a3g.a3gtest.MainActivity.access$super
07-18 16:16:06.885 23316-23316/com.test.a3g.a3gtest W/dalvikvm: VFY: unable to resolve virtual method 231: Landroid/app/Activity;.stopLockTask ()V
07-18 16:16:06.885 23316-23316/com.test.a3g.a3gtest D/dalvikvm: VFY: replacing opcode 0x6f at 0x00b9
07-18 16:16:06.890 23316-23316/com.test.a3g.a3gtest E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.test.a3g.a3gtest.MainActivity.access$super
07-18 16:16:06.890 23316-23316/com.test.a3g.a3gtest W/dalvikvm: VFY: unable to resolve check-cast 226 (Landroid/os/PersistableBundle;) in Lcom/test/a3g/a3gtest/MainActivity;
07-18 16:16:06.890 23316-23316/com.test.a3g.a3gtest D/dalvikvm: VFY: replacing opcode 0x1f at 0x00f1
07-18 16:16:06.890 23316-23316/com.test.a3g.a3gtest I/dalvikvm: Could not find method android.content.Context.getColorStateList, referenced from method com.test.a3g.a3gtest.MainActivity.access$super
07-18 16:16:06.890 23316-23316/com.test.a3g.a3gtest W/dalvikvm: VFY: unable to resolve virtual method 424: Landroid/content/Context;.getColorStateList (I)Landroid/content/res/ColorStateList;
07-18 16:16:06.890 23316-23316/com.test.a3g.a3gtest D/dalvikvm: VFY: replacing opcode 0x6f at 0x0101
07-18 16:16:06.890 23316-23316/com.test.a3g.a3gtest I/dalvikvm: Could not find method android.app.Activity.onVisibleBehindCanceled, referenced from method com.test.a3g.a3gtest.MainActivity.access$super
07-18 16:16:06.890 23316-23316/com.test.a3g.a3gtest W/dalvikvm: VFY: unable to resolve virtual method 154: Landroid/app/Activity;.onVisibleBehindCanceled ()V
07-18 16:16:06.890 23316-23316/com.test.a3g.a3gtest D/dalvikvm: VFY: replacing opcode 0x6f at 0x0111
07-18 16:16:06.890 23316-23316/com.test.a3g.a3gtest I/dalvikvm: Could not find method android.app.Activity.onWindowStartingActionMode, referenced from method com.test.a3g.a3gtest.MainActivity.access$super
07-18 16:16:06.890 23316-23316/com.test.a3g.a3gtest W/dalvikvm: VFY: unable to resolve virtual method 158: Landroid/app/Activity;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
A.Belta
  • 11
  • 1
  • 7
  • is it possible that you could post the stacktrace? Now we don't know, where exactly the NPE happened, so we don't know which object was null. You can get it by using `e.printStackTrace()` in your catch-method. – UeliDeSchwert Jul 18 '16 at 14:31
  • I already updated my question. – A.Belta Jul 18 '16 at 15:19
  • See [this answer](http://stackoverflow.com/a/18688268/1536843) why getAllCellInfo() could return null. – iamantony Sep 01 '16 at 15:27

0 Answers0