Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0d6d9f97 authored by Svet Ganov's avatar Svet Ganov
Browse files

Add AR intent to ingest exempt attribution tags

bug: 179069158

Test: atest CtsActivityRecognitionTestCases

Change-Id: I3fa454351a586cc5d408217a2c1382048e6031e4
parent a7e6b948
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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";
+15 −0
Original line number Diff line number Diff line
@@ -847,6 +847,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.
     *
     * <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.
     *
+26 −19
Original line number Diff line number Diff line
@@ -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,26 +238,32 @@ 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) {
        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 = recognizerAppInfo.metaData.getString(ACTIVITY_RECOGNITION_TAGS);
        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(recognizerAppInfo.uid,
                            recognizerAppInfo.packageName, new ArraySet<>(tags),
                updateAllowListedTagsForPackageLocked(
                        resolvedService.serviceInfo.applicationInfo.uid,
                        resolvedService.serviceInfo.packageName, new ArraySet<>(tags),
                        mActivityRecognitionTags);
            }
        }
        } catch (PackageManager.NameNotFoundException e) {
            Slog.wtf(LOG_TAG, "Missing " + RoleManager.ROLE_SYSTEM_ACTIVITY_RECOGNIZER
                    + " role holder package " + activityRecognizer);
        }
    }

    private static void updateAllowListedTagsForPackageLocked(int uid, String packageName,