Last active
August 29, 2015 14:06
-
-
Save asksven/b95f05c8be634f6d5086 to your computer and use it in GitHub Desktop.
Print History Item
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
885 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS | |
886 = new BitDescription[] { | |
887 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged"), | |
888 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen"), | |
889 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps"), | |
890 new BitDescription(HistoryItem.STATE_PHONE_IN_CALL_FLAG, "phone_in_call"), | |
891 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning"), | |
892 new BitDescription(HistoryItem.STATE_WIFI_ON_FLAG, "wifi"), | |
893 new BitDescription(HistoryItem.STATE_WIFI_RUNNING_FLAG, "wifi_running"), | |
894 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock"), | |
895 new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan"), | |
896 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast"), | |
897 new BitDescription(HistoryItem.STATE_BLUETOOTH_ON_FLAG, "bluetooth"), | |
898 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio"), | |
899 new BitDescription(HistoryItem.STATE_VIDEO_ON_FLAG, "video"), | |
900 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock"), | |
901 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor"), | |
902 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK, | |
903 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", | |
904 SCREEN_BRIGHTNESS_NAMES), | |
905 new BitDescription(HistoryItem.STATE_SIGNAL_STRENGTH_MASK, | |
906 HistoryItem.STATE_SIGNAL_STRENGTH_SHIFT, "signal_strength", | |
907 SignalStrength.SIGNAL_STRENGTH_NAMES), | |
908 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK, | |
909 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", | |
910 new String[] {"in", "out", "emergency", "off"}), | |
911 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK, | |
912 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", | |
913 DATA_CONNECTION_NAMES), | |
914 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
443 public final static class More ...HistoryItem implements Parcelable { | |
444 static final String TAG = "HistoryItem"; | |
445 static final boolean DEBUG = false; | |
446 | |
447 public HistoryItem next; | |
448 | |
449 public long time; | |
450 | |
451 public static final byte CMD_NULL = 0; | |
452 public static final byte CMD_UPDATE = 1; | |
453 public static final byte CMD_START = 2; | |
454 public static final byte CMD_OVERFLOW = 3; | |
455 | |
456 public byte cmd = CMD_NULL; | |
457 | |
458 public byte batteryLevel; | |
459 public byte batteryStatus; | |
460 public byte batteryHealth; | |
461 public byte batteryPlugType; | |
462 | |
463 public char batteryTemperature; | |
464 public char batteryVoltage; | |
465 | |
466 // Constants from SCREEN_BRIGHTNESS_* | |
467 public static final int STATE_BRIGHTNESS_MASK = 0x0000000f; | |
468 public static final int STATE_BRIGHTNESS_SHIFT = 0; | |
469 // Constants from SIGNAL_STRENGTH_* | |
470 public static final int STATE_SIGNAL_STRENGTH_MASK = 0x000000f0; | |
471 public static final int STATE_SIGNAL_STRENGTH_SHIFT = 4; | |
472 // Constants from ServiceState.STATE_* | |
473 public static final int STATE_PHONE_STATE_MASK = 0x00000f00; | |
474 public static final int STATE_PHONE_STATE_SHIFT = 8; | |
475 // Constants from DATA_CONNECTION_* | |
476 public static final int STATE_DATA_CONNECTION_MASK = 0x0000f000; | |
477 public static final int STATE_DATA_CONNECTION_SHIFT = 12; | |
478 | |
479 // These states always appear directly in the first int token | |
480 // of a delta change; they should be ones that change relatively | |
481 // frequently. | |
482 public static final int STATE_WAKE_LOCK_FLAG = 1<<30; | |
483 public static final int STATE_SENSOR_ON_FLAG = 1<<29; | |
484 public static final int STATE_GPS_ON_FLAG = 1<<28; | |
485 public static final int STATE_PHONE_SCANNING_FLAG = 1<<27; | |
486 public static final int STATE_WIFI_RUNNING_FLAG = 1<<26; | |
487 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<25; | |
488 public static final int STATE_WIFI_SCAN_FLAG = 1<<24; | |
489 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<23; | |
490 // These are on the lower bits used for the command; if they change | |
491 // we need to write another int of data. | |
492 public static final int STATE_AUDIO_ON_FLAG = 1<<22; | |
493 public static final int STATE_VIDEO_ON_FLAG = 1<<21; | |
494 public static final int STATE_SCREEN_ON_FLAG = 1<<20; | |
495 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; | |
496 public static final int STATE_PHONE_IN_CALL_FLAG = 1<<18; | |
497 public static final int STATE_WIFI_ON_FLAG = 1<<17; | |
498 public static final int STATE_BLUETOOTH_ON_FLAG = 1<<16; | |
499 | |
500 public static final int MOST_INTERESTING_STATES = | |
501 STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG | |
502 | STATE_GPS_ON_FLAG | STATE_PHONE_IN_CALL_FLAG; | |
503 | |
504 public int states; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2154 static void More ...printBitDescriptions(PrintWriter pw, int oldval, int newval, BitDescription[] descriptions) { | |
2155 int diff = oldval ^ newval; | |
2156 if (diff == 0) return; | |
2157 for (int i=0; i<descriptions.length; i++) { | |
2158 BitDescription bd = descriptions[i]; | |
2159 if ((diff&bd.mask) != 0) { | |
2160 if (bd.shift < 0) { | |
2161 pw.print((newval&bd.mask) != 0 ? " +" : " -"); | |
2162 pw.print(bd.name); | |
2163 } else { | |
2164 pw.print(" "); | |
2165 pw.print(bd.name); | |
2166 pw.print("="); | |
2167 int val = (newval&bd.mask)>>bd.shift; | |
2168 if (bd.values != null && val >= 0 && val < bd.values.length) { | |
2169 pw.print(bd.values[val]); | |
2170 } else { | |
2171 pw.print(val); | |
2172 } | |
2173 } | |
2174 } | |
2175 } | |
2176 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2189 public void More ...printNextItem(PrintWriter pw, HistoryItem rec, long now) { | |
2190 pw.print(" "); | |
2191 TimeUtils.formatDuration(rec.time-now, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN); | |
2192 pw.print(" "); | |
2193 if (rec.cmd == HistoryItem.CMD_START) { | |
2194 pw.println(" START"); | |
2195 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) { | |
2196 pw.println(" *OVERFLOW*"); | |
2197 } else { | |
2198 if (rec.batteryLevel < 10) pw.print("00"); | |
2199 else if (rec.batteryLevel < 100) pw.print("0"); | |
2200 pw.print(rec.batteryLevel); | |
2201 pw.print(" "); | |
2202 if (rec.states < 0x10) pw.print("0000000"); | |
2203 else if (rec.states < 0x100) pw.print("000000"); | |
2204 else if (rec.states < 0x1000) pw.print("00000"); | |
2205 else if (rec.states < 0x10000) pw.print("0000"); | |
2206 else if (rec.states < 0x100000) pw.print("000"); | |
2207 else if (rec.states < 0x1000000) pw.print("00"); | |
2208 else if (rec.states < 0x10000000) pw.print("0"); | |
2209 pw.print(Integer.toHexString(rec.states)); | |
2210 if (oldStatus != rec.batteryStatus) { | |
2211 oldStatus = rec.batteryStatus; | |
2212 pw.print(" status="); | |
2213 switch (oldStatus) { | |
2214 case BatteryManager.BATTERY_STATUS_UNKNOWN: | |
2215 pw.print("unknown"); | |
2216 break; | |
2217 case BatteryManager.BATTERY_STATUS_CHARGING: | |
2218 pw.print("charging"); | |
2219 break; | |
2220 case BatteryManager.BATTERY_STATUS_DISCHARGING: | |
2221 pw.print("discharging"); | |
2222 break; | |
2223 case BatteryManager.BATTERY_STATUS_NOT_CHARGING: | |
2224 pw.print("not-charging"); | |
2225 break; | |
2226 case BatteryManager.BATTERY_STATUS_FULL: | |
2227 pw.print("full"); | |
2228 break; | |
2229 default: | |
2230 pw.print(oldStatus); | |
2231 break; | |
2232 } | |
2233 } | |
2234 if (oldHealth != rec.batteryHealth) { | |
2235 oldHealth = rec.batteryHealth; | |
2236 pw.print(" health="); | |
2237 switch (oldHealth) { | |
2238 case BatteryManager.BATTERY_HEALTH_UNKNOWN: | |
2239 pw.print("unknown"); | |
2240 break; | |
2241 case BatteryManager.BATTERY_HEALTH_GOOD: | |
2242 pw.print("good"); | |
2243 break; | |
2244 case BatteryManager.BATTERY_HEALTH_OVERHEAT: | |
2245 pw.print("overheat"); | |
2246 break; | |
2247 case BatteryManager.BATTERY_HEALTH_DEAD: | |
2248 pw.print("dead"); | |
2249 break; | |
2250 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE: | |
2251 pw.print("over-voltage"); | |
2252 break; | |
2253 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE: | |
2254 pw.print("failure"); | |
2255 break; | |
2256 default: | |
2257 pw.print(oldHealth); | |
2258 break; | |
2259 } | |
2260 } | |
2261 if (oldPlug != rec.batteryPlugType) { | |
2262 oldPlug = rec.batteryPlugType; | |
2263 pw.print(" plug="); | |
2264 switch (oldPlug) { | |
2265 case 0: | |
2266 pw.print("none"); | |
2267 break; | |
2268 case BatteryManager.BATTERY_PLUGGED_AC: | |
2269 pw.print("ac"); | |
2270 break; | |
2271 case BatteryManager.BATTERY_PLUGGED_USB: | |
2272 pw.print("usb"); | |
2273 break; | |
2274 case BatteryManager.BATTERY_PLUGGED_WIRELESS: | |
2275 pw.print("wireless"); | |
2276 break; | |
2277 default: | |
2278 pw.print(oldPlug); | |
2279 break; | |
2280 } | |
2281 } | |
2282 if (oldTemp != rec.batteryTemperature) { | |
2283 oldTemp = rec.batteryTemperature; | |
2284 pw.print(" temp="); | |
2285 pw.print(oldTemp); | |
2286 } | |
2287 if (oldVolt != rec.batteryVoltage) { | |
2288 oldVolt = rec.batteryVoltage; | |
2289 pw.print(" volt="); | |
2290 pw.print(oldVolt); | |
2291 } | |
2292 printBitDescriptions(pw, oldState, rec.states, | |
2293 HISTORY_STATE_DESCRIPTIONS); | |
2294 pw.println(); | |
2295 } | |
2296 oldState = rec.states; | |
2297 } | |
2298 | |
2322 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment