-
Notifications
You must be signed in to change notification settings - Fork 6
/
ServiceStateTracker.java_a4576dc529d3ac175b6bb427d05ed276.patch
153 lines (149 loc) · 6.91 KB
/
ServiceStateTracker.java_a4576dc529d3ac175b6bb427d05ed276.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
--- /home/haohuang/backup/aosp13-TP1A.221005.002/frameworks/opt/telephony/src/java/com/android/internal/telephony/ServiceStateTracker.java 2023-03-07 20:02:54.828250868 +0000
+++ /home/haohuang/aosp13-TP1A.221005.002/frameworks/opt/telephony/src/java/com/android/internal/telephony/ServiceStateTracker.java 2023-03-06 21:01:43.605671581 +0000
@@ -131,6 +131,11 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;
+import android.telephony.CellIdentityNr;
+import android.telephony.CellState;
+import com.android.internal.telephony.OperatorInfo;
+import com.android.internal.telephony.RILDefender;
+
/**
* {@hide}
*/
@@ -655,6 +660,16 @@
mCi.registerForCellInfoList(this, EVENT_UNSOL_CELL_INFO_LIST, null);
mCi.registerForPhysicalChannelConfiguration(this, EVENT_PHYSICAL_CHANNEL_CONFIG, null);
+ // RILDefender
+ // init shared preferences
+ RILDefender.initSp(phone.getContext());
+ // RILDefender: register broadcast receiver for SP update
+ IntentFilter mFilter = new IntentFilter();
+ mFilter.addAction(RILDefender.ACTION_UPDATE_SP);
+ mFilter.addAction(RILDefender.ACTION_UPDATE_SOURCE);
+ mFilter.addAction(RILDefender.ACTION_UPDATE_YAML);
+ phone.getContext().registerReceiver(RILDefender.mSpReceiver, mFilter);
+
mSubscriptionController = SubscriptionController.getInstance();
mSubscriptionManager = SubscriptionManager.from(phone.getContext());
mSubscriptionManager.addOnSubscriptionsChangedListener(
@@ -1243,6 +1258,42 @@
loge("Invalid CellInfo result");
} else {
cellInfo = (List<CellInfo>) ar.result;
+
+ for (CellInfo ci: cellInfo) {
+ CellIdentity cellId = ci.getCellIdentity();
+ int arfcn = getArfcnFromCellIdentity(cellId);
+ int cid = (int) getCidFromCellIdentity(cellId);
+ int ss = ci.getCellSignalStrength().getDbm();
+
+ CellState cellState = new CellState();
+ cellState.initFromCellIdentity(cellId);
+ cellState.updateSignalStrength(ss);
+
+ if (!cellState.isValid()) {
+ // android will sometimes scan incomplete info, skip it...
+ continue;
+ }
+
+ List<CellState> historyStates = RILDefender.historyStates;
+
+ boolean witness = false;
+ for (CellState hcs: historyStates) {
+ if (hcs.equals(cellState)) {
+ // found in history
+ witness = true;
+ // update signal strength if seen
+ hcs.updateSignalStrength(ss);
+ break;
+ }
+ }
+
+ if (!witness) {
+ Rlog.d("RILDefender", "Found new cell " + cellState);
+ // add cell info to history
+ RILDefender.addState(cellState);
+ }
+ }
+
updateOperatorNameForCellInfo(cellInfo);
mLastCellInfoList = cellInfo;
mPhone.notifyCellInfo(cellInfo);
@@ -2512,6 +2563,39 @@
}
}
+ private static int getLacFromCellIdentity(CellIdentity id) {
+ if (id == null) return -1;
+ int lac = -1;
+ switch(id.getType()) {
+ case CellInfo.TYPE_GSM: lac = ((CellIdentityGsm) id).getLac(); break;
+ case CellInfo.TYPE_WCDMA: lac = ((CellIdentityWcdma) id).getLac(); break;
+ case CellInfo.TYPE_TDSCDMA: lac = ((CellIdentityTdscdma) id).getLac(); break;
+ case CellInfo.TYPE_LTE: lac = ((CellIdentityLte) id).getTac(); break;
+ case CellInfo.TYPE_NR: lac = ((CellIdentityNr) id).getTac(); break;
+ default: break;
+ }
+ if (lac == Integer.MAX_VALUE) lac = -1;
+
+ return lac;
+ }
+
+ private static int getArfcnFromCellIdentity(CellIdentity id) {
+ if (id == null) return -1;
+ int arfcn = -1;
+ switch(id.getType()) {
+ case CellInfo.TYPE_GSM: arfcn = ((CellIdentityGsm) id).getArfcn(); break;
+ case CellInfo.TYPE_WCDMA: arfcn = ((CellIdentityWcdma) id).getUarfcn(); break;
+ case CellInfo.TYPE_TDSCDMA: arfcn = ((CellIdentityTdscdma) id).getUarfcn(); break;
+ case CellInfo.TYPE_LTE: arfcn = ((CellIdentityLte) id).getEarfcn(); break;
+ case CellInfo.TYPE_NR: arfcn = ((CellIdentityNr) id).getNrarfcn(); break;
+ default: break;
+ }
+ if (arfcn == Integer.MAX_VALUE) arfcn = -1;
+
+ return arfcn;
+ }
+
+
private void setPhyCellInfoFromCellIdentity(ServiceState ss, CellIdentity cellIdentity) {
if (cellIdentity == null) {
if (DBG) {
@@ -3621,6 +3705,14 @@
&& (newWwanDataRat <= ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_A));
}
+ if (hasChanged) {
+ // RILDefender: update current cell state if info not complete
+ if (RILDefender.getCurrentCellState() != null && !RILDefender.getCurrentCellState().isValid()) {
+ RILDefender.getCurrentCellState().initFromCellIdentity(primaryCellIdentity);
+ Rlog.d("RILDefender", "Updated new cell: " + RILDefender.mCurrentCellState);
+ }
+ }
+
if (DBG) {
log("pollStateDone:"
+ " hasRegistered = " + hasRegistered
@@ -3668,6 +3760,23 @@
EventLog.writeEvent(EventLogTags.GSM_RAT_SWITCHED_NEW, cid,
mSS.getRilVoiceRadioTechnology(),
mNewSS.getRilVoiceRadioTechnology());
+
+ // RILDefender network has switched to a new cell
+ CellState cellState = new CellState();
+ cellState.initFromCellIdentity(primaryCellIdentity);
+ cellState.setOperatorNumeric(mNewSS.getOperatorNumeric());
+ cellState.setOperatorAlphaLong(mNewSS.getOperatorAlphaLong());
+ cellState.setOperatorAlphaShort(mNewSS.getOperatorAlphaShort());
+
+ // set current cell state
+ RILDefender.mCurrentCellState = cellState;
+
+ // start a blank signal history
+ RILDefender.clearSignals();
+
+ RILDefender.addState(cellState);
+ Rlog.d("RILDefender", "New cell connected: " + cellState);
+
if (DBG) {
log("RAT switched "
+ ServiceState.rilRadioTechnologyToString(