Impl app anomlay preference

[ScreenShot]: https://screenshot.googleplex.com/BBrHTQbwbFHxZE9

Bug: 291689623
Bug: 291689643
Test: manual
Change-Id: Ia257f3ace4a2d71b2221f861be3e1238de6d791e
This commit is contained in:
mxyyiyi
2023-08-11 21:13:38 +08:00
committed by Wesley Wang
parent 6c70c5ecfd
commit c4fb17d740
10 changed files with 220 additions and 27 deletions

View File

@@ -39,6 +39,7 @@ import com.android.settings.fuelgauge.batteryusage.PowerAnomalyEventList;
import com.android.settings.fuelgauge.batteryusage.PowerAnomalyKey;
import com.android.settings.fuelgauge.batteryusage.PowerAnomalyType;
import com.android.settings.fuelgauge.batteryusage.WarningBannerInfo;
import com.android.settings.fuelgauge.batteryusage.WarningItemInfo;
import com.android.settings.fuelgauge.batteryusage.db.AppUsageEventDao;
import com.android.settings.fuelgauge.batteryusage.db.AppUsageEventEntity;
import com.android.settings.fuelgauge.batteryusage.db.BatteryState;
@@ -70,14 +71,18 @@ public class BatteryTestUtils {
BatteryManager.BATTERY_STATUS_DISCHARGING);
}
/** Sets the work profile mode. */
/**
* Sets the work profile mode.
*/
public static void setWorkProfile(Context context) {
final UserManager userManager = context.getSystemService(UserManager.class);
Shadows.shadowOf(userManager).setManagedProfile(true);
Shadows.shadowOf(userManager).setIsSystemUser(false);
}
/** Creates and sets up the in-memory {@link BatteryStateDatabase}. */
/**
* Creates and sets up the in-memory {@link BatteryStateDatabase}.
*/
public static BatteryStateDatabase setUpBatteryStateDatabase(Context context) {
final BatteryStateDatabase inMemoryDatabase =
Room.inMemoryDatabaseBuilder(context, BatteryStateDatabase.class)
@@ -87,21 +92,27 @@ public class BatteryTestUtils {
return inMemoryDatabase;
}
/** Inserts a fake data into the database for testing. */
/**
* Inserts a fake data into the database for testing.
*/
public static void insertDataToBatteryStateTable(
Context context, long timestamp, String packageName) {
insertDataToBatteryStateTable(
context, timestamp, packageName, /*multiple=*/ false, /*isFullChargeStart=*/ false);
}
/** Inserts a fake data into the database for testing. */
/**
* Inserts a fake data into the database for testing.
*/
public static void insertDataToBatteryStateTable(
Context context, long timestamp, String packageName, boolean isFullChargeStart) {
insertDataToBatteryStateTable(
context, timestamp, packageName, /*multiple=*/ false, isFullChargeStart);
}
/** Inserts a fake data into the database for testing. */
/**
* Inserts a fake data into the database for testing.
*/
public static void insertDataToBatteryStateTable(
Context context, long timestamp, String packageName, boolean multiple,
boolean isFullChargeStart) {
@@ -151,14 +162,18 @@ public class BatteryTestUtils {
}
}
/** Inserts a fake data into the database for testing. */
/**
* Inserts a fake data into the database for testing.
*/
public static void insertDataToAppUsageEventTable(
Context context, long userId, long timestamp, String packageName) {
insertDataToAppUsageEventTable(
context, userId, timestamp, packageName, /*multiple=*/ false);
}
/** Inserts a fake data into the database for testing. */
/**
* Inserts a fake data into the database for testing.
*/
public static void insertDataToAppUsageEventTable(
Context context, long userId, long timestamp, String packageName, boolean multiple) {
final AppUsageEventEntity entity =
@@ -179,7 +194,9 @@ public class BatteryTestUtils {
}
}
/** Gets customized battery changed intent. */
/**
* Gets customized battery changed intent.
*/
public static Intent getCustomBatteryIntent(int plugged, int level, int scale, int status) {
Intent intent = new Intent();
intent.putExtra(BatteryManager.EXTRA_PLUGGED, plugged);
@@ -190,7 +207,9 @@ public class BatteryTestUtils {
return intent;
}
/** Configures the incompatible charger environment. */
/**
* Configures the incompatible charger environment.
*/
public static void setupIncompatibleEvent(
UsbPort mockUsbPort, UsbManager mockUsbManager, UsbPortStatus mockUsbPortStatus) {
final List<UsbPort> usbPorts = new ArrayList<>();
@@ -203,12 +222,16 @@ public class BatteryTestUtils {
.thenReturn(new int[]{UsbPortStatus.COMPLIANCE_WARNING_OTHER});
}
/** Create an empty power anomaly event list proto. */
/**
* Create an empty power anomaly event list proto.
*/
public static PowerAnomalyEventList createEmptyPowerAnomalyEventList() {
return PowerAnomalyEventList.getDefaultInstance();
}
/** Create an non-empty power anomaly event list proto. */
/**
* Create an non-empty power anomaly event list proto.
*/
public static PowerAnomalyEventList createNonEmptyPowerAnomalyEventList() {
return PowerAnomalyEventList.newBuilder()
.addPowerAnomalyEvents(0, createAdaptiveBrightnessAnomalyEvent())
@@ -216,7 +239,9 @@ public class BatteryTestUtils {
.build();
}
/** Create a power anomaly event proto of adaptive brightness. */
/**
* Create a power anomaly event proto of adaptive brightness.
*/
public static PowerAnomalyEvent createAdaptiveBrightnessAnomalyEvent() {
return PowerAnomalyEvent.newBuilder()
.setEventId("BrightnessAnomaly")
@@ -231,7 +256,9 @@ public class BatteryTestUtils {
.build();
}
/** Create a power anomaly event proto of screen timeout. */
/**
* Create a power anomaly event proto of screen timeout.
*/
public static PowerAnomalyEvent createScreenTimeoutAnomalyEvent() {
return PowerAnomalyEvent.newBuilder()
.setEventId("ScreenTimeoutAnomaly")
@@ -245,4 +272,21 @@ public class BatteryTestUtils {
.build())
.build();
}
/**
* Create a power anomaly event proto of app anomaly.
*/
public static PowerAnomalyEvent createAppAnomalyEvent() {
return PowerAnomalyEvent.newBuilder()
.setEventId("AppAnomaly")
.setType(PowerAnomalyType.TYPE_APPS_ITEM)
.setKey(PowerAnomalyKey.KEY_APP)
.setScore(2.0f)
.setWarningItemInfo(WarningItemInfo.newBuilder()
.setTitleString("Chrome used more battery than usual in foreground")
.setMainButtonString("Check")
.setCancelButtonString("Got it")
.build())
.build();
}
}