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

Commit 218e63b7 authored by Kelvin Kwan's avatar Kelvin Kwan
Browse files

Only enable cross-profile feature on Android R or above

Bug: 150455760
Test: atest DocumentsUIGoogleTests
Change-Id: I4326ac02b2d6fec893b25e5eaf4fd31b290dd8d7
parent 6afa197c
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -85,6 +85,11 @@ public class State implements android.os.Parcelable {
    public boolean openableOnly;
    public boolean restrictScopeStorage;

    /**
     * Represents whether the state supports cross-profile file picking.
     */
    public boolean supportsCrossProfile = false;

    /**
     * Represents whether the intent is a cross-profile intent
     */
@@ -151,10 +156,10 @@ public class State implements android.os.Parcelable {
    }

    /**
     * Returns true if the action of the {@link State} can support cross-profile by DocsUI.
     * Returns true if DocsUI supports cross-profile for this {@link State}.
     */
    public boolean supportsCrossProfile() {
        return action == ACTION_GET_CONTENT;
        return supportsCrossProfile;
    }

    @Override
+4 −0
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ import com.android.documentsui.sidebar.RootsFragment;
import com.android.documentsui.ui.DialogController;
import com.android.documentsui.ui.MessageBuilder;
import com.android.documentsui.util.CrossProfileUtils;
import com.android.documentsui.util.VersionUtils;

import java.util.Collection;
import java.util.Collections;
@@ -265,6 +266,9 @@ public class PickActivity extends BaseActivity implements ActionHandler.Addons {
            state.copyOperationSubType = intent.getIntExtra(
                    FileOperationService.EXTRA_OPERATION_TYPE,
                    FileOperationService.OPERATION_COPY);
        } else if (Features.CROSS_PROFILE_TABS && VersionUtils.isAtLeastR()
                && state.action == ACTION_GET_CONTENT) {
            state.supportsCrossProfile = true;
        }
    }

+5 −5
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ public class GlobalSearchLoaderTest {

    @Test
    public void testCrossProfileRoot_notInTextSearch_beIgnored() {
        mEnv.state.action = State.ACTION_GET_CONTENT;
        mEnv.state.supportsCrossProfile = true;
        mQueryArgs.remove(DocumentsContract.QUERY_ARG_DISPLAY_NAME);
        TestProvidersAccess.DOWNLOADS.userId = TestProvidersAccess.OtherUser.USER_ID;
        assertThat(mLoader.shouldIgnoreRoot(TestProvidersAccess.DOWNLOADS)).isTrue();
@@ -116,7 +116,7 @@ public class GlobalSearchLoaderTest {

    @Test
    public void testCrossProfileRoot_inTextSearch_beIncluded() {
        mEnv.state.action = State.ACTION_GET_CONTENT;
        mEnv.state.supportsCrossProfile = true;
        TestProvidersAccess.DOWNLOADS.userId = TestProvidersAccess.OtherUser.USER_ID;
        assertThat(mLoader.shouldIgnoreRoot(TestProvidersAccess.DOWNLOADS)).isFalse();
        TestProvidersAccess.DOWNLOADS.userId = TestProvidersAccess.USER_ID;
@@ -250,7 +250,7 @@ public class GlobalSearchLoaderTest {
    @Test
    public void testSearchResult_includeCurrentUserRootOnly() {
        mEnv.state.canShareAcrossProfile = false;
        mEnv.state.action = State.ACTION_GET_CONTENT;
        mEnv.state.supportsCrossProfile = true;

        final DocumentInfo pdfDoc = mEnv.model.createFile(SEARCH_STRING + ".pdf");
        pdfDoc.lastModified = System.currentTimeMillis();
@@ -284,7 +284,7 @@ public class GlobalSearchLoaderTest {
    @Test
    public void testSearchResult_includeBothUsersRoots() {
        mEnv.state.canShareAcrossProfile = true;
        mEnv.state.action = State.ACTION_GET_CONTENT;
        mEnv.state.supportsCrossProfile = true;

        final DocumentInfo pdfDoc = mEnv.model.createFile(SEARCH_STRING + ".pdf");
        pdfDoc.lastModified = System.currentTimeMillis();
@@ -318,7 +318,7 @@ public class GlobalSearchLoaderTest {
    @Test
    public void testSearchResult_emptyCurrentUsersRoot() {
        mEnv.state.canShareAcrossProfile = false;
        mEnv.state.action = State.ACTION_GET_CONTENT;
        mEnv.state.supportsCrossProfile = true;

        final DocumentInfo pdfDoc = mEnv.model.createFile(SEARCH_STRING + ".pdf");
        pdfDoc.lastModified = System.currentTimeMillis();
+3 −3
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ public class ProfileTabsTest {
        mContext.getTheme().applyStyle(R.style.DocumentsDefaultTheme, false);
        LayoutInflater layoutInflater = LayoutInflater.from(mContext);
        mState = new State();
        mState.action = State.ACTION_GET_CONTENT;
        mState.supportsCrossProfile = true;
        mState.stack.changeRoot(TestProvidersAccess.DOWNLOADS);
        mState.stack.push(TestEnv.FOLDER_0);
        View view = layoutInflater.inflate(R.layout.directory_header, null);
@@ -104,10 +104,10 @@ public class ProfileTabsTest {
    }

    @Test
    public void testUpdateView_twoUsers_browse_shouldHide() {
    public void testUpdateView_twoUsers_doesNotSupportCrossProfile_shouldHide() {
        initializeWithUsers(systemUser, managedUser);

        mState.action = State.ACTION_BROWSE;
        mState.supportsCrossProfile = false;
        mProfileTabs.updateView();

        assertThat(mTabLayout.getVisibility()).isEqualTo(View.GONE);
+3 −3
Original line number Diff line number Diff line
@@ -231,7 +231,7 @@ public class AppsRowManagerTest {

    @Test
    public void testUpdateView_crossProfileSearch_hideRow() {
        mState.action = State.ACTION_GET_CONTENT;
        mState.supportsCrossProfile = true;
        when(mActivity.isSearchExpanded()).thenReturn(true);

        mState.stack.changeRoot(TestProvidersAccess.RECENTS);
@@ -252,7 +252,7 @@ public class AppsRowManagerTest {

    @Test
    public void testUpdateView_notCrossProfileSearch_showRow() {
        mState.action = State.ACTION_GET_CONTENT;
        mState.supportsCrossProfile = true;
        when(mActivity.isSearchExpanded()).thenReturn(false);

        mState.stack.changeRoot(TestProvidersAccess.RECENTS);
@@ -273,7 +273,7 @@ public class AppsRowManagerTest {

    @Test
    public void testUpdateView_noItemsOnSelectedUser_hideRow() {
        mState.action = State.ACTION_GET_CONTENT;
        mState.supportsCrossProfile = true;
        mState.stack.changeRoot(TestProvidersAccess.RECENTS);
        when(mActivity.getSelectedUser()).thenReturn(TestProvidersAccess.OtherUser.USER_ID);

Loading