Android development requires tons of disconnected approaches for the development and testing. Consider some scenarios
- To test runtime permission – Go to Settings -> Applications -> Application info of the app you are looking for and disable that permission.
- To test a fresh install – adb shell pm clear-data com.example
- To test your app under the battery saver mode – turn on the battery saver mode by expanding the notification bar
- To stop the execution of an app – kill it via activity manager, adb shell am kill com.example
- To test your app under doze mode – first, make the device believe that it is unplugged via “adb shell dumpsys battery unplug”, then, make it think that it is discharging via “adb shell dumpsys battery set status 3”, and then enable doze mode via “adb shell dumpsys deviceidle force-idle”. And don’t forget to execute a set of unrelated complementary commands once you are done to bring the device back to the normal state.
- To see the overdraw of the app – Go to the developer options and enable/disable it there.
pip3 install adb-enhanced # Use "pip" for python2. Both are supported.
Now, let’s look at the about use-cases again with this tool:
- To test a runtime permission :
Shell12# Use grant instead of revoke to grant the permissionadbe permission revoke com.example camera # See all possible such permissions via "adbe -h"
- To test a fresh install –
Shell1234# Unlike adb shell pm clear-data com.example, this command will# produce an error if com.example is not installed# which is good for catching typosadbe clear-data com.example
- To test your app under the battery saver mode –
Shell12# As you would guess, use "off" to turn the battery saver offadbe battery saver on
- To stop the execution of an app –
Shell12# For a more aggressive kill, try adbe force-stop com.exampleadbe stop com.example
- To test your app under doze mode
Shell1adbe doze on # Use "off" to turn the doze mode off
- To see the overdraw of the app
Shell1adbe overdraw on