ImsServiceProxyCompat.java revision e63b35d0b22db8769ffd3378fc305d5f3d27fd50
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    private static final int SERVICE_ID = ImsFeature.MMTEL;
46
47    protected final int mSlotId;
48    protected IBinder mBinder;
49
50    public ImsServiceProxyCompat(int slotId, IBinder binder) {
51        mSlotId = slotId;
52        mBinder = binder;
53    }
54
55    @Override
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
64    public void endSession(int sessionId) throws RemoteException {
65        checkBinderConnection();
66        getServiceInterface(mBinder).close(sessionId);
67    }
68
69    @Override
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
77    public boolean isOpened() throws RemoteException {
78        checkBinderConnection();
79        return getServiceInterface(mBinder).isOpened(SERVICE_ID);
80    }
81
82    @Override
83    public void addRegistrationListener(IImsRegistrationListener listener)
84            throws RemoteException {
85        checkBinderConnection();
86        getServiceInterface(mBinder).addRegistrationListener(mSlotId, ImsFeature.MMTEL, listener);
87    }
88
89    @Override
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
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
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
111    public IImsCallSession getPendingCallSession(int sessionId, String callId)
112            throws RemoteException {
113        checkBinderConnection();
114        return getServiceInterface(mBinder).getPendingCallSession(sessionId, callId);
115    }
116
117    @Override
118    public IImsUt getUtInterface() throws RemoteException {
119        checkBinderConnection();
120        return getServiceInterface(mBinder).getUtInterface(SERVICE_ID);
121    }
122
123    @Override
124    public IImsConfig getConfigInterface() throws RemoteException {
125        checkBinderConnection();
126        return getServiceInterface(mBinder).getConfigInterface(mSlotId);
127    }
128
129    @Override
130    public void turnOnIms() throws RemoteException {
131        checkBinderConnection();
132        getServiceInterface(mBinder).turnOnIms(mSlotId);
133    }
134
135    @Override
136    public void turnOffIms() throws RemoteException {
137        checkBinderConnection();
138        getServiceInterface(mBinder).turnOffIms(mSlotId);
139    }
140
141    @Override
142    public IImsEcbm getEcbmInterface() throws RemoteException {
143        checkBinderConnection();
144        return getServiceInterface(mBinder).getEcbmInterface(SERVICE_ID);
145    }
146
147    @Override
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
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     */
163    public int getFeatureStatus() {
164        return ImsFeature.STATE_READY;
165    }
166
167    /**
168     * @return false if the binder connection is no longer alive.
169     */
170    public boolean isBinderAlive() {
171        return mBinder != null && mBinder.isBinderAlive();
172    }
173
174    private IImsService getServiceInterface(IBinder b) {
175        return IImsService.Stub.asInterface(b);
176    }
177
178    protected void checkBinderConnection() throws RemoteException {
179        if (!isBinderAlive()) {
180            throw new RemoteException("ImsServiceProxy is not available for that feature.");
181        }
182    }
183}
184