Skip to content

Commit

Permalink
RESTRICT AUTOMERGE Clear app-provided shortcut icons
Browse files Browse the repository at this point in the history
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:dbc02ea629b0ea503b2f1accb062bb5ec249aa58)
Merged-In: If7e291eb2254c3cbec23673c65e7477e6ad45b09
Change-Id: If7e291eb2254c3cbec23673c65e7477e6ad45b09
  • Loading branch information
Ben Murdoch authored and aoleary committed Nov 18, 2024
1 parent 1185a79 commit c9ab8de
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
13 changes: 11 additions & 2 deletions core/java/android/view/KeyboardShortcutInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -165,4 +174,4 @@ public KeyboardShortcutInfo[] newArray(int size) {
return new KeyboardShortcutInfo[size];
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ private void showKeyboardShortcuts(int deviceId) {
@Override
public void onKeyboardShortcutsReceived(
final List<KeyboardShortcutGroup> result) {
sanitiseShortcuts(result);
result.add(getSystemShortcuts());
final KeyboardShortcutGroup appShortcuts = getDefaultApplicationShortcuts();
if (appShortcuts != null) {
Expand All @@ -388,6 +389,14 @@ public void onKeyboardShortcutsReceived(
}, deviceId);
}

static void sanitiseShortcuts(List<KeyboardShortcutGroup> shortcutGroups) {
for (KeyboardShortcutGroup group : shortcutGroups) {
for (KeyboardShortcutInfo info : group.getItems()) {
info.clearIcon();
}
}
}

private void dismissKeyboardShortcuts() {
if (mKeyboardShortcutsDialog != null) {
mKeyboardShortcutsDialog.dismiss();
Expand Down

0 comments on commit c9ab8de

Please sign in to comment.