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

Commit 8228c296 authored by Steven Ng's avatar Steven Ng Committed by Android (Google) Code Review
Browse files

Merge "Fix the user ID check in note controller for updating note taking...

Merge "Fix the user ID check in note controller for updating note taking shortcuts" into udc-qpr-dev
parents 7786667a 834a12aa
Loading
Loading
Loading
Loading
+7 −1
Original line number Original line Diff line number Diff line
@@ -31,6 +31,7 @@ import android.content.Intent
import android.content.pm.PackageManager
import android.content.pm.PackageManager
import android.content.pm.ShortcutManager
import android.content.pm.ShortcutManager
import android.graphics.drawable.Icon
import android.graphics.drawable.Icon
import android.os.Process
import android.os.UserHandle
import android.os.UserHandle
import android.os.UserManager
import android.os.UserManager
import android.provider.Settings
import android.provider.Settings
@@ -317,7 +318,9 @@ constructor(
            return
            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)
            updateNoteTaskAsUserInternal(user)
        } else {
        } else {
            // TODO(b/278729185): Replace fire and forget service with a bounded service.
            // TODO(b/278729185): Replace fire and forget service with a bounded service.
@@ -354,6 +357,9 @@ constructor(
        updateNoteTaskAsUser(user)
        updateNoteTaskAsUser(user)
    }
    }


    // Returns the [UserHandle] that this class is running on.
    @VisibleForTesting internal fun getCurrentRunningUser(): UserHandle = Process.myUserHandle()

    private val SecureSettings.preferredUser: UserHandle
    private val SecureSettings.preferredUser: UserHandle
        get() {
        get() {
            val trackingUserId = userTracker.userHandle.identifier
            val trackingUserId = userTracker.userHandle.identifier
+3 −2
Original line number Original line Diff line number Diff line
@@ -702,9 +702,10 @@ internal class NoteTaskControllerTest : SysuiTestCase() {
    // region updateNoteTaskAsUser
    // region updateNoteTaskAsUser
    @Test
    @Test
    fun updateNoteTaskAsUser_sameUser_shouldUpdateShortcuts() {
    fun updateNoteTaskAsUser_sameUser_shouldUpdateShortcuts() {
        val user = userTracker.userHandle
        val user = UserHandle.CURRENT
        val controller = spy(createNoteTaskController())
        val controller = spy(createNoteTaskController())
        doNothing().whenever(controller).updateNoteTaskAsUserInternal(any())
        doNothing().whenever(controller).updateNoteTaskAsUserInternal(any())
        whenever(controller.getCurrentRunningUser()).thenReturn(user)


        controller.updateNoteTaskAsUser(user)
        controller.updateNoteTaskAsUser(user)


@@ -714,10 +715,10 @@ internal class NoteTaskControllerTest : SysuiTestCase() {


    @Test
    @Test
    fun updateNoteTaskAsUser_differentUser_shouldUpdateShortcutsInUserProcess() {
    fun updateNoteTaskAsUser_differentUser_shouldUpdateShortcutsInUserProcess() {
        // FakeUserTracker will default to UserHandle.SYSTEM.
        val user = UserHandle.CURRENT
        val user = UserHandle.CURRENT
        val controller = spy(createNoteTaskController(isEnabled = true))
        val controller = spy(createNoteTaskController(isEnabled = true))
        doNothing().whenever(controller).updateNoteTaskAsUserInternal(any())
        doNothing().whenever(controller).updateNoteTaskAsUserInternal(any())
        whenever(controller.getCurrentRunningUser()).thenReturn(UserHandle.SYSTEM)


        controller.updateNoteTaskAsUser(user)
        controller.updateNoteTaskAsUser(user)