Merge "Guard slices from being requested by guest user" into udc-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
9718f0e04f
@@ -119,6 +119,7 @@ public class SettingsSliceProviderTest {
|
||||
private Context mContext;
|
||||
private SettingsSliceProvider mProvider;
|
||||
private ShadowPackageManager mPackageManager;
|
||||
private ShadowUserManager mShadowUserManager;
|
||||
|
||||
@Mock
|
||||
private SliceManager mManager;
|
||||
@@ -157,6 +158,7 @@ public class SettingsSliceProviderTest {
|
||||
when(mManager.getPinnedSlices()).thenReturn(Collections.emptyList());
|
||||
|
||||
mPackageManager = Shadows.shadowOf(mContext.getPackageManager());
|
||||
mShadowUserManager = ShadowUserManager.getShadow();
|
||||
|
||||
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
|
||||
}
|
||||
@@ -292,6 +294,37 @@ public class SettingsSliceProviderTest {
|
||||
assertThat(ShadowTheme.isThemeRebased()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindSlice_guestRestricted_returnsNull() {
|
||||
final String key = "enable_usb_tethering";
|
||||
mShadowUserManager.setGuestUser(true);
|
||||
final Uri testUri = new Uri.Builder()
|
||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath(key)
|
||||
.build();
|
||||
|
||||
final Slice slice = mProvider.onBindSlice(testUri);
|
||||
|
||||
assertThat(slice).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindSlice_notGuestRestricted_returnsNotNull() {
|
||||
final String key = "enable_usb_tethering";
|
||||
final Uri testUri = new Uri.Builder()
|
||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath(key)
|
||||
.build();
|
||||
|
||||
final Slice slice = mProvider.onBindSlice(testUri);
|
||||
|
||||
assertThat(slice).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDescendantUris_fullActionUri_returnsSelf() {
|
||||
final Collection<Uri> descendants = mProvider.onGetSliceDescendants(ACTION_SLICE_URI);
|
||||
|
@@ -55,6 +55,7 @@ public class ShadowUserManager extends org.robolectric.shadows.ShadowUserManager
|
||||
private int[] profileIdsForUser = new int[0];
|
||||
private boolean mUserSwitchEnabled;
|
||||
private Bundle mDefaultGuestUserRestriction = new Bundle();
|
||||
private boolean mIsGuestUser = false;
|
||||
|
||||
private @UserManager.UserSwitchabilityResult int mSwitchabilityStatus =
|
||||
UserManager.SWITCHABILITY_STATUS_OK;
|
||||
@@ -270,4 +271,13 @@ public class ShadowUserManager extends org.robolectric.shadows.ShadowUserManager
|
||||
mUserProfileInfos.get(i).flags |= UserInfo.FLAG_ADMIN;
|
||||
}
|
||||
}
|
||||
|
||||
@Implementation
|
||||
protected boolean isGuestUser() {
|
||||
return mIsGuestUser;
|
||||
}
|
||||
|
||||
public void setGuestUser(boolean isGuestUser) {
|
||||
mIsGuestUser = isGuestUser;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user