summaryrefslogtreecommitdiffstats
path: root/core/java
diff options
context:
space:
mode:
authorYorke Lee <yorkelee@google.com>2014-08-21 09:37:22 -0700
committerYorke Lee <yorkelee@google.com>2014-08-21 16:24:19 -0700
commit3dbc1185fb54561ed628554fa0dcb080a9453219 (patch)
tree3293bd9c13980887dd91c70ba35b034a10b05204 /core/java
parent7bf41929f246873f3c1206a0ef2d2180b9e2edb6 (diff)
downloadframeworks_base-3dbc1185fb54561ed628554fa0dcb080a9453219.zip
frameworks_base-3dbc1185fb54561ed628554fa0dcb080a9453219.tar.gz
frameworks_base-3dbc1185fb54561ed628554fa0dcb080a9453219.tar.bz2
Update normalized phone number for contact for successful call
Bug: 13792353 Change-Id: I6461bd225994160ace45238aee49f39eb13cb702
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/provider/CallLog.java72
1 files changed, 66 insertions, 6 deletions
diff --git a/core/java/android/provider/CallLog.java b/core/java/android/provider/CallLog.java
index 8db99a5..942da5a 100644
--- a/core/java/android/provider/CallLog.java
+++ b/core/java/android/provider/CallLog.java
@@ -24,13 +24,17 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.UserInfo;
import android.database.Cursor;
+import android.location.Country;
+import android.location.CountryDetector;
import android.net.Uri;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.ContactsContract.CommonDataKinds.Callable;
import android.provider.ContactsContract.CommonDataKinds.Phone;
+import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.DataUsageFeedback;
import android.telecomm.PhoneAccountHandle;
+import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;
import com.android.internal.telephony.CallerInfo;
@@ -345,6 +349,13 @@ public class CallLog {
public static final String PHONE_ACCOUNT_ID = "subscription_id";
/**
+ * If a successful call is made that is longer than this duration, update the phone number
+ * in the ContactsProvider with the normalized version of the number, based on the user's
+ * current country code.
+ */
+ private static final int MIN_DURATION_FOR_NORMALIZED_NUMBER_UPDATE_MS = 1000 * 10;
+
+ /**
* Adds a call to the call log.
*
* @param ci the CallerInfo object to get the target contact from. Can be null
@@ -484,12 +495,13 @@ public class CallLog {
if (cursor != null) {
try {
if (cursor.getCount() > 0 && cursor.moveToFirst()) {
- final Uri feedbackUri = DataUsageFeedback.FEEDBACK_URI.buildUpon()
- .appendPath(cursor.getString(0))
- .appendQueryParameter(DataUsageFeedback.USAGE_TYPE,
- DataUsageFeedback.USAGE_TYPE_CALL)
- .build();
- resolver.update(feedbackUri, new ContentValues(), null, null);
+ final String dataId = cursor.getString(0);
+ updateDataUsageStatForData(resolver, dataId);
+ if (duration >= MIN_DURATION_FOR_NORMALIZED_NUMBER_UPDATE_MS
+ && callType == Calls.OUTGOING_TYPE
+ && TextUtils.isEmpty(ci.normalizedNumber)) {
+ updateNormalizedNumber(context, resolver, dataId, number);
+ }
}
} finally {
cursor.close();
@@ -562,5 +574,53 @@ public class CallLog {
+ " LIMIT -1 OFFSET 500)", null);
return result;
}
+
+ private static void updateDataUsageStatForData(ContentResolver resolver, String dataId) {
+ final Uri feedbackUri = DataUsageFeedback.FEEDBACK_URI.buildUpon()
+ .appendPath(dataId)
+ .appendQueryParameter(DataUsageFeedback.USAGE_TYPE,
+ DataUsageFeedback.USAGE_TYPE_CALL)
+ .build();
+ resolver.update(feedbackUri, new ContentValues(), null, null);
+ }
+
+ /**
+ * Update the normalized phone number for the given dataId in the ContactsProvider, based
+ * on the user's current country.
+ */
+ private static void updateNormalizedNumber(Context context, ContentResolver resolver,
+ String dataId, String number) {
+ if (TextUtils.isEmpty(number) || TextUtils.isEmpty(dataId)) {
+ return;
+ }
+
+ final String countryIso = getCurrentCountryIso(context);
+ if (TextUtils.isEmpty(countryIso)) {
+ return;
+ }
+
+ final String normalizedNumber = PhoneNumberUtils.formatNumberToE164(number,
+ getCurrentCountryIso(context));
+ if (TextUtils.isEmpty(normalizedNumber)) {
+ return;
+ }
+
+ final ContentValues values = new ContentValues();
+ values.put(Phone.NORMALIZED_NUMBER, normalizedNumber);
+ resolver.update(Data.CONTENT_URI, values, Data._ID + "=?", new String[] {dataId});
+ }
+
+ private static String getCurrentCountryIso(Context context) {
+ String countryIso = null;
+ final CountryDetector detector = (CountryDetector) context.getSystemService(
+ Context.COUNTRY_DETECTOR);
+ if (detector != null) {
+ final Country country = detector.detectCountry();
+ if (country != null) {
+ countryIso = country.getCountryIso();
+ }
+ }
+ return countryIso;
+ }
}
}