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

Commit 331c1044 authored by Cuong's avatar Cuong Committed by Gerrit Code Review
Browse files

* Only do a cancel discovery if the device is discovering.

* explicitly close input and outputstream. This could prevent objects from being cleaned up before
  the next connect attempt.

Change-Id: I43edf58baccf56046abf79202739af31558ac098
parent e91a2373
Loading
Loading
Loading
Loading
+21 −1
Original line number Diff line number Diff line
@@ -267,7 +267,8 @@ public class BTGPSService {
            }
            mmSocket = tmp;
            // Make a connection to the BluetoothSocket
            if (mAdapter.isEnabled()) mAdapter.cancelDiscovery();
            if (mAdapter.isEnabled() && mAdapter.isDiscovering()) 
                mAdapter.cancelDiscovery();
            try {
                // This is a blocking call and will only return on a
                // successful connection or an exception
@@ -389,12 +390,31 @@ public class BTGPSService {
        }

        public void cancel() {
            try {
                if (mmInStream != null) {
                    mmInStream.close();
                    mmInStream = null;
                }
            } catch (Exception e) {
                Log.i(TAG, "Failed to close inputstream", e);
            }

            try {
                if (mmOutStream != null) {
                    mmOutStream.close();
                    mmOutStream = null;
                }
            } catch (Exception e) {
                Log.i(TAG, "Failed to close outputstream", e);
            }

            try {
                if (mmSocket == null) {
                    Log.e(TAG, "Input stream null. Aborting Cacnel");
                    return;
                }
                mmSocket.close();
                mmSocket = null;
            } catch (IOException e) {
                Log.e(TAG, "close() of connect socket failed", e);
            } finally {