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