Loading protos/fuelgauge_log.proto +1 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ message BatteryUsageHistoricalLogEntry { RECHECK_JOB = 3; FETCH_USAGE_DATA = 4; INSERT_USAGE_DATA = 5; TIME_UPDATED = 6; } optional int64 timestamp = 1; Loading src/com/android/settings/fuelgauge/batteryusage/BootBroadcastReceiver.java +1 −2 Original line number Diff line number Diff line Loading @@ -70,8 +70,7 @@ public final class BootBroadcastReceiver extends BroadcastReceiver { break; case Intent.ACTION_TIME_CHANGED: Log.d(TAG, "refresh job and clear all data from action=" + action); DatabaseUtils.clearAll(context); PeriodicJobManager.getInstance(context).refreshJob(/*fromBoot=*/ false); DatabaseUtils.clearDataAfterTimeChangedIfNeeded(context); break; default: Log.w(TAG, "receive unsupported action=" + action); Loading src/com/android/settings/fuelgauge/batteryusage/DataProcessManager.java +1 −3 Original line number Diff line number Diff line Loading @@ -72,8 +72,6 @@ public class DataProcessManager { private static final String TAG = "DataProcessManager"; private static final List<BatteryEventType> POWER_CONNECTION_EVENTS = List.of(BatteryEventType.POWER_CONNECTED, BatteryEventType.POWER_DISCONNECTED); private static final List<BatteryEventType> BATTERY_LEVEL_RECORD_EVENTS = List.of(BatteryEventType.FULL_CHARGED, BatteryEventType.EVEN_HOUR); // For testing only. @VisibleForTesting Loading Loading @@ -575,7 +573,7 @@ public class DataProcessManager { final List<BatteryEvent> batteryLevelRecordEvents = DatabaseUtils.getBatteryEvents( context, Calendar.getInstance(), lastFullChargeTime, BATTERY_LEVEL_RECORD_EVENTS); DatabaseUtils.BATTERY_LEVEL_RECORD_EVENTS); final long startTimestamp = batteryLevelRecordEvents.isEmpty() ? lastFullChargeTime : batteryLevelRecordEvents.get(0).getTimestamp(); final BatteryLevelData batteryLevelData = getPeriodBatteryLevelData(context, handler, Loading src/com/android/settings/fuelgauge/batteryusage/DatabaseUtils.java +33 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ import java.time.Duration; import java.util.ArrayList; import java.util.Calendar; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.function.Function; Loading Loading @@ -133,6 +134,9 @@ public final class DatabaseUtils { .authority(AUTHORITY) .appendPath(BATTERY_USAGE_SLOT_TABLE) .build(); /** A list of level record event types to access battery usage data. */ public static final List<BatteryEventType> BATTERY_LEVEL_RECORD_EVENTS = List.of(BatteryEventType.FULL_CHARGED, BatteryEventType.EVEN_HOUR); // For testing only. @VisibleForTesting Loading Loading @@ -408,6 +412,35 @@ public final class DatabaseUtils { }); } /** Clears all data and jobs if current timestamp is out of the range of last recorded job. */ public static void clearDataAfterTimeChangedIfNeeded(Context context) { AsyncTask.execute(() -> { try { final List<BatteryEvent> batteryLevelRecordEvents = DatabaseUtils.getBatteryEvents(context, Calendar.getInstance(), getLastFullChargeTime(context), BATTERY_LEVEL_RECORD_EVENTS); final long lastRecordTimestamp = batteryLevelRecordEvents.isEmpty() ? INVALID_TIMESTAMP : batteryLevelRecordEvents.get(0).getTimestamp(); final long nextRecordTimestamp = TimestampUtils.getNextEvenHourTimestamp(lastRecordTimestamp); final long currentTime = System.currentTimeMillis(); final boolean isOutOfTimeRange = lastRecordTimestamp == INVALID_TIMESTAMP || currentTime < lastRecordTimestamp || currentTime > nextRecordTimestamp; final String logInfo = String.format(Locale.ENGLISH, "clear database = %b, current time = %d, last record time = %d", isOutOfTimeRange, currentTime, lastRecordTimestamp); Log.d(TAG, logInfo); BatteryUsageLogUtils.writeLog(context, Action.TIME_UPDATED, logInfo); if (isOutOfTimeRange) { DatabaseUtils.clearAll(context); PeriodicJobManager.getInstance(context).refreshJob(/* fromBoot= */ false); } } catch (RuntimeException e) { Log.e(TAG, "refreshDataAndJobIfNeededAfterTimeChanged() failed", e); } }); } /** Returns the timestamp for 00:00 6 days before the calendar date. */ public static long getTimestampSixDaysAgo(Calendar calendar) { Calendar startCalendar = Loading Loading
protos/fuelgauge_log.proto +1 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ message BatteryUsageHistoricalLogEntry { RECHECK_JOB = 3; FETCH_USAGE_DATA = 4; INSERT_USAGE_DATA = 5; TIME_UPDATED = 6; } optional int64 timestamp = 1; Loading
src/com/android/settings/fuelgauge/batteryusage/BootBroadcastReceiver.java +1 −2 Original line number Diff line number Diff line Loading @@ -70,8 +70,7 @@ public final class BootBroadcastReceiver extends BroadcastReceiver { break; case Intent.ACTION_TIME_CHANGED: Log.d(TAG, "refresh job and clear all data from action=" + action); DatabaseUtils.clearAll(context); PeriodicJobManager.getInstance(context).refreshJob(/*fromBoot=*/ false); DatabaseUtils.clearDataAfterTimeChangedIfNeeded(context); break; default: Log.w(TAG, "receive unsupported action=" + action); Loading
src/com/android/settings/fuelgauge/batteryusage/DataProcessManager.java +1 −3 Original line number Diff line number Diff line Loading @@ -72,8 +72,6 @@ public class DataProcessManager { private static final String TAG = "DataProcessManager"; private static final List<BatteryEventType> POWER_CONNECTION_EVENTS = List.of(BatteryEventType.POWER_CONNECTED, BatteryEventType.POWER_DISCONNECTED); private static final List<BatteryEventType> BATTERY_LEVEL_RECORD_EVENTS = List.of(BatteryEventType.FULL_CHARGED, BatteryEventType.EVEN_HOUR); // For testing only. @VisibleForTesting Loading Loading @@ -575,7 +573,7 @@ public class DataProcessManager { final List<BatteryEvent> batteryLevelRecordEvents = DatabaseUtils.getBatteryEvents( context, Calendar.getInstance(), lastFullChargeTime, BATTERY_LEVEL_RECORD_EVENTS); DatabaseUtils.BATTERY_LEVEL_RECORD_EVENTS); final long startTimestamp = batteryLevelRecordEvents.isEmpty() ? lastFullChargeTime : batteryLevelRecordEvents.get(0).getTimestamp(); final BatteryLevelData batteryLevelData = getPeriodBatteryLevelData(context, handler, Loading
src/com/android/settings/fuelgauge/batteryusage/DatabaseUtils.java +33 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ import java.time.Duration; import java.util.ArrayList; import java.util.Calendar; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.function.Function; Loading Loading @@ -133,6 +134,9 @@ public final class DatabaseUtils { .authority(AUTHORITY) .appendPath(BATTERY_USAGE_SLOT_TABLE) .build(); /** A list of level record event types to access battery usage data. */ public static final List<BatteryEventType> BATTERY_LEVEL_RECORD_EVENTS = List.of(BatteryEventType.FULL_CHARGED, BatteryEventType.EVEN_HOUR); // For testing only. @VisibleForTesting Loading Loading @@ -408,6 +412,35 @@ public final class DatabaseUtils { }); } /** Clears all data and jobs if current timestamp is out of the range of last recorded job. */ public static void clearDataAfterTimeChangedIfNeeded(Context context) { AsyncTask.execute(() -> { try { final List<BatteryEvent> batteryLevelRecordEvents = DatabaseUtils.getBatteryEvents(context, Calendar.getInstance(), getLastFullChargeTime(context), BATTERY_LEVEL_RECORD_EVENTS); final long lastRecordTimestamp = batteryLevelRecordEvents.isEmpty() ? INVALID_TIMESTAMP : batteryLevelRecordEvents.get(0).getTimestamp(); final long nextRecordTimestamp = TimestampUtils.getNextEvenHourTimestamp(lastRecordTimestamp); final long currentTime = System.currentTimeMillis(); final boolean isOutOfTimeRange = lastRecordTimestamp == INVALID_TIMESTAMP || currentTime < lastRecordTimestamp || currentTime > nextRecordTimestamp; final String logInfo = String.format(Locale.ENGLISH, "clear database = %b, current time = %d, last record time = %d", isOutOfTimeRange, currentTime, lastRecordTimestamp); Log.d(TAG, logInfo); BatteryUsageLogUtils.writeLog(context, Action.TIME_UPDATED, logInfo); if (isOutOfTimeRange) { DatabaseUtils.clearAll(context); PeriodicJobManager.getInstance(context).refreshJob(/* fromBoot= */ false); } } catch (RuntimeException e) { Log.e(TAG, "refreshDataAndJobIfNeededAfterTimeChanged() failed", e); } }); } /** Returns the timestamp for 00:00 6 days before the calendar date. */ public static long getTimestampSixDaysAgo(Calendar calendar) { Calendar startCalendar = Loading