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

Commit 3120705c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Optimize checking if package defines companion services in CDM" into tm-dev am: ba88e170

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17056084

Change-Id: I5adc01d44cb950b602222cb570e838b3ced89f85
parents 880f835d ba88e170
Loading
Loading
Loading
Loading
+24 −17
Original line number Diff line number Diff line
@@ -108,8 +108,16 @@ class CompanionApplicationController {

        final List<ComponentName> companionServices =
                mCompanionServicesRegister.forPackage(userId, packageName);
        final List<CompanionDeviceServiceConnector> serviceConnectors;
        if (companionServices.isEmpty()) {
            Slog.w(TAG, "Can not bind companion applications u" + userId + "/" + packageName + ": "
                    + "eligible CompanionDeviceService not found.\n"
                    + "A CompanionDeviceService should declare an intent-filter for "
                    + "\"android.companion.CompanionDeviceService\" action and require "
                    + "\"android.permission.BIND_COMPANION_DEVICE_SERVICE\" permission.");
            return;
        }

        final List<CompanionDeviceServiceConnector> serviceConnectors;
        synchronized (mBoundCompanionApplications) {
            if (mBoundCompanionApplications.containsValueForPackage(userId, packageName)) {
                if (DEBUG) Log.e(TAG, "u" + userId + "/" + packageName + " is ALREADY bound.");
@@ -118,13 +126,6 @@ class CompanionApplicationController {

            serviceConnectors = CollectionUtils.map(companionServices, componentName ->
                            new CompanionDeviceServiceConnector(mContext, userId, componentName));

            if (serviceConnectors.isEmpty()) {
                Slog.e(TAG, "Can't find CompanionDeviceService implementer in package: "
                        + packageName + ". Please check if they are correctly declared.");
                return;
            }

            mBoundCompanionApplications.setValueForPackage(userId, packageName, serviceConnectors);
        }

@@ -145,7 +146,11 @@ class CompanionApplicationController {
            serviceConnectors = mBoundCompanionApplications.removePackage(userId, packageName);
        }
        if (serviceConnectors == null) {
            if (DEBUG) Log.e(TAG, "u" + userId + "/" + packageName + " is NOT bound");
            if (DEBUG) {
                Log.e(TAG, "unbindCompanionApplication(): "
                        + "u" + userId + "/" + packageName + " is NOT bound");
                Log.d(TAG, "Stacktrace", new Throwable());
            }
            return;
        }

@@ -191,7 +196,11 @@ class CompanionApplicationController {
        final CompanionDeviceServiceConnector primaryServiceConnector =
                getPrimaryServiceConnector(userId, packageName);
        if (primaryServiceConnector == null) {
            if (DEBUG) Log.e(TAG, "u" + userId + "/" + packageName + " is NOT bound.");
            if (DEBUG) {
                Log.e(TAG, "notify_CompanionApplicationDevice_Appeared(): "
                        + "u" + userId + "/" + packageName + " is NOT bound.");
                Log.d(TAG, "Stacktrace", new Throwable());
            }
            return;
        }

@@ -209,7 +218,11 @@ class CompanionApplicationController {
        final CompanionDeviceServiceConnector primaryServiceConnector =
                getPrimaryServiceConnector(userId, packageName);
        if (primaryServiceConnector == null) {
            if (DEBUG) Log.e(TAG, "u" + userId + "/" + packageName + " is NOT bound.");
            if (DEBUG) {
                Log.e(TAG, "notify_CompanionApplicationDevice_Disappeared(): "
                        + "u" + userId + "/" + packageName + " is NOT bound.");
                Log.d(TAG, "Stacktrace", new Throwable());
            }
            return;
        }

@@ -253,12 +266,6 @@ class CompanionApplicationController {
            return forUser(userId).getOrDefault(packageName, Collections.emptyList());
        }

        synchronized @NonNull ComponentName primaryForPackage(
                @UserIdInt int userId, @NonNull String packageName) {
            // The primary service is always at the head of the list.
            return forPackage(userId, packageName).get(0);
        }

        synchronized void invalidate(@UserIdInt int userId) {
            remove(userId);
        }