Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 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 com.android.ims; |
| 18 | |
Brad Ebinger | 0e170c7 | 2017-12-14 14:24:02 -0800 | [diff] [blame] | 19 | import android.annotation.Nullable; |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 20 | import android.app.PendingIntent; |
Brad Ebinger | 0e170c7 | 2017-12-14 14:24:02 -0800 | [diff] [blame] | 21 | import android.content.Context; |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 22 | import android.os.IBinder; |
| 23 | import android.os.Message; |
| 24 | import android.os.RemoteException; |
Brad Ebinger | 0e170c7 | 2017-12-14 14:24:02 -0800 | [diff] [blame] | 25 | import android.telephony.Rlog; |
| 26 | import android.telephony.TelephonyManager; |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 27 | import android.telephony.ims.feature.ImsFeature; |
| 28 | import android.util.Log; |
| 29 | |
| 30 | import com.android.ims.internal.IImsCallSession; |
| 31 | import com.android.ims.internal.IImsCallSessionListener; |
| 32 | import com.android.ims.internal.IImsConfig; |
| 33 | import com.android.ims.internal.IImsEcbm; |
Brad Ebinger | f3cda82 | 2017-11-09 10:25:46 -0800 | [diff] [blame] | 34 | import com.android.ims.internal.IImsMMTelFeature; |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 35 | import com.android.ims.internal.IImsMultiEndpoint; |
Brad Ebinger | 0e170c7 | 2017-12-14 14:24:02 -0800 | [diff] [blame] | 36 | import com.android.ims.internal.IImsRegistration; |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 37 | import com.android.ims.internal.IImsRegistrationListener; |
Brad Ebinger | f3cda82 | 2017-11-09 10:25:46 -0800 | [diff] [blame] | 38 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 39 | import com.android.ims.internal.IImsUt; |
| 40 | |
| 41 | /** |
| 42 | * A container of the IImsServiceController binder, which implements all of the ImsFeatures that |
| 43 | * the platform currently supports: MMTel and RCS. |
| 44 | * @hide |
| 45 | */ |
| 46 | |
Brad Ebinger | 3c7f2f4 | 2017-11-07 11:08:11 -0800 | [diff] [blame] | 47 | public class ImsServiceProxy { |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 48 | |
Brad Ebinger | 0e170c7 | 2017-12-14 14:24:02 -0800 | [diff] [blame] | 49 | protected static final String TAG = "ImsServiceProxy"; |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 50 | protected final int mSlotId; |
| 51 | protected IBinder mBinder; |
| 52 | private final int mSupportedFeature; |
Brad Ebinger | 0e170c7 | 2017-12-14 14:24:02 -0800 | [diff] [blame] | 53 | private Context mContext; |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 54 | |
| 55 | // Start by assuming the proxy is available for usage. |
| 56 | private boolean mIsAvailable = true; |
| 57 | // ImsFeature Status from the ImsService. Cached. |
| 58 | private Integer mFeatureStatusCached = null; |
Brad Ebinger | 0e170c7 | 2017-12-14 14:24:02 -0800 | [diff] [blame] | 59 | private IFeatureUpdate mStatusCallback; |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 60 | private final Object mLock = new Object(); |
| 61 | |
Brad Ebinger | 0e170c7 | 2017-12-14 14:24:02 -0800 | [diff] [blame] | 62 | public static ImsServiceProxy create(Context context , int slotId) { |
| 63 | ImsServiceProxy serviceProxy = new ImsServiceProxy(context, slotId, ImsFeature.MMTEL); |
| 64 | |
| 65 | TelephonyManager tm = getTelephonyManager(context); |
| 66 | if (tm == null) { |
| 67 | Rlog.w(TAG, "getServiceProxy: TelephonyManager is null!"); |
| 68 | // Binder can be unset in this case because it will be torn down/recreated as part of |
| 69 | // a retry mechanism until the serviceProxy binder is set successfully. |
| 70 | return serviceProxy; |
| 71 | } |
| 72 | |
| 73 | IImsMMTelFeature binder = tm.getImsMMTelFeatureAndListen(slotId, |
| 74 | serviceProxy.getListener()); |
| 75 | if (binder != null) { |
| 76 | serviceProxy.setBinder(binder.asBinder()); |
| 77 | // Trigger the cache to be updated for feature status. |
| 78 | serviceProxy.getFeatureStatus(); |
| 79 | } else { |
| 80 | Rlog.w(TAG, "getServiceProxy: binder is null! Phone Id: " + slotId); |
| 81 | } |
| 82 | return serviceProxy; |
| 83 | } |
| 84 | |
| 85 | public static TelephonyManager getTelephonyManager(Context context) { |
| 86 | return (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); |
| 87 | } |
| 88 | |
| 89 | public interface IFeatureUpdate { |
| 90 | /** |
| 91 | * Called when the ImsFeature has changed its state. Use |
| 92 | * {@link ImsFeature#getFeatureState()} to get the new state. |
| 93 | */ |
| 94 | void notifyStateChanged(); |
| 95 | |
| 96 | /** |
| 97 | * Called when the ImsFeature has become unavailable due to the binder switching or app |
| 98 | * crashing. A new ImsServiceProxy should be requested for that feature. |
| 99 | */ |
| 100 | void notifyUnavailable(); |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 101 | } |
| 102 | |
Brad Ebinger | f3cda82 | 2017-11-09 10:25:46 -0800 | [diff] [blame] | 103 | private final IImsServiceFeatureCallback mListenerBinder = |
| 104 | new IImsServiceFeatureCallback.Stub() { |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 105 | |
| 106 | @Override |
| 107 | public void imsFeatureCreated(int slotId, int feature) throws RemoteException { |
| 108 | // The feature has been re-enabled. This may happen when the service crashes. |
| 109 | synchronized (mLock) { |
| 110 | if (!mIsAvailable && mSlotId == slotId && feature == mSupportedFeature) { |
Brad Ebinger | 0e170c7 | 2017-12-14 14:24:02 -0800 | [diff] [blame] | 111 | Log.i(TAG, "Feature enabled on slotId: " + slotId + " for feature: " + |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 112 | feature); |
| 113 | mIsAvailable = true; |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public void imsFeatureRemoved(int slotId, int feature) throws RemoteException { |
| 120 | synchronized (mLock) { |
| 121 | if (mIsAvailable && mSlotId == slotId && feature == mSupportedFeature) { |
Brad Ebinger | 0e170c7 | 2017-12-14 14:24:02 -0800 | [diff] [blame] | 122 | Log.i(TAG, "Feature disabled on slotId: " + slotId + " for feature: " + |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 123 | feature); |
| 124 | mIsAvailable = false; |
Brad Ebinger | 0e170c7 | 2017-12-14 14:24:02 -0800 | [diff] [blame] | 125 | if (mStatusCallback != null) { |
| 126 | mStatusCallback.notifyUnavailable(); |
| 127 | } |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | @Override |
| 133 | public void imsStatusChanged(int slotId, int feature, int status) throws RemoteException { |
| 134 | synchronized (mLock) { |
Brad Ebinger | 0e170c7 | 2017-12-14 14:24:02 -0800 | [diff] [blame] | 135 | Log.i(TAG, "imsStatusChanged: slot: " + slotId + " feature: " + feature + |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 136 | " status: " + status); |
| 137 | if (mSlotId == slotId && feature == mSupportedFeature) { |
| 138 | mFeatureStatusCached = status; |
| 139 | if (mStatusCallback != null) { |
Brad Ebinger | 0e170c7 | 2017-12-14 14:24:02 -0800 | [diff] [blame] | 140 | mStatusCallback.notifyStateChanged(); |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 141 | } |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | }; |
| 146 | |
Brad Ebinger | 3418c13 | 2018-01-18 12:03:33 -0800 | [diff] [blame^] | 147 | public ImsServiceProxy(Context context, int slotId, IBinder binder, int featureType) { |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 148 | mSlotId = slotId; |
| 149 | mBinder = binder; |
| 150 | mSupportedFeature = featureType; |
Brad Ebinger | 3418c13 | 2018-01-18 12:03:33 -0800 | [diff] [blame^] | 151 | mContext = context; |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 152 | } |
| 153 | |
Brad Ebinger | 0e170c7 | 2017-12-14 14:24:02 -0800 | [diff] [blame] | 154 | public ImsServiceProxy(Context context, int slotId, int featureType) { |
Brad Ebinger | 3418c13 | 2018-01-18 12:03:33 -0800 | [diff] [blame^] | 155 | this(context, slotId, null, featureType); |
Brad Ebinger | 0e170c7 | 2017-12-14 14:24:02 -0800 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | public @Nullable IImsRegistration getRegistration() { |
| 159 | TelephonyManager tm = getTelephonyManager(mContext); |
| 160 | return tm != null ? tm.getImsRegistration(mSlotId, ImsFeature.MMTEL) : null; |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 161 | } |
| 162 | |
Brad Ebinger | f3cda82 | 2017-11-09 10:25:46 -0800 | [diff] [blame] | 163 | public IImsServiceFeatureCallback getListener() { |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 164 | return mListenerBinder; |
| 165 | } |
| 166 | |
| 167 | public void setBinder(IBinder binder) { |
| 168 | mBinder = binder; |
| 169 | } |
| 170 | |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 171 | public int startSession(PendingIntent incomingCallIntent, IImsRegistrationListener listener) |
| 172 | throws RemoteException { |
| 173 | synchronized (mLock) { |
| 174 | checkServiceIsReady(); |
Brad Ebinger | f3cda82 | 2017-11-09 10:25:46 -0800 | [diff] [blame] | 175 | return getServiceInterface(mBinder).startSession(incomingCallIntent, listener); |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 179 | public void endSession(int sessionId) throws RemoteException { |
| 180 | synchronized (mLock) { |
| 181 | // Only check to make sure the binder connection still exists. This method should |
| 182 | // still be able to be called when the state is STATE_NOT_AVAILABLE. |
| 183 | checkBinderConnection(); |
Brad Ebinger | f3cda82 | 2017-11-09 10:25:46 -0800 | [diff] [blame] | 184 | getServiceInterface(mBinder).endSession(sessionId); |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 185 | } |
| 186 | } |
| 187 | |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 188 | public boolean isConnected(int callServiceType, int callType) |
| 189 | throws RemoteException { |
| 190 | synchronized (mLock) { |
| 191 | checkServiceIsReady(); |
Brad Ebinger | f3cda82 | 2017-11-09 10:25:46 -0800 | [diff] [blame] | 192 | return getServiceInterface(mBinder).isConnected(callServiceType, callType); |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 196 | public boolean isOpened() throws RemoteException { |
| 197 | synchronized (mLock) { |
| 198 | checkServiceIsReady(); |
Brad Ebinger | f3cda82 | 2017-11-09 10:25:46 -0800 | [diff] [blame] | 199 | return getServiceInterface(mBinder).isOpened(); |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 200 | } |
| 201 | } |
| 202 | |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 203 | public void addRegistrationListener(IImsRegistrationListener listener) |
| 204 | throws RemoteException { |
| 205 | synchronized (mLock) { |
| 206 | checkServiceIsReady(); |
Brad Ebinger | f3cda82 | 2017-11-09 10:25:46 -0800 | [diff] [blame] | 207 | getServiceInterface(mBinder).addRegistrationListener(listener); |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 208 | } |
| 209 | } |
| 210 | |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 211 | public void removeRegistrationListener(IImsRegistrationListener listener) |
| 212 | throws RemoteException { |
| 213 | synchronized (mLock) { |
| 214 | checkServiceIsReady(); |
Brad Ebinger | f3cda82 | 2017-11-09 10:25:46 -0800 | [diff] [blame] | 215 | getServiceInterface(mBinder).removeRegistrationListener(listener); |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 219 | public ImsCallProfile createCallProfile(int sessionId, int callServiceType, int callType) |
| 220 | throws RemoteException { |
| 221 | synchronized (mLock) { |
| 222 | checkServiceIsReady(); |
Brad Ebinger | f3cda82 | 2017-11-09 10:25:46 -0800 | [diff] [blame] | 223 | return getServiceInterface(mBinder).createCallProfile(sessionId, callServiceType, |
| 224 | callType); |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 228 | public IImsCallSession createCallSession(int sessionId, ImsCallProfile profile, |
| 229 | IImsCallSessionListener listener) throws RemoteException { |
| 230 | synchronized (mLock) { |
| 231 | checkServiceIsReady(); |
Brad Ebinger | f3cda82 | 2017-11-09 10:25:46 -0800 | [diff] [blame] | 232 | return getServiceInterface(mBinder).createCallSession(sessionId, profile, listener); |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 236 | public IImsCallSession getPendingCallSession(int sessionId, String callId) |
| 237 | throws RemoteException { |
| 238 | synchronized (mLock) { |
| 239 | checkServiceIsReady(); |
Brad Ebinger | f3cda82 | 2017-11-09 10:25:46 -0800 | [diff] [blame] | 240 | return getServiceInterface(mBinder).getPendingCallSession(sessionId, callId); |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 241 | } |
| 242 | } |
| 243 | |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 244 | public IImsUt getUtInterface() throws RemoteException { |
| 245 | synchronized (mLock) { |
| 246 | checkServiceIsReady(); |
Brad Ebinger | f3cda82 | 2017-11-09 10:25:46 -0800 | [diff] [blame] | 247 | return getServiceInterface(mBinder).getUtInterface(); |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 251 | public IImsConfig getConfigInterface() throws RemoteException { |
| 252 | synchronized (mLock) { |
| 253 | checkServiceIsReady(); |
Brad Ebinger | f3cda82 | 2017-11-09 10:25:46 -0800 | [diff] [blame] | 254 | return getServiceInterface(mBinder).getConfigInterface(); |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 255 | } |
| 256 | } |
| 257 | |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 258 | public void turnOnIms() throws RemoteException { |
| 259 | synchronized (mLock) { |
| 260 | checkServiceIsReady(); |
Brad Ebinger | f3cda82 | 2017-11-09 10:25:46 -0800 | [diff] [blame] | 261 | getServiceInterface(mBinder).turnOnIms(); |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 265 | public void turnOffIms() throws RemoteException { |
| 266 | synchronized (mLock) { |
| 267 | checkServiceIsReady(); |
Brad Ebinger | f3cda82 | 2017-11-09 10:25:46 -0800 | [diff] [blame] | 268 | getServiceInterface(mBinder).turnOffIms(); |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 269 | } |
| 270 | } |
| 271 | |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 272 | public IImsEcbm getEcbmInterface() throws RemoteException { |
| 273 | synchronized (mLock) { |
| 274 | checkServiceIsReady(); |
Brad Ebinger | f3cda82 | 2017-11-09 10:25:46 -0800 | [diff] [blame] | 275 | return getServiceInterface(mBinder).getEcbmInterface(); |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 276 | } |
| 277 | } |
| 278 | |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 279 | public void setUiTTYMode(int uiTtyMode, Message onComplete) |
| 280 | throws RemoteException { |
| 281 | synchronized (mLock) { |
| 282 | checkServiceIsReady(); |
Brad Ebinger | f3cda82 | 2017-11-09 10:25:46 -0800 | [diff] [blame] | 283 | getServiceInterface(mBinder).setUiTTYMode(uiTtyMode, onComplete); |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 284 | } |
| 285 | } |
| 286 | |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 287 | public IImsMultiEndpoint getMultiEndpointInterface() throws RemoteException { |
| 288 | synchronized (mLock) { |
| 289 | checkServiceIsReady(); |
Brad Ebinger | f3cda82 | 2017-11-09 10:25:46 -0800 | [diff] [blame] | 290 | return getServiceInterface(mBinder).getMultiEndpointInterface(); |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 291 | } |
| 292 | } |
| 293 | |
| 294 | /** |
| 295 | * @return an integer describing the current Feature Status, defined in |
| 296 | * {@link ImsFeature.ImsState}. |
| 297 | */ |
| 298 | public int getFeatureStatus() { |
| 299 | synchronized (mLock) { |
| 300 | if (isBinderAlive() && mFeatureStatusCached != null) { |
Brad Ebinger | 0e170c7 | 2017-12-14 14:24:02 -0800 | [diff] [blame] | 301 | Log.i(TAG, "getFeatureStatus - returning cached: " + mFeatureStatusCached); |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 302 | return mFeatureStatusCached; |
| 303 | } |
| 304 | } |
| 305 | // Don't synchronize on Binder call. |
| 306 | Integer status = retrieveFeatureStatus(); |
| 307 | synchronized (mLock) { |
| 308 | if (status == null) { |
| 309 | return ImsFeature.STATE_NOT_AVAILABLE; |
| 310 | } |
| 311 | // Cache only non-null value for feature status. |
| 312 | mFeatureStatusCached = status; |
| 313 | } |
Brad Ebinger | 0e170c7 | 2017-12-14 14:24:02 -0800 | [diff] [blame] | 314 | Log.i(TAG, "getFeatureStatus - returning " + status); |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 315 | return status; |
| 316 | } |
| 317 | |
| 318 | /** |
| 319 | * Internal method used to retrieve the feature status from the corresponding ImsService. |
| 320 | */ |
| 321 | private Integer retrieveFeatureStatus() { |
| 322 | if (mBinder != null) { |
| 323 | try { |
Brad Ebinger | f3cda82 | 2017-11-09 10:25:46 -0800 | [diff] [blame] | 324 | return getServiceInterface(mBinder).getFeatureStatus(); |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 325 | } catch (RemoteException e) { |
| 326 | // Status check failed, don't update cache |
| 327 | } |
| 328 | } |
| 329 | return null; |
| 330 | } |
| 331 | |
| 332 | /** |
| 333 | * @param c Callback that will fire when the feature status has changed. |
| 334 | */ |
Brad Ebinger | 0e170c7 | 2017-12-14 14:24:02 -0800 | [diff] [blame] | 335 | public void setStatusCallback(IFeatureUpdate c) { |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 336 | mStatusCallback = c; |
| 337 | } |
| 338 | |
| 339 | /** |
| 340 | * @return Returns true if the ImsService is ready to take commands, false otherwise. If this |
| 341 | * method returns false, it doesn't mean that the Binder connection is not available (use |
| 342 | * {@link #isBinderReady()} to check that), but that the ImsService is not accepting commands |
| 343 | * at this time. |
| 344 | * |
| 345 | * For example, for DSDS devices, only one slot can be {@link ImsFeature#STATE_READY} to take |
| 346 | * commands at a time, so the other slot must stay at {@link ImsFeature#STATE_NOT_AVAILABLE}. |
| 347 | */ |
| 348 | public boolean isBinderReady() { |
| 349 | return isBinderAlive() && getFeatureStatus() == ImsFeature.STATE_READY; |
| 350 | } |
| 351 | |
| 352 | /** |
| 353 | * @return false if the binder connection is no longer alive. |
| 354 | */ |
| 355 | public boolean isBinderAlive() { |
| 356 | return mIsAvailable && mBinder != null && mBinder.isBinderAlive(); |
| 357 | } |
| 358 | |
| 359 | protected void checkServiceIsReady() throws RemoteException { |
| 360 | if (!isBinderReady()) { |
| 361 | throw new RemoteException("ImsServiceProxy is not ready to accept commands."); |
| 362 | } |
| 363 | } |
| 364 | |
Brad Ebinger | f3cda82 | 2017-11-09 10:25:46 -0800 | [diff] [blame] | 365 | private IImsMMTelFeature getServiceInterface(IBinder b) { |
| 366 | return IImsMMTelFeature.Stub.asInterface(b); |
Brad Ebinger | 89fb564 | 2017-11-06 15:17:32 -0800 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | protected void checkBinderConnection() throws RemoteException { |
| 370 | if (!isBinderAlive()) { |
| 371 | throw new RemoteException("ImsServiceProxy is not available for that feature."); |
| 372 | } |
| 373 | } |
| 374 | } |