Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 50e5307b authored by Danny Baumann's avatar Danny Baumann
Browse files

Store phone blacklist in content provider (3/4)

Change-Id: I7b42e872b1ccaba7eff6f6c4903e8a3612aa8375
parent bb9d22dd
Loading
Loading
Loading
Loading
+12 −10
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.contacts.calllog;

import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
@@ -23,6 +24,7 @@ import android.net.Uri;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.PhoneLookup;
import android.provider.Settings;
import android.provider.Telephony;
import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;
import android.widget.Toast;
@@ -37,10 +39,6 @@ public class ContactInfoHelper {
    private final Context mContext;
    private final String mCurrentCountryIso;

    // Blacklist support
    private static final String INSERT_BLACKLIST = "com.android.phone.INSERT_BLACKLIST";
    private static final String BLACKLIST_NUMBER = "number";

    public ContactInfoHelper(Context context, String currentCountryIso) {
        mContext = context;
        mCurrentCountryIso = currentCountryIso;
@@ -227,14 +225,18 @@ public class ContactInfoHelper {
     * @param number the number to be blacklisted
     */
    public void addNumberToBlacklist(String number) {
                Intent intent = new Intent(INSERT_BLACKLIST);
        intent.putExtra(BLACKLIST_NUMBER, number);
        mContext.sendBroadcast(intent);
        ContentValues cv = new ContentValues();
        cv.put(Telephony.Blacklist.PHONE_MODE, 1);

        Uri uri = Uri.withAppendedPath(Telephony.Blacklist.CONTENT_FILTER_BYNUMBER_URI, number);
        int count = mContext.getContentResolver().update(uri, cv, null, null);

        if (count != 0) {
            // Give the user some feedback
            String message = mContext.getString(R.string.toast_added_to_blacklist, number);
            Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();
        }
    }

    /**
     * Checks whether calls can be blacklisted; that is, whether the