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

Commit e8728dbf authored by Ashwini Oruganti's avatar Ashwini Oruganti Committed by Android (Google) Code Review
Browse files

Merge "Require explicit `android:exported` in manifests"

parents 54f357c0 c4e90ac0
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.content.pm.parsing.ParsingPackage;
import android.content.pm.parsing.ParsingPackageUtils;
import android.content.pm.parsing.ParsingUtils;
import android.content.pm.parsing.result.ParseInput;
import android.content.pm.parsing.result.ParseInput.DeferredError;
import android.content.pm.parsing.result.ParseResult;
import android.content.res.Configuration;
import android.content.res.Resources;
@@ -390,7 +391,18 @@ public class ParsedActivityUtils {
        activity.windowLayout = layoutResult.getResult();

        if (!setExported) {
            activity.exported = activity.getIntents().size() > 0;
            boolean hasIntentFilters = activity.getIntents().size() > 0;
            if (hasIntentFilters) {
                final ParseResult exportedCheckResult = input.deferError(
                        activity.getName() + ": Targeting S+ (version " + Build.VERSION_CODES.S
                        + " and above) requires that an explicit value for android:exported be"
                        + " defined when intent filters are present",
                        DeferredError.MISSING_EXPORTED_FLAG);
                if (exportedCheckResult.isError()) {
                    return input.error(exportedCheckResult);
                }
            }
            activity.exported = hasIntentFilters;
        }

        return input.success(activity);
+12 −0
Original line number Diff line number Diff line
@@ -71,6 +71,14 @@ public interface ParseInput {
        @EnabledAfter(targetSdkVersion = Build.VERSION_CODES.Q)
        public static final long RESOURCES_ARSC_COMPRESSED = 132742131;

        /**
         * Missing `android:exported` flag. When an intent filter is defined, an explicit value
         * for the android:exported flag is required.
         */
        @ChangeId
        @EnabledAfter(targetSdkVersion = Build.VERSION_CODES.R)
        public static final long MISSING_EXPORTED_FLAG = 150232615;

        /**
         * TODO(chiuwinson): This is required because PackageManager#getPackageArchiveInfo
         *   cannot read the targetSdk info from the changeId because it requires the
@@ -87,6 +95,10 @@ public interface ParseInput {
                return Build.VERSION_CODES.Q;
            }

            if (changeId == MISSING_EXPORTED_FLAG) {
                return Build.VERSION_CODES.R;
            }

            return -1;
        }
    }