Permission Denial: startActivity asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
When I'm trying to use android 'am' command to start an activity ,it's wrong under 4.2 platform(I tried , it's ok under 2.3 version).The code is like this
out = process.getOutputStream();
out.write(("am start -a android.intent.action.VIEW -n com.android.browser/com.android.browser.BrowserActivity\n").getBytes());
out.flush();
InputStream in = process.getInputStream();
BufferedReader re = new BufferedReader(new InputStreamReader(in));
String line = null;
while((line = re.readLine()) != null) {
Log.d("conio","[result]"+line);
}
and the error is like this:
java.lang.SecurityException: Permission Denial: startActivity asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
at android.os.Parcel.readException(Parcel.java:1425)
at android.os.Parcel.readException(Parcel.java:1379)
at android.app.ActivityManagerProxy.startActivityAsUser(ActivityManagerNative.java:1921)
at com.android.commands.am.Am.runStart(Am.java:494)
at com.android.commands.am.Am.run(Am.java:109)
at com.android.commands.am.Am.main(Am.java:82)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:235)
at dalvik.system.NativeStart.main(Native Method)
I want to know
1.what does the user -2 and 0 means?
2.where I can find the details about these ids?
3.what should I do,just add the permissions? I don't want to add the permissions which I know nothing about them.Could anyone help me it,very thanks!
The user 0 and user -2 you are seeing are framework userIds, not Linux uids. From android.os.UserHandle, you can see that userId
0 is the device owner, USER_OWNER
(this is totally different than the Linux uid
0, which is root). userId
-1 represents all users (USER_ALL
), userId
-2 represents the current user (USER_CURRENT
), userId
-3 represents the current user or self (CURRENT_OR_SELF
), and userId
-10000 represents the null user (USER_NULL
).
As far as the permission INTERACT_ACROSS_USERS_FULL
, you can declare it in your manifest file, but you will only be granted it if your app is in the Android system image or signed with the same certificate as another application in the system image that declares the permission. In other words it is a signature
or signatureOrSystem
permission.
As @juanmf mentioned in a comment, adding the --user 0
option to the command resolved the issue for me. The resulting command would look like this:
am start --user 0 -a android.intent.action.VIEW -n com.android.browser/com.android.browser.BrowserActivity
I was receiving this error after my Samsung Galaxy Tab Active 2 tablet upgraded to Android 9. After much searching, I found this post that suggested turning developer options off, restarting the tablet, then turning developer options back on. I ended up just turning USB Debugging off, restarting, then turning USB debugging back on, and everything worked fine after that.