From fdb93b7079d522d688ec0ebe58c92d45aee48786 Mon Sep 17 00:00:00 2001 From: Nancy Chen Date: Tue, 22 Dec 2015 11:41:36 -0800 Subject: Make TelecomManager APIs compatible with Lollipop. (1/3) + Add methods to TelecomManagerCompat - Move TelecomManagerCompat to ContactsCommon because it is called within ContactsCommon - Move TestTelecomCallLogCache to the right package so tests pass Bug: 25776171 Change-Id: I1963959292d8038ab505488d831afd06e6fef6d0 --- src/com/android/dialer/SpecialCharSequenceMgr.java | 22 ++++---- .../android/dialer/calllog/PhoneAccountUtils.java | 40 +++++++-------- .../dialer/calllog/calllogcache/CallLogCache.java | 2 +- .../android/dialer/compat/DialerCompatUtils.java | 18 +------ .../dialer/settings/DialerSettingsActivity.java | 15 +++--- src/com/android/dialer/util/TelecomUtil.java | 48 ++++++++--------- .../dialer/calllog/CallLogListItemHelperTest.java | 1 + .../dialer/calllog/PhoneCallDetailsHelperTest.java | 1 + .../dialer/calllog/TestTelecomCallLogCache.java | 60 ---------------------- .../calllogcache/TestTelecomCallLogCache.java | 58 +++++++++++++++++++++ .../tests/calllog/FillCallLogTestActivity.java | 14 +++-- 11 files changed, 126 insertions(+), 153 deletions(-) delete mode 100644 tests/src/com/android/dialer/calllog/TestTelecomCallLogCache.java create mode 100644 tests/src/com/android/dialer/calllog/calllogcache/TestTelecomCallLogCache.java diff --git a/src/com/android/dialer/SpecialCharSequenceMgr.java b/src/com/android/dialer/SpecialCharSequenceMgr.java index c212597f6..4303f3e1f 100644 --- a/src/com/android/dialer/SpecialCharSequenceMgr.java +++ b/src/com/android/dialer/SpecialCharSequenceMgr.java @@ -42,6 +42,7 @@ import android.widget.Toast; import com.android.common.io.MoreCloseables; import com.android.contacts.common.compat.CompatUtils; +import com.android.contacts.common.compat.TelephonyManagerCompat; import com.android.contacts.common.database.NoNullCursorAsyncQueryHandler; import com.android.contacts.common.util.ContactDisplayUtils; import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment; @@ -252,12 +253,10 @@ public class SpecialCharSequenceMgr { TelecomUtil.getDefaultOutgoingPhoneAccount(applicationContext, PhoneAccount.SCHEME_TEL)); - if (!CompatUtils.isMSIMCompatible()) { - handleAdnQuery(handler, sc, Uri.parse("content://icc/adn")); - } else if (subscriptionAccountHandles.size() == 1 || hasUserSelectedDefault) { + if (subscriptionAccountHandles.size() <= 1 || hasUserSelectedDefault) { Uri uri = TelecomUtil.getAdnUriForPhoneAccount(applicationContext, null); handleAdnQuery(handler, sc, uri); - } else if (subscriptionAccountHandles.size() > 1){ + } else { SelectPhoneAccountListener callback = new HandleAdnEntryAccountSelectedCallback( applicationContext, handler, sc); @@ -265,8 +264,6 @@ public class SpecialCharSequenceMgr { subscriptionAccountHandles, callback); dialogFragment.show(((Activity) context).getFragmentManager(), TAG_SELECT_ACCT_FRAGMENT); - } else { - return false; } return true; @@ -305,12 +302,11 @@ public class SpecialCharSequenceMgr { boolean hasUserSelectedDefault = subscriptionAccountHandles.contains( TelecomUtil.getDefaultOutgoingPhoneAccount(context, PhoneAccount.SCHEME_TEL)); - if (!CompatUtils.isMSIMCompatible() || subscriptionAccountHandles.size() == 1 - || hasUserSelectedDefault) { + if (subscriptionAccountHandles.size() <= 1 || hasUserSelectedDefault) { // Don't bring up the dialog for single-SIM or if the default outgoing account is // a subscription account. return TelecomUtil.handleMmi(context, input, null); - } else if (subscriptionAccountHandles.size() > 1){ + } else { SelectPhoneAccountListener listener = new HandleMmiAccountSelectedCallback(context, input); @@ -335,15 +331,17 @@ public class SpecialCharSequenceMgr { R.string.imei : R.string.meid; List deviceIds = new ArrayList(); - if (!CompatUtils.isMSIMCompatible()) { - deviceIds.add(telephonyManager.getDeviceId()); - } else { + if (TelephonyManagerCompat.getPhoneCount(telephonyManager) > 1 && + CompatUtils.isMethodAvailable(TelephonyManagerCompat.TELEPHONY_MANAGER_CLASS, + "getDeviceId", Integer.TYPE)) { for (int slot = 0; slot < telephonyManager.getPhoneCount(); slot++) { String deviceId = telephonyManager.getDeviceId(slot); if (!TextUtils.isEmpty(deviceId)) { deviceIds.add(deviceId); } } + } else { + deviceIds.add(telephonyManager.getDeviceId()); } AlertDialog alert = new AlertDialog.Builder(context) diff --git a/src/com/android/dialer/calllog/PhoneAccountUtils.java b/src/com/android/dialer/calllog/PhoneAccountUtils.java index 7dc329237..8c3985b3f 100644 --- a/src/com/android/dialer/calllog/PhoneAccountUtils.java +++ b/src/com/android/dialer/calllog/PhoneAccountUtils.java @@ -18,11 +18,12 @@ package com.android.dialer.calllog; import android.content.ComponentName; import android.content.Context; +import android.support.annotation.Nullable; import android.telecom.PhoneAccount; import android.telecom.PhoneAccountHandle; -import android.telecom.TelecomManager; import android.text.TextUtils; +import com.android.contacts.common.compat.CompatUtils; import com.android.dialer.util.TelecomUtil; import java.util.ArrayList; @@ -36,14 +37,11 @@ public class PhoneAccountUtils { * Return a list of phone accounts that are subscription/SIM accounts. */ public static List getSubscriptionPhoneAccounts(Context context) { - final TelecomManager telecomManager = - (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); - List subscriptionAccountHandles = new ArrayList(); final List accountHandles = TelecomUtil.getCallCapablePhoneAccounts(context); for (PhoneAccountHandle accountHandle : accountHandles) { - PhoneAccount account = telecomManager.getPhoneAccount(accountHandle); + PhoneAccount account = TelecomUtil.getPhoneAccount(context, accountHandle); if (account.hasCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION)) { subscriptionAccountHandles.add(accountHandle); } @@ -54,7 +52,9 @@ public class PhoneAccountUtils { /** * Compose PhoneAccount object from component name and account id. */ - public static PhoneAccountHandle getAccount(String componentString, String accountId) { + @Nullable + public static PhoneAccountHandle getAccount(@Nullable String componentString, + @Nullable String accountId) { if (TextUtils.isEmpty(componentString) || TextUtils.isEmpty(accountId)) { return null; } @@ -65,7 +65,9 @@ public class PhoneAccountUtils { /** * Extract account label from PhoneAccount object. */ - public static String getAccountLabel(Context context, PhoneAccountHandle accountHandle) { + @Nullable + public static String getAccountLabel(Context context, + @Nullable PhoneAccountHandle accountHandle) { PhoneAccount account = getAccountOrNull(context, accountHandle); if (account != null && account.getLabel() != null) { return account.getLabel().toString(); @@ -76,10 +78,8 @@ public class PhoneAccountUtils { /** * Extract account color from PhoneAccount object. */ - public static int getAccountColor(Context context, PhoneAccountHandle accountHandle) { - TelecomManager telecomManager = - (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); - final PhoneAccount account = telecomManager.getPhoneAccount(accountHandle); + public static int getAccountColor(Context context, @Nullable PhoneAccountHandle accountHandle) { + final PhoneAccount account = TelecomUtil.getPhoneAccount(context, accountHandle); // For single-sim devices the PhoneAccount will be NO_HIGHLIGHT_COLOR by default, so it is // safe to always use the account highlight color. @@ -92,10 +92,8 @@ public class PhoneAccountUtils { * @return {@code true} if call subjects are supported, {@code false} otherwise. */ public static boolean getAccountSupportsCallSubject(Context context, - PhoneAccountHandle accountHandle) { - TelecomManager telecomManager = - (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); - final PhoneAccount account = telecomManager.getPhoneAccount(accountHandle); + @Nullable PhoneAccountHandle accountHandle) { + final PhoneAccount account = TelecomUtil.getPhoneAccount(context, accountHandle); return account == null ? false : account.hasCapabilities(PhoneAccount.CAPABILITY_CALL_SUBJECT); @@ -105,14 +103,12 @@ public class PhoneAccountUtils { * Retrieve the account metadata, but if the account does not exist or the device has only a * single registered and enabled account, return null. */ - static PhoneAccount getAccountOrNull(Context context, - PhoneAccountHandle accountHandle) { - TelecomManager telecomManager = - (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); - final PhoneAccount account = telecomManager.getPhoneAccount(accountHandle); - if (telecomManager.getCallCapablePhoneAccounts().size() <= 1) { + @Nullable + private static PhoneAccount getAccountOrNull(Context context, + @Nullable PhoneAccountHandle accountHandle) { + if (TelecomUtil.getCallCapablePhoneAccounts(context).size() <= 1) { return null; } - return account; + return TelecomUtil.getPhoneAccount(context, accountHandle); } } diff --git a/src/com/android/dialer/calllog/calllogcache/CallLogCache.java b/src/com/android/dialer/calllog/calllogcache/CallLogCache.java index e64c0121d..dc1217cf5 100644 --- a/src/com/android/dialer/calllog/calllogcache/CallLogCache.java +++ b/src/com/android/dialer/calllog/calllogcache/CallLogCache.java @@ -49,7 +49,7 @@ public abstract class CallLogCache { * Return the most compatible version of the TelecomCallLogCache. */ public static CallLogCache getCallLogCache(Context context) { - if (CompatUtils.isMSIMCompatible()) { + if (CompatUtils.isClassAvailable("android.telecom.PhoneAccountHandle")) { return new CallLogCacheLollipopMr1(context); } return new CallLogCacheLollipop(context); diff --git a/src/com/android/dialer/compat/DialerCompatUtils.java b/src/com/android/dialer/compat/DialerCompatUtils.java index 1bcdd14ad..a9c9c5319 100644 --- a/src/com/android/dialer/compat/DialerCompatUtils.java +++ b/src/com/android/dialer/compat/DialerCompatUtils.java @@ -15,22 +15,9 @@ */ package com.android.dialer.compat; -import android.os.Build; - -import com.android.contacts.common.compat.SdkVersionOverride; +import com.android.contacts.common.compat.CompatUtils; public final class DialerCompatUtils { - /** - * Determines if this version is compatible with a default dialer. Can also force the version to - * be lower through SdkVersionOverride. - * - * @return {@code true} if default dialer is a feature on this device, {@code false} otherwise. - */ - public static boolean isDefaultDialerCompatible() { - return SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.LOLLIPOP) - >= Build.VERSION_CODES.M; - } - /** * Determines if this version has access to the * {@link android.provider.CallLog.Calls.CACHED_PHOTO_URI} column @@ -39,7 +26,6 @@ public final class DialerCompatUtils { * {@code false} otherwise */ public static boolean isCallsCachedPhotoUriCompatible() { - return SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.M) - >= Build.VERSION_CODES.M; + return CompatUtils.isMarshmallowCompatible(); } } \ No newline at end of file diff --git a/src/com/android/dialer/settings/DialerSettingsActivity.java b/src/com/android/dialer/settings/DialerSettingsActivity.java index 13d196595..a18715760 100644 --- a/src/com/android/dialer/settings/DialerSettingsActivity.java +++ b/src/com/android/dialer/settings/DialerSettingsActivity.java @@ -30,6 +30,7 @@ import android.widget.Toast; import com.android.contacts.common.compat.CompatUtils; import com.android.contacts.common.compat.SdkVersionOverride; +import com.android.contacts.common.compat.TelephonyManagerCompat; import com.android.dialer.R; import com.android.dialer.compat.SettingsCompat; import com.android.dialer.compat.UserManagerCompat; @@ -59,8 +60,7 @@ public class DialerSettingsActivity extends AppCompatPreferenceActivity { soundSettingsHeader.id = R.id.settings_header_sounds_and_vibration; target.add(soundSettingsHeader); - if (SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.M) - >= Build.VERSION_CODES.M) { + if (CompatUtils.isMarshmallowCompatible()) { Header quickResponseSettingsHeader = new Header(); Intent quickResponseSettingsIntent = new Intent(TelecomManager.ACTION_SHOW_RESPOND_VIA_SMS_SETTINGS); @@ -69,7 +69,6 @@ public class DialerSettingsActivity extends AppCompatPreferenceActivity { target.add(quickResponseSettingsHeader); } - TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); @@ -78,7 +77,8 @@ public class DialerSettingsActivity extends AppCompatPreferenceActivity { // primary user and there are multiple SIMs. In N+, "Calling accounts" is shown whenever // "Call Settings" is not shown. boolean isPrimaryUser = isPrimaryUser(); - if (isPrimaryUser && telephonyManager.getPhoneCount() <= 1) { + if (isPrimaryUser + && TelephonyManagerCompat.getPhoneCount(telephonyManager) <= 1) { Header callSettingsHeader = new Header(); Intent callSettingsIntent = new Intent(TelecomManager.ACTION_SHOW_CALL_SETTINGS); callSettingsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); @@ -102,10 +102,9 @@ public class DialerSettingsActivity extends AppCompatPreferenceActivity { blockedCallsHeader.intent = new Intent(this, BlockedNumbersSettingsActivity.class); target.add(blockedCallsHeader); - if (SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.M) - >= Build.VERSION_CODES.M - && (telephonyManager.isTtyModeSupported() - || telephonyManager.isHearingAidCompatibilitySupported())) { + if (TelephonyManagerCompat.isTtyModeSupported(telephonyManager) + || TelephonyManagerCompat + .isHearingAidCompatibilitySupported(telephonyManager)) { Header accessibilitySettingsHeader = new Header(); Intent accessibilitySettingsIntent = new Intent(TelecomManager.ACTION_SHOW_CALL_ACCESSIBILITY_SETTINGS); diff --git a/src/com/android/dialer/util/TelecomUtil.java b/src/com/android/dialer/util/TelecomUtil.java index 1792cd04a..bd201c459 100644 --- a/src/com/android/dialer/util/TelecomUtil.java +++ b/src/com/android/dialer/util/TelecomUtil.java @@ -23,7 +23,9 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; import android.provider.CallLog.Calls; +import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; +import android.telecom.PhoneAccount; import android.telecom.PhoneAccountHandle; import android.telecom.TelecomManager; import android.telephony.PhoneNumberUtils; @@ -83,7 +85,8 @@ public class TelecomUtil { public static Uri getAdnUriForPhoneAccount(Context context, PhoneAccountHandle handle) { if (hasModifyPhoneStatePermission(context)) { try { - return getTelecomManager(context).getAdnUriForPhoneAccount(handle); + return TelecomManagerCompat.getAdnUriForPhoneAccount( + getTelecomManager(context), handle); } catch (SecurityException e) { Log.w(TAG, "TelecomManager.getAdnUriForPhoneAccount called without permission."); } @@ -95,11 +98,8 @@ public class TelecomUtil { PhoneAccountHandle handle) { if (hasModifyPhoneStatePermission(context)) { try { - if (handle == null) { - return getTelecomManager(context).handleMmi(dialString); - } else { - return getTelecomManager(context).handleMmi(dialString, handle); - } + return TelecomManagerCompat.handleMmi( + getTelecomManager(context), dialString, handle); } catch (SecurityException e) { Log.w(TAG, "TelecomManager.handleMmi called without permission."); } @@ -107,17 +107,23 @@ public class TelecomUtil { return false; } + @Nullable public static PhoneAccountHandle getDefaultOutgoingPhoneAccount(Context context, String uriScheme) { if (hasReadPhoneStatePermission(context)) { - return getTelecomManager(context).getDefaultOutgoingPhoneAccount(uriScheme); + return TelecomManagerCompat.getDefaultOutgoingPhoneAccount( + getTelecomManager(context), uriScheme); } return null; } + public static PhoneAccount getPhoneAccount(Context context, PhoneAccountHandle handle) { + return TelecomManagerCompat.getPhoneAccount(getTelecomManager(context), handle); + } + public static List getCallCapablePhoneAccounts(Context context) { - if (hasReadPhoneStatePermission(context) && CompatUtils.isMSIMCompatible()) { - return getTelecomManager(context).getCallCapablePhoneAccounts(); + if (hasReadPhoneStatePermission(context)) { + return TelecomManagerCompat.getCallCapablePhoneAccounts(getTelecomManager(context)); } return new ArrayList<>(); } @@ -132,22 +138,17 @@ public class TelecomUtil { public static boolean isVoicemailNumber(Context context, PhoneAccountHandle accountHandle, String number) { if (hasReadPhoneStatePermission(context)) { - if (CompatUtils.isMSIMCompatible()) { - return getTelecomManager(context).isVoiceMailNumber(accountHandle, number); - } else { - return PhoneNumberUtils.isVoiceMailNumber(number); - } + return TelecomManagerCompat.isVoiceMailNumber(getTelecomManager(context), + accountHandle, number); } return false; } + @Nullable public static String getVoicemailNumber(Context context, PhoneAccountHandle accountHandle) { if (hasReadPhoneStatePermission(context)) { - if (CompatUtils.isMSIMCompatible()) { - return getTelecomManager(context).getVoiceMailNumber(accountHandle); - } else { - return getTelephonyManager(context).getVoiceMailNumber(); - } + return TelecomManagerCompat.getVoiceMailNumber(getTelecomManager(context), + getTelephonyManager(context), accountHandle); } return null; } @@ -156,8 +157,7 @@ public class TelecomUtil { * Tries to place a call using the {@link TelecomManager}. * * @param activity a valid activity. - * @param address Handle to call. - * @param extras Bundle of extras to attach to the call intent. + * @param intent the call intent. * * @return {@code true} if we successfully attempted to place the call, {@code false} if it * failed due to a permission check. @@ -202,12 +202,8 @@ public class TelecomUtil { } public static boolean isDefaultDialer(Context context) { - if (!DialerCompatUtils.isDefaultDialerCompatible()) { - return false; - } - final boolean result = TextUtils.equals(context.getPackageName(), - getTelecomManager(context).getDefaultDialerPackage()); + TelecomManagerCompat.getDefaultDialerPackage(getTelecomManager(context))); if (result) { sWarningLogged = false; } else { diff --git a/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java b/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java index a97fce3f7..28caed469 100644 --- a/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java +++ b/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java @@ -26,6 +26,7 @@ import android.view.View; import com.android.contacts.common.CallUtil; import com.android.dialer.PhoneCallDetails; import com.android.dialer.R; +import com.android.dialer.calllog.calllogcache.TestTelecomCallLogCache; import com.android.dialer.util.AppCompatConstants; /** diff --git a/tests/src/com/android/dialer/calllog/PhoneCallDetailsHelperTest.java b/tests/src/com/android/dialer/calllog/PhoneCallDetailsHelperTest.java index 23ee7b311..b6202b904 100644 --- a/tests/src/com/android/dialer/calllog/PhoneCallDetailsHelperTest.java +++ b/tests/src/com/android/dialer/calllog/PhoneCallDetailsHelperTest.java @@ -28,6 +28,7 @@ import android.widget.TextView; import com.android.dialer.PhoneCallDetails; import com.android.dialer.R; +import com.android.dialer.calllog.calllogcache.TestTelecomCallLogCache; import com.android.dialer.util.AppCompatConstants; import com.android.dialer.util.LocaleTestUtils; diff --git a/tests/src/com/android/dialer/calllog/TestTelecomCallLogCache.java b/tests/src/com/android/dialer/calllog/TestTelecomCallLogCache.java deleted file mode 100644 index fcf988412..000000000 --- a/tests/src/com/android/dialer/calllog/TestTelecomCallLogCache.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -package com.android.dialer.calllog; - -import android.content.Context; -import android.telecom.PhoneAccount; -import android.telecom.PhoneAccountHandle; - -import com.android.dialer.calllog.calllogcache.CallLogCache; - -/** - * Modified version of {@link com.android.dialer.calllog.calllogcache.CallLogCache} to be used in - * tests that allows injecting the voicemail number. - * - * NOTE: This tests the pre-LMR1 version because currently none of the tests involve multi-SIM, - * but... - * TODO: write tests to test multi-SIM functionality in TelecomCallLogCache. - */ -public final class TestTelecomCallLogCache extends CallLogCache { - private CharSequence mVoicemailNumber; - - public TestTelecomCallLogCache(Context context, CharSequence voicemailNumber) { - super(context); - mVoicemailNumber = voicemailNumber; - } - - @Override - public boolean isVoicemailNumber(PhoneAccountHandle accountHandle, CharSequence number) { - return mVoicemailNumber.equals(number); - } - - @Override - public String getAccountLabel(PhoneAccountHandle accountHandle) { - return null; - } - - @Override - public int getAccountColor(PhoneAccountHandle accountHandle) { - return PhoneAccount.NO_HIGHLIGHT_COLOR; - } - - @Override - public boolean doesAccountSupportCallSubject(PhoneAccountHandle accountHandle) { - return false; - } -} diff --git a/tests/src/com/android/dialer/calllog/calllogcache/TestTelecomCallLogCache.java b/tests/src/com/android/dialer/calllog/calllogcache/TestTelecomCallLogCache.java new file mode 100644 index 000000000..077a498c9 --- /dev/null +++ b/tests/src/com/android/dialer/calllog/calllogcache/TestTelecomCallLogCache.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.dialer.calllog.calllogcache; + +import android.content.Context; +import android.telecom.PhoneAccount; +import android.telecom.PhoneAccountHandle; + +/** + * Modified version of {@link com.android.dialer.calllog.calllogcache.CallLogCache} to be used in + * tests that allows injecting the voicemail number. + * + * NOTE: This tests the pre-LMR1 version because currently none of the tests involve multi-SIM, + * but... + * TODO: write tests to test multi-SIM functionality in TelecomCallLogCache. + */ +public final class TestTelecomCallLogCache extends CallLogCache { + private CharSequence mVoicemailNumber; + + public TestTelecomCallLogCache(Context context, CharSequence voicemailNumber) { + super(context); + mVoicemailNumber = voicemailNumber; + } + + @Override + public boolean isVoicemailNumber(PhoneAccountHandle accountHandle, CharSequence number) { + return mVoicemailNumber.equals(number); + } + + @Override + public String getAccountLabel(PhoneAccountHandle accountHandle) { + return null; + } + + @Override + public int getAccountColor(PhoneAccountHandle accountHandle) { + return PhoneAccount.NO_HIGHLIGHT_COLOR; + } + + @Override + public boolean doesAccountSupportCallSubject(PhoneAccountHandle accountHandle) { + return false; + } +} diff --git a/tests/src/com/android/dialer/tests/calllog/FillCallLogTestActivity.java b/tests/src/com/android/dialer/tests/calllog/FillCallLogTestActivity.java index ae0dba822..da41dfce4 100644 --- a/tests/src/com/android/dialer/tests/calllog/FillCallLogTestActivity.java +++ b/tests/src/com/android/dialer/tests/calllog/FillCallLogTestActivity.java @@ -39,7 +39,6 @@ import android.provider.VoicemailContract.Status; import android.provider.VoicemailContract.Voicemails; import android.telecom.PhoneAccount; import android.telecom.PhoneAccountHandle; -import android.telecom.TelecomManager; import android.text.Editable; import android.text.TextWatcher; import android.text.format.DateFormat; @@ -56,8 +55,10 @@ import android.widget.TextView; import android.widget.TimePicker; import android.widget.Toast; +import com.android.contacts.common.compat.telecom.TelecomManagerCompat; import com.android.dialer.tests.R; import com.android.dialer.util.AppCompatConstants; +import com.android.dialer.util.TelecomUtil; import java.util.Calendar; import java.util.List; @@ -439,9 +440,8 @@ public class FillCallLogTestActivity extends Activity { } private PhoneAccountHandle getManualAccount() { - TelecomManager telecomManager = - (TelecomManager) getSystemService(Context.TELECOM_SERVICE); - List accountHandles = telecomManager.getCallCapablePhoneAccounts(); + List accountHandles = TelecomUtil.getCallCapablePhoneAccounts(this); + //TODO: hide the corresponding radio buttons if no accounts are available. if (mAccount0.isChecked()) { return accountHandles.get(0); } else if (mAccount1.isChecked()){ @@ -567,11 +567,9 @@ public class FillCallLogTestActivity extends Activity { final ContentResolver resolver = getContentResolver(); int numberPresentation = Calls.PRESENTATION_ALLOWED; - TelecomManager tm = (TelecomManager) getSystemService(Context.TELECOM_SERVICE); - String accountAddress = null; - if (tm != null && accountHandle != null) { - PhoneAccount account = tm.getPhoneAccount(accountHandle); + if (accountHandle != null) { + PhoneAccount account = TelecomUtil.getPhoneAccount(this, accountHandle); if (account != null) { Uri address = account.getSubscriptionAddress(); if (address != null) { -- cgit v1.2.3