Fix uris coming into SliceManager.getPinnedSpecs

Test: Added a test
Bug: 110699668
Change-Id: I8c4c377babba4b44484096e5456184dd364350c8
This commit is contained in:
Jason Monk
2018-06-22 16:01:55 -04:00
parent 86450e87a1
commit 4f645cc2d6
2 changed files with 19 additions and 2 deletions

View File

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

View File

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