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

Commit 08224ce1 authored by Marco Loaiza's avatar Marco Loaiza
Browse files

Handle device context with invalid deviceId

- Update documentation to clarify that deviceId of a context
  created with CreateDeviceContext() will not be updated even
  if the underlying device is closed/removed.
- Update isDeviceContext to return false in such a case as this
  is not a reliable ID anymore.

Bug: 265020871
Test: atest DeviceAssociationTest
Change-Id: I31857c58959c47dc3e2193df4bd5d4c9beba4676
parent 5ffbb10f
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -3043,7 +3043,14 @@ class ContextImpl extends Context {

    @Override
    public boolean isDeviceContext() {
        return mIsExplicitDeviceId || isAssociatedWithDisplay();
        if (mIsExplicitDeviceId) {
            if (mDeviceId == VirtualDeviceManager.DEVICE_ID_DEFAULT) {
                return true;
            }
            VirtualDeviceManager vdm = getSystemService(VirtualDeviceManager.class);
            return vdm.isValidVirtualDeviceId(mDeviceId);
        }
        return isAssociatedWithDisplay();
    }

    @Override
+4 −2
Original line number Diff line number Diff line
@@ -7340,10 +7340,12 @@ public abstract class Context {
    /**
     * Indicates whether the value of {@link Context#getDeviceId()} can be relied upon for
     * this instance. It will return {@code true} for Contexts created by
     * {@link Context#createDeviceContext(int)}, as well as for UI and Display Contexts.
     * {@link Context#createDeviceContext(int)} which reference a valid device ID, as well as for
     * UI and Display Contexts.
     * <p>
     * Contexts created with {@link Context#createDeviceContext(int)} will have an explicit
     * device association, which will never change. UI Contexts and Display Contexts are
     * device association, which will never change, even if the underlying device is closed or is
     * removed. UI Contexts and Display Contexts are
     * already associated with a display, so if the device association is not explicitly
     * given, {@link Context#getDeviceId()} will return the ID of the device associated with
     * the associated display. The system can assign an arbitrary device id value for Contexts not