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
This commit is contained in:
Marcello Galhardo
2023-05-05 14:54:27 +00:00
parent 5b18837a49
commit bb8c04e072
4 changed files with 0 additions and 177 deletions

View File

@@ -4868,22 +4868,6 @@
</intent-filter> </intent-filter>
</receiver> </receiver>
<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_shortcut_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>
<activity <activity
android:name="com.android.settings.bluetooth.QrCodeScanModeActivity" android:name="com.android.settings.bluetooth.QrCodeScanModeActivity"
android:permission="android.permission.BLUETOOTH_CONNECT" android:permission="android.permission.BLUETOOTH_CONNECT"

View File

@@ -1,33 +0,0 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="48"
android:viewportHeight="48">
<group>
<path
android:fillColor="#0B57D0"
android:pathData="M48 24C48 10.7452 37.2548 0 24 0C10.7452 0 0 10.7452 0 24C0 37.2548 10.7452 48 24 48C37.2548 48 48 37.2548 48 24Z" />
<path
android:fillColor="#ffffff"
android:pathData="M37.692 16.8L36 15.108C35.556 14.652 34.944 14.4 34.308 14.4C33.672 14.4 33.06 14.652 32.616 15.108L23.268 24.456L20.508 27.216L19.248 32.28C19.212 32.352 19.2 32.448 19.2 32.532C19.2 33.12 19.68 33.6 20.268 33.6C20.352 33.6 20.448 33.588 20.532 33.564L25.596 32.304L28.356 29.544L37.704 20.196C38.148 19.74 38.4 19.128 38.4 18.492C38.4 17.856 38.148 17.244 37.692 16.8ZM26.652 27.852L25.452 29.052L23.76 27.36L24.96 26.16L34.308 16.8L36 18.492L26.652 27.852Z" />
<path
android:fillColor="#ffffff"
android:pathData="M17.825 33.6C12.257 33.6 10.2 31.9581 10.2 28.7351C10.2 25.8284 12.727 24.4472 16.656 23.8703C17.95 23.6802 18.6125 23.137 18.6125 22.5654C18.6125 20.9818 15.415 21.0788 14.4 21.0324V18.6C14.4 18.6 17.95 18.6 19.65 19.8923C20.5181 20.5521 21 21.4125 21 22.7149C21 24.5027 19.7375 25.9099 16.656 26.1633C14.6206 26.3307 12.6 26.9351 12.6 28.7351C12.6 30.3527 14.616 31.1676 18.6 31.1676L17.825 33.6Z" />
</group>
</vector>

View File

@@ -12079,7 +12079,4 @@
<!-- Warning message when we try to dock an app not supporting multiple instances split into multiple sides [CHAR LIMIT=NONE] --> <!-- Warning message when we try to dock an app not supporting multiple instances split into multiple sides [CHAR LIMIT=NONE] -->
<string name="dock_multi_instances_not_supported_text">"This app can only be opened in 1 window"</string> <string name="dock_multi_instances_not_supported_text">"This app can only be opened in 1 window"</string>
<!-- [CHAR LIMIT=30] Label used to open Note Task -->
<string name="note_task_shortcut_label">Note shortcut</string>
</resources> </resources>

View File

@@ -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 <a
* href="https://developer.android.com/develop/ui/views/launch/shortcuts/creating-shortcuts#custom-pinned">Creating
* a custom shortcut activity</a>
*/
internal class CreateNoteTaskShortcutActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
val roleManager = requireNotNull(getSystemService<RoleManager>())
val shortcutManager = requireNotNull(getSystemService<ShortcutManager>())
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)
}
}
}
}