From 06445c2da12517a608868482c87e21c1f6a8afe1 Mon Sep 17 00:00:00 2001 From: Pinyao Ting Date: Mon, 29 Mar 2021 18:26:16 -0700 Subject: [PATCH] Remove unnecessary invokation on AppSearch There are some legacy logic which attempts to load shortcuts from xml file, which in most cases ended up calling AppSearchSession#putDocuments with an empty list because there are nothing to write into AppSearch. Since this is happening for every package that has a shortcut, these invokations collectively added some delay when launcher is starting. This CL removes the invokations altogether since they are not needed in the first place. Bug: 183982287 Test: flash the device, reboot and observe Test: atest ShortcutManagerTest1 ShortcutManagerTest2 ShortcutManagerTest3 ShortcutManagerTest4 ShortcutManagerTest5 ShortcutManagerTest6 ShortcutManagerTest7 ShortcutManagerTest8 ShortcutManagerTest9 ShortcutManagerTest10 ShortcutManagerTest11 Test: atest CtsShortcutManagerTestCases Change-Id: I57bd9ed93c1a2068a090ff3d67906702481220fd --- services/core/java/com/android/server/pm/ShortcutPackage.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/core/java/com/android/server/pm/ShortcutPackage.java b/services/core/java/com/android/server/pm/ShortcutPackage.java index fd8ec7f4bdeb3..2dad8ceb4add5 100644 --- a/services/core/java/com/android/server/pm/ShortcutPackage.java +++ b/services/core/java/com/android/server/pm/ShortcutPackage.java @@ -2187,6 +2187,10 @@ class ShortcutPackage extends ShortcutPackageItem { private void saveShortcut(@NonNull final Collection shortcuts) { Objects.requireNonNull(shortcuts); + if (shortcuts.isEmpty()) { + // No need to invoke AppSearch when there's nothing to save. + return; + } ConcurrentUtils.waitForFutureNoInterrupt( runInAppSearch(session -> { final AndroidFuture future = new AndroidFuture<>();