Skip to content

Instantly share code, notes, and snippets.

@yukkerike
Created September 28, 2023 18:43
Show Gist options
  • Save yukkerike/9e6f96d4f9150f68dcb643b3fb2f551a to your computer and use it in GitHub Desktop.
Save yukkerike/9e6f96d4f9150f68dcb643b3fb2f551a to your computer and use it in GitHub Desktop.
Imagine if you accidentally pushed a disabling trackers in system apps button with https://github.com/MuntashirAkon/AppManager and your phone came in an unresponsive state. If you still have adb access this tool may save you lots of painfull hours.
import re
import os
import sys
if len(sys.argv) < 2:
print("Usage:\nadb shell dumpsys package > disabled_services.txt\npython3 analyze_dumpsys.py disabled_services.txt > services.txt")
sys.exit(1)
cwd = os.getcwd()
file_name = os.path.join(cwd, sys.argv[1])
if not os.path.isfile(file_name):
print("File not found.")
sys.exit(1)
with open(file_name, "r") as f:
packages_file = f.readlines()
packages_file = packages_file[packages_file.index("Packages:\n") + 1:]
packages = {}
current_package = None
for line in packages_file:
if line.find("Package [") != -1:
package = re.search(r"Package \[(.*)\]", line).group(1)
packages[package] = []
current_package = package
if current_package is not None:
packages[current_package].append(line)
packages_with_activities = {"": []}
for package in packages:
packages_with_activities[package] = []
writing = False
for line in packages[package]:
if line.find("disabledComponents:") != -1:
writing = True
continue
elif writing and (line.find("enabledComponents:") != -1 or line.find("User ") != -1):
writing = False
break
if writing:
packages_with_activities[package].append(line.strip())
count=0
for package in packages_with_activities:
for activity in packages_with_activities[package]:
print('/'.join((package, activity)))
count+=1
print('Total number of disabled services: ', count, '\nTo start reenabling them:\nadb push services.txt /data/local/tmp/services.txt\ncat /data/local/tmp/services.txt | xargs -n1 pm enable', file=sys.stderr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment