Fix b/264582296: Incorrect app battery usage after switching between 'restricted/unrestricted/optimized'.

This bug is due to the instance fields state is not refreshed after setAppUsageState(). When setting back to the original mode in the same page, getAppOptimizationMode(mMode, mAllowListed) still returns the original mode. So the setting back action is ignored.

Bug: 264582296
Fix: 264582296
Test: manual
Change-Id: I4da5dd7f1ca2660661f842a67b7d799aabd1ba05
This commit is contained in:
Zaiyue Xue
2023-01-12 12:08:22 +08:00
parent c9e42d4d73
commit e8f2631f25

View File

@@ -118,7 +118,7 @@ public class BatteryOptimizeUtils {
/** Sets the {@link OptimizationMode} for associated app. */ /** Sets the {@link OptimizationMode} for associated app. */
public void setAppUsageState(@OptimizationMode int mode, Action action) { public void setAppUsageState(@OptimizationMode int mode, Action action) {
if (getAppOptimizationMode(mMode, mAllowListed) == mode) { if (getAppOptimizationMode() == mode) {
Log.w(TAG, "set the same optimization mode for: " + mPackageName); Log.w(TAG, "set the same optimization mode for: " + mPackageName);
return; return;
} }