Skip to content

Instantly share code, notes, and snippets.

@GokulNC
Created June 1, 2020 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GokulNC/9bf9980920e00a5b6d8917bdb72551b6 to your computer and use it in GitHub Desktop.
Save GokulNC/9bf9980920e00a5b6d8917bdb72551b6 to your computer and use it in GitHub Desktop.
A script to uninstall a given Android package-name. If it's a system app, it will be force-disabled.
import sys
from subprocess import Popen, PIPE, STDOUT
def run_command(command):
out = Popen(command.split(), shell=True, stdout=PIPE, stderr=STDOUT)
stdout, stderr = out.communicate()
return stdout.decode("utf-8").strip()
def remove_package_adb(pkg_name, disable=True):
out = run_command('adb uninstall %s' % pkg_name)
if 'Success' in out:
return pkg_name + ' UNINSTALLED successfully globally'
errors = out
if disable:
out = run_command('adb shell pm uninstall -k --user 0 %s' % pkg_name)
if 'Success' in out:
return pkg_name + ' DISABLED successfully for user 0'
errors += '\n' + out
return 'UNABLE to uninstall %s\nERROR: %s' % (pkg_name, errors)
def get_active_devices():
lines = run_command('adb devices').split('\n')[1:]
device_ids = [line.split()[0] for line in lines if line.strip() and 'device' in line.split()[1]]
return device_ids
if __name__ == '__main__':
pkg_name = sys.argv[1]
if not pkg_name:
sys.exit('USAGE: python %s <<package_name>>' % sys.argv[0])
devices = get_active_devices()
if not devices:
sys.exit('ERROR: No active devices found!')
# print('FOUND DEVICES %s\n' % str(devices))
print(remove_package_adb(pkg_name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment