Fix uris coming into SliceManager.getPinnedSpecs
Test: Added a test Bug: 110699668 Change-Id: I8c4c377babba4b44484096e5456184dd364350c8
This commit is contained in:
@@ -197,6 +197,7 @@ public class SliceManagerService extends ISliceManager.Stub {
|
||||
public SliceSpec[] getPinnedSpecs(Uri uri, String pkg) throws RemoteException {
|
||||
verifyCaller(pkg);
|
||||
enforceAccess(pkg, uri);
|
||||
uri = maybeAddUserId(uri, Binder.getCallingUserHandle().getIdentifier());
|
||||
return getPinnedSlice(uri).getSpecs();
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import static android.content.ContentProvider.maybeAddUserId;
|
||||
import static android.content.pm.PackageManager.PERMISSION_DENIED;
|
||||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
@@ -59,7 +60,7 @@ import org.junit.runner.RunWith;
|
||||
public class SliceManagerServiceTest extends UiServiceTestCase {
|
||||
|
||||
private static final String AUTH = "com.android.services.uitests";
|
||||
private static final Uri TEST_URI = maybeAddUserId(Uri.parse("content://" + AUTH + "/path"), 0);
|
||||
private static final Uri TEST_URI = Uri.parse("content://" + AUTH + "/path");
|
||||
|
||||
private static final SliceSpec[] EMPTY_SPECS = new SliceSpec[]{
|
||||
};
|
||||
@@ -93,7 +94,7 @@ public class SliceManagerServiceTest extends UiServiceTestCase {
|
||||
|
||||
mService.pinSlice("pkg", TEST_URI, EMPTY_SPECS, mToken);
|
||||
mService.pinSlice("pkg", TEST_URI, EMPTY_SPECS, mToken);
|
||||
verify(mService, times(1)).createPinnedSlice(eq(TEST_URI), anyString());
|
||||
verify(mService, times(1)).createPinnedSlice(eq(maybeAddUserId(TEST_URI, 0)), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -126,4 +127,19 @@ public class SliceManagerServiceTest extends UiServiceTestCase {
|
||||
verify(mContextSpy).checkPermission(eq("perm2"), eq(Process.myPid()), eq(Process.myUid()));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testNoPinThrow() throws Exception {
|
||||
mService.getPinnedSpecs(TEST_URI, "pkg");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPinnedSpecs() throws Exception {
|
||||
SliceSpec[] specs = new SliceSpec[] {
|
||||
new SliceSpec("Something", 1) };
|
||||
mService.pinSlice("pkg", TEST_URI, specs, mToken);
|
||||
|
||||
when(mCreatedSliceState.getSpecs()).thenReturn(specs);
|
||||
assertEquals(specs, mService.getPinnedSpecs(TEST_URI, "pkg"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user