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)
diff --git a/services/core/java/com/android/server/slice/SliceManagerService.java b/services/core/java/com/android/server/slice/SliceManagerService.java
index 7c8c494..c49720f 100644
--- a/services/core/java/com/android/server/slice/SliceManagerService.java
+++ b/services/core/java/com/android/server/slice/SliceManagerService.java
@@ -251,11 +251,6 @@
                 }
             }
         }
-        // Fallback to allowing uri permissions through.
-        if (mContext.checkUriPermission(uri, pid, uid, Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
-                == PERMISSION_GRANTED) {
-            return PackageManager.PERMISSION_GRANTED;
-        }
         return PackageManager.PERMISSION_DENIED;
     }
 
diff --git a/services/tests/uiservicestests/src/com/android/server/slice/SliceManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/slice/SliceManagerServiceTest.java
index a443695..dd0c162 100644
--- a/services/tests/uiservicestests/src/com/android/server/slice/SliceManagerServiceTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/slice/SliceManagerServiceTest.java
@@ -75,7 +75,6 @@
         LocalServices.addService(UsageStatsManagerInternal.class,
                 mock(UsageStatsManagerInternal.class));
         mContext.addMockSystemService(AppOpsManager.class, mock(AppOpsManager.class));
-        mContext.getTestablePermissions().setPermission(TEST_URI, PERMISSION_GRANTED);
 
         mContextSpy = spy(mContext);
         mService = spy(new SliceManagerService(mContextSpy, TestableLooper.get(this).getLooper()));
@@ -90,6 +89,7 @@
 
     @Test
     public void testAddPinCreatesPinned() throws RemoteException {
+        grantSlicePermission();
         doReturn("pkg").when(mService).getDefaultHome(anyInt());
 
         mService.pinSlice("pkg", TEST_URI, EMPTY_SPECS, mToken);
@@ -99,6 +99,7 @@
 
     @Test
     public void testRemovePinDestroysPinned() throws RemoteException {
+        grantSlicePermission();
         doReturn("pkg").when(mService).getDefaultHome(anyInt());
 
         mService.pinSlice("pkg", TEST_URI, EMPTY_SPECS, mToken);
@@ -130,11 +131,13 @@
 
     @Test(expected = IllegalStateException.class)
     public void testNoPinThrow() throws Exception {
+        grantSlicePermission();
         mService.getPinnedSpecs(TEST_URI, "pkg");
     }
 
     @Test
     public void testGetPinnedSpecs() throws Exception {
+        grantSlicePermission();
         SliceSpec[] specs = new SliceSpec[] {
             new SliceSpec("Something", 1) };
         mService.pinSlice("pkg", TEST_URI, specs, mToken);
@@ -143,4 +146,10 @@
         assertEquals(specs, mService.getPinnedSpecs(TEST_URI, "pkg"));
     }
 
+    private void grantSlicePermission() {
+        doReturn(PERMISSION_GRANTED).when(mService).checkSlicePermission(
+                eq(TEST_URI), anyString(), anyString(), anyInt(), anyInt(), any());
+        doReturn(PERMISSION_GRANTED).when(mService).checkAccess(
+                anyString(), eq(TEST_URI), anyInt(), anyInt());
+    }
 }