Update PermissionChecker usages to avoid unnecessary attribution.

We had accidental usages of the PermissionChecker for cases where no
private data was provided to the app but the checkPermission API on
the latter also did blame data access on the app. The PermissionChecker
was designed to handle IPC calls and not for generic API checks.

To avoid future accidental incorrect PermissionChecker usages this
change renames the existing APIs of the latter to clearly indicate
that they should be used for data delivery and also adds sibling
methods for doing the same permission checks for preflight purposes.
Also the documentation is improved to furhter assist developers.

In addition, this change fixes accidental permission checker usages
that blame when they should not by using the new preflight flavor
of the permission check APIs.

    atest com.android.settingslib.location.RecentLocationAppsTest
    atest CtsPermissionTestCases
    added: LocationAccessCheckTest#notificationOnlyForAccessesSinceFeatureWasEnabled
    added: LocationAccessCheckTest#noNotificationIfFeatureDisabled
    added: LocationAccessCheckTest#noNotificationIfBlamerNotSystemOrLocationProvider
    added: LocationAccessCheckTest#testOpeningLocationSettingsDoesNotTriggerAccess

Merged-In: I24e7f16f70ab183a9515e6e298d21ccb9006c3cf
Change-Id: I24e7f16f70ab183a9515e6e298d21ccb9006c3cf
(cherry picked from commit a8ffa3c6063cbf38af2202a63d3358ed4ac9b0d3)
diff --git a/src/com/android/providers/media/LocalCallingIdentity.java b/src/com/android/providers/media/LocalCallingIdentity.java
index 584a8d6..0c763e9 100644
--- a/src/com/android/providers/media/LocalCallingIdentity.java
+++ b/src/com/android/providers/media/LocalCallingIdentity.java
@@ -28,6 +28,7 @@
 import android.app.AppOpsManager;
 import android.content.ContentProvider;
 import android.content.Context;
+import android.content.PermissionChecker;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager.NameNotFoundException;
 import android.os.Binder;
@@ -226,8 +227,9 @@
     private boolean isRedactionNeededInternal() {
         // System internals or callers holding permission have no redaction
-        if (hasPermission(PERMISSION_IS_SYSTEM) || getContext()
-                .checkPermission(ACCESS_MEDIA_LOCATION, pid, uid) == PERMISSION_GRANTED) {
+        if (hasPermission(PERMISSION_IS_SYSTEM) || PermissionChecker.checkPermissionForDataDelivery(
+                getContext(), ACCESS_MEDIA_LOCATION, pid, uid, getPackageName())
+                        == PermissionChecker.PERMISSION_GRANTED) {
             return false;
         return true;