diff options
| author | 2023-04-06 09:22:48 +0000 | |
|---|---|---|
| committer | 2023-04-06 09:22:48 +0000 | |
| commit | 508f03b2503605db06aa8cf1bf9157cb1b00876c (patch) | |
| tree | 580b09b951c6e88314c572becc8a2c760c17e5a3 | |
| parent | ab9ca8fe9419dbbeb4f5700826c7e92ce85c048b (diff) | |
| parent | 43e79b2dcb5c3eb7aa1b700efef6baf086cbacc7 (diff) | |
Merge "Replace the main user look up with UserManager#getMainUser" into udc-dev
2 files changed, 31 insertions, 5 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/notetask/shortcut/LaunchNoteTaskActivity.kt b/packages/SystemUI/src/com/android/systemui/notetask/shortcut/LaunchNoteTaskActivity.kt index 44855fb7c8cc..0f38d32e0b64 100644 --- a/packages/SystemUI/src/com/android/systemui/notetask/shortcut/LaunchNoteTaskActivity.kt +++ b/packages/SystemUI/src/com/android/systemui/notetask/shortcut/LaunchNoteTaskActivity.kt @@ -18,9 +18,11 @@ package com.android.systemui.notetask.shortcut import android.content.Context import android.content.Intent -import android.content.pm.UserInfo +import android.os.Build import android.os.Bundle +import android.os.UserHandle import android.os.UserManager +import android.util.Log import androidx.activity.ComponentActivity import com.android.systemui.notetask.NoteTaskController import com.android.systemui.notetask.NoteTaskEntryPoint @@ -63,9 +65,13 @@ constructor( // | Bubble#showOrHideAppBubble | <-------------- // | (with WP user ID) | // ---------------------------- - val mainUser: UserInfo? = userTracker.userProfiles.firstOrNull { it.isMain } - if (userManager.isManagedProfile && mainUser != null) { - controller.startNoteTaskProxyActivityForUser(mainUser.userHandle) + val mainUser: UserHandle? = userManager.mainUser + if (userManager.isManagedProfile) { + if (mainUser == null) { + logDebug { "Can't find the main user. Skipping the notes app launch." } + } else { + controller.startNoteTaskProxyActivityForUser(mainUser) + } } else { controller.showNoteTask(entryPoint = NoteTaskEntryPoint.WIDGET_PICKER_SHORTCUT) } @@ -83,3 +89,8 @@ constructor( } } } + +/** [Log.println] a [Log.DEBUG] message, only when [Build.IS_DEBUGGABLE]. */ +private inline fun Any.logDebug(message: () -> String) { + if (Build.IS_DEBUGGABLE) Log.d(this::class.java.simpleName.orEmpty(), message()) +} diff --git a/packages/SystemUI/tests/src/com/android/systemui/notetask/shortcut/LaunchNoteTaskActivityTest.kt b/packages/SystemUI/tests/src/com/android/systemui/notetask/shortcut/LaunchNoteTaskActivityTest.kt index c96853d1a406..a0c376ff1a1c 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/notetask/shortcut/LaunchNoteTaskActivityTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/notetask/shortcut/LaunchNoteTaskActivityTest.kt @@ -30,6 +30,7 @@ import com.android.systemui.SysuiTestCase import com.android.systemui.notetask.NoteTaskController import com.android.systemui.notetask.NoteTaskEntryPoint import com.android.systemui.settings.FakeUserTracker +import com.android.systemui.util.mockito.any import com.android.systemui.util.mockito.eq import com.android.systemui.util.mockito.whenever import org.junit.After @@ -38,6 +39,7 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mock +import org.mockito.Mockito.never import org.mockito.MockitoAnnotations @RunWith(AndroidTestingRunner::class) @@ -86,15 +88,28 @@ class LaunchNoteTaskActivityTest : SysuiTestCase() { @Test fun startActivityOnWorkProfileUser_shouldLaunchProxyActivity() { + val mainUserHandle: UserHandle = mainUser.userHandle userTracker.set(listOf(mainUser, workProfileUser), selectedUserIndex = 1) whenever(userManager.isManagedProfile).thenReturn(true) + whenever(userManager.mainUser).thenReturn(mainUserHandle) activityRule.launchActivity(/* startIntent= */ null) - val mainUserHandle: UserHandle = mainUser.userHandle verify(noteTaskController).startNoteTaskProxyActivityForUser(eq(mainUserHandle)) } + @Test + fun startActivityOnWorkProfileUser_noMainUser_shouldNotLaunch() { + userTracker.set(listOf(mainUser, workProfileUser), selectedUserIndex = 1) + whenever(userManager.isManagedProfile).thenReturn(true) + whenever(userManager.mainUser).thenReturn(null) + + activityRule.launchActivity(/* startIntent= */ null) + + verify(noteTaskController, never()).showNoteTask(any()) + verify(noteTaskController, never()).startNoteTaskProxyActivityForUser(any()) + } + private companion object { val mainUser = UserInfo(/* id= */ 0, /* name= */ "primary", /* flags= */ UserInfo.FLAG_MAIN) val workProfileUser = |