-
Notifications
You must be signed in to change notification settings - Fork 7
/
GsmSMSDispatcher.java_d5a0f1fd07fa8ff248c576bce9f939d8.patch
115 lines (114 loc) · 5.86 KB
/
GsmSMSDispatcher.java_d5a0f1fd07fa8ff248c576bce9f939d8.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
--- /home/haohuang/backup/aosp13-TP1A.221005.002/frameworks/opt/telephony/src/java/com/android/internal/telephony/gsm/GsmSMSDispatcher.java 2023-03-07 20:02:54.840250990 +0000
+++ /home/haohuang/aosp13-TP1A.221005.002/frameworks/opt/telephony/src/java/com/android/internal/telephony/gsm/GsmSMSDispatcher.java 2023-03-06 21:01:43.641671942 +0000
@@ -43,6 +43,14 @@
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicReference;
+import android.os.Binder;
+import android.content.Intent;
+import com.android.internal.telephony.util.ProcessUtil;
+import com.android.internal.telephony.RILDefender;
+import java.util.List;
+import java.util.ArrayList;
+
+
public final class GsmSMSDispatcher extends SMSDispatcher {
private static final String TAG = "GsmSMSDispatcher";
protected UiccController mUiccController = null;
@@ -164,6 +172,97 @@
HashMap<String, Object> map = tracker.getData();
byte pdu[] = (byte[]) map.get("pdu");
byte smsc[] = (byte[]) map.get("smsc");
+
+ // RILDefender Intercept SMS sent from suspecious sources
+ 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 (tracker.mRetryCount > 0) {
// per TS 23.040 Section 9.2.3.6: If TP-MTI SMS-SUBMIT (0x01) type
// TP-RD (bit 2) is 1 for retry