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

Commit 98cbbae5 authored by Evan Chen's avatar Evan Chen
Browse files

Fix CDM discovery timeout

CDM has a regression preventing activity launches after timeout
due to DiscoveryState potentially remaining in FINISHED_TIMEOUT.
We must ensure activities are cancelled when timeout occurs while discovery is in progress.

Flag: EXEMPT bugfix
Bug: 342470917
Test: CTS
Change-Id: I531676195e674e2ce52632e5bae6c93fc1d5e1d0
parent 5cc2247e
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -27,6 +27,8 @@ import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTE

import static com.android.companiondevicemanager.CompanionDeviceDiscoveryService.DiscoveryState;
import static com.android.companiondevicemanager.CompanionDeviceDiscoveryService.DiscoveryState.FINISHED_TIMEOUT;
import static com.android.companiondevicemanager.CompanionDeviceDiscoveryService.LOCK;
import static com.android.companiondevicemanager.CompanionDeviceDiscoveryService.sDiscoveryStarted;
import static com.android.companiondevicemanager.CompanionDeviceResources.PROFILE_ICONS;
import static com.android.companiondevicemanager.CompanionDeviceResources.PROFILE_NAMES;
import static com.android.companiondevicemanager.CompanionDeviceResources.PROFILE_PERMISSIONS;
@@ -326,10 +328,14 @@ public class CompanionAssociationActivity extends FragmentActivity implements
    private void onDiscoveryStateChanged(DiscoveryState newState) {
        if (newState == FINISHED_TIMEOUT
                && CompanionDeviceDiscoveryService.getScanResult().getValue().isEmpty()) {
            synchronized (LOCK) {
                if (sDiscoveryStarted) {
                    cancel(/* discoveryTimeOut */ true,
                            /* userRejected */ false, /* internalError */ false);
                }
            }
        }
    }

    private void onUserSelectedDevice(@NonNull DeviceFilterPair<?> selectedDevice) {
        final MacAddress macAddress = selectedDevice.getMacAddress();
+4 −3
Original line number Diff line number Diff line
@@ -90,9 +90,6 @@ public class CompanionDeviceDiscoveryService extends Service {
            new MutableLiveData<>(Collections.emptyList());
    private static MutableLiveData<DiscoveryState> sStateLiveData =
            new MutableLiveData<>(DiscoveryState.NOT_STARTED);
    private static final Object LOCK = new Object();
    @GuardedBy("LOCK")
    private static boolean sDiscoveryStarted = false;

    private BluetoothManager mBtManager;
    private BluetoothAdapter mBtAdapter;
@@ -109,6 +106,10 @@ public class CompanionDeviceDiscoveryService extends Service {

    private boolean mStopAfterFirstMatch;

    static final Object LOCK = new Object();
    @GuardedBy("LOCK")
    static boolean sDiscoveryStarted = false;

    /**
     * A state enum for devices' discovery.
     */