添加黑名单规则和区号规则设定
This commit is contained in:
parent
c16c6bba74
commit
234d2d57de
@ -65,7 +65,7 @@ dependencies {
|
|||||||
api 'com.google.android.material:material:1.4.0'
|
api 'com.google.android.material:material:1.4.0'
|
||||||
|
|
||||||
api 'cc.winboll.studio:libapputils:9.3.2'
|
api 'cc.winboll.studio:libapputils:9.3.2'
|
||||||
api 'cc.winboll.studio:libappbase:1.5.5'
|
api 'cc.winboll.studio:libappbase:1.5.6'
|
||||||
|
|
||||||
api fileTree(dir: 'libs', include: ['*.jar'])
|
api fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Fri Feb 21 01:46:02 GMT 2025
|
#Fri Feb 21 03:30:46 GMT 2025
|
||||||
stageCount=0
|
stageCount=0
|
||||||
libraryProject=winboll-shared
|
libraryProject=winboll-shared
|
||||||
baseVersion=1.0
|
baseVersion=1.0
|
||||||
publishVersion=1.0.0
|
publishVersion=1.0.0
|
||||||
buildCount=175
|
buildCount=194
|
||||||
baseBetaVersion=1.0.1
|
baseBetaVersion=1.0.1
|
||||||
|
@ -0,0 +1,88 @@
|
|||||||
|
package cc.winboll.studio.contacts.beans;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen@AliYun.Com
|
||||||
|
* @Date 2025/02/21 09:52:10
|
||||||
|
* @Describe 电话黑名单规则
|
||||||
|
*/
|
||||||
|
import android.util.JsonReader;
|
||||||
|
import android.util.JsonWriter;
|
||||||
|
import cc.winboll.studio.libappbase.BaseBean;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class PhoneBlackRuleBean extends BaseBean {
|
||||||
|
|
||||||
|
public static final String TAG = "PhoneBlackRuleBean";
|
||||||
|
|
||||||
|
String ruleText;
|
||||||
|
boolean isEnable;
|
||||||
|
|
||||||
|
public PhoneBlackRuleBean() {
|
||||||
|
this.ruleText = "";
|
||||||
|
this.isEnable = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PhoneBlackRuleBean(String ruleText, boolean isEnable) {
|
||||||
|
this.ruleText = ruleText;
|
||||||
|
this.isEnable = isEnable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRuleText(String ruleText) {
|
||||||
|
this.ruleText = ruleText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRuleText() {
|
||||||
|
return ruleText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsEnable(boolean isEnable) {
|
||||||
|
this.isEnable = isEnable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEnable() {
|
||||||
|
return isEnable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return PhoneBlackRuleBean.class.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
|
||||||
|
super.writeThisToJsonWriter(jsonWriter);
|
||||||
|
jsonWriter.name("ruleText").value(getRuleText());
|
||||||
|
jsonWriter.name("isEnable").value(isEnable());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean initObjectsFromJsonReader(JsonReader jsonReader, String name) throws IOException {
|
||||||
|
if (super.initObjectsFromJsonReader(jsonReader, name)) { return true; } else {
|
||||||
|
if (name.equals("ruleText")) {
|
||||||
|
setRuleText(jsonReader.nextString());
|
||||||
|
} else if (name.equals("isEnable")) {
|
||||||
|
setIsEnable(jsonReader.nextBoolean());
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
|
||||||
|
jsonReader.beginObject();
|
||||||
|
while (jsonReader.hasNext()) {
|
||||||
|
String name = jsonReader.nextName();
|
||||||
|
if (!initObjectsFromJsonReader(jsonReader, name)) {
|
||||||
|
jsonReader.skipValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 结束 JSON 对象
|
||||||
|
jsonReader.endObject();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -5,19 +5,72 @@ package cc.winboll.studio.contacts.dun;
|
|||||||
* @Date 2025/02/21 06:15:10
|
* @Date 2025/02/21 06:15:10
|
||||||
* @Describe 云盾防御规则
|
* @Describe 云盾防御规则
|
||||||
*/
|
*/
|
||||||
|
import cc.winboll.studio.contacts.beans.PhoneBlackRuleBean;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
public class Rules {
|
public class Rules {
|
||||||
|
|
||||||
public static final String TAG = "Rules";
|
public static final String TAG = "Rules";
|
||||||
|
|
||||||
public static boolean isValidPhoneNumber(String phoneNumber) {
|
ArrayList<PhoneBlackRuleBean> _PhoneBlacRuleBeanList;
|
||||||
// 中国手机号码正则表达式,以1开头,第二位可以是3、4、5、6、7、8、9,后面跟9位数字
|
static volatile Rules _Rules;
|
||||||
String regex = "^1[3-9]\\d{9}$";
|
Context mContext;
|
||||||
return Pattern.matches(regex, phoneNumber);
|
|
||||||
|
Rules(Context context) {
|
||||||
|
mContext = context;
|
||||||
|
_PhoneBlacRuleBeanList = new ArrayList<PhoneBlackRuleBean>();
|
||||||
|
PhoneBlackRuleBean.loadBeanList(mContext, _PhoneBlacRuleBeanList, PhoneBlackRuleBean.class);
|
||||||
|
|
||||||
|
}
|
||||||
|
public static synchronized Rules getInstance(Context context) {
|
||||||
|
if (_Rules == null) {
|
||||||
|
_Rules = new Rules(context);
|
||||||
|
}
|
||||||
|
return _Rules;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isAllowed(String phoneNumber) {
|
public boolean isAllowed(String phoneNumber) {
|
||||||
return isValidPhoneNumber(phoneNumber);
|
// 黑名单拒接
|
||||||
|
for (int i = 0; i < _PhoneBlacRuleBeanList.size(); i++) {
|
||||||
|
if (_PhoneBlacRuleBeanList.get(i).isEnable()) {
|
||||||
|
String regex = _PhoneBlacRuleBeanList.get(i).getRuleText();
|
||||||
|
if (Pattern.matches(regex, phoneNumber)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 手机号码允许
|
||||||
|
// 中国手机号码正则表达式,以1开头,第二位可以是3、4、5、6、7、8、9,后面跟9位数字
|
||||||
|
String regex = "^1[3-9]\\d{9}$";
|
||||||
|
if (Pattern.matches(regex, phoneNumber)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 指定区号号码允许
|
||||||
|
regex = "^0660\\d+$";
|
||||||
|
if (Pattern.matches(regex, phoneNumber)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 指定区号号码允许
|
||||||
|
regex = "^020\\d+$";
|
||||||
|
if (Pattern.matches(regex, phoneNumber)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 其他拒接
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(String phoneRuleBlack, boolean isEnable) {
|
||||||
|
_PhoneBlacRuleBeanList.add(new PhoneBlackRuleBean(phoneRuleBlack, isEnable));
|
||||||
|
PhoneBlackRuleBean.saveBeanList(mContext, _PhoneBlacRuleBeanList, PhoneBlackRuleBean.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<PhoneBlackRuleBean> getPhoneBlacRuleBeanList() {
|
||||||
|
return _PhoneBlacRuleBeanList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,6 @@ public class PhoneCallManager {
|
|||||||
*/
|
*/
|
||||||
public void answer() {
|
public void answer() {
|
||||||
if (call != null) {
|
if (call != null) {
|
||||||
Call.Details details = call.getDetails();
|
|
||||||
String phoneNumber = details.getHandle().getSchemeSpecificPart();
|
|
||||||
call.answer(VideoProfile.STATE_AUDIO_ONLY);
|
call.answer(VideoProfile.STATE_AUDIO_ONLY);
|
||||||
openSpeaker();
|
openSpeaker();
|
||||||
}
|
}
|
||||||
|
@ -13,11 +13,21 @@ import android.telecom.Call;
|
|||||||
import android.telecom.InCallService;
|
import android.telecom.InCallService;
|
||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
import cc.winboll.studio.contacts.ActivityStack;
|
import cc.winboll.studio.contacts.ActivityStack;
|
||||||
|
import cc.winboll.studio.contacts.beans.PhoneBlackRuleBean;
|
||||||
import cc.winboll.studio.contacts.dun.Rules;
|
import cc.winboll.studio.contacts.dun.Rules;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||||
public class PhoneCallService extends InCallService {
|
public class PhoneCallService extends InCallService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate() {
|
||||||
|
super.onCreate();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private int originalRingVolume;
|
private int originalRingVolume;
|
||||||
|
|
||||||
private final Call.Callback callback = new Call.Callback() {
|
private final Call.Callback callback = new Call.Callback() {
|
||||||
@ -59,7 +69,7 @@ public class PhoneCallService extends InCallService {
|
|||||||
// 记录原始铃声音量
|
// 记录原始铃声音量
|
||||||
AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
|
AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
|
||||||
originalRingVolume = audioManager.getStreamVolume(AudioManager.STREAM_RING);
|
originalRingVolume = audioManager.getStreamVolume(AudioManager.STREAM_RING);
|
||||||
if (!Rules.isAllowed(phoneNumber)) {
|
if (!Rules.getInstance(this).isAllowed(phoneNumber)) {
|
||||||
// 预先静音
|
// 预先静音
|
||||||
audioManager.setStreamVolume(AudioManager.STREAM_RING, 0, 0);
|
audioManager.setStreamVolume(AudioManager.STREAM_RING, 0, 0);
|
||||||
call.disconnect();
|
call.disconnect();
|
||||||
|
@ -27,6 +27,7 @@ import cc.winboll.studio.contacts.widgets.APPStatusWidget;
|
|||||||
import cc.winboll.studio.libappbase.LogUtils;
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
import cc.winboll.studio.libappbase.SOS;
|
import cc.winboll.studio.libappbase.SOS;
|
||||||
import cc.winboll.studio.libappbase.bean.APPSOSBean;
|
import cc.winboll.studio.libappbase.bean.APPSOSBean;
|
||||||
|
import cc.winboll.studio.contacts.dun.Rules;
|
||||||
|
|
||||||
public class MainService extends Service {
|
public class MainService extends Service {
|
||||||
|
|
||||||
@ -99,6 +100,10 @@ public class MainService extends Service {
|
|||||||
mMainReceiver.registerAction(this);
|
mMainReceiver.registerAction(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rules.getInstance(this);
|
||||||
|
//Rules.getInstance(this).add("18888888888", true);
|
||||||
|
//Rules.getInstance(this).add("16769764848", true);
|
||||||
|
|
||||||
startPhoneCallListener();
|
startPhoneCallListener();
|
||||||
|
|
||||||
MainServiceThread.getInstance(this, mMainServiceHandler).start();
|
MainServiceThread.getInstance(this, mMainServiceHandler).start();
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Fri Feb 21 01:46:02 GMT 2025
|
#Fri Feb 21 03:30:46 GMT 2025
|
||||||
stageCount=0
|
stageCount=0
|
||||||
libraryProject=winboll-shared
|
libraryProject=winboll-shared
|
||||||
baseVersion=1.0
|
baseVersion=1.0
|
||||||
publishVersion=1.0.0
|
publishVersion=1.0.0
|
||||||
buildCount=175
|
buildCount=194
|
||||||
baseBetaVersion=1.0.1
|
baseBetaVersion=1.0.1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user