blob: 56f2cb1dc43797cffbf89deb313c03cba7a17a5f [file] [log] [blame]
Chiao Cheng94b10b52012-08-17 16:59:12 -07001/*
2 * Copyright (C) 2009 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;
18
Brian Attwellbeab3bb2014-10-27 12:24:49 -070019import android.app.Activity;
Chiao Cheng94b10b52012-08-17 16:59:12 -070020import android.content.ContentResolver;
21import android.content.ContentUris;
Chiao Cheng94b10b52012-08-17 16:59:12 -070022import android.content.Context;
23import android.content.Intent;
24import android.content.res.Resources;
Chiao Cheng94b10b52012-08-17 16:59:12 -070025import android.net.Uri;
Chiao Cheng94b10b52012-08-17 16:59:12 -070026import android.os.Bundle;
Yorke Lee71513982015-02-25 20:23:53 -080027import android.os.PowerManager;
Chiao Cheng94b10b52012-08-17 16:59:12 -070028import android.provider.ContactsContract.CommonDataKinds.Phone;
Chiao Cheng94b10b52012-08-17 16:59:12 -070029import android.provider.VoicemailContract.Voicemails;
Tyler Gunn9dc924c2014-09-12 09:33:50 -070030import android.telecom.PhoneAccount;
Nancy Chene80d6222014-10-08 20:17:55 -070031import android.telecom.PhoneAccountHandle;
Chiao Cheng94b10b52012-08-17 16:59:12 -070032import android.telephony.TelephonyManager;
Andrew Lee99e8adb2014-10-02 12:27:37 -070033import android.text.BidiFormatter;
34import android.text.TextDirectionHeuristics;
Chiao Cheng94b10b52012-08-17 16:59:12 -070035import android.text.TextUtils;
36import android.util.Log;
Chiao Cheng94b10b52012-08-17 16:59:12 -070037import android.view.KeyEvent;
38import android.view.LayoutInflater;
39import android.view.Menu;
40import android.view.MenuItem;
41import android.view.View;
Yorke Lee257b6f22014-07-31 14:16:44 -070042import android.widget.LinearLayout;
Chiao Cheng94b10b52012-08-17 16:59:12 -070043import android.widget.ListView;
Tyler Gunn18164c82014-06-09 10:20:57 -070044import android.widget.QuickContactBadge;
Chiao Cheng94b10b52012-08-17 16:59:12 -070045import android.widget.TextView;
46import android.widget.Toast;
47
Chiao Cheng35071c02012-10-15 18:36:24 -070048import com.android.contacts.common.ContactPhotoManager;
Yorke Lee56cb0ef2014-02-21 10:02:18 -080049import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest;
Yorke Lee2a613022015-07-01 14:28:13 -070050import com.android.contacts.common.util.PermissionsUtil;
Chiao Cheng35071c02012-10-15 18:36:24 -070051import com.android.contacts.common.GeoUtil;
Brian Attwell82043242015-02-03 14:13:58 -080052import com.android.contacts.common.CallUtil;
Tyler Gunn18b4a2e2015-08-05 08:18:37 -070053import com.android.contacts.common.util.UriUtils;
Chiao Cheng94b10b52012-08-17 16:59:12 -070054import com.android.dialer.calllog.CallDetailHistoryAdapter;
Andrew Lee7c461dc2015-05-15 10:18:45 -070055import com.android.dialer.calllog.CallLogAsyncTaskUtil.CallLogAsyncTaskListener;
56import com.android.dialer.calllog.CallLogAsyncTaskUtil;
Chiao Cheng94b10b52012-08-17 16:59:12 -070057import com.android.dialer.calllog.CallTypeHelper;
58import com.android.dialer.calllog.ContactInfo;
59import com.android.dialer.calllog.ContactInfoHelper;
Nancy Chenb2eebaf2014-07-21 13:41:36 -070060import com.android.dialer.calllog.PhoneAccountUtils;
Andrew Lee49efd912015-05-19 12:17:26 -070061import com.android.dialer.calllog.PhoneNumberDisplayUtil;
Yorke Lee39213592014-04-07 15:39:48 -070062import com.android.dialer.util.DialerUtils;
Andrew Leed3f6a6c2015-06-25 16:53:56 -070063import com.android.dialer.util.IntentUtil;
64import com.android.dialer.util.PhoneNumberUtil;
Yorke Lee4aece952015-05-02 22:22:54 -070065import com.android.dialer.util.TelecomUtil;
Chiao Cheng94b10b52012-08-17 16:59:12 -070066
67import java.util.List;
68
69/**
70 * Displays the details of a specific call log entry.
71 * <p>
72 * This activity can be either started with the URI of a single call log entry, or with the
73 * {@link #EXTRA_CALL_LOG_IDS} extra to specify a group of call log entries.
74 */
Andrew Lee2f05af32015-06-09 15:59:47 -070075public class CallDetailActivity extends Activity
76 implements MenuItem.OnMenuItemClickListener {
Chiao Cheng94b10b52012-08-17 16:59:12 -070077 private static final String TAG = "CallDetail";
78
Andrew Lee7c461dc2015-05-15 10:18:45 -070079 /** A long array extra containing ids of call log entries to display. */
Chiao Cheng94b10b52012-08-17 16:59:12 -070080 public static final String EXTRA_CALL_LOG_IDS = "EXTRA_CALL_LOG_IDS";
81 /** If we are started with a voicemail, we'll find the uri to play with this extra. */
82 public static final String EXTRA_VOICEMAIL_URI = "EXTRA_VOICEMAIL_URI";
Chiao Cheng94b10b52012-08-17 16:59:12 -070083 /** If the activity was triggered from a notification. */
84 public static final String EXTRA_FROM_NOTIFICATION = "EXTRA_FROM_NOTIFICATION";
85
Yorke Lee8cd94232014-07-23 14:05:31 -070086 public static final String VOICEMAIL_FRAGMENT_TAG = "voicemail_fragment";
87
Andrew Lee7c461dc2015-05-15 10:18:45 -070088 private CallLogAsyncTaskListener mCallLogAsyncTaskListener = new CallLogAsyncTaskListener() {
89 @Override
90 public void onDeleteCall() {
91 finish();
92 }
93
94 @Override
95 public void onDeleteVoicemail() {
96 finish();
97 }
98
99 @Override
100 public void onGetCallDetails(PhoneCallDetails[] details) {
Andrew Lee7c461dc2015-05-15 10:18:45 -0700101 if (details == null) {
102 // Somewhere went wrong: we're going to bail out and show error to users.
Andrew Leee177fe62015-06-05 13:01:09 -0700103 Toast.makeText(mContext, R.string.toast_call_detail_error,
Andrew Lee7c461dc2015-05-15 10:18:45 -0700104 Toast.LENGTH_SHORT).show();
105 finish();
106 return;
107 }
108
109 // We know that all calls are from the same number and the same contact, so pick the
110 // first.
111 PhoneCallDetails firstDetails = details[0];
112 mNumber = TextUtils.isEmpty(firstDetails.number) ?
113 null : firstDetails.number.toString();
114 final int numberPresentation = firstDetails.numberPresentation;
115 final Uri contactUri = firstDetails.contactUri;
116 final Uri photoUri = firstDetails.photoUri;
117 final PhoneAccountHandle accountHandle = firstDetails.accountHandle;
118
119 // Cache the details about the phone number.
120 final boolean canPlaceCallsTo =
Andrew Leed3f6a6c2015-06-25 16:53:56 -0700121 PhoneNumberUtil.canPlaceCallsTo(mNumber, numberPresentation);
Andrew Leee177fe62015-06-05 13:01:09 -0700122 mIsVoicemailNumber =
Andrew Leed3f6a6c2015-06-25 16:53:56 -0700123 PhoneNumberUtil.isVoicemailNumber(mContext, accountHandle, mNumber);
124 final boolean isSipNumber = PhoneNumberUtil.isSipNumber(mNumber);
Andrew Lee7c461dc2015-05-15 10:18:45 -0700125
126 final CharSequence callLocationOrType = getNumberTypeOrLocation(firstDetails);
127
128 final CharSequence displayNumber = firstDetails.displayNumber;
129 final String displayNumberStr = mBidiFormatter.unicodeWrap(
130 displayNumber.toString(), TextDirectionHeuristics.LTR);
131
132 if (!TextUtils.isEmpty(firstDetails.name)) {
133 mCallerName.setText(firstDetails.name);
134 mCallerNumber.setText(callLocationOrType + " " + displayNumberStr);
135 } else {
136 mCallerName.setText(displayNumberStr);
137 if (!TextUtils.isEmpty(callLocationOrType)) {
138 mCallerNumber.setText(callLocationOrType);
139 mCallerNumber.setVisibility(View.VISIBLE);
140 } else {
141 mCallerNumber.setVisibility(View.GONE);
142 }
143 }
144
Andrew Leee177fe62015-06-05 13:01:09 -0700145 mCallButton.setVisibility(canPlaceCallsTo ? View.VISIBLE : View.GONE);
146
147 String accountLabel = PhoneAccountUtils.getAccountLabel(mContext, accountHandle);
Andrew Lee7c461dc2015-05-15 10:18:45 -0700148 if (!TextUtils.isEmpty(accountLabel)) {
149 mAccountLabel.setText(accountLabel);
150 mAccountLabel.setVisibility(View.VISIBLE);
151 } else {
152 mAccountLabel.setVisibility(View.GONE);
153 }
154
155 mHasEditNumberBeforeCallOption =
Andrew Leee177fe62015-06-05 13:01:09 -0700156 canPlaceCallsTo && !isSipNumber && !mIsVoicemailNumber;
Andrew Lee2f05af32015-06-09 15:59:47 -0700157 mHasReportMenuOption = mContactInfoHelper.canReportAsInvalid(
158 firstDetails.sourceType, firstDetails.objectId);
Andrew Lee7c461dc2015-05-15 10:18:45 -0700159 invalidateOptionsMenu();
160
161 ListView historyList = (ListView) findViewById(R.id.history);
162 historyList.setAdapter(
Andrew Leee177fe62015-06-05 13:01:09 -0700163 new CallDetailHistoryAdapter(mContext, mInflater, mCallTypeHelper, details));
Andrew Lee7c461dc2015-05-15 10:18:45 -0700164
165 String lookupKey = contactUri == null ? null
Tyler Gunn18b4a2e2015-08-05 08:18:37 -0700166 : UriUtils.getLookupKeyFromUri(contactUri);
Andrew Lee7c461dc2015-05-15 10:18:45 -0700167
168 final boolean isBusiness = mContactInfoHelper.isBusiness(firstDetails.sourceType);
169
170 final int contactType =
Andrew Leee177fe62015-06-05 13:01:09 -0700171 mIsVoicemailNumber ? ContactPhotoManager.TYPE_VOICEMAIL :
Andrew Lee7c461dc2015-05-15 10:18:45 -0700172 isBusiness ? ContactPhotoManager.TYPE_BUSINESS :
173 ContactPhotoManager.TYPE_DEFAULT;
174
175 String nameForDefaultImage;
176 if (TextUtils.isEmpty(firstDetails.name)) {
177 nameForDefaultImage = firstDetails.displayNumber;
178 } else {
179 nameForDefaultImage = firstDetails.name.toString();
180 }
181
182 loadContactPhotos(
183 contactUri, photoUri, nameForDefaultImage, lookupKey, contactType);
184 findViewById(R.id.call_detail).setVisibility(View.VISIBLE);
185 }
186
187 /**
188 * Determines the location geocode text for a call, or the phone number type
189 * (if available).
190 *
191 * @param details The call details.
192 * @return The phone number type or location.
193 */
194 private CharSequence getNumberTypeOrLocation(PhoneCallDetails details) {
195 if (!TextUtils.isEmpty(details.name)) {
196 return Phone.getTypeLabel(mResources, details.numberType,
197 details.numberLabel);
198 } else {
199 return details.geocode;
200 }
201 }
202 };
203
Andrew Leee177fe62015-06-05 13:01:09 -0700204 private Context mContext;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700205 private CallTypeHelper mCallTypeHelper;
Tyler Gunn18164c82014-06-09 10:20:57 -0700206 private QuickContactBadge mQuickContactBadge;
207 private TextView mCallerName;
208 private TextView mCallerNumber;
Nancy Chen19702632014-07-25 13:23:16 -0700209 private TextView mAccountLabel;
Andrew Leee177fe62015-06-05 13:01:09 -0700210 private View mCallButton;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700211 private ContactInfoHelper mContactInfoHelper;
212
Andrew Lee2f05af32015-06-09 15:59:47 -0700213 protected String mNumber;
Andrew Leee177fe62015-06-05 13:01:09 -0700214 private boolean mIsVoicemailNumber;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700215 private String mDefaultCountryIso;
216
217 /* package */ LayoutInflater mInflater;
218 /* package */ Resources mResources;
219 /** Helper to load contact photos. */
220 private ContactPhotoManager mContactPhotoManager;
Andrew Leec1167e92015-05-18 11:27:54 -0700221
Yorke Lee257b6f22014-07-31 14:16:44 -0700222 private Uri mVoicemailUri;
Andrew Lee99e8adb2014-10-02 12:27:37 -0700223 private BidiFormatter mBidiFormatter = BidiFormatter.getInstance();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700224
225 /** Whether we should show "edit number before call" in the options menu. */
226 private boolean mHasEditNumberBeforeCallOption;
Andrew Lee2f05af32015-06-09 15:59:47 -0700227 private boolean mHasReportMenuOption;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700228
Chiao Cheng94b10b52012-08-17 16:59:12 -0700229 @Override
230 protected void onCreate(Bundle icicle) {
231 super.onCreate(icicle);
232
Andrew Leee177fe62015-06-05 13:01:09 -0700233 mContext = this;
234
Chiao Cheng94b10b52012-08-17 16:59:12 -0700235 setContentView(R.layout.call_detail);
236
Chiao Cheng94b10b52012-08-17 16:59:12 -0700237 mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
238 mResources = getResources();
239
240 mCallTypeHelper = new CallTypeHelper(getResources());
Yorke Lee257b6f22014-07-31 14:16:44 -0700241
242 mVoicemailUri = getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI);
243
Tyler Gunn18164c82014-06-09 10:20:57 -0700244 mQuickContactBadge = (QuickContactBadge) findViewById(R.id.quick_contact_photo);
245 mQuickContactBadge.setOverlay(null);
Brian Attwell74eb4ec2015-02-25 22:31:22 -0800246 mQuickContactBadge.setPrioritizedMimeType(Phone.CONTENT_ITEM_TYPE);
Tyler Gunn18164c82014-06-09 10:20:57 -0700247 mCallerName = (TextView) findViewById(R.id.caller_name);
248 mCallerNumber = (TextView) findViewById(R.id.caller_number);
Nancy Chen19702632014-07-25 13:23:16 -0700249 mAccountLabel = (TextView) findViewById(R.id.phone_account_label);
Chiao Cheng35071c02012-10-15 18:36:24 -0700250 mDefaultCountryIso = GeoUtil.getCurrentCountryIso(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700251 mContactPhotoManager = ContactPhotoManager.getInstance(this);
Yorke Lee71513982015-02-25 20:23:53 -0800252
Andrew Leee177fe62015-06-05 13:01:09 -0700253 mCallButton = (View) findViewById(R.id.call_back_button);
254 mCallButton.setOnClickListener(new View.OnClickListener() {
255 @Override
256 public void onClick(View view) {
257 mContext.startActivity(IntentUtil.getCallIntent(mNumber));
258 }
259 });
260
Chiao Cheng35071c02012-10-15 18:36:24 -0700261 mContactInfoHelper = new ContactInfoHelper(this, GeoUtil.getCurrentCountryIso(this));
Chiao Chengadb742c2013-10-07 17:46:25 -0700262 getActionBar().setDisplayHomeAsUpEnabled(true);
Yorke Lee257b6f22014-07-31 14:16:44 -0700263
Chiao Cheng94b10b52012-08-17 16:59:12 -0700264 if (getIntent().getBooleanExtra(EXTRA_FROM_NOTIFICATION, false)) {
265 closeSystemDialogs();
266 }
267 }
268
269 @Override
270 public void onResume() {
271 super.onResume();
Andrew Lee2f05af32015-06-09 15:59:47 -0700272 getCallDetails();
273 }
Andrew Lee7c461dc2015-05-15 10:18:45 -0700274
Andrew Lee2f05af32015-06-09 15:59:47 -0700275 public void getCallDetails() {
Andrew Lee7c461dc2015-05-15 10:18:45 -0700276 CallLogAsyncTaskUtil.getCallDetails(this, getCallLogEntryUris(), mCallLogAsyncTaskListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700277 }
278
Chiao Cheng94b10b52012-08-17 16:59:12 -0700279 private boolean hasVoicemail() {
Yorke Lee257b6f22014-07-31 14:16:44 -0700280 return mVoicemailUri != null;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700281 }
282
Chiao Cheng94b10b52012-08-17 16:59:12 -0700283 /**
284 * Returns the list of URIs to show.
285 * <p>
286 * There are two ways the URIs can be provided to the activity: as the data on the intent, or as
287 * a list of ids in the call log added as an extra on the URI.
288 * <p>
289 * If both are available, the data on the intent takes precedence.
290 */
291 private Uri[] getCallLogEntryUris() {
Jay Shrauner757bdd32014-05-28 10:13:40 -0700292 final Uri uri = getIntent().getData();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700293 if (uri != null) {
294 // If there is a data on the intent, it takes precedence over the extra.
295 return new Uri[]{ uri };
296 }
Jay Shrauner757bdd32014-05-28 10:13:40 -0700297 final long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS);
298 final int numIds = ids == null ? 0 : ids.length;
299 final Uri[] uris = new Uri[numIds];
300 for (int index = 0; index < numIds; ++index) {
Yorke Lee4aece952015-05-02 22:22:54 -0700301 uris[index] = ContentUris.withAppendedId(
302 TelecomUtil.getCallLogUri(CallDetailActivity.this), ids[index]);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700303 }
304 return uris;
305 }
306
Chiao Cheng94b10b52012-08-17 16:59:12 -0700307 /** Load the contact photos and places them in the corresponding views. */
Tyler Gunn18164c82014-06-09 10:20:57 -0700308 private void loadContactPhotos(Uri contactUri, Uri photoUri, String displayName,
309 String lookupKey, int contactType) {
310
Yorke Lee56cb0ef2014-02-21 10:02:18 -0800311 final DefaultImageRequest request = new DefaultImageRequest(displayName, lookupKey,
Tyler Gunn18164c82014-06-09 10:20:57 -0700312 contactType, true /* isCircular */);
313
314 mQuickContactBadge.assignContactUri(contactUri);
315 mQuickContactBadge.setContentDescription(
316 mResources.getString(R.string.description_contact_details, displayName));
317
318 mContactPhotoManager.loadDirectoryPhoto(mQuickContactBadge, photoUri,
319 false /* darkTheme */, true /* isCircular */, request);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700320 }
321
Chiao Cheng94b10b52012-08-17 16:59:12 -0700322 @Override
323 public boolean onCreateOptionsMenu(Menu menu) {
324 getMenuInflater().inflate(R.menu.call_details_options, menu);
325 return super.onCreateOptionsMenu(menu);
326 }
327
328 @Override
329 public boolean onPrepareOptionsMenu(Menu menu) {
330 // This action deletes all elements in the group from the call log.
331 // We don't have this action for voicemails, because you can just use the trash button.
Andrew Lee2f05af32015-06-09 15:59:47 -0700332 menu.findItem(R.id.menu_remove_from_call_log)
333 .setVisible(!hasVoicemail())
334 .setOnMenuItemClickListener(this);
335 menu.findItem(R.id.menu_edit_number_before_call)
336 .setVisible(mHasEditNumberBeforeCallOption)
337 .setOnMenuItemClickListener(this);
338 menu.findItem(R.id.menu_trash)
339 .setVisible(hasVoicemail())
340 .setOnMenuItemClickListener(this);
341 menu.findItem(R.id.menu_report)
342 .setVisible(mHasReportMenuOption)
343 .setOnMenuItemClickListener(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700344 return super.onPrepareOptionsMenu(menu);
345 }
346
Andrew Lee2f05af32015-06-09 15:59:47 -0700347 @Override
348 public boolean onMenuItemClick(MenuItem item) {
349 switch (item.getItemId()) {
350 case R.id.menu_remove_from_call_log:
351 final StringBuilder callIds = new StringBuilder();
352 for (Uri callUri : getCallLogEntryUris()) {
353 if (callIds.length() != 0) {
354 callIds.append(",");
355 }
356 callIds.append(ContentUris.parseId(callUri));
357 }
358 CallLogAsyncTaskUtil.deleteCalls(
359 this, callIds.toString(), mCallLogAsyncTaskListener);
360 break;
361 case R.id.menu_edit_number_before_call:
362 startActivity(new Intent(Intent.ACTION_DIAL, CallUtil.getCallUri(mNumber)));
363 break;
364 case R.id.menu_trash:
365 CallLogAsyncTaskUtil.deleteVoicemail(
366 this, mVoicemailUri, mCallLogAsyncTaskListener);
367 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700368 }
Andrew Lee2f05af32015-06-09 15:59:47 -0700369 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700370 }
371
Chiao Cheng94b10b52012-08-17 16:59:12 -0700372 private void closeSystemDialogs() {
373 sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
374 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700375}