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

Commit 94c90299 authored by Oleg Petšjonkin's avatar Oleg Petšjonkin Committed by Automerger Merge Worker
Browse files

Merge "Fixing race condition between deleting display and updating votes" into...

Merge "Fixing race condition between deleting display and updating votes" into udc-dev am: 84471c97

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21853339



Change-Id: I66d1f7d8e55ea6089085ba007c211b63a678f5ce
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents c30f96f7 84471c97
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -84,7 +84,11 @@ final class SkinThermalStatusObserver extends IThermalEventListener.Stub impleme
    @Override
    public void notifyThrottling(Temperature temp) {
        @Temperature.ThrottlingStatus int currentStatus = temp.getStatus();

        synchronized (mThermalObserverLock) {
            if (mStatus == currentStatus) {
                return; // status not changed, skip update
            }
            mStatus = currentStatus;
            mHandler.post(this::updateVotes);
        }
@@ -188,6 +192,10 @@ final class SkinThermalStatusObserver extends IThermalEventListener.Stub impleme
            localStatus = mStatus;
            localMap = mThermalThrottlingByDisplay.get(displayId);
        }
        if (localMap == null) {
            Slog.d(TAG, "Updating votes, display already removed, display=" + displayId);
            return;
        }
        if (mLoggingEnabled) {
            Slog.d(TAG, "Updating votes for status=" + localStatus + ", display =" + displayId
                    + ", map=" + localMap);
+38 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.display.mode;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import android.hardware.display.DisplayManager;
@@ -49,6 +50,7 @@ public class SkinThermalStatusObserverTest {
    private static final float FLOAT_TOLERANCE = 0.01f;
    private static final int DISPLAY_ID = 1;
    private static final int DISPLAY_ID_OTHER = 2;
    private static final int DISPLAY_ID_ADDED = 3;

    SkinThermalStatusObserver mObserver;

@@ -167,6 +169,42 @@ public class SkinThermalStatusObserverTest {
        assertEquals(120, vote.refreshRateRanges.render.max, FLOAT_TOLERANCE);
    }

    @Test
    public void testDisplayAdded() {
        // GIVEN 2 displays with no thermalThrottling config AND temperature level CRITICAL
        mObserver.observe();
        mObserver.notifyThrottling(createTemperature(Temperature.THROTTLING_CRITICAL));
        // WHEN new display is added
        mObserver.onDisplayAdded(DISPLAY_ID_ADDED);
        mHandler.flush();
        // THEN 3rd vote is added to storage with (0,60) render refresh rate(default behaviour)
        assertEquals(3, mStorage.mVoteRegistry.size());

        SparseArray<DisplayModeDirector.Vote> displayVotes = mStorage.mVoteRegistry.get(
                DISPLAY_ID_ADDED);
        assertEquals(1, displayVotes.size());

        DisplayModeDirector.Vote vote = displayVotes.get(
                DisplayModeDirector.Vote.PRIORITY_SKIN_TEMPERATURE);
        assertEquals(0, vote.refreshRateRanges.render.min, FLOAT_TOLERANCE);
        assertEquals(60, vote.refreshRateRanges.render.max, FLOAT_TOLERANCE);
    }

    @Test
    public void testDisplayAddedAndThenImmediatelyRemoved() {
        // GIVEN 2 displays with no thermalThrottling config AND temperature level CRITICAL
        mObserver.observe();
        mObserver.notifyThrottling(createTemperature(Temperature.THROTTLING_CRITICAL));
        // WHEN new display is added and immediately removed
        mObserver.onDisplayAdded(DISPLAY_ID_ADDED);
        mObserver.onDisplayRemoved(DISPLAY_ID_ADDED);
        mHandler.flush();
        // THEN there are 2 votes in registry
        assertEquals(2, mStorage.mVoteRegistry.size());
        assertNotNull(mStorage.mVoteRegistry.get(DISPLAY_ID));
        assertNotNull(mStorage.mVoteRegistry.get(DISPLAY_ID_OTHER));
    }

    private static Temperature createTemperature(@Temperature.ThrottlingStatus int status) {
        return new Temperature(40.0f, Temperature.TYPE_SKIN, "test_temp", status);
    }