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