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

Commit 7a26faa3 authored by Aditya's avatar Aditya Committed by Automerger Merge Worker
Browse files

Modify onProfileActionStatusChange and add tests. am: 1b46dcdc

parents e906ca47 1b46dcdc
Loading
Loading
Loading
Loading
+7 −1
Original line number Original line Diff line number Diff line
@@ -140,7 +140,7 @@ public abstract class BaseActivity


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


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


        mUserIdManager = DocumentsApplication.getUserIdManager(this);
        mUserIdManager = DocumentsApplication.getUserIdManager(this);
        mUserManagerState = DocumentsApplication.getUserManagerState(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,
        mSearchManager = new SearchViewManager(searchListener, queryInterceptor,
                chipGroup, savedInstanceState);
                chipGroup, savedInstanceState);
        // initialize the chip sets by accept mime types
        // initialize the chip sets by accept mime types
+7 −15
Original line number Original line Diff line number Diff line
@@ -85,7 +85,7 @@ public class DocumentsApplication extends Application {
    public static ProvidersCache getProvidersCache(Context context) {
    public static ProvidersCache getProvidersCache(Context context) {
        ProvidersCache providers =
        ProvidersCache providers =
                ((DocumentsApplication) context.getApplicationContext()).mProviders;
                ((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
        // 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
        // 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.
        // 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) {
    public static UserManagerState getUserManagerState(Context context) {
        UserManagerState userManagerState =
        UserManagerState userManagerState =
                ((DocumentsApplication) context.getApplicationContext()).mUserManagerState;
                ((DocumentsApplication) context.getApplicationContext()).mUserManagerState;
        if (userManagerState == null && getConfigStore(context).isPrivateSpaceInDocsUIEnabled()) {
        if (userManagerState == null && getConfigStore().isPrivateSpaceInDocsUIEnabled()) {
            userManagerState = UserManagerState.create(context);
            userManagerState = UserManagerState.create(context);
            ((DocumentsApplication) context.getApplicationContext()).mUserManagerState =
            ((DocumentsApplication) context.getApplicationContext()).mUserManagerState =
                    userManagerState;
                    userManagerState;
@@ -159,21 +159,13 @@ public class DocumentsApplication extends Application {
    /**
    /**
     * Retrieve {@link ConfigStore} instance to access feature flags in production code.
     * 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) {
        if (sConfigStore == null) {
            sConfigStore = new ConfigStore.ConfigStoreImpl();
            sConfigStore = new ConfigStore.ConfigStoreImpl();
        }
        }
        return sConfigStore;
        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
     * Set {@link #mUserManagerState} as null onDestroy of BaseActivity so that new session uses new
     * instance of {@link #mUserManagerState}
     * instance of {@link #mUserManagerState}
@@ -217,17 +209,17 @@ public class DocumentsApplication extends Application {
            Log.w(TAG, "Can't obtain OverlayManager from System Service!");
            Log.w(TAG, "Can't obtain OverlayManager from System Service!");
        }
        }


        if (getConfigStore(this).isPrivateSpaceInDocsUIEnabled()) {
        if (getConfigStore().isPrivateSpaceInDocsUIEnabled()) {
            mUserManagerState = UserManagerState.create(this);
            mUserManagerState = UserManagerState.create(this);
            mUserIdManager = null;
            mUserIdManager = null;
            synchronized (DocumentsApplication.class) {
            synchronized (DocumentsApplication.class) {
                mProviders = new ProvidersCache(this, mUserManagerState, getConfigStore(this));
                mProviders = new ProvidersCache(this, mUserManagerState, getConfigStore());
            }
            }
        } else {
        } else {
            mUserManagerState = null;
            mUserManagerState = null;
            mUserIdManager = UserIdManager.create(this);
            mUserIdManager = UserIdManager.create(this);
            synchronized (DocumentsApplication.class) {
            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)) {
            } else if (PROFILE_FILTER_ACTIONS.contains(action)) {
                // After we have reloaded roots. Resend the broadcast locally so the other
                // After we have reloaded roots. Resend the broadcast locally so the other
                // components can reload properly after roots are updated.
                // components can reload properly after roots are updated.
                if (getConfigStore(context).isPrivateSpaceInDocsUIEnabled()) {
                if (getConfigStore().isPrivateSpaceInDocsUIEnabled()) {
                    UserHandle userHandle = intent.getParcelableExtra(Intent.EXTRA_USER);
                    UserHandle userHandle = intent.getParcelableExtra(Intent.EXTRA_USER);
                    UserId userId = UserId.of(userHandle);
                    UserId userId = UserId.of(userHandle);
                    getUserManagerState(context).onProfileActionStatusChange(action, userId);
                    getUserManagerState(context).onProfileActionStatusChange(action, userId);
+32 −16
Original line number Original line Diff line number Diff line
@@ -94,6 +94,11 @@ public interface UserManagerState {
     */
     */
    void onProfileActionStatusChange(String action, UserId userId);
    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}.
     * Creates an implementation of {@link UserManagerState}.
     */
     */
@@ -136,6 +141,7 @@ public interface UserManagerState {
        @GuardedBy("mCanFrowardToProfileIdMap")
        @GuardedBy("mCanFrowardToProfileIdMap")
        private final Map<UserId, Boolean> mCanFrowardToProfileIdMap = new HashMap<>();
        private final Map<UserId, Boolean> mCanFrowardToProfileIdMap = new HashMap<>();


        private Intent mCurrentStateIntent;


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


        @VisibleForTesting
        @VisibleForTesting
@@ -185,7 +191,6 @@ public interface UserManagerState {
        public List<UserId> getUserIds() {
        public List<UserId> getUserIds() {
            synchronized (mUserIds) {
            synchronized (mUserIds) {
                if (mUserIds.isEmpty()) {
                if (mUserIds.isEmpty()) {
                    Log.d("profileAction", "user ids empty");
                    mUserIds.addAll(getUserIdsInternal());
                    mUserIds.addAll(getUserIdsInternal());
                }
                }
                return mUserIds;
                return mUserIds;
@@ -234,15 +239,6 @@ public interface UserManagerState {
                synchronized (mUserIds) {
                synchronized (mUserIds) {
                    mUserIds.remove(userId);
                    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)) {
            } else if (Intent.ACTION_PROFILE_AVAILABLE.equals(action)) {
                synchronized (mUserIds) {
                synchronized (mUserIds) {
                    if (!mUserIds.contains(userId)) {
                    if (!mUserIds.contains(userId)) {
@@ -250,19 +246,40 @@ public interface UserManagerState {
                    }
                    }
                }
                }
                synchronized (mUserIdToLabelMap) {
                synchronized (mUserIdToLabelMap) {
                    if (!mUserIdToLabelMap.containsKey(userId)) {
                        mUserIdToLabelMap.put(userId, getProfileLabel(userId));
                        mUserIdToLabelMap.put(userId, getProfileLabel(userId));
                    }
                    }
                }
                synchronized (mUserIdToBadgeMap) {
                synchronized (mUserIdToBadgeMap) {
                    if (!mUserIdToBadgeMap.containsKey(userId)) {
                        mUserIdToBadgeMap.put(userId, getProfileBadge(userId));
                        mUserIdToBadgeMap.put(userId, getProfileBadge(userId));
                    }
                    }
                }
                synchronized (mCanFrowardToProfileIdMap) {
                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);
                            mCanFrowardToProfileIdMap.put(userId, true);
                        } else {
                            mCanFrowardToProfileIdMap.put(userId, false);
                        }

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


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

        private List<UserId> getUserIdsInternal() {
        private List<UserId> getUserIdsInternal() {
            final List<UserId> result = new ArrayList<>();
            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:
             * 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
             * 1. current user is either parent or delegates check to parent and the target user
             * does
             *    does not delegate to parent
             *    not delegate to parent
             * 2. current user does not delegate check to the parent and the target user is the
             * 2. current user does not delegate check to the parent and the target user is the
             *    parent profile
             *    parent profile
             */
             */
+1 −1
Original line number Original line Diff line number Diff line
@@ -300,7 +300,7 @@ public class FilesActivity extends BaseActivity implements AbstractActionHandler
    }
    }


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


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


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

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