Impl app anomlay preference
[ScreenShot]: https://screenshot.googleplex.com/BBrHTQbwbFHxZE9 Bug: 291689623 Bug: 291689643 Test: manual Change-Id: Ia257f3ace4a2d71b2221f861be3e1238de6d791e
This commit is contained in:
@@ -26,6 +26,7 @@ import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.os.LocaleList;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.BatteryTestUtils;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
@@ -83,6 +84,9 @@ public final class BatteryTipsControllerTest {
|
||||
// Check pre-defined string
|
||||
verify(mBatteryTipsCardPreference).setTitle(
|
||||
"Turn on adaptive brightness to extend battery life");
|
||||
verify(mBatteryTipsCardPreference).setIconResourceId(R.drawable.ic_battery_tips_lightbulb);
|
||||
verify(mBatteryTipsCardPreference).setMainButtonStrokeColorResourceId(
|
||||
R.color.color_accent_selector);
|
||||
verify(mBatteryTipsCardPreference).setMainButtonLabel("View Settings");
|
||||
verify(mBatteryTipsCardPreference).setDismissButtonLabel("Got it");
|
||||
// Check proto info
|
||||
@@ -103,6 +107,9 @@ public final class BatteryTipsControllerTest {
|
||||
|
||||
verify(mBatteryTipsCardPreference).setAnomalyEventId("ScreenTimeoutAnomaly");
|
||||
verify(mBatteryTipsCardPreference).setTitle("Reduce screen timeout to extend battery life");
|
||||
verify(mBatteryTipsCardPreference).setIconResourceId(R.drawable.ic_battery_tips_lightbulb);
|
||||
verify(mBatteryTipsCardPreference).setMainButtonStrokeColorResourceId(
|
||||
R.color.color_accent_selector);
|
||||
verify(mBatteryTipsCardPreference).setMainButtonLabel("View Settings");
|
||||
verify(mBatteryTipsCardPreference).setDismissButtonLabel("Got it");
|
||||
verify(mBatteryTipsCardPreference).setMainButtonLauncherInfo(
|
||||
@@ -129,6 +136,9 @@ public final class BatteryTipsControllerTest {
|
||||
|
||||
verify(mBatteryTipsCardPreference).setAnomalyEventId("ScreenTimeoutAnomaly");
|
||||
verify(mBatteryTipsCardPreference).setTitle(testTitle);
|
||||
verify(mBatteryTipsCardPreference).setIconResourceId(R.drawable.ic_battery_tips_lightbulb);
|
||||
verify(mBatteryTipsCardPreference).setMainButtonStrokeColorResourceId(
|
||||
R.color.color_accent_selector);
|
||||
verify(mBatteryTipsCardPreference).setMainButtonLabel("View Settings");
|
||||
verify(mBatteryTipsCardPreference).setDismissButtonLabel("Got it");
|
||||
verify(mBatteryTipsCardPreference).setMainButtonLauncherInfo(
|
||||
@@ -138,4 +148,27 @@ public final class BatteryTipsControllerTest {
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(
|
||||
mContext, SettingsEnums.ACTION_BATTERY_TIPS_CARD_SHOW, "ScreenTimeoutAnomaly");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleBatteryTipsCardUpdated_appAnomaly_showAnomaly() {
|
||||
PowerAnomalyEvent event = BatteryTestUtils.createAppAnomalyEvent();
|
||||
when(mFeatureFactory.powerUsageFeatureProvider.isBatteryTipsEnabled()).thenReturn(true);
|
||||
|
||||
mBatteryTipsController.handleBatteryTipsCardUpdated(event);
|
||||
|
||||
verify(mBatteryTipsCardPreference).setAnomalyEventId("AppAnomaly");
|
||||
verify(mBatteryTipsCardPreference).setTitle(
|
||||
"Chrome used more battery than usual in foreground");
|
||||
verify(mBatteryTipsCardPreference).setIconResourceId(
|
||||
R.drawable.ic_battery_tips_warning_icon);
|
||||
verify(mBatteryTipsCardPreference).setMainButtonStrokeColorResourceId(
|
||||
R.color.color_battery_anomaly_yellow_selector);
|
||||
verify(mBatteryTipsCardPreference).setMainButtonLabel("Check");
|
||||
verify(mBatteryTipsCardPreference).setDismissButtonLabel("Got it");
|
||||
verify(mBatteryTipsCardPreference).setMainButtonLauncherInfo(
|
||||
null, null, null);
|
||||
verify(mBatteryTipsCardPreference).setVisible(true);
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(
|
||||
mContext, SettingsEnums.ACTION_BATTERY_TIPS_CARD_SHOW, "AppAnomaly");
|
||||
}
|
||||
}
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user