Update connected devices sets when app is killed

Update the current connected devices sets when binder is dead, so that
application is able to call notifyDeviceAppeared after re-launch the application.

Bug: 230668833
Test: atest CtsCompanionDeviceManagerCoreTestCases
      atest CtsCompanionDeviceManagerUiAutomationTestCases
      atest CtsOsTestCases:CompanionDeviceManagerTest
Change-Id: I851a0fd0dda2a65750591685aedd1b694fc4c741
This commit is contained in:
Evan Chen
2022-05-02 15:43:29 -07:00
parent bf068a0636
commit f90a00f410
2 changed files with 19 additions and 3 deletions

View File

@@ -294,6 +294,15 @@ public class CompanionDeviceManagerService extends SystemService {
private boolean onCompanionApplicationBindingDiedInternal(
@UserIdInt int userId, @NonNull String packageName) {
// Update the current connected devices sets when binderDied, so that application is able
// to call notifyDeviceAppeared after re-launch the application.
for (AssociationInfo ai :
mAssociationStore.getAssociationsForPackage(userId, packageName)) {
int id = ai.getId();
Slog.i(TAG, "Removing association id: " + id + " for package: "
+ packageName + " due to binderDied.");
mDevicePresenceMonitor.removeDeviceFromMonitoring(id);
}
// TODO(b/218613015): implement.
return false;
}

View File

@@ -205,6 +205,15 @@ public class CompanionDevicePresenceMonitor implements AssociationStore.OnChange
mCallback.onDeviceDisappeared(goneDeviceAssociationId);
}
/**
* Remove the current connected devices by associationId.
*/
public void removeDeviceFromMonitoring(int associationId) {
mConnectedBtDevices.remove(associationId);
mNearbyBleDevices.remove(associationId);
mReportedSelfManagedDevices.remove(associationId);
}
/**
* Implements
* {@link AssociationStore.OnChangeListener#onAssociationRemoved(AssociationInfo)}
@@ -217,9 +226,7 @@ public class CompanionDevicePresenceMonitor implements AssociationStore.OnChange
Log.d(TAG, " > association=" + association);
}
mConnectedBtDevices.remove(id);
mNearbyBleDevices.remove(id);
mReportedSelfManagedDevices.remove(id);
removeDeviceFromMonitoring(id);
// Do NOT call mCallback.onDeviceDisappeared()!
// CompanionDeviceManagerService will know that the association is removed, and will do