Skip to content
dtmilano edited this page Apr 28, 2013 · 17 revisions

LocalViewServer is an Android Library that implements ViewServer as part of an application instead of as a system component.

When a device is in secure mode, system ViewServer is not available, so this approach provides an alternative to be able to obtain the View hierarchy used by AndroidViewClient, hierarchyviewer and monitor.

LocalViewServer should be included in your project as an Android Library as showed in the following image.

TemperatureConverter sample

TemperatureConverter is a sample application used to demonstrated several testing techniques and features.

TemperatureConverterActivity extends LocalViewServerActivity enabling the use of AndroidViewClient, Culebra and other utilities even on devices with Secure mode enabled.

Device with secure mode enabled

If secure mode is enabled and you run this command line:

 (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")

this is obtained:

System is secure: AVC won't work

Running TemperatureConverter

Running TemperatureConverter with LocalViewServer will circumvent this restriction, though for this sole application.

In such case you will be able to run:

$ dump.py -IS

and obtain

com.android.internal.policy.impl.PhoneWindow$DecorView NO_ID None
   android.widget.LinearLayout NO_ID None
      android.view.ViewStub id/action_mode_bar_stub None
      android.widget.FrameLayout NO_ID None
         android.widget.TextView id/title TemperatureConverter
      android.widget.FrameLayout id/content None
         android.widget.LinearLayout id/main_layout None
            android.widget.TextView NO_ID Enter the temperature to convert
            android.widget.TextView id/celsius_label Celsius
            com.example.i2at.tc.EditNumber id/celsius 
            android.widget.TextView id/fahrenheit_label Fahrenheit
            com.example.i2at.tc.EditNumber id/fahrenheit 
            android.widget.TextView id/debug 

monitor

When an application supporting LocalViewServer is running on the device, monitor will be able to obtain the View hierarchy even if the device is in secure mode and does not support UiAutomator.

The following screenshot shows monitor displaying the TemperatureConverterActivity with LocalViewServer enabled.

Repository

LocalViewServer repository can be found at https://github.com/dtmilano/ViewServer