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

Commit 7240e031 authored by Alexander Martinz's avatar Alexander Martinz Committed by Bruno Martins
Browse files

PowerProfile: allow overriding default power profile



  * override it with ro.power_profile.override

[mikeioannina]: Adapt for Pie
Change-Id: I2b229822b18a54060d577f25c0ddaf5b7e7563b7
Signed-off-by: default avatarAlexander Martinz <eviscerationls@gmail.com>
parent bc865c16
Loading
Loading
Loading
Loading
+28 −2
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import android.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.os.SystemProperties;
import android.util.Slog;
import android.util.proto.ProtoOutputStream;

import com.android.internal.annotations.VisibleForTesting;
@@ -39,6 +41,7 @@ import java.util.HashMap;
 * [hidden]
 */
public class PowerProfile {
    private static final String TAG = "PowerProfile";

    /*
     * POWER_CPU_SUSPEND: Power consumption when CPU is in power collapse mode.
@@ -259,8 +262,7 @@ public class PowerProfile {
    }

    private void readPowerValuesFromXml(Context context, boolean forTest) {
        final int id = forTest ? com.android.internal.R.xml.power_profile_test :
                com.android.internal.R.xml.power_profile;
        int id = getPowerProfileResId(context, forTest);
        final Resources resources = context.getResources();
        XmlResourceParser parser = resources.getXml(id);
        boolean parsingArray = false;
@@ -421,6 +423,30 @@ public class PowerProfile {
        return 0;
    }

    private int getPowerProfileResId(final Context context, boolean forTest) {
        if (forTest) {
            return com.android.internal.R.xml.power_profile_test;
        }

        /*
         * If ro.power_profile.override is set, use it to override the default.
         * This is used for devices, which need to dynamically define the power profile.
         */
        String powerProfileOverride = SystemProperties.get("ro.power_profile.override");
        if (!powerProfileOverride.isEmpty()) {
            int id = context.getResources().getIdentifier(powerProfileOverride, "xml", "android");
            if (id > 0) {
                Slog.i(TAG, "getPowerProfileResId: using power profile \""
                        + powerProfileOverride + "\"");
                return id;
            }
            Slog.e(TAG, "getPowerProfileResId: could not retrieve power profile \""
                    + powerProfileOverride + "\", using default instead");
        }

        return com.android.internal.R.xml.power_profile;
    }

    /**
     * Returns the number of memory bandwidth buckets defined in power_profile.xml, or a
     * default value if the subsystem has no recorded value.