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

Commit e08ce731 authored by Vania Januar's avatar Vania Januar Committed by Android (Google) Code Review
Browse files

Merge "Allow setting of preferred user profile to open Notes role" into udc-qpr-dev

parents 7187216c 222bcd66
Loading
Loading
Loading
Loading
+8 −0
Original line number Original line Diff line number Diff line
@@ -7485,6 +7485,14 @@ public final class Settings {
        @SuppressLint("NoSettingsProvider")
        @SuppressLint("NoSettingsProvider")
        public static final String STYLUS_BUTTONS_ENABLED = "stylus_buttons_enabled";
        public static final String STYLUS_BUTTONS_ENABLED = "stylus_buttons_enabled";
        /**
         * Preferred default user profile to use with the notes task button shortcut.
         *
         * @hide
         */
        @SuppressLint("NoSettingsProvider")
        public static final String DEFAULT_NOTE_TASK_PROFILE = "default_note_task_profile";
        /**
        /**
         * Host name and port for global http proxy. Uses ':' seperator for
         * Host name and port for global http proxy. Uses ':' seperator for
         * between host and port.
         * between host and port.
+1 −0
Original line number Original line Diff line number Diff line
@@ -727,6 +727,7 @@ public class SettingsBackupTest {
                 Settings.Secure.CONNECTIVITY_RELEASE_PENDING_INTENT_DELAY_MS,
                 Settings.Secure.CONNECTIVITY_RELEASE_PENDING_INTENT_DELAY_MS,
                 Settings.Secure.CONTENT_CAPTURE_ENABLED,
                 Settings.Secure.CONTENT_CAPTURE_ENABLED,
                 Settings.Secure.DEFAULT_INPUT_METHOD,
                 Settings.Secure.DEFAULT_INPUT_METHOD,
                 Settings.Secure.DEFAULT_NOTE_TASK_PROFILE,
                 Settings.Secure.DEVICE_PAIRED,
                 Settings.Secure.DEVICE_PAIRED,
                 Settings.Secure.DIALER_DEFAULT_APPLICATION,
                 Settings.Secure.DIALER_DEFAULT_APPLICATION,
                 Settings.Secure.DISABLED_PRINT_SERVICES,
                 Settings.Secure.DISABLED_PRINT_SERVICES,
+14 −1
Original line number Original line Diff line number Diff line
@@ -33,6 +33,7 @@ import android.content.pm.ShortcutManager
import android.graphics.drawable.Icon
import android.graphics.drawable.Icon
import android.os.UserHandle
import android.os.UserHandle
import android.os.UserManager
import android.os.UserManager
import android.provider.Settings
import android.widget.Toast
import android.widget.Toast
import androidx.annotation.VisibleForTesting
import androidx.annotation.VisibleForTesting
import com.android.systemui.R
import com.android.systemui.R
@@ -46,6 +47,7 @@ import com.android.systemui.notetask.shortcut.LaunchNoteTaskManagedProfileProxyA
import com.android.systemui.settings.UserTracker
import com.android.systemui.settings.UserTracker
import com.android.systemui.shared.system.ActivityManagerKt.isInForeground
import com.android.systemui.shared.system.ActivityManagerKt.isInForeground
import com.android.systemui.util.kotlin.getOrNull
import com.android.systemui.util.kotlin.getOrNull
import com.android.systemui.util.settings.SecureSettings
import com.android.wm.shell.bubbles.Bubble
import com.android.wm.shell.bubbles.Bubble
import com.android.wm.shell.bubbles.Bubbles
import com.android.wm.shell.bubbles.Bubbles
import com.android.wm.shell.bubbles.Bubbles.BubbleExpandListener
import com.android.wm.shell.bubbles.Bubbles.BubbleExpandListener
@@ -76,6 +78,7 @@ constructor(
    @NoteTaskEnabledKey private val isEnabled: Boolean,
    @NoteTaskEnabledKey private val isEnabled: Boolean,
    private val devicePolicyManager: DevicePolicyManager,
    private val devicePolicyManager: DevicePolicyManager,
    private val userTracker: UserTracker,
    private val userTracker: UserTracker,
    private val secureSettings: SecureSettings,
) {
) {


    @VisibleForTesting val infoReference = AtomicReference<NoteTaskInfo?>()
    @VisibleForTesting val infoReference = AtomicReference<NoteTaskInfo?>()
@@ -146,7 +149,7 @@ constructor(
            userTracker.userProfiles.firstOrNull { userManager.isManagedProfile(it.id) }?.userHandle
            userTracker.userProfiles.firstOrNull { userManager.isManagedProfile(it.id) }?.userHandle
                ?: userTracker.userHandle
                ?: userTracker.userHandle
        } else {
        } else {
            userTracker.userHandle
            secureSettings.preferredUser
        }
        }


    /**
    /**
@@ -324,6 +327,16 @@ constructor(
        }
        }
    }
    }


    private val SecureSettings.preferredUser: UserHandle
        get() {
            val userId =
                secureSettings.getInt(
                    Settings.Secure.DEFAULT_NOTE_TASK_PROFILE,
                    userTracker.userHandle.identifier,
                )
            return UserHandle.of(userId)
        }

    companion object {
    companion object {
        val TAG = NoteTaskController::class.simpleName.orEmpty()
        val TAG = NoteTaskController::class.simpleName.orEmpty()


+43 −0
Original line number Original line Diff line number Diff line
@@ -42,6 +42,7 @@ import android.content.pm.UserInfo
import android.graphics.drawable.Icon
import android.graphics.drawable.Icon
import android.os.UserHandle
import android.os.UserHandle
import android.os.UserManager
import android.os.UserManager
import android.provider.Settings
import androidx.test.ext.truth.content.IntentSubject.assertThat
import androidx.test.ext.truth.content.IntentSubject.assertThat
import androidx.test.filters.SmallTest
import androidx.test.filters.SmallTest
import androidx.test.runner.AndroidJUnit4
import androidx.test.runner.AndroidJUnit4
@@ -63,6 +64,7 @@ import com.android.systemui.util.mockito.argumentCaptor
import com.android.systemui.util.mockito.capture
import com.android.systemui.util.mockito.capture
import com.android.systemui.util.mockito.eq
import com.android.systemui.util.mockito.eq
import com.android.systemui.util.mockito.whenever
import com.android.systemui.util.mockito.whenever
import com.android.systemui.util.settings.SecureSettings
import com.android.wm.shell.bubbles.Bubble
import com.android.wm.shell.bubbles.Bubble
import com.android.wm.shell.bubbles.Bubbles
import com.android.wm.shell.bubbles.Bubbles
import com.google.common.truth.Truth.assertThat
import com.google.common.truth.Truth.assertThat
@@ -97,6 +99,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() {
    @Mock private lateinit var shortcutManager: ShortcutManager
    @Mock private lateinit var shortcutManager: ShortcutManager
    @Mock private lateinit var activityManager: ActivityManager
    @Mock private lateinit var activityManager: ActivityManager
    @Mock private lateinit var devicePolicyManager: DevicePolicyManager
    @Mock private lateinit var devicePolicyManager: DevicePolicyManager
    @Mock private lateinit var secureSettings: SecureSettings
    private val userTracker = FakeUserTracker()
    private val userTracker = FakeUserTracker()


    @Before
    @Before
@@ -122,6 +125,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() {
        whenever(activityManager.getRunningTasks(anyInt())).thenReturn(emptyList())
        whenever(activityManager.getRunningTasks(anyInt())).thenReturn(emptyList())
        whenever(userManager.isManagedProfile(workUserInfo.id)).thenReturn(true)
        whenever(userManager.isManagedProfile(workUserInfo.id)).thenReturn(true)
        whenever(context.resources).thenReturn(getContext().resources)
        whenever(context.resources).thenReturn(getContext().resources)
        whenever(secureSettings.userTracker).thenReturn(userTracker)
    }
    }


    private fun createNoteTaskController(
    private fun createNoteTaskController(
@@ -141,6 +145,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() {
            roleManager = roleManager,
            roleManager = roleManager,
            shortcutManager = shortcutManager,
            shortcutManager = shortcutManager,
            activityManager = activityManager,
            activityManager = activityManager,
            secureSettings = secureSettings,
        )
        )


    // region onBubbleExpandChanged
    // region onBubbleExpandChanged
@@ -250,6 +255,44 @@ internal class NoteTaskControllerTest : SysuiTestCase() {
        verifyZeroInteractions(bubbles)
        verifyZeroInteractions(bubbles)
    }
    }


    @Test
    fun showNoteTask_defaultUserSet_shouldStartActivityWithExpectedUserAndLogUiEvent() {
        whenever(secureSettings.getInt(eq(Settings.Secure.DEFAULT_NOTE_TASK_PROFILE), any()))
            .thenReturn(10)
        val user10 = UserHandle.of(/* userId= */ 10)

        val expectedInfo =
            NOTE_TASK_INFO.copy(
                entryPoint = NoteTaskEntryPoint.TAIL_BUTTON,
                isKeyguardLocked = true,
                user = user10,
            )
        whenever(keyguardManager.isKeyguardLocked).thenReturn(expectedInfo.isKeyguardLocked)
        whenever(resolver.resolveInfo(any(), any(), any())).thenReturn(expectedInfo)

        createNoteTaskController()
            .showNoteTask(
                entryPoint = expectedInfo.entryPoint!!,
            )

        val intentCaptor = argumentCaptor<Intent>()
        val userCaptor = argumentCaptor<UserHandle>()
        verify(context).startActivityAsUser(capture(intentCaptor), capture(userCaptor))
        intentCaptor.value.let { intent ->
            assertThat(intent.action).isEqualTo(Intent.ACTION_CREATE_NOTE)
            assertThat(intent.`package`).isEqualTo(NOTE_TASK_PACKAGE_NAME)
            assertThat(intent.flags and FLAG_ACTIVITY_NEW_TASK).isEqualTo(FLAG_ACTIVITY_NEW_TASK)
            assertThat(intent.flags and FLAG_ACTIVITY_MULTIPLE_TASK)
                .isEqualTo(FLAG_ACTIVITY_MULTIPLE_TASK)
            assertThat(intent.flags and FLAG_ACTIVITY_NEW_DOCUMENT)
                .isEqualTo(FLAG_ACTIVITY_NEW_DOCUMENT)
            assertThat(intent.getBooleanExtra(Intent.EXTRA_USE_STYLUS_MODE, false)).isTrue()
        }
        assertThat(userCaptor.value).isEqualTo(user10)
        verify(eventLogger).logNoteTaskOpened(expectedInfo)
        verifyZeroInteractions(bubbles)
    }

    @Test
    @Test
    fun showNoteTaskWithUser_keyguardIsLocked_shouldStartActivityWithExpectedUserAndLogUiEvent() {
    fun showNoteTaskWithUser_keyguardIsLocked_shouldStartActivityWithExpectedUserAndLogUiEvent() {
        val user10 = UserHandle.of(/* userId= */ 10)
        val user10 = UserHandle.of(/* userId= */ 10)