diff options
author | Sanket Agarwal <sanketa@google.com> | 2016-02-02 16:02:33 -0800 |
---|---|---|
committer | Sanket Agarwal <sanketa@google.com> | 2016-02-04 17:10:13 -0800 |
commit | 80232af158166fbf46e0b4fd529cfd298fd8b759 (patch) | |
tree | a8b70828d0e1553a416883cf365bec5c4d0d8010 | |
parent | c7a36097b73a0df89b22df1ad93f790a7c9d40d7 (diff) | |
download | bluetooth-80232af158166fbf46e0b4fd529cfd298fd8b759.tar.gz |
PBAP takes Account so that VCardList can add them to operation list.android-n-preview-2android-n-preview-1
Since VCardList can create the commits for the accounts database, we
need to add Account information to the parser. This avoids having to do
this in client code.
Bug: b/26862739
Change-Id: I7690489c4e133c09dd4da6c8e3736ea71bb23a4b
4 files changed, 39 insertions, 12 deletions
diff --git a/src/android/bluetooth/client/pbap/BluetoothPbapClient.java b/src/android/bluetooth/client/pbap/BluetoothPbapClient.java index 5e212e8..b1fc441 100644 --- a/src/android/bluetooth/client/pbap/BluetoothPbapClient.java +++ b/src/android/bluetooth/client/pbap/BluetoothPbapClient.java @@ -16,6 +16,7 @@ package android.bluetooth.client.pbap; +import android.accounts.Account; import android.bluetooth.BluetoothDevice; import android.os.Handler; import android.os.Message; @@ -72,6 +73,8 @@ import java.lang.ref.WeakReference; * connection and disconnection happens automatically internally. */ public class BluetoothPbapClient { + private static final boolean DBG = true; + private static final String TAG = "BluetoothPbapClient"; /** @@ -372,6 +375,7 @@ public class BluetoothPbapClient { DISCONNECTED, CONNECTING, CONNECTED, DISCONNECTING; } + private final Account mAccount; private final Handler mClientHandler; private final BluetoothPbapSession mSession; private ConnectionState mConnectionState = ConnectionState.DISCONNECTED; @@ -503,15 +507,21 @@ public class BluetoothPbapClient { * * @param device BluetoothDevice that corresponds to remote acting in PSE * role + * @param account the account to which contacts will be added {@see #pullPhoneBook}. * @param handler the handle that will be used by PCE to notify events and * results to application * @throws NullPointerException */ - public BluetoothPbapClient(BluetoothDevice device, Handler handler) { + public BluetoothPbapClient(BluetoothDevice device, Account account, Handler handler) { + if (DBG) { + Log.d(TAG, " device " + device + " account " + account); + } if (device == null) { - throw new NullPointerException("BluetothDevice is null"); + throw new NullPointerException("BluetoothDevice is null"); } + mAccount = account; + mClientHandler = handler; mSessionHandler = new SessionHandler(this); @@ -696,8 +706,8 @@ public class BluetoothPbapClient { */ public boolean pullPhoneBook(String pbName, long filter, byte format, int maxListCount, int listStartOffset) { - BluetoothPbapRequest req = new BluetoothPbapRequestPullPhoneBook(pbName, filter, format, - maxListCount, listStartOffset); + BluetoothPbapRequest req = new BluetoothPbapRequestPullPhoneBook( + pbName, mAccount, filter, format, maxListCount, listStartOffset); return mSession.makeRequest(req); } @@ -835,7 +845,8 @@ public class BluetoothPbapClient { * @link #EVENT_PULL_VCARD_ERROR} in case of failure */ public boolean pullVcardEntry(String handle, long filter, byte format) { - BluetoothPbapRequest req = new BluetoothPbapRequestPullVcardEntry(handle, filter, format); + BluetoothPbapRequest req = + new BluetoothPbapRequestPullVcardEntry(handle, mAccount, filter, format); return mSession.makeRequest(req); } diff --git a/src/android/bluetooth/client/pbap/BluetoothPbapRequestPullPhoneBook.java b/src/android/bluetooth/client/pbap/BluetoothPbapRequestPullPhoneBook.java index 3d9f018..411a8de 100644 --- a/src/android/bluetooth/client/pbap/BluetoothPbapRequestPullPhoneBook.java +++ b/src/android/bluetooth/client/pbap/BluetoothPbapRequestPullPhoneBook.java @@ -16,6 +16,7 @@ package android.bluetooth.client.pbap; +import android.accounts.Account; import android.util.Log; import com.android.vcard.VCardEntry; @@ -37,13 +38,16 @@ final class BluetoothPbapRequestPullPhoneBook extends BluetoothPbapRequest { private BluetoothPbapVcardList mResponse; + private Account mAccount; + private int mNewMissedCalls = -1; private final byte mFormat; - public BluetoothPbapRequestPullPhoneBook(String pbName, long filter, byte format, + public BluetoothPbapRequestPullPhoneBook( + String pbName, Account account, long filter, byte format, int maxListCount, int listStartOffset) { - + mAccount = account; if (maxListCount < 0 || maxListCount > 65535) { throw new IllegalArgumentException("maxListCount should be [0..65535]"); } @@ -93,7 +97,7 @@ final class BluetoothPbapRequestPullPhoneBook extends BluetoothPbapRequest { protected void readResponse(InputStream stream) throws IOException { Log.v(TAG, "readResponse"); - mResponse = new BluetoothPbapVcardList(stream, mFormat); + mResponse = new BluetoothPbapVcardList(mAccount, stream, mFormat); if (DBG) { Log.d(TAG, "Read " + mResponse.getCount() + " entries."); } diff --git a/src/android/bluetooth/client/pbap/BluetoothPbapRequestPullVcardEntry.java b/src/android/bluetooth/client/pbap/BluetoothPbapRequestPullVcardEntry.java index 42b6692..ed823d5 100644 --- a/src/android/bluetooth/client/pbap/BluetoothPbapRequestPullVcardEntry.java +++ b/src/android/bluetooth/client/pbap/BluetoothPbapRequestPullVcardEntry.java @@ -16,6 +16,7 @@ package android.bluetooth.client.pbap; +import android.accounts.Account; import android.util.Log; import com.android.vcard.VCardEntry; @@ -35,9 +36,14 @@ final class BluetoothPbapRequestPullVcardEntry extends BluetoothPbapRequest { private BluetoothPbapVcardList mResponse; + private final Account mAccount; + private final byte mFormat; - public BluetoothPbapRequestPullVcardEntry(String handle, long filter, byte format) { + public BluetoothPbapRequestPullVcardEntry( + String handle, Account account, long filter, byte format) { + mAccount = account; + mHeaderSet.setHeader(HeaderSet.NAME, handle); mHeaderSet.setHeader(HeaderSet.TYPE, TYPE); @@ -64,7 +70,7 @@ final class BluetoothPbapRequestPullVcardEntry extends BluetoothPbapRequest { protected void readResponse(InputStream stream) throws IOException { Log.v(TAG, "readResponse"); - mResponse = new BluetoothPbapVcardList(stream, mFormat); + mResponse = new BluetoothPbapVcardList(mAccount, stream, mFormat); } @Override protected void checkResponseCode(int responseCode) throws IOException { diff --git a/src/android/bluetooth/client/pbap/BluetoothPbapVcardList.java b/src/android/bluetooth/client/pbap/BluetoothPbapVcardList.java index 8e23e1a..6bc75de 100644 --- a/src/android/bluetooth/client/pbap/BluetoothPbapVcardList.java +++ b/src/android/bluetooth/client/pbap/BluetoothPbapVcardList.java @@ -16,6 +16,9 @@ package android.bluetooth.client.pbap; +import android.accounts.Account; + +import com.android.vcard.VCardConfig; import com.android.vcard.VCardEntry; import com.android.vcard.VCardEntryConstructor; import com.android.vcard.VCardEntryCounter; @@ -32,6 +35,7 @@ import java.util.ArrayList; class BluetoothPbapVcardList { private final ArrayList<VCardEntry> mCards = new ArrayList<VCardEntry>(); + private final Account mAccount; class CardEntryHandler implements VCardEntryHandler { @Override @@ -48,7 +52,8 @@ class BluetoothPbapVcardList { } } - public BluetoothPbapVcardList(InputStream in, byte format) throws IOException { + public BluetoothPbapVcardList(Account account, InputStream in, byte format) throws IOException { + mAccount = account; parse(in, format); } @@ -61,7 +66,8 @@ class BluetoothPbapVcardList { parser = new VCardParser_V21(); } - VCardEntryConstructor constructor = new VCardEntryConstructor(); + VCardEntryConstructor constructor = + new VCardEntryConstructor(VCardConfig.VCARD_TYPE_V21_GENERIC, mAccount); VCardEntryCounter counter = new VCardEntryCounter(); CardEntryHandler handler = new CardEntryHandler(); |