From: Matthew Xie Date: Tue, 2 Oct 2012 01:20:37 +0000 (-0700) Subject: Move socket initialization code out of pbap service's main thread X-Git-Tag: android-7.1.2_r17~1026^2~18 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=6458cffaca286611e898c75ad86e2d98c89008b6;p=android-x86%2Fpackages-apps-Bluetooth.git Move socket initialization code out of pbap service's main thread 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 --- diff --git a/src/com/android/bluetooth/btservice/RemoteDevices.java b/src/com/android/bluetooth/btservice/RemoteDevices.java index 08ba36b8..48b740c9 100755 --- a/src/com/android/bluetooth/btservice/RemoteDevices.java +++ b/src/com/android/bluetooth/btservice/RemoteDevices.java @@ -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) { diff --git a/src/com/android/bluetooth/pbap/BluetoothPbapService.java b/src/com/android/bluetooth/pbap/BluetoothPbapService.java index dde971fe..53810aac 100755 --- a/src/com/android/bluetooth/pbap/BluetoothPbapService.java +++ b/src/com/android/bluetooth/pbap/BluetoothPbapService.java @@ -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...");