Guard slices from being requested by guest user

According to patch of A-231987122, AOSP restricts app to modify relevant
mobile settings when user is a guest. This change intends to prevent the
slices related to mobile settings from being requested by guest user.

Bug: 278616139
Bug: 277333776
Bug: 262244832
Bug: 278616520
Bug: 278615120
Test: robotests
Change-Id: I4dc4bbfdb5cf76e188e6f62ebfd74ef6fa2fe33b
This commit is contained in:
Mill Chen
2023-05-13 03:40:14 +08:00
parent f2f899106d
commit d4eecf6132
4 changed files with 133 additions and 0 deletions

View File

@@ -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);