diff options
| author | 2024-02-07 18:32:53 +0000 | |
|---|---|---|
| committer | 2024-02-07 18:32:53 +0000 | |
| commit | 64bf4a87341453f35e071bffd0a571016dfa9bc7 (patch) | |
| tree | e466580a3c8d3e90fa90b05df1c0c35f035153ee | |
| parent | 2f2b95a0f33087e50af3a616f3f569c9247f86da (diff) | |
| parent | 014062b383adcf41fbbad969d708f97f6072744b (diff) | |
Merge "Prevent SystemUISecondaryUserService from screwing up SystemUI." into main
14 files changed, 77 insertions, 12 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/CoreStartable.java b/packages/SystemUI/src/com/android/systemui/CoreStartable.java index 4c9782cdf36c..39e1c4150167 100644 --- a/packages/SystemUI/src/com/android/systemui/CoreStartable.java +++ b/packages/SystemUI/src/com/android/systemui/CoreStartable.java @@ -36,7 +36,7 @@ import java.io.PrintWriter; * If your CoreStartable depends on different CoreStartables starting before it, use a * {@link com.android.systemui.startable.Dependencies} annotation to list out those dependencies. * - * @see SystemUIApplication#startServicesIfNeeded() + * @see SystemUIApplication#startSystemUserServicesIfNeeded() */ public interface CoreStartable extends Dumpable { diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java index 8aae20651a10..15ef61ed5934 100644 --- a/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java +++ b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java @@ -42,6 +42,7 @@ import com.android.internal.protolog.common.ProtoLog; import com.android.systemui.dagger.GlobalRootComponent; import com.android.systemui.dagger.SysUIComponent; import com.android.systemui.dump.DumpManager; +import com.android.systemui.process.ProcessWrapper; import com.android.systemui.res.R; import com.android.systemui.startable.Dependencies; import com.android.systemui.statusbar.policy.ConfigurationController; @@ -77,6 +78,7 @@ public class SystemUIApplication extends Application implements private SystemUIAppComponentFactoryBase.ContextAvailableCallback mContextAvailableCallback; private SysUIComponent mSysUIComponent; private SystemUIInitializer mInitializer; + private ProcessWrapper mProcessWrapper; public SystemUIApplication() { super(); @@ -115,6 +117,7 @@ public class SystemUIApplication extends Application implements // Enable Looper trace points. // This allows us to see Handler callbacks on traces. rootComponent.getMainLooper().setTraceTag(Trace.TRACE_TAG_APP); + mProcessWrapper = rootComponent.getProcessWrapper(); // Set the application theme that is inherited by all services. Note that setting the // application theme in the manifest does only work for activities. Keep this in sync with @@ -132,7 +135,7 @@ public class SystemUIApplication extends Application implements View.setTraceLayoutSteps(true); } - if (rootComponent.getProcessWrapper().isSystemUser()) { + if (mProcessWrapper.isSystemUser()) { IntentFilter bootCompletedFilter = new IntentFilter(Intent.ACTION_LOCKED_BOOT_COMPLETED); bootCompletedFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); @@ -199,7 +202,11 @@ public class SystemUIApplication extends Application implements * <p>This method must only be called from the main thread.</p> */ - public void startServicesIfNeeded() { + public void startSystemUserServicesIfNeeded() { + if (!mProcessWrapper.isSystemUser()) { + Log.wtf(TAG, "Tried starting SystemUser services on non-SystemUser"); + return; // Per-user startables are handled in #startSystemUserServicesIfNeeded. + } final String vendorComponent = mInitializer.getVendorComponent(getResources()); // Sort the startables so that we get a deterministic ordering. @@ -219,6 +226,9 @@ public class SystemUIApplication extends Application implements * <p>This method must only be called from the main thread.</p> */ void startSecondaryUserServicesIfNeeded() { + if (mProcessWrapper.isSystemUser()) { + return; // Per-user startables are handled in #startSystemUserServicesIfNeeded. + } // Sort the startables so that we get a deterministic ordering. Map<Class<?>, Provider<CoreStartable>> sortedStartables = new TreeMap<>( Comparator.comparing(Class::getName)); diff --git a/packages/SystemUI/src/com/android/systemui/SystemUISecondaryUserService.java b/packages/SystemUI/src/com/android/systemui/SystemUISecondaryUserService.java index f4ec6f75b06b..407f7643d9d8 100644 --- a/packages/SystemUI/src/com/android/systemui/SystemUISecondaryUserService.java +++ b/packages/SystemUI/src/com/android/systemui/SystemUISecondaryUserService.java @@ -19,12 +19,31 @@ package com.android.systemui; import android.app.Service; import android.content.Intent; import android.os.IBinder; +import android.util.Log; + +import com.android.systemui.process.ProcessWrapper; + +import javax.inject.Inject; public class SystemUISecondaryUserService extends Service { + private static final String TAG = "SysUISecondaryService"; + + private final ProcessWrapper mProcessWrapper; + + @Inject + SystemUISecondaryUserService(ProcessWrapper processWrapper) { + mProcessWrapper = processWrapper; + } + @Override public void onCreate() { super.onCreate(); + if (mProcessWrapper.isSystemUser()) { + Log.w(TAG, "SecondaryServices started for System User. Stopping it."); + stopSelf(); + return; + } ((SystemUIApplication) getApplication()).startSecondaryUserServicesIfNeeded(); } diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIService.java b/packages/SystemUI/src/com/android/systemui/SystemUIService.java index 76c228252484..b26be0c74ece 100644 --- a/packages/SystemUI/src/com/android/systemui/SystemUIService.java +++ b/packages/SystemUI/src/com/android/systemui/SystemUIService.java @@ -77,7 +77,7 @@ public class SystemUIService extends Service { super.onCreate(); // Start all of SystemUI - ((SystemUIApplication) getApplication()).startServicesIfNeeded(); + ((SystemUIApplication) getApplication()).startSystemUserServicesIfNeeded(); // Finish initializing dump logic mLogBufferFreezer.attach(mBroadcastDispatcher); diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java index 28fd9a994f8a..1720de880cbd 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java @@ -17,6 +17,7 @@ package com.android.systemui.dagger; import android.app.INotificationManager; +import android.app.Service; import android.content.Context; import android.service.dreams.IDreamManager; @@ -28,6 +29,7 @@ import com.android.keyguard.dagger.KeyguardBouncerComponent; import com.android.systemui.BootCompleteCache; import com.android.systemui.BootCompleteCacheImpl; import com.android.systemui.CameraProtectionModule; +import com.android.systemui.SystemUISecondaryUserService; import com.android.systemui.accessibility.AccessibilityModule; import com.android.systemui.accessibility.data.repository.AccessibilityRepositoryModule; import com.android.systemui.appops.dagger.AppOpsModule; @@ -150,6 +152,8 @@ import dagger.Binds; import dagger.BindsOptionalOf; import dagger.Module; import dagger.Provides; +import dagger.multibindings.ClassKey; +import dagger.multibindings.IntoMap; import java.util.Collections; import java.util.Optional; @@ -384,4 +388,9 @@ public abstract class SystemUIModule { @Binds abstract LargeScreenShadeInterpolator largeScreensShadeInterpolator( LargeScreenShadeInterpolatorImpl impl); + + @Binds + @IntoMap + @ClassKey(SystemUISecondaryUserService.class) + abstract Service bindsSystemUISecondaryUserService(SystemUISecondaryUserService service); } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java index 4cabd70cb142..2e233d8e5dd2 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java @@ -327,7 +327,7 @@ public class KeyguardService extends Service { @Override public void onCreate() { - ((SystemUIApplication) getApplication()).startServicesIfNeeded(); + ((SystemUIApplication) getApplication()).startSystemUserServicesIfNeeded(); if (mShellTransitions == null || !Transitions.ENABLE_SHELL_TRANSITIONS) { RemoteAnimationDefinition definition = new RemoteAnimationDefinition(); diff --git a/packages/SystemUI/src/com/android/systemui/process/ProcessWrapper.java b/packages/SystemUI/src/com/android/systemui/process/ProcessWrapper.java index 27510720ae2f..3671dd439239 100644 --- a/packages/SystemUI/src/com/android/systemui/process/ProcessWrapper.java +++ b/packages/SystemUI/src/com/android/systemui/process/ProcessWrapper.java @@ -16,6 +16,9 @@ package com.android.systemui.process; +import android.os.Process; +import android.os.UserHandle; + import javax.inject.Inject; /** @@ -30,6 +33,15 @@ public class ProcessWrapper { * Returns {@code true} if System User is running the current process. */ public boolean isSystemUser() { - return android.os.Process.myUserHandle().isSystem(); + return myUserHandle().isSystem(); + } + + /** + * Returns {@link UserHandle} as returned statically by {@link Process#myUserHandle()}. + * + * Please strongly consider using {@link com.android.systemui.settings.UserTracker} instead. + */ + public UserHandle myUserHandle() { + return Process.myUserHandle(); } } diff --git a/packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractor.kt b/packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractor.kt index c170eb567344..a122311e3b34 100644 --- a/packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractor.kt @@ -27,7 +27,6 @@ import android.content.pm.UserInfo import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable import android.graphics.drawable.Icon -import android.os.Process import android.os.RemoteException import android.os.UserHandle import android.os.UserManager @@ -50,6 +49,7 @@ import com.android.systemui.flags.FeatureFlags import com.android.systemui.flags.Flags import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor import com.android.systemui.plugins.ActivityStarter +import com.android.systemui.process.ProcessWrapper import com.android.systemui.qs.user.UserSwitchDialogController import com.android.systemui.res.R import com.android.systemui.telephony.domain.interactor.TelephonyInteractor @@ -108,6 +108,7 @@ constructor( private val guestUserInteractor: GuestUserInteractor, private val uiEventLogger: UiEventLogger, private val userRestrictionChecker: UserRestrictionChecker, + private val processWrapper: ProcessWrapper ) { /** * Defines interface for classes that can be notified when the state of users on the device is @@ -669,7 +670,7 @@ constructor( // Connect to the new secondary user's service (purely to ensure that a persistent // SystemUI application is created for that user) - if (userId != Process.myUserHandle().identifier) { + if (userId != processWrapper.myUserHandle().identifier && !processWrapper.isSystemUser) { applicationContext.startServiceAsUser( intent, UserHandle.of(userId), diff --git a/packages/SystemUI/tests/src/com/android/systemui/SystemUIApplicationTest.kt b/packages/SystemUI/tests/src/com/android/systemui/SystemUIApplicationTest.kt index 202d9ce27a34..e157fc508f87 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/SystemUIApplicationTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/SystemUIApplicationTest.kt @@ -91,7 +91,7 @@ class SystemUIApplicationTest : SysuiTestCase() { whenever(sysuiComponent.startables) .thenReturn(mutableMapOf(StartableA::class.java to Provider { startableA })) app.onCreate() - app.startServicesIfNeeded() + app.startSystemUserServicesIfNeeded() assertThat(startableA.started).isTrue() } @@ -105,7 +105,7 @@ class SystemUIApplicationTest : SysuiTestCase() { ) ) app.onCreate() - app.startServicesIfNeeded() + app.startSystemUserServicesIfNeeded() assertThat(startableA.started).isTrue() assertThat(startableB.started).isTrue() } @@ -121,7 +121,7 @@ class SystemUIApplicationTest : SysuiTestCase() { ) ) app.onCreate() - app.startServicesIfNeeded() + app.startSystemUserServicesIfNeeded() assertThat(startableA.started).isTrue() assertThat(startableB.started).isTrue() assertThat(startableC.started).isTrue() @@ -141,7 +141,7 @@ class SystemUIApplicationTest : SysuiTestCase() { ) ) app.onCreate() - app.startServicesIfNeeded() + app.startSystemUserServicesIfNeeded() assertThat(startableA.started).isTrue() assertThat(startableB.started).isTrue() assertThat(startableC.started).isTrue() diff --git a/packages/SystemUI/tests/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractorTest.kt index b6a033a7c5f6..1b4385148f88 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractorTest.kt @@ -46,6 +46,7 @@ import com.android.systemui.keyguard.domain.interactor.KeyguardInteractorFactory import com.android.systemui.kosmos.testDispatcher import com.android.systemui.kosmos.testScope import com.android.systemui.plugins.ActivityStarter +import com.android.systemui.process.processWrapper import com.android.systemui.qs.user.UserSwitchDialogController import com.android.systemui.res.R import com.android.systemui.statusbar.policy.DeviceProvisionedController @@ -1147,6 +1148,7 @@ class UserSwitcherInteractorTest : SysuiTestCase() { uiEventLogger = uiEventLogger, featureFlags = kosmos.fakeFeatureFlagsClassic, userRestrictionChecker = mock(), + processWrapper = kosmos.processWrapper, ) } diff --git a/packages/SystemUI/tests/src/com/android/systemui/user/ui/viewmodel/StatusBarUserChipViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/user/ui/viewmodel/StatusBarUserChipViewModelTest.kt index 21d4549c904d..661837bdb1e4 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/user/ui/viewmodel/StatusBarUserChipViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/user/ui/viewmodel/StatusBarUserChipViewModelTest.kt @@ -34,6 +34,7 @@ import com.android.systemui.flags.FakeFeatureFlags import com.android.systemui.flags.Flags import com.android.systemui.keyguard.domain.interactor.KeyguardInteractorFactory import com.android.systemui.plugins.ActivityStarter +import com.android.systemui.process.ProcessWrapperFake import com.android.systemui.statusbar.policy.DeviceProvisionedController import com.android.systemui.telephony.data.repository.FakeTelephonyRepository import com.android.systemui.telephony.domain.interactor.TelephonyInteractor @@ -264,6 +265,7 @@ class StatusBarUserChipViewModelTest : SysuiTestCase() { guestUserInteractor = guestUserInteractor, uiEventLogger = uiEventLogger, userRestrictionChecker = mock(), + processWrapper = ProcessWrapperFake() ) ) } diff --git a/packages/SystemUI/tests/src/com/android/systemui/user/ui/viewmodel/UserSwitcherViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/user/ui/viewmodel/UserSwitcherViewModelTest.kt index d0804be81072..5661e202d134 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/user/ui/viewmodel/UserSwitcherViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/user/ui/viewmodel/UserSwitcherViewModelTest.kt @@ -34,6 +34,7 @@ import com.android.systemui.flags.Flags import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository import com.android.systemui.keyguard.domain.interactor.KeyguardInteractorFactory import com.android.systemui.plugins.ActivityStarter +import com.android.systemui.process.ProcessWrapperFake import com.android.systemui.statusbar.policy.DeviceProvisionedController import com.android.systemui.telephony.data.repository.FakeTelephonyRepository import com.android.systemui.telephony.domain.interactor.TelephonyInteractor @@ -176,6 +177,7 @@ class UserSwitcherViewModelTest : SysuiTestCase() { guestUserInteractor = guestUserInteractor, uiEventLogger = uiEventLogger, userRestrictionChecker = mock(), + processWrapper = ProcessWrapperFake() ), guestUserInteractor = guestUserInteractor, ) diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/process/ProcessWrapperFake.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/process/ProcessWrapperFake.kt index 9841778f835b..dee3644e95bd 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/process/ProcessWrapperFake.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/process/ProcessWrapperFake.kt @@ -16,11 +16,17 @@ package com.android.systemui.process +import android.os.UserHandle + class ProcessWrapperFake : ProcessWrapper() { var systemUser: Boolean = false + var userHandle: UserHandle = UserHandle.getUserHandleForUid(0) + override fun isSystemUser(): Boolean { return systemUser } + + override fun myUserHandle() = userHandle } diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractorKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractorKosmos.kt index 4e2dc7af8cb4..1504df4ef6d0 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractorKosmos.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractorKosmos.kt @@ -28,6 +28,7 @@ import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.applicationCoroutineScope import com.android.systemui.kosmos.testDispatcher import com.android.systemui.plugins.activityStarter +import com.android.systemui.process.processWrapper import com.android.systemui.telephony.domain.interactor.telephonyInteractor import com.android.systemui.user.data.repository.userRepository import com.android.systemui.utils.userRestrictionChecker @@ -53,5 +54,6 @@ val Kosmos.userSwitcherInteractor by guestUserInteractor = guestUserInteractor, uiEventLogger = uiEventLogger, userRestrictionChecker = userRestrictionChecker, + processWrapper = processWrapper, ) } |