Loading services/core/java/com/android/server/display/mode/SystemRequestObserver.java +14 −2 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.os.IBinder; import android.os.RemoteException; import android.util.Slog; import android.util.SparseArray; import com.android.internal.annotations.GuardedBy; Loading @@ -28,12 +29,15 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.NoSuchElementException; /** * SystemRequestObserver responsible for handling system requests to filter allowable display * modes */ class SystemRequestObserver { private static final String TAG = "SystemRequestObserver"; private final VotesStorage mVotesStorage; private final IBinder.DeathRecipient mDeathRecipient = new IBinder.DeathRecipient() { Loading @@ -43,6 +47,7 @@ class SystemRequestObserver { } @Override public void binderDied(@NonNull IBinder who) { Slog.d(TAG, "binder died: " + who); removeSystemRequestedVotes(who); who.unlinkToDeath(mDeathRecipient, 0); } Loading Loading @@ -83,9 +88,11 @@ class SystemRequestObserver { updateStorageLocked(displayId); } if (needLinkToDeath) { Slog.d(TAG, "binder linking to death: " + token); token.linkToDeath(mDeathRecipient, 0); } } catch (RemoteException re) { Slog.d(TAG, "linking to death failed: " + token, re); removeSystemRequestedVotes(token); } } Loading @@ -94,14 +101,19 @@ class SystemRequestObserver { boolean needToUnlink = false; synchronized (mLock) { SparseArray<List<Integer>> modesByDisplay = mDisplaysRestrictions.get(token); if (modesByDisplay != null) { if (modesByDisplay != null && modesByDisplay.size() > 0) { modesByDisplay.remove(displayId); needToUnlink = modesByDisplay.size() == 0; updateStorageLocked(displayId); } } if (needToUnlink) { try { Slog.d(TAG, "binder unlinking to death: " + token); token.unlinkToDeath(mDeathRecipient, 0); } catch (NoSuchElementException e) { Slog.d(TAG, "unlinking to death failed: " + token, e); } } } Loading services/tests/displayservicetests/src/com/android/server/display/mode/SystemRequestObserverTest.kt +24 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import org.junit.runner.RunWith import org.mockito.junit.MockitoJUnit import org.mockito.kotlin.any import org.mockito.kotlin.argumentCaptor import org.mockito.kotlin.clearInvocations import org.mockito.kotlin.doThrow import org.mockito.kotlin.eq import org.mockito.kotlin.mock Loading Loading @@ -148,6 +149,29 @@ class SystemRequestObserverTest { verify(mockToken).unlinkToDeath(any(), eq(0)) } @Test fun testTokenUnlinkToDeath_noVotes() { val systemRequestObserver = SystemRequestObserver(storage) systemRequestObserver.requestDisplayModes(mockToken, DISPLAY_ID, null) verify(mockToken, never()).unlinkToDeath(any(), eq(0)) } @Test fun testTokenUnlinkToDeath_removedVotes() { val systemRequestObserver = SystemRequestObserver(storage) val requestedModes = intArrayOf(1, 2, 3) systemRequestObserver.requestDisplayModes(mockToken, DISPLAY_ID, requestedModes) systemRequestObserver.requestDisplayModes(mockToken, DISPLAY_ID, null) clearInvocations(mockToken) systemRequestObserver.requestDisplayModes(mockToken, DISPLAY_ID, null) verify(mockToken, never()).unlinkToDeath(any(), eq(0)) } @Test fun testTokenUnlinkToDeathNotCalled_votesForOtherDisplayInStorage() { val systemRequestObserver = SystemRequestObserver(storage) Loading Loading
services/core/java/com/android/server/display/mode/SystemRequestObserver.java +14 −2 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.os.IBinder; import android.os.RemoteException; import android.util.Slog; import android.util.SparseArray; import com.android.internal.annotations.GuardedBy; Loading @@ -28,12 +29,15 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.NoSuchElementException; /** * SystemRequestObserver responsible for handling system requests to filter allowable display * modes */ class SystemRequestObserver { private static final String TAG = "SystemRequestObserver"; private final VotesStorage mVotesStorage; private final IBinder.DeathRecipient mDeathRecipient = new IBinder.DeathRecipient() { Loading @@ -43,6 +47,7 @@ class SystemRequestObserver { } @Override public void binderDied(@NonNull IBinder who) { Slog.d(TAG, "binder died: " + who); removeSystemRequestedVotes(who); who.unlinkToDeath(mDeathRecipient, 0); } Loading Loading @@ -83,9 +88,11 @@ class SystemRequestObserver { updateStorageLocked(displayId); } if (needLinkToDeath) { Slog.d(TAG, "binder linking to death: " + token); token.linkToDeath(mDeathRecipient, 0); } } catch (RemoteException re) { Slog.d(TAG, "linking to death failed: " + token, re); removeSystemRequestedVotes(token); } } Loading @@ -94,14 +101,19 @@ class SystemRequestObserver { boolean needToUnlink = false; synchronized (mLock) { SparseArray<List<Integer>> modesByDisplay = mDisplaysRestrictions.get(token); if (modesByDisplay != null) { if (modesByDisplay != null && modesByDisplay.size() > 0) { modesByDisplay.remove(displayId); needToUnlink = modesByDisplay.size() == 0; updateStorageLocked(displayId); } } if (needToUnlink) { try { Slog.d(TAG, "binder unlinking to death: " + token); token.unlinkToDeath(mDeathRecipient, 0); } catch (NoSuchElementException e) { Slog.d(TAG, "unlinking to death failed: " + token, e); } } } Loading
services/tests/displayservicetests/src/com/android/server/display/mode/SystemRequestObserverTest.kt +24 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import org.junit.runner.RunWith import org.mockito.junit.MockitoJUnit import org.mockito.kotlin.any import org.mockito.kotlin.argumentCaptor import org.mockito.kotlin.clearInvocations import org.mockito.kotlin.doThrow import org.mockito.kotlin.eq import org.mockito.kotlin.mock Loading Loading @@ -148,6 +149,29 @@ class SystemRequestObserverTest { verify(mockToken).unlinkToDeath(any(), eq(0)) } @Test fun testTokenUnlinkToDeath_noVotes() { val systemRequestObserver = SystemRequestObserver(storage) systemRequestObserver.requestDisplayModes(mockToken, DISPLAY_ID, null) verify(mockToken, never()).unlinkToDeath(any(), eq(0)) } @Test fun testTokenUnlinkToDeath_removedVotes() { val systemRequestObserver = SystemRequestObserver(storage) val requestedModes = intArrayOf(1, 2, 3) systemRequestObserver.requestDisplayModes(mockToken, DISPLAY_ID, requestedModes) systemRequestObserver.requestDisplayModes(mockToken, DISPLAY_ID, null) clearInvocations(mockToken) systemRequestObserver.requestDisplayModes(mockToken, DISPLAY_ID, null) verify(mockToken, never()).unlinkToDeath(any(), eq(0)) } @Test fun testTokenUnlinkToDeathNotCalled_votesForOtherDisplayInStorage() { val systemRequestObserver = SystemRequestObserver(storage) Loading