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 --- .../dialer/calllog/CallLogListItemHelperTest.java | 1 + .../dialer/calllog/PhoneCallDetailsHelperTest.java | 1 + .../dialer/calllog/TestTelecomCallLogCache.java | 60 ---------------------- .../calllogcache/TestTelecomCallLogCache.java | 58 +++++++++++++++++++++ .../tests/calllog/FillCallLogTestActivity.java | 14 +++-- 5 files changed, 66 insertions(+), 68 deletions(-) delete mode 100644 tests/src/com/android/dialer/calllog/TestTelecomCallLogCache.java create mode 100644 tests/src/com/android/dialer/calllog/calllogcache/TestTelecomCallLogCache.java (limited to 'tests/src') 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