-
Notifications
You must be signed in to change notification settings - Fork 6
/
show_package_options.py
155 lines (134 loc) · 4.96 KB
/
show_package_options.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import subprocess
import os
import sys
from workflow import Workflow, ICON_INFO
from toolchain import run_script
from commands import CMD_DUMP_PACKAGE
import commands
packName = os.getenv('package')
def main(wf):
shell_cmd = CMD_DUMP_PACKAGE.format(packName)
result = None
infos= None
versionName = ""
enabled = True
userId = None
versionCopyText = ""
# Package info
try:
result = run_script(shell_cmd)
except subprocess.CalledProcessError as e:
log.debug(e)
if result:
result = result[result.rfind("enabled="):]
infos = result.rstrip().split('\n')
log.debug(infos)
userIdInfo = [x.strip() for x in infos if x.strip().startswith("userId=")]
log.debug(userIdInfo)
if len(userIdInfo) == 1:
userId = userIdInfo[0][7:]
versionName = infos[1].strip()[12:]
versionCode = infos[2].strip()[12:]
if userId != None:
versionCode = versionCode + " userId={0}".format(userId)
it = wf.add_item(title=packName,
subtitle="{0}({1})".format(versionName, versionCode),
valid=False,
copytext=packName,
icon=ICON_INFO)
versionCopyText = it.subtitle
if infos:
appInfo = infos[0].strip()
enabled = (appInfo[appInfo.find("enabled=") + 8] != '2')
log.debug("enabled ? {0}".format(enabled))
# App info
title = "App info"
it = wf.add_item(title=title,
subtitle="Open app info page",
arg="app_info",
copytext=versionCopyText,
valid=True)
it.add_modifier("cmd", subtitle="cmd + C to copy app info")
if (infos and enabled):
# Force stop
title = "Force stop"
wf.add_item(title=title,
arg="force_stop",
valid=True)
if (infos and len(infos) > 4 and enabled):
# Start app
title = "Start application"
wf.add_item(title=title,
arg="start_app",
copytext=commands.CMD_LAUNCH_APP.format(packName),
valid=True)
# Clear data
title = "Clear app data"
wf.add_item(title=title,
arg="clear_app_data",
copytext=commands.CMD_CLEAR_DATA.format(packName),
valid=True)
# Uninstall
title = "Uninstall app"
it = wf.add_item(title=title,
arg="uninstall_app",
subtitle="`cmd` to keep data and cache",
copytext=commands.CMD_UNINSTALL_APP.format(packName, ""),
valid=True)
mod = it.add_modifier("cmd", subtitle="keep the data and cache directories")
mod.setvar("mod", "keep_data")
if infos:
# Disable/Enable app
title = ("Enable app", "Disable app")[enabled]
it = wf.add_item(title=title,
arg="dis_enable_app",
copytext=commands.CMD_DISABLE_APP.format(("enable", "disable")[enabled], packName),
valid=True)
it.setvar("enabled", enabled)
if enabled:
mod = it.add_modifier("cmd", subtitle="disable for current user")
mod.setvar("mod", "disable_for_current_user")
# Reset AppOps
title = "Reset AppOps"
it = wf.add_item(title=title,
arg="reset_appops",
subtitle="Reset permissions to default. Will not work if exec too often.",
copytext=commands.CMD_RESET_APPOPS.format(packName),
valid=True)
# Get apk file
title = "Extract apk file"
it = wf.add_item(title=title,
arg="extract_apk",
copytext=commands.CMD_SHOW_APK_PATH.format(packName),
valid=True)
if versionName:
it.setvar("pretty_version", versionName)
idx = 1
while idx > 0:
config = os.getenv('self_script_app_%d' % idx)
if config:
title = config.split("|")[0]
path = config.split("|")[1]
it = wf.add_item(title=title,
subtitle="with script: %s" % path,
arg="self_script_app_%d" % idx,
valid=True)
it.setvar("self_script_app", config)
mod = it.add_modifier("cmd", subtitle="apply cmd modifier")
mod.setvar("mod", "cmd")
mod = it.add_modifier("alt", subtitle="apply alt modifier")
mod.setvar("mod", "alt")
mod = it.add_modifier("ctrl", subtitle="apply ctrl modifier")
mod.setvar("mod", "ctrl")
mod = it.add_modifier("fn", subtitle="apply fn modifier")
mod.setvar("mod", "fn")
mod = it.add_modifier("shift", subtitle="apply shift modifier")
mod.setvar("mod", "shift")
idx = idx + 1
else:
idx = -1
wf.send_feedback()
if __name__ == '__main__':
wf = Workflow()
log = wf.logger
sys.exit(wf.run(main))