1 package edu.jiangxin.apktoolbox.android.dumpsys.alarm;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 public class AlarmBatch {
7 private String signature;
8 private String id;
9 private int alarmCount;
10 private long start;
11 private long end;
12 String flags;
13
14 private List<Alarm> listAlarms = new ArrayList<>();
15
16 public void appendAlarm(Alarm alarm) {
17 alarm.setParentBatch(this);
18 listAlarms.add(alarm);
19 }
20
21 public static AlarmBatch fromString(String batchDefinition) {
22 String[] components = batchDefinition.split(" ");
23 if (components.length < 4) {
24 return null;
25 }
26 return new AlarmBatch(components);
27 }
28
29 private AlarmBatch(String[] components) {
30 signature = "BATCH";
31 id = components[0];
32
33 if (components.length >= 5) {
34 flags = components[4];
35 }
36
37 setParameter(components[1]);
38 setParameter(components[2]);
39 setParameter(components[3]);
40 }
41
42 private boolean setParameter(String expression) {
43 String[] components = expression.split("=");
44 if (components.length != 2) {
45 return false;
46 }
47
48 if ("num".equals(components[0])) {
49 alarmCount = Integer.valueOf(components[1]);
50 return true;
51 }
52
53
54
55
56 if ("start".equals(components[0])) {
57 start = Long.valueOf(components[1]);
58 return true;
59 }
60
61 if ("end".equals(components[0])) {
62 end = Long.valueOf(components[1]);
63 return true;
64 }
65
66 return false;
67 }
68
69 public String getSignature() {
70 return signature;
71 }
72
73 public String getId() {
74 return id;
75 }
76
77 public int getAlarmCount() {
78 return alarmCount;
79 }
80
81 public long getStart() {
82 return start;
83 }
84
85 public long getEnd() {
86 return end;
87 }
88
89 public String getFlags() {
90 return flags;
91 }
92
93 public List<Alarm> getListAlarms() {
94 return listAlarms;
95 }
96 }