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

Commit 821db53b authored by John Wu's avatar John Wu Committed by Android Build Coastguard Worker
Browse files

Fix several bugs in SaferIntentUtils

- Switch over to noLogging platformCompat APIs to reduce performance
  overhead
- Add additional null check to prevent NPE

Bug: 336039853
Bug: 349017965
Flag: EXEMPT bugfix
Test: atest CtsPackageContentTestCases:SaferIntentTest
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:d4ac3c2d1e424686591d927e8097506bb7ec756c)
Merged-In: I698c3ca89f7f18cb6aa451bf885ddaa950a76e4b
Change-Id: I698c3ca89f7f18cb6aa451bf885ddaa950a76e4b
parent 9bbcc866
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -236,6 +236,25 @@ public class PlatformCompat extends IPlatformCompat.Stub {
        return enabled;
    }

    /**
     * Internal version of {@link #isChangeEnabledByUid(long, int)}.
     *
     * <p>Does not perform costly permission check and logging.
     */
    public boolean isChangeEnabledByUidInternalNoLogging(long changeId, int uid) {
        String[] packages = mContext.getPackageManager().getPackagesForUid(uid);
        if (packages == null || packages.length == 0) {
            return mCompatConfig.defaultChangeIdValue(changeId);
        }
        boolean enabled = true;
        final int userId = UserHandle.getUserId(uid);
        for (String packageName : packages) {
            final var appInfo = getApplicationInfo(packageName, userId);
            enabled &= isChangeEnabledInternalNoLogging(changeId, appInfo);
        }
        return enabled;
    }

    @Override
    @EnforcePermission(OVERRIDE_COMPAT_CHANGE_CONFIG)
    public void setOverrides(CompatibilityChangeConfig overrides, String packageName) {
+4 −2
Original line number Diff line number Diff line
@@ -104,6 +104,7 @@ public class SaferIntentUtils {
    @Disabled
    private static final long ENFORCE_INTENTS_TO_MATCH_INTENT_FILTERS = 161252188;

    @Nullable
    private static ParsedMainComponent infoToComponent(
            ComponentInfo info, ComponentResolverApi resolver, boolean isReceiver) {
        if (info instanceof ActivityInfo) {
@@ -186,7 +187,7 @@ public class SaferIntentUtils {
        }

        boolean isChangeEnabled(long changeId) {
            return platformCompat == null || platformCompat.isChangeEnabledByUidInternal(
            return platformCompat == null || platformCompat.isChangeEnabledByUidInternalNoLogging(
                    changeId, callingUid);
        }

@@ -233,7 +234,8 @@ public class SaferIntentUtils {
                }
                final ParsedMainComponent comp = infoToComponent(
                        resolveInfo.getComponentInfo(), resolver, args.isReceiver);
                if (!comp.getIntents().isEmpty() && args.intent.getAction() == null) {
                if (comp != null && !comp.getIntents().isEmpty()
                        && args.intent.getAction() == null) {
                    match = false;
                }
            } else if (c instanceof IntentFilter) {