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

Commit bf5ea140 authored by Zaiyue Xue's avatar Zaiyue Xue Committed by Android (Google) Code Review
Browse files

Merge "Support phonetype control for Settings Battery database retention time" into main

parents 9c67a100 08a3aa7f
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -64,6 +64,9 @@ public interface PowerUsageFeatureProvider {
    /** Returns an allowlist of app names combined into the system-apps item */
    List<String> getSystemAppsAllowlist();

    /** Returns the data retention days in the database */
    int getDataRetentionDays();

    /** Check whether location setting is enabled */
    boolean isLocationSettingEnabled(String[] packages);

+5 −0
Original line number Diff line number Diff line
@@ -118,6 +118,11 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
        return new ArrayList<>();
    }

    @Override
    public int getDataRetentionDays() {
        return 9;
    }

    @Override
    public boolean isLocationSettingEnabled(String[] packages) {
        return false;
+5 −2
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import com.android.settings.fuelgauge.BatteryUsageHistoricalLogEntry.Action;
import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.fuelgauge.batteryusage.bugreport.BatteryUsageLogUtils;
import com.android.settings.fuelgauge.batteryusage.db.BatteryStateDatabase;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.fuelgauge.BatteryStatus;

import java.io.PrintWriter;
@@ -67,7 +68,6 @@ public final class DatabaseUtils {
    private static final String SHARED_PREFS_FILE = "battery_usage_shared_prefs";
    private static final long INVALID_TIMESTAMP = 0L;

    static final int DATA_RETENTION_INTERVAL_DAY = 9;
    static final String KEY_LAST_LOAD_FULL_CHARGE_TIME = "last_load_full_charge_time";
    static final String KEY_LAST_UPLOAD_FULL_CHARGE_TIME = "last_upload_full_charge_time";
    static final String KEY_LAST_USAGE_SOURCE = "last_usage_source";
@@ -468,11 +468,14 @@ public final class DatabaseUtils {
        AsyncTask.execute(
                () -> {
                    try {
                        final int dataRetentionDays =
                                FeatureFactory.getFeatureFactory()
                                        .getPowerUsageFeatureProvider().getDataRetentionDays();
                        final BatteryStateDatabase database =
                                BatteryStateDatabase.getInstance(context.getApplicationContext());
                        final long earliestTimestamp =
                                Clock.systemUTC().millis()
                                        - Duration.ofDays(DATA_RETENTION_INTERVAL_DAY).toMillis();
                                        - Duration.ofDays(dataRetentionDays).toMillis();
                        database.appUsageEventDao().clearAllBefore(earliestTimestamp);
                        database.batteryEventDao().clearAllBefore(earliestTimestamp);
                        database.batteryStateDao().clearAllBefore(earliestTimestamp);
+7 −2
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import androidx.test.core.app.ApplicationProvider;

import com.android.settings.fuelgauge.batteryusage.db.BatteryStateDao;
import com.android.settings.fuelgauge.batteryusage.db.BatteryStateDatabase;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.testutils.BatteryTestUtils;

import org.junit.After;
@@ -104,7 +105,9 @@ public final class PeriodicJobReceiverTest {
    @Test
    public void onReceive_containsExpiredData_clearsExpiredDataFromDatabase()
            throws InterruptedException {
        insertExpiredData(/* shiftDay= */ DatabaseUtils.DATA_RETENTION_INTERVAL_DAY);
        int dataRetentionDays = FeatureFactory.getFeatureFactory()
                .getPowerUsageFeatureProvider().getDataRetentionDays();
        insertExpiredData(/* shiftDay= */ dataRetentionDays);

        mReceiver.onReceive(mContext, JOB_UPDATE_INTENT);

@@ -115,7 +118,9 @@ public final class PeriodicJobReceiverTest {
    @Test
    public void onReceive_withoutExpiredData_notClearsExpiredDataFromDatabase()
            throws InterruptedException {
        insertExpiredData(/* shiftDay= */ DatabaseUtils.DATA_RETENTION_INTERVAL_DAY - 1);
        int dataRetentionDays = FeatureFactory.getFeatureFactory()
                .getPowerUsageFeatureProvider().getDataRetentionDays();
        insertExpiredData(dataRetentionDays - 1);

        mReceiver.onReceive(mContext, JOB_UPDATE_INTENT);