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 | |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame^] | 19 | import android.Manifest; |
James.cf Lin | 051dd25 | 2021-01-21 03:30:54 +0800 | [diff] [blame] | 20 | import android.app.ActivityManager; |
Brad Ebinger | 63b6f5a | 2020-10-27 11:43:35 -0700 | [diff] [blame] | 21 | import android.content.pm.PackageManager; |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 22 | import android.net.Uri; |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 23 | import android.os.Binder; |
| 24 | import android.os.RemoteException; |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 25 | import android.os.ServiceSpecificException; |
Brad Ebinger | 63b6f5a | 2020-10-27 11:43:35 -0700 | [diff] [blame] | 26 | import android.os.UserHandle; |
Brad Ebinger | b7a866a | 2020-01-22 17:51:55 -0800 | [diff] [blame] | 27 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 28 | import android.telephony.TelephonyFrameworkInitializer; |
Brad Ebinger | af1e983 | 2020-10-14 10:49:28 -0700 | [diff] [blame] | 29 | import android.telephony.ims.DelegateRequest; |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 30 | import android.telephony.ims.ImsException; |
James.cf Lin | 99a360d | 2020-11-04 10:48:37 +0800 | [diff] [blame] | 31 | import android.telephony.ims.RcsUceAdapter.PublishState; |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 32 | import android.telephony.ims.RegistrationManager; |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 33 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
| 34 | import android.telephony.ims.aidl.IImsRcsController; |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 35 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 36 | import android.telephony.ims.aidl.IRcsUceControllerCallback; |
James.cf Lin | cdad386 | 2020-02-25 15:55:03 +0800 | [diff] [blame] | 37 | import android.telephony.ims.aidl.IRcsUcePublishStateCallback; |
Brad Ebinger | af1e983 | 2020-10-14 10:49:28 -0700 | [diff] [blame] | 38 | import android.telephony.ims.aidl.ISipDelegate; |
| 39 | import android.telephony.ims.aidl.ISipDelegateConnectionStateCallback; |
| 40 | import android.telephony.ims.aidl.ISipDelegateMessageCallback; |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 41 | import android.telephony.ims.feature.ImsFeature; |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 42 | import android.telephony.ims.feature.RcsFeature; |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 43 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 44 | import android.util.Log; |
| 45 | |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 46 | import com.android.ims.ImsManager; |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 47 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 48 | import com.android.internal.telephony.IIntegerConsumer; |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 49 | import com.android.internal.telephony.Phone; |
Brad Ebinger | 8b79edc | 2020-02-27 19:13:24 -0800 | [diff] [blame] | 50 | import com.android.internal.telephony.TelephonyPermissions; |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 51 | import com.android.internal.telephony.ims.ImsResolver; |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 52 | import com.android.internal.telephony.imsphone.ImsPhone; |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 53 | import com.android.services.telephony.rcs.RcsFeatureController; |
Brad Ebinger | b989c7c | 2020-09-23 17:03:48 -0700 | [diff] [blame] | 54 | import com.android.services.telephony.rcs.SipTransportController; |
James.cf Lin | c9f35a4 | 2020-01-15 02:35:22 +0800 | [diff] [blame] | 55 | import com.android.services.telephony.rcs.TelephonyRcsService; |
James.cf Lin | 99a360d | 2020-11-04 10:48:37 +0800 | [diff] [blame] | 56 | import com.android.services.telephony.rcs.UceControllerManager; |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 57 | |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 58 | import java.util.List; |
| 59 | |
| 60 | /** |
| 61 | * Implementation of the IImsRcsController interface. |
| 62 | */ |
| 63 | public class ImsRcsController extends IImsRcsController.Stub { |
| 64 | private static final String TAG = "ImsRcsController"; |
| 65 | |
| 66 | /** The singleton instance. */ |
| 67 | private static ImsRcsController sInstance; |
| 68 | |
| 69 | private PhoneGlobals mApp; |
James.cf Lin | c9f35a4 | 2020-01-15 02:35:22 +0800 | [diff] [blame] | 70 | private TelephonyRcsService mRcsService; |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 71 | private ImsResolver mImsResolver; |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 72 | // set by shell cmd phone src set-device-enabled true/false |
| 73 | private Boolean mSingleRegistrationOverride; |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * Initialize the singleton ImsRcsController instance. |
| 77 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 78 | */ |
| 79 | static ImsRcsController init(PhoneGlobals app) { |
| 80 | synchronized (ImsRcsController.class) { |
| 81 | if (sInstance == null) { |
| 82 | sInstance = new ImsRcsController(app); |
| 83 | } else { |
| 84 | Log.wtf(TAG, "init() called multiple times! sInstance = " + sInstance); |
| 85 | } |
| 86 | return sInstance; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | /** Private constructor; @see init() */ |
| 91 | private ImsRcsController(PhoneGlobals app) { |
| 92 | Log.i(TAG, "ImsRcsController"); |
| 93 | mApp = app; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 94 | TelephonyFrameworkInitializer |
| 95 | .getTelephonyServiceManager().getTelephonyImsServiceRegisterer().register(this); |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 96 | mImsResolver = mApp.getImsResolver(); |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 97 | } |
| 98 | |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 99 | /** |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 100 | * Register a {@link RegistrationManager.RegistrationCallback} to receive IMS network |
| 101 | * registration state. |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 102 | */ |
| 103 | @Override |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 104 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback callback) { |
James.cf Lin | f020d16 | 2021-01-31 22:15:52 +0800 | [diff] [blame] | 105 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 106 | mApp, subId, "registerImsRegistrationCallback"); |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 107 | final long token = Binder.clearCallingIdentity(); |
| 108 | try { |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 109 | getRcsFeatureController(subId).registerImsRegistrationCallback(subId, callback); |
| 110 | } catch (ImsException e) { |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 111 | Log.e(TAG, "registerImsRegistrationCallback: sudId=" + subId + ", " + e.getMessage()); |
| 112 | throw new ServiceSpecificException(e.getCode()); |
| 113 | } finally { |
| 114 | Binder.restoreCallingIdentity(token); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | /** |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 119 | * Removes an existing {@link RegistrationManager.RegistrationCallback}. |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 120 | */ |
| 121 | @Override |
| 122 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback callback) { |
James.cf Lin | f020d16 | 2021-01-31 22:15:52 +0800 | [diff] [blame] | 123 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 124 | mApp, subId, "unregisterImsRegistrationCallback"); |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 125 | final long token = Binder.clearCallingIdentity(); |
| 126 | try { |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 127 | getRcsFeatureController(subId).unregisterImsRegistrationCallback(subId, callback); |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 128 | } catch (ServiceSpecificException e) { |
| 129 | Log.e(TAG, "unregisterImsRegistrationCallback: error=" + e.errorCode); |
| 130 | } finally { |
| 131 | Binder.restoreCallingIdentity(token); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Get the IMS service registration state for the RcsFeature associated with this sub id. |
| 137 | */ |
| 138 | @Override |
| 139 | public void getImsRcsRegistrationState(int subId, IIntegerConsumer consumer) { |
James.cf Lin | f020d16 | 2021-01-31 22:15:52 +0800 | [diff] [blame] | 140 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 141 | mApp, subId, "getImsRcsRegistrationState"); |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 142 | final long token = Binder.clearCallingIdentity(); |
| 143 | try { |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 144 | getRcsFeatureController(subId).getRegistrationState(regState -> { |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 145 | try { |
| 146 | consumer.accept((regState == null) |
| 147 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 148 | } catch (RemoteException e) { |
| 149 | Log.w(TAG, "getImsRcsRegistrationState: callback is not available."); |
| 150 | } |
| 151 | }); |
| 152 | } finally { |
| 153 | Binder.restoreCallingIdentity(token); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Gets the Transport Type associated with the current IMS RCS registration. |
| 159 | */ |
| 160 | @Override |
| 161 | public void getImsRcsRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
James.cf Lin | f020d16 | 2021-01-31 22:15:52 +0800 | [diff] [blame] | 162 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 163 | mApp, subId, "getImsRcsRegistrationTransportType"); |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 164 | final long token = Binder.clearCallingIdentity(); |
| 165 | try { |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 166 | getRcsFeatureController(subId).getRegistrationTech(regTech -> { |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 167 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 168 | int regTechConverted = (regTech == null) |
| 169 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 170 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 171 | regTechConverted); |
| 172 | try { |
| 173 | consumer.accept(regTechConverted); |
| 174 | } catch (RemoteException e) { |
| 175 | Log.w(TAG, "getImsRcsRegistrationTransportType: callback is not available."); |
| 176 | } |
| 177 | }); |
| 178 | } finally { |
| 179 | Binder.restoreCallingIdentity(token); |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | /** |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 184 | * Register a capability callback which will provide RCS availability updates for the |
| 185 | * subscription specified. |
| 186 | * |
| 187 | * @param subId the subscription ID |
| 188 | * @param callback The ImsCapabilityCallback to be registered. |
| 189 | */ |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 190 | @Override |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 191 | public void registerRcsAvailabilityCallback(int subId, IImsCapabilityCallback callback) { |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 192 | enforceReadPrivilegedPermission("registerRcsAvailabilityCallback"); |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 193 | final long token = Binder.clearCallingIdentity(); |
| 194 | try { |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 195 | getRcsFeatureController(subId).registerRcsAvailabilityCallback(subId, callback); |
| 196 | } catch (ImsException e) { |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 197 | Log.e(TAG, "registerRcsAvailabilityCallback: sudId=" + subId + ", " + e.getMessage()); |
| 198 | throw new ServiceSpecificException(e.getCode()); |
| 199 | } finally { |
| 200 | Binder.restoreCallingIdentity(token); |
| 201 | } |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 202 | } |
| 203 | |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 204 | /** |
| 205 | * Remove the registered capability callback. |
| 206 | * |
| 207 | * @param subId the subscription ID |
| 208 | * @param callback The ImsCapabilityCallback to be removed. |
| 209 | */ |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 210 | @Override |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 211 | public void unregisterRcsAvailabilityCallback(int subId, IImsCapabilityCallback callback) { |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 212 | enforceReadPrivilegedPermission("unregisterRcsAvailabilityCallback"); |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 213 | final long token = Binder.clearCallingIdentity(); |
| 214 | try { |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 215 | getRcsFeatureController(subId).unregisterRcsAvailabilityCallback(subId, callback); |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 216 | } finally { |
| 217 | Binder.restoreCallingIdentity(token); |
| 218 | } |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 219 | } |
| 220 | |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 221 | /** |
| 222 | * Query for the capability of an IMS RCS service |
| 223 | * |
| 224 | * @param subId the subscription ID |
| 225 | * @param capability the RCS capability to query. |
James.cf Lin | f020d16 | 2021-01-31 22:15:52 +0800 | [diff] [blame] | 226 | * @param radioTech the radio technology type that we are querying. |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 227 | * @return true if the RCS capability is capable for this subscription, false otherwise. |
| 228 | */ |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 229 | @Override |
| 230 | public boolean isCapable(int subId, |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 231 | @RcsFeature.RcsImsCapabilities.RcsImsCapabilityFlag int capability, |
| 232 | @ImsRegistrationImplBase.ImsRegistrationTech int radioTech) { |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 233 | enforceReadPrivilegedPermission("isCapable"); |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 234 | final long token = Binder.clearCallingIdentity(); |
| 235 | try { |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 236 | return getRcsFeatureController(subId).isCapable(capability, radioTech); |
| 237 | } catch (ImsException e) { |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 238 | Log.e(TAG, "isCapable: sudId=" + subId |
| 239 | + ", capability=" + capability + ", " + e.getMessage()); |
| 240 | return false; |
| 241 | } finally { |
| 242 | Binder.restoreCallingIdentity(token); |
| 243 | } |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 244 | } |
| 245 | |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 246 | /** |
| 247 | * Query the availability of an IMS RCS capability. |
| 248 | * |
| 249 | * @param subId the subscription ID |
| 250 | * @param capability the RCS capability to query. |
| 251 | * @return true if the RCS capability is currently available for the associated subscription, |
James.cf Lin | f020d16 | 2021-01-31 22:15:52 +0800 | [diff] [blame] | 252 | * @param radioTech the radio technology type that we are querying. |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 253 | * false otherwise. |
| 254 | */ |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 255 | @Override |
| 256 | public boolean isAvailable(int subId, |
James.cf Lin | f020d16 | 2021-01-31 22:15:52 +0800 | [diff] [blame] | 257 | @RcsFeature.RcsImsCapabilities.RcsImsCapabilityFlag int capability, |
| 258 | @ImsRegistrationImplBase.ImsRegistrationTech int radioTech) { |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 259 | enforceReadPrivilegedPermission("isAvailable"); |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 260 | final long token = Binder.clearCallingIdentity(); |
| 261 | try { |
James.cf Lin | f020d16 | 2021-01-31 22:15:52 +0800 | [diff] [blame] | 262 | return getRcsFeatureController(subId).isAvailable(capability, radioTech); |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 263 | } catch (ImsException e) { |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 264 | Log.e(TAG, "isAvailable: sudId=" + subId |
| 265 | + ", capability=" + capability + ", " + e.getMessage()); |
| 266 | return false; |
| 267 | } finally { |
| 268 | Binder.restoreCallingIdentity(token); |
| 269 | } |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | @Override |
Brad Ebinger | 8b79edc | 2020-02-27 19:13:24 -0800 | [diff] [blame] | 273 | public void requestCapabilities(int subId, String callingPackage, String callingFeatureId, |
| 274 | List<Uri> contactNumbers, IRcsUceControllerCallback c) { |
James.cf Lin | 051dd25 | 2021-01-21 03:30:54 +0800 | [diff] [blame] | 275 | enforceAccessUserCapabilityExchangePermission("requestCapabilities"); |
| 276 | enforceReadContactsPermission("requestCapabilities"); |
| 277 | if (!isCallingProcessInForeground(Binder.getCallingUid())) { |
| 278 | throw new SecurityException("The caller is not in the foreground."); |
| 279 | } |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 280 | final long token = Binder.clearCallingIdentity(); |
| 281 | try { |
James.cf Lin | 99a360d | 2020-11-04 10:48:37 +0800 | [diff] [blame] | 282 | UceControllerManager uceCtrlManager = getRcsFeatureController(subId).getFeature( |
| 283 | UceControllerManager.class); |
| 284 | if (uceCtrlManager == null) { |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 285 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 286 | "This subscription does not support UCE."); |
| 287 | } |
James.cf Lin | 99a360d | 2020-11-04 10:48:37 +0800 | [diff] [blame] | 288 | uceCtrlManager.requestCapabilities(contactNumbers, c); |
| 289 | } catch (ImsException e) { |
| 290 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 291 | } finally { |
| 292 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 1aa9499 | 2020-01-22 14:17:23 -0800 | [diff] [blame] | 293 | } |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | @Override |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 297 | public void requestAvailability(int subId, String callingPackage, |
James.cf Lin | 64e9121 | 2020-10-30 01:09:52 +0800 | [diff] [blame] | 298 | String callingFeatureId, Uri contactNumber, IRcsUceControllerCallback c) { |
James.cf Lin | 051dd25 | 2021-01-21 03:30:54 +0800 | [diff] [blame] | 299 | enforceAccessUserCapabilityExchangePermission("requestAvailability"); |
| 300 | enforceReadContactsPermission("requestAvailability"); |
| 301 | if (!isCallingProcessInForeground(Binder.getCallingUid())) { |
| 302 | throw new SecurityException("The caller is not in the foreground."); |
| 303 | } |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 304 | final long token = Binder.clearCallingIdentity(); |
| 305 | try { |
James.cf Lin | 99a360d | 2020-11-04 10:48:37 +0800 | [diff] [blame] | 306 | UceControllerManager uceCtrlManager = getRcsFeatureController(subId).getFeature( |
| 307 | UceControllerManager.class); |
| 308 | if (uceCtrlManager == null) { |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 309 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 310 | "This subscription does not support UCE."); |
| 311 | } |
James.cf Lin | 99a360d | 2020-11-04 10:48:37 +0800 | [diff] [blame] | 312 | uceCtrlManager.requestNetworkAvailability(contactNumber, c); |
| 313 | } catch (ImsException e) { |
| 314 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 315 | } finally { |
| 316 | Binder.restoreCallingIdentity(token); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | @Override |
| 321 | public @PublishState int getUcePublishState(int subId) { |
| 322 | enforceReadPrivilegedPermission("getUcePublishState"); |
| 323 | final long token = Binder.clearCallingIdentity(); |
| 324 | try { |
| 325 | UceControllerManager uceCtrlManager = getRcsFeatureController(subId).getFeature( |
| 326 | UceControllerManager.class); |
| 327 | if (uceCtrlManager == null) { |
| 328 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 329 | "This subscription does not support UCE."); |
| 330 | } |
| 331 | return uceCtrlManager.getUcePublishState(); |
| 332 | } catch (ImsException e) { |
| 333 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 334 | } finally { |
| 335 | Binder.restoreCallingIdentity(token); |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | @Override |
| 340 | public void registerUcePublishStateCallback(int subId, IRcsUcePublishStateCallback c) { |
| 341 | enforceReadPrivilegedPermission("registerUcePublishStateCallback"); |
| 342 | final long token = Binder.clearCallingIdentity(); |
| 343 | try { |
| 344 | UceControllerManager uceCtrlManager = getRcsFeatureController(subId).getFeature( |
| 345 | UceControllerManager.class); |
| 346 | if (uceCtrlManager == null) { |
| 347 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 348 | "This subscription does not support UCE."); |
| 349 | } |
| 350 | uceCtrlManager.registerPublishStateCallback(c); |
| 351 | } catch (ImsException e) { |
| 352 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 353 | } finally { |
| 354 | Binder.restoreCallingIdentity(token); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | @Override |
| 359 | public void unregisterUcePublishStateCallback(int subId, IRcsUcePublishStateCallback c) { |
| 360 | enforceReadPrivilegedPermission("unregisterUcePublishStateCallback"); |
| 361 | final long token = Binder.clearCallingIdentity(); |
| 362 | try { |
| 363 | UceControllerManager uceCtrlManager = getRcsFeatureController(subId).getFeature( |
| 364 | UceControllerManager.class); |
| 365 | if (uceCtrlManager == null) { |
| 366 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 367 | "This subscription does not support UCE."); |
| 368 | } |
| 369 | uceCtrlManager.unregisterPublishStateCallback(c); |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 370 | } finally { |
| 371 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 1aa9499 | 2020-01-22 14:17:23 -0800 | [diff] [blame] | 372 | } |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | @Override |
Brad Ebinger | 8b79edc | 2020-02-27 19:13:24 -0800 | [diff] [blame] | 376 | public boolean isUceSettingEnabled(int subId, String callingPackage, String callingFeatureId) { |
| 377 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 378 | mApp, subId, callingPackage, callingFeatureId, "isUceSettingEnabled")) { |
| 379 | Log.w(TAG, "isUceSettingEnabled: READ_PHONE_STATE app op disabled when accessing " |
| 380 | + "isUceSettingEnabled"); |
| 381 | return false; |
| 382 | } |
| 383 | final long token = Binder.clearCallingIdentity(); |
| 384 | try { |
| 385 | return SubscriptionManager.getBooleanSubscriptionProperty(subId, |
| 386 | SubscriptionManager.IMS_RCS_UCE_ENABLED, false /*defaultValue*/, mApp); |
| 387 | } finally { |
| 388 | Binder.restoreCallingIdentity(token); |
| 389 | } |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | @Override |
| 393 | public void setUceSettingEnabled(int subId, boolean isEnabled) { |
| 394 | enforceModifyPermission(); |
Brad Ebinger | 8b79edc | 2020-02-27 19:13:24 -0800 | [diff] [blame] | 395 | final long token = Binder.clearCallingIdentity(); |
| 396 | try { |
| 397 | SubscriptionManager.setSubscriptionProperty(subId, |
| 398 | SubscriptionManager.IMS_RCS_UCE_ENABLED, (isEnabled ? "1" : "0")); |
| 399 | } finally { |
| 400 | Binder.restoreCallingIdentity(token); |
| 401 | } |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 402 | } |
| 403 | |
Brad Ebinger | b989c7c | 2020-09-23 17:03:48 -0700 | [diff] [blame] | 404 | @Override |
| 405 | public boolean isSipDelegateSupported(int subId) { |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame^] | 406 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 407 | "isSipDelegateSupported", |
| 408 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 409 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 410 | if (!isImsSingleRegistrationSupportedOnDevice()) { |
| 411 | return false; |
| 412 | } |
Brad Ebinger | b989c7c | 2020-09-23 17:03:48 -0700 | [diff] [blame] | 413 | final long token = Binder.clearCallingIdentity(); |
| 414 | try { |
| 415 | SipTransportController transport = getRcsFeatureController(subId).getFeature( |
| 416 | SipTransportController.class); |
| 417 | if (transport == null) { |
| 418 | return false; |
| 419 | } |
| 420 | return transport.isSupported(subId); |
| 421 | } catch (ImsException e) { |
| 422 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 423 | } catch (ServiceSpecificException e) { |
| 424 | if (e.errorCode == ImsException.CODE_ERROR_UNSUPPORTED_OPERATION) { |
| 425 | return false; |
| 426 | } |
| 427 | throw e; |
| 428 | } finally { |
| 429 | Binder.restoreCallingIdentity(token); |
| 430 | } |
| 431 | } |
| 432 | |
Brad Ebinger | af1e983 | 2020-10-14 10:49:28 -0700 | [diff] [blame] | 433 | @Override |
Brad Ebinger | 63b6f5a | 2020-10-27 11:43:35 -0700 | [diff] [blame] | 434 | public void createSipDelegate(int subId, DelegateRequest request, String packageName, |
Brad Ebinger | af1e983 | 2020-10-14 10:49:28 -0700 | [diff] [blame] | 435 | ISipDelegateConnectionStateCallback delegateState, |
| 436 | ISipDelegateMessageCallback delegateMessage) { |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame^] | 437 | enforceImsSingleRegistrationPermission("createSipDelegate"); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 438 | if (!isImsSingleRegistrationSupportedOnDevice()) { |
| 439 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 440 | "SipDelegate creation is only supported for devices supporting IMS single " |
| 441 | + "registration"); |
| 442 | } |
Brad Ebinger | 63b6f5a | 2020-10-27 11:43:35 -0700 | [diff] [blame] | 443 | if (!UserHandle.getUserHandleForUid(Binder.getCallingUid()).isSystem()) { |
| 444 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 445 | "SipDelegate creation is only available to primary user."); |
| 446 | } |
| 447 | try { |
| 448 | int remoteUid = mApp.getPackageManager().getPackageUid(packageName, 0 /*flags*/); |
| 449 | if (Binder.getCallingUid() != remoteUid) { |
| 450 | throw new SecurityException("passed in packageName does not match the caller"); |
| 451 | } |
| 452 | } catch (PackageManager.NameNotFoundException e) { |
| 453 | throw new SecurityException("Passed in PackageName can not be found on device"); |
| 454 | } |
Brad Ebinger | af1e983 | 2020-10-14 10:49:28 -0700 | [diff] [blame] | 455 | |
| 456 | final long identity = Binder.clearCallingIdentity(); |
| 457 | SipTransportController transport = getRcsFeatureController(subId).getFeature( |
| 458 | SipTransportController.class); |
| 459 | if (transport == null) { |
| 460 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 461 | "This subscription does not support the creation of SIP delegates"); |
| 462 | } |
| 463 | try { |
Brad Ebinger | 63b6f5a | 2020-10-27 11:43:35 -0700 | [diff] [blame] | 464 | transport.createSipDelegate(subId, request, packageName, delegateState, |
| 465 | delegateMessage); |
Brad Ebinger | af1e983 | 2020-10-14 10:49:28 -0700 | [diff] [blame] | 466 | } catch (ImsException e) { |
| 467 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 468 | } finally { |
| 469 | Binder.restoreCallingIdentity(identity); |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | @Override |
| 474 | public void destroySipDelegate(int subId, ISipDelegate connection, int reason) { |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame^] | 475 | enforceImsSingleRegistrationPermission("destroySipDelegate"); |
Brad Ebinger | af1e983 | 2020-10-14 10:49:28 -0700 | [diff] [blame] | 476 | |
| 477 | final long identity = Binder.clearCallingIdentity(); |
| 478 | try { |
Brad Ebinger | 63b6f5a | 2020-10-27 11:43:35 -0700 | [diff] [blame] | 479 | SipTransportController transport = getRcsFeatureController(subId).getFeature( |
| 480 | SipTransportController.class); |
| 481 | if (transport == null) { |
| 482 | return; |
| 483 | } |
| 484 | transport.destroySipDelegate(subId, connection, reason); |
Brad Ebinger | af1e983 | 2020-10-14 10:49:28 -0700 | [diff] [blame] | 485 | } finally { |
| 486 | Binder.restoreCallingIdentity(identity); |
| 487 | } |
| 488 | } |
| 489 | |
Brad Ebinger | 3622138 | 2020-12-09 00:33:39 +0000 | [diff] [blame] | 490 | @Override |
| 491 | public void triggerNetworkRegistration(int subId, ISipDelegate connection, int sipCode, |
| 492 | String sipReason) { |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame^] | 493 | enforceImsSingleRegistrationPermission("triggerNetworkRegistration"); |
Brad Ebinger | 3622138 | 2020-12-09 00:33:39 +0000 | [diff] [blame] | 494 | |
| 495 | final long identity = Binder.clearCallingIdentity(); |
| 496 | try { |
| 497 | SipTransportController transport = getRcsFeatureController(subId).getFeature( |
| 498 | SipTransportController.class); |
| 499 | if (transport == null) { |
| 500 | return; |
| 501 | } |
| 502 | transport.triggerFullNetworkRegistration(subId, connection, sipCode, sipReason); |
| 503 | } finally { |
| 504 | Binder.restoreCallingIdentity(identity); |
| 505 | } |
| 506 | } |
| 507 | |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 508 | /** |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 509 | * Registers for updates to the RcsFeature connection through the IImsServiceFeatureCallback |
| 510 | * callback. |
| 511 | */ |
| 512 | @Override |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 513 | public void registerRcsFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 514 | enforceModifyPermission(); |
| 515 | |
| 516 | final long identity = Binder.clearCallingIdentity(); |
| 517 | try { |
| 518 | if (mImsResolver == null) { |
| 519 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 520 | "Device does not support IMS"); |
| 521 | } |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 522 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_RCS, callback); |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 523 | } finally { |
| 524 | Binder.restoreCallingIdentity(identity); |
| 525 | } |
| 526 | } |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 527 | |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 528 | /** |
| 529 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 530 | */ |
| 531 | @Override |
| 532 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
| 533 | enforceModifyPermission(); |
| 534 | |
| 535 | final long identity = Binder.clearCallingIdentity(); |
| 536 | try { |
| 537 | if (mImsResolver == null) return; |
| 538 | mImsResolver.unregisterImsFeatureCallback(callback); |
| 539 | } finally { |
| 540 | Binder.restoreCallingIdentity(identity); |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | /** |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 545 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 546 | * |
| 547 | * @throws SecurityException if the caller does not have the required permission |
| 548 | */ |
| 549 | private void enforceReadPrivilegedPermission(String message) { |
| 550 | mApp.enforceCallingOrSelfPermission( |
| 551 | android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message); |
| 552 | } |
| 553 | |
| 554 | /** |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame^] | 555 | * @throws SecurityException if the caller does not have the required |
| 556 | * PERFORM_IMS_SINGLE_REGISTRATION permission. |
| 557 | */ |
| 558 | private void enforceImsSingleRegistrationPermission(String message) { |
| 559 | mApp.enforceCallingOrSelfPermission( |
| 560 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, message); |
| 561 | } |
| 562 | |
| 563 | /** |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 564 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 565 | * |
| 566 | * @throws SecurityException if the caller does not have the required permission |
| 567 | */ |
| 568 | private void enforceModifyPermission() { |
| 569 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 570 | } |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 571 | |
| 572 | /** |
James.cf Lin | 051dd25 | 2021-01-21 03:30:54 +0800 | [diff] [blame] | 573 | * Make sure the caller has the ACCESS_RCS_USER_CAPABILITY_EXCHANGE permission. |
| 574 | * |
| 575 | * @throws SecurityException if the caller does not have the required permission. |
| 576 | */ |
| 577 | private void enforceAccessUserCapabilityExchangePermission(String message) { |
| 578 | mApp.enforceCallingOrSelfPermission( |
| 579 | android.Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, message); |
| 580 | } |
| 581 | |
| 582 | /** |
| 583 | * Make sure the caller has the READ_CONTACTS permission. |
| 584 | * |
| 585 | * @throws SecurityException if the caller does not have the required permission. |
| 586 | */ |
| 587 | private void enforceReadContactsPermission(String message) { |
| 588 | mApp.enforceCallingOrSelfPermission( |
| 589 | android.Manifest.permission.READ_CONTACTS, message); |
| 590 | } |
| 591 | |
| 592 | /** |
| 593 | * Check if the calling process is in the foreground. |
| 594 | * |
| 595 | * @return true if the caller is in the foreground. |
| 596 | */ |
| 597 | private boolean isCallingProcessInForeground(int uid) { |
| 598 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 599 | boolean isCallingProcessForeground = am != null |
| 600 | && am.getUidImportance(uid) |
| 601 | == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND; |
| 602 | return isCallingProcessForeground; |
| 603 | } |
| 604 | |
| 605 | /** |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 606 | * Retrieve ImsPhone instance. |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 607 | * |
| 608 | * @param subId the subscription ID |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 609 | * @return The ImsPhone instance |
| 610 | * @throws ServiceSpecificException if getting ImsPhone instance failed. |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 611 | */ |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 612 | private ImsPhone getImsPhone(int subId) { |
| 613 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 614 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 615 | "IMS is not available on device."); |
| 616 | } |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 617 | Phone phone = PhoneGlobals.getPhone(subId); |
| 618 | if (phone == null) { |
| 619 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 620 | "Invalid subscription Id: " + subId); |
| 621 | } |
| 622 | ImsPhone imsPhone = (ImsPhone) phone.getImsPhone(); |
| 623 | if (imsPhone == null) { |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 624 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 625 | "Cannot find ImsPhone instance: " + subId); |
| 626 | } |
| 627 | return imsPhone; |
| 628 | } |
| 629 | |
| 630 | /** |
| 631 | * Retrieve RcsFeatureManager instance. |
| 632 | * |
| 633 | * @param subId the subscription ID |
| 634 | * @return The RcsFeatureManager instance |
| 635 | * @throws ServiceSpecificException if getting RcsFeatureManager instance failed. |
| 636 | */ |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 637 | private RcsFeatureController getRcsFeatureController(int subId) { |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 638 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 639 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 640 | "IMS is not available on device."); |
| 641 | } |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 642 | if (mRcsService == null) { |
| 643 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 644 | "IMS is not available on device."); |
| 645 | } |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 646 | Phone phone = PhoneGlobals.getPhone(subId); |
| 647 | if (phone == null) { |
| 648 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 649 | "Invalid subscription Id: " + subId); |
| 650 | } |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 651 | int slotId = phone.getPhoneId(); |
| 652 | RcsFeatureController c = mRcsService.getFeatureController(slotId); |
| 653 | if (c == null) { |
Brad Ebinger | 036dc9e | 2020-02-06 15:49:06 -0800 | [diff] [blame] | 654 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 655 | "The requested operation is not supported for subId " + subId); |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 656 | } |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 657 | return c; |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 658 | } |
James.cf Lin | c9f35a4 | 2020-01-15 02:35:22 +0800 | [diff] [blame] | 659 | |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 660 | private boolean isImsSingleRegistrationSupportedOnDevice() { |
| 661 | return mSingleRegistrationOverride != null ? mSingleRegistrationOverride |
| 662 | : mApp.getPackageManager().hasSystemFeature( |
| 663 | PackageManager.FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION); |
| 664 | } |
| 665 | |
James.cf Lin | c9f35a4 | 2020-01-15 02:35:22 +0800 | [diff] [blame] | 666 | void setRcsService(TelephonyRcsService rcsService) { |
| 667 | mRcsService = rcsService; |
| 668 | } |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 669 | |
| 670 | /** |
| 671 | * Override device RCS single registration support check for CTS testing or remove override |
| 672 | * if the Boolean is set to null. |
| 673 | */ |
| 674 | void setDeviceSingleRegistrationSupportOverride(Boolean deviceOverrideValue) { |
| 675 | mSingleRegistrationOverride = deviceOverrideValue; |
| 676 | } |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 677 | } |