diff options
Diffstat (limited to 'java/com/android/dialer/app/calllog')
21 files changed, 1514 insertions, 859 deletions
diff --git a/java/com/android/dialer/app/calllog/CallLogActivity.java b/java/com/android/dialer/app/calllog/CallLogActivity.java index 443171d3f..6433af9a6 100644 --- a/java/com/android/dialer/app/calllog/CallLogActivity.java +++ b/java/com/android/dialer/app/calllog/CallLogActivity.java @@ -34,6 +34,9 @@ import com.android.dialer.app.R; import com.android.dialer.database.CallLogQueryHandler; import com.android.dialer.logging.Logger; import com.android.dialer.logging.ScreenEvent; +import com.android.dialer.logging.UiAction; +import com.android.dialer.performancereport.PerformanceReport; +import com.android.dialer.postcall.PostCall; import com.android.dialer.util.TransactionSafeActivity; import com.android.dialer.util.ViewUtil; @@ -48,7 +51,6 @@ public class CallLogActivity extends TransactionSafeActivity private ViewPagerTabs mViewPagerTabs; private ViewPagerAdapter mViewPagerAdapter; private CallLogFragment mAllCallsFragment; - private CallLogFragment mMissedCallsFragment; private String[] mTabTitles; private boolean mIsResumed; @@ -93,9 +95,16 @@ public class CallLogActivity extends TransactionSafeActivity @Override protected void onResume() { + // Some calls may not be recorded (eg. from quick contact), + // so we should restart recording after these calls. (Recorded call is stopped) + PostCall.restartPerformanceRecordingIfARecentCallExist(this); + if (!PerformanceReport.isRecording()) { + PerformanceReport.startRecording(); + } + mIsResumed = true; super.onResume(); - sendScreenViewForChildFragment(mViewPager.getCurrentItem()); + sendScreenViewForChildFragment(); } @Override @@ -129,6 +138,7 @@ public class CallLogActivity extends TransactionSafeActivity } if (item.getItemId() == android.R.id.home) { + PerformanceReport.recordClick(UiAction.Type.CLOSE_CALL_HISTORY_WITH_CANCEL_BUTTON); final Intent intent = new Intent(this, DialtactsActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); @@ -148,7 +158,7 @@ public class CallLogActivity extends TransactionSafeActivity @Override public void onPageSelected(int position) { if (mIsResumed) { - sendScreenViewForChildFragment(position); + sendScreenViewForChildFragment(); } mViewPagerTabs.onPageSelected(position); } @@ -158,7 +168,7 @@ public class CallLogActivity extends TransactionSafeActivity mViewPagerTabs.onPageScrollStateChanged(state); } - private void sendScreenViewForChildFragment(int position) { + private void sendScreenViewForChildFragment() { Logger.get(this).logScreenView(ScreenEvent.Type.CALL_LOG_FILTER, this); } @@ -169,6 +179,12 @@ public class CallLogActivity extends TransactionSafeActivity return position; } + @Override + public void onBackPressed() { + PerformanceReport.recordClick(UiAction.Type.PRESS_ANDROID_BACK_BUTTON); + super.onBackPressed(); + } + /** Adapter for the view pager. */ public class ViewPagerAdapter extends FragmentPagerAdapter { @@ -189,20 +205,16 @@ public class CallLogActivity extends TransactionSafeActivity CallLogQueryHandler.CALL_TYPE_ALL, true /* isCallLogActivity */); case TAB_INDEX_MISSED: return new CallLogFragment(Calls.MISSED_TYPE, true /* isCallLogActivity */); + default: + throw new IllegalStateException("No fragment at position " + position); } - throw new IllegalStateException("No fragment at position " + position); } @Override public Object instantiateItem(ViewGroup container, int position) { final CallLogFragment fragment = (CallLogFragment) super.instantiateItem(container, position); - switch (position) { - case TAB_INDEX_ALL: + if (position == TAB_INDEX_ALL) { mAllCallsFragment = fragment; - break; - case TAB_INDEX_MISSED: - mMissedCallsFragment = fragment; - break; } return fragment; } diff --git a/java/com/android/dialer/app/calllog/CallLogAdapter.java b/java/com/android/dialer/app/calllog/CallLogAdapter.java index 2f8a58c8a..f1d051a8c 100644 --- a/java/com/android/dialer/app/calllog/CallLogAdapter.java +++ b/java/com/android/dialer/app/calllog/CallLogAdapter.java @@ -19,6 +19,7 @@ package com.android.dialer.app.calllog; import android.app.Activity; import android.content.ContentUris; import android.content.DialogInterface; +import android.content.DialogInterface.OnCancelListener; import android.content.res.Resources; import android.database.Cursor; import android.net.Uri; @@ -52,7 +53,6 @@ import android.view.ViewGroup; import com.android.contacts.common.ContactsUtils; import com.android.contacts.common.compat.PhoneNumberUtilsCompat; import com.android.contacts.common.preference.ContactsPreferences; -import com.android.dialer.app.Bindings; import com.android.dialer.app.DialtactsActivity; import com.android.dialer.app.R; import com.android.dialer.app.calllog.CallLogGroupBuilder.GroupCreator; @@ -66,10 +66,10 @@ import com.android.dialer.calldetails.CallDetailsEntries.CallDetailsEntry; import com.android.dialer.calllogutils.PhoneAccountUtils; import com.android.dialer.calllogutils.PhoneCallDetails; import com.android.dialer.common.Assert; -import com.android.dialer.common.ConfigProviderBindings; import com.android.dialer.common.LogUtil; import com.android.dialer.common.concurrent.AsyncTaskExecutor; import com.android.dialer.common.concurrent.AsyncTaskExecutors; +import com.android.dialer.configprovider.ConfigProviderBindings; import com.android.dialer.enrichedcall.EnrichedCallCapabilities; import com.android.dialer.enrichedcall.EnrichedCallComponent; import com.android.dialer.enrichedcall.EnrichedCallManager; @@ -80,12 +80,15 @@ import com.android.dialer.lightbringer.LightbringerListener; import com.android.dialer.logging.ContactSource; import com.android.dialer.logging.DialerImpression; import com.android.dialer.logging.Logger; +import com.android.dialer.logging.UiAction; +import com.android.dialer.performancereport.PerformanceReport; import com.android.dialer.phonenumbercache.CallLogQuery; import com.android.dialer.phonenumbercache.ContactInfo; import com.android.dialer.phonenumbercache.ContactInfoHelper; import com.android.dialer.phonenumberutil.PhoneNumberHelper; import com.android.dialer.spam.Spam; import com.android.dialer.util.PermissionsUtil; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; @@ -105,11 +108,12 @@ public class CallLogAdapter extends GroupingListAdapter private static final String KEY_EXPANDED_POSITION = "expanded_position"; private static final String KEY_EXPANDED_ROW_ID = "expanded_row_id"; + private static final String KEY_ACTION_MODE = "action_mode_selected_items"; public static final String LOAD_DATA_TASK_IDENTIFIER = "load_data"; public static final String ENABLE_CALL_LOG_MULTI_SELECT = "enable_call_log_multiselect"; - public static final boolean ENABLE_CALL_LOG_MULTI_SELECT_FLAG = false; + public static final boolean ENABLE_CALL_LOG_MULTI_SELECT_FLAG = true; protected final Activity mActivity; protected final VoicemailPlaybackPresenter mVoicemailPlaybackPresenter; @@ -117,6 +121,8 @@ public class CallLogAdapter extends GroupingListAdapter protected final CallLogCache mCallLogCache; private final CallFetcher mCallFetcher; + private final OnActionModeStateChangedListener mActionModeStateChangedListener; + private final MultiSelectRemoveView mMultiSelectRemoveView; @NonNull private final FilteredNumberAsyncQueryHandler mFilteredNumberAsyncQueryHandler; private final int mActivityType; @@ -136,6 +142,8 @@ public class CallLogAdapter extends GroupingListAdapter private final CallLogAlertManager mCallLogAlertManager; public ActionMode mActionMode = null; + public boolean selectAllMode = false; + public boolean deselectAllMode = false; private final SparseArray<String> selectedItems = new SparseArray<>(); private final ActionMode.Callback mActionModeCallback = @@ -144,10 +152,17 @@ public class CallLogAdapter extends GroupingListAdapter // Called when the action mode is created; startActionMode() was called @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { + if (mActivity != null) { + announceforAccessibility( + mActivity.getCurrentFocus(), + mActivity.getString(R.string.description_entering_bulk_action_mode)); + } mActionMode = mode; // Inflate a menu resource providing context menu items MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.actionbar_delete, menu); + mMultiSelectRemoveView.showMultiSelectRemoveView(true); + mActionModeStateChangedListener.onActionModeStateChanged(true); return true; } @@ -162,10 +177,10 @@ public class CallLogAdapter extends GroupingListAdapter @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { if (item.getItemId() == R.id.action_bar_delete_menu_item) { + Logger.get(mActivity).logImpression(DialerImpression.Type.MULTISELECT_TAP_DELETE_ICON); if (selectedItems.size() > 0) { showDeleteSelectedItemsDialog(); } - mode.finish(); return true; } else { return false; @@ -175,53 +190,78 @@ public class CallLogAdapter extends GroupingListAdapter // Called when the user exits the action mode @Override public void onDestroyActionMode(ActionMode mode) { + if (mActivity != null) { + announceforAccessibility( + mActivity.getCurrentFocus(), + mActivity.getString(R.string.description_leaving_bulk_action_mode)); + } selectedItems.clear(); mActionMode = null; + selectAllMode = false; + deselectAllMode = false; + mMultiSelectRemoveView.showMultiSelectRemoveView(false); + mActionModeStateChangedListener.onActionModeStateChanged(false); notifyDataSetChanged(); } }; - // Todo (uabdullah): Use plurals http://b/37751831 private void showDeleteSelectedItemsDialog() { - AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); - Assert.checkArgument(selectedItems.size() > 0); - String voicemailString = - selectedItems.size() == 1 - ? mActivity.getResources().getString(R.string.voicemailMultiSelectVoicemail) - : mActivity.getResources().getString(R.string.voicemailMultiSelectVoicemails); - String deleteVoicemailTitle = - mActivity - .getResources() - .getString(R.string.voicemailMultiSelectDialogTitle, voicemailString); SparseArray<String> voicemailsToDeleteOnConfirmation = selectedItems.clone(); - builder.setTitle(deleteVoicemailTitle); - - builder.setPositiveButton( - mActivity.getResources().getString(R.string.voicemailMultiSelectDeleteConfirm), - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - deleteSelectedItems(voicemailsToDeleteOnConfirmation); - dialog.cancel(); - } - }); - - builder.setNegativeButton( - mActivity.getResources().getString(R.string.voicemailMultiSelectDeleteCancel), - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - dialog.cancel(); - } - }); - - AlertDialog dialog = builder.create(); - dialog.show(); + new AlertDialog.Builder(mActivity, R.style.AlertDialogCustom) + .setCancelable(true) + .setTitle( + mActivity + .getResources() + .getQuantityString( + R.plurals.delete_voicemails_confirmation_dialog_title, selectedItems.size())) + .setPositiveButton( + R.string.voicemailMultiSelectDeleteConfirm, + new DialogInterface.OnClickListener() { + @Override + public void onClick(final DialogInterface dialog, final int button) { + LogUtil.i( + "CallLogAdapter.showDeleteSelectedItemsDialog", + "onClick, these items to delete " + voicemailsToDeleteOnConfirmation); + deleteSelectedItems(voicemailsToDeleteOnConfirmation); + mActionMode.finish(); + dialog.cancel(); + Logger.get(mActivity) + .logImpression( + DialerImpression.Type.MULTISELECT_DELETE_ENTRY_VIA_CONFIRMATION_DIALOG); + } + }) + .setOnCancelListener( + new OnCancelListener() { + @Override + public void onCancel(DialogInterface dialogInterface) { + Logger.get(mActivity) + .logImpression( + DialerImpression.Type + .MULTISELECT_CANCEL_CONFIRMATION_DIALOG_VIA_CANCEL_TOUCH); + dialogInterface.cancel(); + } + }) + .setNegativeButton( + R.string.voicemailMultiSelectDeleteCancel, + new DialogInterface.OnClickListener() { + @Override + public void onClick(final DialogInterface dialog, final int button) { + Logger.get(mActivity) + .logImpression( + DialerImpression.Type + .MULTISELECT_CANCEL_CONFIRMATION_DIALOG_VIA_CANCEL_BUTTON); + dialog.cancel(); + } + }) + .show(); + Logger.get(mActivity) + .logImpression(DialerImpression.Type.MULTISELECT_DISPLAY_DELETE_CONFIRMATION_DIALOG); } private void deleteSelectedItems(SparseArray<String> voicemailsToDelete) { for (int i = 0; i < voicemailsToDelete.size(); i++) { String voicemailUri = voicemailsToDelete.get(voicemailsToDelete.keyAt(i)); + LogUtil.i("CallLogAdapter.deleteSelectedItems", "deleting uri:" + voicemailUri); CallLogAsyncTaskUtil.deleteVoicemail(mActivity, Uri.parse(voicemailUri), null); } } @@ -235,8 +275,13 @@ public class CallLogAdapter extends GroupingListAdapter && mVoicemailPlaybackPresenter != null) { if (v.getId() == R.id.primary_action_view || v.getId() == R.id.quick_contact_photo) { if (mActionMode == null) { + Logger.get(mActivity) + .logImpression( + DialerImpression.Type.MULTISELECT_LONG_PRESS_ENTER_MULTI_SELECT_MODE); mActionMode = v.startActionMode(mActionModeCallback); } + Logger.get(mActivity) + .logImpression(DialerImpression.Type.MULTISELECT_LONG_PRESS_TAP_ENTRY); CallLogListItemViewHolder viewHolder = (CallLogListItemViewHolder) v.getTag(); viewHolder.quickContactView.setVisibility(View.GONE); viewHolder.checkBoxView.setVisibility(View.VISIBLE); @@ -253,27 +298,26 @@ public class CallLogAdapter extends GroupingListAdapter new View.OnClickListener() { @Override public void onClick(View v) { + PerformanceReport.recordClick(UiAction.Type.CLICK_CALL_LOG_ITEM); + CallLogListItemViewHolder viewHolder = (CallLogListItemViewHolder) v.getTag(); if (viewHolder == null) { return; } if (mActionMode != null && viewHolder.voicemailUri != null) { + selectAllMode = false; + deselectAllMode = false; + mMultiSelectRemoveView.setSelectAllModeToFalse(); int id = getVoicemailId(viewHolder.voicemailUri); if (selectedItems.get(id) != null) { - selectedItems.delete(id); - viewHolder.checkBoxView.setVisibility(View.GONE); - viewHolder.quickContactView.setVisibility(View.VISIBLE); + Logger.get(mActivity) + .logImpression(DialerImpression.Type.MULTISELECT_SINGLE_PRESS_UNSELECT_ENTRY); + uncheckMarkCallLogEntry(viewHolder, id); } else { - viewHolder.quickContactView.setVisibility(View.GONE); - viewHolder.checkBoxView.setVisibility(View.VISIBLE); - selectedItems.put(getVoicemailId(viewHolder.voicemailUri), viewHolder.voicemailUri); + Logger.get(mActivity) + .logImpression(DialerImpression.Type.MULTISELECT_SINGLE_PRESS_SELECT_ENTRY); + checkMarkCallLogEntry(viewHolder); } - - if (selectedItems.size() == 0) { - mActionMode.finish(); - return; - } - mActionMode.setTitle(Integer.toString(selectedItems.size())); return; } @@ -312,6 +356,50 @@ public class CallLogAdapter extends GroupingListAdapter } }; + private void checkMarkCallLogEntry(CallLogListItemViewHolder viewHolder) { + announceforAccessibility( + mActivity.getCurrentFocus(), + mActivity.getString( + R.string.description_selecting_bulk_action_mode, viewHolder.nameOrNumber)); + viewHolder.quickContactView.setVisibility(View.GONE); + viewHolder.checkBoxView.setVisibility(View.VISIBLE); + selectedItems.put(getVoicemailId(viewHolder.voicemailUri), viewHolder.voicemailUri); + updateActionBar(); + } + + private void announceforAccessibility(View view, String announcement) { + if (view != null) { + view.announceForAccessibility(announcement); + } + } + + private void updateActionBar() { + if (mActionMode == null && selectedItems.size() > 0) { + Logger.get(mActivity) + .logImpression(DialerImpression.Type.MULTISELECT_ROTATE_AND_SHOW_ACTION_MODE); + mActivity.startActionMode(mActionModeCallback); + } + if (mActionMode != null) { + mActionMode.setTitle( + mActivity + .getResources() + .getString( + R.string.voicemailMultiSelectActionBarTitle, + Integer.toString(selectedItems.size()))); + } + } + + private void uncheckMarkCallLogEntry(CallLogListItemViewHolder viewHolder, int id) { + announceforAccessibility( + mActivity.getCurrentFocus(), + mActivity.getString( + R.string.description_unselecting_bulk_action_mode, viewHolder.nameOrNumber)); + selectedItems.delete(id); + viewHolder.checkBoxView.setVisibility(View.GONE); + viewHolder.quickContactView.setVisibility(View.VISIBLE); + updateActionBar(); + } + private static int getVoicemailId(String voicemailUri) { Assert.checkArgument(voicemailUri != null); Assert.checkArgument(voicemailUri.length() > 0); @@ -358,6 +446,8 @@ public class CallLogAdapter extends GroupingListAdapter Activity activity, ViewGroup alertContainer, CallFetcher callFetcher, + MultiSelectRemoveView multiSelectRemoveView, + OnActionModeStateChangedListener actionModeStateChangedListener, CallLogCache callLogCache, ContactInfoCache contactInfoCache, VoicemailPlaybackPresenter voicemailPlaybackPresenter, @@ -367,6 +457,8 @@ public class CallLogAdapter extends GroupingListAdapter mActivity = activity; mCallFetcher = callFetcher; + mActionModeStateChangedListener = actionModeStateChangedListener; + mMultiSelectRemoveView = multiSelectRemoveView; mVoicemailPlaybackPresenter = voicemailPlaybackPresenter; if (mVoicemailPlaybackPresenter != null) { mVoicemailPlaybackPresenter.setOnVoicemailDeletedListener(this); @@ -426,6 +518,25 @@ public class CallLogAdapter extends GroupingListAdapter public void onSaveInstanceState(Bundle outState) { outState.putInt(KEY_EXPANDED_POSITION, mCurrentlyExpandedPosition); outState.putLong(KEY_EXPANDED_ROW_ID, mCurrentlyExpandedRowId); + + ArrayList<String> listOfSelectedItems = new ArrayList<>(); + + if (selectedItems.size() > 0) { + for (int i = 0; i < selectedItems.size(); i++) { + int id = selectedItems.keyAt(i); + String voicemailUri = selectedItems.valueAt(i); + LogUtil.i( + "CallLogAdapter.onSaveInstanceState", "index %d, id=%d, uri=%s ", i, id, voicemailUri); + listOfSelectedItems.add(voicemailUri); + } + } + outState.putStringArrayList(KEY_ACTION_MODE, listOfSelectedItems); + + LogUtil.i( + "CallLogAdapter.onSaveInstanceState", + "saved: %d, selectedItemsSize:%d", + listOfSelectedItems.size(), + selectedItems.size()); } public void onRestoreInstanceState(Bundle savedInstanceState) { @@ -434,6 +545,33 @@ public class CallLogAdapter extends GroupingListAdapter savedInstanceState.getInt(KEY_EXPANDED_POSITION, RecyclerView.NO_POSITION); mCurrentlyExpandedRowId = savedInstanceState.getLong(KEY_EXPANDED_ROW_ID, NO_EXPANDED_LIST_ITEM); + // Restoring multi selected entries + ArrayList<String> listOfSelectedItems = + savedInstanceState.getStringArrayList(KEY_ACTION_MODE); + LogUtil.i( + "CallLogAdapter.onRestoreInstanceState", + "restored selectedItemsList:%d", + listOfSelectedItems.size()); + + if (!listOfSelectedItems.isEmpty()) { + for (int i = 0; i < listOfSelectedItems.size(); i++) { + String voicemailUri = listOfSelectedItems.get(i); + int id = getVoicemailId(voicemailUri); + LogUtil.i( + "CallLogAdapter.onRestoreInstanceState", + "restoring selected index %d, id=%d, uri=%s ", + i, + id, + voicemailUri); + selectedItems.put(id, voicemailUri); + } + + LogUtil.i( + "CallLogAdapter.onRestoreInstance", + "restored selectedItems %s", + selectedItems.toString()); + updateActionBar(); + } } } @@ -521,6 +659,7 @@ public class CallLogAdapter extends GroupingListAdapter mBlockReportSpamListener, mExpandCollapseListener, mLongPressListener, + mActionModeStateChangedListener, mCallLogCache, mCallLogListItemHelper, mVoicemailPlaybackPresenter); @@ -546,7 +685,7 @@ public class CallLogAdapter extends GroupingListAdapter Trace.beginSection("onBindViewHolder: " + position); switch (getItemViewType(position)) { case VIEW_TYPE_ALERT: - //Do nothing + // Do nothing break; default: bindCallLogListViewHolder(viewHolder, position); @@ -559,6 +698,8 @@ public class CallLogAdapter extends GroupingListAdapter public void onViewRecycled(ViewHolder viewHolder) { if (viewHolder.getItemViewType() == VIEW_TYPE_CALLLOG) { CallLogListItemViewHolder views = (CallLogListItemViewHolder) viewHolder; + updateCheckMarkedStatusOfEntry(views); + if (views.asyncTask != null) { views.asyncTask.cancel(true); } @@ -591,6 +732,8 @@ public class CallLogAdapter extends GroupingListAdapter return; } CallLogListItemViewHolder views = (CallLogListItemViewHolder) viewHolder; + updateCheckMarkedStatusOfEntry(views); + views.isLoaded = false; int groupSize = getGroupSize(position); CallDetailsEntries callDetailsEntries = createCallDetailsEntries(c, groupSize); @@ -609,6 +752,17 @@ public class CallLogAdapter extends GroupingListAdapter loadAndRender(views, views.rowId, details, callDetailsEntries); } + private void updateCheckMarkedStatusOfEntry(CallLogListItemViewHolder views) { + if (selectedItems.size() > 0 && views.voicemailUri != null) { + int id = getVoicemailId(views.voicemailUri); + if (selectedItems.get(id) != null) { + checkMarkCallLogEntry(views); + } else { + uncheckMarkCallLogEntry(views, id); + } + } + } + private void loadAndRender( final CallLogListItemViewHolder views, final long rowId, @@ -840,8 +994,7 @@ public class CallLogAdapter extends GroupingListAdapter details.countryIso, details.cachedContactInfo, position - < Bindings.get(mActivity) - .getConfigProvider() + < ConfigProviderBindings.get(mActivity) .getLong("number_of_call_to_do_remote_lookup", 5L)); } CharSequence formattedNumber = @@ -917,6 +1070,12 @@ public class CallLogAdapter extends GroupingListAdapter views.workIconView.setVisibility( details.contactUserType == ContactsUtils.USER_TYPE_WORK ? View.VISIBLE : View.GONE); + if (selectAllMode && views.voicemailUri != null) { + selectedItems.put(getVoicemailId(views.voicemailUri), views.voicemailUri); + } + if (deselectAllMode && views.voicemailUri != null) { + selectedItems.delete(getVoicemailId(views.voicemailUri)); + } if (views.voicemailUri != null && selectedItems.get(getVoicemailId(views.voicemailUri)) != null) { views.checkBoxView.setVisibility(View.VISIBLE); @@ -925,7 +1084,6 @@ public class CallLogAdapter extends GroupingListAdapter views.checkBoxView.setVisibility(View.GONE); views.quickContactView.setVisibility(View.VISIBLE); } - mCallLogListItemHelper.setPhoneCallDetails(views, details); if (mCurrentlyExpandedRowId == views.rowId) { // In case ViewHolders were added/removed, update the expanded position if the rowIds @@ -1192,9 +1350,49 @@ public class CallLogAdapter extends GroupingListAdapter notifyDataSetChanged(); } + public void onAllSelected() { + selectAllMode = true; + deselectAllMode = false; + selectedItems.clear(); + for (int i = 0; i < getItemCount(); i++) { + Cursor c = (Cursor) getItem(i); + if (c != null) { + Assert.checkArgument(CallLogQuery.VOICEMAIL_URI == c.getColumnIndex("voicemail_uri")); + String voicemailUri = c.getString(CallLogQuery.VOICEMAIL_URI); + selectedItems.put(getVoicemailId(voicemailUri), voicemailUri); + } + } + updateActionBar(); + notifyDataSetChanged(); + } + + public void onAllDeselected() { + selectAllMode = false; + deselectAllMode = true; + selectedItems.clear(); + updateActionBar(); + notifyDataSetChanged(); + } + /** Interface used to initiate a refresh of the content. */ public interface CallFetcher { void fetchCalls(); } + + /** Interface used to allow single tap multi select for contact photos. */ + public interface OnActionModeStateChangedListener { + + void onActionModeStateChanged(boolean isEnabled); + + boolean isActionModeStateEnabled(); + } + + /** Interface used to hide the fragments. */ + public interface MultiSelectRemoveView { + + void showMultiSelectRemoveView(boolean show); + + void setSelectAllModeToFalse(); + } } diff --git a/java/com/android/dialer/app/calllog/CallLogAsyncTaskUtil.java b/java/com/android/dialer/app/calllog/CallLogAsyncTaskUtil.java index a5553d134..10866aae2 100644 --- a/java/com/android/dialer/app/calllog/CallLogAsyncTaskUtil.java +++ b/java/com/android/dialer/app/calllog/CallLogAsyncTaskUtil.java @@ -28,6 +28,7 @@ import android.provider.VoicemailContract.Voicemails; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.text.TextUtils; +import com.android.dialer.common.LogUtil; import com.android.dialer.common.concurrent.AsyncTaskExecutor; import com.android.dialer.common.concurrent.AsyncTaskExecutors; import com.android.dialer.util.PermissionsUtil; @@ -45,6 +46,7 @@ public class CallLogAsyncTaskUtil { public static void markVoicemailAsRead( @NonNull final Context context, @NonNull final Uri voicemailUri) { + LogUtil.enterBlock("CallLogAsyncTaskUtil.markVoicemailAsRead, voicemailUri: " + voicemailUri); if (sAsyncTaskExecutor == null) { initTaskExecutor(); } @@ -66,9 +68,7 @@ public class CallLogAsyncTaskUtil { uploadVoicemailLocalChangesToServer(context); } - Intent intent = new Intent(context, CallLogNotificationsService.class); - intent.setAction(CallLogNotificationsService.ACTION_MARK_NEW_VOICEMAILS_AS_OLD); - context.startService(intent); + CallLogNotificationsService.markAllNewVoicemailsAsOld(context); return null; } }); diff --git a/java/com/android/dialer/app/calllog/CallLogFragment.java b/java/com/android/dialer/app/calllog/CallLogFragment.java index 6e4b23fc1..b03a4ad64 100644 --- a/java/com/android/dialer/app/calllog/CallLogFragment.java +++ b/java/com/android/dialer/app/calllog/CallLogFragment.java @@ -35,53 +35,68 @@ import android.provider.ContactsContract; import android.support.annotation.CallSuper; import android.support.annotation.Nullable; import android.support.v13.app.FragmentCompat; +import android.support.v13.app.FragmentCompat.OnRequestPermissionsResultCallback; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; +import android.view.View.OnClickListener; import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; import com.android.dialer.app.Bindings; import com.android.dialer.app.R; +import com.android.dialer.app.calllog.CallLogAdapter.CallFetcher; +import com.android.dialer.app.calllog.CallLogAdapter.MultiSelectRemoveView; import com.android.dialer.app.calllog.calllogcache.CallLogCache; import com.android.dialer.app.contactinfo.ContactInfoCache; import com.android.dialer.app.contactinfo.ContactInfoCache.OnContactInfoChangedListener; import com.android.dialer.app.contactinfo.ExpirableCacheHeadlessFragment; import com.android.dialer.app.list.ListsFragment; import com.android.dialer.app.voicemail.VoicemailPlaybackPresenter; -import com.android.dialer.app.widget.EmptyContentView; -import com.android.dialer.app.widget.EmptyContentView.OnEmptyViewActionButtonClickedListener; import com.android.dialer.blocking.FilteredNumberAsyncQueryHandler; import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; import com.android.dialer.database.CallLogQueryHandler; +import com.android.dialer.database.CallLogQueryHandler.Listener; import com.android.dialer.location.GeoUtil; +import com.android.dialer.logging.DialerImpression; +import com.android.dialer.logging.Logger; +import com.android.dialer.oem.CequintCallerIdManager; +import com.android.dialer.performancereport.PerformanceReport; import com.android.dialer.phonenumbercache.ContactInfoHelper; import com.android.dialer.util.PermissionsUtil; +import com.android.dialer.widget.EmptyContentView; +import com.android.dialer.widget.EmptyContentView.OnEmptyViewActionButtonClickedListener; +import java.util.Arrays; /** * Displays a list of call log entries. To filter for a particular kind of call (all, missed or * voicemails), specify it in the constructor. */ public class CallLogFragment extends Fragment - implements CallLogQueryHandler.Listener, - CallLogAdapter.CallFetcher, + implements Listener, + CallFetcher, + MultiSelectRemoveView, OnEmptyViewActionButtonClickedListener, - FragmentCompat.OnRequestPermissionsResultCallback, - CallLogModalAlertManager.Listener { + OnRequestPermissionsResultCallback, + CallLogModalAlertManager.Listener, + OnClickListener { private static final String KEY_FILTER_TYPE = "filter_type"; private static final String KEY_LOG_LIMIT = "log_limit"; private static final String KEY_DATE_LIMIT = "date_limit"; private static final String KEY_IS_CALL_LOG_ACTIVITY = "is_call_log_activity"; private static final String KEY_HAS_READ_CALL_LOG_PERMISSION = "has_read_call_log_permission"; private static final String KEY_REFRESH_DATA_REQUIRED = "refresh_data_required"; + private static final String KEY_SELECT_ALL_MODE = "select_all_mode_checked"; // No limit specified for the number of logs to show; use the CallLogQueryHandler's default. private static final int NO_LOG_LIMIT = -1; // No date-based filtering. private static final int NO_DATE_LIMIT = 0; - private static final int READ_CALL_LOG_PERMISSION_REQUEST_CODE = 1; + private static final int PHONE_PERMISSIONS_REQUEST_CODE = 1; private static final int EVENT_UPDATE_DISPLAY = 1; @@ -90,6 +105,9 @@ public class CallLogFragment extends Fragment // See issue 6363009 private final ContentObserver mCallLogObserver = new CustomContentObserver(); private final ContentObserver mContactsObserver = new CustomContentObserver(); + private View mMultiSelectUnSelectAllViewContent; + private TextView mSelectUnselectAllViewText; + private ImageView mSelectUnselectAllIcon; private RecyclerView mRecyclerView; private LinearLayoutManager mLayoutManager; private CallLogAdapter mAdapter; @@ -123,6 +141,7 @@ public class CallLogFragment extends Fragment * True if this instance of the CallLogFragment shown in the CallLogActivity. */ private boolean mIsCallLogActivity = false; + private boolean selectAllMode; private final Handler mDisplayUpdateHandler = new Handler() { @Override @@ -194,6 +213,7 @@ public class CallLogFragment extends Fragment mIsCallLogActivity = state.getBoolean(KEY_IS_CALL_LOG_ACTIVITY, mIsCallLogActivity); mHasReadCallLogPermission = state.getBoolean(KEY_HAS_READ_CALL_LOG_PERMISSION, false); mRefreshDataRequired = state.getBoolean(KEY_REFRESH_DATA_REQUIRED, mRefreshDataRequired); + selectAllMode = state.getBoolean(KEY_SELECT_ALL_MODE, false); } final Activity activity = getActivity(); @@ -290,12 +310,20 @@ public class CallLogFragment extends Fragment mRecyclerView.setHasFixedSize(true); mLayoutManager = new LinearLayoutManager(getActivity()); mRecyclerView.setLayoutManager(mLayoutManager); + PerformanceReport.logOnScrollStateChange(mRecyclerView); mEmptyListView = (EmptyContentView) view.findViewById(R.id.empty_list_view); mEmptyListView.setImage(R.drawable.empty_call_log); mEmptyListView.setActionClickedListener(this); mModalAlertView = (ViewGroup) view.findViewById(R.id.modal_message_container); mModalAlertManager = new CallLogModalAlertManager(LayoutInflater.from(getContext()), mModalAlertView, this); + mMultiSelectUnSelectAllViewContent = + view.findViewById(R.id.multi_select_select_all_view_content); + mSelectUnselectAllViewText = (TextView) view.findViewById(R.id.select_all_view_text); + mSelectUnselectAllIcon = (ImageView) view.findViewById(R.id.select_all_view_icon); + mMultiSelectUnSelectAllViewContent.setOnClickListener(null); + mSelectUnselectAllIcon.setOnClickListener(this); + mSelectUnselectAllViewText.setOnClickListener(this); } protected void setupData() { @@ -317,6 +345,10 @@ public class CallLogFragment extends Fragment getActivity(), mRecyclerView, this, + this, + activityType == CallLogAdapter.ACTIVITY_TYPE_DIALTACTS + ? (CallLogAdapter.OnActionModeStateChangedListener) getActivity() + : null, CallLogCache.getCallLogCache(getActivity()), mContactInfoCache, getVoicemailPlaybackPresenter(), @@ -335,9 +367,18 @@ public class CallLogFragment extends Fragment public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setupData(); + updateSelectAllState(savedInstanceState); mAdapter.onRestoreInstanceState(savedInstanceState); } + private void updateSelectAllState(Bundle savedInstanceState) { + if (savedInstanceState != null) { + if (savedInstanceState.getBoolean(KEY_SELECT_ALL_MODE, false)) { + updateSelectAllIcon(); + } + } + } + @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); @@ -380,6 +421,16 @@ public class CallLogFragment extends Fragment } @Override + public void onStart() { + super.onStart(); + CequintCallerIdManager cequintCallerIdManager = null; + if (CequintCallerIdManager.isCequintCallerIdEnabled(getContext())) { + cequintCallerIdManager = CequintCallerIdManager.createInstanceForCallLog(); + } + mContactInfoCache.setCequintCallerIdManager(cequintCallerIdManager); + } + + @Override public void onStop() { updateOnTransition(); @@ -407,7 +458,7 @@ public class CallLogFragment extends Fragment outState.putBoolean(KEY_IS_CALL_LOG_ACTIVITY, mIsCallLogActivity); outState.putBoolean(KEY_HAS_READ_CALL_LOG_PERMISSION, mHasReadCallLogPermission); outState.putBoolean(KEY_REFRESH_DATA_REQUIRED, mRefreshDataRequired); - + outState.putBoolean(KEY_SELECT_ALL_MODE, selectAllMode); mAdapter.onSaveInstanceState(outState); } @@ -451,6 +502,8 @@ public class CallLogFragment extends Fragment mEmptyListView.setActionLabel(EmptyContentView.NO_LABEL); } else if (filterType == CallLogQueryHandler.CALL_TYPE_ALL) { mEmptyListView.setActionLabel(R.string.call_log_all_empty_action); + } else { + mEmptyListView.setActionLabel(EmptyContentView.NO_LABEL); } } @@ -503,7 +556,8 @@ public class CallLogFragment extends Fragment if (mKeyguardManager != null && !mKeyguardManager.inKeyguardRestrictedInputMode() && mCallTypeFilter == Calls.VOICEMAIL_TYPE) { - CallLogNotificationsService.markNewVoicemailsAsOld(getActivity(), null); + LogUtil.i("CallLogFragment.updateOnTransition", "clearing all new voicemails"); + CallLogNotificationsService.markAllNewVoicemailsAsOld(getActivity()); } } @@ -514,9 +568,14 @@ public class CallLogFragment extends Fragment return; } - if (!PermissionsUtil.hasPermission(activity, READ_CALL_LOG)) { - FragmentCompat.requestPermissions( - this, new String[] {READ_CALL_LOG}, READ_CALL_LOG_PERMISSION_REQUEST_CODE); + String[] deniedPermissions = + PermissionsUtil.getPermissionsCurrentlyDenied( + getContext(), PermissionsUtil.allPhoneGroupPermissionsUsedInDialer); + if (deniedPermissions.length > 0) { + LogUtil.i( + "CallLogFragment.onEmptyViewActionButtonClicked", + "Requesting permissions: " + Arrays.toString(deniedPermissions)); + FragmentCompat.requestPermissions(this, deniedPermissions, PHONE_PERMISSIONS_REQUEST_CODE); } else if (!mIsCallLogActivity) { // Show dialpad if we are not in the call log activity. ((HostInterface) activity).showDialpad(); @@ -526,7 +585,7 @@ public class CallLogFragment extends Fragment @Override public void onRequestPermissionsResult( int requestCode, String[] permissions, int[] grantResults) { - if (requestCode == READ_CALL_LOG_PERMISSION_REQUEST_CODE) { + if (requestCode == PHONE_PERMISSIONS_REQUEST_CODE) { if (grantResults.length >= 1 && PackageManager.PERMISSION_GRANTED == grantResults[0]) { // Force a refresh of the data since we were missing the permission before this. mRefreshDataRequired = true; @@ -589,6 +648,44 @@ public class CallLogFragment extends Fragment } } + @Override + public void showMultiSelectRemoveView(boolean show) { + mMultiSelectUnSelectAllViewContent.setVisibility(show ? View.VISIBLE : View.GONE); + mMultiSelectUnSelectAllViewContent.setAlpha(show ? 0 : 1); + mMultiSelectUnSelectAllViewContent.animate().alpha(show ? 1 : 0).start(); + ((ListsFragment) getParentFragment()).showMultiSelectRemoveView(show); + } + + @Override + public void setSelectAllModeToFalse() { + selectAllMode = false; + mSelectUnselectAllIcon.setImageDrawable( + getContext().getDrawable(R.drawable.ic_empty_check_mark_white_24dp)); + } + + @Override + public void onClick(View v) { + selectAllMode = !selectAllMode; + if (selectAllMode) { + Logger.get(v.getContext()).logImpression(DialerImpression.Type.MULTISELECT_SELECT_ALL); + } else { + Logger.get(v.getContext()).logImpression(DialerImpression.Type.MULTISELECT_UNSELECT_ALL); + } + updateSelectAllIcon(); + } + + private void updateSelectAllIcon() { + if (selectAllMode) { + mSelectUnselectAllIcon.setImageDrawable( + getContext().getDrawable(R.drawable.ic_check_mark_blue_24dp)); + getAdapter().onAllSelected(); + } else { + mSelectUnselectAllIcon.setImageDrawable( + getContext().getDrawable(R.drawable.ic_empty_check_mark_white_24dp)); + getAdapter().onAllDeselected(); + } + } + public interface HostInterface { void showDialpad(); diff --git a/java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java b/java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java index 1daccd1a4..c59f0dd61 100644 --- a/java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java +++ b/java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java @@ -17,6 +17,7 @@ package com.android.dialer.app.calllog; import android.app.Activity; +import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; import android.content.res.Resources; @@ -25,32 +26,37 @@ import android.os.AsyncTask; import android.provider.CallLog; import android.provider.CallLog.Calls; import android.provider.ContactsContract.CommonDataKinds.Phone; +import android.support.annotation.IntDef; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.VisibleForTesting; import android.support.v7.widget.CardView; import android.support.v7.widget.RecyclerView; +import android.telecom.PhoneAccount; import android.telecom.PhoneAccountHandle; -import android.telecom.TelecomManager; import android.telephony.PhoneNumberUtils; import android.text.BidiFormatter; import android.text.TextDirectionHeuristics; import android.text.TextUtils; import android.view.ContextMenu; +import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewStub; import android.widget.ImageButton; import android.widget.ImageView; -import android.widget.QuickContactBadge; import android.widget.TextView; +import android.widget.Toast; import com.android.contacts.common.ClipboardUtils; import com.android.contacts.common.ContactPhotoManager; import com.android.contacts.common.compat.PhoneNumberUtilsCompat; import com.android.contacts.common.dialog.CallSubjectDialog; +import com.android.contacts.common.lettertiles.LetterTileDrawable; +import com.android.contacts.common.lettertiles.LetterTileDrawable.ContactType; import com.android.contacts.common.util.UriUtils; import com.android.dialer.app.DialtactsActivity; import com.android.dialer.app.R; +import com.android.dialer.app.calllog.CallLogAdapter.OnActionModeStateChangedListener; import com.android.dialer.app.calllog.calllogcache.CallLogCache; import com.android.dialer.app.voicemail.VoicemailPlaybackLayout; import com.android.dialer.app.voicemail.VoicemailPlaybackPresenter; @@ -58,23 +64,31 @@ import com.android.dialer.blocking.BlockedNumbersMigrator; import com.android.dialer.blocking.FilteredNumberCompat; import com.android.dialer.blocking.FilteredNumbersUtil; import com.android.dialer.callcomposer.CallComposerActivity; -import com.android.dialer.callcomposer.CallComposerContact; +import com.android.dialer.calldetails.CallDetailsActivity; import com.android.dialer.calldetails.CallDetailsEntries; -import com.android.dialer.common.ConfigProviderBindings; +import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; import com.android.dialer.compat.CompatUtils; +import com.android.dialer.configprovider.ConfigProviderBindings; +import com.android.dialer.dialercontact.DialerContact; +import com.android.dialer.dialercontact.SimDetails; import com.android.dialer.lightbringer.Lightbringer; import com.android.dialer.lightbringer.LightbringerComponent; import com.android.dialer.logging.ContactSource; import com.android.dialer.logging.DialerImpression; +import com.android.dialer.logging.InteractionEvent; import com.android.dialer.logging.Logger; import com.android.dialer.logging.ScreenEvent; +import com.android.dialer.logging.UiAction; +import com.android.dialer.performancereport.PerformanceReport; import com.android.dialer.phonenumbercache.CachedNumberLookupService; import com.android.dialer.phonenumbercache.ContactInfo; import com.android.dialer.phonenumbercache.PhoneNumberCache; import com.android.dialer.phonenumberutil.PhoneNumberHelper; import com.android.dialer.util.CallUtil; import com.android.dialer.util.DialerUtils; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; /** * This is an object containing references to views contained by the call log list item. This @@ -90,7 +104,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder /** The root view of the call log list item */ public final View rootView; /** The quick contact badge for the contact. */ - public final QuickContactBadge quickContactView; + public final DialerQuickContactBadge quickContactView; /** The primary action view of the entry. */ public final View primaryActionView; /** The details of the phone call. */ @@ -108,6 +122,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder private final CachedNumberLookupService mCachedNumberLookupService; private final VoicemailPlaybackPresenter mVoicemailPlaybackPresenter; private final OnClickListener mBlockReportListener; + @HostUi private final int hostUi; /** Whether the data fields are populated by the worker thread, ready to be shown. */ public boolean isLoaded; /** The view containing call log item actions. Null until the ViewStub is inflated. */ @@ -201,6 +216,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder public boolean lightbringerReady; private View.OnClickListener mExpandCollapseListener; + private final OnActionModeStateChangedListener onActionModeStateChangedListener; private final View.OnLongClickListener longPressListener; private boolean mVoicemailPrimaryActionButtonClicked; @@ -216,11 +232,12 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder OnClickListener blockReportListener, View.OnClickListener expandCollapseListener, View.OnLongClickListener longClickListener, + CallLogAdapter.OnActionModeStateChangedListener actionModeStateChangedListener, CallLogCache callLogCache, CallLogListItemHelper callLogListItemHelper, VoicemailPlaybackPresenter voicemailPlaybackPresenter, View rootView, - QuickContactBadge quickContactView, + DialerQuickContactBadge dialerQuickContactView, View primaryActionView, PhoneCallDetailsViews phoneCallDetailsViews, CardView callLogEntryView, @@ -230,6 +247,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder mContext = context; mExpandCollapseListener = expandCollapseListener; + onActionModeStateChangedListener = actionModeStateChangedListener; longPressListener = longClickListener; mCallLogCache = callLogCache; mCallLogListItemHelper = callLogListItemHelper; @@ -238,7 +256,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder mCachedNumberLookupService = PhoneNumberCache.get(mContext).getCachedNumberLookupService(); this.rootView = rootView; - this.quickContactView = quickContactView; + this.quickContactView = dialerQuickContactView; this.primaryActionView = primaryActionView; this.phoneCallDetailsViews = phoneCallDetailsViews; this.callLogEntryView = callLogEntryView; @@ -251,6 +269,23 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder phoneCallDetailsViews.nameView.setElegantTextHeight(false); phoneCallDetailsViews.callLocationAndDate.setElegantTextHeight(false); + if (mContext instanceof CallLogActivity) { + hostUi = HostUi.CALL_HISTORY; + Logger.get(mContext) + .logQuickContactOnTouch( + quickContactView, InteractionEvent.Type.OPEN_QUICK_CONTACT_FROM_CALL_HISTORY, true); + } else if (mVoicemailPlaybackPresenter == null) { + hostUi = HostUi.CALL_LOG; + Logger.get(mContext) + .logQuickContactOnTouch( + quickContactView, InteractionEvent.Type.OPEN_QUICK_CONTACT_FROM_CALL_LOG, true); + } else { + hostUi = HostUi.VOICEMAIL; + Logger.get(mContext) + .logQuickContactOnTouch( + quickContactView, InteractionEvent.Type.OPEN_QUICK_CONTACT_FROM_VOICEMAIL, false); + } + quickContactView.setOverlay(null); if (CompatUtils.hasPrioritizedMimeType()) { quickContactView.setPrioritizedMimeType(Phone.CONTENT_ITEM_TYPE); @@ -264,6 +299,8 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder CallLogAdapter.ENABLE_CALL_LOG_MULTI_SELECT_FLAG)) { primaryActionView.setOnLongClickListener(longPressListener); quickContactView.setOnLongClickListener(longPressListener); + quickContactView.setMulitSelectListeners( + mExpandCollapseListener, onActionModeStateChangedListener); } else { primaryActionView.setOnCreateContextMenuListener(this); } @@ -275,6 +312,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder OnClickListener blockReportListener, View.OnClickListener expandCollapseListener, View.OnLongClickListener longClickListener, + CallLogAdapter.OnActionModeStateChangedListener actionModeStateChangeListener, CallLogCache callLogCache, CallLogListItemHelper callLogListItemHelper, VoicemailPlaybackPresenter voicemailPlaybackPresenter) { @@ -284,11 +322,12 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder blockReportListener, expandCollapseListener, longClickListener, + actionModeStateChangeListener, callLogCache, callLogListItemHelper, voicemailPlaybackPresenter, view, - (QuickContactBadge) view.findViewById(R.id.quick_contact_photo), + (DialerQuickContactBadge) view.findViewById(R.id.quick_contact_photo), view.findViewById(R.id.primary_action_view), PhoneCallDetailsViews.fromView(view), (CardView) view.findViewById(R.id.call_log_row), @@ -297,6 +336,11 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder } public static CallLogListItemViewHolder createForTest(Context context) { + return createForTest(context, null); + } + + static CallLogListItemViewHolder createForTest( + Context context, VoicemailPlaybackPresenter voicemailPlaybackPresenter) { Resources resources = context.getResources(); CallLogCache callLogCache = CallLogCache.getCallLogCache(context); PhoneCallDetailsHelper phoneCallDetailsHelper = @@ -308,11 +352,12 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder null, null /* expandCollapseListener */, null, + null, callLogCache, new CallLogListItemHelper(phoneCallDetailsHelper, resources, callLogCache), - null /* voicemailPlaybackPresenter */, - new View(context), - new QuickContactBadge(context), + voicemailPlaybackPresenter, + LayoutInflater.from(context).inflate(R.layout.call_log_list_item, null), + new DialerQuickContactBadge(context), new View(context), PhoneCallDetailsViews.createForTest(context), new CardView(context), @@ -456,6 +501,17 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder // Treat as normal list item; show call button, if possible. if (PhoneNumberHelper.canPlaceCallsTo(number, numberPresentation)) { boolean isVoicemailNumber = mCallLogCache.isVoicemailNumber(accountHandle, number); + + if (!isVoicemailNumber && showLightbringerPrimaryButton()) { + primaryActionButtonView.setTag(IntentProvider.getLightbringerIntentProvider(number)); + primaryActionButtonView.setContentDescription( + TextUtils.expandTemplate( + mContext.getString(R.string.description_video_call_action), validNameOrNumber)); + primaryActionButtonView.setImageResource(R.drawable.quantum_ic_videocam_vd_theme_24); + primaryActionButtonView.setVisibility(View.VISIBLE); + return; + } + if (isVoicemailNumber) { // Call to generic voicemail number, in case there are multiple accounts. primaryActionButtonView.setTag(IntentProvider.getReturnVoicemailCallIntentProvider()); @@ -467,7 +523,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder primaryActionButtonView.setContentDescription( TextUtils.expandTemplate( mContext.getString(R.string.description_call_action), validNameOrNumber)); - primaryActionButtonView.setImageResource(R.drawable.quantum_ic_call_white_24); + primaryActionButtonView.setImageResource(R.drawable.quantum_ic_call_vd_theme_24); primaryActionButtonView.setVisibility(View.VISIBLE); } else { primaryActionButtonView.setTag(null); @@ -513,8 +569,15 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder return; } - if (!TextUtils.isEmpty(voicemailUri) && canPlaceCallToNumber) { + if (canPlaceCallToNumber) { + // Set up the call button but hide it by default (the primary action is to call so it is + // redundant). We then set it to be visible when appropriate below. This saves us having to + // remember to set it to GONE in multiple places. callButtonView.setTag(IntentProvider.getReturnCallIntentProvider(number)); + callButtonView.setVisibility(View.GONE); + } + + if (!TextUtils.isEmpty(voicemailUri) && canPlaceCallToNumber) { ((TextView) callButtonView.findViewById(R.id.call_action_text)) .setText( TextUtils.expandTemplate( @@ -529,13 +592,14 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder callTypeOrLocationView.setVisibility(View.GONE); } callButtonView.setVisibility(View.VISIBLE); - } else { - callButtonView.setVisibility(View.GONE); } if (hasPlacedCarrierVideoCall() || canSupportCarrierVideoCall()) { videoCallButtonView.setTag(IntentProvider.getReturnVideoCallIntentProvider(number)); videoCallButtonView.setVisibility(View.VISIBLE); + } else if (showLightbringerPrimaryButton()) { + callButtonView.setVisibility(View.VISIBLE); + videoCallButtonView.setVisibility(View.GONE); } else if (lightbringerReady) { videoCallButtonView.setTag(IntentProvider.getLightbringerIntentProvider(number)); videoCallButtonView.setVisibility(View.VISIBLE); @@ -567,8 +631,12 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder detailsButtonView.setVisibility(View.GONE); } else { detailsButtonView.setVisibility(View.VISIBLE); + boolean canReportCallerId = + mCachedNumberLookupService != null + && mCachedNumberLookupService.canReportAsInvalid(info.sourceType, info.objectId); detailsButtonView.setTag( - IntentProvider.getCallDetailIntentProvider(callDetailsEntries, buildContact())); + IntentProvider.getCallDetailIntentProvider( + callDetailsEntries, buildContact(), canReportCallerId)); } boolean isBlockedOrSpam = blockId != null || (isSpamFeatureEnabled && isSpam); @@ -616,6 +684,12 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder return false; } + private boolean showLightbringerPrimaryButton() { + return accountHandle != null + && accountHandle.getComponentName().equals(getLightbringer().getPhoneAccountComponentName()) + && lightbringerReady; + } + private static boolean hasDialableChar(CharSequence number) { if (TextUtils.isEmpty(number)) { return false; @@ -635,9 +709,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder if (accountHandle == null) { return false; } - if (accountHandle - .getComponentName() - .equals(getLightbringer().getPhoneAccountComponentName(mContext))) { + if (accountHandle.getComponentName().equals(getLightbringer().getPhoneAccountComponentName())) { return false; } return true; @@ -717,19 +789,14 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder getContactType()); } - private int getContactType() { - int contactType = ContactPhotoManager.TYPE_DEFAULT; - if (mCallLogCache.isVoicemailNumber(accountHandle, number)) { - contactType = ContactPhotoManager.TYPE_VOICEMAIL; - } else if (isSpam) { - contactType = ContactPhotoManager.TYPE_SPAM; - } else if (mCachedNumberLookupService != null - && mCachedNumberLookupService.isBusiness(info.sourceType)) { - contactType = ContactPhotoManager.TYPE_BUSINESS; - } else if (numberPresentation == TelecomManager.PRESENTATION_RESTRICTED) { - contactType = ContactPhotoManager.TYPE_GENERIC_AVATAR; - } - return contactType; + private @ContactType int getContactType() { + return LetterTileDrawable.getContactTypeFromPrimitives( + mCallLogCache.isVoicemailNumber(accountHandle, number), + isSpam, + mCachedNumberLookupService != null + && mCachedNumberLookupService.isBusiness(info.sourceType), + numberPresentation, + false); } @Override @@ -795,19 +862,45 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder mVoicemailPlaybackPresenter.shareVoicemail(); } else { logCallLogAction(view.getId()); + final IntentProvider intentProvider = (IntentProvider) view.getTag(); - if (intentProvider != null) { - final Intent intent = intentProvider.getIntent(mContext); - // See IntentProvider.getCallDetailIntentProvider() for why this may be null. - if (intent != null) { - DialerUtils.startActivityWithErrorToast(mContext, intent); + if (intentProvider == null) { + return; + } + + final Intent intent = intentProvider.getIntent(mContext); + // See IntentProvider.getCallDetailIntentProvider() for why this may be null. + if (intent == null) { + return; + } + + // We check to see if we are starting a Lightbringer intent. The reason is Lightbringer + // intents need to be started using startActivityForResult instead of the usual startActivity + String packageName = intent.getPackage(); + if (getLightbringer().getPackageName().equals(packageName)) { + startLightbringerActivity(intent); + } else { + if (intent.getComponent() != null + && CallDetailsActivity.class.getName().equals(intent.getComponent().getClassName())) { + // We are going to open call detail + PerformanceReport.recordClick(UiAction.Type.OPEN_CALL_DETAIL); } + DialerUtils.startActivityWithErrorToast(mContext, intent); } } } - private CallComposerContact buildContact() { - CallComposerContact.Builder contact = CallComposerContact.newBuilder(); + private void startLightbringerActivity(Intent intent) { + try { + Activity activity = (Activity) mContext; + activity.startActivityForResult(intent, DialtactsActivity.ACTIVITY_REQUEST_CODE_LIGHTBRINGER); + } catch (ActivityNotFoundException e) { + Toast.makeText(mContext, R.string.activity_not_available, Toast.LENGTH_SHORT).show(); + } + } + + private DialerContact buildContact() { + DialerContact.Builder contact = DialerContact.newBuilder(); contact.setPhotoId(info.photoId); if (info.photoUri != null) { contact.setPhotoUri(info.photoUri.toString()); @@ -826,6 +919,19 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder } /* phone number type (e.g. mobile) in second line of contact view */ contact.setNumberLabel(numberType); + + /* third line of contact view. */ + String accountLabel = mCallLogCache.getAccountLabel(accountHandle); + if (!TextUtils.isEmpty(accountLabel)) { + SimDetails.Builder simDetails = SimDetails.newBuilder().setNetwork(accountLabel); + int color = mCallLogCache.getAccountColor(accountHandle); + if (color == PhoneAccount.NO_HIGHLIGHT_COLOR) { + simDetails.setColor(R.color.secondary_text_color); + } else { + simDetails.setColor(color); + } + contact.setSimDetails(simDetails.build()); + } return contact.build(); } @@ -834,8 +940,38 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder Logger.get(mContext).logImpression(DialerImpression.Type.CALL_LOG_SEND_MESSAGE); } else if (id == R.id.add_to_existing_contact_action) { Logger.get(mContext).logImpression(DialerImpression.Type.CALL_LOG_ADD_TO_CONTACT); + switch (hostUi) { + case HostUi.CALL_HISTORY: + Logger.get(mContext) + .logImpression(DialerImpression.Type.ADD_TO_A_CONTACT_FROM_CALL_HISTORY); + break; + case HostUi.CALL_LOG: + Logger.get(mContext).logImpression(DialerImpression.Type.ADD_TO_A_CONTACT_FROM_CALL_LOG); + break; + case HostUi.VOICEMAIL: + Logger.get(mContext).logImpression(DialerImpression.Type.ADD_TO_A_CONTACT_FROM_VOICEMAIL); + break; + default: + throw Assert.createIllegalStateFailException(); + } } else if (id == R.id.create_new_contact_action) { Logger.get(mContext).logImpression(DialerImpression.Type.CALL_LOG_CREATE_NEW_CONTACT); + switch (hostUi) { + case HostUi.CALL_HISTORY: + Logger.get(mContext) + .logImpression(DialerImpression.Type.CREATE_NEW_CONTACT_FROM_CALL_HISTORY); + break; + case HostUi.CALL_LOG: + Logger.get(mContext) + .logImpression(DialerImpression.Type.CREATE_NEW_CONTACT_FROM_CALL_LOG); + break; + case HostUi.VOICEMAIL: + Logger.get(mContext) + .logImpression(DialerImpression.Type.CREATE_NEW_CONTACT_FROM_VOICEMAIL); + break; + default: + throw Assert.createIllegalStateFailException(); + } } } @@ -987,6 +1123,15 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder Logger.get(mContext).logScreenView(ScreenEvent.Type.CALL_LOG_CONTEXT_MENU, (Activity) mContext); } + /** Specifies where the view holder belongs. */ + @IntDef({HostUi.CALL_LOG, HostUi.CALL_HISTORY, HostUi.VOICEMAIL}) + @Retention(RetentionPolicy.SOURCE) + private @interface HostUi { + int CALL_LOG = 0; + int CALL_HISTORY = 1; + int VOICEMAIL = 2; + } + public interface OnClickListener { void onBlockReportSpam( diff --git a/java/com/android/dialer/app/calllog/CallLogNotificationsQueryHelper.java b/java/com/android/dialer/app/calllog/CallLogNotificationsQueryHelper.java index e169b8de9..43e03e9fd 100644 --- a/java/com/android/dialer/app/calllog/CallLogNotificationsQueryHelper.java +++ b/java/com/android/dialer/app/calllog/CallLogNotificationsQueryHelper.java @@ -18,7 +18,6 @@ package com.android.dialer.app.calllog; import android.Manifest; import android.annotation.TargetApi; -import android.app.NotificationManager; import android.content.ContentResolver; import android.content.ContentUris; import android.content.ContentValues; @@ -27,6 +26,7 @@ import android.database.Cursor; import android.net.Uri; import android.os.Build.VERSION_CODES; import android.provider.CallLog.Calls; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.WorkerThread; import android.support.v4.os.UserManagerCompat; @@ -36,7 +36,6 @@ import com.android.dialer.app.R; import com.android.dialer.calllogutils.PhoneNumberDisplayUtil; import com.android.dialer.common.LogUtil; import com.android.dialer.location.GeoUtil; -import com.android.dialer.notification.GroupedNotificationUtil; import com.android.dialer.phonenumbercache.ContactInfo; import com.android.dialer.phonenumbercache.ContactInfoHelper; import com.android.dialer.util.PermissionsUtil; @@ -46,7 +45,6 @@ import java.util.List; /** Helper class operating on call log notifications. */ public class CallLogNotificationsQueryHelper { - private static final String TAG = "CallLogNotifHelper"; private final Context mContext; private final NewCallsQuery mNewCallsQuery; private final ContactInfoHelper mContactInfoHelper; @@ -74,44 +72,58 @@ public class CallLogNotificationsQueryHelper { countryIso); } + public static void markAllMissedCallsInCallLogAsRead(@NonNull Context context) { + markMissedCallsInCallLogAsRead(context, null); + } + + public static void markSingleMissedCallInCallLogAsRead( + @NonNull Context context, @Nullable Uri callUri) { + if (callUri == null) { + LogUtil.e( + "CallLogNotificationsQueryHelper.markSingleMissedCallInCallLogAsRead", + "call URI is null, unable to mark call as read"); + } else { + markMissedCallsInCallLogAsRead(context, callUri); + } + } + /** - * Removes the missed call notifications and marks calls as read. If a callUri is provided, only - * that call is marked as read. + * If callUri is null then calls with a matching callUri are marked as read, otherwise all calls + * are marked as read. */ @WorkerThread - public static void removeMissedCallNotifications(Context context, @Nullable Uri callUri) { - // Call log is only accessible when unlocked. If that's the case, clear the list of - // new missed calls from the call log. - if (UserManagerCompat.isUserUnlocked(context) && PermissionsUtil.hasPhonePermissions(context)) { - ContentValues values = new ContentValues(); - values.put(Calls.NEW, 0); - values.put(Calls.IS_READ, 1); - StringBuilder where = new StringBuilder(); - where.append(Calls.NEW); - where.append(" = 1 AND "); - where.append(Calls.TYPE); - where.append(" = ?"); - try { - context - .getContentResolver() - .update( - callUri == null ? Calls.CONTENT_URI : callUri, - values, - where.toString(), - new String[] {Integer.toString(Calls.MISSED_TYPE)}); - } catch (IllegalArgumentException e) { - LogUtil.e( - "CallLogNotificationsQueryHelper.removeMissedCallNotifications", - "contacts provider update command failed", - e); - } + private static void markMissedCallsInCallLogAsRead(Context context, @Nullable Uri callUri) { + if (!UserManagerCompat.isUserUnlocked(context)) { + LogUtil.e("CallLogNotificationsQueryHelper.markMissedCallsInCallLogAsRead", "locked"); + return; + } + if (!PermissionsUtil.hasPhonePermissions(context)) { + LogUtil.e("CallLogNotificationsQueryHelper.markMissedCallsInCallLogAsRead", "no permission"); + return; } - GroupedNotificationUtil.removeNotification( - context.getSystemService(NotificationManager.class), - callUri != null ? callUri.toString() : null, - R.id.notification_missed_call, - MissedCallNotifier.NOTIFICATION_TAG); + ContentValues values = new ContentValues(); + values.put(Calls.NEW, 0); + values.put(Calls.IS_READ, 1); + StringBuilder where = new StringBuilder(); + where.append(Calls.NEW); + where.append(" = 1 AND "); + where.append(Calls.TYPE); + where.append(" = ?"); + try { + context + .getContentResolver() + .update( + callUri == null ? Calls.CONTENT_URI : callUri, + values, + where.toString(), + new String[] {Integer.toString(Calls.MISSED_TYPE)}); + } catch (IllegalArgumentException e) { + LogUtil.e( + "CallLogNotificationsQueryHelper.markMissedCallsInCallLogAsRead", + "contacts provider update command failed", + e); + } } /** Create a new instance of {@link NewCallsQuery}. */ @@ -281,7 +293,9 @@ public class CallLogNotificationsQueryHelper { @TargetApi(VERSION_CODES.M) public List<NewCall> query(int type) { if (!PermissionsUtil.hasPermission(mContext, Manifest.permission.READ_CALL_LOG)) { - LogUtil.w(TAG, "No READ_CALL_LOG permission, returning null for calls lookup."); + LogUtil.w( + "CallLogNotificationsQueryHelper.DefaultNewCallsQuery.query", + "no READ_CALL_LOG permission, returning null for calls lookup."); return null; } final String selection = String.format("%s = 1 AND %s = ?", Calls.NEW, Calls.TYPE); @@ -302,7 +316,9 @@ public class CallLogNotificationsQueryHelper { } return newCalls; } catch (RuntimeException e) { - LogUtil.w(TAG, "Exception when querying Contacts Provider for calls lookup"); + LogUtil.w( + "CallLogNotificationsQueryHelper.DefaultNewCallsQuery.query", + "exception when querying Contacts Provider for calls lookup"); return null; } } diff --git a/java/com/android/dialer/app/calllog/CallLogNotificationsService.java b/java/com/android/dialer/app/calllog/CallLogNotificationsService.java index 7dfd2cb69..be1ebfb6d 100644 --- a/java/com/android/dialer/app/calllog/CallLogNotificationsService.java +++ b/java/com/android/dialer/app/calllog/CallLogNotificationsService.java @@ -17,12 +17,13 @@ package com.android.dialer.app.calllog; import android.app.IntentService; +import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.net.Uri; -import android.os.Handler; -import android.os.Looper; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.VisibleForTesting; import com.android.dialer.common.LogUtil; import com.android.dialer.telecom.TelecomUtil; import com.android.dialer.util.PermissionsUtil; @@ -43,16 +44,20 @@ import com.android.dialer.util.PermissionsUtil; */ public class CallLogNotificationsService extends IntentService { - /** Action to mark all the new voicemails as old. */ - public static final String ACTION_MARK_NEW_VOICEMAILS_AS_OLD = - "com.android.dialer.calllog.ACTION_MARK_NEW_VOICEMAILS_AS_OLD"; + private static final String ACTION_MARK_ALL_NEW_VOICEMAILS_AS_OLD = + "com.android.dialer.calllog.ACTION_MARK_ALL_NEW_VOICEMAILS_AS_OLD"; - /** Action to mark all the new missed calls as old. */ - public static final String ACTION_MARK_NEW_MISSED_CALLS_AS_OLD = - "com.android.dialer.calllog.ACTION_MARK_NEW_MISSED_CALLS_AS_OLD"; + private static final String ACTION_MARK_SINGLE_NEW_VOICEMAIL_AS_OLD = + "com.android.dialer.calllog.ACTION_MARK_SINGLE_NEW_VOICEMAIL_AS_OLD "; - /** Action to update missed call notifications with a post call note. */ - public static final String ACTION_INCOMING_POST_CALL = + @VisibleForTesting + static final String ACTION_CANCEL_ALL_MISSED_CALLS = + "com.android.dialer.calllog.ACTION_CANCEL_ALL_MISSED_CALLS"; + + private static final String ACTION_CANCEL_SINGLE_MISSED_CALL = + "com.android.dialer.calllog.ACTION_CANCEL_SINGLE_MISSED_CALL"; + + private static final String ACTION_INCOMING_POST_CALL = "com.android.dialer.calllog.INCOMING_POST_CALL"; /** Action to call back a missed call. */ @@ -64,7 +69,7 @@ public class CallLogNotificationsService extends IntentService { * * <p>It must be a {@link String} */ - public static final String EXTRA_POST_CALL_NOTE = "POST_CALL_NOTE"; + private static final String EXTRA_POST_CALL_NOTE = "POST_CALL_NOTE"; /** * Extra to be included with {@link #ACTION_INCOMING_POST_CALL} to represent the phone number the @@ -72,10 +77,9 @@ public class CallLogNotificationsService extends IntentService { * * <p>It must be a {@link String} */ - public static final String EXTRA_POST_CALL_NUMBER = "POST_CALL_NUMBER"; + private static final String EXTRA_POST_CALL_NUMBER = "POST_CALL_NUMBER"; public static final int UNKNOWN_MISSED_CALL_COUNT = -1; - private VoicemailQueryHandler mVoicemailQueryHandler; public CallLogNotificationsService() { super("CallLogNotificationsService"); @@ -89,52 +93,95 @@ public class CallLogNotificationsService extends IntentService { context.startService(serviceIntent); } - public static void markNewVoicemailsAsOld(Context context, @Nullable Uri voicemailUri) { + public static void markAllNewVoicemailsAsOld(Context context) { + LogUtil.enterBlock("CallLogNotificationsService.markAllNewVoicemailsAsOld"); Intent serviceIntent = new Intent(context, CallLogNotificationsService.class); - serviceIntent.setAction(CallLogNotificationsService.ACTION_MARK_NEW_VOICEMAILS_AS_OLD); + serviceIntent.setAction(CallLogNotificationsService.ACTION_MARK_ALL_NEW_VOICEMAILS_AS_OLD); + context.startService(serviceIntent); + } + + public static void markSingleNewVoicemailAsOld(Context context, @Nullable Uri voicemailUri) { + LogUtil.enterBlock("CallLogNotificationsService.markSingleNewVoicemailAsOld"); + Intent serviceIntent = new Intent(context, CallLogNotificationsService.class); + serviceIntent.setAction(CallLogNotificationsService.ACTION_MARK_SINGLE_NEW_VOICEMAIL_AS_OLD); serviceIntent.setData(voicemailUri); context.startService(serviceIntent); } - public static void markNewMissedCallsAsOld(Context context, @Nullable Uri callUri) { + public static PendingIntent createMarkAllNewVoicemailsAsOldIntent(@NonNull Context context) { + Intent intent = new Intent(context, CallLogNotificationsService.class); + intent.setAction(CallLogNotificationsService.ACTION_MARK_ALL_NEW_VOICEMAILS_AS_OLD); + return PendingIntent.getService(context, 0, intent, 0); + } + + public static PendingIntent createMarkSingleNewVoicemailAsOldIntent( + @NonNull Context context, @Nullable Uri voicemailUri) { + Intent intent = new Intent(context, CallLogNotificationsService.class); + intent.setAction(CallLogNotificationsService.ACTION_MARK_SINGLE_NEW_VOICEMAIL_AS_OLD); + intent.setData(voicemailUri); + return PendingIntent.getService(context, 0, intent, 0); + } + + public static void cancelAllMissedCalls(@NonNull Context context) { + LogUtil.enterBlock("CallLogNotificationsService.cancelAllMissedCalls"); Intent serviceIntent = new Intent(context, CallLogNotificationsService.class); - serviceIntent.setAction(ACTION_MARK_NEW_MISSED_CALLS_AS_OLD); - serviceIntent.setData(callUri); + serviceIntent.setAction(ACTION_CANCEL_ALL_MISSED_CALLS); context.startService(serviceIntent); } + public static PendingIntent createCancelAllMissedCallsPendingIntent(@NonNull Context context) { + Intent intent = new Intent(context, CallLogNotificationsService.class); + intent.setAction(ACTION_CANCEL_ALL_MISSED_CALLS); + return PendingIntent.getService(context, 0, intent, 0); + } + + public static PendingIntent createCancelSingleMissedCallPendingIntent( + @NonNull Context context, @Nullable Uri callUri) { + Intent intent = new Intent(context, CallLogNotificationsService.class); + intent.setAction(ACTION_CANCEL_SINGLE_MISSED_CALL); + intent.setData(callUri); + return PendingIntent.getService(context, 0, intent, 0); + } + @Override protected void onHandleIntent(Intent intent) { if (intent == null) { - LogUtil.d("CallLogNotificationsService.onHandleIntent", "could not handle null intent"); + LogUtil.e("CallLogNotificationsService.onHandleIntent", "could not handle null intent"); return; } - if (!PermissionsUtil.hasPermission(this, android.Manifest.permission.READ_CALL_LOG)) { + if (!PermissionsUtil.hasPermission(this, android.Manifest.permission.READ_CALL_LOG) + || !PermissionsUtil.hasPermission(this, android.Manifest.permission.WRITE_CALL_LOG)) { + LogUtil.e("CallLogNotificationsService.onHandleIntent", "no READ_CALL_LOG permission"); return; } String action = intent.getAction(); + LogUtil.i("CallLogNotificationsService.onHandleIntent", "action: " + action); switch (action) { - case ACTION_MARK_NEW_VOICEMAILS_AS_OLD: - // VoicemailQueryHandler cannot be created on the IntentService worker thread. The completed - // callback might happen when the thread is dead. - Handler handler = new Handler(Looper.getMainLooper()); - handler.post( - () -> { - if (mVoicemailQueryHandler == null) { - mVoicemailQueryHandler = new VoicemailQueryHandler(this, getContentResolver()); - } - mVoicemailQueryHandler.markNewVoicemailsAsOld(intent.getData()); - }); + case ACTION_MARK_ALL_NEW_VOICEMAILS_AS_OLD: + VoicemailQueryHandler.markAllNewVoicemailsAsRead(this); + VisualVoicemailNotifier.cancelAllVoicemailNotifications(this); + break; + case ACTION_MARK_SINGLE_NEW_VOICEMAIL_AS_OLD: + Uri voicemailUri = intent.getData(); + VoicemailQueryHandler.markSingleNewVoicemailAsRead(this, voicemailUri); + VisualVoicemailNotifier.cancelSingleVoicemailNotification(this, voicemailUri); break; case ACTION_INCOMING_POST_CALL: String note = intent.getStringExtra(EXTRA_POST_CALL_NOTE); String phoneNumber = intent.getStringExtra(EXTRA_POST_CALL_NUMBER); MissedCallNotifier.getIstance(this).insertPostCallNotification(phoneNumber, note); break; - case ACTION_MARK_NEW_MISSED_CALLS_AS_OLD: - CallLogNotificationsQueryHelper.removeMissedCallNotifications(this, intent.getData()); + case ACTION_CANCEL_ALL_MISSED_CALLS: + CallLogNotificationsQueryHelper.markAllMissedCallsInCallLogAsRead(this); + MissedCallNotifier.cancelAllMissedCallNotifications(this); + TelecomUtil.cancelMissedCallsNotification(this); + break; + case ACTION_CANCEL_SINGLE_MISSED_CALL: + Uri callUri = intent.getData(); + CallLogNotificationsQueryHelper.markSingleMissedCallInCallLogAsRead(this, callUri); + MissedCallNotifier.cancelSingleMissedCallNotification(this, callUri); TelecomUtil.cancelMissedCallsNotification(this); break; case ACTION_CALL_BACK_FROM_MISSED_CALL_NOTIFICATION: @@ -145,7 +192,7 @@ public class CallLogNotificationsService extends IntentService { intent.getData()); break; default: - LogUtil.d("CallLogNotificationsService.onHandleIntent", "could not handle: " + intent); + LogUtil.e("CallLogNotificationsService.onHandleIntent", "no handler for action: " + action); break; } } diff --git a/java/com/android/dialer/app/calllog/CallLogReceiver.java b/java/com/android/dialer/app/calllog/CallLogReceiver.java index 172d00100..ce3132d12 100644 --- a/java/com/android/dialer/app/calllog/CallLogReceiver.java +++ b/java/com/android/dialer/app/calllog/CallLogReceiver.java @@ -39,10 +39,10 @@ public class CallLogReceiver extends BroadcastReceiver { if (VoicemailContract.ACTION_NEW_VOICEMAIL.equals(intent.getAction())) { checkVoicemailStatus(context); PendingResult pendingResult = goAsync(); - DefaultVoicemailNotifier.updateVoicemailNotifications(context, pendingResult::finish); + VisualVoicemailUpdateTask.scheduleTask(context, pendingResult::finish); } else if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { PendingResult pendingResult = goAsync(); - DefaultVoicemailNotifier.updateVoicemailNotifications(context, pendingResult::finish); + VisualVoicemailUpdateTask.scheduleTask(context, pendingResult::finish); } else { LogUtil.w("CallLogReceiver.onReceive", "could not handle: " + intent); } diff --git a/java/com/android/dialer/app/calllog/ClearCallLogDialog.java b/java/com/android/dialer/app/calllog/ClearCallLogDialog.java index a01b89527..155a91618 100644 --- a/java/com/android/dialer/app/calllog/ClearCallLogDialog.java +++ b/java/com/android/dialer/app/calllog/ClearCallLogDialog.java @@ -54,7 +54,7 @@ public class ClearCallLogDialog extends DialogFragment { ProgressDialog.show( getActivity(), getString(R.string.clearCallLogProgress_title), "", true, false); progressDialog.setOwnerActivity(getActivity()); - CallLogNotificationsService.markNewMissedCallsAsOld(getContext(), null); + CallLogNotificationsService.cancelAllMissedCalls(getContext()); final AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() { @Override diff --git a/java/com/android/dialer/app/calllog/DefaultVoicemailNotifier.java b/java/com/android/dialer/app/calllog/DefaultVoicemailNotifier.java deleted file mode 100644 index 58fe6fa2c..000000000 --- a/java/com/android/dialer/app/calllog/DefaultVoicemailNotifier.java +++ /dev/null @@ -1,446 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -package com.android.dialer.app.calllog; - -import android.annotation.TargetApi; -import android.app.Notification; -import android.app.NotificationManager; -import android.app.PendingIntent; -import android.content.Context; -import android.content.Intent; -import android.content.res.Resources; -import android.graphics.Bitmap; -import android.net.Uri; -import android.os.Build.VERSION; -import android.os.Build.VERSION_CODES; -import android.os.PersistableBundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.annotation.VisibleForTesting; -import android.support.annotation.WorkerThread; -import android.support.v4.os.BuildCompat; -import android.support.v4.util.Pair; -import android.telecom.PhoneAccount; -import android.telecom.PhoneAccountHandle; -import android.telecom.TelecomManager; -import android.telephony.CarrierConfigManager; -import android.telephony.PhoneNumberUtils; -import android.telephony.TelephonyManager; -import android.text.TextUtils; -import android.util.ArrayMap; -import com.android.contacts.common.compat.TelephonyManagerCompat; -import com.android.contacts.common.util.ContactDisplayUtils; -import com.android.dialer.app.DialtactsActivity; -import com.android.dialer.app.R; -import com.android.dialer.app.calllog.CallLogNotificationsQueryHelper.NewCall; -import com.android.dialer.app.contactinfo.ContactPhotoLoader; -import com.android.dialer.app.list.DialtactsPagerAdapter; -import com.android.dialer.blocking.FilteredNumberAsyncQueryHandler; -import com.android.dialer.blocking.FilteredNumbersUtil; -import com.android.dialer.calllogutils.PhoneAccountUtils; -import com.android.dialer.common.Assert; -import com.android.dialer.common.LogUtil; -import com.android.dialer.common.concurrent.DialerExecutor.Worker; -import com.android.dialer.common.concurrent.DialerExecutors; -import com.android.dialer.logging.DialerImpression; -import com.android.dialer.logging.Logger; -import com.android.dialer.notification.NotificationChannelManager; -import com.android.dialer.notification.NotificationChannelManager.Channel; -import com.android.dialer.phonenumbercache.ContactInfo; -import com.android.dialer.telecom.TelecomUtil; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -/** Shows a voicemail notification in the status bar. */ -public class DefaultVoicemailNotifier implements Worker<Void, Void> { - - public static final String TAG = "VoicemailNotifier"; - - /** The tag used to identify notifications from this class. */ - static final String VISUAL_VOICEMAIL_NOTIFICATION_TAG = "DefaultVoicemailNotifier"; - /** The identifier of the notification of new voicemails. */ - private static final int VISUAL_VOICEMAIL_NOTIFICATION_ID = R.id.notification_visual_voicemail; - - private static final int LEGACY_VOICEMAIL_NOTIFICATION_ID = R.id.notification_legacy_voicemail; - private static final String LEGACY_VOICEMAIL_NOTIFICATION_TAG = "legacy_voicemail"; - - private final Context context; - private final CallLogNotificationsQueryHelper queryHelper; - private final FilteredNumberAsyncQueryHandler filteredNumberAsyncQueryHandler; - - @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) - DefaultVoicemailNotifier( - Context context, - CallLogNotificationsQueryHelper queryHelper, - FilteredNumberAsyncQueryHandler filteredNumberAsyncQueryHandler) { - this.context = context; - this.queryHelper = queryHelper; - this.filteredNumberAsyncQueryHandler = filteredNumberAsyncQueryHandler; - } - - public DefaultVoicemailNotifier(Context context) { - this( - context, - CallLogNotificationsQueryHelper.getInstance(context), - new FilteredNumberAsyncQueryHandler(context)); - } - - @Nullable - @Override - public Void doInBackground(@Nullable Void input) throws Throwable { - updateNotification(); - return null; - } - - /** - * Updates the notification and notifies of the call with the given URI. - * - * <p>Clears the notification if there are no new voicemails, and notifies if the given URI - * corresponds to a new voicemail. - * - * <p>It is not safe to call this method from the main thread. - */ - @VisibleForTesting - @WorkerThread - void updateNotification() { - Assert.isWorkerThread(); - // Lookup the list of new voicemails to include in the notification. - final List<NewCall> newCalls = queryHelper.getNewVoicemails(); - - if (newCalls == null) { - // Query failed, just return. - return; - } - - Resources resources = context.getResources(); - - // This represents a list of names to include in the notification. - String callers = null; - - // Maps each number into a name: if a number is in the map, it has already left a more - // recent voicemail. - final Map<String, ContactInfo> contactInfos = new ArrayMap<>(); - - // Iterate over the new voicemails to determine all the information above. - Iterator<NewCall> itr = newCalls.iterator(); - while (itr.hasNext()) { - NewCall newCall = itr.next(); - - // Skip notifying for numbers which are blocked. - if (!FilteredNumbersUtil.hasRecentEmergencyCall(context) - && filteredNumberAsyncQueryHandler.getBlockedIdSynchronous( - newCall.number, newCall.countryIso) - != null) { - itr.remove(); - - if (newCall.voicemailUri != null) { - // Delete the voicemail. - CallLogAsyncTaskUtil.deleteVoicemailSynchronous(context, newCall.voicemailUri); - } - continue; - } - - // Check if we already know the name associated with this number. - ContactInfo contactInfo = contactInfos.get(newCall.number); - if (contactInfo == null) { - contactInfo = - queryHelper.getContactInfo( - newCall.number, newCall.numberPresentation, newCall.countryIso); - contactInfos.put(newCall.number, contactInfo); - // This is a new caller. Add it to the back of the list of callers. - if (TextUtils.isEmpty(callers)) { - callers = contactInfo.name; - } else { - callers = - resources.getString( - R.string.notification_voicemail_callers_list, callers, contactInfo.name); - } - } - } - - if (newCalls.isEmpty()) { - // No voicemails to notify about - return; - } - - Notification.Builder groupSummary = - createNotificationBuilder() - .setContentTitle( - resources.getQuantityString( - R.plurals.notification_voicemail_title, newCalls.size(), newCalls.size())) - .setContentText(callers) - .setDeleteIntent(createMarkNewVoicemailsAsOldIntent(null)) - .setGroupSummary(true) - .setContentIntent(newVoicemailIntent(null)); - - if (BuildCompat.isAtLeastO()) { - groupSummary.setGroupAlertBehavior(Notification.GROUP_ALERT_CHILDREN); - } - - NotificationChannelManager.applyChannel( - groupSummary, - context, - Channel.VOICEMAIL, - PhoneAccountHandles.getAccount(context, newCalls.get(0))); - - LogUtil.i(TAG, "Creating visual voicemail notification"); - getNotificationManager() - .notify( - VISUAL_VOICEMAIL_NOTIFICATION_TAG, - VISUAL_VOICEMAIL_NOTIFICATION_ID, - groupSummary.build()); - - for (NewCall voicemail : newCalls) { - getNotificationManager() - .notify( - voicemail.callsUri.toString(), - VISUAL_VOICEMAIL_NOTIFICATION_ID, - createNotificationForVoicemail(voicemail, contactInfos)); - } - } - - /** - * Replicates how packages/services/Telephony/NotificationMgr.java handles legacy voicemail - * notification. The notification will not be stackable because no information is available for - * individual voicemails. - */ - @TargetApi(VERSION_CODES.O) - public void notifyLegacyVoicemail( - @NonNull PhoneAccountHandle phoneAccountHandle, - int count, - String voicemailNumber, - PendingIntent callVoicemailIntent, - PendingIntent voicemailSettingIntent) { - Assert.isNotNull(phoneAccountHandle); - Assert.checkArgument(BuildCompat.isAtLeastO()); - TelephonyManager telephonyManager = - context - .getSystemService(TelephonyManager.class) - .createForPhoneAccountHandle(phoneAccountHandle); - Assert.isNotNull(telephonyManager); - LogUtil.i(TAG, "Creating legacy voicemail notification"); - - PersistableBundle carrierConfig = telephonyManager.getCarrierConfig(); - - String notificationTitle = - context - .getResources() - .getQuantityString(R.plurals.notification_voicemail_title, count, count); - - TelecomManager telecomManager = context.getSystemService(TelecomManager.class); - PhoneAccount phoneAccount = telecomManager.getPhoneAccount(phoneAccountHandle); - - String notificationText; - PendingIntent pendingIntent; - - if (voicemailSettingIntent != null) { - // If the voicemail number if unknown, instead of calling voicemail, take the user - // to the voicemail settings. - notificationText = context.getString(R.string.notification_voicemail_no_vm_number); - pendingIntent = voicemailSettingIntent; - } else { - if (PhoneAccountUtils.getSubscriptionPhoneAccounts(context).size() > 1) { - notificationText = phoneAccount.getShortDescription().toString(); - } else { - notificationText = - String.format( - context.getString(R.string.notification_voicemail_text_format), - PhoneNumberUtils.formatNumber(voicemailNumber)); - } - pendingIntent = callVoicemailIntent; - } - Notification.Builder builder = new Notification.Builder(context); - builder - .setSmallIcon(android.R.drawable.stat_notify_voicemail) - .setColor(context.getColor(R.color.dialer_theme_color)) - .setWhen(System.currentTimeMillis()) - .setContentTitle(notificationTitle) - .setContentText(notificationText) - .setContentIntent(pendingIntent) - .setSound(telephonyManager.getVoicemailRingtoneUri(phoneAccountHandle)) - .setOngoing( - carrierConfig.getBoolean( - CarrierConfigManager.KEY_VOICEMAIL_NOTIFICATION_PERSISTENT_BOOL)); - - if (telephonyManager.isVoicemailVibrationEnabled(phoneAccountHandle)) { - builder.setDefaults(Notification.DEFAULT_VIBRATE); - } - - NotificationChannelManager.applyChannel( - builder, context, Channel.VOICEMAIL, phoneAccountHandle); - Notification notification = builder.build(); - getNotificationManager() - .notify(LEGACY_VOICEMAIL_NOTIFICATION_TAG, LEGACY_VOICEMAIL_NOTIFICATION_ID, notification); - } - - public void cancelLegacyNotification() { - LogUtil.i(TAG, "Clearing legacy voicemail notification"); - getNotificationManager() - .cancel(LEGACY_VOICEMAIL_NOTIFICATION_TAG, LEGACY_VOICEMAIL_NOTIFICATION_ID); - } - - /** - * Determines which ringtone Uri and Notification defaults to use when updating the notification - * for the given call. - */ - private Pair<Uri, Integer> getNotificationInfo(@Nullable NewCall callToNotify) { - LogUtil.v(TAG, "getNotificationInfo"); - if (callToNotify == null) { - LogUtil.i(TAG, "callToNotify == null"); - return new Pair<>(null, 0); - } - PhoneAccountHandle accountHandle = PhoneAccountHandles.getAccount(context, callToNotify); - if (accountHandle == null) { - LogUtil.i(TAG, "No default phone account found, using default notification ringtone"); - return new Pair<>(null, Notification.DEFAULT_ALL); - } - return new Pair<>( - TelephonyManagerCompat.getVoicemailRingtoneUri(getTelephonyManager(), accountHandle), - getNotificationDefaults(accountHandle)); - } - - private int getNotificationDefaults(PhoneAccountHandle accountHandle) { - if (VERSION.SDK_INT >= VERSION_CODES.N) { - return TelephonyManagerCompat.isVoicemailVibrationEnabled( - getTelephonyManager(), accountHandle) - ? Notification.DEFAULT_VIBRATE - : 0; - } - return Notification.DEFAULT_ALL; - } - - /** Creates a pending intent that marks all new voicemails as old. */ - private PendingIntent createMarkNewVoicemailsAsOldIntent(@Nullable Uri voicemailUri) { - Intent intent = new Intent(context, CallLogNotificationsService.class); - intent.setAction(CallLogNotificationsService.ACTION_MARK_NEW_VOICEMAILS_AS_OLD); - intent.setData(voicemailUri); - return PendingIntent.getService(context, 0, intent, 0); - } - - private NotificationManager getNotificationManager() { - return (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); - } - - private TelephonyManager getTelephonyManager() { - return (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); - } - - private Notification createNotificationForVoicemail( - @NonNull NewCall voicemail, @NonNull Map<String, ContactInfo> contactInfos) { - Pair<Uri, Integer> notificationInfo = getNotificationInfo(voicemail); - ContactInfo contactInfo = contactInfos.get(voicemail.number); - - Notification.Builder notificationBuilder = - createNotificationBuilder() - .setContentTitle( - context - .getResources() - .getQuantityString(R.plurals.notification_voicemail_title, 1, 1)) - .setContentText( - ContactDisplayUtils.getTtsSpannedPhoneNumber( - context.getResources(), - R.string.notification_new_voicemail_ticker, - contactInfo.name)) - .setWhen(voicemail.dateMs) - .setSound(notificationInfo.first) - .setDefaults(notificationInfo.second); - - if (voicemail.voicemailUri != null) { - notificationBuilder.setDeleteIntent( - createMarkNewVoicemailsAsOldIntent(voicemail.voicemailUri)); - } - - NotificationChannelManager.applyChannel( - notificationBuilder, - context, - Channel.VOICEMAIL, - PhoneAccountHandles.getAccount(context, voicemail)); - - ContactPhotoLoader loader = new ContactPhotoLoader(context, contactInfo); - Bitmap photoIcon = loader.loadPhotoIcon(); - if (photoIcon != null) { - notificationBuilder.setLargeIcon(photoIcon); - } - if (!TextUtils.isEmpty(voicemail.transcription)) { - Logger.get(context) - .logImpression(DialerImpression.Type.VVM_NOTIFICATION_CREATED_WITH_TRANSCRIPTION); - notificationBuilder.setStyle( - new Notification.BigTextStyle().bigText(voicemail.transcription)); - } - notificationBuilder.setContentIntent(newVoicemailIntent(voicemail)); - Logger.get(context).logImpression(DialerImpression.Type.VVM_NOTIFICATION_CREATED); - return notificationBuilder.build(); - } - - private Notification.Builder createNotificationBuilder() { - return new Notification.Builder(context) - .setSmallIcon(android.R.drawable.stat_notify_voicemail) - .setColor(context.getColor(R.color.dialer_theme_color)) - .setGroup(VISUAL_VOICEMAIL_NOTIFICATION_TAG) - .setOnlyAlertOnce(true) - .setAutoCancel(true); - } - - private PendingIntent newVoicemailIntent(@Nullable NewCall voicemail) { - Intent intent = - DialtactsActivity.getShowTabIntent(context, DialtactsPagerAdapter.TAB_INDEX_VOICEMAIL); - // TODO (b/35486204): scroll to this voicemail - if (voicemail != null) { - intent.setData(voicemail.voicemailUri); - } - intent.putExtra(DialtactsActivity.EXTRA_CLEAR_NEW_VOICEMAILS, true); - return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); - } - - /** - * Updates the voicemail notifications displayed. - * - * @param runnable Called when the async update task completes no matter if it succeeds or fails. - * May be null. - */ - static void updateVoicemailNotifications(Context context, Runnable runnable) { - if (!TelecomUtil.isDefaultDialer(context)) { - LogUtil.i( - "DefaultVoicemailNotifier.updateVoicemailNotifications", - "not default dialer, not scheduling update to voicemail notifications"); - return; - } - - DialerExecutors.createNonUiTaskBuilder(new DefaultVoicemailNotifier(context)) - .onSuccess( - output -> { - LogUtil.i( - "DefaultVoicemailNotifier.updateVoicemailNotifications", - "update voicemail notifications successful"); - if (runnable != null) { - runnable.run(); - } - }) - .onFailure( - throwable -> { - LogUtil.i( - "DefaultVoicemailNotifier.updateVoicemailNotifications", - "update voicemail notifications failed"); - if (runnable != null) { - runnable.run(); - } - }) - .build() - .executeParallel(null); - } -} diff --git a/java/com/android/dialer/app/calllog/DialerQuickContactBadge.java b/java/com/android/dialer/app/calllog/DialerQuickContactBadge.java new file mode 100644 index 000000000..a3aac41fa --- /dev/null +++ b/java/com/android/dialer/app/calllog/DialerQuickContactBadge.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.dialer.app.calllog; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.View; +import android.widget.QuickContactBadge; +import com.android.dialer.app.calllog.CallLogAdapter.OnActionModeStateChangedListener; +import com.android.dialer.logging.DialerImpression; +import com.android.dialer.logging.Logger; + +/** Allows us to click the contact badge for non multi select mode. */ +class DialerQuickContactBadge extends QuickContactBadge { + + private View.OnClickListener mExtraOnClickListener; + private OnActionModeStateChangedListener onActionModeStateChangeListener; + + public DialerQuickContactBadge(Context context) { + super(context); + } + + public DialerQuickContactBadge(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public DialerQuickContactBadge(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + @Override + public void onClick(View v) { + if (mExtraOnClickListener != null + && onActionModeStateChangeListener.isActionModeStateEnabled()) { + Logger.get(v.getContext()) + .logImpression(DialerImpression.Type.MULTISELECT_SINGLE_PRESS_TAP_VIA_CONTACT_BADGE); + mExtraOnClickListener.onClick(v); + } else { + super.onClick(v); + } + } + + public void setMulitSelectListeners( + View.OnClickListener extraOnClickListener, + OnActionModeStateChangedListener actionModeStateChangeListener) { + mExtraOnClickListener = extraOnClickListener; + onActionModeStateChangeListener = actionModeStateChangeListener; + } +} diff --git a/java/com/android/dialer/app/calllog/IntentProvider.java b/java/com/android/dialer/app/calllog/IntentProvider.java index a94c6781e..e1ec9f509 100644 --- a/java/com/android/dialer/app/calllog/IntentProvider.java +++ b/java/com/android/dialer/app/calllog/IntentProvider.java @@ -24,12 +24,14 @@ import android.provider.ContactsContract; import android.telecom.PhoneAccountHandle; import com.android.contacts.common.model.Contact; import com.android.contacts.common.model.ContactLoader; -import com.android.dialer.callcomposer.CallComposerContact; import com.android.dialer.calldetails.CallDetailsActivity; import com.android.dialer.calldetails.CallDetailsEntries; import com.android.dialer.callintent.CallInitiationType; import com.android.dialer.callintent.CallIntentBuilder; +import com.android.dialer.dialercontact.DialerContact; import com.android.dialer.lightbringer.LightbringerComponent; +import com.android.dialer.logging.DialerImpression; +import com.android.dialer.logging.Logger; import com.android.dialer.util.CallUtil; import com.android.dialer.util.IntentUtil; import java.util.ArrayList; @@ -68,6 +70,7 @@ public abstract class IntentProvider { return new IntentProvider() { @Override public Intent getIntent(Context context) { + Logger.get(context).logImpression(DialerImpression.Type.IMS_VIDEO_REQUESTED_FROM_CALL_LOG); return new CallIntentBuilder(number, CallInitiationType.Type.CALL_LOG) .setPhoneAccountHandle(accountHandle) .setIsVideoCall(true) @@ -80,6 +83,8 @@ public abstract class IntentProvider { return new IntentProvider() { @Override public Intent getIntent(Context context) { + Logger.get(context) + .logImpression(DialerImpression.Type.LIGHTBRINGER_VIDEO_REQUESTED_FROM_CALL_LOG); return LightbringerComponent.get(context).getLightbringer().getIntent(context, number); } }; @@ -112,11 +117,12 @@ public abstract class IntentProvider { * @return The call details intent provider. */ public static IntentProvider getCallDetailIntentProvider( - CallDetailsEntries callDetailsEntries, CallComposerContact contact) { + CallDetailsEntries callDetailsEntries, DialerContact contact, boolean canReportCallerId) { return new IntentProvider() { @Override public Intent getIntent(Context context) { - return CallDetailsActivity.newInstance(context, callDetailsEntries, contact); + return CallDetailsActivity.newInstance( + context, callDetailsEntries, contact, canReportCallerId); } }; } diff --git a/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java b/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java new file mode 100644 index 000000000..428c71677 --- /dev/null +++ b/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java @@ -0,0 +1,156 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.dialer.app.calllog; + +import android.annotation.TargetApi; +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; +import android.os.Build.VERSION_CODES; +import android.support.annotation.NonNull; +import android.support.v4.os.BuildCompat; +import android.telecom.PhoneAccount; +import android.telecom.PhoneAccountHandle; +import android.telecom.TelecomManager; +import android.telephony.CarrierConfigManager; +import android.telephony.PhoneNumberUtils; +import android.telephony.TelephonyManager; +import android.text.TextUtils; +import com.android.dialer.app.R; +import com.android.dialer.calllogutils.PhoneAccountUtils; +import com.android.dialer.common.Assert; +import com.android.dialer.common.LogUtil; +import com.android.dialer.notification.NotificationChannelManager; + +/** Shows a notification in the status bar for legacy vociemail. */ +@TargetApi(VERSION_CODES.O) +public final class LegacyVoicemailNotifier { + private static final String NOTIFICATION_TAG = "LegacyVoicemail"; + private static final int NOTIFICATION_ID = 1; + + /** + * Replicates how packages/services/Telephony/NotificationMgr.java handles legacy voicemail + * notification. The notification will not be stackable because no information is available for + * individual voicemails. + */ + public static void showNotification( + @NonNull Context context, + @NonNull PhoneAccountHandle handle, + int count, + String voicemailNumber, + PendingIntent callVoicemailIntent, + PendingIntent voicemailSettingsIntent, + boolean isRefresh) { + LogUtil.enterBlock("LegacyVoicemailNotifier.showNotification"); + Assert.isNotNull(handle); + Assert.checkArgument(BuildCompat.isAtLeastO()); + + TelephonyManager pinnedTelephonyManager = + context.getSystemService(TelephonyManager.class).createForPhoneAccountHandle(handle); + if (pinnedTelephonyManager == null) { + LogUtil.e("LegacyVoicemailNotifier.showNotification", "invalid PhoneAccountHandle"); + return; + } + + Notification notification = + createNotification( + context, + pinnedTelephonyManager, + handle, + count, + voicemailNumber, + callVoicemailIntent, + voicemailSettingsIntent, + isRefresh); + context + .getSystemService(NotificationManager.class) + .notify(NOTIFICATION_TAG, NOTIFICATION_ID, notification); + } + + @NonNull + private static Notification createNotification( + @NonNull Context context, + @NonNull TelephonyManager pinnedTelephonyManager, + @NonNull PhoneAccountHandle handle, + int count, + String voicemailNumber, + PendingIntent callVoicemailIntent, + PendingIntent voicemailSettingsIntent, + boolean isRefresh) { + String notificationTitle = + context + .getResources() + .getQuantityString(R.plurals.notification_voicemail_title, count, count); + boolean isOngoing = + pinnedTelephonyManager + .getCarrierConfig() + .getBoolean(CarrierConfigManager.KEY_VOICEMAIL_NOTIFICATION_PERSISTENT_BOOL); + + String contentText; + PendingIntent contentIntent; + if (!TextUtils.isEmpty(voicemailNumber) && callVoicemailIntent != null) { + contentText = getNotificationText(context, handle, voicemailNumber); + contentIntent = callVoicemailIntent; + } else { + contentText = context.getString(R.string.notification_voicemail_no_vm_number); + contentIntent = voicemailSettingsIntent; + } + + Notification.Builder builder = + new Notification.Builder(context) + .setSmallIcon(android.R.drawable.stat_notify_voicemail) + .setColor(context.getColor(R.color.dialer_theme_color)) + .setWhen(System.currentTimeMillis()) + .setContentTitle(notificationTitle) + .setContentText(contentText) + .setContentIntent(contentIntent) + .setSound(pinnedTelephonyManager.getVoicemailRingtoneUri(handle)) + .setOngoing(isOngoing) + .setOnlyAlertOnce(isRefresh) + .setChannelId(NotificationChannelManager.getVoicemailChannelId(context, handle)); + + if (pinnedTelephonyManager.isVoicemailVibrationEnabled(handle)) { + builder.setDefaults(Notification.DEFAULT_VIBRATE); + } + + return builder.build(); + } + + @NonNull + private static String getNotificationText( + @NonNull Context context, PhoneAccountHandle handle, String voicemailNumber) { + if (PhoneAccountUtils.getSubscriptionPhoneAccounts(context).size() > 1) { + TelecomManager telecomManager = context.getSystemService(TelecomManager.class); + PhoneAccount phoneAccount = telecomManager.getPhoneAccount(handle); + return phoneAccount.getShortDescription().toString(); + } else { + return String.format( + context.getString(R.string.notification_voicemail_text_format), + PhoneNumberUtils.formatNumber(voicemailNumber)); + } + } + + public static void cancelNotification(@NonNull Context context) { + LogUtil.enterBlock("LegacyVoicemailNotifier.cancelNotification"); + Assert.checkArgument(BuildCompat.isAtLeastO()); + NotificationManager notificationManager = context.getSystemService(NotificationManager.class); + notificationManager.cancel(NOTIFICATION_TAG, NOTIFICATION_ID); + } + + private LegacyVoicemailNotifier() {} +} diff --git a/java/com/android/dialer/app/calllog/MissedCallNotifier.java b/java/com/android/dialer/app/calllog/MissedCallNotifier.java index dd13298bc..e0e3fdf3f 100644 --- a/java/com/android/dialer/app/calllog/MissedCallNotifier.java +++ b/java/com/android/dialer/app/calllog/MissedCallNotifier.java @@ -30,11 +30,13 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.VisibleForTesting; import android.support.annotation.WorkerThread; +import android.support.v4.os.BuildCompat; import android.support.v4.os.UserManagerCompat; import android.support.v4.util.Pair; import android.text.BidiFormatter; import android.text.TextDirectionHeuristics; import android.text.TextUtils; +import android.util.ArraySet; import com.android.contacts.common.ContactsUtils; import com.android.contacts.common.compat.PhoneNumberUtilsCompat; import com.android.dialer.app.DialtactsActivity; @@ -46,23 +48,20 @@ import com.android.dialer.callintent.CallInitiationType; import com.android.dialer.callintent.CallIntentBuilder; import com.android.dialer.common.LogUtil; import com.android.dialer.common.concurrent.DialerExecutor.Worker; -import com.android.dialer.notification.NotificationChannelManager; -import com.android.dialer.notification.NotificationChannelManager.Channel; +import com.android.dialer.notification.NotificationChannelId; import com.android.dialer.phonenumbercache.ContactInfo; import com.android.dialer.phonenumberutil.PhoneNumberHelper; import com.android.dialer.util.DialerUtils; import com.android.dialer.util.IntentUtil; -import java.util.HashSet; import java.util.List; import java.util.Set; /** Creates a notification for calls that the user missed (neither answered nor rejected). */ public class MissedCallNotifier implements Worker<Pair<Integer, String>, Void> { - /** The tag used to identify notifications from this class. */ - static final String NOTIFICATION_TAG = "MissedCallNotifier"; - /** The identifier of the notification of new missed calls. */ - private static final int NOTIFICATION_ID = R.id.notification_missed_call; + static final String NOTIFICATION_TAG_PREFIX = "MissedCall_"; + static final String NOTIFICATION_GROUP = "MissedCall"; + private static final int NOTIFICATION_ID = 1; private final Context context; private final CallLogNotificationsQueryHelper callLogNotificationsQueryHelper; @@ -104,7 +103,8 @@ public class MissedCallNotifier implements Worker<Pair<Integer, String>, Void> { if ((newCalls != null && newCalls.isEmpty()) || count == 0) { // No calls to notify about: clear the notification. - CallLogNotificationsQueryHelper.removeMissedCallNotifications(context, null); + CallLogNotificationsQueryHelper.markAllMissedCallsInCallLogAsRead(context); + cancelAllMissedCallNotifications(context); return; } @@ -146,7 +146,7 @@ public class MissedCallNotifier implements Worker<Pair<Integer, String>, Void> { null, System.currentTimeMillis()); - //TODO: look up caller ID that is not in contacts. + // TODO: look up caller ID that is not in contacts. ContactInfo contactInfo = callLogNotificationsQueryHelper.getContactInfo( call.number, call.numberPresentation, call.countryIso); @@ -181,36 +181,39 @@ public class MissedCallNotifier implements Worker<Pair<Integer, String>, Void> { publicSummaryBuilder .setContentTitle(context.getText(titleResId)) .setContentIntent(createCallLogPendingIntent()) - .setDeleteIntent(createClearMissedCallsPendingIntent(null)); + .setDeleteIntent( + CallLogNotificationsService.createCancelAllMissedCallsPendingIntent(context)); // Create the notification summary suitable for display when sensitive information is showing. groupSummary .setContentTitle(context.getText(titleResId)) .setContentText(expandedText) .setContentIntent(createCallLogPendingIntent()) - .setDeleteIntent(createClearMissedCallsPendingIntent(null)) + .setDeleteIntent( + CallLogNotificationsService.createCancelAllMissedCallsPendingIntent(context)) .setGroupSummary(useCallList) .setOnlyAlertOnce(useCallList) .setPublicVersion(publicSummaryBuilder.build()); - - NotificationChannelManager.applyChannel(groupSummary, context, Channel.MISSED_CALL, null); + if (BuildCompat.isAtLeastO()) { + groupSummary.setChannelId(NotificationChannelId.MISSED_CALL); + } Notification notification = groupSummary.build(); configureLedOnNotification(notification); LogUtil.i("MissedCallNotifier.updateMissedCallNotification", "adding missed call notification"); - getNotificationMgr().notify(NOTIFICATION_TAG, NOTIFICATION_ID, notification); + getNotificationMgr().notify(getNotificationTagForGroupSummary(), NOTIFICATION_ID, notification); if (useCallList) { // Do not repost active notifications to prevent erasing post call notes. NotificationManager manager = getNotificationMgr(); - Set<String> activeTags = new HashSet<>(); + Set<String> activeTags = new ArraySet<>(); for (StatusBarNotification activeNotification : manager.getActiveNotifications()) { activeTags.add(activeNotification.getTag()); } for (NewCall call : newCalls) { - String callTag = call.callsUri.toString(); + String callTag = getNotificationTagForCall(call); if (!activeTags.contains(callTag)) { manager.notify(callTag, NOTIFICATION_ID, getNotificationForCall(call, null)); } @@ -218,6 +221,59 @@ public class MissedCallNotifier implements Worker<Pair<Integer, String>, Void> { } } + public static void cancelAllMissedCallNotifications(@NonNull Context context) { + NotificationManager notificationManager = context.getSystemService(NotificationManager.class); + for (StatusBarNotification notification : notificationManager.getActiveNotifications()) { + String tag = notification.getTag(); + if (tag != null && tag.startsWith(NOTIFICATION_TAG_PREFIX)) { + notificationManager.cancel(tag, notification.getId()); + } + } + } + + public static void cancelSingleMissedCallNotification( + @NonNull Context context, @Nullable Uri callUri) { + if (callUri == null) { + LogUtil.e( + "MissedCallNotifier.cancelSingleMissedCallNotification", + "unable to cancel notification, uri is null"); + return; + } + NotificationManager notificationManager = context.getSystemService(NotificationManager.class); + String callTag = getNotificationTagForCallUri(callUri); + String summaryTag = getNotificationTagForGroupSummary(); + int notificationCount = 0; + + for (StatusBarNotification notification : notificationManager.getActiveNotifications()) { + String currentTag = notification.getTag(); + if (currentTag == null) { + continue; + } + if (currentTag.equals(callTag)) { + notificationManager.cancel(notification.getTag(), notification.getId()); + } else if (currentTag.startsWith(NOTIFICATION_TAG_PREFIX) && !currentTag.equals(summaryTag)) { + notificationCount++; + } + } + + if (notificationCount == 0) { + // There are no more missed call notifications. Remove the summary notification too. + notificationManager.cancel(summaryTag, NOTIFICATION_ID); + } + } + + private static String getNotificationTagForGroupSummary() { + return NOTIFICATION_TAG_PREFIX + "GroupSummary"; + } + + private static String getNotificationTagForCall(@NonNull NewCall call) { + return getNotificationTagForCallUri(call.callsUri); + } + + private static String getNotificationTagForCallUri(@NonNull Uri callUri) { + return NOTIFICATION_TAG_PREFIX + callUri; + } + public void insertPostCallNotification(@NonNull String number, @NonNull String note) { List<NewCall> newCalls = callLogNotificationsQueryHelper.getNewMissedCalls(); if (newCalls != null && !newCalls.isEmpty()) { @@ -226,7 +282,9 @@ public class MissedCallNotifier implements Worker<Pair<Integer, String>, Void> { // Update the first notification that matches our post call note sender. getNotificationMgr() .notify( - call.callsUri.toString(), NOTIFICATION_ID, getNotificationForCall(call, note)); + getNotificationTagForCall(call), + NOTIFICATION_ID, + getNotificationForCall(call, note)); break; } } @@ -308,7 +366,7 @@ public class MissedCallNotifier implements Worker<Pair<Integer, String>, Void> { private Notification.Builder createNotificationBuilder() { return new Notification.Builder(context) - .setGroup(NOTIFICATION_TAG) + .setGroup(NOTIFICATION_GROUP) .setSmallIcon(android.R.drawable.stat_notify_missed_call) .setColor(context.getResources().getColor(R.color.dialer_theme_color, null)) .setAutoCancel(true) @@ -321,10 +379,14 @@ public class MissedCallNotifier implements Worker<Pair<Integer, String>, Void> { Builder builder = createNotificationBuilder() .setWhen(call.dateMs) - .setDeleteIntent(createClearMissedCallsPendingIntent(call.callsUri)) + .setDeleteIntent( + CallLogNotificationsService.createCancelSingleMissedCallPendingIntent( + context, call.callsUri)) .setContentIntent(createCallLogPendingIntent(call.callsUri)); + if (BuildCompat.isAtLeastO()) { + builder.setChannelId(NotificationChannelId.MISSED_CALL); + } - NotificationChannelManager.applyChannel(builder, context, Channel.MISSED_CALL, null); return builder; } @@ -332,7 +394,8 @@ public class MissedCallNotifier implements Worker<Pair<Integer, String>, Void> { @WorkerThread public void callBackFromMissedCall(String number, Uri callUri) { closeSystemDialogs(context); - CallLogNotificationsQueryHelper.removeMissedCallNotifications(context, callUri); + CallLogNotificationsQueryHelper.markSingleMissedCallInCallLogAsRead(context, callUri); + cancelSingleMissedCallNotification(context, callUri); DialerUtils.startActivityWithErrorToast( context, new CallIntentBuilder(number, CallInitiationType.Type.MISSED_CALL_NOTIFICATION) @@ -343,7 +406,8 @@ public class MissedCallNotifier implements Worker<Pair<Integer, String>, Void> { /** Trigger an intent to send an sms from a missed call number. */ public void sendSmsFromMissedCall(String number, Uri callUri) { closeSystemDialogs(context); - CallLogNotificationsQueryHelper.removeMissedCallNotifications(context, callUri); + CallLogNotificationsQueryHelper.markSingleMissedCallInCallLogAsRead(context, callUri); + cancelSingleMissedCallNotification(context, callUri); DialerUtils.startActivityWithErrorToast( context, IntentUtil.getSendSmsIntent(number).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } @@ -371,14 +435,6 @@ public class MissedCallNotifier implements Worker<Pair<Integer, String>, Void> { return PendingIntent.getActivity(context, 0, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT); } - /** Creates a pending intent that marks all new missed calls as old. */ - private PendingIntent createClearMissedCallsPendingIntent(@Nullable Uri callUri) { - Intent intent = new Intent(context, CallLogNotificationsService.class); - intent.setAction(CallLogNotificationsService.ACTION_MARK_NEW_MISSED_CALLS_AS_OLD); - intent.setData(callUri); - return PendingIntent.getService(context, 0, intent, 0); - } - private PendingIntent createCallBackPendingIntent(String number, @NonNull Uri callUri) { Intent intent = new Intent(context, CallLogNotificationsService.class); intent.setAction(CallLogNotificationsService.ACTION_CALL_BACK_FROM_MISSED_CALL_NOTIFICATION); diff --git a/java/com/android/dialer/app/calllog/PhoneAccountHandles.java b/java/com/android/dialer/app/calllog/PhoneAccountHandles.java deleted file mode 100644 index acffffb1d..000000000 --- a/java/com/android/dialer/app/calllog/PhoneAccountHandles.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.dialer.app.calllog; - -import android.content.ComponentName; -import android.content.Context; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.telecom.PhoneAccount; -import android.telecom.PhoneAccountHandle; -import com.android.dialer.app.calllog.CallLogNotificationsQueryHelper.NewCall; -import com.android.dialer.common.LogUtil; -import com.android.dialer.telecom.TelecomUtil; -import java.util.List; - -/** Methods to help extract {@link PhoneAccount} information from database and Telecomm sources. */ -class PhoneAccountHandles { - - @Nullable - public static PhoneAccountHandle getAccount(@NonNull Context context, @Nullable NewCall call) { - PhoneAccountHandle handle; - if (call == null || call.accountComponentName == null || call.accountId == null) { - LogUtil.v( - "PhoneAccountUtils.getAccount", - "accountComponentName == null || callToNotify.accountId == null"); - handle = TelecomUtil.getDefaultOutgoingPhoneAccount(context, PhoneAccount.SCHEME_TEL); - if (handle == null) { - List<PhoneAccountHandle> callCapablePhoneAccounts = - TelecomUtil.getCallCapablePhoneAccounts(context); - if (!callCapablePhoneAccounts.isEmpty()) { - return callCapablePhoneAccounts.get(0); - } - return null; - } - } else { - handle = - new PhoneAccountHandle( - ComponentName.unflattenFromString(call.accountComponentName), call.accountId); - } - if (handle.getComponentName() != null) { - LogUtil.v( - "PhoneAccountUtils.getAccount", - "PhoneAccountHandle.ComponentInfo:" + handle.getComponentName()); - } else { - LogUtil.i("PhoneAccountUtils.getAccount", "PhoneAccountHandle.ComponentInfo: null"); - } - return handle; - } -} diff --git a/java/com/android/dialer/app/calllog/VisualVoicemailNotifier.java b/java/com/android/dialer/app/calllog/VisualVoicemailNotifier.java new file mode 100644 index 000000000..99fe466d8 --- /dev/null +++ b/java/com/android/dialer/app/calllog/VisualVoicemailNotifier.java @@ -0,0 +1,291 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.dialer.app.calllog; + +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.graphics.Bitmap; +import android.net.Uri; +import android.os.Build.VERSION; +import android.os.Build.VERSION_CODES; +import android.service.notification.StatusBarNotification; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v4.os.BuildCompat; +import android.telecom.PhoneAccount; +import android.telecom.PhoneAccountHandle; +import android.telephony.TelephonyManager; +import android.text.TextUtils; +import com.android.contacts.common.util.ContactDisplayUtils; +import com.android.dialer.app.DialtactsActivity; +import com.android.dialer.app.R; +import com.android.dialer.app.calllog.CallLogNotificationsQueryHelper.NewCall; +import com.android.dialer.app.contactinfo.ContactPhotoLoader; +import com.android.dialer.app.list.DialtactsPagerAdapter; +import com.android.dialer.common.LogUtil; +import com.android.dialer.logging.DialerImpression; +import com.android.dialer.logging.Logger; +import com.android.dialer.notification.NotificationChannelManager; +import com.android.dialer.phonenumbercache.ContactInfo; +import com.android.dialer.telecom.TelecomUtil; +import java.util.List; +import java.util.Map; + +/** Shows a notification in the status bar for visual voicemail. */ +final class VisualVoicemailNotifier { + private static final String NOTIFICATION_TAG_PREFIX = "VisualVoicemail_"; + private static final String NOTIFICATION_GROUP = "VisualVoicemail"; + private static final int NOTIFICATION_ID = 1; + + public static void showNotifications( + @NonNull Context context, + @NonNull List<NewCall> newCalls, + @NonNull Map<String, ContactInfo> contactInfos, + @Nullable String callers) { + LogUtil.enterBlock("VisualVoicemailNotifier.showNotifications"); + PendingIntent deleteIntent = + CallLogNotificationsService.createMarkAllNewVoicemailsAsOldIntent(context); + String contentTitle = + context + .getResources() + .getQuantityString( + R.plurals.notification_voicemail_title, newCalls.size(), newCalls.size()); + Notification.Builder groupSummary = + createNotificationBuilder(context) + .setContentTitle(contentTitle) + .setContentText(callers) + .setDeleteIntent(deleteIntent) + .setGroupSummary(true) + .setContentIntent(newVoicemailIntent(context, null)); + + if (BuildCompat.isAtLeastO()) { + groupSummary.setGroupAlertBehavior(Notification.GROUP_ALERT_CHILDREN); + PhoneAccountHandle handle = getAccountForCall(context, newCalls.get(0)); + groupSummary.setChannelId(NotificationChannelManager.getVoicemailChannelId(context, handle)); + } + + NotificationManager notificationManager = context.getSystemService(NotificationManager.class); + notificationManager.notify( + getNotificationTagForGroupSummary(), NOTIFICATION_ID, groupSummary.build()); + + for (NewCall voicemail : newCalls) { + notificationManager.notify( + getNotificationTagForVoicemail(voicemail), + NOTIFICATION_ID, + createNotificationForVoicemail(context, voicemail, contactInfos)); + } + } + + public static void cancelAllVoicemailNotifications(@NonNull Context context) { + LogUtil.enterBlock("VisualVoicemailNotifier.cancelAllVoicemailNotifications"); + NotificationManager notificationManager = context.getSystemService(NotificationManager.class); + for (StatusBarNotification notification : notificationManager.getActiveNotifications()) { + String tag = notification.getTag(); + if (tag != null && tag.startsWith(NOTIFICATION_TAG_PREFIX)) { + notificationManager.cancel(tag, notification.getId()); + } + } + } + + public static void cancelSingleVoicemailNotification( + @NonNull Context context, @Nullable Uri voicemailUri) { + LogUtil.enterBlock("VisualVoicemailNotifier.cancelSingleVoicemailNotification"); + if (voicemailUri == null) { + LogUtil.e("VisualVoicemailNotifier.cancelSingleVoicemailNotification", "uri is null"); + return; + } + NotificationManager notificationManager = context.getSystemService(NotificationManager.class); + String voicemailTag = getNotificationTagForUri(voicemailUri); + String summaryTag = getNotificationTagForGroupSummary(); + int notificationCount = 0; + + for (StatusBarNotification notification : notificationManager.getActiveNotifications()) { + String currentTag = notification.getTag(); + if (currentTag == null) { + continue; + } + if (currentTag.equals(voicemailTag)) { + notificationManager.cancel(notification.getTag(), notification.getId()); + } else if (currentTag.startsWith(NOTIFICATION_TAG_PREFIX) && !currentTag.equals(summaryTag)) { + notificationCount++; + } + } + + if (notificationCount == 0) { + // There are no more visual voicemail notifications. Remove the summary notification too. + notificationManager.cancel(summaryTag, NOTIFICATION_ID); + } + } + + private static String getNotificationTagForVoicemail(@NonNull NewCall voicemail) { + return getNotificationTagForUri(voicemail.voicemailUri); + } + + private static String getNotificationTagForUri(@NonNull Uri voicemailUri) { + return NOTIFICATION_TAG_PREFIX + voicemailUri; + } + + private static String getNotificationTagForGroupSummary() { + return NOTIFICATION_TAG_PREFIX + "GroupSummary"; + } + + private static Notification.Builder createNotificationBuilder(@NonNull Context context) { + return new Notification.Builder(context) + .setSmallIcon(android.R.drawable.stat_notify_voicemail) + .setColor(context.getColor(R.color.dialer_theme_color)) + .setGroup(NOTIFICATION_GROUP) + .setOnlyAlertOnce(true) + .setAutoCancel(true); + } + + private static Notification createNotificationForVoicemail( + @NonNull Context context, + @NonNull NewCall voicemail, + @NonNull Map<String, ContactInfo> contactInfos) { + PhoneAccountHandle handle = getAccountForCall(context, voicemail); + ContactInfo contactInfo = contactInfos.get(voicemail.number); + + Notification.Builder builder = + createNotificationBuilder(context) + .setContentTitle( + context + .getResources() + .getQuantityString(R.plurals.notification_voicemail_title, 1, 1)) + .setContentText( + ContactDisplayUtils.getTtsSpannedPhoneNumber( + context.getResources(), + R.string.notification_new_voicemail_ticker, + contactInfo.name)) + .setWhen(voicemail.dateMs) + .setSound(getVoicemailRingtoneUri(context, handle)) + .setDefaults(getNotificationDefaultFlags(context, handle)); + + if (voicemail.voicemailUri != null) { + builder.setDeleteIntent( + CallLogNotificationsService.createMarkSingleNewVoicemailAsOldIntent( + context, voicemail.voicemailUri)); + } + + if (BuildCompat.isAtLeastO()) { + builder.setChannelId(NotificationChannelManager.getVoicemailChannelId(context, handle)); + } + + ContactPhotoLoader loader = new ContactPhotoLoader(context, contactInfo); + Bitmap photoIcon = loader.loadPhotoIcon(); + if (photoIcon != null) { + builder.setLargeIcon(photoIcon); + } + if (!TextUtils.isEmpty(voicemail.transcription)) { + Logger.get(context) + .logImpression(DialerImpression.Type.VVM_NOTIFICATION_CREATED_WITH_TRANSCRIPTION); + builder.setStyle(new Notification.BigTextStyle().bigText(voicemail.transcription)); + } + builder.setContentIntent(newVoicemailIntent(context, voicemail)); + Logger.get(context).logImpression(DialerImpression.Type.VVM_NOTIFICATION_CREATED); + return builder.build(); + } + + @Nullable + private static Uri getVoicemailRingtoneUri( + @NonNull Context context, @Nullable PhoneAccountHandle handle) { + if (VERSION.SDK_INT < VERSION_CODES.N) { + return null; + } + if (handle == null) { + LogUtil.i("VisualVoicemailNotifier.getVoicemailRingtoneUri", "null handle, getting fallback"); + handle = getFallbackAccount(context); + if (handle == null) { + LogUtil.i( + "VisualVoicemailNotifier.getVoicemailRingtoneUri", + "no fallback handle, using null (default) ringtone"); + return null; + } + } + return context.getSystemService(TelephonyManager.class).getVoicemailRingtoneUri(handle); + } + + private static int getNotificationDefaultFlags( + @NonNull Context context, @Nullable PhoneAccountHandle handle) { + if (VERSION.SDK_INT < VERSION_CODES.N) { + return Notification.DEFAULT_ALL; + } + if (handle == null) { + LogUtil.i( + "VisualVoicemailNotifier.getNotificationDefaultFlags", "null handle, getting fallback"); + handle = getFallbackAccount(context); + if (handle == null) { + LogUtil.i( + "VisualVoicemailNotifier.getNotificationDefaultFlags", + "no fallback handle, using default vibration"); + return Notification.DEFAULT_ALL; + } + } + if (context.getSystemService(TelephonyManager.class).isVoicemailVibrationEnabled(handle)) { + return Notification.DEFAULT_VIBRATE; + } + return 0; + } + + private static PendingIntent newVoicemailIntent( + @NonNull Context context, @Nullable NewCall voicemail) { + Intent intent = + DialtactsActivity.getShowTabIntent(context, DialtactsPagerAdapter.TAB_INDEX_VOICEMAIL); + // TODO (b/35486204): scroll to this voicemail + if (voicemail != null) { + intent.setData(voicemail.voicemailUri); + } + intent.putExtra(DialtactsActivity.EXTRA_CLEAR_NEW_VOICEMAILS, true); + return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); + } + + /** + * Gets a phone account for the given call entry. This could be null if SIM associated with the + * entry is no longer in the device or for other reasons (for example, modem reboot). + */ + @Nullable + public static PhoneAccountHandle getAccountForCall( + @NonNull Context context, @Nullable NewCall call) { + if (call == null || call.accountComponentName == null || call.accountId == null) { + return null; + } + return new PhoneAccountHandle( + ComponentName.unflattenFromString(call.accountComponentName), call.accountId); + } + + /** + * Gets any available phone account that can be used to get sound settings for voicemail. This is + * only called if the phone account for the voicemail entry can't be found. + */ + @Nullable + public static PhoneAccountHandle getFallbackAccount(@NonNull Context context) { + PhoneAccountHandle handle = + TelecomUtil.getDefaultOutgoingPhoneAccount(context, PhoneAccount.SCHEME_TEL); + if (handle == null) { + List<PhoneAccountHandle> handles = TelecomUtil.getCallCapablePhoneAccounts(context); + if (!handles.isEmpty()) { + handle = handles.get(0); + } + } + return handle; + } + + private VisualVoicemailNotifier() {} +} diff --git a/java/com/android/dialer/app/calllog/VisualVoicemailUpdateTask.java b/java/com/android/dialer/app/calllog/VisualVoicemailUpdateTask.java new file mode 100644 index 000000000..d6601be36 --- /dev/null +++ b/java/com/android/dialer/app/calllog/VisualVoicemailUpdateTask.java @@ -0,0 +1,168 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.dialer.app.calllog; + +import android.content.Context; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.annotation.WorkerThread; +import android.text.TextUtils; +import android.util.ArrayMap; +import com.android.dialer.app.R; +import com.android.dialer.app.calllog.CallLogNotificationsQueryHelper.NewCall; +import com.android.dialer.blocking.FilteredNumberAsyncQueryHandler; +import com.android.dialer.blocking.FilteredNumbersUtil; +import com.android.dialer.common.Assert; +import com.android.dialer.common.LogUtil; +import com.android.dialer.common.concurrent.DialerExecutor.Worker; +import com.android.dialer.common.concurrent.DialerExecutors; +import com.android.dialer.phonenumbercache.ContactInfo; +import com.android.dialer.telecom.TelecomUtil; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** Updates voicemail notifications in the background. */ +class VisualVoicemailUpdateTask implements Worker<VisualVoicemailUpdateTask.Input, Void> { + @Nullable + @Override + public Void doInBackground(@NonNull Input input) throws Throwable { + updateNotification(input.context, input.queryHelper, input.queryHandler); + return null; + } + + /** + * Updates the notification and notifies of the call with the given URI. + * + * <p>Clears the notification if there are no new voicemails, and notifies if the given URI + * corresponds to a new voicemail. + */ + @WorkerThread + private static void updateNotification( + Context context, + CallLogNotificationsQueryHelper queryHelper, + FilteredNumberAsyncQueryHandler queryHandler) { + Assert.isWorkerThread(); + + List<NewCall> newCalls = queryHelper.getNewVoicemails(); + if (newCalls == null) { + return; + } + newCalls = filterBlockedNumbers(context, queryHandler, newCalls); + if (newCalls.isEmpty()) { + return; + } + + // This represents a list of names to include in the notification. + String callers = null; + + // Maps each number into a name: if a number is in the map, it has already left a more + // recent voicemail. + Map<String, ContactInfo> contactInfos = new ArrayMap<>(); + for (NewCall newCall : newCalls) { + if (!contactInfos.containsKey(newCall.number)) { + ContactInfo contactInfo = + queryHelper.getContactInfo( + newCall.number, newCall.numberPresentation, newCall.countryIso); + contactInfos.put(newCall.number, contactInfo); + + // This is a new caller. Add it to the back of the list of callers. + if (TextUtils.isEmpty(callers)) { + callers = contactInfo.name; + } else { + callers = + context.getString( + R.string.notification_voicemail_callers_list, callers, contactInfo.name); + } + } + } + VisualVoicemailNotifier.showNotifications(context, newCalls, contactInfos, callers); + } + + @WorkerThread + private static List<NewCall> filterBlockedNumbers( + Context context, FilteredNumberAsyncQueryHandler queryHandler, List<NewCall> newCalls) { + Assert.isWorkerThread(); + if (FilteredNumbersUtil.hasRecentEmergencyCall(context)) { + LogUtil.i( + "VisualVoicemailUpdateTask.filterBlockedNumbers", + "not filtering due to recent emergency call"); + return newCalls; + } + + List<NewCall> result = new ArrayList<>(); + for (NewCall newCall : newCalls) { + if (queryHandler.getBlockedIdSynchronous(newCall.number, newCall.countryIso) != null) { + LogUtil.i( + "VisualVoicemailUpdateTask.filterBlockedNumbers", + "found voicemail from blocked number, deleting"); + if (newCall.voicemailUri != null) { + // Delete the voicemail. + CallLogAsyncTaskUtil.deleteVoicemailSynchronous(context, newCall.voicemailUri); + } + } else { + result.add(newCall); + } + } + return result; + } + + /** Updates the voicemail notifications displayed. */ + static void scheduleTask(@NonNull Context context, @NonNull Runnable callback) { + Assert.isNotNull(context); + Assert.isNotNull(callback); + if (!TelecomUtil.isDefaultDialer(context)) { + LogUtil.i("VisualVoicemailUpdateTask.scheduleTask", "not default dialer, not running"); + callback.run(); + return; + } + + Input input = + new Input( + context, + CallLogNotificationsQueryHelper.getInstance(context), + new FilteredNumberAsyncQueryHandler(context)); + DialerExecutors.createNonUiTaskBuilder(new VisualVoicemailUpdateTask()) + .onSuccess( + output -> { + LogUtil.i("VisualVoicemailUpdateTask.scheduleTask", "update successful"); + callback.run(); + }) + .onFailure( + throwable -> { + LogUtil.i("VisualVoicemailUpdateTask.scheduleTask", "update failed: " + throwable); + callback.run(); + }) + .build() + .executeParallel(input); + } + + static class Input { + @NonNull final Context context; + @NonNull final CallLogNotificationsQueryHelper queryHelper; + @NonNull final FilteredNumberAsyncQueryHandler queryHandler; + + Input( + Context context, + CallLogNotificationsQueryHelper queryHelper, + FilteredNumberAsyncQueryHandler queryHandler) { + this.context = context; + this.queryHelper = queryHelper; + this.queryHandler = queryHandler; + } + } +} diff --git a/java/com/android/dialer/app/calllog/VoicemailQueryHandler.java b/java/com/android/dialer/app/calllog/VoicemailQueryHandler.java index 777f4c79f..2fbebdd30 100644 --- a/java/com/android/dialer/app/calllog/VoicemailQueryHandler.java +++ b/java/com/android/dialer/app/calllog/VoicemailQueryHandler.java @@ -15,7 +15,6 @@ */ package com.android.dialer.app.calllog; -import android.app.NotificationManager; import android.content.AsyncQueryHandler; import android.content.ContentResolver; import android.content.ContentValues; @@ -23,30 +22,49 @@ import android.content.Context; import android.net.Uri; import android.provider.CallLog.Calls; import android.support.annotation.MainThread; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import com.android.dialer.app.R; +import android.support.annotation.WorkerThread; import com.android.dialer.common.Assert; -import com.android.dialer.notification.GroupedNotificationUtil; +import com.android.dialer.common.LogUtil; +import com.android.dialer.common.concurrent.ThreadUtil; /** Handles asynchronous queries to the call log for voicemail. */ public class VoicemailQueryHandler extends AsyncQueryHandler { - private static final String TAG = "VoicemailQueryHandler"; - /** The token for the query to mark all new voicemails as old. */ private static final int UPDATE_MARK_VOICEMAILS_AS_OLD_TOKEN = 50; - private Context mContext; - @MainThread - public VoicemailQueryHandler(Context context, ContentResolver contentResolver) { + private VoicemailQueryHandler(ContentResolver contentResolver) { super(contentResolver); Assert.isMainThread(); - mContext = context; + } + + @WorkerThread + public static void markAllNewVoicemailsAsRead(final @NonNull Context context) { + ThreadUtil.postOnUiThread( + () -> { + new VoicemailQueryHandler(context.getContentResolver()).markNewVoicemailsAsOld(null); + }); + } + + @WorkerThread + public static void markSingleNewVoicemailAsRead( + final @NonNull Context context, final Uri voicemailUri) { + if (voicemailUri == null) { + LogUtil.e("VoicemailQueryHandler.markSingleNewVoicemailAsRead", "voicemail URI is null"); + return; + } + ThreadUtil.postOnUiThread( + () -> { + new VoicemailQueryHandler(context.getContentResolver()) + .markNewVoicemailsAsOld(voicemailUri); + }); } /** Updates all new voicemails to mark them as old. */ - public void markNewVoicemailsAsOld(@Nullable Uri voicemailUri) { + private void markNewVoicemailsAsOld(@Nullable Uri voicemailUri) { // Mark all "new" voicemails as not new anymore. StringBuilder where = new StringBuilder(); where.append(Calls.NEW); @@ -70,11 +88,5 @@ public class VoicemailQueryHandler extends AsyncQueryHandler { voicemailUri == null ? new String[] {Integer.toString(Calls.VOICEMAIL_TYPE)} : new String[] {Integer.toString(Calls.VOICEMAIL_TYPE), voicemailUri.toString()}); - - GroupedNotificationUtil.removeNotification( - mContext.getSystemService(NotificationManager.class), - voicemailUri != null ? voicemailUri.toString() : null, - R.id.notification_visual_voicemail, - DefaultVoicemailNotifier.VISUAL_VOICEMAIL_NOTIFICATION_TAG); } } diff --git a/java/com/android/dialer/app/calllog/calllogcache/CallLogCache.java b/java/com/android/dialer/app/calllog/calllogcache/CallLogCache.java index 7645a333e..6728dfb38 100644 --- a/java/com/android/dialer/app/calllog/calllogcache/CallLogCache.java +++ b/java/com/android/dialer/app/calllog/calllogcache/CallLogCache.java @@ -19,7 +19,6 @@ package com.android.dialer.app.calllog.calllogcache; import android.content.Context; import android.telecom.PhoneAccountHandle; import com.android.dialer.app.calllog.CallLogAdapter; -import com.android.dialer.compat.CompatUtils; import com.android.dialer.util.CallUtil; /** @@ -46,10 +45,7 @@ public abstract class CallLogCache { /** Return the most compatible version of the TelecomCallLogCache. */ public static CallLogCache getCallLogCache(Context context) { - if (CompatUtils.isClassAvailable("android.telecom.PhoneAccountHandle")) { - return new CallLogCacheLollipopMr1(context); - } - return new CallLogCacheLollipop(context); + return new CallLogCacheLollipopMr1(context); } public void reset() { diff --git a/java/com/android/dialer/app/calllog/calllogcache/CallLogCacheLollipop.java b/java/com/android/dialer/app/calllog/calllogcache/CallLogCacheLollipop.java deleted file mode 100644 index 78aaa4193..000000000 --- a/java/com/android/dialer/app/calllog/calllogcache/CallLogCacheLollipop.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2015 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -package com.android.dialer.app.calllog.calllogcache; - -import android.content.Context; -import android.telecom.PhoneAccount; -import android.telecom.PhoneAccountHandle; -import android.telephony.PhoneNumberUtils; -import android.text.TextUtils; - -/** - * This is a compatibility class for the CallLogCache for versions of dialer before Lollipop Mr1 - * (the introduction of phone accounts). - * - * <p>This class should not be initialized directly and instead be acquired from {@link - * CallLogCache#getCallLogCache}. - */ -class CallLogCacheLollipop extends CallLogCache { - - private String mVoicemailNumber; - - /* package */ CallLogCacheLollipop(Context context) { - super(context); - } - - @Override - public boolean isVoicemailNumber(PhoneAccountHandle accountHandle, CharSequence number) { - if (TextUtils.isEmpty(number)) { - return false; - } - - String numberString = number.toString(); - - if (!TextUtils.isEmpty(mVoicemailNumber)) { - return PhoneNumberUtils.compare(numberString, mVoicemailNumber); - } - - if (PhoneNumberUtils.isVoiceMailNumber(numberString)) { - mVoicemailNumber = numberString; - return true; - } - - return false; - } - - @Override - public String getAccountLabel(PhoneAccountHandle accountHandle) { - return null; - } - - @Override - public int getAccountColor(PhoneAccountHandle accountHandle) { - return PhoneAccount.NO_HIGHLIGHT_COLOR; - } - - @Override - public boolean doesAccountSupportCallSubject(PhoneAccountHandle accountHandle) { - return false; - } -} diff --git a/java/com/android/dialer/app/calllog/calllogcache/CallLogCacheLollipopMr1.java b/java/com/android/dialer/app/calllog/calllogcache/CallLogCacheLollipopMr1.java index 039998780..f85680649 100644 --- a/java/com/android/dialer/app/calllog/calllogcache/CallLogCacheLollipopMr1.java +++ b/java/com/android/dialer/app/calllog/calllogcache/CallLogCacheLollipopMr1.java @@ -17,15 +17,11 @@ package com.android.dialer.app.calllog.calllogcache; import android.content.Context; -import android.support.annotation.VisibleForTesting; import android.telecom.PhoneAccountHandle; -import android.text.TextUtils; import android.util.ArrayMap; -import android.util.Pair; import com.android.dialer.calllogutils.PhoneAccountUtils; -import com.android.dialer.phonenumberutil.PhoneNumberHelper; +import com.android.dialer.telecom.TelecomUtil; import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; /** * This is the CallLogCache for versions of dialer Lollipop Mr1 and above with support for multi-SIM @@ -36,15 +32,6 @@ import java.util.concurrent.ConcurrentHashMap; */ class CallLogCacheLollipopMr1 extends CallLogCache { - /* - * Maps from a phone-account/number pair to a boolean because multiple numbers could return true - * for the voicemail number if those numbers are not pre-normalized. Access must be synchronzied - * as it's used in the background thread in CallLogAdapter. {@see CallLogAdapter#loadData} - */ - @VisibleForTesting - final Map<Pair<PhoneAccountHandle, CharSequence>, Boolean> mVoicemailQueryCache = - new ConcurrentHashMap<>(); - private final Map<PhoneAccountHandle, String> mPhoneAccountLabelCache = new ArrayMap<>(); private final Map<PhoneAccountHandle, Integer> mPhoneAccountColorCache = new ArrayMap<>(); private final Map<PhoneAccountHandle, Boolean> mPhoneAccountCallWithNoteCache = new ArrayMap<>(); @@ -55,7 +42,6 @@ class CallLogCacheLollipopMr1 extends CallLogCache { @Override public void reset() { - mVoicemailQueryCache.clear(); mPhoneAccountLabelCache.clear(); mPhoneAccountColorCache.clear(); mPhoneAccountCallWithNoteCache.clear(); @@ -65,19 +51,7 @@ class CallLogCacheLollipopMr1 extends CallLogCache { @Override public boolean isVoicemailNumber(PhoneAccountHandle accountHandle, CharSequence number) { - if (TextUtils.isEmpty(number)) { - return false; - } - - Pair<PhoneAccountHandle, CharSequence> key = new Pair<>(accountHandle, number); - Boolean value = mVoicemailQueryCache.get(key); - if (value != null) { - return value; - } - boolean isVoicemail = - PhoneNumberHelper.isVoicemailNumber(mContext, accountHandle, number.toString()); - mVoicemailQueryCache.put(key, isVoicemail); - return isVoicemail; + return TelecomUtil.isVoicemailNumber(mContext, accountHandle, number.toString()); } @Override |