[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:
Eugene Susla
2017-06-28 10:58:46 -07:00
parent f36a995424
commit 7a090a11ed
2 changed files with 4 additions and 4 deletions

View File

@@ -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;

View File

@@ -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);
}
}