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

Commit 3ff3df2d authored by Vania Januar's avatar Vania Januar Committed by Automerger Merge Worker
Browse files

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

parents c707913e e08ce731
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -7485,6 +7485,14 @@ public final class Settings {
        @SuppressLint("NoSettingsProvider")
        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
         * between host and port.
+1 −0
Original line number Diff line number Diff line
@@ -727,6 +727,7 @@ public class SettingsBackupTest {
                 Settings.Secure.CONNECTIVITY_RELEASE_PENDING_INTENT_DELAY_MS,
                 Settings.Secure.CONTENT_CAPTURE_ENABLED,
                 Settings.Secure.DEFAULT_INPUT_METHOD,
                 Settings.Secure.DEFAULT_NOTE_TASK_PROFILE,
                 Settings.Secure.DEVICE_PAIRED,
                 Settings.Secure.DIALER_DEFAULT_APPLICATION,
                 Settings.Secure.DISABLED_PRINT_SERVICES,
+14 −1
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.content.pm.ShortcutManager
import android.graphics.drawable.Icon
import android.os.UserHandle
import android.os.UserManager
import android.provider.Settings
import android.widget.Toast
import androidx.annotation.VisibleForTesting
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.shared.system.ActivityManagerKt.isInForeground
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.Bubbles
import com.android.wm.shell.bubbles.Bubbles.BubbleExpandListener
@@ -76,6 +78,7 @@ constructor(
    @NoteTaskEnabledKey private val isEnabled: Boolean,
    private val devicePolicyManager: DevicePolicyManager,
    private val userTracker: UserTracker,
    private val secureSettings: SecureSettings,
) {

    @VisibleForTesting val infoReference = AtomicReference<NoteTaskInfo?>()
@@ -146,7 +149,7 @@ constructor(
            userTracker.userProfiles.firstOrNull { userManager.isManagedProfile(it.id) }?.userHandle
                ?: userTracker.userHandle
        } 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 {
        val TAG = NoteTaskController::class.simpleName.orEmpty()

+43 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.content.pm.UserInfo
import android.graphics.drawable.Icon
import android.os.UserHandle
import android.os.UserManager
import android.provider.Settings
import androidx.test.ext.truth.content.IntentSubject.assertThat
import androidx.test.filters.SmallTest
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.eq
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.Bubbles
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 activityManager: ActivityManager
    @Mock private lateinit var devicePolicyManager: DevicePolicyManager
    @Mock private lateinit var secureSettings: SecureSettings
    private val userTracker = FakeUserTracker()

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

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

    // region onBubbleExpandChanged
@@ -250,6 +255,44 @@ internal class NoteTaskControllerTest : SysuiTestCase() {
        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
    fun showNoteTaskWithUser_keyguardIsLocked_shouldStartActivityWithExpectedUserAndLogUiEvent() {
        val user10 = UserHandle.of(/* userId= */ 10)