diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 0772478e2be4c..b1b34114a718d 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -2344,6 +2344,7 @@ package android.content { } 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 f4ae2c512c88e..8a8dfd1971572 100644 --- a/core/java/android/content/Intent.java +++ b/core/java/android/content/Intent.java @@ -848,6 +848,21 @@ public class Intent implements Parcelable, Cloneable { public static final String ACTION_SHOW_APP_INFO = "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. + * + *
Input: Nothing.
+ *Output: Nothing
+ * + * @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. * diff --git a/services/core/java/com/android/server/policy/AppOpsPolicy.java b/services/core/java/com/android/server/policy/AppOpsPolicy.java index 25709d4295d2b..ca7406be52702 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.BroadcastReceiver; 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.os.UserHandle; 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 @@ public final class AppOpsPolicy implements AppOpsManagerInternal.CheckOpsDelegat } 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); } }