Merge "DisplayManagerGlobal: suppress redundant onDisplayChanged events" into sc-dev

This commit is contained in:
Ady Abraham
2021-04-07 16:45:53 +00:00
committed by Android (Google) Code Review
4 changed files with 18 additions and 5 deletions

View File

@@ -391,8 +391,9 @@ public final class DisplayManagerGlobal {
}
final int numListeners = mDisplayListeners.size();
DisplayInfo info = getDisplayInfo(displayId);
for (int i = 0; i < numListeners; i++) {
mDisplayListeners.get(i).sendDisplayEvent(displayId, event);
mDisplayListeners.get(i).sendDisplayEvent(displayId, event, info);
}
if (event == EVENT_DISPLAY_CHANGED && mDispatchNativeCallbacks) {
// Choreographer only supports a single display, so only dispatch refresh rate
@@ -894,6 +895,8 @@ public final class DisplayManagerGlobal {
public final DisplayListener mListener;
public long mEventsMask;
private final DisplayInfo mDisplayInfo = new DisplayInfo();
DisplayListenerDelegate(DisplayListener listener, @NonNull Looper looper,
@EventsMask long eventsMask) {
super(looper, null, true /*async*/);
@@ -901,8 +904,8 @@ public final class DisplayManagerGlobal {
mEventsMask = eventsMask;
}
public void sendDisplayEvent(int displayId, @DisplayEvent int event) {
Message msg = obtainMessage(event, displayId, 0);
public void sendDisplayEvent(int displayId, @DisplayEvent int event, DisplayInfo info) {
Message msg = obtainMessage(event, displayId, 0, info);
sendMessage(msg);
}
@@ -924,7 +927,11 @@ public final class DisplayManagerGlobal {
break;
case EVENT_DISPLAY_CHANGED:
if ((mEventsMask & DisplayManager.EVENT_FLAG_DISPLAY_CHANGED) != 0) {
mListener.onDisplayChanged(msg.arg1);
DisplayInfo newInfo = (DisplayInfo) msg.obj;
if (newInfo != null && !newInfo.equals(mDisplayInfo)) {
mDisplayInfo.copyFrom(newInfo);
mListener.onDisplayChanged(msg.arg1);
}
}
break;
case EVENT_DISPLAY_REMOVED:

View File

@@ -377,7 +377,7 @@ public final class DisplayInfo implements Parcelable {
&& ownerUid == other.ownerUid
&& Objects.equals(ownerPackageName, other.ownerPackageName)
&& removeMode == other.removeMode
&& refreshRateOverride == other.refreshRateOverride
&& getRefreshRate() == other.getRefreshRate()
&& brightnessMinimum == other.brightnessMinimum
&& brightnessMaximum == other.brightnessMaximum
&& brightnessDefault == other.brightnessDefault

View File

@@ -346,6 +346,9 @@ public class DisplayManagerServiceTest {
DisplayDeviceInfo displayDeviceInfo = new DisplayDeviceInfo();
displayDeviceInfo.width = 100;
displayDeviceInfo.height = 200;
displayDeviceInfo.supportedModes = new Display.Mode[1];
displayDeviceInfo.supportedModes[0] = new Display.Mode(1, 100, 200, 60f);
displayDeviceInfo.modeId = 1;
final Rect zeroRect = new Rect();
displayDeviceInfo.displayCutout = new DisplayCutout(
Insets.of(0, 10, 0, 0),

View File

@@ -239,6 +239,9 @@ public class LogicalDisplayMapperTest {
displayDeviceInfo.width = width;
displayDeviceInfo.height = height;
displayDeviceInfo.flags = flags;
displayDeviceInfo.supportedModes = new Display.Mode[1];
displayDeviceInfo.supportedModes[0] = new Display.Mode(1, width, height, 60f);
displayDeviceInfo.modeId = 1;
displayDeviceInfo.address = new DisplayAddressImpl();
return device;
}