summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaniel Lehmann <lehmannd@google.com>2012-04-06 20:24:00 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-04-06 20:24:00 -0700
commit18cb61aa592aa2c02c7f583f608ad0f8832f5742 (patch)
tree23e8101be04d3aac4083e6b359d63ff519cd8ffd /src
parenta9bdc5599848d608961238ef90897589e6bfe746 (diff)
parent904f4a2addf4fdf063cb40185cb73252ff0edefd (diff)
downloadpackages_providers_ContactsProvider-18cb61aa592aa2c02c7f583f608ad0f8832f5742.zip
packages_providers_ContactsProvider-18cb61aa592aa2c02c7f583f608ad0f8832f5742.tar.gz
packages_providers_ContactsProvider-18cb61aa592aa2c02c7f583f608ad0f8832f5742.tar.bz2
Merge "Allow access to the NORMALIZED_NUMBER, so that sync adapters can sync it"
Diffstat (limited to 'src')
-rw-r--r--src/com/android/providers/contacts/DataRowHandlerForPhoneNumber.java57
1 files changed, 30 insertions, 27 deletions
diff --git a/src/com/android/providers/contacts/DataRowHandlerForPhoneNumber.java b/src/com/android/providers/contacts/DataRowHandlerForPhoneNumber.java
index f6d6d5d..2ee61e4 100644
--- a/src/com/android/providers/contacts/DataRowHandlerForPhoneNumber.java
+++ b/src/com/android/providers/contacts/DataRowHandlerForPhoneNumber.java
@@ -41,25 +41,18 @@ public class DataRowHandlerForPhoneNumber extends DataRowHandlerForCommonDataKin
@Override
public long insert(SQLiteDatabase db, TransactionContext txContext, long rawContactId,
ContentValues values) {
- long dataId;
- if (values.containsKey(Phone.NUMBER)) {
- String number = values.getAsString(Phone.NUMBER);
-
- String numberE164 =
- PhoneNumberUtils.formatNumberToE164(number, mDbHelper.getCurrentCountryIso());
- if (numberE164 != null) {
- values.put(Phone.NORMALIZED_NUMBER, numberE164);
- }
- dataId = super.insert(db, txContext, rawContactId, values);
+ fillNormalizedNumber(values);
- updatePhoneLookup(db, rawContactId, dataId, number, numberE164);
+ final long dataId = super.insert(db, txContext, rawContactId, values);
+ if (values.containsKey(Phone.NUMBER)) {
+ final String number = values.getAsString(Phone.NUMBER);
+ final String normalizedNumber = values.getAsString(Phone.NORMALIZED_NUMBER);
+ updatePhoneLookup(db, rawContactId, dataId, number, normalizedNumber);
mContactAggregator.updateHasPhoneNumber(db, rawContactId);
fixRawContactDisplayName(db, txContext, rawContactId);
- if (numberE164 != null) {
+ if (normalizedNumber != null) {
triggerAggregation(txContext, rawContactId);
}
- } else {
- dataId = super.insert(db, txContext, rawContactId, values);
}
return dataId;
}
@@ -67,18 +60,7 @@ public class DataRowHandlerForPhoneNumber extends DataRowHandlerForCommonDataKin
@Override
public boolean update(SQLiteDatabase db, TransactionContext txContext, ContentValues values,
Cursor c, boolean callerIsSyncAdapter) {
- String number = null;
- String numberE164 = null;
- if (values.containsKey(Phone.NUMBER)) {
- number = values.getAsString(Phone.NUMBER);
- if (number != null) {
- numberE164 = PhoneNumberUtils.formatNumberToE164(number,
- mDbHelper.getCurrentCountryIso());
- }
- if (numberE164 != null) {
- values.put(Phone.NORMALIZED_NUMBER, numberE164);
- }
- }
+ fillNormalizedNumber(values);
if (!super.update(db, txContext, values, c, callerIsSyncAdapter)) {
return false;
@@ -87,7 +69,9 @@ public class DataRowHandlerForPhoneNumber extends DataRowHandlerForCommonDataKin
if (values.containsKey(Phone.NUMBER)) {
long dataId = c.getLong(DataUpdateQuery._ID);
long rawContactId = c.getLong(DataUpdateQuery.RAW_CONTACT_ID);
- updatePhoneLookup(db, rawContactId, dataId, number, numberE164);
+ updatePhoneLookup(db, rawContactId, dataId,
+ values.getAsString(Phone.NUMBER),
+ values.getAsString(Phone.NORMALIZED_NUMBER));
mContactAggregator.updateHasPhoneNumber(db, rawContactId);
fixRawContactDisplayName(db, txContext, rawContactId);
triggerAggregation(txContext, rawContactId);
@@ -95,6 +79,25 @@ public class DataRowHandlerForPhoneNumber extends DataRowHandlerForCommonDataKin
return true;
}
+ private void fillNormalizedNumber(ContentValues values) {
+ // No NUMBER? Also ignore NORMALIZED_NUMBER
+ if (!values.containsKey(Phone.NUMBER)) {
+ values.remove(Phone.NORMALIZED_NUMBER);
+ return;
+ }
+
+ // NUMBER is given. Try to extract NORMALIZED_NUMBER from it, unless it is also given
+ final String number = values.getAsString(Phone.NUMBER);
+ final String numberE164 = values.getAsString(Phone.NORMALIZED_NUMBER);
+ if (number != null && numberE164 == null) {
+ final String newNumberE164 = PhoneNumberUtils.formatNumberToE164(number,
+ mDbHelper.getCurrentCountryIso());
+ if (newNumberE164 != null) {
+ values.put(Phone.NORMALIZED_NUMBER, newNumberE164);
+ }
+ }
+ }
+
@Override
public int delete(SQLiteDatabase db, TransactionContext txContext, Cursor c) {
long dataId = c.getLong(DataDeleteQuery._ID);