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

Commit 0a30f83b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Hide notes app lock screen shortcut when there is no default notes app...

Merge "Hide notes app lock screen shortcut when there is no default notes app set" into udc-dev am: 9b957e80

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22898062



Change-Id: I926c41aeb9531d18a7e9a39978c4b566ec15e032
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 7717eff8 9b957e80
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -992,6 +992,18 @@
            android:excludeFromRecents="true"
            android:resizeableActivity="false"
            android:theme="@android:style/Theme.NoDisplay" />

        <activity
            android:name=".notetask.LaunchNotesRoleSettingsTrampolineActivity"
            android:exported="true"
            android:excludeFromRecents="true"
            android:resizeableActivity="false"
            android:theme="@android:style/Theme.NoDisplay" >
            <intent-filter>
                <action android:name="com.android.systemui.action.MANAGE_NOTES_ROLE_FROM_QUICK_AFFORDANCE" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <!-- endregion -->

        <!-- started from ControlsRequestReceiver -->
+13 −0
Original line number Diff line number Diff line
@@ -3038,6 +3038,19 @@
    -->
    <string name="keyguard_affordance_enablement_dialog_home_instruction_2">&#8226; At least one device is available</string>

    <!---
    Requirement for the notes app to be available for the user to use. This is shown as part of a
    bulleted list of requirements. When all requirements are met, the app can be accessed through a
    shortcut button on the lock screen. [CHAR LIMIT=NONE] -->
    <string name="keyguard_affordance_enablement_dialog_notes_app_instruction">Select a default notes app to use notetaking shortcut</string>

    <!---
    The action to make the lock screen shortcut for the notes app to be available for the user to
    use. This is shown as the action button in the dialog listing the requirements. When all
    requirements are met, the app can be accessed through a shortcut button on the lock screen.
    [CHAR LIMIT=NONE] -->
    <string name="keyguard_affordance_enablement_dialog_notes_app_action">Open settings</string>

    <!--
    Error message shown when a shortcut must be pressed and held to activate it, usually shown when
    the user tried to tap the shortcut or held it for too short a time. [CHAR LIMIT=32].
+54 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.notetask

import android.os.Bundle
import androidx.activity.ComponentActivity
import com.android.systemui.keyguard.data.quickaffordance.KeyguardQuickAffordanceConfig
import javax.inject.Inject

/**
 * An internal proxy activity that starts the notes role setting.
 *
 * This activity is introduced mainly for the error handling of the notes app lock screen shortcut
 * picker, which only supports package + action but not extras. See
 * [KeyguardQuickAffordanceConfig.PickerScreenState.Disabled.actionComponentName].
 */
class LaunchNotesRoleSettingsTrampolineActivity
@Inject
constructor(
    private val controller: NoteTaskController,
) : ComponentActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val entryPoint =
            if (intent?.action == ACTION_MANAGE_NOTES_ROLE_FROM_QUICK_AFFORDANCE) {
                NoteTaskEntryPoint.QUICK_AFFORDANCE
            } else {
                null
            }
        controller.startNotesRoleSetting(this, entryPoint)
        finish()
    }

    companion object {
        const val ACTION_MANAGE_NOTES_ROLE_FROM_QUICK_AFFORDANCE =
            "com.android.systemui.action.MANAGE_NOTES_ROLE_FROM_QUICK_AFFORDANCE"
    }
}
+38 −18
Original line number Diff line number Diff line
@@ -112,6 +112,43 @@ constructor(
        )
    }

    /** Starts the notes role setting. */
    fun startNotesRoleSetting(activityContext: Context, entryPoint: NoteTaskEntryPoint?) {
        val user =
            if (entryPoint == null) {
                userTracker.userHandle
            } else {
                getUserForHandlingNotesTaking(entryPoint)
            }
        activityContext.startActivityAsUser(
            Intent(Intent.ACTION_MANAGE_DEFAULT_APP).apply {
                putExtra(Intent.EXTRA_ROLE_NAME, ROLE_NOTES)
            },
            user
        )
    }

    /**
     * Returns the [UserHandle] of an android user that should handle the notes taking [entryPoint].
     *
     * On company owned personally enabled (COPE) devices, if the given [entryPoint] is in the
     * [FORCE_WORK_NOTE_APPS_ENTRY_POINTS_ON_COPE_DEVICES] list, the default notes app in the work
     * profile user will always be launched.
     *
     * On non managed devices or devices with other management modes, the current [UserHandle] is
     * returned.
     */
    fun getUserForHandlingNotesTaking(entryPoint: NoteTaskEntryPoint): UserHandle =
        if (
            entryPoint in FORCE_WORK_NOTE_APPS_ENTRY_POINTS_ON_COPE_DEVICES &&
                devicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile
        ) {
            userTracker.userProfiles.firstOrNull { userManager.isManagedProfile(it.id) }?.userHandle
                ?: userTracker.userHandle
        } else {
            userTracker.userHandle
        }

    /**
     * Shows a note task. How the task is shown will depend on when the method is invoked.
     *
@@ -122,30 +159,13 @@ constructor(
     * bubble is already opened.
     *
     * That will let users open other apps in full screen, and take contextual notes.
     *
     * On company owned personally enabled (COPE) devices, if the given [entryPoint] is in the
     * [FORCE_WORK_NOTE_APPS_ENTRY_POINTS_ON_COPE_DEVICES] list, the default notes app in the work
     * profile user will always be launched.
     */
    fun showNoteTask(
        entryPoint: NoteTaskEntryPoint,
    ) {
        if (!isEnabled) return

        val user: UserHandle =
            if (
                entryPoint in FORCE_WORK_NOTE_APPS_ENTRY_POINTS_ON_COPE_DEVICES &&
                    devicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile
            ) {
                userTracker.userProfiles
                    .firstOrNull { userManager.isManagedProfile(it.id) }
                    ?.userHandle
                    ?: userTracker.userHandle
            } else {
                userTracker.userHandle
            }

        showNoteTaskAsUser(entryPoint, user)
        showNoteTaskAsUser(entryPoint, getUserForHandlingNotesTaking(entryPoint))
    }

    /** A variant of [showNoteTask] which launches note task in the given [user]. */
+4 −0
Original line number Diff line number Diff line
@@ -45,6 +45,10 @@ interface NoteTaskModule {
    @[Binds IntoMap ClassKey(LaunchNoteTaskManagedProfileProxyActivity::class)]
    fun LaunchNoteTaskManagedProfileProxyActivity.bindNoteTaskLauncherProxyActivity(): Activity

    @[Binds IntoMap ClassKey(LaunchNotesRoleSettingsTrampolineActivity::class)]
    fun LaunchNotesRoleSettingsTrampolineActivity.bindLaunchNotesRoleSettingsTrampolineActivity():
        Activity

    companion object {

        @[Provides NoteTaskEnabledKey]
Loading