From 249a06ba04b7bdf1a7bc0d1bc5658a7787d19ff4 Mon Sep 17 00:00:00 2001 From: Evan Rosky Date: Fri, 18 Jun 2021 21:00:15 -0700 Subject: [PATCH] Register binder-depth per remote animation Was just clearing all registered remotes. However, not all remotes are from the same process, so things can get messed-up (since we aren't relaunching the non-crashed binders, they won't re-register). This is useful both for robustness as well as making that failing tests don't break all subsequent tests. This makes a death recipient for each remote. Bug: 183993924 Test: crash launcher, make sure remote keyguard transition still works. Change-Id: Idbec7ff72afd9bac974e7dbb1a067ad237606bd7 --- .../transition/RemoteTransitionHandler.java | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/RemoteTransitionHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/RemoteTransitionHandler.java index e67186fcf6408..f432049f44f63 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/RemoteTransitionHandler.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/RemoteTransitionHandler.java @@ -56,14 +56,7 @@ public class RemoteTransitionHandler implements Transitions.TransitionHandler { private final ArrayList> mFilters = new ArrayList<>(); - private final IBinder.DeathRecipient mTransitionDeathRecipient = - new IBinder.DeathRecipient() { - @Override - @BinderThread - public void binderDied() { - mMainExecutor.execute(() -> mFilters.clear()); - } - }; + private final ArrayMap mDeathHandlers = new ArrayMap<>(); RemoteTransitionHandler(@NonNull ShellExecutor mainExecutor) { mMainExecutor = mainExecutor; @@ -71,7 +64,9 @@ public class RemoteTransitionHandler implements Transitions.TransitionHandler { void addFiltered(TransitionFilter filter, IRemoteTransition remote) { try { - remote.asBinder().linkToDeath(mTransitionDeathRecipient, 0 /* flags */); + RemoteDeathHandler handler = new RemoteDeathHandler(remote.asBinder()); + remote.asBinder().linkToDeath(handler, 0 /* flags */); + mDeathHandlers.put(remote.asBinder(), handler); } catch (RemoteException e) { Slog.e(TAG, "Failed to link to death"); return; @@ -88,7 +83,8 @@ public class RemoteTransitionHandler implements Transitions.TransitionHandler { } } if (removed) { - remote.asBinder().unlinkToDeath(mTransitionDeathRecipient, 0 /* flags */); + RemoteDeathHandler handler = mDeathHandlers.remove(remote.asBinder()); + remote.asBinder().unlinkToDeath(handler, 0 /* flags */); } } @@ -206,4 +202,25 @@ public class RemoteTransitionHandler implements Transitions.TransitionHandler { + " for %s: %s", transition, remote); return new WindowContainerTransaction(); } + + /** NOTE: binder deaths can alter the filter order */ + private class RemoteDeathHandler implements IBinder.DeathRecipient { + private final IBinder mRemote; + + RemoteDeathHandler(IBinder remote) { + mRemote = remote; + } + + @Override + @BinderThread + public void binderDied() { + mMainExecutor.execute(() -> { + for (int i = mFilters.size() - 1; i >= 0; --i) { + if (mRemote.equals(mFilters.get(i).second.asBinder())) { + mFilters.remove(i); + } + } + }); + } + } }