Loading src/com/android/bluetooth/map/BluetoothMasService.java +39 −40 Original line number Diff line number Diff line Loading @@ -560,7 +560,7 @@ public class BluetoothMasService extends Service { for (BluetoothMasObexConnection connection : mConnections) { // Stop the possible trying to init serverSocket connection.mInterrupted = true; connection.closeConnection(); connection.closeConnection(true); } } Loading Loading @@ -645,12 +645,6 @@ public class BluetoothMasService extends Service { if (VERBOSE) Log.v(TAG, "Map Service startRfcommSocketListener"); if (mServerSocket == null) { if (!initSocket()) { closeService(); return; } } if (mAcceptThread == null) { mAcceptThread = new SocketAcceptThread(mnsClient, mMasId); mAcceptThread.setName("BluetoothMapAcceptThread " + mPortNum); Loading Loading @@ -701,14 +695,24 @@ public class BluetoothMasService extends Service { return initSocketOK; } private final void closeSocket() throws IOException { if (mConnSocket != null) { private final void closeSocket(boolean server, boolean accept) throws IOException { if (server) { // Stop the possible trying to init serverSocket mInterrupted = true; if (mServerSocket != null) { mServerSocket.close(); mServerSocket = null; } } if (accept && mConnSocket != null) { mConnSocket.close(); mConnSocket = null; } } public void closeConnection() { public void closeConnection(boolean closeServer) { if (VERBOSE) Log.v(TAG, "Mas connection closing"); // Release the wake lock if obex transaction is over Loading @@ -716,16 +720,27 @@ public class BluetoothMasService extends Service { if (mWakeLock.isHeld()) { if (VERBOSE) Log.v(TAG,"Release full wake lock"); mWakeLock.release(); } mWakeLock = null; } else { mWakeLock = null; } if (mServerSession != null) { mServerSession.close(); mServerSession = null; } try { closeSocket(closeServer, true); } catch (IOException ex) { Log.e(TAG, "CloseSocket error: " + ex); } if (mAcceptThread != null) { try { if (closeServer) { mAcceptThread.shutdown(); mAcceptThread.join(); } } catch (InterruptedException ex) { Log.w(TAG, "mAcceptThread close error" + ex); } finally { Loading @@ -733,16 +748,6 @@ public class BluetoothMasService extends Service { } } if (mServerSession != null) { mServerSession.close(); mServerSession = null; } try { closeSocket(); } catch (IOException ex) { Log.e(TAG, "CloseSocket error: " + ex); } if (VERBOSE) Log.v(TAG, "Mas connection closed"); } Loading Loading @@ -795,7 +800,7 @@ public class BluetoothMasService extends Service { private void stopObexServerSession() { if (VERBOSE) Log.v(TAG, "Map Service stopObexServerSession "); closeConnection(); closeConnection(false); // Last obex transaction is finished, we start to listen for incoming // connection again Loading @@ -822,11 +827,15 @@ public class BluetoothMasService extends Service { @Override public void run() { while (!stopped) { try { if (mServerSocket == null) { break; if (!initSocket()) { closeService(); return; } } while (!stopped) { try { BluetoothSocket connSocket = mServerSocket.accept(); BluetoothDevice device = connSocket.getRemoteDevice(); Loading Loading @@ -875,9 +884,7 @@ public class BluetoothMasService extends Service { } stopped = true; // job done ,close this thread; } catch (IOException ex) { if (stopped) { break; } stopped = true; if (VERBOSE) Log.v(TAG, "Accept exception: " + ex.toString()); } Loading @@ -888,14 +895,6 @@ public class BluetoothMasService extends Service { if (VERBOSE) Log.v(TAG, "AcceptThread shutdown for MAS id: " + mMasId); stopped = true; interrupt(); if (mServerSocket != null) { try { mServerSocket.close(); mServerSocket = null; } catch (IOException e) { Log.e(TAG, "Failed to close socket", e); } } } } } Loading Loading
src/com/android/bluetooth/map/BluetoothMasService.java +39 −40 Original line number Diff line number Diff line Loading @@ -560,7 +560,7 @@ public class BluetoothMasService extends Service { for (BluetoothMasObexConnection connection : mConnections) { // Stop the possible trying to init serverSocket connection.mInterrupted = true; connection.closeConnection(); connection.closeConnection(true); } } Loading Loading @@ -645,12 +645,6 @@ public class BluetoothMasService extends Service { if (VERBOSE) Log.v(TAG, "Map Service startRfcommSocketListener"); if (mServerSocket == null) { if (!initSocket()) { closeService(); return; } } if (mAcceptThread == null) { mAcceptThread = new SocketAcceptThread(mnsClient, mMasId); mAcceptThread.setName("BluetoothMapAcceptThread " + mPortNum); Loading Loading @@ -701,14 +695,24 @@ public class BluetoothMasService extends Service { return initSocketOK; } private final void closeSocket() throws IOException { if (mConnSocket != null) { private final void closeSocket(boolean server, boolean accept) throws IOException { if (server) { // Stop the possible trying to init serverSocket mInterrupted = true; if (mServerSocket != null) { mServerSocket.close(); mServerSocket = null; } } if (accept && mConnSocket != null) { mConnSocket.close(); mConnSocket = null; } } public void closeConnection() { public void closeConnection(boolean closeServer) { if (VERBOSE) Log.v(TAG, "Mas connection closing"); // Release the wake lock if obex transaction is over Loading @@ -716,16 +720,27 @@ public class BluetoothMasService extends Service { if (mWakeLock.isHeld()) { if (VERBOSE) Log.v(TAG,"Release full wake lock"); mWakeLock.release(); } mWakeLock = null; } else { mWakeLock = null; } if (mServerSession != null) { mServerSession.close(); mServerSession = null; } try { closeSocket(closeServer, true); } catch (IOException ex) { Log.e(TAG, "CloseSocket error: " + ex); } if (mAcceptThread != null) { try { if (closeServer) { mAcceptThread.shutdown(); mAcceptThread.join(); } } catch (InterruptedException ex) { Log.w(TAG, "mAcceptThread close error" + ex); } finally { Loading @@ -733,16 +748,6 @@ public class BluetoothMasService extends Service { } } if (mServerSession != null) { mServerSession.close(); mServerSession = null; } try { closeSocket(); } catch (IOException ex) { Log.e(TAG, "CloseSocket error: " + ex); } if (VERBOSE) Log.v(TAG, "Mas connection closed"); } Loading Loading @@ -795,7 +800,7 @@ public class BluetoothMasService extends Service { private void stopObexServerSession() { if (VERBOSE) Log.v(TAG, "Map Service stopObexServerSession "); closeConnection(); closeConnection(false); // Last obex transaction is finished, we start to listen for incoming // connection again Loading @@ -822,11 +827,15 @@ public class BluetoothMasService extends Service { @Override public void run() { while (!stopped) { try { if (mServerSocket == null) { break; if (!initSocket()) { closeService(); return; } } while (!stopped) { try { BluetoothSocket connSocket = mServerSocket.accept(); BluetoothDevice device = connSocket.getRemoteDevice(); Loading Loading @@ -875,9 +884,7 @@ public class BluetoothMasService extends Service { } stopped = true; // job done ,close this thread; } catch (IOException ex) { if (stopped) { break; } stopped = true; if (VERBOSE) Log.v(TAG, "Accept exception: " + ex.toString()); } Loading @@ -888,14 +895,6 @@ public class BluetoothMasService extends Service { if (VERBOSE) Log.v(TAG, "AcceptThread shutdown for MAS id: " + mMasId); stopped = true; interrupt(); if (mServerSocket != null) { try { mServerSocket.close(); mServerSocket = null; } catch (IOException e) { Log.e(TAG, "Failed to close socket", e); } } } } } Loading