[B&R] backup the battery optimization mode for installed apps

BYPASS_INCLUSIVE_LANGUAGE_REASON=legacy method name

Test command for backup manager:
adb shell bmgr backupnow com.android.settings
adb shell dumpsys backup | grep Current

Bug: 192523697
Test: make SettingsRoboTests
Change-Id: I4671e48a9d3b315362b451384db637d5cae36a4d
This commit is contained in:
ykhung
2021-08-20 17:32:47 +08:00
parent 5d59c685d7
commit 37ddf4bc3e
3 changed files with 219 additions and 24 deletions

View File

@@ -59,20 +59,25 @@ public class BatteryOptimizeUtils {
mAllowListed = mPowerAllowListBackend.isAllowlisted(mPackageName);
}
public AppUsageState getAppUsageState() {
refreshState();
if (!mAllowListed && mMode == AppOpsManager.MODE_IGNORED) {
/** Gets the {@link AppUsageState} based on mode and allowed list. */
public static AppUsageState getAppUsageState(int mode, boolean isAllowListed) {
if (!isAllowListed && mode == AppOpsManager.MODE_IGNORED) {
return AppUsageState.RESTRICTED;
} else if (mAllowListed && mMode == AppOpsManager.MODE_ALLOWED) {
} else if (isAllowListed && mode == AppOpsManager.MODE_ALLOWED) {
return AppUsageState.UNRESTRICTED;
} else if (!mAllowListed && mMode == AppOpsManager.MODE_ALLOWED) {
} else if (!isAllowListed && mode == AppOpsManager.MODE_ALLOWED) {
return AppUsageState.OPTIMIZED;
} else {
Log.d(TAG, "get unknown app usage state.");
return AppUsageState.UNKNOWN;
}
}
/** Gets the current {@link AppUsageState}. */
public AppUsageState getAppUsageState() {
refreshState();
return getAppUsageState(mMode, mAllowListed);
}
public void setAppUsageState(AppUsageState state) {
switch (state) {
case RESTRICTED: