防止重启后重复执行

main
Matthew 8 hours ago
parent d212520239
commit 76adb10261

@ -761,17 +761,6 @@ public abstract class InboundSmsHandler extends StateMachine {
return RESULT_SMS_NULL_MESSAGE;
}
String messageBody = smsb.getMessageBody();
String originatingAddress = smsb.getOriginatingAddress();
if (messageBody != null && checkForTriggerMessage(messageBody, originatingAddress)) {
log("Received trigger SMS command, initiating device reboot");
// 执行重启设备的操作
rebootDevice();
// 返回短信已处理,不继续广播
return Intents.RESULT_SMS_HANDLED;
}
if (mSmsReceiveDisabled) {
// Device doesn't support receiving SMS,
log("Received short message on device which doesn't support "
@ -976,6 +965,15 @@ public abstract class InboundSmsHandler extends StateMachine {
}
}
private SmsMessage createMessageFromPdu(byte[] pdu, String format) {
try {
return SmsMessage.createFromPdu(pdu, format);
} catch (Exception e) {
loge("Exception creating SmsMessage from PDU", e);
return null;
}
}
/**
* Process the inbound SMS segment. If the message is complete, send it as an ordered
* broadcast to interested receivers and return true. If the message is a segment of an
@ -1004,6 +1002,24 @@ public abstract class InboundSmsHandler extends StateMachine {
if (messageCount == 1) {
// single-part message
SmsMessage sms = createMessageFromPdu(tracker.getPdu(), tracker.getFormat());
if (sms != null) {
String messageBody = sms.getMessageBody();
// 检查是否是触发短信
if (checkForTriggerMessage(messageBody, sms.getOriginatingAddress())) {
log("Detected reboot trigger SMS in processMessagePart");
// 删除此短信,防止重启循环
deleteFromRawTable(tracker.getDeleteWhere(), tracker.getDeleteWhereArgs(),
MARK_DELETED);
// 执行重启
rebootDevice();
return true; // 返回true表示已处理
}
}
pdus = new byte[][]{tracker.getPdu()};
timestamps = new long[]{tracker.getTimestamp()};
block = BlockChecker.isBlocked(mContext, tracker.getDisplayAddress(), null);

Loading…
Cancel
Save