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

Commit cd0d36e2 authored by Dorin Drimus's avatar Dorin Drimus
Browse files

Use single source of truth for CDM associations

The single source of thruth for state of the cdm associations is
cdm.getAllAssociations. The callback for onAssociationsChanged can have
an already stale list of associations, so removing all associations when
some have just been created will destroy recently created virtual
devices.
Also added some logs for virtual device creation and closure.
This fixes flakiness for CTS tests involving virtual devices, since this
is mostly applicable to tests that create and close virtual devices as
part of the setup and cleanup.

Bug: 443003159 (and many more)
Test: atest VirtualDeviceImeTest VirtualDevicePowerTest
Flag: EXEMPT BUGFIX
Change-Id: Ic162f8c1bbf402d4ce60e190fffcea7f077881a8
parent f759f9c9
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -529,6 +529,7 @@ final class VirtualDeviceImpl extends IVirtualDevice.Stub implements IBinder.Dea
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
        Slog.d(TAG, "Creating virtual device with deviceId: " + deviceId);
        mVirtualDeviceLog.logCreated(deviceId, mOwnerUid);

        mPublicVirtualDeviceObject = new VirtualDevice(
@@ -849,6 +850,7 @@ final class VirtualDeviceImpl extends IVirtualDevice.Stub implements IBinder.Dea
            return;
        }

        Slog.d(TAG, "Closing virtual device with deviceId: " + mDeviceId);
        mVirtualDeviceLog.logClosed(mDeviceId, mOwnerUid);

        final long ident = Binder.clearCallingIdentity();
@@ -902,6 +904,7 @@ final class VirtualDeviceImpl extends IVirtualDevice.Stub implements IBinder.Dea

    @Override
    public void binderDied() {
        Slog.d(TAG, "Binder died, closing virtual device with deviceId: " + mDeviceId);
        close();
    }

+6 −1
Original line number Diff line number Diff line
@@ -232,8 +232,11 @@ public class VirtualDeviceManagerService extends SystemService {
        CompanionDeviceManager cdm = getContext().getSystemService(CompanionDeviceManager.class);
        if (cdm != null) {
            onCdmAssociationsChanged(cdm.getAllAssociations(UserHandle.USER_ALL));
            // The associations received in the callback can provide a stale state so always get
            // the accurate list of associations from the single source of truth
            cdm.addOnAssociationsChangedListener(getContext().getMainExecutor(),
                    this::onCdmAssociationsChanged, UserHandle.USER_ALL);
                    associations -> onCdmAssociationsChanged(
                            cdm.getAllAssociations(UserHandle.USER_ALL)), UserHandle.USER_ALL);
        } else {
            Slog.e(TAG, "Failed to find CompanionDeviceManager. No CDM association info "
                    + " will be available.");
@@ -380,6 +383,8 @@ public class VirtualDeviceManagerService extends SystemService {
        }

        for (VirtualDeviceImpl virtualDevice : virtualDevicesToRemove) {
            Slog.d(TAG, "onCdmAssociationsChanged, removing virtual device with deviceId: "
                    + virtualDevice.getDeviceId());
            virtualDevice.close();
        }