Secure mode

Brant Xiong edited this page May 6, 2015 · 23 revisions

AndroidViewClient has two possible back-ends:

When we refer to ViewServer in general in this or any other document we are referring to any of the implementations: System ViewServer or LocalViewServer indistinctly

UiAutomator works on Android API 16 and higher, so if your device has a previous version your only alternatives are System ViewServer or LocalViewServer (which does not require secure mode disabled but you have to be able to modify application's source code and include a library).

System ViewServer is started only when the device is not considered secure.

    private boolean isSystemSecure() {
        return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
                "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
    }

The properties involved to consider a device secure are

private static final String SYSTEM_SECURE = "ro.secure";
private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";

This oneliner can be used to test these properties

$ (eval $(adb shell getprop | dos2unix | egrep '\[ro\.secure]|\[ro\.debuggable]' | sed 's/\./_/g; s/]: /=/g; s/[][]//g'); [[ 1 == $ro_secure && 0 == $ro_debuggable ]] && echo "System is secure: AVC won't work" || echo "System is not secure: AVC will work")

when run, this oneliner will tell you if AndroidViewClient could work on your device:

System is secure: AVC won't work

If you run it against any emulator (which is always not secure) it will return

System is not secure: AVC will work

dump

dump is one of the tools provided with AndroidViewClient. In its latest versions it provides a --verbose option that will give you extra information about your device:

$ dump --verbose
Connecting to a device with serialno=.* with a timeout of 60 secs...
Connected to device with serialno=.*
dump.py: ERROR: Device is secure, AndroidViewClient won't work.
    secure=1 debuggable=0 version=15 ignoresecuredevice=False

See detailed information about dump.

Hierarchyviewer

hierarchyviewer is one of the standard Android tools (now deprecated in favor of tools/monitor) and it's described here.

For its operation hierarchyviewer uses the same ViewServer as AndroidViewClient so if you have doubts about it working on your device just try to run

$ hierarchyviewer

and if you receive a message like this

00:00:00 E/hierarchyviewer: Unable to debug device 0123456789

then neither AndroidViewClient or hierarchyviewer will work unless you follow (at your own risk) some of the instructions mentioned in Resources.

Monitor

monitor can use ViewServer or UiAutomator depending on the device.

$ monitor

If the device does not support UiAutomator and is in secure mode you will receive an error message indicating the Views couldn't be obtained.

Resources