Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 35fa3c26 authored by Andrii Kulian's avatar Andrii Kulian
Browse files

Associate rotation watchers with displays

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
parent ca6d48f3
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -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) {
                    }
                }
+2 −2
Original line number Diff line number Diff line
@@ -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.
+2 −1
Original line number Diff line number Diff line
@@ -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) {
+1 −1
Original line number Diff line number Diff line
@@ -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();
        }
+23 −17
Original line number Diff line number Diff line
@@ -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;

@@ -4074,11 +4078,14 @@ public class WindowManagerService extends IWindowManager.Stub
        }

        for (int i = mRotationWatchers.size() - 1; i >= 0; i--) {
            final RotationWatcher rotationWatcher = mRotationWatchers.get(i);
            if (rotationWatcher.mDisplayId == displayId) {
                try {
                mRotationWatchers.get(i).watcher.onRotationChanged(rotation);
                    rotationWatcher.mWatcher.onRotationChanged(rotation);
                } catch (RemoteException e) {
                }
            }
        }

        // TODO (multidisplay): Magnification is supported only for the default display.
        // Announce rotation only if we will not animate as we already have the
@@ -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--;
                }
Loading