Support phonetype control for Settings Battery database retention time
Bug: 404740486 Fix: 404740486 Test: atest Flag: EXEMPT bug fix Change-Id: Ifc9032e19a5b26e307d1426ea5c07de84e1613f4
This commit is contained in:
@@ -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);
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user