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

Commit d5526d53 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix initialization of display stats on multi-screen devices" into main

parents 729c8f71 bddee3a4
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -105,7 +105,7 @@ public final class LongArrayMultiStateCounter implements Parcelable {
        public void setValues(long[] array) {
            if (array.length != mLength) {
                throw new IllegalArgumentException(
                        "Invalid array length: " + mLength + ", expected: " + mLength);
                        "Invalid array length: " + array.length + ", expected: " + mLength);
            }
            native_setValues(mNativeObject, array);
        }
@@ -116,7 +116,7 @@ public final class LongArrayMultiStateCounter implements Parcelable {
        public void getValues(long[] array) {
            if (array.length != mLength) {
                throw new IllegalArgumentException(
                        "Invalid array length: " + mLength + ", expected: " + mLength);
                        "Invalid array length: " + array.length + ", expected: " + mLength);
            }
            native_getValues(mNativeObject, array);
        }
@@ -347,6 +347,11 @@ public final class LongArrayMultiStateCounter implements Parcelable {
            throw new IllegalArgumentException(
                    "State: " + state + ", outside the range: [0-" + mStateCount + "]");
        }
        if (longArrayContainer.mLength != mLength) {
            throw new IllegalArgumentException(
                    "Invalid array length: " + longArrayContainer.mLength
                            + ", expected: " + mLength);
        }
        native_getCounts(mNativeObject, longArrayContainer.mNativeObject, state);
    }

+0 −3
Original line number Diff line number Diff line
@@ -11509,9 +11509,6 @@ public class BatteryStatsImpl extends BatteryStats {
                    mOnBatteryTimeBase);
        }
        mPerDisplayBatteryStats = new DisplayBatteryStats[1];
        mPerDisplayBatteryStats[0] = new DisplayBatteryStats(mClock, mOnBatteryTimeBase);
        mInteractiveTimer = new StopwatchTimer(mClock, null, -10, null, mOnBatteryTimeBase);
        mPowerSaveModeEnabledTimer = new StopwatchTimer(mClock, null, -2, null,
                mOnBatteryTimeBase);
+7 −5
Original line number Diff line number Diff line
@@ -50,12 +50,14 @@ class AmbientDisplayPowerStatsProcessor extends PowerStatsProcessor {
            return;
        }

        if (mScreenPowerStatsDescriptor == null) {
            mScreenPowerStatsDescriptor = screenStats.getPowerStatsDescriptor();
            if (mScreenPowerStatsDescriptor == null) {
        PowerStats.Descriptor screenDescriptor = screenStats.getPowerStatsDescriptor();
        if (screenDescriptor == null) {
            return;
        }

        if (mScreenPowerStatsDescriptor == null
                || !mScreenPowerStatsDescriptor.equals(screenDescriptor)) {
            mScreenPowerStatsDescriptor = screenDescriptor;
            mScreenPowerStatsLayout = new ScreenPowerStatsLayout(mScreenPowerStatsDescriptor);
            mTmpScreenStats = new long[mScreenPowerStatsDescriptor.statsArrayLength];
        }
+5 −4
Original line number Diff line number Diff line
@@ -89,14 +89,15 @@ class ScreenPowerStatsProcessor extends PowerStatsProcessor {
            return true;
        }

        mLastUsedDescriptor = descriptor;
        mStatsLayout = new ScreenPowerStatsLayout(descriptor);
        if (mStatsLayout.getDisplayCount() != mDisplayCount) {
            Slog.e(TAG, "Incompatible number of displays: " + mStatsLayout.getDisplayCount()
        ScreenPowerStatsLayout statsLayout = new ScreenPowerStatsLayout(descriptor);
        if (statsLayout.getDisplayCount() != mDisplayCount) {
            Slog.e(TAG, "Incompatible number of displays: " + statsLayout.getDisplayCount()
                    + ", expected: " + mDisplayCount);
            return false;
        }

        mLastUsedDescriptor = descriptor;
        mStatsLayout = statsLayout;
        mTmpDeviceStatsArray = new long[descriptor.statsArrayLength];
        mTmpUidStatsArray = new long[descriptor.uidStatsArrayLength];
        return true;
+8 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.power.stats;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import android.annotation.NonNull;
import android.app.usage.NetworkStatsManager;
@@ -80,7 +81,7 @@ public class MockBatteryStatsImpl extends BatteryStatsImpl {
            Handler handler, PowerStatsUidResolver powerStatsUidResolver) {
        super(config, clock, new MonotonicClock(0, clock), historyDirectory, handler,
                mock(PlatformIdleStateCallback.class), mock(EnergyStatsRetriever.class),
                mock(UserInfoProvider.class), mock(PowerProfile.class),
                mock(UserInfoProvider.class), mockPowerProfile(),
                new CpuScalingPolicies(new SparseArray<>(), new SparseArray<>()),
                powerStatsUidResolver, mock(FrameworkStatsLogger.class),
                mock(BatteryStatsHistory.TraceDelegate.class),
@@ -96,6 +97,12 @@ public class MockBatteryStatsImpl extends BatteryStatsImpl {
        mKernelWakelockReader = null;
    }

    private static PowerProfile mockPowerProfile() {
        PowerProfile powerProfile = mock(PowerProfile.class);
        when(powerProfile.getNumDisplays()).thenReturn(1);
        return powerProfile;
    }

    public void initMeasuredEnergyStats(String[] customBucketNames) {
        final boolean[] supportedStandardBuckets =
                new boolean[EnergyConsumerStats.NUMBER_STANDARD_POWER_BUCKETS];