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

Commit 376c6471 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Associate rotation watchers with displays"

parents b73ea727 35fa3c26
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
@@ -533,13 +533,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;

@@ -4076,11 +4080,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
@@ -4106,16 +4113,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);
                            }
@@ -4129,12 +4136,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();
        }
    }
@@ -4145,11 +4151,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