1

I have this exception in my app, under warnings in the Logcat. The app is a system app.

java.lang.reflect.InvocationTargetException
 W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
 W/System.err:     at netchanger.tawkon.com.lib.network.NetworkChanger.setPreferredNetwork(NetworkChanger.java:48)
 W/System.err:     at netchanger.tawkon.com.lib.network.NetworkChanger.setPreferredNetwork(NetworkChanger.java:36)
 W/System.err:     at netchanger.tawkon.com.lib.services.LocationMonitorService.stopService(LocationMonitorService.java:57)
 W/System.err:     at com.tawkon.data.lib.service.KeepAliveService$PowerReceiver.onReceive(KeepAliveService.java:154)
 W/System.err:     at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$-android_app_LoadedApk$ReceiverDispatcher$Args_52497(LoadedApk.java:1313)
 W/System.err:     at android.app.-$Lambda$aS31cHIhRx41653CMnd4gZqshIQ.$m$7(Unknown Source:4)
 W/System.err:     at android.app.-$Lambda$aS31cHIhRx41653CMnd4gZqshIQ.run(Unknown Source:39)
 W/System.err:     at android.os.Handler.handleCallback(Handler.java:790)
 W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:99)
 W/System.err:     at android.os.Looper.loop(Looper.java:164)
 W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:6494)
 W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
 W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
 W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
 W/System.err: Caused by: java.lang.SecurityException: No Carrier Privilege.
 W/System.err:     at android.os.Parcel.readException(Parcel.java:2005)
 W/System.err:     at android.os.Parcel.readException(Parcel.java:1951)
 W/System.err:     at com.android.internal.telephony.ITelephony$Stub$Proxy.setPreferredNetworkType(ITelephony.java:4237)
 W/System.err:     at android.telephony.TelephonyManager.setPreferredNetworkType(TelephonyManager.java:4821)
 W/System.err:  ... 15 more

I see that this is InvocationTargetException and it's caused by SecurityException.

What does 'No Carrier Privilege.' mean? How can I avoid this?

Keselme
  • 3,779
  • 7
  • 36
  • 68

2 Answers2

0

Security Exception implies there is a permission required to which the user hasn't granted. Ensure you request for the correct permission and confirm that the user has granted the permission before execution of the functionality. Read on telephony manager

clifford_owino
  • 462
  • 1
  • 6
  • 24
  • Is there a way, I can know which permission I am missing? I granted all the permissions I asked for. – Keselme Mar 17 '19 at 17:36
0

As per the android documentation in order to use android.telephony.TelephonyManager.setPreferredNetworkType() method your app should have carrier privileges.

Carrier Privileges in a gist: Android grants special privileges to apps from Mobile (Virtual) Network Operator (MNO/MVNOs) via UICC to override certain carrier configurations (e.g. IMS settings) on the device. This app from operator is signed with a signing key whose hash value is stored in UICC, which is in-turn read by Android Platform to allow the app to make calls to handful of special APIs

More information related to how to give your app carrier privileges can be found here. The link explains the method to override IMS settings using carrier privileges but it can be applied to whatever functionality you are trying to achieve

Skyprenet
  • 60
  • 5