添加联系人查询,在联系人名单内就允许连接。
This commit is contained in:
parent
3eaec5ed73
commit
05cc5c72f8
@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Sun Mar 09 20:33:54 HKT 2025
|
#Wed Mar 19 00:46:03 GMT 2025
|
||||||
stageCount=20
|
stageCount=20
|
||||||
libraryProject=
|
libraryProject=
|
||||||
baseVersion=1.0
|
baseVersion=1.0
|
||||||
publishVersion=1.0.19
|
publishVersion=1.0.19
|
||||||
buildCount=0
|
buildCount=12
|
||||||
baseBetaVersion=1.0.20
|
baseBetaVersion=1.0.20
|
||||||
|
@ -6,12 +6,11 @@ package cc.winboll.studio.contacts.dun;
|
|||||||
* @Describe 云盾防御规则
|
* @Describe 云盾防御规则
|
||||||
*/
|
*/
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.media.AudioManager;
|
|
||||||
import cc.winboll.studio.contacts.activities.SettingsActivity;
|
import cc.winboll.studio.contacts.activities.SettingsActivity;
|
||||||
import cc.winboll.studio.contacts.beans.PhoneConnectRuleModel;
|
import cc.winboll.studio.contacts.beans.PhoneConnectRuleModel;
|
||||||
import cc.winboll.studio.contacts.beans.RingTongBean;
|
|
||||||
import cc.winboll.studio.contacts.beans.SettingsModel;
|
import cc.winboll.studio.contacts.beans.SettingsModel;
|
||||||
import cc.winboll.studio.contacts.services.MainService;
|
import cc.winboll.studio.contacts.services.MainService;
|
||||||
|
import cc.winboll.studio.contacts.utils.ContactUtils;
|
||||||
import cc.winboll.studio.contacts.utils.RegexPPiUtils;
|
import cc.winboll.studio.contacts.utils.RegexPPiUtils;
|
||||||
import cc.winboll.studio.libappbase.LogUtils;
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -125,6 +124,19 @@ public class Rules {
|
|||||||
LogUtils.d(TAG, String.format("isDefend == %s\nisConnect == %s", isDefend, isConnect));
|
LogUtils.d(TAG, String.format("isDefend == %s\nisConnect == %s", isDefend, isConnect));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 查询通讯录是否有该联系人
|
||||||
|
boolean isPhoneInContacts = ContactUtils.getInstance(mContext).isPhoneInContacts(mContext, phoneNumber);
|
||||||
|
if (!isDefend) {
|
||||||
|
if (isPhoneInContacts) {
|
||||||
|
LogUtils.d(TAG, String.format("Phone %s is in contacts.", phoneNumber));
|
||||||
|
isDefend = true;
|
||||||
|
isConnect = true;
|
||||||
|
LogUtils.d(TAG, String.format("isDefend == %s\nisConnect == %s", isDefend, isConnect));
|
||||||
|
} else {
|
||||||
|
LogUtils.d(TAG, String.format("Phone %s is not in contacts.", phoneNumber));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 检验拨不通号码群
|
// 检验拨不通号码群
|
||||||
if (!isDefend && MainService.isPhoneInBoBullToon(phoneNumber)) {
|
if (!isDefend && MainService.isPhoneInBoBullToon(phoneNumber)) {
|
||||||
LogUtils.d(TAG, String.format("PhoneNumber %s\n Is In BoBullToon", phoneNumber));
|
LogUtils.d(TAG, String.format("PhoneNumber %s\n Is In BoBullToon", phoneNumber));
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
package cc.winboll.studio.contacts.utils;
|
package cc.winboll.studio.contacts.utils;
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.database.Cursor;
|
|
||||||
import android.provider.ContactsContract;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author ZhanGSKen@AliYun.Com
|
* @Author ZhanGSKen@AliYun.Com
|
||||||
* @Date 2025/03/06 21:08:16
|
* @Date 2025/03/06 21:08:16
|
||||||
* @Describe ContactUtils
|
* @Describe ContactUtils
|
||||||
*/
|
*/
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.provider.ContactsContract;
|
||||||
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class ContactUtils {
|
public class ContactUtils {
|
||||||
|
|
||||||
public static final String TAG = "ContactUtils";
|
public static final String TAG = "ContactUtils";
|
||||||
@ -59,34 +61,62 @@ public class ContactUtils {
|
|||||||
// static String getSimplePhone(String phone) {
|
// static String getSimplePhone(String phone) {
|
||||||
// return phone.replaceAll("[+\\s]", "");
|
// return phone.replaceAll("[+\\s]", "");
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public static String formatToSimplePhoneNumber(String number) {
|
public static String formatToSimplePhoneNumber(String number) {
|
||||||
// 去除所有空格和非数字字符
|
// 去除所有空格和非数字字符
|
||||||
return number.replaceAll("[^0-9]", "");
|
return number.replaceAll("[^0-9]", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getDisplayNameByPhone(Context context, String phoneNumber) {
|
public static String getDisplayNameByPhone(Context context, String phoneNumber) {
|
||||||
String displayName = null;
|
String displayName = null;
|
||||||
ContentResolver resolver = context.getContentResolver();
|
ContentResolver resolver = context.getContentResolver();
|
||||||
String[] projection = {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME};
|
String[] projection = {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME};
|
||||||
Cursor cursor = resolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projection, ContactsContract.CommonDataKinds.Phone.NUMBER + "=?", new String[]{formatToSimplePhoneNumber(phoneNumber)}, null);
|
Cursor cursor = resolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projection, ContactsContract.CommonDataKinds.Phone.NUMBER + "=?", new String[]{phoneNumber}, null);
|
||||||
if (cursor!= null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
displayName = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
|
displayName = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
|
||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
return displayName;
|
return displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getDisplayNameByPhoneSimple(Context context, String phoneNumber) {
|
||||||
|
String displayName = null;
|
||||||
|
ContentResolver resolver = context.getContentResolver();
|
||||||
|
String[] projection = {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME};
|
||||||
|
Cursor cursor = resolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projection, ContactsContract.CommonDataKinds.Phone.NUMBER + "=?", new String[]{formatToSimplePhoneNumber(phoneNumber)}, null);
|
||||||
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
|
displayName = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
return displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isPhoneInContacts(Context context, String phoneNumber) {
|
||||||
|
String szPhoneNumber = formatToSimplePhoneNumber(phoneNumber);
|
||||||
|
String szDisplayName = getDisplayNameByPhone(context, szPhoneNumber);
|
||||||
|
if (szDisplayName == null) {
|
||||||
|
LogUtils.d(TAG, String.format("Phone %s is not in contacts.", szPhoneNumber));
|
||||||
|
szPhoneNumber = formatToSpacePhoneNumber(szPhoneNumber);
|
||||||
|
szDisplayName = getDisplayNameByPhone(context, szPhoneNumber);
|
||||||
|
if (szDisplayName == null) {
|
||||||
|
LogUtils.d(TAG, String.format("Phone %s is not in contacts.", szPhoneNumber));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LogUtils.d(TAG, String.format("Phone %s is found in contacts %s.", szPhoneNumber, szDisplayName));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public static String formatToSpacePhoneNumber(String simpleNumber) {
|
public static String formatToSpacePhoneNumber(String simpleNumber) {
|
||||||
// 去除所有空格和非数字字符
|
// 去除所有空格和非数字字符
|
||||||
StringBuilder sbSpaceNumber = new StringBuilder();
|
StringBuilder sbSpaceNumber = new StringBuilder();
|
||||||
String regex = "^1[0-9]{10}$";
|
String regex = "^1[0-9]{10}$";
|
||||||
if(simpleNumber.matches(regex)) {
|
if (simpleNumber.matches(regex)) {
|
||||||
sbSpaceNumber.append(simpleNumber.substring(0,2));
|
sbSpaceNumber.append(simpleNumber.substring(0, 3));
|
||||||
sbSpaceNumber.append(" ");
|
sbSpaceNumber.append(" ");
|
||||||
sbSpaceNumber.append(simpleNumber.substring(3,6));
|
sbSpaceNumber.append(simpleNumber.substring(3, 7));
|
||||||
sbSpaceNumber.append(" ");
|
sbSpaceNumber.append(" ");
|
||||||
sbSpaceNumber.append(simpleNumber.substring(7,10));
|
sbSpaceNumber.append(simpleNumber.substring(7, 11));
|
||||||
}
|
}
|
||||||
return sbSpaceNumber.toString();
|
return sbSpaceNumber.toString();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user