Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 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.app.calllog; |
| 18 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 19 | import android.content.ContentValues; |
| 20 | import android.content.Context; |
| 21 | import android.content.Intent; |
| 22 | import android.net.Uri; |
| 23 | import android.provider.ContactsContract; |
twyen | c2ea695 | 2017-11-06 16:56:11 -0800 | [diff] [blame] | 24 | import android.support.annotation.Nullable; |
roldenburg | 77c2b4c | 2017-12-08 15:14:07 -0800 | [diff] [blame^] | 25 | import android.telecom.PhoneAccount; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 26 | import android.telecom.PhoneAccountHandle; |
erfanian | 04ac93d | 2017-10-09 15:12:22 -0700 | [diff] [blame] | 27 | import android.telephony.TelephonyManager; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 28 | import com.android.contacts.common.model.Contact; |
| 29 | import com.android.contacts.common.model.ContactLoader; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 30 | import com.android.dialer.calldetails.CallDetailsActivity; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 31 | import com.android.dialer.calldetails.CallDetailsEntries; |
| 32 | import com.android.dialer.callintent.CallInitiationType; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 33 | import com.android.dialer.callintent.CallIntentBuilder; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 34 | import com.android.dialer.dialercontact.DialerContact; |
roldenburg | 4f02639 | 2017-10-13 18:42:20 -0700 | [diff] [blame] | 35 | import com.android.dialer.duo.DuoComponent; |
roldenburg | 77c2b4c | 2017-12-08 15:14:07 -0800 | [diff] [blame^] | 36 | import com.android.dialer.duo.DuoConstants; |
twyen | 0efc840 | 2017-11-07 15:39:15 -0800 | [diff] [blame] | 37 | import com.android.dialer.precall.PreCall; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 38 | import com.android.dialer.util.IntentUtil; |
| 39 | import 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 | */ |
| 46 | public 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) { |
twyen | 0efc840 | 2017-11-07 15:39:15 -0800 | [diff] [blame] | 59 | return PreCall.getIntent( |
| 60 | context, |
| 61 | new CallIntentBuilder(number, CallInitiationType.Type.CALL_LOG) |
| 62 | .setPhoneAccountHandle(accountHandle)); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 63 | } |
| 64 | }; |
| 65 | } |
| 66 | |
erfanian | 04ac93d | 2017-10-09 15:12:22 -0700 | [diff] [blame] | 67 | 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) { |
twyen | 0efc840 | 2017-11-07 15:39:15 -0800 | [diff] [blame] | 72 | return PreCall.getIntent( |
| 73 | context, |
| 74 | new CallIntentBuilder(number, CallInitiationType.Type.CALL_LOG) |
| 75 | .setAllowAssistedDial(true)); |
erfanian | 04ac93d | 2017-10-09 15:12:22 -0700 | [diff] [blame] | 76 | } |
| 77 | }; |
| 78 | } |
| 79 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 80 | 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) { |
twyen | 0efc840 | 2017-11-07 15:39:15 -0800 | [diff] [blame] | 89 | return PreCall.getIntent( |
| 90 | context, |
| 91 | new CallIntentBuilder(number, CallInitiationType.Type.CALL_LOG) |
| 92 | .setPhoneAccountHandle(accountHandle) |
| 93 | .setIsVideoCall(true)); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 94 | } |
| 95 | }; |
| 96 | } |
| 97 | |
roldenburg | 4f02639 | 2017-10-13 18:42:20 -0700 | [diff] [blame] | 98 | public static IntentProvider getDuoVideoIntentProvider(String number) { |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 99 | return new IntentProvider() { |
| 100 | @Override |
| 101 | public Intent getIntent(Context context) { |
roldenburg | 4f02639 | 2017-10-13 18:42:20 -0700 | [diff] [blame] | 102 | return DuoComponent.get(context).getDuo().getIntent(context, number); |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 103 | } |
| 104 | }; |
| 105 | } |
| 106 | |
roldenburg | 77c2b4c | 2017-12-08 15:14:07 -0800 | [diff] [blame^] | 107 | 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 | |
twyen | c2ea695 | 2017-11-06 16:56:11 -0800 | [diff] [blame] | 130 | public static IntentProvider getReturnVoicemailCallIntentProvider( |
| 131 | @Nullable PhoneAccountHandle phoneAccountHandle) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 132 | return new IntentProvider() { |
| 133 | @Override |
| 134 | public Intent getIntent(Context context) { |
twyen | 0efc840 | 2017-11-07 15:39:15 -0800 | [diff] [blame] | 135 | return PreCall.getIntent( |
| 136 | context, |
| 137 | CallIntentBuilder.forVoicemail(phoneAccountHandle, CallInitiationType.Type.CALL_LOG)); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 138 | } |
| 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 Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 154 | * @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. |
linyuh | 7b96fb1 | 2017-10-10 11:03:33 -0700 | [diff] [blame] | 156 | * @param canReportCallerId Whether reporting a caller ID is supported. |
| 157 | * @param canSupportAssistedDialing Whether assisted dialing is supported. |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 158 | * @return The call details intent provider. |
| 159 | */ |
| 160 | public static IntentProvider getCallDetailIntentProvider( |
linyuh | 7b96fb1 | 2017-10-10 11:03:33 -0700 | [diff] [blame] | 161 | CallDetailsEntries callDetailsEntries, |
| 162 | DialerContact contact, |
| 163 | boolean canReportCallerId, |
| 164 | boolean canSupportAssistedDialing) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 165 | return new IntentProvider() { |
| 166 | @Override |
| 167 | public Intent getIntent(Context context) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 168 | return CallDetailsActivity.newInstance( |
linyuh | 7b96fb1 | 2017-10-10 11:03:33 -0700 | [diff] [blame] | 169 | context, callDetailsEntries, contact, canReportCallerId, canSupportAssistedDialing); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 170 | } |
| 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 | } |