From 879024a03b48cbd1177ea5d86c97d6583451564d Mon Sep 17 00:00:00 2001 From: Hall Liu Date: Wed, 17 Apr 2019 13:33:43 -0700 Subject: [PATCH] Change ServiceState and TelephonyRegistry logging When an app bypasses a location access check due to its target SDK for queries to ServiceState or when we're pushing out info through TelephonyRegistry, log it as info instead of error to avoid spamming the logs too much. Fixes: 130668054 Test: manual Change-Id: Ia490f2de2f0b5d326e5290e166e6f97b25e6e187 --- .../java/com/android/server/TelephonyRegistry.java | 2 ++ .../android/telephony/LocationAccessPolicy.java | 27 ++++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/TelephonyRegistry.java b/services/core/java/com/android/server/TelephonyRegistry.java index af78b769ce8c..da91187c053f 100644 --- a/services/core/java/com/android/server/TelephonyRegistry.java +++ b/services/core/java/com/android/server/TelephonyRegistry.java @@ -2300,6 +2300,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { .setCallingPid(r.callerPid) .setCallingUid(r.callerUid) .setMethod("TelephonyRegistry push") + .setLogAsInfo(true) // we don't need to log an error every time we push .setMinSdkVersionForFine(minSdk) .build(); @@ -2317,6 +2318,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { .setCallingPid(r.callerPid) .setCallingUid(r.callerUid) .setMethod("TelephonyRegistry push") + .setLogAsInfo(true) // we don't need to log an error every time we push .setMinSdkVersionForCoarse(minSdk) .build(); diff --git a/telephony/java/android/telephony/LocationAccessPolicy.java b/telephony/java/android/telephony/LocationAccessPolicy.java index b9d8eb637c34..eb744f619f2e 100644 --- a/telephony/java/android/telephony/LocationAccessPolicy.java +++ b/telephony/java/android/telephony/LocationAccessPolicy.java @@ -63,15 +63,18 @@ public final class LocationAccessPolicy { public final int callingPid; public final int minSdkVersionForCoarse; public final int minSdkVersionForFine; + public final boolean logAsInfo; public final String method; private LocationPermissionQuery(String callingPackage, int callingUid, int callingPid, - int minSdkVersionForCoarse, int minSdkVersionForFine, String method) { + int minSdkVersionForCoarse, int minSdkVersionForFine, boolean logAsInfo, + String method) { this.callingPackage = callingPackage; this.callingUid = callingUid; this.callingPid = callingPid; this.minSdkVersionForCoarse = minSdkVersionForCoarse; this.minSdkVersionForFine = minSdkVersionForFine; + this.logAsInfo = logAsInfo; this.method = method; } @@ -81,6 +84,7 @@ public final class LocationAccessPolicy { private int mCallingPid; private int mMinSdkVersionForCoarse = Integer.MAX_VALUE; private int mMinSdkVersionForFine = Integer.MAX_VALUE; + private boolean mLogAsInfo = false; private String mMethod; /** @@ -135,14 +139,27 @@ public final class LocationAccessPolicy { return this; } + /** + * If called with {@code true}, log messages will only be printed at the info level. + */ + public Builder setLogAsInfo(boolean logAsInfo) { + mLogAsInfo = logAsInfo; + return this; + } + public LocationPermissionQuery build() { return new LocationPermissionQuery(mCallingPackage, mCallingUid, - mCallingPid, mMinSdkVersionForCoarse, mMinSdkVersionForFine, mMethod); + mCallingPid, mMinSdkVersionForCoarse, mMinSdkVersionForFine, + mLogAsInfo, mMethod); } } } - private static void logError(Context context, String errorMsg) { + private static void logError(Context context, LocationPermissionQuery query, String errorMsg) { + if (query.logAsInfo) { + Log.i(TAG, errorMsg); + return; + } Log.e(TAG, errorMsg); try { if (Build.IS_DEBUGGABLE) { @@ -201,13 +218,13 @@ public final class LocationAccessPolicy { + " because we're not enforcing API " + minSdkVersion + " yet." + " Please fix this app because it will break in the future. Called from " + query.method; - logError(context, errorMsg); + logError(context, query, errorMsg); return null; } else if (!isAppAtLeastSdkVersion(context, query.callingPackage, minSdkVersion)) { String errorMsg = "Allowing " + query.callingPackage + " " + locationTypeForLog + " because it doesn't target API " + minSdkVersion + " yet." + " Please fix this app. Called from " + query.method; - logError(context, errorMsg); + logError(context, query, errorMsg); return null; } else { // If we're not allowing it due to the above two conditions, this means that the app -- 2.11.0