From bb8c04e07246e174a18f6d14a88bcf47f87353f6 Mon Sep 17 00:00:00 2001 From: Marcello Galhardo Date: Fri, 5 May 2023 14:54:27 +0000 Subject: [PATCH] Move Note Shortcut from Settings to SystemUI * Removes all code related to Note Shortcut from Settings Test: manual Flag: not needed Fixes: b/280431176 Change-Id: I6bb6cfbb98a57b6ad3cf261626b3d84d0be96e53 --- AndroidManifest.xml | 16 --- res/drawable/ic_note_task_shortcut_widget.xml | 33 ----- res/values/strings.xml | 3 - .../CreateNoteTaskShortcutActivity.kt | 125 ------------------ 4 files changed, 177 deletions(-) delete mode 100644 res/drawable/ic_note_task_shortcut_widget.xml delete mode 100644 src/com/android/settings/notetask/shortcut/CreateNoteTaskShortcutActivity.kt diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 6fe6832b76a..5904282dd97 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -4868,22 +4868,6 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 261829b56ef..69c29ae0d40 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -12079,7 +12079,4 @@ "This app can only be opened in 1 window" - - - Note shortcut diff --git a/src/com/android/settings/notetask/shortcut/CreateNoteTaskShortcutActivity.kt b/src/com/android/settings/notetask/shortcut/CreateNoteTaskShortcutActivity.kt deleted file mode 100644 index d3d751063b3..00000000000 --- a/src/com/android/settings/notetask/shortcut/CreateNoteTaskShortcutActivity.kt +++ /dev/null @@ -1,125 +0,0 @@ -/* - * 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.settings.notetask.shortcut - -import android.app.Activity -import android.app.role.RoleManager -import android.app.role.RoleManager.ROLE_NOTES -import android.content.ComponentName -import android.content.Context -import android.content.Intent -import android.content.pm.ShortcutInfo -import android.content.pm.ShortcutManager -import android.graphics.drawable.Icon -import android.os.Bundle -import android.os.PersistableBundle -import android.os.UserHandle -import androidx.activity.ComponentActivity -import androidx.core.content.getSystemService -import com.android.settings.R - -/** - * 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. - * - * IMPORTANT! The shortcut package name and class should be synchronized with SystemUI controller: - * [com.android.systemui.notetask.NoteTaskController#SETTINGS_CREATE_NOTE_TASK_SHORTCUT_COMPONENT]. - * - * Changing the package name or class is a breaking change. - * - * @see Creating - * a custom shortcut activity - */ -internal class CreateNoteTaskShortcutActivity : ComponentActivity() { - - override fun onCreate(savedInstanceState: Bundle?) { - val roleManager = requireNotNull(getSystemService()) - val shortcutManager = requireNotNull(getSystemService()) - - super.onCreate(savedInstanceState) - - val shortcutInfo = roleManager.createNoteShortcutInfoAsUser(context = this, user) - val shortcutIntent = shortcutManager.createShortcutResultIntent(shortcutInfo) - setResult(Activity.RESULT_OK, shortcutIntent) - - finish() - } - - private companion object { - - private const val SHORTCUT_ID = "note_task_shortcut_id" - private const val EXTRA_SHORTCUT_BADGE_OVERRIDE_PACKAGE = - "extra_shortcut_badge_override_package" - private const val ACTION_LAUNCH_NOTE_TASK = "com.android.systemui.action.LAUNCH_NOTE_TASK" - - private fun RoleManager.createNoteShortcutInfoAsUser( - context: Context, - user: UserHandle, - ): ShortcutInfo? { - val systemUiComponent = context.getSystemUiComponent() ?: return null - - val extras = PersistableBundle() - getDefaultRoleHolderAsUser(ROLE_NOTES, user)?.let { packageName -> - // Set custom app badge using the icon from ROLES_NOTES default app. - extras.putString(EXTRA_SHORTCUT_BADGE_OVERRIDE_PACKAGE, packageName) - } - - val icon = Icon.createWithResource(context, R.drawable.ic_note_task_shortcut_widget) - - val intent = Intent(ACTION_LAUNCH_NOTE_TASK).apply { - setPackage(systemUiComponent.packageName) - } - - // Creates a System UI context. That will let the ownership with SystemUI and allows it - // to perform updates such as enabling or updating the badge override package. - val systemUiContext = context.createPackageContext( - systemUiComponent.packageName, - /* flags */ 0, - ) - - return ShortcutInfo.Builder(systemUiContext, SHORTCUT_ID) - .setIntent(intent) - .setShortLabel(context.getString(R.string.note_task_shortcut_label)) - .setLongLived(true) - .setIcon(icon) - .setExtras(extras) - .build() - } - - private fun RoleManager.getDefaultRoleHolderAsUser( - role: String, - user: UserHandle, - ): String? = getRoleHoldersAsUser(role, user).firstOrNull() - - private fun Context.getSystemUiComponent(): ComponentName? { - val flattenName = getString( - com.android.internal.R.string.config_systemUIServiceComponent) - check(flattenName.isNotEmpty()) { - "No 'com.android.internal.R.string.config_systemUIServiceComponent' resource" - } - return try { - ComponentName.unflattenFromString(flattenName) - } catch (e: RuntimeException) { - val message = "Invalid component name defined by 'com.android.internal.R.string." + - "config_systemUIServiceComponent' resource: $flattenName" - throw IllegalStateException(message, e) - } - } - } -}