Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b4f70d30 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Unblock the registration of shortcut callbacks" into main

parents 39f7f0d5 69469059
Loading
Loading
Loading
Loading
+17 −32
Original line number Original line Diff line number Diff line
@@ -50,6 +50,7 @@ import android.content.pm.ComponentInfo;
import android.content.pm.IPackageManager;
import android.content.pm.IPackageManager;
import android.content.pm.IShortcutService;
import android.content.pm.IShortcutService;
import android.content.pm.LauncherApps;
import android.content.pm.LauncherApps;
import android.content.pm.LauncherApps.ShortcutChangeCallback;
import android.content.pm.LauncherApps.ShortcutQuery;
import android.content.pm.LauncherApps.ShortcutQuery;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
@@ -151,6 +152,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Collections;
import java.util.List;
import java.util.List;
import java.util.Objects;
import java.util.Objects;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Consumer;
import java.util.function.Consumer;
@@ -320,12 +322,11 @@ public class ShortcutService extends IShortcutService.Stub {


    private final Handler mHandler;
    private final Handler mHandler;


    @GuardedBy("mLock")
    private final CopyOnWriteArrayList<ShortcutChangeListener> mListeners =
    private final ArrayList<ShortcutChangeListener> mListeners = new ArrayList<>(1);
            new CopyOnWriteArrayList<>();


    @GuardedBy("mLock")
    private final CopyOnWriteArrayList<ShortcutChangeCallback> mShortcutChangeCallbacks =
    private final ArrayList<LauncherApps.ShortcutChangeCallback> mShortcutChangeCallbacks =
            new CopyOnWriteArrayList<>();
            new ArrayList<>(1);


    private final AtomicLong mRawLastResetTime = new AtomicLong(0);
    private final AtomicLong mRawLastResetTime = new AtomicLong(0);


@@ -1841,18 +1842,11 @@ public class ShortcutService extends IShortcutService.Stub {
            @UserIdInt final int userId) {
            @UserIdInt final int userId) {
        return () -> {
        return () -> {
            try {
            try {
                final ArrayList<ShortcutChangeListener> copy;
                synchronized (mLock) {
                if (!isUserUnlockedL(userId)) {
                if (!isUserUnlockedL(userId)) {
                    return;
                    return;
                }
                }

                    copy = new ArrayList<>(mListeners);
                }
                // Note onShortcutChanged() needs to be called with the system service permissions.
                // Note onShortcutChanged() needs to be called with the system service permissions.
                for (int i = copy.size() - 1; i >= 0; i--) {
                mListeners.forEach(listener -> listener.onShortcutChanged(packageName, userId));
                    copy.get(i).onShortcutChanged(packageName, userId);
                }
            } catch (Exception ignore) {
            } catch (Exception ignore) {
            }
            }
        };
        };
@@ -1867,22 +1861,17 @@ public class ShortcutService extends IShortcutService.Stub {
        final UserHandle user = UserHandle.of(userId);
        final UserHandle user = UserHandle.of(userId);
        injectPostToHandler(() -> {
        injectPostToHandler(() -> {
            try {
            try {
                final ArrayList<LauncherApps.ShortcutChangeCallback> copy;
                synchronized (mLock) {
                if (!isUserUnlockedL(userId)) {
                if (!isUserUnlockedL(userId)) {
                    return;
                    return;
                }
                }

                mShortcutChangeCallbacks.forEach(callback -> {
                    copy = new ArrayList<>(mShortcutChangeCallbacks);
                }
                for (int i = copy.size() - 1; i >= 0; i--) {
                    if (!CollectionUtils.isEmpty(changedList)) {
                    if (!CollectionUtils.isEmpty(changedList)) {
                        copy.get(i).onShortcutsAddedOrUpdated(packageName, changedList, user);
                        callback.onShortcutsAddedOrUpdated(packageName, changedList, user);
                    }
                    }
                    if (!CollectionUtils.isEmpty(removedList)) {
                    if (!CollectionUtils.isEmpty(removedList)) {
                        copy.get(i).onShortcutsRemoved(packageName, removedList, user);
                        callback.onShortcutsRemoved(packageName, removedList, user);
                    }
                    }
                    }
                });
            } catch (Exception ignore) {
            } catch (Exception ignore) {
            }
            }
        });
        });
@@ -3425,18 +3414,14 @@ public class ShortcutService extends IShortcutService.Stub {


        @Override
        @Override
        public void addListener(@NonNull ShortcutChangeListener listener) {
        public void addListener(@NonNull ShortcutChangeListener listener) {
            synchronized (mLock) {
            mListeners.add(Objects.requireNonNull(listener));
            mListeners.add(Objects.requireNonNull(listener));
        }
        }
        }


        @Override
        @Override
        public void addShortcutChangeCallback(
        public void addShortcutChangeCallback(
                @NonNull LauncherApps.ShortcutChangeCallback callback) {
                @NonNull LauncherApps.ShortcutChangeCallback callback) {
            synchronized (mLock) {
            mShortcutChangeCallbacks.add(Objects.requireNonNull(callback));
            mShortcutChangeCallbacks.add(Objects.requireNonNull(callback));
        }
        }
        }


        @Override
        @Override
        public int getShortcutIconResId(int launcherUserId, @NonNull String callingPackage,
        public int getShortcutIconResId(int launcherUserId, @NonNull String callingPackage,