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

Commit d1371847 authored by Alexander Martinz's avatar Alexander Martinz Committed by Michael Bestas
Browse files

PowerProfile: allow overriding default power profile



  * override it with ro.power_profile.override

Change-Id: I2b229822b18a54060d577f25c0ddaf5b7e7563b7
Signed-off-by: default avatarAlexander Martinz <eviscerationls@gmail.com>
parent 16c042a9
Loading
Loading
Loading
Loading
+26 −1
Original line number Original line Diff line number Diff line
@@ -20,6 +20,8 @@ package com.android.internal.os;
import android.content.Context;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.content.res.XmlResourceParser;
import android.os.SystemProperties;
import android.util.Slog;


import com.android.internal.util.XmlUtils;
import com.android.internal.util.XmlUtils;


@@ -36,6 +38,7 @@ import java.util.HashMap;
 * [hidden]
 * [hidden]
 */
 */
public class PowerProfile {
public class PowerProfile {
    private static final String TAG = "PowerProfile";


    /**
    /**
     * No power consumption, or accounted for elsewhere.
     * No power consumption, or accounted for elsewhere.
@@ -210,7 +213,7 @@ public class PowerProfile {
    }
    }


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


    private int getPowerProfileResId(final Context context) {
        int id = com.android.internal.R.xml.power_profile;
        /*
         * 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 tmpId = context.getResources().getIdentifier(powerProfileOverride, "xml",
                    "android");
            if (tmpId > 0) {
                Slog.i(TAG, "getPowerProfileResId: using power profile \""
                        + powerProfileOverride + "\"");
                id = tmpId;
            } else {
                Slog.e(TAG, "getPowerProfileResId: could not retrieve power profile \""
                        + powerProfileOverride + "\", using default instead");
            }
        }
        return id;
    }

    /**
    /**
     * Returns the average current in mA consumed by the subsystem, or the given
     * Returns the average current in mA consumed by the subsystem, or the given
     * default value if the subsystem has no recorded value.
     * default value if the subsystem has no recorded value.