diff options
| author | 2023-04-24 19:36:48 +0000 | |
|---|---|---|
| committer | 2023-04-25 09:49:22 +0000 | |
| commit | e8b786395d4692c23f36a166edf18a2bea83d325 (patch) | |
| tree | 88eac60a65e36eb9da46b5fee862d79cfc719d0b | |
| parent | 90664488b427cf0e4c96c3077de36d3106a3956a (diff) | |
Update Note Task shortcut in Settings
We have moved Note Task shortcut from SystemUI to Settings, as requested per Shortcut team and agreed with Settings team. We are now deleting all shortcut code duplicated inside SystemUI, and moving the "shortcut management logic" from NoteTaskController to point to the new shortcut in settings.
Test: atest NoteTaskControllerTest
Fixes: b/278724068
Change-Id: Idb772752bce28c97258c3a0855d87f613ee2d134
5 files changed, 24 insertions, 94 deletions
diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml index 4652ef195a0c..32d6b70f7f47 100644 --- a/packages/SystemUI/AndroidManifest.xml +++ b/packages/SystemUI/AndroidManifest.xml @@ -966,22 +966,6 @@ android:permission="android.permission.BIND_JOB_SERVICE"/> <!-- region Note Task --> - <activity - android:name=".notetask.shortcut.CreateNoteTaskShortcutActivity" - android:enabled="false" - android:exported="true" - android:excludeFromRecents="true" - android:resizeableActivity="false" - android:theme="@android:style/Theme.NoDisplay" - android:label="@string/note_task_button_label" - android:icon="@drawable/ic_note_task_shortcut_widget"> - - <intent-filter> - <action android:name="android.intent.action.CREATE_SHORTCUT" /> - <category android:name="android.intent.category.DEFAULT" /> - </intent-filter> - </activity> - <service android:name=".notetask.NoteTaskControllerUpdateService" /> <activity diff --git a/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskController.kt b/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskController.kt index 8aec0c61c75c..d4052f54b3da 100644 --- a/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskController.kt +++ b/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskController.kt @@ -42,7 +42,6 @@ import com.android.systemui.dagger.SysUISingleton import com.android.systemui.devicepolicy.areKeyguardShortcutsDisabled import com.android.systemui.notetask.NoteTaskRoleManagerExt.createNoteShortcutInfoAsUser import com.android.systemui.notetask.NoteTaskRoleManagerExt.getDefaultRoleHolderAsUser -import com.android.systemui.notetask.shortcut.CreateNoteTaskShortcutActivity import com.android.systemui.notetask.shortcut.LaunchNoteTaskManagedProfileProxyActivity import com.android.systemui.settings.UserTracker import com.android.systemui.shared.system.ActivityManagerKt.isInForeground @@ -231,8 +230,6 @@ constructor( * Widget Picker to all users. */ fun setNoteTaskShortcutEnabled(value: Boolean, user: UserHandle) { - val componentName = ComponentName(context, CreateNoteTaskShortcutActivity::class.java) - val enabledState = if (value) { PackageManager.COMPONENT_ENABLED_STATE_ENABLED @@ -249,8 +246,9 @@ constructor( } else { context.createContextAsUser(user, /* flags= */ 0) } + userContext.packageManager.setComponentEnabledSetting( - componentName, + SETTINGS_CREATE_NOTE_TASK_SHORTCUT_COMPONENT, enabledState, PackageManager.DONT_KILL_APP, ) @@ -298,6 +296,19 @@ constructor( companion object { val TAG = NoteTaskController::class.simpleName.orEmpty() + /** + * IMPORTANT! The shortcut package name and class should be synchronized with Settings: + * [com.android.settings.notetask.shortcut.CreateNoteTaskShortcutActivity]. + * + * Changing the package name or class is a breaking change. + */ + @VisibleForTesting + val SETTINGS_CREATE_NOTE_TASK_SHORTCUT_COMPONENT = + ComponentName( + "com.android.settings", + "com.android.settings.notetask.shortcut.CreateNoteTaskShortcutActivity", + ) + const val SHORTCUT_ID = "note_task_shortcut_id" /** diff --git a/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskModule.kt b/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskModule.kt index a166393ec29c..2c62ffd4841f 100644 --- a/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskModule.kt +++ b/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskModule.kt @@ -24,7 +24,6 @@ import android.app.role.RoleManager import com.android.systemui.flags.FeatureFlags import com.android.systemui.flags.Flags import com.android.systemui.notetask.quickaffordance.NoteTaskQuickAffordanceModule -import com.android.systemui.notetask.shortcut.CreateNoteTaskShortcutActivity import com.android.systemui.notetask.shortcut.LaunchNoteTaskActivity import com.android.systemui.notetask.shortcut.LaunchNoteTaskManagedProfileProxyActivity import dagger.Binds @@ -46,9 +45,6 @@ interface NoteTaskModule { @[Binds IntoMap ClassKey(LaunchNoteTaskManagedProfileProxyActivity::class)] fun LaunchNoteTaskManagedProfileProxyActivity.bindNoteTaskLauncherProxyActivity(): Activity - @[Binds IntoMap ClassKey(CreateNoteTaskShortcutActivity::class)] - fun CreateNoteTaskShortcutActivity.bindNoteTaskShortcutActivity(): Activity - companion object { @[Provides NoteTaskEnabledKey] diff --git a/packages/SystemUI/src/com/android/systemui/notetask/shortcut/CreateNoteTaskShortcutActivity.kt b/packages/SystemUI/src/com/android/systemui/notetask/shortcut/CreateNoteTaskShortcutActivity.kt deleted file mode 100644 index 0cfb0a521820..000000000000 --- a/packages/SystemUI/src/com/android/systemui/notetask/shortcut/CreateNoteTaskShortcutActivity.kt +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2022 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. - */ - -@file:OptIn(InternalNoteTaskApi::class) - -package com.android.systemui.notetask.shortcut - -import android.app.Activity -import android.app.role.RoleManager -import android.content.pm.ShortcutManager -import android.os.Bundle -import androidx.activity.ComponentActivity -import com.android.systemui.notetask.InternalNoteTaskApi -import com.android.systemui.notetask.NoteTaskRoleManagerExt.createNoteShortcutInfoAsUser -import javax.inject.Inject - -/** - * Activity responsible for create a shortcut for notes action. If the shortcut is enabled, a new - * shortcut will appear in the widget picker. If the shortcut is selected, the Activity here will be - * launched, creating a new shortcut for [CreateNoteTaskShortcutActivity], and will finish. - * - * @see <a - * href="https://developer.android.com/develop/ui/views/launch/shortcuts/creating-shortcuts#custom-pinned">Creating - * a custom shortcut activity</a> - */ -class CreateNoteTaskShortcutActivity -@Inject -constructor( - private val roleManager: RoleManager, - private val shortcutManager: ShortcutManager, -) : ComponentActivity() { - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - - val shortcutInfo = roleManager.createNoteShortcutInfoAsUser(context = this, user) - val shortcutIntent = shortcutManager.createShortcutResultIntent(shortcutInfo) - setResult(Activity.RESULT_OK, shortcutIntent) - - finish() - } -} diff --git a/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt index 55f221df1f0a..5dbcd33ab0e6 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt @@ -45,8 +45,8 @@ import androidx.test.runner.AndroidJUnit4 import com.android.systemui.R import com.android.systemui.SysuiTestCase import com.android.systemui.notetask.NoteTaskController.Companion.EXTRA_SHORTCUT_BADGE_OVERRIDE_PACKAGE +import com.android.systemui.notetask.NoteTaskController.Companion.SETTINGS_CREATE_NOTE_TASK_SHORTCUT_COMPONENT import com.android.systemui.notetask.NoteTaskController.Companion.SHORTCUT_ID -import com.android.systemui.notetask.shortcut.CreateNoteTaskShortcutActivity import com.android.systemui.notetask.shortcut.LaunchNoteTaskActivity import com.android.systemui.notetask.shortcut.LaunchNoteTaskManagedProfileProxyActivity import com.android.systemui.settings.FakeUserTracker @@ -423,8 +423,8 @@ internal class NoteTaskControllerTest : SysuiTestCase() { eq(COMPONENT_ENABLED_STATE_ENABLED), eq(PackageManager.DONT_KILL_APP), ) - assertThat(argument.value.className) - .isEqualTo(CreateNoteTaskShortcutActivity::class.java.name) + + assertThat(argument.value).isEqualTo(SETTINGS_CREATE_NOTE_TASK_SHORTCUT_COMPONENT) } @Test @@ -438,8 +438,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { eq(COMPONENT_ENABLED_STATE_DISABLED), eq(PackageManager.DONT_KILL_APP), ) - assertThat(argument.value.className) - .isEqualTo(CreateNoteTaskShortcutActivity::class.java.name) + assertThat(argument.value).isEqualTo(SETTINGS_CREATE_NOTE_TASK_SHORTCUT_COMPONENT) } @Test @@ -458,8 +457,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { eq(COMPONENT_ENABLED_STATE_ENABLED), eq(PackageManager.DONT_KILL_APP), ) - assertThat(argument.value.className) - .isEqualTo(CreateNoteTaskShortcutActivity::class.java.name) + assertThat(argument.value).isEqualTo(SETTINGS_CREATE_NOTE_TASK_SHORTCUT_COMPONENT) } @Test @@ -479,8 +477,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { eq(COMPONENT_ENABLED_STATE_DISABLED), eq(PackageManager.DONT_KILL_APP), ) - assertThat(argument.value.className) - .isEqualTo(CreateNoteTaskShortcutActivity::class.java.name) + assertThat(argument.value).isEqualTo(SETTINGS_CREATE_NOTE_TASK_SHORTCUT_COMPONENT) } // endregion @@ -664,8 +661,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { eq(COMPONENT_ENABLED_STATE_ENABLED), eq(PackageManager.DONT_KILL_APP), ) - assertThat(actualComponent.value.className) - .isEqualTo(CreateNoteTaskShortcutActivity::class.java.name) + assertThat(actualComponent.value).isEqualTo(SETTINGS_CREATE_NOTE_TASK_SHORTCUT_COMPONENT) verify(shortcutManager, never()).disableShortcuts(any()) verify(shortcutManager).enableShortcuts(listOf(SHORTCUT_ID)) val actualShortcuts = argumentCaptor<List<ShortcutInfo>>() @@ -696,8 +692,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { eq(COMPONENT_ENABLED_STATE_DISABLED), eq(PackageManager.DONT_KILL_APP), ) - assertThat(argument.value.className) - .isEqualTo(CreateNoteTaskShortcutActivity::class.java.name) + assertThat(argument.value).isEqualTo(SETTINGS_CREATE_NOTE_TASK_SHORTCUT_COMPONENT) verify(shortcutManager).disableShortcuts(listOf(SHORTCUT_ID)) verify(shortcutManager, never()).enableShortcuts(any()) verify(shortcutManager, never()).updateShortcuts(any()) @@ -714,8 +709,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { eq(COMPONENT_ENABLED_STATE_DISABLED), eq(PackageManager.DONT_KILL_APP), ) - assertThat(argument.value.className) - .isEqualTo(CreateNoteTaskShortcutActivity::class.java.name) + assertThat(argument.value).isEqualTo(SETTINGS_CREATE_NOTE_TASK_SHORTCUT_COMPONENT) verify(shortcutManager).disableShortcuts(listOf(SHORTCUT_ID)) verify(shortcutManager, never()).enableShortcuts(any()) verify(shortcutManager, never()).updateShortcuts(any()) |