Add AR intent to ingest exempt attribution tags
bug: 179069158
Test: atest CtsActivityRecognitionTestCases
Change-Id: I3fa454351a586cc5d408217a2c1382048e6031e4
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index 0772478..b1b3411 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -2344,6 +2344,7 @@
}
public class Intent implements java.lang.Cloneable android.os.Parcelable {
+ field public static final String ACTION_ACTIVITY_RECOGNIZER = "android.intent.action.ACTIVITY_RECOGNIZER";
field public static final String ACTION_BATTERY_LEVEL_CHANGED = "android.intent.action.BATTERY_LEVEL_CHANGED";
field public static final String ACTION_CALL_EMERGENCY = "android.intent.action.CALL_EMERGENCY";
field public static final String ACTION_CALL_PRIVILEGED = "android.intent.action.CALL_PRIVILEGED";
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java
index 183e73c..fd0bd23 100644
--- a/core/java/android/content/Intent.java
+++ b/core/java/android/content/Intent.java
@@ -848,6 +848,21 @@
= "android.intent.action.SHOW_APP_INFO";
/**
+ * Activity Action: Placeholder that the component handling it can do activity
+ * recognition. Can be placed on a service. Only one service per package is
+ * supported.
+ *
+ * <p>Input: Nothing.</p>
+ * <p>Output: Nothing </p>
+ *
+ * @hide
+ */
+ @SystemApi
+ @SdkConstant(SdkConstantType.SERVICE_ACTION)
+ public static final String ACTION_ACTIVITY_RECOGNIZER =
+ "android.intent.action.ACTIVITY_RECOGNIZER";
+
+ /**
* Represents a shortcut/live folder icon resource.
*
* @see Intent#ACTION_CREATE_SHORTCUT
diff --git a/services/core/java/com/android/server/policy/AppOpsPolicy.java b/services/core/java/com/android/server/policy/AppOpsPolicy.java
index 25709d4..ca7406b 100644
--- a/services/core/java/com/android/server/policy/AppOpsPolicy.java
+++ b/services/core/java/com/android/server/policy/AppOpsPolicy.java
@@ -27,8 +27,8 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
-import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
import android.location.LocationManagerInternal;
import android.net.Uri;
import android.os.IBinder;
@@ -36,6 +36,7 @@
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.ArraySet;
+import android.util.Log;
import android.util.Slog;
import com.android.internal.annotations.GuardedBy;
@@ -237,25 +238,31 @@
}
private void updateActivityRecognizerTags(@NonNull String activityRecognizer) {
- try {
- final ApplicationInfo recognizerAppInfo = mContext.getPackageManager()
- .getApplicationInfoAsUser(activityRecognizer, PackageManager.GET_META_DATA,
- UserHandle.USER_SYSTEM);
- if (recognizerAppInfo.metaData == null) {
- return;
+ final int flags = PackageManager.GET_SERVICES
+ | PackageManager.GET_META_DATA
+ | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
+ | PackageManager.MATCH_DIRECT_BOOT_AWARE
+ | PackageManager.MATCH_DIRECT_BOOT_UNAWARE;
+
+ final Intent intent = new Intent(Intent.ACTION_ACTIVITY_RECOGNIZER);
+ intent.setPackage(activityRecognizer);
+ final ResolveInfo resolvedService = mContext.getPackageManager()
+ .resolveServiceAsUser(intent, flags, UserHandle.USER_SYSTEM);
+ if (resolvedService == null || resolvedService.serviceInfo == null) {
+ Log.w(LOG_TAG, "Service recognizer doesn't handle "
+ + Intent.ACTION_ACTIVITY_RECOGNIZER + ", ignoring!");
+ return;
+ }
+ final String tagsList = resolvedService.serviceInfo.metaData.getString(
+ ACTIVITY_RECOGNITION_TAGS);
+ if (tagsList != null) {
+ final String[] tags = tagsList.split(ACTIVITY_RECOGNITION_TAGS_SEPARATOR);
+ synchronized (mLock) {
+ updateAllowListedTagsForPackageLocked(
+ resolvedService.serviceInfo.applicationInfo.uid,
+ resolvedService.serviceInfo.packageName, new ArraySet<>(tags),
+ mActivityRecognitionTags);
}
- final String tagsList = recognizerAppInfo.metaData.getString(ACTIVITY_RECOGNITION_TAGS);
- if (tagsList != null) {
- final String[] tags = tagsList.split(ACTIVITY_RECOGNITION_TAGS_SEPARATOR);
- synchronized (mLock) {
- updateAllowListedTagsForPackageLocked(recognizerAppInfo.uid,
- recognizerAppInfo.packageName, new ArraySet<>(tags),
- mActivityRecognitionTags);
- }
- }
- } catch (PackageManager.NameNotFoundException e) {
- Slog.wtf(LOG_TAG, "Missing " + RoleManager.ROLE_SYSTEM_ACTIVITY_RECOGNIZER
- + " role holder package " + activityRecognizer);
}
}