Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.dialer; |
| 18 | |
Brian Attwell | beab3bb | 2014-10-27 12:24:49 -0700 | [diff] [blame] | 19 | import android.app.Activity; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 20 | import android.content.ContentResolver; |
| 21 | import android.content.ContentUris; |
| 22 | import android.content.ContentValues; |
| 23 | import android.content.Context; |
| 24 | import android.content.Intent; |
| 25 | import android.content.res.Resources; |
| 26 | import android.database.Cursor; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 27 | import android.net.Uri; |
| 28 | import android.os.AsyncTask; |
| 29 | import android.os.Bundle; |
Yorke Lee | 7151398 | 2015-02-25 20:23:53 -0800 | [diff] [blame] | 30 | import android.os.PowerManager; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 31 | import android.provider.CallLog; |
| 32 | import android.provider.CallLog.Calls; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 33 | import android.provider.ContactsContract.CommonDataKinds.Phone; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 34 | import android.provider.VoicemailContract.Voicemails; |
Tyler Gunn | 9dc924c | 2014-09-12 09:33:50 -0700 | [diff] [blame] | 35 | import android.telecom.PhoneAccount; |
Nancy Chen | e80d622 | 2014-10-08 20:17:55 -0700 | [diff] [blame] | 36 | import android.telecom.PhoneAccountHandle; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 37 | import android.telephony.TelephonyManager; |
Andrew Lee | 99e8adb | 2014-10-02 12:27:37 -0700 | [diff] [blame] | 38 | import android.text.BidiFormatter; |
| 39 | import android.text.TextDirectionHeuristics; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 40 | import android.text.TextUtils; |
| 41 | import android.util.Log; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 42 | import android.view.KeyEvent; |
| 43 | import android.view.LayoutInflater; |
| 44 | import android.view.Menu; |
| 45 | import android.view.MenuItem; |
| 46 | import android.view.View; |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 47 | import android.widget.LinearLayout; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 48 | import android.widget.ListView; |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 49 | import android.widget.QuickContactBadge; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 50 | import android.widget.TextView; |
| 51 | import android.widget.Toast; |
| 52 | |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 53 | import com.android.contacts.common.ContactPhotoManager; |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 54 | import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest; |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 55 | import com.android.contacts.common.GeoUtil; |
Brian Attwell | 8204324 | 2015-02-03 14:13:58 -0800 | [diff] [blame] | 56 | import com.android.contacts.common.CallUtil; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 57 | import com.android.dialer.calllog.CallDetailHistoryAdapter; |
Nancy Chen | f153bf4 | 2015-05-06 19:29:56 -0700 | [diff] [blame] | 58 | import com.android.dialer.calllog.CallLogNotificationsService; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 59 | import com.android.dialer.calllog.CallTypeHelper; |
| 60 | import com.android.dialer.calllog.ContactInfo; |
| 61 | import com.android.dialer.calllog.ContactInfoHelper; |
Nancy Chen | b2eebaf | 2014-07-21 13:41:36 -0700 | [diff] [blame] | 62 | import com.android.dialer.calllog.PhoneAccountUtils; |
Andrew Lee | 49efd91 | 2015-05-19 12:17:26 -0700 | [diff] [blame^] | 63 | import com.android.dialer.calllog.PhoneNumberDisplayUtil; |
Chiao Cheng | fb0a934 | 2013-09-13 17:27:42 -0700 | [diff] [blame] | 64 | import com.android.dialer.calllog.PhoneNumberUtilsWrapper; |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 65 | import com.android.dialer.util.AsyncTaskExecutor; |
| 66 | import com.android.dialer.util.AsyncTaskExecutors; |
Andrew Lee | 247df6e | 2015-05-12 19:09:00 -0700 | [diff] [blame] | 67 | import com.android.dialer.util.IntentUtil; |
Yorke Lee | 3921359 | 2014-04-07 15:39:48 -0700 | [diff] [blame] | 68 | import com.android.dialer.util.DialerUtils; |
Yorke Lee | 4aece95 | 2015-05-02 22:22:54 -0700 | [diff] [blame] | 69 | import com.android.dialer.util.TelecomUtil; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 70 | import com.android.dialer.voicemail.VoicemailPlaybackFragment; |
| 71 | import com.android.dialer.voicemail.VoicemailStatusHelper; |
| 72 | import com.android.dialer.voicemail.VoicemailStatusHelper.StatusMessage; |
| 73 | import com.android.dialer.voicemail.VoicemailStatusHelperImpl; |
| 74 | |
| 75 | import java.util.List; |
| 76 | |
| 77 | /** |
| 78 | * Displays the details of a specific call log entry. |
| 79 | * <p> |
| 80 | * This activity can be either started with the URI of a single call log entry, or with the |
| 81 | * {@link #EXTRA_CALL_LOG_IDS} extra to specify a group of call log entries. |
| 82 | */ |
Andrew Lee | 93b816f | 2015-05-13 12:23:35 -0700 | [diff] [blame] | 83 | public class CallDetailActivity extends Activity { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 84 | private static final String TAG = "CallDetail"; |
| 85 | |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 86 | private static final char LEFT_TO_RIGHT_EMBEDDING = '\u202A'; |
| 87 | private static final char POP_DIRECTIONAL_FORMATTING = '\u202C'; |
| 88 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 89 | /** The enumeration of {@link AsyncTask} objects used in this class. */ |
| 90 | public enum Tasks { |
| 91 | MARK_VOICEMAIL_READ, |
| 92 | DELETE_VOICEMAIL_AND_FINISH, |
| 93 | REMOVE_FROM_CALL_LOG_AND_FINISH, |
| 94 | UPDATE_PHONE_CALL_DETAILS, |
| 95 | } |
| 96 | |
| 97 | /** A long array extra containing ids of call log entries to display. */ |
| 98 | public static final String EXTRA_CALL_LOG_IDS = "EXTRA_CALL_LOG_IDS"; |
| 99 | /** If we are started with a voicemail, we'll find the uri to play with this extra. */ |
| 100 | public static final String EXTRA_VOICEMAIL_URI = "EXTRA_VOICEMAIL_URI"; |
| 101 | /** If we should immediately start playback of the voicemail, this extra will be set to true. */ |
| 102 | public static final String EXTRA_VOICEMAIL_START_PLAYBACK = "EXTRA_VOICEMAIL_START_PLAYBACK"; |
| 103 | /** If the activity was triggered from a notification. */ |
| 104 | public static final String EXTRA_FROM_NOTIFICATION = "EXTRA_FROM_NOTIFICATION"; |
| 105 | |
Yorke Lee | 8cd9423 | 2014-07-23 14:05:31 -0700 | [diff] [blame] | 106 | public static final String VOICEMAIL_FRAGMENT_TAG = "voicemail_fragment"; |
| 107 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 108 | private CallTypeHelper mCallTypeHelper; |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 109 | private QuickContactBadge mQuickContactBadge; |
| 110 | private TextView mCallerName; |
| 111 | private TextView mCallerNumber; |
Nancy Chen | 1970263 | 2014-07-25 13:23:16 -0700 | [diff] [blame] | 112 | private TextView mAccountLabel; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 113 | private AsyncTaskExecutor mAsyncTaskExecutor; |
| 114 | private ContactInfoHelper mContactInfoHelper; |
| 115 | |
| 116 | private String mNumber = null; |
| 117 | private String mDefaultCountryIso; |
| 118 | |
| 119 | /* package */ LayoutInflater mInflater; |
| 120 | /* package */ Resources mResources; |
| 121 | /** Helper to load contact photos. */ |
| 122 | private ContactPhotoManager mContactPhotoManager; |
Andrew Lee | c1167e9 | 2015-05-18 11:27:54 -0700 | [diff] [blame] | 123 | |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 124 | private LinearLayout mVoicemailHeader; |
| 125 | |
| 126 | private Uri mVoicemailUri; |
Andrew Lee | 99e8adb | 2014-10-02 12:27:37 -0700 | [diff] [blame] | 127 | private BidiFormatter mBidiFormatter = BidiFormatter.getInstance(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 128 | |
| 129 | /** Whether we should show "edit number before call" in the options menu. */ |
| 130 | private boolean mHasEditNumberBeforeCallOption; |
| 131 | /** Whether we should show "trash" in the options menu. */ |
| 132 | private boolean mHasTrashOption; |
| 133 | /** Whether we should show "remove from call log" in the options menu. */ |
| 134 | private boolean mHasRemoveFromCallLogOption; |
| 135 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 136 | static final String[] CALL_LOG_PROJECTION = new String[] { |
| 137 | CallLog.Calls.DATE, |
| 138 | CallLog.Calls.DURATION, |
| 139 | CallLog.Calls.NUMBER, |
| 140 | CallLog.Calls.TYPE, |
| 141 | CallLog.Calls.COUNTRY_ISO, |
| 142 | CallLog.Calls.GEOCODED_LOCATION, |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 143 | CallLog.Calls.NUMBER_PRESENTATION, |
Ihab Awad | c8daf20 | 2014-07-02 14:03:28 -0700 | [diff] [blame] | 144 | CallLog.Calls.PHONE_ACCOUNT_COMPONENT_NAME, |
| 145 | CallLog.Calls.PHONE_ACCOUNT_ID, |
Tyler Gunn | 8b0e858 | 2014-07-10 12:28:43 -0700 | [diff] [blame] | 146 | CallLog.Calls.FEATURES, |
Yorke Lee | 8cd9423 | 2014-07-23 14:05:31 -0700 | [diff] [blame] | 147 | CallLog.Calls.DATA_USAGE, |
| 148 | CallLog.Calls.TRANSCRIPTION |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 149 | }; |
| 150 | |
| 151 | static final int DATE_COLUMN_INDEX = 0; |
| 152 | static final int DURATION_COLUMN_INDEX = 1; |
| 153 | static final int NUMBER_COLUMN_INDEX = 2; |
| 154 | static final int CALL_TYPE_COLUMN_INDEX = 3; |
| 155 | static final int COUNTRY_ISO_COLUMN_INDEX = 4; |
| 156 | static final int GEOCODED_LOCATION_COLUMN_INDEX = 5; |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 157 | static final int NUMBER_PRESENTATION_COLUMN_INDEX = 6; |
Ihab Awad | 1d1bd0d | 2014-06-30 21:24:01 -0700 | [diff] [blame] | 158 | static final int ACCOUNT_COMPONENT_NAME = 7; |
| 159 | static final int ACCOUNT_ID = 8; |
Tyler Gunn | 8b0e858 | 2014-07-10 12:28:43 -0700 | [diff] [blame] | 160 | static final int FEATURES = 9; |
| 161 | static final int DATA_USAGE = 10; |
Yorke Lee | 8cd9423 | 2014-07-23 14:05:31 -0700 | [diff] [blame] | 162 | static final int TRANSCRIPTION_COLUMN_INDEX = 11; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 163 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 164 | @Override |
| 165 | protected void onCreate(Bundle icicle) { |
| 166 | super.onCreate(icicle); |
| 167 | |
| 168 | setContentView(R.layout.call_detail); |
| 169 | |
| 170 | mAsyncTaskExecutor = AsyncTaskExecutors.createThreadPoolExecutor(); |
| 171 | mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); |
| 172 | mResources = getResources(); |
| 173 | |
| 174 | mCallTypeHelper = new CallTypeHelper(getResources()); |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 175 | |
| 176 | mVoicemailUri = getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI); |
| 177 | |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 178 | mQuickContactBadge = (QuickContactBadge) findViewById(R.id.quick_contact_photo); |
| 179 | mQuickContactBadge.setOverlay(null); |
Brian Attwell | 74eb4ec | 2015-02-25 22:31:22 -0800 | [diff] [blame] | 180 | mQuickContactBadge.setPrioritizedMimeType(Phone.CONTENT_ITEM_TYPE); |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 181 | mCallerName = (TextView) findViewById(R.id.caller_name); |
| 182 | mCallerNumber = (TextView) findViewById(R.id.caller_number); |
Nancy Chen | 1970263 | 2014-07-25 13:23:16 -0700 | [diff] [blame] | 183 | mAccountLabel = (TextView) findViewById(R.id.phone_account_label); |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 184 | mDefaultCountryIso = GeoUtil.getCurrentCountryIso(this); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 185 | mContactPhotoManager = ContactPhotoManager.getInstance(this); |
Yorke Lee | 7151398 | 2015-02-25 20:23:53 -0800 | [diff] [blame] | 186 | |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 187 | mContactInfoHelper = new ContactInfoHelper(this, GeoUtil.getCurrentCountryIso(this)); |
Chiao Cheng | adb742c | 2013-10-07 17:46:25 -0700 | [diff] [blame] | 188 | getActionBar().setDisplayHomeAsUpEnabled(true); |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 189 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 190 | optionallyHandleVoicemail(); |
| 191 | if (getIntent().getBooleanExtra(EXTRA_FROM_NOTIFICATION, false)) { |
| 192 | closeSystemDialogs(); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | @Override |
| 197 | public void onResume() { |
| 198 | super.onResume(); |
| 199 | updateData(getCallLogEntryUris()); |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * Handle voicemail playback or hide voicemail ui. |
| 204 | * <p> |
| 205 | * If the Intent used to start this Activity contains the suitable extras, then start voicemail |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 206 | * playback. If it doesn't, then don't inflate the voicemail ui. |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 207 | */ |
| 208 | private void optionallyHandleVoicemail() { |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 209 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 210 | if (hasVoicemail()) { |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 211 | LayoutInflater inflater = |
| 212 | (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
| 213 | mVoicemailHeader = |
| 214 | (LinearLayout) inflater.inflate(R.layout.call_details_voicemail_header, null); |
| 215 | View voicemailContainer = mVoicemailHeader.findViewById(R.id.voicemail_container); |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 216 | ListView historyList = (ListView) findViewById(R.id.history); |
| 217 | historyList.addHeaderView(mVoicemailHeader); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 218 | // Has voicemail: add the voicemail fragment. Add suitable arguments to set the uri |
| 219 | // to play and optionally start the playback. |
| 220 | // Do a query to fetch the voicemail status messages. |
Yorke Lee | 8cd9423 | 2014-07-23 14:05:31 -0700 | [diff] [blame] | 221 | VoicemailPlaybackFragment playbackFragment; |
| 222 | |
| 223 | playbackFragment = (VoicemailPlaybackFragment) getFragmentManager().findFragmentByTag( |
| 224 | VOICEMAIL_FRAGMENT_TAG); |
| 225 | |
| 226 | if (playbackFragment == null) { |
| 227 | playbackFragment = new VoicemailPlaybackFragment(); |
| 228 | Bundle fragmentArguments = new Bundle(); |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 229 | fragmentArguments.putParcelable(EXTRA_VOICEMAIL_URI, mVoicemailUri); |
Yorke Lee | 8cd9423 | 2014-07-23 14:05:31 -0700 | [diff] [blame] | 230 | if (getIntent().getBooleanExtra(EXTRA_VOICEMAIL_START_PLAYBACK, false)) { |
| 231 | fragmentArguments.putBoolean(EXTRA_VOICEMAIL_START_PLAYBACK, true); |
| 232 | } |
| 233 | playbackFragment.setArguments(fragmentArguments); |
| 234 | getFragmentManager().beginTransaction() |
| 235 | .add(R.id.voicemail_container, playbackFragment, VOICEMAIL_FRAGMENT_TAG) |
| 236 | .commitAllowingStateLoss(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 237 | } |
Yorke Lee | 8cd9423 | 2014-07-23 14:05:31 -0700 | [diff] [blame] | 238 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 239 | voicemailContainer.setVisibility(View.VISIBLE); |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 240 | markVoicemailAsRead(mVoicemailUri); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 241 | } |
| 242 | } |
| 243 | |
| 244 | private boolean hasVoicemail() { |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 245 | return mVoicemailUri != null; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | private void markVoicemailAsRead(final Uri voicemailUri) { |
| 249 | mAsyncTaskExecutor.submit(Tasks.MARK_VOICEMAIL_READ, new AsyncTask<Void, Void, Void>() { |
| 250 | @Override |
| 251 | public Void doInBackground(Void... params) { |
| 252 | ContentValues values = new ContentValues(); |
| 253 | values.put(Voicemails.IS_READ, true); |
| 254 | getContentResolver().update(voicemailUri, values, |
| 255 | Voicemails.IS_READ + " = 0", null); |
Nancy Chen | f153bf4 | 2015-05-06 19:29:56 -0700 | [diff] [blame] | 256 | Intent intent = new Intent(getBaseContext(), CallLogNotificationsService.class); |
| 257 | intent.setAction(CallLogNotificationsService.ACTION_MARK_NEW_VOICEMAILS_AS_OLD); |
| 258 | getBaseContext().startService(intent); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 259 | return null; |
| 260 | } |
| 261 | }); |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * Returns the list of URIs to show. |
| 266 | * <p> |
| 267 | * There are two ways the URIs can be provided to the activity: as the data on the intent, or as |
| 268 | * a list of ids in the call log added as an extra on the URI. |
| 269 | * <p> |
| 270 | * If both are available, the data on the intent takes precedence. |
| 271 | */ |
| 272 | private Uri[] getCallLogEntryUris() { |
Jay Shrauner | 757bdd3 | 2014-05-28 10:13:40 -0700 | [diff] [blame] | 273 | final Uri uri = getIntent().getData(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 274 | if (uri != null) { |
| 275 | // If there is a data on the intent, it takes precedence over the extra. |
| 276 | return new Uri[]{ uri }; |
| 277 | } |
Jay Shrauner | 757bdd3 | 2014-05-28 10:13:40 -0700 | [diff] [blame] | 278 | final long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS); |
| 279 | final int numIds = ids == null ? 0 : ids.length; |
| 280 | final Uri[] uris = new Uri[numIds]; |
| 281 | for (int index = 0; index < numIds; ++index) { |
Yorke Lee | 4aece95 | 2015-05-02 22:22:54 -0700 | [diff] [blame] | 282 | uris[index] = ContentUris.withAppendedId( |
| 283 | TelecomUtil.getCallLogUri(CallDetailActivity.this), ids[index]); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 284 | } |
| 285 | return uris; |
| 286 | } |
| 287 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 288 | /** |
| 289 | * Update user interface with details of given call. |
| 290 | * |
Nancy Chen | e80d622 | 2014-10-08 20:17:55 -0700 | [diff] [blame] | 291 | * @param callUris URIs into {@link android.provider.CallLog.Calls} of the calls to be displayed |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 292 | */ |
| 293 | private void updateData(final Uri... callUris) { |
| 294 | class UpdateContactDetailsTask extends AsyncTask<Void, Void, PhoneCallDetails[]> { |
| 295 | @Override |
| 296 | public PhoneCallDetails[] doInBackground(Void... params) { |
| 297 | // TODO: All phone calls correspond to the same person, so we can make a single |
| 298 | // lookup. |
| 299 | final int numCalls = callUris.length; |
| 300 | PhoneCallDetails[] details = new PhoneCallDetails[numCalls]; |
| 301 | try { |
| 302 | for (int index = 0; index < numCalls; ++index) { |
| 303 | details[index] = getPhoneCallDetailsForUri(callUris[index]); |
| 304 | } |
| 305 | return details; |
| 306 | } catch (IllegalArgumentException e) { |
| 307 | // Something went wrong reading in our primary data. |
| 308 | Log.w(TAG, "invalid URI starting call details", e); |
| 309 | return null; |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | @Override |
| 314 | public void onPostExecute(PhoneCallDetails[] details) { |
Nancy Chen | e80d622 | 2014-10-08 20:17:55 -0700 | [diff] [blame] | 315 | Context context = CallDetailActivity.this; |
| 316 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 317 | if (details == null) { |
| 318 | // Somewhere went wrong: we're going to bail out and show error to users. |
Nancy Chen | e80d622 | 2014-10-08 20:17:55 -0700 | [diff] [blame] | 319 | Toast.makeText(context, R.string.toast_call_detail_error, |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 320 | Toast.LENGTH_SHORT).show(); |
| 321 | finish(); |
| 322 | return; |
| 323 | } |
| 324 | |
| 325 | // We know that all calls are from the same number and the same contact, so pick the |
| 326 | // first. |
| 327 | PhoneCallDetails firstDetails = details[0]; |
Nancy Chen | 164d9d5 | 2015-03-09 16:24:08 -0700 | [diff] [blame] | 328 | mNumber = TextUtils.isEmpty(firstDetails.number) ? |
| 329 | null : firstDetails.number.toString(); |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 330 | final int numberPresentation = firstDetails.numberPresentation; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 331 | final Uri contactUri = firstDetails.contactUri; |
| 332 | final Uri photoUri = firstDetails.photoUri; |
Nancy Chen | e80d622 | 2014-10-08 20:17:55 -0700 | [diff] [blame] | 333 | final PhoneAccountHandle accountHandle = firstDetails.accountHandle; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 334 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 335 | // Cache the details about the phone number. |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 336 | final boolean canPlaceCallsTo = |
Chiao Cheng | fb0a934 | 2013-09-13 17:27:42 -0700 | [diff] [blame] | 337 | PhoneNumberUtilsWrapper.canPlaceCallsTo(mNumber, numberPresentation); |
Nancy Chen | e80d622 | 2014-10-08 20:17:55 -0700 | [diff] [blame] | 338 | final PhoneNumberUtilsWrapper phoneUtils = new PhoneNumberUtilsWrapper(context); |
| 339 | final boolean isVoicemailNumber = |
| 340 | phoneUtils.isVoicemailNumber(accountHandle, mNumber); |
| 341 | final boolean isSipNumber = PhoneNumberUtilsWrapper.isSipNumber(mNumber); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 342 | |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 343 | final CharSequence callLocationOrType = getNumberTypeOrLocation(firstDetails); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 344 | |
Andrew Lee | 49efd91 | 2015-05-19 12:17:26 -0700 | [diff] [blame^] | 345 | final CharSequence displayNumber = firstDetails.displayNumber; |
Andrew Lee | 99e8adb | 2014-10-02 12:27:37 -0700 | [diff] [blame] | 346 | final String displayNumberStr = mBidiFormatter.unicodeWrap( |
| 347 | displayNumber.toString(), TextDirectionHeuristics.LTR); |
| 348 | |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 349 | if (!TextUtils.isEmpty(firstDetails.name)) { |
| 350 | mCallerName.setText(firstDetails.name); |
Andrew Lee | 99e8adb | 2014-10-02 12:27:37 -0700 | [diff] [blame] | 351 | mCallerNumber.setText(callLocationOrType + " " + displayNumberStr); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 352 | } else { |
Andrew Lee | 99e8adb | 2014-10-02 12:27:37 -0700 | [diff] [blame] | 353 | mCallerName.setText(displayNumberStr); |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 354 | if (!TextUtils.isEmpty(callLocationOrType)) { |
| 355 | mCallerNumber.setText(callLocationOrType); |
| 356 | mCallerNumber.setVisibility(View.VISIBLE); |
| 357 | } else { |
| 358 | mCallerNumber.setVisibility(View.GONE); |
| 359 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Nancy Chen | e80d622 | 2014-10-08 20:17:55 -0700 | [diff] [blame] | 362 | String accountLabel = PhoneAccountUtils.getAccountLabel(context, accountHandle); |
| 363 | if (!TextUtils.isEmpty(accountLabel)) { |
| 364 | mAccountLabel.setText(accountLabel); |
Nancy Chen | 1970263 | 2014-07-25 13:23:16 -0700 | [diff] [blame] | 365 | mAccountLabel.setVisibility(View.VISIBLE); |
| 366 | } else { |
| 367 | mAccountLabel.setVisibility(View.GONE); |
| 368 | } |
| 369 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 370 | mHasEditNumberBeforeCallOption = |
| 371 | canPlaceCallsTo && !isSipNumber && !isVoicemailNumber; |
| 372 | mHasTrashOption = hasVoicemail(); |
| 373 | mHasRemoveFromCallLogOption = !hasVoicemail(); |
| 374 | invalidateOptionsMenu(); |
| 375 | |
| 376 | ListView historyList = (ListView) findViewById(R.id.history); |
| 377 | historyList.setAdapter( |
Nancy Chen | e80d622 | 2014-10-08 20:17:55 -0700 | [diff] [blame] | 378 | new CallDetailHistoryAdapter(context, mInflater, mCallTypeHelper, details)); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 379 | |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 380 | String lookupKey = contactUri == null ? null |
| 381 | : ContactInfoHelper.getLookupKeyFromUri(contactUri); |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 382 | |
| 383 | final boolean isBusiness = mContactInfoHelper.isBusiness(firstDetails.sourceType); |
| 384 | |
| 385 | final int contactType = |
| 386 | isVoicemailNumber? ContactPhotoManager.TYPE_VOICEMAIL : |
| 387 | isBusiness ? ContactPhotoManager.TYPE_BUSINESS : |
| 388 | ContactPhotoManager.TYPE_DEFAULT; |
| 389 | |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 390 | String nameForDefaultImage; |
| 391 | if (TextUtils.isEmpty(firstDetails.name)) { |
Andrew Lee | 49efd91 | 2015-05-19 12:17:26 -0700 | [diff] [blame^] | 392 | nameForDefaultImage = firstDetails.displayNumber.toString(); |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 393 | } else { |
| 394 | nameForDefaultImage = firstDetails.name.toString(); |
| 395 | } |
| 396 | |
| 397 | loadContactPhotos( |
| 398 | contactUri, photoUri, nameForDefaultImage, lookupKey, contactType); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 399 | findViewById(R.id.call_detail).setVisibility(View.VISIBLE); |
| 400 | } |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 401 | |
| 402 | /** |
| 403 | * Determines the location geocode text for a call, or the phone number type |
| 404 | * (if available). |
| 405 | * |
| 406 | * @param details The call details. |
| 407 | * @return The phone number type or location. |
| 408 | */ |
| 409 | private CharSequence getNumberTypeOrLocation(PhoneCallDetails details) { |
| 410 | if (!TextUtils.isEmpty(details.name)) { |
| 411 | return Phone.getTypeLabel(mResources, details.numberType, |
| 412 | details.numberLabel); |
| 413 | } else { |
| 414 | return details.geocode; |
| 415 | } |
| 416 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 417 | } |
| 418 | mAsyncTaskExecutor.submit(Tasks.UPDATE_PHONE_CALL_DETAILS, new UpdateContactDetailsTask()); |
| 419 | } |
| 420 | |
| 421 | /** Return the phone call details for a given call log URI. */ |
| 422 | private PhoneCallDetails getPhoneCallDetailsForUri(Uri callUri) { |
| 423 | ContentResolver resolver = getContentResolver(); |
| 424 | Cursor callCursor = resolver.query(callUri, CALL_LOG_PROJECTION, null, null, null); |
| 425 | try { |
| 426 | if (callCursor == null || !callCursor.moveToFirst()) { |
| 427 | throw new IllegalArgumentException("Cannot find content: " + callUri); |
| 428 | } |
| 429 | |
| 430 | // Read call log specifics. |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 431 | final String number = callCursor.getString(NUMBER_COLUMN_INDEX); |
| 432 | final int numberPresentation = callCursor.getInt( |
| 433 | NUMBER_PRESENTATION_COLUMN_INDEX); |
| 434 | final long date = callCursor.getLong(DATE_COLUMN_INDEX); |
| 435 | final long duration = callCursor.getLong(DURATION_COLUMN_INDEX); |
| 436 | final int callType = callCursor.getInt(CALL_TYPE_COLUMN_INDEX); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 437 | String countryIso = callCursor.getString(COUNTRY_ISO_COLUMN_INDEX); |
| 438 | final String geocode = callCursor.getString(GEOCODED_LOCATION_COLUMN_INDEX); |
Yorke Lee | 8cd9423 | 2014-07-23 14:05:31 -0700 | [diff] [blame] | 439 | final String transcription = callCursor.getString(TRANSCRIPTION_COLUMN_INDEX); |
Nancy Chen | b2eebaf | 2014-07-21 13:41:36 -0700 | [diff] [blame] | 440 | |
Nancy Chen | e80d622 | 2014-10-08 20:17:55 -0700 | [diff] [blame] | 441 | final PhoneAccountHandle accountHandle = PhoneAccountUtils.getAccount( |
Nancy Chen | b2eebaf | 2014-07-21 13:41:36 -0700 | [diff] [blame] | 442 | callCursor.getString(ACCOUNT_COMPONENT_NAME), |
Nancy Chen | e80d622 | 2014-10-08 20:17:55 -0700 | [diff] [blame] | 443 | callCursor.getString(ACCOUNT_ID)); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 444 | |
| 445 | if (TextUtils.isEmpty(countryIso)) { |
| 446 | countryIso = mDefaultCountryIso; |
| 447 | } |
| 448 | |
| 449 | // Formatted phone number. |
| 450 | final CharSequence formattedNumber; |
Andrew Lee | 49efd91 | 2015-05-19 12:17:26 -0700 | [diff] [blame^] | 451 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 452 | // If this is not a regular number, there is no point in looking it up in the contacts. |
Andrew Lee | 49efd91 | 2015-05-19 12:17:26 -0700 | [diff] [blame^] | 453 | ContactInfo info = ContactInfo.EMPTY; |
| 454 | final boolean isVoicemail = new PhoneNumberUtilsWrapper(this) |
| 455 | .isVoicemailNumber(accountHandle, number); |
| 456 | if (PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation) |
| 457 | && !isVoicemail) { |
| 458 | mContactInfoHelper.lookupNumber(number, countryIso); |
| 459 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 460 | if (info == null) { |
Andrew Lee | 49efd91 | 2015-05-19 12:17:26 -0700 | [diff] [blame^] | 461 | formattedNumber = PhoneNumberDisplayUtil.getDisplayNumber( |
| 462 | this, |
| 463 | accountHandle, |
| 464 | number, |
| 465 | numberPresentation, |
| 466 | null /* formattedNumber */, |
| 467 | isVoicemail); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 468 | } else { |
| 469 | formattedNumber = info.formattedNumber; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 470 | } |
Tyler Gunn | 8b0e858 | 2014-07-10 12:28:43 -0700 | [diff] [blame] | 471 | final int features = callCursor.getInt(FEATURES); |
| 472 | Long dataUsage = null; |
| 473 | if (!callCursor.isNull(DATA_USAGE)) { |
| 474 | dataUsage = callCursor.getLong(DATA_USAGE); |
| 475 | } |
Andrew Lee | 49efd91 | 2015-05-19 12:17:26 -0700 | [diff] [blame^] | 476 | return new PhoneCallDetails(this, number, numberPresentation, |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 477 | formattedNumber, countryIso, geocode, |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 478 | new int[]{ callType }, date, duration, |
Andrew Lee | 49efd91 | 2015-05-19 12:17:26 -0700 | [diff] [blame^] | 479 | info.name, info.type, info.label, info.lookupUri, info.photoUri, |
| 480 | info.sourceType, accountHandle, features, dataUsage, transcription, |
| 481 | isVoicemail); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 482 | } finally { |
| 483 | if (callCursor != null) { |
| 484 | callCursor.close(); |
| 485 | } |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | /** Load the contact photos and places them in the corresponding views. */ |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 490 | private void loadContactPhotos(Uri contactUri, Uri photoUri, String displayName, |
| 491 | String lookupKey, int contactType) { |
| 492 | |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 493 | final DefaultImageRequest request = new DefaultImageRequest(displayName, lookupKey, |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 494 | contactType, true /* isCircular */); |
| 495 | |
| 496 | mQuickContactBadge.assignContactUri(contactUri); |
| 497 | mQuickContactBadge.setContentDescription( |
| 498 | mResources.getString(R.string.description_contact_details, displayName)); |
| 499 | |
| 500 | mContactPhotoManager.loadDirectoryPhoto(mQuickContactBadge, photoUri, |
| 501 | false /* darkTheme */, true /* isCircular */, request); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 502 | } |
| 503 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 504 | @Override |
| 505 | public boolean onCreateOptionsMenu(Menu menu) { |
| 506 | getMenuInflater().inflate(R.menu.call_details_options, menu); |
| 507 | return super.onCreateOptionsMenu(menu); |
| 508 | } |
| 509 | |
| 510 | @Override |
| 511 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 512 | // This action deletes all elements in the group from the call log. |
| 513 | // We don't have this action for voicemails, because you can just use the trash button. |
| 514 | menu.findItem(R.id.menu_remove_from_call_log).setVisible(mHasRemoveFromCallLogOption); |
| 515 | menu.findItem(R.id.menu_edit_number_before_call).setVisible(mHasEditNumberBeforeCallOption); |
| 516 | menu.findItem(R.id.menu_trash).setVisible(mHasTrashOption); |
| 517 | return super.onPrepareOptionsMenu(menu); |
| 518 | } |
| 519 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 520 | public void onMenuRemoveFromCallLog(MenuItem menuItem) { |
| 521 | final StringBuilder callIds = new StringBuilder(); |
| 522 | for (Uri callUri : getCallLogEntryUris()) { |
| 523 | if (callIds.length() != 0) { |
| 524 | callIds.append(","); |
| 525 | } |
| 526 | callIds.append(ContentUris.parseId(callUri)); |
| 527 | } |
| 528 | mAsyncTaskExecutor.submit(Tasks.REMOVE_FROM_CALL_LOG_AND_FINISH, |
| 529 | new AsyncTask<Void, Void, Void>() { |
| 530 | @Override |
| 531 | public Void doInBackground(Void... params) { |
Yorke Lee | 4aece95 | 2015-05-02 22:22:54 -0700 | [diff] [blame] | 532 | getContentResolver().delete( |
| 533 | TelecomUtil.getCallLogUri(CallDetailActivity.this), |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 534 | Calls._ID + " IN (" + callIds + ")", null); |
| 535 | return null; |
| 536 | } |
| 537 | |
| 538 | @Override |
| 539 | public void onPostExecute(Void result) { |
| 540 | finish(); |
| 541 | } |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 542 | } |
| 543 | ); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | public void onMenuEditNumberBeforeCall(MenuItem menuItem) { |
Chiao Cheng | 9d4f3b2 | 2012-09-05 16:00:16 -0700 | [diff] [blame] | 547 | startActivity(new Intent(Intent.ACTION_DIAL, CallUtil.getCallUri(mNumber))); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | public void onMenuTrashVoicemail(MenuItem menuItem) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 551 | mAsyncTaskExecutor.submit(Tasks.DELETE_VOICEMAIL_AND_FINISH, |
| 552 | new AsyncTask<Void, Void, Void>() { |
| 553 | @Override |
| 554 | public Void doInBackground(Void... params) { |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 555 | getContentResolver().delete(mVoicemailUri, null, null); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 556 | return null; |
| 557 | } |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 558 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 559 | @Override |
| 560 | public void onPostExecute(Void result) { |
| 561 | finish(); |
| 562 | } |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 563 | } |
| 564 | ); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 565 | } |
| 566 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 567 | private void closeSystemDialogs() { |
| 568 | sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); |
| 569 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 570 | } |