diff options
Diffstat (limited to 'src/com/android/dialer/calllog/ContactInfoHelper.java')
-rw-r--r-- | src/com/android/dialer/calllog/ContactInfoHelper.java | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/com/android/dialer/calllog/ContactInfoHelper.java b/src/com/android/dialer/calllog/ContactInfoHelper.java index 68654f28c..3274a9df5 100644 --- a/src/com/android/dialer/calllog/ContactInfoHelper.java +++ b/src/com/android/dialer/calllog/ContactInfoHelper.java @@ -15,6 +15,7 @@ package com.android.dialer.calllog; import android.content.ContentUris; +import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.net.Uri; @@ -24,13 +25,17 @@ import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.DisplayNameSources; import android.provider.ContactsContract.PhoneLookup; import android.provider.ContactsContract.RawContacts; +import android.provider.Settings; +import android.provider.Telephony; import android.telephony.PhoneNumberUtils; import android.text.TextUtils; +import android.widget.Toast; import com.android.contacts.common.util.Constants; import com.android.contacts.common.util.PhoneNumberHelper; import com.android.contacts.common.util.UriUtils; import com.android.dialer.lookup.LookupCache; +import com.android.dialer.R; import com.android.dialer.service.CachedNumberLookupService; import com.android.dialer.service.CachedNumberLookupService.CachedContactInfo; import com.android.dialerbind.ObjectFactory; @@ -324,7 +329,34 @@ public class ContactInfoHelper { public boolean canReportAsInvalid(int sourceType, String objectId) { return mCachedNumberLookupService != null && mCachedNumberLookupService.canReportAsInvalid(sourceType, objectId); + } + + /** + * Checks whether calls can be blacklisted; that is, whether the + * phone blacklist is enabled + */ + public boolean canBlacklistCalls() { + return Settings.System.getInt(mContext.getContentResolver(), + Settings.System.PHONE_BLACKLIST_ENABLED, 1) != 0; } + /** + * Requests the given number to be added to the phone blacklist + * + * @param number the number to be blacklisted + */ + public void addNumberToBlacklist(String number) { + 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(); + } + } } |