James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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.phone; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.net.Uri; |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 21 | import android.os.Binder; |
| 22 | import android.os.RemoteException; |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 23 | import android.os.ServiceManager; |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 24 | import android.os.ServiceSpecificException; |
Brad Ebinger | 6e3543b | 2020-01-22 17:51:55 -0800 | [diff] [blame] | 25 | import android.telephony.SubscriptionManager; |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 26 | import android.telephony.ims.ImsException; |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 27 | import android.telephony.ims.RegistrationManager; |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 28 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
| 29 | import android.telephony.ims.aidl.IImsRcsController; |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 30 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 31 | import android.telephony.ims.aidl.IRcsUceControllerCallback; |
James.cf Lin | cdad386 | 2020-02-25 15:55:03 +0800 | [diff] [blame^] | 32 | import android.telephony.ims.aidl.IRcsUcePublishStateCallback; |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 33 | import android.telephony.ims.feature.RcsFeature; |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 34 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 35 | import android.util.Log; |
| 36 | |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 37 | import com.android.ims.ImsManager; |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 38 | import com.android.internal.telephony.IIntegerConsumer; |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 39 | import com.android.internal.telephony.Phone; |
| 40 | import com.android.internal.telephony.imsphone.ImsPhone; |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 41 | import com.android.services.telephony.rcs.RcsFeatureController; |
James.cf Lin | c9f35a4 | 2020-01-15 02:35:22 +0800 | [diff] [blame] | 42 | import com.android.services.telephony.rcs.TelephonyRcsService; |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 43 | import com.android.services.telephony.rcs.UserCapabilityExchangeImpl; |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 44 | |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 45 | import java.util.List; |
| 46 | |
| 47 | /** |
| 48 | * Implementation of the IImsRcsController interface. |
| 49 | */ |
| 50 | public class ImsRcsController extends IImsRcsController.Stub { |
| 51 | private static final String TAG = "ImsRcsController"; |
| 52 | |
| 53 | /** The singleton instance. */ |
| 54 | private static ImsRcsController sInstance; |
| 55 | |
| 56 | private PhoneGlobals mApp; |
James.cf Lin | c9f35a4 | 2020-01-15 02:35:22 +0800 | [diff] [blame] | 57 | private TelephonyRcsService mRcsService; |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 58 | |
| 59 | /** |
| 60 | * Initialize the singleton ImsRcsController instance. |
| 61 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 62 | */ |
| 63 | static ImsRcsController init(PhoneGlobals app) { |
| 64 | synchronized (ImsRcsController.class) { |
| 65 | if (sInstance == null) { |
| 66 | sInstance = new ImsRcsController(app); |
| 67 | } else { |
| 68 | Log.wtf(TAG, "init() called multiple times! sInstance = " + sInstance); |
| 69 | } |
| 70 | return sInstance; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | /** Private constructor; @see init() */ |
| 75 | private ImsRcsController(PhoneGlobals app) { |
| 76 | Log.i(TAG, "ImsRcsController"); |
| 77 | mApp = app; |
| 78 | ServiceManager.addService(Context.TELEPHONY_IMS_SERVICE, this); |
| 79 | } |
| 80 | |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 81 | /** |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 82 | * Register a {@link RegistrationManager.RegistrationCallback} to receive IMS network |
| 83 | * registration state. |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 84 | */ |
| 85 | @Override |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 86 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback callback) { |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 87 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
| 88 | final long token = Binder.clearCallingIdentity(); |
| 89 | try { |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 90 | getRcsFeatureController(subId).registerImsRegistrationCallback(subId, callback); |
| 91 | } catch (ImsException e) { |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 92 | Log.e(TAG, "registerImsRegistrationCallback: sudId=" + subId + ", " + e.getMessage()); |
| 93 | throw new ServiceSpecificException(e.getCode()); |
| 94 | } finally { |
| 95 | Binder.restoreCallingIdentity(token); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | /** |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 100 | * Removes an existing {@link RegistrationManager.RegistrationCallback}. |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 101 | */ |
| 102 | @Override |
| 103 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback callback) { |
| 104 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
| 105 | final long token = Binder.clearCallingIdentity(); |
| 106 | try { |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 107 | getRcsFeatureController(subId).unregisterImsRegistrationCallback(subId, callback); |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 108 | } catch (ServiceSpecificException e) { |
| 109 | Log.e(TAG, "unregisterImsRegistrationCallback: error=" + e.errorCode); |
| 110 | } finally { |
| 111 | Binder.restoreCallingIdentity(token); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Get the IMS service registration state for the RcsFeature associated with this sub id. |
| 117 | */ |
| 118 | @Override |
| 119 | public void getImsRcsRegistrationState(int subId, IIntegerConsumer consumer) { |
| 120 | enforceReadPrivilegedPermission("getImsRcsRegistrationState"); |
| 121 | final long token = Binder.clearCallingIdentity(); |
| 122 | try { |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 123 | getRcsFeatureController(subId).getRegistrationState(regState -> { |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 124 | try { |
| 125 | consumer.accept((regState == null) |
| 126 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 127 | } catch (RemoteException e) { |
| 128 | Log.w(TAG, "getImsRcsRegistrationState: callback is not available."); |
| 129 | } |
| 130 | }); |
| 131 | } finally { |
| 132 | Binder.restoreCallingIdentity(token); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Gets the Transport Type associated with the current IMS RCS registration. |
| 138 | */ |
| 139 | @Override |
| 140 | public void getImsRcsRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
| 141 | enforceReadPrivilegedPermission("getImsRcsRegistrationTransportType"); |
| 142 | final long token = Binder.clearCallingIdentity(); |
| 143 | try { |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 144 | getRcsFeatureController(subId).getRegistrationTech(regTech -> { |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 145 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 146 | int regTechConverted = (regTech == null) |
| 147 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 148 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 149 | regTechConverted); |
| 150 | try { |
| 151 | consumer.accept(regTechConverted); |
| 152 | } catch (RemoteException e) { |
| 153 | Log.w(TAG, "getImsRcsRegistrationTransportType: callback is not available."); |
| 154 | } |
| 155 | }); |
| 156 | } finally { |
| 157 | Binder.restoreCallingIdentity(token); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | /** |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 162 | * Register a capability callback which will provide RCS availability updates for the |
| 163 | * subscription specified. |
| 164 | * |
| 165 | * @param subId the subscription ID |
| 166 | * @param callback The ImsCapabilityCallback to be registered. |
| 167 | */ |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 168 | @Override |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 169 | public void registerRcsAvailabilityCallback(int subId, IImsCapabilityCallback callback) { |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 170 | enforceReadPrivilegedPermission("registerRcsAvailabilityCallback"); |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 171 | final long token = Binder.clearCallingIdentity(); |
| 172 | try { |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 173 | getRcsFeatureController(subId).registerRcsAvailabilityCallback(subId, callback); |
| 174 | } catch (ImsException e) { |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 175 | Log.e(TAG, "registerRcsAvailabilityCallback: sudId=" + subId + ", " + e.getMessage()); |
| 176 | throw new ServiceSpecificException(e.getCode()); |
| 177 | } finally { |
| 178 | Binder.restoreCallingIdentity(token); |
| 179 | } |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 180 | } |
| 181 | |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 182 | /** |
| 183 | * Remove the registered capability callback. |
| 184 | * |
| 185 | * @param subId the subscription ID |
| 186 | * @param callback The ImsCapabilityCallback to be removed. |
| 187 | */ |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 188 | @Override |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 189 | public void unregisterRcsAvailabilityCallback(int subId, IImsCapabilityCallback callback) { |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 190 | enforceReadPrivilegedPermission("unregisterRcsAvailabilityCallback"); |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 191 | final long token = Binder.clearCallingIdentity(); |
| 192 | try { |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 193 | getRcsFeatureController(subId).unregisterRcsAvailabilityCallback(subId, callback); |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 194 | } finally { |
| 195 | Binder.restoreCallingIdentity(token); |
| 196 | } |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 197 | } |
| 198 | |
James.cf Lin | cdad386 | 2020-02-25 15:55:03 +0800 | [diff] [blame^] | 199 | @Override |
| 200 | public void registerUcePublishStateCallback(int subId, IRcsUcePublishStateCallback c) { |
| 201 | enforceReadPrivilegedPermission("registerUcePublishStateCallback"); |
| 202 | final long token = Binder.clearCallingIdentity(); |
| 203 | try { |
| 204 | UserCapabilityExchangeImpl uce = getRcsFeatureController(subId).getFeature( |
| 205 | UserCapabilityExchangeImpl.class); |
| 206 | if (uce == null) { |
| 207 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 208 | "This subscription does not support UCE."); |
| 209 | } |
| 210 | uce.registerPublishStateCallback(c); |
| 211 | } finally { |
| 212 | Binder.restoreCallingIdentity(token); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | @Override |
| 217 | public void unregisterUcePublishStateCallback(int subId, IRcsUcePublishStateCallback c) { |
| 218 | enforceReadPrivilegedPermission("unregisterUcePublishStateCallback"); |
| 219 | final long token = Binder.clearCallingIdentity(); |
| 220 | try { |
| 221 | UserCapabilityExchangeImpl uce = getRcsFeatureController(subId).getFeature( |
| 222 | UserCapabilityExchangeImpl.class); |
| 223 | if (uce == null) { |
| 224 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 225 | "This subscription does not support UCE."); |
| 226 | } |
| 227 | uce.unregisterUcePublishStateCallback(c); |
| 228 | } finally { |
| 229 | Binder.restoreCallingIdentity(token); |
| 230 | } |
| 231 | } |
| 232 | |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 233 | /** |
| 234 | * Query for the capability of an IMS RCS service |
| 235 | * |
| 236 | * @param subId the subscription ID |
| 237 | * @param capability the RCS capability to query. |
| 238 | * @param radioTech the radio tech that this capability failed for |
| 239 | * @return true if the RCS capability is capable for this subscription, false otherwise. |
| 240 | */ |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 241 | @Override |
| 242 | public boolean isCapable(int subId, |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 243 | @RcsFeature.RcsImsCapabilities.RcsImsCapabilityFlag int capability, |
| 244 | @ImsRegistrationImplBase.ImsRegistrationTech int radioTech) { |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 245 | enforceReadPrivilegedPermission("isCapable"); |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 246 | final long token = Binder.clearCallingIdentity(); |
| 247 | try { |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 248 | return getRcsFeatureController(subId).isCapable(capability, radioTech); |
| 249 | } catch (ImsException e) { |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 250 | Log.e(TAG, "isCapable: sudId=" + subId |
| 251 | + ", capability=" + capability + ", " + e.getMessage()); |
| 252 | return false; |
| 253 | } finally { |
| 254 | Binder.restoreCallingIdentity(token); |
| 255 | } |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 256 | } |
| 257 | |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 258 | /** |
| 259 | * Query the availability of an IMS RCS capability. |
| 260 | * |
| 261 | * @param subId the subscription ID |
| 262 | * @param capability the RCS capability to query. |
| 263 | * @return true if the RCS capability is currently available for the associated subscription, |
| 264 | * false otherwise. |
| 265 | */ |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 266 | @Override |
| 267 | public boolean isAvailable(int subId, |
| 268 | @RcsFeature.RcsImsCapabilities.RcsImsCapabilityFlag int capability) { |
| 269 | enforceReadPrivilegedPermission("isAvailable"); |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 270 | final long token = Binder.clearCallingIdentity(); |
| 271 | try { |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 272 | return getRcsFeatureController(subId).isAvailable(capability); |
| 273 | } catch (ImsException e) { |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 274 | Log.e(TAG, "isAvailable: sudId=" + subId |
| 275 | + ", capability=" + capability + ", " + e.getMessage()); |
| 276 | return false; |
| 277 | } finally { |
| 278 | Binder.restoreCallingIdentity(token); |
| 279 | } |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | @Override |
| 283 | public void requestCapabilities(int subId, List<Uri> contactNumbers, |
| 284 | IRcsUceControllerCallback c) { |
| 285 | enforceReadPrivilegedPermission("requestCapabilities"); |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 286 | final long token = Binder.clearCallingIdentity(); |
| 287 | try { |
| 288 | UserCapabilityExchangeImpl uce = getRcsFeatureController(subId).getFeature( |
| 289 | UserCapabilityExchangeImpl.class); |
| 290 | if (uce == null) { |
| 291 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 292 | "This subscription does not support UCE."); |
| 293 | } |
| 294 | uce.requestCapabilities(contactNumbers, c); |
| 295 | } finally { |
| 296 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 278e9bf | 2020-01-22 14:17:23 -0800 | [diff] [blame] | 297 | } |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | @Override |
| 301 | public int getUcePublishState(int subId) { |
| 302 | enforceReadPrivilegedPermission("getUcePublishState"); |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 303 | final long token = Binder.clearCallingIdentity(); |
| 304 | try { |
| 305 | UserCapabilityExchangeImpl uce = getRcsFeatureController(subId).getFeature( |
| 306 | UserCapabilityExchangeImpl.class); |
| 307 | if (uce == null) { |
| 308 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 309 | "This subscription does not support UCE."); |
| 310 | } |
| 311 | return uce.getUcePublishState(); |
| 312 | } finally { |
| 313 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 278e9bf | 2020-01-22 14:17:23 -0800 | [diff] [blame] | 314 | } |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | @Override |
| 318 | public boolean isUceSettingEnabled(int subId) { |
| 319 | enforceReadPrivilegedPermission("isUceSettingEnabled"); |
Brad Ebinger | 6e3543b | 2020-01-22 17:51:55 -0800 | [diff] [blame] | 320 | return SubscriptionManager.getBooleanSubscriptionProperty(subId, |
| 321 | SubscriptionManager.IMS_RCS_UCE_ENABLED, false /*defaultValue*/, mApp); |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | @Override |
| 325 | public void setUceSettingEnabled(int subId, boolean isEnabled) { |
| 326 | enforceModifyPermission(); |
Brad Ebinger | 6e3543b | 2020-01-22 17:51:55 -0800 | [diff] [blame] | 327 | SubscriptionManager.setSubscriptionProperty(subId, SubscriptionManager.IMS_RCS_UCE_ENABLED, |
| 328 | (isEnabled ? "1" : "0")); |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | /** |
| 332 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 333 | * |
| 334 | * @throws SecurityException if the caller does not have the required permission |
| 335 | */ |
| 336 | private void enforceReadPrivilegedPermission(String message) { |
| 337 | mApp.enforceCallingOrSelfPermission( |
| 338 | android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message); |
| 339 | } |
| 340 | |
| 341 | /** |
| 342 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 343 | * |
| 344 | * @throws SecurityException if the caller does not have the required permission |
| 345 | */ |
| 346 | private void enforceModifyPermission() { |
| 347 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 348 | } |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 349 | |
| 350 | /** |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 351 | * Retrieve ImsPhone instance. |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 352 | * |
| 353 | * @param subId the subscription ID |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 354 | * @return The ImsPhone instance |
| 355 | * @throws ServiceSpecificException if getting ImsPhone instance failed. |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 356 | */ |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 357 | private ImsPhone getImsPhone(int subId) { |
| 358 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 359 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 360 | "IMS is not available on device."); |
| 361 | } |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 362 | Phone phone = PhoneGlobals.getPhone(subId); |
| 363 | if (phone == null) { |
| 364 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 365 | "Invalid subscription Id: " + subId); |
| 366 | } |
| 367 | ImsPhone imsPhone = (ImsPhone) phone.getImsPhone(); |
| 368 | if (imsPhone == null) { |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 369 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 370 | "Cannot find ImsPhone instance: " + subId); |
| 371 | } |
| 372 | return imsPhone; |
| 373 | } |
| 374 | |
| 375 | /** |
| 376 | * Retrieve RcsFeatureManager instance. |
| 377 | * |
| 378 | * @param subId the subscription ID |
| 379 | * @return The RcsFeatureManager instance |
| 380 | * @throws ServiceSpecificException if getting RcsFeatureManager instance failed. |
| 381 | */ |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 382 | private RcsFeatureController getRcsFeatureController(int subId) { |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 383 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 384 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 385 | "IMS is not available on device."); |
| 386 | } |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 387 | if (mRcsService == null) { |
| 388 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 389 | "IMS is not available on device."); |
| 390 | } |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 391 | Phone phone = PhoneGlobals.getPhone(subId); |
| 392 | if (phone == null) { |
| 393 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 394 | "Invalid subscription Id: " + subId); |
| 395 | } |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 396 | int slotId = phone.getPhoneId(); |
| 397 | RcsFeatureController c = mRcsService.getFeatureController(slotId); |
| 398 | if (c == null) { |
Brad Ebinger | 036dc9e | 2020-02-06 15:49:06 -0800 | [diff] [blame] | 399 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 400 | "The requested operation is not supported for subId " + subId); |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 401 | } |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 402 | return c; |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 403 | } |
James.cf Lin | c9f35a4 | 2020-01-15 02:35:22 +0800 | [diff] [blame] | 404 | |
| 405 | void setRcsService(TelephonyRcsService rcsService) { |
| 406 | mRcsService = rcsService; |
| 407 | } |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 408 | } |