Permission Denial: startActivity asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL

匿名 (未验证) 提交于 2019-12-03 02:38:01

问题:

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!

回答1:

1)In linux every user has an id number. 0 and -2 are User IDs (UIDs). 0 is root, -2 is some random user (which may not be a person, it may just be a fake account used for internal reasons).

2)Any book on Linux. Android is just a graphical framework on top of Linux.

3)Yes, just add the permission.



回答2:

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.



回答3:

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


回答4:

Permissions are just a line of code that you need to add in the manifest to inform that you accessing those resources and requesting android to allow these resources to use.

1) i just added an example containing permission.

2) In Linux there is root user ,group and others . 0 comes to root and UID cannot be negative its value is between 0 - 999. See this link



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!