Merge "FTP: Handle null pointer exception for socket accept thread synchronize."
diff --git a/src/org/codeaurora/bluetooth/ftp/BluetoothFtpService.java b/src/org/codeaurora/bluetooth/ftp/BluetoothFtpService.java
index 45c5440..5a55476 100644
--- a/src/org/codeaurora/bluetooth/ftp/BluetoothFtpService.java
+++ b/src/org/codeaurora/bluetooth/ftp/BluetoothFtpService.java
@@ -451,13 +451,8 @@
private final void closeService() {
if (VERBOSE) Log.v(TAG, "Ftp Service closeService");
- if (mServerSession != null) {
- mServerSession.close();
- mServerSession = null;
- }
-
try {
- closeRfcommSocket(true, true);
+ closeRfcommSocket(true, false);
} catch (IOException ex) {
Log.e(TAG, "CloseSocket error: " + ex);
}
@@ -472,6 +467,17 @@
}
}
+ try {
+ closeRfcommSocket(false, true);
+ } catch (IOException ex) {
+ Log.e(TAG, "CloseSocket error: " + ex);
+ }
+
+ if (mServerSession != null) {
+ mServerSession.close();
+ mServerSession = null;
+ }
+
mHasStarted = false;
if (stopSelfResult(mStartId)) {
if (VERBOSE) Log.v(TAG, "successfully stopped ftp service");
@@ -589,8 +595,14 @@
try {
Log.v(RTAG,"Run Accept thread");
mConnSocket = mRfcommServerSocket.accept();
- isL2capSocket = false;
- mRemoteDevice = mConnSocket.getRemoteDevice();
+ synchronized(BluetoothFtpService.this) {
+ if(mConnSocket == null){
+ Log.i(RTAG, "mConnSocket = null");
+ break;
+ }
+ isL2capSocket = false;
+ mRemoteDevice = mConnSocket.getRemoteDevice();
+ }
if (mRemoteDevice == null) {
Log.i(RTAG, "getRemoteDevice() = null");
break;