Merge "DisplayManagerGlobal: fix native refresh rate callback registration" into sc-qpr1-dev am: c265f32026 am: a999a6220a
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15689742 Change-Id: Ie85ca93f7ec1e4296d4e222c9bbf43201a5aff7e
This commit is contained in:
@@ -361,6 +361,11 @@ public final class DisplayManagerGlobal {
|
|||||||
for (int i = 0; i < numListeners; i++) {
|
for (int i = 0; i < numListeners; i++) {
|
||||||
mask |= mDisplayListeners.get(i).mEventsMask;
|
mask |= mDisplayListeners.get(i).mEventsMask;
|
||||||
}
|
}
|
||||||
|
if (mDispatchNativeCallbacks) {
|
||||||
|
mask |= DisplayManager.EVENT_FLAG_DISPLAY_ADDED
|
||||||
|
| DisplayManager.EVENT_FLAG_DISPLAY_CHANGED
|
||||||
|
| DisplayManager.EVENT_FLAG_DISPLAY_REMOVED;
|
||||||
|
}
|
||||||
return mask;
|
return mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1075,12 +1080,17 @@ public final class DisplayManagerGlobal {
|
|||||||
|
|
||||||
private static native void nSignalNativeCallbacks(float refreshRate);
|
private static native void nSignalNativeCallbacks(float refreshRate);
|
||||||
|
|
||||||
// Called from AChoreographer via JNI.
|
/**
|
||||||
// Registers AChoreographer so that refresh rate callbacks can be dispatched from DMS.
|
* Called from AChoreographer via JNI.
|
||||||
private void registerNativeChoreographerForRefreshRateCallbacks() {
|
* Registers AChoreographer so that refresh rate callbacks can be dispatched from DMS.
|
||||||
|
* Public for unit testing to be able to call this method.
|
||||||
|
*/
|
||||||
|
@VisibleForTesting
|
||||||
|
public void registerNativeChoreographerForRefreshRateCallbacks() {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
registerCallbackIfNeededLocked();
|
|
||||||
mDispatchNativeCallbacks = true;
|
mDispatchNativeCallbacks = true;
|
||||||
|
registerCallbackIfNeededLocked();
|
||||||
|
updateCallbackIfNeededLocked();
|
||||||
DisplayInfo display = getDisplayInfoLocked(Display.DEFAULT_DISPLAY);
|
DisplayInfo display = getDisplayInfoLocked(Display.DEFAULT_DISPLAY);
|
||||||
if (display != null) {
|
if (display != null) {
|
||||||
// We need to tell AChoreographer instances the current refresh rate so that apps
|
// We need to tell AChoreographer instances the current refresh rate so that apps
|
||||||
@@ -1091,11 +1101,16 @@ public final class DisplayManagerGlobal {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called from AChoreographer via JNI.
|
/**
|
||||||
// Unregisters AChoreographer from receiving refresh rate callbacks.
|
* Called from AChoreographer via JNI.
|
||||||
private void unregisterNativeChoreographerForRefreshRateCallbacks() {
|
* Unregisters AChoreographer from receiving refresh rate callbacks.
|
||||||
|
* Public for unit testing to be able to call this method.
|
||||||
|
*/
|
||||||
|
@VisibleForTesting
|
||||||
|
public void unregisterNativeChoreographerForRefreshRateCallbacks() {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
mDispatchNativeCallbacks = false;
|
mDispatchNativeCallbacks = false;
|
||||||
|
updateCallbackIfNeededLocked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Captor;
|
import org.mockito.Captor;
|
||||||
|
import org.mockito.InOrder;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
@@ -121,6 +122,46 @@ public class DisplayManagerGlobalTest {
|
|||||||
Mockito.verifyZeroInteractions(mListener);
|
Mockito.verifyZeroInteractions(mListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDisplayManagerGlobalRegistersWithDisplayManager_WhenThereAreNoOtherListeners()
|
||||||
|
throws RemoteException {
|
||||||
|
mDisplayManagerGlobal.registerNativeChoreographerForRefreshRateCallbacks();
|
||||||
|
Mockito.verify(mDisplayManager)
|
||||||
|
.registerCallbackWithEventMask(mCallbackCaptor.capture(), eq(ALL_DISPLAY_EVENTS));
|
||||||
|
|
||||||
|
mDisplayManagerGlobal.unregisterNativeChoreographerForRefreshRateCallbacks();
|
||||||
|
Mockito.verify(mDisplayManager)
|
||||||
|
.registerCallbackWithEventMask(mCallbackCaptor.capture(), eq(0L));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDisplayManagerGlobalRegistersWithDisplayManager_WhenThereAreListeners()
|
||||||
|
throws RemoteException {
|
||||||
|
mDisplayManagerGlobal.registerDisplayListener(mListener, mHandler,
|
||||||
|
DisplayManager.EVENT_FLAG_DISPLAY_BRIGHTNESS);
|
||||||
|
InOrder inOrder = Mockito.inOrder(mDisplayManager);
|
||||||
|
|
||||||
|
inOrder.verify(mDisplayManager)
|
||||||
|
.registerCallbackWithEventMask(mCallbackCaptor.capture(),
|
||||||
|
eq(DisplayManager.EVENT_FLAG_DISPLAY_BRIGHTNESS));
|
||||||
|
|
||||||
|
mDisplayManagerGlobal.registerNativeChoreographerForRefreshRateCallbacks();
|
||||||
|
inOrder.verify(mDisplayManager)
|
||||||
|
.registerCallbackWithEventMask(mCallbackCaptor.capture(),
|
||||||
|
eq(ALL_DISPLAY_EVENTS | DisplayManager.EVENT_FLAG_DISPLAY_BRIGHTNESS));
|
||||||
|
|
||||||
|
mDisplayManagerGlobal.unregisterNativeChoreographerForRefreshRateCallbacks();
|
||||||
|
inOrder.verify(mDisplayManager)
|
||||||
|
.registerCallbackWithEventMask(mCallbackCaptor.capture(),
|
||||||
|
eq(DisplayManager.EVENT_FLAG_DISPLAY_BRIGHTNESS));
|
||||||
|
|
||||||
|
mDisplayManagerGlobal.unregisterDisplayListener(mListener);
|
||||||
|
inOrder.verify(mDisplayManager)
|
||||||
|
.registerCallbackWithEventMask(mCallbackCaptor.capture(), eq(0L));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void waitForHandler() {
|
private void waitForHandler() {
|
||||||
mHandler.runWithScissors(() -> { }, 0);
|
mHandler.runWithScissors(() -> { }, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user