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

Commit 184d0745 authored by Soonil Nagarkar's avatar Soonil Nagarkar
Browse files

Support null service resources in ServiceWatcher

Allow OEMs to use null as a valid value for service implementations that
should not bind to any service, and should not be supported.

Bug: 311210517
Test: manual
Change-Id: I266eca7278bb11faca26c736052c2bb467b7fb72
parent 7ad4889e
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
package: "android.location.flags"

flag {
    name: "fix_service_watcher"
    namespace: "location"
    description: "Enable null explicit services in ServiceWatcher"
    bug: "311210517"
}

flag {
    name: "gnss_api_navic_l1"
    namespace: "location"
+27 −1
Original line number Diff line number Diff line
@@ -36,10 +36,12 @@ import android.content.IntentFilter;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.content.res.Resources;
import android.location.flags.Flags;
import android.os.Bundle;
import android.os.Process;
import android.os.UserHandle;
import android.util.Log;
import android.util.TypedValue;

import com.android.internal.util.Preconditions;
import com.android.server.FgThread;
@@ -70,6 +72,10 @@ public final class CurrentUserServiceSupplier extends BroadcastReceiver implemen
    private static final String EXTRA_SERVICE_VERSION = "serviceVersion";
    private static final String EXTRA_SERVICE_IS_MULTIUSER = "serviceIsMultiuser";

    // a package value that will never match against any package (we can't use null since this will
    // match against any package).
    private static final String NO_MATCH_PACKAGE = "";

    private static final Comparator<BoundServiceInfo> sBoundServiceInfoComparator = (o1, o2) -> {
        if (o1 == o2) {
            return 0;
@@ -196,7 +202,19 @@ public final class CurrentUserServiceSupplier extends BroadcastReceiver implemen
        Resources resources = context.getResources();
        boolean enableOverlay = resources.getBoolean(enableOverlayResId);
        if (!enableOverlay) {
            if (Flags.fixServiceWatcher()) {
                // we don't use getText() or similar because it won't return null values
                TypedValue out = new TypedValue();
                resources.getValue(nonOverlayPackageResId, out, true);
                CharSequence explicitPackage = out.coerceToString();
                if (explicitPackage == null) {
                    return NO_MATCH_PACKAGE;
                } else {
                    return explicitPackage.toString();
                }
            } else {
                return resources.getString(nonOverlayPackageResId);
            }
        } else {
            return null;
        }
@@ -233,6 +251,10 @@ public final class CurrentUserServiceSupplier extends BroadcastReceiver implemen

    @Override
    public boolean hasMatchingService() {
        if (Flags.fixServiceWatcher() && NO_MATCH_PACKAGE.equals(mIntent.getPackage())) {
            return false;
        }

        int intentQueryFlags = MATCH_DIRECT_BOOT_AWARE | MATCH_DIRECT_BOOT_UNAWARE;
        if (mMatchSystemAppsOnly) {
            intentQueryFlags |= MATCH_SYSTEM_ONLY;
@@ -268,6 +290,10 @@ public final class CurrentUserServiceSupplier extends BroadcastReceiver implemen

    @Override
    public BoundServiceInfo getServiceInfo() {
        if (Flags.fixServiceWatcher() && NO_MATCH_PACKAGE.equals(mIntent.getPackage())) {
            return null;
        }

        BoundServiceInfo bestServiceInfo = null;

        // only allow services in the correct direct boot state to match