Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ LOCAL_SRC_FILES := $(call all-java-files-under, src/java) \
$(call all-Iaidl-files-under, src/java) \
$(call all-logtags-files-under, src/java)

ifneq ($(BOARD_RIL_CLASS),)
LOCAL_SRC_FILES += $(call find-other-java-files,$(BOARD_RIL_CLASS))
endif

LOCAL_JAVA_LIBRARIES := voip-common ims-common
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := telephony-common
Expand Down
181 changes: 181 additions & 0 deletions src/java/com/android/internal/telephony/BlacklistUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/*
* Copyright (C) 2013 The CyanogenMod 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.internal.telephony.util;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.UserHandle;
import android.provider.Settings;
import android.provider.Telephony.Blacklist;
import android.text.TextUtils;
import android.util.Log;

import java.util.ArrayList;
import java.util.List;

import com.android.internal.telephony.CallerInfo;

/**
* Blacklist Utility Class
* @hide
*/
public class BlacklistUtils {
private static final String TAG = "BlacklistUtils";
private static final boolean DEBUG = false;

// Blacklist matching type
public final static int MATCH_NONE = 0;
public final static int MATCH_PRIVATE = 1;
public final static int MATCH_UNKNOWN = 2;
public final static int MATCH_LIST = 3;
public final static int MATCH_REGEX = 4;

public final static int BLOCK_CALLS =
Settings.System.BLACKLIST_BLOCK << Settings.System.BLACKLIST_PHONE_SHIFT;
public final static int BLOCK_MESSAGES =
Settings.System.BLACKLIST_BLOCK << Settings.System.BLACKLIST_MESSAGE_SHIFT;

public static boolean addOrUpdate(Context context, String number, int flags, int valid) {
ContentValues cv = new ContentValues();

if ((valid & BLOCK_CALLS) != 0) {
cv.put(Blacklist.PHONE_MODE, (flags & BLOCK_CALLS) != 0 ? 1 : 0);
}
if ((valid & BLOCK_MESSAGES) != 0) {
cv.put(Blacklist.MESSAGE_MODE, (flags & BLOCK_MESSAGES) != 0 ? 1 : 0);
}

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

return count > 0;
}

/**
* Check if the number is in the blacklist
* @param number: Number to check
* @return one of: MATCH_NONE, MATCH_PRIVATE, MATCH_UNKNOWN, MATCH_LIST or MATCH_REGEX
*/
public static int isListed(Context context, String number, int mode) {
if (!isBlacklistEnabled(context)) {
return MATCH_NONE;
}

if (DEBUG) {
Log.d(TAG, "Checking number " + number + " against the Blacklist for mode " + mode);
}

final String type;

if (mode == BLOCK_CALLS) {
if (DEBUG) Log.d(TAG, "Checking if an incoming call should be blocked");
type = Blacklist.PHONE_MODE;
} else if (mode == BLOCK_MESSAGES) {
if (DEBUG) Log.d(TAG, "Checking if an incoming message should be blocked");
type = Blacklist.MESSAGE_MODE;
} else {
Log.e(TAG, "Invalid mode " + mode);
return MATCH_NONE;
}

// Private and unknown number matching
if (TextUtils.isEmpty(number)) {
if (isBlacklistPrivateNumberEnabled(context, mode)) {
return MATCH_PRIVATE;
}
return MATCH_NONE;
}

if (isBlacklistUnknownNumberEnabled(context, mode)) {
CallerInfo ci = CallerInfo.getCallerInfo(context, number);
if (!ci.contactExists) {
return MATCH_UNKNOWN;
}
}

Uri.Builder builder = Blacklist.CONTENT_FILTER_BYNUMBER_URI.buildUpon();
builder.appendPath(number);
if (isBlacklistRegexEnabled(context)) {
builder.appendQueryParameter(Blacklist.REGEX_KEY, "1");
}

int result = MATCH_NONE;
Cursor c = context.getContentResolver().query(builder.build(),
new String[] { Blacklist.IS_REGEX, type }, null, null, null);

if (c != null) {
if (DEBUG) Log.d(TAG, "Blacklist query successful, " + c.getCount() + " matches");
int regexColumnIndex = c.getColumnIndexOrThrow(Blacklist.IS_REGEX);
int modeColumnIndex = c.getColumnIndexOrThrow(type);
boolean whitelisted = false;

c.moveToPosition(-1);
while (c.moveToNext()) {
boolean isRegex = c.getInt(regexColumnIndex) != 0;
boolean blocked = c.getInt(modeColumnIndex) != 0;

if (!isRegex) {
whitelisted = !blocked;
result = MATCH_LIST;
if (blocked) {
break;
}
} else if (blocked) {
result = MATCH_REGEX;
}
}
if (whitelisted) {
result = MATCH_NONE;
}
c.close();
}

return result;
}

public static boolean isBlacklistEnabled(Context context) {
return Settings.System.getIntForUser(context.getContentResolver(),
Settings.System.PHONE_BLACKLIST_ENABLED, 1,
UserHandle.USER_CURRENT_OR_SELF) != 0;
}

public static boolean isBlacklistNotifyEnabled(Context context) {
return Settings.System.getIntForUser(context.getContentResolver(),
Settings.System.PHONE_BLACKLIST_NOTIFY_ENABLED, 1,
UserHandle.USER_CURRENT_OR_SELF) != 0;
}

public static boolean isBlacklistPrivateNumberEnabled(Context context, int mode) {
return (Settings.System.getIntForUser(context.getContentResolver(),
Settings.System.PHONE_BLACKLIST_PRIVATE_NUMBER_MODE, 0,
UserHandle.USER_CURRENT_OR_SELF) & mode) != 0;
}

public static boolean isBlacklistUnknownNumberEnabled(Context context, int mode) {
return (Settings.System.getIntForUser(context.getContentResolver(),
Settings.System.PHONE_BLACKLIST_UNKNOWN_NUMBER_MODE, 0,
UserHandle.USER_CURRENT_OR_SELF) & mode) != 0;
}

public static boolean isBlacklistRegexEnabled(Context context) {
return Settings.System.getIntForUser(context.getContentResolver(),
Settings.System.PHONE_BLACKLIST_REGEX_ENABLED, 0,
UserHandle.USER_CURRENT_OR_SELF) != 0;
}
}
22 changes: 15 additions & 7 deletions src/java/com/android/internal/telephony/CommandsInterface.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2006 The Android Open Source Project
* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -113,11 +114,11 @@ public boolean isAvailable() {
/**
* response.obj.result is an int[2]
*
* response.obj.result[0] is IMS registration state
* response.obj.result[0] is registration state
* 0 - Not registered
* 1 - Registered
* response.obj.result[1] is of type RILConstants.GSM_PHONE or
* RILConstants.CDMA_PHONE
* response.obj.result[1] is of type const RIL_IMS_SMS_Format,
* corresponds to sms format used for SMS over IMS.
*/
void getImsRegistrationState(Message result);

Expand Down Expand Up @@ -643,6 +644,7 @@ public boolean isAvailable() {
*
* AID (Application ID), See ETSI 102.221 8.1 and 101.220 4
*
* returned message
* retMsg.obj = AsyncResult ar
* ar.exception carries exception on failure
* This exception is CommandException with an error of PASSWORD_INCORRECT
Expand Down Expand Up @@ -1327,12 +1329,18 @@ void setFacilityLockForApp(String facility, boolean lockState, String password,
* Query the list of band mode supported by RF.
*
* @param response is callback message
* ((AsyncResult)response.obj).result is an int[] where int[0] is
* ((AsyncResult)response.obj).result is an int[] with every
* the size of the array and the rest of each element representing
* one available BM_*_BAND
* element representing one avialable BM_*_BAND
*/
void queryAvailableBandMode (Message response);

/**
* Set the current preferred network type. This will be the last
* networkType that was passed to setPreferredNetworkType.
*/
void setCurrentPreferredNetworkType();

/**
* Requests to set the preferred network type for searching and registering
* (CS/PS domain, RAT, and operation mode)
Expand Down Expand Up @@ -1703,11 +1711,11 @@ public void setupDataCall(String radioTechnology, String profile,
* Sets the minimum time in milli-seconds between when RIL_UNSOL_CELL_INFO_LIST
* should be invoked.
*
* The default, 0, means invoke RIL_UNSOL_CELL_INFO_LIST when any of the reported
* The default, 0, means invoke RIL_UNSOL_CELL_INFO_LIST when any of the reported
* information changes. Setting the value to INT_MAX(0x7fffffff) means never issue
* A RIL_UNSOL_CELL_INFO_LIST.
*
*
*

* @param rateInMillis is sent back to handler and result.obj is a AsyncResult
* @param response.obj is AsyncResult ar when sent to associated handler
Expand Down
Loading