Fix issue with Shell listeners being unbound if SysUI is restarted

- If SysUI is restarted (ie. during dev or a crash), the components
  registering the shell listeners may not be aware of this, and
  listener callbacks will not be re-registered.  Currently all the
  listeners are managed correctly (bound & later unbound) so we can
  just keep the active listener references to re-register if this
  happens.

Bug: 207142749
Test: Kill SysUI, start some apps and ensure Launcher still shows them
      in recents
Change-Id: I47665180bbff3a12b12686e2ca3063ecd188bb56
This commit is contained in:
Winson Chung committed 2021-12-03 04:38:26 +00:00
1 parent eb4b2d0147
commit e4dc13ac72
4 files changed
+61 -41

No files matched your search

@@ -83,14 +83,16 @@ public class SystemUiProxy implements ISystemUiProxy,
MAIN_EXECUTOR.execute(() -> clearProxy());
};
// Save the listeners passed into the proxy since when set/register these listeners,
// setProxy may not have been called, eg. OverviewProxyService is not connected yet.
private IPipAnimationListener mPendingPipAnimationListener;
private ISplitScreenListener mPendingSplitScreenListener;
private IStartingWindowListener mPendingStartingWindowListener;
private ISmartspaceCallback mPendingSmartspaceCallback;
private IRecentTasksListener mPendingRecentTasksListener;
private final ArrayList<RemoteTransitionCompat> mPendingRemoteTransitions = new ArrayList<>();
// Save the listeners passed into the proxy since OverviewProxyService may not have been bound
// yet, and we'll need to set/register these listeners with SysUI when they do. Note that it is
// up to the caller to clear the listeners to prevent leaks as these can be held indefinitely
// in case SysUI needs to rebind.
private IPipAnimationListener mPipAnimationListener;
private ISplitScreenListener mSplitScreenListener;
private IStartingWindowListener mStartingWindowListener;
private ISmartspaceCallback mSmartspaceCallback;
private IRecentTasksListener mRecentTasksListener;
private final ArrayList<RemoteTransitionCompat> mRemoteTransitions = new ArrayList<>();
// Used to dedupe calls to SystemUI
private int mLastShelfHeight;
@@ -167,29 +169,23 @@ public class SystemUiProxy implements ISystemUiProxy,
mRecentTasks = recentTasks;
linkToDeath();
// re-attach the listeners once missing due to setProxy has not been initialized yet.
if (mPendingPipAnimationListener != null && mPip != null) {
setPinnedStackAnimationListener(mPendingPipAnimationListener);
mPendingPipAnimationListener = null;
if (mPipAnimationListener != null && mPip != null) {
setPinnedStackAnimationListener(mPipAnimationListener);
}
if (mPendingSplitScreenListener != null && mSplitScreen != null) {
registerSplitScreenListener(mPendingSplitScreenListener);
mPendingSplitScreenListener = null;
if (mSplitScreenListener != null && mSplitScreen != null) {
registerSplitScreenListener(mSplitScreenListener);
}
if (mPendingStartingWindowListener != null && mStartingWindow != null) {
setStartingWindowListener(mPendingStartingWindowListener);
mPendingStartingWindowListener = null;
if (mStartingWindowListener != null && mStartingWindow != null) {
setStartingWindowListener(mStartingWindowListener);
}
if (mPendingSmartspaceCallback != null && mSmartspaceTransitionController != null) {
setSmartspaceCallback(mPendingSmartspaceCallback);
mPendingSmartspaceCallback = null;
if (mSmartspaceCallback != null && mSmartspaceTransitionController != null) {
setSmartspaceCallback(mSmartspaceCallback);
}
for (int i = mPendingRemoteTransitions.size() - 1; i >= 0; --i) {
registerRemoteTransition(mPendingRemoteTransitions.get(i));
for (int i = mRemoteTransitions.size() - 1; i >= 0; --i) {
registerRemoteTransition(mRemoteTransitions.get(i));
}
mPendingRemoteTransitions.clear();
if (mPendingRecentTasksListener != null && mRecentTasks != null) {
registerRecentTasksListener(mPendingRecentTasksListener);
mPendingRecentTasksListener = null;
if (mRecentTasksListener != null && mRecentTasks != null) {
registerRecentTasksListener(mRecentTasksListener);
}
if (mPendingSetNavButtonAlpha != null) {
@@ -513,9 +509,8 @@ public class SystemUiProxy implements ISystemUiProxy,
} catch (RemoteException e) {
Log.w(TAG, "Failed call setPinnedStackAnimationListener", e);
}
} else {
mPendingPipAnimationListener = listener;
}
mPipAnimationListener = listener;
}
public Rect startSwipePipToHome(ComponentName componentName, ActivityInfo activityInfo,
@@ -553,9 +548,8 @@ public class SystemUiProxy implements ISystemUiProxy,
} catch (RemoteException e) {
Log.w(TAG, "Failed call registerSplitScreenListener");
}
} else {
mPendingSplitScreenListener = listener;
}
mSplitScreenListener = listener;
}
public void unregisterSplitScreenListener(ISplitScreenListener listener) {
@@ -566,7 +560,7 @@ public class SystemUiProxy implements ISystemUiProxy,
Log.w(TAG, "Failed call unregisterSplitScreenListener");
}
}
mPendingSplitScreenListener = null;
mSplitScreenListener = null;
}
/** Start multiple tasks in split-screen simultaneously. */
@@ -687,8 +681,9 @@ public class SystemUiProxy implements ISystemUiProxy,
} catch (RemoteException e) {
Log.w(TAG, "Failed call registerRemoteTransition");
}
} else {
mPendingRemoteTransitions.add(remoteTransition);
}
if (!mRemoteTransitions.contains(remoteTransition)) {
mRemoteTransitions.add(remoteTransition);
}
}
@@ -700,7 +695,7 @@ public class SystemUiProxy implements ISystemUiProxy,
Log.w(TAG, "Failed call registerRemoteTransition");
}
}
mPendingRemoteTransitions.remove(remoteTransition);
mRemoteTransitions.remove(remoteTransition);
}
//
@@ -717,9 +712,8 @@ public class SystemUiProxy implements ISystemUiProxy,
} catch (RemoteException e) {
Log.w(TAG, "Failed call setStartingWindowListener", e);
}
} else {
mPendingStartingWindowListener = listener;
}
mStartingWindowListener = listener;
}
//
@@ -733,9 +727,8 @@ public class SystemUiProxy implements ISystemUiProxy,
} catch (RemoteException e) {
Log.w(TAG, "Failed call setStartingWindowListener", e);
}
} else {
mPendingSmartspaceCallback = callback;
}
mSmartspaceCallback = callback;
}
//
@@ -749,9 +742,8 @@ public class SystemUiProxy implements ISystemUiProxy,
} catch (RemoteException e) {
Log.w(TAG, "Failed call registerRecentTasksListener", e);
}
} else {
mPendingRecentTasksListener = listener;
}
mRecentTasksListener = listener;
}
public void unregisterRecentTasksListener(IRecentTasksListener listener) {
@@ -762,7 +754,7 @@ public class SystemUiProxy implements ISystemUiProxy,
Log.w(TAG, "Failed call unregisterRecentTasksListener");
}
}
mPendingRecentTasksListener = null;
mRecentTasksListener = null;
}
public ArrayList<GroupedRecentTaskInfo> getRecentTasks(int numTasks, int userId) {