From 16b68491261362737752e6babc95f89e2b468f49 Mon Sep 17 00:00:00 2001 From: Jay Shrauner Date: Thu, 27 Aug 2015 16:24:40 -0700 Subject: Unbundled build fixes for tests Build tests against current SDK. Use android-support-test instead of android.test.runner. Temporarily disable ContextMenuBuilder tests. Use internal copy of LaunchPerformanceBase. Use reflection to call CursorLoader.waitForLoader. Make local copy of android.provider.CallLog.addCall. Bug:23642167 Change-Id: I6b5901f60cd28cdee4857d9e66696a5c66efcd20 (cherry picked from commit 81b66b8ef878e6209e6f7dfc011e41fe806ec099) --- tests/Android.mk | 4 +- .../com/android/dialer/CallDetailActivityTest.java | 9 +-- .../android/dialer/DialerLaunchPerformance.java | 3 +- .../interactions/PhoneNumberInteractionTest.java | 24 +++++-- .../tests/calllog/FillCallLogTestActivity.java | 74 +++++++++++++++++++++- .../dialer/voicemail/VoicemailPlaybackTest.java | 3 +- 6 files changed, 102 insertions(+), 15 deletions(-) diff --git a/tests/Android.mk b/tests/Android.mk index 30c6286c6..21beca8fd 100644 --- a/tests/Android.mk +++ b/tests/Android.mk @@ -5,7 +5,7 @@ include $(CLEAR_VARS) LOCAL_MODULE_TAGS := tests LOCAL_CERTIFICATE := shared -LOCAL_JAVA_LIBRARIES := android.test.runner +LOCAL_STATIC_JAVA_LIBRARIES := android-support-test # Include all test java files. LOCAL_SRC_FILES := $(call all-java-files-under, src) @@ -20,4 +20,6 @@ LOCAL_PACKAGE_NAME := DialerTests LOCAL_INSTRUMENTATION_FOR := Dialer +LOCAL_SDK_VERSION := current + include $(BUILD_PACKAGE) diff --git a/tests/src/com/android/dialer/CallDetailActivityTest.java b/tests/src/com/android/dialer/CallDetailActivityTest.java index 3b6b61141..c87424482 100644 --- a/tests/src/com/android/dialer/CallDetailActivityTest.java +++ b/tests/src/com/android/dialer/CallDetailActivityTest.java @@ -34,7 +34,7 @@ import android.widget.TextView; import com.android.dialer.calllog.CallLogAsyncTaskUtil; import com.android.dialer.util.AsyncTaskExecutors; import com.android.dialer.util.FakeAsyncTaskExecutor; -import com.android.internal.view.menu.ContextMenuBuilder; +// import com.android.internal.view.menu.ContextMenuBuilder; /** * Unit tests for the {@link CallDetailActivity}. NOTE: The screen needs to be on for the @@ -86,7 +86,6 @@ public class CallDetailActivityTest extends ActivityInstrumentationTestCase2 * See http://b/5054103. - */ public void testVoicemailDoesNotHaveRemoveFromCallLog() throws Throwable { setActivityIntentForTestVoicemailEntry(); startActivityUnderTest(); @@ -98,10 +97,10 @@ public class CallDetailActivityTest extends ActivityInstrumentationTestCase2 phoneList) { this.mPhoneList = phoneList; } + + public void waitForLoader() { + final CursorLoader loader = getLoader(); + try { + final Method waitMethod = CursorLoader.class.getMethod("waitForLoader"); + waitMethod.invoke(loader, null); + } catch(Exception e) { + // ignore + } + } } private ContactsMockContext mContext; @@ -87,7 +99,7 @@ public class PhoneNumberInteractionTest extends InstrumentationTestCase { mContext, ContactDisplayUtils.INTERACTION_SMS, null); interaction.startInteraction(contactUri); - interaction.getLoader().waitForLoader(); + interaction.waitForLoader(); Intent intent = mContext.getIntentForStartActivity(); assertNotNull(intent); @@ -106,7 +118,7 @@ public class PhoneNumberInteractionTest extends InstrumentationTestCase { mContext, ContactDisplayUtils.INTERACTION_SMS, null); interaction.startInteraction(dataUri); - interaction.getLoader().waitForLoader(); + interaction.waitForLoader(); Intent intent = mContext.getIntentForStartActivity(); assertNotNull(intent); @@ -127,7 +139,7 @@ public class PhoneNumberInteractionTest extends InstrumentationTestCase { mContext, ContactDisplayUtils.INTERACTION_SMS, null); interaction.startInteraction(contactUri); - interaction.getLoader().waitForLoader(); + interaction.waitForLoader(); Intent intent = mContext.getIntentForStartActivity(); assertNotNull(intent); @@ -168,7 +180,7 @@ public class PhoneNumberInteractionTest extends InstrumentationTestCase { mContext, ContactDisplayUtils.INTERACTION_CALL, null); interaction.startInteraction(contactUri); - interaction.getLoader().waitForLoader(); + interaction.waitForLoader(); Intent intent = mContext.getIntentForStartActivity(); assertNotNull(intent); @@ -186,7 +198,7 @@ public class PhoneNumberInteractionTest extends InstrumentationTestCase { mContext, ContactDisplayUtils.INTERACTION_CALL, null); interaction.startInteraction(contactUri); - interaction.getLoader().waitForLoader(); + interaction.waitForLoader(); Intent intent = mContext.getIntentForStartActivity(); assertNotNull(intent); @@ -207,7 +219,7 @@ public class PhoneNumberInteractionTest extends InstrumentationTestCase { mContext, ContactDisplayUtils.INTERACTION_CALL, null); interaction.startInteraction(contactUri); - interaction.getLoader().waitForLoader(); + interaction.waitForLoader(); List items = interaction.mPhoneList; assertNotNull(items); diff --git a/tests/src/com/android/dialer/tests/calllog/FillCallLogTestActivity.java b/tests/src/com/android/dialer/tests/calllog/FillCallLogTestActivity.java index 71571549f..1cfdc2833 100644 --- a/tests/src/com/android/dialer/tests/calllog/FillCallLogTestActivity.java +++ b/tests/src/com/android/dialer/tests/calllog/FillCallLogTestActivity.java @@ -25,6 +25,7 @@ import android.app.TimePickerDialog; import android.content.ContentProviderClient; import android.content.ContentResolver; import android.content.ContentValues; +import android.content.Context; import android.content.CursorLoader; import android.content.Loader; import android.database.Cursor; @@ -36,6 +37,7 @@ import android.provider.CallLog.Calls; import android.provider.VoicemailContract; 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.format.DateFormat; @@ -407,7 +409,8 @@ public class FillCallLogTestActivity extends Activity { } private PhoneAccountHandle getManualAccount() { - TelecomManager telecomManager = TelecomManager.from(this); + TelecomManager telecomManager = + (TelecomManager) getSystemService(Context.TELECOM_SERVICE); List accountHandles = telecomManager.getCallCapablePhoneAccounts(); if (mAccount0.isChecked()) { return accountHandles.get(0); @@ -509,7 +512,7 @@ public class FillCallLogTestActivity extends Activity { if (getManualCallType() == Calls.VOICEMAIL_TYPE) { addManualVoicemail(dateTime.getTimeInMillis()); } else { - Calls.addCall(null, this, mPhoneNumber.getText().toString(), getManualPresentation(), + addCall(mPhoneNumber.getText().toString(), getManualPresentation(), getManualCallType(), features, getManualAccount(), dateTime.getTimeInMillis(), RNG.nextInt(60 * 60), dataUsage); } @@ -527,6 +530,73 @@ public class FillCallLogTestActivity extends Activity { setDisplayTime(); } + // Copied and modified to compile unbundled from android.provider.CallLog + public Uri addCall(String number, + int presentation, int callType, int features, PhoneAccountHandle accountHandle, + long start, int duration, Long dataUsage) { + 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 (account != null) { + Uri address = account.getSubscriptionAddress(); + if (address != null) { + accountAddress = address.getSchemeSpecificPart(); + } + } + } + + if (numberPresentation != Calls.PRESENTATION_ALLOWED) { + number = ""; + } + + // accountHandle information + String accountComponentString = null; + String accountId = null; + if (accountHandle != null) { + accountComponentString = accountHandle.getComponentName().flattenToString(); + accountId = accountHandle.getId(); + } + + ContentValues values = new ContentValues(6); + + values.put(Calls.NUMBER, number); + values.put(Calls.NUMBER_PRESENTATION, Integer.valueOf(numberPresentation)); + values.put(Calls.TYPE, Integer.valueOf(callType)); + values.put(Calls.FEATURES, features); + values.put(Calls.DATE, Long.valueOf(start)); + values.put(Calls.DURATION, Long.valueOf(duration)); + if (dataUsage != null) { + values.put(Calls.DATA_USAGE, dataUsage); + } + values.put(Calls.PHONE_ACCOUNT_COMPONENT_NAME, accountComponentString); + values.put(Calls.PHONE_ACCOUNT_ID, accountId); + // Calls.PHONE_ACCOUNT_ADDRESS + values.put("phone_account_address", accountAddress); + values.put(Calls.NEW, Integer.valueOf(1)); + + if (callType == Calls.MISSED_TYPE) { + values.put(Calls.IS_READ, 0); + } + + return addEntryAndRemoveExpiredEntries(this, Calls.CONTENT_URI, values); + } + + // Copied from android.provider.CallLog + private static Uri addEntryAndRemoveExpiredEntries(Context context, Uri uri, + ContentValues values) { + final ContentResolver resolver = context.getContentResolver(); + Uri result = resolver.insert(uri, values); + resolver.delete(uri, "_id IN " + + "(SELECT _id FROM calls ORDER BY " + Calls.DEFAULT_SORT_ORDER + + " LIMIT -1 OFFSET 500)", null); + return result; + } + private void addManualVoicemail(Long time) { final ContentValues contentValues = new ContentValues(); contentValues.put(Voicemails.DATE, time); diff --git a/tests/src/com/android/dialer/voicemail/VoicemailPlaybackTest.java b/tests/src/com/android/dialer/voicemail/VoicemailPlaybackTest.java index 58b4f558d..b9c70d38f 100644 --- a/tests/src/com/android/dialer/voicemail/VoicemailPlaybackTest.java +++ b/tests/src/com/android/dialer/voicemail/VoicemailPlaybackTest.java @@ -183,7 +183,8 @@ public class VoicemailPlaybackTest extends ActivityInstrumentationTestCase2