• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License
15  */
16 
17 package android.telephony.ims;
18 
19 import android.app.PendingIntent;
20 import android.os.IBinder;
21 import android.os.Message;
22 import android.os.RemoteException;
23 import android.telephony.ims.feature.IMMTelFeature;
24 import android.telephony.ims.feature.ImsFeature;
25 
26 import com.android.ims.ImsCallProfile;
27 import com.android.ims.internal.IImsCallSession;
28 import com.android.ims.internal.IImsCallSessionListener;
29 import com.android.ims.internal.IImsConfig;
30 import com.android.ims.internal.IImsEcbm;
31 import com.android.ims.internal.IImsMultiEndpoint;
32 import com.android.ims.internal.IImsRegistrationListener;
33 import com.android.ims.internal.IImsService;
34 import com.android.ims.internal.IImsUt;
35 
36 /**
37  * Compatibility class that implements the new ImsService IMMTelFeature interface, but
38  * uses the old IImsService interface to support older devices that implement the deprecated
39  * opt/net/ims interface.
40  * @hide
41  */
42 
43 public class ImsServiceProxyCompat implements IMMTelFeature {
44 
45     private static final int SERVICE_ID = ImsFeature.MMTEL;
46 
47     protected final int mSlotId;
48     protected IBinder mBinder;
49 
ImsServiceProxyCompat(int slotId, IBinder binder)50     public ImsServiceProxyCompat(int slotId, IBinder binder) {
51         mSlotId = slotId;
52         mBinder = binder;
53     }
54 
55     @Override
startSession(PendingIntent incomingCallIntent, IImsRegistrationListener listener)56     public int startSession(PendingIntent incomingCallIntent, IImsRegistrationListener listener)
57             throws RemoteException {
58         checkBinderConnection();
59         return getServiceInterface(mBinder).open(mSlotId, ImsFeature.MMTEL, incomingCallIntent,
60                 listener);
61     }
62 
63     @Override
endSession(int sessionId)64     public void endSession(int sessionId) throws RemoteException {
65         checkBinderConnection();
66         getServiceInterface(mBinder).close(sessionId);
67     }
68 
69     @Override
isConnected(int callServiceType, int callType)70     public boolean isConnected(int callServiceType, int callType)
71             throws RemoteException {
72         checkBinderConnection();
73         return getServiceInterface(mBinder).isConnected(SERVICE_ID,  callServiceType, callType);
74     }
75 
76     @Override
isOpened()77     public boolean isOpened() throws RemoteException {
78         checkBinderConnection();
79         return getServiceInterface(mBinder).isOpened(SERVICE_ID);
80     }
81 
82     @Override
addRegistrationListener(IImsRegistrationListener listener)83     public void addRegistrationListener(IImsRegistrationListener listener)
84             throws RemoteException {
85         checkBinderConnection();
86         getServiceInterface(mBinder).addRegistrationListener(mSlotId, ImsFeature.MMTEL, listener);
87     }
88 
89     @Override
removeRegistrationListener(IImsRegistrationListener listener)90     public void removeRegistrationListener(IImsRegistrationListener listener)
91             throws RemoteException {
92         // Not Implemented in old ImsService. If the registration listener becomes invalid, the
93         // ImsService will remove.
94     }
95 
96     @Override
createCallProfile(int sessionId, int callServiceType, int callType)97     public ImsCallProfile createCallProfile(int sessionId, int callServiceType, int callType)
98             throws RemoteException {
99         checkBinderConnection();
100         return getServiceInterface(mBinder).createCallProfile(sessionId, callServiceType, callType);
101     }
102 
103     @Override
createCallSession(int sessionId, ImsCallProfile profile, IImsCallSessionListener listener)104     public IImsCallSession createCallSession(int sessionId, ImsCallProfile profile,
105             IImsCallSessionListener listener) throws RemoteException {
106         checkBinderConnection();
107         return getServiceInterface(mBinder).createCallSession(sessionId, profile, listener);
108     }
109 
110     @Override
getPendingCallSession(int sessionId, String callId)111     public IImsCallSession getPendingCallSession(int sessionId, String callId)
112             throws RemoteException {
113         checkBinderConnection();
114         return getServiceInterface(mBinder).getPendingCallSession(sessionId, callId);
115     }
116 
117     @Override
getUtInterface()118     public IImsUt getUtInterface() throws RemoteException {
119         checkBinderConnection();
120         return getServiceInterface(mBinder).getUtInterface(SERVICE_ID);
121     }
122 
123     @Override
getConfigInterface()124     public IImsConfig getConfigInterface() throws RemoteException {
125         checkBinderConnection();
126         return getServiceInterface(mBinder).getConfigInterface(mSlotId);
127     }
128 
129     @Override
turnOnIms()130     public void turnOnIms() throws RemoteException {
131         checkBinderConnection();
132         getServiceInterface(mBinder).turnOnIms(mSlotId);
133     }
134 
135     @Override
turnOffIms()136     public void turnOffIms() throws RemoteException {
137         checkBinderConnection();
138         getServiceInterface(mBinder).turnOffIms(mSlotId);
139     }
140 
141     @Override
getEcbmInterface()142     public IImsEcbm getEcbmInterface() throws RemoteException {
143         checkBinderConnection();
144         return getServiceInterface(mBinder).getEcbmInterface(SERVICE_ID);
145     }
146 
147     @Override
setUiTTYMode(int uiTtyMode, Message onComplete)148     public void setUiTTYMode(int uiTtyMode, Message onComplete)
149             throws RemoteException {
150         checkBinderConnection();
151         getServiceInterface(mBinder).setUiTTYMode(SERVICE_ID, uiTtyMode, onComplete);
152     }
153 
154     @Override
getMultiEndpointInterface()155     public IImsMultiEndpoint getMultiEndpointInterface() throws RemoteException {
156         checkBinderConnection();
157         return getServiceInterface(mBinder).getMultiEndpointInterface(SERVICE_ID);
158     }
159 
160     /**
161      * Base implementation, always returns READY for compatibility with old ImsService.
162      */
getFeatureStatus()163     public int getFeatureStatus() {
164         return ImsFeature.STATE_READY;
165     }
166 
167     /**
168      * @return false if the binder connection is no longer alive.
169      */
isBinderAlive()170     public boolean isBinderAlive() {
171         return mBinder != null && mBinder.isBinderAlive();
172     }
173 
getServiceInterface(IBinder b)174     private IImsService getServiceInterface(IBinder b) {
175         return IImsService.Stub.asInterface(b);
176     }
177 
checkBinderConnection()178     protected void checkBinderConnection() throws RemoteException {
179         if (!isBinderAlive()) {
180             throw new RemoteException("ImsServiceProxy is not available for that feature.");
181         }
182     }
183 }
184