From 34ff00c8a43436f5f66eac3890a7f64e3759d1b0 Mon Sep 17 00:00:00 2001 From: Danesh M Date: Fri, 12 Feb 2016 16:54:57 -0800 Subject: [PATCH] PerformanceManager : Keep in sync with low power mode Fix edge cases such as : 1) Toggling to power save when plugged in (Should reject) 2) Plugging in to power while in power save should toggle to balanced. 3) Toggling from power save to anything else should disable low power mode (Orange system bars...etc) CYNGNOS-786 Change-Id: If6a4c08843673a6d02c38c94ed44d36230c0cb81 --- .../internal/PerformanceManagerService.java | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 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 17cf0ff..2d84e28 100644 --- a/cm/lib/main/java/org/cyanogenmod/platform/internal/PerformanceManagerService.java +++ b/cm/lib/main/java/org/cyanogenmod/platform/internal/PerformanceManagerService.java @@ -183,6 +183,20 @@ public class PerformanceManagerService extends SystemService { return false; } + boolean isProfileSame = profile == mCurrentProfile; + + if (!isProfileSame) { + if (profile == PerformanceManager.PROFILE_POWER_SAVE) { + // Handle the case where toggle power saver mode + // failed + if (!mPm.setPowerSaveMode(true)) { + return false; + } + } else if (mCurrentProfile == PerformanceManager.PROFILE_POWER_SAVE) { + mPm.setPowerSaveMode(false); + } + } + /** * It's possible that mCurrrentProfile != getUserProfile() because of a * per-app profile. Store the user's profile preference and then bail @@ -193,7 +207,7 @@ public class PerformanceManagerService extends SystemService { CMSettings.Secure.PERFORMANCE_PROFILE, profile); } - if (profile == mCurrentProfile) { + if (isProfileSame) { return false; } @@ -239,7 +253,7 @@ public class PerformanceManagerService extends SystemService { } } - private void applyProfile() { + private void applyProfile(boolean fromUser) { if (mNumProfiles < 1) { // don't have profiles, bail. return; @@ -249,6 +263,8 @@ public class PerformanceManagerService extends SystemService { if (mLowPowerModeEnabled) { // LPM always wins profile = PerformanceManager.PROFILE_POWER_SAVE; + } else if (fromUser && mCurrentProfile == PerformanceManager.PROFILE_POWER_SAVE) { + profile = PerformanceManager.PROFILE_BALANCED; } else { profile = getUserProfile(); // use app specific rules if profile is balanced @@ -256,8 +272,7 @@ public class PerformanceManagerService extends SystemService { profile = getProfileForActivity(mCurrentActivityName); } } - - setPowerProfileInternal(profile, false); + setPowerProfileInternal(profile, fromUser); } private final IBinder mBinder = new IPerformanceManager.Stub() { @@ -324,7 +339,7 @@ public class PerformanceManagerService extends SystemService { } mCurrentActivityName = activityName; - applyProfile(); + applyProfile(false); } } @@ -368,7 +383,7 @@ public class PerformanceManagerService extends SystemService { Slog.d(TAG, "low power mode enabled: " + enabled); } mLowPowerModeEnabled = enabled; - applyProfile(); + applyProfile(true); } }; }