Add error handle for device that not support Bluetooth

- Add LocalBluetoothManager null check for device that
  not support Bluetooth
- Add test to verify when LocalBluetoothManager is null
  will not crash

Bug: 110712414
Test: make -j42 RunSettingsRoboTests
Change-Id: Ib506a0206cfcfdfec60bdfcf9a1944338a7ab729
This commit is contained in:
hughchen
2018-06-25 11:06:45 +08:00
parent a5f68f9c3c
commit 34066fa21a
6 changed files with 81 additions and 3 deletions

View File

@@ -19,6 +19,7 @@ import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.os.Bundle;
import android.os.SystemProperties;
import android.util.Log;
import com.android.settings.R;
import com.android.settings.connecteddevice.DevicePreferenceCallback;
@@ -52,11 +53,12 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback,
private static final String BLUETOOTH_SHOW_DEVICES_WITHOUT_NAMES_PROPERTY =
"persist.bluetooth.showdeviceswithoutnames";
protected final LocalBluetoothManager mLocalManager;
protected final DevicePreferenceCallback mDevicePreferenceCallback;
protected final Map<BluetoothDevice, Preference> mPreferenceMap;
protected Context mPrefContext;
protected DashboardFragment mFragment;
@VisibleForTesting
protected LocalBluetoothManager mLocalManager;
private final boolean mShowDeviceWithoutNames;
@@ -85,6 +87,10 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback,
* Register the bluetooth event callback and update the list
*/
public void registerCallback() {
if (mLocalManager == null) {
Log.e(TAG, "registerCallback() Bluetooth is not supported on this device");
return;
}
mLocalManager.setForegroundActivity(mFragment.getContext());
mLocalManager.getEventManager().registerCallback(this);
mLocalManager.getProfileManager().addServiceListener(this);
@@ -95,6 +101,10 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback,
* Unregister the bluetooth event callback
*/
public void unregisterCallback() {
if (mLocalManager == null) {
Log.e(TAG, "unregisterCallback() Bluetooth is not supported on this device");
return;
}
mLocalManager.setForegroundActivity(null);
mLocalManager.getEventManager().unregisterCallback(this);
mLocalManager.getProfileManager().removeServiceListener(this);