-
Notifications
You must be signed in to change notification settings - Fork 5
/
alarms.py
76 lines (56 loc) · 2.22 KB
/
alarms.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
#!/usr/bin/env python
"""
Alarms.py
Prints all the alarms scheduled for one package name, or the entire system
Usage: python alarms.py [<package name>]
"""
__author__ = 'Udi Cohen <[email protected]>'
__license__ = "Apache 2.0"
__copyright__ = 'Copyright 2012 Udi Cohen'
import subprocess
import re
from subprocess import *
import sys, pprint
print ' **********************************'
print ' * Android Alarms Dumper *'
print ' * *'
print ' * Written by Udi Cohen *'
print ' * http://www.udinic.com *'
print ' **********************************'
print
print
p=subprocess.Popen([r'adb', 'shell', 'dumpsys alarm'],
stdout=PIPE, stderr=PIPE,
shell= True,
cwd='C:\\')
out, err = p.communicate()
p.wait()
pp = pprint.PrettyPrinter(indent=4)
lines= out.split('\n')
alerts = [["RTC TYPE", "When", "Repeat", "pkg", "Type"]]
for i in xrange(len(lines)):
if lines[i].replace(" ","")[:3]=="RTC":
# Extract the information we
rtc_type = lines[i].strip().split()[0]
when=re.findall('when=([0-9a-z+]*)',lines[i+1])[0]
repeat=re.findall('repeatInterval=([0-9a-z+])*',lines[i+1])[0]
intentType=list(re.findall("PendingIntentRecord{(\w+) ([\w\.]+) (\w+)", lines[i+2])[0])
# If the user has passed a package name as an argument
# we'll filter all other packages' alarms
if len(sys.argv) > 1:
if intentType[1] == sys.argv[1]:
alerts.append([rtc_type, when, repeat, intentType[1], intentType[2]])
else:
alerts.append([rtc_type, when, repeat, intentType[1], intentType[2]])
out_lines = [""] * len(alerts)
# Format the data nicely to columns
for column in xrange(len(alerts[0])):
for alert_index in xrange(len(alerts)):
out_lines[alert_index] += str(alerts[alert_index][column])
line_size = max(map(len, out_lines)) + 5
for alert_index in xrange(len(alerts)):
out_lines[alert_index] += " " * (line_size - len(out_lines[alert_index]))
for l in out_lines:
print l
print
raw_input("Press ENTER to exit")