Fix notifyTaskDisplayChanged is called every time onDisplayChanged is triggered.

The original intention was to send the callback
when the task reparented to another display.
So we need to add a check whether displayId has
changed before calling notifyTaskDisplayChanged.

Test: pressure test that notifyTaskDisplayChanged
is triggered when the task moves from one display
to another, and not triggered otherwise.
Bug: b/365477008

Change-Id: I5848ead17a50ccd6ece0e3b0c10e59252a633f89
Signed-off-by: zhou.wei <zhou.wei@oppo.com>
diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java
index 728f739..eee2821 100644
--- a/services/core/java/com/android/server/wm/Task.java
+++ b/services/core/java/com/android/server/wm/Task.java
@@ -2790,11 +2790,15 @@
 
     @Override
     void onDisplayChanged(DisplayContent dc) {
+        final int lastDisplayId = getDisplayId();
         super.onDisplayChanged(dc);
         if (isLeafTask()) {
             final int displayId = (dc != null) ? dc.getDisplayId() : INVALID_DISPLAY;
-            mWmService.mAtmService.getTaskChangeNotificationController().notifyTaskDisplayChanged(
-                    mTaskId, displayId);
+            //Send the callback when the task reparented to another display.
+            if (lastDisplayId != displayId) {
+                mWmService.mAtmService.getTaskChangeNotificationController()
+                        .notifyTaskDisplayChanged(mTaskId, displayId);
+            }
         }
         if (isRootTask()) {
             updateSurfaceBounds();