支持卡槽匹配规则

This commit is contained in:
pppscn 2021-03-11 22:55:19 +08:00
parent f01a15b2a0
commit 2801b0983a
12 changed files with 222 additions and 63 deletions

View File

@ -54,7 +54,7 @@ Android手机监听短信并根据指定规则转发到其他手机钉钉机
- [x] 支持多重匹配规则 - [x] 支持多重匹配规则
- [x] 支持标注卡槽号码(优先使用)、设备信息;自定义转发信息模版 - [x] 支持标注卡槽号码(优先使用)、设备信息;自定义转发信息模版
- [ ] 支持正则匹配规则 - [ ] 支持正则匹配规则
- [ ] 支持卡槽匹配规则 - [x] 支持卡槽匹配规则
- [ ] 转发规则、发送方配置导出与导入 - [ ] 转发规则、发送方配置导出与导入
### 使用流程: ### 使用流程:

View File

@ -81,7 +81,7 @@ public class SmsForwarderBroadcastReceiver extends BroadcastReceiver {
smsVoList.add(new SmsVo(mobile, mobileToContent.get(mobile), date, simInfo)); smsVoList.add(new SmsVo(mobile, mobileToContent.get(mobile), date, simInfo));
} }
Log.d(TAG, "短信:" + smsVoList); Log.d(TAG, "短信:" + smsVoList);
SendUtil.send_msg_list(context, smsVoList); SendUtil.send_msg_list(context, smsVoList, simId);
} }

View File

@ -146,6 +146,9 @@ public class RuleActivity extends AppCompatActivity {
final RadioGroup radioGroupRuleCheck = (RadioGroup) view1.findViewById(R.id.radioGroupRuleCheck); final RadioGroup radioGroupRuleCheck = (RadioGroup) view1.findViewById(R.id.radioGroupRuleCheck);
if (ruleModel != null) radioGroupRuleCheck.check(ruleModel.getRuleCheckCheckId()); if (ruleModel != null) radioGroupRuleCheck.check(ruleModel.getRuleCheckCheckId());
final RadioGroup radioGroupSimSlot = (RadioGroup) view1.findViewById(R.id.radioGroupSimSlot);
if (ruleModel != null) radioGroupSimSlot.check(ruleModel.getRuleSimSlotCheckId());
final TextView tv_mu_rule_tips = (TextView) view1.findViewById(R.id.tv_mu_rule_tips); final TextView tv_mu_rule_tips = (TextView) view1.findViewById(R.id.tv_mu_rule_tips);
final TextView ruleSenderTv = (TextView) view1.findViewById(R.id.ruleSenderTv); final TextView ruleSenderTv = (TextView) view1.findViewById(R.id.ruleSenderTv);
if (ruleModel != null && ruleModel.getSenderId() != null) { if (ruleModel != null && ruleModel.getSenderId() != null) {
@ -190,6 +193,7 @@ public class RuleActivity extends AppCompatActivity {
RuleModel newRuleModel = new RuleModel(); RuleModel newRuleModel = new RuleModel();
newRuleModel.setFiled(RuleModel.getRuleFiledFromCheckId(radioGroupRuleFiled.getCheckedRadioButtonId())); newRuleModel.setFiled(RuleModel.getRuleFiledFromCheckId(radioGroupRuleFiled.getCheckedRadioButtonId()));
newRuleModel.setCheck(RuleModel.getRuleCheckFromCheckId(radioGroupRuleCheck.getCheckedRadioButtonId())); newRuleModel.setCheck(RuleModel.getRuleCheckFromCheckId(radioGroupRuleCheck.getCheckedRadioButtonId()));
newRuleModel.setSimSlot(RuleModel.getRuleSimSlotFromCheckId(radioGroupSimSlot.getCheckedRadioButtonId()));
newRuleModel.setValue(editTextRuleValue.getText().toString()); newRuleModel.setValue(editTextRuleValue.getText().toString());
if (senderId != null) { if (senderId != null) {
newRuleModel.setSenderId(Long.valueOf(senderId.toString())); newRuleModel.setSenderId(Long.valueOf(senderId.toString()));
@ -200,6 +204,7 @@ public class RuleActivity extends AppCompatActivity {
} else { } else {
ruleModel.setFiled(RuleModel.getRuleFiledFromCheckId(radioGroupRuleFiled.getCheckedRadioButtonId())); ruleModel.setFiled(RuleModel.getRuleFiledFromCheckId(radioGroupRuleFiled.getCheckedRadioButtonId()));
ruleModel.setCheck(RuleModel.getRuleCheckFromCheckId(radioGroupRuleCheck.getCheckedRadioButtonId())); ruleModel.setCheck(RuleModel.getRuleCheckFromCheckId(radioGroupRuleCheck.getCheckedRadioButtonId()));
ruleModel.setSimSlot(RuleModel.getRuleSimSlotFromCheckId(radioGroupSimSlot.getCheckedRadioButtonId()));
ruleModel.setValue(editTextRuleValue.getText().toString()); ruleModel.setValue(editTextRuleValue.getText().toString());
if (senderId != null) { if (senderId != null) {
ruleModel.setSenderId(Long.valueOf(senderId.toString())); ruleModel.setSenderId(Long.valueOf(senderId.toString()));
@ -210,10 +215,9 @@ public class RuleActivity extends AppCompatActivity {
} }
show.dismiss(); show.dismiss();
} }
}); });
buttonruledel.setOnClickListener(new View.OnClickListener() { buttonruledel.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -225,6 +229,7 @@ public class RuleActivity extends AppCompatActivity {
show.dismiss(); show.dismiss();
} }
}); });
buttonruletest.setOnClickListener(new View.OnClickListener() { buttonruletest.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -236,23 +241,21 @@ public class RuleActivity extends AppCompatActivity {
RuleModel newRuleModel = new RuleModel(); RuleModel newRuleModel = new RuleModel();
newRuleModel.setFiled(RuleModel.getRuleFiledFromCheckId(radioGroupRuleFiled.getCheckedRadioButtonId())); newRuleModel.setFiled(RuleModel.getRuleFiledFromCheckId(radioGroupRuleFiled.getCheckedRadioButtonId()));
newRuleModel.setCheck(RuleModel.getRuleCheckFromCheckId(radioGroupRuleCheck.getCheckedRadioButtonId())); newRuleModel.setCheck(RuleModel.getRuleCheckFromCheckId(radioGroupRuleCheck.getCheckedRadioButtonId()));
newRuleModel.setSimSlot(RuleModel.getRuleSimSlotFromCheckId(radioGroupSimSlot.getCheckedRadioButtonId()));
newRuleModel.setValue(editTextRuleValue.getText().toString()); newRuleModel.setValue(editTextRuleValue.getText().toString());
newRuleModel.setSenderId(Long.valueOf(senderId.toString())); newRuleModel.setSenderId(Long.valueOf(senderId.toString()));
testRule(newRuleModel, Long.valueOf(senderId.toString())); testRule(newRuleModel, Long.valueOf(senderId.toString()));
} else { } else {
ruleModel.setFiled(RuleModel.getRuleFiledFromCheckId(radioGroupRuleFiled.getCheckedRadioButtonId())); ruleModel.setFiled(RuleModel.getRuleFiledFromCheckId(radioGroupRuleFiled.getCheckedRadioButtonId()));
ruleModel.setCheck(RuleModel.getRuleCheckFromCheckId(radioGroupRuleCheck.getCheckedRadioButtonId())); ruleModel.setCheck(RuleModel.getRuleCheckFromCheckId(radioGroupRuleCheck.getCheckedRadioButtonId()));
ruleModel.setSimSlot(RuleModel.getRuleSimSlotFromCheckId(radioGroupSimSlot.getCheckedRadioButtonId()));
ruleModel.setValue(editTextRuleValue.getText().toString()); ruleModel.setValue(editTextRuleValue.getText().toString());
ruleModel.setSenderId(Long.valueOf(senderId.toString())); ruleModel.setSenderId(Long.valueOf(senderId.toString()));
testRule(ruleModel, Long.valueOf(senderId.toString())); testRule(ruleModel, Long.valueOf(senderId.toString()));
} }
} }
} }
}); });
@ -328,6 +331,7 @@ public class RuleActivity extends AppCompatActivity {
public void testRule(final RuleModel ruleModel, final Long senderId) { public void testRule(final RuleModel ruleModel, final Long senderId) {
final View view = View.inflate(RuleActivity.this, R.layout.alert_dialog_setview_rule_test, null); final View view = View.inflate(RuleActivity.this, R.layout.alert_dialog_setview_rule_test, null);
final RadioGroup radioGroupTestSimSlot = (RadioGroup) view.findViewById(R.id.radioGroupTestSimSlot);
final EditText editTextTestPhone = (EditText) view.findViewById(R.id.editTextTestPhone); final EditText editTextTestPhone = (EditText) view.findViewById(R.id.editTextTestPhone);
final EditText editTextTestMsgContent = (EditText) view.findViewById(R.id.editTextTestMsgContent); final EditText editTextTestMsgContent = (EditText) view.findViewById(R.id.editTextTestMsgContent);
Button buttonruletest = view.findViewById(R.id.buttonruletest); Button buttonruletest = view.findViewById(R.id.buttonruletest);
@ -343,7 +347,13 @@ public class RuleActivity extends AppCompatActivity {
Log.i("editTextTestMsgContent", editTextTestMsgContent.getText().toString()); Log.i("editTextTestMsgContent", editTextTestMsgContent.getText().toString());
try { try {
String simInfo = "SIM1_" + SettingUtil.getAddExtraSim1(); String simSlot = RuleModel.getRuleSimSlotFromCheckId(radioGroupTestSimSlot.getCheckedRadioButtonId());
String simInfo = "";
if (simSlot.equals("SIM2")) {
simInfo = simSlot + "_" + SettingUtil.getAddExtraSim2();
} else {
simInfo = simSlot + "_" + SettingUtil.getAddExtraSim1();
}
SmsVo testSmsVo = new SmsVo(editTextTestPhone.getText().toString(), editTextTestMsgContent.getText().toString(), new Date(), simInfo); SmsVo testSmsVo = new SmsVo(editTextTestPhone.getText().toString(), editTextTestMsgContent.getText().toString(), new Date(), simInfo);
SendUtil.sendMsgByRuleModelSenderId(handler, ruleModel, testSmsVo, senderId); SendUtil.sendMsgByRuleModelSenderId(handler, ruleModel, testSmsVo, senderId);
} catch (Exception e) { } catch (Exception e) {

View File

@ -21,6 +21,10 @@ public class RuleModel {
public static final String CHECK_END_WITH = "endwith"; public static final String CHECK_END_WITH = "endwith";
public static final String CHECK_NOT_IS = "notis"; public static final String CHECK_NOT_IS = "notis";
public static final Map<String, String> CHECK_MAP = new HashMap<String, String>(); public static final Map<String, String> CHECK_MAP = new HashMap<String, String>();
public static final String CHECK_SIM_SLOT_ALL = "ALL";
public static final String CHECK_SIM_SLOT_1 = "SIM1";
public static final String CHECK_SIM_SLOT_2 = "SIM2";
public static final Map<String, String> SIM_SLOT_MAP = new HashMap<String, String>();
static { static {
FILED_MAP.put("transpond_all", "转发全部"); FILED_MAP.put("transpond_all", "转发全部");
@ -37,25 +41,29 @@ public class RuleModel {
CHECK_MAP.put("notis", "不是"); CHECK_MAP.put("notis", "不是");
} }
static {
SIM_SLOT_MAP.put("ALL", "全部");
SIM_SLOT_MAP.put("SIM1", "SIM1");
SIM_SLOT_MAP.put("SIM2", "SIM2");
}
private String TAG = "RuleModel"; private String TAG = "RuleModel";
private Long id; private Long id;
private String filed; private String filed;
private String check; private String check;
private String value; private String value;
private Long senderId; private Long senderId;
private Long time; private Long time;
private String simSlot;
public static String getRuleMatch(String filed, String check, String value) { public static String getRuleMatch(String filed, String check, String value, String simSlot) {
String SimStr = SIM_SLOT_MAP.get(simSlot) + "";
switch (filed) { switch (filed) {
case FILED_TRANSPOND_ALL: case FILED_TRANSPOND_ALL:
return "全部转发到 "; return SimStr + "全部转发到 ";
default: default:
return "" + FILED_MAP.get(filed) + " " + CHECK_MAP.get(check) + " " + value + " 转发到 "; return SimStr + "" + FILED_MAP.get(filed) + " " + CHECK_MAP.get(check) + " " + value + " 转发到 ";
} }
} }
public static String getRuleFiledFromCheckId(int id) { public static String getRuleFiledFromCheckId(int id) {
@ -86,6 +94,17 @@ public class RuleModel {
} }
} }
public static String getRuleSimSlotFromCheckId(int id) {
switch (id) {
case R.id.btnSimSlot1:
return CHECK_SIM_SLOT_1;
case R.id.btnSimSlot2:
return CHECK_SIM_SLOT_2;
default:
return CHECK_SIM_SLOT_ALL;
}
}
//字段分支 //字段分支
public boolean checkMsg(SmsVo msg) throws Exception { public boolean checkMsg(SmsVo msg) throws Exception {
@ -154,13 +173,13 @@ public class RuleModel {
} }
public String getRuleMatch() { public String getRuleMatch() {
String SimStr = SIM_SLOT_MAP.get(simSlot) + "";
switch (filed) { switch (filed) {
case FILED_TRANSPOND_ALL: case FILED_TRANSPOND_ALL:
return "全部转发到 "; return SimStr + "全部转发到 ";
default: default:
return "" + FILED_MAP.get(filed) + " " + CHECK_MAP.get(check) + " " + value + " 转发到 "; return SimStr + "" + FILED_MAP.get(filed) + " " + CHECK_MAP.get(check) + " " + value + " 转发到 ";
} }
} }
public Long getRuleSenderId() { public Long getRuleSenderId() {
@ -195,6 +214,17 @@ public class RuleModel {
} }
} }
public int getRuleSimSlotCheckId() {
switch (simSlot) {
case CHECK_SIM_SLOT_1:
return R.id.btnSimSlot1;
case CHECK_SIM_SLOT_2:
return R.id.btnSimSlot2;
default:
return R.id.btnSimSlotAll;
}
}
public Long getId() { public Long getId() {
return id; return id;
} }
@ -227,6 +257,14 @@ public class RuleModel {
this.filed = filed; this.filed = filed;
} }
public String getSimSlot() {
return simSlot;
}
public void setSimSlot(String simSlot) {
this.simSlot = simSlot;
}
public String getCheck() { public String getCheck() {
return check; return check;
} }

View File

@ -16,5 +16,6 @@ public final class RuleTable {
public static final String COLUMN_NAME_VALUE = "value"; public static final String COLUMN_NAME_VALUE = "value";
public static final String COLUMN_NAME_SENDER_ID = "sender_id"; public static final String COLUMN_NAME_SENDER_ID = "sender_id";
public static final String COLUMN_NAME_TIME = "time"; public static final String COLUMN_NAME_TIME = "time";
public static final String COLUMN_NAME_SIM_SLOT = "sim_slot";
} }
} }

View File

@ -10,7 +10,7 @@ public class SmsVo implements Serializable {
String mobile; String mobile;
String content; String content;
Date date; Date date;
String simInfo = "本机号码:未知"; String simInfo = "SIM1_unknown_unknown";
public SmsVo() { public SmsVo() {
} }

View File

@ -30,19 +30,20 @@ import static com.idormy.sms.forwarder.model.SenderModel.TYPE_WEB_NOTIFY;
public class SendUtil { public class SendUtil {
private static String TAG = "SendUtil"; private static String TAG = "SendUtil";
public static void send_msg_list(Context context, List<SmsVo> smsVoList) { public static void send_msg_list(Context context, List<SmsVo> smsVoList, int simId) {
Log.i(TAG, "send_msg_list size: " + smsVoList.size()); Log.i(TAG, "send_msg_list size: " + smsVoList.size());
for (SmsVo smsVo : smsVoList) { for (SmsVo smsVo : smsVoList) {
SendUtil.send_msg(context, smsVo); SendUtil.send_msg(context, smsVo, simId);
} }
} }
public static void send_msg(Context context, SmsVo smsVo) { public static void send_msg(Context context, SmsVo smsVo, int simId) {
Log.i(TAG, "send_msg smsVo:" + smsVo); Log.i(TAG, "send_msg smsVo:" + smsVo);
RuleUtil.init(context); RuleUtil.init(context);
LogUtil.init(context); LogUtil.init(context);
List<RuleModel> rulelist = RuleUtil.getRule(null, null); String key = "SIM" + simId;
List<RuleModel> rulelist = RuleUtil.getRule(null, key);
if (!rulelist.isEmpty()) { if (!rulelist.isEmpty()) {
SenderUtil.init(context); SenderUtil.init(context);
for (RuleModel ruleModel : rulelist) { for (RuleModel ruleModel : rulelist) {
@ -68,6 +69,13 @@ public class SendUtil {
throw new Exception("先新建并选择发送方"); throw new Exception("先新建并选择发送方");
} }
String testSim = smsVo.getSimInfo().substring(0, 4);
String ruleSim = ruleModel.getSimSlot();
if (!ruleSim.equals("ALL") && !ruleSim.equals(testSim)) {
throw new Exception("接收卡槽未匹配中规则");
}
if (!ruleModel.checkMsg(smsVo)) { if (!ruleModel.checkMsg(smsVo)) {
throw new Exception("短信未匹配中规则"); throw new Exception("短信未匹配中规则");
} }

View File

@ -15,7 +15,7 @@ import java.util.List;
public class DbHelper extends SQLiteOpenHelper { public class DbHelper extends SQLiteOpenHelper {
// If you change the database schema, you must increment the database version. // If you change the database schema, you must increment the database version.
public static final String TAG = "DbHelper"; public static final String TAG = "DbHelper";
public static final int DATABASE_VERSION = 2; public static final int DATABASE_VERSION = 3;
public static final String DATABASE_NAME = "sms_forwarder.db"; public static final String DATABASE_NAME = "sms_forwarder.db";
private static final List<String> SQL_CREATE_ENTRIES = private static final List<String> SQL_CREATE_ENTRIES =
@ -26,21 +26,22 @@ public class DbHelper extends SQLiteOpenHelper {
LogTable.LogEntry.COLUMN_NAME_CONTENT + " TEXT," + LogTable.LogEntry.COLUMN_NAME_CONTENT + " TEXT," +
LogTable.LogEntry.COLUMN_NAME_SIM_INFO + " TEXT," + LogTable.LogEntry.COLUMN_NAME_SIM_INFO + " TEXT," +
LogTable.LogEntry.COLUMN_NAME_RULE_ID + " INTEGER," + LogTable.LogEntry.COLUMN_NAME_RULE_ID + " INTEGER," +
LogTable.LogEntry.COLUMN_NAME_TIME + " TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP)" LogTable.LogEntry.COLUMN_NAME_TIME + " TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP)"
, "CREATE TABLE " + RuleTable.RuleEntry.TABLE_NAME + " (" + , "CREATE TABLE " + RuleTable.RuleEntry.TABLE_NAME + " (" +
RuleTable.RuleEntry._ID + " INTEGER PRIMARY KEY," + RuleTable.RuleEntry._ID + " INTEGER PRIMARY KEY," +
RuleTable.RuleEntry.COLUMN_NAME_FILED + " TEXT," + RuleTable.RuleEntry.COLUMN_NAME_FILED + " TEXT," +
RuleTable.RuleEntry.COLUMN_NAME_CHECK + " TEXT," + RuleTable.RuleEntry.COLUMN_NAME_CHECK + " TEXT," +
RuleTable.RuleEntry.COLUMN_NAME_VALUE + " TEXT," + RuleTable.RuleEntry.COLUMN_NAME_VALUE + " TEXT," +
RuleTable.RuleEntry.COLUMN_NAME_SENDER_ID + " INTEGER," + RuleTable.RuleEntry.COLUMN_NAME_SENDER_ID + " INTEGER," +
RuleTable.RuleEntry.COLUMN_NAME_TIME + " TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP)" RuleTable.RuleEntry.COLUMN_NAME_TIME + " TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
RuleTable.RuleEntry.COLUMN_NAME_SIM_SLOT + " TEXT NOT NULL DEFAULT 'ALL')"
, "CREATE TABLE " + SenderTable.SenderEntry.TABLE_NAME + " (" + , "CREATE TABLE " + SenderTable.SenderEntry.TABLE_NAME + " (" +
SenderTable.SenderEntry._ID + " INTEGER PRIMARY KEY," + SenderTable.SenderEntry._ID + " INTEGER PRIMARY KEY," +
SenderTable.SenderEntry.COLUMN_NAME_NAME + " TEXT," + SenderTable.SenderEntry.COLUMN_NAME_NAME + " TEXT," +
SenderTable.SenderEntry.COLUMN_NAME_STATUS + " INTEGER," + SenderTable.SenderEntry.COLUMN_NAME_STATUS + " INTEGER," +
SenderTable.SenderEntry.COLUMN_NAME_TYPE + " INTEGER," + SenderTable.SenderEntry.COLUMN_NAME_TYPE + " INTEGER," +
SenderTable.SenderEntry.COLUMN_NAME_JSON_SETTING + " TEXT," + SenderTable.SenderEntry.COLUMN_NAME_JSON_SETTING + " TEXT," +
SenderTable.SenderEntry.COLUMN_NAME_TIME + " TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP)" SenderTable.SenderEntry.COLUMN_NAME_TIME + " TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP)"
); );
private static final List<String> SQL_DELETE_ENTRIES = private static final List<String> SQL_DELETE_ENTRIES =
@ -73,14 +74,14 @@ public class DbHelper extends SQLiteOpenHelper {
} }
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// This database is only a cache for online data, so its upgrade policy is
// to simply to discard the data and start over
//delCreateTable(db);
//onCreate(db);
if (oldVersion < 2) { //当数据库版本小于版本2时 if (oldVersion < 2) { //当数据库版本小于版本2时
String sql = "Alter table " + LogTable.LogEntry.TABLE_NAME + " add column " + LogTable.LogEntry.COLUMN_NAME_SIM_INFO + " TEXT "; String sql = "Alter table " + LogTable.LogEntry.TABLE_NAME + " add column " + LogTable.LogEntry.COLUMN_NAME_SIM_INFO + " TEXT ";
db.execSQL(sql); db.execSQL(sql);
} }
if (oldVersion < 3) { //当数据库版本小于版本3时
String sql = "Alter table " + RuleTable.RuleEntry.TABLE_NAME + " add column " + RuleTable.RuleEntry.COLUMN_NAME_SIM_SLOT + " TEXT NOT NULL DEFAULT 'ALL' ";
db.execSQL(sql);
}
} }
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) { public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {

View File

@ -157,12 +157,14 @@ public class LogUtil {
cursor.getColumnIndexOrThrow(RuleTable.RuleEntry.COLUMN_NAME_CHECK)); cursor.getColumnIndexOrThrow(RuleTable.RuleEntry.COLUMN_NAME_CHECK));
String ruleValue = cursor.getString( String ruleValue = cursor.getString(
cursor.getColumnIndexOrThrow(RuleTable.RuleEntry.COLUMN_NAME_VALUE)); cursor.getColumnIndexOrThrow(RuleTable.RuleEntry.COLUMN_NAME_VALUE));
String ruleSimSlot = cursor.getString(
cursor.getColumnIndexOrThrow(RuleTable.RuleEntry.COLUMN_NAME_SIM_SLOT));
String senderName = cursor.getString( String senderName = cursor.getString(
cursor.getColumnIndexOrThrow(SenderTable.SenderEntry.COLUMN_NAME_NAME)); cursor.getColumnIndexOrThrow(SenderTable.SenderEntry.COLUMN_NAME_NAME));
Integer senderType = cursor.getInt( Integer senderType = cursor.getInt(
cursor.getColumnIndexOrThrow(SenderTable.SenderEntry.COLUMN_NAME_TYPE)); cursor.getColumnIndexOrThrow(SenderTable.SenderEntry.COLUMN_NAME_TYPE));
String rule = RuleModel.getRuleMatch(ruleFiled, ruleCheck, ruleValue) + senderName; String rule = RuleModel.getRuleMatch(ruleFiled, ruleCheck, ruleValue, ruleSimSlot) + senderName.trim();
int senderImageId = SenderModel.getImageId(senderType); int senderImageId = SenderModel.getImageId(senderType);
LogVo logVo = new LogVo(itemid, itemfrom, content, simInfo, time, rule, senderImageId); LogVo logVo = new LogVo(itemid, itemfrom, content, simInfo, time, rule, senderImageId);

View File

@ -29,7 +29,6 @@ public class RuleUtil {
// Gets the data repository in write mode // Gets the data repository in write mode
db = dbHelper.getReadableDatabase(); db = dbHelper.getReadableDatabase();
} }
} }
public static long addRule(RuleModel ruleModel) { public static long addRule(RuleModel ruleModel) {
@ -40,6 +39,7 @@ public class RuleUtil {
values.put(RuleTable.RuleEntry.COLUMN_NAME_CHECK, ruleModel.getCheck()); values.put(RuleTable.RuleEntry.COLUMN_NAME_CHECK, ruleModel.getCheck());
values.put(RuleTable.RuleEntry.COLUMN_NAME_VALUE, ruleModel.getValue()); values.put(RuleTable.RuleEntry.COLUMN_NAME_VALUE, ruleModel.getValue());
values.put(RuleTable.RuleEntry.COLUMN_NAME_SENDER_ID, ruleModel.getSenderId()); values.put(RuleTable.RuleEntry.COLUMN_NAME_SENDER_ID, ruleModel.getSenderId());
values.put(RuleTable.RuleEntry.COLUMN_NAME_SIM_SLOT, ruleModel.getSimSlot());
// Insert the new row, returning the primary key value of the new row // Insert the new row, returning the primary key value of the new row
@ -55,6 +55,7 @@ public class RuleUtil {
values.put(RuleTable.RuleEntry.COLUMN_NAME_CHECK, ruleModel.getCheck()); values.put(RuleTable.RuleEntry.COLUMN_NAME_CHECK, ruleModel.getCheck());
values.put(RuleTable.RuleEntry.COLUMN_NAME_VALUE, ruleModel.getValue()); values.put(RuleTable.RuleEntry.COLUMN_NAME_VALUE, ruleModel.getValue());
values.put(RuleTable.RuleEntry.COLUMN_NAME_SENDER_ID, ruleModel.getSenderId()); values.put(RuleTable.RuleEntry.COLUMN_NAME_SENDER_ID, ruleModel.getSenderId());
values.put(RuleTable.RuleEntry.COLUMN_NAME_SIM_SLOT, ruleModel.getSimSlot());
String selection = RuleTable.RuleEntry._ID + " = ? "; String selection = RuleTable.RuleEntry._ID + " = ? ";
String[] whereArgs = {String.valueOf(ruleModel.getId())}; String[] whereArgs = {String.valueOf(ruleModel.getId())};
@ -89,10 +90,11 @@ public class RuleUtil {
RuleTable.RuleEntry.COLUMN_NAME_CHECK, RuleTable.RuleEntry.COLUMN_NAME_CHECK,
RuleTable.RuleEntry.COLUMN_NAME_VALUE, RuleTable.RuleEntry.COLUMN_NAME_VALUE,
RuleTable.RuleEntry.COLUMN_NAME_SENDER_ID, RuleTable.RuleEntry.COLUMN_NAME_SENDER_ID,
RuleTable.RuleEntry.COLUMN_NAME_TIME RuleTable.RuleEntry.COLUMN_NAME_TIME,
RuleTable.RuleEntry.COLUMN_NAME_SIM_SLOT,
}; };
// Define 'where' part of query. // Define 'where' part of query.
String selection = " 1 "; String selection = " 1 = 1 ";
// Specify arguments in placeholder order. // Specify arguments in placeholder order.
List<String> selectionArgList = new ArrayList<>(); List<String> selectionArgList = new ArrayList<>();
if (id != null) { if (id != null) {
@ -104,7 +106,11 @@ public class RuleUtil {
if (key != null) { if (key != null) {
// Define 'where' part of query. // Define 'where' part of query.
selection = " and (" + RuleTable.RuleEntry.COLUMN_NAME_VALUE + " LIKE ? "; if (key.equals("SIM1") || key.equals("SIM2")) {
selection += " and " + RuleTable.RuleEntry.COLUMN_NAME_SIM_SLOT + " IN ( 'ALL', ? ) ";
} else {
selection += " and " + RuleTable.RuleEntry.COLUMN_NAME_VALUE + " LIKE ? ";
}
// Specify arguments in placeholder order. // Specify arguments in placeholder order.
selectionArgList.add(key); selectionArgList.add(key);
} }
@ -138,6 +144,8 @@ public class RuleUtil {
cursor.getColumnIndexOrThrow(RuleTable.RuleEntry.COLUMN_NAME_SENDER_ID)); cursor.getColumnIndexOrThrow(RuleTable.RuleEntry.COLUMN_NAME_SENDER_ID));
long itemTime = cursor.getLong( long itemTime = cursor.getLong(
cursor.getColumnIndexOrThrow(RuleTable.RuleEntry.COLUMN_NAME_TIME)); cursor.getColumnIndexOrThrow(RuleTable.RuleEntry.COLUMN_NAME_TIME));
String itemSimSlot = cursor.getString(
cursor.getColumnIndexOrThrow(RuleTable.RuleEntry.COLUMN_NAME_SIM_SLOT));
Log.d(TAG, "getRule: itemId" + itemId); Log.d(TAG, "getRule: itemId" + itemId);
RuleModel ruleModel = new RuleModel(); RuleModel ruleModel = new RuleModel();
@ -147,6 +155,7 @@ public class RuleUtil {
ruleModel.setValue(itemValue); ruleModel.setValue(itemValue);
ruleModel.setSenderId(itemSenderId); ruleModel.setSenderId(itemSenderId);
ruleModel.setTime(itemTime); ruleModel.setTime(itemTime);
ruleModel.setSimSlot(itemSimSlot);
tRules.add(ruleModel); tRules.add(ruleModel);
} }

View File

@ -11,19 +11,66 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginLeft="10dp" android:layout_marginLeft="5dp"
android:layout_marginRight="10dp" android:layout_marginTop="5dp"
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="设置匹配的卡槽"
android:textStyle="bold" />
<RadioGroup
android:id="@+id/radioGroupSimSlot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left|center_vertical"
android:orientation="horizontal">
<RadioButton
android:id="@+id/btnSimSlotAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="全部"
android:textSize="13sp" />
<RadioButton
android:id="@+id/btnSimSlot1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SIM1"
android:textSize="13sp" />
<RadioButton
android:id="@+id/btnSimSlot2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SIM2"
android:textSize="13sp" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="设置匹配的字段" android:text="设置匹配的字段"
android:textStyle="bold" /> android:textStyle="bold" />
<RadioGroup <RadioGroup
android:id="@+id/radioGroupRuleFiled" android:id="@+id/radioGroupRuleFiled"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="horizontal">
@ -32,25 +79,29 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:checked="true" android:checked="true"
android:text="全部" /> android:text="全部"
android:textSize="13sp" />
<RadioButton <RadioButton
android:id="@+id/btnPhone" android:id="@+id/btnPhone"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="手机号" /> android:text="手机号"
android:textSize="13sp" />
<RadioButton <RadioButton
android:id="@+id/btnContent" android:id="@+id/btnContent"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="内容" /> android:text="内容"
android:textSize="13sp" />
<RadioButton <RadioButton
android:id="@+id/btnMultiMatch" android:id="@+id/btnMultiMatch"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="多重匹配" /> android:text="多重匹配"
android:textSize="13sp" />
</RadioGroup> </RadioGroup>
</LinearLayout> </LinearLayout>
@ -59,20 +110,22 @@
android:id="@+id/matchTypeLayout" android:id="@+id/matchTypeLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginLeft="10dp" android:layout_marginLeft="5dp"
android:layout_marginRight="10dp" android:layout_marginTop="5dp"
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="设置匹配的模式" android:text="设置匹配的模式"
android:textStyle="bold" /> android:textStyle="bold" />
<RadioGroup <RadioGroup
android:id="@+id/radioGroupRuleCheck" android:id="@+id/radioGroupRuleCheck"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="left|center_vertical"
android:orientation="horizontal"> android:orientation="horizontal">
<RadioButton <RadioButton
@ -80,31 +133,36 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:checked="true" android:checked="true"
android:text="是" /> android:text="是"
android:textSize="13sp" />
<RadioButton <RadioButton
android:id="@+id/btnNotIs" android:id="@+id/btnNotIs"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="不是" /> android:text="不是"
android:textSize="13sp" />
<RadioButton <RadioButton
android:id="@+id/btnContain" android:id="@+id/btnContain"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="包含" /> android:text="包含"
android:textSize="13sp" />
<RadioButton <RadioButton
android:id="@+id/btnStartWith" android:id="@+id/btnStartWith"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="开头" /> android:text="开头"
android:textSize="13sp" />
<RadioButton <RadioButton
android:id="@+id/btnEndWith" android:id="@+id/btnEndWith"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="结尾" /> android:text="结尾"
android:textSize="13sp" />
</RadioGroup> </RadioGroup>
</LinearLayout> </LinearLayout>
@ -113,19 +171,20 @@
android:id="@+id/matchValueLayout" android:id="@+id/matchValueLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginLeft="10dp" android:layout_marginLeft="5dp"
android:layout_marginRight="10dp" android:layout_marginTop="5dp"
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="设置匹配的值" android:text="设置匹配的值"
android:textStyle="bold" /> android:textStyle="bold" />
<EditText <EditText
android:id="@+id/editTextRuleValue" android:id="@+id/editTextRuleValue"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ems="14" android:ems="14"
android:inputType="" android:inputType=""
@ -133,7 +192,7 @@
<TextView <TextView
android:id="@+id/tv_mu_rule_tips" android:id="@+id/tv_mu_rule_tips"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="3dp" android:layout_margin="3dp"
android:text=" android:text="
@ -152,11 +211,12 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" android:layout_marginTop="5dp"
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="设置发送方" android:text="设置发送方"
android:textStyle="bold" /> android:textStyle="bold" />
@ -178,7 +238,7 @@
android:id="@+id/ruleSenderTv" android:id="@+id/ruleSenderTv"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="10dp" android:layout_marginLeft="5dp"
android:text="" /> android:text="" />
</LinearLayout> </LinearLayout>
@ -188,7 +248,7 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_margin="10dp" android:layout_margin="5dp"
android:orientation="horizontal"> android:orientation="horizontal">
<Button <Button
@ -217,4 +277,5 @@
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>

View File

@ -18,7 +18,36 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="3dp" android:layout_margin="3dp"
android:text="测试模拟的手机号" /> android:text="测试模拟的接收卡槽" />
<RadioGroup
android:id="@+id/radioGroupTestSimSlot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:gravity="left|center_vertical"
android:orientation="horizontal">
<RadioButton
android:id="@+id/btnSimSlot1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="SIM1" />
<RadioButton
android:id="@+id/btnSimSlot2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SIM2" />
</RadioGroup>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:text="测试模拟的来源号码" />
<EditText <EditText