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

Commit 1b46dcdc authored by Aditya's avatar Aditya
Browse files

Modify onProfileActionStatusChange and add tests.

Modified onProfileActionStatusChange in UserManagerState to make it more
generalised for all kinds of profiles that may come up in the future.
Added tests for getUserIdToLabelMap and getUserIdToBadgeMap.

Bug: 321894374
Test: atest DocumentsUIGoogleTests:UserManagerStateTest
Change-Id: Id2e9f668b3746cee3475d1faf824d40cef1e974b
parent f4fb5cec
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -140,7 +140,7 @@ public abstract class BaseActivity

    @VisibleForTesting
    protected void initConfigStore() {
        mConfigStore = DocumentsApplication.getConfigStore(this);
        mConfigStore = DocumentsApplication.getConfigStore();
    }

    @VisibleForTesting
@@ -287,6 +287,12 @@ public abstract class BaseActivity

        mUserIdManager = DocumentsApplication.getUserIdManager(this);
        mUserManagerState = DocumentsApplication.getUserManagerState(this);
        // If private space feature flag is enabled, we should store the intent that launched docsUi
        // so that we can use this intent to get CrossProfileResolveInfo when ever we want to,
        // for example when ACTION_PROFILE_AVAILABLE intent is received
        if (mUserManagerState != null) {
            mUserManagerState.setCurrentStateIntent(intent);
        }
        mSearchManager = new SearchViewManager(searchListener, queryInterceptor,
                chipGroup, savedInstanceState);
        // initialize the chip sets by accept mime types
+7 −15
Original line number Diff line number Diff line
@@ -85,7 +85,7 @@ public class DocumentsApplication extends Application {
    public static ProvidersCache getProvidersCache(Context context) {
        ProvidersCache providers =
                ((DocumentsApplication) context.getApplicationContext()).mProviders;
        final ConfigStore configStore = getConfigStore(context);
        final ConfigStore configStore = getConfigStore();
        // 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.
@@ -140,7 +140,7 @@ public class DocumentsApplication extends Application {
    public static UserManagerState getUserManagerState(Context context) {
        UserManagerState userManagerState =
                ((DocumentsApplication) context.getApplicationContext()).mUserManagerState;
        if (userManagerState == null && getConfigStore(context).isPrivateSpaceInDocsUIEnabled()) {
        if (userManagerState == null && getConfigStore().isPrivateSpaceInDocsUIEnabled()) {
            userManagerState = UserManagerState.create(context);
            ((DocumentsApplication) context.getApplicationContext()).mUserManagerState =
                    userManagerState;
@@ -159,21 +159,13 @@ public class DocumentsApplication extends Application {
    /**
     * Retrieve {@link ConfigStore} instance to access feature flags in production code.
     */
    public static synchronized ConfigStore getConfigStore(Context context) {
    public static synchronized ConfigStore getConfigStore() {
        if (sConfigStore == null) {
            sConfigStore = new ConfigStore.ConfigStoreImpl();
        }
        return sConfigStore;
    }

    /**
     * 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}
@@ -217,17 +209,17 @@ public class DocumentsApplication extends Application {
            Log.w(TAG, "Can't obtain OverlayManager from System Service!");
        }

        if (getConfigStore(this).isPrivateSpaceInDocsUIEnabled()) {
        if (getConfigStore().isPrivateSpaceInDocsUIEnabled()) {
            mUserManagerState = UserManagerState.create(this);
            mUserIdManager = null;
            synchronized (DocumentsApplication.class) {
                mProviders = new ProvidersCache(this, mUserManagerState, getConfigStore(this));
                mProviders = new ProvidersCache(this, mUserManagerState, getConfigStore());
            }
        } else {
            mUserManagerState = null;
            mUserIdManager = UserIdManager.create(this);
            synchronized (DocumentsApplication.class) {
                mProviders = new ProvidersCache(this, mUserIdManager, getConfigStore(this));
                mProviders = new ProvidersCache(this, mUserIdManager, getConfigStore());
            }
        }

@@ -290,7 +282,7 @@ 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()) {
                if (getConfigStore().isPrivateSpaceInDocsUIEnabled()) {
                    UserHandle userHandle = intent.getParcelableExtra(Intent.EXTRA_USER);
                    UserId userId = UserId.of(userHandle);
                    getUserManagerState(context).onProfileActionStatusChange(action, userId);
+32 −16
Original line number Diff line number Diff line
@@ -94,6 +94,11 @@ public interface UserManagerState {
     */
    void onProfileActionStatusChange(String action, UserId userId);

    /**
     * Sets the intent that triggered the launch of the DocsUI
     */
    void setCurrentStateIntent(Intent intent);

    /**
     * Creates an implementation of {@link UserManagerState}.
     */
@@ -136,6 +141,7 @@ public interface UserManagerState {
        @GuardedBy("mCanFrowardToProfileIdMap")
        private final Map<UserId, Boolean> mCanFrowardToProfileIdMap = new HashMap<>();

        private Intent mCurrentStateIntent;

        private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
            @Override
@@ -159,7 +165,7 @@ public interface UserManagerState {
        private RuntimeUserManagerState(Context context) {
            this(context, UserId.CURRENT_USER,
                    Features.CROSS_PROFILE_TABS && isDeviceSupported(context),
                    DocumentsApplication.getConfigStore(context));
                    DocumentsApplication.getConfigStore());
        }

        @VisibleForTesting
@@ -185,7 +191,6 @@ public interface UserManagerState {
        public List<UserId> getUserIds() {
            synchronized (mUserIds) {
                if (mUserIds.isEmpty()) {
                    Log.d("profileAction", "user ids empty");
                    mUserIds.addAll(getUserIdsInternal());
                }
                return mUserIds;
@@ -234,15 +239,6 @@ public interface UserManagerState {
                synchronized (mUserIds) {
                    mUserIds.remove(userId);
                }
                synchronized (mUserIdToLabelMap) {
                    mUserIdToLabelMap.remove(userId);
                }
                synchronized (mUserIdToBadgeMap) {
                    mUserIdToBadgeMap.remove(userId);
                }
                synchronized (mCanFrowardToProfileIdMap) {
                    mCanFrowardToProfileIdMap.remove(userId);
                }
            } else if (Intent.ACTION_PROFILE_AVAILABLE.equals(action)) {
                synchronized (mUserIds) {
                    if (!mUserIds.contains(userId)) {
@@ -250,19 +246,40 @@ public interface UserManagerState {
                    }
                }
                synchronized (mUserIdToLabelMap) {
                    if (!mUserIdToLabelMap.containsKey(userId)) {
                        mUserIdToLabelMap.put(userId, getProfileLabel(userId));
                    }
                }
                synchronized (mUserIdToBadgeMap) {
                    if (!mUserIdToBadgeMap.containsKey(userId)) {
                        mUserIdToBadgeMap.put(userId, getProfileBadge(userId));
                    }
                }
                synchronized (mCanFrowardToProfileIdMap) {
                    if (!mCanFrowardToProfileIdMap.containsKey(userId)) {
                        if (userId.getIdentifier() == ActivityManager.getCurrentUser()
                                || isCrossProfileContentSharingStrategyDelegatedFromParent(
                                UserHandle.of(userId.getIdentifier()))
                                || CrossProfileUtils.getCrossProfileResolveInfo(mCurrentUser,
                                mContext.getPackageManager(), mCurrentStateIntent, mContext,
                                mConfigStore.isPrivateSpaceInDocsUIEnabled()) != null) {
                            mCanFrowardToProfileIdMap.put(userId, true);
                        } else {
                            mCanFrowardToProfileIdMap.put(userId, false);
                        }

                    }
                }
            } else {
                Log.e(TAG, "Unexpected action received: " + action);
            }
        }

        @Override
        public void setCurrentStateIntent(Intent intent) {
            mCurrentStateIntent = intent;
        }

        private List<UserId> getUserIdsInternal() {
            final List<UserId> result = new ArrayList<>();

@@ -538,8 +555,7 @@ public interface UserManagerState {
            /*
             * Cross profile resolve info need to be checked in the following 2 cases:
             * 1. current user is either parent or delegates check to parent and the target user
             * does
             *    not delegate to parent
             *    does not delegate to parent
             * 2. current user does not delegate check to the parent and the target user is the
             *    parent profile
             */
+1 −1
Original line number Diff line number Diff line
@@ -300,7 +300,7 @@ public class FilesActivity extends BaseActivity implements AbstractActionHandler
    }

    @Override
    public void onDestroy() {
    protected void onDestroy() {
        super.onDestroy();
    }

+5 −0
Original line number Diff line number Diff line
@@ -299,6 +299,11 @@ public class PickActivity extends BaseActivity implements ActionHandler.Addons {
        mNavigator.update();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public String getDrawerTitle() {
        String title;
Loading