1 /*
2  * Copyright (C) 2006 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 com.android.internal.telephony;
18 
19 import static android.telephony.TelephonyManager.HAL_SERVICE_DATA;
20 import static android.telephony.TelephonyManager.HAL_SERVICE_IMS;
21 import static android.telephony.TelephonyManager.HAL_SERVICE_MESSAGING;
22 import static android.telephony.TelephonyManager.HAL_SERVICE_MODEM;
23 import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
24 import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
25 import static android.telephony.TelephonyManager.HAL_SERVICE_SIM;
26 import static android.telephony.TelephonyManager.HAL_SERVICE_VOICE;
27 
28 import static com.android.internal.telephony.RILConstants.*;
29 
30 import android.annotation.NonNull;
31 import android.annotation.Nullable;
32 import android.compat.annotation.UnsupportedAppUsage;
33 import android.content.Context;
34 import android.content.pm.PackageManager;
35 import android.hardware.radio.V1_0.IRadio;
36 import android.hardware.radio.V1_0.RadioError;
37 import android.hardware.radio.V1_0.RadioIndicationType;
38 import android.hardware.radio.V1_0.RadioResponseInfo;
39 import android.hardware.radio.V1_0.RadioResponseType;
40 import android.hardware.radio.modem.ImeiInfo;
41 import android.net.KeepalivePacketData;
42 import android.net.LinkProperties;
43 import android.os.AsyncResult;
44 import android.os.Build;
45 import android.os.Handler;
46 import android.os.HwBinder;
47 import android.os.IBinder;
48 import android.os.Message;
49 import android.os.PowerManager;
50 import android.os.PowerManager.WakeLock;
51 import android.os.RemoteException;
52 import android.os.ServiceManager;
53 import android.os.SystemClock;
54 import android.os.SystemProperties;
55 import android.os.Trace;
56 import android.os.WorkSource;
57 import android.provider.Settings;
58 import android.sysprop.TelephonyProperties;
59 import android.telephony.AccessNetworkConstants;
60 import android.telephony.AccessNetworkConstants.AccessNetworkType;
61 import android.telephony.BarringInfo;
62 import android.telephony.CarrierRestrictionRules;
63 import android.telephony.ClientRequestStats;
64 import android.telephony.DomainSelectionService;
65 import android.telephony.ImsiEncryptionInfo;
66 import android.telephony.ModemActivityInfo;
67 import android.telephony.NeighboringCellInfo;
68 import android.telephony.NetworkScanRequest;
69 import android.telephony.RadioAccessFamily;
70 import android.telephony.RadioAccessSpecifier;
71 import android.telephony.SignalThresholdInfo;
72 import android.telephony.SubscriptionManager;
73 import android.telephony.TelephonyHistogram;
74 import android.telephony.TelephonyManager;
75 import android.telephony.TelephonyManager.HalService;
76 import android.telephony.TelephonyManager.PrefNetworkMode;
77 import android.telephony.data.DataProfile;
78 import android.telephony.data.NetworkSliceInfo;
79 import android.telephony.data.TrafficDescriptor;
80 import android.telephony.emergency.EmergencyNumber;
81 import android.telephony.ims.RegistrationManager;
82 import android.telephony.ims.feature.ConnectionFailureInfo;
83 import android.telephony.ims.stub.ImsRegistrationImplBase;
84 import android.text.TextUtils;
85 import android.util.SparseArray;
86 
87 import com.android.internal.annotations.VisibleForTesting;
88 import com.android.internal.telephony.cdma.CdmaInformationRecords;
89 import com.android.internal.telephony.cdma.CdmaSmsBroadcastConfigInfo;
90 import com.android.internal.telephony.emergency.EmergencyConstants;
91 import com.android.internal.telephony.flags.FeatureFlags;
92 import com.android.internal.telephony.gsm.SmsBroadcastConfigInfo;
93 import com.android.internal.telephony.imsphone.ImsCallInfo;
94 import com.android.internal.telephony.metrics.ModemRestartStats;
95 import com.android.internal.telephony.metrics.TelephonyMetrics;
96 import com.android.internal.telephony.nano.TelephonyProto.SmsSession;
97 import com.android.internal.telephony.uicc.IccCardApplicationStatus.PersoSubState;
98 import com.android.internal.telephony.uicc.IccUtils;
99 import com.android.internal.telephony.uicc.SimPhonebookRecord;
100 import com.android.internal.telephony.util.TelephonyUtils;
101 import com.android.internal.util.FunctionalUtils;
102 import com.android.telephony.Rlog;
103 
104 import java.io.FileDescriptor;
105 import java.io.PrintWriter;
106 import java.util.ArrayList;
107 import java.util.Arrays;
108 import java.util.HashMap;
109 import java.util.HashSet;
110 import java.util.List;
111 import java.util.Map;
112 import java.util.NoSuchElementException;
113 import java.util.Objects;
114 import java.util.Set;
115 import java.util.concurrent.ConcurrentHashMap;
116 import java.util.concurrent.atomic.AtomicBoolean;
117 import java.util.concurrent.atomic.AtomicLong;
118 
119 /**
120  * RIL implementation of the CommandsInterface.
121  * {@hide}
122  */
123 public class RIL extends BaseCommands implements CommandsInterface {
124     static final String RILJ_LOG_TAG = "RILJ";
125     static final String RILJ_WAKELOCK_TAG = "*telephony-radio*";
126     // Have a separate wakelock instance for Ack
127     static final String RILJ_ACK_WAKELOCK_NAME = "RILJ_ACK_WL";
128     static final boolean RILJ_LOGD = true;
129     static final boolean RILJ_LOGV = false; // STOPSHIP if true
130     static final int RIL_HISTOGRAM_BUCKET_COUNT = 5;
131 
132     /**
133      * Wake lock timeout should be longer than the longest timeout in the vendor ril.
134      */
135     private static final int DEFAULT_WAKE_LOCK_TIMEOUT_MS = 60000;
136 
137     // Wake lock default timeout associated with ack
138     private static final int DEFAULT_ACK_WAKE_LOCK_TIMEOUT_MS = 200;
139 
140     private static final int DEFAULT_BLOCKING_MESSAGE_RESPONSE_TIMEOUT_MS = 2000;
141 
142     // Variables used to differentiate ack messages from request while calling clearWakeLock()
143     public static final int INVALID_WAKELOCK = -1;
144     public static final int FOR_WAKELOCK = 0;
145     public static final int FOR_ACK_WAKELOCK = 1;
146     private final ClientWakelockTracker mClientWakelockTracker = new ClientWakelockTracker();
147 
148     /** @hide */
149     public static final HalVersion RADIO_HAL_VERSION_UNSUPPORTED = HalVersion.UNSUPPORTED;
150 
151     /** @hide */
152     public static final HalVersion RADIO_HAL_VERSION_UNKNOWN = HalVersion.UNKNOWN;
153 
154     /** @hide */
155     public static final HalVersion RADIO_HAL_VERSION_1_1 = new HalVersion(1, 1);
156 
157     /** @hide */
158     public static final HalVersion RADIO_HAL_VERSION_1_2 = new HalVersion(1, 2);
159 
160     /** @hide */
161     public static final HalVersion RADIO_HAL_VERSION_1_3 = new HalVersion(1, 3);
162 
163     /** @hide */
164     public static final HalVersion RADIO_HAL_VERSION_1_4 = new HalVersion(1, 4);
165 
166     /** @hide */
167     public static final HalVersion RADIO_HAL_VERSION_1_5 = new HalVersion(1, 5);
168 
169     /** @hide */
170     public static final HalVersion RADIO_HAL_VERSION_1_6 = new HalVersion(1, 6);
171 
172     /** @hide */
173     public static final HalVersion RADIO_HAL_VERSION_2_0 = new HalVersion(2, 0);
174 
175     /** @hide */
176     public static final HalVersion RADIO_HAL_VERSION_2_1 = new HalVersion(2, 1);
177 
178     /** @hide */
179     public static final HalVersion RADIO_HAL_VERSION_2_2 = new HalVersion(2, 2);
180 
181     // Hal version
182     private final Map<Integer, HalVersion> mHalVersion = new HashMap<>();
183 
184     //***** Instance Variables
185 
186     @UnsupportedAppUsage
187     @VisibleForTesting
188     public final WakeLock mWakeLock;           // Wake lock associated with request/response
189     @VisibleForTesting
190     public final WakeLock mAckWakeLock;        // Wake lock associated with ack sent
191     final int mWakeLockTimeout;         // Timeout associated with request/response
192     final int mAckWakeLockTimeout;      // Timeout associated with ack sent
193     // The number of wakelock requests currently active. Don't release the lock until dec'd to 0.
194     int mWakeLockCount;
195 
196     // Variables used to identify releasing of WL on wakelock timeouts
197     volatile int mWlSequenceNum = 0;
198     volatile int mAckWlSequenceNum = 0;
199 
200     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
201     SparseArray<RILRequest> mRequestList = new SparseArray<>();
202     static SparseArray<TelephonyHistogram> sRilTimeHistograms = new SparseArray<>();
203 
204     Object[] mLastNITZTimeInfo;
205 
206     int mLastRadioPowerResult = RadioError.NONE;
207 
208     boolean mIsRadioProxyInitialized = false;
209 
210     Boolean mIsRadioVersion20Cached = null;
211 
212     // When we are testing emergency calls using ril.test.emergencynumber, this will trigger test
213     // ECbM when the call is ended.
214     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
215     AtomicBoolean mTestingEmergencyCall = new AtomicBoolean(false);
216 
217     final Integer mPhoneId;
218 
219     private static final String PROPERTY_IS_VONR_ENABLED = "persist.radio.is_vonr_enabled_";
220 
221     public static final int MIN_SERVICE_IDX = HAL_SERVICE_RADIO;
222 
223     public static final int MAX_SERVICE_IDX = HAL_SERVICE_IMS;
224 
225     @NonNull private final FeatureFlags mFeatureFlags;
226 
227     /**
228      * An array of sets that records if services are disabled in the HAL for a specific phone ID
229      * slot to avoid further getService requests for that service. See XXX_SERVICE for the indices.
230      * RADIO_SERVICE is the HIDL IRadio service, and mDisabledRadioServices.get(RADIO_SERVICE)
231      * will return a set of all phone ID slots that are disabled for IRadio.
232      */
233     private final SparseArray<Set<Integer>> mDisabledRadioServices = new SparseArray<>();
234 
235     /* default work source which will blame phone process */
236     private WorkSource mRILDefaultWorkSource;
237 
238     /* Worksource containing all applications causing wakelock to be held */
239     private WorkSource mActiveWakelockWorkSource;
240 
241     /** Telephony metrics instance for logging metrics event */
242     private TelephonyMetrics mMetrics = TelephonyMetrics.getInstance();
243     /** Radio bug detector instance */
244     private RadioBugDetector mRadioBugDetector = null;
245 
246     private boolean mIsCellularSupported;
247     private RadioResponse mRadioResponse;
248     private RadioIndication mRadioIndication;
249     private volatile IRadio mRadioProxy = null;
250     private DataResponse mDataResponse;
251     private DataIndication mDataIndication;
252     private ImsResponse mImsResponse;
253     private ImsIndication mImsIndication;
254     private MessagingResponse mMessagingResponse;
255     private MessagingIndication mMessagingIndication;
256     private ModemResponse mModemResponse;
257     private ModemIndication mModemIndication;
258     private NetworkResponse mNetworkResponse;
259     private NetworkIndication mNetworkIndication;
260     private SimResponse mSimResponse;
261     private SimIndication mSimIndication;
262     private VoiceResponse mVoiceResponse;
263     private VoiceIndication mVoiceIndication;
264     private SparseArray<RadioServiceProxy> mServiceProxies = new SparseArray<>();
265     private final SparseArray<BinderServiceDeathRecipient> mDeathRecipients = new SparseArray<>();
266     private final SparseArray<AtomicLong> mServiceCookies = new SparseArray<>();
267     private final RadioProxyDeathRecipient mRadioProxyDeathRecipient;
268     final RilHandler mRilHandler;
269     private MockModem mMockModem;
270 
271     // Thread-safe HashMap to map from RIL_REQUEST_XXX constant to HalVersion.
272     // This is for Radio HAL Fallback Compatibility feature. When a RIL request
273     // is received, the HAL method from the mapping HalVersion here (if present),
274     // instead of the latest HalVersion, will be invoked.
275     private final ConcurrentHashMap<Integer, HalVersion> mCompatOverrides =
276             new ConcurrentHashMap<>();
277 
278     //***** Events
279     static final int EVENT_WAKE_LOCK_TIMEOUT = 2;
280     static final int EVENT_ACK_WAKE_LOCK_TIMEOUT = 4;
281     static final int EVENT_BLOCKING_RESPONSE_TIMEOUT = 5;
282     static final int EVENT_RADIO_PROXY_DEAD = 6;
283     static final int EVENT_AIDL_PROXY_DEAD = 7;
284 
285     //***** Constants
286 
287     static final String[] HIDL_SERVICE_NAME = {"slot1", "slot2", "slot3"};
288 
289     private static final Map<String, Integer> FEATURES_TO_SERVICES = Map.ofEntries(
290             Map.entry(PackageManager.FEATURE_TELEPHONY_CALLING, HAL_SERVICE_VOICE),
291             Map.entry(PackageManager.FEATURE_TELEPHONY_DATA, HAL_SERVICE_DATA),
292             Map.entry(PackageManager.FEATURE_TELEPHONY_MESSAGING, HAL_SERVICE_MESSAGING),
293             Map.entry(PackageManager.FEATURE_TELEPHONY_IMS, HAL_SERVICE_IMS)
294     );
295 
getTelephonyRILTimingHistograms()296     public static List<TelephonyHistogram> getTelephonyRILTimingHistograms() {
297         List<TelephonyHistogram> list;
298         synchronized (sRilTimeHistograms) {
299             list = new ArrayList<>(sRilTimeHistograms.size());
300             for (int i = 0; i < sRilTimeHistograms.size(); i++) {
301                 TelephonyHistogram entry = new TelephonyHistogram(sRilTimeHistograms.valueAt(i));
302                 list.add(entry);
303             }
304         }
305         return list;
306     }
307 
308     /** The handler used to handle the internal event of RIL. */
309     @VisibleForTesting
310     public class RilHandler extends Handler {
311 
312         //***** Handler implementation
313         @Override
handleMessage(Message msg)314         public void handleMessage(Message msg) {
315             RILRequest rr;
316 
317             switch (msg.what) {
318                 case EVENT_WAKE_LOCK_TIMEOUT:
319                     // Haven't heard back from the last request.  Assume we're
320                     // not getting a response and  release the wake lock.
321 
322                     // The timer of WAKE_LOCK_TIMEOUT is reset with each
323                     // new send request. So when WAKE_LOCK_TIMEOUT occurs
324                     // all requests in mRequestList already waited at
325                     // least DEFAULT_WAKE_LOCK_TIMEOUT_MS but no response.
326                     //
327                     // Note: Keep mRequestList so that delayed response
328                     // can still be handled when response finally comes.
329 
330                     synchronized (mRequestList) {
331                         if (msg.arg1 == mWlSequenceNum && clearWakeLock(FOR_WAKELOCK)) {
332                             if (mRadioBugDetector != null) {
333                                 mRadioBugDetector.processWakelockTimeout();
334                             }
335                             if (RILJ_LOGD) {
336                                 int count = mRequestList.size();
337                                 riljLog("WAKE_LOCK_TIMEOUT mRequestList=" + count);
338                                 for (int i = 0; i < count; i++) {
339                                     rr = mRequestList.valueAt(i);
340                                     riljLog(i + ": [" + rr.mSerial + "] "
341                                             + RILUtils.requestToString(rr.mRequest));
342                                 }
343                             }
344                         }
345                     }
346                     break;
347 
348                 case EVENT_ACK_WAKE_LOCK_TIMEOUT:
349                     if (msg.arg1 == mAckWlSequenceNum && clearWakeLock(FOR_ACK_WAKELOCK)) {
350                         if (RILJ_LOGV) {
351                             riljLog("ACK_WAKE_LOCK_TIMEOUT");
352                         }
353                     }
354                     break;
355 
356                 case EVENT_BLOCKING_RESPONSE_TIMEOUT:
357                     int serial = (int) msg.obj;
358                     rr = findAndRemoveRequestFromList(serial);
359                     // If the request has already been processed, do nothing
360                     if (rr == null) {
361                         break;
362                     }
363 
364                     // Build a response if expected
365                     if (rr.mResult != null) {
366                         Object timeoutResponse = getResponseForTimedOutRILRequest(rr);
367                         AsyncResult.forMessage(rr.mResult, timeoutResponse, null);
368                         rr.mResult.sendToTarget();
369                         mMetrics.writeOnRilTimeoutResponse(mPhoneId, rr.mSerial, rr.mRequest);
370                     }
371 
372                     decrementWakeLock(rr);
373                     rr.release();
374                     break;
375 
376                 case EVENT_RADIO_PROXY_DEAD:
377                     int service = msg.arg1;
378                     riljLog("handleMessage: EVENT_RADIO_PROXY_DEAD cookie = " + msg.obj
379                             + ", service = " + serviceToString(service) + ", service cookie = "
380                             + mServiceCookies.get(service));
381                     if ((long) msg.obj == mServiceCookies.get(service).get()) {
382                         mIsRadioProxyInitialized = false;
383                         resetProxyAndRequestList(service);
384                     }
385                     break;
386 
387                 case EVENT_AIDL_PROXY_DEAD:
388                     int aidlService = msg.arg1;
389                     long msgCookie = (long) msg.obj;
390                     if (mFeatureFlags.combineRilDeathHandle()) {
391                         if (msgCookie == mServiceCookies.get(aidlService).get()) {
392                             riljLog("handleMessage: EVENT_AIDL_PROXY_DEAD cookie = " + msgCookie
393                                     + ", service = " + serviceToString(aidlService) + ", cookie = "
394                                     + mServiceCookies.get(aidlService));
395                             mIsRadioProxyInitialized = false;
396                             resetProxyAndRequestList(aidlService);
397                             // Remove duplicate death message to avoid duplicate reset.
398                             mRilHandler.removeMessages(EVENT_AIDL_PROXY_DEAD);
399                         } else {
400                             riljLog("Ignore stale EVENT_AIDL_PROXY_DEAD for service "
401                                     + serviceToString(aidlService));
402                         }
403                     } else {
404                         riljLog("handleMessage: EVENT_AIDL_PROXY_DEAD cookie = " + msgCookie
405                                 + ", service = " + serviceToString(aidlService) + ", cookie = "
406                                 + mServiceCookies.get(aidlService));
407                         if (msgCookie == mServiceCookies.get(aidlService).get()) {
408                             mIsRadioProxyInitialized = false;
409                             resetProxyAndRequestList(aidlService);
410                         }
411                     }
412                     break;
413             }
414         }
415     }
416 
417     /** Return RadioBugDetector instance for testing. */
418     @VisibleForTesting
getRadioBugDetector()419     public RadioBugDetector getRadioBugDetector() {
420         if (mRadioBugDetector == null) {
421             mRadioBugDetector = new RadioBugDetector(mContext, mPhoneId);
422         }
423         return mRadioBugDetector;
424     }
425 
426     /**
427      * In order to prevent calls to Telephony from waiting indefinitely
428      * low-latency blocking calls will eventually time out. In the event of
429      * a timeout, this function generates a response that is returned to the
430      * higher layers to unblock the call. This is in lieu of a meaningful
431      * response.
432      * @param rr The RIL Request that has timed out.
433      * @return A default object, such as the one generated by a normal response
434      * that is returned to the higher layers.
435      **/
436     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
getResponseForTimedOutRILRequest(RILRequest rr)437     private static Object getResponseForTimedOutRILRequest(RILRequest rr) {
438         if (rr == null ) return null;
439 
440         Object timeoutResponse = null;
441         switch(rr.mRequest) {
442             case RIL_REQUEST_GET_ACTIVITY_INFO:
443                 timeoutResponse = new ModemActivityInfo(
444                         0, 0, 0, new int [ModemActivityInfo.getNumTxPowerLevels()], 0);
445                 break;
446         };
447         return timeoutResponse;
448     }
449 
450     final class RadioProxyDeathRecipient implements HwBinder.DeathRecipient {
451         @Override
serviceDied(long cookie)452         public void serviceDied(long cookie) {
453             // Deal with service going away
454             riljLog("serviceDied");
455             if (mFeatureFlags.combineRilDeathHandle()) {
456                 mRilHandler.sendMessageAtFrontOfQueue(mRilHandler.obtainMessage(
457                         EVENT_RADIO_PROXY_DEAD,
458                         HAL_SERVICE_RADIO, 0 /* ignored arg2 */, cookie));
459             } else {
460                 mRilHandler.sendMessage(mRilHandler.obtainMessage(EVENT_RADIO_PROXY_DEAD,
461                         HAL_SERVICE_RADIO, 0 /* ignored arg2 */, cookie));
462             }
463         }
464     }
465 
466     private final class BinderServiceDeathRecipient implements IBinder.DeathRecipient {
467         private IBinder mBinder;
468         private final int mService;
469         private long mLinkedFlags;
470 
BinderServiceDeathRecipient(int service)471         BinderServiceDeathRecipient(int service) {
472             mService = service;
473             mLinkedFlags = 0;
474         }
475 
linkToDeath(IBinder service)476         public void linkToDeath(IBinder service) throws RemoteException {
477             if (service != null) {
478                 riljLog("Linked to death for service " + serviceToString(mService));
479                 mBinder = service;
480                 mLinkedFlags = mServiceCookies.get(mService).incrementAndGet();
481                 mBinder.linkToDeath(this, (int) mLinkedFlags);
482             } else {
483                 riljLoge("Unable to link to death for service " + serviceToString(mService));
484             }
485         }
486 
unlinkToDeath()487         public synchronized void unlinkToDeath() {
488             if (mBinder != null) {
489                 mBinder.unlinkToDeath(this, (int) mLinkedFlags);
490                 mBinder = null;
491                 mLinkedFlags = 0;
492             }
493         }
494 
495         @Override
binderDied()496         public void binderDied() {
497             riljLog("Service " + serviceToString(mService) + " has died.");
498             if (mFeatureFlags.combineRilDeathHandle()) {
499                 mRilHandler.sendMessageAtFrontOfQueue(mRilHandler.obtainMessage(
500                         EVENT_AIDL_PROXY_DEAD, mService, 0 /* ignored arg2 */,
501                         mLinkedFlags));
502             } else {
503                 mRilHandler.sendMessage(mRilHandler.obtainMessage(EVENT_AIDL_PROXY_DEAD, mService,
504                         0 /* ignored arg2 */, mLinkedFlags));
505             }
506             unlinkToDeath();
507         }
508     }
509 
510     /**
511      * Reset services. If one of the AIDL service is reset, all the other AIDL services will be
512      * reset as well.
513      * @param service The service to reset.
514      */
resetProxyAndRequestList(@alService int service)515     private synchronized void resetProxyAndRequestList(@HalService int service) {
516         if (service == HAL_SERVICE_RADIO) {
517             mRadioProxy = null;
518             // Increment the cookie so that death notification can be ignored
519             mServiceCookies.get(service).incrementAndGet();
520         } else {
521             if (mFeatureFlags.combineRilDeathHandle()) {
522                 // Reset all aidl services.
523                 for (int i = MIN_SERVICE_IDX; i <= MAX_SERVICE_IDX; i++) {
524                     if (i == HAL_SERVICE_RADIO) continue;
525                     if (mServiceProxies.get(i) == null) {
526                         // This should only happen in tests
527                         riljLoge("Null service proxy for service " + serviceToString(i));
528                         continue;
529                     }
530                     mServiceProxies.get(i).clear();
531                     // Increment the cookie so that death notification can be ignored
532                     mServiceCookies.get(i).incrementAndGet();
533                 }
534             } else {
535                 mServiceProxies.get(service).clear();
536                 // Increment the cookie so that death notification can be ignored
537                 mServiceCookies.get(service).incrementAndGet();
538             }
539         }
540 
541         setRadioState(TelephonyManager.RADIO_POWER_UNAVAILABLE, true /* forceNotifyRegistrants */);
542 
543         RILRequest.resetSerial();
544         // Clear request list on close
545         clearRequestList(RADIO_NOT_AVAILABLE, false);
546 
547         if (service == HAL_SERVICE_RADIO) {
548             getRadioProxy();
549         } else {
550             if (mFeatureFlags.combineRilDeathHandle()) {
551                 // Reset all aidl services.
552                 for (int i = MIN_SERVICE_IDX; i <= MAX_SERVICE_IDX; i++) {
553                     if (i == HAL_SERVICE_RADIO) continue;
554                     if (mServiceProxies.get(i) == null) {
555                         // This should only happen in tests
556                         riljLoge("Null service proxy for service " + serviceToString(i));
557                         continue;
558                     }
559                     getRadioServiceProxy(i);
560                 }
561             } else {
562                 getRadioServiceProxy(service);
563             }
564         }
565     }
566 
567     /**
568      * Request to enable/disable the mock modem service.
569      * This is invoked from shell commands during CTS testing only.
570      *
571      * @param serviceName the service name we want to bind to
572      */
setModemService(String serviceName)573     public boolean setModemService(String serviceName) {
574         boolean serviceBound = true;
575 
576         if (serviceName != null) {
577             riljLog("Binding to MockModemService");
578             mMockModem = null;
579 
580             mMockModem = new MockModem(mContext, serviceName, mPhoneId);
581 
582             // Disable HIDL service
583             if (mRadioProxy != null) {
584                 riljLog("Disable HIDL service");
585                 mDisabledRadioServices.get(HAL_SERVICE_RADIO).add(mPhoneId);
586             }
587 
588             mMockModem.bindAllMockModemService();
589 
590             for (int service = MIN_SERVICE_IDX; service <= MAX_SERVICE_IDX; service++) {
591                 if (service == HAL_SERVICE_RADIO) continue;
592 
593                 int retryCount = 0;
594                 IBinder binder;
595                 do {
596                     binder = mMockModem.getServiceBinder(service);
597 
598                     retryCount++;
599                     if (binder == null) {
600                         riljLog("Retry(" + retryCount + ") Service " + serviceToString(service));
601                         try {
602                             Thread.sleep(MockModem.BINDER_RETRY_MILLIS);
603                         } catch (InterruptedException e) {
604                         }
605                     }
606                 } while ((binder == null) && (retryCount < MockModem.BINDER_MAX_RETRY));
607 
608                 if (binder == null) {
609                     riljLoge("Service " + serviceToString(service) + " bind fail");
610                     serviceBound = false;
611                     break;
612                 }
613             }
614 
615             if (serviceBound) {
616                 mIsRadioProxyInitialized = false;
617                 if (mFeatureFlags.combineRilDeathHandle()) {
618                     // Reset both hidl and aidl proxies.
619                     resetProxyAndRequestList(HAL_SERVICE_RADIO);
620                     resetProxyAndRequestList(HAL_SERVICE_DATA);
621                 } else {
622                     for (int service = MIN_SERVICE_IDX; service <= MAX_SERVICE_IDX; service++) {
623                         resetProxyAndRequestList(service);
624                     }
625                 }
626             }
627         }
628 
629         if ((serviceName == null) || (!serviceBound)) {
630             if (serviceBound) riljLog("Unbinding to MockModemService");
631 
632             if (mDisabledRadioServices.get(HAL_SERVICE_RADIO).contains(mPhoneId)) {
633                 mDisabledRadioServices.get(HAL_SERVICE_RADIO).clear();
634             }
635 
636             if (mMockModem != null) {
637                 mMockModem = null;
638                 for (int service = MIN_SERVICE_IDX; service <= MAX_SERVICE_IDX; service++) {
639                     if (service == HAL_SERVICE_RADIO) {
640                         if (isRadioVersion2_0()) {
641                             mHalVersion.put(service, RADIO_HAL_VERSION_2_0);
642                         } else {
643                             mHalVersion.put(service, RADIO_HAL_VERSION_UNKNOWN);
644                         }
645                     } else {
646                         if (isRadioServiceSupported(service)) {
647                             mHalVersion.put(service, RADIO_HAL_VERSION_UNKNOWN);
648                         } else {
649                             mHalVersion.put(service, RADIO_HAL_VERSION_UNSUPPORTED);
650                         }
651                     }
652                     if (!mFeatureFlags.combineRilDeathHandle()) {
653                         resetProxyAndRequestList(service);
654                     }
655                 }
656                 if (mFeatureFlags.combineRilDeathHandle()) {
657                     // Reset both hidl and aidl proxies. Must be after cleaning mocked halVersion,
658                     // otherwise an aidl service will be incorrectly considered as disabled.
659                     resetProxyAndRequestList(HAL_SERVICE_RADIO);
660                     resetProxyAndRequestList(HAL_SERVICE_DATA);
661                 }
662             }
663         }
664 
665         return serviceBound;
666     }
667 
668     /**
669      * Get current bound service in Radio Module
670      */
getModemService()671     public String getModemService() {
672         if (mMockModem != null) {
673             return mMockModem.getServiceName();
674         } else {
675             return "default";
676         }
677     }
678 
679     /** Set a radio HAL fallback compatibility override. */
680     @VisibleForTesting
setCompatVersion(int rilRequest, @NonNull HalVersion halVersion)681     public void setCompatVersion(int rilRequest, @NonNull HalVersion halVersion) {
682         HalVersion oldVersion = getCompatVersion(rilRequest);
683         // Do not allow to set same or greater versions
684         if (oldVersion != null && halVersion.greaterOrEqual(oldVersion)) {
685             riljLoge("setCompatVersion with equal or greater one, ignored, halVersion=" + halVersion
686                     + ", oldVersion=" + oldVersion);
687             return;
688         }
689         mCompatOverrides.put(rilRequest, halVersion);
690     }
691 
692     /** Get a radio HAL fallback compatibility override, or null if not exist. */
693     @VisibleForTesting
getCompatVersion(int rilRequest)694     public @Nullable HalVersion getCompatVersion(int rilRequest) {
695         return mCompatOverrides.getOrDefault(rilRequest, null);
696     }
697 
698     /** Returns a {@link IRadio} instance or null if the service is not available. */
699     @VisibleForTesting
getRadioProxy()700     public synchronized IRadio getRadioProxy() {
701         if (mHalVersion.containsKey(HAL_SERVICE_RADIO)
702                 && mHalVersion.get(HAL_SERVICE_RADIO).greaterOrEqual(RADIO_HAL_VERSION_2_0)) {
703             return null;
704         }
705         if (!SubscriptionManager.isValidPhoneId(mPhoneId)) return null;
706         if (!mIsCellularSupported) {
707             if (RILJ_LOGV) riljLog("getRadioProxy: Not calling getService(): wifi-only");
708             return null;
709         }
710 
711         if (mRadioProxy != null) {
712             return mRadioProxy;
713         }
714 
715         try {
716             if (mDisabledRadioServices.get(HAL_SERVICE_RADIO).contains(mPhoneId)) {
717                 riljLoge("getRadioProxy: mRadioProxy for " + HIDL_SERVICE_NAME[mPhoneId]
718                         + " is disabled");
719                 return null;
720             } else {
721                 try {
722                     mRadioProxy = android.hardware.radio.V1_6.IRadio.getService(
723                             HIDL_SERVICE_NAME[mPhoneId], true);
724                     mHalVersion.put(HAL_SERVICE_RADIO, RADIO_HAL_VERSION_1_6);
725                 } catch (NoSuchElementException e) {
726                 }
727 
728                 if (mRadioProxy == null) {
729                     try {
730                         mRadioProxy = android.hardware.radio.V1_5.IRadio.getService(
731                                 HIDL_SERVICE_NAME[mPhoneId], true);
732                         mHalVersion.put(HAL_SERVICE_RADIO, RADIO_HAL_VERSION_1_5);
733                     } catch (NoSuchElementException e) {
734                     }
735                 }
736 
737                 if (mRadioProxy == null) {
738                     try {
739                         mRadioProxy = android.hardware.radio.V1_4.IRadio.getService(
740                                 HIDL_SERVICE_NAME[mPhoneId], true);
741                         mHalVersion.put(HAL_SERVICE_RADIO, RADIO_HAL_VERSION_1_4);
742                     } catch (NoSuchElementException e) {
743                     }
744                 }
745 
746                 if (mRadioProxy == null) {
747                     riljLoge("IRadio <1.4 is no longer supported.");
748                 }
749 
750                 if (mRadioProxy != null) {
751                     if (!mIsRadioProxyInitialized) {
752                         mIsRadioProxyInitialized = true;
753                         mRadioProxy.linkToDeath(mRadioProxyDeathRecipient,
754                                 mServiceCookies.get(HAL_SERVICE_RADIO).incrementAndGet());
755                         mRadioProxy.setResponseFunctions(mRadioResponse, mRadioIndication);
756                     }
757                 } else {
758                     mDisabledRadioServices.get(HAL_SERVICE_RADIO).add(mPhoneId);
759                     riljLoge("getRadioProxy: set mRadioProxy for "
760                             + HIDL_SERVICE_NAME[mPhoneId] + " as disabled");
761                     return null;
762                 }
763             }
764         } catch (RemoteException e) {
765             mRadioProxy = null;
766             riljLoge("RadioProxy getService/setResponseFunctions: " + e);
767         }
768 
769         if (mRadioProxy == null) {
770             // getService() is a blocking call, so this should never happen
771             riljLoge("getRadioProxy: mRadioProxy == null");
772         }
773 
774         return mRadioProxy;
775     }
776 
777     /**
778      * Returns a {@link RadioDataProxy}, {@link RadioMessagingProxy}, {@link RadioModemProxy},
779      * {@link RadioNetworkProxy}, {@link RadioSimProxy}, {@link RadioVoiceProxy},
780      * {@link RadioImsProxy}, or null if the service is not available.
781      */
782     @NonNull
getRadioServiceProxy(Class<T> serviceClass)783     public <T extends RadioServiceProxy> T getRadioServiceProxy(Class<T> serviceClass) {
784         if (serviceClass == RadioDataProxy.class) {
785             return (T) getRadioServiceProxy(HAL_SERVICE_DATA);
786         }
787         if (serviceClass == RadioMessagingProxy.class) {
788             return (T) getRadioServiceProxy(HAL_SERVICE_MESSAGING);
789         }
790         if (serviceClass == RadioModemProxy.class) {
791             return (T) getRadioServiceProxy(HAL_SERVICE_MODEM);
792         }
793         if (serviceClass == RadioNetworkProxy.class) {
794             return (T) getRadioServiceProxy(HAL_SERVICE_NETWORK);
795         }
796         if (serviceClass == RadioSimProxy.class) {
797             return (T) getRadioServiceProxy(HAL_SERVICE_SIM);
798         }
799         if (serviceClass == RadioVoiceProxy.class) {
800             return (T) getRadioServiceProxy(HAL_SERVICE_VOICE);
801         }
802         if (serviceClass == RadioImsProxy.class) {
803             return (T) getRadioServiceProxy(HAL_SERVICE_IMS);
804         }
805         riljLoge("getRadioServiceProxy: unrecognized " + serviceClass);
806         return null;
807     }
808 
809     /**
810      * Returns a {@link RadioServiceProxy}, which is empty if the service is not available.
811      * For HAL_SERVICE_RADIO, use {@link #getRadioProxy} instead, as this will always return null.
812      */
813     @VisibleForTesting
814     @NonNull
getRadioServiceProxy(int service)815     public synchronized RadioServiceProxy getRadioServiceProxy(int service) {
816         if (!SubscriptionManager.isValidPhoneId(mPhoneId)) return mServiceProxies.get(service);
817         if ((service >= HAL_SERVICE_IMS) && !isRadioServiceSupported(service)) {
818             // Suppress the excessive logging for HAL_SERVICE_IMS when not supported.
819             if (service != HAL_SERVICE_IMS) {
820                 riljLogw("getRadioServiceProxy: " + serviceToString(service) + " for "
821                         + HIDL_SERVICE_NAME[mPhoneId] + " is not supported\n"
822                         + android.util.Log.getStackTraceString(new RuntimeException()));
823             }
824             return mServiceProxies.get(service);
825         }
826         if (!mIsCellularSupported) {
827             if (RILJ_LOGV) riljLog("getRadioServiceProxy: Not calling getService(): wifi-only");
828             return mServiceProxies.get(service);
829         }
830 
831         RadioServiceProxy serviceProxy = mServiceProxies.get(service);
832         if (!serviceProxy.isEmpty()) {
833             return serviceProxy;
834         }
835 
836         try {
837             if (mMockModem == null && mDisabledRadioServices.get(service).contains(mPhoneId)) {
838                 riljLoge("getRadioServiceProxy: " + serviceToString(service) + " for "
839                         + HIDL_SERVICE_NAME[mPhoneId] + " is disabled\n"
840                         + android.util.Log.getStackTraceString(new RuntimeException()));
841                 return null;
842             } else {
843                 IBinder binder;
844                 switch (service) {
845                     case HAL_SERVICE_DATA:
846                         if (mMockModem == null) {
847                             binder = ServiceManager.waitForDeclaredService(
848                                     android.hardware.radio.data.IRadioData.DESCRIPTOR + "/"
849                                             + HIDL_SERVICE_NAME[mPhoneId]);
850                         } else {
851                             binder = mMockModem.getServiceBinder(HAL_SERVICE_DATA);
852                         }
853                         if (binder != null) {
854                             mHalVersion.put(service, ((RadioDataProxy) serviceProxy).setAidl(
855                                     mHalVersion.get(service),
856                                     android.hardware.radio.data.IRadioData.Stub.asInterface(
857                                             binder)));
858                         }
859                         break;
860                     case HAL_SERVICE_MESSAGING:
861                         if (mMockModem == null) {
862                             binder = ServiceManager.waitForDeclaredService(
863                                     android.hardware.radio.messaging.IRadioMessaging.DESCRIPTOR
864                                             + "/" + HIDL_SERVICE_NAME[mPhoneId]);
865                         } else {
866                             binder = mMockModem.getServiceBinder(HAL_SERVICE_MESSAGING);
867                         }
868                         if (binder != null) {
869                             mHalVersion.put(service, ((RadioMessagingProxy) serviceProxy).setAidl(
870                                     mHalVersion.get(service),
871                                     android.hardware.radio.messaging.IRadioMessaging.Stub
872                                             .asInterface(binder)));
873                         }
874                         break;
875                     case HAL_SERVICE_MODEM:
876                         if (mMockModem == null) {
877                             binder = ServiceManager.waitForDeclaredService(
878                                     android.hardware.radio.modem.IRadioModem.DESCRIPTOR + "/"
879                                             + HIDL_SERVICE_NAME[mPhoneId]);
880                         } else {
881                             binder = mMockModem.getServiceBinder(HAL_SERVICE_MODEM);
882                         }
883                         if (binder != null) {
884                             mHalVersion.put(service, ((RadioModemProxy) serviceProxy).setAidl(
885                                     mHalVersion.get(service),
886                                     android.hardware.radio.modem.IRadioModem.Stub
887                                             .asInterface(binder)));
888                         }
889                         break;
890                     case HAL_SERVICE_NETWORK:
891                         if (mMockModem == null) {
892                             binder = ServiceManager.waitForDeclaredService(
893                                     android.hardware.radio.network.IRadioNetwork.DESCRIPTOR + "/"
894                                             + HIDL_SERVICE_NAME[mPhoneId]);
895                         } else {
896                             binder = mMockModem.getServiceBinder(HAL_SERVICE_NETWORK);
897                         }
898                         if (binder != null) {
899                             mHalVersion.put(service, ((RadioNetworkProxy) serviceProxy).setAidl(
900                                     mHalVersion.get(service),
901                                     android.hardware.radio.network.IRadioNetwork.Stub
902                                             .asInterface(binder)));
903                         }
904                         break;
905                     case HAL_SERVICE_SIM:
906                         if (mMockModem == null) {
907                             binder = ServiceManager.waitForDeclaredService(
908                                     android.hardware.radio.sim.IRadioSim.DESCRIPTOR + "/"
909                                             + HIDL_SERVICE_NAME[mPhoneId]);
910                         } else {
911                             binder = mMockModem.getServiceBinder(HAL_SERVICE_SIM);
912                         }
913                         if (binder != null) {
914                             mHalVersion.put(service, ((RadioSimProxy) serviceProxy).setAidl(
915                                     mHalVersion.get(service),
916                                     android.hardware.radio.sim.IRadioSim.Stub
917                                             .asInterface(binder)));
918                         }
919                         break;
920                     case HAL_SERVICE_VOICE:
921                         if (mMockModem == null) {
922                             binder = ServiceManager.waitForDeclaredService(
923                                     android.hardware.radio.voice.IRadioVoice.DESCRIPTOR + "/"
924                                             + HIDL_SERVICE_NAME[mPhoneId]);
925                         } else {
926                             binder = mMockModem.getServiceBinder(HAL_SERVICE_VOICE);
927                         }
928                         if (binder != null) {
929                             mHalVersion.put(service, ((RadioVoiceProxy) serviceProxy).setAidl(
930                                     mHalVersion.get(service),
931                                     android.hardware.radio.voice.IRadioVoice.Stub
932                                             .asInterface(binder)));
933                         }
934                         break;
935                     case HAL_SERVICE_IMS:
936                         if (mMockModem == null) {
937                             binder = ServiceManager.waitForDeclaredService(
938                                     android.hardware.radio.ims.IRadioIms.DESCRIPTOR + "/"
939                                             + HIDL_SERVICE_NAME[mPhoneId]);
940                         } else {
941                             binder = mMockModem.getServiceBinder(HAL_SERVICE_IMS);
942                         }
943                         if (binder != null) {
944                             mHalVersion.put(service, ((RadioImsProxy) serviceProxy).setAidl(
945                                     mHalVersion.get(service),
946                                     android.hardware.radio.ims.IRadioIms.Stub
947                                             .asInterface(binder)));
948                         }
949                         break;
950                 }
951 
952                 if (serviceProxy.isEmpty()
953                         && mHalVersion.get(service).less(RADIO_HAL_VERSION_2_0)) {
954                     try {
955                         mHalVersion.put(service, RADIO_HAL_VERSION_1_6);
956                         serviceProxy.setHidl(mHalVersion.get(service),
957                                 android.hardware.radio.V1_6.IRadio.getService(
958                                         HIDL_SERVICE_NAME[mPhoneId], true));
959                     } catch (NoSuchElementException e) {
960                     }
961                 }
962 
963                 if (serviceProxy.isEmpty()
964                         && mHalVersion.get(service).less(RADIO_HAL_VERSION_2_0)) {
965                     try {
966                         mHalVersion.put(service, RADIO_HAL_VERSION_1_5);
967                         serviceProxy.setHidl(mHalVersion.get(service),
968                                 android.hardware.radio.V1_5.IRadio.getService(
969                                         HIDL_SERVICE_NAME[mPhoneId], true));
970                     } catch (NoSuchElementException e) {
971                     }
972                 }
973 
974                 if (serviceProxy.isEmpty()
975                         && mHalVersion.get(service).less(RADIO_HAL_VERSION_2_0)) {
976                     try {
977                         mHalVersion.put(service, RADIO_HAL_VERSION_1_4);
978                         serviceProxy.setHidl(mHalVersion.get(service),
979                                 android.hardware.radio.V1_4.IRadio.getService(
980                                         HIDL_SERVICE_NAME[mPhoneId], true));
981                     } catch (NoSuchElementException e) {
982                     }
983                 }
984 
985                 if (serviceProxy.isEmpty()
986                         && mHalVersion.get(service).less(RADIO_HAL_VERSION_2_0)) {
987                     riljLoge("IRadio <1.4 is no longer supported.");
988                 }
989 
990                 if (!serviceProxy.isEmpty()) {
991                     if (serviceProxy.isAidl()) {
992                         switch (service) {
993                             case HAL_SERVICE_DATA:
994                                 mDeathRecipients.get(service).linkToDeath(
995                                         ((RadioDataProxy) serviceProxy).getAidl().asBinder());
996                                 ((RadioDataProxy) serviceProxy).getAidl().setResponseFunctions(
997                                         mDataResponse, mDataIndication);
998                                 break;
999                             case HAL_SERVICE_MESSAGING:
1000                                 mDeathRecipients.get(service).linkToDeath(
1001                                         ((RadioMessagingProxy) serviceProxy).getAidl().asBinder());
1002                                 ((RadioMessagingProxy) serviceProxy).getAidl().setResponseFunctions(
1003                                         mMessagingResponse, mMessagingIndication);
1004                                 break;
1005                             case HAL_SERVICE_MODEM:
1006                                 mDeathRecipients.get(service).linkToDeath(
1007                                         ((RadioModemProxy) serviceProxy).getAidl().asBinder());
1008                                 ((RadioModemProxy) serviceProxy).getAidl().setResponseFunctions(
1009                                         mModemResponse, mModemIndication);
1010                                 break;
1011                             case HAL_SERVICE_NETWORK:
1012                                 mDeathRecipients.get(service).linkToDeath(
1013                                         ((RadioNetworkProxy) serviceProxy).getAidl().asBinder());
1014                                 ((RadioNetworkProxy) serviceProxy).getAidl().setResponseFunctions(
1015                                         mNetworkResponse, mNetworkIndication);
1016                                 break;
1017                             case HAL_SERVICE_SIM:
1018                                 mDeathRecipients.get(service).linkToDeath(
1019                                         ((RadioSimProxy) serviceProxy).getAidl().asBinder());
1020                                 ((RadioSimProxy) serviceProxy).getAidl().setResponseFunctions(
1021                                         mSimResponse, mSimIndication);
1022                                 break;
1023                             case HAL_SERVICE_VOICE:
1024                                 mDeathRecipients.get(service).linkToDeath(
1025                                         ((RadioVoiceProxy) serviceProxy).getAidl().asBinder());
1026                                 ((RadioVoiceProxy) serviceProxy).getAidl().setResponseFunctions(
1027                                         mVoiceResponse, mVoiceIndication);
1028                                 break;
1029                             case HAL_SERVICE_IMS:
1030                                 mDeathRecipients.get(service).linkToDeath(
1031                                         ((RadioImsProxy) serviceProxy).getAidl().asBinder());
1032                                 ((RadioImsProxy) serviceProxy).getAidl().setResponseFunctions(
1033                                         mImsResponse, mImsIndication);
1034                                 break;
1035                         }
1036                     } else {
1037                         if (mHalVersion.get(service).greaterOrEqual(RADIO_HAL_VERSION_2_0)) {
1038                             throw new AssertionError("serviceProxy shouldn't be HIDL with HAL 2.0");
1039                         }
1040                         if (!mIsRadioProxyInitialized) {
1041                             mIsRadioProxyInitialized = true;
1042                             serviceProxy.getHidl().linkToDeath(mRadioProxyDeathRecipient,
1043                                     mServiceCookies.get(HAL_SERVICE_RADIO).incrementAndGet());
1044                             serviceProxy.getHidl().setResponseFunctions(
1045                                     mRadioResponse, mRadioIndication);
1046                         }
1047                     }
1048                 } else {
1049                     mDisabledRadioServices.get(service).add(mPhoneId);
1050                     mHalVersion.put(service, RADIO_HAL_VERSION_UNKNOWN);
1051                     riljLoge("getRadioServiceProxy: set " + serviceToString(service) + " for "
1052                             + HIDL_SERVICE_NAME[mPhoneId] + " as disabled\n"
1053                             + android.util.Log.getStackTraceString(new RuntimeException()));
1054                 }
1055             }
1056         } catch (RemoteException e) {
1057             serviceProxy.clear();
1058             riljLoge("ServiceProxy getService/setResponseFunctions: " + e);
1059         }
1060 
1061         if (serviceProxy.isEmpty()) {
1062             // getService() is a blocking call, so this should never happen
1063             riljLoge("getRadioServiceProxy: serviceProxy == null");
1064         }
1065 
1066         return serviceProxy;
1067     }
1068 
1069     @Override
onSlotActiveStatusChange(boolean active)1070     public synchronized void onSlotActiveStatusChange(boolean active) {
1071         mIsRadioProxyInitialized = false;
1072         if (mFeatureFlags.combineRilDeathHandle()) {
1073             if (active) {
1074                 for (int service = MIN_SERVICE_IDX; service <= MAX_SERVICE_IDX; service++) {
1075                     // Try to connect to RIL services and set response functions.
1076                     if (service == HAL_SERVICE_RADIO) {
1077                         getRadioProxy();
1078                     } else {
1079                         getRadioServiceProxy(service);
1080                     }
1081                 }
1082             } else {
1083                 // Reset both hidl and aidl proxies
1084                 resetProxyAndRequestList(HAL_SERVICE_RADIO);
1085                 resetProxyAndRequestList(HAL_SERVICE_DATA);
1086             }
1087         } else {
1088             for (int service = MIN_SERVICE_IDX; service <= MAX_SERVICE_IDX; service++) {
1089                 if (active) {
1090                     // Try to connect to RIL services and set response functions.
1091                     if (service == HAL_SERVICE_RADIO) {
1092                         getRadioProxy();
1093                     } else {
1094                         getRadioServiceProxy(service);
1095                     }
1096                 } else {
1097                     resetProxyAndRequestList(service);
1098                 }
1099             }
1100         }
1101     }
1102 
1103     //***** Constructors
1104 
1105     @UnsupportedAppUsage
RIL(Context context, int allowedNetworkTypes, int cdmaSubscription, Integer instanceId, @NonNull FeatureFlags flags)1106     public RIL(Context context, int allowedNetworkTypes, int cdmaSubscription, Integer instanceId,
1107             @NonNull FeatureFlags flags) {
1108         this(context, allowedNetworkTypes, cdmaSubscription, instanceId, null, flags);
1109     }
1110 
1111     @VisibleForTesting
RIL(Context context, int allowedNetworkTypes, int cdmaSubscription, Integer instanceId, SparseArray<RadioServiceProxy> proxies, @NonNull FeatureFlags flags)1112     public RIL(Context context, int allowedNetworkTypes, int cdmaSubscription, Integer instanceId,
1113             SparseArray<RadioServiceProxy> proxies, @NonNull FeatureFlags flags) {
1114         super(context);
1115         mFeatureFlags = flags;
1116         if (RILJ_LOGD) {
1117             riljLog("RIL: init allowedNetworkTypes=" + allowedNetworkTypes
1118                     + " cdmaSubscription=" + cdmaSubscription + ")");
1119         }
1120 
1121         mContext = context;
1122         mCdmaSubscription  = cdmaSubscription;
1123         mAllowedNetworkTypesBitmask = allowedNetworkTypes;
1124         mPhoneType = RILConstants.NO_PHONE;
1125         mPhoneId = instanceId == null ? 0 : instanceId;
1126         if (isRadioBugDetectionEnabled()) {
1127             mRadioBugDetector = new RadioBugDetector(context, mPhoneId);
1128         }
1129         try {
1130             if (isRadioVersion2_0()) {
1131                 mHalVersion.put(HAL_SERVICE_RADIO, RADIO_HAL_VERSION_2_0);
1132             } else {
1133                 mHalVersion.put(HAL_SERVICE_RADIO, RADIO_HAL_VERSION_UNKNOWN);
1134             }
1135         } catch (SecurityException ex) {
1136             /* TODO(b/211920208): instead of the following workaround (guessing if we're in a test
1137              * based on proxies being populated), mock ServiceManager to not throw
1138              * SecurityException and return correct value based on what HAL we're testing. */
1139             if (proxies == null) throw ex;
1140         }
1141 
1142         TelephonyManager tm = (TelephonyManager) context.getSystemService(
1143                 Context.TELEPHONY_SERVICE);
1144         mIsCellularSupported = tm.isVoiceCapable() || tm.isSmsCapable() || tm.isDataCapable();
1145 
1146         mRadioResponse = new RadioResponse(this);
1147         mRadioIndication = new RadioIndication(this);
1148         mDataResponse = new DataResponse(this);
1149         mDataIndication = new DataIndication(this);
1150         mImsResponse = new ImsResponse(this);
1151         mImsIndication = new ImsIndication(this);
1152         mMessagingResponse = new MessagingResponse(this);
1153         mMessagingIndication = new MessagingIndication(this);
1154         mModemResponse = new ModemResponse(this);
1155         mModemIndication = new ModemIndication(this);
1156         mNetworkResponse = new NetworkResponse(this);
1157         mNetworkIndication = new NetworkIndication(this);
1158         mSimResponse = new SimResponse(this);
1159         mSimIndication = new SimIndication(this);
1160         mVoiceResponse = new VoiceResponse(this);
1161         mVoiceIndication = new VoiceIndication(this);
1162         mRilHandler = new RilHandler();
1163         mRadioProxyDeathRecipient = new RadioProxyDeathRecipient();
1164         for (int service = MIN_SERVICE_IDX; service <= MAX_SERVICE_IDX; service++) {
1165             if (service != HAL_SERVICE_RADIO) {
1166                 try {
1167                     if (isRadioServiceSupported(service)) {
1168                         mHalVersion.put(service, RADIO_HAL_VERSION_UNKNOWN);
1169                     } else {
1170                         mHalVersion.put(service, RADIO_HAL_VERSION_UNSUPPORTED);
1171                     }
1172                 } catch (SecurityException ex) {
1173                     /* TODO(b/211920208): instead of the following workaround (guessing if
1174                      * we're in a test based on proxies being populated), mock ServiceManager
1175                      * to not throw SecurityException and return correct value based on what
1176                      * HAL we're testing. */
1177                     if (proxies == null) throw ex;
1178                 }
1179                 mDeathRecipients.put(service, new BinderServiceDeathRecipient(service));
1180             }
1181             mDisabledRadioServices.put(service, new HashSet<>());
1182             mServiceCookies.put(service, new AtomicLong(0));
1183         }
1184         if (proxies == null) {
1185             mServiceProxies.put(HAL_SERVICE_DATA, new RadioDataProxy());
1186             mServiceProxies.put(HAL_SERVICE_MESSAGING, new RadioMessagingProxy());
1187             mServiceProxies.put(HAL_SERVICE_MODEM, new RadioModemProxy());
1188             mServiceProxies.put(HAL_SERVICE_NETWORK, new RadioNetworkProxy());
1189             mServiceProxies.put(HAL_SERVICE_SIM, new RadioSimProxy());
1190             mServiceProxies.put(HAL_SERVICE_VOICE, new RadioVoiceProxy());
1191             mServiceProxies.put(HAL_SERVICE_IMS, new RadioImsProxy());
1192         } else {
1193             mServiceProxies = proxies;
1194         }
1195 
1196         PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1197         mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, RILJ_WAKELOCK_TAG);
1198         mWakeLock.setReferenceCounted(false);
1199         mAckWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, RILJ_ACK_WAKELOCK_NAME);
1200         mAckWakeLock.setReferenceCounted(false);
1201         mWakeLockTimeout = TelephonyProperties.wake_lock_timeout()
1202                 .orElse(DEFAULT_WAKE_LOCK_TIMEOUT_MS);
1203         mAckWakeLockTimeout = TelephonyProperties.wake_lock_timeout()
1204                 .orElse(DEFAULT_ACK_WAKE_LOCK_TIMEOUT_MS);
1205         mWakeLockCount = 0;
1206         mRILDefaultWorkSource = new WorkSource(context.getApplicationInfo().uid,
1207                 context.getPackageName());
1208         mActiveWakelockWorkSource = new WorkSource();
1209 
1210         TelephonyDevController tdc = TelephonyDevController.getInstance();
1211         if (proxies == null) {
1212             // TelephonyDevController#registerRIL will call getHardwareConfig.
1213             // To prevent extra requests when running tests, only registerRIL when proxies is null
1214             tdc.registerRIL(this);
1215         }
1216 
1217         validateFeatureFlags();
1218 
1219         // Set radio callback; needed to set RadioIndication callback (should be done after
1220         // wakelock stuff is initialized above as callbacks are received on separate binder threads)
1221         for (int service = MIN_SERVICE_IDX; service <= MAX_SERVICE_IDX; service++) {
1222             if (isRadioVersion2_0() && !isRadioServiceSupported(service)) {
1223                 riljLog("Not initializing " + serviceToString(service) + " (not supported)");
1224                 continue;
1225             }
1226 
1227             if (service == HAL_SERVICE_RADIO) {
1228                 getRadioProxy();
1229             } else {
1230                 if (proxies == null) {
1231                     // Prevent telephony tests from calling the service
1232                     getRadioServiceProxy(service);
1233                 }
1234             }
1235 
1236             if (RILJ_LOGD) {
1237                 riljLog("HAL version of " + serviceToString(service)
1238                         + ": " + mHalVersion.get(service));
1239             }
1240         }
1241     }
1242 
isRadioVersion2_0()1243     private boolean isRadioVersion2_0() {
1244         if (mIsRadioVersion20Cached != null) return mIsRadioVersion20Cached;
1245         for (int service = HAL_SERVICE_DATA; service <= MAX_SERVICE_IDX; service++) {
1246             if (isRadioServiceSupported(service)) {
1247                 return mIsRadioVersion20Cached = true;
1248             }
1249         }
1250         return mIsRadioVersion20Cached = false;
1251     }
1252 
isRadioServiceSupported(int service)1253     private boolean isRadioServiceSupported(int service) {
1254         String serviceName = "";
1255 
1256         if (service == HAL_SERVICE_RADIO) {
1257             return true;
1258         }
1259 
1260         switch (service) {
1261             case HAL_SERVICE_DATA:
1262                 serviceName = android.hardware.radio.data.IRadioData.DESCRIPTOR;
1263                 break;
1264             case HAL_SERVICE_MESSAGING:
1265                 serviceName = android.hardware.radio.messaging.IRadioMessaging.DESCRIPTOR;
1266                 break;
1267             case HAL_SERVICE_MODEM:
1268                 serviceName = android.hardware.radio.modem.IRadioModem.DESCRIPTOR;
1269                 break;
1270             case HAL_SERVICE_NETWORK:
1271                 serviceName = android.hardware.radio.network.IRadioNetwork.DESCRIPTOR;
1272                 break;
1273             case HAL_SERVICE_SIM:
1274                 serviceName = android.hardware.radio.sim.IRadioSim.DESCRIPTOR;
1275                 break;
1276             case HAL_SERVICE_VOICE:
1277                 serviceName = android.hardware.radio.voice.IRadioVoice.DESCRIPTOR;
1278                 break;
1279             case HAL_SERVICE_IMS:
1280                 serviceName = android.hardware.radio.ims.IRadioIms.DESCRIPTOR;
1281                 break;
1282         }
1283 
1284         if (!serviceName.equals("")
1285                 && ServiceManager.isDeclared(serviceName + '/' + HIDL_SERVICE_NAME[mPhoneId])) {
1286             return true;
1287         }
1288 
1289         return false;
1290     }
1291 
validateFeatureFlags()1292     private void validateFeatureFlags() {
1293         PackageManager pm = mContext.getPackageManager();
1294         for (var entry : FEATURES_TO_SERVICES.entrySet()) {
1295             String feature = entry.getKey();
1296             int service = entry.getValue();
1297 
1298             boolean hasFeature = pm.hasSystemFeature(feature);
1299             boolean hasService = isRadioServiceSupported(service);
1300 
1301             if (hasFeature && !hasService) {
1302                 riljLoge("Feature " + feature + " is declared, but service "
1303                         + serviceToString(service) + " is missing");
1304             }
1305             if (!hasFeature && hasService) {
1306                 riljLoge("Service " + serviceToString(service) + " is available, but feature "
1307                         + feature + " is not declared");
1308             }
1309         }
1310     }
1311 
isRadioBugDetectionEnabled()1312     private boolean isRadioBugDetectionEnabled() {
1313         return Settings.Global.getInt(mContext.getContentResolver(),
1314                 Settings.Global.ENABLE_RADIO_BUG_DETECTION, 1) != 0;
1315     }
1316 
1317     @Override
setOnNITZTime(Handler h, int what, Object obj)1318     public void setOnNITZTime(Handler h, int what, Object obj) {
1319         super.setOnNITZTime(h, what, obj);
1320 
1321         // Send the last NITZ time if we have it
1322         if (mLastNITZTimeInfo != null) {
1323             mNITZTimeRegistrant.notifyRegistrant(new AsyncResult(null, mLastNITZTimeInfo, null));
1324         }
1325     }
1326 
addRequest(RILRequest rr)1327     private void addRequest(RILRequest rr) {
1328         acquireWakeLock(rr, FOR_WAKELOCK);
1329         Trace.asyncTraceForTrackBegin(
1330                 Trace.TRACE_TAG_NETWORK, "RIL", rr.mSerial + "> "
1331                 + RILUtils.requestToString(rr.mRequest), rr.mSerial);
1332         synchronized (mRequestList) {
1333             rr.mStartTimeMs = SystemClock.elapsedRealtime();
1334             mRequestList.append(rr.mSerial, rr);
1335         }
1336     }
1337 
obtainRequest(int request, Message result, WorkSource workSource)1338     private RILRequest obtainRequest(int request, Message result, WorkSource workSource) {
1339         RILRequest rr = RILRequest.obtain(request, result, workSource);
1340         addRequest(rr);
1341         return rr;
1342     }
1343 
obtainRequest(int request, Message result, WorkSource workSource, Object... args)1344     private RILRequest obtainRequest(int request, Message result, WorkSource workSource,
1345             Object... args) {
1346         RILRequest rr = RILRequest.obtain(request, result, workSource, args);
1347         addRequest(rr);
1348         return rr;
1349     }
1350 
handleRadioProxyExceptionForRR(int service, String caller, Exception e)1351     private void handleRadioProxyExceptionForRR(int service, String caller, Exception e) {
1352         riljLoge(caller + ": " + e);
1353         e.printStackTrace();
1354         mIsRadioProxyInitialized = false;
1355         resetProxyAndRequestList(service);
1356     }
1357 
radioServiceInvokeHelper(int service, RILRequest rr, String methodName, FunctionalUtils.ThrowingRunnable helper)1358     private void radioServiceInvokeHelper(int service, RILRequest rr, String methodName,
1359             FunctionalUtils.ThrowingRunnable helper) {
1360         try {
1361             helper.runOrThrow();
1362         } catch (RuntimeException e) {
1363             riljLoge(methodName + " RuntimeException: " + e);
1364             int error = RadioError.SYSTEM_ERR;
1365             int responseType = RadioResponseType.SOLICITED;
1366             processResponseInternal(service, rr.mSerial, error, responseType);
1367             processResponseDoneInternal(rr, error, responseType, null);
1368         } catch (Exception e) {
1369             handleRadioProxyExceptionForRR(service, methodName, e);
1370         }
1371     }
1372 
canMakeRequest(String request, RadioServiceProxy proxy, Message result, HalVersion version)1373     private boolean canMakeRequest(String request, RadioServiceProxy proxy, Message result,
1374             HalVersion version) {
1375         int service = HAL_SERVICE_RADIO;
1376         if (proxy instanceof RadioDataProxy) {
1377             service = HAL_SERVICE_DATA;
1378         } else if (proxy instanceof RadioMessagingProxy) {
1379             service = HAL_SERVICE_MESSAGING;
1380         } else if (proxy instanceof RadioModemProxy) {
1381             service = HAL_SERVICE_MODEM;
1382         } else if (proxy instanceof RadioNetworkProxy) {
1383             service = HAL_SERVICE_NETWORK;
1384         } else if (proxy instanceof RadioSimProxy) {
1385             service = HAL_SERVICE_SIM;
1386         } else if (proxy instanceof RadioVoiceProxy) {
1387             service = HAL_SERVICE_VOICE;
1388         } else if (proxy instanceof RadioImsProxy) {
1389             service = HAL_SERVICE_IMS;
1390         }
1391         if (proxy == null || proxy.isEmpty()) {
1392             riljLoge(String.format("Unable to complete %s because service %s is not available.",
1393                     request, serviceToString(service)));
1394             if (result != null) {
1395                 AsyncResult.forMessage(result, null,
1396                         CommandException.fromRilErrno(RADIO_NOT_AVAILABLE));
1397                 result.sendToTarget();
1398             }
1399             return false;
1400         }
1401         if (mHalVersion.get(service).less(version)) {
1402             riljLoge(String.format("%s not supported on service %s < %s.",
1403                     request, serviceToString(service), version));
1404             if (result != null) {
1405                 AsyncResult.forMessage(result, null,
1406                         CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
1407                 result.sendToTarget();
1408             }
1409             return false;
1410         }
1411         return true;
1412     }
1413 
1414     @Override
getIccCardStatus(Message result)1415     public void getIccCardStatus(Message result) {
1416         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
1417         if (!canMakeRequest("getIccCardStatus", simProxy, result, RADIO_HAL_VERSION_1_4)) {
1418             return;
1419         }
1420 
1421         RILRequest rr = obtainRequest(RIL_REQUEST_GET_SIM_STATUS, result, mRILDefaultWorkSource);
1422 
1423         if (RILJ_LOGD) {
1424             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
1425         }
1426 
1427         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "getIccCardStatus", () -> {
1428             simProxy.getIccCardStatus(rr.mSerial);
1429         });
1430     }
1431 
1432     @Override
supplyIccPin(String pin, Message result)1433     public void supplyIccPin(String pin, Message result) {
1434         supplyIccPinForApp(pin, null, result);
1435     }
1436 
1437     @Override
supplyIccPinForApp(String pin, String aid, Message result)1438     public void supplyIccPinForApp(String pin, String aid, Message result) {
1439         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
1440         if (!canMakeRequest("supplyIccPinForApp", simProxy, result, RADIO_HAL_VERSION_1_4)) {
1441             return;
1442         }
1443 
1444         RILRequest rr = obtainRequest(RIL_REQUEST_ENTER_SIM_PIN, result, mRILDefaultWorkSource);
1445 
1446         if (RILJ_LOGD) {
1447             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
1448                     + " aid = " + aid);
1449         }
1450 
1451         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "supplyIccPinForApp", () -> {
1452             simProxy.supplyIccPinForApp(rr.mSerial, RILUtils.convertNullToEmptyString(pin),
1453                     RILUtils.convertNullToEmptyString(aid));
1454         });
1455     }
1456 
1457     @Override
supplyIccPuk(String puk, String newPin, Message result)1458     public void supplyIccPuk(String puk, String newPin, Message result) {
1459         supplyIccPukForApp(puk, newPin, null, result);
1460     }
1461 
1462     @Override
supplyIccPukForApp(String puk, String newPin, String aid, Message result)1463     public void supplyIccPukForApp(String puk, String newPin, String aid, Message result) {
1464         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
1465         if (!canMakeRequest("supplyIccPukForApp", simProxy, result, RADIO_HAL_VERSION_1_4)) {
1466             return;
1467         }
1468 
1469         RILRequest rr = obtainRequest(RIL_REQUEST_ENTER_SIM_PUK, result, mRILDefaultWorkSource);
1470 
1471         String pukStr = RILUtils.convertNullToEmptyString(puk);
1472         if (RILJ_LOGD) {
1473             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
1474                     + " isPukEmpty = " + pukStr.isEmpty() + " aid = " + aid);
1475         }
1476 
1477         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "supplyIccPukForApp", () -> {
1478             simProxy.supplyIccPukForApp(rr.mSerial, pukStr,
1479                     RILUtils.convertNullToEmptyString(newPin),
1480                     RILUtils.convertNullToEmptyString(aid));
1481         });
1482     }
1483 
1484     @Override
supplyIccPin2(String pin, Message result)1485     public void supplyIccPin2(String pin, Message result) {
1486         supplyIccPin2ForApp(pin, null, result);
1487     }
1488 
1489     @Override
supplyIccPin2ForApp(String pin, String aid, Message result)1490     public void supplyIccPin2ForApp(String pin, String aid, Message result) {
1491         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
1492         if (!canMakeRequest("supplyIccPin2ForApp", simProxy, result, RADIO_HAL_VERSION_1_4)) {
1493             return;
1494         }
1495 
1496         RILRequest rr = obtainRequest(RIL_REQUEST_ENTER_SIM_PIN2, result, mRILDefaultWorkSource);
1497 
1498         if (RILJ_LOGD) {
1499             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
1500                     + " aid = " + aid);
1501         }
1502 
1503         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "supplyIccPin2ForApp", () -> {
1504             simProxy.supplyIccPin2ForApp(rr.mSerial, RILUtils.convertNullToEmptyString(pin),
1505                     RILUtils.convertNullToEmptyString(aid));
1506         });
1507     }
1508 
1509     @Override
supplyIccPuk2(String puk2, String newPin2, Message result)1510     public void supplyIccPuk2(String puk2, String newPin2, Message result) {
1511         supplyIccPuk2ForApp(puk2, newPin2, null, result);
1512     }
1513 
1514     @Override
supplyIccPuk2ForApp(String puk, String newPin2, String aid, Message result)1515     public void supplyIccPuk2ForApp(String puk, String newPin2, String aid, Message result) {
1516         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
1517         if (!canMakeRequest("supplyIccPuk2ForApp", simProxy, result, RADIO_HAL_VERSION_1_4)) {
1518             return;
1519         }
1520 
1521         RILRequest rr = obtainRequest(RIL_REQUEST_ENTER_SIM_PUK2, result, mRILDefaultWorkSource);
1522 
1523         if (RILJ_LOGD) {
1524             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
1525                     + " aid = " + aid);
1526         }
1527 
1528         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "supplyIccPuk2ForApp", () -> {
1529             simProxy.supplyIccPuk2ForApp(rr.mSerial, RILUtils.convertNullToEmptyString(puk),
1530                     RILUtils.convertNullToEmptyString(newPin2),
1531                     RILUtils.convertNullToEmptyString(aid));
1532         });
1533     }
1534 
1535     @Override
changeIccPin(String oldPin, String newPin, Message result)1536     public void changeIccPin(String oldPin, String newPin, Message result) {
1537         changeIccPinForApp(oldPin, newPin, null, result);
1538     }
1539 
1540     @Override
changeIccPinForApp(String oldPin, String newPin, String aid, Message result)1541     public void changeIccPinForApp(String oldPin, String newPin, String aid, Message result) {
1542         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
1543         if (!canMakeRequest("changeIccPinForApp", simProxy, result, RADIO_HAL_VERSION_1_4)) {
1544             return;
1545         }
1546 
1547         RILRequest rr = obtainRequest(RIL_REQUEST_CHANGE_SIM_PIN, result, mRILDefaultWorkSource);
1548 
1549         if (RILJ_LOGD) {
1550             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
1551                     + " oldPin = " + oldPin + " newPin = " + newPin + " aid = " + aid);
1552         }
1553 
1554         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "changeIccPinForApp", () -> {
1555             simProxy.changeIccPinForApp(rr.mSerial,
1556                     RILUtils.convertNullToEmptyString(oldPin),
1557                     RILUtils.convertNullToEmptyString(newPin),
1558                     RILUtils.convertNullToEmptyString(aid));
1559         });
1560     }
1561 
1562     @Override
changeIccPin2(String oldPin2, String newPin2, Message result)1563     public void changeIccPin2(String oldPin2, String newPin2, Message result) {
1564         changeIccPin2ForApp(oldPin2, newPin2, null, result);
1565     }
1566 
1567     @Override
changeIccPin2ForApp(String oldPin2, String newPin2, String aid, Message result)1568     public void changeIccPin2ForApp(String oldPin2, String newPin2, String aid, Message result) {
1569         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
1570         if (!canMakeRequest("changeIccPin2ForApp", simProxy, result, RADIO_HAL_VERSION_1_4)) {
1571             return;
1572         }
1573 
1574         RILRequest rr = obtainRequest(RIL_REQUEST_CHANGE_SIM_PIN2, result, mRILDefaultWorkSource);
1575 
1576         if (RILJ_LOGD) {
1577             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
1578                     + " oldPin = " + oldPin2 + " newPin = " + newPin2 + " aid = " + aid);
1579         }
1580 
1581         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "changeIccPin2ForApp", () -> {
1582             simProxy.changeIccPin2ForApp(rr.mSerial,
1583                     RILUtils.convertNullToEmptyString(oldPin2),
1584                     RILUtils.convertNullToEmptyString(newPin2),
1585                     RILUtils.convertNullToEmptyString(aid));
1586         });
1587     }
1588 
1589     @Override
supplyNetworkDepersonalization(String netpin, Message result)1590     public void supplyNetworkDepersonalization(String netpin, Message result) {
1591         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
1592         if (!canMakeRequest("supplyNetworkDepersonalization", networkProxy, result,
1593                 RADIO_HAL_VERSION_1_4)) {
1594             return;
1595         }
1596 
1597         RILRequest rr = obtainRequest(RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION, result,
1598                 mRILDefaultWorkSource);
1599 
1600         if (RILJ_LOGD) {
1601             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
1602                     + " netpin = " + netpin);
1603         }
1604 
1605         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "supplyNetworkDepersonalization", () -> {
1606             networkProxy.supplyNetworkDepersonalization(rr.mSerial,
1607                     RILUtils.convertNullToEmptyString(netpin));
1608         });
1609     }
1610 
1611     @Override
supplySimDepersonalization(PersoSubState persoType, String controlKey, Message result)1612     public void supplySimDepersonalization(PersoSubState persoType, String controlKey,
1613             Message result) {
1614         if (mHalVersion.get(HAL_SERVICE_SIM).less(RADIO_HAL_VERSION_1_5)
1615                 && PersoSubState.PERSOSUBSTATE_SIM_NETWORK == persoType) {
1616             supplyNetworkDepersonalization(controlKey, result);
1617             return;
1618         }
1619         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
1620         if (!canMakeRequest("supplySimDepersonalization", simProxy, result,
1621                 RADIO_HAL_VERSION_1_5)) {
1622             return;
1623         }
1624 
1625         RILRequest rr = obtainRequest(RIL_REQUEST_ENTER_SIM_DEPERSONALIZATION, result,
1626                 mRILDefaultWorkSource);
1627 
1628         if (RILJ_LOGD) {
1629             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
1630                     + " controlKey = " + controlKey + " persoType" + persoType);
1631         }
1632 
1633         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "supplySimDepersonalization", () -> {
1634             simProxy.supplySimDepersonalization(rr.mSerial, persoType,
1635                     RILUtils.convertNullToEmptyString(controlKey));
1636         });
1637     }
1638 
1639     @Override
getCurrentCalls(Message result)1640     public void getCurrentCalls(Message result) {
1641         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
1642         if (!canMakeRequest("getCurrentCalls", voiceProxy, result, RADIO_HAL_VERSION_1_4)) {
1643             return;
1644         }
1645 
1646         RILRequest rr = obtainRequest(RIL_REQUEST_GET_CURRENT_CALLS, result, mRILDefaultWorkSource);
1647 
1648         if (RILJ_LOGD) {
1649             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
1650         }
1651 
1652         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "getCurrentCalls", () -> {
1653             voiceProxy.getCurrentCalls(rr.mSerial);
1654         });
1655     }
1656 
1657     @Override
dial(String address, boolean isEmergencyCall, EmergencyNumber emergencyNumberInfo, boolean hasKnownUserIntentEmergency, int clirMode, Message result)1658     public void dial(String address, boolean isEmergencyCall, EmergencyNumber emergencyNumberInfo,
1659             boolean hasKnownUserIntentEmergency, int clirMode, Message result) {
1660         dial(address, isEmergencyCall, emergencyNumberInfo, hasKnownUserIntentEmergency,
1661                 clirMode, null, result);
1662     }
1663 
1664     @Override
enableModem(boolean enable, Message result)1665     public void enableModem(boolean enable, Message result) {
1666         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class);
1667         if (!canMakeRequest("enableModem", modemProxy, result, RADIO_HAL_VERSION_1_4)) {
1668             return;
1669         }
1670 
1671         RILRequest rr = obtainRequest(RIL_REQUEST_ENABLE_MODEM, result, mRILDefaultWorkSource);
1672 
1673         if (RILJ_LOGD) {
1674             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
1675                     + " enable = " + enable);
1676         }
1677 
1678         radioServiceInvokeHelper(HAL_SERVICE_MODEM, rr, "enableModem", () -> {
1679             modemProxy.enableModem(rr.mSerial, enable);
1680         });
1681     }
1682 
1683     @Override
setSystemSelectionChannels(@onNull List<RadioAccessSpecifier> specifiers, Message result)1684     public void setSystemSelectionChannels(@NonNull List<RadioAccessSpecifier> specifiers,
1685             Message result) {
1686         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
1687         if (!canMakeRequest("setSystemSelectionChannels", networkProxy, result,
1688                 RADIO_HAL_VERSION_1_4)) {
1689             return;
1690         }
1691 
1692         RILRequest rr = obtainRequest(RIL_REQUEST_SET_SYSTEM_SELECTION_CHANNELS, result,
1693                 mRILDefaultWorkSource);
1694 
1695         if (RILJ_LOGD) {
1696             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
1697                     + " setSystemSelectionChannels= " + specifiers);
1698         }
1699 
1700         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "setSystemSelectionChannels", () -> {
1701             networkProxy.setSystemSelectionChannels(rr.mSerial, specifiers);
1702         });
1703     }
1704 
1705     @Override
getSystemSelectionChannels(Message result)1706     public void getSystemSelectionChannels(Message result) {
1707         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
1708         if (!canMakeRequest("getSystemSelectionChannels", networkProxy, result,
1709                 RADIO_HAL_VERSION_1_6)) {
1710             return;
1711         }
1712 
1713         RILRequest rr = obtainRequest(RIL_REQUEST_GET_SYSTEM_SELECTION_CHANNELS, result,
1714                 mRILDefaultWorkSource);
1715 
1716         if (RILJ_LOGD) {
1717             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
1718                     + " getSystemSelectionChannels");
1719         }
1720 
1721         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "getSystemSelectionChannels", () -> {
1722             networkProxy.getSystemSelectionChannels(rr.mSerial);
1723         });
1724     }
1725 
1726     @Override
getModemStatus(Message result)1727     public void getModemStatus(Message result) {
1728         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class);
1729         if (!canMakeRequest("getModemStatus", modemProxy, result, RADIO_HAL_VERSION_1_4)) {
1730             return;
1731         }
1732 
1733         RILRequest rr = obtainRequest(RIL_REQUEST_GET_MODEM_STATUS, result, mRILDefaultWorkSource);
1734 
1735         if (RILJ_LOGD) {
1736             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
1737         }
1738 
1739         radioServiceInvokeHelper(HAL_SERVICE_MODEM, rr, "getModemStatus", () -> {
1740             modemProxy.getModemStackStatus(rr.mSerial);
1741         });
1742     }
1743 
1744     @Override
dial(String address, boolean isEmergencyCall, EmergencyNumber emergencyNumberInfo, boolean hasKnownUserIntentEmergency, int clirMode, UUSInfo uusInfo, Message result)1745     public void dial(String address, boolean isEmergencyCall, EmergencyNumber emergencyNumberInfo,
1746             boolean hasKnownUserIntentEmergency, int clirMode, UUSInfo uusInfo, Message result) {
1747         if (isEmergencyCall && emergencyNumberInfo != null) {
1748             emergencyDial(address, emergencyNumberInfo, hasKnownUserIntentEmergency, clirMode,
1749                     uusInfo, result);
1750             return;
1751         }
1752         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
1753         if (!canMakeRequest("dial", voiceProxy, result, RADIO_HAL_VERSION_1_4)) {
1754             return;
1755         }
1756 
1757         RILRequest rr = obtainRequest(RIL_REQUEST_DIAL, result, mRILDefaultWorkSource);
1758 
1759         if (RILJ_LOGD) {
1760             // Do not log function arg for privacy
1761             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
1762         }
1763 
1764         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "dial", () -> {
1765             voiceProxy.dial(rr.mSerial, address, clirMode, uusInfo);
1766         });
1767     }
1768 
emergencyDial(String address, EmergencyNumber emergencyNumberInfo, boolean hasKnownUserIntentEmergency, int clirMode, UUSInfo uusInfo, Message result)1769     private void emergencyDial(String address, EmergencyNumber emergencyNumberInfo,
1770             boolean hasKnownUserIntentEmergency, int clirMode, UUSInfo uusInfo, Message result) {
1771         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
1772         if (!canMakeRequest("emergencyDial", voiceProxy, result, RADIO_HAL_VERSION_1_4)) {
1773             return;
1774         }
1775 
1776         RILRequest rr = obtainRequest(RIL_REQUEST_EMERGENCY_DIAL, result, mRILDefaultWorkSource);
1777 
1778         if (RILJ_LOGD) {
1779             // Do not log function arg for privacy
1780             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
1781         }
1782 
1783         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "emergencyDial", () -> {
1784             voiceProxy.emergencyDial(rr.mSerial, RILUtils.convertNullToEmptyString(address),
1785                     emergencyNumberInfo, hasKnownUserIntentEmergency, clirMode, uusInfo);
1786         });
1787     }
1788 
1789     @Override
getIMSI(Message result)1790     public void getIMSI(Message result) {
1791         getIMSIForApp(null, result);
1792     }
1793 
1794     @Override
getIMSIForApp(String aid, Message result)1795     public void getIMSIForApp(String aid, Message result) {
1796         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
1797         if (!canMakeRequest("getIMSIForApp", simProxy, result, RADIO_HAL_VERSION_1_4)) {
1798             return;
1799         }
1800 
1801         RILRequest rr = obtainRequest(RIL_REQUEST_GET_IMSI, result, mRILDefaultWorkSource);
1802 
1803         if (RILJ_LOGD) {
1804             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
1805                     + " aid = " + aid);
1806         }
1807         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "getIMSIForApp", () -> {
1808             simProxy.getImsiForApp(rr.mSerial, RILUtils.convertNullToEmptyString(aid));
1809         });
1810     }
1811 
1812     @Override
hangupConnection(int gsmIndex, Message result)1813     public void hangupConnection(int gsmIndex, Message result) {
1814         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
1815         if (!canMakeRequest("hangupConnection", voiceProxy, result, RADIO_HAL_VERSION_1_4)) {
1816             return;
1817         }
1818 
1819         RILRequest rr = obtainRequest(RIL_REQUEST_HANGUP, result, mRILDefaultWorkSource);
1820 
1821         if (RILJ_LOGD) {
1822             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
1823                     + " gsmIndex = " + gsmIndex);
1824         }
1825 
1826         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "hangupConnection", () -> {
1827             voiceProxy.hangup(rr.mSerial, gsmIndex);
1828         });
1829     }
1830 
1831     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
1832     @Override
hangupWaitingOrBackground(Message result)1833     public void hangupWaitingOrBackground(Message result) {
1834         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
1835         if (!canMakeRequest("hangupWaitingOrBackground", voiceProxy, result,
1836                 RADIO_HAL_VERSION_1_4)) {
1837             return;
1838         }
1839 
1840         RILRequest rr = obtainRequest(RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND, result,
1841                 mRILDefaultWorkSource);
1842 
1843         if (RILJ_LOGD) {
1844             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
1845         }
1846 
1847         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "hangupWaitingOrBackground", () -> {
1848             voiceProxy.hangupWaitingOrBackground(rr.mSerial);
1849         });
1850     }
1851 
1852     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
1853     @Override
hangupForegroundResumeBackground(Message result)1854     public void hangupForegroundResumeBackground(Message result) {
1855         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
1856         if (!canMakeRequest("hangupForegroundResumeBackground", voiceProxy, result,
1857                 RADIO_HAL_VERSION_1_4)) {
1858             return;
1859         }
1860 
1861         RILRequest rr = obtainRequest(RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND, result,
1862                 mRILDefaultWorkSource);
1863 
1864         if (RILJ_LOGD) {
1865             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
1866         }
1867 
1868         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "hangupForegroundResumeBackground", () -> {
1869             voiceProxy.hangupForegroundResumeBackground(rr.mSerial);
1870         });
1871     }
1872 
1873     @Override
switchWaitingOrHoldingAndActive(Message result)1874     public void switchWaitingOrHoldingAndActive(Message result) {
1875         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
1876         if (!canMakeRequest("switchWaitingOrHoldingAndActive", voiceProxy, result,
1877                 RADIO_HAL_VERSION_1_4)) {
1878             return;
1879         }
1880 
1881         RILRequest rr = obtainRequest(RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE, result,
1882                 mRILDefaultWorkSource);
1883 
1884         if (RILJ_LOGD) {
1885             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
1886         }
1887 
1888         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "switchWaitingOrHoldingAndActive", () -> {
1889             voiceProxy.switchWaitingOrHoldingAndActive(rr.mSerial);
1890         });
1891     }
1892 
1893     @Override
conference(Message result)1894     public void conference(Message result) {
1895         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
1896         if (!canMakeRequest("conference", voiceProxy, result, RADIO_HAL_VERSION_1_4)) {
1897             return;
1898         }
1899 
1900         RILRequest rr = obtainRequest(RIL_REQUEST_CONFERENCE, result, mRILDefaultWorkSource);
1901 
1902         if (RILJ_LOGD) {
1903             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
1904         }
1905 
1906         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "conference", () -> {
1907             voiceProxy.conference(rr.mSerial);
1908         });
1909     }
1910 
1911     @Override
rejectCall(Message result)1912     public void rejectCall(Message result) {
1913         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
1914         if (!canMakeRequest("rejectCall", voiceProxy, result, RADIO_HAL_VERSION_1_4)) {
1915             return;
1916         }
1917 
1918         RILRequest rr = obtainRequest(RIL_REQUEST_UDUB, result, mRILDefaultWorkSource);
1919 
1920         if (RILJ_LOGD) {
1921             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
1922         }
1923 
1924         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "rejectCall", () -> {
1925             voiceProxy.rejectCall(rr.mSerial);
1926         });
1927     }
1928 
1929     @Override
getLastCallFailCause(Message result)1930     public void getLastCallFailCause(Message result) {
1931         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
1932         if (!canMakeRequest("getLastCallFailCause", voiceProxy, result, RADIO_HAL_VERSION_1_4)) {
1933             return;
1934         }
1935 
1936         RILRequest rr = obtainRequest(RIL_REQUEST_LAST_CALL_FAIL_CAUSE, result,
1937                 mRILDefaultWorkSource);
1938 
1939         if (RILJ_LOGD) {
1940             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
1941         }
1942 
1943         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "getLastCallFailCause", () -> {
1944             voiceProxy.getLastCallFailCause(rr.mSerial);
1945         });
1946     }
1947 
1948     @Override
getSignalStrength(Message result)1949     public void getSignalStrength(Message result) {
1950         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
1951         if (!canMakeRequest("getSignalStrength", networkProxy, result, RADIO_HAL_VERSION_1_4)) {
1952             return;
1953         }
1954 
1955         RILRequest rr = obtainRequest(RIL_REQUEST_SIGNAL_STRENGTH, result, mRILDefaultWorkSource);
1956 
1957         if (RILJ_LOGD) {
1958             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
1959         }
1960 
1961         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "getSignalStrength", () -> {
1962             networkProxy.getSignalStrength(rr.mSerial);
1963         });
1964     }
1965 
1966     @Override
getVoiceRegistrationState(Message result)1967     public void getVoiceRegistrationState(Message result) {
1968         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
1969         if (!canMakeRequest("getVoiceRegistrationState", networkProxy, result,
1970                 RADIO_HAL_VERSION_1_4)) {
1971             return;
1972         }
1973 
1974         RILRequest rr = obtainRequest(RIL_REQUEST_VOICE_REGISTRATION_STATE, result,
1975                 mRILDefaultWorkSource);
1976 
1977         if (RILJ_LOGD) {
1978             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
1979         }
1980 
1981         HalVersion overrideHalVersion = getCompatVersion(RIL_REQUEST_VOICE_REGISTRATION_STATE);
1982         if (RILJ_LOGD) {
1983             riljLog("getVoiceRegistrationState: overrideHalVersion=" + overrideHalVersion);
1984         }
1985 
1986         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "getVoiceRegistrationState", () -> {
1987             networkProxy.getVoiceRegistrationState(rr.mSerial, overrideHalVersion);
1988         });
1989     }
1990 
1991     @Override
getDataRegistrationState(Message result)1992     public void getDataRegistrationState(Message result) {
1993         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
1994         if (!canMakeRequest("getDataRegistrationState", networkProxy, result,
1995                 RADIO_HAL_VERSION_1_4)) {
1996             return;
1997         }
1998 
1999         RILRequest rr = obtainRequest(RIL_REQUEST_DATA_REGISTRATION_STATE, result,
2000                 mRILDefaultWorkSource);
2001 
2002         if (RILJ_LOGD) {
2003             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2004         }
2005 
2006         HalVersion overrideHalVersion = getCompatVersion(RIL_REQUEST_DATA_REGISTRATION_STATE);
2007         if (RILJ_LOGD) {
2008             riljLog("getDataRegistrationState: overrideHalVersion=" + overrideHalVersion);
2009         }
2010 
2011         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "getDataRegistrationState", () -> {
2012             networkProxy.getDataRegistrationState(rr.mSerial, overrideHalVersion);
2013         });
2014     }
2015 
2016     @Override
getOperator(Message result)2017     public void getOperator(Message result) {
2018         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
2019         if (!canMakeRequest("getOperator", networkProxy, result, RADIO_HAL_VERSION_1_4)) {
2020             return;
2021         }
2022 
2023         RILRequest rr = obtainRequest(RIL_REQUEST_OPERATOR, result, mRILDefaultWorkSource);
2024 
2025         if (RILJ_LOGD) {
2026             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2027         }
2028 
2029         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "getOperator", () -> {
2030             networkProxy.getOperator(rr.mSerial);
2031         });
2032     }
2033 
2034     @UnsupportedAppUsage
2035     @Override
setRadioPower(boolean on, boolean forEmergencyCall, boolean preferredForEmergencyCall, Message result)2036     public void setRadioPower(boolean on, boolean forEmergencyCall,
2037             boolean preferredForEmergencyCall, Message result) {
2038         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class);
2039         if (!canMakeRequest("setRadioPower", modemProxy, result, RADIO_HAL_VERSION_1_4)) {
2040             return;
2041         }
2042 
2043         RILRequest rr = obtainRequest(RIL_REQUEST_RADIO_POWER, result, mRILDefaultWorkSource);
2044 
2045         if (RILJ_LOGD) {
2046             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2047                     + " on = " + on + " forEmergencyCall= " + forEmergencyCall
2048                     + " preferredForEmergencyCall=" + preferredForEmergencyCall);
2049         }
2050 
2051         radioServiceInvokeHelper(HAL_SERVICE_MODEM, rr, "setRadioPower", () -> {
2052             modemProxy.setRadioPower(rr.mSerial, on, forEmergencyCall,
2053                     preferredForEmergencyCall);
2054         });
2055     }
2056 
2057     @Override
sendDtmf(char c, Message result)2058     public void sendDtmf(char c, Message result) {
2059         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
2060         if (!canMakeRequest("sendDtmf", voiceProxy, result, RADIO_HAL_VERSION_1_4)) {
2061             return;
2062         }
2063 
2064         RILRequest rr = obtainRequest(RIL_REQUEST_DTMF, result, mRILDefaultWorkSource);
2065 
2066         if (RILJ_LOGD) {
2067             // Do not log function arg for privacy
2068             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2069         }
2070 
2071         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "sendDtmf", () -> {
2072             voiceProxy.sendDtmf(rr.mSerial, c + "");
2073         });
2074     }
2075 
2076     @Override
sendSMS(String smscPdu, String pdu, Message result)2077     public void sendSMS(String smscPdu, String pdu, Message result) {
2078         RadioMessagingProxy messagingProxy = getRadioServiceProxy(RadioMessagingProxy.class);
2079         if (!canMakeRequest("sendSMS", messagingProxy, result, RADIO_HAL_VERSION_1_4)) {
2080             return;
2081         }
2082 
2083         RILRequest rr = obtainRequest(RIL_REQUEST_SEND_SMS, result, mRILDefaultWorkSource);
2084 
2085         // Do not log function args for privacy
2086         if (RILJ_LOGD) {
2087             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2088         }
2089 
2090         radioServiceInvokeHelper(HAL_SERVICE_MESSAGING, rr, "sendSMS", () -> {
2091             messagingProxy.sendSms(rr.mSerial, smscPdu, pdu);
2092             mMetrics.writeRilSendSms(mPhoneId, rr.mSerial, SmsSession.Event.Tech.SMS_GSM,
2093                     SmsSession.Event.Format.SMS_FORMAT_3GPP, getOutgoingSmsMessageId(result));
2094         });
2095     }
2096 
2097     /**
2098      * Extract the outgoing sms messageId from the tracker, if there is one. This is specifically
2099      * for SMS related APIs.
2100      * @param result the result Message
2101      * @return messageId unique identifier or 0 if there is no message id
2102      */
getOutgoingSmsMessageId(Message result)2103     public static long getOutgoingSmsMessageId(Message result) {
2104         if (result == null || !(result.obj instanceof SMSDispatcher.SmsTracker)) {
2105             return 0L;
2106         }
2107         long messageId = ((SMSDispatcher.SmsTracker) result.obj).mMessageId;
2108         if (RILJ_LOGV) {
2109             Rlog.d(RILJ_LOG_TAG, "getOutgoingSmsMessageId "
2110                     + SmsController.formatCrossStackMessageId(messageId));
2111         }
2112         return messageId;
2113     }
2114 
2115     @Override
sendSMSExpectMore(String smscPdu, String pdu, Message result)2116     public void sendSMSExpectMore(String smscPdu, String pdu, Message result) {
2117         RadioMessagingProxy messagingProxy = getRadioServiceProxy(RadioMessagingProxy.class);
2118         if (!canMakeRequest("sendSMSExpectMore", messagingProxy, result, RADIO_HAL_VERSION_1_4)) {
2119             return;
2120         }
2121 
2122         RILRequest rr = obtainRequest(RIL_REQUEST_SEND_SMS_EXPECT_MORE, result,
2123                 mRILDefaultWorkSource);
2124 
2125         // Do not log function arg for privacy
2126         if (RILJ_LOGD) {
2127             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2128         }
2129 
2130         radioServiceInvokeHelper(HAL_SERVICE_MESSAGING, rr, "sendSMSExpectMore", () -> {
2131             messagingProxy.sendSmsExpectMore(rr.mSerial, smscPdu, pdu);
2132             mMetrics.writeRilSendSms(mPhoneId, rr.mSerial, SmsSession.Event.Tech.SMS_GSM,
2133                     SmsSession.Event.Format.SMS_FORMAT_3GPP, getOutgoingSmsMessageId(result));
2134         });
2135     }
2136 
2137     @Override
setupDataCall(int accessNetworkType, DataProfile dataProfile, boolean allowRoaming, int reason, LinkProperties linkProperties, int pduSessionId, NetworkSliceInfo sliceInfo, TrafficDescriptor trafficDescriptor, boolean matchAllRuleAllowed, Message result)2138     public void setupDataCall(int accessNetworkType, DataProfile dataProfile, boolean allowRoaming,
2139             int reason, LinkProperties linkProperties, int pduSessionId, NetworkSliceInfo sliceInfo,
2140             TrafficDescriptor trafficDescriptor, boolean matchAllRuleAllowed, Message result) {
2141         RadioDataProxy dataProxy = getRadioServiceProxy(RadioDataProxy.class);
2142         if (!canMakeRequest("setupDataCall", dataProxy, result, RADIO_HAL_VERSION_1_4)) {
2143             return;
2144         }
2145 
2146         RILRequest rr = obtainRequest(RIL_REQUEST_SETUP_DATA_CALL, result, mRILDefaultWorkSource);
2147 
2148         if (RILJ_LOGD) {
2149             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2150                     + ",reason=" + RILUtils.setupDataReasonToString(reason)
2151                     + ",accessNetworkType=" + AccessNetworkType.toString(accessNetworkType)
2152                     + ",dataProfile=" + dataProfile + ",allowRoaming=" + allowRoaming
2153                     + ",linkProperties=" + linkProperties + ",pduSessionId=" + pduSessionId
2154                     + ",sliceInfo=" + sliceInfo + ",trafficDescriptor=" + trafficDescriptor
2155                     + ",matchAllRuleAllowed=" + matchAllRuleAllowed);
2156         }
2157 
2158         radioServiceInvokeHelper(HAL_SERVICE_DATA, rr, "setupDataCall", () -> {
2159             dataProxy.setupDataCall(rr.mSerial, accessNetworkType, dataProfile, allowRoaming,
2160                     reason, linkProperties, pduSessionId, sliceInfo, trafficDescriptor,
2161                     matchAllRuleAllowed);
2162         });
2163     }
2164 
2165     @Override
iccIO(int command, int fileId, String path, int p1, int p2, int p3, String data, String pin2, Message result)2166     public void iccIO(int command, int fileId, String path, int p1, int p2, int p3, String data,
2167             String pin2, Message result) {
2168         iccIOForApp(command, fileId, path, p1, p2, p3, data, pin2, null, result);
2169     }
2170 
2171     @Override
iccIOForApp(int command, int fileId, String path, int p1, int p2, int p3, String data, String pin2, String aid, Message result)2172     public void iccIOForApp(int command, int fileId, String path, int p1, int p2, int p3,
2173             String data, String pin2, String aid, Message result) {
2174         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
2175         if (!canMakeRequest("iccIOForApp", simProxy, result, RADIO_HAL_VERSION_1_4)) {
2176             return;
2177         }
2178 
2179         RILRequest rr = obtainRequest(RIL_REQUEST_SIM_IO, result, mRILDefaultWorkSource);
2180 
2181         if (RILJ_LOGD) {
2182             if (TelephonyUtils.IS_DEBUGGABLE) {
2183                 riljLog(rr.serialString() + "> iccIO: " + RILUtils.requestToString(rr.mRequest)
2184                         + " command = 0x" + Integer.toHexString(command) + " fileId = 0x"
2185                         + Integer.toHexString(fileId) + " path = " + path + " p1 = " + p1
2186                         + " p2 = " + p2 + " p3 = " + " data = " + data + " aid = " + aid);
2187             } else {
2188                 riljLog(rr.serialString() + "> iccIO: "
2189                         + RILUtils.requestToString(rr.mRequest));
2190             }
2191         }
2192 
2193         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "iccIOForApp", () -> {
2194             simProxy.iccIoForApp(rr.mSerial, command, fileId,
2195                     RILUtils.convertNullToEmptyString(path), p1, p2, p3,
2196                     RILUtils.convertNullToEmptyString(data),
2197                     RILUtils.convertNullToEmptyString(pin2),
2198                     RILUtils.convertNullToEmptyString(aid));
2199         });
2200     }
2201 
2202     @Override
sendUSSD(String ussd, Message result)2203     public void sendUSSD(String ussd, Message result) {
2204         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
2205         if (!canMakeRequest("sendUSSD", voiceProxy, result, RADIO_HAL_VERSION_1_4)) {
2206             return;
2207         }
2208 
2209         RILRequest rr = obtainRequest(RIL_REQUEST_SEND_USSD, result, mRILDefaultWorkSource);
2210 
2211         if (RILJ_LOGD) {
2212             String logUssd = "*******";
2213             if (RILJ_LOGV) logUssd = ussd;
2214             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2215                     + " ussd = " + logUssd);
2216         }
2217 
2218         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "sendUSSD", () -> {
2219             voiceProxy.sendUssd(rr.mSerial, RILUtils.convertNullToEmptyString(ussd));
2220         });
2221     }
2222 
2223     @Override
cancelPendingUssd(Message result)2224     public void cancelPendingUssd(Message result) {
2225         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
2226         if (!canMakeRequest("cancelPendingUssd", voiceProxy, result, RADIO_HAL_VERSION_1_4)) {
2227             return;
2228         }
2229 
2230         RILRequest rr = obtainRequest(RIL_REQUEST_CANCEL_USSD, result, mRILDefaultWorkSource);
2231 
2232         if (RILJ_LOGD) {
2233             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2234         }
2235 
2236         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "cancelPendingUssd", () -> {
2237             voiceProxy.cancelPendingUssd(rr.mSerial);
2238         });
2239     }
2240 
2241     @Override
getCLIR(Message result)2242     public void getCLIR(Message result) {
2243         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
2244         if (!canMakeRequest("getCLIR", voiceProxy, result, RADIO_HAL_VERSION_1_4)) {
2245             return;
2246         }
2247 
2248         RILRequest rr = obtainRequest(RIL_REQUEST_GET_CLIR, result, mRILDefaultWorkSource);
2249 
2250         if (RILJ_LOGD) {
2251             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2252         }
2253 
2254         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "getCLIR", () -> {
2255             voiceProxy.getClir(rr.mSerial);
2256         });
2257     }
2258 
2259     @Override
setCLIR(int clirMode, Message result)2260     public void setCLIR(int clirMode, Message result) {
2261         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
2262         if (!canMakeRequest("setCLIR", voiceProxy, result, RADIO_HAL_VERSION_1_4)) {
2263             return;
2264         }
2265 
2266         RILRequest rr = obtainRequest(RIL_REQUEST_SET_CLIR, result, mRILDefaultWorkSource);
2267 
2268         if (RILJ_LOGD) {
2269             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2270                     + " clirMode = " + clirMode);
2271         }
2272 
2273         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "setCLIR", () -> {
2274             voiceProxy.setClir(rr.mSerial, clirMode);
2275         });
2276     }
2277 
2278     @Override
queryCallForwardStatus(int cfReason, int serviceClass, String number, Message result)2279     public void queryCallForwardStatus(int cfReason, int serviceClass, String number,
2280             Message result) {
2281         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
2282         if (!canMakeRequest("queryCallForwardStatus", voiceProxy, result, RADIO_HAL_VERSION_1_4)) {
2283             return;
2284         }
2285 
2286         RILRequest rr = obtainRequest(RIL_REQUEST_QUERY_CALL_FORWARD_STATUS, result,
2287                 mRILDefaultWorkSource);
2288 
2289         if (RILJ_LOGD) {
2290             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2291                     + " cfReason = " + cfReason + " serviceClass = " + serviceClass);
2292         }
2293 
2294         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "queryCallForwardStatus", () -> {
2295             voiceProxy.getCallForwardStatus(rr.mSerial, cfReason, serviceClass, number);
2296         });
2297     }
2298 
2299     @Override
setCallForward(int action, int cfReason, int serviceClass, String number, int timeSeconds, Message result)2300     public void setCallForward(int action, int cfReason, int serviceClass, String number,
2301             int timeSeconds, Message result) {
2302         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
2303         if (!canMakeRequest("setCallForward", voiceProxy, result, RADIO_HAL_VERSION_1_4)) {
2304             return;
2305         }
2306 
2307         RILRequest rr = obtainRequest(RIL_REQUEST_SET_CALL_FORWARD, result, mRILDefaultWorkSource);
2308 
2309         if (RILJ_LOGD) {
2310             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2311                     + " action = " + action + " cfReason = " + cfReason + " serviceClass = "
2312                     + serviceClass + " timeSeconds = " + timeSeconds);
2313         }
2314 
2315         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "setCallForward", () -> {
2316             voiceProxy.setCallForward(
2317                     rr.mSerial, action, cfReason, serviceClass, number, timeSeconds);
2318         });
2319     }
2320 
2321     @Override
queryCallWaiting(int serviceClass, Message result)2322     public void queryCallWaiting(int serviceClass, Message result) {
2323         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
2324         if (!canMakeRequest("queryCallWaiting", voiceProxy, result, RADIO_HAL_VERSION_1_4)) {
2325             return;
2326         }
2327 
2328         RILRequest rr = obtainRequest(RIL_REQUEST_QUERY_CALL_WAITING, result,
2329                 mRILDefaultWorkSource);
2330 
2331         if (RILJ_LOGD) {
2332             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2333                     + " serviceClass = " + serviceClass);
2334         }
2335 
2336         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "queryCallWaiting", () -> {
2337             voiceProxy.getCallWaiting(rr.mSerial, serviceClass);
2338         });
2339     }
2340 
2341     @Override
setCallWaiting(boolean enable, int serviceClass, Message result)2342     public void setCallWaiting(boolean enable, int serviceClass, Message result) {
2343         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
2344         if (!canMakeRequest("setCallWaiting", voiceProxy, result, RADIO_HAL_VERSION_1_4)) {
2345             return;
2346         }
2347 
2348         RILRequest rr = obtainRequest(RIL_REQUEST_SET_CALL_WAITING, result, mRILDefaultWorkSource);
2349 
2350         if (RILJ_LOGD) {
2351             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2352                     + " enable = " + enable + " serviceClass = " + serviceClass);
2353         }
2354 
2355         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "setCallWaiting", () -> {
2356             voiceProxy.setCallWaiting(rr.mSerial, enable, serviceClass);
2357         });
2358     }
2359 
2360     @Override
acknowledgeLastIncomingGsmSms(boolean success, int cause, Message result)2361     public void acknowledgeLastIncomingGsmSms(boolean success, int cause, Message result) {
2362         RadioMessagingProxy messagingProxy = getRadioServiceProxy(RadioMessagingProxy.class);
2363         if (!canMakeRequest("acknowledgeLastIncomingGsmSms", messagingProxy, result,
2364                 RADIO_HAL_VERSION_1_4)) {
2365             return;
2366         }
2367 
2368         RILRequest rr = obtainRequest(RIL_REQUEST_SMS_ACKNOWLEDGE, result, mRILDefaultWorkSource);
2369 
2370         if (RILJ_LOGD) {
2371             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2372                     + " success = " + success + " cause = " + cause);
2373         }
2374 
2375         radioServiceInvokeHelper(HAL_SERVICE_MESSAGING, rr, "acknowledgeLastIncomingGsmSms", () -> {
2376             messagingProxy.acknowledgeLastIncomingGsmSms(rr.mSerial, success, cause);
2377         });
2378     }
2379 
2380     @Override
acceptCall(Message result)2381     public void acceptCall(Message result) {
2382         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
2383         if (!canMakeRequest("acceptCall", voiceProxy, result, RADIO_HAL_VERSION_1_4)) {
2384             return;
2385         }
2386 
2387         RILRequest rr = obtainRequest(RIL_REQUEST_ANSWER, result, mRILDefaultWorkSource);
2388 
2389         if (RILJ_LOGD) {
2390             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2391         }
2392 
2393         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "acceptCall", () -> {
2394             voiceProxy.acceptCall(rr.mSerial);
2395             mMetrics.writeRilAnswer(mPhoneId, rr.mSerial);
2396         });
2397     }
2398 
2399     @Override
deactivateDataCall(int cid, int reason, Message result)2400     public void deactivateDataCall(int cid, int reason, Message result) {
2401         RadioDataProxy dataProxy = getRadioServiceProxy(RadioDataProxy.class);
2402         if (!canMakeRequest("deactivateDataCall", dataProxy, result, RADIO_HAL_VERSION_1_4)) {
2403             return;
2404         }
2405 
2406         RILRequest rr = obtainRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, result,
2407                 mRILDefaultWorkSource);
2408 
2409         if (RILJ_LOGD) {
2410             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2411                     + " cid = " + cid + " reason = "
2412                     + RILUtils.deactivateDataReasonToString(reason));
2413         }
2414 
2415         radioServiceInvokeHelper(HAL_SERVICE_DATA, rr, "deactivateDataCall", () -> {
2416             dataProxy.deactivateDataCall(rr.mSerial, cid, reason);
2417             mMetrics.writeRilDeactivateDataCall(mPhoneId, rr.mSerial, cid, reason);
2418         });
2419     }
2420 
2421     @Override
queryFacilityLock(String facility, String password, int serviceClass, Message result)2422     public void queryFacilityLock(String facility, String password, int serviceClass,
2423             Message result) {
2424         queryFacilityLockForApp(facility, password, serviceClass, null, result);
2425     }
2426 
2427     @Override
queryFacilityLockForApp(String facility, String password, int serviceClass, String appId, Message result)2428     public void queryFacilityLockForApp(String facility, String password, int serviceClass,
2429             String appId, Message result) {
2430         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
2431         if (!canMakeRequest("queryFacilityLockForApp", simProxy, result, RADIO_HAL_VERSION_1_4)) {
2432             return;
2433         }
2434 
2435         RILRequest rr = obtainRequest(RIL_REQUEST_QUERY_FACILITY_LOCK, result,
2436                 mRILDefaultWorkSource);
2437 
2438         if (RILJ_LOGD) {
2439             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2440                     + " facility = " + facility + " serviceClass = " + serviceClass
2441                     + " appId = " + appId);
2442         }
2443 
2444         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "queryFacilityLockForApp", () -> {
2445             simProxy.getFacilityLockForApp(rr.mSerial,
2446                     RILUtils.convertNullToEmptyString(facility),
2447                     RILUtils.convertNullToEmptyString(password), serviceClass,
2448                     RILUtils.convertNullToEmptyString(appId));
2449         });
2450 
2451     }
2452 
2453     @Override
setFacilityLock(String facility, boolean lockState, String password, int serviceClass, Message result)2454     public void setFacilityLock(String facility, boolean lockState, String password,
2455             int serviceClass, Message result) {
2456         setFacilityLockForApp(facility, lockState, password, serviceClass, null, result);
2457     }
2458 
2459     @Override
setFacilityLockForApp(String facility, boolean lockState, String password, int serviceClass, String appId, Message result)2460     public void setFacilityLockForApp(String facility, boolean lockState, String password,
2461             int serviceClass, String appId, Message result) {
2462         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
2463         if (!canMakeRequest("setFacilityLockForApp", simProxy, result, RADIO_HAL_VERSION_1_4)) {
2464             return;
2465         }
2466 
2467         RILRequest rr = obtainRequest(RIL_REQUEST_SET_FACILITY_LOCK, result, mRILDefaultWorkSource);
2468 
2469         if (RILJ_LOGD) {
2470             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2471                     + " facility = " + facility + " lockstate = " + lockState
2472                     + " serviceClass = " + serviceClass + " appId = " + appId);
2473         }
2474 
2475         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "setFacilityLockForApp", () -> {
2476             simProxy.setFacilityLockForApp(rr.mSerial,
2477                     RILUtils.convertNullToEmptyString(facility), lockState,
2478                     RILUtils.convertNullToEmptyString(password), serviceClass,
2479                     RILUtils.convertNullToEmptyString(appId));
2480         });
2481     }
2482 
2483     @Override
changeBarringPassword(String facility, String oldPwd, String newPwd, Message result)2484     public void changeBarringPassword(String facility, String oldPwd, String newPwd,
2485             Message result) {
2486         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
2487         if (!canMakeRequest("changeBarringPassword", networkProxy, result, RADIO_HAL_VERSION_1_4)) {
2488             return;
2489         }
2490 
2491         RILRequest rr = obtainRequest(RIL_REQUEST_CHANGE_BARRING_PASSWORD, result,
2492                 mRILDefaultWorkSource);
2493 
2494         // Do not log all function args for privacy
2495         if (RILJ_LOGD) {
2496             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2497                     + "facility = " + facility);
2498         }
2499 
2500         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "changeBarringPassword", () -> {
2501             networkProxy.setBarringPassword(rr.mSerial,
2502                     RILUtils.convertNullToEmptyString(facility),
2503                     RILUtils.convertNullToEmptyString(oldPwd),
2504                     RILUtils.convertNullToEmptyString(newPwd));
2505         });
2506     }
2507 
2508     @Override
getNetworkSelectionMode(Message result)2509     public void getNetworkSelectionMode(Message result) {
2510         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
2511         if (!canMakeRequest("getNetworkSelectionMode", networkProxy, result,
2512                 RADIO_HAL_VERSION_1_4)) {
2513             return;
2514         }
2515 
2516         RILRequest rr = obtainRequest(RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE, result,
2517                 mRILDefaultWorkSource);
2518 
2519         if (RILJ_LOGD) {
2520             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2521         }
2522 
2523         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "getNetworkSelectionMode", () -> {
2524             networkProxy.getNetworkSelectionMode(rr.mSerial);
2525         });
2526     }
2527 
2528     @Override
setNetworkSelectionModeAutomatic(Message result)2529     public void setNetworkSelectionModeAutomatic(Message result) {
2530         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
2531         if (!canMakeRequest("setNetworkSelectionModeAutomatic", networkProxy, result,
2532                 RADIO_HAL_VERSION_1_4)) {
2533             return;
2534         }
2535 
2536         RILRequest rr = obtainRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, result,
2537                 mRILDefaultWorkSource);
2538 
2539         if (RILJ_LOGD) {
2540             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2541         }
2542 
2543         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "setNetworkSelectionModeAutomatic",
2544                 () -> {
2545                     networkProxy.setNetworkSelectionModeAutomatic(rr.mSerial);
2546                 });
2547     }
2548 
2549     @Override
setNetworkSelectionModeManual(String operatorNumeric, int ran, Message result)2550     public void setNetworkSelectionModeManual(String operatorNumeric, int ran, Message result) {
2551         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
2552         if (!canMakeRequest("setNetworkSelectionModeManual", networkProxy, result,
2553                 RADIO_HAL_VERSION_1_4)) {
2554             return;
2555         }
2556 
2557         RILRequest rr = obtainRequest(RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL, result,
2558                 mRILDefaultWorkSource);
2559 
2560         if (RILJ_LOGD) {
2561             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2562                     + " operatorNumeric = " + operatorNumeric + ", ran = " + ran);
2563         }
2564 
2565         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "setNetworkSelectionModeManual", () -> {
2566             networkProxy.setNetworkSelectionModeManual(rr.mSerial,
2567                     RILUtils.convertNullToEmptyString(operatorNumeric), ran);
2568         });
2569     }
2570 
2571     @Override
getAvailableNetworks(Message result)2572     public void getAvailableNetworks(Message result) {
2573         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
2574         if (!canMakeRequest("getAvailableNetworks", networkProxy, result, RADIO_HAL_VERSION_1_4)) {
2575             return;
2576         }
2577 
2578         RILRequest rr = obtainRequest(RIL_REQUEST_QUERY_AVAILABLE_NETWORKS, result,
2579                 mRILDefaultWorkSource);
2580 
2581         if (RILJ_LOGD) {
2582             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2583         }
2584 
2585         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "getAvailableNetworks", () -> {
2586             networkProxy.getAvailableNetworks(rr.mSerial);
2587         });
2588     }
2589 
2590     /**
2591      * Radio HAL fallback compatibility feature (b/151106728) assumes that the input parameter
2592      * networkScanRequest is immutable (read-only) here. Once the caller invokes the method, the
2593      * parameter networkScanRequest should not be modified. This helps us keep a consistent and
2594      * simple data model that avoid copying it in the scan result.
2595      */
2596     @Override
startNetworkScan(NetworkScanRequest networkScanRequest, Message result)2597     public void startNetworkScan(NetworkScanRequest networkScanRequest, Message result) {
2598         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
2599         if (!canMakeRequest("startNetworkScan", networkProxy, result, RADIO_HAL_VERSION_1_4)) {
2600             return;
2601         }
2602 
2603         HalVersion overrideHalVersion = getCompatVersion(RIL_REQUEST_START_NETWORK_SCAN);
2604         if (RILJ_LOGD) {
2605             riljLog("startNetworkScan: overrideHalVersion=" + overrideHalVersion);
2606         }
2607 
2608         RILRequest rr = obtainRequest(RIL_REQUEST_START_NETWORK_SCAN, result,
2609                 mRILDefaultWorkSource, networkScanRequest);
2610 
2611         if (RILJ_LOGD) {
2612             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2613         }
2614 
2615         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "startNetworkScan", () -> {
2616             networkProxy.startNetworkScan(rr.mSerial, networkScanRequest, overrideHalVersion,
2617                     result);
2618         });
2619     }
2620 
2621     @Override
stopNetworkScan(Message result)2622     public void stopNetworkScan(Message result) {
2623         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
2624         if (!canMakeRequest("stopNetworkScan", networkProxy, result, RADIO_HAL_VERSION_1_4)) {
2625             return;
2626         }
2627 
2628         RILRequest rr = obtainRequest(RIL_REQUEST_STOP_NETWORK_SCAN, result, mRILDefaultWorkSource);
2629 
2630         if (RILJ_LOGD) {
2631             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2632         }
2633 
2634         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "stopNetworkScan", () -> {
2635             networkProxy.stopNetworkScan(rr.mSerial);
2636         });
2637     }
2638 
2639     @Override
startDtmf(char c, Message result)2640     public void startDtmf(char c, Message result) {
2641         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
2642         if (!canMakeRequest("startDtmf", voiceProxy, result, RADIO_HAL_VERSION_1_4)) {
2643             return;
2644         }
2645 
2646         RILRequest rr = obtainRequest(RIL_REQUEST_DTMF_START, result, mRILDefaultWorkSource);
2647 
2648         // Do not log function arg for privacy
2649         if (RILJ_LOGD) {
2650             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2651         }
2652 
2653         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "startDtmf", () -> {
2654             voiceProxy.startDtmf(rr.mSerial, c + "");
2655         });
2656     }
2657 
2658     @Override
stopDtmf(Message result)2659     public void stopDtmf(Message result) {
2660         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
2661         if (!canMakeRequest("stopDtmf", voiceProxy, result, RADIO_HAL_VERSION_1_4)) {
2662             return;
2663         }
2664 
2665         RILRequest rr = obtainRequest(RIL_REQUEST_DTMF_STOP, result, mRILDefaultWorkSource);
2666 
2667         if (RILJ_LOGD) {
2668             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2669         }
2670 
2671         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "stopDtmf", () -> {
2672             voiceProxy.stopDtmf(rr.mSerial);
2673         });
2674     }
2675 
2676     @Override
separateConnection(int gsmIndex, Message result)2677     public void separateConnection(int gsmIndex, Message result) {
2678         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
2679         if (!canMakeRequest("separateConnection", voiceProxy, result, RADIO_HAL_VERSION_1_4)) {
2680             return;
2681         }
2682 
2683         RILRequest rr = obtainRequest(RIL_REQUEST_SEPARATE_CONNECTION, result,
2684                 mRILDefaultWorkSource);
2685 
2686         if (RILJ_LOGD) {
2687             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2688                     + " gsmIndex = " + gsmIndex);
2689         }
2690 
2691         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "separateConnection", () -> {
2692             voiceProxy.separateConnection(rr.mSerial, gsmIndex);
2693         });
2694     }
2695 
2696     @Override
getBasebandVersion(Message result)2697     public void getBasebandVersion(Message result) {
2698         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class);
2699         if (!canMakeRequest("getBasebandVersion", modemProxy, result, RADIO_HAL_VERSION_1_4)) {
2700             return;
2701         }
2702 
2703         RILRequest rr = obtainRequest(RIL_REQUEST_BASEBAND_VERSION, result, mRILDefaultWorkSource);
2704 
2705         if (RILJ_LOGD) {
2706             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2707         }
2708 
2709         radioServiceInvokeHelper(HAL_SERVICE_MODEM, rr, "getBasebandVersion", () -> {
2710             modemProxy.getBasebandVersion(rr.mSerial);
2711         });
2712     }
2713 
2714     @Override
setMute(boolean enableMute, Message result)2715     public void setMute(boolean enableMute, Message result) {
2716         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
2717         if (!canMakeRequest("setMute", voiceProxy, result, RADIO_HAL_VERSION_1_4)) {
2718             return;
2719         }
2720 
2721         RILRequest rr = obtainRequest(RIL_REQUEST_SET_MUTE, result, mRILDefaultWorkSource);
2722 
2723         if (RILJ_LOGD) {
2724             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2725                     + " enableMute = " + enableMute);
2726         }
2727 
2728         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "setMute", () -> {
2729             voiceProxy.setMute(rr.mSerial, enableMute);
2730         });
2731     }
2732 
2733     @Override
getMute(Message result)2734     public void getMute(Message result) {
2735         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
2736         if (!canMakeRequest("getMute", voiceProxy, result, RADIO_HAL_VERSION_1_4)) {
2737             return;
2738         }
2739 
2740         RILRequest rr = obtainRequest(RIL_REQUEST_GET_MUTE, result, mRILDefaultWorkSource);
2741 
2742         if (RILJ_LOGD) {
2743             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2744         }
2745 
2746         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "getMute", () -> {
2747             voiceProxy.getMute(rr.mSerial);
2748         });
2749     }
2750 
2751     @Override
queryCLIP(Message result)2752     public void queryCLIP(Message result) {
2753         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
2754         if (!canMakeRequest("queryCLIP", voiceProxy, result, RADIO_HAL_VERSION_1_4)) {
2755             return;
2756         }
2757 
2758         RILRequest rr = obtainRequest(RIL_REQUEST_QUERY_CLIP, result, mRILDefaultWorkSource);
2759 
2760         if (RILJ_LOGD) {
2761             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2762         }
2763 
2764         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "queryCLIP", () -> {
2765             voiceProxy.getClip(rr.mSerial);
2766         });
2767     }
2768 
2769     @Override
getDataCallList(Message result)2770     public void getDataCallList(Message result) {
2771         RadioDataProxy dataProxy = getRadioServiceProxy(RadioDataProxy.class);
2772         if (!canMakeRequest("getDataCallList", dataProxy, result, RADIO_HAL_VERSION_1_4)) {
2773             return;
2774         }
2775 
2776         RILRequest rr = obtainRequest(RIL_REQUEST_DATA_CALL_LIST, result, mRILDefaultWorkSource);
2777 
2778         if (RILJ_LOGD) {
2779             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2780         }
2781 
2782         radioServiceInvokeHelper(HAL_SERVICE_DATA, rr, "getDataCallList", () -> {
2783             dataProxy.getDataCallList(rr.mSerial);
2784         });
2785     }
2786 
2787     @Override
setSuppServiceNotifications(boolean enable, Message result)2788     public void setSuppServiceNotifications(boolean enable, Message result) {
2789         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
2790         if (!canMakeRequest("setSuppServiceNotifications", networkProxy, result,
2791                 RADIO_HAL_VERSION_1_4)) {
2792             return;
2793         }
2794 
2795         RILRequest rr = obtainRequest(RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION, result,
2796                 mRILDefaultWorkSource);
2797 
2798         if (RILJ_LOGD) {
2799             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2800                     + " enable = " + enable);
2801         }
2802 
2803         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "setSuppServiceNotifications", () -> {
2804             networkProxy.setSuppServiceNotifications(rr.mSerial, enable);
2805         });
2806     }
2807 
2808     @Override
writeSmsToSim(int status, String smsc, String pdu, Message result)2809     public void writeSmsToSim(int status, String smsc, String pdu, Message result) {
2810         RadioMessagingProxy messagingProxy = getRadioServiceProxy(RadioMessagingProxy.class);
2811         if (!canMakeRequest("writeSmsToSim", messagingProxy, result, RADIO_HAL_VERSION_1_4)) {
2812             return;
2813         }
2814 
2815         RILRequest rr = obtainRequest(RIL_REQUEST_WRITE_SMS_TO_SIM, result, mRILDefaultWorkSource);
2816 
2817         if (RILJ_LOGV) {
2818             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2819                     + " " + status);
2820         }
2821 
2822         radioServiceInvokeHelper(HAL_SERVICE_MESSAGING, rr, "writeSmsToSim", () -> {
2823             messagingProxy.writeSmsToSim(rr.mSerial, status,
2824                     RILUtils.convertNullToEmptyString(smsc),
2825                     RILUtils.convertNullToEmptyString(pdu));
2826         });
2827     }
2828 
2829     @Override
deleteSmsOnSim(int index, Message result)2830     public void deleteSmsOnSim(int index, Message result) {
2831         RadioMessagingProxy messagingProxy = getRadioServiceProxy(RadioMessagingProxy.class);
2832         if (!canMakeRequest("deleteSmsOnSim", messagingProxy, result, RADIO_HAL_VERSION_1_4)) {
2833             return;
2834         }
2835 
2836         RILRequest rr = obtainRequest(RIL_REQUEST_DELETE_SMS_ON_SIM, result, mRILDefaultWorkSource);
2837 
2838         if (RILJ_LOGV) {
2839             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2840                     + " index = " + index);
2841         }
2842 
2843         radioServiceInvokeHelper(HAL_SERVICE_MESSAGING, rr, "deleteSmsOnSim", () -> {
2844             messagingProxy.deleteSmsOnSim(rr.mSerial, index);
2845         });
2846     }
2847 
2848     @Override
setBandMode(int bandMode, Message result)2849     public void setBandMode(int bandMode, Message result) {
2850         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
2851         if (!canMakeRequest("setBandMode", networkProxy, result, RADIO_HAL_VERSION_1_4)) {
2852             return;
2853         }
2854 
2855         RILRequest rr = obtainRequest(RIL_REQUEST_SET_BAND_MODE, result, mRILDefaultWorkSource);
2856 
2857         if (RILJ_LOGD) {
2858             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2859                     + " bandMode = " + bandMode);
2860         }
2861 
2862         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "setBandMode", () -> {
2863             networkProxy.setBandMode(rr.mSerial, bandMode);
2864         });
2865     }
2866 
2867     @Override
queryAvailableBandMode(Message result)2868     public void queryAvailableBandMode(Message result) {
2869         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
2870         if (!canMakeRequest("queryAvailableBandMode", networkProxy, result,
2871                 RADIO_HAL_VERSION_1_4)) {
2872             return;
2873         }
2874 
2875         RILRequest rr = obtainRequest(RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE, result,
2876                 mRILDefaultWorkSource);
2877 
2878         if (RILJ_LOGD) {
2879             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2880         }
2881 
2882         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "queryAvailableBandMode", () -> {
2883             networkProxy.getAvailableBandModes(rr.mSerial);
2884         });
2885     }
2886 
2887     @Override
sendEnvelope(String contents, Message result)2888     public void sendEnvelope(String contents, Message result) {
2889         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
2890         if (!canMakeRequest("sendEnvelope", simProxy, result, RADIO_HAL_VERSION_1_4)) {
2891             return;
2892         }
2893 
2894         RILRequest rr = obtainRequest(RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND, result,
2895                 mRILDefaultWorkSource);
2896 
2897         if (RILJ_LOGD) {
2898             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2899                     + " contents = " + contents);
2900         }
2901 
2902         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "sendEnvelope", () -> {
2903             simProxy.sendEnvelope(rr.mSerial, RILUtils.convertNullToEmptyString(contents));
2904         });
2905     }
2906 
2907     @Override
sendTerminalResponse(String contents, Message result)2908     public void sendTerminalResponse(String contents, Message result) {
2909         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
2910         if (!canMakeRequest("sendTerminalResponse", simProxy, result, RADIO_HAL_VERSION_1_4)) {
2911             return;
2912         }
2913 
2914         RILRequest rr = obtainRequest(RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE, result,
2915                 mRILDefaultWorkSource);
2916 
2917         if (RILJ_LOGD) {
2918             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2919                     + " contents = " + (TelephonyUtils.IS_DEBUGGABLE
2920                     ? contents : RILUtils.convertToCensoredTerminalResponse(contents)));
2921         }
2922 
2923         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "sendTerminalResponse", () -> {
2924             simProxy.sendTerminalResponseToSim(rr.mSerial,
2925                     RILUtils.convertNullToEmptyString(contents));
2926         });
2927     }
2928 
2929     @Override
sendEnvelopeWithStatus(String contents, Message result)2930     public void sendEnvelopeWithStatus(String contents, Message result) {
2931         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
2932         if (!canMakeRequest("sendEnvelopeWithStatus", simProxy, result, RADIO_HAL_VERSION_1_4)) {
2933             return;
2934         }
2935 
2936         RILRequest rr = obtainRequest(RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS, result,
2937                 mRILDefaultWorkSource);
2938 
2939         if (RILJ_LOGD) {
2940             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2941                     + " contents = " + contents);
2942         }
2943 
2944         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "sendEnvelopeWithStatus", () -> {
2945             simProxy.sendEnvelopeWithStatus(rr.mSerial,
2946                     RILUtils.convertNullToEmptyString(contents));
2947         });
2948     }
2949 
2950     @Override
explicitCallTransfer(Message result)2951     public void explicitCallTransfer(Message result) {
2952         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
2953         if (!canMakeRequest("explicitCallTransfer", voiceProxy, result, RADIO_HAL_VERSION_1_4)) {
2954             return;
2955         }
2956 
2957         RILRequest rr = obtainRequest(RIL_REQUEST_EXPLICIT_CALL_TRANSFER, result,
2958                 mRILDefaultWorkSource);
2959 
2960         if (RILJ_LOGD) {
2961             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
2962         }
2963 
2964         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "explicitCallTransfer", () -> {
2965             voiceProxy.explicitCallTransfer(rr.mSerial);
2966         });
2967     }
2968 
2969     @Override
setPreferredNetworkType(@refNetworkMode int networkType , Message result)2970     public void setPreferredNetworkType(@PrefNetworkMode int networkType , Message result) {
2971         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
2972         if (!canMakeRequest("setPreferredNetworkType", networkProxy, result,
2973                 RADIO_HAL_VERSION_1_4)) {
2974             return;
2975         }
2976 
2977         RILRequest rr = obtainRequest(RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE, result,
2978                 mRILDefaultWorkSource);
2979 
2980         if (RILJ_LOGD) {
2981             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
2982                     + " networkType = " + networkType);
2983         }
2984         mAllowedNetworkTypesBitmask = RadioAccessFamily.getRafFromNetworkType(networkType);
2985         mMetrics.writeSetPreferredNetworkType(mPhoneId, networkType);
2986 
2987         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "setPreferredNetworkType", () -> {
2988             networkProxy.setPreferredNetworkTypeBitmap(rr.mSerial, mAllowedNetworkTypesBitmask);
2989         });
2990     }
2991 
2992     @Override
getPreferredNetworkType(Message result)2993     public void getPreferredNetworkType(Message result) {
2994         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
2995         if (!canMakeRequest("getPreferredNetworkType", networkProxy, result,
2996                 RADIO_HAL_VERSION_1_4)) {
2997             return;
2998         }
2999 
3000         RILRequest rr = obtainRequest(RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE, result,
3001                 mRILDefaultWorkSource);
3002 
3003         if (RILJ_LOGD) {
3004             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3005         }
3006 
3007         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "getPreferredNetworkType", () -> {
3008             networkProxy.getAllowedNetworkTypesBitmap(rr.mSerial);
3009         });
3010     }
3011 
3012     @Override
setAllowedNetworkTypesBitmap( @elephonyManager.NetworkTypeBitMask int networkTypeBitmask, Message result)3013     public void setAllowedNetworkTypesBitmap(
3014             @TelephonyManager.NetworkTypeBitMask int networkTypeBitmask, Message result) {
3015         if (mHalVersion.get(HAL_SERVICE_NETWORK).less(RADIO_HAL_VERSION_1_6)) {
3016             // For older HAL, redirects the call to setPreferredNetworkType.
3017             setPreferredNetworkType(
3018                     RadioAccessFamily.getNetworkTypeFromRaf(networkTypeBitmask), result);
3019             return;
3020         }
3021         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
3022         if (!canMakeRequest("setAllowedNetworkTypesBitmap", networkProxy, result,
3023                 RADIO_HAL_VERSION_1_6)) {
3024             return;
3025         }
3026 
3027         RILRequest rr = obtainRequest(RIL_REQUEST_SET_ALLOWED_NETWORK_TYPES_BITMAP, result,
3028                 mRILDefaultWorkSource);
3029 
3030         if (RILJ_LOGD) {
3031             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3032         }
3033         mAllowedNetworkTypesBitmask = networkTypeBitmask;
3034 
3035         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "setAllowedNetworkTypesBitmap", () -> {
3036             networkProxy.setAllowedNetworkTypesBitmap(rr.mSerial, mAllowedNetworkTypesBitmask);
3037         });
3038     }
3039 
3040     @Override
getAllowedNetworkTypesBitmap(Message result)3041     public void getAllowedNetworkTypesBitmap(Message result) {
3042         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
3043         if (!canMakeRequest("getAllowedNetworkTypesBitmap", networkProxy, result,
3044                 RADIO_HAL_VERSION_1_4)) {
3045             return;
3046         }
3047 
3048         RILRequest rr = obtainRequest(RIL_REQUEST_GET_ALLOWED_NETWORK_TYPES_BITMAP, result,
3049                 mRILDefaultWorkSource);
3050 
3051         if (RILJ_LOGD) {
3052             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3053         }
3054 
3055         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "getAllowedNetworkTypesBitmap", () -> {
3056             networkProxy.getAllowedNetworkTypesBitmap(rr.mSerial);
3057         });
3058     }
3059 
3060     @Override
setLocationUpdates(boolean enable, WorkSource workSource, Message result)3061     public void setLocationUpdates(boolean enable, WorkSource workSource, Message result) {
3062         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
3063         if (!canMakeRequest("setLocationUpdates", networkProxy, result, RADIO_HAL_VERSION_1_4)) {
3064             return;
3065         }
3066 
3067         RILRequest rr = obtainRequest(RIL_REQUEST_SET_LOCATION_UPDATES, result,
3068                 getDefaultWorkSourceIfInvalid(workSource));
3069 
3070         if (RILJ_LOGD) {
3071             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3072                     + " enable = " + enable);
3073         }
3074 
3075         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "setLocationUpdates", () -> {
3076             networkProxy.setLocationUpdates(rr.mSerial, enable);
3077         });
3078     }
3079 
3080     /**
3081      * Is E-UTRA-NR Dual Connectivity enabled
3082      */
3083     @Override
isNrDualConnectivityEnabled(Message result, WorkSource workSource)3084     public void isNrDualConnectivityEnabled(Message result, WorkSource workSource) {
3085         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
3086         if (!canMakeRequest("isNrDualConnectivityEnabled", networkProxy, result,
3087                 RADIO_HAL_VERSION_1_6)) {
3088             return;
3089         }
3090 
3091         RILRequest rr = obtainRequest(RIL_REQUEST_IS_NR_DUAL_CONNECTIVITY_ENABLED, result,
3092                 getDefaultWorkSourceIfInvalid(workSource));
3093 
3094         if (RILJ_LOGD) {
3095             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3096         }
3097 
3098         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "isNrDualConnectivityEnabled", () -> {
3099             networkProxy.isNrDualConnectivityEnabled(rr.mSerial);
3100         });
3101     }
3102 
3103     /**
3104      * Enable/Disable E-UTRA-NR Dual Connectivity
3105      * @param nrDualConnectivityState expected NR dual connectivity state
3106      * This can be passed following states
3107      * <ol>
3108      * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
3109      * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
3110      * <li>Disable NR dual connectivity and force secondary cell to be released
3111      * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
3112      * </ol>
3113      */
3114     @Override
setNrDualConnectivityState(int nrDualConnectivityState, Message result, WorkSource workSource)3115     public void setNrDualConnectivityState(int nrDualConnectivityState, Message result,
3116             WorkSource workSource) {
3117         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
3118         if (!canMakeRequest("setNrDualConnectivityState", networkProxy, result,
3119                 RADIO_HAL_VERSION_1_6)) {
3120             return;
3121         }
3122 
3123         RILRequest rr = obtainRequest(RIL_REQUEST_ENABLE_NR_DUAL_CONNECTIVITY, result,
3124                 getDefaultWorkSourceIfInvalid(workSource));
3125 
3126         if (RILJ_LOGD) {
3127             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3128                     + " enable = " + nrDualConnectivityState);
3129         }
3130 
3131         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "setNrDualConnectivityState", () -> {
3132             networkProxy.setNrDualConnectivityState(rr.mSerial, (byte) nrDualConnectivityState);
3133         });
3134     }
3135 
setVoNrEnabled(boolean enabled)3136     private void setVoNrEnabled(boolean enabled) {
3137         SystemProperties.set(PROPERTY_IS_VONR_ENABLED + mPhoneId, String.valueOf(enabled));
3138     }
3139 
isVoNrEnabled()3140     private boolean isVoNrEnabled() {
3141         return SystemProperties.getBoolean(PROPERTY_IS_VONR_ENABLED + mPhoneId, true);
3142     }
3143 
3144     /**
3145      * Is voice over NR enabled
3146      */
3147     @Override
isVoNrEnabled(Message result, WorkSource workSource)3148     public void isVoNrEnabled(Message result, WorkSource workSource) {
3149         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
3150         // Send null result so errors aren't sent in canMakeRequest
3151         if (!canMakeRequest("isVoNrEnabled", voiceProxy, null, RADIO_HAL_VERSION_2_0)) {
3152             boolean isEnabled = isVoNrEnabled();
3153             if (result != null) {
3154                 AsyncResult.forMessage(result, isEnabled, null);
3155                 result.sendToTarget();
3156             }
3157             return;
3158         }
3159 
3160         RILRequest rr = obtainRequest(RIL_REQUEST_IS_VONR_ENABLED, result,
3161                 getDefaultWorkSourceIfInvalid(workSource));
3162 
3163         if (RILJ_LOGD) {
3164             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3165         }
3166 
3167         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "isVoNrEnabled", () -> {
3168             voiceProxy.isVoNrEnabled(rr.mSerial);
3169         });
3170     }
3171 
3172     /**
3173      * Enable or disable Voice over NR (VoNR)
3174      * @param enabled enable or disable VoNR.
3175      */
3176     @Override
setVoNrEnabled(boolean enabled, Message result, WorkSource workSource)3177     public void setVoNrEnabled(boolean enabled, Message result, WorkSource workSource) {
3178         setVoNrEnabled(enabled);
3179         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
3180         // Send null result so errors aren't sent in canMakeRequest
3181         if (!canMakeRequest("setVoNrEnabled", voiceProxy, null, RADIO_HAL_VERSION_2_0)) {
3182             /* calling a query api to let HAL know that VoNREnabled state is updated.
3183                This is a work around as new AIDL API is not allowed for older HAL version devices.
3184                HAL can check the value of PROPERTY_IS_VONR_ENABLED property to determine
3185                if there is any change whenever it receives isNrDualConnectivityEnabled request.
3186             */
3187             isNrDualConnectivityEnabled(null, workSource);
3188             if (result != null) {
3189                 AsyncResult.forMessage(result, null, null);
3190                 result.sendToTarget();
3191             }
3192             return;
3193         }
3194 
3195         RILRequest rr = obtainRequest(RIL_REQUEST_ENABLE_VONR, result,
3196                 getDefaultWorkSourceIfInvalid(workSource));
3197 
3198         if (RILJ_LOGD) {
3199             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3200         }
3201 
3202         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "setVoNrEnabled", () -> {
3203             voiceProxy.setVoNrEnabled(rr.mSerial, enabled);
3204         });
3205     }
3206 
3207     @Override
setCdmaSubscriptionSource(int cdmaSubscription, Message result)3208     public void setCdmaSubscriptionSource(int cdmaSubscription, Message result) {
3209         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
3210         if (!canMakeRequest("setCdmaSubscriptionSource", simProxy, result, RADIO_HAL_VERSION_1_4)) {
3211             return;
3212         }
3213 
3214         RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE, result,
3215                 mRILDefaultWorkSource);
3216 
3217         if (RILJ_LOGD) {
3218             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3219                     + " cdmaSubscription = " + cdmaSubscription);
3220         }
3221 
3222         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "setCdmaSubscriptionSource", () -> {
3223             simProxy.setCdmaSubscriptionSource(rr.mSerial, cdmaSubscription);
3224         });
3225     }
3226 
3227     @Override
queryCdmaRoamingPreference(Message result)3228     public void queryCdmaRoamingPreference(Message result) {
3229         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
3230         if (!canMakeRequest("queryCdmaRoamingPreference", networkProxy, result,
3231                 RADIO_HAL_VERSION_1_4)) {
3232             return;
3233         }
3234 
3235         RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE, result,
3236                 mRILDefaultWorkSource);
3237 
3238         if (RILJ_LOGD) {
3239             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3240         }
3241 
3242         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "queryCdmaRoamingPreference", () -> {
3243             networkProxy.getCdmaRoamingPreference(rr.mSerial);
3244         });
3245     }
3246 
3247     @Override
setCdmaRoamingPreference(int cdmaRoamingType, Message result)3248     public void setCdmaRoamingPreference(int cdmaRoamingType, Message result) {
3249         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
3250         if (!canMakeRequest("setCdmaRoamingPreference", networkProxy, result,
3251                 RADIO_HAL_VERSION_1_4)) {
3252             return;
3253         }
3254 
3255         RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE, result,
3256                 mRILDefaultWorkSource);
3257 
3258         if (RILJ_LOGD) {
3259             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3260                     + " cdmaRoamingType = " + cdmaRoamingType);
3261         }
3262 
3263         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "setCdmaRoamingPreference", () -> {
3264             networkProxy.setCdmaRoamingPreference(rr.mSerial, cdmaRoamingType);
3265         });
3266     }
3267 
3268     @Override
queryTTYMode(Message result)3269     public void queryTTYMode(Message result) {
3270         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
3271         if (!canMakeRequest("queryTTYMode", voiceProxy, result, RADIO_HAL_VERSION_1_4)) {
3272             return;
3273         }
3274 
3275         RILRequest rr = obtainRequest(RIL_REQUEST_QUERY_TTY_MODE, result, mRILDefaultWorkSource);
3276 
3277         if (RILJ_LOGD) {
3278             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3279         }
3280 
3281         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "queryTTYMode", () -> {
3282             voiceProxy.getTtyMode(rr.mSerial);
3283         });
3284     }
3285 
3286     @Override
setTTYMode(int ttyMode, Message result)3287     public void setTTYMode(int ttyMode, Message result) {
3288         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
3289         if (!canMakeRequest("setTTYMode", voiceProxy, result, RADIO_HAL_VERSION_1_4)) {
3290             return;
3291         }
3292 
3293         RILRequest rr = obtainRequest(RIL_REQUEST_SET_TTY_MODE, result, mRILDefaultWorkSource);
3294 
3295         if (RILJ_LOGD) {
3296             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3297                     + " ttyMode = " + ttyMode);
3298         }
3299 
3300         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "setTTYMode", () -> {
3301             voiceProxy.setTtyMode(rr.mSerial, ttyMode);
3302         });
3303     }
3304 
3305     @Override
setPreferredVoicePrivacy(boolean enable, Message result)3306     public void setPreferredVoicePrivacy(boolean enable, Message result) {
3307         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
3308         if (!canMakeRequest("setPreferredVoicePrivacy", voiceProxy, result,
3309                 RADIO_HAL_VERSION_1_4)) {
3310             return;
3311         }
3312 
3313         RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE, result,
3314                 mRILDefaultWorkSource);
3315 
3316         if (RILJ_LOGD) {
3317             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3318                     + " enable = " + enable);
3319         }
3320 
3321         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "setPreferredVoicePrivacy", () -> {
3322             voiceProxy.setPreferredVoicePrivacy(rr.mSerial, enable);
3323         });
3324     }
3325 
3326     @Override
getPreferredVoicePrivacy(Message result)3327     public void getPreferredVoicePrivacy(Message result) {
3328         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
3329         if (!canMakeRequest("getPreferredVoicePrivacy", voiceProxy, result,
3330                 RADIO_HAL_VERSION_1_4)) {
3331             return;
3332         }
3333 
3334         RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE,
3335                 result, mRILDefaultWorkSource);
3336 
3337         if (RILJ_LOGD) {
3338             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3339         }
3340 
3341         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "getPreferredVoicePrivacy", () -> {
3342             voiceProxy.getPreferredVoicePrivacy(rr.mSerial);
3343         });
3344     }
3345 
3346     @Override
sendCDMAFeatureCode(String featureCode, Message result)3347     public void sendCDMAFeatureCode(String featureCode, Message result) {
3348         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
3349         if (!canMakeRequest("sendCDMAFeatureCode", voiceProxy, result, RADIO_HAL_VERSION_1_4)) {
3350             return;
3351         }
3352 
3353         RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_FLASH, result, mRILDefaultWorkSource);
3354 
3355         if (RILJ_LOGD) {
3356             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3357                     + " featureCode = " + Rlog.pii(RILJ_LOG_TAG, featureCode));
3358         }
3359 
3360         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "sendCDMAFeatureCode", () -> {
3361             voiceProxy.sendCdmaFeatureCode(rr.mSerial,
3362                     RILUtils.convertNullToEmptyString(featureCode));
3363         });
3364     }
3365 
3366     @Override
sendBurstDtmf(String dtmfString, int on, int off, Message result)3367     public void sendBurstDtmf(String dtmfString, int on, int off, Message result) {
3368         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
3369         if (!canMakeRequest("sendBurstDtmf", voiceProxy, result, RADIO_HAL_VERSION_1_4)) {
3370             return;
3371         }
3372 
3373         RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_BURST_DTMF, result, mRILDefaultWorkSource);
3374 
3375         if (RILJ_LOGD) {
3376             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3377                     + " dtmfString = " + dtmfString + " on = " + on + " off = " + off);
3378         }
3379 
3380         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "sendBurstDtmf", () -> {
3381             voiceProxy.sendBurstDtmf(rr.mSerial, RILUtils.convertNullToEmptyString(dtmfString),
3382                     on, off);
3383         });
3384     }
3385 
3386     @Override
sendCdmaSMSExpectMore(byte[] pdu, Message result)3387     public void sendCdmaSMSExpectMore(byte[] pdu, Message result) {
3388         RadioMessagingProxy messagingProxy = getRadioServiceProxy(RadioMessagingProxy.class);
3389         if (!canMakeRequest("sendCdmaSMSExpectMore", messagingProxy, result,
3390                 RADIO_HAL_VERSION_1_4)) {
3391             return;
3392         }
3393 
3394         RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_SEND_SMS_EXPECT_MORE, result,
3395                 mRILDefaultWorkSource);
3396 
3397         // Do not log function arg for privacy
3398         if (RILJ_LOGD) {
3399             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3400         }
3401 
3402         radioServiceInvokeHelper(HAL_SERVICE_MESSAGING, rr, "sendCdmaSMSExpectMore", () -> {
3403             messagingProxy.sendCdmaSmsExpectMore(rr.mSerial, pdu);
3404             if (mHalVersion.get(HAL_SERVICE_MESSAGING).greaterOrEqual(RADIO_HAL_VERSION_1_5)) {
3405                 mMetrics.writeRilSendSms(mPhoneId, rr.mSerial, SmsSession.Event.Tech.SMS_CDMA,
3406                         SmsSession.Event.Format.SMS_FORMAT_3GPP2,
3407                         getOutgoingSmsMessageId(result));
3408             }
3409         });
3410     }
3411 
3412     @Override
sendCdmaSms(byte[] pdu, Message result)3413     public void sendCdmaSms(byte[] pdu, Message result) {
3414         RadioMessagingProxy messagingProxy = getRadioServiceProxy(RadioMessagingProxy.class);
3415         if (!canMakeRequest("sendCdmaSms", messagingProxy, result, RADIO_HAL_VERSION_1_4)) {
3416             return;
3417         }
3418 
3419         RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_SEND_SMS, result, mRILDefaultWorkSource);
3420 
3421         // Do not log function arg for privacy
3422         if (RILJ_LOGD) {
3423             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3424         }
3425 
3426         radioServiceInvokeHelper(HAL_SERVICE_MESSAGING, rr, "sendCdmaSms", () -> {
3427             messagingProxy.sendCdmaSms(rr.mSerial, pdu);
3428             mMetrics.writeRilSendSms(mPhoneId, rr.mSerial, SmsSession.Event.Tech.SMS_CDMA,
3429                     SmsSession.Event.Format.SMS_FORMAT_3GPP2, getOutgoingSmsMessageId(result));
3430         });
3431     }
3432 
3433     @Override
acknowledgeLastIncomingCdmaSms(boolean success, int cause, Message result)3434     public void acknowledgeLastIncomingCdmaSms(boolean success, int cause, Message result) {
3435         RadioMessagingProxy messagingProxy = getRadioServiceProxy(RadioMessagingProxy.class);
3436         if (!canMakeRequest("acknowledgeLastIncomingCdmaSms", messagingProxy, result,
3437                 RADIO_HAL_VERSION_1_4)) {
3438             return;
3439         }
3440 
3441         RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE, result,
3442                 mRILDefaultWorkSource);
3443 
3444         if (RILJ_LOGD) {
3445             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3446                     + " success = " + success + " cause = " + cause);
3447         }
3448 
3449         radioServiceInvokeHelper(HAL_SERVICE_MESSAGING, rr, "acknowledgeLastIncomingCdmaSms",
3450                 () -> {
3451                     messagingProxy.acknowledgeLastIncomingCdmaSms(rr.mSerial, success, cause);
3452                 });
3453     }
3454 
3455     @Override
getGsmBroadcastConfig(Message result)3456     public void getGsmBroadcastConfig(Message result) {
3457         RadioMessagingProxy messagingProxy = getRadioServiceProxy(RadioMessagingProxy.class);
3458         if (!canMakeRequest("getGsmBroadcastConfig", messagingProxy, result,
3459                 RADIO_HAL_VERSION_1_4)) {
3460             return;
3461         }
3462 
3463         RILRequest rr = obtainRequest(RIL_REQUEST_GSM_GET_BROADCAST_CONFIG, result,
3464                 mRILDefaultWorkSource);
3465 
3466         if (RILJ_LOGD) {
3467             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3468         }
3469 
3470         radioServiceInvokeHelper(HAL_SERVICE_MESSAGING, rr, "getGsmBroadcastConfig", () -> {
3471             messagingProxy.getGsmBroadcastConfig(rr.mSerial);
3472         });
3473     }
3474 
3475     @Override
setGsmBroadcastConfig(SmsBroadcastConfigInfo[] config, Message result)3476     public void setGsmBroadcastConfig(SmsBroadcastConfigInfo[] config, Message result) {
3477         RadioMessagingProxy messagingProxy = getRadioServiceProxy(RadioMessagingProxy.class);
3478         if (!canMakeRequest("setGsmBroadcastConfig", messagingProxy, result,
3479                 RADIO_HAL_VERSION_1_4)) {
3480             return;
3481         }
3482 
3483         RILRequest rr = obtainRequest(RIL_REQUEST_GSM_SET_BROADCAST_CONFIG, result,
3484                 mRILDefaultWorkSource);
3485 
3486         if (RILJ_LOGD) {
3487             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3488                     + " with " + config.length + " configs : ");
3489             for (int i = 0; i < config.length; i++) {
3490                 riljLog(config[i].toString());
3491             }
3492         }
3493 
3494         radioServiceInvokeHelper(HAL_SERVICE_MESSAGING, rr, "setGsmBroadcastConfig", () -> {
3495             messagingProxy.setGsmBroadcastConfig(rr.mSerial, config);
3496         });
3497     }
3498 
3499     @Override
setGsmBroadcastActivation(boolean activate, Message result)3500     public void setGsmBroadcastActivation(boolean activate, Message result) {
3501         RadioMessagingProxy messagingProxy = getRadioServiceProxy(RadioMessagingProxy.class);
3502         if (!canMakeRequest("setGsmBroadcastActivation", messagingProxy, result,
3503                 RADIO_HAL_VERSION_1_4)) {
3504             return;
3505         }
3506 
3507         RILRequest rr = obtainRequest(RIL_REQUEST_GSM_BROADCAST_ACTIVATION, result,
3508                 mRILDefaultWorkSource);
3509 
3510         if (RILJ_LOGD) {
3511             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3512                     + " activate = " + activate);
3513         }
3514 
3515         radioServiceInvokeHelper(HAL_SERVICE_MESSAGING, rr, "setGsmBroadcastActivation", () -> {
3516             messagingProxy.setGsmBroadcastActivation(rr.mSerial, activate);
3517         });
3518     }
3519 
3520     @Override
getCdmaBroadcastConfig(Message result)3521     public void getCdmaBroadcastConfig(Message result) {
3522         RadioMessagingProxy messagingProxy = getRadioServiceProxy(RadioMessagingProxy.class);
3523         if (!canMakeRequest("getCdmaBroadcastConfig", messagingProxy, result,
3524                 RADIO_HAL_VERSION_1_4)) {
3525             return;
3526         }
3527 
3528         RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_GET_BROADCAST_CONFIG, result,
3529                 mRILDefaultWorkSource);
3530 
3531         if (RILJ_LOGD) {
3532             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3533         }
3534 
3535         radioServiceInvokeHelper(HAL_SERVICE_MESSAGING, rr, "getCdmaBroadcastConfig", () -> {
3536             messagingProxy.getCdmaBroadcastConfig(rr.mSerial);
3537         });
3538     }
3539 
3540     @Override
setCdmaBroadcastConfig(CdmaSmsBroadcastConfigInfo[] configs, Message result)3541     public void setCdmaBroadcastConfig(CdmaSmsBroadcastConfigInfo[] configs, Message result) {
3542         RadioMessagingProxy messagingProxy = getRadioServiceProxy(RadioMessagingProxy.class);
3543         if (!canMakeRequest("setCdmaBroadcastConfig", messagingProxy, result,
3544                 RADIO_HAL_VERSION_1_4)) {
3545             return;
3546         }
3547 
3548         RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_SET_BROADCAST_CONFIG, result,
3549                 mRILDefaultWorkSource);
3550 
3551         if (RILJ_LOGD) {
3552             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3553                     + " with " + configs.length + " configs : ");
3554             for (CdmaSmsBroadcastConfigInfo config : configs) {
3555                 riljLog(config.toString());
3556             }
3557         }
3558 
3559         radioServiceInvokeHelper(HAL_SERVICE_MESSAGING, rr, "setCdmaBroadcastConfig", () -> {
3560             messagingProxy.setCdmaBroadcastConfig(rr.mSerial, configs);
3561         });
3562     }
3563 
3564     @Override
setCdmaBroadcastActivation(boolean activate, Message result)3565     public void setCdmaBroadcastActivation(boolean activate, Message result) {
3566         RadioMessagingProxy messagingProxy = getRadioServiceProxy(RadioMessagingProxy.class);
3567         if (!canMakeRequest("setCdmaBroadcastActivation", messagingProxy, result,
3568                 RADIO_HAL_VERSION_1_4)) {
3569             return;
3570         }
3571 
3572         RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_BROADCAST_ACTIVATION, result,
3573                 mRILDefaultWorkSource);
3574 
3575         if (RILJ_LOGD) {
3576             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3577                     + " activate = " + activate);
3578         }
3579 
3580         radioServiceInvokeHelper(HAL_SERVICE_MESSAGING, rr, "setCdmaBroadcastActivation", () -> {
3581             messagingProxy.setCdmaBroadcastActivation(rr.mSerial, activate);
3582         });
3583     }
3584 
3585     @Override
getCDMASubscription(Message result)3586     public void getCDMASubscription(Message result) {
3587         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
3588         if (!canMakeRequest("getCDMASubscription", simProxy, result, RADIO_HAL_VERSION_1_4)) {
3589             return;
3590         }
3591 
3592         RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_SUBSCRIPTION, result, mRILDefaultWorkSource);
3593 
3594         if (RILJ_LOGD) {
3595             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3596         }
3597 
3598         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "getCDMASubscription", () -> {
3599             simProxy.getCdmaSubscription(rr.mSerial);
3600         });
3601     }
3602 
3603     @Override
writeSmsToRuim(int status, byte[] pdu, Message result)3604     public void writeSmsToRuim(int status, byte[] pdu, Message result) {
3605         RadioMessagingProxy messagingProxy = getRadioServiceProxy(RadioMessagingProxy.class);
3606         if (!canMakeRequest("writeSmsToRuim", messagingProxy, result, RADIO_HAL_VERSION_1_4)) {
3607             return;
3608         }
3609 
3610         RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM, result,
3611                 mRILDefaultWorkSource);
3612 
3613         if (RILJ_LOGV) {
3614             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3615                     + " status = " + status);
3616         }
3617 
3618         radioServiceInvokeHelper(HAL_SERVICE_MESSAGING, rr, "writeSmsToRuim", () -> {
3619             messagingProxy.writeSmsToRuim(rr.mSerial, status, pdu);
3620         });
3621     }
3622 
3623     @Override
deleteSmsOnRuim(int index, Message result)3624     public void deleteSmsOnRuim(int index, Message result) {
3625         RadioMessagingProxy messagingProxy = getRadioServiceProxy(RadioMessagingProxy.class);
3626         if (!canMakeRequest("deleteSmsOnRuim", messagingProxy, result, RADIO_HAL_VERSION_1_4)) {
3627             return;
3628         }
3629 
3630         RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM, result,
3631                 mRILDefaultWorkSource);
3632 
3633         if (RILJ_LOGV) {
3634             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3635                     + " index = " + index);
3636         }
3637 
3638         radioServiceInvokeHelper(HAL_SERVICE_MESSAGING, rr, "deleteSmsOnRuim", () -> {
3639             messagingProxy.deleteSmsOnRuim(rr.mSerial, index);
3640         });
3641     }
3642 
3643     @Override
getDeviceIdentity(Message result)3644     public void getDeviceIdentity(Message result) {
3645         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class);
3646         if (!canMakeRequest("getDeviceIdentity", modemProxy, result, RADIO_HAL_VERSION_1_4)) {
3647             return;
3648         }
3649 
3650         RILRequest rr = obtainRequest(RIL_REQUEST_DEVICE_IDENTITY, result, mRILDefaultWorkSource);
3651 
3652         if (RILJ_LOGD) {
3653             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3654         }
3655 
3656         radioServiceInvokeHelper(HAL_SERVICE_MODEM, rr, "getDeviceIdentity", () -> {
3657             modemProxy.getDeviceIdentity(rr.mSerial);
3658         });
3659     }
3660 
3661     @Override
getImei(Message result)3662     public void getImei(Message result) {
3663         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class);
3664         if (!canMakeRequest("getImei", modemProxy, result, RADIO_HAL_VERSION_2_1)) {
3665             return;
3666         }
3667 
3668         RILRequest rr = obtainRequest(RIL_REQUEST_DEVICE_IMEI, result, mRILDefaultWorkSource);
3669 
3670         if (RILJ_LOGD) {
3671             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3672         }
3673 
3674         radioServiceInvokeHelper(HAL_SERVICE_MODEM, rr, "getImei", () -> {
3675             modemProxy.getImei(rr.mSerial);
3676         });
3677     }
3678 
3679     @Override
exitEmergencyCallbackMode(Message result)3680     public void exitEmergencyCallbackMode(Message result) {
3681         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
3682         if (!canMakeRequest("exitEmergencyCallbackMode", voiceProxy, result,
3683                 RADIO_HAL_VERSION_1_4)) {
3684             return;
3685         }
3686 
3687         RILRequest rr = obtainRequest(RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE, result,
3688                 mRILDefaultWorkSource);
3689 
3690         if (RILJ_LOGD) {
3691             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3692         }
3693 
3694         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "exitEmergencyCallbackMode", () -> {
3695             voiceProxy.exitEmergencyCallbackMode(rr.mSerial);
3696         });
3697     }
3698 
3699     @Override
getSmscAddress(Message result)3700     public void getSmscAddress(Message result) {
3701         RadioMessagingProxy messagingProxy = getRadioServiceProxy(RadioMessagingProxy.class);
3702         if (!canMakeRequest("getSmscAddress", messagingProxy, result, RADIO_HAL_VERSION_1_4)) {
3703             return;
3704         }
3705 
3706         RILRequest rr = obtainRequest(RIL_REQUEST_GET_SMSC_ADDRESS, result, mRILDefaultWorkSource);
3707 
3708         if (RILJ_LOGD) {
3709             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3710         }
3711 
3712         radioServiceInvokeHelper(HAL_SERVICE_MESSAGING, rr, "getSmscAddress", () -> {
3713             messagingProxy.getSmscAddress(rr.mSerial);
3714         });
3715     }
3716 
3717     @Override
setSmscAddress(String address, Message result)3718     public void setSmscAddress(String address, Message result) {
3719         RadioMessagingProxy messagingProxy = getRadioServiceProxy(RadioMessagingProxy.class);
3720         if (!canMakeRequest("setSmscAddress", messagingProxy, result, RADIO_HAL_VERSION_1_4)) {
3721             return;
3722         }
3723 
3724         RILRequest rr = obtainRequest(RIL_REQUEST_SET_SMSC_ADDRESS, result, mRILDefaultWorkSource);
3725 
3726         if (RILJ_LOGD) {
3727             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3728                     + " address = " + address);
3729         }
3730 
3731         radioServiceInvokeHelper(HAL_SERVICE_MESSAGING, rr, "setSmscAddress", () -> {
3732             messagingProxy.setSmscAddress(rr.mSerial, RILUtils.convertNullToEmptyString(address));
3733         });
3734     }
3735 
3736     @Override
reportSmsMemoryStatus(boolean available, Message result)3737     public void reportSmsMemoryStatus(boolean available, Message result) {
3738         RadioMessagingProxy messagingProxy = getRadioServiceProxy(RadioMessagingProxy.class);
3739         if (!canMakeRequest("reportSmsMemoryStatus", messagingProxy, result,
3740                 RADIO_HAL_VERSION_1_4)) {
3741             return;
3742         }
3743 
3744         RILRequest rr = obtainRequest(RIL_REQUEST_REPORT_SMS_MEMORY_STATUS, result,
3745                 mRILDefaultWorkSource);
3746 
3747         if (RILJ_LOGD) {
3748             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3749                     + " available = " + available);
3750         }
3751 
3752         radioServiceInvokeHelper(HAL_SERVICE_MESSAGING, rr, "reportSmsMemoryStatus", () -> {
3753             messagingProxy.reportSmsMemoryStatus(rr.mSerial, available);
3754         });
3755     }
3756 
3757     @Override
reportStkServiceIsRunning(Message result)3758     public void reportStkServiceIsRunning(Message result) {
3759         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
3760         if (!canMakeRequest("reportStkServiceIsRunning", simProxy, result, RADIO_HAL_VERSION_1_4)) {
3761             return;
3762         }
3763 
3764         RILRequest rr = obtainRequest(RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING, result,
3765                 mRILDefaultWorkSource);
3766 
3767         if (RILJ_LOGD) {
3768             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3769         }
3770 
3771         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "reportStkServiceIsRunning", () -> {
3772             simProxy.reportStkServiceIsRunning(rr.mSerial);
3773         });
3774     }
3775 
3776     @Override
getCdmaSubscriptionSource(Message result)3777     public void getCdmaSubscriptionSource(Message result) {
3778         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
3779         if (!canMakeRequest("getCdmaSubscriptionSource", simProxy, result, RADIO_HAL_VERSION_1_4)) {
3780             return;
3781         }
3782 
3783         RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE, result,
3784                 mRILDefaultWorkSource);
3785 
3786         if (RILJ_LOGD) {
3787             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3788         }
3789 
3790         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "getCdmaSubscriptionSource", () -> {
3791             simProxy.getCdmaSubscriptionSource(rr.mSerial);
3792         });
3793     }
3794 
3795     @Override
acknowledgeIncomingGsmSmsWithPdu(boolean success, String ackPdu, Message result)3796     public void acknowledgeIncomingGsmSmsWithPdu(boolean success, String ackPdu, Message result) {
3797         RadioMessagingProxy messagingProxy = getRadioServiceProxy(RadioMessagingProxy.class);
3798         if (!canMakeRequest("acknowledgeIncomingGsmSmsWithPdu", messagingProxy, result,
3799                 RADIO_HAL_VERSION_1_4)) {
3800             return;
3801         }
3802 
3803         RILRequest rr = obtainRequest(RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU, result,
3804                 mRILDefaultWorkSource);
3805 
3806         if (RILJ_LOGD) {
3807             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3808                     + " success = " + success);
3809         }
3810 
3811         radioServiceInvokeHelper(HAL_SERVICE_MESSAGING, rr, "acknowledgeIncomingGsmSmsWithPdu",
3812                 () -> {
3813                     messagingProxy.acknowledgeIncomingGsmSmsWithPdu(rr.mSerial, success,
3814                             RILUtils.convertNullToEmptyString(ackPdu));
3815                 });
3816     }
3817 
3818     @Override
getVoiceRadioTechnology(Message result)3819     public void getVoiceRadioTechnology(Message result) {
3820         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
3821         if (!canMakeRequest("getVoiceRadioTechnology", networkProxy, result,
3822                 RADIO_HAL_VERSION_1_4)) {
3823             return;
3824         }
3825 
3826         RILRequest rr = obtainRequest(RIL_REQUEST_VOICE_RADIO_TECH, result, mRILDefaultWorkSource);
3827 
3828         if (RILJ_LOGD) {
3829             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3830         }
3831 
3832         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "getVoiceRadioTechnology", () -> {
3833             networkProxy.getVoiceRadioTechnology(rr.mSerial);
3834         });
3835     }
3836 
3837     @Override
getCellInfoList(Message result, WorkSource workSource)3838     public void getCellInfoList(Message result, WorkSource workSource) {
3839         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
3840         if (!canMakeRequest("getCellInfoList", networkProxy, result, RADIO_HAL_VERSION_1_4)) {
3841             return;
3842         }
3843 
3844         RILRequest rr = obtainRequest(RIL_REQUEST_GET_CELL_INFO_LIST, result,
3845                 getDefaultWorkSourceIfInvalid(workSource));
3846 
3847         if (RILJ_LOGD) {
3848             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3849         }
3850 
3851         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "getCellInfoList", () -> {
3852             networkProxy.getCellInfoList(rr.mSerial);
3853         });
3854     }
3855 
3856     @Override
setCellInfoListRate(int rateInMillis, Message result, WorkSource workSource)3857     public void setCellInfoListRate(int rateInMillis, Message result, WorkSource workSource) {
3858         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
3859         if (!canMakeRequest("setCellInfoListRate", networkProxy, result, RADIO_HAL_VERSION_1_4)) {
3860             return;
3861         }
3862 
3863         RILRequest rr = obtainRequest(RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE, result,
3864                 getDefaultWorkSourceIfInvalid(workSource));
3865 
3866         if (RILJ_LOGD) {
3867             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3868                     + " rateInMillis = " + rateInMillis);
3869         }
3870 
3871         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "setCellInfoListRate", () -> {
3872             networkProxy.setCellInfoListRate(rr.mSerial, rateInMillis);
3873         });
3874     }
3875 
3876     @Override
setInitialAttachApn(DataProfile dataProfile, Message result)3877     public void setInitialAttachApn(DataProfile dataProfile, Message result) {
3878         RadioDataProxy dataProxy = getRadioServiceProxy(RadioDataProxy.class);
3879         if (!canMakeRequest("setInitialAttachApn", dataProxy, result, RADIO_HAL_VERSION_1_4)) {
3880             return;
3881         }
3882 
3883         RILRequest rr = obtainRequest(RIL_REQUEST_SET_INITIAL_ATTACH_APN, result,
3884                 mRILDefaultWorkSource);
3885 
3886         if (RILJ_LOGD) {
3887             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest) + dataProfile);
3888         }
3889 
3890         radioServiceInvokeHelper(HAL_SERVICE_DATA, rr, "setInitialAttachApn", () -> {
3891             dataProxy.setInitialAttachApn(rr.mSerial, dataProfile);
3892         });
3893     }
3894 
3895     @Override
getImsRegistrationState(Message result)3896     public void getImsRegistrationState(Message result) {
3897         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
3898         if (!canMakeRequest("getImsRegistrationState", networkProxy, result,
3899                 RADIO_HAL_VERSION_1_4)) {
3900             return;
3901         }
3902 
3903         RILRequest rr = obtainRequest(RIL_REQUEST_IMS_REGISTRATION_STATE, result,
3904                 mRILDefaultWorkSource);
3905 
3906         if (RILJ_LOGD) {
3907             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3908         }
3909 
3910         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "getImsRegistrationState", () -> {
3911             networkProxy.getImsRegistrationState(rr.mSerial);
3912         });
3913     }
3914 
3915     @Override
sendImsGsmSms(String smscPdu, String pdu, int retry, int messageRef, Message result)3916     public void sendImsGsmSms(String smscPdu, String pdu, int retry, int messageRef,
3917             Message result) {
3918         RadioMessagingProxy messagingProxy = getRadioServiceProxy(RadioMessagingProxy.class);
3919         if (!canMakeRequest("sendImsGsmSms", messagingProxy, result, RADIO_HAL_VERSION_1_4)) {
3920             return;
3921         }
3922 
3923         RILRequest rr = obtainRequest(RIL_REQUEST_IMS_SEND_SMS, result, mRILDefaultWorkSource);
3924 
3925         // Do not log function args for privacy
3926         if (RILJ_LOGD) {
3927             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3928         }
3929 
3930         radioServiceInvokeHelper(HAL_SERVICE_MESSAGING, rr, "sendImsGsmSms", () -> {
3931             messagingProxy.sendImsSms(rr.mSerial, smscPdu, pdu, null, retry, messageRef);
3932             mMetrics.writeRilSendSms(mPhoneId, rr.mSerial, SmsSession.Event.Tech.SMS_IMS,
3933                     SmsSession.Event.Format.SMS_FORMAT_3GPP, getOutgoingSmsMessageId(result));
3934         });
3935     }
3936 
3937     @Override
sendImsCdmaSms(byte[] pdu, int retry, int messageRef, Message result)3938     public void sendImsCdmaSms(byte[] pdu, int retry, int messageRef, Message result) {
3939         RadioMessagingProxy messagingProxy = getRadioServiceProxy(RadioMessagingProxy.class);
3940         if (!canMakeRequest("sendImsCdmaSms", messagingProxy, result, RADIO_HAL_VERSION_1_4)) {
3941             return;
3942         }
3943 
3944         RILRequest rr = obtainRequest(RIL_REQUEST_IMS_SEND_SMS, result, mRILDefaultWorkSource);
3945 
3946         // Do not log function args for privacy
3947         if (RILJ_LOGD) {
3948             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3949         }
3950 
3951         radioServiceInvokeHelper(HAL_SERVICE_MESSAGING, rr, "sendImsCdmaSms", () -> {
3952             messagingProxy.sendImsSms(rr.mSerial, null, null, pdu, retry, messageRef);
3953             mMetrics.writeRilSendSms(mPhoneId, rr.mSerial, SmsSession.Event.Tech.SMS_IMS,
3954                     SmsSession.Event.Format.SMS_FORMAT_3GPP2, getOutgoingSmsMessageId(result));
3955         });
3956     }
3957 
3958     @Override
iccTransmitApduBasicChannel(int cla, int instruction, int p1, int p2, int p3, String data, Message result)3959     public void iccTransmitApduBasicChannel(int cla, int instruction, int p1, int p2, int p3,
3960             String data, Message result) {
3961         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
3962         if (!canMakeRequest("iccTransmitApduBasicChannel", simProxy, result,
3963                 RADIO_HAL_VERSION_1_4)) {
3964             return;
3965         }
3966 
3967         RILRequest rr = obtainRequest(RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC, result,
3968                 mRILDefaultWorkSource);
3969 
3970         if (RILJ_LOGD) {
3971             if (TelephonyUtils.IS_DEBUGGABLE) {
3972                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3973                         + String.format(" cla = 0x%02X ins = 0x%02X", cla, instruction)
3974                         + String.format(" p1 = 0x%02X p2 = 0x%02X p3 = 0x%02X", p1, p2, p3)
3975                         + " data = " + data);
3976             } else {
3977                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
3978             }
3979         }
3980 
3981         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "iccTransmitApduBasicChannel", () -> {
3982             simProxy.iccTransmitApduBasicChannel(rr.mSerial, cla, instruction, p1, p2, p3, data);
3983         });
3984     }
3985 
3986     @Override
iccOpenLogicalChannel(String aid, int p2, Message result)3987     public void iccOpenLogicalChannel(String aid, int p2, Message result) {
3988         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
3989         if (!canMakeRequest("iccOpenLogicalChannel", simProxy, result, RADIO_HAL_VERSION_1_4)) {
3990             return;
3991         }
3992 
3993         RILRequest rr = obtainRequest(RIL_REQUEST_SIM_OPEN_CHANNEL, result, mRILDefaultWorkSource);
3994 
3995         if (RILJ_LOGD) {
3996             if (TelephonyUtils.IS_DEBUGGABLE) {
3997                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
3998                         + " aid = " + aid + " p2 = " + p2);
3999             } else {
4000                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4001             }
4002         }
4003 
4004         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "iccOpenLogicalChannel", () -> {
4005             simProxy.iccOpenLogicalChannel(rr.mSerial, RILUtils.convertNullToEmptyString(aid), p2);
4006         });
4007     }
4008 
4009     @Override
iccCloseLogicalChannel(int channel, boolean isEs10, Message result)4010     public void iccCloseLogicalChannel(int channel, boolean isEs10, Message result) {
4011         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
4012         if (!canMakeRequest("iccCloseLogicalChannel", simProxy, result, RADIO_HAL_VERSION_1_4)) {
4013             return;
4014         }
4015 
4016         RILRequest rr = obtainRequest(RIL_REQUEST_SIM_CLOSE_CHANNEL, result, mRILDefaultWorkSource);
4017 
4018         if (RILJ_LOGD) {
4019             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4020                     + " channel = " + channel + " isEs10 = " + isEs10);
4021         }
4022         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "iccCloseLogicalChannel", () -> {
4023             simProxy.iccCloseLogicalChannel(rr.mSerial, channel, isEs10);
4024         });
4025     }
4026 
4027     @Override
iccTransmitApduLogicalChannel(int channel, int cla, int instruction, int p1, int p2, int p3, String data, boolean isEs10Command, Message result)4028     public void iccTransmitApduLogicalChannel(int channel, int cla, int instruction, int p1, int p2,
4029             int p3, String data, boolean isEs10Command, Message result) {
4030         if (channel <= 0) {
4031             throw new RuntimeException(
4032                     "Invalid channel in iccTransmitApduLogicalChannel: " + channel);
4033         }
4034 
4035         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
4036         if (!canMakeRequest("iccTransmitApduLogicalChannel", simProxy, result,
4037                 RADIO_HAL_VERSION_1_4)) {
4038             return;
4039         }
4040 
4041         RILRequest rr = obtainRequest(RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL, result,
4042                 mRILDefaultWorkSource);
4043 
4044         if (RILJ_LOGD) {
4045             if (TelephonyUtils.IS_DEBUGGABLE) {
4046                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4047                         + String.format(" channel = %d", channel)
4048                         + String.format(" cla = 0x%02X ins = 0x%02X", cla, instruction)
4049                         + String.format(" p1 = 0x%02X p2 = 0x%02X p3 = 0x%02X", p1, p2, p3)
4050                         + " isEs10Command = " + isEs10Command
4051                         + " data = " + data);
4052             } else {
4053                 riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4054             }
4055         }
4056 
4057         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "iccTransmitApduLogicalChannel", () -> {
4058             simProxy.iccTransmitApduLogicalChannel(rr.mSerial, channel, cla, instruction, p1, p2,
4059                     p3, data, isEs10Command);
4060         });
4061     }
4062 
4063     @Override
nvReadItem(int itemID, Message result, WorkSource workSource)4064     public void nvReadItem(int itemID, Message result, WorkSource workSource) {
4065         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class);
4066         if (!canMakeRequest("nvReadItem", modemProxy, result, RADIO_HAL_VERSION_1_4)) {
4067             return;
4068         }
4069 
4070         RILRequest rr = obtainRequest(RIL_REQUEST_NV_READ_ITEM, result,
4071                 getDefaultWorkSourceIfInvalid(workSource));
4072 
4073         if (RILJ_LOGD) {
4074             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4075                     + " itemId = " + itemID);
4076         }
4077 
4078         radioServiceInvokeHelper(HAL_SERVICE_MODEM, rr, "nvReadItem", () -> {
4079             modemProxy.nvReadItem(rr.mSerial, itemID);
4080         });
4081     }
4082 
4083     @Override
nvWriteItem(int itemId, String itemValue, Message result, WorkSource workSource)4084     public void nvWriteItem(int itemId, String itemValue, Message result, WorkSource workSource) {
4085         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class);
4086         if (!canMakeRequest("nvWriteItem", modemProxy, result, RADIO_HAL_VERSION_1_4)) {
4087             return;
4088         }
4089 
4090         RILRequest rr = obtainRequest(RIL_REQUEST_NV_WRITE_ITEM, result,
4091                 getDefaultWorkSourceIfInvalid(workSource));
4092 
4093         if (RILJ_LOGD) {
4094             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4095                     + " itemId = " + itemId + " itemValue = " + itemValue);
4096         }
4097 
4098         radioServiceInvokeHelper(HAL_SERVICE_MODEM, rr, "nvWriteItem", () -> {
4099             modemProxy.nvWriteItem(rr.mSerial, itemId,
4100                     RILUtils.convertNullToEmptyString(itemValue));
4101         });
4102     }
4103 
4104     @Override
nvWriteCdmaPrl(byte[] preferredRoamingList, Message result)4105     public void nvWriteCdmaPrl(byte[] preferredRoamingList, Message result) {
4106         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class);
4107         if (!canMakeRequest("nvWriteCdmaPrl", modemProxy, result, RADIO_HAL_VERSION_1_4)) {
4108             return;
4109         }
4110 
4111         RILRequest rr = obtainRequest(RIL_REQUEST_NV_WRITE_CDMA_PRL, result, mRILDefaultWorkSource);
4112 
4113         if (RILJ_LOGD) {
4114             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4115                     + " PreferredRoamingList = 0x"
4116                     + IccUtils.bytesToHexString(preferredRoamingList));
4117         }
4118 
4119         radioServiceInvokeHelper(HAL_SERVICE_MODEM, rr, "nvWriteCdmaPrl", () -> {
4120             modemProxy.nvWriteCdmaPrl(rr.mSerial, preferredRoamingList);
4121         });
4122     }
4123 
4124     @Override
nvResetConfig(int resetType, Message result)4125     public void nvResetConfig(int resetType, Message result) {
4126         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class);
4127         if (!canMakeRequest("nvResetConfig", modemProxy, result, RADIO_HAL_VERSION_1_4)) {
4128             return;
4129         }
4130 
4131         RILRequest rr = obtainRequest(RIL_REQUEST_NV_RESET_CONFIG, result, mRILDefaultWorkSource);
4132 
4133         if (RILJ_LOGD) {
4134             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4135                     + " resetType = " + resetType);
4136         }
4137 
4138         radioServiceInvokeHelper(HAL_SERVICE_MODEM, rr, "nvResetConfig", () -> {
4139             modemProxy.nvResetConfig(rr.mSerial, resetType);
4140         });
4141     }
4142 
4143     @Override
setUiccSubscription(int slotId, int appIndex, int subId, int subStatus, Message result)4144     public void setUiccSubscription(int slotId, int appIndex, int subId, int subStatus,
4145             Message result) {
4146         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
4147         if (!canMakeRequest("setUiccSubscription", simProxy, result, RADIO_HAL_VERSION_1_4)) {
4148             return;
4149         }
4150 
4151         RILRequest rr = obtainRequest(RIL_REQUEST_SET_UICC_SUBSCRIPTION, result,
4152                 mRILDefaultWorkSource);
4153 
4154         if (RILJ_LOGD) {
4155             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4156                     + " slot = " + slotId + " appIndex = " + appIndex
4157                     + " subId = " + subId + " subStatus = " + subStatus);
4158         }
4159 
4160         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "setUiccSubscription", () -> {
4161             simProxy.setUiccSubscription(rr.mSerial, slotId, appIndex, subId, subStatus);
4162         });
4163     }
4164 
4165     @Override
setDataAllowed(boolean allowed, Message result)4166     public void setDataAllowed(boolean allowed, Message result) {
4167         RadioDataProxy dataProxy = getRadioServiceProxy(RadioDataProxy.class);
4168         if (!canMakeRequest("setDataAllowed", dataProxy, result, RADIO_HAL_VERSION_1_4)) {
4169             return;
4170         }
4171 
4172         RILRequest rr = obtainRequest(RIL_REQUEST_ALLOW_DATA, result, mRILDefaultWorkSource);
4173 
4174         if (RILJ_LOGD) {
4175             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4176                     + " allowed = " + allowed);
4177         }
4178 
4179         radioServiceInvokeHelper(HAL_SERVICE_DATA, rr, "setDataAllowed", () -> {
4180             dataProxy.setDataAllowed(rr.mSerial, allowed);
4181         });
4182     }
4183 
4184     @Override
getHardwareConfig(Message result)4185     public void getHardwareConfig(Message result) {
4186         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class);
4187         if (!canMakeRequest("getHardwareConfig", modemProxy, result, RADIO_HAL_VERSION_1_4)) {
4188             return;
4189         }
4190 
4191         RILRequest rr = obtainRequest(RIL_REQUEST_GET_HARDWARE_CONFIG, result,
4192                 mRILDefaultWorkSource);
4193 
4194         // Do not log function args for privacy
4195         if (RILJ_LOGD) {
4196             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4197         }
4198 
4199         radioServiceInvokeHelper(HAL_SERVICE_MODEM, rr, "getHardwareConfig", () -> {
4200             modemProxy.getHardwareConfig(rr.mSerial);
4201         });
4202     }
4203 
4204     @Override
requestIccSimAuthentication(int authContext, String data, String aid, Message result)4205     public void requestIccSimAuthentication(int authContext, String data, String aid,
4206             Message result) {
4207         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
4208         if (!canMakeRequest("requestIccSimAuthentication", simProxy, result,
4209                 RADIO_HAL_VERSION_1_4)) {
4210             return;
4211         }
4212 
4213         RILRequest rr = obtainRequest(RIL_REQUEST_SIM_AUTHENTICATION, result,
4214                 mRILDefaultWorkSource);
4215 
4216         // Do not log function args for privacy
4217         if (RILJ_LOGD) {
4218             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4219         }
4220 
4221         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "requestIccSimAuthentication", () -> {
4222             simProxy.requestIccSimAuthentication(rr.mSerial, authContext,
4223                     RILUtils.convertNullToEmptyString(data),
4224                     RILUtils.convertNullToEmptyString(aid));
4225         });
4226     }
4227 
4228     @Override
setDataProfile(DataProfile[] dps, Message result)4229     public void setDataProfile(DataProfile[] dps, Message result) {
4230         RadioDataProxy dataProxy = getRadioServiceProxy(RadioDataProxy.class);
4231         if (!canMakeRequest("setDataProfile", dataProxy, result, RADIO_HAL_VERSION_1_4)) {
4232             return;
4233         }
4234 
4235         RILRequest rr = obtainRequest(RIL_REQUEST_SET_DATA_PROFILE, result, mRILDefaultWorkSource);
4236 
4237         if (RILJ_LOGD) {
4238             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4239                     + " with data profiles : ");
4240             for (DataProfile profile : dps) {
4241                 riljLog(profile.toString());
4242             }
4243         }
4244 
4245         radioServiceInvokeHelper(HAL_SERVICE_DATA, rr, "setDataProfile", () -> {
4246             dataProxy.setDataProfile(rr.mSerial, dps);
4247         });
4248     }
4249 
4250     @Override
requestShutdown(Message result)4251     public void requestShutdown(Message result) {
4252         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class);
4253         if (!canMakeRequest("requestShutdown", modemProxy, result, RADIO_HAL_VERSION_1_4)) {
4254             return;
4255         }
4256 
4257         RILRequest rr = obtainRequest(RIL_REQUEST_SHUTDOWN, result, mRILDefaultWorkSource);
4258 
4259         if (RILJ_LOGD) {
4260             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4261         }
4262 
4263         radioServiceInvokeHelper(HAL_SERVICE_MODEM, rr, "requestShutdown", () -> {
4264             modemProxy.requestShutdown(rr.mSerial);
4265         });
4266     }
4267 
4268     @Override
getRadioCapability(Message result)4269     public void getRadioCapability(Message result) {
4270         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class);
4271         if (!canMakeRequest("getRadioCapability", modemProxy, result, RADIO_HAL_VERSION_1_4)) {
4272             return;
4273         }
4274 
4275         RILRequest rr = obtainRequest(RIL_REQUEST_GET_RADIO_CAPABILITY, result,
4276                 mRILDefaultWorkSource);
4277 
4278         if (RILJ_LOGD) {
4279             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4280         }
4281 
4282         radioServiceInvokeHelper(HAL_SERVICE_MODEM, rr, "getRadioCapability", () -> {
4283             modemProxy.getRadioCapability(rr.mSerial);
4284         });
4285     }
4286 
4287     @Override
setRadioCapability(RadioCapability rc, Message result)4288     public void setRadioCapability(RadioCapability rc, Message result) {
4289         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class);
4290         if (!canMakeRequest("setRadioCapability", modemProxy, result, RADIO_HAL_VERSION_1_4)) {
4291             return;
4292         }
4293 
4294         RILRequest rr = obtainRequest(RIL_REQUEST_SET_RADIO_CAPABILITY, result,
4295                 mRILDefaultWorkSource);
4296 
4297         if (RILJ_LOGD) {
4298             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4299                     + " RadioCapability = " + rc.toString());
4300         }
4301 
4302         radioServiceInvokeHelper(HAL_SERVICE_MODEM, rr, "setRadioCapability", () -> {
4303             modemProxy.setRadioCapability(rr.mSerial, rc);
4304         });
4305     }
4306 
4307     /**
4308      * Control the data throttling at modem.
4309      *
4310      * @param result Message that will be sent back to the requester
4311      * @param workSource calling Worksource
4312      * @param dataThrottlingAction the DataThrottlingAction that is being requested. Defined in
4313      *      android.hardware.radio@1.6.types.
4314      * @param completionWindowMillis milliseconds in which full throttling has to be achieved.
4315      */
4316     @Override
setDataThrottling(Message result, WorkSource workSource, int dataThrottlingAction, long completionWindowMillis)4317     public void setDataThrottling(Message result, WorkSource workSource, int dataThrottlingAction,
4318             long completionWindowMillis) {
4319         RadioDataProxy dataProxy = getRadioServiceProxy(RadioDataProxy.class);
4320         if (!canMakeRequest("setDataThrottling", dataProxy, result, RADIO_HAL_VERSION_1_6)) {
4321             return;
4322         }
4323 
4324         RILRequest rr = obtainRequest(RIL_REQUEST_SET_DATA_THROTTLING, result,
4325                 getDefaultWorkSourceIfInvalid(workSource));
4326 
4327         if (RILJ_LOGD) {
4328             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4329                     + " dataThrottlingAction = " + dataThrottlingAction
4330                     + " completionWindowMillis " + completionWindowMillis);
4331         }
4332 
4333         radioServiceInvokeHelper(HAL_SERVICE_DATA, rr, "setDataThrottling", () -> {
4334             dataProxy.setDataThrottling(rr.mSerial, (byte) dataThrottlingAction,
4335                     completionWindowMillis);
4336         });
4337     }
4338 
4339     @Override
getModemActivityInfo(Message result, WorkSource workSource)4340     public void getModemActivityInfo(Message result, WorkSource workSource) {
4341         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class);
4342         if (!canMakeRequest("getModemActivityInfo", modemProxy, result, RADIO_HAL_VERSION_1_4)) {
4343             return;
4344         }
4345 
4346         RILRequest rr = obtainRequest(RIL_REQUEST_GET_ACTIVITY_INFO, result,
4347                 getDefaultWorkSourceIfInvalid(workSource));
4348 
4349         if (RILJ_LOGD) {
4350             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4351         }
4352 
4353         radioServiceInvokeHelper(HAL_SERVICE_MODEM, rr, "getModemActivityInfo", () -> {
4354             modemProxy.getModemActivityInfo(rr.mSerial);
4355             Message msg = mRilHandler.obtainMessage(EVENT_BLOCKING_RESPONSE_TIMEOUT, rr.mSerial);
4356             mRilHandler.sendMessageDelayed(msg, DEFAULT_BLOCKING_MESSAGE_RESPONSE_TIMEOUT_MS);
4357         });
4358     }
4359 
4360     @Override
setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules, Message result, WorkSource workSource)4361     public void setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules,
4362             Message result, WorkSource workSource) {
4363         Objects.requireNonNull(carrierRestrictionRules, "Carrier restriction cannot be null.");
4364 
4365         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
4366         if (!canMakeRequest("setAllowedCarriers", simProxy, result, RADIO_HAL_VERSION_1_4)) {
4367             return;
4368         }
4369 
4370         RILRequest rr = obtainRequest(RIL_REQUEST_SET_ALLOWED_CARRIERS, result,
4371                 getDefaultWorkSourceIfInvalid(workSource));
4372 
4373         if (RILJ_LOGD) {
4374             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4375                     + " params: " + carrierRestrictionRules);
4376         }
4377 
4378         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "setAllowedCarriers", () -> {
4379             simProxy.setAllowedCarriers(rr.mSerial, carrierRestrictionRules);
4380         });
4381     }
4382 
4383     @Override
getAllowedCarriers(Message result, WorkSource workSource)4384     public void getAllowedCarriers(Message result, WorkSource workSource) {
4385         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
4386         if (!canMakeRequest("getAllowedCarriers", simProxy, result, RADIO_HAL_VERSION_1_4)) {
4387             return;
4388         }
4389 
4390         RILRequest rr = obtainRequest(RIL_REQUEST_GET_ALLOWED_CARRIERS, result,
4391                 getDefaultWorkSourceIfInvalid(workSource));
4392 
4393         if (RILJ_LOGD) {
4394             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4395         }
4396 
4397         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "getAllowedCarriers", () -> {
4398             simProxy.getAllowedCarriers(rr.mSerial);
4399         });
4400     }
4401 
4402     @Override
sendDeviceState(int stateType, boolean state, Message result)4403     public void sendDeviceState(int stateType, boolean state, Message result) {
4404         RadioModemProxy modemProxy = getRadioServiceProxy(RadioModemProxy.class);
4405         if (!canMakeRequest("sendDeviceState", modemProxy, result, RADIO_HAL_VERSION_1_4)) {
4406             return;
4407         }
4408 
4409         RILRequest rr = obtainRequest(RIL_REQUEST_SEND_DEVICE_STATE, result, mRILDefaultWorkSource);
4410 
4411         if (RILJ_LOGD) {
4412             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest) + " "
4413                     + stateType + ":" + state);
4414         }
4415 
4416         radioServiceInvokeHelper(HAL_SERVICE_MODEM, rr, "sendDeviceState", () -> {
4417             modemProxy.sendDeviceState(rr.mSerial, stateType, state);
4418         });
4419     }
4420 
4421     @Override
setUnsolResponseFilter(int filter, Message result)4422     public void setUnsolResponseFilter(int filter, Message result) {
4423         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
4424         if (!canMakeRequest("setUnsolResponseFilter", networkProxy, result,
4425                 RADIO_HAL_VERSION_1_4)) {
4426             return;
4427         }
4428 
4429         RILRequest rr = obtainRequest(RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER, result,
4430                 mRILDefaultWorkSource);
4431 
4432         if (RILJ_LOGD) {
4433             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4434                     + " " + filter);
4435         }
4436 
4437         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "setUnsolResponseFilter", () -> {
4438             networkProxy.setIndicationFilter(rr.mSerial, filter);
4439         });
4440     }
4441 
4442     @Override
setSignalStrengthReportingCriteria( @onNull List<SignalThresholdInfo> signalThresholdInfos, @Nullable Message result)4443     public void setSignalStrengthReportingCriteria(
4444             @NonNull List<SignalThresholdInfo> signalThresholdInfos, @Nullable Message result) {
4445         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
4446         if (!canMakeRequest("setSignalStrengthReportingCriteria", networkProxy, result,
4447                 RADIO_HAL_VERSION_1_4)) {
4448             return;
4449         }
4450 
4451         RILRequest rr = obtainRequest(RIL_REQUEST_SET_SIGNAL_STRENGTH_REPORTING_CRITERIA, result,
4452                 mRILDefaultWorkSource);
4453 
4454         if (RILJ_LOGD) {
4455             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4456         }
4457 
4458         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "setSignalStrengthReportingCriteria",
4459                 () -> {
4460                     networkProxy.setSignalStrengthReportingCriteria(rr.mSerial,
4461                             signalThresholdInfos);
4462                 });
4463     }
4464 
4465     @Override
setLinkCapacityReportingCriteria(int hysteresisMs, int hysteresisDlKbps, int hysteresisUlKbps, int[] thresholdsDlKbps, int[] thresholdsUlKbps, int ran, Message result)4466     public void setLinkCapacityReportingCriteria(int hysteresisMs, int hysteresisDlKbps,
4467             int hysteresisUlKbps, int[] thresholdsDlKbps, int[] thresholdsUlKbps, int ran,
4468             Message result) {
4469         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
4470         if (!canMakeRequest("setLinkCapacityReportingCriteria", networkProxy, result,
4471                 RADIO_HAL_VERSION_1_4)) {
4472             return;
4473         }
4474 
4475         RILRequest rr = obtainRequest(RIL_REQUEST_SET_LINK_CAPACITY_REPORTING_CRITERIA, result,
4476                 mRILDefaultWorkSource);
4477 
4478         if (RILJ_LOGD) {
4479             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4480         }
4481 
4482         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "setLinkCapacityReportingCriteria",
4483                 () -> {
4484                     networkProxy.setLinkCapacityReportingCriteria(rr.mSerial, hysteresisMs,
4485                             hysteresisDlKbps, hysteresisUlKbps, thresholdsDlKbps, thresholdsUlKbps,
4486                             ran);
4487                 });
4488     }
4489 
4490     @Override
setSimCardPower(int state, Message result, WorkSource workSource)4491     public void setSimCardPower(int state, Message result, WorkSource workSource) {
4492         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
4493         if (!canMakeRequest("setSimCardPower", simProxy, result, RADIO_HAL_VERSION_1_4)) {
4494             return;
4495         }
4496 
4497         RILRequest rr = obtainRequest(RIL_REQUEST_SET_SIM_CARD_POWER, result,
4498                 getDefaultWorkSourceIfInvalid(workSource));
4499 
4500         if (RILJ_LOGD) {
4501             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4502                     + " " + state);
4503         }
4504 
4505         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "setSimCardPower", () -> {
4506             simProxy.setSimCardPower(rr.mSerial, state);
4507         });
4508     }
4509 
4510     @Override
setCarrierInfoForImsiEncryption(ImsiEncryptionInfo imsiEncryptionInfo, Message result)4511     public void setCarrierInfoForImsiEncryption(ImsiEncryptionInfo imsiEncryptionInfo,
4512             Message result) {
4513         Objects.requireNonNull(imsiEncryptionInfo, "ImsiEncryptionInfo cannot be null.");
4514         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
4515         if (!canMakeRequest("setCarrierInfoForImsiEncryption", simProxy, result,
4516                 RADIO_HAL_VERSION_1_4)) {
4517             return;
4518         }
4519 
4520         RILRequest rr = obtainRequest(RIL_REQUEST_SET_CARRIER_INFO_IMSI_ENCRYPTION, result,
4521                 mRILDefaultWorkSource);
4522         if (RILJ_LOGD) {
4523             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4524         }
4525 
4526         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "setCarrierInfoForImsiEncryption", () -> {
4527             simProxy.setCarrierInfoForImsiEncryption(rr.mSerial, imsiEncryptionInfo);
4528         });
4529     }
4530 
4531     @Override
startNattKeepalive(int contextId, KeepalivePacketData packetData, int intervalMillis, Message result)4532     public void startNattKeepalive(int contextId, KeepalivePacketData packetData,
4533             int intervalMillis, Message result) {
4534         Objects.requireNonNull(packetData, "KeepaliveRequest cannot be null.");
4535         RadioDataProxy dataProxy = getRadioServiceProxy(RadioDataProxy.class);
4536         if (!canMakeRequest("startNattKeepalive", dataProxy, result, RADIO_HAL_VERSION_1_4)) {
4537             return;
4538         }
4539 
4540         RILRequest rr = obtainRequest(RIL_REQUEST_START_KEEPALIVE, result, mRILDefaultWorkSource);
4541 
4542         if (RILJ_LOGD) {
4543             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4544         }
4545 
4546         radioServiceInvokeHelper(HAL_SERVICE_DATA, rr, "startNattKeepalive", () -> {
4547             dataProxy.startKeepalive(rr.mSerial, contextId, packetData, intervalMillis, result);
4548         });
4549     }
4550 
4551     @Override
stopNattKeepalive(int sessionHandle, Message result)4552     public void stopNattKeepalive(int sessionHandle, Message result) {
4553         RadioDataProxy dataProxy = getRadioServiceProxy(RadioDataProxy.class);
4554         if (!canMakeRequest("stopNattKeepalive", dataProxy, result, RADIO_HAL_VERSION_1_4)) {
4555             return;
4556         }
4557 
4558         RILRequest rr = obtainRequest(RIL_REQUEST_STOP_KEEPALIVE, result, mRILDefaultWorkSource);
4559 
4560         if (RILJ_LOGD) {
4561             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4562         }
4563 
4564         radioServiceInvokeHelper(HAL_SERVICE_DATA, rr, "stopNattKeepalive", () -> {
4565             dataProxy.stopKeepalive(rr.mSerial, sessionHandle);
4566         });
4567     }
4568 
4569     /**
4570      * Enable or disable uicc applications on the SIM.
4571      *
4572      * @param enable whether to enable or disable uicc applications.
4573      * @param result a Message to return to the requester
4574      */
4575     @Override
enableUiccApplications(boolean enable, Message result)4576     public void enableUiccApplications(boolean enable, Message result) {
4577         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
4578         if (!canMakeRequest("enableUiccApplications", simProxy, result, RADIO_HAL_VERSION_1_5)) {
4579             return;
4580         }
4581 
4582         RILRequest rr = obtainRequest(RIL_REQUEST_ENABLE_UICC_APPLICATIONS, result,
4583                 mRILDefaultWorkSource);
4584 
4585         if (RILJ_LOGD) {
4586             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4587                     + " " + enable);
4588         }
4589 
4590         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "enableUiccApplications", () -> {
4591             simProxy.enableUiccApplications(rr.mSerial, enable);
4592         });
4593     }
4594 
4595     /**
4596      * Whether uicc applications are enabled or not.
4597      *
4598      * @param result a Message to return to the requester
4599      */
4600     @Override
areUiccApplicationsEnabled(Message result)4601     public void areUiccApplicationsEnabled(Message result) {
4602         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
4603         if (!canMakeRequest("areUiccApplicationsEnabled", simProxy, result,
4604                 RADIO_HAL_VERSION_1_5)) {
4605             return;
4606         }
4607 
4608         RILRequest rr = obtainRequest(RIL_REQUEST_GET_UICC_APPLICATIONS_ENABLEMENT, result,
4609                 mRILDefaultWorkSource);
4610 
4611         if (RILJ_LOGD) {
4612             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4613         }
4614 
4615         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "areUiccApplicationsEnabled", () -> {
4616             simProxy.areUiccApplicationsEnabled(rr.mSerial);
4617         });
4618     }
4619 
4620     /**
4621      * Whether {@link #enableUiccApplications} is supported, which is supported in 1.5 version.
4622      */
4623     @Override
canToggleUiccApplicationsEnablement()4624     public boolean canToggleUiccApplicationsEnablement() {
4625         return canMakeRequest("canToggleUiccApplicationsEnablement",
4626                 getRadioServiceProxy(RadioSimProxy.class), null, RADIO_HAL_VERSION_1_5);
4627     }
4628 
4629     /**
4630      * {@inheritDoc}
4631      */
4632     @Override
handleCallSetupRequestFromSim(boolean accept, Message result)4633     public void handleCallSetupRequestFromSim(boolean accept, Message result) {
4634         RadioVoiceProxy voiceProxy = getRadioServiceProxy(RadioVoiceProxy.class);
4635         if (!canMakeRequest("handleCallSetupRequestFromSim", voiceProxy, result,
4636                 RADIO_HAL_VERSION_1_4)) {
4637             return;
4638         }
4639 
4640         RILRequest rr = obtainRequest(RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM,
4641                 result, mRILDefaultWorkSource);
4642 
4643         if (RILJ_LOGD) {
4644             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4645         }
4646 
4647         radioServiceInvokeHelper(HAL_SERVICE_VOICE, rr, "handleCallSetupRequestFromSim", () -> {
4648             voiceProxy.handleStkCallSetupRequestFromSim(rr.mSerial, accept);
4649         });
4650     }
4651 
4652     /**
4653      * {@inheritDoc}
4654      */
4655     @Override
getBarringInfo(Message result)4656     public void getBarringInfo(Message result) {
4657         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
4658         if (!canMakeRequest("getBarringInfo", networkProxy, result, RADIO_HAL_VERSION_1_5)) {
4659             return;
4660         }
4661 
4662         RILRequest rr = obtainRequest(RIL_REQUEST_GET_BARRING_INFO, result, mRILDefaultWorkSource);
4663 
4664         if (RILJ_LOGD) {
4665             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4666         }
4667 
4668         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "getBarringInfo", () -> {
4669             networkProxy.getBarringInfo(rr.mSerial);
4670         });
4671     }
4672 
4673     /**
4674      * {@inheritDoc}
4675      */
4676     @Override
allocatePduSessionId(Message result)4677     public void allocatePduSessionId(Message result) {
4678         RadioDataProxy dataProxy = getRadioServiceProxy(RadioDataProxy.class);
4679         if (!canMakeRequest("allocatePduSessionId", dataProxy, result, RADIO_HAL_VERSION_1_6)) {
4680             return;
4681         }
4682 
4683         RILRequest rr = obtainRequest(RIL_REQUEST_ALLOCATE_PDU_SESSION_ID, result,
4684                 mRILDefaultWorkSource);
4685         if (RILJ_LOGD) {
4686             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4687         }
4688 
4689         radioServiceInvokeHelper(HAL_SERVICE_DATA, rr, "allocatePduSessionId", () -> {
4690             dataProxy.allocatePduSessionId(rr.mSerial);
4691         });
4692     }
4693 
4694     /**
4695      * {@inheritDoc}
4696      */
4697     @Override
releasePduSessionId(Message result, int pduSessionId)4698     public void releasePduSessionId(Message result, int pduSessionId) {
4699         RadioDataProxy dataProxy = getRadioServiceProxy(RadioDataProxy.class);
4700         if (!canMakeRequest("releasePduSessionId", dataProxy, result, RADIO_HAL_VERSION_1_6)) {
4701             return;
4702         }
4703 
4704         RILRequest rr = obtainRequest(RIL_REQUEST_RELEASE_PDU_SESSION_ID, result,
4705                 mRILDefaultWorkSource);
4706         if (RILJ_LOGD) {
4707             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4708         }
4709 
4710         radioServiceInvokeHelper(HAL_SERVICE_DATA, rr, "releasePduSessionId", () -> {
4711             dataProxy.releasePduSessionId(rr.mSerial, pduSessionId);
4712         });
4713     }
4714 
4715     /**
4716      * {@inheritDoc}
4717      */
4718     @Override
startHandover(Message result, int callId)4719     public void startHandover(Message result, int callId) {
4720         RadioDataProxy dataProxy = getRadioServiceProxy(RadioDataProxy.class);
4721         if (!canMakeRequest("startHandover", dataProxy, result, RADIO_HAL_VERSION_1_6)) {
4722             return;
4723         }
4724 
4725         RILRequest rr = obtainRequest(RIL_REQUEST_START_HANDOVER, result, mRILDefaultWorkSource);
4726         if (RILJ_LOGD) {
4727             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4728         }
4729 
4730         radioServiceInvokeHelper(HAL_SERVICE_DATA, rr, "startHandover", () -> {
4731             dataProxy.startHandover(rr.mSerial, callId);
4732         });
4733     }
4734 
4735     /**
4736      * {@inheritDoc}
4737      */
4738     @Override
cancelHandover(Message result, int callId)4739     public void cancelHandover(Message result, int callId) {
4740         RadioDataProxy dataProxy = getRadioServiceProxy(RadioDataProxy.class);
4741         if (!canMakeRequest("cancelHandover", dataProxy, result, RADIO_HAL_VERSION_1_6)) {
4742             return;
4743         }
4744 
4745         RILRequest rr = obtainRequest(RIL_REQUEST_CANCEL_HANDOVER, result, mRILDefaultWorkSource);
4746         if (RILJ_LOGD) {
4747             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4748         }
4749 
4750         radioServiceInvokeHelper(HAL_SERVICE_DATA, rr, "cancelHandover", () -> {
4751             dataProxy.cancelHandover(rr.mSerial, callId);
4752         });
4753     }
4754 
4755     /**
4756      * {@inheritDoc}
4757      */
4758     @Override
getSlicingConfig(Message result)4759     public void getSlicingConfig(Message result) {
4760         RadioDataProxy dataProxy = getRadioServiceProxy(RadioDataProxy.class);
4761         if (!canMakeRequest("getSlicingConfig", dataProxy, result, RADIO_HAL_VERSION_1_6)) {
4762             return;
4763         }
4764 
4765         RILRequest rr = obtainRequest(RIL_REQUEST_GET_SLICING_CONFIG, result,
4766                 mRILDefaultWorkSource);
4767 
4768         if (RILJ_LOGD) {
4769             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4770         }
4771 
4772         radioServiceInvokeHelper(HAL_SERVICE_DATA, rr, "getSlicingConfig", () -> {
4773             dataProxy.getSlicingConfig(rr.mSerial);
4774         });
4775     }
4776 
4777     @Override
getSimPhonebookRecords(Message result)4778     public void getSimPhonebookRecords(Message result) {
4779         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
4780         if (!canMakeRequest("getSimPhonebookRecords", simProxy, result, RADIO_HAL_VERSION_1_6)) {
4781             return;
4782         }
4783 
4784         RILRequest rr = obtainRequest(RIL_REQUEST_GET_SIM_PHONEBOOK_RECORDS, result,
4785                 mRILDefaultWorkSource);
4786 
4787         if (RILJ_LOGD) {
4788             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4789         }
4790 
4791         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "getSimPhonebookRecords", () -> {
4792             simProxy.getSimPhonebookRecords(rr.mSerial);
4793         });
4794     }
4795 
4796     @Override
getSimPhonebookCapacity(Message result)4797     public void getSimPhonebookCapacity(Message result) {
4798         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
4799         if (!canMakeRequest("getSimPhonebookCapacity", simProxy, result, RADIO_HAL_VERSION_1_6)) {
4800             return;
4801         }
4802 
4803         RILRequest rr = obtainRequest(RIL_REQUEST_GET_SIM_PHONEBOOK_CAPACITY, result,
4804                 mRILDefaultWorkSource);
4805 
4806         if (RILJ_LOGD) {
4807             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4808         }
4809 
4810         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "getSimPhonebookCapacity", () -> {
4811             simProxy.getSimPhonebookCapacity(rr.mSerial);
4812         });
4813     }
4814 
4815     @Override
updateSimPhonebookRecord(SimPhonebookRecord phonebookRecord, Message result)4816     public void updateSimPhonebookRecord(SimPhonebookRecord phonebookRecord, Message result) {
4817         RadioSimProxy simProxy = getRadioServiceProxy(RadioSimProxy.class);
4818         if (!canMakeRequest("updateSimPhonebookRecord", simProxy, result, RADIO_HAL_VERSION_1_6)) {
4819             return;
4820         }
4821 
4822         RILRequest rr = obtainRequest(RIL_REQUEST_UPDATE_SIM_PHONEBOOK_RECORD, result,
4823                 mRILDefaultWorkSource);
4824 
4825         if (RILJ_LOGD) {
4826             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4827                     + " with " + phonebookRecord.toString());
4828         }
4829 
4830         radioServiceInvokeHelper(HAL_SERVICE_SIM, rr, "updateSimPhonebookRecord", () -> {
4831             simProxy.updateSimPhonebookRecords(rr.mSerial, phonebookRecord);
4832         });
4833     }
4834 
4835     /**
4836      * Set the UE's usage setting.
4837      *
4838      * @param result Callback message containing the success or failure status.
4839      * @param usageSetting the UE's usage setting, either VOICE_CENTRIC or DATA_CENTRIC.
4840      */
4841     @Override
setUsageSetting(Message result, int usageSetting)4842     public void setUsageSetting(Message result,
4843             /* @TelephonyManager.UsageSetting */ int usageSetting) {
4844         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
4845         if (!canMakeRequest("setUsageSetting", networkProxy, result, RADIO_HAL_VERSION_2_0)) {
4846             return;
4847         }
4848 
4849         RILRequest rr = obtainRequest(RIL_REQUEST_SET_USAGE_SETTING, result, mRILDefaultWorkSource);
4850 
4851         if (RILJ_LOGD) {
4852             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4853         }
4854 
4855         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "setUsageSetting", () -> {
4856             networkProxy.setUsageSetting(rr.mSerial, usageSetting);
4857         });
4858     }
4859 
4860     /**
4861      * Get the UE's usage setting.
4862      *
4863      * @param result Callback message containing the usage setting (or a failure status).
4864      */
4865     @Override
getUsageSetting(Message result)4866     public void getUsageSetting(Message result) {
4867         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
4868         if (!canMakeRequest("getUsageSetting", networkProxy, result, RADIO_HAL_VERSION_2_0)) {
4869             return;
4870         }
4871 
4872         RILRequest rr = obtainRequest(RIL_REQUEST_GET_USAGE_SETTING, result, mRILDefaultWorkSource);
4873 
4874         if (RILJ_LOGD) {
4875             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4876         }
4877 
4878         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "getUsageSetting", () -> {
4879             networkProxy.getUsageSetting(rr.mSerial);
4880         });
4881     }
4882 
4883     @Override
setSrvccCallInfo(SrvccConnection[] srvccConnections, Message result)4884     public void setSrvccCallInfo(SrvccConnection[] srvccConnections, Message result) {
4885         RadioImsProxy imsProxy = getRadioServiceProxy(RadioImsProxy.class);
4886         if (!canMakeRequest("setSrvccCallInfo", imsProxy, result, RADIO_HAL_VERSION_2_0)) {
4887             return;
4888         }
4889 
4890         RILRequest rr = obtainRequest(RIL_REQUEST_SET_SRVCC_CALL_INFO, result,
4891                 mRILDefaultWorkSource);
4892 
4893         if (RILJ_LOGD) {
4894             // Do not log function arg for privacy
4895             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
4896         }
4897 
4898         radioServiceInvokeHelper(HAL_SERVICE_IMS, rr, "setSrvccCallInfo", () -> {
4899             imsProxy.setSrvccCallInfo(rr.mSerial, RILUtils.convertToHalSrvccCall(srvccConnections));
4900         });
4901     }
4902 
4903     @Override
updateImsRegistrationInfo( @egistrationManager.ImsRegistrationState int state, @ImsRegistrationImplBase.ImsRegistrationTech int imsRadioTech, @RegistrationManager.SuggestedAction int suggestedAction, int capabilities, Message result)4904     public void updateImsRegistrationInfo(
4905             @RegistrationManager.ImsRegistrationState int state,
4906             @ImsRegistrationImplBase.ImsRegistrationTech int imsRadioTech,
4907             @RegistrationManager.SuggestedAction int suggestedAction,
4908             int capabilities, Message result) {
4909         RadioImsProxy imsProxy = getRadioServiceProxy(RadioImsProxy.class);
4910         if (!canMakeRequest("updateImsRegistrationInfo", imsProxy, result, RADIO_HAL_VERSION_2_0)) {
4911             return;
4912         }
4913 
4914         RILRequest rr = obtainRequest(RIL_REQUEST_UPDATE_IMS_REGISTRATION_INFO, result,
4915                 mRILDefaultWorkSource);
4916 
4917         if (RILJ_LOGD) {
4918             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4919                     + " state=" + state + ", radioTech=" + imsRadioTech
4920                     + ", suggested=" + suggestedAction + ", cap=" + capabilities);
4921         }
4922 
4923         android.hardware.radio.ims.ImsRegistration registrationInfo =
4924                 new android.hardware.radio.ims.ImsRegistration();
4925         registrationInfo.regState = RILUtils.convertImsRegistrationState(state);
4926         registrationInfo.accessNetworkType = RILUtils.convertImsRegistrationTech(imsRadioTech);
4927         registrationInfo.suggestedAction = suggestedAction;
4928         registrationInfo.capabilities = RILUtils.convertImsCapability(capabilities);
4929 
4930         radioServiceInvokeHelper(HAL_SERVICE_IMS, rr, "updateImsRegistrationInfo", () -> {
4931             imsProxy.updateImsRegistrationInfo(rr.mSerial, registrationInfo);
4932         });
4933     }
4934 
4935     @Override
startImsTraffic(int token, int trafficType, int accessNetworkType, int trafficDirection, Message result)4936     public void startImsTraffic(int token, int trafficType, int accessNetworkType,
4937             int trafficDirection, Message result) {
4938         RadioImsProxy imsProxy = getRadioServiceProxy(RadioImsProxy.class);
4939         if (!canMakeRequest("startImsTraffic", imsProxy, result, RADIO_HAL_VERSION_2_0)) {
4940             return;
4941         }
4942 
4943         RILRequest rr = obtainRequest(RIL_REQUEST_START_IMS_TRAFFIC, result, mRILDefaultWorkSource);
4944 
4945         if (RILJ_LOGD) {
4946             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4947                     + "{" + token + ", " + trafficType + ", "
4948                     + accessNetworkType + ", " + trafficDirection + "}");
4949         }
4950 
4951         radioServiceInvokeHelper(HAL_SERVICE_IMS, rr, "startImsTraffic", () -> {
4952             imsProxy.startImsTraffic(rr.mSerial, token, RILUtils.convertImsTrafficType(trafficType),
4953                     accessNetworkType, RILUtils.convertImsTrafficDirection(trafficDirection));
4954         });
4955     }
4956 
4957     @Override
stopImsTraffic(int token, Message result)4958     public void stopImsTraffic(int token, Message result) {
4959         RadioImsProxy imsProxy = getRadioServiceProxy(RadioImsProxy.class);
4960         if (!canMakeRequest("stopImsTraffic", imsProxy, result, RADIO_HAL_VERSION_2_0)) {
4961             return;
4962         }
4963 
4964         RILRequest rr = obtainRequest(RIL_REQUEST_STOP_IMS_TRAFFIC, result, mRILDefaultWorkSource);
4965 
4966         if (RILJ_LOGD) {
4967             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4968                     + "{" + token + "}");
4969         }
4970 
4971         radioServiceInvokeHelper(HAL_SERVICE_IMS, rr, "stopImsTraffic", () -> {
4972             imsProxy.stopImsTraffic(rr.mSerial, token);
4973         });
4974     }
4975 
4976     @Override
triggerEpsFallback(int reason, Message result)4977     public void triggerEpsFallback(int reason, Message result) {
4978         RadioImsProxy imsProxy = getRadioServiceProxy(RadioImsProxy.class);
4979         if (!canMakeRequest("triggerEpsFallback", imsProxy, result, RADIO_HAL_VERSION_2_0)) {
4980             return;
4981         }
4982 
4983         RILRequest rr = obtainRequest(RIL_REQUEST_TRIGGER_EPS_FALLBACK, result,
4984                 mRILDefaultWorkSource);
4985 
4986         if (RILJ_LOGD) {
4987             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
4988                     + " reason=" + reason);
4989         }
4990 
4991         radioServiceInvokeHelper(HAL_SERVICE_IMS, rr, "triggerEpsFallback", () -> {
4992             imsProxy.triggerEpsFallback(rr.mSerial, reason);
4993         });
4994     }
4995 
4996     @Override
sendAnbrQuery(int mediaType, int direction, int bitsPerSecond, Message result)4997     public void sendAnbrQuery(int mediaType, int direction, int bitsPerSecond, Message result) {
4998         RadioImsProxy imsProxy = getRadioServiceProxy(RadioImsProxy.class);
4999         if (!canMakeRequest("sendAnbrQuery", imsProxy, result, RADIO_HAL_VERSION_2_0)) {
5000             return;
5001         }
5002 
5003         RILRequest rr = obtainRequest(RIL_REQUEST_SEND_ANBR_QUERY, result, mRILDefaultWorkSource);
5004 
5005         if (RILJ_LOGD) {
5006             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
5007         }
5008 
5009         radioServiceInvokeHelper(HAL_SERVICE_IMS, rr, "sendAnbrQuery", () -> {
5010             imsProxy.sendAnbrQuery(rr.mSerial, mediaType, direction, bitsPerSecond);
5011         });
5012     }
5013 
5014     /**
5015      * {@inheritDoc}
5016      */
5017     @Override
setEmergencyMode(int emcMode, Message result)5018     public void setEmergencyMode(int emcMode, Message result) {
5019         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
5020         if (!canMakeRequest("setEmergencyMode", networkProxy, result, RADIO_HAL_VERSION_2_1)) {
5021             return;
5022         }
5023 
5024         RILRequest rr = obtainRequest(RIL_REQUEST_SET_EMERGENCY_MODE, result,
5025                 mRILDefaultWorkSource);
5026 
5027         if (RILJ_LOGD) {
5028             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
5029                     + " mode=" + EmergencyConstants.emergencyModeToString(emcMode));
5030         }
5031 
5032         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "setEmergencyMode", () -> {
5033             networkProxy.setEmergencyMode(rr.mSerial, emcMode);
5034         });
5035     }
5036 
5037     /**
5038      * {@inheritDoc}
5039      */
5040     @Override
triggerEmergencyNetworkScan( @onNull @ccessNetworkConstants.RadioAccessNetworkType int[] accessNetwork, @DomainSelectionService.EmergencyScanType int scanType, Message result)5041     public void triggerEmergencyNetworkScan(
5042             @NonNull @AccessNetworkConstants.RadioAccessNetworkType int[] accessNetwork,
5043             @DomainSelectionService.EmergencyScanType int scanType, Message result) {
5044         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
5045         if (!canMakeRequest("triggerEmergencyNetworkScan", networkProxy, result,
5046                 RADIO_HAL_VERSION_2_1)) {
5047             return;
5048         }
5049 
5050         RILRequest rr = obtainRequest(RIL_REQUEST_TRIGGER_EMERGENCY_NETWORK_SCAN, result,
5051                 mRILDefaultWorkSource);
5052 
5053         if (RILJ_LOGD) {
5054             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
5055                     + " networkType=" + RILUtils.accessNetworkTypesToString(accessNetwork)
5056                     + ", scanType=" + RILUtils.scanTypeToString(scanType));
5057         }
5058 
5059         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "triggerEmergencyNetworkScan", () -> {
5060             networkProxy.triggerEmergencyNetworkScan(rr.mSerial,
5061                     RILUtils.convertEmergencyNetworkScanTrigger(accessNetwork, scanType));
5062         });
5063     }
5064 
5065     /**
5066      * {@inheritDoc}
5067      */
5068     @Override
cancelEmergencyNetworkScan(boolean resetScan, Message result)5069     public void cancelEmergencyNetworkScan(boolean resetScan, Message result) {
5070         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
5071         if (!canMakeRequest("cancelEmergencyNetworkScan", networkProxy, result,
5072                 RADIO_HAL_VERSION_2_1)) {
5073             return;
5074         }
5075 
5076         RILRequest rr = obtainRequest(RIL_REQUEST_CANCEL_EMERGENCY_NETWORK_SCAN, result,
5077                 mRILDefaultWorkSource);
5078 
5079         if (RILJ_LOGD) {
5080             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
5081                     + " resetScan=" + resetScan);
5082         }
5083 
5084         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "cancelEmergencyNetworkScan", () -> {
5085             networkProxy.cancelEmergencyNetworkScan(rr.mSerial, resetScan);
5086         });
5087     }
5088 
5089     /**
5090      * {@inheritDoc}
5091      */
5092     @Override
exitEmergencyMode(Message result)5093     public void exitEmergencyMode(Message result) {
5094         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
5095         if (!canMakeRequest("exitEmergencyMode", networkProxy, result, RADIO_HAL_VERSION_2_1)) {
5096             return;
5097         }
5098 
5099         RILRequest rr = obtainRequest(RIL_REQUEST_EXIT_EMERGENCY_MODE, result,
5100                 mRILDefaultWorkSource);
5101 
5102         if (RILJ_LOGD) {
5103             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
5104         }
5105 
5106         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "exitEmergencyMode", () -> {
5107             networkProxy.exitEmergencyMode(rr.mSerial);
5108         });
5109     }
5110 
5111     /**
5112      * Set if null ciphering / null integrity modes are permitted.
5113      *
5114      * @param result Callback message containing the success or failure status.
5115      * @param enabled true if null ciphering / null integrity modes are permitted, false otherwise
5116      */
5117     @Override
setNullCipherAndIntegrityEnabled(boolean enabled, Message result)5118     public void setNullCipherAndIntegrityEnabled(boolean enabled, Message result) {
5119         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
5120         if (!canMakeRequest("setNullCipherAndIntegrityEnabled", networkProxy, result,
5121                 RADIO_HAL_VERSION_2_1)) {
5122             return;
5123         }
5124 
5125         RILRequest rr = obtainRequest(RIL_REQUEST_SET_NULL_CIPHER_AND_INTEGRITY_ENABLED, result,
5126                 mRILDefaultWorkSource);
5127 
5128         if (RILJ_LOGD) {
5129             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
5130         }
5131 
5132         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "setNullCipherAndIntegrityEnabled",
5133                 () -> {
5134                     networkProxy.setNullCipherAndIntegrityEnabled(rr.mSerial, enabled);
5135                 });
5136     }
5137 
5138     /**
5139      * Get if null ciphering / null integrity are enabled / disabled.
5140      *
5141      * @param result Callback message containing the success or failure status.
5142      */
5143     @Override
isNullCipherAndIntegrityEnabled(Message result)5144     public void isNullCipherAndIntegrityEnabled(Message result) {
5145         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
5146         if (!canMakeRequest("isNullCipherAndIntegrityEnabled", networkProxy, result,
5147                 RADIO_HAL_VERSION_2_1)) {
5148             return;
5149         }
5150 
5151         RILRequest rr = obtainRequest(RIL_REQUEST_IS_NULL_CIPHER_AND_INTEGRITY_ENABLED, result,
5152                 mRILDefaultWorkSource);
5153 
5154         if (RILJ_LOGD) {
5155             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
5156         }
5157 
5158         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "isNullCipherAndIntegrityEnabled", () -> {
5159             networkProxy.isNullCipherAndIntegrityEnabled(rr.mSerial);
5160         });
5161     }
5162 
5163     /**
5164      * {@inheritDoc}
5165      */
5166     @Override
updateImsCallStatus(@onNull List<ImsCallInfo> imsCallInfo, Message result)5167     public void updateImsCallStatus(@NonNull List<ImsCallInfo> imsCallInfo, Message result) {
5168         RadioImsProxy imsProxy = getRadioServiceProxy(RadioImsProxy.class);
5169         if (!canMakeRequest("updateImsCallStatus", imsProxy, result, RADIO_HAL_VERSION_2_0)) {
5170             return;
5171         }
5172 
5173         RILRequest rr = obtainRequest(RIL_REQUEST_UPDATE_IMS_CALL_STATUS, result,
5174                 mRILDefaultWorkSource);
5175 
5176         if (RILJ_LOGD) {
5177             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
5178                     + " " + imsCallInfo);
5179         }
5180         radioServiceInvokeHelper(HAL_SERVICE_IMS, rr, "updateImsCallStatus", () -> {
5181             imsProxy.updateImsCallStatus(rr.mSerial, RILUtils.convertImsCallInfo(imsCallInfo));
5182         });
5183     }
5184 
5185     /**
5186      * {@inheritDoc}
5187      */
5188     @Override
setN1ModeEnabled(boolean enable, Message result)5189     public void setN1ModeEnabled(boolean enable, Message result) {
5190         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
5191         if (!canMakeRequest("setN1ModeEnabled", networkProxy, result, RADIO_HAL_VERSION_2_1)) {
5192             return;
5193         }
5194 
5195         RILRequest rr = obtainRequest(RIL_REQUEST_SET_N1_MODE_ENABLED, result,
5196                 mRILDefaultWorkSource);
5197 
5198         if (RILJ_LOGD) {
5199             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
5200                     + " enable=" + enable);
5201         }
5202 
5203         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "setN1ModeEnabled", () -> {
5204             networkProxy.setN1ModeEnabled(rr.mSerial, enable);
5205         });
5206     }
5207 
5208     /**
5209      * {@inheritDoc}
5210      */
5211     @Override
isN1ModeEnabled(Message result)5212     public void isN1ModeEnabled(Message result) {
5213         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
5214         if (!canMakeRequest("isN1ModeEnabled", networkProxy, result, RADIO_HAL_VERSION_2_1)) {
5215             return;
5216         }
5217 
5218         RILRequest rr = obtainRequest(RIL_REQUEST_IS_N1_MODE_ENABLED, result,
5219                 mRILDefaultWorkSource);
5220 
5221         if (RILJ_LOGD) {
5222             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
5223         }
5224 
5225         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "isN1ModeEnabled", () -> {
5226             networkProxy.isN1ModeEnabled(rr.mSerial);
5227         });
5228     }
5229 
5230     /**
5231      * {@inheritDoc}
5232      */
5233     @Override
setCellularIdentifierTransparencyEnabled(boolean enable, Message result)5234     public void setCellularIdentifierTransparencyEnabled(boolean enable, Message result) {
5235         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
5236         if (!canMakeRequest(
5237                 "setCellularIdentifierTransparencyEnabled",
5238                 networkProxy,
5239                 result,
5240                 RADIO_HAL_VERSION_2_2)) {
5241             return;
5242         }
5243 
5244         RILRequest rr = obtainRequest(RIL_REQUEST_SET_CELLULAR_IDENTIFIER_DISCLOSED_ENABLED, result,
5245                 mRILDefaultWorkSource);
5246 
5247         if (RILJ_LOGD) {
5248             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
5249                     + " enable=" + enable);
5250         }
5251 
5252         radioServiceInvokeHelper(
5253                 HAL_SERVICE_NETWORK,
5254                 rr,
5255                 "setCellularIdentifierTransparencyEnabled",
5256                 () -> {
5257                     networkProxy.setCellularIdentifierTransparencyEnabled(rr.mSerial, enable);
5258                 });
5259     }
5260 
5261     /**
5262      * {@inheritDoc}
5263      */
5264     @Override
isCellularIdentifierTransparencyEnabled(Message result)5265     public void isCellularIdentifierTransparencyEnabled(Message result) {
5266         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
5267         if (!canMakeRequest(
5268                 "isCellularIdentifierTransparencyEnabled",
5269                 networkProxy,
5270                 result,
5271                 RADIO_HAL_VERSION_2_2)) {
5272             return;
5273         }
5274 
5275         RILRequest rr = obtainRequest(RIL_REQUEST_IS_CELLULAR_IDENTIFIER_DISCLOSED_ENABLED, result,
5276                 mRILDefaultWorkSource);
5277 
5278         if (RILJ_LOGD) {
5279             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
5280         }
5281 
5282         radioServiceInvokeHelper(
5283                 HAL_SERVICE_NETWORK,
5284                 rr,
5285                 "isCellularIdentifierTransparencyEnabled",
5286                 () -> {
5287                     networkProxy.isCellularIdentifierTransparencyEnabled(rr.mSerial);
5288                 });
5289     }
5290 
5291    /**
5292      * {@inheritDoc}
5293      */
5294     @Override
setSecurityAlgorithmsUpdatedEnabled(boolean enable, Message result)5295     public void setSecurityAlgorithmsUpdatedEnabled(boolean enable, Message result) {
5296         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
5297         if (!canMakeRequest(
5298                 "setSecurityAlgorithmsUpdatedEnabled",
5299                 networkProxy,
5300                 result,
5301                 RADIO_HAL_VERSION_2_2)) {
5302             return;
5303         }
5304 
5305         RILRequest rr = obtainRequest(RIL_REQUEST_SET_SECURITY_ALGORITHMS_UPDATED_ENABLED, result,
5306                 mRILDefaultWorkSource);
5307 
5308         if (RILJ_LOGD) {
5309             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest)
5310                     + " enable=" + enable);
5311         }
5312 
5313         radioServiceInvokeHelper(HAL_SERVICE_NETWORK, rr, "setSecurityAlgorithmsUpdatedEnabled",
5314                 () -> {
5315                     networkProxy.setSecurityAlgorithmsUpdatedEnabled(rr.mSerial, enable);
5316             });
5317     }
5318 
5319     /**
5320      * {@inheritDoc}
5321      */
5322     @Override
isSecurityAlgorithmsUpdatedEnabled(Message result)5323     public void isSecurityAlgorithmsUpdatedEnabled(Message result) {
5324         RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class);
5325         if (!canMakeRequest(
5326                 "isSecurityAlgorithmsUpdatedEnabled",
5327                 networkProxy,
5328                 result,
5329                 RADIO_HAL_VERSION_2_2)) {
5330             return;
5331         }
5332 
5333         RILRequest rr = obtainRequest(RIL_REQUEST_IS_SECURITY_ALGORITHMS_UPDATED_ENABLED, result,
5334                 mRILDefaultWorkSource);
5335 
5336         if (RILJ_LOGD) {
5337             riljLog(rr.serialString() + "> " + RILUtils.requestToString(rr.mRequest));
5338         }
5339 
5340         radioServiceInvokeHelper(
5341                 HAL_SERVICE_NETWORK, rr, "isSecurityAlgorithmsUpdatedEnabled", () -> {
5342                 networkProxy.isSecurityAlgorithmsUpdatedEnabled(rr.mSerial);
5343             });
5344     }
5345 
5346     //***** Private Methods
5347     /**
5348      * This is a helper function to be called when an indication callback is called for any radio
5349      * service. It takes care of acquiring wakelock and sending ack if needed.
5350      * @param service radio service the indication is for
5351      * @param indicationType indication type received
5352      */
processIndication(int service, int indicationType)5353     void processIndication(int service, int indicationType) {
5354         if (indicationType == RadioIndicationType.UNSOLICITED_ACK_EXP) {
5355             sendAck(service);
5356             if (RILJ_LOGD) riljLog("Unsol response received; Sending ack to ril.cpp");
5357         } else {
5358             // ack is not expected to be sent back. Nothing is required to be done here.
5359         }
5360     }
5361 
processRequestAck(int serial)5362     void processRequestAck(int serial) {
5363         RILRequest rr;
5364         synchronized (mRequestList) {
5365             rr = mRequestList.get(serial);
5366         }
5367         if (rr == null) {
5368             riljLogw("processRequestAck: Unexpected solicited ack response! serial: " + serial);
5369         } else {
5370             decrementWakeLock(rr);
5371             if (RILJ_LOGD) {
5372                 riljLog(rr.serialString() + " Ack < " + RILUtils.requestToString(rr.mRequest));
5373             }
5374         }
5375     }
5376 
5377     /**
5378      * This is a helper function to be called when a RadioResponse callback is called.
5379      * It takes care of acks, wakelocks, and finds and returns RILRequest corresponding to the
5380      * response if one is found.
5381      * @param responseInfo RadioResponseInfo received in response callback
5382      * @return RILRequest corresponding to the response
5383      */
5384     @VisibleForTesting
processResponse(RadioResponseInfo responseInfo)5385     public RILRequest processResponse(RadioResponseInfo responseInfo) {
5386         return processResponseInternal(HAL_SERVICE_RADIO, responseInfo.serial, responseInfo.error,
5387                 responseInfo.type);
5388     }
5389 
5390     /**
5391      * This is a helper function for V1_6.RadioResponseInfo to be called when a RadioResponse
5392      * callback is called. It takes care of acks, wakelocks, and finds and returns RILRequest
5393      * corresponding to the response if one is found.
5394      * @param responseInfo RadioResponseInfo received in response callback
5395      * @return RILRequest corresponding to the response
5396      */
5397     @VisibleForTesting
processResponse_1_6( android.hardware.radio.V1_6.RadioResponseInfo responseInfo)5398     public RILRequest processResponse_1_6(
5399             android.hardware.radio.V1_6.RadioResponseInfo responseInfo) {
5400         return processResponseInternal(HAL_SERVICE_RADIO, responseInfo.serial, responseInfo.error,
5401                 responseInfo.type);
5402     }
5403 
5404     /**
5405      * This is a helper function for an AIDL RadioResponseInfo to be called when a RadioResponse
5406      * callback is called. It takes care of acks, wakelocks, and finds and returns RILRequest
5407      * corresponding to the response if one is found.
5408      * @param service Radio service that received the response
5409      * @param responseInfo RadioResponseInfo received in response callback
5410      * @return RILRequest corresponding to the response
5411      */
processResponse(int service, android.hardware.radio.RadioResponseInfo responseInfo)5412     public RILRequest processResponse(int service,
5413             android.hardware.radio.RadioResponseInfo responseInfo) {
5414         return processResponseInternal(service, responseInfo.serial, responseInfo.error,
5415                 responseInfo.type);
5416     }
5417 
processResponseInternal(int service, int serial, int error, int type)5418     private RILRequest processResponseInternal(int service, int serial, int error, int type) {
5419         RILRequest rr;
5420 
5421         if (type == RadioResponseType.SOLICITED_ACK) {
5422             synchronized (mRequestList) {
5423                 rr = mRequestList.get(serial);
5424             }
5425             if (rr == null) {
5426                 riljLogw("Unexpected solicited ack response! sn: " + serial);
5427             } else {
5428                 decrementWakeLock(rr);
5429                 if (mRadioBugDetector != null) {
5430                     mRadioBugDetector.detectRadioBug(rr.mRequest, error);
5431                 }
5432                 if (RILJ_LOGD) {
5433                     riljLog(rr.serialString() + " Ack from " + serviceToString(service)
5434                             + " < " + RILUtils.requestToString(rr.mRequest));
5435                 }
5436             }
5437             return rr;
5438         }
5439 
5440         rr = findAndRemoveRequestFromList(serial);
5441         if (rr == null) {
5442             riljLoge("processResponse: Unexpected response! serial: " + serial
5443                     + ", error: " + error);
5444             return null;
5445         }
5446         Trace.asyncTraceForTrackEnd(Trace.TRACE_TAG_NETWORK, "RIL", rr.mSerial);
5447 
5448         // Time logging for RIL command and storing it in TelephonyHistogram.
5449         addToRilHistogram(rr);
5450         if (mRadioBugDetector != null) {
5451             mRadioBugDetector.detectRadioBug(rr.mRequest, error);
5452         }
5453         if (type == RadioResponseType.SOLICITED_ACK_EXP) {
5454             sendAck(service);
5455             if (RILJ_LOGD) {
5456                 riljLog("Response received from " + serviceToString(service) + " for "
5457                         + rr.serialString() + " " + RILUtils.requestToString(rr.mRequest)
5458                         + " Sending ack to ril.cpp");
5459             }
5460         } else {
5461             // ack sent for SOLICITED_ACK_EXP above; nothing to do for SOLICITED response
5462         }
5463 
5464         // Here and below fake RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, see b/7255789.
5465         // This is needed otherwise we don't automatically transition to the main lock
5466         // screen when the pin or puk is entered incorrectly.
5467         switch (rr.mRequest) {
5468             case RIL_REQUEST_ENTER_SIM_PUK:
5469             case RIL_REQUEST_ENTER_SIM_PUK2:
5470                 if (mIccStatusChangedRegistrants != null) {
5471                     if (RILJ_LOGD) {
5472                         riljLog("ON enter sim puk fakeSimStatusChanged: reg count="
5473                                 + mIccStatusChangedRegistrants.size());
5474                     }
5475                     mIccStatusChangedRegistrants.notifyRegistrants();
5476                 }
5477                 break;
5478             case RIL_REQUEST_SHUTDOWN:
5479                 setRadioState(TelephonyManager.RADIO_POWER_UNAVAILABLE,
5480                         false /* forceNotifyRegistrants */);
5481                 break;
5482         }
5483 
5484         if (error != RadioError.NONE) {
5485             switch (rr.mRequest) {
5486                 case RIL_REQUEST_ENTER_SIM_PIN:
5487                 case RIL_REQUEST_ENTER_SIM_PIN2:
5488                 case RIL_REQUEST_CHANGE_SIM_PIN:
5489                 case RIL_REQUEST_CHANGE_SIM_PIN2:
5490                 case RIL_REQUEST_SET_FACILITY_LOCK:
5491                     if (mIccStatusChangedRegistrants != null) {
5492                         if (RILJ_LOGD) {
5493                             riljLog("ON some errors fakeSimStatusChanged: reg count="
5494                                     + mIccStatusChangedRegistrants.size());
5495                         }
5496                         mIccStatusChangedRegistrants.notifyRegistrants();
5497                     }
5498                     break;
5499 
5500             }
5501         } else {
5502             switch (rr.mRequest) {
5503                 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND:
5504                     if (mTestingEmergencyCall.getAndSet(false)) {
5505                         if (mEmergencyCallbackModeRegistrant != null) {
5506                             riljLog("testing emergency call, notify ECM Registrants");
5507                             mEmergencyCallbackModeRegistrant.notifyRegistrant();
5508                         }
5509                     }
5510             }
5511         }
5512         return rr;
5513     }
5514 
5515     /**
5516      * This is a helper function to be called at the end of all RadioResponse callbacks.
5517      * It takes care of sending error response, logging, decrementing wakelock if needed, and
5518      * releases the request from memory pool.
5519      * @param rr RILRequest for which response callback was called
5520      * @param responseInfo RadioResponseInfo received in the callback
5521      * @param ret object to be returned to request sender
5522      */
5523     @VisibleForTesting(visibility = VisibleForTesting.Visibility.PROTECTED)
processResponseDone(RILRequest rr, RadioResponseInfo responseInfo, Object ret)5524     public void processResponseDone(RILRequest rr, RadioResponseInfo responseInfo, Object ret) {
5525         processResponseDoneInternal(rr, responseInfo.error, responseInfo.type, ret);
5526     }
5527 
5528     /**
5529      * This is a helper function to be called at the end of the RadioResponse callbacks using for
5530      * V1_6.RadioResponseInfo.
5531      * It takes care of sending error response, logging, decrementing wakelock if needed, and
5532      * releases the request from memory pool.
5533      * @param rr RILRequest for which response callback was called
5534      * @param responseInfo RadioResponseInfo received in the callback
5535      * @param ret object to be returned to request sender
5536      */
5537     @VisibleForTesting
processResponseDone_1_6(RILRequest rr, android.hardware.radio.V1_6.RadioResponseInfo responseInfo, Object ret)5538     public void processResponseDone_1_6(RILRequest rr,
5539             android.hardware.radio.V1_6.RadioResponseInfo responseInfo, Object ret) {
5540         processResponseDoneInternal(rr, responseInfo.error, responseInfo.type, ret);
5541     }
5542 
5543     /**
5544      * This is a helper function to be called at the end of the RadioResponse callbacks using for
5545      * RadioResponseInfo AIDL.
5546      * It takes care of sending error response, logging, decrementing wakelock if needed, and
5547      * releases the request from memory pool.
5548      * @param rr RILRequest for which response callback was called
5549      * @param responseInfo RadioResponseInfo received in the callback
5550      * @param ret object to be returned to request sender
5551      */
5552     @VisibleForTesting
processResponseDone(RILRequest rr, android.hardware.radio.RadioResponseInfo responseInfo, Object ret)5553     public void processResponseDone(RILRequest rr,
5554             android.hardware.radio.RadioResponseInfo responseInfo, Object ret) {
5555         processResponseDoneInternal(rr, responseInfo.error, responseInfo.type, ret);
5556     }
5557 
processResponseDoneInternal(RILRequest rr, int rilError, int responseType, Object ret)5558     private void processResponseDoneInternal(RILRequest rr, int rilError, int responseType,
5559             Object ret) {
5560         if (rilError == 0) {
5561             if (isLogOrTrace()) {
5562                 String logStr = rr.serialString() + "< " + RILUtils.requestToString(rr.mRequest)
5563                         + " " + retToString(rr.mRequest, ret);
5564                 if (RILJ_LOGD) {
5565                     riljLog(logStr);
5566                 }
5567                 Trace.instantForTrack(Trace.TRACE_TAG_NETWORK, "RIL", logStr);
5568             }
5569         } else {
5570             if (isLogOrTrace()) {
5571                 String logStr = rr.serialString() + "< " + RILUtils.requestToString(rr.mRequest)
5572                         + " error " + rilError;
5573                 if (RILJ_LOGD) {
5574                     riljLog(logStr);
5575                 }
5576                 Trace.instantForTrack(Trace.TRACE_TAG_NETWORK, "RIL", logStr);
5577             }
5578             rr.onError(rilError, ret);
5579         }
5580         processResponseCleanUp(rr, rilError, responseType, ret);
5581     }
5582 
5583     /**
5584      * This is a helper function to be called at the end of all RadioResponse callbacks for
5585      * radio HAL fallback cases. It takes care of logging, decrementing wakelock if needed, and
5586      * releases the request from memory pool. Unlike processResponseDone, it will not send
5587      * error response to caller.
5588      * @param rr RILRequest for which response callback was called
5589      * @param responseInfo RadioResponseInfo received in the callback
5590      * @param ret object to be returned to request sender
5591      */
5592     @VisibleForTesting
processResponseFallback(RILRequest rr, RadioResponseInfo responseInfo, Object ret)5593     public void processResponseFallback(RILRequest rr, RadioResponseInfo responseInfo, Object ret) {
5594         if (responseInfo.error == REQUEST_NOT_SUPPORTED && RILJ_LOGD) {
5595             riljLog(rr.serialString() + "< " + RILUtils.requestToString(rr.mRequest)
5596                     + " request not supported, falling back");
5597         }
5598         processResponseCleanUp(rr, responseInfo.error, responseInfo.type, ret);
5599     }
5600 
processResponseCleanUp(RILRequest rr, int rilError, int responseType, Object ret)5601     private void processResponseCleanUp(RILRequest rr, int rilError, int responseType, Object ret) {
5602         if (rr != null) {
5603             mMetrics.writeOnRilSolicitedResponse(mPhoneId, rr.mSerial, rilError, rr.mRequest, ret);
5604             if (responseType == RadioResponseType.SOLICITED) {
5605                 decrementWakeLock(rr);
5606             }
5607             rr.release();
5608         }
5609     }
5610 
5611     /**
5612      * Function to send ack and acquire related wakelock
5613      */
sendAck(int service)5614     private void sendAck(int service) {
5615         // TODO: Remove rr and clean up acquireWakelock for response and ack
5616         RILRequest rr = RILRequest.obtain(RIL_RESPONSE_ACKNOWLEDGEMENT, null,
5617                 mRILDefaultWorkSource);
5618         acquireWakeLock(rr, FOR_ACK_WAKELOCK);
5619         if (service == HAL_SERVICE_RADIO) {
5620             IRadio radioProxy = getRadioProxy();
5621             if (radioProxy != null) {
5622                 try {
5623                     radioProxy.responseAcknowledgement();
5624                 } catch (RemoteException | RuntimeException e) {
5625                     handleRadioProxyExceptionForRR(HAL_SERVICE_RADIO, "sendAck", e);
5626                     riljLoge("sendAck: " + e);
5627                 }
5628             } else {
5629                 riljLoge("Error trying to send ack, radioProxy = null");
5630             }
5631         } else {
5632             RadioServiceProxy serviceProxy = getRadioServiceProxy(service);
5633             if (!serviceProxy.isEmpty()) {
5634                 try {
5635                     serviceProxy.responseAcknowledgement();
5636                 } catch (RemoteException | RuntimeException e) {
5637                     handleRadioProxyExceptionForRR(service, "sendAck", e);
5638                     riljLoge("sendAck: " + e);
5639                 }
5640             } else {
5641                 riljLoge("Error trying to send ack, serviceProxy is empty");
5642             }
5643         }
5644         rr.release();
5645     }
5646 
getDefaultWorkSourceIfInvalid(WorkSource workSource)5647     private WorkSource getDefaultWorkSourceIfInvalid(WorkSource workSource) {
5648         if (workSource == null) {
5649             workSource = mRILDefaultWorkSource;
5650         }
5651 
5652         return workSource;
5653     }
5654 
5655 
5656     /**
5657      * Holds a PARTIAL_WAKE_LOCK whenever
5658      * a) There is outstanding RIL request sent to RIL deamon and no replied
5659      * b) There is a request pending to be sent out.
5660      *
5661      * There is a WAKE_LOCK_TIMEOUT to release the lock, though it shouldn't
5662      * happen often.
5663      */
5664     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
acquireWakeLock(RILRequest rr, int wakeLockType)5665     private void acquireWakeLock(RILRequest rr, int wakeLockType) {
5666         synchronized (rr) {
5667             if (rr.mWakeLockType != INVALID_WAKELOCK) {
5668                 riljLog("Failed to acquire wakelock for " + rr.serialString());
5669                 return;
5670             }
5671 
5672             switch (wakeLockType) {
5673                 case FOR_WAKELOCK:
5674                     synchronized (mWakeLock) {
5675                         mWakeLock.acquire();
5676                         mWakeLockCount++;
5677                         mWlSequenceNum++;
5678 
5679                         String clientId = rr.getWorkSourceClientId();
5680                         if (!mClientWakelockTracker.isClientActive(clientId)) {
5681                             mActiveWakelockWorkSource.add(rr.mWorkSource);
5682                             mWakeLock.setWorkSource(mActiveWakelockWorkSource);
5683                         }
5684 
5685                         mClientWakelockTracker.startTracking(rr.mClientId,
5686                                 rr.mRequest, rr.mSerial, mWakeLockCount);
5687 
5688                         Message msg = mRilHandler.obtainMessage(EVENT_WAKE_LOCK_TIMEOUT);
5689                         msg.arg1 = mWlSequenceNum;
5690                         mRilHandler.sendMessageDelayed(msg, mWakeLockTimeout);
5691                     }
5692                     break;
5693                 case FOR_ACK_WAKELOCK:
5694                     synchronized (mAckWakeLock) {
5695                         mAckWakeLock.acquire();
5696                         mAckWlSequenceNum++;
5697 
5698                         Message msg = mRilHandler.obtainMessage(EVENT_ACK_WAKE_LOCK_TIMEOUT);
5699                         msg.arg1 = mAckWlSequenceNum;
5700                         mRilHandler.sendMessageDelayed(msg, mAckWakeLockTimeout);
5701                     }
5702                     break;
5703                 default: //WTF
5704                     riljLogw("Acquiring Invalid Wakelock type " + wakeLockType);
5705                     return;
5706             }
5707             rr.mWakeLockType = wakeLockType;
5708         }
5709     }
5710 
5711     /** Returns the wake lock of the given type. */
5712     @VisibleForTesting
getWakeLock(int wakeLockType)5713     public WakeLock getWakeLock(int wakeLockType) {
5714         return wakeLockType == FOR_WAKELOCK ? mWakeLock : mAckWakeLock;
5715     }
5716 
5717     /** Returns the {@link RilHandler} instance. */
5718     @VisibleForTesting
getRilHandler()5719     public RilHandler getRilHandler() {
5720         return mRilHandler;
5721     }
5722 
5723     /** Returns the Ril request list. */
5724     @VisibleForTesting
getRilRequestList()5725     public SparseArray<RILRequest> getRilRequestList() {
5726         return mRequestList;
5727     }
5728 
5729     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
decrementWakeLock(RILRequest rr)5730     private void decrementWakeLock(RILRequest rr) {
5731         synchronized (rr) {
5732             switch(rr.mWakeLockType) {
5733                 case FOR_WAKELOCK:
5734                     synchronized (mWakeLock) {
5735                         mClientWakelockTracker.stopTracking(rr.mClientId,
5736                                 rr.mRequest, rr.mSerial,
5737                                 (mWakeLockCount > 1) ? mWakeLockCount - 1 : 0);
5738                         String clientId = rr.getWorkSourceClientId();
5739                         if (!mClientWakelockTracker.isClientActive(clientId)) {
5740                             mActiveWakelockWorkSource.remove(rr.mWorkSource);
5741                             mWakeLock.setWorkSource(mActiveWakelockWorkSource);
5742                         }
5743 
5744                         if (mWakeLockCount > 1) {
5745                             mWakeLockCount--;
5746                         } else {
5747                             mWakeLockCount = 0;
5748                             mWakeLock.release();
5749                         }
5750                     }
5751                     break;
5752                 case FOR_ACK_WAKELOCK:
5753                     //We do not decrement the ACK wakelock
5754                     break;
5755                 case INVALID_WAKELOCK:
5756                     break;
5757                 default:
5758                     riljLogw("Decrementing Invalid Wakelock type " + rr.mWakeLockType);
5759             }
5760             rr.mWakeLockType = INVALID_WAKELOCK;
5761         }
5762     }
5763 
5764     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
clearWakeLock(int wakeLockType)5765     private boolean clearWakeLock(int wakeLockType) {
5766         if (wakeLockType == FOR_WAKELOCK) {
5767             synchronized (mWakeLock) {
5768                 if (mWakeLockCount == 0 && !mWakeLock.isHeld()) return false;
5769                 riljLog("NOTE: mWakeLockCount is " + mWakeLockCount + " at time of clearing");
5770                 mWakeLockCount = 0;
5771                 mWakeLock.release();
5772                 mClientWakelockTracker.stopTrackingAll();
5773                 mActiveWakelockWorkSource = new WorkSource();
5774                 return true;
5775             }
5776         } else {
5777             synchronized (mAckWakeLock) {
5778                 if (!mAckWakeLock.isHeld()) return false;
5779                 mAckWakeLock.release();
5780                 return true;
5781             }
5782         }
5783     }
5784 
5785     /**
5786      * Release each request in mRequestList then clear the list
5787      * @param error is the RIL_Errno sent back
5788      * @param loggable true means to print all requests in mRequestList
5789      */
5790     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
clearRequestList(int error, boolean loggable)5791     private void clearRequestList(int error, boolean loggable) {
5792         RILRequest rr;
5793         synchronized (mRequestList) {
5794             int count = mRequestList.size();
5795             if (RILJ_LOGD && loggable) {
5796                 riljLog("clearRequestList " + " mWakeLockCount=" + mWakeLockCount
5797                         + " mRequestList=" + count);
5798             }
5799 
5800             for (int i = 0; i < count; i++) {
5801                 rr = mRequestList.valueAt(i);
5802                 if (RILJ_LOGD && loggable) {
5803                     riljLog(i + ": [" + rr.mSerial + "] " + RILUtils.requestToString(rr.mRequest));
5804                 }
5805                 rr.onError(error, null);
5806                 decrementWakeLock(rr);
5807                 rr.release();
5808             }
5809             mRequestList.clear();
5810         }
5811     }
5812 
5813     @UnsupportedAppUsage
findAndRemoveRequestFromList(int serial)5814     private RILRequest findAndRemoveRequestFromList(int serial) {
5815         RILRequest rr;
5816         synchronized (mRequestList) {
5817             rr = mRequestList.get(serial);
5818             if (rr != null) {
5819                 mRequestList.remove(serial);
5820             }
5821         }
5822 
5823         return rr;
5824     }
5825 
addToRilHistogram(RILRequest rr)5826     private void addToRilHistogram(RILRequest rr) {
5827         long endTime = SystemClock.elapsedRealtime();
5828         int totalTime = (int) (endTime - rr.mStartTimeMs);
5829 
5830         synchronized (sRilTimeHistograms) {
5831             TelephonyHistogram entry = sRilTimeHistograms.get(rr.mRequest);
5832             if (entry == null) {
5833                 // We would have total #RIL_HISTOGRAM_BUCKET_COUNT range buckets for RIL commands
5834                 entry = new TelephonyHistogram(TelephonyHistogram.TELEPHONY_CATEGORY_RIL,
5835                         rr.mRequest, RIL_HISTOGRAM_BUCKET_COUNT);
5836                 sRilTimeHistograms.put(rr.mRequest, entry);
5837             }
5838             entry.addTimeTaken(totalTime);
5839         }
5840     }
5841 
5842     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
makeStaticRadioCapability()5843     RadioCapability makeStaticRadioCapability() {
5844         // default to UNKNOWN so we fail fast.
5845         int raf = RadioAccessFamily.RAF_UNKNOWN;
5846 
5847         String rafString = mContext.getResources().getString(
5848                 com.android.internal.R.string.config_radio_access_family);
5849         if (!TextUtils.isEmpty(rafString)) {
5850             raf = RadioAccessFamily.rafTypeFromString(rafString);
5851         }
5852         RadioCapability rc = new RadioCapability(mPhoneId.intValue(), 0, 0, raf,
5853                 "", RadioCapability.RC_STATUS_SUCCESS);
5854         if (RILJ_LOGD) riljLog("Faking RIL_REQUEST_GET_RADIO_CAPABILITY response using " + raf);
5855         return rc;
5856     }
5857 
5858     @UnsupportedAppUsage
retToString(int req, Object ret)5859     static String retToString(int req, Object ret) {
5860         if (ret == null) return "";
5861         switch (req) {
5862             // Don't log these return values, for privacy's sake.
5863             case RIL_REQUEST_GET_IMSI:
5864             case RIL_REQUEST_GET_IMEI:
5865             case RIL_REQUEST_GET_IMEISV:
5866             case RIL_REQUEST_SIM_OPEN_CHANNEL:
5867             case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL:
5868             case RIL_REQUEST_DEVICE_IMEI:
5869 
5870                 if (!RILJ_LOGV) {
5871                     // If not versbose logging just return and don't display IMSI and IMEI, IMEISV
5872                     return "";
5873                 }
5874         }
5875 
5876         StringBuilder sb;
5877         String s;
5878         int length;
5879         if (ret instanceof int[]) {
5880             int[] intArray = (int[]) ret;
5881             length = intArray.length;
5882             sb = new StringBuilder("{");
5883             if (length > 0) {
5884                 int i = 0;
5885                 sb.append(intArray[i++]);
5886                 while (i < length) {
5887                     sb.append(", ").append(intArray[i++]);
5888                 }
5889             }
5890             sb.append("}");
5891             s = sb.toString();
5892         } else if (ret instanceof String[]) {
5893             String[] strings = (String[]) ret;
5894             length = strings.length;
5895             sb = new StringBuilder("{");
5896             if (length > 0) {
5897                 int i = 0;
5898                 // position 0 is IMEI in RIL_REQUEST_DEVICE_IDENTITY
5899                 if (req == RIL_REQUEST_DEVICE_IDENTITY) {
5900                     sb.append(Rlog.pii(RILJ_LOG_TAG, strings[i++]));
5901                 } else {
5902                     sb.append(strings[i++]);
5903                 }
5904                 while (i < length) {
5905                     sb.append(", ").append(strings[i++]);
5906                 }
5907             }
5908             sb.append("}");
5909             s = sb.toString();
5910         } else if (req == RIL_REQUEST_GET_CURRENT_CALLS) {
5911             ArrayList<DriverCall> calls = (ArrayList<DriverCall>) ret;
5912             sb = new StringBuilder("{");
5913             for (DriverCall dc : calls) {
5914                 sb.append("[").append(dc).append("] ");
5915             }
5916             sb.append("}");
5917             s = sb.toString();
5918         } else if (req == RIL_REQUEST_GET_NEIGHBORING_CELL_IDS) {
5919             ArrayList<NeighboringCellInfo> cells = (ArrayList<NeighboringCellInfo>) ret;
5920             sb = new StringBuilder("{");
5921             for (NeighboringCellInfo cell : cells) {
5922                 sb.append("[").append(cell).append("] ");
5923             }
5924             sb.append("}");
5925             s = sb.toString();
5926         } else if (req == RIL_REQUEST_QUERY_CALL_FORWARD_STATUS) {
5927             CallForwardInfo[] cinfo = (CallForwardInfo[]) ret;
5928             length = cinfo.length;
5929             sb = new StringBuilder("{");
5930             for (int i = 0; i < length; i++) {
5931                 sb.append("[").append(cinfo[i]).append("] ");
5932             }
5933             sb.append("}");
5934             s = sb.toString();
5935         } else if (req == RIL_REQUEST_GET_HARDWARE_CONFIG) {
5936             ArrayList<HardwareConfig> hwcfgs = (ArrayList<HardwareConfig>) ret;
5937             sb = new StringBuilder(" ");
5938             for (HardwareConfig hwcfg : hwcfgs) {
5939                 sb.append("[").append(hwcfg).append("] ");
5940             }
5941             s = sb.toString();
5942         } else if (req == RIL_REQUEST_START_IMS_TRAFFIC
5943                 || req == RIL_UNSOL_CONNECTION_SETUP_FAILURE) {
5944             sb = new StringBuilder("{");
5945             Object[] info = (Object[]) ret;
5946             int token = (Integer) info[0];
5947             sb.append(token).append(", ");
5948             if (info[1] != null) {
5949                 ConnectionFailureInfo failureInfo = (ConnectionFailureInfo) info[1];
5950                 sb.append(failureInfo.getReason()).append(", ");
5951                 sb.append(failureInfo.getCauseCode()).append(", ");
5952                 sb.append(failureInfo.getWaitTimeMillis());
5953             } else {
5954                 sb.append("null");
5955             }
5956             sb.append("}");
5957             s = sb.toString();
5958         } else {
5959             // Check if toString() was overridden. Java classes created from HIDL have a built-in
5960             // toString() method, but AIDL classes only have it if the parcelable contains a
5961             // @JavaDerive annotation. Manually convert to String as a backup for AIDL parcelables
5962             // missing the annotation.
5963             boolean toStringExists = false;
5964             try {
5965                 toStringExists = ret.getClass().getMethod("toString").getDeclaringClass()
5966                         != Object.class;
5967             } catch (NoSuchMethodException e) {
5968                 Rlog.e(RILJ_LOG_TAG, e.getMessage());
5969             }
5970             if (toStringExists) {
5971                 s = ret.toString();
5972             } else {
5973                 s = RILUtils.convertToString(ret) + " [convertToString]";
5974             }
5975         }
5976         return s;
5977     }
5978 
writeMetricsCallRing(char[] response)5979     void writeMetricsCallRing(char[] response) {
5980         mMetrics.writeRilCallRing(mPhoneId, response);
5981     }
5982 
writeMetricsSrvcc(int state)5983     void writeMetricsSrvcc(int state) {
5984         mMetrics.writeRilSrvcc(mPhoneId, state);
5985         PhoneFactory.getPhone(mPhoneId).getVoiceCallSessionStats().onRilSrvccStateChanged(state);
5986     }
5987 
writeMetricsModemRestartEvent(String reason)5988     void writeMetricsModemRestartEvent(String reason) {
5989         mMetrics.writeModemRestartEvent(mPhoneId, reason);
5990         // Write metrics to statsd. Generate metric only when modem reset is detected by the
5991         // first instance of RIL to avoid duplicated events.
5992         if (mPhoneId == 0) {
5993             ModemRestartStats.onModemRestart(reason);
5994         }
5995     }
5996 
5997     /**
5998      * Notify all registrants that the ril has connected or disconnected.
5999      *
6000      * @param rilVer is the version of the ril or -1 if disconnected.
6001      */
6002     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
notifyRegistrantsRilConnectionChanged(int rilVer)6003     void notifyRegistrantsRilConnectionChanged(int rilVer) {
6004         mRilVersion = rilVer;
6005         if (mRilConnectedRegistrants != null) {
6006             mRilConnectedRegistrants.notifyRegistrants(
6007                     new AsyncResult(null, new Integer(rilVer), null));
6008         }
6009     }
6010 
6011     @UnsupportedAppUsage
notifyRegistrantsCdmaInfoRec(CdmaInformationRecords infoRec)6012     void notifyRegistrantsCdmaInfoRec(CdmaInformationRecords infoRec) {
6013         int response = RIL_UNSOL_CDMA_INFO_REC;
6014         if (infoRec.record instanceof CdmaInformationRecords.CdmaDisplayInfoRec) {
6015             if (mDisplayInfoRegistrants != null) {
6016                 if (isLogOrTrace()) unsljLogRet(response, infoRec.record);
6017                 mDisplayInfoRegistrants.notifyRegistrants(
6018                         new AsyncResult(null, infoRec.record, null));
6019             }
6020         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaSignalInfoRec) {
6021             if (mSignalInfoRegistrants != null) {
6022                 if (isLogOrTrace()) unsljLogRet(response, infoRec.record);
6023                 mSignalInfoRegistrants.notifyRegistrants(
6024                         new AsyncResult(null, infoRec.record, null));
6025             }
6026         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaNumberInfoRec) {
6027             if (mNumberInfoRegistrants != null) {
6028                 if (isLogOrTrace()) unsljLogRet(response, infoRec.record);
6029                 mNumberInfoRegistrants.notifyRegistrants(
6030                         new AsyncResult(null, infoRec.record, null));
6031             }
6032         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaRedirectingNumberInfoRec) {
6033             if (mRedirNumInfoRegistrants != null) {
6034                 if (isLogOrTrace()) unsljLogRet(response, infoRec.record);
6035                 mRedirNumInfoRegistrants.notifyRegistrants(
6036                         new AsyncResult(null, infoRec.record, null));
6037             }
6038         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaLineControlInfoRec) {
6039             if (mLineControlInfoRegistrants != null) {
6040                 if (isLogOrTrace()) unsljLogRet(response, infoRec.record);
6041                 mLineControlInfoRegistrants.notifyRegistrants(
6042                         new AsyncResult(null, infoRec.record, null));
6043             }
6044         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaT53ClirInfoRec) {
6045             if (mT53ClirInfoRegistrants != null) {
6046                 if (isLogOrTrace()) unsljLogRet(response, infoRec.record);
6047                 mT53ClirInfoRegistrants.notifyRegistrants(
6048                         new AsyncResult(null, infoRec.record, null));
6049             }
6050         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaT53AudioControlInfoRec) {
6051             if (mT53AudCntrlInfoRegistrants != null) {
6052                 if (isLogOrTrace()) {
6053                     unsljLogRet(response, infoRec.record);
6054                 }
6055                 mT53AudCntrlInfoRegistrants.notifyRegistrants(
6056                         new AsyncResult(null, infoRec.record, null));
6057             }
6058         }
6059     }
6060 
notifyRegistrantsImeiMappingChanged(ImeiInfo imeiInfo)6061     void notifyRegistrantsImeiMappingChanged(ImeiInfo imeiInfo) {
6062         if (mImeiInfoRegistrants != null) {
6063             mImeiInfoRegistrants.notifyRegistrants(
6064                     new AsyncResult(null, imeiInfo, null));
6065         }
6066     }
6067 
6068     @UnsupportedAppUsage
riljLog(String msg)6069     void riljLog(String msg) {
6070         Rlog.d(RILJ_LOG_TAG, msg + (" [PHONE" + mPhoneId + "]"));
6071     }
6072 
riljLoge(String msg)6073     void riljLoge(String msg) {
6074         Rlog.e(RILJ_LOG_TAG, msg + (" [PHONE" + mPhoneId + "]"));
6075     }
6076 
riljLogv(String msg)6077     void riljLogv(String msg) {
6078         Rlog.v(RILJ_LOG_TAG, msg + (" [PHONE" + mPhoneId + "]"));
6079     }
6080 
riljLogw(String msg)6081     void riljLogw(String msg) {
6082         Rlog.w(RILJ_LOG_TAG, msg + (" [PHONE" + mPhoneId + "]"));
6083     }
6084 
isLogOrTrace()6085     boolean isLogOrTrace() {
6086         return RILJ_LOGD || Trace.isTagEnabled(Trace.TRACE_TAG_NETWORK);
6087     }
6088 
isLogvOrTrace()6089     boolean isLogvOrTrace() {
6090         return RILJ_LOGV || Trace.isTagEnabled(Trace.TRACE_TAG_NETWORK);
6091     }
6092 
6093     @UnsupportedAppUsage
unsljLog(int response)6094     void unsljLog(int response) {
6095         String logStr = RILUtils.responseToString(response);
6096         if (RILJ_LOGD) {
6097             riljLog("[UNSL]< " + logStr);
6098         }
6099         Trace.instantForTrack(Trace.TRACE_TAG_NETWORK, "RIL", logStr);
6100     }
6101 
6102     @UnsupportedAppUsage
unsljLogMore(int response, String more)6103     void unsljLogMore(int response, String more) {
6104         String logStr = RILUtils.responseToString(response) + " " + more;
6105         if (RILJ_LOGD) {
6106             riljLog("[UNSL]< " + logStr);
6107         }
6108         Trace.instantForTrack(Trace.TRACE_TAG_NETWORK, "RIL", logStr);
6109     }
6110 
6111     @UnsupportedAppUsage
unsljLogRet(int response, Object ret)6112     void unsljLogRet(int response, Object ret) {
6113         String logStr = RILUtils.responseToString(response) + " " + retToString(response, ret);
6114         if (RILJ_LOGD) {
6115             riljLog("[UNSL]< " + logStr);
6116         }
6117         Trace.instantForTrack(Trace.TRACE_TAG_NETWORK, "RIL", logStr);
6118     }
6119 
6120     @UnsupportedAppUsage
unsljLogvRet(int response, Object ret)6121     void unsljLogvRet(int response, Object ret) {
6122         String logStr = RILUtils.responseToString(response) + " " + retToString(response, ret);
6123         if (RILJ_LOGV) {
6124             riljLogv("[UNSL]< " + logStr);
6125         }
6126         Trace.instantForTrack(Trace.TRACE_TAG_NETWORK, "RIL", logStr);
6127     }
6128 
6129     @Override
setPhoneType(int phoneType)6130     public void setPhoneType(int phoneType) { // Called by GsmCdmaPhone
6131         if (RILJ_LOGD) riljLog("setPhoneType=" + phoneType + " old value=" + mPhoneType);
6132         mPhoneType = phoneType;
6133     }
6134 
6135     /* (non-Javadoc)
6136      * @see com.android.internal.telephony.BaseCommands#testingEmergencyCall()
6137      */
6138     @Override
testingEmergencyCall()6139     public void testingEmergencyCall() {
6140         if (RILJ_LOGD) riljLog("testingEmergencyCall");
6141         mTestingEmergencyCall.set(true);
6142     }
6143 
dump(FileDescriptor fd, PrintWriter pw, String[] args)6144     public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
6145         pw.println("RIL: " + this);
6146         pw.println(" " + mServiceProxies.get(HAL_SERVICE_DATA));
6147         pw.println(" " + mServiceProxies.get(HAL_SERVICE_MESSAGING));
6148         pw.println(" " + mServiceProxies.get(HAL_SERVICE_MODEM));
6149         pw.println(" " + mServiceProxies.get(HAL_SERVICE_NETWORK));
6150         pw.println(" " + mServiceProxies.get(HAL_SERVICE_SIM));
6151         pw.println(" " + mServiceProxies.get(HAL_SERVICE_VOICE));
6152         pw.println(" " + mServiceProxies.get(HAL_SERVICE_IMS));
6153         pw.println(" mWakeLock=" + mWakeLock);
6154         pw.println(" mWakeLockTimeout=" + mWakeLockTimeout);
6155         synchronized (mRequestList) {
6156             synchronized (mWakeLock) {
6157                 pw.println(" mWakeLockCount=" + mWakeLockCount);
6158             }
6159             int count = mRequestList.size();
6160             pw.println(" mRequestList count=" + count);
6161             for (int i = 0; i < count; i++) {
6162                 RILRequest rr = mRequestList.valueAt(i);
6163                 pw.println("  [" + rr.mSerial + "] " + RILUtils.requestToString(rr.mRequest));
6164             }
6165         }
6166         pw.println(" mLastNITZTimeInfo=" + Arrays.toString(mLastNITZTimeInfo));
6167         pw.println(" mLastRadioPowerResult=" + mLastRadioPowerResult);
6168         pw.println(" mTestingEmergencyCall=" + mTestingEmergencyCall.get());
6169         mClientWakelockTracker.dumpClientRequestTracker(pw);
6170     }
6171 
getClientRequestStats()6172     public List<ClientRequestStats> getClientRequestStats() {
6173         return mClientWakelockTracker.getClientRequestStats();
6174     }
6175 
notifyBarringInfoChanged(@onNull BarringInfo barringInfo)6176     void notifyBarringInfoChanged(@NonNull BarringInfo barringInfo) {
6177         mLastBarringInfo = barringInfo;
6178         mBarringInfoChangedRegistrants.notifyRegistrants(new AsyncResult(null, barringInfo, null));
6179     }
6180 
6181     /**
6182      * Get the HAL version with a specific service.
6183      *
6184      * @param service the hal service id
6185      * @return the current HalVersion
6186      */
getHalVersion(int service)6187     public HalVersion getHalVersion(int service) {
6188         HalVersion halVersion = mHalVersion.get(service);
6189         if (halVersion == null) {
6190             if (isRadioServiceSupported(service)) {
6191                 halVersion = RADIO_HAL_VERSION_UNKNOWN;
6192             } else {
6193                 halVersion = RADIO_HAL_VERSION_UNSUPPORTED;
6194             }
6195         }
6196         return halVersion;
6197     }
6198 
6199     /**
6200      * Get the HAL version corresponding to the interface version of a IRadioService module.
6201      * @param interfaceVersion The interface version, from IRadioService#getInterfaceVersion().
6202      * @return The corresponding HalVersion.
6203      */
getServiceHalVersion(int interfaceVersion)6204     public static HalVersion getServiceHalVersion(int interfaceVersion) {
6205         switch (interfaceVersion) {
6206             case 1: return RADIO_HAL_VERSION_2_0;
6207             case 2: return RADIO_HAL_VERSION_2_1;
6208             case 3: return RADIO_HAL_VERSION_2_2;
6209             default: return RADIO_HAL_VERSION_UNKNOWN;
6210         }
6211     }
6212 
serviceToString(@alService int service)6213     private static String serviceToString(@HalService int service) {
6214         switch (service) {
6215             case HAL_SERVICE_RADIO:
6216                 return "RADIO";
6217             case HAL_SERVICE_DATA:
6218                 return "DATA";
6219             case HAL_SERVICE_MESSAGING:
6220                 return "MESSAGING";
6221             case HAL_SERVICE_MODEM:
6222                 return "MODEM";
6223             case HAL_SERVICE_NETWORK:
6224                 return "NETWORK";
6225             case HAL_SERVICE_SIM:
6226                 return "SIM";
6227             case HAL_SERVICE_VOICE:
6228                 return "VOICE";
6229             case HAL_SERVICE_IMS:
6230                 return "IMS";
6231             default:
6232                 return "UNKNOWN:" + service;
6233         }
6234     }
6235 }
6236