App crashes with SecurityException on Android M [duplicate] - android

This question already has answers here:
Android 6.0 Permission Error
(5 answers)
Closed 7 years ago.
Yesterday I set upped target and compile sdk to 23 API level. When I launched the app on Nexus 9 with Preview Android M (MPA441) the app crashes with following SecurityException:
FATAL EXCEPTION: main
Process: com.grouplogic.mobilecho, PID: 22554
java.lang.RuntimeException: Unable to create application com.mypackage.MyApplication: java.lang.SecurityException: getDeviceId: Neither user 10098 nor current process has android.permission.READ_PHONE_STATE.
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4710)
at android.app.ActivityThread.-wrap1(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.SecurityException: getDeviceId: Neither user 10098 nor current process has android.permission.READ_PHONE_STATE.
at android.os.Parcel.readException(Parcel.java:1599)
at android.os.Parcel.readException(Parcel.java:1552)
at com.android.internal.telephony.ITelephony$Stub$Proxy.getDeviceId(ITelephony.java:4175)
at android.telephony.TelephonyManager.getDeviceId(TelephonyManager.java:706)
at com.mypackage.utils.DeviceUtils.isRunOnEmulator(DeviceUtils.java:63)
at com.mypackage.utils.DeviceUtils.getDeviceID(DeviceUtils.java:49)
at com.mypackage.domain.service.SettingService.setupPreferences(SettingService.java:79)
at com.mypackage.app.BaseApplication.createSingletons(BaseApplication.java:84)
at com.mypackage.app.BaseApplication.onCreate(BaseApplication.java:66)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1013)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4707)
at android.app.ActivityThread.-wrap1(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Does somebody know why the permission is disabled by default for new installed app when I install app through Android Studio? What is the correct way to avoid this crash, maybe there is way to check enable or not target permission and only if it is enabled the app should use some specific device API (read phone state, contacts and other permissions)? In the Internet I've just found this mention related to this problem1, but there I didn't find any clear explanation: is it bug in Android M or developer cannot understand how to use permission in a safe manner!? Also I've read this post but approach when user should go to settings and enable permission for app looks strange and not user friendly. I guess if user installs app from the Google Play everything will be fine because he explicitly to apply requested permission, but I need to confirm it.

Here you can find how-to request permissions at runtime.
https://developer.android.com/training/permissions/requesting.html

Related

React Native for Android 11 get phone number from device using READ_PHONE_NUMBERS

anyone has any idea about Android 11 updates? My APP gets user phone number on SIM and I am using READ_PHONE_STATE permission to get this, but recently Google forced to target SDK above 30(Android11) and from the devices with Android 11, my APP crashes, so I checked document from Google (https://developer.android.com/about/versions/11/privacy/permissions#phone-numbers) and added manifest and updated other stuff as well. Now my APP ask for permission to get phone number on Android 11, no more crash, but it returns null, cannot get phone number. so the question is, any way to solve this issue? or React Native doesn't support get phone number on Android 11? Here are the logs
2021-08-05 15:57:16.427 29800-30293/? E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
Process: com.shuket.worldmart.bakchon, PID: 29800
java.lang.SecurityException: getLine1NumberForDisplay: Neither user 11034 nor current process has android.permission.READ_PHONE_STATE, android.permission.READ_SMS, or android.permission.READ_PHONE_NUMBERS
at android.os.Parcel.createExceptionOrNull(Parcel.java:2385)
at android.os.Parcel.createException(Parcel.java:2369)
at android.os.Parcel.readException(Parcel.java:2352)
at android.os.Parcel.readException(Parcel.java:2294)
at com.android.internal.telephony.ITelephony$Stub$Proxy.getLine1NumberForDisplay(ITelephony.java:10831)
at android.telephony.TelephonyManager.getLine1Number(TelephonyManager.java:5349)
at android.telephony.TelephonyManager.getLine1Number(TelephonyManager.java:5317)
at com.learnium.RNDeviceInfo.RNDeviceModule.getPhoneNumberSync(Unknown Source:66)
at com.learnium.RNDeviceInfo.RNDeviceModule.getPhoneNumber(Unknown Source:0)
at java.lang.reflect.Method.invoke(Native Method)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(Unknown Source:147)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(Unknown Source:21)
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(Unknown Source:0)
at android.os.Looper.loop(Looper.java:246)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(Unknown Source:37)
at java.lang.Thread.run(Thread.java:923)

Instant app crash on Samsung device with Android O

I met a crash issue when instant app running on Samsung device, here is the crash log:
Fatal Exception: java.lang.SecurityException: Setting aod_show_state is not accessible from ephemeral package xx.xx.xx
at android.os.Parcel.readException(Parcel.java:1958)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
at android.content.ContentProviderProxy.call(ContentProviderNative.java:651)
at android.provider.Settings$NameValueCache.getStringForUser(Settings.java:1923)
at android.provider.Settings$System.getStringForUser(Settings.java:2229)
at android.provider.Settings$System.getIntForUser(Settings.java:2299)
at android.provider.Settings$System.getInt(Settings.java:2294)
at android.view.ViewRootImpl$1.toViewScreenState(ViewRootImpl.java:1363)
at android.view.ViewRootImpl$1.onDisplayChanged(ViewRootImpl.java:1319)
at android.hardware.display.DisplayManagerGlobal$DisplayListenerDelegate.handleMessage(DisplayManagerGlobal.java:966)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Seems like it's trying to access the aod_show_state Settings(which is the specific feature called "Always on Display" on Samsung device), and it requires permission WRITE_SETTINGS/WRITE_SECURE_SETTINGS, and the instant app does not support these two permissions, then app crashed...
Is there any way to solve this problem?

Fingerprint crash on specific Samsung devices

I've recently released a new app which contains support for authentication via fingerprint.
This has worked fine on all of our test devices:
- OnePlus Three
- OnePlus Five
- Samsung S6 Edge
- Samsung S7
- Samsung S8
But when released, we began getting crashes from Fabric with this stack trace:
Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.our.app/com.our.app.ui.LoginActivity}: java.lang.SecurityException: Permission Denial: getCurrentUser() from pid=30208, uid=10038 requires android.permission.INTERACT_ACROSS_USERS
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3319)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
at android.app.ActivityThread.access$1100(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by java.lang.SecurityException: Permission Denial: getCurrentUser() from pid=30208, uid=10038 requires android.permission.INTERACT_ACROSS_USERS
at android.os.Parcel.readException(Parcel.java:1620)
at android.os.Parcel.readException(Parcel.java:1573)
at android.hardware.fingerprint.IFingerprintService$Stub$Proxy.hasEnrolledFingerprints(IFingerprintService.java:503)
at android.hardware.fingerprint.FingerprintManager.hasEnrolledFingerprints(FingerprintManager.java:776)
at com.our.app.fingerprint.handler.FingerprintHandler.canUseFingerprint(SourceFile:65)
at com.our.app.Client.canUseFingerprint(SourceFile:335)
at com.our.app.ui.LoginActivity.updateViewVisibilityBasedOnState(SourceFile:501)
at com.our.app.ui.LoginActivity.updateViewVisibilityBasedOnState(SourceFile:472)
at com.our.app.ui.LoginActivity.continueWithOnCreateLogic(SourceFile:399)
at com.our.app.ui.LoginActivity.onCreate(SourceFile:321)
at android.app.Activity.performCreate(Activity.java:6904)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3266)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
at android.app.ActivityThread.access$1100(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
According to Fabric, these devices are experiencing the crash:
- Galaxy A5
- Galaxy S5 Mini
- Galaxy A3(2016)
All of them are running Android 6.0.1.
Seeing as they're all Samsung devices, I began suspecting that Knox could be the issue, even though it isn't specifically listed anywhere in the stacktrace. But i have no idea on how to work around it, or fix it.
I found a similar issue posted on Samsung's own website, but without a fix:
https://seap.samsung.com/forum-topic/getting-javalangsecurityexception-permission-denial
The permission that's named in the stacktrace is a system permission, which no user apps can get. Only system apps can.
Does anyone have an idea on how to fix this?
Not sure if you were ever able to find a solution for this, as a workaround I simply wrapped our calls in a permission check.
inline val Activity.fingerprintManager: FingerprintManagerCompat?
get() = (
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.USE_FINGERPRINT) == PackageManager.PERMISSION_GRANTED) {
FingerprintManagerCompat.from(this)
} else { null }
)
Yes, I’ve seen this crash.
Since INTERACT_WITH_USERS is a system permission, it’s no wonder it crashes for us.
Silly Samsung.
Wrap the code in a try/catch for a SecurityException.
-Ken

Android app crash with ResourceNotFoundException

I recently checked for my GP crash logs and I am getting this callstack very frequently. Could you please help me.
A few things:
The failed to add asset path sometimes shows /data/app/com.xxx.xxx.xxx-x/base.apk and sometimes /mnt/asec/com.xxx.xxx.xxx-x/base.apk.
The device android versions (where it is reported) varies from Android 4.4. to Android 7.0
In the GP console, Android version shows Android 7.0 for all crashes but the device list has devices with Android version 6.0, 5.0, etc which is unclear.
I have two apps with shared user Id, say with package names P1, P2. For P1, the failed to add asset path sometimes shows /data/app/P2 and sometimes /mnt/asec/P1. Isn't this incorrect and what could cause this?
Call stacks:
java.lang.RuntimeException: Unable to create BackupAgent android.app.backup.FullBackupAgent: android.content.res.Resources$NotFoundException: failed to add asset path data/app/com.P2.xxx/base.apk
at android.app.ActivityThread.handleCreateBackupAgent(ActivityThread.java:3452)
at android.app.ActivityThread.-wrap5(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1796)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6688)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Caused by: android.content.res.Resources$NotFoundException: failed to add asset path /data/app/com.P2.xxx/base.apk
at android.app.ResourcesManager.createAssetManager(ResourcesManager.java:281)
at android.app.ResourcesManager.createResourcesImpl(ResourcesManager.java:359)
at android.app.ResourcesManager.getOrCreateResources(ResourcesManager.java:638)
at android.app.ResourcesManager.getResources(ResourcesManager.java:730)
at android.app.ActivityThread.getTopLevelResources(ActivityThread.java:2068)
at android.app.LoadedApk.getResources(LoadedApk.java:780)
at android.app.ContextImpl.<init>(ContextImpl.java:2244)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2184)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2175)
at android.app.ActivityThread.handleCreateBackupAgent(ActivityThread.java:3422)
Another crash:
android.content.res.Resources$NotFoundException: failed to add asset path /mnt/asec/com.P1.xxx/base.apk
at android.app.ResourcesManager.createAssetManager(ResourcesManager.java:281)
at android.app.ResourcesManager.createResourcesImpl(ResourcesManager.java:359)
at android.app.ResourcesManager.getOrCreateResources(ResourcesManager.java:638)
at android.app.ResourcesManager.getResources(ResourcesManager.java:730)
at android.app.ActivityThread.getTopLevelResources(ActivityThread.java:2052)
at android.app.LoadedApk.getResources(LoadedApk.java:787)
at android.app.ContextImpl.<init>(ContextImpl.java:2266)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2210)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2196)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5861)
at android.app.ActivityThread.-wrap3(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1710)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
Please check if the App has external drive permissions.
In my case this issue triggered when ADB installed the App to the device which is screen locked, the same test has passed when the device is awake, so even though permissions available to this App
I have this error for com.android.billingclient:billing. Problem is "there is no account in the device", for example a new device or reset to vendor settings.
So just add an account in global settings.

Google Sign In is failing only on (some) Xiaomi devices

I am using Google Sign In in my application. I am using google play services version 9.0.2
compile 'com.google.android.gms:play-services-plus:9.0.2'
It was working fine for all devices, but now I am getting crash logs from Crashlytics and the crash is only happening on Xiaomi devices. Here are the crash logs.
Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.eterno/com.google.android.gms.auth.api.signin.internal.SignInHubActivity}: java.lang.IllegalStateException: Bad magic number for Bundle: 0xffff4f45
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2423)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483)
at android.app.ActivityThread.access$900(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5441)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
Caused by java.lang.IllegalStateException: Bad magic number for Bundle: 0xffff4f45
at android.os.Parcel.readException(Parcel.java:1628)
at android.os.Parcel.readException(Parcel.java:1573)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2661)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1509)
at android.app.Activity.startActivityForResult(Activity.java:3978)
at android.app.Activity.startActivityForResult(Activity.java:3939)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:842)
at com.google.android.gms.auth.api.signin.internal.SignInHubActivity.zza(Unknown Source)
at com.google.android.gms.auth.api.signin.internal.SignInHubActivity.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:6303)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2376)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483)
at android.app.ActivityThread.access$900(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5441)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
I am not able to reproduce the crash with any of the test devices that we can locally with us. Did any one else also face this issue with Xiaomi devices? Also, will upgrading the google play services version help in mitigating the issue?
P.S. I am not attaching code snippets which I wrote for Google Sign In because it is working for all other devices. This seems to be a specific problem related to Xiaomi devices.
Checkout out the playService App Version in device
I was getting same problem in my code. I found that release app is not working on those Xiaomi devices installed debug build.
I tried same release app without changing a single line of code on a different Xiaomi android phone and found app is working fine.
I didn't tried but this might be possible that resetting Xiaomi devices solve this problem.

Categories

Resources