sdk: Cleanup PerformanceManager

* Remove per-app profiles support
* Remove cpu boost support

Change-Id: I37e7473f8df1d08a69bc9274ae356dc1133811db
This commit is contained in:
Luca Stefani
2018-02-08 16:41:17 +01:00
parent 18337dc1da
commit 38b21a6648
8 changed files with 19 additions and 247 deletions

View File

@@ -429,7 +429,6 @@ package lineageos.power {
method public int getPowerProfile();
method public lineageos.power.PerformanceProfile getPowerProfile(int);
method public java.util.SortedSet<lineageos.power.PerformanceProfile> getPowerProfiles();
method public boolean getProfileHasAppProfiles(int);
method public boolean setPowerProfile(int);
method public boolean setPowerProfile(lineageos.power.PerformanceProfile);
field public static final java.lang.String POWER_PROFILE_CHANGED = "lineageos.power.PROFILE_CHANGED";
@@ -442,14 +441,13 @@ package lineageos.power {
}
public class PerformanceProfile implements java.lang.Comparable android.os.Parcelable {
ctor public PerformanceProfile(int, float, java.lang.String, java.lang.String, boolean);
ctor public PerformanceProfile(int, float, java.lang.String, java.lang.String);
method public int compareTo(lineageos.power.PerformanceProfile);
method public int describeContents();
method public java.lang.String getDescription();
method public int getId();
method public java.lang.String getName();
method public float getWeight();
method public boolean isBoostEnabled();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<lineageos.power.PerformanceProfile> CREATOR;
}

View File

@@ -1,5 +1,6 @@
/*
* Copyright (C) 2014 The CyanogenMod Project
* 2018 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +18,6 @@
package org.lineageos.platform.internal;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
@@ -44,21 +44,16 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.regex.Pattern;
import lineageos.app.LineageContextConstants;
import lineageos.power.IPerformanceManager;
import lineageos.power.PerformanceManagerInternal;
import lineageos.power.PerformanceProfile;
import static lineageos.power.PerformanceManager.PROFILE_BALANCED;
import static lineageos.power.PerformanceManager.PROFILE_HIGH_PERFORMANCE;
import static lineageos.power.PerformanceManager.PROFILE_POWER_SAVE;
import static lineageos.providers.LineageSettings.Secure.APP_PERFORMANCE_PROFILES_ENABLED;
import static lineageos.providers.LineageSettings.Secure.PERFORMANCE_PROFILE;
import static lineageos.providers.LineageSettings.Secure.getInt;
import static lineageos.providers.LineageSettings.Secure.getUriFor;
@@ -75,16 +70,14 @@ public class PerformanceManagerService extends LineageSystemService {
private final Context mContext;
private final LinkedHashMap<Pattern, Integer> mAppProfiles = new LinkedHashMap<>();
private final ArrayMap<Integer, PerformanceProfile> mProfiles = new ArrayMap<>();
private int mNumProfiles = 0;
private final ServiceThread mHandlerThread;
private final BoostHandler mHandler;
private final HintHandler mHandler;
// keep in sync with hardware/libhardware/include/hardware/power.h
private final int POWER_HINT_CPU_BOOST = 0x00000110;
private final int POWER_HINT_SET_PROFILE = 0x00000111;
private final int POWER_FEATURE_SUPPORTED_PROFILES = 0x00001000;
@@ -94,31 +87,20 @@ public class PerformanceManagerService extends LineageSystemService {
// Observes user-controlled settings
private PerformanceSettingsObserver mObserver;
// Max time (microseconds) to allow a CPU boost for
private static final int MAX_CPU_BOOST_TIME = 5000000;
// Standard weights
private static final float WEIGHT_POWER_SAVE = 0.0f;
private static final float WEIGHT_BALANCED = 0.5f;
private static final float WEIGHT_HIGH_PERFORMANCE = 1.0f;
// Take lock when accessing mProfiles
private final Object mLock = new Object();
// Manipulate state variables under lock
private boolean mLowPowerModeEnabled = false;
private boolean mSystemReady = false;
private boolean mBoostEnabled = true;
private int mUserProfile = -1;
private int mActiveProfile = -1;
private String mCurrentActivityName = null;
// Dumpable circular buffer for boost logging
private final BoostLog mBoostLog = new BoostLog();
private final PerformanceLog mPerformanceLog = new PerformanceLog();
// Events on the handler
private static final int MSG_CPU_BOOST = 1;
private static final int MSG_SET_PROFILE = 2;
private static final int MSG_SET_PROFILE = 1;
// PowerManager ServiceType to use when we're only
// interested in gleaning global battery saver state.
@@ -128,21 +110,6 @@ public class PerformanceManagerService extends LineageSystemService {
super(context);
mContext = context;
Resources res = context.getResources();
String[] activities = res.getStringArray(R.array.config_auto_perf_activities);
if (activities != null && activities.length > 0) {
for (int i = 0; i < activities.length; i++) {
String[] info = activities[i].split(",");
if (info.length == 2) {
mAppProfiles.put(Pattern.compile(info[0]), Integer.valueOf(info[1]));
if (DEBUG) {
Slog.d(TAG, String.format(Locale.US,"App profile #%d: %s => %s",
i, info[0], info[1]));
}
}
}
}
// We need a higher priority thread to handle these requests in front of
// everything else asynchronously
@@ -150,14 +117,11 @@ public class PerformanceManagerService extends LineageSystemService {
Process.THREAD_PRIORITY_DISPLAY, false /*allowIo*/);
mHandlerThread.start();
mHandler = new BoostHandler(mHandlerThread.getLooper());
mHandler = new HintHandler(mHandlerThread.getLooper());
}
private class PerformanceSettingsObserver extends ContentObserver {
private final Uri APP_PERFORMANCE_PROFILES_ENABLED_URI =
getUriFor(APP_PERFORMANCE_PROFILES_ENABLED);
private final Uri PERFORMANCE_PROFILE_URI =
getUriFor(PERFORMANCE_PROFILE);
@@ -170,10 +134,8 @@ public class PerformanceManagerService extends LineageSystemService {
public void observe(boolean enabled) {
if (enabled) {
mCR.registerContentObserver(APP_PERFORMANCE_PROFILES_ENABLED_URI, false, this);
mCR.registerContentObserver(PERFORMANCE_PROFILE_URI, false, this);
onChange(false);
} else {
mCR.unregisterContentObserver(this);
}
@@ -182,14 +144,8 @@ public class PerformanceManagerService extends LineageSystemService {
@Override
public void onChange(boolean selfChange) {
int profile = getInt(mCR, PERFORMANCE_PROFILE, PROFILE_BALANCED);
boolean boost = getInt(mCR, APP_PERFORMANCE_PROFILES_ENABLED, 1) == 1;
synchronized (mLock) {
if (hasProfiles() && mProfiles.containsKey(profile)) {
boost = boost && mProfiles.get(profile).isBoostEnabled();
}
mBoostEnabled = boost;
if (mUserProfile < 0) {
mUserProfile = profile;
setPowerProfileLocked(mUserProfile, false);
@@ -206,7 +162,6 @@ public class PerformanceManagerService extends LineageSystemService {
@Override
public void onStart() {
publishBinderService(LineageContextConstants.LINEAGE_PERFORMANCE_SERVICE, mBinder);
publishLocalService(PerformanceManagerInternal.class, new LocalService());
}
private void populateProfilesLocked() {
@@ -224,7 +179,7 @@ public class PerformanceManagerService extends LineageSystemService {
}
float weight = Float.valueOf(profileWeights[i]);
mProfiles.put(profileIds[i], new PerformanceProfile(profileIds[i],
weight, profileNames[i], profileDescs[i], shouldUseOptimizations(weight)));
weight, profileNames[i], profileDescs[i]));
}
}
@@ -258,10 +213,6 @@ public class PerformanceManagerService extends LineageSystemService {
return mNumProfiles > 0;
}
private boolean hasAppProfiles() {
return hasProfiles() && mBoostEnabled && mAppProfiles.size() > 0;
}
/**
* Apply a power profile and persist if fromUser = true
* <p>
@@ -325,45 +276,7 @@ public class PerformanceManagerService extends LineageSystemService {
return true;
}
private int getProfileForActivity(String componentName) {
int profile = -1;
if (componentName != null) {
for (Map.Entry<Pattern, Integer> entry : mAppProfiles.entrySet()) {
if (entry.getKey().matcher(componentName).matches()) {
profile = entry.getValue();
break;
}
}
}
if (DEBUG) {
Slog.d(TAG, "getProfileForActivity: activity=" + componentName + " profile=" + profile);
}
return profile < 0 ? mUserProfile : profile;
}
private static boolean shouldUseOptimizations(float weight) {
return weight >= (WEIGHT_BALANCED / 2) &&
weight <= (WEIGHT_BALANCED + (WEIGHT_BALANCED / 2));
}
private void cpuBoostInternal(int duration) {
if (!mSystemReady) {
Slog.e(TAG, "System is not ready, dropping cpu boost request");
return;
}
if (!mBoostEnabled) {
return;
}
if (duration > 0 && duration <= MAX_CPU_BOOST_TIME) {
mHandler.obtainMessage(MSG_CPU_BOOST, duration, 0).sendToTarget();
} else {
Slog.e(TAG, "Invalid boost duration: " + duration);
}
}
private void applyAppProfileLocked() {
private void applyProfileLocked() {
if (!hasProfiles()) {
// don't have profiles, bail.
return;
@@ -373,8 +286,6 @@ public class PerformanceManagerService extends LineageSystemService {
if (mLowPowerModeEnabled) {
// LPM always wins
profile = PROFILE_POWER_SAVE;
} else if (hasAppProfiles()) {
profile = getProfileForActivity(mCurrentActivityName);
} else {
profile = mUserProfile;
}
@@ -391,16 +302,6 @@ public class PerformanceManagerService extends LineageSystemService {
}
}
/**
* Boost the CPU
*
* @param duration Duration to boost the CPU for, in milliseconds.
*/
@Override
public void cpuBoost(int duration) {
cpuBoostInternal(duration);
}
@Override
public int getPowerProfile() {
synchronized (mLock) {
@@ -443,7 +344,6 @@ public class PerformanceManagerService extends LineageSystemService {
pw.println();
pw.println("PerformanceManager Service State:");
pw.println();
pw.println(" Boost enabled: " + mBoostEnabled);
if (!hasProfiles()) {
pw.println(" No profiles available.");
@@ -459,48 +359,17 @@ public class PerformanceManagerService extends LineageSystemService {
for (Map.Entry<Integer, PerformanceProfile> profile : mProfiles.entrySet()) {
pw.println(" " + profile.getKey() + ": " + profile.getValue().toString());
}
if (hasAppProfiles()) {
pw.println();
pw.println(" App trigger count: " + mAppProfiles.size());
}
pw.println();
mBoostLog.dump(pw);
mPerformanceLog.dump(pw);
}
}
}
};
private final class LocalService implements PerformanceManagerInternal {
@Override
public void cpuBoost(int duration) {
cpuBoostInternal(duration);
}
@Override
public void activityResumed(Intent intent) {
String activityName = null;
if (intent != null) {
final ComponentName cn = intent.getComponent();
if (cn != null) {
activityName = cn.flattenToString();
}
}
synchronized (mLock) {
mCurrentActivityName = activityName;
applyAppProfileLocked();
}
}
}
private static class BoostLog {
static final int APP_PROFILE = 0;
static final int CPU_BOOST = 1;
private static class PerformanceLog {
static final int USER_PROFILE = 2;
static final String[] EVENTS = new String[] {
"APP_PROFILE", "CPU_BOOST", "USER_PROFILE" };
static final String[] EVENTS = new String[] { "USER_PROFILE" };
private static final int LOG_BUF_SIZE = 25;
@@ -529,7 +398,7 @@ public class PerformanceManagerService extends LineageSystemService {
void dump(PrintWriter pw) {
synchronized (mBuffer) {
pw.println(" Boost log:");
pw.println("Performance log:");
for (Entry entry : mBuffer) {
pw.println(String.format(" %1$tH:%1$tM:%1$tS.%1$tL: %2$14s %3$s",
new Date(entry.timestamp), EVENTS[entry.event], entry.info));
@@ -542,23 +411,18 @@ public class PerformanceManagerService extends LineageSystemService {
/**
* Handler for asynchronous operations performed by the performance manager.
*/
private final class BoostHandler extends Handler {
private final class HintHandler extends Handler {
public BoostHandler(Looper looper) {
public HintHandler(Looper looper) {
super(looper, null, true /*async*/);
}
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MSG_CPU_BOOST:
mPm.powerHint(POWER_HINT_CPU_BOOST, msg.arg1);
mBoostLog.log(BoostLog.CPU_BOOST, "duration=" + msg.arg1);
break;
case MSG_SET_PROFILE:
mPm.powerHint(POWER_HINT_SET_PROFILE, msg.arg1);
mBoostLog.log((msg.arg2 == 1 ? BoostLog.USER_PROFILE : BoostLog.APP_PROFILE),
"profile=" + msg.arg1);
mPerformanceLog.log(PerformanceLog.USER_PROFILE, "profile=" + msg.arg1);
break;
}
}
@@ -578,7 +442,7 @@ public class PerformanceManagerService extends LineageSystemService {
Slog.d(TAG, "low power mode enabled: " + enabled);
}
mLowPowerModeEnabled = enabled;
applyAppProfileLocked();
applyProfileLocked();
}
}

View File

@@ -16,12 +16,6 @@
limitations under the License.
-->
<resources>
<!-- Automatic power profile management per app.
Each item should list the fully-qualified activity
name and the power profile id, separated by a comma. -->
<string-array name="config_auto_perf_activities" translatable="false">
</string-array>
<!-- Default value for proximity check on screen wake
NOTE ! - Enable for devices that have a fast response proximity sensor (ideally < 300ms)-->
<bool name="config_proximityCheckOnWake">false</bool>

View File

@@ -38,9 +38,6 @@
<java-symbol type="string" name="perf_profile_bias_power_summary" />
<java-symbol type="string" name="perf_profile_bias_perf_summary" />
<!-- Array of default activities with custom power management -->
<java-symbol type="array" name="config_auto_perf_activities" />
<!-- Proximity check on screen on -->
<java-symbol type="bool" name="config_proximityCheckOnWake" />

View File

@@ -21,8 +21,6 @@ import lineageos.power.PerformanceProfile;
/** @hide */
interface IPerformanceManager {
oneway void cpuBoost(int duration);
boolean setPowerProfile(int profile);
int getPowerProfile();

View File

@@ -136,23 +136,6 @@ public class PerformanceManager {
return true;
}
/**
* Boost the CPU. Boosts the cpu for the given duration in microseconds.
* Requires the {@link android.Manifest.permission#CPU_BOOST} permission.
*
* @param duration in microseconds to boost the CPU
* @hide
*/
public void cpuBoost(int duration)
{
try {
if (checkService()) {
sService.cpuBoost(duration);
}
} catch (RemoteException e) {
}
}
/**
* Returns the number of supported profiles, -1 if unsupported
* This is queried via the PowerHAL.
@@ -259,24 +242,6 @@ public class PerformanceManager {
}
return ret;
}
/**
* Check if profile has app-specific profiles
*
* Returns true if profile has app-specific profiles.
*/
public boolean getProfileHasAppProfiles(int profile) {
boolean ret = false;
if (mNumberOfProfiles > 0) {
try {
if (checkService()) {
ret = sService.getPowerProfileById(profile).isBoostEnabled();
}
} catch (RemoteException e) {
// nothing
}
}
return ret;
}
/**
* Gets a set, sorted by weight, of all supported power profiles

View File

@@ -1,27 +0,0 @@
/*
* Copyright (C) 2015 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package lineageos.power;
import android.content.Intent;
/** {@hide} */
public interface PerformanceManagerInternal {
void activityResumed(Intent intent);
void cpuBoost(int duration);
}

View File

@@ -37,15 +37,11 @@ public class PerformanceProfile implements Parcelable, Comparable<PerformancePro
private final String mDescription;
private final boolean mBoostEnabled;
public PerformanceProfile(int id, float weight, String name, String description,
boolean boostEnabled) {
public PerformanceProfile(int id, float weight, String name, String description) {
mId = id;
mWeight = weight;
mName = name;
mDescription = description;
mBoostEnabled = boostEnabled;
}
private PerformanceProfile(Parcel in) {
@@ -56,7 +52,6 @@ public class PerformanceProfile implements Parcelable, Comparable<PerformancePro
mWeight = in.readFloat();
mName = in.readString();
mDescription = in.readString();
mBoostEnabled = in.readInt() == 1;
if (parcelableVersion >= Build.LINEAGE_VERSION_CODES.GUAVA) {
// nothing yet
@@ -104,17 +99,6 @@ public class PerformanceProfile implements Parcelable, Comparable<PerformancePro
return mDescription;
}
/**
* Whether or not per-app profiles and boosting will be used when this
* profile is active. Far-end modes (powersave / high performance) do
* not use boosting.
*
* @return true if boosting and per-app optimization will be used
*/
public boolean isBoostEnabled() {
return mBoostEnabled;
}
@Override
public int describeContents() {
return 0;
@@ -128,7 +112,6 @@ public class PerformanceProfile implements Parcelable, Comparable<PerformancePro
dest.writeFloat(mWeight);
dest.writeString(mName);
dest.writeString(mDescription);
dest.writeInt(mBoostEnabled ? 1 : 0);
parcelInfo.complete();
}
@@ -170,7 +153,7 @@ public class PerformanceProfile implements Parcelable, Comparable<PerformancePro
@Override
public String toString() {
return String.format("PerformanceProfile[id=%d, weight=%f, name=%s desc=%s " +
"boostEnabled=%b]", mId, mWeight, mName, mDescription, mBoostEnabled);
return String.format("PerformanceProfile[id=%d, weight=%f, name=%s desc=%s]",
mId, mWeight, mName, mDescription);
}
}