View Javadoc
1   package edu.jiangxin.apktoolbox.android.dumpsys.alarm;
2   
3   import org.apache.commons.lang3.StringUtils;
4   
5   public class Alarm {
6       private String signature;
7       private String alarmType;
8       private int index;
9       private String id;
10      private int type;
11      private String ownerPackageName;
12      private AlarmBatch parentBatch;
13      private long when;
14  
15      public String getOwnerPackageName() {
16          return ownerPackageName;
17      }
18  
19      public void setParentBatch(AlarmBatch parentBatch) {
20          this.parentBatch = parentBatch;
21      }
22  
23      public static Alarm fromString(String stringDefinition) {
24          return new Alarm(stringDefinition);
25      }
26  
27      private Alarm(String stringDefinition) {
28          signature = "ALARM";
29          parentBatch = null;
30  
31          index = Integer.valueOf(StringUtils.substringBetween(stringDefinition, " #", ": "));
32  
33          String alarmDefinition = StringUtils.substringBetween(stringDefinition, "Alarm{", "}" + System.getProperty("line.separator"));
34  
35          String[] tmp = alarmDefinition.split(" ");
36  
37          id = tmp[0];
38          type = Integer.valueOf(tmp[2]);
39  
40          switch (type) {
41              case 0:
42                  alarmType = "RTC_WAKEUP";
43                  break;
44              case 1:
45                  alarmType = "RTC";
46                  break;
47              case 2:
48                  alarmType = "ELAPSED_WAKEUP";
49                  break;
50              case 3:
51                  alarmType = "ELAPSED";
52                  break;
53          }
54  
55          if (tmp.length >= 5) {
56              when = Long.valueOf(tmp[4]);
57              ownerPackageName = StringUtils.substringBetween(alarmDefinition, tmp[4]+" ", " procName");
58              if (ownerPackageName != null && ownerPackageName.contains("}")) {
59                  ownerPackageName = StringUtils.substringAfterLast(ownerPackageName, "}");
60              }
61          }
62      }
63  
64      public String getSignature() {
65          return signature;
66      }
67  
68      public String getAlarmType() {
69          return alarmType;
70      }
71  
72      public int getIndex() {
73          return index;
74      }
75  
76      public String getId() {
77          return id;
78      }
79  
80      public int getType() {
81          return type;
82      }
83  
84      public AlarmBatch getParentBatch() {
85          return parentBatch;
86      }
87  
88      public long getWhen() {
89          return when;
90      }
91  }