[Companion] Dont crash if started with bluetooth off
Bug: 63068644 Test: Turn BT off, and ensure the attached bud doesn't reproduce Change-Id: I0de5ba6d28d7195dd3ebc7a3af36f057c762de60
This commit is contained in:
@@ -77,7 +77,7 @@ public class DeviceDiscoveryService extends Service {
|
||||
|
||||
private BluetoothAdapter mBluetoothAdapter;
|
||||
private WifiManager mWifiManager;
|
||||
private BluetoothLeScanner mBLEScanner;
|
||||
@Nullable private BluetoothLeScanner mBLEScanner;
|
||||
private ScanSettings mDefaultScanSettings = new ScanSettings.Builder().build();
|
||||
|
||||
private List<DeviceFilter<?>> mFilters;
|
||||
@@ -185,7 +185,7 @@ public class DeviceDiscoveryService extends Service {
|
||||
mBluetoothAdapter.startDiscovery();
|
||||
}
|
||||
|
||||
if (shouldScan(mBLEFilters)) {
|
||||
if (shouldScan(mBLEFilters) && mBLEScanner != null) {
|
||||
mBLEScanCallback = new BLEScanCallback();
|
||||
mBLEScanner.startScan(mBLEScanFilters, mDefaultScanSettings, mBLEScanCallback);
|
||||
}
|
||||
@@ -224,7 +224,7 @@ public class DeviceDiscoveryService extends Service {
|
||||
unregisterReceiver(mBluetoothBroadcastReceiver);
|
||||
mBluetoothBroadcastReceiver = null;
|
||||
}
|
||||
mBLEScanner.stopScan(mBLEScanCallback);
|
||||
if (mBLEScanner != null) mBLEScanner.stopScan(mBLEScanCallback);
|
||||
if (mWifiBroadcastReceiver != null) {
|
||||
unregisterReceiver(mWifiBroadcastReceiver);
|
||||
mWifiBroadcastReceiver = null;
|
||||
|
||||
@@ -383,7 +383,7 @@ public class CompanionDeviceManagerService extends SystemService implements Bind
|
||||
findDeviceCallback,
|
||||
getServiceCallback());
|
||||
} catch (RemoteException e) {
|
||||
throw new RuntimeException(e);
|
||||
Log.e(LOG_TAG, "Error while initiating device discovery", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user