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

Commit 85dd0852 authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Extreme battery saver: Log BS state in the event log.

Test: manual test (adb logcat -b events | grep battery_saver_mode)
Bug: 68769804
Change-Id: I93b26e3434a60dcae1efaa7ab8c78da2ba73192c
parent 3336a352
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -32,9 +32,11 @@ option java_package com.android.server
# The device is being asked to go into a soft sleep (typically by the ungaze gesture).
# It logs the time remaining before the device would've normally gone to sleep without the request.
2731 power_soft_sleep_requested (savedwaketimems|2)
# Power save state has changed. See BatterySaverController.java for the details.
2739 battery_saver_mode (prevOffOrOn|1|5),(nowOffOrOn|1|5),(interactive|1|5),(features|3|5)

#
# Leave IDs through 2739 for more power logs (2730 used by battery_discharge above)
# Leave IDs through 2740 for more power logs (2730 used by battery_discharge above)
#


+33 −0
Original line number Diff line number Diff line
@@ -86,6 +86,12 @@ public class BatterySaverPolicy extends ContentObserver {
    @GuardedBy("mLock")
    private String mDeviceSpecificSettingsSource; // For dump() only.

    /**
     * A short string describing which battery saver is now enabled, which we dump in the eventlog.
     */
    @GuardedBy("mLock")
    private String mEventLogKeys;

    /**
     * {@code true} if vibration is disabled in battery saver mode.
     *
@@ -354,6 +360,27 @@ public class BatterySaverPolicy extends ContentObserver {

        mFilesForNoninteractive = (new CpuFrequencies()).parseString(
                parser.getString(KEY_CPU_FREQ_NONINTERACTIVE, "")).toSysFileMap();

        final StringBuilder sb = new StringBuilder();

        if (mForceAllAppsStandby) sb.append("A");
        if (mForceBackgroundCheck) sb.append("B");

        if (mVibrationDisabled) sb.append("v");
        if (mAnimationDisabled) sb.append("a");
        if (mSoundTriggerDisabled) sb.append("s");
        if (mFullBackupDeferred) sb.append("F");
        if (mKeyValueBackupDeferred) sb.append("K");
        if (!mFireWallDisabled) sb.append("f");
        if (!mDataSaverDisabled) sb.append("d");
        if (!mAdjustBrightnessDisabled) sb.append("b");

        if (mLaunchBoostDisabled) sb.append("l");
        if (mOptionalSensorsDisabled) sb.append("S");

        sb.append(mGpsMode);

        mEventLogKeys = sb.toString();
    }

    /**
@@ -431,6 +458,12 @@ public class BatterySaverPolicy extends ContentObserver {
        }
    }

    public String toEventLogString() {
        synchronized (mLock) {
            return mEventLogKeys;
        }
    }

    public void dump(PrintWriter pw) {
        synchronized (mLock) {
            pw.println();
+15 −2
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.widget.Toast;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.Preconditions;
import com.android.server.EventLogTags;
import com.android.server.LocalServices;
import com.android.server.power.BatterySaverPolicy;
import com.android.server.power.BatterySaverPolicy.BatterySaverPolicyListener;
@@ -67,6 +68,12 @@ public class BatterySaverController implements BatterySaverPolicyListener {
    @GuardedBy("mLock")
    private boolean mEnabled;

    /**
     * Previously enabled or not; only for the event logging. Only use it from
     * {@link #handleBatterySaverStateChanged}.
     */
    private boolean mPreviouslyEnabled;

    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
@@ -203,12 +210,18 @@ public class BatterySaverController implements BatterySaverPolicyListener {
        final ArrayMap<String, String> fileValues;

        synchronized (mLock) {
            Slog.i(TAG, "Battery saver " + (mEnabled ? "enabled" : "disabled")
                    + ": isInteractive=" + isInteractive);
            EventLogTags.writeBatterySaverMode(
                    mPreviouslyEnabled ? 1 : 0, // Previously off or on.
                    mEnabled ? 1 : 0, // Now off or on.
                    isInteractive ?  1 : 0, // Device interactive state.
                    mEnabled ? mBatterySaverPolicy.toEventLogString() : "");
            mPreviouslyEnabled = mEnabled;

            listeners = mListeners.toArray(new LowPowerModeListener[mListeners.size()]);

            enabled = mEnabled;


            if (enabled) {
                fileValues = mBatterySaverPolicy.getFileValues(isInteractive);
            } else {