From 61137013376ee0bd5ddcd07343f05ca044876485 Mon Sep 17 00:00:00 2001 From: Scott Mertz Date: Thu, 12 May 2016 15:26:49 -0700 Subject: [PATCH] PerformanceManagerService: drop requests if system is not yet ready There is a race condition between when onBootPhase(PHASE_SYSTEM_SERVICES_READY) is handled and when clients request profiles, cpu boost, or launch boost. Drop these requests in this condition. OPO-702 Change-Id: I0860f824473767a4a4776e9febc7fb786b81f457 --- .../internal/PerformanceManagerService.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 9c6a44a..ba10e5e 100644 --- a/cm/lib/main/java/org/cyanogenmod/platform/internal/PerformanceManagerService.java +++ b/cm/lib/main/java/org/cyanogenmod/platform/internal/PerformanceManagerService.java @@ -180,6 +180,10 @@ public class PerformanceManagerService extends SystemService { "setPowerProfileInternal(profile=%d, fromUser=%b)", profile, fromUser)); } + if (mPm == null) { + Slog.e(TAG, "System is not ready, dropping profile request"); + return false; + } if (profile < 0 || profile > mNumProfiles) { Slog.e(TAG, "Invalid profile: " + profile); return false; @@ -248,6 +252,12 @@ public class PerformanceManagerService extends SystemService { } private void cpuBoostInternal(int duration) { + synchronized (PerformanceManagerService.this) { + if (mPm == null) { + Slog.e(TAG, "System is not ready, dropping cpu boost request"); + return; + } + } if (duration > 0 && duration <= MAX_CPU_BOOST_TIME) { // Don't send boosts if we're in another power profile if (mCurrentProfile == PerformanceManager.PROFILE_POWER_SAVE || @@ -325,6 +335,12 @@ public class PerformanceManagerService extends SystemService { @Override public void launchBoost(int pid, String packageName) { + synchronized (PerformanceManagerService.this) { + if (mPm == null) { + Slog.e(TAG, "System is not ready, dropping launch boost request"); + return; + } + } // Don't send boosts if we're in another power profile if (mCurrentProfile == PerformanceManager.PROFILE_POWER_SAVE || mCurrentProfile == PerformanceManager.PROFILE_HIGH_PERFORMANCE) {