Skip to content

Instantly share code, notes, and snippets.

@androidneha
Last active March 6, 2024 19:00
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save androidneha/896ec6b08137ef75a95341550b9c60fc to your computer and use it in GitHub Desktop.
Save androidneha/896ec6b08137ef75a95341550b9c60fc to your computer and use it in GitHub Desktop.
Some adb commands to change setting for battery optimisation, start service, stop service, grant permission, revoke permission and etc.

To list-up installed app

pm list packages

Search for a particualr app with pacakagename

pm list pacakges | grep com.abc

Turn on Battery Optimization for a particular app

adb shell dumpsys deviceidle whitelist -<package_name>

Turn off Battery Optimization for a particular app

adb shell dumpsys deviceidle whitelist +<package_name>

To start a service

adb shell am startservice com.some.package.name/.YourServiceSubClassName

To start a service

adb shell am stopservice com.some.package.name/.YourServiceSubClassName

Grant Permission for ex WRITE_SECURE_STTINGS

adb shell pm grant com.abc.yourpackagename android.permission.WRITE_SECURE_SETTINGS

Revoke Permission for ex WRITE_SECURE_STTINGS

adb shell pm revoke com.abc.yourpackagename android.permission.WRITE_SECURE_SETTINGS

Enable accessibility

adb shell settings put secure enabled_accessibility_services packagname/servicename

Turn on Device admin

adb shell dpm set-active-admin --user current packagename/.receivers.DeviceAdministrationReceiver

@jacko9000
Copy link

You have the + and - the wrong way round for battery optimization; it is + to turn off battery optimization.

@opus-x
Copy link

opus-x commented Dec 23, 2022

You have the + and - the wrong way round for battery optimization; it is + to turn off battery optimization.

Indeed

@androidneha
Copy link
Author

You have the + and - the wrong way round for battery optimization; it is + to turn off battery optimization.

Thanks

@aIecxs
Copy link

aIecxs commented Feb 20, 2023

still there are six more typos, but thx it was what I was looking for ;)

@binarynoise
Copy link

adb shell settings put secure enabled_accessibility_services packagname/servicename

this will disable all the other accessibility services, you need to concat them with : (like with $PATH)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment