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

Commit 2b9feda3 authored by Pinyao Ting's avatar Pinyao Ting Committed by Android (Google) Code Review
Browse files

Merge "Rename locks used in shortcut service for clarity" into main

parents 2edb4057 f4d59329
Loading
Loading
Loading
Loading
+12 −12
Original line number Original line Diff line number Diff line
@@ -46,7 +46,7 @@ import java.util.List;
/**
/**
 * Launcher information used by {@link ShortcutService}.
 * Launcher information used by {@link ShortcutService}.
 *
 *
 * All methods should be guarded by {@code #mShortcutUser.mService.mLock}.
 * All methods should be guarded by {@code ShortcutPackageItem#mPackageItemLock}.
 */
 */
class ShortcutLauncher extends ShortcutPackageItem {
class ShortcutLauncher extends ShortcutPackageItem {
    private static final String TAG = ShortcutService.TAG;
    private static final String TAG = ShortcutService.TAG;
@@ -66,7 +66,7 @@ class ShortcutLauncher extends ShortcutPackageItem {
    /**
    /**
     * Package name -> IDs.
     * Package name -> IDs.
     */
     */
    @GuardedBy("mLock")
    @GuardedBy("mPackageItemLock")
    private final ArrayMap<UserPackage, ArraySet<String>> mPinnedShortcuts = new ArrayMap<>();
    private final ArrayMap<UserPackage, ArraySet<String>> mPinnedShortcuts = new ArrayMap<>();


    private ShortcutLauncher(@NonNull ShortcutUser shortcutUser,
    private ShortcutLauncher(@NonNull ShortcutUser shortcutUser,
@@ -99,7 +99,7 @@ class ShortcutLauncher extends ShortcutPackageItem {
     */
     */
    private void onRestoreBlocked() {
    private void onRestoreBlocked() {
        final ArrayList<UserPackage> pinnedPackages;
        final ArrayList<UserPackage> pinnedPackages;
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            pinnedPackages = new ArrayList<>(mPinnedShortcuts.keySet());
            pinnedPackages = new ArrayList<>(mPinnedShortcuts.keySet());
            mPinnedShortcuts.clear();
            mPinnedShortcuts.clear();
        }
        }
@@ -138,7 +138,7 @@ class ShortcutLauncher extends ShortcutPackageItem {


        final int idSize = ids.size();
        final int idSize = ids.size();
        if (idSize == 0) {
        if (idSize == 0) {
            synchronized (mLock) {
            synchronized (mPackageItemLock) {
                mPinnedShortcuts.remove(up);
                mPinnedShortcuts.remove(up);
            }
            }
        } else {
        } else {
@@ -165,7 +165,7 @@ class ShortcutLauncher extends ShortcutPackageItem {
                    floatingSet.add(id);
                    floatingSet.add(id);
                }
                }
            }
            }
            synchronized (mLock) {
            synchronized (mPackageItemLock) {
                final ArraySet<String> prevSet = mPinnedShortcuts.get(up);
                final ArraySet<String> prevSet = mPinnedShortcuts.get(up);
                if (prevSet != null) {
                if (prevSet != null) {
                    for (String id : floatingSet) {
                    for (String id : floatingSet) {
@@ -187,7 +187,7 @@ class ShortcutLauncher extends ShortcutPackageItem {
    @Nullable
    @Nullable
    public ArraySet<String> getPinnedShortcutIds(@NonNull String packageName,
    public ArraySet<String> getPinnedShortcutIds(@NonNull String packageName,
            @UserIdInt int packageUserId) {
            @UserIdInt int packageUserId) {
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            final ArraySet<String> pinnedShortcuts = mPinnedShortcuts.get(
            final ArraySet<String> pinnedShortcuts = mPinnedShortcuts.get(
                    UserPackage.of(packageUserId, packageName));
                    UserPackage.of(packageUserId, packageName));
            return pinnedShortcuts == null ? null : new ArraySet<>(pinnedShortcuts);
            return pinnedShortcuts == null ? null : new ArraySet<>(pinnedShortcuts);
@@ -198,7 +198,7 @@ class ShortcutLauncher extends ShortcutPackageItem {
     * Return true if the given shortcut is pinned by this launcher.<code></code>
     * Return true if the given shortcut is pinned by this launcher.<code></code>
     */
     */
    public boolean hasPinned(ShortcutInfo shortcut) {
    public boolean hasPinned(ShortcutInfo shortcut) {
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            final ArraySet<String> pinned = mPinnedShortcuts.get(
            final ArraySet<String> pinned = mPinnedShortcuts.get(
                    UserPackage.of(shortcut.getUserId(), shortcut.getPackage()));
                    UserPackage.of(shortcut.getUserId(), shortcut.getPackage()));
            return (pinned != null) && pinned.contains(shortcut.getId());
            return (pinned != null) && pinned.contains(shortcut.getId());
@@ -211,7 +211,7 @@ class ShortcutLauncher extends ShortcutPackageItem {
    public void addPinnedShortcut(@NonNull String packageName, @UserIdInt int packageUserId,
    public void addPinnedShortcut(@NonNull String packageName, @UserIdInt int packageUserId,
            String id, boolean forPinRequest) {
            String id, boolean forPinRequest) {
        final ArrayList<String> pinnedList;
        final ArrayList<String> pinnedList;
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            final ArraySet<String> pinnedSet = mPinnedShortcuts.get(
            final ArraySet<String> pinnedSet = mPinnedShortcuts.get(
                    UserPackage.of(packageUserId, packageName));
                    UserPackage.of(packageUserId, packageName));
            if (pinnedSet != null) {
            if (pinnedSet != null) {
@@ -227,7 +227,7 @@ class ShortcutLauncher extends ShortcutPackageItem {
    }
    }


    boolean cleanUpPackage(String packageName, @UserIdInt int packageUserId) {
    boolean cleanUpPackage(String packageName, @UserIdInt int packageUserId) {
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            return mPinnedShortcuts.remove(UserPackage.of(packageUserId, packageName)) != null;
            return mPinnedShortcuts.remove(UserPackage.of(packageUserId, packageName)) != null;
        }
        }
    }
    }
@@ -253,7 +253,7 @@ class ShortcutLauncher extends ShortcutPackageItem {
            return;
            return;
        }
        }
        final ArrayMap<UserPackage, ArraySet<String>> pinnedShortcuts;
        final ArrayMap<UserPackage, ArraySet<String>> pinnedShortcuts;
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            pinnedShortcuts = new ArrayMap<>(mPinnedShortcuts);
            pinnedShortcuts = new ArrayMap<>(mPinnedShortcuts);
        }
        }
        final int size = pinnedShortcuts.size();
        final int size = pinnedShortcuts.size();
@@ -366,7 +366,7 @@ class ShortcutLauncher extends ShortcutPackageItem {
                                : ShortcutService.parseIntAttribute(parser,
                                : ShortcutService.parseIntAttribute(parser,
                                ATTR_PACKAGE_USER_ID, ownerUserId);
                                ATTR_PACKAGE_USER_ID, ownerUserId);
                        ids = new ArraySet<>();
                        ids = new ArraySet<>();
                        synchronized (ret.mLock) {
                        synchronized (ret.mPackageItemLock) {
                            ret.mPinnedShortcuts.put(
                            ret.mPinnedShortcuts.put(
                                    UserPackage.of(packageUserId, packageName), ids);
                                    UserPackage.of(packageUserId, packageName), ids);
                        }
                        }
@@ -407,7 +407,7 @@ class ShortcutLauncher extends ShortcutPackageItem {
        pw.println();
        pw.println();


        final ArrayMap<UserPackage, ArraySet<String>> pinnedShortcuts;
        final ArrayMap<UserPackage, ArraySet<String>> pinnedShortcuts;
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            pinnedShortcuts = new ArrayMap<>(mPinnedShortcuts);
            pinnedShortcuts = new ArrayMap<>(mPinnedShortcuts);
        }
        }
        final int size = pinnedShortcuts.size();
        final int size = pinnedShortcuts.size();
+29 −29
Original line number Original line Diff line number Diff line
@@ -163,20 +163,20 @@ class ShortcutPackage extends ShortcutPackageItem {
    /**
    /**
     * An in-memory copy of shortcuts for this package that was loaded from xml, keyed on IDs.
     * An in-memory copy of shortcuts for this package that was loaded from xml, keyed on IDs.
     */
     */
    @GuardedBy("mLock")
    @GuardedBy("mPackageItemLock")
    private final ArrayMap<String, ShortcutInfo> mShortcuts = new ArrayMap<>();
    private final ArrayMap<String, ShortcutInfo> mShortcuts = new ArrayMap<>();


    /**
    /**
     * A temporary copy of shortcuts that are to be cleared once persisted into AppSearch, keyed on
     * A temporary copy of shortcuts that are to be cleared once persisted into AppSearch, keyed on
     * IDs.
     * IDs.
     */
     */
    @GuardedBy("mLock")
    @GuardedBy("mPackageItemLock")
    private final ArrayMap<String, ShortcutInfo> mTransientShortcuts = new ArrayMap<>(0);
    private final ArrayMap<String, ShortcutInfo> mTransientShortcuts = new ArrayMap<>(0);


    /**
    /**
     * All the share targets from the package
     * All the share targets from the package
     */
     */
    @GuardedBy("mLock")
    @GuardedBy("mPackageItemLock")
    private final ArrayList<ShareTargetInfo> mShareTargets = new ArrayList<>(0);
    private final ArrayList<ShareTargetInfo> mShareTargets = new ArrayList<>(0);


    /**
    /**
@@ -193,10 +193,10 @@ class ShortcutPackage extends ShortcutPackageItem {


    private long mLastKnownForegroundElapsedTime;
    private long mLastKnownForegroundElapsedTime;


    @GuardedBy("mLock")
    @GuardedBy("mPackageItemLock")
    private long mLastReportedTime;
    private long mLastReportedTime;


    @GuardedBy("mLock")
    @GuardedBy("mPackageItemLock")
    private boolean mIsAppSearchSchemaUpToDate;
    private boolean mIsAppSearchSchemaUpToDate;


    private ShortcutPackage(ShortcutUser shortcutUser,
    private ShortcutPackage(ShortcutUser shortcutUser,
@@ -233,7 +233,7 @@ class ShortcutPackage extends ShortcutPackageItem {
    }
    }


    public int getShortcutCount() {
    public int getShortcutCount() {
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            return mShortcuts.size();
            return mShortcuts.size();
        }
        }
    }
    }
@@ -276,7 +276,7 @@ class ShortcutPackage extends ShortcutPackageItem {
    @Nullable
    @Nullable
    public ShortcutInfo findShortcutById(@Nullable final String id) {
    public ShortcutInfo findShortcutById(@Nullable final String id) {
        if (id == null) return null;
        if (id == null) return null;
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            return mShortcuts.get(id);
            return mShortcuts.get(id);
        }
        }
    }
    }
@@ -354,7 +354,7 @@ class ShortcutPackage extends ShortcutPackageItem {
     */
     */
    private ShortcutInfo forceDeleteShortcutInner(@NonNull String id) {
    private ShortcutInfo forceDeleteShortcutInner(@NonNull String id) {
        final ShortcutInfo shortcut;
        final ShortcutInfo shortcut;
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            shortcut = mShortcuts.remove(id);
            shortcut = mShortcuts.remove(id);
            if (shortcut != null) {
            if (shortcut != null) {
                removeIcon(shortcut);
                removeIcon(shortcut);
@@ -409,7 +409,7 @@ class ShortcutPackage extends ShortcutPackageItem {


        if (newShortcut.isExcludedFromSurfaces(ShortcutInfo.SURFACE_LAUNCHER)) {
        if (newShortcut.isExcludedFromSurfaces(ShortcutInfo.SURFACE_LAUNCHER)) {
            if (isAppSearchEnabled()) {
            if (isAppSearchEnabled()) {
                synchronized (mLock) {
                synchronized (mPackageItemLock) {
                    mTransientShortcuts.put(newShortcut.getId(), newShortcut);
                    mTransientShortcuts.put(newShortcut.getId(), newShortcut);
                }
                }
            }
            }
@@ -482,7 +482,7 @@ class ShortcutPackage extends ShortcutPackageItem {


        if (newShortcut.isExcludedFromSurfaces(ShortcutInfo.SURFACE_LAUNCHER)) {
        if (newShortcut.isExcludedFromSurfaces(ShortcutInfo.SURFACE_LAUNCHER)) {
            if (isAppSearchEnabled()) {
            if (isAppSearchEnabled()) {
                synchronized (mLock) {
                synchronized (mPackageItemLock) {
                    mTransientShortcuts.put(newShortcut.getId(), newShortcut);
                    mTransientShortcuts.put(newShortcut.getId(), newShortcut);
                }
                }
            }
            }
@@ -506,7 +506,7 @@ class ShortcutPackage extends ShortcutPackageItem {
        final ShortcutService service = mShortcutUser.mService;
        final ShortcutService service = mShortcutUser.mService;
        // Ensure the total number of shortcuts doesn't exceed the hard limit per app.
        // Ensure the total number of shortcuts doesn't exceed the hard limit per app.
        final int maxShortcutPerApp = service.getMaxAppShortcuts();
        final int maxShortcutPerApp = service.getMaxAppShortcuts();
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            final List<ShortcutInfo> appShortcuts = mShortcuts.values().stream().filter(si ->
            final List<ShortcutInfo> appShortcuts = mShortcuts.values().stream().filter(si ->
                    !si.isPinned()).collect(Collectors.toList());
                    !si.isPinned()).collect(Collectors.toList());
            if (appShortcuts.size() >= maxShortcutPerApp) {
            if (appShortcuts.size() >= maxShortcutPerApp) {
@@ -555,7 +555,7 @@ class ShortcutPackage extends ShortcutPackageItem {
    public List<ShortcutInfo> deleteAllDynamicShortcuts() {
    public List<ShortcutInfo> deleteAllDynamicShortcuts() {
        final long now = mShortcutUser.mService.injectCurrentTimeMillis();
        final long now = mShortcutUser.mService.injectCurrentTimeMillis();
        boolean changed = false;
        boolean changed = false;
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            for (int i = mShortcuts.size() - 1; i >= 0; i--) {
            for (int i = mShortcuts.size() - 1; i >= 0; i--) {
                ShortcutInfo si = mShortcuts.valueAt(i);
                ShortcutInfo si = mShortcuts.valueAt(i);
                if (si.isDynamic() && si.isVisibleToPublisher()) {
                if (si.isDynamic() && si.isVisibleToPublisher()) {
@@ -914,7 +914,7 @@ class ShortcutPackage extends ShortcutPackageItem {


    List<ShortcutManager.ShareShortcutInfo> getMatchingShareTargets(
    List<ShortcutManager.ShareShortcutInfo> getMatchingShareTargets(
            @NonNull final IntentFilter filter, @Nullable final String pkgName) {
            @NonNull final IntentFilter filter, @Nullable final String pkgName) {
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            final List<ShareTargetInfo> matchedTargets = new ArrayList<>();
            final List<ShareTargetInfo> matchedTargets = new ArrayList<>();
            for (int i = 0; i < mShareTargets.size(); i++) {
            for (int i = 0; i < mShareTargets.size(); i++) {
                final ShareTargetInfo target = mShareTargets.get(i);
                final ShareTargetInfo target = mShareTargets.get(i);
@@ -967,7 +967,7 @@ class ShortcutPackage extends ShortcutPackageItem {
    }
    }


    public boolean hasShareTargets() {
    public boolean hasShareTargets() {
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            return !mShareTargets.isEmpty();
            return !mShareTargets.isEmpty();
        }
        }
    }
    }
@@ -978,7 +978,7 @@ class ShortcutPackage extends ShortcutPackageItem {
     * the app's Xml resource.
     * the app's Xml resource.
     */
     */
    int getSharingShortcutCount() {
    int getSharingShortcutCount() {
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            if (mShareTargets.isEmpty()) {
            if (mShareTargets.isEmpty()) {
                return 0;
                return 0;
            }
            }
@@ -1017,7 +1017,7 @@ class ShortcutPackage extends ShortcutPackageItem {
    /**
    /**
     * Return the filenames (excluding path names) of icon bitmap files from this package.
     * Return the filenames (excluding path names) of icon bitmap files from this package.
     */
     */
    @GuardedBy("mLock")
    @GuardedBy("mPackageItemLock")
    private ArraySet<String> getUsedBitmapFilesLocked() {
    private ArraySet<String> getUsedBitmapFilesLocked() {
        final ArraySet<String> usedFiles = new ArraySet<>(1);
        final ArraySet<String> usedFiles = new ArraySet<>(1);
        forEachShortcut(si -> {
        forEachShortcut(si -> {
@@ -1029,7 +1029,7 @@ class ShortcutPackage extends ShortcutPackageItem {
    }
    }


    public void cleanupDanglingBitmapFiles(@NonNull File path) {
    public void cleanupDanglingBitmapFiles(@NonNull File path) {
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            mShortcutBitmapSaver.waitForAllSavesLocked();
            mShortcutBitmapSaver.waitForAllSavesLocked();
            final ArraySet<String> usedFiles = getUsedBitmapFilesLocked();
            final ArraySet<String> usedFiles = getUsedBitmapFilesLocked();


@@ -1136,7 +1136,7 @@ class ShortcutPackage extends ShortcutPackageItem {
        // Now prepare to publish manifest shortcuts.
        // Now prepare to publish manifest shortcuts.
        List<ShortcutInfo> newManifestShortcutList = null;
        List<ShortcutInfo> newManifestShortcutList = null;
        int shareTargetSize = 0;
        int shareTargetSize = 0;
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            try {
            try {
                shareTargetSize = mShareTargets.size();
                shareTargetSize = mShareTargets.size();
                newManifestShortcutList = ShortcutParser.parseShortcuts(mShortcutUser.mService,
                newManifestShortcutList = ShortcutParser.parseShortcuts(mShortcutUser.mService,
@@ -1680,7 +1680,7 @@ class ShortcutPackage extends ShortcutPackageItem {


    void reportShortcutUsed(@NonNull final UsageStatsManagerInternal usageStatsManagerInternal,
    void reportShortcutUsed(@NonNull final UsageStatsManagerInternal usageStatsManagerInternal,
            @NonNull final String shortcutId) {
            @NonNull final String shortcutId) {
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            final long currentTS = SystemClock.elapsedRealtime();
            final long currentTS = SystemClock.elapsedRealtime();
            final ShortcutService s = mShortcutUser.mService;
            final ShortcutService s = mShortcutUser.mService;
            if (currentTS - mLastReportedTime > s.mSaveDelayMillis) {
            if (currentTS - mLastReportedTime > s.mSaveDelayMillis) {
@@ -1757,7 +1757,7 @@ class ShortcutPackage extends ShortcutPackageItem {
        pw.println(")");
        pw.println(")");


        pw.println();
        pw.println();
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            mShortcutBitmapSaver.dumpLocked(pw, "  ");
            mShortcutBitmapSaver.dumpLocked(pw, "  ");
        }
        }
    }
    }
@@ -1827,7 +1827,7 @@ class ShortcutPackage extends ShortcutPackageItem {
    @Override
    @Override
    public void saveToXml(@NonNull TypedXmlSerializer out, boolean forBackup)
    public void saveToXml(@NonNull TypedXmlSerializer out, boolean forBackup)
            throws IOException, XmlPullParserException {
            throws IOException, XmlPullParserException {
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            final int size = mShortcuts.size();
            final int size = mShortcuts.size();
            final int shareTargetSize = mShareTargets.size();
            final int shareTargetSize = mShareTargets.size();


@@ -2037,7 +2037,7 @@ class ShortcutPackage extends ShortcutPackageItem {


        final ShortcutPackage ret = new ShortcutPackage(shortcutUser,
        final ShortcutPackage ret = new ShortcutPackage(shortcutUser,
                shortcutUser.getUserId(), packageName);
                shortcutUser.getUserId(), packageName);
        synchronized (ret.mLock) {
        synchronized (ret.mPackageItemLock) {
            ret.mIsAppSearchSchemaUpToDate = ShortcutService.parseIntAttribute(
            ret.mIsAppSearchSchemaUpToDate = ShortcutService.parseIntAttribute(
                    parser, ATTR_SCHEMA_VERSON, 0) == AppSearchShortcutInfo.SCHEMA_VERSION;
                    parser, ATTR_SCHEMA_VERSON, 0) == AppSearchShortcutInfo.SCHEMA_VERSION;


@@ -2283,7 +2283,7 @@ class ShortcutPackage extends ShortcutPackageItem {


    @VisibleForTesting
    @VisibleForTesting
    List<ShareTargetInfo> getAllShareTargetsForTest() {
    List<ShareTargetInfo> getAllShareTargetsForTest() {
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            return new ArrayList<>(mShareTargets);
            return new ArrayList<>(mShareTargets);
        }
        }
    }
    }
@@ -2404,7 +2404,7 @@ class ShortcutPackage extends ShortcutPackageItem {
            @NonNull final Consumer<ShortcutInfo> transform) {
            @NonNull final Consumer<ShortcutInfo> transform) {
        Objects.requireNonNull(id);
        Objects.requireNonNull(id);
        Objects.requireNonNull(transform);
        Objects.requireNonNull(transform);
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            if (shortcut != null) {
            if (shortcut != null) {
                transform.accept(shortcut);
                transform.accept(shortcut);
            }
            }
@@ -2424,7 +2424,7 @@ class ShortcutPackage extends ShortcutPackageItem {


    private void saveShortcut(@NonNull final Collection<ShortcutInfo> shortcuts) {
    private void saveShortcut(@NonNull final Collection<ShortcutInfo> shortcuts) {
        Objects.requireNonNull(shortcuts);
        Objects.requireNonNull(shortcuts);
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            for (ShortcutInfo si : shortcuts) {
            for (ShortcutInfo si : shortcuts) {
                mShortcuts.put(si.getId(), si);
                mShortcuts.put(si.getId(), si);
            }
            }
@@ -2433,7 +2433,7 @@ class ShortcutPackage extends ShortcutPackageItem {


    @Nullable
    @Nullable
    List<ShortcutInfo> findAll(@NonNull final Collection<String> ids) {
    List<ShortcutInfo> findAll(@NonNull final Collection<String> ids) {
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            return ids.stream().map(mShortcuts::get)
            return ids.stream().map(mShortcuts::get)
                    .filter(Objects::nonNull).collect(Collectors.toList());
                    .filter(Objects::nonNull).collect(Collectors.toList());
        }
        }
@@ -2455,7 +2455,7 @@ class ShortcutPackage extends ShortcutPackageItem {


    private void forEachShortcutStopWhen(
    private void forEachShortcutStopWhen(
            @NonNull final Function<ShortcutInfo, Boolean> cb) {
            @NonNull final Function<ShortcutInfo, Boolean> cb) {
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            for (int i = mShortcuts.size() - 1; i >= 0; i--) {
            for (int i = mShortcuts.size() - 1; i >= 0; i--) {
                final ShortcutInfo si = mShortcuts.valueAt(i);
                final ShortcutInfo si = mShortcuts.valueAt(i);
                if (cb.apply(si)) {
                if (cb.apply(si)) {
@@ -2600,7 +2600,7 @@ class ShortcutPackage extends ShortcutPackageItem {
                        })));
                        })));
    }
    }


    @GuardedBy("mLock")
    @GuardedBy("mPackageItemLock")
    @Override
    @Override
    void scheduleSaveToAppSearchLocked() {
    void scheduleSaveToAppSearchLocked() {
        final Map<String, ShortcutInfo> copy = new ArrayMap<>(mShortcuts);
        final Map<String, ShortcutInfo> copy = new ArrayMap<>(mShortcuts);
@@ -2684,7 +2684,7 @@ class ShortcutPackage extends ShortcutPackageItem {
                    .penaltyLog() // TODO: change this to penaltyDeath to fix the call-site
                    .penaltyLog() // TODO: change this to penaltyDeath to fix the call-site
                    .build());
                    .build());
            future = mShortcutUser.getAppSearch(searchContext);
            future = mShortcutUser.getAppSearch(searchContext);
            synchronized (mLock) {
            synchronized (mPackageItemLock) {
                if (!mIsAppSearchSchemaUpToDate) {
                if (!mIsAppSearchSchemaUpToDate) {
                    future = future.thenCompose(this::setupSchema);
                    future = future.thenCompose(this::setupSchema);
                }
                }
+11 −11
Original line number Original line Diff line number Diff line
@@ -39,7 +39,7 @@ import java.nio.charset.StandardCharsets;
import java.util.Objects;
import java.util.Objects;


/**
/**
 * All methods should be either guarded by {@code #mShortcutUser.mService.mLock} or {@code #mLock}.
 * All methods should be either guarded by {@code #mPackageItemLock}.
 */
 */
abstract class ShortcutPackageItem {
abstract class ShortcutPackageItem {
    private static final String TAG = ShortcutService.TAG;
    private static final String TAG = ShortcutService.TAG;
@@ -52,10 +52,10 @@ abstract class ShortcutPackageItem {


    protected ShortcutUser mShortcutUser;
    protected ShortcutUser mShortcutUser;


    @GuardedBy("mLock")
    @GuardedBy("mPackageItemLock")
    protected final ShortcutBitmapSaver mShortcutBitmapSaver;
    protected final ShortcutBitmapSaver mShortcutBitmapSaver;


    protected final Object mLock = new Object();
    protected final Object mPackageItemLock = new Object();


    protected ShortcutPackageItem(@NonNull ShortcutUser shortcutUser,
    protected ShortcutPackageItem(@NonNull ShortcutUser shortcutUser,
            int packageUserId, @NonNull String packageName,
            int packageUserId, @NonNull String packageName,
@@ -157,7 +157,7 @@ abstract class ShortcutPackageItem {
    public abstract void saveToXml(@NonNull TypedXmlSerializer out, boolean forBackup)
    public abstract void saveToXml(@NonNull TypedXmlSerializer out, boolean forBackup)
            throws IOException, XmlPullParserException;
            throws IOException, XmlPullParserException;


    @GuardedBy("mLock")
    @GuardedBy("mPackageItemLock")
    public void saveToFileLocked(File path, boolean forBackup) {
    public void saveToFileLocked(File path, boolean forBackup) {
        try (ResilientAtomicFile file = getResilientFile(path)) {
        try (ResilientAtomicFile file = getResilientFile(path)) {
            FileOutputStream os = null;
            FileOutputStream os = null;
@@ -187,7 +187,7 @@ abstract class ShortcutPackageItem {
        }
        }
    }
    }


    @GuardedBy("mLock")
    @GuardedBy("mPackageItemLock")
    void scheduleSaveToAppSearchLocked() {
    void scheduleSaveToAppSearchLocked() {


    }
    }
@@ -219,7 +219,7 @@ abstract class ShortcutPackageItem {
        if (ShortcutService.DEBUG || ShortcutService.DEBUG_REBOOT) {
        if (ShortcutService.DEBUG || ShortcutService.DEBUG_REBOOT) {
            Slog.d(TAG, "Saving package item " + getPackageName() + " to " + path);
            Slog.d(TAG, "Saving package item " + getPackageName() + " to " + path);
        }
        }
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            path.getParentFile().mkdirs();
            path.getParentFile().mkdirs();
            // TODO: Since we are persisting shortcuts into AppSearch, we should read from/write to
            // TODO: Since we are persisting shortcuts into AppSearch, we should read from/write to
            //  AppSearch as opposed to maintaining a separate XML file.
            //  AppSearch as opposed to maintaining a separate XML file.
@@ -229,14 +229,14 @@ abstract class ShortcutPackageItem {
    }
    }


    public boolean waitForBitmapSaves() {
    public boolean waitForBitmapSaves() {
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            return mShortcutBitmapSaver.waitForAllSavesLocked();
            return mShortcutBitmapSaver.waitForAllSavesLocked();
        }
        }
    }
    }


    public void saveBitmap(ShortcutInfo shortcut,
    public void saveBitmap(ShortcutInfo shortcut,
            int maxDimension, Bitmap.CompressFormat format, int quality) {
            int maxDimension, Bitmap.CompressFormat format, int quality) {
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            mShortcutBitmapSaver.saveBitmapLocked(shortcut, maxDimension, format, quality);
            mShortcutBitmapSaver.saveBitmapLocked(shortcut, maxDimension, format, quality);
        }
        }
    }
    }
@@ -246,19 +246,19 @@ abstract class ShortcutPackageItem {
     */
     */
    @Nullable
    @Nullable
    public String getBitmapPathMayWait(ShortcutInfo shortcut) {
    public String getBitmapPathMayWait(ShortcutInfo shortcut) {
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            return mShortcutBitmapSaver.getBitmapPathMayWaitLocked(shortcut);
            return mShortcutBitmapSaver.getBitmapPathMayWaitLocked(shortcut);
        }
        }
    }
    }


    public void removeIcon(ShortcutInfo shortcut) {
    public void removeIcon(ShortcutInfo shortcut) {
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            mShortcutBitmapSaver.removeIcon(shortcut);
            mShortcutBitmapSaver.removeIcon(shortcut);
        }
        }
    }
    }


    void removeShortcutPackageItem() {
    void removeShortcutPackageItem() {
        synchronized (mLock) {
        synchronized (mPackageItemLock) {
            getResilientFile(getShortcutPackageItemFile()).delete();
            getResilientFile(getShortcutPackageItemFile()).delete();
        }
        }
    }
    }
+106 −106

File changed.

Preview size limit exceeded, changes collapsed.