loading...

Introducing ADB-enhanced: A swiss army knife for Android development

ashishb profile image Ashish Bhatia ・2 min read

Android development requires tons of disconnected approaches for the development and testing. Consider some scenarios

  1. To test runtime permission – Go to Settings -> Applications -> Application info of the app you are looking for and disable that permission.
  2. To test a fresh install – adb shell pm clear-data com.example
  3. To test your app under the battery saver mode – turn on the battery saver mode by expanding the notification bar
  4. To stop the execution of an app – kill it via activity manager, adb shell am kill com.example
  5. 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.
  6. To see the overdraw of an app – Go to the developer options and enable/disable it there.

Over time, this became a significant mental burden that I first wrote some of these flows in a text file and then converted them to automated shell scripts. But when even that felt insufficient, I created a tool for myself called adb-enhanced.
How it works:
First, install the tool. I wrote this in Python, so, if the following command does not work, install Python

pip3 install adb-enhanced # I would discourage Python 2 based install at this point

Now, let’s look at the about use-cases again with this tool:

  1. To test a runtime permission :
# Use grant instead of revoke to grant the permission
adbe permission revoke com.example camera  # See all possible such permissions via "adbe -h"

# Use grant instead of revoke to grant the permission
adbe permission revoke com.example camera  # See all possible such permissions via "adbe -h"
  1. To test a fresh install –
# 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 typos
adbe clear-data com.example
# 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 typos
adbe clear-data com.example
  1. To test your app under the battery saver mode –
# As you would guess, use "off" to turn the battery saver off
adbe battery saver on
# As you would guess, use "off" to turn the battery saver off
adbe battery saver on
  1. To stop the execution of an app –
# For a more aggressive kill, try adbe force-stop com.example
adbe stop com.example
  1. To test your app under doze mode
adbe doze on # Use "off" to turn the doze mode off
  1. To see the overdraw of the app
adbe overdraw on

I open-sourced the code at https://github.com/ashishb/adb-enhanced. See the GitHub repository for what all this tool can do. Feedbacks and pull requests are welcome.

Discussion

pic
Editor guide