1 /*
2  * Copyright (c) 2013 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.ims;
18 
19 import android.net.Uri;
20 import android.telephony.ims.RegistrationManager;
21 import android.telephony.ims.ImsReasonInfo;
22 import android.telephony.ims.feature.MmTelFeature;
23 import android.telephony.ims.stub.ImsRegistrationImplBase;
24 
25 import java.util.Arrays;
26 
27 /**
28  * Listener for receiving notifications about changes to the IMS connection.
29  * It provides a state of IMS registration between UE and IMS network, the service
30  * availability of the local device during IMS registered.
31  * @Deprecated Use {@link RegistrationManager.RegistrationCallback} instead.
32  * @hide
33  */
34 public class ImsConnectionStateListener extends RegistrationManager.RegistrationCallback {
35 
36     @Override
onRegistered(@msRegistrationImplBase.ImsRegistrationTech int imsRadioTech)37     public final void onRegistered(@ImsRegistrationImplBase.ImsRegistrationTech int imsRadioTech) {
38         onImsConnected(imsRadioTech);
39     }
40 
41     @Override
onRegistering(@msRegistrationImplBase.ImsRegistrationTech int imsRadioTech)42     public final void onRegistering(@ImsRegistrationImplBase.ImsRegistrationTech int imsRadioTech) {
43         onImsProgressing(imsRadioTech);
44     }
45 
46     @Override
onUnregistered(ImsReasonInfo info)47     public final void onUnregistered(ImsReasonInfo info) {
48         onImsDisconnected(info);
49     }
50 
51     @Override
onTechnologyChangeFailed( @msRegistrationImplBase.ImsRegistrationTech int imsRadioTech, ImsReasonInfo info)52     public final void onTechnologyChangeFailed(
53             @ImsRegistrationImplBase.ImsRegistrationTech int imsRadioTech, ImsReasonInfo info) {
54         onRegistrationChangeFailed(imsRadioTech, info);
55     }
56 
57     @Override
onSubscriberAssociatedUriChanged(Uri[] uris)58     public void onSubscriberAssociatedUriChanged(Uri[] uris) {
59         registrationAssociatedUriChanged(uris);
60     }
61 
62     /**
63      * Used to convert from the new capabilities structure to the old features structure for
64      * backwards compatibility.
65      * @param imsRadioTech The registration that will be used to convert to the old feature
66      *         structure. Can be either {@link ImsRegistrationImplBase#REGISTRATION_TECH_LTE} or
67      *         {@link ImsRegistrationImplBase#REGISTRATION_TECH_IWLAN}
68      * @param c Capabilities that will be turned into old feature array.
69      */
onFeatureCapabilityChangedAdapter( @msRegistrationImplBase.ImsRegistrationTech int imsRadioTech, MmTelFeature.MmTelCapabilities c)70     public void onFeatureCapabilityChangedAdapter(
71             @ImsRegistrationImplBase.ImsRegistrationTech int imsRadioTech,
72             MmTelFeature.MmTelCapabilities c) {
73         // Size of ImsConfig.FeatureConstants
74         int[] enabledCapabilities = new int[6];
75         // UNKNOWN means disabled.
76         Arrays.fill(enabledCapabilities, ImsConfig.FeatureConstants.FEATURE_TYPE_UNKNOWN);
77         // Size of ImsConfig.FeatureConstants
78         int[] disabledCapabilities = new int[6];
79         Arrays.fill(disabledCapabilities, ImsConfig.FeatureConstants.FEATURE_TYPE_UNKNOWN);
80         // populate enabledCapabilities
81         switch (imsRadioTech) {
82             case ImsRegistrationImplBase.REGISTRATION_TECH_LTE: {
83                 if (c.isCapable(MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE)) {
84                     // enabled means equal to its own integer value.
85                     enabledCapabilities[ImsConfig.FeatureConstants.FEATURE_TYPE_VOICE_OVER_LTE] =
86                             ImsConfig.FeatureConstants.FEATURE_TYPE_VOICE_OVER_LTE;
87                 }
88                 if (c.isCapable(MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO)) {
89                     enabledCapabilities[ImsConfig.FeatureConstants.FEATURE_TYPE_VIDEO_OVER_LTE] =
90                             ImsConfig.FeatureConstants.FEATURE_TYPE_VIDEO_OVER_LTE;
91                 }
92                 if (c.isCapable(MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT)) {
93                     enabledCapabilities[ImsConfig.FeatureConstants.FEATURE_TYPE_UT_OVER_LTE] =
94                             ImsConfig.FeatureConstants.FEATURE_TYPE_UT_OVER_LTE;
95                 }
96                 break;
97             }
98             case ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN: {
99                 if (c.isCapable(MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE)) {
100                     enabledCapabilities[ImsConfig.FeatureConstants.FEATURE_TYPE_VOICE_OVER_WIFI] =
101                             ImsConfig.FeatureConstants.FEATURE_TYPE_VOICE_OVER_WIFI;
102                 }
103                 if (c.isCapable(MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO)) {
104                     enabledCapabilities[ImsConfig.FeatureConstants.FEATURE_TYPE_VIDEO_OVER_WIFI] =
105                             ImsConfig.FeatureConstants.FEATURE_TYPE_VIDEO_OVER_WIFI;
106                 }
107                 if (c.isCapable(MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT)) {
108                     enabledCapabilities[ImsConfig.FeatureConstants.FEATURE_TYPE_UT_OVER_WIFI] =
109                             ImsConfig.FeatureConstants.FEATURE_TYPE_UT_OVER_WIFI;
110                 }
111                 break;
112             }
113         }
114         // make disabledCapabilities the opposite of enabledCapabilities. Since the disabled
115         // capabilities array was defaulted to -1 it is UNKNOWN if not disabled.
116         for (int i = 0; i < enabledCapabilities.length; i++) {
117             if (enabledCapabilities[i] != i) {
118                 disabledCapabilities[i] = i;
119             }
120         }
121         onFeatureCapabilityChanged(ImsServiceClass.MMTEL, enabledCapabilities,
122                 disabledCapabilities);
123     }
124     /**
125      * Called when the device is connected to the IMS network with {@param imsRadioTech}.
126      */
onImsConnected(int imsRadioTech)127     public void onImsConnected(int imsRadioTech) {
128         // no-op
129     }
130 
131     /**
132      * Called when the device is trying to connect to the IMS network with {@param imsRadioTech}.
133      */
onImsProgressing(int imsRadioTech)134     public void onImsProgressing(int imsRadioTech) {
135         // no-op
136     }
137 
138     /**
139      * Called when the device is disconnected from the IMS network.
140      */
onImsDisconnected(ImsReasonInfo imsReasonInfo)141     public void onImsDisconnected(ImsReasonInfo imsReasonInfo) {
142         // no-op
143     }
144 
145     /**
146      * Called when its suspended IMS connection is resumed, meaning the connection
147      * now allows throughput.
148      * @deprecated not used in newer IMS provider implementations.
149      */
onImsResumed()150     public void onImsResumed() {
151         // no-op
152     }
153 
154     /**
155      * Called when its current IMS connection is suspended, meaning there is no data throughput.
156      * @deprecated not used in newer IMS provider implementations.
157      */
onImsSuspended()158     public void onImsSuspended() {
159         // no-op
160     }
161 
162     /**
163      * Called when its current IMS connection feature capability changes.
164      * @deprecated Not used in newer IMS provider implementations.
165      */
onFeatureCapabilityChanged(int serviceClass, int[] enabledFeatures, int[] disabledFeatures)166     public void onFeatureCapabilityChanged(int serviceClass,
167                 int[] enabledFeatures, int[] disabledFeatures) {
168         // no-op
169     }
170 
171     /**
172      * Called when waiting voice message count changes.
173      * @deprecated not used in newer IMS provider implementations.
174      */
onVoiceMessageCountChanged(int count)175     public void onVoiceMessageCountChanged(int count) {
176         // no-op
177     }
178 
179     /**
180      * Called after IMS registration.
181      */
registrationAssociatedUriChanged(Uri[] uris)182     public void registrationAssociatedUriChanged(Uri[] uris) {
183         // no-op
184     }
185 
186     /**
187      * Called when IMS registration attempt on {@param imsRadioTech} failed
188      */
onRegistrationChangeFailed(int imsRadioTech, ImsReasonInfo imsReasonInfo)189     public void onRegistrationChangeFailed(int imsRadioTech, ImsReasonInfo imsReasonInfo) {
190         // no-op
191     }
192 }
193