OSDN Git Service

Move socket initialization code out of pbap service's main thread
authorMatthew Xie <mattx@google.com>
Tue, 2 Oct 2012 01:20:37 +0000 (18:20 -0700)
committerMatthew Xie <mattx@google.com>
Tue, 2 Oct 2012 21:44:41 +0000 (14:44 -0700)
Socket initialization need the preparation from stack and a domain socket
connection. All this takes time and not proper to be run in the main thread.
bug 7258324

Change-Id: Ic46601602556c2949f18d446016188d874099874

src/com/android/bluetooth/btservice/RemoteDevices.java
src/com/android/bluetooth/pbap/BluetoothPbapService.java

index 08ba36b..48b740c 100755 (executable)
@@ -437,7 +437,7 @@ final class RemoteDevices {
     }
 
     private void debugLog(String msg) {
-        if (DBG) Log.e(TAG, msg);
+        if (DBG) Log.d(TAG, msg);
     }
 
     private void infoLog(String msg) {
index dde971f..53810aa 100755 (executable)
@@ -316,12 +316,6 @@ public class BluetoothPbapService extends Service {
     private void startRfcommSocketListener() {
         if (VERBOSE) Log.v(TAG, "Pbap Service startRfcommSocketListener");
 
-        if (mServerSocket == null) {
-            if (!initSocket()) {
-                closeService();
-                return;
-            }
-        }
         if (mAcceptThread == null) {
             mAcceptThread = new SocketAcceptThread();
             mAcceptThread.setName("BluetoothPbapAcceptThread");
@@ -340,7 +334,8 @@ public class BluetoothPbapService extends Service {
             try {
                 // It is mandatory for PSE to support initiation of bonding and
                 // encryption.
-                mServerSocket = mAdapter.listenUsingEncryptedRfcommWithServiceRecord("OBEX Phonebook Access Server", BluetoothUuid.PBAP_PSE.getUuid());
+                mServerSocket = mAdapter.listenUsingEncryptedRfcommWithServiceRecord
+                    ("OBEX Phonebook Access Server", BluetoothUuid.PBAP_PSE.getUuid());
 
             } catch (IOException e) {
                 Log.e(TAG, "Error create RfcommServerSocket " + e.toString());
@@ -521,6 +516,13 @@ public class BluetoothPbapService extends Service {
 
         @Override
         public void run() {
+            if (mServerSocket == null) {
+                if (!initSocket()) {
+                    closeService();
+                    return;
+                }
+            }
+
             while (!stopped) {
                 try {
                     if (VERBOSE) Log.v(TAG, "Accepting socket connection...");