• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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.calllogutils;
18 
19 import android.content.Context;
20 import android.content.res.Resources;
21 import android.net.Uri;
22 import android.provider.CallLog;
23 import android.provider.CallLog.Calls;
24 import android.support.annotation.Nullable;
25 import android.telecom.PhoneAccountHandle;
26 import android.text.TextUtils;
27 import com.android.contacts.common.ContactsUtils.UserType;
28 import com.android.contacts.common.util.ContactDisplayUtils;
29 import com.android.dialer.contacts.displaypreference.ContactDisplayPreferences.DisplayOrder;
30 import com.android.dialer.logging.ContactSource;
31 import com.android.dialer.phonenumbercache.ContactInfo;
32 
33 /** The details of a phone call to be shown in the UI. */
34 public class PhoneCallDetails {
35 
36   // The number of the other party involved in the call.
37   public CharSequence number;
38   // Post-dial digits associated with the outgoing call.
39   public String postDialDigits;
40   // The secondary line number the call was received via.
41   public String viaNumber;
42   // The number presenting rules set by the network, e.g., {@link Calls#PRESENTATION_ALLOWED}
43   public int numberPresentation;
44   // The country corresponding with the phone number.
45   public String countryIso;
46   // The geocoded location for the phone number.
47   public String geocode;
48 
49   /**
50    * The type of calls, as defined in the call log table, e.g., {@link Calls#INCOMING_TYPE}.
51    *
52    * <p>There might be multiple types if this represents a set of entries grouped together.
53    */
54   public int[] callTypes;
55 
56   // The date of the call, in milliseconds since the epoch.
57   public long date;
58   // The duration of the call in milliseconds, or 0 for missed calls.
59   public long duration;
60   // The name of the contact, or the empty string.
61   public CharSequence namePrimary;
62   // The alternative name of the contact, e.g. last name first, or the empty string
63   public CharSequence nameAlternative;
64   /**
65    * The user's preference on name display order, last name first or first time first. {@see
66    * ContactsPreferences}
67    */
68   public DisplayOrder nameDisplayOrder;
69   // The type of phone, e.g., {@link Phone#TYPE_HOME}, 0 if not available.
70   public int numberType;
71   // The custom label associated with the phone number in the contact, or the empty string.
72   public CharSequence numberLabel;
73   // The URI of the contact associated with this phone call.
74   public Uri contactUri;
75 
76   /**
77    * The photo URI of the picture of the contact that is associated with this phone call or null if
78    * there is none.
79    *
80    * <p>This is meant to store the high-res photo only.
81    */
82   public Uri photoUri;
83 
84   // The source type of the contact associated with this call.
85   public ContactSource.Type sourceType;
86 
87   // The object id type of the contact associated with this call.
88   public String objectId;
89 
90   // The unique identifier for the account associated with the call.
91   public PhoneAccountHandle accountHandle;
92 
93   // Features applicable to this call.
94   public int features;
95 
96   // Total data usage for this call.
97   public Long dataUsage;
98 
99   // Voicemail transcription
100   public String transcription;
101 
102   // Voicemail transcription state, ie. in-progress, failed, etc.
103   public int transcriptionState;
104 
105   // The display string for the number.
106   public String displayNumber;
107 
108   // Whether the contact number is a voicemail number.
109   public boolean isVoicemail;
110 
111   /** The {@link UserType} of the contact */
112   public @UserType long contactUserType;
113 
114   /**
115    * If this is a voicemail, whether the message is read. For other types of calls, this defaults to
116    * {@code true}.
117    */
118   public boolean isRead = true;
119 
120   // If this call is a spam number.
121   public boolean isSpam = false;
122 
123   // If this call is a blocked number.
124   public boolean isBlocked = false;
125 
126   // Call location and date text.
127   public CharSequence callLocationAndDate;
128 
129   // Call description.
130   public CharSequence callDescription;
131   public String accountComponentName;
132   public String accountId;
133   public ContactInfo cachedContactInfo;
134   public int voicemailId;
135   public int previousGroup;
136 
137   // The URI of the voicemail associated with this phone call, if this call went to voicemail.
138   public String voicemailUri;
139 
140   /**
141    * Constructor with required fields for the details of a call with a number associated with a
142    * contact.
143    */
PhoneCallDetails( CharSequence number, int numberPresentation, CharSequence postDialDigits)144   public PhoneCallDetails(
145       CharSequence number, int numberPresentation, CharSequence postDialDigits) {
146     this.number = number;
147     this.numberPresentation = numberPresentation;
148     this.postDialDigits = postDialDigits.toString();
149   }
150   /**
151    * Construct the "on {accountLabel} via {viaNumber}" accessibility description for the account
152    * list item, depending on the existence of the accountLabel and viaNumber.
153    *
154    * @param viaNumber The number that this call is being placed via.
155    * @param accountLabel The {@link PhoneAccount} label that this call is being placed with.
156    * @return The description of the account that this call has been placed on.
157    */
createAccountLabelDescription( Resources resources, @Nullable String viaNumber, @Nullable CharSequence accountLabel)158   public static CharSequence createAccountLabelDescription(
159       Resources resources, @Nullable String viaNumber, @Nullable CharSequence accountLabel) {
160 
161     if ((!TextUtils.isEmpty(viaNumber)) && !TextUtils.isEmpty(accountLabel)) {
162       String msg =
163           resources.getString(
164               R.string.description_via_number_phone_account, accountLabel, viaNumber);
165       CharSequence accountNumberLabel =
166           ContactDisplayUtils.getTelephoneTtsSpannable(msg, viaNumber);
167       return (accountNumberLabel == null) ? msg : accountNumberLabel;
168     } else if (!TextUtils.isEmpty(viaNumber)) {
169       CharSequence viaNumberLabel =
170           ContactDisplayUtils.getTtsSpannedPhoneNumber(
171               resources, R.string.description_via_number, viaNumber);
172       return (viaNumberLabel == null) ? viaNumber : viaNumberLabel;
173     } else if (!TextUtils.isEmpty(accountLabel)) {
174       return TextUtils.expandTemplate(
175           resources.getString(R.string.description_phone_account), accountLabel);
176     }
177     return "";
178   }
179 
180   /**
181    * Returns the preferred name for the call details as specified by the {@link #nameDisplayOrder}
182    *
183    * @return the preferred name
184    */
getPreferredName()185   public CharSequence getPreferredName() {
186     if (nameDisplayOrder == DisplayOrder.PRIMARY || TextUtils.isEmpty(nameAlternative)) {
187       return namePrimary;
188     }
189     return nameAlternative;
190   }
191 
updateDisplayNumber( Context context, CharSequence formattedNumber, boolean isVoicemail)192   public void updateDisplayNumber(
193       Context context, CharSequence formattedNumber, boolean isVoicemail) {
194     displayNumber =
195         PhoneNumberDisplayUtil.getDisplayNumber(
196                 context, number, numberPresentation, formattedNumber, postDialDigits, isVoicemail)
197             .toString();
198   }
199 
hasIncomingCalls()200   public boolean hasIncomingCalls() {
201     for (int i = 0; i < callTypes.length; i++) {
202       if (callTypes[i] == CallLog.Calls.INCOMING_TYPE
203           || callTypes[i] == CallLog.Calls.MISSED_TYPE
204           || callTypes[i] == CallLog.Calls.VOICEMAIL_TYPE
205           || callTypes[i] == CallLog.Calls.REJECTED_TYPE
206           || callTypes[i] == CallLog.Calls.BLOCKED_TYPE) {
207         return true;
208       }
209     }
210     return false;
211   }
212 }
213