Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7695fad9 authored by Steve Kondik's avatar Steve Kondik
Browse files

perf: Improve performance profiles

 * Performance Profiles is going to grow into a much more powerful
   feature which can apply advanced optimizations or power saving
   techniques depending on both the state of the hardware as well
   as the current applications in use.
 * Refactor the original code and move it into PowerManager so
   that it's managed from the same place.
 * Implement "automatic performance profiles". This feature will
   automatically select a profile when specific activities are
   running. Currently this list is static and engages performance
   mode for several benchmarks (trollface).
 * Added support for a new power hint, POWER_HINT_SET_PROFILE.
   Currently, these profiles are fired using a property trigger
   in init. This is easy, but the PowerHAL can do more.
 * Moved the setting to Settings.Secure and also wrapped calls
   to the service in the DEVICE_POWER permission. Nobody should
   mess with this stuff except the system.

TODO:
 * Allow user configuration per-app.
 * Implement an advanced power-saving mode.

Change-Id: I140ebc0648c4cf05900e005923247c3180be8c93
parent 5c4db827
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -60,4 +60,6 @@ interface IPowerManager

    void setKeyboardLight(boolean on, int key);

	void setPowerProfile(String profile);
	String getPowerProfile();
}
+89 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.os;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;

/**
@@ -290,6 +291,31 @@ public final class PowerManager {
     */
    public static final int GO_TO_SLEEP_REASON_TIMEOUT = 2;

    /**
     * Power save profile
     * @hide
     */
    public static final String PROFILE_POWER_SAVE = "0";

    /**
     * Balanced power profile
     * @hide
     */
    public static final String PROFILE_BALANCED = "1";

    /**
     * High-performance profile
     * @hide
     */
    public static final String PROFILE_HIGH_PERFORMANCE = "2";

    /**
     * Broadcast sent when profile is changed
     * @hide
     */
    public static final String POWER_PROFILE_CHANGED =
            "com.cyanogenmod.power.PROFILE_CHANGED";

    final Context mContext;
    final IPowerManager mService;
    final Handler mHandler;
@@ -636,6 +662,69 @@ public final class PowerManager {
        }
    }

    /**
     * True if the system supports power profiles
     *
     * @hide
     */
    public boolean hasPowerProfiles() {
        return !TextUtils.isEmpty(getDefaultPowerProfile()) &&
               !TextUtils.isEmpty(mContext.getResources().getString(
                       com.android.internal.R.string.config_perf_profile_prop));
    }

    /**
     * Gets the default power profile for the device.
     *
     * Returns null if not enabled.
     *
     * @hide
     */
    public String getDefaultPowerProfile() {
        return mContext.getResources().getString(
                com.android.internal.R.string.config_perf_profile_default_entry);
    }

    /**
     * Set the system power profile
     *
     * @throws IllegalArgumentException if invalid
     * @hide
     */
    public void setPowerProfile(String profile) {
        if (!hasPowerProfiles()) {
            throw new IllegalArgumentException("Power profiles not enabled on this system!");
        }

        try {
            if (mService != null) {
                mService.setPowerProfile(profile);
            }
        } catch (RemoteException e) {
            throw new IllegalArgumentException(e);
        }
    }

    /**
     * Gets the current power profile
     *
     * Returns null if power profiles are not enabled
     * @hide
     */
    public String getPowerProfile() {
        String ret = null;
        if (hasPowerProfiles()) {
            try {
                if (mService != null) {
                    ret = mService.getPowerProfile();
                }
            } catch (RemoteException e) {
                // nothing
            }
        }
        return ret;
    }

    /**
     * A wake lock is a mechanism to indicate that your application needs
     * to have the device stay on.
+13 −7
Original line number Diff line number Diff line
@@ -3527,13 +3527,6 @@ public final class Settings {
         */
        public static final String LOCKSCREEN_MAXIMIZE_WIDGETS = "lockscreen_maximize_widgets";

        /**
         * Performance profile
         * @see config_perf_profile_prop in frameworks/base/core/res/res/values/config.xml
         * @hide
         */
        public static final String PERFORMANCE_PROFILE = "performance_profile";

        /**
         * Whether to unlock the screen with the home key.  The value is boolean (1 or 0).
         * @hide
@@ -5720,6 +5713,19 @@ public final class Settings {
        public static final String DEFAULT_THEME_APPLIED_ON_FIRST_BOOT =
                "default_theme_applied_on_first_boot";

        /**
         * Performance profile
         * @see config_perf_profile_prop in frameworks/base/core/res/res/values/config.xml
         * @hide
         */
        public static final String PERFORMANCE_PROFILE = "performance_profile";

        /**
         * App-based performance profile selection
         * @hide
         */
        public static final String APP_PERFORMANCE_PROFILES_ENABLED = "app_perf_profiles_enabled";

        /**
         * This are the settings to be backed up.
         *
+7 −0
Original line number Diff line number Diff line
@@ -1513,4 +1513,11 @@

         The default value is false which represents AOSP behavior. -->
    <bool name="config_smsUseExpectMore">false</bool>

    <!-- 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>

</resources>
+3 −0
Original line number Diff line number Diff line
@@ -2005,4 +2005,7 @@

  <!-- Label for the Android system components when they are shown to the user. -->
  <java-symbol type="string" name="android_system_label" />

  <!-- Array of default activities with custom power management -->
  <java-symbol type="array" name="config_auto_perf_activities" />
</resources>
Loading