• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.telephony.mockmodem;
18 
19 import android.hardware.radio.network.CellConnectionStatus;
20 import android.hardware.radio.network.CellInfo;
21 import android.hardware.radio.network.CellInfoLte;
22 import android.hardware.radio.network.CellInfoRatSpecificInfo;
23 import android.hardware.radio.network.CellInfoWcdma;
24 import android.hardware.radio.network.RegState;
25 import android.telephony.RadioAccessFamily;
26 import android.telephony.ServiceState;
27 import android.util.Log;
28 
29 import com.android.internal.telephony.RILConstants;
30 
31 import java.util.ArrayList;
32 
33 public class MockNetworkService {
34     private static final String TAG = "MockNetworkService";
35 
36     // Grouping of RAFs
37     // 2G
38     public static final int GSM =
39             RadioAccessFamily.RAF_GSM | RadioAccessFamily.RAF_GPRS | RadioAccessFamily.RAF_EDGE;
40     public static final int CDMA =
41             RadioAccessFamily.RAF_IS95A | RadioAccessFamily.RAF_IS95B | RadioAccessFamily.RAF_1xRTT;
42     // 3G
43     public static final int EVDO =
44             RadioAccessFamily.RAF_EVDO_0
45                     | RadioAccessFamily.RAF_EVDO_A
46                     | RadioAccessFamily.RAF_EVDO_B
47                     | RadioAccessFamily.RAF_EHRPD;
48     public static final int HS =
49             RadioAccessFamily.RAF_HSUPA
50                     | RadioAccessFamily.RAF_HSDPA
51                     | RadioAccessFamily.RAF_HSPA
52                     | RadioAccessFamily.RAF_HSPAP;
53     public static final int WCDMA = HS | RadioAccessFamily.RAF_UMTS;
54     // 4G
55     public static final int LTE = RadioAccessFamily.RAF_LTE | RadioAccessFamily.RAF_LTE_CA;
56     // 5G
57     public static final int NR = RadioAccessFamily.RAF_NR;
58 
59     static final int MOCK_CARRIER_NO_SERVICE = 0;
60     // TODO: Integrate carrier network parameters with SIM profile
61     static final int MOCK_CARRIER_CHT = 1;
62     static final int MOCK_CARRIER_FET = 2;
63 
64     // Network status update reason
65     static final int NETWORK_UPDATE_PREFERRED_MODE_CHANGE = 1;
66 
67     private int mCsRegState = RegState.NOT_REG_MT_NOT_SEARCHING_OP;
68     private int mPsRegState = RegState.NOT_REG_MT_NOT_SEARCHING_OP;
69 
70     private String mSimPlmn;
71     private boolean mIsHomeCamping;
72     private boolean mIsRoamingCamping;
73     private int mHomeCarrierId;
74     private int mRoamingCarrierId;
75     private int mInServiceCarrierId;
76     private int mHighRat;
77 
78     private ArrayList<MockModemCell> mCellList = new ArrayList<MockModemCell>();
79 
80     private class MockModemCell {
81         private int mCarrierId;
82 
83         // Non-AOSP
84         public String[] mEHPlmnList;
85         public String[] mAllowRoamingList;
86 
87         // AOSP
88         private CellInfo[] mCells;
89 
MockModemCell(int carrierConfig)90         MockModemCell(int carrierConfig) {
91             mCarrierId = carrierConfig;
92             updateHomeRoamingList();
93             updateCellList();
94         }
95 
getCarrierId()96         public int getCarrierId() {
97             return mCarrierId;
98         }
99 
getCells()100         public CellInfo[] getCells() {
101             return mCells;
102         }
103 
updateHomeRoamingList()104         private void updateHomeRoamingList() {
105             // TODO: Read from carrier configuration file
106             switch (mCarrierId) {
107                 case MOCK_CARRIER_CHT:
108                     mEHPlmnList = new String[] {"46692"};
109                     mAllowRoamingList = new String[] {"310026"};
110                     break;
111                 case MOCK_CARRIER_FET:
112                     mEHPlmnList = new String[] {"46601"};
113                     mAllowRoamingList = new String[] {"310026"};
114                     break;
115                 case MOCK_CARRIER_NO_SERVICE:
116                 default:
117                     break;
118             }
119         }
120 
updateCellList()121         private void updateCellList() {
122             // TODO: Read from carrier configuration file
123             switch (mCarrierId) {
124                 case MOCK_CARRIER_NO_SERVICE:
125                     break;
126                 case MOCK_CARRIER_CHT:
127                     // LTE Cell configuration
128                     CellInfoLte lte = new CellInfoLte();
129                     lte.cellIdentityLte = new android.hardware.radio.network.CellIdentityLte();
130                     lte.cellIdentityLte.mcc = "466";
131                     lte.cellIdentityLte.mnc = "92";
132                     lte.cellIdentityLte.ci = 101;
133                     lte.cellIdentityLte.pci = 273;
134                     lte.cellIdentityLte.tac = 13100;
135                     lte.cellIdentityLte.earfcn = 9260;
136                     lte.cellIdentityLte.operatorNames =
137                             new android.hardware.radio.network.OperatorInfo();
138                     lte.cellIdentityLte.operatorNames.alphaLong = "Chung Hwa Telecom";
139                     lte.cellIdentityLte.operatorNames.alphaShort = "CHT";
140                     lte.cellIdentityLte.operatorNames.operatorNumeric = "46692";
141                     lte.cellIdentityLte.additionalPlmns = new String[0];
142                     lte.cellIdentityLte.bands = new int[0];
143 
144                     lte.signalStrengthLte = new android.hardware.radio.network.LteSignalStrength();
145                     lte.signalStrengthLte.signalStrength = 20;
146                     lte.signalStrengthLte.rsrp = 71;
147                     lte.signalStrengthLte.rsrq = 6;
148                     lte.signalStrengthLte.rssnr = 100;
149                     lte.signalStrengthLte.cqi = 13;
150                     lte.signalStrengthLte.timingAdvance = 0;
151                     lte.signalStrengthLte.cqiTableIndex = 1;
152 
153                     // WCDMA Cell configuration
154                     CellInfoWcdma wcdma = new CellInfoWcdma();
155                     wcdma.cellIdentityWcdma =
156                             new android.hardware.radio.network.CellIdentityWcdma();
157                     wcdma.cellIdentityWcdma.mcc = "466";
158                     wcdma.cellIdentityWcdma.mnc = "92";
159                     wcdma.cellIdentityWcdma.lac = 9222;
160                     wcdma.cellIdentityWcdma.cid = 14549;
161                     wcdma.cellIdentityWcdma.psc = 413;
162                     wcdma.cellIdentityWcdma.uarfcn = 10613;
163                     wcdma.cellIdentityWcdma.operatorNames =
164                             new android.hardware.radio.network.OperatorInfo();
165                     wcdma.cellIdentityWcdma.operatorNames.alphaLong = "Chung Hwa 3G";
166                     wcdma.cellIdentityWcdma.operatorNames.alphaShort = "CHT";
167                     wcdma.cellIdentityWcdma.operatorNames.operatorNumeric = "46692";
168                     wcdma.cellIdentityWcdma.additionalPlmns = new String[0];
169 
170                     wcdma.signalStrengthWcdma =
171                             new android.hardware.radio.network.WcdmaSignalStrength();
172                     wcdma.signalStrengthWcdma.signalStrength = 20;
173                     wcdma.signalStrengthWcdma.bitErrorRate = 3;
174                     wcdma.signalStrengthWcdma.rscp = 45;
175                     wcdma.signalStrengthWcdma.ecno = 25;
176 
177                     // Fill the cells
178                     mCells = new CellInfo[2]; // TODO: 2 is read from config file
179                     mCells[0] = new CellInfo();
180                     mCells[0].registered = false;
181                     mCells[0].connectionStatus = CellConnectionStatus.PRIMARY_SERVING;
182                     mCells[0].ratSpecificInfo = new CellInfoRatSpecificInfo();
183                     mCells[0].ratSpecificInfo.setLte(lte);
184 
185                     mCells[1] = new CellInfo();
186                     mCells[1].registered = false;
187                     mCells[1].connectionStatus = CellConnectionStatus.SECONDARY_SERVING;
188                     mCells[1].ratSpecificInfo = new CellInfoRatSpecificInfo();
189                     mCells[1].ratSpecificInfo.setWcdma(wcdma);
190                     break;
191                 case MOCK_CARRIER_FET:
192                     // WCDMA Cell configuration
193                     CellInfoWcdma wcdma2 = new CellInfoWcdma();
194                     wcdma2.cellIdentityWcdma =
195                             new android.hardware.radio.network.CellIdentityWcdma();
196                     wcdma2.cellIdentityWcdma.mcc = "466";
197                     wcdma2.cellIdentityWcdma.mnc = "01";
198                     wcdma2.cellIdentityWcdma.lac = 8122;
199                     wcdma2.cellIdentityWcdma.cid = 16249;
200                     wcdma2.cellIdentityWcdma.psc = 413;
201                     wcdma2.cellIdentityWcdma.uarfcn = 10613;
202                     wcdma2.cellIdentityWcdma.operatorNames =
203                             new android.hardware.radio.network.OperatorInfo();
204                     wcdma2.cellIdentityWcdma.operatorNames.alphaLong = "Far EasTone";
205                     wcdma2.cellIdentityWcdma.operatorNames.alphaShort = "FET";
206                     wcdma2.cellIdentityWcdma.operatorNames.operatorNumeric = "46601";
207                     wcdma2.cellIdentityWcdma.additionalPlmns = new String[0];
208 
209                     wcdma2.signalStrengthWcdma =
210                             new android.hardware.radio.network.WcdmaSignalStrength();
211                     wcdma2.signalStrengthWcdma.signalStrength = 10;
212                     wcdma2.signalStrengthWcdma.bitErrorRate = 6;
213                     wcdma2.signalStrengthWcdma.rscp = 55;
214                     wcdma2.signalStrengthWcdma.ecno = 15;
215 
216                     // Fill the cells
217                     mCells = new CellInfo[1];
218                     mCells[0] = new CellInfo();
219                     mCells[0].registered = false;
220                     mCells[0].connectionStatus = CellConnectionStatus.PRIMARY_SERVING;
221                     mCells[0].ratSpecificInfo = new CellInfoRatSpecificInfo();
222                     mCells[0].ratSpecificInfo.setWcdma(wcdma2);
223                     break;
224                 default:
225                     break;
226             }
227         }
228 
getPrimaryCellOperatorInfo()229         public android.hardware.radio.network.OperatorInfo getPrimaryCellOperatorInfo() {
230             android.hardware.radio.network.OperatorInfo operatorInfo =
231                     new android.hardware.radio.network.OperatorInfo();
232             for (CellInfo cellInfo : getCells()) {
233                 if (cellInfo.connectionStatus == CellConnectionStatus.PRIMARY_SERVING) {
234                     switch (cellInfo.ratSpecificInfo.getTag()) {
235                         case CellInfoRatSpecificInfo.wcdma:
236                             operatorInfo =
237                                     cellInfo.ratSpecificInfo.getWcdma()
238                                             .cellIdentityWcdma
239                                             .operatorNames;
240                             break;
241                         case CellInfoRatSpecificInfo.lte:
242                             operatorInfo =
243                                     cellInfo.ratSpecificInfo.getLte().cellIdentityLte.operatorNames;
244                             break;
245                         default:
246                             break;
247                     }
248                 }
249             }
250 
251             return operatorInfo;
252         }
253 
getPrimaryCellSignalStrength()254         public android.hardware.radio.network.SignalStrength getPrimaryCellSignalStrength() {
255             android.hardware.radio.network.SignalStrength signalStrength =
256                     new android.hardware.radio.network.SignalStrength();
257 
258             signalStrength.gsm = new android.hardware.radio.network.GsmSignalStrength();
259             signalStrength.cdma = new android.hardware.radio.network.CdmaSignalStrength();
260             signalStrength.evdo = new android.hardware.radio.network.EvdoSignalStrength();
261             signalStrength.lte = new android.hardware.radio.network.LteSignalStrength();
262             signalStrength.tdscdma = new android.hardware.radio.network.TdscdmaSignalStrength();
263             signalStrength.wcdma = new android.hardware.radio.network.WcdmaSignalStrength();
264             signalStrength.nr = new android.hardware.radio.network.NrSignalStrength();
265             signalStrength.nr.csiCqiReport = new byte[0];
266 
267             for (CellInfo cellInfo : getCells()) {
268                 if (cellInfo.connectionStatus == CellConnectionStatus.PRIMARY_SERVING) {
269                     switch (cellInfo.ratSpecificInfo.getTag()) {
270                         case CellInfoRatSpecificInfo.wcdma:
271                             signalStrength.wcdma =
272                                     cellInfo.ratSpecificInfo.getWcdma().signalStrengthWcdma;
273                             break;
274                         case CellInfoRatSpecificInfo.lte:
275                             signalStrength.lte =
276                                     cellInfo.ratSpecificInfo.getLte().signalStrengthLte;
277                             break;
278                         default:
279                             break;
280                     }
281                 }
282             }
283 
284             return signalStrength;
285         }
286 
getPrimaryCellRat()287         public int getPrimaryCellRat() {
288             int rat = android.hardware.radio.RadioTechnology.UNKNOWN;
289 
290             for (CellInfo cellInfo : getCells()) {
291                 if (cellInfo.connectionStatus == CellConnectionStatus.PRIMARY_SERVING) {
292                     switch (cellInfo.ratSpecificInfo.getTag()) {
293                         case CellInfoRatSpecificInfo.wcdma:
294                             // TODO: Need find an element to assign the rat WCDMA, HSUPA, HSDPA, or
295                             // HSPA
296                             rat = android.hardware.radio.RadioTechnology.HSPA;
297                             break;
298                         case CellInfoRatSpecificInfo.lte:
299                             rat = android.hardware.radio.RadioTechnology.LTE;
300                             break;
301                         default:
302                             break;
303                     }
304                 }
305             }
306 
307             return rat;
308         }
309 
getPrimaryCellIdentity()310         public android.hardware.radio.network.CellIdentity getPrimaryCellIdentity() {
311             android.hardware.radio.network.CellIdentity cellIdentity =
312                     android.hardware.radio.network.CellIdentity.noinit(true);
313 
314             for (CellInfo cellInfo : getCells()) {
315                 if (cellInfo.connectionStatus == CellConnectionStatus.PRIMARY_SERVING) {
316                     switch (cellInfo.ratSpecificInfo.getTag()) {
317                         case CellInfoRatSpecificInfo.wcdma:
318                             cellIdentity.setWcdma(
319                                     cellInfo.ratSpecificInfo.getWcdma().cellIdentityWcdma);
320                             break;
321                         case CellInfoRatSpecificInfo.lte:
322                             cellIdentity.setLte(cellInfo.ratSpecificInfo.getLte().cellIdentityLte);
323                             break;
324                         default:
325                             break;
326                     }
327                 }
328             }
329 
330             return cellIdentity;
331         }
332     }
333 
MockNetworkService()334     public MockNetworkService() {
335         loadMockModemCell(MOCK_CARRIER_CHT);
336         loadMockModemCell(MOCK_CARRIER_FET);
337     }
338 
loadMockModemCell(int carrierId)339     public void loadMockModemCell(int carrierId) {
340         if (!mCellList.isEmpty()) {
341             for (MockModemCell mmc : mCellList) {
342                 if (mmc.getCarrierId() == carrierId) {
343                     Log.d(TAG, "Carrier ID " + carrierId + " is loaded.");
344                     return;
345                 }
346             }
347         }
348 
349         mCellList.add(new MockModemCell(carrierId));
350     }
351 
getHighestRatFromNetworkType(int raf)352     private int getHighestRatFromNetworkType(int raf) {
353         int rat;
354         int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(raf);
355 
356         switch (networkMode) {
357             case RILConstants.NETWORK_MODE_WCDMA_PREF:
358                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_HSPA;
359                 break;
360             case RILConstants.NETWORK_MODE_GSM_ONLY:
361                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_GSM;
362                 break;
363             case RILConstants.NETWORK_MODE_WCDMA_ONLY:
364                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_HSPA;
365                 break;
366             case RILConstants.NETWORK_MODE_GSM_UMTS:
367                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_HSPA;
368                 break;
369             case RILConstants.NETWORK_MODE_CDMA:
370                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_IS95A;
371                 break;
372             case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO:
373                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_LTE;
374                 break;
375             case RILConstants.NETWORK_MODE_LTE_GSM_WCDMA:
376                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_LTE;
377                 break;
378             case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
379                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_LTE;
380                 break;
381             case RILConstants.NETWORK_MODE_LTE_ONLY:
382                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_LTE;
383                 break;
384             case RILConstants.NETWORK_MODE_LTE_WCDMA:
385                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_LTE;
386                 break;
387             case RILConstants.NETWORK_MODE_CDMA_NO_EVDO:
388                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_IS95A;
389                 break;
390             case RILConstants.NETWORK_MODE_EVDO_NO_CDMA:
391                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_0;
392                 break;
393             case RILConstants.NETWORK_MODE_GLOBAL:
394                 // GSM | WCDMA | CDMA | EVDO;
395                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_HSPA;
396                 break;
397             case RILConstants.NETWORK_MODE_TDSCDMA_ONLY:
398                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_TD_SCDMA;
399                 break;
400             case RILConstants.NETWORK_MODE_TDSCDMA_WCDMA:
401                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_HSPA;
402                 break;
403             case RILConstants.NETWORK_MODE_LTE_TDSCDMA:
404                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_LTE;
405                 break;
406             case RILConstants.NETWORK_MODE_TDSCDMA_GSM:
407                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_TD_SCDMA;
408                 break;
409             case RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM:
410                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_LTE;
411                 break;
412             case RILConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA:
413                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_HSPA;
414                 break;
415             case RILConstants.NETWORK_MODE_LTE_TDSCDMA_WCDMA:
416                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_LTE;
417                 break;
418             case RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA:
419                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_LTE;
420                 break;
421             case RILConstants.NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
422                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_HSPA;
423                 break;
424             case RILConstants.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
425                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_LTE;
426                 break;
427             case RILConstants.NETWORK_MODE_NR_ONLY:
428                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_NR;
429                 break;
430             case RILConstants.NETWORK_MODE_NR_LTE:
431                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_NR;
432                 break;
433             case RILConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO:
434                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_NR;
435                 break;
436             case RILConstants.NETWORK_MODE_NR_LTE_GSM_WCDMA:
437                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_NR;
438                 break;
439             case RILConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA:
440                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_NR;
441                 break;
442             case RILConstants.NETWORK_MODE_NR_LTE_WCDMA:
443                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_NR;
444                 break;
445             case RILConstants.NETWORK_MODE_NR_LTE_TDSCDMA:
446                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_NR;
447                 break;
448             case RILConstants.NETWORK_MODE_NR_LTE_TDSCDMA_GSM:
449                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_NR;
450                 break;
451             case RILConstants.NETWORK_MODE_NR_LTE_TDSCDMA_WCDMA:
452                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_NR;
453                 break;
454             case RILConstants.NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA:
455                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_NR;
456                 break;
457             case RILConstants.NETWORK_MODE_NR_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
458                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_NR;
459                 break;
460             default:
461                 rat = ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN;
462                 break;
463         }
464         return rat;
465     }
466 
getPrimaryCellOperatorInfo()467     public android.hardware.radio.network.OperatorInfo getPrimaryCellOperatorInfo() {
468         android.hardware.radio.network.OperatorInfo operatorInfo =
469                 new android.hardware.radio.network.OperatorInfo();
470 
471         if (mCsRegState == RegState.REG_HOME || mPsRegState == RegState.REG_HOME) {
472             operatorInfo = getCarrierStatus(mHomeCarrierId).getPrimaryCellOperatorInfo();
473         } else if (mCsRegState == RegState.REG_ROAMING || mPsRegState == RegState.REG_ROAMING) {
474             operatorInfo = getCarrierStatus(mRoamingCarrierId).getPrimaryCellOperatorInfo();
475         }
476 
477         return operatorInfo;
478     }
479 
getPrimaryCellIdentity()480     public android.hardware.radio.network.CellIdentity getPrimaryCellIdentity() {
481         android.hardware.radio.network.CellIdentity cellIdentity =
482                 android.hardware.radio.network.CellIdentity.noinit(true);
483 
484         if (mCsRegState == RegState.REG_HOME || mPsRegState == RegState.REG_HOME) {
485             cellIdentity = getCarrierStatus(mHomeCarrierId).getPrimaryCellIdentity();
486         } else if (mCsRegState == RegState.REG_ROAMING || mPsRegState == RegState.REG_ROAMING) {
487             cellIdentity = getCarrierStatus(mRoamingCarrierId).getPrimaryCellIdentity();
488         }
489 
490         return cellIdentity;
491     }
492 
getCells()493     public android.hardware.radio.network.CellInfo[] getCells() {
494         ArrayList<android.hardware.radio.network.CellInfo> cellInfos = new ArrayList<>();
495 
496         for (MockModemCell mmc : mCellList) {
497             CellInfo[] cells = mmc.getCells();
498             if (cells != null) {
499                 for (CellInfo cellInfo : cells) {
500                     cellInfos.add(cellInfo);
501                 }
502             }
503         }
504 
505         return cellInfos.stream().toArray(android.hardware.radio.network.CellInfo[]::new);
506     }
507 
updateHighestRegisteredRat(int raf)508     public boolean updateHighestRegisteredRat(int raf) {
509 
510         int rat = mHighRat;
511         mHighRat = getHighestRatFromNetworkType(raf);
512 
513         return (rat == mHighRat);
514     }
515 
updateNetworkStatus(int reason)516     public void updateNetworkStatus(int reason) {
517         if (reason == NETWORK_UPDATE_PREFERRED_MODE_CHANGE) {
518             Log.d(TAG, "updateNetworkStatus: NETWORK_UPDATE_PREFERRED_MODE_CHANGE");
519             // TODO
520         }
521     }
522 
getRegistrationRat()523     public int getRegistrationRat() {
524         int rat = android.hardware.radio.RadioTechnology.UNKNOWN;
525 
526         if (mCsRegState == RegState.REG_HOME || mPsRegState == RegState.REG_HOME) {
527             rat = getCarrierStatus(mHomeCarrierId).getPrimaryCellRat();
528         } else if (mCsRegState == RegState.REG_ROAMING || mPsRegState == RegState.REG_ROAMING) {
529             rat = getCarrierStatus(mRoamingCarrierId).getPrimaryCellRat();
530         }
531 
532         return rat;
533     }
534 
getSignalStrength()535     public android.hardware.radio.network.SignalStrength getSignalStrength() {
536         android.hardware.radio.network.SignalStrength signalStrength =
537                 new android.hardware.radio.network.SignalStrength();
538 
539         if (mCsRegState == RegState.REG_HOME || mPsRegState == RegState.REG_HOME) {
540             signalStrength = getCarrierStatus(mHomeCarrierId).getPrimaryCellSignalStrength();
541         } else if (mCsRegState == RegState.REG_ROAMING || mPsRegState == RegState.REG_ROAMING) {
542             signalStrength = getCarrierStatus(mRoamingCarrierId).getPrimaryCellSignalStrength();
543         } else {
544             // TODO
545         }
546 
547         return signalStrength;
548     }
549 
getRegistration(int domain)550     public int getRegistration(int domain) {
551         if (domain == android.hardware.radio.network.Domain.CS) {
552             return mCsRegState;
553         } else {
554             return mPsRegState;
555         }
556     }
557 
isInService()558     public boolean isInService() {
559         return ((mCsRegState == RegState.REG_HOME)
560                 || (mPsRegState == RegState.REG_HOME)
561                 || (mCsRegState == RegState.REG_ROAMING)
562                 || (mPsRegState == RegState.REG_ROAMING));
563     }
564 
updateSimPlmn(String simPlmn)565     public void updateSimPlmn(String simPlmn) {
566         mSimPlmn = simPlmn;
567 
568         // Reset mHomeCarrierId and mRoamingCarrierId
569         mHomeCarrierId = MOCK_CARRIER_NO_SERVICE;
570         mRoamingCarrierId = MOCK_CARRIER_NO_SERVICE;
571 
572         if (mSimPlmn == null || mSimPlmn.isEmpty()) return;
573 
574         if (mCellList.isEmpty()) return;
575 
576         for (MockModemCell mmc : mCellList) {
577 
578             if (isHomeCellExisted() && isRoamingCellExisted()) break;
579 
580             // Find out which cell is Home cell
581             for (String plmn : mmc.mEHPlmnList) {
582                 if (!isHomeCellExisted() && mSimPlmn.equals(plmn)) {
583                     mHomeCarrierId = mmc.getCarrierId();
584                     Log.d(TAG, "Cell ID: Home Cell " + mHomeCarrierId);
585                 }
586             }
587 
588             // Find out which cell is Home cell
589             for (String plmn : mmc.mAllowRoamingList) {
590                 if (!isRoamingCellExisted() && mSimPlmn.equals(plmn)) {
591                     mRoamingCarrierId = mmc.getCarrierId();
592                     Log.d(TAG, "Cell ID: Roaming Cell " + mRoamingCarrierId);
593                 }
594             }
595         }
596     }
597 
598     /**
599      * Set the device enters IN SERVICE
600      *
601      * @param isRoaming boolean true if the camping network is Roaming service, otherwise Home
602      *     service
603      * @param inService boolean true if the deviec enters carrier coverge, otherwise the device
604      *     leaves the carrier coverage.
605      */
setServiceStatus(boolean isRoaming, boolean inService)606     public void setServiceStatus(boolean isRoaming, boolean inService) {
607         if (isRoaming) {
608             mIsRoamingCamping = inService;
609         } else {
610             mIsHomeCamping = inService;
611         }
612     }
613 
getIsHomeCamping()614     public boolean getIsHomeCamping() {
615         return mIsHomeCamping;
616     }
617 
getIsRoamingCamping()618     public boolean getIsRoamingCamping() {
619         return mIsRoamingCamping;
620     }
621 
isHomeCellExisted()622     public boolean isHomeCellExisted() {
623         return (mHomeCarrierId != MOCK_CARRIER_NO_SERVICE);
624     }
625 
isRoamingCellExisted()626     public boolean isRoamingCellExisted() {
627         return (mRoamingCarrierId != MOCK_CARRIER_NO_SERVICE);
628     }
629 
updateServiceState(int reg)630     public void updateServiceState(int reg) {
631         Log.d(TAG, "Cell ID: updateServiceState " + reg);
632         switch (reg) {
633             case RegState.NOT_REG_MT_SEARCHING_OP:
634                 mCsRegState = RegState.NOT_REG_MT_SEARCHING_OP;
635                 mPsRegState = RegState.NOT_REG_MT_SEARCHING_OP;
636                 break;
637             case RegState.REG_HOME:
638                 mCsRegState = RegState.REG_HOME;
639                 mPsRegState = RegState.REG_HOME;
640                 break;
641             case RegState.REG_ROAMING:
642                 mCsRegState = RegState.REG_ROAMING;
643                 mPsRegState = RegState.REG_ROAMING;
644                 break;
645             case RegState.NOT_REG_MT_NOT_SEARCHING_OP:
646             default:
647                 mCsRegState = RegState.NOT_REG_MT_NOT_SEARCHING_OP;
648                 mPsRegState = RegState.NOT_REG_MT_NOT_SEARCHING_OP;
649                 break;
650         }
651 
652         // TODO: mCsRegState and mPsReState may be changed by the registration denied reason set by
653         // TestCase
654 
655         for (MockModemCell mmc : mCellList) {
656             boolean registered;
657             if ((mCsRegState == RegState.REG_HOME || mPsRegState == RegState.REG_HOME)
658                     && mHomeCarrierId == mmc.getCarrierId()) {
659                 registered = true;
660             } else if ((mCsRegState == RegState.REG_ROAMING || mPsRegState == RegState.REG_ROAMING)
661                     && mRoamingCarrierId == mmc.getCarrierId()) {
662                 registered = true;
663             } else {
664                 registered = false;
665             }
666 
667             CellInfo[] cells = mmc.getCells();
668             if (cells != null) {
669                 for (CellInfo cellInfo : cells) {
670                     cellInfo.registered = registered;
671                 }
672             }
673         }
674     }
675 
getCarrierStatus(int carrierId)676     public MockModemCell getCarrierStatus(int carrierId) {
677         for (MockModemCell mmc : mCellList) {
678             if (mmc.getCarrierId() == carrierId) return mmc;
679         }
680 
681         return null;
682     }
683 
684     @Override
toString()685     public String toString() {
686         return "isInService():" + isInService() + " Rat:" + getRegistrationRat() + "";
687     }
688 }
689