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