惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Tailwind CSS Blog
有赞技术团队
有赞技术团队
爱范儿
爱范儿
Engineering at Meta
Engineering at Meta
J
Java Code Geeks
雷峰网
雷峰网
WordPress大学
WordPress大学
L
LangChain Blog
D
DataBreaches.Net
The GitHub Blog
The GitHub Blog
博客园 - 三生石上(FineUI控件)
Microsoft Security Blog
Microsoft Security Blog
P
Proofpoint News Feed
腾讯CDC
GbyAI
GbyAI
罗磊的独立博客
Blog — PlanetScale
Blog — PlanetScale
月光博客
月光博客
F
Fortinet All Blogs
Y
Y Combinator Blog
V
V2EX
A
About on SuperTechFans

ashishb.net

A day in Luxembourg - the richest country in the world I was asked to install malware during a fake interview Book summary: Breakneck - China's quest to engineer the future by Dan Wang Book summary: How to Teach Your Baby to Read Book Summary: The Discontented Little Baby Book by Pamela Douglas Introducing Amazing Sandbox - run third-party tools and AI agents securely on your machine Why software outsourcing gets a bad reputation? Book summary: The Natural Baby Sleep Solution by Polly Moore A day in Antwerp, Belgium Journey of online influencers Two days in Brussels, Belgium Shortcuts - when we love them and when we don't A visit to Rakhigarhi Three days in overhyped Paris Empty Japan, crowded Tokyo The real lock-in in GitHub is not the code, but the stars 11-day Norwegian Breakaway East Caribbean cruise Sanskrit and Sri Lankan Air Force Use REST with Open API The Achilles heel of American capitalism Costa Rica in 4 days At a juice stall in Sri Lanka A short stay at Warsaw, Poland Best practices for using Python & uv inside Docker Two days in Vilnius, Lithuania How IntelliJ IDEs waste disk space Pregnancy Why there aren't many digital nomads from India Two days in Riga, Latvia To keep your machine secure, run third-party tools inside Docker
adb-enhanced: A swiss army knife for Android development
Ashish Bhatia · 2018-06-24 · via ashishb.net
Featured in Android WeeklyFeatured on CSDN blogGitHub Repo starsPyPI - Version

Android development requires tons of disconnected approaches for 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 its normal state.
  6. To see the over draw of the 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

1
pip3 install adb-enhanced # Python2 is no longer supported since 2021

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

  1. To test runtime permission :
1
2
# 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 installation -
1
2
3
4
# 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 -
1
2
# As you would guess, use "off" to turn the battery saver off
adbe battery saver on
  1. To stop the execution of an app -
1
2
# For a more aggressive kill, try adbe force-stop com.example
adbe stop com.example
  1. To test your app under doze mode
1
adbe doze on # Use "off" to turn the doze mode off
  1. To see to overdraw of the app

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