am 5eadab02: am 4492b2c6: Fix OPP crash and Call Log sort order.

Merge commit '5eadab02ea3202f417434a13a7637379fffc43de'

* commit '5eadab02ea3202f417434a13a7637379fffc43de':
  Fix OPP crash and Call Log sort order.
diff --git a/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java b/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java
index 278d29e..cb292c1 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java
@@ -286,14 +286,14 @@
         if (V) Log.v(TAG, "mLocalShareInfoId = " + mLocalShareInfoId);
 
         if (V) Log.v(TAG, "acquire partial WakeLock");
-        if (mWakeLock.isHeld()) {
-            mPartialWakeLock.acquire();
-            mWakeLock.release();
-        }
 
-        mServerBlocking = true;
 
         synchronized (this) {
+            if (mWakeLock.isHeld()) {
+                mPartialWakeLock.acquire();
+                mWakeLock.release();
+            }
+            mServerBlocking = true;
             try {
 
                 while (mServerBlocking) {
@@ -538,15 +538,20 @@
         resp.responseCode = ResponseCodes.OBEX_HTTP_OK;
     }
 
-    @Override
-    public void onClose() {
-        if (V) Log.v(TAG, "release WakeLock");
+    private synchronized void releaseWakeLocks() {
         if (mWakeLock.isHeld()) {
             mWakeLock.release();
         }
         if (mPartialWakeLock.isHeld()) {
             mPartialWakeLock.release();
         }
+    }
+
+    @Override
+    public void onClose() {
+        if (V) Log.v(TAG, "release WakeLock");
+        releaseWakeLocks();
+
         /* onClose could happen even before start() where mCallback is set */
         if (mCallback != null) {
             Message msg = Message.obtain(mCallback);
diff --git a/src/com/android/bluetooth/pbap/BluetoothPbapVcardManager.java b/src/com/android/bluetooth/pbap/BluetoothPbapVcardManager.java
index 5135bc0..831dac4 100644
--- a/src/com/android/bluetooth/pbap/BluetoothPbapVcardManager.java
+++ b/src/com/android/bluetooth/pbap/BluetoothPbapVcardManager.java
@@ -444,7 +444,7 @@
 
                 composer = new VCardComposer(mContext, vcardType, true);
                 composer.addHandler(new HandlerForStringBuffer(op, ownerVCard));
-                if (!composer.init(Contacts.CONTENT_URI, selection, null, null)) {
+                if (!composer.init(Contacts.CONTENT_URI, selection, null, Contacts._ID)) {
                     return ResponseCodes.OBEX_HTTP_INTERNAL_ERROR;
                 }
 
@@ -470,7 +470,8 @@
             try {
                 composer = new BluetoothPbapCallLogComposer(mContext, true);
                 composer.addHandler(new HandlerForStringBuffer(op, ownerVCard));
-                if (!composer.init(CallLog.Calls.CONTENT_URI, selection, null, null)) {
+                if (!composer.init(CallLog.Calls.CONTENT_URI, selection, null,
+                                   CALLLOG_SORT_ORDER)) {
                     return ResponseCodes.OBEX_HTTP_INTERNAL_ERROR;
                 }