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

Commit 3cf332a4 authored by Yeabkal Wubshit's avatar Yeabkal Wubshit
Browse files

Enable batterystats for all display IDs

Batterystats used to be enabled only for the default display. This
change enables it for all displays (both for noting screen state and
brightness).

Bug: 366112793
Test: atest DisplayPowerControllerTest
Flag: com.android.server.display.feature.flags.enable_battery_stats_for_all_displays
Change-Id: I12e6ca4c9777fbdc3023e014dbd43fb2361eff06
parent e65b5d36
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -146,7 +146,7 @@ interface IBatteryStats {
    @EnforcePermission("UPDATE_DEVICE_STATS")
    void noteScreenState(int displayId, int state, int reason);
    @EnforcePermission("UPDATE_DEVICE_STATS")
    void noteScreenBrightness(int brightness);
    void noteScreenBrightness(int displayId, int brightness);
    @EnforcePermission("UPDATE_DEVICE_STATS")
    void noteUserActivity(int uid, int event);
    @EnforcePermission("UPDATE_DEVICE_STATS")
+3 −2
Original line number Diff line number Diff line
@@ -1855,7 +1855,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub

    @Override
    @EnforcePermission(UPDATE_DEVICE_STATS)
    public void noteScreenBrightness(final int brightness) {
    public void noteScreenBrightness(final int displayId, final int brightness) {
        super.noteScreenBrightness_enforcePermission();

        synchronized (mLock) {
@@ -1863,7 +1863,8 @@ public final class BatteryStatsService extends IBatteryStats.Stub
            final long uptime = SystemClock.uptimeMillis();
            mHandler.post(() -> {
                synchronized (mStats) {
                    mStats.noteScreenBrightnessLocked(0, brightness, elapsedRealtime, uptime);
                    mStats.noteScreenBrightnessLocked(
                            displayId, brightness, elapsedRealtime, uptime);
                }
            });
        }
+5 −4
Original line number Diff line number Diff line
@@ -536,7 +536,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        mLastBrightnessEvent = new BrightnessEvent(mDisplayId);
        mTempBrightnessEvent = new BrightnessEvent(mDisplayId);

        if (mDisplayId == Display.DEFAULT_DISPLAY) {
        if (flags.isBatteryStatsEnabledForAllDisplays()) {
            mBatteryStats = BatteryStatsService.getService();
        } else if (mDisplayId == Display.DEFAULT_DISPLAY) {
            mBatteryStats = BatteryStatsService.getService();
        } else {
            mBatteryStats = null;
@@ -2791,8 +2793,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                screenState, mDisplayStatsId, reason);
        if (mBatteryStats != null) {
            try {
                // TODO(multi-display): make this multi-display
                mBatteryStats.noteScreenState(/* displayId= */ 0, screenState, reason);
                mBatteryStats.noteScreenState(mDisplayId, screenState, reason);
            } catch (RemoteException e) {
                // same process
            }
@@ -2807,7 +2808,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                int brightnessInt = mFlags.isBrightnessIntRangeUserPerceptionEnabled()
                        ? BrightnessSynchronizer.brightnessFloatToIntSetting(mContext, brightness)
                        : BrightnessSynchronizer.brightnessFloatToInt(brightness);
                mBatteryStats.noteScreenBrightness(brightnessInt);
                mBatteryStats.noteScreenBrightness(mDisplayId, brightnessInt);
            } catch (RemoteException e) {
                // same process
            }
+14 −0
Original line number Diff line number Diff line
@@ -200,6 +200,11 @@ public class DisplayManagerFlags {
            Flags::normalBrightnessForDozeParameter
    );

    private final FlagState mEnableBatteryStatsForAllDisplays = new FlagState(
            Flags.FLAG_ENABLE_BATTERY_STATS_FOR_ALL_DISPLAYS,
            Flags::enableBatteryStatsForAllDisplays
    );

    /**
     * @return {@code true} if 'port' is allowed in display layout configuration file.
     */
@@ -414,6 +419,14 @@ public class DisplayManagerFlags {
        return mIdleScreenConfigInSubscribingLightSensor.isEnabled();
    }

    /**
      * @return {@code true} if battery stats is enabled for all displays, not just the primary
      * display.
      */
    public boolean isBatteryStatsEnabledForAllDisplays() {
        return mEnableBatteryStatsForAllDisplays.isEnabled();
    }

    /**
     * dumps all flagstates
     * @param pw printWriter
@@ -456,6 +469,7 @@ public class DisplayManagerFlags {
        pw.println(" " + mNewHdrBrightnessModifier);
        pw.println(" " + mNormalBrightnessForDozeParameter);
        pw.println(" " + mIdleScreenConfigInSubscribingLightSensor);
        pw.println(" " + mEnableBatteryStatsForAllDisplays);
    }

    private static class FlagState {
+8 −0
Original line number Diff line number Diff line
@@ -341,3 +341,11 @@ flag {
      purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "enable_battery_stats_for_all_displays"
    namespace: "display_manager"
    description: "Flag to enable battery stats for all displays."
    bug: "366112793"
    is_fixed_read_only: true
}
 No newline at end of file
Loading