summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Pinyao Ting <pinyaoting@google.com> 2022-01-22 05:12:10 +0000
committer Pinyao Ting <pinyaoting@google.com> 2022-01-26 21:35:00 +0000
commit523f3050065010afb4a0b7d409a9a062535f6b29 (patch)
tree4617c01a34de995a02748a2dc071415344f0d765
parented0e121883152eadea5dbcb8fa08b2c0e3a1a324 (diff)
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
-rw-r--r--services/core/java/com/android/server/pm/ShortcutPackage.java23
-rw-r--r--services/core/java/com/android/server/pm/ShortcutService.java19
2 files changed, 28 insertions, 14 deletions
diff --git a/services/core/java/com/android/server/pm/ShortcutPackage.java b/services/core/java/com/android/server/pm/ShortcutPackage.java
index 72db2428c8c9..bda25895a4b3 100644
--- a/services/core/java/com/android/server/pm/ShortcutPackage.java
+++ b/services/core/java/com/android/server/pm/ShortcutPackage.java
@@ -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 {
diff --git a/services/core/java/com/android/server/pm/ShortcutService.java b/services/core/java/com/android/server/pm/ShortcutService.java
index 8393deea1e7b..27605789891e 100644
--- a/services/core/java/com/android/server/pm/ShortcutService.java
+++ b/services/core/java/com/android/server/pm/ShortcutService.java
@@ -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.