ImsServiceProxyCompat.java revision 1639c21be6e7cd7699db4080fcf2ccc5cb2006e6
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
17package android.telephony.ims;
18
19import android.app.PendingIntent;
20import android.os.IBinder;
21import android.os.Message;
22import android.os.RemoteException;
23import android.telephony.ims.feature.IMMTelFeature;
24import android.telephony.ims.feature.ImsFeature;
25
26import com.android.ims.ImsCallProfile;
27import com.android.ims.internal.IImsCallSession;
28import com.android.ims.internal.IImsCallSessionListener;
29import com.android.ims.internal.IImsConfig;
30import com.android.ims.internal.IImsEcbm;
31import com.android.ims.internal.IImsMultiEndpoint;
32import com.android.ims.internal.IImsRegistrationListener;
33import com.android.ims.internal.IImsService;
34import 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
43public class ImsServiceProxyCompat implements IMMTelFeature {
44
45    protected final int mSlotId;
46    protected IBinder mBinder;
47
48    public ImsServiceProxyCompat(int slotId, IBinder binder) {
49        mSlotId = slotId;
50        mBinder = binder;
51    }
52
53    @Override
54    public int startSession(PendingIntent incomingCallIntent, IImsRegistrationListener listener)
55            throws RemoteException {
56        checkBinderConnection();
57        return getServiceInterface(mBinder).open(mSlotId, ImsFeature.MMTEL, incomingCallIntent,
58                listener);
59    }
60
61    @Override
62    public void endSession(int sessionId) throws RemoteException {
63        checkBinderConnection();
64        getServiceInterface(mBinder).close(sessionId);
65    }
66
67    @Override
68    public boolean isConnected(int sessionId, int callServiceType, int callType)
69            throws RemoteException {
70        checkBinderConnection();
71        return getServiceInterface(mBinder).isConnected(sessionId,  callServiceType, callType);
72    }
73
74    @Override
75    public boolean isOpened(int sessionId) throws RemoteException {
76        checkBinderConnection();
77        return getServiceInterface(mBinder).isOpened(sessionId);
78    }
79
80    @Override
81    public void addRegistrationListener(int sessionId, IImsRegistrationListener listener)
82            throws RemoteException {
83        checkBinderConnection();
84        getServiceInterface(mBinder).addRegistrationListener(mSlotId, ImsFeature.MMTEL, listener);
85    }
86
87    @Override
88    public void removeRegistrationListener(int sessionId, IImsRegistrationListener listener)
89            throws RemoteException {
90        checkBinderConnection();
91        // Not Implemented in old ImsService. If the registration listener becomes invalid, the
92        // ImsService will remove.
93    }
94
95    @Override
96    public ImsCallProfile createCallProfile(int sessionId, int callServiceType, int callType)
97            throws RemoteException {
98        checkBinderConnection();
99        return getServiceInterface(mBinder).createCallProfile(sessionId, callServiceType, callType);
100    }
101
102    @Override
103    public IImsCallSession createCallSession(int sessionId, ImsCallProfile profile,
104            IImsCallSessionListener listener) throws RemoteException {
105        checkBinderConnection();
106        return getServiceInterface(mBinder).createCallSession(sessionId, profile, listener);
107    }
108
109    @Override
110    public IImsCallSession getPendingCallSession(int sessionId, String callId)
111            throws RemoteException {
112        checkBinderConnection();
113        return getServiceInterface(mBinder).getPendingCallSession(sessionId, callId);
114    }
115
116    @Override
117    public IImsUt getUtInterface(int sessionId) throws RemoteException {
118        checkBinderConnection();
119        return getServiceInterface(mBinder).getUtInterface(sessionId);
120    }
121
122    @Override
123    public IImsConfig getConfigInterface(int sessionId) throws RemoteException {
124        checkBinderConnection();
125        return getServiceInterface(mBinder).getConfigInterface(mSlotId);
126    }
127
128    @Override
129    public void turnOnIms(int sessionId) throws RemoteException {
130        checkBinderConnection();
131        getServiceInterface(mBinder).turnOnIms(mSlotId);
132    }
133
134    @Override
135    public void turnOffIms(int sessionId) throws RemoteException {
136        checkBinderConnection();
137        getServiceInterface(mBinder).turnOffIms(mSlotId);
138    }
139
140    @Override
141    public IImsEcbm getEcbmInterface(int sessionId) throws RemoteException {
142        checkBinderConnection();
143        return getServiceInterface(mBinder).getEcbmInterface(sessionId);
144    }
145
146    @Override
147    public void setUiTTYMode(int sessionId, int uiTtyMode, Message onComplete)
148            throws RemoteException {
149        checkBinderConnection();
150        getServiceInterface(mBinder).setUiTTYMode(sessionId, uiTtyMode, onComplete);
151    }
152
153    @Override
154    public IImsMultiEndpoint getMultiEndpointInterface(int sessionId) throws RemoteException {
155        checkBinderConnection();
156        return getServiceInterface(mBinder).getMultiEndpointInterface(sessionId);
157    }
158
159    /**
160     * Base implementation, always returns READY for compatibility with old ImsService.
161     */
162    public int getFeatureStatus() {
163        return ImsFeature.STATE_READY;
164    }
165
166    /**
167     * @return false if the binder connection is no longer alive.
168     */
169    public boolean isBinderAlive() {
170        return mBinder != null && mBinder.isBinderAlive();
171    }
172
173    private IImsService getServiceInterface(IBinder b) {
174        return IImsService.Stub.asInterface(b);
175    }
176
177    protected void checkBinderConnection() throws RemoteException {
178        if (!isBinderAlive()) {
179            throw new RemoteException("ImsServiceProxy is not available for that feature.");
180        }
181    }
182}
183