Oleg Cherr
Oleg Cherr

Reputation: 3675

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

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?

Upvotes: 7

Views: 3223

Answers (1)

Onik
Onik

Reputation: 19949

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.

Upvotes: 5

Related Questions