summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author Shubhi <shubhisaxena@google.com> 2025-02-24 18:27:41 +0000
committer Shubhi <shubhisaxena@google.com> 2025-02-27 17:41:10 +0000
commit37a8ed07adff4b374d169613c2b471b56954a047 (patch)
treed7556c7ab108b4551816fab06b2c86678577ebc3 /src
parentfd58e8d50d9f3c9cbd6ce62285d39efc51563c72 (diff)
Hide cloud collections when a full sync is in progress
* Media set contents are only visible in Photopicker UI if they have also been synced in the main media table. * For large cloud libraries, in case a full sync is triggered, it can take a while before media sets contents can be displayed to the user. In order to mitigate this, hide the categories that contain media set contents while a full sync pending or in progress. Bug: 393046585 Test: atest PickerSyncControllerTest Flag: EXEMPT mitigation Change-Id: Ie50daa7e9e8d84ee3e565f4299ba53310ea3a1ed
Diffstat (limited to 'src')
-rw-r--r--src/com/android/providers/media/photopicker/PickerSyncController.java80
-rw-r--r--src/com/android/providers/media/photopicker/v2/PickerDataLayerV2.java12
2 files changed, 90 insertions, 2 deletions
diff --git a/src/com/android/providers/media/photopicker/PickerSyncController.java b/src/com/android/providers/media/photopicker/PickerSyncController.java
index 34e02645a..b29d52896 100644
--- a/src/com/android/providers/media/photopicker/PickerSyncController.java
+++ b/src/com/android/providers/media/photopicker/PickerSyncController.java
@@ -1469,6 +1469,38 @@ public class PickerSyncController {
return bundle;
}
+ /**
+ * Checks if full sync is pending for the given CMP.
+ *
+ * @param authority Authority of the CMP that uniquely identifies it.
+ * @param isLocal true of the authority belongs to the local provider, else false.
+ * @return true if full sync is pending for the CMP, else false.
+ * @throws RequestObsoleteException if the input authority is different than the authority of
+ * the current cloud provider.
+ */
+ public boolean isFullSyncPending(@NonNull String authority, boolean isLocal)
+ throws RequestObsoleteException {
+ final ProviderCollectionInfo latestCollectionInfo = isLocal
+ ? getLocalProviderLatestCollectionInfo()
+ : getCloudProviderLatestCollectionInfo();
+
+ if (!authority.equals(latestCollectionInfo.getAuthority())) {
+ throw new RequestObsoleteException(
+ "Authority has changed to " + latestCollectionInfo.getAuthority());
+ }
+
+ final Bundle cachedPreviousCollectionInfo = getCachedMediaCollectionInfo(isLocal);
+ final String cachedPreviousCollectionId =
+ cachedPreviousCollectionInfo.getString(MEDIA_COLLECTION_ID);
+ final long cachedPreviousGeneration =
+ cachedPreviousCollectionInfo.getLong(LAST_MEDIA_SYNC_GENERATION);
+
+ return isFullSyncRequired(
+ latestCollectionInfo.getCollectionId(),
+ cachedPreviousCollectionId,
+ cachedPreviousGeneration);
+ }
+
@NonNull
private SyncRequestParams getSyncRequestParams(@Nullable String authority,
boolean isLocal) throws RequestObsoleteException, UnableToAcquireLockException {
@@ -1523,7 +1555,7 @@ public class PickerSyncController {
+ "ID/Gen=" + latestCollectionId + "/" + latestGeneration);
}
- if (!Objects.equals(latestCollectionId, cachedCollectionId)) {
+ if (isFullSyncWithResetRequired(latestCollectionId, cachedCollectionId)) {
result = SyncRequestParams.forFullMediaWithReset(latestMediaCollectionInfo);
// Update collection info cache.
@@ -1535,7 +1567,8 @@ public class PickerSyncController {
new ProviderCollectionInfo(authority, latestCollectionId, latestAccountName,
latestAccountConfigurationIntent);
updateLatestKnownCollectionInfoLocked(isLocal, latestCollectionInfo);
- } else if (cachedGeneration == DEFAULT_GENERATION) {
+ } else if (isFullSyncWithoutResetRequired(
+ latestCollectionId, cachedCollectionId, cachedGeneration)) {
result = SyncRequestParams.forFullMedia(latestMediaCollectionInfo);
} else if (cachedGeneration == latestGeneration) {
result = SyncRequestParams.forNone();
@@ -1548,6 +1581,49 @@ public class PickerSyncController {
return result;
}
+ /**
+ * @param latestCollectionId The latest collection id of the CMP library.
+ * @param cachedCollectionId The last collection id Picker DB was synced with, either fully
+ * or partially.
+ * @param cachedGenerationId The last generation id Picker DB was synced with.
+ * @return true if a full sync is pending, else false.
+ */
+ private boolean isFullSyncRequired(
+ @Nullable String latestCollectionId,
+ @Nullable String cachedCollectionId,
+ long cachedGenerationId) {
+ return isFullSyncWithResetRequired(latestCollectionId, cachedCollectionId)
+ || isFullSyncWithoutResetRequired(latestCollectionId, cachedCollectionId,
+ cachedGenerationId);
+ }
+
+ /**
+ * @param latestCollectionId The latest collection id of the CMP library.
+ * @param cachedCollectionId The last collection id Picker DB was synced with, either fully
+ * or partially.
+ * @return true if a full sync with reset is pending, else false.
+ */
+ private boolean isFullSyncWithResetRequired(
+ @Nullable String latestCollectionId,
+ @Nullable String cachedCollectionId) {
+ return !Objects.equals(latestCollectionId, cachedCollectionId);
+ }
+
+ /**
+ * @param latestCollectionId The latest collection id of the CMP library.
+ * @param cachedCollectionId The last collection id Picker DB was synced with, either fully
+ * or partially.
+ * @param cachedGenerationId The last generation id Picker DB was synced with.
+ * @return true if a resumable full sync is pending, else false.
+ */
+ private boolean isFullSyncWithoutResetRequired(
+ @Nullable String latestCollectionId,
+ @Nullable String cachedCollectionId,
+ long cachedGenerationId) {
+ return Objects.equals(latestCollectionId, cachedCollectionId)
+ && cachedGenerationId == DEFAULT_GENERATION;
+ }
+
private void updateLatestKnownCollectionInfoLocked(
boolean isLocal,
@Nullable ProviderCollectionInfo latestCollectionInfo) {
diff --git a/src/com/android/providers/media/photopicker/v2/PickerDataLayerV2.java b/src/com/android/providers/media/photopicker/v2/PickerDataLayerV2.java
index 3f970463f..6471205f2 100644
--- a/src/com/android/providers/media/photopicker/v2/PickerDataLayerV2.java
+++ b/src/com/android/providers/media/photopicker/v2/PickerDataLayerV2.java
@@ -1132,6 +1132,18 @@ public class PickerDataLayerV2 {
Log.d(TAG, "Cannot fetch cloud categories when cloud authority is null.");
return null;
}
+
+ try {
+ if (syncController.isFullSyncPending(cloudAuthority, /* isLocal */ false)) {
+ Log.d(TAG, "Don't return cloud categories when full sync is pending.");
+ return null;
+ }
+ } catch (RequestObsoleteException | RuntimeException e) {
+ Log.e(TAG, "Could not check if full sync is pending. "
+ + "Not returning cloud categories", e);
+ return null;
+ }
+
final PickerSearchProviderClient searchClient = PickerSearchProviderClient.create(
appContext, cloudAuthority);
if (syncController.getCategoriesState().areCategoriesEnabled(