• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.dialer.calllog;
18 
19 import android.content.ComponentName;
20 import android.content.Context;
21 import android.content.res.Resources;
22 import android.provider.CallLog.Calls;
23 import android.telecom.PhoneAccountHandle;
24 import android.test.AndroidTestCase;
25 import android.test.suitebuilder.annotation.MediumTest;
26 import android.text.Html;
27 import android.text.Spanned;
28 import android.view.View;
29 import android.widget.TextView;
30 
31 import com.android.dialer.PhoneCallDetails;
32 import com.android.dialer.R;
33 import com.android.dialer.calllog.calllogcache.TestTelecomCallLogCache;
34 import com.android.dialer.util.AppCompatConstants;
35 import com.android.dialer.util.LocaleTestUtils;
36 
37 import java.util.GregorianCalendar;
38 import java.util.Locale;
39 import java.util.regex.Matcher;
40 import java.util.regex.Pattern;
41 
42 /**
43  * Unit tests for {@link PhoneCallDetailsHelper}.
44  */
45 @MediumTest
46 public class PhoneCallDetailsHelperTest extends AndroidTestCase {
47     /** The number to be used to access the voicemail. */
48     private static final String TEST_VOICEMAIL_NUMBER = "125";
49     /** The date of the call log entry. */
50     private static final long TEST_DATE =
51         new GregorianCalendar(2011, 5, 3, 13, 0, 0).getTimeInMillis();
52     private static final long INJECTED_CURRENT_DATE =
53         new GregorianCalendar(2011, 5, 4, 13, 0, 0).getTimeInMillis();
54     /** A test duration value for phone calls. */
55     private static final long TEST_DURATION = 62300;
56     /** The number of the caller/callee in the log entry. */
57     private static final String TEST_NUMBER = "14125555555";
58     /** The formatted version of {@link #TEST_NUMBER}. */
59     private static final String TEST_FORMATTED_NUMBER = "1-412-255-5555";
60     /** The country ISO name used in the tests. */
61     private static final String TEST_COUNTRY_ISO = "US";
62     /** The geocoded location used in the tests. */
63     private static final String TEST_GEOCODE = "United States";
64     /** Empty geocode label */
65     private static final String EMPTY_GEOCODE = "";
66     /** Empty post-dial digits label */
67     private static final String EMPTY_POSTDIAL = "";
68     /** The number that the call was received via */
69     private static final String TEST_VIA_NUMBER = "+16505551234";
70     /** The Phone Account name that the Call was received on */
71     private static final String TEST_ACCOUNT_LABEL = "T-Stationary";
72 
73     /** The object under test. */
74     private PhoneCallDetailsHelper mHelper;
75     /** The views to fill. */
76     private PhoneCallDetailsViews mViews;
77     private TextView mNameView;
78     private LocaleTestUtils mLocaleTestUtils;
79     private TestTelecomCallLogCache mPhoneUtils;
80 
81     private Context mContext;
82 
83     @Override
setUp()84     protected void setUp() throws Exception {
85         super.setUp();
86         mContext = getContext();
87         Resources resources = mContext.getResources();
88         mPhoneUtils = new TestTelecomCallLogCache(mContext, TEST_VOICEMAIL_NUMBER,
89                 TEST_ACCOUNT_LABEL);
90         mHelper = new PhoneCallDetailsHelper(mContext, resources, mPhoneUtils);
91         mHelper.setCurrentTimeForTest(INJECTED_CURRENT_DATE);
92         mViews = PhoneCallDetailsViews.createForTest(mContext);
93         mNameView = new TextView(mContext);
94         mLocaleTestUtils = new LocaleTestUtils(mContext);
95         mLocaleTestUtils.setLocale(Locale.US);
96     }
97 
98     @Override
tearDown()99     protected void tearDown() throws Exception {
100         mLocaleTestUtils.restoreLocale();
101         mNameView = null;
102         mViews = null;
103         mHelper = null;
104         super.tearDown();
105     }
106 
testSetPhoneCallDetails_Unknown()107     public void testSetPhoneCallDetails_Unknown() {
108         setPhoneCallDetailsWithNumber("", Calls.PRESENTATION_UNKNOWN, "");
109         assertNameEqualsResource(R.string.unknown);
110     }
111 
testSetPhoneCallDetails_Private()112     public void testSetPhoneCallDetails_Private() {
113         setPhoneCallDetailsWithNumber("", Calls.PRESENTATION_RESTRICTED, "");
114         assertNameEqualsResource(R.string.private_num);
115     }
116 
testSetPhoneCallDetails_Payphone()117     public void testSetPhoneCallDetails_Payphone() {
118         setPhoneCallDetailsWithNumber("", Calls.PRESENTATION_PAYPHONE, "");
119         assertNameEqualsResource(R.string.payphone);
120     }
121 
testSetPhoneCallDetails_Voicemail()122     public void testSetPhoneCallDetails_Voicemail() {
123         setPhoneCallDetailsWithNumber(TEST_VOICEMAIL_NUMBER,
124                 Calls.PRESENTATION_ALLOWED, TEST_VOICEMAIL_NUMBER);
125         assertNameEqualsResource(R.string.voicemail);
126     }
127 
testSetPhoneCallDetails_ViaNumber()128     public void testSetPhoneCallDetails_ViaNumber() {
129         setPhoneCallDetailsWithViaNumber(TEST_VIA_NUMBER);
130         assertViaNumberEquals(TEST_VIA_NUMBER);
131     }
132 
testSetPhoneCallDetails_NoViaNumber()133     public void testSetPhoneCallDetails_NoViaNumber() {
134         setDefaultPhoneCallDetailsNoViaNumber();
135         assertCallAccountInvisible();
136     }
137 
testSetPhoneCallDetails_AccountLabel()138     public void testSetPhoneCallDetails_AccountLabel() {
139         setPhoneCallDetailsWithAccountHandle();
140         assertAccountLabelEquals(TEST_ACCOUNT_LABEL);
141     }
142 
testSetPhoneCallDetails_AccountHandleViaNumber()143     public void testSetPhoneCallDetails_AccountHandleViaNumber() {
144         setPhoneCallDetailsWithAccountLabelViaNumber(TEST_VIA_NUMBER);
145         assertAccountLabelEquals(TEST_VIA_NUMBER, TEST_ACCOUNT_LABEL);
146     }
147 
148     // Voicemail date string has 3 different formats depending on how long ago the call was placed
testSetVoicemailPhoneCallDetails_Today()149     public void testSetVoicemailPhoneCallDetails_Today() {
150         setVoicemailPhoneCallDetailsWithDate(System.currentTimeMillis());
151         assertLocationAndDateContains("Today at");
152     }
153 
testSetVoicemailPhoneCallDetails_WithinCurrentYear()154     public void testSetVoicemailPhoneCallDetails_WithinCurrentYear() {
155         mHelper.setCurrentTimeForTest(INJECTED_CURRENT_DATE);
156         String formattedTestDate = "Jun 3 at 1:00 PM";
157         setVoicemailPhoneCallDetailsWithDate(TEST_DATE);
158         assertLocationAndDateContains(formattedTestDate);
159     }
160 
testSetVoicemailPhoneCallDetails_OutsideCurrentYear()161     public void testSetVoicemailPhoneCallDetails_OutsideCurrentYear() {
162         mHelper.setCurrentTimeForTest(INJECTED_CURRENT_DATE);
163         long testDate = new GregorianCalendar(2009, 5, 3, 13, 0, 0).getTimeInMillis();
164         String formattedTestDate = "Jun 3, 2009 at 1:00 PM";
165         setVoicemailPhoneCallDetailsWithDate(testDate);
166         assertLocationAndDateContains(formattedTestDate);
167     }
168 
testVoicemailLocationNotShownWithDate()169     public void testVoicemailLocationNotShownWithDate() {
170         setVoicemailPhoneCallDetailsWithDate(TEST_DATE);
171         assertLocationAndDateExactEquals("Jun 3 at 1:00 PM • 99:20");
172     }
173 
testVoicemailDuration()174     public void testVoicemailDuration() {
175         setVoicemailPhoneCallDetailsWithDuration(100);
176         assertDurationExactEquals("01:40");
177     }
178 
testVoicemailDuration_Capped()179     public void testVoicemailDuration_Capped() {
180         setVoicemailPhoneCallDetailsWithDuration(TEST_DURATION);
181         assertDurationExactEquals("99:20");
182     }
183 
testVoicemailDuration_Zero()184     public void testVoicemailDuration_Zero() {
185         setVoicemailPhoneCallDetailsWithDuration(0);
186         assertLocationAndDateExactEquals("Jun 3 at 1:00 PM");
187     }
188 
testVoicemailDuration_EvenMinute()189     public void testVoicemailDuration_EvenMinute() {
190         setVoicemailPhoneCallDetailsWithDuration(60);
191         assertDurationExactEquals("01:00");
192     }
193 
194     /** Asserts that a char sequence is actually a Spanned corresponding to the expected HTML. */
assertEqualsHtml(String expectedHtml, CharSequence actualText)195     private void assertEqualsHtml(String expectedHtml, CharSequence actualText) {
196         // In order to contain HTML, the text should actually be a Spanned.
197         assertTrue(actualText instanceof Spanned);
198         Spanned actualSpanned = (Spanned) actualText;
199         // Convert from and to HTML to take care of alternative formatting of HTML.
200         assertEquals(Html.toHtml(Html.fromHtml(expectedHtml)), Html.toHtml(actualSpanned));
201 
202     }
203 
testSetPhoneCallDetails_Date()204     public void testSetPhoneCallDetails_Date() {
205         mHelper.setCurrentTimeForTest(
206                 new GregorianCalendar(2011, 5, 3, 13, 0, 0).getTimeInMillis());
207 
208         setPhoneCallDetailsWithDate(
209                 new GregorianCalendar(2011, 5, 3, 13, 0, 0).getTimeInMillis());
210         assertLocationAndDateContains("0 min. ago");
211 
212         setPhoneCallDetailsWithDate(
213                 new GregorianCalendar(2011, 5, 3, 12, 0, 0).getTimeInMillis());
214         assertLocationAndDateContains("1 hr. ago");
215 
216         setPhoneCallDetailsWithDate(
217                 new GregorianCalendar(2011, 5, 2, 13, 0, 0).getTimeInMillis());
218         assertLocationAndDateContains("Yesterday");
219 
220         setPhoneCallDetailsWithDate(
221                 new GregorianCalendar(2011, 5, 1, 13, 0, 0).getTimeInMillis());
222         assertLocationAndDateContains("2 days ago");
223     }
224 
testSetPhoneCallDetails_CallTypeIcons()225     public void testSetPhoneCallDetails_CallTypeIcons() {
226         setPhoneCallDetailsWithCallTypeIcons(AppCompatConstants.CALLS_INCOMING_TYPE);
227         assertCallTypeIconsEquals(AppCompatConstants.CALLS_INCOMING_TYPE);
228 
229         setPhoneCallDetailsWithCallTypeIcons(AppCompatConstants.CALLS_OUTGOING_TYPE);
230         assertCallTypeIconsEquals(AppCompatConstants.CALLS_OUTGOING_TYPE);
231 
232         setPhoneCallDetailsWithCallTypeIcons(AppCompatConstants.CALLS_MISSED_TYPE);
233         assertCallTypeIconsEquals(AppCompatConstants.CALLS_MISSED_TYPE);
234 
235         setPhoneCallDetailsWithCallTypeIcons(AppCompatConstants.CALLS_VOICEMAIL_TYPE);
236         assertCallTypeIconsEquals(AppCompatConstants.CALLS_VOICEMAIL_TYPE);
237     }
238 
239     /**
240      * Tests a case where the video call feature is present.
241      */
testSetPhoneCallDetails_Video()242     public void testSetPhoneCallDetails_Video() {
243         PhoneCallDetails details = getPhoneCallDetails();
244         details.features = Calls.FEATURES_VIDEO;
245         mHelper.setPhoneCallDetails(mViews, details);
246 
247         assertIsVideoCall(true);
248     }
249 
250     /**
251      * Tests a case where the video call feature is not present.
252      */
testSetPhoneCallDetails_NoVideo()253     public void testSetPhoneCallDetails_NoVideo() {
254         PhoneCallDetails details = getPhoneCallDetails();
255         details.features = 0;
256         mHelper.setPhoneCallDetails(mViews, details);
257 
258         assertIsVideoCall(false);
259     }
260 
testSetPhoneCallDetails_MultipleCallTypeIcons()261     public void testSetPhoneCallDetails_MultipleCallTypeIcons() {
262         setPhoneCallDetailsWithCallTypeIcons(
263                 AppCompatConstants.CALLS_INCOMING_TYPE,
264                 AppCompatConstants.CALLS_OUTGOING_TYPE);
265         assertCallTypeIconsEquals(
266                 AppCompatConstants.CALLS_INCOMING_TYPE,
267                 AppCompatConstants.CALLS_OUTGOING_TYPE);
268 
269         setPhoneCallDetailsWithCallTypeIcons(
270                 AppCompatConstants.CALLS_MISSED_TYPE,
271                 AppCompatConstants.CALLS_MISSED_TYPE);
272         assertCallTypeIconsEquals(
273                 AppCompatConstants.CALLS_MISSED_TYPE,
274                 AppCompatConstants.CALLS_MISSED_TYPE);
275     }
276 
testSetPhoneCallDetails_MultipleCallTypeIconsLastOneDropped()277     public void testSetPhoneCallDetails_MultipleCallTypeIconsLastOneDropped() {
278         setPhoneCallDetailsWithCallTypeIcons(
279                 AppCompatConstants.CALLS_MISSED_TYPE,
280                 AppCompatConstants.CALLS_MISSED_TYPE,
281                 AppCompatConstants.CALLS_INCOMING_TYPE,
282                 AppCompatConstants.CALLS_OUTGOING_TYPE);
283         assertCallTypeIconsEqualsPlusOverflow("(4)",
284                 AppCompatConstants.CALLS_MISSED_TYPE,
285                 AppCompatConstants.CALLS_MISSED_TYPE,
286                 AppCompatConstants.CALLS_INCOMING_TYPE);
287     }
288 
testSetPhoneCallDetails_Geocode()289     public void testSetPhoneCallDetails_Geocode() {
290         setPhoneCallDetailsWithNumberAndGeocode("+14125555555", "1-412-555-5555", "Pennsylvania");
291         assertNameEquals("1-412-555-5555");  // The phone number is shown as the name.
292         assertLocationAndDateContains("Pennsylvania"); // The geocode is shown as the label.
293     }
294 
testSetPhoneCallDetails_NoGeocode()295     public void testSetPhoneCallDetails_NoGeocode() {
296         setPhoneCallDetailsWithNumberAndGeocode("+14125555555", "1-412-555-5555", null);
297         assertNameEquals("1-412-555-5555");  // The phone number is shown as the name.
298         assertLocationAndDateContains(EMPTY_GEOCODE); // The empty geocode is shown as the label.
299     }
300 
testSetPhoneCallDetails_EmptyGeocode()301     public void testSetPhoneCallDetails_EmptyGeocode() {
302         setPhoneCallDetailsWithNumberAndGeocode("+14125555555", "1-412-555-5555", "");
303         assertNameEquals("1-412-555-5555");  // The phone number is shown as the name.
304         assertLocationAndDateContains(EMPTY_GEOCODE); // The empty geocode is shown as the label.
305     }
306 
testSetPhoneCallDetails_NoGeocodeForVoicemail()307     public void testSetPhoneCallDetails_NoGeocodeForVoicemail() {
308         setPhoneCallDetailsWithNumberAndGeocode(TEST_VOICEMAIL_NUMBER, "", "United States");
309         assertLocationAndDateContains(EMPTY_GEOCODE); // The empty geocode is shown as the label.
310     }
311 
testSetPhoneCallDetails_Highlighted()312     public void testSetPhoneCallDetails_Highlighted() {
313         setPhoneCallDetailsWithNumber(TEST_VOICEMAIL_NUMBER,
314                 Calls.PRESENTATION_ALLOWED, "");
315     }
316 
testSetCallDetailsHeader_NumberOnly()317     public void testSetCallDetailsHeader_NumberOnly() {
318         setCallDetailsHeaderWithNumber(TEST_NUMBER, Calls.PRESENTATION_ALLOWED);
319         assertEquals(View.VISIBLE, mNameView.getVisibility());
320         assertEquals("1-412-255-5555", mNameView.getText().toString());
321     }
322 
testSetCallDetailsHeader_UnknownNumber()323     public void testSetCallDetailsHeader_UnknownNumber() {
324         setCallDetailsHeaderWithNumber("", Calls.PRESENTATION_UNKNOWN);
325         assertEquals(View.VISIBLE, mNameView.getVisibility());
326         assertEquals("Unknown", mNameView.getText().toString());
327     }
328 
testSetCallDetailsHeader_PrivateNumber()329     public void testSetCallDetailsHeader_PrivateNumber() {
330         setCallDetailsHeaderWithNumber("", Calls.PRESENTATION_RESTRICTED);
331         assertEquals(View.VISIBLE, mNameView.getVisibility());
332         assertEquals("Private number", mNameView.getText().toString());
333     }
334 
testSetCallDetailsHeader_PayphoneNumber()335     public void testSetCallDetailsHeader_PayphoneNumber() {
336         setCallDetailsHeaderWithNumber("", Calls.PRESENTATION_PAYPHONE);
337         assertEquals(View.VISIBLE, mNameView.getVisibility());
338         assertEquals("Payphone", mNameView.getText().toString());
339     }
340 
testSetCallDetailsHeader_VoicemailNumber()341     public void testSetCallDetailsHeader_VoicemailNumber() {
342         PhoneCallDetails details = getPhoneCallDetails(
343                 TEST_VOICEMAIL_NUMBER,
344                 Calls.PRESENTATION_ALLOWED,
345                 TEST_FORMATTED_NUMBER);
346         mHelper.setCallDetailsHeader(mNameView, details);
347         assertEquals(View.VISIBLE, mNameView.getVisibility());
348         assertEquals("Voicemail", mNameView.getText().toString());
349     }
350 
testSetCallDetailsHeader()351     public void testSetCallDetailsHeader() {
352         setCallDetailsHeader("John Doe");
353         assertEquals(View.VISIBLE, mNameView.getVisibility());
354         assertEquals("John Doe", mNameView.getText().toString());
355     }
356 
testGetCallTypeOrLocation_Geocode()357     public void testGetCallTypeOrLocation_Geocode() {
358         assertEquals(TEST_GEOCODE, mHelper.getCallTypeOrLocation(getPhoneCallDetails()));
359     }
360 
testGetCallTypeOrLocation_CallType()361     public void testGetCallTypeOrLocation_CallType() {
362         PhoneCallDetails details = getPhoneCallDetails();
363         details.geocode = null;
364         details.numberType = Calls.INCOMING_TYPE;
365         mHelper.setPhoneTypeLabelForTest("mobile");
366         assertEquals("mobile", mHelper.getCallTypeOrLocation(details));
367     }
368 
testGetCallTypeOrLocation_DisplayNumber()369     public void testGetCallTypeOrLocation_DisplayNumber() {
370         PhoneCallDetails details = getPhoneCallDetails("", Calls.PRESENTATION_ALLOWED,
371                 TEST_FORMATTED_NUMBER);
372         details.namePrimary = "name";
373         assertEquals(TEST_FORMATTED_NUMBER, mHelper.getCallTypeOrLocation(details));
374     }
375 
376     /** Asserts that the name text field contains the value of the given string resource. */
assertNameEqualsResource(int resId)377     private void assertNameEqualsResource(int resId) {
378         assertNameEquals(getContext().getString(resId));
379     }
380 
381     /** Asserts that the name text field contains the given string value. */
assertNameEquals(String text)382     private void assertNameEquals(String text) {
383         assertEquals(text, mViews.nameView.getText().toString());
384     }
385 
386     /** Asserts that the location and date text field contains the given string value. */
assertLocationAndDateContains(String text)387     private void assertLocationAndDateContains(String text) {
388         assertTrue(mViews.callLocationAndDate.getText().toString().contains(text));
389     }
390 
391     /** Asserts that the location and date text field exactly equals the given string value. */
assertLocationAndDateExactEquals(String text)392     private void assertLocationAndDateExactEquals(String text) {
393         assertEquals(text, mViews.callLocationAndDate.getText());
394     }
395 
396     /** Asserts that the via number is correct. */
assertViaNumberEquals(String text)397     private void assertViaNumberEquals(String text) {
398         final String callAccountText =
399                 mContext.getResources().getString(R.string.description_via_number, text);
400         assertEquals(callAccountText, mViews.callAccountLabel.getText());
401     }
402 
403     /** Asserts that the account label is correct. */
assertAccountLabelEquals(String text)404     private void assertAccountLabelEquals(String text) {
405         assertEquals(text, mViews.callAccountLabel.getText());
406     }
407 
408     /** Asserts that the account label is correct when also showing the via number. */
assertAccountLabelEquals(String viaNumber, String accountLabel)409     private void assertAccountLabelEquals(String viaNumber, String accountLabel) {
410         final String viaNumberText =
411                 mContext.getResources().getString(R.string.description_via_number, viaNumber);
412         assertEquals(accountLabel + " " + viaNumberText, mViews.callAccountLabel.getText());
413     }
414 
415     /** Asserts that the call account label is invisible. */
assertCallAccountInvisible()416     private void assertCallAccountInvisible() {
417         assertEquals(mViews.callAccountLabel.getVisibility(), View.GONE);
418     }
419 
420     /** Asserts that the duration is exactly as included in the location and date text field. */
assertDurationExactEquals(String text)421     private void assertDurationExactEquals(String text) {
422         Matcher matcher = Pattern.compile("(.*) (\\u2022) (\\d{2}:\\d{2})").matcher(
423                 mViews.callLocationAndDate.getText());
424         assertEquals(true, matcher.matches());
425         assertEquals(text, matcher.group(3));
426     }
427 
428     /** Asserts that the video icon is shown. */
assertIsVideoCall(boolean isVideoCall)429     private void assertIsVideoCall(boolean isVideoCall) {
430         assertEquals(isVideoCall, mViews.callTypeIcons.isVideoShown());
431     }
432 
433     /** Asserts that the call type contains the images with the given drawables. */
assertCallTypeIconsEquals(int... ids)434     private void assertCallTypeIconsEquals(int... ids) {
435         assertEquals(ids.length, mViews.callTypeIcons.getCount());
436         for (int index = 0; index < ids.length; ++index) {
437             int id = ids[index];
438             assertEquals(id, mViews.callTypeIcons.getCallType(index));
439         }
440         assertEquals(View.VISIBLE, mViews.callTypeIcons.getVisibility());
441     }
442 
443     /**
444      * Asserts that the call type contains the images with the given drawables and shows the given
445      * text next to the icons.
446      */
assertCallTypeIconsEqualsPlusOverflow(String overflowText, int... ids)447     private void assertCallTypeIconsEqualsPlusOverflow(String overflowText, int... ids) {
448         assertEquals(ids.length, mViews.callTypeIcons.getCount());
449         for (int index = 0; index < ids.length; ++index) {
450             int id = ids[index];
451             assertEquals(id, mViews.callTypeIcons.getCallType(index));
452         }
453         assertEquals(View.VISIBLE, mViews.callTypeIcons.getVisibility());
454         assertTrue(mViews.callLocationAndDate.getText().toString().contains(overflowText));
455         assertTrue(mViews.callLocationAndDate.getText().toString().contains("Yesterday"));
456     }
457 
458     /** Sets the phone call details with default values and the given number. */
setPhoneCallDetailsWithNumber(String number, int presentation, String formattedNumber)459     private void setPhoneCallDetailsWithNumber(String number, int presentation,
460             String formattedNumber) {
461         PhoneCallDetails details = getPhoneCallDetails(number, presentation, formattedNumber);
462         details.callTypes = new int[]{ AppCompatConstants.CALLS_VOICEMAIL_TYPE };
463         mHelper.setPhoneCallDetails(mViews, details);
464     }
465 
466     /** Sets the phone call details with default values and the given via number. */
setPhoneCallDetailsWithViaNumber(String viaNumber)467     private void setPhoneCallDetailsWithViaNumber(String viaNumber) {
468         PhoneCallDetails details = getPhoneCallDetails();
469         mPhoneUtils.setAccountLabel("");
470         details.viaNumber = viaNumber;
471         mHelper.setPhoneCallDetails(mViews, details);
472     }
473 
474     /** Sets the phone call details with an account handle. */
setPhoneCallDetailsWithAccountHandle()475     private void setPhoneCallDetailsWithAccountHandle() {
476         PhoneCallDetails details = getPhoneCallDetails();
477         details.accountHandle = new PhoneAccountHandle(new ComponentName("",""), "");
478         mHelper.setPhoneCallDetails(mViews, details);
479     }
480 
481     /** Sets the phone call details with an account handle and via number */
setPhoneCallDetailsWithAccountLabelViaNumber(String viaNumber)482     private void setPhoneCallDetailsWithAccountLabelViaNumber(String viaNumber) {
483         PhoneCallDetails details = getPhoneCallDetails();
484         details.viaNumber = viaNumber;
485         details.accountHandle = new PhoneAccountHandle(new ComponentName("",""), "");
486         mHelper.setPhoneCallDetails(mViews, details);
487     }
488 
489     /** Populates the phone call details with the Defaults. */
setDefaultPhoneCallDetailsNoViaNumber()490     private void setDefaultPhoneCallDetailsNoViaNumber() {
491         PhoneCallDetails details = getPhoneCallDetails();
492         mPhoneUtils.setAccountLabel("");
493         mHelper.setPhoneCallDetails(mViews, details);
494     }
495 
496     /** Sets the phone call details with default values and the given number. */
setPhoneCallDetailsWithNumberAndGeocode( String number, String formattedNumber, String geocodedLocation)497     private void setPhoneCallDetailsWithNumberAndGeocode(
498             String number, String formattedNumber, String geocodedLocation) {
499         PhoneCallDetails details = getPhoneCallDetails(
500                 number, Calls.PRESENTATION_ALLOWED, formattedNumber);
501         details.geocode = geocodedLocation;
502         mHelper.setPhoneCallDetails(mViews, details);
503     }
504 
505     /** Sets the phone call details with default values and the given date. */
setPhoneCallDetailsWithDate(long date)506     private void setPhoneCallDetailsWithDate(long date) {
507         PhoneCallDetails details = getPhoneCallDetails();
508         details.date = date;
509         mHelper.setPhoneCallDetails(mViews, details);
510     }
511 
setVoicemailPhoneCallDetailsWithDate(long date)512     private void setVoicemailPhoneCallDetailsWithDate(long date) {
513         PhoneCallDetails details = getPhoneCallDetails();
514         details.date = date;
515         details.callTypes = new int[] {Calls.VOICEMAIL_TYPE};
516         mHelper.setPhoneCallDetails(mViews, details);
517     }
518 
519     /** Sets the voice mail details with default values and the given duration. */
setVoicemailPhoneCallDetailsWithDuration(long duration)520     private void setVoicemailPhoneCallDetailsWithDuration(long duration) {
521         PhoneCallDetails details = getPhoneCallDetails();
522         details.duration = duration;
523         details.callTypes = new int[] {Calls.VOICEMAIL_TYPE};
524         mHelper.setPhoneCallDetails(mViews, details);
525     }
526 
527     /** Sets the phone call details with default values and the given call types using icons. */
setPhoneCallDetailsWithCallTypeIcons(int... callTypes)528     private void setPhoneCallDetailsWithCallTypeIcons(int... callTypes) {
529         PhoneCallDetails details = getPhoneCallDetails();
530         details.callTypes = callTypes;
531         mHelper.setPhoneCallDetails(mViews, details);
532     }
533 
setCallDetailsHeaderWithNumber(String number, int presentation)534     private void setCallDetailsHeaderWithNumber(String number, int presentation) {
535         mHelper.setCallDetailsHeader(mNameView,
536                 getPhoneCallDetails(number, presentation, TEST_FORMATTED_NUMBER));
537     }
538 
setCallDetailsHeader(String name)539     private void setCallDetailsHeader(String name) {
540         PhoneCallDetails details = getPhoneCallDetails();
541         details.namePrimary = name;
542         mHelper.setCallDetailsHeader(mNameView, details);
543     }
544 
getPhoneCallDetails()545     private PhoneCallDetails getPhoneCallDetails() {
546         PhoneCallDetails details = new PhoneCallDetails(
547                 mContext,
548                 TEST_NUMBER,
549                 Calls.PRESENTATION_ALLOWED,
550                 TEST_FORMATTED_NUMBER,
551                 EMPTY_POSTDIAL,
552                 false /* isVoicemail */);
553         setDefaultDetails(details);
554         return details;
555     }
556 
getPhoneCallDetails( String number, int presentation, String formattedNumber)557     private PhoneCallDetails getPhoneCallDetails(
558             String number, int presentation, String formattedNumber) {
559         PhoneCallDetails details = new PhoneCallDetails(
560                 mContext,
561                 number,
562                 presentation,
563                 formattedNumber,
564                 EMPTY_POSTDIAL,
565                 isVoicemail(number));
566         setDefaultDetails(details);
567         return details;
568     }
569 
setDefaultDetails(PhoneCallDetails details)570     private void setDefaultDetails(PhoneCallDetails details) {
571         details.callTypes = new int[]{ AppCompatConstants.CALLS_INCOMING_TYPE };
572         details.countryIso = TEST_COUNTRY_ISO;
573         details.date = TEST_DATE;
574         details.duration = TEST_DURATION;
575         details.geocode = TEST_GEOCODE;
576     }
577 
isVoicemail(String number)578     private boolean isVoicemail(String number) {
579         return number.equals(TEST_VOICEMAIL_NUMBER);
580     }
581 }
582