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

Commit 553bada3 authored by Ashwini Oruganti's avatar Ashwini Oruganti
Browse files

Require explicit `android:exported` in manifests for services

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: Icc34b533cd7420e5754f7a1e7ae9fde937febf7d
parent bc48719e
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -25,10 +25,12 @@ 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.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.os.Build;

import com.android.internal.R;

@@ -157,7 +159,18 @@ public class ParsedServiceUtils {
        }

        if (!setExported) {
            service.exported = service.getIntents().size() > 0;
            boolean hasIntentFilters = service.getIntents().size() > 0;
            if (hasIntentFilters) {
                final ParseResult exportedCheckResult = input.deferError(
                        service.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);
                }
            }
            service.exported = hasIntentFilters;
        }

        return input.success(service);