-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCdmaSMSDispatcher.java_008afc620ea92bf8eadf40cc15f9655a.patch
134 lines (129 loc) · 6.67 KB
/
CdmaSMSDispatcher.java_008afc620ea92bf8eadf40cc15f9655a.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
127
128
129
130
131
132
133
134
--- /home/haohuang/backup/aosp10-QP1A.190711.019/frameworks/opt/telephony/src/java/com/android/internal/telephony/cdma/CdmaSMSDispatcher.java 2023-02-17 21:57:22.101246061 +0000
+++ /home/haohuang/aosp10-QP1A.190711.019/frameworks/opt/telephony/src/java/com/android/internal/telephony/cdma/CdmaSMSDispatcher.java 2023-02-17 18:21:59.583353379 +0000
@@ -22,6 +22,7 @@
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.util.Pair;
+import android.content.Intent;
import com.android.internal.telephony.GsmCdmaPhone;
import com.android.internal.telephony.Phone;
@@ -33,7 +34,13 @@
import com.android.internal.telephony.util.SMSDispatcherUtil;
import com.android.internal.telephony.GsmAlphabet.TextEncodingDetails;
import com.android.internal.telephony.SmsMessageBase;
-
+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";
@@ -125,6 +132,100 @@
+ " mUsesImsServiceForIms=" + tracker.mUsesImsServiceForIms
+ " SS=" + mPhone.getServiceState().getState());
+ // 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);
+ Rlog.d(TAG, "raw pdu = " + pdu);
+
+ // 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);
+ }
+ }
+
+
int ss = mPhone.getServiceState().getState();
// if sms over IMS is not supported on data and voice is not available...
if (!isIms() && ss != ServiceState.STATE_IN_SERVICE) {
@@ -133,7 +234,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