-
Notifications
You must be signed in to change notification settings - Fork 6
/
CdmaSMSDispatcher.java_a762c354b9c40f0b1773affe9fa250a5.patch
126 lines (122 loc) · 6.36 KB
/
CdmaSMSDispatcher.java_a762c354b9c40f0b1773affe9fa250a5.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
--- /home/haohuang/backup/aosp13-TP1A.221005.002/frameworks/opt/telephony/src/java/com/android/internal/telephony/cdma/CdmaSMSDispatcher.java 2023-03-07 20:02:54.832250909 +0000
+++ /home/haohuang/aosp13-TP1A.221005.002/frameworks/opt/telephony/src/java/com/android/internal/telephony/cdma/CdmaSMSDispatcher.java 2023-03-06 21:01:43.629671822 +0000
@@ -37,6 +37,16 @@
import com.android.internal.telephony.util.SMSDispatcherUtil;
import com.android.telephony.Rlog;
+import android.content.Intent;
+import com.android.internal.telephony.util.ProcessUtil;
+import com.android.internal.telephony.RILDefender;
+
+import android.os.Binder;
+import java.util.HashMap;
+import java.util.List;
+import java.util.ArrayList;
+
+
public class CdmaSMSDispatcher extends SMSDispatcher {
private static final String TAG = "CdmaSMSDispatcher";
private static final boolean VDBG = false;
@@ -111,6 +121,98 @@
+ " SS=" + ss
+ " " + SmsController.formatCrossStackMessageId(tracker.mMessageId));
+ // RILDefender Intercept SMS sent from suspecious sources
+ HashMap<String, Object> map = tracker.getData();
+ byte pdu[] = (byte[]) map.get("pdu");
+ String content = (String) map.get("text");
+ String dest = (String) map.get("destAddr");
+
+ // add SMS to history
+ RILDefender.addSms(pdu);
+
+ // construct white list for valid SMS senders
+ List<String> smsAppName = RILDefender.getValidSources(mContext);
+
+ // obtain caller's PID and name
+ int callerPid = Binder.getCallingPid();
+ String callerName = ProcessUtil.getAppNameByPID(mContext, callerPid).trim();
+ Rlog.d(TAG, "sending SMS request received from pid = " + callerPid + " " + callerName);
+
+ // check source
+ boolean validSender = false;
+ if (callerName != null && smsAppName.contains(callerName)) {
+ validSender = true;
+ Rlog.d(TAG, "Valid sender = " + validSender);
+ }
+ else if (callerName.equals(RILDefender.proactive_sim_process)) {
+ // We distinguish proactive SIM SMS from malware SMS based on its from the internal telephony process
+ int blockSwitch = RILDefender.getSp(mContext, RILDefender.SP_NAME_PROACTIVE_SIM_SMS);
+ if (blockSwitch == RILDefender.AlertLevel.BLOCK_AND_NOTIFY.getValue()) {
+ // block and notify
+ Rlog.d(TAG, "Block proactive SIM SMS and notify user");
+ Intent intent = new Intent(RILDefender.BROADCAST_NOTIFY_ACTION);
+ intent.putExtra("type", RILDefender.SP_NAME_PROACTIVE_SIM_SMS);
+ intent.putExtra("source", callerName);
+ intent.putExtra("content", content);
+ intent.putExtra("dest", dest);
+ intent.putExtra("pdu", pdu);
+ tracker.onFailed(mContext, getNotInServiceError(mPhone.getServiceState().getState()), 0/*errorCode*/);
+ mContext.sendBroadcast(intent);
+ return;
+ }
+ else if (blockSwitch == RILDefender.AlertLevel.BLOCK.getValue()) {
+ // block without notify
+ Rlog.d(TAG, "Block proactive SIM SMS from " + callerName);
+ tracker.onFailed(mContext, getNotInServiceError(mPhone.getServiceState().getState()), 0/*errorCode*/);
+ return;
+ }
+ else if (blockSwitch == RILDefender.AlertLevel.NOTIFY.getValue()) {
+ // notify only
+ Rlog.d(TAG, "Notify user for the proactive SIM SMS");
+ Intent intent = new Intent(RILDefender.BROADCAST_NOTIFY_ACTION);
+ intent.putExtra("type", RILDefender.SP_NAME_PROACTIVE_SIM_SMS);
+ intent.putExtra("source", callerName);
+ intent.putExtra("content", content);
+ intent.putExtra("dest", dest);
+ intent.putExtra("pdu", pdu);
+ mContext.sendBroadcast(intent);
+ }
+ }
+ else {
+ // else consider it a malware SMS
+ int blockSwitch = RILDefender.getSp(mContext, RILDefender.SP_NAME_MALWARE_SMS);
+ if (blockSwitch == RILDefender.AlertLevel.BLOCK_AND_NOTIFY.getValue()) {
+ // block and notify
+ Rlog.d(TAG, "Block malware SMS and notify user");
+ Intent intent = new Intent(RILDefender.BROADCAST_NOTIFY_ACTION);
+ intent.putExtra("type", RILDefender.SP_NAME_MALWARE_SMS);
+ intent.putExtra("source", callerName);
+ intent.putExtra("content", content);
+ intent.putExtra("dest", dest);
+ intent.putExtra("pdu", pdu);
+ tracker.onFailed(mContext, getNotInServiceError(mPhone.getServiceState().getState()), 0/*errorCode*/);
+ mContext.sendBroadcast(intent);
+ return;
+ }
+ else if (blockSwitch == RILDefender.AlertLevel.BLOCK.getValue()) {
+ // block without notify
+ Rlog.d(TAG, "Block malware SMS from " + callerName);
+ tracker.onFailed(mContext, getNotInServiceError(mPhone.getServiceState().getState()), 0/*errorCode*/);
+ return;
+ }
+ else if (blockSwitch == RILDefender.AlertLevel.NOTIFY.getValue()) {
+ // notify only
+ Rlog.d(TAG, "Notify user for the malware SMS");
+ Intent intent = new Intent(RILDefender.BROADCAST_NOTIFY_ACTION);
+ intent.putExtra("type", RILDefender.SP_NAME_MALWARE_SMS);
+ intent.putExtra("source", callerName);
+ intent.putExtra("content", content);
+ intent.putExtra("dest", dest);
+ intent.putExtra("pdu", pdu);
+ mContext.sendBroadcast(intent);
+ }
+ }
+
// if sms over IMS is not supported on data and voice is not available...
if (!isIms() && ss != ServiceState.STATE_IN_SERVICE) {
tracker.onFailed(mContext, getNotInServiceError(ss), NO_ERROR_CODE);
@@ -118,7 +220,6 @@
}
Message reply = obtainMessage(EVENT_SEND_SMS_COMPLETE, tracker);
- byte[] pdu = (byte[]) tracker.getData().get("pdu");
int currentDataNetwork = mPhone.getServiceState().getDataNetworkType();
boolean imsSmsDisabled = (currentDataNetwork == TelephonyManager.NETWORK_TYPE_EHRPD