crash before app starts : SecurityException: Permi

2019-03-17 10:12发布

问题:

Background

I have a rooted device, which is Galaxy S3 I9300 , with Samsung stock based ROM, based on Android 4.3.

I never had any problems running an app i'm working on with this device.

The problem

ever since yesterday (and I didn't change anything on the device), each time I open the app, it shows for a very short time, closes itself without any crash dialog yet it shows the next log:

01-30 09:27:18.325: E/DatabaseUtils(2366): Writing exception to parcel
01-30 09:27:18.325: E/DatabaseUtils(2366): java.lang.SecurityException: Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
01-30 09:27:18.325: E/DatabaseUtils(2366):  at com.android.server.am.ActivityManagerService.handleIncomingUser(ActivityManagerService.java:13140)
01-30 09:27:18.325: E/DatabaseUtils(2366):  at android.app.ActivityManager.handleIncomingUser(ActivityManager.java:2038)
01-30 09:27:18.325: E/DatabaseUtils(2366):  at com.android.providers.settings.SettingsProvider.callFromPackage(SettingsProvider.java:607)
01-30 09:27:18.325: E/DatabaseUtils(2366):  at android.content.ContentProvider$Transport.call(ContentProvider.java:279)
01-30 09:27:18.325: E/DatabaseUtils(2366):  at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:273)
01-30 09:27:18.325: E/DatabaseUtils(2366):  at android.os.Binder.execTransact(Binder.java:388)
01-30 09:27:18.325: E/DatabaseUtils(2366):  at dalvik.system.NativeStart.run(Native Method)

it doesn't even get to the code of the class that extends Application ...

What I've found

It seems that this problem is very common (many have reported about it), but I can't find any solution and why it occurs, other than having a rooted device.

People also say the permission that is written here is actually a system permission, but I never even heard of it, let alone use it (not even sure what it is).

Problem is, the app I'm working on doesn't have anything related to root, plus it worked just a few days ago.

I've tried to re-install the ROM (Omega ROM v54) and also disable anything related to xposed framework. it didn't help.

The question

How do I fix this issue? How would I know other users won't have this problem?

Is it even related to rooted devices?


EDIT: i thought i've found an answer that fixes it, by choosing "revoke USB debugging..." on the developers section of the settings screen. it seemed to work at first, but later the problem returned and clicking it didn't do anything helpful anymore...


EDIT: I think it's just a bug on the app itself or the ROM, since I can't reproduce it anymore. It's quite weird since I'm quite sure I've tried to debug the app and put a breakpoint on the onCreate method of the acitivity (and maybe of the application class itself) and it didn't stop there.

回答1:

01-30 09:27:18.325: E/DatabaseUtils(2366): java.lang.SecurityException: Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL

This error comes from where you get/set any user/system settings in your app. This particular error log is showing your settings get/set (from your app code) is calling from user 0 (USER_OWNER), but the setting you're changing is for user -2 (USER_CURRENT).

You can't change other users' settings without the permission android.permission.INTERACT_ACROSS_USERS_FULL.

You're probably not considering the case of having different userID's (between calling userID and userID whom the setting is for) in your code and calling set/get settings with the incorrect userID (I don't know why they're different when this happened - for ex, it might happen when there are more than one user accounts on the device).

You need to modify the code to take the correct userID into logic and call the settings set/get for the appropriate userID (the calling userID and the userID for whom the settings is modified for should be the same).



回答2:

You can try moving the apk to /system/app/ and checking if there it works, because there it will be executed as user 0. After that maybe you can compare both logs (working one and regular one) to see where does the app stops.

To install it from your shell:

adb remount
adb push yourApp.apk /system/app/
adb reboot


回答3:

Move your apk to /system/app/. It will not be executed as user 0, but it will allow you to use this permission:

android.permission.INTERACT_ACROSS_USERS_FULL


回答4:

I experienced this SecurityException on an Android Wear watch and it happened when I executed a notification action. I also cannot reproduced it but noticed, that it only happens, when I reinstalled the app by using the IDE or adb install. I never saw it on a proper build signed by my Google Play key.