Loading android/app/src/com/android/bluetooth/pbapclient/CallLogPullRequest.java +45 −4 Original line number Diff line number Diff line Loading @@ -19,8 +19,11 @@ import android.content.ContentProviderOperation; import android.content.ContentValues; import android.content.Context; import android.content.OperationApplicationException; import android.database.Cursor; import android.net.Uri; import android.os.RemoteException; import android.provider.CallLog; import android.provider.ContactsContract; import android.util.Log; import android.util.Pair; Loading @@ -30,6 +33,7 @@ import com.android.vcard.VCardEntry.PhoneData; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; public class CallLogPullRequest extends PullRequest { Loading @@ -39,11 +43,14 @@ 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 Context mContext; private HashMap<String, Integer> mCallCounter; public CallLogPullRequest(Context context, String path) { public CallLogPullRequest(Context context, String path, HashMap<String, Integer> map) { mContext = context; this.path = path; mCallCounter = map; } @Override Loading Loading @@ -82,9 +89,15 @@ public class CallLogPullRequest extends PullRequest { if (phones == null || phones.get(0).getNumber().equals(";")) { values.put(CallLog.Calls.NUMBER, ""); } else { values.put(CallLog.Calls.NUMBER, phones.get(0).getNumber()); String phoneNumber = phones.get(0).getNumber(); values.put(CallLog.Calls.NUMBER, phoneNumber); if (mCallCounter.get(phoneNumber) != null) { int updateCounter = mCallCounter.get(phoneNumber) + 1; mCallCounter.put(phoneNumber, updateCounter); } else { mCallCounter.put(phoneNumber, 1); } } List<Pair<String, String>> irmc = vcard.getUnknownXData(); SimpleDateFormat parser = new SimpleDateFormat(TIMESTAMP_FORMAT); if (irmc != null) { Loading @@ -101,7 +114,6 @@ public class CallLogPullRequest extends PullRequest { } } } ops.add(ContentProviderOperation.newInsert(CallLog.Calls.CONTENT_URI) .withValues(values) .withYieldAllowed(true) Loading @@ -109,6 +121,10 @@ public class CallLogPullRequest extends PullRequest { } mContext.getContentResolver().applyBatch(CallLog.AUTHORITY, ops); Log.d(TAG, "Updated call logs."); //OUTGOING_TYPE is the last callLog we fetched. if (type == CallLog.Calls.OUTGOING_TYPE) { updateTimesContacted(); } } catch (RemoteException | OperationApplicationException e) { Log.d(TAG, "Failed to update call log for path=" + path, e); } finally { Loading @@ -117,4 +133,29 @@ public class CallLogPullRequest extends PullRequest { } } } private void updateTimesContacted() { for (String key : mCallCounter.keySet()) { ContentValues values = new ContentValues(); values.put(ContactsContract.RawContacts.TIMES_CONTACTED, mCallCounter.get(key)); Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(key)); Cursor c = mContext.getContentResolver().query(uri, null, null, null); if (c != null && c.getCount() > 0) { c.moveToNext(); String contactId = c.getString(c.getColumnIndex( ContactsContract.PhoneLookup.CONTACT_ID)); if (VDBG) { Log.d(TAG, "onPullComplete: ID " + contactId + " key : " + key); } String where = ContactsContract.RawContacts.CONTACT_ID + "=" + contactId; mContext.getContentResolver().update( ContactsContract.RawContacts.CONTENT_URI, values, where, null); } } if (DBG) { Log.d(TAG, "Updated TIMES_CONTACTED"); } } } android/app/src/com/android/bluetooth/pbapclient/PbapClientConnectionHandler.java +8 −6 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import com.android.bluetooth.BluetoothObexTransport; import com.android.bluetooth.R; import java.io.IOException; import java.util.HashMap; import javax.obex.ClientSession; import javax.obex.HeaderSet; Loading Loading @@ -96,6 +97,7 @@ class PbapClientConnectionHandler extends Handler { public static final String MCH_PATH = "telecom/mch.vcf"; public static final String ICH_PATH = "telecom/ich.vcf"; public static final String OCH_PATH = "telecom/och.vcf"; public static final byte VCARD_TYPE_21 = 0; public static final byte VCARD_TYPE_30 = 1; Loading Loading @@ -251,10 +253,10 @@ class PbapClientConnectionHandler extends Handler { mAccount); processor.setResults(request.getList()); processor.onPullComplete(); downloadCallLog(MCH_PATH); downloadCallLog(ICH_PATH); downloadCallLog(OCH_PATH); HashMap<String, Integer> callCounter = new HashMap<>(); downloadCallLog(MCH_PATH, callCounter); downloadCallLog(ICH_PATH, callCounter); downloadCallLog(OCH_PATH, callCounter); } catch (IOException e) { Log.w(TAG, "DOWNLOAD_CONTACTS Failure" + e.toString()); } Loading Loading @@ -362,13 +364,13 @@ class PbapClientConnectionHandler extends Handler { } } void downloadCallLog(String path) { void downloadCallLog(String path, HashMap<String, Integer> callCounter) { try { BluetoothPbapRequestPullPhoneBook request = new BluetoothPbapRequestPullPhoneBook(path, mAccount, 0, VCARD_TYPE_30, 0, 0); request.execute(mObexSession); CallLogPullRequest processor = new CallLogPullRequest(mPbapClientStateMachine.getContext(), path); new CallLogPullRequest(mPbapClientStateMachine.getContext(), path, callCounter); processor.setResults(request.getList()); processor.onPullComplete(); } catch (IOException e) { Loading android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapParserTest.java +7 −3 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import org.junit.runner.RunWith; import java.io.IOException; import java.io.InputStream; import java.util.HashMap; import java.util.TimeZone; @MediumTest Loading Loading @@ -68,7 +69,8 @@ public class PbapParserTest { PbapClientConnectionHandler.VCARD_TYPE_30); Assert.assertEquals(1, pbapVCardList.getCount()); CallLogPullRequest processor = new CallLogPullRequest(mTargetContext, PbapClientConnectionHandler.MCH_PATH); new CallLogPullRequest(mTargetContext, PbapClientConnectionHandler.MCH_PATH, new HashMap<>()); processor.setResults(pbapVCardList.getList()); // Verify that these entries aren't in the call log to start. Loading @@ -89,7 +91,8 @@ public class PbapParserTest { PbapClientConnectionHandler.VCARD_TYPE_30); Assert.assertEquals(1, pbapVCardList.getCount()); CallLogPullRequest processor = new CallLogPullRequest(mTargetContext, PbapClientConnectionHandler.MCH_PATH); new CallLogPullRequest(mTargetContext, PbapClientConnectionHandler.MCH_PATH, new HashMap<>()); processor.setResults(pbapVCardList.getList()); // Verify that these entries aren't in the call log to start. Loading @@ -109,7 +112,8 @@ public class PbapParserTest { PbapClientConnectionHandler.VCARD_TYPE_30); Assert.assertEquals(2, pbapVCardList.getCount()); CallLogPullRequest processor = new CallLogPullRequest(mTargetContext, PbapClientConnectionHandler.MCH_PATH); new CallLogPullRequest(mTargetContext, PbapClientConnectionHandler.MCH_PATH, new HashMap<>()); processor.setResults(pbapVCardList.getList()); // Verify that these entries aren't in the call log to start. Loading Loading
android/app/src/com/android/bluetooth/pbapclient/CallLogPullRequest.java +45 −4 Original line number Diff line number Diff line Loading @@ -19,8 +19,11 @@ import android.content.ContentProviderOperation; import android.content.ContentValues; import android.content.Context; import android.content.OperationApplicationException; import android.database.Cursor; import android.net.Uri; import android.os.RemoteException; import android.provider.CallLog; import android.provider.ContactsContract; import android.util.Log; import android.util.Pair; Loading @@ -30,6 +33,7 @@ import com.android.vcard.VCardEntry.PhoneData; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; public class CallLogPullRequest extends PullRequest { Loading @@ -39,11 +43,14 @@ 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 Context mContext; private HashMap<String, Integer> mCallCounter; public CallLogPullRequest(Context context, String path) { public CallLogPullRequest(Context context, String path, HashMap<String, Integer> map) { mContext = context; this.path = path; mCallCounter = map; } @Override Loading Loading @@ -82,9 +89,15 @@ public class CallLogPullRequest extends PullRequest { if (phones == null || phones.get(0).getNumber().equals(";")) { values.put(CallLog.Calls.NUMBER, ""); } else { values.put(CallLog.Calls.NUMBER, phones.get(0).getNumber()); String phoneNumber = phones.get(0).getNumber(); values.put(CallLog.Calls.NUMBER, phoneNumber); if (mCallCounter.get(phoneNumber) != null) { int updateCounter = mCallCounter.get(phoneNumber) + 1; mCallCounter.put(phoneNumber, updateCounter); } else { mCallCounter.put(phoneNumber, 1); } } List<Pair<String, String>> irmc = vcard.getUnknownXData(); SimpleDateFormat parser = new SimpleDateFormat(TIMESTAMP_FORMAT); if (irmc != null) { Loading @@ -101,7 +114,6 @@ public class CallLogPullRequest extends PullRequest { } } } ops.add(ContentProviderOperation.newInsert(CallLog.Calls.CONTENT_URI) .withValues(values) .withYieldAllowed(true) Loading @@ -109,6 +121,10 @@ public class CallLogPullRequest extends PullRequest { } mContext.getContentResolver().applyBatch(CallLog.AUTHORITY, ops); Log.d(TAG, "Updated call logs."); //OUTGOING_TYPE is the last callLog we fetched. if (type == CallLog.Calls.OUTGOING_TYPE) { updateTimesContacted(); } } catch (RemoteException | OperationApplicationException e) { Log.d(TAG, "Failed to update call log for path=" + path, e); } finally { Loading @@ -117,4 +133,29 @@ public class CallLogPullRequest extends PullRequest { } } } private void updateTimesContacted() { for (String key : mCallCounter.keySet()) { ContentValues values = new ContentValues(); values.put(ContactsContract.RawContacts.TIMES_CONTACTED, mCallCounter.get(key)); Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(key)); Cursor c = mContext.getContentResolver().query(uri, null, null, null); if (c != null && c.getCount() > 0) { c.moveToNext(); String contactId = c.getString(c.getColumnIndex( ContactsContract.PhoneLookup.CONTACT_ID)); if (VDBG) { Log.d(TAG, "onPullComplete: ID " + contactId + " key : " + key); } String where = ContactsContract.RawContacts.CONTACT_ID + "=" + contactId; mContext.getContentResolver().update( ContactsContract.RawContacts.CONTENT_URI, values, where, null); } } if (DBG) { Log.d(TAG, "Updated TIMES_CONTACTED"); } } }
android/app/src/com/android/bluetooth/pbapclient/PbapClientConnectionHandler.java +8 −6 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import com.android.bluetooth.BluetoothObexTransport; import com.android.bluetooth.R; import java.io.IOException; import java.util.HashMap; import javax.obex.ClientSession; import javax.obex.HeaderSet; Loading Loading @@ -96,6 +97,7 @@ class PbapClientConnectionHandler extends Handler { public static final String MCH_PATH = "telecom/mch.vcf"; public static final String ICH_PATH = "telecom/ich.vcf"; public static final String OCH_PATH = "telecom/och.vcf"; public static final byte VCARD_TYPE_21 = 0; public static final byte VCARD_TYPE_30 = 1; Loading Loading @@ -251,10 +253,10 @@ class PbapClientConnectionHandler extends Handler { mAccount); processor.setResults(request.getList()); processor.onPullComplete(); downloadCallLog(MCH_PATH); downloadCallLog(ICH_PATH); downloadCallLog(OCH_PATH); HashMap<String, Integer> callCounter = new HashMap<>(); downloadCallLog(MCH_PATH, callCounter); downloadCallLog(ICH_PATH, callCounter); downloadCallLog(OCH_PATH, callCounter); } catch (IOException e) { Log.w(TAG, "DOWNLOAD_CONTACTS Failure" + e.toString()); } Loading Loading @@ -362,13 +364,13 @@ class PbapClientConnectionHandler extends Handler { } } void downloadCallLog(String path) { void downloadCallLog(String path, HashMap<String, Integer> callCounter) { try { BluetoothPbapRequestPullPhoneBook request = new BluetoothPbapRequestPullPhoneBook(path, mAccount, 0, VCARD_TYPE_30, 0, 0); request.execute(mObexSession); CallLogPullRequest processor = new CallLogPullRequest(mPbapClientStateMachine.getContext(), path); new CallLogPullRequest(mPbapClientStateMachine.getContext(), path, callCounter); processor.setResults(request.getList()); processor.onPullComplete(); } catch (IOException e) { Loading
android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapParserTest.java +7 −3 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import org.junit.runner.RunWith; import java.io.IOException; import java.io.InputStream; import java.util.HashMap; import java.util.TimeZone; @MediumTest Loading Loading @@ -68,7 +69,8 @@ public class PbapParserTest { PbapClientConnectionHandler.VCARD_TYPE_30); Assert.assertEquals(1, pbapVCardList.getCount()); CallLogPullRequest processor = new CallLogPullRequest(mTargetContext, PbapClientConnectionHandler.MCH_PATH); new CallLogPullRequest(mTargetContext, PbapClientConnectionHandler.MCH_PATH, new HashMap<>()); processor.setResults(pbapVCardList.getList()); // Verify that these entries aren't in the call log to start. Loading @@ -89,7 +91,8 @@ public class PbapParserTest { PbapClientConnectionHandler.VCARD_TYPE_30); Assert.assertEquals(1, pbapVCardList.getCount()); CallLogPullRequest processor = new CallLogPullRequest(mTargetContext, PbapClientConnectionHandler.MCH_PATH); new CallLogPullRequest(mTargetContext, PbapClientConnectionHandler.MCH_PATH, new HashMap<>()); processor.setResults(pbapVCardList.getList()); // Verify that these entries aren't in the call log to start. Loading @@ -109,7 +112,8 @@ public class PbapParserTest { PbapClientConnectionHandler.VCARD_TYPE_30); Assert.assertEquals(2, pbapVCardList.getCount()); CallLogPullRequest processor = new CallLogPullRequest(mTargetContext, PbapClientConnectionHandler.MCH_PATH); new CallLogPullRequest(mTargetContext, PbapClientConnectionHandler.MCH_PATH, new HashMap<>()); processor.setResults(pbapVCardList.getList()); // Verify that these entries aren't in the call log to start. Loading