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

Commit 66c8387f authored by Daniel Jacob Chittoor's avatar Daniel Jacob Chittoor
Browse files

Merge branch '852devices-t-powerext' into 'v1-t'

PowerManager: Introduce PowerExt supported boosting APIs

See merge request e/os/android_frameworks_base!186
parents 88086cbe 4f92106f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -34,6 +34,8 @@ interface IPowerManager
    @UnsupportedAppUsage
    void releaseWakeLock(IBinder lock, int flags);
    void updateWakeLockUids(IBinder lock, in int[] uids);
    oneway void setPowerExtMode(String mode_name, boolean enabled);
    oneway void setPowerExtBoost(String boost_name, int durationMs);
    oneway void setPowerBoost(int boost, int durationMs);
    oneway void setPowerMode(int mode, boolean enabled);

+72 −0
Original line number Diff line number Diff line
@@ -236,6 +236,31 @@ public abstract class PowerManagerInternal {
     */
    public static final int BOOST_DISPLAY_UPDATE_IMMINENT = 1;

    /**
     * SetPowerExtMode() is called to enable/disable specific hint mode, which
     * may result in adjustment of power/performance parameters of the
     * cpufreq governor and other controls on device side.
     *
     * @param string mode_name which is to be enable/disable.
     * @param enabled true to enable, false to disable the mode.
     */
    public abstract void setPowerExtMode(String mode_name, boolean enabled);

    /**
     * SetPowerExtBoost() indicates the device may need to boost some resources, as
     * the load is likely to increase before the kernel governors can react.
     * Depending on the boost, it may be appropriate to raise the frequencies of
     * CPU, GPU, memory subsystem, or stop CPU from going into deep sleep state.
     *
     * @param boost_name, which is the boost name from PowerExtBoosts enum to be set
     * @param durationMs The expected duration of the user's interaction, if
     *        known, or 0 if the expected duration is unknown.
     *        a negative value indicates canceling previous boost.
     *        A given platform can choose to boost some time based on durationMs,
     *        and may also pick an appropriate timeout for 0 case.
     */
    public abstract void setPowerExtBoost(String boost_name, int durationMs);

    /**
     * SetPowerBoost() indicates the device may need to boost some resources, as
     * the load is likely to increase before the kernel governors can react.
@@ -357,4 +382,51 @@ public abstract class PowerManagerInternal {
     * return false if ambient display is not available.
     */
    public abstract boolean isAmbientDisplaySuppressed();

    /**
     * This parcelable enum contains the platform supported custom boosts along with defined fallback
     * standard boosts for when the Extension HAL isn't available.
     */
    public enum PowerExtBoosts {
        // Custom boosts list
        // There already is INTERACTION boost when user touches the screen but if an OEM would like
        // to add additional actions for FLING only they can use this boost.
        FLING_BOOST(BOOST_INTERACTION),
        // Although there is already a LAUNCH mode boost when an app is launched, OEMs may wish to
        // boost resources for a period after to ensure the app is responsive while it is loading.
        // This has a duration of 2000ms.
        // There is no fallback.
        ACTIVITY_SWITCH,
        // Like before, this hint allows OEMs to boost resources for when a new package is launched
        // This is triggered for a duration of 4000ms.
        // There is no fallback.
        PACKAGE_SWITCH,
        // This hint allows OEMs to boost resources for when a new process thread is created,
        // a package Cold Launch with a duration of 4000ms.
        // There is no fallback.
        PROCESS_CREATE,
        // This hint allows OEMs to boost resources in case of package installation.
        // There is no fallback.
        PACKAGE_INSTALL,
        // This hint allows OEMs to boost resources when app rotation animation occurs.
        // There is no fallback.
        APP_ROTATE;
        // End boosts list

        // Fallback boost for given value
        private final int mFallback;

        PowerExtBoosts(int fallback) {
            mFallback = fallback;
        }

        public int getFallback() {
            return mFallback;
        }
        // End fallback boost

        PowerExtBoosts() {
            mFallback = -1;
        }
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
@@ -94,6 +95,7 @@ import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.PowerManager;
import android.os.PowerManagerInternal.PowerExtBoosts;
import android.os.Process;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
@@ -123,6 +125,7 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.ProcessMap;
import com.android.internal.os.Zygote;
import com.android.internal.R;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.FrameworkStatsLog;
import com.android.internal.util.MemInfoReader;
@@ -1664,6 +1667,10 @@ public final class ProcessList {
        mService.updateCpuStats();
        checkSlow(startUptime, "startProcess: done updating cpu stats");

        if (mService.mLocalPowerManager != null && hostingRecord.getType().contains("activity") == true) {
            mService.mLocalPowerManager.setPowerExtBoost(PowerExtBoosts.PROCESS_CREATE.name(), Resources.getSystem().getInteger(org.lineageos.platform.internal.R.integer.power_ext_activity_switch_duration));
        }

        try {
            final int userId = UserHandle.getUserId(app.uid);
            try {
+6 −0
Original line number Diff line number Diff line
@@ -123,6 +123,7 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Message;
import android.os.PowerManagerInternal.PowerExtBoosts;
import android.os.Process;
import android.os.RemoteException;
import android.os.SystemProperties;
@@ -2653,6 +2654,11 @@ final class InstallPackageHelper {
        final boolean removedBeforeUpdate = (pkgSetting == null)
                || (pkgSetting.isSystem() && !pkgSetting.getPath().getPath().equals(
                res.mPkg.getPath()));
        // Disable boost early to prevent stuck boost.
        if (mPm.mPowerManagerInternal != null) {
            mPm.mPowerManagerInternal.setPowerExtMode(
                PowerExtBoosts.PACKAGE_INSTALL.name(), false);
        }
        if (succeeded && removedBeforeUpdate) {
            Slog.e(TAG, packageName + " was removed before handlePackagePostInstall "
                    + "could be executed");
+5 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.os.PowerManagerInternal.PowerExtBoosts;
import android.os.Process;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
@@ -934,6 +935,10 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
    @Override
    public IPackageInstallerSession openSession(int sessionId) {
        try {
            if (mPm.mPowerManagerInternal != null) {
                mPm.mPowerManagerInternal.setPowerExtMode(
                    PowerExtBoosts.PACKAGE_INSTALL.name(), true);
            }
            return openSessionInternal(sessionId);
        } catch (IOException e) {
            throw ExceptionUtils.wrap(e);
Loading