summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chris Göllner <chrisgollner@google.com> 2023-09-05 14:50:36 +0100
committer Chris Göllner <chrisgollner@google.com> 2023-09-05 14:56:55 +0100
commit1f77cf96b297487e4937d75f396c9b24ef5aee8b (patch)
tree6d4a38f2b49f1bd2995ef005c94b37f5204d8c81
parent61e1769c1bf040318d3c004b2c38185a4c12ad97 (diff)
Lazily inject NotifPresenter & NotifActivStarter into CentralSurfaces.
This is needed to not crash after completing the partial screen sharing dialog in a secondary user. When the partial screen sharing dialog is launched from an application that is *not* in the primary user (e.g. it's launched from work profile), that dialog is started in a *secondary* SysUI process. This secondary SysUI process has a separate Dagger graph, and most of the Dagger graph is not instantiated on startup because it's not referenced, because only the CoreStartables labelled with `@PerUser` are started (and almost all of our CoreStartables are *not* per user). Once this very small Dagger graph is instantiated, InitController runs any post init tasks (of which there are none). Later, once the user completes the partial screen sharing dialog, MediaProjectionPermissionActivity launches an activity using ActivityStarterImpl. That class eventually triggers OpaEnabledDispatcher#dispatchUnchecked. That method requests CentralSurfaces, which means the CentralSurfaces part of the Dagger graph suddently gets instantiated after initial process startup. StatusBarNotificationPresenter is injected into CentralSurfaces, so the notification presenter is created. On the presenter's creation, it adds some post init tasks, but those tasks have been completed long ago, leading to the crash. This change updates the notif presenter to be injected *lazily* into CentralSurfaces, so that creating CentralSurfaces doesn't also create the notif presenter. Because this dialog doesn't use any notif presenter code directly, the presenter is never created and never requests post init tasks after init has finished. This change also makes the NotificationActivityStarter lazily injected because the activity starter also injects the presenter. Bug: 298099682 Test: Launch partial screen share dialog from work profile -> complete dialog -> verify no crash and verify via logging that StatusBarNotificationPresenter is never instantiated (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:2efc5dc7673f62a3dd47649adac1658095415d28) Merged-In: I3647d583623d6c4a6ddef60301d4a3da8dd9207a Change-Id: I001c89a772a35913c37bd3d47dc7988d8400a47f
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java28
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CentralSurfacesImplTest.java2
2 files changed, 16 insertions, 14 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java
index ccb87bf44dc8..a243356c8690 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java
@@ -624,7 +624,7 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
private final ActivityLaunchAnimator mActivityLaunchAnimator;
private NotificationLaunchAnimatorControllerProvider mNotificationAnimationProvider;
- private final NotificationPresenter mPresenter;
+ private final Lazy<NotificationPresenter> mPresenterLazy;
private NotificationActivityStarter mNotificationActivityStarter;
private final Lazy<NotificationShadeDepthController> mNotificationShadeDepthControllerLazy;
private final Optional<Bubbles> mBubblesOptional;
@@ -725,7 +725,8 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
Lazy<NotificationShadeWindowViewController> notificationShadeWindowViewControllerLazy,
NotificationShelfController notificationShelfController,
NotificationStackScrollLayoutController notificationStackScrollLayoutController,
- NotificationPresenter notificationPresenter,
+ // Lazy due to b/298099682.
+ Lazy<NotificationPresenter> notificationPresenterLazy,
NotificationExpansionRepository notificationExpansionRepository,
DozeParameters dozeParameters,
ScrimController scrimController,
@@ -833,7 +834,7 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
mStackScrollerController = notificationStackScrollLayoutController;
mStackScroller = mStackScrollerController.getView();
mNotifListContainer = mStackScrollerController.getNotificationListContainer();
- mPresenter = notificationPresenter;
+ mPresenterLazy = notificationPresenterLazy;
mNotificationExpansionRepository = notificationExpansionRepository;
mDozeServiceHost = dozeServiceHost;
mPowerManager = powerManager;
@@ -1556,9 +1557,9 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
mRemoteInputManager.addControllerCallback(mNotificationShadeWindowController);
mStackScrollerController.setNotificationActivityStarter(mNotificationActivityStarter);
mGutsManager.setNotificationActivityStarter(mNotificationActivityStarter);
- mShadeController.setNotificationPresenter(mPresenter);
+ mShadeController.setNotificationPresenter(mPresenterLazy.get());
mNotificationsController.initialize(
- mPresenter,
+ mPresenterLazy.get(),
mNotifListContainer,
mStackScrollerController.getNotifStackController(),
mNotificationActivityStarter);
@@ -1736,12 +1737,12 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
@Override
public boolean isDeviceInVrMode() {
- return mPresenter.isDeviceInVrMode();
+ return mPresenterLazy.get().isDeviceInVrMode();
}
@Override
public NotificationPresenter getPresenter() {
- return mPresenter;
+ return mPresenterLazy.get();
}
@VisibleForTesting
@@ -2148,7 +2149,7 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
String action = intent.getAction();
if (ACTION_FAKE_ARTWORK.equals(action)) {
if (DEBUG_MEDIA_FAKE_ARTWORK) {
- mPresenter.updateMediaMetaData(true, true);
+ mPresenterLazy.get().updateMediaMetaData(true, true);
}
}
}
@@ -2234,10 +2235,10 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
*/
boolean pinnedHeadsUp = mHeadsUpManager.hasPinnedHeadsUp();
boolean clearNotificationEffects =
- !mPresenter.isPresenterFullyCollapsed() && (mState == StatusBarState.SHADE
+ !mPresenterLazy.get().isPresenterFullyCollapsed() && (mState == StatusBarState.SHADE
|| mState == StatusBarState.SHADE_LOCKED);
int notificationLoad = mNotificationsController.getActiveNotificationsCount();
- if (pinnedHeadsUp && mPresenter.isPresenterFullyCollapsed()) {
+ if (pinnedHeadsUp && mPresenterLazy.get().isPresenterFullyCollapsed()) {
notificationLoad = 1;
}
final int finalNotificationLoad = notificationLoad;
@@ -2405,7 +2406,7 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
releaseGestureWakeLock();
runLaunchTransitionEndRunnable();
mKeyguardStateController.setLaunchTransitionFadingAway(false);
- mPresenter.updateMediaMetaData(true /* metaDataChanged */, true);
+ mPresenterLazy.get().updateMediaMetaData(true /* metaDataChanged */, true);
}
/**
@@ -2429,7 +2430,7 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
beforeFading.run();
}
updateScrimController();
- mPresenter.updateMediaMetaData(false, true);
+ mPresenterLazy.get().updateMediaMetaData(false, true);
mShadeSurface.resetAlpha();
mShadeSurface.fadeOut(
FADE_KEYGUARD_START_DELAY, FADE_KEYGUARD_DURATION,
@@ -3564,7 +3565,8 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
updateDozingState();
checkBarModes();
updateScrimController();
- mPresenter.updateMediaMetaData(false, mState != StatusBarState.KEYGUARD);
+ mPresenterLazy.get()
+ .updateMediaMetaData(false, mState != StatusBarState.KEYGUARD);
Trace.endSection();
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CentralSurfacesImplTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CentralSurfacesImplTest.java
index 39b294879450..de00747df4e2 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CentralSurfacesImplTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CentralSurfacesImplTest.java
@@ -516,7 +516,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
mNotificationShadeWindowViewControllerLazy,
mNotificationShelfController,
mStackScrollerController,
- mNotificationPresenter,
+ () -> mNotificationPresenter,
new NotificationExpansionRepository(),
mDozeParameters,
mScrimController,