Merge "Impl app anomlay preference" into udc-qpr-dev am: c51a3da148 am: 428b124bea

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/24404174

Change-Id: I147d8496db00a770d8de45229813ae146e1e87cb
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Xinyi Mao
2023-09-01 09:54:53 +00:00
committed by Automerger Merge Worker
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();
}
}