Skip to content

Commit e2dee8e

Browse files
committed
2014-9-2
1 parent e695bb1 commit e2dee8e

8 files changed

Lines changed: 213 additions & 0 deletions

File tree

python/AndroidAdb/AndroidAdb.exe

811 KB
Binary file not shown.

python/batch_install.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#coding=utf-8
2+
3+
#需要在脚本所在目录下有个AndroidAdb.exe程序,该adb可以支持安装以中文命名的apk
4+
#需要将apk文件放在脚本所在目录下的Apps目录下
5+
6+
import os
7+
import time
8+
import sys
9+
10+
def check_adb():
11+
if os.path.isfile(os.getcwd() + "\\AndroidAdb\\AndroidAdb.exe"):
12+
return True
13+
else:
14+
return False
15+
16+
def check_dir():
17+
if os.path.isdir(os.getcwd() + "\\Apps"):
18+
return True
19+
else:
20+
return False
21+
22+
def install():
23+
count = 0
24+
for path, subdir, files in os.walk(os.getcwd() + "\\Apps"):
25+
for apk in files:
26+
os.system(os.getcwd() + "\\AndroidAdb\\AndroidAdb.exe install " + os.path.join(path, apk))
27+
count += 1
28+
29+
print "\n" + str(count) + " apps install complete."
30+
31+
if __name__ == "__main__":
32+
if check_adb():
33+
pass
34+
else:
35+
print "AndroidAdb.exe not exist."
36+
time.sleep(5)
37+
sys.exit(1)
38+
39+
if check_dir():
40+
pass
41+
else:
42+
print "Apps Directory not exist"
43+
time.sleep(5)
44+
sys.exit(1)
45+
46+
install()

python/batch_uninstall.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/python
2+
3+
import os
4+
import sys
5+
6+
def uninstall():
7+
os.popen("adb wait-for-device")
8+
print "start uninstall..."
9+
for packages in os.popen("adb shell pm list packages -3").readlines():
10+
packageName = packages.split(":")[-1].splitlines()[0]
11+
os.popen("adb uninstall " + packageName)
12+
print "remove " + packageName + " successes."
13+
14+
if __name__ == "__main__":
15+
uninstall()
16+
print " "
17+
print "All the third-party applications uninstall successes."

python/getApp.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!coding=utf-8
2+
3+
import os
4+
import re
5+
6+
#打开手机上的第三方应用,运行脚本,会将该应用对应的apk复制到本地的Apps文件夹下
7+
8+
PATH = lambda p: os.path.abspath(p)
9+
10+
def get_current_package_name():
11+
pattern = re.compile(r"[a-zA-Z0-9\.]+/.[a-zA-Z0-9\.]+")
12+
os.popen("adb wait-for-device")
13+
out = os.popen("adb shell dumpsys input | findstr FocusedApplication").read()
14+
package_name = pattern.findall(out)[0].split("/")[0]
15+
16+
return package_name
17+
18+
def get_match_apk(package_name, path):
19+
list = []
20+
for packages in os.popen("adb shell pm list packages -f " + package_name).readlines():
21+
list.append(packages.split(":")[-1].split("=")[0])
22+
apk_name = list[0].split("/")[-1]
23+
os.popen("adb pull " + list[0] + " " + path)
24+
25+
if __name__ == "__main__":
26+
path = PATH(os.getcwd() + "/Apps")
27+
if not os.path.isdir(PATH(os.getcwd() + "/Apps")):
28+
os.makedirs(path)
29+
30+
get_match_apk(get_current_package_name(), path)

python/get_current_activity.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/python
2+
3+
import os
4+
import platform
5+
import re
6+
import sys
7+
8+
PATH = lambda p: os.path.abspath(
9+
os.path.join(os.path.dirname(__file__), p)
10+
)
11+
12+
system = platform.system()
13+
if system is "Windows":
14+
find_util = "findstr"
15+
else:
16+
find_util = "grep"
17+
18+
pattern = re.compile(r"[a-zA-Z0-9\.]+/.[a-zA-Z0-9\.]+")
19+
20+
def get_activity():
21+
os.popen("adb wait-for-device")
22+
out = os.popen("adb shell dumpsys input | " + find_util + " FocusedApplication").read()
23+
return pattern.findall(out)[0]
24+
25+
26+
if __name__ == "__main__":
27+
f = open(PATH(os.getcwd() + "/CurrentActivity.txt"), "w")
28+
f.write("Activity: \n" + get_activity())
29+
f.close()
30+
sys.exit(0)

python/get_current_pkginfo.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import os
2+
import tempfile
3+
import re
4+
5+
tempFile = tempfile.gettempdir()
6+
7+
def get_aapt():
8+
if "ANDROID_HOME" in os.environ:
9+
rootDir = os.path.join(os.environ["ANDROID_HOME"], "build-tools")
10+
for path, subdir, files in os.walk(rootDir):
11+
if "aapt.exe" in files:
12+
return os.path.join(path, "aapt.exe")
13+
else:
14+
return "ANDROID_HOME not exist"
15+
16+
def get_current_package_name():
17+
pattern = re.compile(r"[a-zA-Z0-9\.]+/.[a-zA-Z0-9\.]+")
18+
os.popen("adb wait-for-device")
19+
out = os.popen("adb shell dumpsys input | findstr FocusedApplication").read()
20+
package_name = pattern.findall(out)[0].split("/")[0]
21+
22+
return package_name
23+
24+
def get_match_apk(package_name):
25+
list = []
26+
for packages in os.popen("adb shell pm list packages -f " + package_name).readlines():
27+
list.append(packages.split(":")[-1].split("=")[0])
28+
apk_name = list[0].split("/")[-1]
29+
os.popen("adb pull " + list[0] + " " + tempFile)
30+
31+
return tempFile + "\\" + apk_name
32+
33+
if __name__ == "__main__":
34+
os.popen(get_aapt() + \
35+
" dump badging " + \
36+
get_match_apk(get_current_package_name()) + \
37+
" > PackageInfo.txt")
38+
os.popen("del " + tempFile + "\\*.apk")

python/get_package_name.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/python
2+
3+
import os
4+
import platform
5+
import re
6+
import sys
7+
8+
PATH = lambda p: os.path.abspath(
9+
os.path.join(os.path.dirname(__file__), p)
10+
)
11+
12+
system = platform.system()
13+
if system is "Windows":
14+
find_util = "findstr"
15+
else:
16+
find_util = "grep"
17+
18+
pattern = re.compile(r"[a-zA-Z0-9\.]+/.[a-zA-Z0-9\.]+")
19+
20+
def get_package_name():
21+
os.popen("adb wait-for-device")
22+
out = os.popen("adb shell dumpsys input | " + find_util + " FocusedApplication").read()
23+
package_name = pattern.findall(out)[0].split("/")[0]
24+
25+
return package_name
26+
27+
28+
if __name__ == "__main__":
29+
f = open(PATH(os.getcwd() + "/PackageName.txt"), "w")
30+
f.write("Package: \n" + get_package_name())
31+
f.close()
32+
sys.exit(0)

python/screenshot.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env python
2+
3+
import os
4+
import time
5+
6+
PATH = lambda p: os.path.abspath(p)
7+
8+
def screenshot():
9+
path = PATH(os.getcwd() + "/screenshot")
10+
timestamp = time.strftime('%Y-%m-%d-%H-%M-%S',time.localtime(time.time()))
11+
os.popen("adb wait-for-device")
12+
os.popen("adb shell screencap -p /data/local/tmp/tmp.png")
13+
if not os.path.isdir(PATH(os.getcwd() + "/screenshot")):
14+
os.makedirs(path)
15+
os.popen("adb pull /data/local/tmp/tmp.png " + PATH(path + "/" + timestamp + ".png"))
16+
os.popen("adb shell rm /data/local/tmp/tmp.png")
17+
print "success"
18+
19+
if __name__ == "__main__":
20+
screenshot()

0 commit comments

Comments
 (0)