Reattribute data into other apps as the final result (4/5)
Bug: 346706894 Test: atest SettingsRoboTests:com.android.settings.fuelgauge.batteryusage Flag: EXEMPT bug fix Change-Id: I8b8a988df2718b64cd752915205db687ffe9d559
This commit is contained in:
@@ -23,6 +23,8 @@ import android.os.Bundle;
|
|||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
import android.util.SparseIntArray;
|
import android.util.SparseIntArray;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.android.settings.fuelgauge.batteryusage.BatteryDiffData;
|
import com.android.settings.fuelgauge.batteryusage.BatteryDiffData;
|
||||||
import com.android.settings.fuelgauge.batteryusage.DetectRequestSourceType;
|
import com.android.settings.fuelgauge.batteryusage.DetectRequestSourceType;
|
||||||
import com.android.settings.fuelgauge.batteryusage.PowerAnomalyEventList;
|
import com.android.settings.fuelgauge.batteryusage.PowerAnomalyEventList;
|
||||||
@@ -162,5 +164,7 @@ public interface PowerUsageFeatureProvider {
|
|||||||
|
|
||||||
/** Collect and process battery reattribute data if needed. */
|
/** Collect and process battery reattribute data if needed. */
|
||||||
boolean processBatteryReattributeData(
|
boolean processBatteryReattributeData(
|
||||||
Context context, Map<Long, BatteryDiffData> batteryDiffDataMap);
|
@NonNull Context context,
|
||||||
|
@NonNull Map<Long, BatteryDiffData> batteryDiffDataMap,
|
||||||
|
final boolean isFromPeriodJob);
|
||||||
}
|
}
|
||||||
|
@@ -27,6 +27,8 @@ import android.util.ArrayMap;
|
|||||||
import android.util.ArraySet;
|
import android.util.ArraySet;
|
||||||
import android.util.SparseIntArray;
|
import android.util.SparseIntArray;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.android.internal.util.ArrayUtils;
|
import com.android.internal.util.ArrayUtils;
|
||||||
import com.android.settings.fuelgauge.batteryusage.BatteryDiffData;
|
import com.android.settings.fuelgauge.batteryusage.BatteryDiffData;
|
||||||
import com.android.settings.fuelgauge.batteryusage.DetectRequestSourceType;
|
import com.android.settings.fuelgauge.batteryusage.DetectRequestSourceType;
|
||||||
@@ -250,7 +252,9 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean processBatteryReattributeData(
|
public boolean processBatteryReattributeData(
|
||||||
Context context, Map<Long, BatteryDiffData> batteryDiffDataMap) {
|
@NonNull Context context,
|
||||||
|
@NonNull Map<Long, BatteryDiffData> batteryDiffDataMap,
|
||||||
|
final boolean isFromPeriodJob) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -128,9 +128,6 @@ public final class BatteryUsageDataLoader {
|
|||||||
final PowerUsageFeatureProvider featureProvider =
|
final PowerUsageFeatureProvider featureProvider =
|
||||||
FeatureFactory.getFeatureFactory()
|
FeatureFactory.getFeatureFactory()
|
||||||
.getPowerUsageFeatureProvider();
|
.getPowerUsageFeatureProvider();
|
||||||
// Collect and process battery reattribute data.
|
|
||||||
featureProvider.processBatteryReattributeData(
|
|
||||||
context, batteryDiffDataMap);
|
|
||||||
DatabaseUtils.sendBatteryUsageSlotData(
|
DatabaseUtils.sendBatteryUsageSlotData(
|
||||||
context,
|
context,
|
||||||
ConvertUtils.convertToBatteryUsageSlotList(
|
ConvertUtils.convertToBatteryUsageSlotList(
|
||||||
|
@@ -28,6 +28,8 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
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.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
@@ -78,6 +80,7 @@ public class DataProcessManager {
|
|||||||
// Raw start timestamp with round to the nearest hour.
|
// Raw start timestamp with round to the nearest hour.
|
||||||
private final long mRawStartTimestamp;
|
private final long mRawStartTimestamp;
|
||||||
private final long mLastFullChargeTimestamp;
|
private final long mLastFullChargeTimestamp;
|
||||||
|
private final boolean mIsFromPeriodJob;
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final Handler mHandler;
|
private final Handler mHandler;
|
||||||
private final UserIdsSeries mUserIdsSeries;
|
private final UserIdsSeries mUserIdsSeries;
|
||||||
@@ -122,6 +125,7 @@ public class DataProcessManager {
|
|||||||
Context context,
|
Context context,
|
||||||
Handler handler,
|
Handler handler,
|
||||||
final UserIdsSeries userIdsSeries,
|
final UserIdsSeries userIdsSeries,
|
||||||
|
final boolean isFromPeriodJob,
|
||||||
final long rawStartTimestamp,
|
final long rawStartTimestamp,
|
||||||
final long lastFullChargeTimestamp,
|
final long lastFullChargeTimestamp,
|
||||||
@NonNull final OnBatteryDiffDataMapLoadedListener callbackFunction,
|
@NonNull final OnBatteryDiffDataMapLoadedListener callbackFunction,
|
||||||
@@ -130,6 +134,7 @@ public class DataProcessManager {
|
|||||||
mContext = context.getApplicationContext();
|
mContext = context.getApplicationContext();
|
||||||
mHandler = handler;
|
mHandler = handler;
|
||||||
mUserIdsSeries = userIdsSeries;
|
mUserIdsSeries = userIdsSeries;
|
||||||
|
mIsFromPeriodJob = isFromPeriodJob;
|
||||||
mRawStartTimestamp = rawStartTimestamp;
|
mRawStartTimestamp = rawStartTimestamp;
|
||||||
mLastFullChargeTimestamp = lastFullChargeTimestamp;
|
mLastFullChargeTimestamp = lastFullChargeTimestamp;
|
||||||
mCallbackFunction = callbackFunction;
|
mCallbackFunction = callbackFunction;
|
||||||
@@ -147,6 +152,7 @@ public class DataProcessManager {
|
|||||||
mHandler = handler;
|
mHandler = handler;
|
||||||
mUserIdsSeries = userIdsSeries;
|
mUserIdsSeries = userIdsSeries;
|
||||||
mCallbackFunction = callbackFunction;
|
mCallbackFunction = callbackFunction;
|
||||||
|
mIsFromPeriodJob = false;
|
||||||
mRawStartTimestamp = 0L;
|
mRawStartTimestamp = 0L;
|
||||||
mLastFullChargeTimestamp = 0L;
|
mLastFullChargeTimestamp = 0L;
|
||||||
mHourlyBatteryLevelsPerDay = null;
|
mHourlyBatteryLevelsPerDay = null;
|
||||||
@@ -158,14 +164,9 @@ public class DataProcessManager {
|
|||||||
|
|
||||||
/** Starts the async tasks to load battery history data and app usage data. */
|
/** Starts the async tasks to load battery history data and app usage data. */
|
||||||
public void start() {
|
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 we have battery level data, load the battery history map and app usage simultaneously.
|
||||||
if (mHourlyBatteryLevelsPerDay != null) {
|
if (mHourlyBatteryLevelsPerDay != null) {
|
||||||
if (isFromPeriodJob) {
|
if (mIsFromPeriodJob) {
|
||||||
mIsCurrentBatteryHistoryLoaded = true;
|
mIsCurrentBatteryHistoryLoaded = true;
|
||||||
mIsCurrentAppUsageLoaded = true;
|
mIsCurrentAppUsageLoaded = true;
|
||||||
mIsBatteryUsageSlotLoaded = true;
|
mIsBatteryUsageSlotLoaded = true;
|
||||||
@@ -514,6 +515,14 @@ public class DataProcessManager {
|
|||||||
mAppUsagePeriodMap,
|
mAppUsagePeriodMap,
|
||||||
getSystemAppsPackageNames(),
|
getSystemAppsPackageNames(),
|
||||||
getSystemAppsUids()));
|
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, mIsFromPeriodJob);
|
||||||
|
|
||||||
Log.d(
|
Log.d(
|
||||||
TAG,
|
TAG,
|
||||||
@@ -683,12 +692,13 @@ public class DataProcessManager {
|
|||||||
context,
|
context,
|
||||||
handler,
|
handler,
|
||||||
userIdsSeries,
|
userIdsSeries,
|
||||||
|
isFromPeriodJob,
|
||||||
startTimestamp,
|
startTimestamp,
|
||||||
lastFullChargeTime,
|
lastFullChargeTime,
|
||||||
onBatteryDiffDataMapLoadedListener,
|
onBatteryDiffDataMapLoadedListener,
|
||||||
batteryLevelData.getHourlyBatteryLevelsPerDay(),
|
batteryLevelData.getHourlyBatteryLevelsPerDay(),
|
||||||
processedBatteryHistoryMap)
|
processedBatteryHistoryMap)
|
||||||
.start(isFromPeriodJob);
|
.start();
|
||||||
|
|
||||||
return batteryLevelData;
|
return batteryLevelData;
|
||||||
}
|
}
|
||||||
|
@@ -112,6 +112,7 @@ public final class DataProcessManagerTest {
|
|||||||
mContext,
|
mContext,
|
||||||
/* handler= */ null,
|
/* handler= */ null,
|
||||||
mUserIdsSeries,
|
mUserIdsSeries,
|
||||||
|
/* isFromPeriodJob= */ false,
|
||||||
/* rawStartTimestamp= */ 0L,
|
/* rawStartTimestamp= */ 0L,
|
||||||
/* lastFullChargeTimestamp= */ 0L,
|
/* lastFullChargeTimestamp= */ 0L,
|
||||||
/* callbackFunction= */ null,
|
/* callbackFunction= */ null,
|
||||||
@@ -258,6 +259,7 @@ public final class DataProcessManagerTest {
|
|||||||
mContext,
|
mContext,
|
||||||
/* handler= */ null,
|
/* handler= */ null,
|
||||||
mUserIdsSeries,
|
mUserIdsSeries,
|
||||||
|
/* isFromPeriodJob= */ false,
|
||||||
/* rawStartTimestamp= */ 2L,
|
/* rawStartTimestamp= */ 2L,
|
||||||
/* lastFullChargeTimestamp= */ 1L,
|
/* lastFullChargeTimestamp= */ 1L,
|
||||||
/* callbackFunction= */ null,
|
/* callbackFunction= */ null,
|
||||||
|
Reference in New Issue
Block a user