From e35ff257bea55d04a759f1e825a2a6f44fc0a022 Mon Sep 17 00:00:00 2001 From: Pinyao Ting Date: Thu, 10 Feb 2022 21:16:19 +0000 Subject: [PATCH] Include error logging for investigation on pushDynamicShortcut Include additional logs for further investigation on reported issue where calling pushDynamicShortcut in a loop resulted in having more shortcuts that occupies system memory then allowed by ShortcutManager#getMaxShortcutCountPerActivity. Bug: 218259921, 218545269 Test: manual Change-Id: I268831784ed31f60f3b793c99434178c6e39861b --- .../java/com/android/server/pm/ShortcutPackage.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/services/core/java/com/android/server/pm/ShortcutPackage.java b/services/core/java/com/android/server/pm/ShortcutPackage.java index bda25895a4b37..8921fee6c8e0a 100644 --- a/services/core/java/com/android/server/pm/ShortcutPackage.java +++ b/services/core/java/com/android/server/pm/ShortcutPackage.java @@ -442,6 +442,16 @@ class ShortcutPackage extends ShortcutPackageItem { sortShortcutsToActivities(); final ArrayList activityShortcuts = all.get(newShortcut.getActivity()); + if (activityShortcuts != null && activityShortcuts.size() > maxShortcuts) { + Slog.e(TAG, "Error pushing shortcut. There are already " + + activityShortcuts.size() + " shortcuts, exceeding the " + maxShortcuts + + " shortcuts limit when pushing the new shortcut " + newShortcut + + ". Id of shortcuts currently available in system memory are " + + activityShortcuts.stream().map(ShortcutInfo::getId) + .collect(Collectors.joining(",", "[", "]"))); + // TODO: This should not have happened. If it does, identify the root cause where + // possible, otherwise bail-out early to prevent memory issue. + } if (activityShortcuts != null && activityShortcuts.size() == maxShortcuts) { // Max has reached. Delete the shortcut with lowest rank.