Refactor background optimization mode in Power Usage Detail page.

[Screenshot]:
before: https://screenshot.googleplex.com/6m5jYWHofY2pFov

after:
[App battery usage]
- [normal] https://screenshot.googleplex.com/7aurWk7cHKaWds7
- [always unrestried/optimized] https://screenshot.googleplex.com/3rGAh4ccUYTKBAr

[Allow Background usage]
- [Restricted]: https://screenshot.googleplex.com/MPXjQe5kPWw2nhr
- [Optimized]: https://screenshot.googleplex.com/6w4zTT6r34APnGc
- [Unrestricted]: https://screenshot.googleplex.com/97FgvHWMrwASqYH

Bug: 302063050
Bug: 306295660
Bug: 308359833
Test: manual
Change-Id: I3237d015549fe26e62d6d68c13403cc2cbdf0017
This commit is contained in:
mxyyiyi
2023-10-09 17:23:07 +08:00
parent 5ac8a4e281
commit 81e028931a
19 changed files with 1085 additions and 400 deletions

View File

@@ -17,7 +17,6 @@
package com.android.settings.fuelgauge;
import android.content.Context;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
@@ -31,7 +30,9 @@ public class UnrestrictedPreferenceController extends AbstractPreferenceControll
private static final String TAG = "UNRESTRICTED_PREF";
@VisibleForTesting String KEY_UNRESTRICTED_PREF = "unrestricted_pref";
@VisibleForTesting
static final String KEY_UNRESTRICTED_PREF = "unrestricted_preference";
@VisibleForTesting BatteryOptimizeUtils mBatteryOptimizeUtils;
public UnrestrictedPreferenceController(Context context, int uid, String packageName) {
@@ -41,26 +42,11 @@ public class UnrestrictedPreferenceController extends AbstractPreferenceControll
@Override
public void updateState(Preference preference) {
preference.setEnabled(mBatteryOptimizeUtils.isSelectorPreferenceEnabled());
if (mBatteryOptimizeUtils.isDisabledForOptimizeModeOnly()) {
Log.d(TAG, "disable preference for " + mBatteryOptimizeUtils.getPackageName());
preference.setEnabled(false);
return;
} else {
preference.setEnabled(true);
}
if (mBatteryOptimizeUtils.getAppOptimizationMode()
== BatteryOptimizeUtils.MODE_UNRESTRICTED) {
Log.d(TAG, "is unrestricted states");
((SelectorWithWidgetPreference) preference).setChecked(true);
} else {
((SelectorWithWidgetPreference) preference).setChecked(false);
if (mBatteryOptimizeUtils.isSystemOrDefaultApp()) {
Log.d(TAG, "is system or default app, disable pref");
preference.setEnabled(false);
}
}
final boolean isUnrestricted = mBatteryOptimizeUtils.getAppOptimizationMode()
== BatteryOptimizeUtils.MODE_UNRESTRICTED;
((SelectorWithWidgetPreference) preference).setChecked(isUnrestricted);
}
@Override