Loading services/core/java/com/android/server/pm/ShortcutService.java +32 −17 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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); Loading Loading @@ -1842,11 +1841,18 @@ public class ShortcutService extends IShortcutService.Stub { @UserIdInt final int userId) { return () -> { try { 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) { } }; Loading @@ -1861,17 +1867,22 @@ public class ShortcutService extends IShortcutService.Stub { final UserHandle user = UserHandle.of(userId); injectPostToHandler(() -> { try { final ArrayList<LauncherApps.ShortcutChangeCallback> copy; synchronized (mServiceLock) { if (!isUserUnlockedL(userId)) { return; } mShortcutChangeCallbacks.forEach(callback -> { copy = new ArrayList<>(mShortcutChangeCallbacks); } 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) { } }); Loading Loading @@ -3414,14 +3425,18 @@ public class ShortcutService extends IShortcutService.Stub { @Override public void addListener(@NonNull ShortcutChangeListener listener) { synchronized (mServiceLock) { mListeners.add(Objects.requireNonNull(listener)); } } @Override public void addShortcutChangeCallback( @NonNull LauncherApps.ShortcutChangeCallback callback) { synchronized (mServiceLock) { mShortcutChangeCallbacks.add(Objects.requireNonNull(callback)); } } @Override public int getShortcutIconResId(int launcherUserId, @NonNull String callingPackage, Loading Loading
services/core/java/com/android/server/pm/ShortcutService.java +32 −17 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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); Loading Loading @@ -1842,11 +1841,18 @@ public class ShortcutService extends IShortcutService.Stub { @UserIdInt final int userId) { return () -> { try { 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) { } }; Loading @@ -1861,17 +1867,22 @@ public class ShortcutService extends IShortcutService.Stub { final UserHandle user = UserHandle.of(userId); injectPostToHandler(() -> { try { final ArrayList<LauncherApps.ShortcutChangeCallback> copy; synchronized (mServiceLock) { if (!isUserUnlockedL(userId)) { return; } mShortcutChangeCallbacks.forEach(callback -> { copy = new ArrayList<>(mShortcutChangeCallbacks); } 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) { } }); Loading Loading @@ -3414,14 +3425,18 @@ public class ShortcutService extends IShortcutService.Stub { @Override public void addListener(@NonNull ShortcutChangeListener listener) { synchronized (mServiceLock) { mListeners.add(Objects.requireNonNull(listener)); } } @Override public void addShortcutChangeCallback( @NonNull LauncherApps.ShortcutChangeCallback callback) { synchronized (mServiceLock) { mShortcutChangeCallbacks.add(Objects.requireNonNull(callback)); } } @Override public int getShortcutIconResId(int launcherUserId, @NonNull String callingPackage, Loading