When running the following code:
try {
TelephonyManager telephonyManager = (TelephonyManager) MainApplication.getAppContext()
.getSystemService(Context.TELEPHONY_SERVICE);
String simMCCMNC = telephonyManager.getSimOperator();
} catch (Exception e) {
Crashlytics.logException(e);
}
The app crashes with the following log:
Non-fatal Exception: java.lang.SecurityException: Requires READ_PHONE_STATE: Neither user 10076 nor current process has android.permission.READ_PHONE_STATE. at android.os.Parcel.readException(Parcel.java:1546) at android.os.Parcel.readException(Parcel.java:1499) at com.android.internal.telephony.ISub$Stub$Proxy.getActiveSubscriptionInfoForSimSlotIndex(ISub.java:459) at android.telephony.SubscriptionManager.getDefaultSmsSubId(SubscriptionManager.java:910) at android.telephony.TelephonyManager.getSimOperatorNumeric(TelephonyManager.java:1622) at android.telephony.TelephonyManager.getSimOperator(TelephonyManager.java:1592) at com.myapp.app.ApplicationInitializer.generateBaseUrl(SourceFile:297) at com.myapp.app.ApplicationInitializer.initFailProofComponents(SourceFile:193) at com.myapp.app.ApplicationInitializer.prepareManager(SourceFile:121) at com.myapp.managers.base.BaseManager.prepareManagerIfPossible(SourceFile:43) at com.my.app.ApplicationInitializer.init(SourceFile:137) at com.my.app.MainApplication.onCreate(SourceFile:23) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4628) at android.app.ActivityThread.access$1500(ActivityThread.java:151) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1374) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5345) at java.lang.reflect.Method.invoke(Method.java) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:947) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:742)
Looking at the source code for Android getSimOperator(). I do not understand how the code can crash on a permission which is not required for this method?
I was able to reproduce when calling getDeviceId() because it requires READ_PHONE_STATE.
I've only seen this happen on android version 5.1.