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

Commit b9b1de53 authored by John Wu's avatar John Wu Committed by Android (Google) Code Review
Browse files

Merge changes from topics "merge_safer_intent", "unsafe_intent_strict_mode" into main

* changes:
  Add new unsafe intent usage strict mode violations
  Consolidate all safer intent implementation
  Simplify and fix resolveIntent implementation
parents 42cb9e22 3e66b0ad
Loading
Loading
Loading
Loading
+2 −12
Original line number Diff line number Diff line
@@ -1101,19 +1101,9 @@ public abstract class ActivityManagerInternal {
    public abstract ArraySet<String> getClientPackages(String servicePackageName);

    /**
     * Retrieve an IUnsafeIntentStrictModeCallback matching the given callingUid.
     * Returns null no match is found.
     * @param callingPid The PID mapped with the callback.
     * @return The callback, if it exists.
     * Trigger an unsafe intent usage strict mode violation.
     */
    public abstract IUnsafeIntentStrictModeCallback getRegisteredStrictModeCallback(
            int callingPid);

    /**
     * Unregisters an IUnsafeIntentStrictModeCallback matching the given callingUid.
     * @param callingPid The PID mapped with the callback.
     */
    public abstract void unregisterStrictModeCallback(int callingPid);
    public abstract void triggerUnsafeIntentStrictMode(int callingPid, int type, Intent intent);

    /**
     * Start a foreground service delegate.
+1 −1
Original line number Diff line number Diff line
@@ -24,5 +24,5 @@ import android.content.Intent;
 */
oneway interface IUnsafeIntentStrictModeCallback
{
    void onImplicitIntentMatchedInternalComponent(in Intent intent);
    void onUnsafeIntent(int type, in Intent intent);
}
+36 −20
Original line number Diff line number Diff line
@@ -17,6 +17,10 @@ package android.os;

import static android.annotation.SystemApi.Client.MODULE_LIBRARIES;

import static com.android.internal.util.FrameworkStatsLog.UNSAFE_INTENT_EVENT_REPORTED__EVENT_TYPE__EXPLICIT_INTENT_FILTER_UNMATCH;
import static com.android.internal.util.FrameworkStatsLog.UNSAFE_INTENT_EVENT_REPORTED__EVENT_TYPE__INTERNAL_NON_EXPORTED_COMPONENT_MATCH;
import static com.android.internal.util.FrameworkStatsLog.UNSAFE_INTENT_EVENT_REPORTED__EVENT_TYPE__NULL_ACTION_MATCH;

import android.animation.ValueAnimator;
import android.annotation.IntDef;
import android.annotation.NonNull;
@@ -2135,27 +2139,26 @@ public final class StrictMode {
        }
    }

    private static void registerIntentMatchingRestrictionCallback() {
        try {
            ActivityManager.getService().registerStrictModeCallback(
                    new UnsafeIntentStrictModeCallback());
        } catch (RemoteException e) {
            /*
            If exception is DeadObjectException it means system process is dead, so we can ignore
             */
            if (!(e instanceof DeadObjectException)) {
                Log.e(TAG, "RemoteException handling StrictMode violation", e);
            }
        }
    }

    private static final class UnsafeIntentStrictModeCallback
            extends IUnsafeIntentStrictModeCallback.Stub {
        @Override
        public void onImplicitIntentMatchedInternalComponent(Intent intent) {
        public void onUnsafeIntent(int type, Intent intent) {
            if (StrictMode.vmUnsafeIntentLaunchEnabled()) {
                StrictMode.onUnsafeIntentLaunch(intent,
                        "Launch of unsafe implicit intent: " + intent);
                StrictMode.onUnsafeIntentLaunch(type, intent);
            }
        }
    }

    /** Each process should only have one singleton callback */
    private static volatile UnsafeIntentStrictModeCallback sUnsafeIntentCallback;

    private static void registerIntentMatchingRestrictionCallback() {
        if (sUnsafeIntentCallback == null) {
            sUnsafeIntentCallback = new UnsafeIntentStrictModeCallback();
            try {
                ActivityManager.getService().registerStrictModeCallback(sUnsafeIntentCallback);
            } catch (RemoteException e) {
                // system_server should not throw
            }
        }
    }
@@ -2383,9 +2386,22 @@ public final class StrictMode {
        onVmPolicyViolation(new UnsafeIntentLaunchViolation(intent));
    }

    /** @hide */
    public static void onUnsafeIntentLaunch(Intent intent, String message) {
        onVmPolicyViolation(new UnsafeIntentLaunchViolation(intent, message));
    private static void onUnsafeIntentLaunch(int type, Intent intent) {
        String msg;
        switch (type) {
            case UNSAFE_INTENT_EVENT_REPORTED__EVENT_TYPE__NULL_ACTION_MATCH:
                msg = "Launch of intent with null action: ";
                break;
            case UNSAFE_INTENT_EVENT_REPORTED__EVENT_TYPE__INTERNAL_NON_EXPORTED_COMPONENT_MATCH:
                msg = "Implicit intent matching internal non-exported component: ";
                break;
            case UNSAFE_INTENT_EVENT_REPORTED__EVENT_TYPE__EXPLICIT_INTENT_FILTER_UNMATCH:
                msg = "Intent mismatch target component intent filter: ";
                break;
            default:
                return;
        }
        onVmPolicyViolation(new UnsafeIntentLaunchViolation(intent, msg + intent));
    }

    /** Assume locked until we hear otherwise */
+16 −15
Original line number Diff line number Diff line
@@ -368,17 +368,17 @@ public abstract class PackageManagerInternal {
            Intent intent, @Nullable String resolvedType,
            @PackageManager.ResolveInfoFlagsBits long flags, int filterCallingUid, int userId);


    /**
     * Retrieve all receivers that can handle a broadcast of the given intent.
     *
     * @param filterCallingUid The results will be filtered in the context of this UID instead
     *                         of the calling UID.
     * @param forSend          true if the invocation is intended for sending broadcasts. The value
     *                         of this parameter affects how packages are filtered.
     */
    public abstract List<ResolveInfo> queryIntentReceivers(Intent intent,
            String resolvedType, @PackageManager.ResolveInfoFlagsBits long flags,
            int filterCallingUid, int userId, boolean forSend);
    public abstract List<ResolveInfo> queryIntentReceivers(
            Intent intent, String resolvedType, @PackageManager.ResolveInfoFlagsBits long flags,
            int filterCallingUid, int callingPid, int userId, boolean forSend);

    /**
     * Retrieve all services that can be performed for the given intent.
@@ -610,18 +610,10 @@ public abstract class PackageManagerInternal {
            @NonNull Set<String> outUpdatedPackageNames,
            @NonNull Set<String> outInvalidPackageNames);

    /**
     * Resolves an activity intent, allowing instant apps to be resolved.
     */
    public abstract ResolveInfo resolveIntent(Intent intent, String resolvedType,
            @PackageManager.ResolveInfoFlagsBits long flags,
            @PrivateResolveFlags long privateResolveFlags, int userId, boolean resolveForStart,
            int filterCallingUid);

    /**
     * Resolves an exported activity intent, allowing instant apps to be resolved.
     */
    public abstract ResolveInfo resolveIntentExported(Intent intent, String resolvedType,
    public abstract ResolveInfo resolveIntent(Intent intent, String resolvedType,
            @PackageManager.ResolveInfoFlagsBits long flags,
            @PrivateResolveFlags long privateResolveFlags, int userId, boolean resolveForStart,
            int filterCallingUid, int callingPid);
@@ -632,6 +624,15 @@ public abstract class PackageManagerInternal {
    public abstract ResolveInfo resolveService(Intent intent, String resolvedType,
            @PackageManager.ResolveInfoFlagsBits long flags, int userId, int callingUid);


    /**
     * Resolves a service intent for start.
     */
    public abstract ResolveInfo resolveService(
            Intent intent, String resolvedType,
            @PackageManager.ResolveInfoFlagsBits long flags, int userId,
            int callingUid, int callingPid);

    /**
    * Resolves a content provider intent.
    */
+2 −2
Original line number Diff line number Diff line
@@ -4862,7 +4862,7 @@ public final class ActiveServices {
                }
                // TODO: come back and remove this assumption to triage all services
                ResolveInfo rInfo = mAm.getPackageManagerInternal().resolveService(service,
                        resolvedType, flags, userId, callingUid);
                        resolvedType, flags, userId, callingUid, callingPid);
                ServiceInfo sInfo = rInfo != null ? rInfo.serviceInfo : null;
                if (sInfo == null) {
                    Slog.w(TAG_SERVICE, "Unable to start service " + service + " U=" + userId +
@@ -4982,7 +4982,7 @@ public final class ActiveServices {
                        try {
                            ResolveInfo rInfoForUserId0 =
                                    mAm.getPackageManagerInternal().resolveService(service,
                                            resolvedType, flags, userId, callingUid);
                                            resolvedType, flags, userId, callingUid, callingPid);
                            if (rInfoForUserId0 == null) {
                                Slog.w(TAG_SERVICE,
                                        "Unable to resolve service " + service + " U=" + userId
Loading