From 4b14ba4d1829f4a6855dfebc8948905dc90d99f3 Mon Sep 17 00:00:00 2001 From: Gabriele M Date: Mon, 6 Mar 2017 22:07:04 +0100 Subject: [PATCH] PerformanceManager: Don't override the user preference The current code can override the user preference in different ways. For instance, entering and exiting the powersaving mode will set the balanced profile, no matter what was the user preference. mUserProfile is now updated only when the user changes the profile and not when the profile is changed automatically (e.g. when enetering the powersaving mode). When mUserProfile is updated, the value in the database is also updated, except when initialized. This also includes the case in which the powersave mode is enabled. Change-Id: Id88e64389ccb877ebee665d90bf081aa94537542 --- .../internal/PerformanceManagerService.java | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/cm/lib/main/java/org/cyanogenmod/platform/internal/PerformanceManagerService.java b/cm/lib/main/java/org/cyanogenmod/platform/internal/PerformanceManagerService.java index f3b1cb6f..378050e3 100644 --- a/cm/lib/main/java/org/cyanogenmod/platform/internal/PerformanceManagerService.java +++ b/cm/lib/main/java/org/cyanogenmod/platform/internal/PerformanceManagerService.java @@ -186,6 +186,7 @@ public class PerformanceManagerService extends CMSystemService { mBoostEnabled = boost; if (mUserProfile < 0) { mUserProfile = profile; + setPowerProfileLocked(mUserProfile, false); } } } @@ -238,13 +239,7 @@ public class PerformanceManagerService extends CMSystemService { mSystemReady = true; if (hasProfiles()) { - if (mUserProfile == PROFILE_HIGH_PERFORMANCE) { - Slog.w(TAG, "Reverting profile HIGH_PERFORMANCE to BALANCED"); - setPowerProfileLocked(PROFILE_BALANCED, true); - } else { - setPowerProfileLocked(mUserProfile, true); - } - + setPowerProfileLocked(mUserProfile, false); mPm.registerLowPowerModeObserver(mLowPowerModeListener); mContext.registerReceiver(mLocaleChangedReceiver, new IntentFilter(Intent.ACTION_LOCALE_CHANGED)); @@ -362,7 +357,7 @@ public class PerformanceManagerService extends CMSystemService { } } - private void applyAppProfileLocked(boolean fromUser) { + private void applyAppProfileLocked() { if (!hasProfiles()) { // don't have profiles, bail. return; @@ -372,16 +367,13 @@ public class PerformanceManagerService extends CMSystemService { if (mLowPowerModeEnabled) { // LPM always wins profile = PROFILE_POWER_SAVE; - } else if (fromUser && mActiveProfile == PROFILE_POWER_SAVE) { - // leaving LPM - profile = PROFILE_BALANCED; } else if (hasAppProfiles()) { profile = getProfileForActivity(mCurrentActivityName); } else { profile = mUserProfile; } - setPowerProfileLocked(profile, fromUser); + setPowerProfileLocked(profile, false); } private final IBinder mBinder = new IPerformanceManager.Stub() { @@ -491,7 +483,7 @@ public class PerformanceManagerService extends CMSystemService { synchronized (mLock) { mCurrentActivityName = activityName; - applyAppProfileLocked(false); + applyAppProfileLocked(); } } } @@ -579,7 +571,7 @@ public class PerformanceManagerService extends CMSystemService { Slog.d(TAG, "low power mode enabled: " + enabled); } mLowPowerModeEnabled = enabled; - applyAppProfileLocked(true); + applyAppProfileLocked(); } } };