diff options
author | 2024-02-14 13:23:48 +0000 | |
---|---|---|
committer | 2024-02-19 07:16:07 +0000 | |
commit | 4f6b2ff5ac461d0517f766ddd06cb6609c4e2ec9 (patch) | |
tree | 477b05be5fb1e8854f3a80a4b8cf3ce4d9dfc6e0 | |
parent | c62da974b9534f29e153736e63a8ee3b3982bb9d (diff) |
Fix for loss of `Recents` content from private tab on flag change.
Invalidated the providers on change in the flag's value. This ensures
that the new session uses correct argument for construction of provider:
UserIdManager when flag is false, and UserStateManager when flag is
true.
Bug: 325203017
Test: Manual testing
Change-Id: Ic768f57f614509775f911983e4859b062a7fe270
3 files changed, 57 insertions, 19 deletions
diff --git a/src/com/android/documentsui/DocumentsApplication.java b/src/com/android/documentsui/DocumentsApplication.java index db7b3f9f9..92aa3f75e 100644 --- a/src/com/android/documentsui/DocumentsApplication.java +++ b/src/com/android/documentsui/DocumentsApplication.java @@ -28,6 +28,7 @@ import android.content.IntentFilter; import android.content.om.OverlayManager; import android.net.Uri; import android.os.RemoteException; +import android.os.UserHandle; import android.text.format.DateUtils; import android.util.Log; @@ -47,7 +48,6 @@ import com.android.modules.utils.build.SdkLevel; import com.google.common.collect.Lists; import java.util.List; -import java.util.Objects; import javax.annotation.concurrent.GuardedBy; @@ -83,7 +83,20 @@ public class DocumentsApplication extends Application { private Lookup<String, String> mFileTypeLookup; public static ProvidersCache getProvidersCache(Context context) { - return ((DocumentsApplication) context.getApplicationContext()).mProviders; + ProvidersCache providers = + ((DocumentsApplication) context.getApplicationContext()).mProviders; + final ConfigStore configStore = getConfigStore(context); + // When private space in DocsUI is enabled then ProvidersCache should use UserManagerState + // else it should use UserIdManager. The following if-check will ensure the construction of + // a new ProvidersCache instance whenever there is a mismatch in this. + if (configStore.isPrivateSpaceInDocsUIEnabled() + != providers.isProvidersCacheUsingUserManagerState()) { + providers = configStore.isPrivateSpaceInDocsUIEnabled() + ? new ProvidersCache(context, getUserManagerState(context), configStore) + : new ProvidersCache(context, getUserIdManager(context), configStore); + ((DocumentsApplication) context.getApplicationContext()).mProviders = providers; + } + return providers; } public static ThumbnailCache getThumbnailCache(Context context) { @@ -111,7 +124,13 @@ public class DocumentsApplication extends Application { } public static UserIdManager getUserIdManager(Context context) { - return ((DocumentsApplication) context.getApplicationContext()).mUserIdManager; + UserIdManager userIdManager = + ((DocumentsApplication) context.getApplicationContext()).mUserIdManager; + if (userIdManager == null) { + userIdManager = UserIdManager.create(context); + ((DocumentsApplication) context.getApplicationContext()).mUserIdManager = userIdManager; + } + return userIdManager; } /** @@ -119,9 +138,14 @@ public class DocumentsApplication extends Application { * cross profile access, label and badge associated with these userIds. */ public static UserManagerState getUserManagerState(Context context) { - return Objects.requireNonNullElseGet( - ((DocumentsApplication) context.getApplicationContext()).mUserManagerState, - () -> UserManagerState.create(context)); + UserManagerState userManagerState = + ((DocumentsApplication) context.getApplicationContext()).mUserManagerState; + if (userManagerState == null && getConfigStore(context).isPrivateSpaceInDocsUIEnabled()) { + userManagerState = UserManagerState.create(context); + ((DocumentsApplication) context.getApplicationContext()).mUserManagerState = + userManagerState; + } + return userManagerState; } public static DragAndDropManager getDragAndDropManager(Context context) { @@ -133,14 +157,6 @@ public class DocumentsApplication extends Application { } /** - * Set {@link #mUserManagerState} as null onDestroy of BaseActivity so that new session uses new - * instance of {@link #mUserManagerState} - */ - public static void invalidateUserManagerState(Context context) { - ((DocumentsApplication) context.getApplicationContext()).mUserManagerState = null; - } - - /** * Retrieve {@link ConfigStore} instance to access feature flags in production code. */ public static synchronized ConfigStore getConfigStore(Context context) { @@ -151,6 +167,22 @@ public class DocumentsApplication extends Application { } /** + * Set {@link #mProviders} as null onDestroy of BaseActivity so that new session uses new + * instance of {@link #mProviders} + */ + public static void invalidateProvidersCache(Context context) { + ((DocumentsApplication) context.getApplicationContext()).mProviders = null; + } + + /** + * Set {@link #mUserManagerState} as null onDestroy of BaseActivity so that new session uses new + * instance of {@link #mUserManagerState} + */ + public static void invalidateUserManagerState(Context context) { + ((DocumentsApplication) context.getApplicationContext()).mUserManagerState = null; + } + + /** * Set {@link #sConfigStore} as null onDestroy of BaseActivity so that new session uses new * instance of {@link #sConfigStore} */ @@ -189,13 +221,13 @@ public class DocumentsApplication extends Application { mUserManagerState = UserManagerState.create(this); mUserIdManager = null; synchronized (DocumentsApplication.class) { - mProviders = new ProvidersCache(this, mUserManagerState, sConfigStore); + mProviders = new ProvidersCache(this, mUserManagerState, getConfigStore(this)); } } else { mUserManagerState = null; mUserIdManager = UserIdManager.create(this); synchronized (DocumentsApplication.class) { - mProviders = new ProvidersCache(this, mUserIdManager, sConfigStore); + mProviders = new ProvidersCache(this, mUserIdManager, getConfigStore(this)); } } @@ -258,6 +290,11 @@ public class DocumentsApplication extends Application { } else if (PROFILE_FILTER_ACTIONS.contains(action)) { // After we have reloaded roots. Resend the broadcast locally so the other // components can reload properly after roots are updated. + if (getConfigStore(context).isPrivateSpaceInDocsUIEnabled()) { + UserHandle userHandle = intent.getParcelableExtra(Intent.EXTRA_USER); + UserId userId = UserId.of(userHandle); + getUserManagerState(context).onProfileActionStatusChange(action, userId); + } mProviders.updateAsync(/* forceRefreshAll= */ true, () -> LocalBroadcastManager.getInstance(context).sendBroadcast(intent)); } else { diff --git a/src/com/android/documentsui/dirlist/DirectoryFragment.java b/src/com/android/documentsui/dirlist/DirectoryFragment.java index 3d47a32c3..32f3683e3 100644 --- a/src/com/android/documentsui/dirlist/DirectoryFragment.java +++ b/src/com/android/documentsui/dirlist/DirectoryFragment.java @@ -91,7 +91,6 @@ import com.android.documentsui.ProfileTabsController; import com.android.documentsui.R; import com.android.documentsui.ThumbnailCache; import com.android.documentsui.TimeoutTask; -import com.android.documentsui.UserManagerState; import com.android.documentsui.base.DocumentFilters; import com.android.documentsui.base.DocumentInfo; import com.android.documentsui.base.DocumentStack; @@ -310,8 +309,6 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On } private void onHiddenProfileStatusChange(String action, UserId userId) { - UserManagerState userManagerState = DocumentsApplication.getUserManagerState(mActivity); - userManagerState.onProfileActionStatusChange(action, userId); if (Intent.ACTION_PROFILE_UNAVAILABLE.equals(action)) { mActivity.setHasProfileBecomeUnavailable(true); if (mProviderTestRunnable != null) { diff --git a/src/com/android/documentsui/roots/ProvidersCache.java b/src/com/android/documentsui/roots/ProvidersCache.java index 317daab25..080b729c5 100644 --- a/src/com/android/documentsui/roots/ProvidersCache.java +++ b/src/com/android/documentsui/roots/ProvidersCache.java @@ -142,6 +142,10 @@ public class ProvidersCache implements ProvidersAccess, LookupApplicationName { mConfigStore = configStore; } + public boolean isProvidersCacheUsingUserManagerState() { + return mUserManagerState != null; + } + /** * Generates recent root for the provided user id */ |