Always hide blocked calls.

- Remove setting for show/hide.
- Remove utilities and behaviors for show/hide.
~ Continue filtering blocked call types in call log (which may be
marked by other applications.)
~ Change behavior after blocking call; instead of keeping the call
log entry but changing the type to BLOCKED, delete it instead.
+ Default behavior is now to delete entries and visual voicemails of
blocked calls.

Bug: 25378068
Bug: 25106387
Change-Id: I8cbc419b25cce6ba39099857cffe4eb1df9d0bef
diff --git a/res/layout/blocked_number_header.xml b/res/layout/blocked_number_header.xml
index 29a05bd..bbb9c10 100644
--- a/res/layout/blocked_number_header.xml
+++ b/res/layout/blocked_number_header.xml
@@ -45,41 +45,6 @@
 
     </LinearLayout>
 
-
-    <android.support.v7.widget.CardView
-        android:id="@+id/hide_blocked_calls_setting"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:layout_marginBottom="8dp"
-        card_view:cardCornerRadius="0dp">
-
-        <LinearLayout
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:orientation="horizontal"
-            android:gravity="center_vertical"
-            android:padding="16dp"
-            android:paddingEnd="8dp"
-            android:background="@android:color/white"
-            android:focusable="true">
-
-            <TextView
-                android:layout_width="0dp"
-                android:layout_height="wrap_content"
-                android:layout_weight="1"
-                android:text="@string/blocked_call_settings_hide_setting"
-                style="@style/BlockedNumbersDescriptionTextStyle" />
-
-            <Switch android:id="@+id/hide_blocked_calls_switch"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_marginLeft="40dp"
-                android:focusable="false" />
-
-        </LinearLayout>
-
-    </android.support.v7.widget.CardView>
-
     <android.support.v7.widget.CardView
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index f74d2ea..773626f 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -855,12 +855,6 @@
         You previously marked some callers to be automatically sent to voicemail via other apps.
     </string>
 
-    <!-- Text for a setting to hide blocked calls and automatically delete new voicemail from block
-         numbers. [CHAR LIMIT=NONE] -->
-    <string name="blocked_call_settings_hide_setting">
-        Hide calls and automatically delete new voicemails from blocked numbers.
-    </string>
-
     <!-- Label for button to view numbers of contacts previous marked to be sent to voicemail.
          [CHAR_LIMIT=20] -->
     <string name="blocked_call_settings_view_numbers_button">View Numbers</string>
diff --git a/src/com/android/dialer/calllog/CallLogAsyncTaskUtil.java b/src/com/android/dialer/calllog/CallLogAsyncTaskUtil.java
index 2fffaff..7771563 100644
--- a/src/com/android/dialer/calllog/CallLogAsyncTaskUtil.java
+++ b/src/com/android/dialer/calllog/CallLogAsyncTaskUtil.java
@@ -46,7 +46,7 @@
     public enum Tasks {
         DELETE_VOICEMAIL,
         DELETE_CALL,
-        MARK_BLOCKED,
+        DELETE_BLOCKED_CALL,
         MARK_VOICEMAIL_READ,
         GET_CALL_DETAILS,
     }
@@ -81,7 +81,7 @@
         static final int TRANSCRIPTION_COLUMN_INDEX = 11;
     }
 
-    private static class CallLogMarkBlockedQuery {
+    private static class CallLogDeleteBlockedCallQuery {
         static final String[] PROJECTION = new String[] {
             CallLog.Calls._ID,
             CallLog.Calls.DATE
@@ -104,7 +104,7 @@
     // Try to identify if a call log entry corresponds to a number which was blocked. We match by
     // by comparing its creation time to the time it was added in the InCallUi and seeing if they
     // fall within a certain threshold.
-    private static final int MATCH_BLOCKED_CALL_THRESHOLD_MS = 1500;
+    private static final int MATCH_BLOCKED_CALL_THRESHOLD_MS = 3000;
 
     private static AsyncTaskExecutor sAsyncTaskExecutor;
 
@@ -256,15 +256,16 @@
     }
 
     /**
-     * Marks last call made by the number the call type of the specified call as BLOCKED in the call log.
+     * Deletes the last call made by the number within a threshold of the call time added in the
+     * call log, assuming it is a blocked call for which no entry should be shown.
      *
      * @param context The context.
-     * @param number Number of which to mark the most recent call as BLOCKED.
+     * @param number Number of blocked call, for which to delete the call log entry.
      * @param timeAddedMs The time the number was added to InCall, in milliseconds.
      * @param listener The listener to invoke after looking up for a call log entry matching the
      *     number and time added.
      */
-    public static void markCallAsBlocked(
+    public static void deleteBlockedCall(
             final Context context,
             final String number,
             final long timeAddedMs,
@@ -273,23 +274,30 @@
             initTaskExecutor();
         }
 
-        sAsyncTaskExecutor.submit(Tasks.MARK_BLOCKED, new AsyncTask<Void, Void, Long>() {
+        sAsyncTaskExecutor.submit(Tasks.DELETE_BLOCKED_CALL, new AsyncTask<Void, Void, Long>() {
             @Override
             public Long doInBackground(Void... params) {
                 // First, lookup the call log entry of the most recent call with this number.
                 Cursor cursor = context.getContentResolver().query(
                         TelecomUtil.getCallLogUri(context),
-                        CallLogMarkBlockedQuery.PROJECTION,
+                        CallLogDeleteBlockedCallQuery.PROJECTION,
                         CallLog.Calls.NUMBER + "= ?",
                         new String[] { number },
                         CallLog.Calls.DATE + " DESC LIMIT 1");
 
-                // If found, return the call log entry id.
+                // If match is found, delete this call log entry and return the call log entry id.
                 if (cursor.moveToFirst()) {
-                    long creationTime = cursor.getLong(CallLogMarkBlockedQuery.DATE_COLUMN_INDEX);
+                    long creationTime =
+                            cursor.getLong(CallLogDeleteBlockedCallQuery.DATE_COLUMN_INDEX);
                     if (timeAddedMs > creationTime
                             && timeAddedMs - creationTime < MATCH_BLOCKED_CALL_THRESHOLD_MS) {
-                        return cursor.getLong(CallLogMarkBlockedQuery.ID_COLUMN_INDEX);
+                        long callLogEntryId =
+                                cursor.getLong(CallLogDeleteBlockedCallQuery.ID_COLUMN_INDEX);
+                        context.getContentResolver().delete(
+                                TelecomUtil.getCallLogUri(context),
+                                CallLog.Calls._ID + " IN (" + callLogEntryId + ")",
+                                null);
+                        return callLogEntryId;
                     }
                 }
                 return (long) -1;
@@ -300,20 +308,6 @@
                 if (listener != null) {
                     listener.onQueryFinished(callLogEntryId >= 0);
                 }
-
-                if (callLogEntryId < 0) {
-                    return;
-                }
-
-                // Then, update that call log entry to have type BLOCKED.
-                final ContentValues values = new ContentValues();
-                values.put(CallLog.Calls.TYPE, AppCompatConstants.CALLS_BLOCKED_TYPE);
-
-                context.getContentResolver().update(
-                        TelecomUtil.getCallLogUri(context),
-                        values,
-                        CallLog.Calls._ID + "= ?",
-                        new String[] { Long.toString(callLogEntryId) });
             }
         });
     }
diff --git a/src/com/android/dialer/calllog/CallLogFragment.java b/src/com/android/dialer/calllog/CallLogFragment.java
index f84ffd5..3cf58bd 100644
--- a/src/com/android/dialer/calllog/CallLogFragment.java
+++ b/src/com/android/dialer/calllog/CallLogFragment.java
@@ -125,7 +125,6 @@
     private boolean mRefreshDataRequired = true;
 
     private boolean mHasReadCallLogPermission = false;
-    private boolean mShouldHideBlockedCalls = false;
 
     // Exactly same variable is in Fragment as a package private.
     private boolean mMenuVisible = true;
@@ -211,8 +210,6 @@
         resolver.registerContentObserver(Status.CONTENT_URI, true, mVoicemailStatusObserver);
         setHasOptionsMenu(true);
 
-        mShouldHideBlockedCalls = FilteredNumbersUtil.shouldHideBlockedCalls(getActivity());
-
         if (mCallTypeFilter == Calls.VOICEMAIL_TYPE) {
             mVoicemailPlaybackPresenter = VoicemailPlaybackPresenter
                     .getInstance(activity, state);
@@ -342,10 +339,6 @@
             mRefreshDataRequired = true;
             updateEmptyMessage(mCallTypeFilter);
         }
-        if (mShouldHideBlockedCalls != FilteredNumbersUtil.shouldHideBlockedCalls(getActivity())) {
-            mShouldHideBlockedCalls = !mShouldHideBlockedCalls;
-            mRefreshDataRequired = true;
-        }
 
         mHasReadCallLogPermission = hasReadCallLogPermission;
         refreshData();
diff --git a/src/com/android/dialer/calllog/CallLogQueryHandler.java b/src/com/android/dialer/calllog/CallLogQueryHandler.java
index 01489c1..3efdce7 100644
--- a/src/com/android/dialer/calllog/CallLogQueryHandler.java
+++ b/src/com/android/dialer/calllog/CallLogQueryHandler.java
@@ -191,13 +191,10 @@
             selectionArgs.add(Long.toString(newerThan));
         }
 
-        final boolean shouldHideBlockedCalls =
-                FilteredNumbersUtil.shouldHideBlockedCalls(mContext);
-        if (shouldHideBlockedCalls) {
-            where.append(" AND ");
-            where.append("(" + Calls.TYPE + " != ?)");
-            selectionArgs.add(Integer.toString(AppCompatConstants.CALLS_BLOCKED_TYPE));
-        }
+        // Always hide blocked calls.
+        where.append(" AND ");
+        where.append("(" + Calls.TYPE + " != ?)");
+        selectionArgs.add(Integer.toString(AppCompatConstants.CALLS_BLOCKED_TYPE));
 
         final int limit = (mLogLimit == -1) ? NUM_LOGS_TO_DISPLAY : mLogLimit;
         final String selection = where.length() > 0 ? where.toString() : null;
diff --git a/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java b/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java
index 1987b80..635e874 100644
--- a/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java
+++ b/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java
@@ -135,9 +135,8 @@
                     mContext, newCall.number, newCall.countryIso, newCall.dateMs)) {
                 itr.remove();
 
-                if (FilteredNumbersUtil.shouldHideBlockedCalls(mContext)) {
-                    mContext.getContentResolver().delete(newCall.voicemailUri, null, null);
-                }
+                // Delete the voicemail.
+                mContext.getContentResolver().delete(newCall.voicemailUri, null, null);
                 continue;
             }
 
diff --git a/src/com/android/dialer/filterednumber/BlockedNumbersFragment.java b/src/com/android/dialer/filterednumber/BlockedNumbersFragment.java
index 853076c..b7b2639 100644
--- a/src/com/android/dialer/filterednumber/BlockedNumbersFragment.java
+++ b/src/com/android/dialer/filterednumber/BlockedNumbersFragment.java
@@ -36,7 +36,6 @@
 import android.widget.Switch;
 
 import com.android.dialer.R;
-import com.android.dialer.calllog.CallLogQueryHandler;
 import com.android.dialer.database.FilteredNumberContract;
 import com.android.dialer.filterednumber.FilteredNumbersUtil.CheckForSendToVoicemailContactListener;
 import com.android.dialer.filterednumber.FilteredNumbersUtil.ImportSendToVoicemailContactsListener;
@@ -44,14 +43,11 @@
 import com.android.dialer.voicemail.VoicemailStatusHelperImpl;
 
 public class BlockedNumbersFragment extends ListFragment
-        implements LoaderManager.LoaderCallbacks<Cursor>, View.OnClickListener,
-                CallLogQueryHandler.Listener {
+        implements LoaderManager.LoaderCallbacks<Cursor>, View.OnClickListener {
 
     private BlockedNumbersAdapter mAdapter;
-    private CallLogQueryHandler mCallLogQueryHandler;
     private VoicemailStatusHelper mVoicemailStatusHelper;
 
-    private Switch mHideSettingSwitch;
     private View mImportSettings;
     private View mBlockedNumbersDisabledForEmergency;
 
@@ -69,25 +65,8 @@
         }
         setListAdapter(mAdapter);
 
-        mCallLogQueryHandler
-                = new CallLogQueryHandler(getContext(), getContext().getContentResolver(), this);
         mVoicemailStatusHelper = new VoicemailStatusHelperImpl();
 
-        mHideSettingSwitch = (Switch) getActivity().findViewById(R.id.hide_blocked_calls_switch);
-        mHideSettingSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
-            @Override
-            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
-                FilteredNumbersUtil.setShouldHideBlockedCalls(getActivity(), isChecked);
-            }
-        });
-        getActivity().findViewById(R.id.hide_blocked_calls_setting).setOnClickListener(
-                new View.OnClickListener() {
-                    @Override
-                    public void onClick(final View view) {
-                        mHideSettingSwitch.toggle();
-                    }
-                });
-
         mImportSettings = getActivity().findViewById(R.id.import_settings);
         mBlockedNumbersDisabledForEmergency =
                 getActivity().findViewById(R.id.blocked_numbers_disabled_for_emergency);
@@ -132,9 +111,6 @@
                     }
                 });
 
-        mHideSettingSwitch.setChecked(FilteredNumbersUtil.shouldHideBlockedCalls(getContext()));
-        mCallLogQueryHandler.fetchVoicemailStatus();
-
         if (FilteredNumbersUtil.hasRecentEmergencyCall(getContext())) {
             mBlockedNumbersDisabledForEmergency.setVisibility(View.VISIBLE);
         } else {
@@ -199,37 +175,4 @@
                 break;
         }
     }
-
-    @Override
-    public void onVoicemailStatusFetched(Cursor cursor) {
-        Activity activity = getActivity();
-        if (activity == null) {
-            return;
-        }
-
-        final View hideSetting = activity.findViewById(R.id.hide_blocked_calls_setting);
-        if (cursor == null) {
-            hideSetting.setVisibility(View.GONE);
-            return;
-        }
-
-        final boolean hasVisualVoicemailSource =
-                mVoicemailStatusHelper.getNumberActivityVoicemailSources(cursor) > 0;
-        if (hasVisualVoicemailSource) {
-            hideSetting.setVisibility(View.VISIBLE);
-        } else {
-            hideSetting.setVisibility(View.GONE);
-        }
-    }
-
-    @Override
-    public void onVoicemailUnreadCountFetched(Cursor cursor) {
-        // Do nothing.
-    }
-
-    @Override
-    public boolean onCallsFetched(Cursor cursor) {
-        // Do nothing.
-        return false;
-    }
 }
diff --git a/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java b/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java
index 8a0d792..ddb70de 100644
--- a/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java
+++ b/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java
@@ -52,7 +52,6 @@
     // Disable incoming call blocking if there was a call within the past 2 days.
     private static final long RECENT_EMERGENCY_CALL_THRESHOLD_MS = 1000 * 60 * 60 * 24 * 2;
 
-    private static final String HIDE_BLOCKED_CALLS_PREF_KEY = "hide_blocked_calls";
     // Pref key for storing the time of end of the last emergency call in milliseconds after epoch.
     private static final String LAST_EMERGENCY_CALL_MS_PREF_KEY = "last_emergency_call_ms";
 
@@ -265,24 +264,6 @@
         return shouldBlock;
     }
 
-    public static boolean shouldHideBlockedCalls(Context context) {
-        if (context == null) {
-            return false;
-        }
-        return PreferenceManager.getDefaultSharedPreferences(context)
-                .getBoolean(HIDE_BLOCKED_CALLS_PREF_KEY, false);
-    }
-
-    public static void setShouldHideBlockedCalls(Context context, boolean shouldHide) {
-        if (context == null) {
-            return;
-        }
-        PreferenceManager.getDefaultSharedPreferences(context)
-                .edit()
-                .putBoolean(HIDE_BLOCKED_CALLS_PREF_KEY, shouldHide)
-                .apply();
-    }
-
     public static boolean hasRecentEmergencyCall(Context context) {
         if (context == null) {
             return false;