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