/*
* 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.blocking;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.os.AsyncTask;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Contacts;
import android.provider.Settings;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
import android.support.v4.os.BuildCompat;
import android.support.v4.os.UserManagerCompat;
import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;
import android.widget.Toast;
import com.android.dialer.blocking.FilteredNumberAsyncQueryHandler.OnHasBlockedNumbersListener;
import com.android.dialer.common.LogUtil;
import com.android.dialer.logging.InteractionEvent;
import com.android.dialer.logging.Logger;
import com.android.dialer.notification.DialerNotificationManager;
import com.android.dialer.notification.NotificationChannelId;
import com.android.dialer.storage.StorageComponent;
import com.android.dialer.util.PermissionsUtil;
import java.util.concurrent.TimeUnit;
/** Utility to help with tasks related to filtered numbers. */
public class FilteredNumbersUtil {
public static final String CALL_BLOCKING_NOTIFICATION_TAG = "call_blocking";
public static final int CALL_BLOCKING_DISABLED_BY_EMERGENCY_CALL_NOTIFICATION_ID = 10;
// Pref key for storing the time of end of the last emergency call in milliseconds after epoch.\
@VisibleForTesting
public static final String LAST_EMERGENCY_CALL_MS_PREF_KEY = "last_emergency_call_ms";
// Pref key for storing whether a notification has been dispatched to notify the user that call
// blocking has been disabled because of a recent emergency call.
protected static final String NOTIFIED_CALL_BLOCKING_DISABLED_BY_EMERGENCY_CALL_PREF_KEY =
"notified_call_blocking_disabled_by_emergency_call";
// Disable incoming call blocking if there was a call within the past 2 days.
static final long RECENT_EMERGENCY_CALL_THRESHOLD_MS = TimeUnit.DAYS.toMillis(2);
/**
* Used for testing to specify the custom threshold value, in milliseconds for whether an
* emergency call is "recent". The default value will be used if this custom threshold is less
* than zero. For example, to set this threshold to 60 seconds:
*
*
adb shell settings put system dialer_emergency_call_threshold_ms 60000
*/
private static final String RECENT_EMERGENCY_CALL_THRESHOLD_SETTINGS_KEY =
"dialer_emergency_call_threshold_ms";
/** Checks if there exists a contact with {@code Contacts.SEND_TO_VOICEMAIL} set to true. */
public static void checkForSendToVoicemailContact(
final Context context, final CheckForSendToVoicemailContactListener listener) {
final AsyncTask task =
new AsyncTask