Loading core/java/android/provider/CallLog.java +56 −7 Original line number Original line Diff line number Diff line Loading @@ -24,13 +24,17 @@ import android.content.Context; import android.content.Intent; import android.content.Intent; import android.content.pm.UserInfo; import android.content.pm.UserInfo; import android.database.Cursor; import android.database.Cursor; import android.location.Country; import android.location.CountryDetector; import android.net.Uri; import android.net.Uri; import android.os.UserHandle; import android.os.UserHandle; import android.os.UserManager; import android.os.UserManager; import android.provider.ContactsContract.CommonDataKinds.Callable; import android.provider.ContactsContract.CommonDataKinds.Callable; import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.ContactsContract.Data; import android.provider.ContactsContract.DataUsageFeedback; import android.provider.ContactsContract.DataUsageFeedback; import android.telecom.PhoneAccountHandle; import android.telecom.PhoneAccountHandle; import android.telephony.PhoneNumberUtils; import android.text.TextUtils; import android.text.TextUtils; import com.android.internal.telephony.CallerInfo; import com.android.internal.telephony.CallerInfo; Loading Loading @@ -404,7 +408,6 @@ public class CallLog { * @param accountHandle The accountHandle object identifying the provider of the call * @param accountHandle The accountHandle object identifying the provider of the call * @param start time stamp for the call in milliseconds * @param start time stamp for the call in milliseconds * @param duration call duration in seconds * @param duration call duration in seconds * @param subId the subscription id. * @param dataUsage data usage for the call in bytes, null if data usage was not tracked for * @param dataUsage data usage for the call in bytes, null if data usage was not tracked for * the call. * the call. * @param addForAllUsers If true, the call is added to the call log of all currently * @param addForAllUsers If true, the call is added to the call log of all currently Loading Loading @@ -503,12 +506,13 @@ public class CallLog { if (cursor != null) { if (cursor != null) { try { try { if (cursor.getCount() > 0 && cursor.moveToFirst()) { if (cursor.getCount() > 0 && cursor.moveToFirst()) { final Uri feedbackUri = DataUsageFeedback.FEEDBACK_URI.buildUpon() final String dataId = cursor.getString(0); .appendPath(cursor.getString(0)) updateDataUsageStatForData(resolver, dataId); .appendQueryParameter(DataUsageFeedback.USAGE_TYPE, if (duration >= MIN_DURATION_FOR_NORMALIZED_NUMBER_UPDATE_MS DataUsageFeedback.USAGE_TYPE_CALL) && callType == Calls.OUTGOING_TYPE .build(); && TextUtils.isEmpty(ci.normalizedNumber)) { resolver.update(feedbackUri, new ContentValues(), null, null); updateNormalizedNumber(context, resolver, dataId, number); } } } } finally { } finally { cursor.close(); cursor.close(); Loading Loading @@ -581,5 +585,50 @@ public class CallLog { + " LIMIT -1 OFFSET 500)", null); + " LIMIT -1 OFFSET 500)", null); return result; 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; } } } } } Loading
core/java/android/provider/CallLog.java +56 −7 Original line number Original line Diff line number Diff line Loading @@ -24,13 +24,17 @@ import android.content.Context; import android.content.Intent; import android.content.Intent; import android.content.pm.UserInfo; import android.content.pm.UserInfo; import android.database.Cursor; import android.database.Cursor; import android.location.Country; import android.location.CountryDetector; import android.net.Uri; import android.net.Uri; import android.os.UserHandle; import android.os.UserHandle; import android.os.UserManager; import android.os.UserManager; import android.provider.ContactsContract.CommonDataKinds.Callable; import android.provider.ContactsContract.CommonDataKinds.Callable; import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.ContactsContract.Data; import android.provider.ContactsContract.DataUsageFeedback; import android.provider.ContactsContract.DataUsageFeedback; import android.telecom.PhoneAccountHandle; import android.telecom.PhoneAccountHandle; import android.telephony.PhoneNumberUtils; import android.text.TextUtils; import android.text.TextUtils; import com.android.internal.telephony.CallerInfo; import com.android.internal.telephony.CallerInfo; Loading Loading @@ -404,7 +408,6 @@ public class CallLog { * @param accountHandle The accountHandle object identifying the provider of the call * @param accountHandle The accountHandle object identifying the provider of the call * @param start time stamp for the call in milliseconds * @param start time stamp for the call in milliseconds * @param duration call duration in seconds * @param duration call duration in seconds * @param subId the subscription id. * @param dataUsage data usage for the call in bytes, null if data usage was not tracked for * @param dataUsage data usage for the call in bytes, null if data usage was not tracked for * the call. * the call. * @param addForAllUsers If true, the call is added to the call log of all currently * @param addForAllUsers If true, the call is added to the call log of all currently Loading Loading @@ -503,12 +506,13 @@ public class CallLog { if (cursor != null) { if (cursor != null) { try { try { if (cursor.getCount() > 0 && cursor.moveToFirst()) { if (cursor.getCount() > 0 && cursor.moveToFirst()) { final Uri feedbackUri = DataUsageFeedback.FEEDBACK_URI.buildUpon() final String dataId = cursor.getString(0); .appendPath(cursor.getString(0)) updateDataUsageStatForData(resolver, dataId); .appendQueryParameter(DataUsageFeedback.USAGE_TYPE, if (duration >= MIN_DURATION_FOR_NORMALIZED_NUMBER_UPDATE_MS DataUsageFeedback.USAGE_TYPE_CALL) && callType == Calls.OUTGOING_TYPE .build(); && TextUtils.isEmpty(ci.normalizedNumber)) { resolver.update(feedbackUri, new ContentValues(), null, null); updateNormalizedNumber(context, resolver, dataId, number); } } } } finally { } finally { cursor.close(); cursor.close(); Loading Loading @@ -581,5 +585,50 @@ public class CallLog { + " LIMIT -1 OFFSET 500)", null); + " LIMIT -1 OFFSET 500)", null); return result; 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; } } } } }