TEMP add app ops debug logs

Bug: 190073375
Bug: 189484870
Test: build
Change-Id: Id9133066fa58b158e2a3e00d12af9e92407caccb
This commit is contained in:
Nate Myren
2021-06-03 15:36:13 -07:00
parent 1de80b1d70
commit 39c56f4be2
2 changed files with 56 additions and 4 deletions

View File

@@ -3351,10 +3351,21 @@ public class AppOpsService extends IAppOpsService.Stub {
boolean shouldCollectMessage) {
RestrictionBypass bypass;
try {
bypass = verifyAndGetBypass(uid, packageName, attributionTag, proxyPackageName);
boolean isLocOrActivity = code == AppOpsManager.OP_FINE_LOCATION
|| code == AppOpsManager.OP_FINE_LOCATION_SOURCE
|| code == AppOpsManager.OP_ACTIVITY_RECOGNITION
|| code == AppOpsManager.OP_ACTIVITY_RECOGNITION_SOURCE;
bypass = verifyAndGetBypass(uid, packageName, attributionTag, proxyPackageName,
isLocOrActivity);
boolean wasNull = attributionTag == null;
if (bypass != null && bypass.getIsAttributionTagNotFound()) {
attributionTag = null;
}
if (attributionTag == null && isLocOrActivity
&& packageName.equals("com.google.android.gms")) {
Slog.i("AppOpsDebug", "null tag on location or activity op " + code
+ " for " + packageName + ", was overridden: " + !wasNull, new Exception());
}
} catch (SecurityException e) {
Slog.e(TAG, "noteOperation", e);
return new SyncNotedAppOp(AppOpsManager.MODE_ERRORED, code, attributionTag,
@@ -3861,10 +3872,20 @@ public class AppOpsService extends IAppOpsService.Stub {
int attributionChainId, boolean dryRun) {
RestrictionBypass bypass;
try {
bypass = verifyAndGetBypass(uid, packageName, attributionTag, proxyPackageName);
boolean isLocOrActivity = code == AppOpsManager.OP_FINE_LOCATION
|| code == AppOpsManager.OP_FINE_LOCATION_SOURCE
|| code == AppOpsManager.OP_ACTIVITY_RECOGNITION
|| code == AppOpsManager.OP_ACTIVITY_RECOGNITION_SOURCE;
bypass = verifyAndGetBypass(uid, packageName, attributionTag, proxyPackageName,
isLocOrActivity);
if (bypass != null && bypass.getIsAttributionTagNotFound()) {
attributionTag = null;
}
if (attributionTag == null && isLocOrActivity
&& packageName.equals("com.google.android.gms")) {
Slog.i("AppOpsDebug", "null tag on location or activity op "
+ code + " for " + packageName, new Exception());
}
} catch (SecurityException e) {
Slog.e(TAG, "startOperation", e);
return new SyncNotedAppOp(AppOpsManager.MODE_ERRORED, code, attributionTag,
@@ -4418,7 +4439,7 @@ public class AppOpsService extends IAppOpsService.Stub {
*/
private @Nullable RestrictionBypass verifyAndGetBypass(int uid, String packageName,
@Nullable String attributionTag) {
return verifyAndGetBypass(uid, packageName, attributionTag, null);
return verifyAndGetBypass(uid, packageName, attributionTag, null, false);
}
/**
@@ -4433,7 +4454,7 @@ public class AppOpsService extends IAppOpsService.Stub {
* @return {@code true} iff the package is privileged
*/
private @Nullable RestrictionBypass verifyAndGetBypass(int uid, String packageName,
@Nullable String attributionTag, @Nullable String proxyPackageName) {
@Nullable String attributionTag, @Nullable String proxyPackageName, boolean extraLog) {
if (uid == Process.ROOT_UID) {
// For backwards compatibility, don't check package name for root UID.
return null;
@@ -4475,6 +4496,15 @@ public class AppOpsService extends IAppOpsService.Stub {
AndroidPackage pkg = pmInt.getPackage(packageName);
if (pkg != null) {
isAttributionTagValid = isAttributionInPackage(pkg, attributionTag);
if (packageName.equals("com.google.android.gms") && extraLog) {
if (isAttributionTagValid && attributionTag != null) {
Slog.i("AppOpsDebug", "tag " + attributionTag + " found in "
+ packageName);
} else {
Slog.i("AppOpsDebug", "tag " + attributionTag + " missing from "
+ packageName);
}
}
pkgUid = UserHandle.getUid(userId, UserHandle.getAppId(pkg.getUid()));
bypass = getBypassforPackage(pkg);

View File

@@ -225,13 +225,21 @@ public final class AppOpsPolicy implements AppOpsManagerInternal.CheckOpsDelegat
if (isDatasourceAttributionTag(uid, packageName, attributionTag,
mLocationTags)) {
return resolvedCode;
} else if (packageName.equals("com.google.android.gms")) {
Log.i("AppOpsDebugRemapping", "NOT remapping " + packageName + " code "
+ code + " for tag " + attributionTag);
}
} else {
resolvedCode = resolveArOp(code);
if (resolvedCode != code) {
if (isDatasourceAttributionTag(uid, packageName, attributionTag,
mActivityRecognitionTags)) {
Log.i("AppOpsDebugRemapping", "remapping " + packageName + " code "
+ code + " to " + resolvedCode + " for tag " + attributionTag);
return resolvedCode;
} else if (packageName.equals("com.google.android.gms")) {
Log.i("AppOpsDebugRemapping", "NOT remapping " + packageName
+ " code " + code + " for tag " + attributionTag);
}
}
}
@@ -334,8 +342,22 @@ public final class AppOpsPolicy implements AppOpsManagerInternal.CheckOpsDelegat
if (appIdTags != null) {
final ArraySet<String> packageTags = appIdTags.get(packageName);
if (packageTags != null && packageTags.contains(attributionTag)) {
if (packageName.equals("com.google.android.gms")) {
Log.i("AppOpsDebugRemapping", packageName + " tag "
+ attributionTag + " in " + packageTags);
}
return true;
}
if (packageName.equals("com.google.android.gms")) {
Log.i("AppOpsDebugRemapping", packageName + " tag " + attributionTag
+ " NOT in " + packageTags);
}
} else {
if (packageName.equals("com.google.android.gms")) {
Log.i("AppOpsDebugRemapping", "no package tags for uid " + uid
+ " package " + packageName);
}
}
return false;
}