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

Commit ecc4ce44 authored by Raphael Kim's avatar Raphael Kim Committed by Automerger Merge Worker
Browse files

Merge "Handle device presence registry when device is already active." into...

Merge "Handle device presence registry when device is already active." into tm-dev am: fb9cbc6a am: 4540a72d am: 5cc61809 am: e64bdca7

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



Change-Id: Ife99e0626889482a120c884f03ec144780c1e2e0
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents d6ed414a e64bdca7
Loading
Loading
Loading
Loading
+23 −1
Original line number Diff line number Diff line
@@ -689,6 +689,12 @@ public class CompanionDeviceManagerService extends SystemService {

        private void registerDevicePresenceListenerActive(String packageName, String deviceAddress,
                boolean active) throws RemoteException {
            if (DEBUG) {
                Log.i(TAG, "registerDevicePresenceListenerActive()"
                        + " active=" + active
                        + " deviceAddress=" + deviceAddress);
            }

            getContext().enforceCallingOrSelfPermission(
                    android.Manifest.permission.REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE,
                    "[un]registerDevicePresenceListenerService");
@@ -704,6 +710,12 @@ public class CompanionDeviceManagerService extends SystemService {
                        + " for user " + userId));
            }

            // If already at specified state, then no-op.
            if (active == association.isNotifyOnDeviceNearby()) {
                if (DEBUG) Log.d(TAG, "Device presence listener is already at desired state.");
                return;
            }

            // AssociationInfo class is immutable: create a new AssociationInfo object with updated
            // flag.
            association = AssociationInfo.builder(association)
@@ -714,7 +726,17 @@ public class CompanionDeviceManagerService extends SystemService {
            // an application sets/unsets the mNotifyOnDeviceNearby flag.
            mAssociationStore.updateAssociation(association);

            // TODO(b/218615198): correctly handle the case when the device is currently present.
            // If device is already present, then trigger callback.
            if (active && mDevicePresenceMonitor.isDevicePresent(association.getId())) {
                if (DEBUG) Log.d(TAG, "Device is already present. Triggering callback.");
                onDeviceAppearedInternal(association.getId());
            }

            // If last listener is unregistered, then unbind application.
            if (!active && !shouldBindPackage(userId, packageName)) {
                if (DEBUG) Log.d(TAG, "Last listener unregistered. Unbinding application.");
                mCompanionAppController.unbindCompanionApplication(userId, packageName);
            }
        }

        @Override