blob: 996bca0f6015894d3cab3075cd4c7018339001b6 [file] [log] [blame]
Eric Erfanianccca3152017-02-22 16:32:36 -08001/*
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
17package com.android.dialer.app.calllog;
18
Eric Erfanianccca3152017-02-22 16:32:36 -080019import android.content.ContentValues;
20import android.content.Context;
21import android.content.Intent;
22import android.net.Uri;
23import android.provider.ContactsContract;
twyenc2ea6952017-11-06 16:56:11 -080024import android.support.annotation.Nullable;
roldenburg77c2b4c2017-12-08 15:14:07 -080025import android.telecom.PhoneAccount;
Eric Erfanianccca3152017-02-22 16:32:36 -080026import android.telecom.PhoneAccountHandle;
erfanian04ac93d2017-10-09 15:12:22 -070027import android.telephony.TelephonyManager;
Eric Erfanianccca3152017-02-22 16:32:36 -080028import com.android.contacts.common.model.Contact;
29import com.android.contacts.common.model.ContactLoader;
Eric Erfaniand5e47f62017-03-15 14:41:07 -070030import com.android.dialer.calldetails.CallDetailsActivity;
Eric Erfanian8369df02017-05-03 10:27:13 -070031import com.android.dialer.calldetails.CallDetailsEntries;
32import com.android.dialer.callintent.CallInitiationType;
Eric Erfanianccca3152017-02-22 16:32:36 -080033import com.android.dialer.callintent.CallIntentBuilder;
Eric Erfanian2ca43182017-08-31 06:57:16 -070034import com.android.dialer.dialercontact.DialerContact;
roldenburg4f026392017-10-13 18:42:20 -070035import com.android.dialer.duo.DuoComponent;
roldenburg77c2b4c2017-12-08 15:14:07 -080036import com.android.dialer.duo.DuoConstants;
twyen0efc8402017-11-07 15:39:15 -080037import com.android.dialer.precall.PreCall;
Eric Erfanianccca3152017-02-22 16:32:36 -080038import com.android.dialer.util.IntentUtil;
39import java.util.ArrayList;
40
41/**
42 * Used to create an intent to attach to an action in the call log.
43 *
44 * <p>The intent is constructed lazily with the given information.
45 */
46public abstract class IntentProvider {
47
48 private static final String TAG = IntentProvider.class.getSimpleName();
49
50 public static IntentProvider getReturnCallIntentProvider(final String number) {
51 return getReturnCallIntentProvider(number, null);
52 }
53
54 public static IntentProvider getReturnCallIntentProvider(
55 final String number, final PhoneAccountHandle accountHandle) {
56 return new IntentProvider() {
57 @Override
58 public Intent getIntent(Context context) {
twyen0efc8402017-11-07 15:39:15 -080059 return PreCall.getIntent(
60 context,
61 new CallIntentBuilder(number, CallInitiationType.Type.CALL_LOG)
62 .setPhoneAccountHandle(accountHandle));
Eric Erfanianccca3152017-02-22 16:32:36 -080063 }
64 };
65 }
66
erfanian04ac93d2017-10-09 15:12:22 -070067 public static IntentProvider getAssistedDialIntentProvider(
68 final String number, final Context context, final TelephonyManager telephonyManager) {
69 return new IntentProvider() {
70 @Override
71 public Intent getIntent(Context context) {
twyen0efc8402017-11-07 15:39:15 -080072 return PreCall.getIntent(
73 context,
74 new CallIntentBuilder(number, CallInitiationType.Type.CALL_LOG)
75 .setAllowAssistedDial(true));
erfanian04ac93d2017-10-09 15:12:22 -070076 }
77 };
78 }
79
Eric Erfanianccca3152017-02-22 16:32:36 -080080 public static IntentProvider getReturnVideoCallIntentProvider(final String number) {
81 return getReturnVideoCallIntentProvider(number, null);
82 }
83
84 public static IntentProvider getReturnVideoCallIntentProvider(
85 final String number, final PhoneAccountHandle accountHandle) {
86 return new IntentProvider() {
87 @Override
88 public Intent getIntent(Context context) {
twyen0efc8402017-11-07 15:39:15 -080089 return PreCall.getIntent(
90 context,
91 new CallIntentBuilder(number, CallInitiationType.Type.CALL_LOG)
92 .setPhoneAccountHandle(accountHandle)
93 .setIsVideoCall(true));
Eric Erfanianccca3152017-02-22 16:32:36 -080094 }
95 };
96 }
97
roldenburg4f026392017-10-13 18:42:20 -070098 public static IntentProvider getDuoVideoIntentProvider(String number) {
Eric Erfaniand8046e52017-04-06 09:41:50 -070099 return new IntentProvider() {
100 @Override
101 public Intent getIntent(Context context) {
roldenburg4f026392017-10-13 18:42:20 -0700102 return DuoComponent.get(context).getDuo().getIntent(context, number);
Eric Erfaniand8046e52017-04-06 09:41:50 -0700103 }
104 };
105 }
106
roldenburg77c2b4c2017-12-08 15:14:07 -0800107 public static IntentProvider getSetUpDuoIntentProvider() {
108 return new IntentProvider() {
109 @Override
110 public Intent getIntent(Context context) {
111 return new Intent("com.google.android.apps.tachyon.action.REGISTER")
112 .setPackage(DuoConstants.PACKAGE_NAME);
113 }
114 };
115 }
116
117 public static IntentProvider getDuoInviteIntentProvider(String number) {
118 return new IntentProvider() {
119 @Override
120 public Intent getIntent(Context context) {
121 Intent intent =
122 new Intent("com.google.android.apps.tachyon.action.INVITE")
123 .setPackage(DuoConstants.PACKAGE_NAME)
124 .setData(Uri.fromParts(PhoneAccount.SCHEME_TEL, number, null /* fragment */));
125 return intent;
126 }
127 };
128 }
129
twyenc2ea6952017-11-06 16:56:11 -0800130 public static IntentProvider getReturnVoicemailCallIntentProvider(
131 @Nullable PhoneAccountHandle phoneAccountHandle) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800132 return new IntentProvider() {
133 @Override
134 public Intent getIntent(Context context) {
twyen0efc8402017-11-07 15:39:15 -0800135 return PreCall.getIntent(
136 context,
137 CallIntentBuilder.forVoicemail(phoneAccountHandle, CallInitiationType.Type.CALL_LOG));
Eric Erfanianccca3152017-02-22 16:32:36 -0800138 }
139 };
140 }
141
142 public static IntentProvider getSendSmsIntentProvider(final String number) {
143 return new IntentProvider() {
144 @Override
145 public Intent getIntent(Context context) {
146 return IntentUtil.getSendSmsIntent(number);
147 }
148 };
149 }
150
151 /**
152 * Retrieves the call details intent provider for an entry in the call log.
153 *
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700154 * @param callDetailsEntries The call details of the other calls grouped together with the call.
155 * @param contact The contact with which this call details intent pertains to.
linyuh7b96fb12017-10-10 11:03:33 -0700156 * @param canReportCallerId Whether reporting a caller ID is supported.
157 * @param canSupportAssistedDialing Whether assisted dialing is supported.
Eric Erfanianccca3152017-02-22 16:32:36 -0800158 * @return The call details intent provider.
159 */
160 public static IntentProvider getCallDetailIntentProvider(
linyuh7b96fb12017-10-10 11:03:33 -0700161 CallDetailsEntries callDetailsEntries,
162 DialerContact contact,
163 boolean canReportCallerId,
164 boolean canSupportAssistedDialing) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800165 return new IntentProvider() {
166 @Override
167 public Intent getIntent(Context context) {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700168 return CallDetailsActivity.newInstance(
linyuh7b96fb12017-10-10 11:03:33 -0700169 context, callDetailsEntries, contact, canReportCallerId, canSupportAssistedDialing);
Eric Erfanianccca3152017-02-22 16:32:36 -0800170 }
171 };
172 }
173
174 /** Retrieves an add contact intent for the given contact and phone call details. */
175 public static IntentProvider getAddContactIntentProvider(
176 final Uri lookupUri,
177 final CharSequence name,
178 final CharSequence number,
179 final int numberType,
180 final boolean isNewContact) {
181 return new IntentProvider() {
182 @Override
183 public Intent getIntent(Context context) {
184 Contact contactToSave = null;
185
186 if (lookupUri != null) {
187 contactToSave = ContactLoader.parseEncodedContactEntity(lookupUri);
188 }
189
190 if (contactToSave != null) {
191 // Populate the intent with contact information stored in the lookup URI.
192 // Note: This code mirrors code in Contacts/QuickContactsActivity.
193 final Intent intent;
194 if (isNewContact) {
195 intent = IntentUtil.getNewContactIntent();
196 } else {
197 intent = IntentUtil.getAddToExistingContactIntent();
198 }
199
200 ArrayList<ContentValues> values = contactToSave.getContentValues();
201 // Only pre-fill the name field if the provided display name is an nickname
202 // or better (e.g. structured name, nickname)
203 if (contactToSave.getDisplayNameSource()
204 >= ContactsContract.DisplayNameSources.NICKNAME) {
205 intent.putExtra(ContactsContract.Intents.Insert.NAME, contactToSave.getDisplayName());
206 } else if (contactToSave.getDisplayNameSource()
207 == ContactsContract.DisplayNameSources.ORGANIZATION) {
208 // This is probably an organization. Instead of copying the organization
209 // name into a name entry, copy it into the organization entry. This
210 // way we will still consider the contact an organization.
211 final ContentValues organization = new ContentValues();
212 organization.put(
213 ContactsContract.CommonDataKinds.Organization.COMPANY,
214 contactToSave.getDisplayName());
215 organization.put(
216 ContactsContract.Data.MIMETYPE,
217 ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE);
218 values.add(organization);
219 }
220
221 // Last time used and times used are aggregated values from the usage stat
222 // table. They need to be removed from data values so the SQL table can insert
223 // properly
224 for (ContentValues value : values) {
225 value.remove(ContactsContract.Data.LAST_TIME_USED);
226 value.remove(ContactsContract.Data.TIMES_USED);
227 }
228
229 intent.putExtra(ContactsContract.Intents.Insert.DATA, values);
230
231 return intent;
232 } else {
233 // If no lookup uri is provided, rely on the available phone number and name.
234 if (isNewContact) {
235 return IntentUtil.getNewContactIntent(name, number, numberType);
236 } else {
237 return IntentUtil.getAddToExistingContactIntent(name, number, numberType);
238 }
239 }
240 }
241 };
242 }
243
244 public abstract Intent getIntent(Context context);
245}