1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.internal.telephony;
18 
19 import static android.telephony.TelephonyManager.HAL_SERVICE_IMS;
20 
21 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_CONNECTION_SETUP_FAILURE;
22 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_NOTIFY_ANBR;
23 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_TRIGGER_IMS_DEREGISTRATION;
24 
25 import android.hardware.radio.ims.IRadioImsIndication;
26 import android.os.AsyncResult;
27 import android.telephony.ims.feature.ConnectionFailureInfo;
28 
29 /**
30  * Interface declaring unsolicited radio indications for IMS APIs.
31  */
32 public class ImsIndication extends IRadioImsIndication.Stub {
33     private final RIL mRil;
34 
ImsIndication(RIL ril)35     public ImsIndication(RIL ril) {
36         mRil = ril;
37     }
38 
39     @Override
getInterfaceHash()40     public String getInterfaceHash() {
41         return IRadioImsIndication.HASH;
42     }
43 
44     @Override
getInterfaceVersion()45     public int getInterfaceVersion() {
46         return IRadioImsIndication.VERSION;
47     }
48 
49     /**
50      * Fired by radio when any IMS traffic is not sent to network due to any failure
51      * on cellular networks.
52      *
53      * @param indicationType Type of radio indication.
54      * @param token The token provided by {@link #startImsTraffic}.
55      * @param failureInfo Connection failure information.
56      */
onConnectionSetupFailure(int indicationType, int token, android.hardware.radio.ims.ConnectionFailureInfo failureInfo)57     public void onConnectionSetupFailure(int indicationType, int token,
58             android.hardware.radio.ims.ConnectionFailureInfo failureInfo) {
59         mRil.processIndication(HAL_SERVICE_IMS, indicationType);
60 
61         Object[] response = new Object[2];
62         response[0] = token;
63         response[1] = new ConnectionFailureInfo(
64                 RILUtils.convertHalConnectionFailureReason(failureInfo.failureReason),
65                 failureInfo.causeCode, failureInfo.waitTimeMillis);
66 
67         if (RIL.RILJ_LOGD) mRil.unsljLogRet(RIL_UNSOL_CONNECTION_SETUP_FAILURE, response);
68 
69         mRil.mConnectionSetupFailureRegistrants.notifyRegistrants(
70                 new AsyncResult(null, response, null));
71     }
72 
73     /**
74      * Fired by radio when ANBR is received form the network.
75      *
76      * @param indicationType Type of radio indication.
77      * @param qosSessionId QoS session ID is used to identify media stream such as audio or video.
78      * @param imsdirection Direction of this packet stream (e.g. uplink or downlink).
79      * @param bitsPerSecond The recommended bit rate for the UE
80      *        for a specific logical channel and a specific direction by the network.
81      */
notifyAnbr(int indicationType, int qosSessionId, int imsdirection, int bitsPerSecond)82     public void notifyAnbr(int indicationType, int qosSessionId, int imsdirection,
83             int bitsPerSecond) {
84         mRil.processIndication(HAL_SERVICE_IMS, indicationType);
85 
86         int[] response = new int[3];
87         response[0] = qosSessionId;
88         response[1] = imsdirection;
89         response[2] = bitsPerSecond;
90 
91         if (RIL.RILJ_LOGD) mRil.unsljLogRet(RIL_UNSOL_NOTIFY_ANBR, response);
92 
93         mRil.mNotifyAnbrRegistrants.notifyRegistrants(new AsyncResult(null, response, null));
94     }
95 
96     /**
97      * Requests IMS stack to perform graceful IMS deregistration before radio performing
98      * network detach in the events of SIM remove, refresh or and so on. The radio waits for
99      * the IMS deregistration, which will be notified by telephony via
100      * {@link IRadioIms#updateImsRegistrationInfo()}, or a certain timeout interval to start
101      * the network detach procedure.
102      *
103      * @param indicationType Type of radio indication.
104      * @param reason the reason why the deregistration is triggered.
105      */
triggerImsDeregistration(int indicationType, int reason)106     public void triggerImsDeregistration(int indicationType, int reason) {
107         mRil.processIndication(HAL_SERVICE_IMS, indicationType);
108 
109         if (RIL.RILJ_LOGD) mRil.unsljLogRet(RIL_UNSOL_TRIGGER_IMS_DEREGISTRATION, reason);
110 
111         int[] response = new int[1];
112         response[0] = RILUtils.convertHalDeregistrationReason(reason);
113 
114         mRil.mTriggerImsDeregistrationRegistrants.notifyRegistrants(
115                 new AsyncResult(null, response, null));
116     }
117 }
118