Merge "Show a separate tab for the Private Space" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
2770170e0d
@@ -19,6 +19,7 @@ package com.android.settings.dashboard.profileselector;
|
||||
import static android.content.Intent.EXTRA_USER_ID;
|
||||
|
||||
import static com.android.settings.dashboard.profileselector.ProfileSelectFragment.PERSONAL_TAB;
|
||||
import static com.android.settings.dashboard.profileselector.ProfileSelectFragment.PRIVATE_TAB;
|
||||
import static com.android.settings.dashboard.profileselector.ProfileSelectFragment.WORK_TAB;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
@@ -29,6 +30,9 @@ import static org.mockito.Mockito.when;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Flags;
|
||||
import android.os.UserHandle;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
@@ -38,6 +42,7 @@ import com.android.settings.SettingsPreferenceFragmentTest;
|
||||
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
@@ -60,6 +65,7 @@ public class ProfileSelectFragmentTest {
|
||||
private TestProfileSelectFragment mFragment;
|
||||
private FragmentActivity mActivity;
|
||||
private ShadowUserManager mUserManager;
|
||||
@Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -85,6 +91,14 @@ public class ProfileSelectFragmentTest {
|
||||
assertThat(mFragment.getTabId(mActivity, bundle)).isEqualTo(WORK_TAB);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTabId_setArgumentPrivate_setCorrectTab() {
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putInt(SettingsActivity.EXTRA_SHOW_FRAGMENT_TAB, PRIVATE_TAB);
|
||||
|
||||
assertThat(mFragment.getTabId(mActivity, bundle)).isEqualTo(PRIVATE_TAB);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTabId_setArgumentPersonal_setCorrectTab() {
|
||||
final Bundle bundle = new Bundle();
|
||||
@@ -104,6 +118,16 @@ public class ProfileSelectFragmentTest {
|
||||
assertThat(mFragment.getTabId(mActivity, bundle)).isEqualTo(WORK_TAB);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTabId_setPrivateId_getCorrectTab() {
|
||||
mSetFlagsRule.enableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE);
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putInt(EXTRA_USER_ID, 11);
|
||||
mUserManager.setPrivateProfile(11, "private", 0);
|
||||
|
||||
assertThat(mFragment.getTabId(mActivity, bundle)).isEqualTo(PRIVATE_TAB);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTabId_setPersonalId_getCorrectTab() {
|
||||
final Bundle bundle = new Bundle();
|
||||
@@ -124,12 +148,120 @@ public class ProfileSelectFragmentTest {
|
||||
assertThat(mFragment.getTabId(mActivity, null)).isEqualTo(WORK_TAB);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFragments_whenOnlyPersonal_returnsOneFragment() {
|
||||
mSetFlagsRule.disableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE);
|
||||
Fragment[] fragments = ProfileSelectFragment.getFragments(
|
||||
mContext,
|
||||
null /* bundle */,
|
||||
TestProfileSelectFragment::new,
|
||||
TestProfileSelectFragment::new,
|
||||
TestProfileSelectFragment::new);
|
||||
assertThat(fragments).hasLength(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFragments_whenPrivateDisabled_returnsOneFragment() {
|
||||
Fragment[] fragments = ProfileSelectFragment.getFragments(
|
||||
mContext,
|
||||
null /* bundle */,
|
||||
TestProfileSelectFragment::new,
|
||||
TestProfileSelectFragment::new,
|
||||
TestProfileSelectFragment::new,
|
||||
new ProfileSelectFragment.PrivateSpaceInfoProvider() {
|
||||
@Override
|
||||
public boolean isPrivateSpaceLocked(Context context) {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
new ProfileSelectFragment.ManagedProfileInfoProvider() {
|
||||
@Override
|
||||
public UserHandle getManagedProfile(Context context) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
assertThat(fragments).hasLength(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFragments_whenPrivateEnabled_returnsTwoFragments() {
|
||||
mSetFlagsRule.enableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE);
|
||||
Fragment[] fragments = ProfileSelectFragment.getFragments(
|
||||
mContext,
|
||||
null /* bundle */,
|
||||
TestProfileSelectFragment::new,
|
||||
TestProfileSelectFragment::new,
|
||||
TestProfileSelectFragment::new,
|
||||
new ProfileSelectFragment.PrivateSpaceInfoProvider() {
|
||||
@Override
|
||||
public boolean isPrivateSpaceLocked(Context context) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
new ProfileSelectFragment.ManagedProfileInfoProvider() {
|
||||
@Override
|
||||
public UserHandle getManagedProfile(Context context) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
assertThat(fragments).hasLength(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFragments_whenManagedProfile_returnsTwoFragments() {
|
||||
mSetFlagsRule.disableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE);
|
||||
Fragment[] fragments = ProfileSelectFragment.getFragments(
|
||||
mContext,
|
||||
null /* bundle */,
|
||||
TestProfileSelectFragment::new,
|
||||
TestProfileSelectFragment::new,
|
||||
TestProfileSelectFragment::new,
|
||||
new ProfileSelectFragment.PrivateSpaceInfoProvider() {
|
||||
@Override
|
||||
public boolean isPrivateSpaceLocked(Context context) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
new ProfileSelectFragment.ManagedProfileInfoProvider() {
|
||||
@Override
|
||||
public UserHandle getManagedProfile(Context context) {
|
||||
return new UserHandle(123);
|
||||
}
|
||||
});
|
||||
assertThat(fragments).hasLength(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFragments_whenAllProfiles_returnsThreeFragments() {
|
||||
mSetFlagsRule.enableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE);
|
||||
Fragment[] fragments = ProfileSelectFragment.getFragments(
|
||||
mContext,
|
||||
null /* bundle */,
|
||||
TestProfileSelectFragment::new,
|
||||
TestProfileSelectFragment::new,
|
||||
TestProfileSelectFragment::new,
|
||||
new ProfileSelectFragment.PrivateSpaceInfoProvider() {
|
||||
@Override
|
||||
public boolean isPrivateSpaceLocked(Context context) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
new ProfileSelectFragment.ManagedProfileInfoProvider() {
|
||||
@Override
|
||||
public UserHandle getManagedProfile(Context context) {
|
||||
return new UserHandle(123);
|
||||
}
|
||||
});
|
||||
assertThat(fragments).hasLength(3);
|
||||
}
|
||||
|
||||
public static class TestProfileSelectFragment extends ProfileSelectFragment {
|
||||
|
||||
@Override
|
||||
public Fragment[] getFragments() {
|
||||
return new Fragment[]{
|
||||
new SettingsPreferenceFragmentTest.TestFragment(), //0
|
||||
new SettingsPreferenceFragmentTest.TestFragment(),
|
||||
new SettingsPreferenceFragmentTest.TestFragment()
|
||||
};
|
||||
}
|
||||
|
||||
@@ -39,10 +39,12 @@ public class ProfileSelectLocationFragmentTest {
|
||||
|
||||
@Test
|
||||
public void getFragments_containsCorrectBundle() {
|
||||
assertThat(mProfileSelectLocationFragment.getFragments().length).isEqualTo(2);
|
||||
assertThat(mProfileSelectLocationFragment.getFragments().length).isEqualTo(3);
|
||||
assertThat(mProfileSelectLocationFragment.getFragments()[0].getArguments().getInt(
|
||||
EXTRA_PROFILE, -1)).isEqualTo(ProfileSelectFragment.ProfileType.PERSONAL);
|
||||
assertThat(mProfileSelectLocationFragment.getFragments()[1].getArguments().getInt(
|
||||
EXTRA_PROFILE, -1)).isEqualTo(ProfileSelectFragment.ProfileType.WORK);
|
||||
assertThat(mProfileSelectLocationFragment.getFragments()[1].getArguments().getInt(
|
||||
EXTRA_PROFILE, -1)).isEqualTo(ProfileSelectFragment.ProfileType.PRIVATE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.SubSettings;
|
||||
import com.android.settings.applications.manageapplications.ManageApplications;
|
||||
import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
|
||||
import com.android.settings.dashboard.profileselector.ProfileSelectFragment.ProfileType;
|
||||
import com.android.settings.deviceinfo.StorageItemPreference;
|
||||
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||
import com.android.settingslib.deviceinfo.StorageVolumeProvider;
|
||||
@@ -99,7 +100,7 @@ public class StorageItemPreferenceControllerTest {
|
||||
// Note: null is passed as the Lifecycle because we are handling it outside of the normal
|
||||
// Settings fragment lifecycle for test purposes.
|
||||
mController = new StorageItemPreferenceController(mContext, mFragment, mVolume, mSvp,
|
||||
false /* isWorkProfile */);
|
||||
ProfileSelectFragment.ProfileType.PERSONAL);
|
||||
mPreference = new StorageItemPreference(mContext);
|
||||
|
||||
// Inflate the preference and the widget.
|
||||
@@ -175,7 +176,7 @@ public class StorageItemPreferenceControllerTest {
|
||||
mPreference.setKey(StorageItemPreferenceController.IMAGES_KEY);
|
||||
final Context mockContext = getMockContext();
|
||||
mController = new StorageItemPreferenceController(mockContext, mFragment, mVolume,
|
||||
mSvp, false /* isWorkProfile */);
|
||||
mSvp, ProfileSelectFragment.ProfileType.PERSONAL);
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
@@ -192,7 +193,7 @@ public class StorageItemPreferenceControllerTest {
|
||||
mPreference.setKey(StorageItemPreferenceController.AUDIO_KEY);
|
||||
final Context mockContext = getMockContext();
|
||||
mController = new StorageItemPreferenceController(mockContext, mFragment, mVolume,
|
||||
mSvp, false /* isWorkProfile */);
|
||||
mSvp, ProfileSelectFragment.ProfileType.PERSONAL);
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
@@ -242,7 +243,7 @@ public class StorageItemPreferenceControllerTest {
|
||||
@Test
|
||||
public void launchAppsIntent_forWork_settingsIntent() {
|
||||
mController = new FakeStorageItemPreferenceController(mContext, mFragment, mVolume, mSvp,
|
||||
true /* isWorkProfile */);
|
||||
ProfileType.WORK);
|
||||
mPreference.setKey(StorageItemPreferenceController.APPS_KEY);
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
@@ -272,7 +273,7 @@ public class StorageItemPreferenceControllerTest {
|
||||
mPreference.setKey(StorageItemPreferenceController.DOCUMENTS_AND_OTHER_KEY);
|
||||
final Context mockContext = getMockContext();
|
||||
mController = new StorageItemPreferenceController(mockContext, mFragment, mVolume,
|
||||
mSvp, false /* isWorkProfile */);
|
||||
mSvp, ProfileSelectFragment.ProfileType.PERSONAL);
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
@@ -307,7 +308,7 @@ public class StorageItemPreferenceControllerTest {
|
||||
mPreference.setKey(StorageItemPreferenceController.VIDEOS_KEY);
|
||||
final Context mockContext = getMockContext();
|
||||
mController = new StorageItemPreferenceController(mockContext, mFragment, mVolume,
|
||||
mSvp, false /* isWorkProfile */);
|
||||
mSvp, ProfileSelectFragment.ProfileType.PERSONAL);
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
@@ -457,8 +458,8 @@ public class StorageItemPreferenceControllerTest {
|
||||
private static final int CURRENT_USER_ID = 10;
|
||||
|
||||
FakeStorageItemPreferenceController(Context context, Fragment hostFragment,
|
||||
VolumeInfo volume, StorageVolumeProvider svp, boolean isWorkProfile) {
|
||||
super(context, hostFragment, volume, svp, isWorkProfile);
|
||||
VolumeInfo volume, StorageVolumeProvider svp, @ProfileType int profileType) {
|
||||
super(context, hostFragment, volume, svp, profileType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user