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
This commit is contained in:
Danesh M 2016-02-12 16:54:57 -08:00 committed by Gerrit Code Review
parent 783463c739
commit 34ff00c8a4
1 changed files with 21 additions and 6 deletions

View File

@ -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);
}
};
}