AiCore reattribute feature

Bug: 344438848
Bug: 346706894
Test: atest SettingsRoboTests:com.android.settings.fuelgauge.batteryusage
Flag: EXEMPT bug fix
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:164e2be9380ef0df6afe7616fb0bedc8eea6f899)
Merged-In: Ifb18c2d156d11fcfdc67cff575ba800c4a6cc0fe
Change-Id: Ifb18c2d156d11fcfdc67cff575ba800c4a6cc0fe
This commit is contained in:
Zaiyue Xue
2024-07-01 16:17:14 +00:00
committed by Android Build Coastguard Worker
parent 9e96efe1ca
commit dc841cd077
17 changed files with 572 additions and 16 deletions

View File

@@ -28,6 +28,8 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
import java.util.ArrayList;
import java.util.Calendar;
@@ -78,6 +80,7 @@ public class DataProcessManager {
// Raw start timestamp with round to the nearest hour.
private final long mRawStartTimestamp;
private final long mLastFullChargeTimestamp;
private final boolean mIsFromPeriodJob;
private final Context mContext;
private final Handler mHandler;
private final UserIdsSeries mUserIdsSeries;
@@ -122,6 +125,7 @@ public class DataProcessManager {
Context context,
Handler handler,
final UserIdsSeries userIdsSeries,
final boolean isFromPeriodJob,
final long rawStartTimestamp,
final long lastFullChargeTimestamp,
@NonNull final OnBatteryDiffDataMapLoadedListener callbackFunction,
@@ -130,6 +134,7 @@ public class DataProcessManager {
mContext = context.getApplicationContext();
mHandler = handler;
mUserIdsSeries = userIdsSeries;
mIsFromPeriodJob = isFromPeriodJob;
mRawStartTimestamp = rawStartTimestamp;
mLastFullChargeTimestamp = lastFullChargeTimestamp;
mCallbackFunction = callbackFunction;
@@ -147,6 +152,7 @@ public class DataProcessManager {
mHandler = handler;
mUserIdsSeries = userIdsSeries;
mCallbackFunction = callbackFunction;
mIsFromPeriodJob = false;
mRawStartTimestamp = 0L;
mLastFullChargeTimestamp = 0L;
mHourlyBatteryLevelsPerDay = null;
@@ -158,14 +164,9 @@ public class DataProcessManager {
/** Starts the async tasks to load battery history data and app usage data. */
public void start() {
start(/* isFromPeriodJob= */ false);
}
/** Starts the async tasks to load battery history data and app usage data. */
public void start(boolean isFromPeriodJob) {
// If we have battery level data, load the battery history map and app usage simultaneously.
if (mHourlyBatteryLevelsPerDay != null) {
if (isFromPeriodJob) {
if (mIsFromPeriodJob) {
mIsCurrentBatteryHistoryLoaded = true;
mIsCurrentAppUsageLoaded = true;
mIsBatteryUsageSlotLoaded = true;
@@ -514,6 +515,14 @@ public class DataProcessManager {
mAppUsagePeriodMap,
getSystemAppsPackageNames(),
getSystemAppsUids()));
// Process the reattributate data for the following two cases:
// 1) the latest slot for the timestamp "until now"
// 2) walkthrough all BatteryDiffData again to handle "re-compute" case
final PowerUsageFeatureProvider featureProvider =
FeatureFactory.getFeatureFactory()
.getPowerUsageFeatureProvider();
featureProvider.processBatteryReattributeData(
mContext, batteryDiffDataMap, mBatteryEventList, mIsFromPeriodJob);
Log.d(
TAG,
@@ -683,12 +692,13 @@ public class DataProcessManager {
context,
handler,
userIdsSeries,
isFromPeriodJob,
startTimestamp,
lastFullChargeTime,
onBatteryDiffDataMapLoadedListener,
batteryLevelData.getHourlyBatteryLevelsPerDay(),
processedBatteryHistoryMap)
.start(isFromPeriodJob);
.start();
return batteryLevelData;
}