Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 669
Oleg Cherr Avatar asked May 06 '16 14:05

Oleg Cherr


1 Answers

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.

like image 92
Onik Avatar answered Nov 20 '22 16:11

Onik