Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 834a12aa authored by Steven Ng's avatar Steven Ng
Browse files

Fix the user ID check in note controller for updating note taking shortcuts

Test: Run NoteTaskControllerTest
Fix: 293020892
Change-Id: Iea66f85d2ace31e927a38197016cc2f960e03153
parent d95ea68d
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -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
+3 −2
Original line number Diff line number Diff line
@@ -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)