Loading android/app/src/com/android/bluetooth/pbap/BluetoothPbapCallLogComposer.java +4 −59 Original line number Diff line number Diff line Loading @@ -32,11 +32,8 @@ import com.android.vcard.VCardBuilder; import com.android.vcard.VCardConfig; import com.android.vcard.VCardConstants; import com.android.vcard.VCardUtils; import com.android.vcard.VCardComposer.OneEntryHandler; import java.util.ArrayList; import java.util.Arrays; import java.util.List; /** * VCard composer especially for Call Log used in Bluetooth. Loading Loading @@ -82,18 +79,14 @@ public class BluetoothPbapCallLogComposer { private final Context mContext; private ContentResolver mContentResolver; private Cursor mCursor; private final boolean mCareHandlerErrors; private boolean mTerminateIsCalled; private final List<OneEntryHandler> mHandlerList; private String mErrorReason = NO_ERROR; public BluetoothPbapCallLogComposer(final Context context, boolean careHandlerErrors) { public BluetoothPbapCallLogComposer(final Context context) { mContext = context; mContentResolver = context.getContentResolver(); mCareHandlerErrors = careHandlerErrors; mHandlerList = new ArrayList<OneEntryHandler>(); } public boolean init(final Uri contentUri, final String selection, Loading @@ -114,24 +107,6 @@ public class BluetoothPbapCallLogComposer { return false; } if (mCareHandlerErrors) { List<OneEntryHandler> finishedList = new ArrayList<OneEntryHandler>( mHandlerList.size()); for (OneEntryHandler handler : mHandlerList) { if (!handler.onInit(mContext)) { for (OneEntryHandler finished : finishedList) { finished.onTerminate(); } return false; } } } else { // Just ignore the false returned from onInit(). for (OneEntryHandler handler : mHandlerList) { handler.onInit(mContext); } } if (mCursor.getCount() == 0 || !mCursor.moveToFirst()) { try { mCursor.close(); Loading @@ -147,42 +122,16 @@ public class BluetoothPbapCallLogComposer { return true; } public void addHandler(OneEntryHandler handler) { if (handler != null) { mHandlerList.add(handler); } } public boolean createOneEntry() { public String createOneEntry() { if (mCursor == null || mCursor.isAfterLast()) { mErrorReason = FAILURE_REASON_NOT_INITIALIZED; return false; return null; } final String vcard; try { vcard = createOneCallLogEntryInternal(); } catch (OutOfMemoryError error) { Log.e(TAG, "OutOfMemoryError occured. Ignore the entry"); System.gc(); return true; return createOneCallLogEntryInternal(); } finally { mCursor.moveToNext(); } if (mCareHandlerErrors) { for (OneEntryHandler handler : mHandlerList) { if (!handler.onEntryCreated(vcard)) { return false; } } } else { for (OneEntryHandler handler : mHandlerList) { handler.onEntryCreated(vcard); } } return true; } private String createOneCallLogEntryInternal() { Loading Loading @@ -290,10 +239,6 @@ public class BluetoothPbapCallLogComposer { } public void terminate() { for (OneEntryHandler handler : mHandlerList) { handler.onTerminate(); } if (mCursor != null) { try { mCursor.close(); Loading android/app/src/com/android/bluetooth/pbap/BluetoothPbapVcardManager.java +27 −10 Original line number Diff line number Diff line Loading @@ -49,7 +49,6 @@ import android.util.Log; import com.android.bluetooth.R; import com.android.vcard.VCardComposer; import com.android.vcard.VCardConfig; import com.android.vcard.VCardComposer.OneEntryHandler; import java.io.IOException; import java.io.OutputStream; Loading Loading @@ -105,7 +104,7 @@ public class BluetoothPbapVcardManager { } public final String getOwnerPhoneNumberVcard(final boolean vcardType21) { BluetoothPbapCallLogComposer composer = new BluetoothPbapCallLogComposer(mContext, false); BluetoothPbapCallLogComposer composer = new BluetoothPbapCallLogComposer(mContext); String name = BluetoothPbapService.getLocalPhoneName(); String number = BluetoothPbapService.getLocalPhoneNum(); String vcard = composer.composeVCardForPhoneOwnNumber(Phone.TYPE_MOBILE, name, number, Loading Loading @@ -429,6 +428,7 @@ public class BluetoothPbapVcardManager { if (isContacts) { VCardComposer composer = null; HandlerForStringBuffer buffer = null; try { // Currently only support Generic Vcard 2.1 and 3.0 int vcardType; Loading @@ -441,8 +441,9 @@ public class BluetoothPbapVcardManager { vcardType |= VCardConfig.FLAG_REFRAIN_PHONE_NUMBER_FORMATTING; composer = new VCardComposer(mContext, vcardType, true); composer.addHandler(new HandlerForStringBuffer(op, ownerVCard)); if (!composer.init(Contacts.CONTENT_URI, selection, null, Contacts._ID)) { buffer = new HandlerForStringBuffer(op, ownerVCard); if (!composer.init(Contacts.CONTENT_URI, selection, null, Contacts._ID) || !buffer.onInit(mContext)) { return ResponseCodes.OBEX_HTTP_INTERNAL_ERROR; } Loading @@ -452,24 +453,35 @@ public class BluetoothPbapVcardManager { BluetoothPbapObexServer.sIsAborted = false; break; } if (!composer.createOneEntryLegacy()) { String vcard = composer.createOneEntry(); if (vcard == null) { Log.e(TAG, "Failed to read a contact. Error reason: " + composer.getErrorReason()); return ResponseCodes.OBEX_HTTP_INTERNAL_ERROR; } if (!buffer.onEntryCreated(vcard)) { // onEntryCreate() already emits error. return ResponseCodes.OBEX_HTTP_INTERNAL_ERROR; } } } finally { if (composer != null) { composer.terminate(); } if (buffer != null) { buffer.onTerminate(); } } } else { // CallLog BluetoothPbapCallLogComposer composer = null; HandlerForStringBuffer buffer = null; try { composer = new BluetoothPbapCallLogComposer(mContext, true); composer.addHandler(new HandlerForStringBuffer(op, ownerVCard)); composer = new BluetoothPbapCallLogComposer(mContext); buffer = new HandlerForStringBuffer(op, ownerVCard); if (!composer.init(CallLog.Calls.CONTENT_URI, selection, null, CALLLOG_SORT_ORDER)) { CALLLOG_SORT_ORDER) || !buffer.onInit(mContext)) { return ResponseCodes.OBEX_HTTP_INTERNAL_ERROR; } Loading @@ -479,16 +491,21 @@ public class BluetoothPbapVcardManager { BluetoothPbapObexServer.sIsAborted = false; break; } if (!composer.createOneEntry()) { String vcard = composer.createOneEntry(); if (vcard == null) { Log.e(TAG, "Failed to read a contact. Error reason: " + composer.getErrorReason()); return ResponseCodes.OBEX_HTTP_INTERNAL_ERROR; } buffer.onEntryCreated(vcard); } } finally { if (composer != null) { composer.terminate(); } if (buffer != null) { buffer.onTerminate(); } } } Loading @@ -501,7 +518,7 @@ public class BluetoothPbapVcardManager { /** * Handler to emit VCard String to PCE once size grow to maxPacketSize. */ public class HandlerForStringBuffer implements OneEntryHandler { public class HandlerForStringBuffer { private Operation operation; private OutputStream outputStream; Loading Loading
android/app/src/com/android/bluetooth/pbap/BluetoothPbapCallLogComposer.java +4 −59 Original line number Diff line number Diff line Loading @@ -32,11 +32,8 @@ import com.android.vcard.VCardBuilder; import com.android.vcard.VCardConfig; import com.android.vcard.VCardConstants; import com.android.vcard.VCardUtils; import com.android.vcard.VCardComposer.OneEntryHandler; import java.util.ArrayList; import java.util.Arrays; import java.util.List; /** * VCard composer especially for Call Log used in Bluetooth. Loading Loading @@ -82,18 +79,14 @@ public class BluetoothPbapCallLogComposer { private final Context mContext; private ContentResolver mContentResolver; private Cursor mCursor; private final boolean mCareHandlerErrors; private boolean mTerminateIsCalled; private final List<OneEntryHandler> mHandlerList; private String mErrorReason = NO_ERROR; public BluetoothPbapCallLogComposer(final Context context, boolean careHandlerErrors) { public BluetoothPbapCallLogComposer(final Context context) { mContext = context; mContentResolver = context.getContentResolver(); mCareHandlerErrors = careHandlerErrors; mHandlerList = new ArrayList<OneEntryHandler>(); } public boolean init(final Uri contentUri, final String selection, Loading @@ -114,24 +107,6 @@ public class BluetoothPbapCallLogComposer { return false; } if (mCareHandlerErrors) { List<OneEntryHandler> finishedList = new ArrayList<OneEntryHandler>( mHandlerList.size()); for (OneEntryHandler handler : mHandlerList) { if (!handler.onInit(mContext)) { for (OneEntryHandler finished : finishedList) { finished.onTerminate(); } return false; } } } else { // Just ignore the false returned from onInit(). for (OneEntryHandler handler : mHandlerList) { handler.onInit(mContext); } } if (mCursor.getCount() == 0 || !mCursor.moveToFirst()) { try { mCursor.close(); Loading @@ -147,42 +122,16 @@ public class BluetoothPbapCallLogComposer { return true; } public void addHandler(OneEntryHandler handler) { if (handler != null) { mHandlerList.add(handler); } } public boolean createOneEntry() { public String createOneEntry() { if (mCursor == null || mCursor.isAfterLast()) { mErrorReason = FAILURE_REASON_NOT_INITIALIZED; return false; return null; } final String vcard; try { vcard = createOneCallLogEntryInternal(); } catch (OutOfMemoryError error) { Log.e(TAG, "OutOfMemoryError occured. Ignore the entry"); System.gc(); return true; return createOneCallLogEntryInternal(); } finally { mCursor.moveToNext(); } if (mCareHandlerErrors) { for (OneEntryHandler handler : mHandlerList) { if (!handler.onEntryCreated(vcard)) { return false; } } } else { for (OneEntryHandler handler : mHandlerList) { handler.onEntryCreated(vcard); } } return true; } private String createOneCallLogEntryInternal() { Loading Loading @@ -290,10 +239,6 @@ public class BluetoothPbapCallLogComposer { } public void terminate() { for (OneEntryHandler handler : mHandlerList) { handler.onTerminate(); } if (mCursor != null) { try { mCursor.close(); Loading
android/app/src/com/android/bluetooth/pbap/BluetoothPbapVcardManager.java +27 −10 Original line number Diff line number Diff line Loading @@ -49,7 +49,6 @@ import android.util.Log; import com.android.bluetooth.R; import com.android.vcard.VCardComposer; import com.android.vcard.VCardConfig; import com.android.vcard.VCardComposer.OneEntryHandler; import java.io.IOException; import java.io.OutputStream; Loading Loading @@ -105,7 +104,7 @@ public class BluetoothPbapVcardManager { } public final String getOwnerPhoneNumberVcard(final boolean vcardType21) { BluetoothPbapCallLogComposer composer = new BluetoothPbapCallLogComposer(mContext, false); BluetoothPbapCallLogComposer composer = new BluetoothPbapCallLogComposer(mContext); String name = BluetoothPbapService.getLocalPhoneName(); String number = BluetoothPbapService.getLocalPhoneNum(); String vcard = composer.composeVCardForPhoneOwnNumber(Phone.TYPE_MOBILE, name, number, Loading Loading @@ -429,6 +428,7 @@ public class BluetoothPbapVcardManager { if (isContacts) { VCardComposer composer = null; HandlerForStringBuffer buffer = null; try { // Currently only support Generic Vcard 2.1 and 3.0 int vcardType; Loading @@ -441,8 +441,9 @@ public class BluetoothPbapVcardManager { vcardType |= VCardConfig.FLAG_REFRAIN_PHONE_NUMBER_FORMATTING; composer = new VCardComposer(mContext, vcardType, true); composer.addHandler(new HandlerForStringBuffer(op, ownerVCard)); if (!composer.init(Contacts.CONTENT_URI, selection, null, Contacts._ID)) { buffer = new HandlerForStringBuffer(op, ownerVCard); if (!composer.init(Contacts.CONTENT_URI, selection, null, Contacts._ID) || !buffer.onInit(mContext)) { return ResponseCodes.OBEX_HTTP_INTERNAL_ERROR; } Loading @@ -452,24 +453,35 @@ public class BluetoothPbapVcardManager { BluetoothPbapObexServer.sIsAborted = false; break; } if (!composer.createOneEntryLegacy()) { String vcard = composer.createOneEntry(); if (vcard == null) { Log.e(TAG, "Failed to read a contact. Error reason: " + composer.getErrorReason()); return ResponseCodes.OBEX_HTTP_INTERNAL_ERROR; } if (!buffer.onEntryCreated(vcard)) { // onEntryCreate() already emits error. return ResponseCodes.OBEX_HTTP_INTERNAL_ERROR; } } } finally { if (composer != null) { composer.terminate(); } if (buffer != null) { buffer.onTerminate(); } } } else { // CallLog BluetoothPbapCallLogComposer composer = null; HandlerForStringBuffer buffer = null; try { composer = new BluetoothPbapCallLogComposer(mContext, true); composer.addHandler(new HandlerForStringBuffer(op, ownerVCard)); composer = new BluetoothPbapCallLogComposer(mContext); buffer = new HandlerForStringBuffer(op, ownerVCard); if (!composer.init(CallLog.Calls.CONTENT_URI, selection, null, CALLLOG_SORT_ORDER)) { CALLLOG_SORT_ORDER) || !buffer.onInit(mContext)) { return ResponseCodes.OBEX_HTTP_INTERNAL_ERROR; } Loading @@ -479,16 +491,21 @@ public class BluetoothPbapVcardManager { BluetoothPbapObexServer.sIsAborted = false; break; } if (!composer.createOneEntry()) { String vcard = composer.createOneEntry(); if (vcard == null) { Log.e(TAG, "Failed to read a contact. Error reason: " + composer.getErrorReason()); return ResponseCodes.OBEX_HTTP_INTERNAL_ERROR; } buffer.onEntryCreated(vcard); } } finally { if (composer != null) { composer.terminate(); } if (buffer != null) { buffer.onTerminate(); } } } Loading @@ -501,7 +518,7 @@ public class BluetoothPbapVcardManager { /** * Handler to emit VCard String to PCE once size grow to maxPacketSize. */ public class HandlerForStringBuffer implements OneEntryHandler { public class HandlerForStringBuffer { private Operation operation; private OutputStream outputStream; Loading