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

Commit c4e90ac0 authored by Ashwini Oruganti's avatar Ashwini Oruganti
Browse files

Require explicit `android:exported` in manifests

Starting S+, if an intent filter is defined, we are requiring that the
android:exported flag also be explicitly defined in the manifest. With
this change apps targeting S+  that do not meet this requirement will
fail to install.

There is no change in the default behavior of the `android:exported`
flag when there is no intent filter defined (i.e. the flag defaults to
false in these cases).

Bug: 150232615
Test: Flashed the build on a device and tested with test apps
Change-Id: I36efeebf28f21a4d4277f40a17e38d2183514037
parent 977f828b
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;
@@ -383,7 +384,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;
        }
    }