From 27ef1e6c1ae0a0b6b15c7ff83cbb7396d7bd976e Mon Sep 17 00:00:00 2001 From: Christine Chen Date: Fri, 18 Oct 2013 16:50:13 -0700 Subject: Removing private dependencies in InCallUi - This CL addresses most of the private API calls in InCallUi. - This CL removed Android.mk as we are not building InCallUi.apk separately anymore. Changes to make an unbundled app will go into Dialer, GoogleDialer, and Contacts apps' makefiles. - Separated CLs will add libphonenumber, libgeocoding, and util classes for TelephonyManager and PhoneNumberUtils. - The only thing left for InCallUi is to unbundle ProximitySensor. Currently PowerManager's functions to deal with the proximity sensor are all private. It will take a rather substaintial amount of work to implement the proximity sensor functions ourselves (read proximity sensor event values, ask the screen to turn on, etc.). So we should rather push to get those functions into the public API. Change-Id: I18b3c52adb41c6131c1eb3c07ce32ebd56d0cc59 --- .../com/android/incallui/AudioModeProvider.java | 3 +- .../com/android/incallui/CallButtonPresenter.java | 19 ++++-- .../com/android/incallui/CallHandlerService.java | 5 +- InCallUI/src/com/android/incallui/CallList.java | 8 +-- InCallUI/src/com/android/incallui/CallerInfo.java | 67 ++++++---------------- .../com/android/incallui/CallerInfoAsyncQuery.java | 19 +++--- .../src/com/android/incallui/ContactInfoCache.java | 10 ++-- .../src/com/android/incallui/InCallActivity.java | 2 +- .../src/com/android/incallui/InCallPresenter.java | 2 +- 9 files changed, 61 insertions(+), 74 deletions(-) (limited to 'InCallUI/src') diff --git a/InCallUI/src/com/android/incallui/AudioModeProvider.java b/InCallUI/src/com/android/incallui/AudioModeProvider.java index 870087565..407aa3a0f 100644 --- a/InCallUI/src/com/android/incallui/AudioModeProvider.java +++ b/InCallUI/src/com/android/incallui/AudioModeProvider.java @@ -16,13 +16,12 @@ package com.android.incallui; -import com.google.android.collect.Lists; +import com.google.common.collect.Lists; import com.android.services.telephony.common.AudioMode; import java.util.List; - /** * Proxy class for getting and setting the audio mode. */ diff --git a/InCallUI/src/com/android/incallui/CallButtonPresenter.java b/InCallUI/src/com/android/incallui/CallButtonPresenter.java index be257378f..67a642b06 100644 --- a/InCallUI/src/com/android/incallui/CallButtonPresenter.java +++ b/InCallUI/src/com/android/incallui/CallButtonPresenter.java @@ -16,6 +16,8 @@ package com.android.incallui; +import com.android.contacts.common.util.PhoneNumberHelper; +import com.android.contacts.common.util.TelephonyManagerUtils; import com.android.incallui.AudioModeProvider.AudioModeListener; import com.android.incallui.InCallPresenter.InCallState; import com.android.incallui.InCallPresenter.InCallStateListener; @@ -24,7 +26,7 @@ import com.android.services.telephony.common.AudioMode; import com.android.services.telephony.common.Call; import com.android.services.telephony.common.Call.Capabilities; -import android.telephony.PhoneNumberUtils; +import android.app.Fragment; /** * Logic for call buttons. @@ -66,6 +68,7 @@ public class CallButtonPresenter extends Presenter mCallMap = Maps.newHashMap(); private final HashMap> mCallTextReponsesMap = Maps.newHashMap(); - private final Set mListeners = Sets.newArraySet(); + private final Set mListeners = Sets.newHashSet(); private final HashMap> mCallUpdateListenerMap = Maps .newHashMap(); diff --git a/InCallUI/src/com/android/incallui/CallerInfo.java b/InCallUI/src/com/android/incallui/CallerInfo.java index ea6ebd9f3..2e89e48d9 100644 --- a/InCallUI/src/com/android/incallui/CallerInfo.java +++ b/InCallUI/src/com/android/incallui/CallerInfo.java @@ -16,29 +16,27 @@ package com.android.incallui; +import com.android.contacts.common.util.PhoneNumberHelper; +import com.android.contacts.common.util.TelephonyManagerUtils; import android.content.Context; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; -import android.location.Country; -import android.location.CountryDetector; import android.net.Uri; import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.ContactsContract.Data; import android.provider.ContactsContract.PhoneLookup; import android.provider.ContactsContract.RawContacts; import android.telephony.PhoneNumberUtils; -import android.telephony.TelephonyManager; import android.text.TextUtils; -import com.android.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder; -import com.android.i18n.phonenumbers.NumberParseException; -import com.android.i18n.phonenumbers.PhoneNumberUtil; -import com.android.i18n.phonenumbers.Phonenumber.PhoneNumber; +import com.google.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder; +import com.google.i18n.phonenumbers.NumberParseException; +import com.google.i18n.phonenumbers.PhoneNumberUtil; +import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; import java.util.Locale; - /** * Looks up caller information for the given phone number. * @@ -195,7 +193,7 @@ public class CallerInfo { if (typeColumnIndex != -1) { info.numberType = cursor.getInt(typeColumnIndex); info.numberLabel = cursor.getString(columnIndex); - info.phoneLabel = Phone.getDisplayLabel(context, + info.phoneLabel = Phone.getTypeLabel(context.getResources(), info.numberType, info.numberLabel) .toString(); } @@ -274,10 +272,10 @@ public class CallerInfo { // Change the callerInfo number ONLY if it is an emergency number // or if it is the voicemail number. If it is either, take a // shortcut and skip the query. - if (PhoneNumberUtils.isLocalEmergencyNumber(number, context)) { + if (PhoneNumberHelper.isLocalEmergencyNumber(number, context)) { return new CallerInfo().markAsEmergency(context); - } else if (PhoneNumberUtils.isVoiceMailNumber(number)) { - return new CallerInfo().markAsVoiceMail(); + } else if (TelephonyManagerUtils.isVoiceMailNumber(number, context)) { + return new CallerInfo().markAsVoiceMail(context); } Uri contactUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)); @@ -307,8 +305,8 @@ public class CallerInfo { static CallerInfo doSecondaryLookupIfNecessary(Context context, String number, CallerInfo previousResult) { if (!previousResult.contactExists - && PhoneNumberUtils.isUriNumber(number)) { - String username = PhoneNumberUtils.getUsernameFromUriNumber(number); + && PhoneNumberHelper.isUriNumber(number)) { + String username = PhoneNumberHelper.getUsernameFromUriNumber(number); if (PhoneNumberUtils.isGlobalPhoneNumber(username)) { previousResult = getCallerInfo(context, Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, @@ -396,13 +394,14 @@ public class CallerInfo { */ // TODO: As in the emergency number handling, we end up writing a // string in the phone number field. - /* package */ CallerInfo markAsVoiceMail() { + /* package */ CallerInfo markAsVoiceMail(Context context) { mIsVoiceMail = true; try { - String voiceMailLabel = TelephonyManager.getDefault().getVoiceMailAlphaTag(); - - phoneNumber = voiceMailLabel; + // For voicemail calls, we display the voice mail tag + // instead of the real phone number in the "number" + // field. + phoneNumber = TelephonyManagerUtils.getVoiceMailAlphaTag(context); } catch (SecurityException se) { // Should never happen: if this process does not have // permission to retrieve VM tag, it should not have @@ -534,7 +533,7 @@ public class CallerInfo { PhoneNumberOfflineGeocoder geocoder = PhoneNumberOfflineGeocoder.getInstance(); Locale locale = context.getResources().getConfiguration().locale; - String countryIso = getCurrentCountryIso(context, locale); + String countryIso = TelephonyManagerUtils.getCurrentCountryIso(context, locale); PhoneNumber pn = null; try { Log.v(TAG, "parsing '" + number @@ -550,37 +549,9 @@ public class CallerInfo { String description = geocoder.getDescriptionForNumber(pn, locale); Log.v(TAG, "- got description: '" + description + "'"); return description; - } else { - return null; } - } - - /** - * @return The ISO 3166-1 two letters country code of the country the user - * is in. - */ - private static String getCurrentCountryIso(Context context, Locale locale) { - String countryIso = null; - CountryDetector detector = (CountryDetector) context.getSystemService( - Context.COUNTRY_DETECTOR); - if (detector != null) { - Country country = detector.detectCountry(); - if (country != null) { - countryIso = country.getCountryIso(); - } else { - Log.e(TAG, "CountryDetector.detectCountry() returned null."); - } - } - if (countryIso == null) { - countryIso = locale.getCountry(); - Log.w(TAG, "No CountryDetector; falling back to countryIso based on locale: " - + countryIso); - } - return countryIso; - } - protected static String getCurrentCountryIso(Context context) { - return getCurrentCountryIso(context, Locale.getDefault()); + return null; } /** diff --git a/InCallUI/src/com/android/incallui/CallerInfoAsyncQuery.java b/InCallUI/src/com/android/incallui/CallerInfoAsyncQuery.java index c09baf210..a186d37fe 100644 --- a/InCallUI/src/com/android/incallui/CallerInfoAsyncQuery.java +++ b/InCallUI/src/com/android/incallui/CallerInfoAsyncQuery.java @@ -27,9 +27,13 @@ import android.os.Message; import android.provider.ContactsContract.CommonDataKinds.SipAddress; import android.provider.ContactsContract.Data; import android.provider.ContactsContract.PhoneLookup; -import android.telephony.PhoneNumberUtils; import android.text.TextUtils; +import com.android.contacts.common.util.PhoneNumberHelper; +import com.android.contacts.common.util.TelephonyManagerUtils; + +import java.util.Locale; + /** * Helper class to make it easier to run asynchronous caller-id lookup queries. * @see CallerInfo @@ -231,7 +235,7 @@ public class CallerInfoAsyncQuery { // comments at the top of CallerInfo class). mCallerInfo = new CallerInfo().markAsEmergency(mQueryContext); } else if (cw.event == EVENT_VOICEMAIL_NUMBER) { - mCallerInfo = new CallerInfo().markAsVoiceMail(); + mCallerInfo = new CallerInfo().markAsVoiceMail(mQueryContext); } else { mCallerInfo = CallerInfo.getCallerInfo(mQueryContext, mQueryUri, cursor); Log.d(this, "==> Got mCallerInfo: " + mCallerInfo); @@ -268,9 +272,10 @@ public class CallerInfoAsyncQuery { // Use the number entered by the user for display. if (!TextUtils.isEmpty(cw.number)) { - mCallerInfo.phoneNumber = PhoneNumberUtils.formatNumber(cw.number, + mCallerInfo.phoneNumber = PhoneNumberHelper.formatNumber(cw.number, mCallerInfo.normalizedNumber, - CallerInfo.getCurrentCountryIso(mQueryContext)); + TelephonyManagerUtils.getCurrentCountryIso(mQueryContext, + Locale.getDefault())); } } @@ -343,7 +348,7 @@ public class CallerInfoAsyncQuery { String selection; String[] selectionArgs; - if (PhoneNumberUtils.isUriNumber(number)) { + if (PhoneNumberHelper.isUriNumber(number)) { // "number" is really a SIP address. Log.d(LOG_TAG, " - Treating number as a SIP address: " + /* number */"xxxxxxx"); @@ -396,9 +401,9 @@ public class CallerInfoAsyncQuery { cw.number = number; // check to see if these are recognized numbers, and use shortcuts if we can. - if (PhoneNumberUtils.isLocalEmergencyNumber(number, context)) { + if (PhoneNumberHelper.isLocalEmergencyNumber(number, context)) { cw.event = EVENT_EMERGENCY_NUMBER; - } else if (PhoneNumberUtils.isVoiceMailNumber(number)) { + } else if (TelephonyManagerUtils.isVoiceMailNumber(number, context)) { cw.event = EVENT_VOICEMAIL_NUMBER; } else { cw.event = EVENT_NEW_QUERY; diff --git a/InCallUI/src/com/android/incallui/ContactInfoCache.java b/InCallUI/src/com/android/incallui/ContactInfoCache.java index 45a38c7cf..c950ed417 100644 --- a/InCallUI/src/com/android/incallui/ContactInfoCache.java +++ b/InCallUI/src/com/android/incallui/ContactInfoCache.java @@ -25,17 +25,17 @@ import android.net.Uri; import android.os.Looper; import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.CommonDataKinds.Phone; -import android.telephony.PhoneNumberUtils; import android.text.TextUtils; +import com.android.contacts.common.util.PhoneNumberHelper; import com.android.incallui.service.PhoneNumberService; import com.android.incalluibind.ServiceFactory; import com.android.services.telephony.common.Call; import com.android.services.telephony.common.CallIdentification; import com.android.services.telephony.common.MoreStrings; -import com.google.android.collect.Lists; -import com.google.android.collect.Maps; -import com.google.android.collect.Sets; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; import com.google.common.base.Objects; import com.google.common.base.Preconditions; @@ -375,7 +375,7 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete String number = info.phoneNumber; if (!TextUtils.isEmpty(number)) { - isSipCall = PhoneNumberUtils.isUriNumber(number); + isSipCall = PhoneNumberHelper.isUriNumber(number); if (number.startsWith("sip:")) { number = number.substring(4); } diff --git a/InCallUI/src/com/android/incallui/InCallActivity.java b/InCallUI/src/com/android/incallui/InCallActivity.java index 58db132a6..d018b9d8a 100644 --- a/InCallUI/src/com/android/incallui/InCallActivity.java +++ b/InCallUI/src/com/android/incallui/InCallActivity.java @@ -259,7 +259,7 @@ public class InCallActivity extends Activity { // Dump starting from the top-level view of the entire activity: Window w = this.getWindow(); View decorView = w.getDecorView(); - decorView.debug(); + Log.d(this, "View dump:" + decorView); return true; } break; diff --git a/InCallUI/src/com/android/incallui/InCallPresenter.java b/InCallUI/src/com/android/incallui/InCallPresenter.java index 5830e726c..27dd569fc 100644 --- a/InCallUI/src/com/android/incallui/InCallPresenter.java +++ b/InCallUI/src/com/android/incallui/InCallPresenter.java @@ -17,7 +17,7 @@ package com.android.incallui; import com.android.incallui.service.PhoneNumberService; -import com.google.android.collect.Sets; +import com.google.common.collect.Sets; import com.google.common.base.Preconditions; import android.content.Context; -- cgit v1.2.3