Non-exported activities: launched on emulators; SecurityException on phones

限于喜欢 提交于 2020-01-21 11:35:34

问题


I have a non-exported activity in my project.

If I try to launch it on my phone using adb:

adb shell am start -n "packagename/activityname"

I get the error:

java.lang.SecurityException:
Permission Denial: starting Intent { ... } from null (...) not exported from uid ...

But, if I run the same command on an emulator, then everything works Okay. How comes?


回答1:


But, if I run the same command on an emulator, then everything works Okay. How comes?

An emulator instance runs as root by default, meaning that more system processes has root rights compared to a non-rooted device.

Consider the ps command output grep-ed with adbd and sh (i.e. adb shell ps | grep 'adbd' and adb shell ps | grep 'sh', respectively). You might see the following (with different PID and PPID on your device/emulator, of course):

  • Non-rooted device

    USER     PID   PPID  NAME
    shell    166   1     /sbin/adbd
    ...
    shell    15721 166   /system/bin/sh
    
  • Emulator

    USER     PID   PPID  NAME
    root     1183  1     /sbin/adbd
    ...
    root     2884  1183  /system/bin/sh
    

sh process, so is its parent process adbd, is owned by root on an emulator, in contrast to the shell owner on a non-rooted device. And a root user has a "permission" to access your app's sandbox, despite the android:exported attribute set to false.



来源:https://stackoverflow.com/questions/37075351/non-exported-activities-launched-on-emulators-securityexception-on-phones

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