| Index: device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothDevice.java
|
| diff --git a/device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothDevice.java b/device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothDevice.java
|
| index 925d78fb68327b700048104cbb50c73474b35068..fc76c3220ad0f89226b4a4357c0aee012d654821 100644
|
| --- a/device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothDevice.java
|
| +++ b/device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothDevice.java
|
| @@ -27,7 +27,7 @@ import java.util.List;
|
| final class ChromeBluetoothDevice {
|
| private static final String TAG = "Bluetooth";
|
|
|
| - private final long mNativeBluetoothDeviceAndroid;
|
| + private long mNativeBluetoothDeviceAndroid;
|
| final Wrappers.BluetoothDeviceWrapper mDevice;
|
| private List<ParcelUuid> mUuidsFromScan;
|
| Wrappers.BluetoothGattWrapper mBluetoothGatt;
|
| @@ -41,6 +41,15 @@ final class ChromeBluetoothDevice {
|
| Log.v(TAG, "ChromeBluetoothDevice created.");
|
| }
|
|
|
| + /**
|
| + * Handles C++ object being destroyed.
|
| + */
|
| + @CalledByNative
|
| + private void onBluetoothDeviceAndroidDestruction() {
|
| + disconnectGatt();
|
| + mNativeBluetoothDeviceAndroid = 0;
|
| + }
|
| +
|
| // ---------------------------------------------------------------------------------------------
|
| // BluetoothDeviceAndroid methods implemented in java:
|
|
|
| @@ -112,7 +121,7 @@ final class ChromeBluetoothDevice {
|
| @CalledByNative
|
| private void disconnectGatt() {
|
| Log.i(TAG, "BluetoothGatt.disconnect");
|
| - mBluetoothGatt.disconnect();
|
| + if (mBluetoothGatt != null) mBluetoothGatt.disconnect();
|
| }
|
|
|
| // Implements BluetoothDeviceAndroid::GetDeviceName.
|
| @@ -129,8 +138,10 @@ final class ChromeBluetoothDevice {
|
| (newState == android.bluetooth.BluetoothProfile.STATE_CONNECTED)
|
| ? "Connected"
|
| : "Disconnected");
|
| - nativeOnConnectionStateChange(mNativeBluetoothDeviceAndroid, status,
|
| - newState == android.bluetooth.BluetoothProfile.STATE_CONNECTED);
|
| + if (mNativeBluetoothDeviceAndroid != 0) {
|
| + nativeOnConnectionStateChange(mNativeBluetoothDeviceAndroid, status,
|
| + newState == android.bluetooth.BluetoothProfile.STATE_CONNECTED);
|
| + }
|
| }
|
| }
|
|
|
|
|