Loading android/app/src/com/android/bluetooth/pbapclient/CallLogPullRequest.java +7 −3 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ package com.android.bluetooth.pbapclient; import android.accounts.Account; import android.content.ContentProviderOperation; import android.content.ContentValues; import android.content.Context; Loading @@ -23,6 +24,7 @@ import android.database.Cursor; import android.net.Uri; import android.os.RemoteException; import android.provider.CallLog; import android.provider.CallLog.Calls; import android.provider.ContactsContract; import android.util.Log; import android.util.Pair; Loading @@ -43,14 +45,16 @@ public class CallLogPullRequest extends PullRequest { private static final String TIMESTAMP_PROPERTY = "X-IRMC-CALL-DATETIME"; private static final String TIMESTAMP_FORMAT = "yyyyMMdd'T'HHmmss"; private final Account mAccount; private Context mContext; private HashMap<String, Integer> mCallCounter; public CallLogPullRequest(Context context, String path, HashMap<String, Integer> map) { public CallLogPullRequest(Context context, String path, HashMap<String, Integer> map, Account account) { mContext = context; this.path = path; mCallCounter = map; mAccount = account; } @Override Loading Loading @@ -84,7 +88,7 @@ public class CallLogPullRequest extends PullRequest { ContentValues values = new ContentValues(); values.put(CallLog.Calls.TYPE, type); values.put(Calls.PHONE_ACCOUNT_ID, mAccount.hashCode()); List<PhoneData> phones = vcard.getPhoneList(); if (phones == null || phones.get(0).getNumber().equals(";")) { values.put(CallLog.Calls.NUMBER, ""); Loading android/app/src/com/android/bluetooth/pbapclient/PbapClientConnectionHandler.java +25 −6 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.os.Handler; import android.os.Looper; import android.os.Message; import android.provider.CallLog; import android.provider.CallLog.Calls; import android.util.Log; import com.android.bluetooth.BluetoothObexTransport; Loading Loading @@ -232,7 +233,8 @@ class PbapClientConnectionHandler extends Handler { Log.d(TAG, "Completing Disconnect"); } removeAccount(mAccount); mContext.getContentResolver().delete(CallLog.Calls.CONTENT_URI, null, null); removeCallLog(mAccount); mPbapClientStateMachine.obtainMessage(PbapClientStateMachine.MSG_CONNECTION_CLOSED) .sendToTarget(); break; Loading Loading @@ -371,7 +373,8 @@ class PbapClientConnectionHandler extends Handler { new BluetoothPbapRequestPullPhoneBook(path, mAccount, 0, VCARD_TYPE_30, 0, 0); request.execute(mObexSession); CallLogPullRequest processor = new CallLogPullRequest(mPbapClientStateMachine.getContext(), path, callCounter); new CallLogPullRequest(mPbapClientStateMachine.getContext(), path, callCounter, mAccount); processor.setResults(request.getList()); processor.onPullComplete(); } catch (IOException e) { Loading @@ -389,13 +392,29 @@ class PbapClientConnectionHandler extends Handler { return false; } private void removeAccount(Account acc) { if (mAccountManager.removeAccountExplicitly(acc)) { private void removeAccount(Account account) { if (mAccountManager.removeAccountExplicitly(account)) { if (DBG) { Log.d(TAG, "Removed account " + acc); Log.d(TAG, "Removed account " + account); } } else { Log.e(TAG, "Failed to remove account " + mAccount); } } private void removeCallLog(Account account) { try { // need to check call table is exist ? if (mContext.getContentResolver() == null) { if (DBG) { Log.d(TAG, "CallLog ContentResolver is not found"); } return; } String where = Calls.PHONE_ACCOUNT_ID + "=" + account.hashCode(); mContext.getContentResolver().delete(CallLog.Calls.CONTENT_URI, where, null); } catch (IllegalArgumentException e) { Log.d(TAG, "Call Logs could not be deleted, they may not exist yet."); } } } android/app/tests/unit/res/raw/v30_simple.vcf 0 → 100644 +13 −0 Original line number Diff line number Diff line BEGIN:VCARD VERSION:3.0 FN:And Roid N:And;Roid;;; ORG:Open;Handset; Alliance SORT-STRING:android TEL;TYPE=PREF;TYPE=VOICE:0300000000 CLASS:PUBLIC X-GNO:0 X-GN:group0 X-REDUCTION:0 REV:20081031T065854Z END:VCARD android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapParserTest.java +42 −3 Original line number Diff line number Diff line Loading @@ -21,7 +21,9 @@ import android.content.Context; import android.content.pm.PackageManager; import android.content.res.Resources; import android.database.Cursor; import android.net.Uri; import android.provider.CallLog.Calls; import android.provider.ContactsContract; import android.support.test.InstrumentationRegistry; import android.support.test.filters.MediumTest; import android.support.test.runner.AndroidJUnit4; Loading Loading @@ -62,6 +64,7 @@ public class PbapParserTest { Assert.fail("Setup Failure Unable to get resources" + e.toString()); } cleanupCallLog(); cleanupPhonebook(); } // testNoTimestamp should parse 1 poorly formed vcard and not crash. Loading @@ -75,7 +78,7 @@ public class PbapParserTest { Assert.assertEquals(1, pbapVCardList.getCount()); CallLogPullRequest processor = new CallLogPullRequest(mTargetContext, PbapClientConnectionHandler.MCH_PATH, new HashMap<>()); new HashMap<>(), mAccount); processor.setResults(pbapVCardList.getList()); // Verify that these entries aren't in the call log to start. Loading @@ -97,7 +100,7 @@ public class PbapParserTest { Assert.assertEquals(1, pbapVCardList.getCount()); CallLogPullRequest processor = new CallLogPullRequest(mTargetContext, PbapClientConnectionHandler.MCH_PATH, new HashMap<>()); new HashMap<>(), mAccount); processor.setResults(pbapVCardList.getList()); // Verify that these entries aren't in the call log to start. Loading @@ -118,7 +121,7 @@ public class PbapParserTest { Assert.assertEquals(2, pbapVCardList.getCount()); CallLogPullRequest processor = new CallLogPullRequest(mTargetContext, PbapClientConnectionHandler.MCH_PATH, new HashMap<>()); new HashMap<>(), mAccount); processor.setResults(pbapVCardList.getList()); // Verify that these entries aren't in the call log to start. Loading @@ -131,10 +134,30 @@ public class PbapParserTest { Assert.assertTrue(verifyCallLog("", "1483232580000", "3")); } @Test public void testPullPhoneBook() throws IOException { InputStream fileStream; fileStream = mTestResources.openRawResource( com.android.bluetooth.tests.R.raw.v30_simple); BluetoothPbapVcardList pbapVCardList = new BluetoothPbapVcardList(mAccount, fileStream, PbapClientConnectionHandler.VCARD_TYPE_30); Assert.assertEquals(1, pbapVCardList.getCount()); PhonebookPullRequest processor = new PhonebookPullRequest(mTargetContext, mAccount); processor.setResults(pbapVCardList.getList()); Assert.assertFalse(verifyPhonebook("Roid And", "0300000000")); processor.onPullComplete(); Assert.assertTrue(verifyPhonebook("Roid And", "0300000000")); } private void cleanupCallLog() { mTargetContext.getContentResolver().delete(Calls.CONTENT_URI, null, null); } private void cleanupPhonebook() { mTargetContext.getContentResolver().delete(ContactsContract.RawContacts.CONTENT_URI, null, null); } // Find Entries in call log with type matching number and date. // If number or date is null it will match any number or date respectively. private boolean verifyCallLog(String number, String date, String type) { Loading Loading @@ -165,4 +188,20 @@ public class PbapParserTest { long dt = Long.valueOf(date) - tz.getRawOffset(); return Long.toString(dt); } private boolean verifyPhonebook(String name, String number) { Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)); Cursor c = mTargetContext.getContentResolver().query(uri, null, null, null); if (c != null && c.getCount() > 0) { c.moveToNext(); String displayName = c.getString( c.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME)); if (displayName.equals(name)) { return true; } } return false; } } Loading
android/app/src/com/android/bluetooth/pbapclient/CallLogPullRequest.java +7 −3 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ package com.android.bluetooth.pbapclient; import android.accounts.Account; import android.content.ContentProviderOperation; import android.content.ContentValues; import android.content.Context; Loading @@ -23,6 +24,7 @@ import android.database.Cursor; import android.net.Uri; import android.os.RemoteException; import android.provider.CallLog; import android.provider.CallLog.Calls; import android.provider.ContactsContract; import android.util.Log; import android.util.Pair; Loading @@ -43,14 +45,16 @@ public class CallLogPullRequest extends PullRequest { private static final String TIMESTAMP_PROPERTY = "X-IRMC-CALL-DATETIME"; private static final String TIMESTAMP_FORMAT = "yyyyMMdd'T'HHmmss"; private final Account mAccount; private Context mContext; private HashMap<String, Integer> mCallCounter; public CallLogPullRequest(Context context, String path, HashMap<String, Integer> map) { public CallLogPullRequest(Context context, String path, HashMap<String, Integer> map, Account account) { mContext = context; this.path = path; mCallCounter = map; mAccount = account; } @Override Loading Loading @@ -84,7 +88,7 @@ public class CallLogPullRequest extends PullRequest { ContentValues values = new ContentValues(); values.put(CallLog.Calls.TYPE, type); values.put(Calls.PHONE_ACCOUNT_ID, mAccount.hashCode()); List<PhoneData> phones = vcard.getPhoneList(); if (phones == null || phones.get(0).getNumber().equals(";")) { values.put(CallLog.Calls.NUMBER, ""); Loading
android/app/src/com/android/bluetooth/pbapclient/PbapClientConnectionHandler.java +25 −6 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.os.Handler; import android.os.Looper; import android.os.Message; import android.provider.CallLog; import android.provider.CallLog.Calls; import android.util.Log; import com.android.bluetooth.BluetoothObexTransport; Loading Loading @@ -232,7 +233,8 @@ class PbapClientConnectionHandler extends Handler { Log.d(TAG, "Completing Disconnect"); } removeAccount(mAccount); mContext.getContentResolver().delete(CallLog.Calls.CONTENT_URI, null, null); removeCallLog(mAccount); mPbapClientStateMachine.obtainMessage(PbapClientStateMachine.MSG_CONNECTION_CLOSED) .sendToTarget(); break; Loading Loading @@ -371,7 +373,8 @@ class PbapClientConnectionHandler extends Handler { new BluetoothPbapRequestPullPhoneBook(path, mAccount, 0, VCARD_TYPE_30, 0, 0); request.execute(mObexSession); CallLogPullRequest processor = new CallLogPullRequest(mPbapClientStateMachine.getContext(), path, callCounter); new CallLogPullRequest(mPbapClientStateMachine.getContext(), path, callCounter, mAccount); processor.setResults(request.getList()); processor.onPullComplete(); } catch (IOException e) { Loading @@ -389,13 +392,29 @@ class PbapClientConnectionHandler extends Handler { return false; } private void removeAccount(Account acc) { if (mAccountManager.removeAccountExplicitly(acc)) { private void removeAccount(Account account) { if (mAccountManager.removeAccountExplicitly(account)) { if (DBG) { Log.d(TAG, "Removed account " + acc); Log.d(TAG, "Removed account " + account); } } else { Log.e(TAG, "Failed to remove account " + mAccount); } } private void removeCallLog(Account account) { try { // need to check call table is exist ? if (mContext.getContentResolver() == null) { if (DBG) { Log.d(TAG, "CallLog ContentResolver is not found"); } return; } String where = Calls.PHONE_ACCOUNT_ID + "=" + account.hashCode(); mContext.getContentResolver().delete(CallLog.Calls.CONTENT_URI, where, null); } catch (IllegalArgumentException e) { Log.d(TAG, "Call Logs could not be deleted, they may not exist yet."); } } }
android/app/tests/unit/res/raw/v30_simple.vcf 0 → 100644 +13 −0 Original line number Diff line number Diff line BEGIN:VCARD VERSION:3.0 FN:And Roid N:And;Roid;;; ORG:Open;Handset; Alliance SORT-STRING:android TEL;TYPE=PREF;TYPE=VOICE:0300000000 CLASS:PUBLIC X-GNO:0 X-GN:group0 X-REDUCTION:0 REV:20081031T065854Z END:VCARD
android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapParserTest.java +42 −3 Original line number Diff line number Diff line Loading @@ -21,7 +21,9 @@ import android.content.Context; import android.content.pm.PackageManager; import android.content.res.Resources; import android.database.Cursor; import android.net.Uri; import android.provider.CallLog.Calls; import android.provider.ContactsContract; import android.support.test.InstrumentationRegistry; import android.support.test.filters.MediumTest; import android.support.test.runner.AndroidJUnit4; Loading Loading @@ -62,6 +64,7 @@ public class PbapParserTest { Assert.fail("Setup Failure Unable to get resources" + e.toString()); } cleanupCallLog(); cleanupPhonebook(); } // testNoTimestamp should parse 1 poorly formed vcard and not crash. Loading @@ -75,7 +78,7 @@ public class PbapParserTest { Assert.assertEquals(1, pbapVCardList.getCount()); CallLogPullRequest processor = new CallLogPullRequest(mTargetContext, PbapClientConnectionHandler.MCH_PATH, new HashMap<>()); new HashMap<>(), mAccount); processor.setResults(pbapVCardList.getList()); // Verify that these entries aren't in the call log to start. Loading @@ -97,7 +100,7 @@ public class PbapParserTest { Assert.assertEquals(1, pbapVCardList.getCount()); CallLogPullRequest processor = new CallLogPullRequest(mTargetContext, PbapClientConnectionHandler.MCH_PATH, new HashMap<>()); new HashMap<>(), mAccount); processor.setResults(pbapVCardList.getList()); // Verify that these entries aren't in the call log to start. Loading @@ -118,7 +121,7 @@ public class PbapParserTest { Assert.assertEquals(2, pbapVCardList.getCount()); CallLogPullRequest processor = new CallLogPullRequest(mTargetContext, PbapClientConnectionHandler.MCH_PATH, new HashMap<>()); new HashMap<>(), mAccount); processor.setResults(pbapVCardList.getList()); // Verify that these entries aren't in the call log to start. Loading @@ -131,10 +134,30 @@ public class PbapParserTest { Assert.assertTrue(verifyCallLog("", "1483232580000", "3")); } @Test public void testPullPhoneBook() throws IOException { InputStream fileStream; fileStream = mTestResources.openRawResource( com.android.bluetooth.tests.R.raw.v30_simple); BluetoothPbapVcardList pbapVCardList = new BluetoothPbapVcardList(mAccount, fileStream, PbapClientConnectionHandler.VCARD_TYPE_30); Assert.assertEquals(1, pbapVCardList.getCount()); PhonebookPullRequest processor = new PhonebookPullRequest(mTargetContext, mAccount); processor.setResults(pbapVCardList.getList()); Assert.assertFalse(verifyPhonebook("Roid And", "0300000000")); processor.onPullComplete(); Assert.assertTrue(verifyPhonebook("Roid And", "0300000000")); } private void cleanupCallLog() { mTargetContext.getContentResolver().delete(Calls.CONTENT_URI, null, null); } private void cleanupPhonebook() { mTargetContext.getContentResolver().delete(ContactsContract.RawContacts.CONTENT_URI, null, null); } // Find Entries in call log with type matching number and date. // If number or date is null it will match any number or date respectively. private boolean verifyCallLog(String number, String date, String type) { Loading Loading @@ -165,4 +188,20 @@ public class PbapParserTest { long dt = Long.valueOf(date) - tz.getRawOffset(); return Long.toString(dt); } private boolean verifyPhonebook(String name, String number) { Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)); Cursor c = mTargetContext.getContentResolver().query(uri, null, null, null); if (c != null && c.getCount() > 0) { c.moveToNext(); String displayName = c.getString( c.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME)); if (displayName.equals(name)) { return true; } } return false; } }