Merge "Restrict number of shortcuts can be added through addDynamicShortcuts" into rvc-dev am: 0e03b8d4f2

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23623109

Change-Id: I2211e60a745e9870688b94dba86fb31e7c6b21ce
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/services/core/java/com/android/server/pm/ShortcutPackage.java b/services/core/java/com/android/server/pm/ShortcutPackage.java
index b2d78ec..4bc3cdb 100644
--- a/services/core/java/com/android/server/pm/ShortcutPackage.java
+++ b/services/core/java/com/android/server/pm/ShortcutPackage.java
@@ -305,6 +305,7 @@
         // Extract Icon and update the icon res ID and the bitmap path.
         s.saveIconAndFixUpShortcutLocked(newShortcut);
         s.fixUpShortcutResourceNamesAndValues(newShortcut);
+        ensureShortcutCountBeforePush();
         mShortcuts.put(newShortcut.getId(), newShortcut);
     }
 
@@ -351,7 +352,6 @@
             @NonNull List<ShortcutInfo> changedShortcuts) {
         Preconditions.checkArgument(newShortcut.isEnabled(),
                 "pushDynamicShortcuts() cannot publish disabled shortcuts");
-        ensureShortcutCountBeforePush();
 
         newShortcut.addFlags(ShortcutInfo.FLAG_DYNAMIC);