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

Commit 7861e408 authored by Eugene Susla's avatar Eugene Susla
Browse files

Don't send onDeviceDisappeared when device is connected

Connected devices often stop advertizing but it's
confusing to report them as gone.
In this case we'll rely on the disconnected callback to
properly notify a device being gone.

Bug: 181344542
Test: presubmit
Change-Id: I30af50c0cd2a19ec5b91d52801eafa46e62a7010
parent 70a30dab
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -1075,6 +1075,7 @@ public class CompanionDeviceManagerService extends SystemService implements Bind
        Date lastSeen = mDevicesLastNearby.get(address);
        if (isDeviceDisappeared(lastSeen)) {
            onDeviceDisappeared(address);
            unscheduleTriggerDeviceDisappearedRunnable(address);
        }
    }

@@ -1210,9 +1211,20 @@ public class CompanionDeviceManagerService extends SystemService implements Bind
        @Override
        public void run() {
            Slog.d(LOG_TAG, "TriggerDeviceDisappearedRunnable.run(address = " + mAddress + ")");
            if (!mCurrentlyConnectedDevices.contains(mAddress)) {
                onDeviceDisappeared(mAddress);
            }
        }
    }

    private void unscheduleTriggerDeviceDisappearedRunnable(String address) {
        Runnable r = mTriggerDeviceDisappearedRunnables.get(address);
        if (r != null) {
            Slog.d(LOG_TAG,
                    "unscheduling TriggerDeviceDisappearedRunnable(address = " + address + ")");
            mMainHandler.removeCallbacks(r);
        }
    }

    private Set<Association> getAllAssociations(String deviceAddress) {
        List<UserInfo> aliveUsers = mUserManager.getAliveUsers();