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

Commit 523f3050 authored by Pinyao Ting's avatar Pinyao Ting
Browse files

Enable Shortcut integration with AppSearch.

Static shortcuts and dynamic shortcuts will now be additionally
persisted in AppSearch in a background thread when they are published.

Shortcuts persisted in AppSearch have a TTL of 90 days and will be
removed if they are not republished (i.e. used by the user) within the
timeframe.

The number of shortcuts persisted in AppSearch are not bounded by the
limit defined in ShortcutManager#getMaxShortcutCountPerActivity.

Bug: 151359749
Test: atest CtsShortcutManagerTestCases
Change-Id: I6b1474bf60529e43172a0facae5561d2d89ede46
parent ed0e1218
Loading
Loading
Loading
Loading
+13 −10
Original line number Diff line number Diff line
@@ -1694,15 +1694,6 @@ class ShortcutPackage extends ShortcutPackageItem {
            for (int j = 0; j < shareTargetSize; j++) {
                mShareTargets.get(j).saveToXml(out);
            }
            synchronized (mLock) {
                final Map<String, ShortcutInfo> copy = mShortcuts;
                if (!mTransientShortcuts.isEmpty()) {
                    copy.putAll(mTransientShortcuts);
                    mTransientShortcuts.clear();
                }
                saveShortcutsAsync(copy.values().stream().filter(ShortcutInfo::usesQuota).collect(
                        Collectors.toList()));
            }
        }

        out.endTag(null, TAG_ROOT);
@@ -2418,6 +2409,18 @@ class ShortcutPackage extends ShortcutPackageItem {
                        })));
    }

    void persistsAllShortcutsAsync() {
        synchronized (mLock) {
            final Map<String, ShortcutInfo> copy = mShortcuts;
            if (!mTransientShortcuts.isEmpty()) {
                copy.putAll(mTransientShortcuts);
                mTransientShortcuts.clear();
            }
            saveShortcutsAsync(copy.values().stream().filter(ShortcutInfo::usesQuota).collect(
                    Collectors.toList()));
        }
    }

    private void saveShortcutsAsync(
            @NonNull final Collection<ShortcutInfo> shortcuts) {
        Objects.requireNonNull(shortcuts);
@@ -2489,7 +2492,7 @@ class ShortcutPackage extends ShortcutPackageItem {
                mIsAppSearchSchemaUpToDate = true;
            }
        } catch (Exception e) {
            Slog.e(TAG, "Failed to invoke app search pkg="
            Slog.e(TAG, "Failed to create app search session. pkg="
                    + getPackageName() + " user=" + mShortcutUser.getUserId(), e);
            Objects.requireNonNull(future).completeExceptionally(e);
        } finally {
+15 −4
Original line number Diff line number Diff line
@@ -488,7 +488,7 @@ public class ShortcutService extends IShortcutService.Stub {
        mShortcutBitmapSaver = new ShortcutBitmapSaver(this);
        mShortcutDumpFiles = new ShortcutDumpFiles(this);
        mIsAppSearchEnabled = DeviceConfig.getBoolean(NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.SHORTCUT_APPSEARCH_INTEGRATION, false);
                SystemUiDeviceConfigFlags.SHORTCUT_APPSEARCH_INTEGRATION, true);

        if (onlyForPackageManagerApis) {
            return; // Don't do anything further.  For unit tests only.
@@ -736,7 +736,7 @@ public class ShortcutService extends IShortcutService.Stub {
            Slog.d(TAG, "unloadUserLocked: user=" + userId);
        }
        // Save all dirty information.
        saveDirtyInfo();
        saveDirtyInfo(false);

        // Unload
        mUsers.delete(userId);
@@ -1191,6 +1191,10 @@ public class ShortcutService extends IShortcutService.Stub {

    @VisibleForTesting
    void saveDirtyInfo() {
        saveDirtyInfo(true);
    }

    private void saveDirtyInfo(boolean saveShortcutsInAppSearch) {
        if (DEBUG || DEBUG_REBOOT) {
            Slog.d(TAG, "saveDirtyInfo");
        }
@@ -1205,6 +1209,10 @@ public class ShortcutService extends IShortcutService.Stub {
                    if (userId == UserHandle.USER_NULL) { // USER_NULL for base state.
                        saveBaseStateLocked();
                    } else {
                        if (saveShortcutsInAppSearch) {
                            getUserShortcutsLocked(userId).forAllPackages(
                                    ShortcutPackage::persistsAllShortcutsAsync);
                        }
                        saveUserLocked(userId);
                    }
                }
@@ -3719,13 +3727,16 @@ public class ShortcutService extends IShortcutService.Stub {
    private final BroadcastReceiver mShutdownReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (DEBUG || DEBUG_REBOOT) {
                Slog.d(TAG, "Shutdown broadcast received.");
            }
            // Since it cleans up the shortcut directory and rewrite the ShortcutPackageItems
            // in odrder during saveToXml(), it could lead to shortcuts missing when shutdown.
            // We need it so that it can finish up saving before shutdown.
            synchronized (mLock) {
                if (mHandler.hasCallbacks(mSaveDirtyInfoRunner)) {
                    mHandler.removeCallbacks(mSaveDirtyInfoRunner);
                    saveDirtyInfo();
                    saveDirtyInfo(false);
                }
                mShutdown.set(true);
            }
@@ -4394,7 +4405,7 @@ public class ShortcutService extends IShortcutService.Stub {

            // Save to the filesystem.
            scheduleSaveUser(userId);
            saveDirtyInfo();
            saveDirtyInfo(false);

            // Note, in case of backup, we don't have to wait on bitmap saving, because we don't
            // back up bitmaps anyway.