Skip to content

Commit 26bf81f

Browse files
committed
Removes undesirable invokation of checkUriPermission
Slice uses internal permission control, either the provider app can specify a list of auto-grant permission, or the host app can request user's consent on presenting slices from the provider app. In both cases the invokation of checkUriPermission is non-neccessary. Bug: 140727941 Test: atest SliceManagerServiceTest Change-Id: Iac808eda08ac188185cd27f7ab8ce13accf7fce4 Merged-In: Iac808eda08ac188185cd27f7ab8ce13accf7fce4 (cherry picked from commit ab9a91fb6983552095d5ebfcbf6610ec1b048090)
1 parent 166d683 commit 26bf81f

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

services/core/java/com/android/server/slice/SliceManagerService.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,6 @@ public int checkSlicePermission(Uri uri, String callingPkg, String pkg, int pid,
251251
}
252252
}
253253
}
254-
// Fallback to allowing uri permissions through.
255-
if (mContext.checkUriPermission(uri, pid, uid, Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
256-
== PERMISSION_GRANTED) {
257-
return PackageManager.PERMISSION_GRANTED;
258-
}
259254
return PackageManager.PERMISSION_DENIED;
260255
}
261256

services/tests/uiservicestests/src/com/android/server/slice/SliceManagerServiceTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public void setUp() {
7575
LocalServices.addService(UsageStatsManagerInternal.class,
7676
mock(UsageStatsManagerInternal.class));
7777
mContext.addMockSystemService(AppOpsManager.class, mock(AppOpsManager.class));
78-
mContext.getTestablePermissions().setPermission(TEST_URI, PERMISSION_GRANTED);
7978

8079
mContextSpy = spy(mContext);
8180
mService = spy(new SliceManagerService(mContextSpy, TestableLooper.get(this).getLooper()));
@@ -90,6 +89,7 @@ public void teardown() {
9089

9190
@Test
9291
public void testAddPinCreatesPinned() throws RemoteException {
92+
grantSlicePermission();
9393
doReturn("pkg").when(mService).getDefaultHome(anyInt());
9494

9595
mService.pinSlice("pkg", TEST_URI, EMPTY_SPECS, mToken);
@@ -99,6 +99,7 @@ public void testAddPinCreatesPinned() throws RemoteException {
9999

100100
@Test
101101
public void testRemovePinDestroysPinned() throws RemoteException {
102+
grantSlicePermission();
102103
doReturn("pkg").when(mService).getDefaultHome(anyInt());
103104

104105
mService.pinSlice("pkg", TEST_URI, EMPTY_SPECS, mToken);
@@ -130,11 +131,13 @@ public void testCheckAutoGrantPermissions() throws RemoteException {
130131

131132
@Test(expected = IllegalStateException.class)
132133
public void testNoPinThrow() throws Exception {
134+
grantSlicePermission();
133135
mService.getPinnedSpecs(TEST_URI, "pkg");
134136
}
135137

136138
@Test
137139
public void testGetPinnedSpecs() throws Exception {
140+
grantSlicePermission();
138141
SliceSpec[] specs = new SliceSpec[] {
139142
new SliceSpec("Something", 1) };
140143
mService.pinSlice("pkg", TEST_URI, specs, mToken);
@@ -143,4 +146,10 @@ public void testGetPinnedSpecs() throws Exception {
143146
assertEquals(specs, mService.getPinnedSpecs(TEST_URI, "pkg"));
144147
}
145148

149+
private void grantSlicePermission() {
150+
doReturn(PERMISSION_GRANTED).when(mService).checkSlicePermission(
151+
eq(TEST_URI), anyString(), anyString(), anyInt(), anyInt(), any());
152+
doReturn(PERMISSION_GRANTED).when(mService).checkAccess(
153+
anyString(), eq(TEST_URI), anyInt(), anyInt());
154+
}
146155
}

0 commit comments

Comments
 (0)