Revert "Add tests for the api Context#checkUriPermission"

Revert submission 15065651-pm_package_visibility_check_uri_permission

Reason for revert: [Regression] Cross-profile sharing is broken
Reverted Changes:
Iea2f2d8a8:Enforce package visibility to the api checkUriPerm...
I0a4ed9350:Add tests for the api Context#checkUriPermission

Bug: 192357488
Change-Id: I1f3a32d6fee7bccdf05f4edcfb535dabe4436a21
(cherry picked from commit 877920ebde5a98978fd86f88161af4d9f88b21e9)
diff --git a/tests/tests/appenumeration/AndroidTest.xml b/tests/tests/appenumeration/AndroidTest.xml
index fbaac01..8bb21c0 100644
--- a/tests/tests/appenumeration/AndroidTest.xml
+++ b/tests/tests/appenumeration/AndroidTest.xml
@@ -51,7 +51,6 @@
         <option name="test-file-name" value="CtsAppEnumerationQueriesUnexportedProviderViaAuthority.apk" />
         <option name="test-file-name" value="CtsAppEnumerationQueriesUnexportedProviderViaAction.apk" />
         <option name="test-file-name" value="CtsAppEnumerationQueriesPackage.apk" />
-        <option name="test-file-name" value="CtsAppEnumerationQueriesPackageHasProvider.apk" />
         <option name="test-file-name" value="CtsAppEnumerationQueriesNothingTargetsQ.apk" />
         <option name="test-file-name" value="CtsAppEnumerationQueriesNothingHasPermission.apk" />
         <option name="test-file-name" value="CtsAppEnumerationQueriesNothingUsesLibrary.apk" />
diff --git a/tests/tests/appenumeration/app/source/Android.bp b/tests/tests/appenumeration/app/source/Android.bp
index 0583f10..deee2f4 100644
--- a/tests/tests/appenumeration/app/source/Android.bp
+++ b/tests/tests/appenumeration/app/source/Android.bp
@@ -167,17 +167,6 @@
 }
 
 android_test_helper_app {
-    name: "CtsAppEnumerationQueriesPackageHasProvider",
-    manifest: "AndroidManifest-queriesPackage-hasProvider.xml",
-    defaults: ["CtsAppEnumerationQueriesDefaults"],
-    // Tag this module as a cts test artifact
-    test_suites: [
-        "cts",
-        "general-tests",
-    ],
-}
-
-android_test_helper_app {
     name: "CtsAppEnumerationQueriesNothingTargetsQ",
     manifest: "AndroidManifest-queriesNothing-targetsQ.xml",
     defaults: ["CtsAppEnumerationQueriesDefaults"],
diff --git a/tests/tests/appenumeration/app/source/AndroidManifest-queriesPackage-hasProvider.xml b/tests/tests/appenumeration/app/source/AndroidManifest-queriesPackage-hasProvider.xml
deleted file mode 100644
index 3a473b3..0000000
--- a/tests/tests/appenumeration/app/source/AndroidManifest-queriesPackage-hasProvider.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-    Copyright (C) 2021 The Android Open Source Project
-
-    Licensed under the Apache License, Version 2.0 (the "License");
-    you may not use this file except in compliance with the License.
-    You may obtain a copy of the License at
-
-         http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing, software
-    distributed under the License is distributed on an "AS IS" BASIS,
-    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-    See the License for the specific language governing permissions and
-    limitations under the License.
-  -->
-
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="android.appenumeration.queries.pkg.hasprovider">
-
-    <queries>
-        <package android:name="android.appenumeration.noapi" />
-    </queries>
-
-    <application>
-        <uses-library android:name="android.test.runner" />
-        <activity android:name="android.appenumeration.cts.query.TestActivity"
-                  android:exported="true" />
-        <provider android:name="android.appenumeration.cts.query.TestProvider"
-                  android:authorities="android.appenumeration.queries.pkg.hasprovider"
-                  android:grantUriPermissions="true"
-                  android:exported="false" >
-        </provider>
-    </application>
-</manifest>
diff --git a/tests/tests/appenumeration/app/source/src/android/appenumeration/cts/query/TestActivity.java b/tests/tests/appenumeration/app/source/src/android/appenumeration/cts/query/TestActivity.java
index 040a0dd..98f1377 100644
--- a/tests/tests/appenumeration/app/source/src/android/appenumeration/cts/query/TestActivity.java
+++ b/tests/tests/appenumeration/app/source/src/android/appenumeration/cts/query/TestActivity.java
@@ -243,13 +243,6 @@
             } else if (Constants.ACTION_GET_INSTALLED_ACCESSIBILITYSERVICES_PACKAGES.equals(
                     action)) {
                 sendGetInstalledAccessibilityServicePackages(remoteCallback);
-            } else if (Constants.ACTION_CHECK_URI_PERMISSION.equals(action)) {
-                final String targetPackageName = intent.getStringExtra(Intent.EXTRA_PACKAGE_NAME);
-                final int targetUid = intent.getIntExtra(Intent.EXTRA_UID, INVALID_UID);
-                final String sourceAuthority = intent.getBundleExtra(EXTRA_DATA)
-                        .getString(EXTRA_AUTHORITY);
-                sendCheckUriPermission(remoteCallback, sourceAuthority, targetPackageName,
-                        targetUid);
             } else {
                 sendError(remoteCallback, new Exception("unknown action " + action));
             }
@@ -625,19 +618,6 @@
         }
     }
 
-    private void sendCheckUriPermission(RemoteCallback remoteCallback, String sourceAuthority,
-            String targetPackageName, int targetUid) {
-        final Uri uri = Uri.parse("content://" + sourceAuthority);
-        grantUriPermission(targetPackageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
-        final int permissionResult = checkUriPermission(uri, 0 /* pid */, targetUid,
-                Intent.FLAG_GRANT_READ_URI_PERMISSION);
-        revokeUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
-        final Bundle result = new Bundle();
-        result.putInt(EXTRA_RETURN_RESULT, permissionResult);
-        remoteCallback.sendResult(result);
-        finish();
-    }
-
     @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
         super.onActivityResult(requestCode, resultCode, data);
diff --git a/tests/tests/appenumeration/lib/src/android/appenumeration/cts/Constants.java b/tests/tests/appenumeration/lib/src/android/appenumeration/cts/Constants.java
index 18c2cfd..c93016b 100644
--- a/tests/tests/appenumeration/lib/src/android/appenumeration/cts/Constants.java
+++ b/tests/tests/appenumeration/lib/src/android/appenumeration/cts/Constants.java
@@ -22,8 +22,6 @@
 
     /** A package that queries for {@link #TARGET_NO_API} package */
     public static final String QUERIES_PACKAGE = PKG_BASE + "queries.pkg";
-    /** A package has a provider that queries for {@link #TARGET_NO_API} package */
-    public static final String QUERIES_PACKAGE_PROVIDER = PKG_BASE + "queries.pkg.hasprovider";
     /** Queries for the unexported authority in {@link #TARGET_FILTERS} provider */
     public static final String QUERIES_UNEXPORTED_PROVIDER_AUTH =
             PKG_BASE + "queries.provider.authority.unexported";
@@ -209,9 +207,6 @@
             PKG_BASE + "cts.action.SET_INSTALLER_PACKAGE_NAME";
     public static final String ACTION_GET_INSTALLED_ACCESSIBILITYSERVICES_PACKAGES =
             PKG_BASE + "cts.action.GET_INSTALLED_ACCESSIBILITYSERVICES_PACKAGES";
-    public static final String ACTION_CHECK_URI_PERMISSION =
-            PKG_BASE + "cts.action.CHECK_URI_PERMISSION";
-
     public static final String EXTRA_REMOTE_CALLBACK = "remoteCallback";
     public static final String EXTRA_REMOTE_READY_CALLBACK = "remoteReadyCallback";
     public static final String EXTRA_ERROR = "error";
diff --git a/tests/tests/appenumeration/src/android/appenumeration/cts/AppEnumerationTests.java b/tests/tests/appenumeration/src/android/appenumeration/cts/AppEnumerationTests.java
index eb55555..123808e 100644
--- a/tests/tests/appenumeration/src/android/appenumeration/cts/AppEnumerationTests.java
+++ b/tests/tests/appenumeration/src/android/appenumeration/cts/AppEnumerationTests.java
@@ -20,7 +20,6 @@
 import static android.appenumeration.cts.Constants.ACTION_AWAIT_LAUNCHER_APPS_CALLBACK;
 import static android.appenumeration.cts.Constants.ACTION_BIND_SERVICE;
 import static android.appenumeration.cts.Constants.ACTION_CHECK_SIGNATURES;
-import static android.appenumeration.cts.Constants.ACTION_CHECK_URI_PERMISSION;
 import static android.appenumeration.cts.Constants.ACTION_GET_INSTALLED_ACCESSIBILITYSERVICES_PACKAGES;
 import static android.appenumeration.cts.Constants.ACTION_GET_INSTALLED_APPWIDGET_PROVIDERS;
 import static android.appenumeration.cts.Constants.ACTION_GET_INSTALLED_PACKAGES;
@@ -73,7 +72,6 @@
 import static android.appenumeration.cts.Constants.QUERIES_NOTHING_USES_LIBRARY;
 import static android.appenumeration.cts.Constants.QUERIES_NOTHING_USES_OPTIONAL_LIBRARY;
 import static android.appenumeration.cts.Constants.QUERIES_PACKAGE;
-import static android.appenumeration.cts.Constants.QUERIES_PACKAGE_PROVIDER;
 import static android.appenumeration.cts.Constants.QUERIES_PROVIDER_ACTION;
 import static android.appenumeration.cts.Constants.QUERIES_PROVIDER_AUTH;
 import static android.appenumeration.cts.Constants.QUERIES_SERVICE_ACTION;
@@ -109,7 +107,6 @@
 import static android.appenumeration.cts.Constants.TARGET_SYNCADAPTER_SHARED_USER;
 import static android.appenumeration.cts.Constants.TARGET_WEB;
 import static android.content.Intent.EXTRA_PACKAGES;
-import static android.content.Intent.EXTRA_RETURN_RESULT;
 import static android.content.pm.PackageManager.GET_SIGNING_CERTIFICATES;
 import static android.content.pm.PackageManager.MATCH_SYSTEM_ONLY;
 import static android.content.pm.PackageManager.SIGNATURE_MATCH;
@@ -1089,18 +1086,6 @@
         assertThat(ex.getMessage(), containsString(TARGET_NO_API));
     }
 
-    @Test
-    public void queriesPackageHasProvider_checkUriPermission_canSeeNoApi() throws Exception {
-        final int permissionResult = checkUriPermission(QUERIES_PACKAGE_PROVIDER, TARGET_NO_API);
-        assertThat(permissionResult, is(PackageManager.PERMISSION_GRANTED));
-    }
-
-    @Test
-    public void queriesPackageHasProvider_checkUriPermission_cannotSeeFilters() throws Exception {
-        final int permissionResult = checkUriPermission(QUERIES_PACKAGE_PROVIDER, TARGET_FILTERS);
-        assertThat(permissionResult, is(PackageManager.PERMISSION_DENIED));
-    }
-
     private void assertNotVisible(String sourcePackageName, String targetPackageName)
             throws Exception {
         if (!sGlobalFeatureEnabled) return;
@@ -1424,17 +1409,6 @@
                 extraData, ACTION_SET_INSTALLER_PACKAGE_NAME);
     }
 
-    private int checkUriPermission(String sourcePackageName, String targetPackageName)
-            throws Exception {
-        final int targetUid = sPm.getPackageUid(targetPackageName, /* flags */ 0);
-        final Bundle extraData = new Bundle();
-        extraData.putString(EXTRA_AUTHORITY, sourcePackageName);
-        final Result result = sendCommand(sourcePackageName, targetPackageName, targetUid,
-                extraData, ACTION_CHECK_URI_PERMISSION, /* waitForReady */ false);
-        final Bundle response = result.await();
-        return response.getInt(EXTRA_RETURN_RESULT);
-    }
-
     interface Result {
         Bundle await() throws Exception;
     }