Generate app and device screen-on time data and return back to UI for
rendering. Test: make RunSettingsRoboTests + manually Bug: 260964903 Change-Id: I2fd69b4686cc2e1413ad0eb43c07b6164e411411
This commit is contained in:
@@ -330,9 +330,9 @@ public class DataProcessManager {
|
||||
}
|
||||
|
||||
private void loadAndApplyBatteryMapFromServiceOnly() {
|
||||
new AsyncTask<Void, Void, Map<Integer, Map<Integer, BatteryDiffData>>>() {
|
||||
new AsyncTask<Void, Void, BatteryCallbackData>() {
|
||||
@Override
|
||||
protected Map<Integer, Map<Integer, BatteryDiffData>> doInBackground(Void... voids) {
|
||||
protected BatteryCallbackData doInBackground(Void... voids) {
|
||||
final long startTime = System.currentTimeMillis();
|
||||
final Map<Integer, Map<Integer, BatteryDiffData>> batteryUsageMap =
|
||||
DataProcessor.getBatteryUsageMapFromStatsService(mContext);
|
||||
@@ -340,18 +340,18 @@ public class DataProcessManager {
|
||||
Log.d(TAG, String.format(
|
||||
"execute loadAndApplyBatteryMapFromServiceOnly size=%d in %d/ms",
|
||||
batteryUsageMap.size(), (System.currentTimeMillis() - startTime)));
|
||||
return batteryUsageMap;
|
||||
return new BatteryCallbackData(batteryUsageMap, /*deviceScreenOnTime=*/ null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(
|
||||
final Map<Integer, Map<Integer, BatteryDiffData>> batteryUsageMap) {
|
||||
final BatteryCallbackData batteryCallbackData) {
|
||||
// Set the unused variables to null.
|
||||
mContext = null;
|
||||
// Post results back to main thread to refresh UI.
|
||||
if (mHandler != null && mCallbackFunction != null) {
|
||||
mHandler.post(() -> {
|
||||
mCallbackFunction.onBatteryUsageMapLoaded(batteryUsageMap);
|
||||
mCallbackFunction.onBatteryCallbackDataLoaded(batteryCallbackData);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -391,12 +391,36 @@ public class DataProcessManager {
|
||||
}
|
||||
|
||||
private void generateFinalDataAndApplyCallback() {
|
||||
// TODO: generate the final data including battery usage map and device screen-on time and
|
||||
// then apply the callback function.
|
||||
// Set the unused variables to null.
|
||||
mContext = null;
|
||||
mHourlyBatteryLevelsPerDay = null;
|
||||
mBatteryHistoryMap = null;
|
||||
new AsyncTask<Void, Void, BatteryCallbackData>() {
|
||||
@Override
|
||||
protected BatteryCallbackData doInBackground(Void... voids) {
|
||||
final long startTime = System.currentTimeMillis();
|
||||
final Map<Integer, Map<Integer, BatteryDiffData>> batteryUsageMap =
|
||||
DataProcessor.getBatteryUsageMap(
|
||||
mContext, mHourlyBatteryLevelsPerDay, mBatteryHistoryMap,
|
||||
mAppUsagePeriodMap);
|
||||
final Map<Integer, Map<Integer, Long>> deviceScreenOnTime =
|
||||
DataProcessor.getDeviceScreenOnTime(mAppUsagePeriodMap);
|
||||
DataProcessor.loadLabelAndIcon(batteryUsageMap);
|
||||
Log.d(TAG, String.format("execute generateFinalDataAndApplyCallback in %d/ms",
|
||||
(System.currentTimeMillis() - startTime)));
|
||||
return new BatteryCallbackData(batteryUsageMap, deviceScreenOnTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(final BatteryCallbackData batteryCallbackData) {
|
||||
// Set the unused variables to null.
|
||||
mContext = null;
|
||||
mHourlyBatteryLevelsPerDay = null;
|
||||
mBatteryHistoryMap = null;
|
||||
// Post results back to main thread to refresh UI.
|
||||
if (mHandler != null && mCallbackFunction != null) {
|
||||
mHandler.post(() -> {
|
||||
mCallbackFunction.onBatteryCallbackDataLoaded(batteryCallbackData);
|
||||
});
|
||||
}
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
// Whether we should load app usage data from service or database.
|
||||
@@ -465,15 +489,13 @@ public class DataProcessManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO: replace the task below with new DataProcessManager(...).start() after
|
||||
// DataProcessManager is completed;
|
||||
// Start the async task to compute diff usage data and load labels and icons.
|
||||
new DataProcessor.ComputeUsageMapAndLoadItemsTask(
|
||||
new DataProcessManager(
|
||||
context,
|
||||
handler,
|
||||
asyncResponseDelegate,
|
||||
batteryLevelData.getHourlyBatteryLevelsPerDay(),
|
||||
processedBatteryHistoryMap).execute();
|
||||
processedBatteryHistoryMap).start();
|
||||
|
||||
return batteryLevelData;
|
||||
}
|
||||
|
Reference in New Issue
Block a user