From 527ea3afca9a6ae7d330e5f982f9d22011adab7d Mon Sep 17 00:00:00 2001 From: Ben Murdoch Date: Fri, 30 Aug 2024 17:22:59 +0000 Subject: [PATCH] RESTRICT AUTOMERGE Clear app-provided shortcut icons When displaying keyboard shortcuts provided by an app, clear any icon that may have been set (this is only possible via reflection, and is not a intended for usage outside of the system). Bug: 331180422 Test: Verify on device (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:a031e9f221cf87657c42d3ed0ddbe93fc6d7a9c3) Merged-In: If7e291eb2254c3cbec23673c65e7477e6ad45b09 Change-Id: If7e291eb2254c3cbec23673c65e7477e6ad45b09 --- core/java/android/view/KeyboardShortcutInfo.java | 13 +++++++++++-- .../systemui/statusbar/KeyboardShortcuts.java | 9 +++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/core/java/android/view/KeyboardShortcutInfo.java b/core/java/android/view/KeyboardShortcutInfo.java index 2660e74dcb205..2075d77a9871e 100644 --- a/core/java/android/view/KeyboardShortcutInfo.java +++ b/core/java/android/view/KeyboardShortcutInfo.java @@ -29,7 +29,7 @@ */ public final class KeyboardShortcutInfo implements Parcelable { private final CharSequence mLabel; - private final Icon mIcon; + private Icon mIcon; private final char mBaseCharacter; private final int mKeycode; private final int mModifiers; @@ -115,6 +115,15 @@ public Icon getIcon() { return mIcon; } + /** + * Removes an icon that was previously set. + * + * @hide + */ + public void clearIcon() { + mIcon = null; + } + /** * Returns the base keycode that, combined with the modifiers, triggers this shortcut. If the * base character was set instead, returns {@link KeyEvent#KEYCODE_UNKNOWN}. Valid keycodes are @@ -165,4 +174,4 @@ public KeyboardShortcutInfo[] newArray(int size) { return new KeyboardShortcutInfo[size]; } }; -} \ No newline at end of file +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java index 7e6ddcfea7620..cc373d3c8b0f1 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java @@ -378,6 +378,7 @@ private void showKeyboardShortcuts(int deviceId) { @Override public void onKeyboardShortcutsReceived( final List result) { + sanitiseShortcuts(result); result.add(getSystemShortcuts()); final KeyboardShortcutGroup appShortcuts = getDefaultApplicationShortcuts(); if (appShortcuts != null) { @@ -388,6 +389,14 @@ public void onKeyboardShortcutsReceived( }, deviceId); } + static void sanitiseShortcuts(List shortcutGroups) { + for (KeyboardShortcutGroup group : shortcutGroups) { + for (KeyboardShortcutInfo info : group.getItems()) { + info.clearIcon(); + } + } + } + private void dismissKeyboardShortcuts() { if (mKeyboardShortcutsDialog != null) { mKeyboardShortcutsDialog.dismiss();