From ee3cbbe095bc8d48d0b50d0100e66b2c77d1485c Mon Sep 17 00:00:00 2001 From: Soonil Nagarkar Date: Mon, 22 Feb 2021 13:46:46 -0800 Subject: [PATCH] Dump location noteOp with location off These are appropriate in some circumstances, but we dump them to the log for future evaluation just in case they are inappropriate. Bug: 180111317 Test: presubmits Change-Id: I39fc93e9288fa782d30a652427d9d37fbd311c11 --- .../server/location/LocationManagerService.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/services/core/java/com/android/server/location/LocationManagerService.java b/services/core/java/com/android/server/location/LocationManagerService.java index 6deb19a536290..fd0b9454cfc1b 100644 --- a/services/core/java/com/android/server/location/LocationManagerService.java +++ b/services/core/java/com/android/server/location/LocationManagerService.java @@ -70,6 +70,7 @@ import android.location.provider.IProviderRequestListener; import android.location.provider.ProviderProperties; import android.location.util.identity.CallerIdentity; import android.os.Binder; +import android.os.Build; import android.os.Bundle; import android.os.ICancellationSignal; import android.os.ParcelFileDescriptor; @@ -350,6 +351,22 @@ public class LocationManagerService extends ILocationManager.Stub { void onSystemReady() { mInjector.getSettingsHelper().addOnLocationEnabledChangedListener( this::onLocationModeChanged); + + if (Build.IS_DEBUGGABLE) { + // on debug builds, watch for location noteOps while location is off. there are some + // scenarios (emergency location) where this is expected, but generally this should + // rarely occur, and may indicate bugs. dump occurrences to logs for further evaluation + AppOpsManager appOps = Objects.requireNonNull( + mContext.getSystemService(AppOpsManager.class)); + appOps.startWatchingNoted( + new int[]{AppOpsManager.OP_FINE_LOCATION, AppOpsManager.OP_COARSE_LOCATION}, + (code, uid, packageName, attributionTag, flags, result) -> { + if (!isLocationEnabledForUser(UserHandle.getUserId(uid))) { + Log.w(TAG, "location noteOp with location off - " + + CallerIdentity.forTest(uid, 0, packageName, attributionTag)); + } + }); + } } void onSystemThirdPartyAppsCanStart() {