diff options
| author | 2024-05-02 15:44:50 +0000 | |
|---|---|---|
| committer | 2024-05-02 16:55:57 +0000 | |
| commit | d1ccf684cd45cdfe94b081d20c1ced40a07080b7 (patch) | |
| tree | 548886101088342dfcb4ec41429aec6ef3487663 | |
| parent | 72c374646769904ffa08869e7b27c73ca4faed4e (diff) | |
Revert "Unblock the registration of shortcut callbacks"
This reverts commit 694690596407ea43d082948154dfb029196bc2b3.
Reason for revert: performance regression b/335838918
Change-Id: I9230ab1d5826ad965adf52a110477565fcab505b
| -rw-r--r-- | services/core/java/com/android/server/pm/ShortcutService.java | 49 |
1 files changed, 32 insertions, 17 deletions
diff --git a/services/core/java/com/android/server/pm/ShortcutService.java b/services/core/java/com/android/server/pm/ShortcutService.java index 3f5ec0678f85..82902d45f1f2 100644 --- a/services/core/java/com/android/server/pm/ShortcutService.java +++ b/services/core/java/com/android/server/pm/ShortcutService.java @@ -50,7 +50,6 @@ import android.content.pm.ComponentInfo; import android.content.pm.IPackageManager; import android.content.pm.IShortcutService; import android.content.pm.LauncherApps; -import android.content.pm.LauncherApps.ShortcutChangeCallback; import android.content.pm.LauncherApps.ShortcutQuery; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; @@ -152,7 +151,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Objects; -import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; import java.util.function.Consumer; @@ -322,11 +320,12 @@ public class ShortcutService extends IShortcutService.Stub { private final Handler mHandler; - private final CopyOnWriteArrayList<ShortcutChangeListener> mListeners = - new CopyOnWriteArrayList<>(); + @GuardedBy("mServiceLock") + private final ArrayList<ShortcutChangeListener> mListeners = new ArrayList<>(1); - private final CopyOnWriteArrayList<ShortcutChangeCallback> mShortcutChangeCallbacks = - new CopyOnWriteArrayList<>(); + @GuardedBy("mServiceLock") + private final ArrayList<LauncherApps.ShortcutChangeCallback> mShortcutChangeCallbacks = + new ArrayList<>(1); private final AtomicLong mRawLastResetTime = new AtomicLong(0); @@ -1842,11 +1841,18 @@ public class ShortcutService extends IShortcutService.Stub { @UserIdInt final int userId) { return () -> { try { - if (!isUserUnlockedL(userId)) { - return; + final ArrayList<ShortcutChangeListener> copy; + synchronized (mServiceLock) { + if (!isUserUnlockedL(userId)) { + return; + } + + copy = new ArrayList<>(mListeners); } // Note onShortcutChanged() needs to be called with the system service permissions. - mListeners.forEach(listener -> listener.onShortcutChanged(packageName, userId)); + for (int i = copy.size() - 1; i >= 0; i--) { + copy.get(i).onShortcutChanged(packageName, userId); + } } catch (Exception ignore) { } }; @@ -1861,17 +1867,22 @@ public class ShortcutService extends IShortcutService.Stub { final UserHandle user = UserHandle.of(userId); injectPostToHandler(() -> { try { - if (!isUserUnlockedL(userId)) { - return; + final ArrayList<LauncherApps.ShortcutChangeCallback> copy; + synchronized (mServiceLock) { + if (!isUserUnlockedL(userId)) { + return; + } + + copy = new ArrayList<>(mShortcutChangeCallbacks); } - mShortcutChangeCallbacks.forEach(callback -> { + for (int i = copy.size() - 1; i >= 0; i--) { if (!CollectionUtils.isEmpty(changedList)) { - callback.onShortcutsAddedOrUpdated(packageName, changedList, user); + copy.get(i).onShortcutsAddedOrUpdated(packageName, changedList, user); } if (!CollectionUtils.isEmpty(removedList)) { - callback.onShortcutsRemoved(packageName, removedList, user); + copy.get(i).onShortcutsRemoved(packageName, removedList, user); } - }); + } } catch (Exception ignore) { } }); @@ -3414,13 +3425,17 @@ public class ShortcutService extends IShortcutService.Stub { @Override public void addListener(@NonNull ShortcutChangeListener listener) { - mListeners.add(Objects.requireNonNull(listener)); + synchronized (mServiceLock) { + mListeners.add(Objects.requireNonNull(listener)); + } } @Override public void addShortcutChangeCallback( @NonNull LauncherApps.ShortcutChangeCallback callback) { - mShortcutChangeCallbacks.add(Objects.requireNonNull(callback)); + synchronized (mServiceLock) { + mShortcutChangeCallbacks.add(Objects.requireNonNull(callback)); + } } @Override |