Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ad1fa9b0 authored by YK Hung's avatar YK Hung Committed by Android (Google) Code Review
Browse files

Merge "Reattribute data into other apps as the final result (4/5)" into main

parents 832c751e bc93a6a1
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import android.os.Bundle;
import android.util.ArrayMap;
import android.util.SparseIntArray;

import androidx.annotation.NonNull;

import com.android.settings.fuelgauge.batteryusage.BatteryDiffData;
import com.android.settings.fuelgauge.batteryusage.DetectRequestSourceType;
import com.android.settings.fuelgauge.batteryusage.PowerAnomalyEventList;
@@ -162,5 +164,7 @@ public interface PowerUsageFeatureProvider {

    /** Collect and process battery reattribute data if needed. */
    boolean processBatteryReattributeData(
            Context context, Map<Long, BatteryDiffData> batteryDiffDataMap);
            @NonNull Context context,
            @NonNull Map<Long, BatteryDiffData> batteryDiffDataMap,
            final boolean isFromPeriodJob);
}
+5 −1
Original line number Diff line number Diff line
@@ -27,6 +27,8 @@ import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.SparseIntArray;

import androidx.annotation.NonNull;

import com.android.internal.util.ArrayUtils;
import com.android.settings.fuelgauge.batteryusage.BatteryDiffData;
import com.android.settings.fuelgauge.batteryusage.DetectRequestSourceType;
@@ -250,7 +252,9 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider

    @Override
    public boolean processBatteryReattributeData(
            Context context, Map<Long, BatteryDiffData> batteryDiffDataMap) {
            @NonNull Context context,
            @NonNull Map<Long, BatteryDiffData> batteryDiffDataMap,
            final boolean isFromPeriodJob) {
        return false;
    }
}
+0 −3
Original line number Diff line number Diff line
@@ -128,9 +128,6 @@ public final class BatteryUsageDataLoader {
                            final PowerUsageFeatureProvider featureProvider =
                                    FeatureFactory.getFeatureFactory()
                                            .getPowerUsageFeatureProvider();
                            // Collect and process battery reattribute data.
                            featureProvider.processBatteryReattributeData(
                                    context, batteryDiffDataMap);
                            DatabaseUtils.sendBatteryUsageSlotData(
                                    context,
                                    ConvertUtils.convertToBatteryUsageSlotList(
+17 −7
Original line number Diff line number Diff line
@@ -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, 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;
    }
+2 −0
Original line number Diff line number Diff line
@@ -112,6 +112,7 @@ public final class DataProcessManagerTest {
                        mContext,
                        /* handler= */ null,
                        mUserIdsSeries,
                        /* isFromPeriodJob= */ false,
                        /* rawStartTimestamp= */ 0L,
                        /* lastFullChargeTimestamp= */ 0L,
                        /* callbackFunction= */ null,
@@ -258,6 +259,7 @@ public final class DataProcessManagerTest {
                        mContext,
                        /* handler= */ null,
                        mUserIdsSeries,
                        /* isFromPeriodJob= */ false,
                        /* rawStartTimestamp= */ 2L,
                        /* lastFullChargeTimestamp= */ 1L,
                        /* callbackFunction= */ null,