From 834a12aacf0433776a03b951f49028133ee5cfe7 Mon Sep 17 00:00:00 2001 From: Steven Ng Date: Mon, 31 Jul 2023 19:25:19 +0100 Subject: [PATCH] Fix the user ID check in note controller for updating note taking shortcuts Test: Run NoteTaskControllerTest Fix: 293020892 Change-Id: Iea66f85d2ace31e927a38197016cc2f960e03153 --- .../com/android/systemui/notetask/NoteTaskController.kt | 8 +++++++- .../android/systemui/notetask/NoteTaskControllerTest.kt | 5 +++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskController.kt b/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskController.kt index 2adc211ef23fe..0842fe0dd764c 100644 --- a/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskController.kt +++ b/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskController.kt @@ -31,6 +31,7 @@ import android.content.Intent import android.content.pm.PackageManager import android.content.pm.ShortcutManager import android.graphics.drawable.Icon +import android.os.Process import android.os.UserHandle import android.os.UserManager import android.provider.Settings @@ -317,7 +318,9 @@ constructor( return } - if (user == userTracker.userHandle) { + // When switched to a secondary user, the sysUI is still running in the main user, we will + // need to update the shortcut in the secondary user. + if (user == getCurrentRunningUser()) { updateNoteTaskAsUserInternal(user) } else { // TODO(b/278729185): Replace fire and forget service with a bounded service. @@ -354,6 +357,9 @@ constructor( updateNoteTaskAsUser(user) } + // Returns the [UserHandle] that this class is running on. + @VisibleForTesting internal fun getCurrentRunningUser(): UserHandle = Process.myUserHandle() + private val SecureSettings.preferredUser: UserHandle get() { val trackingUserId = userTracker.userHandle.identifier diff --git a/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt index c65a2d36e2237..d933b57e8e153 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt @@ -702,9 +702,10 @@ internal class NoteTaskControllerTest : SysuiTestCase() { // region updateNoteTaskAsUser @Test fun updateNoteTaskAsUser_sameUser_shouldUpdateShortcuts() { - val user = userTracker.userHandle + val user = UserHandle.CURRENT val controller = spy(createNoteTaskController()) doNothing().whenever(controller).updateNoteTaskAsUserInternal(any()) + whenever(controller.getCurrentRunningUser()).thenReturn(user) controller.updateNoteTaskAsUser(user) @@ -714,10 +715,10 @@ internal class NoteTaskControllerTest : SysuiTestCase() { @Test fun updateNoteTaskAsUser_differentUser_shouldUpdateShortcutsInUserProcess() { - // FakeUserTracker will default to UserHandle.SYSTEM. val user = UserHandle.CURRENT val controller = spy(createNoteTaskController(isEnabled = true)) doNothing().whenever(controller).updateNoteTaskAsUserInternal(any()) + whenever(controller.getCurrentRunningUser()).thenReturn(UserHandle.SYSTEM) controller.updateNoteTaskAsUser(user)