OSDN Git Service

Associate rotation watchers with displays
authorAndrii Kulian <akulian@google.com>
Sat, 11 Mar 2017 17:37:28 +0000 (09:37 -0800)
committerAndrii Kulian <akulian@google.com>
Tue, 14 Mar 2017 01:27:24 +0000 (18:27 -0700)
Displays can be rotated separately and rotation watcher clients
are only interested in rotation of some specific display. This CL
adds displayId to rotation watchers and only informs them about
changes on their display.

Bug: 34242678
Test: Manual and debug.
Change-Id: If0f03804da0392c2b14a4e7c2d6a06068ad8760b

core/java/android/hardware/LegacySensorManager.java
core/java/android/view/IWindowManager.aidl
core/java/com/android/internal/policy/PhoneWindow.java
packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java
services/core/java/com/android/server/wm/WindowManagerService.java
tools/layoutlib/bridge/src/android/view/IWindowManagerImpl.java

index f959093..f5cf3f7 100644 (file)
@@ -16,6 +16,8 @@
 
 package android.hardware;
 
+import static android.view.Display.DEFAULT_DISPLAY;
+
 import android.os.RemoteException;
 import android.os.ServiceManager;
 import android.view.IRotationWatcher;
@@ -57,8 +59,7 @@ final class LegacySensorManager {
                                     public void onRotationChanged(int rotation) {
                                         LegacySensorManager.onRotationChanged(rotation);
                                     }
-                                }
-                        );
+                                }, DEFAULT_DISPLAY);
                     } catch (RemoteException e) {
                     }
                 }
index 27c6d08..586b3b2 100644 (file)
@@ -209,10 +209,10 @@ interface IWindowManager
     int getDefaultDisplayRotation();
 
     /**
-     * Watch the rotation of the screen.  Returns the current rotation,
+     * Watch the rotation of the specified screen.  Returns the current rotation,
      * calls back when it changes.
      */
-    int watchRotation(IRotationWatcher watcher);
+    int watchRotation(IRotationWatcher watcher, int displayId);
 
     /**
      * Remove a rotation watcher set using watchRotation.
index 804bd29..6c9280a 100644 (file)
@@ -3585,7 +3585,8 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
             synchronized (mWindows) {
                 if (!mIsWatching) {
                     try {
-                        WindowManagerHolder.sWindowManager.watchRotation(this);
+                        WindowManagerHolder.sWindowManager.watchRotation(this,
+                                phoneWindow.getContext().getDisplay().getDisplayId());
                         mHandler = new Handler();
                         mIsWatching = true;
                     } catch (RemoteException ex) {
index 99f8aaf..8a3c4e3 100644 (file)
@@ -142,7 +142,7 @@ public class NavigationBarFragment extends Fragment implements Callbacks {
 
         try {
             WindowManagerGlobal.getWindowManagerService()
-                    .watchRotation(mRotationWatcher);
+                    .watchRotation(mRotationWatcher, getContext().getDisplay().getDisplayId());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
index 47c62f9..3e9f2a8 100644 (file)
@@ -532,13 +532,17 @@ public class WindowManagerService extends IWindowManager.Stub
     }
 
     class RotationWatcher {
-        IRotationWatcher watcher;
-        IBinder.DeathRecipient deathRecipient;
-        RotationWatcher(IRotationWatcher w, IBinder.DeathRecipient d) {
-            watcher = w;
-            deathRecipient = d;
+        IRotationWatcher mWatcher;
+        IBinder.DeathRecipient mDeathRecipient;
+        int mDisplayId;
+        RotationWatcher(IRotationWatcher watcher, IBinder.DeathRecipient deathRecipient,
+                int displayId) {
+            mWatcher = watcher;
+            mDeathRecipient = deathRecipient;
+            mDisplayId = displayId;
         }
     }
+
     ArrayList<RotationWatcher> mRotationWatchers = new ArrayList<>();
     int mDeferredRotationPauseCount;
 
@@ -4073,10 +4077,13 @@ public class WindowManagerService extends IWindowManager.Stub
             mH.sendEmptyMessageDelayed(H.SEAMLESS_ROTATION_TIMEOUT, SEAMLESS_ROTATION_TIMEOUT_DURATION);
         }
 
-        for (int i=mRotationWatchers.size()-1; i>=0; i--) {
-            try {
-                mRotationWatchers.get(i).watcher.onRotationChanged(rotation);
-            } catch (RemoteException e) {
+        for (int i = mRotationWatchers.size() - 1; i >= 0; i--) {
+            final RotationWatcher rotationWatcher = mRotationWatchers.get(i);
+            if (rotationWatcher.mDisplayId == displayId) {
+                try {
+                    rotationWatcher.mWatcher.onRotationChanged(rotation);
+                } catch (RemoteException e) {
+                }
             }
         }
 
@@ -4104,16 +4111,16 @@ public class WindowManagerService extends IWindowManager.Stub
     }
 
     @Override
-    public int watchRotation(IRotationWatcher watcher) {
+    public int watchRotation(IRotationWatcher watcher, int displayId) {
         final IBinder watcherBinder = watcher.asBinder();
         IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
             @Override
             public void binderDied() {
                 synchronized (mWindowMap) {
                     for (int i=0; i<mRotationWatchers.size(); i++) {
-                        if (watcherBinder == mRotationWatchers.get(i).watcher.asBinder()) {
+                        if (watcherBinder == mRotationWatchers.get(i).mWatcher.asBinder()) {
                             RotationWatcher removed = mRotationWatchers.remove(i);
-                            IBinder binder = removed.watcher.asBinder();
+                            IBinder binder = removed.mWatcher.asBinder();
                             if (binder != null) {
                                 binder.unlinkToDeath(this, 0);
                             }
@@ -4127,12 +4134,11 @@ public class WindowManagerService extends IWindowManager.Stub
         synchronized (mWindowMap) {
             try {
                 watcher.asBinder().linkToDeath(dr, 0);
-                mRotationWatchers.add(new RotationWatcher(watcher, dr));
+                mRotationWatchers.add(new RotationWatcher(watcher, dr, displayId));
             } catch (RemoteException e) {
                 // Client died, no cleanup needed.
             }
 
-            // TODO(multi-display): Modify rotation watchers to include display id.
             return getDefaultDisplayRotation();
         }
     }
@@ -4143,11 +4149,11 @@ public class WindowManagerService extends IWindowManager.Stub
         synchronized (mWindowMap) {
             for (int i=0; i<mRotationWatchers.size(); i++) {
                 RotationWatcher rotationWatcher = mRotationWatchers.get(i);
-                if (watcherBinder == rotationWatcher.watcher.asBinder()) {
+                if (watcherBinder == rotationWatcher.mWatcher.asBinder()) {
                     RotationWatcher removed = mRotationWatchers.remove(i);
-                    IBinder binder = removed.watcher.asBinder();
+                    IBinder binder = removed.mWatcher.asBinder();
                     if (binder != null) {
-                        binder.unlinkToDeath(removed.deathRecipient, 0);
+                        binder.unlinkToDeath(removed.mDeathRecipient, 0);
                     }
                     i--;
                 }
index fb90ce0..1282349 100644 (file)
@@ -399,7 +399,7 @@ public class IWindowManagerImpl implements IWindowManager {
     }
 
     @Override
-    public int watchRotation(IRotationWatcher arg0) throws RemoteException {
+    public int watchRotation(IRotationWatcher arg0, int arg1) throws RemoteException {
         // TODO Auto-generated method stub
         return 0;
     }