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; |
Hyunho | 8ea90f3 | 2021-11-16 08:53:02 +0000 | [diff] [blame] | 20 | import android.app.compat.CompatChanges; |
| 21 | import android.compat.annotation.ChangeId; |
| 22 | import android.compat.annotation.EnabledAfter; |
Brad Ebinger | 63b6f5a | 2020-10-27 11:43:35 -0700 | [diff] [blame] | 23 | import android.content.pm.PackageManager; |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 24 | import android.net.Uri; |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 25 | import android.os.Binder; |
Hyunho | 8ea90f3 | 2021-11-16 08:53:02 +0000 | [diff] [blame] | 26 | import android.os.Build; |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 27 | import android.os.RemoteException; |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 28 | import android.os.ServiceSpecificException; |
Brad Ebinger | 63b6f5a | 2020-10-27 11:43:35 -0700 | [diff] [blame] | 29 | import android.os.UserHandle; |
Brad Ebinger | b7a866a | 2020-01-22 17:51:55 -0800 | [diff] [blame] | 30 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 31 | import android.telephony.TelephonyFrameworkInitializer; |
Brad Ebinger | af1e983 | 2020-10-14 10:49:28 -0700 | [diff] [blame] | 32 | import android.telephony.ims.DelegateRequest; |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 33 | import android.telephony.ims.ImsException; |
Brad Ebinger | d4c5bde | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 34 | import android.telephony.ims.RcsContactUceCapability; |
James.cf Lin | 99a360d | 2020-11-04 10:48:37 +0800 | [diff] [blame] | 35 | import android.telephony.ims.RcsUceAdapter.PublishState; |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 36 | import android.telephony.ims.RegistrationManager; |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 37 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
| 38 | import android.telephony.ims.aidl.IImsRcsController; |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 39 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 40 | import android.telephony.ims.aidl.IRcsUceControllerCallback; |
James.cf Lin | cdad386 | 2020-02-25 15:55:03 +0800 | [diff] [blame] | 41 | import android.telephony.ims.aidl.IRcsUcePublishStateCallback; |
Brad Ebinger | af1e983 | 2020-10-14 10:49:28 -0700 | [diff] [blame] | 42 | import android.telephony.ims.aidl.ISipDelegate; |
| 43 | import android.telephony.ims.aidl.ISipDelegateConnectionStateCallback; |
| 44 | import android.telephony.ims.aidl.ISipDelegateMessageCallback; |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 45 | import android.telephony.ims.feature.ImsFeature; |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 46 | import android.telephony.ims.feature.RcsFeature; |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 47 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 48 | import android.util.Log; |
| 49 | |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 50 | import com.android.ims.ImsManager; |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 51 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 52 | import com.android.internal.telephony.IIntegerConsumer; |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 53 | import com.android.internal.telephony.Phone; |
Brad Ebinger | 8b79edc | 2020-02-27 19:13:24 -0800 | [diff] [blame] | 54 | import com.android.internal.telephony.TelephonyPermissions; |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 55 | import com.android.internal.telephony.ims.ImsResolver; |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 56 | import com.android.services.telephony.rcs.RcsFeatureController; |
Brad Ebinger | b989c7c | 2020-09-23 17:03:48 -0700 | [diff] [blame] | 57 | import com.android.services.telephony.rcs.SipTransportController; |
James.cf Lin | c9f35a4 | 2020-01-15 02:35:22 +0800 | [diff] [blame] | 58 | import com.android.services.telephony.rcs.TelephonyRcsService; |
James.cf Lin | 99a360d | 2020-11-04 10:48:37 +0800 | [diff] [blame] | 59 | import com.android.services.telephony.rcs.UceControllerManager; |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 60 | |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 61 | import java.util.List; |
Brad Ebinger | d4c5bde | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 62 | import java.util.Set; |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 63 | |
| 64 | /** |
| 65 | * Implementation of the IImsRcsController interface. |
| 66 | */ |
| 67 | public class ImsRcsController extends IImsRcsController.Stub { |
| 68 | private static final String TAG = "ImsRcsController"; |
| 69 | |
| 70 | /** The singleton instance. */ |
| 71 | private static ImsRcsController sInstance; |
| 72 | |
| 73 | private PhoneGlobals mApp; |
James.cf Lin | c9f35a4 | 2020-01-15 02:35:22 +0800 | [diff] [blame] | 74 | private TelephonyRcsService mRcsService; |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 75 | private ImsResolver mImsResolver; |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 76 | // set by shell cmd phone src set-device-enabled true/false |
| 77 | private Boolean mSingleRegistrationOverride; |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 78 | |
| 79 | /** |
Hyunho | 8ea90f3 | 2021-11-16 08:53:02 +0000 | [diff] [blame] | 80 | * For apps targeting Android T and above, support the publishing state on APIs, such as |
| 81 | * {@code RcsUceAdapter#PUBLISH_STATE_PUBLISHING} |
| 82 | * @hide |
| 83 | */ |
| 84 | @ChangeId |
| 85 | @EnabledAfter(targetSdkVersion = Build.VERSION_CODES.S) |
| 86 | public static final long SUPPORT_PUBLISHING_STATE = 202894742; |
| 87 | |
| 88 | /** |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 89 | * Initialize the singleton ImsRcsController instance. |
| 90 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 91 | */ |
| 92 | static ImsRcsController init(PhoneGlobals app) { |
| 93 | synchronized (ImsRcsController.class) { |
| 94 | if (sInstance == null) { |
| 95 | sInstance = new ImsRcsController(app); |
| 96 | } else { |
| 97 | Log.wtf(TAG, "init() called multiple times! sInstance = " + sInstance); |
| 98 | } |
| 99 | return sInstance; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | /** Private constructor; @see init() */ |
| 104 | private ImsRcsController(PhoneGlobals app) { |
| 105 | Log.i(TAG, "ImsRcsController"); |
| 106 | mApp = app; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 107 | TelephonyFrameworkInitializer |
| 108 | .getTelephonyServiceManager().getTelephonyImsServiceRegisterer().register(this); |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 109 | mImsResolver = ImsResolver.getInstance(); |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 110 | } |
| 111 | |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 112 | /** |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 113 | * Register a {@link RegistrationManager.RegistrationCallback} to receive IMS network |
| 114 | * registration state. |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 115 | */ |
| 116 | @Override |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 117 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback callback) { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 118 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
James.cf Lin | f020d16 | 2021-01-31 22:15:52 +0800 | [diff] [blame] | 119 | mApp, subId, "registerImsRegistrationCallback"); |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 120 | final long token = Binder.clearCallingIdentity(); |
| 121 | try { |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 122 | getRcsFeatureController(subId).registerImsRegistrationCallback(subId, callback); |
| 123 | } catch (ImsException e) { |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 124 | Log.e(TAG, "registerImsRegistrationCallback: sudId=" + subId + ", " + e.getMessage()); |
| 125 | throw new ServiceSpecificException(e.getCode()); |
| 126 | } finally { |
| 127 | Binder.restoreCallingIdentity(token); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | /** |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 132 | * Removes an existing {@link RegistrationManager.RegistrationCallback}. |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 133 | */ |
| 134 | @Override |
| 135 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback callback) { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 136 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
James.cf Lin | f020d16 | 2021-01-31 22:15:52 +0800 | [diff] [blame] | 137 | mApp, subId, "unregisterImsRegistrationCallback"); |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 138 | final long token = Binder.clearCallingIdentity(); |
| 139 | try { |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 140 | getRcsFeatureController(subId).unregisterImsRegistrationCallback(subId, callback); |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 141 | } catch (ServiceSpecificException e) { |
| 142 | Log.e(TAG, "unregisterImsRegistrationCallback: error=" + e.errorCode); |
| 143 | } finally { |
| 144 | Binder.restoreCallingIdentity(token); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Get the IMS service registration state for the RcsFeature associated with this sub id. |
| 150 | */ |
| 151 | @Override |
| 152 | public void getImsRcsRegistrationState(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 153 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
James.cf Lin | f020d16 | 2021-01-31 22:15:52 +0800 | [diff] [blame] | 154 | mApp, subId, "getImsRcsRegistrationState"); |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 155 | final long token = Binder.clearCallingIdentity(); |
| 156 | try { |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 157 | getRcsFeatureController(subId).getRegistrationState(regState -> { |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 158 | try { |
| 159 | consumer.accept((regState == null) |
| 160 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 161 | } catch (RemoteException e) { |
| 162 | Log.w(TAG, "getImsRcsRegistrationState: callback is not available."); |
| 163 | } |
| 164 | }); |
| 165 | } finally { |
| 166 | Binder.restoreCallingIdentity(token); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Gets the Transport Type associated with the current IMS RCS registration. |
| 172 | */ |
| 173 | @Override |
| 174 | public void getImsRcsRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 175 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
James.cf Lin | f020d16 | 2021-01-31 22:15:52 +0800 | [diff] [blame] | 176 | mApp, subId, "getImsRcsRegistrationTransportType"); |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +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).getRegistrationTech(regTech -> { |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 180 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 181 | int regTechConverted = (regTech == null) |
| 182 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 183 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 184 | regTechConverted); |
| 185 | try { |
| 186 | consumer.accept(regTechConverted); |
| 187 | } catch (RemoteException e) { |
| 188 | Log.w(TAG, "getImsRcsRegistrationTransportType: callback is not available."); |
| 189 | } |
| 190 | }); |
| 191 | } finally { |
| 192 | Binder.restoreCallingIdentity(token); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | /** |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 197 | * Register a capability callback which will provide RCS availability updates for the |
| 198 | * subscription specified. |
| 199 | * |
| 200 | * @param subId the subscription ID |
| 201 | * @param callback The ImsCapabilityCallback to be registered. |
| 202 | */ |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 203 | @Override |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 204 | public void registerRcsAvailabilityCallback(int subId, IImsCapabilityCallback callback) { |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 205 | enforceReadPrivilegedPermission("registerRcsAvailabilityCallback"); |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 206 | final long token = Binder.clearCallingIdentity(); |
| 207 | try { |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 208 | getRcsFeatureController(subId).registerRcsAvailabilityCallback(subId, callback); |
| 209 | } catch (ImsException e) { |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 210 | Log.e(TAG, "registerRcsAvailabilityCallback: sudId=" + subId + ", " + e.getMessage()); |
| 211 | throw new ServiceSpecificException(e.getCode()); |
| 212 | } finally { |
| 213 | Binder.restoreCallingIdentity(token); |
| 214 | } |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 215 | } |
| 216 | |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 217 | /** |
| 218 | * Remove the registered capability callback. |
| 219 | * |
| 220 | * @param subId the subscription ID |
| 221 | * @param callback The ImsCapabilityCallback to be removed. |
| 222 | */ |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 223 | @Override |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 224 | public void unregisterRcsAvailabilityCallback(int subId, IImsCapabilityCallback callback) { |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 225 | enforceReadPrivilegedPermission("unregisterRcsAvailabilityCallback"); |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 226 | final long token = Binder.clearCallingIdentity(); |
| 227 | try { |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 228 | getRcsFeatureController(subId).unregisterRcsAvailabilityCallback(subId, callback); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 229 | } catch (ServiceSpecificException e) { |
| 230 | Log.e(TAG, "unregisterRcsAvailabilityCallback: error=" + e.errorCode); |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 231 | } finally { |
| 232 | Binder.restoreCallingIdentity(token); |
| 233 | } |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 234 | } |
| 235 | |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 236 | /** |
| 237 | * Query for the capability of an IMS RCS service |
| 238 | * |
| 239 | * @param subId the subscription ID |
| 240 | * @param capability the RCS capability to query. |
James.cf Lin | f020d16 | 2021-01-31 22:15:52 +0800 | [diff] [blame] | 241 | * @param radioTech the radio technology type that we are querying. |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 242 | * @return true if the RCS capability is capable for this subscription, false otherwise. |
| 243 | */ |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 244 | @Override |
| 245 | public boolean isCapable(int subId, |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 246 | @RcsFeature.RcsImsCapabilities.RcsImsCapabilityFlag int capability, |
| 247 | @ImsRegistrationImplBase.ImsRegistrationTech int radioTech) { |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 248 | enforceReadPrivilegedPermission("isCapable"); |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 249 | final long token = Binder.clearCallingIdentity(); |
| 250 | try { |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 251 | return getRcsFeatureController(subId).isCapable(capability, radioTech); |
| 252 | } catch (ImsException e) { |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 253 | Log.e(TAG, "isCapable: sudId=" + subId |
| 254 | + ", capability=" + capability + ", " + e.getMessage()); |
Brad Ebinger | e3885b2 | 2022-02-16 13:18:59 -0800 | [diff] [blame] | 255 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 256 | } finally { |
| 257 | Binder.restoreCallingIdentity(token); |
| 258 | } |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 259 | } |
| 260 | |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 261 | /** |
| 262 | * Query the availability of an IMS RCS capability. |
| 263 | * |
| 264 | * @param subId the subscription ID |
| 265 | * @param capability the RCS capability to query. |
| 266 | * @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] | 267 | * @param radioTech the radio technology type that we are querying. |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 268 | * false otherwise. |
| 269 | */ |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 270 | @Override |
| 271 | public boolean isAvailable(int subId, |
James.cf Lin | f020d16 | 2021-01-31 22:15:52 +0800 | [diff] [blame] | 272 | @RcsFeature.RcsImsCapabilities.RcsImsCapabilityFlag int capability, |
| 273 | @ImsRegistrationImplBase.ImsRegistrationTech int radioTech) { |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 274 | enforceReadPrivilegedPermission("isAvailable"); |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 275 | final long token = Binder.clearCallingIdentity(); |
| 276 | try { |
James.cf Lin | f020d16 | 2021-01-31 22:15:52 +0800 | [diff] [blame] | 277 | return getRcsFeatureController(subId).isAvailable(capability, radioTech); |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 278 | } catch (ImsException e) { |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 279 | Log.e(TAG, "isAvailable: sudId=" + subId |
| 280 | + ", capability=" + capability + ", " + e.getMessage()); |
Brad Ebinger | e3885b2 | 2022-02-16 13:18:59 -0800 | [diff] [blame] | 281 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 282 | } finally { |
| 283 | Binder.restoreCallingIdentity(token); |
| 284 | } |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | @Override |
Brad Ebinger | 8b79edc | 2020-02-27 19:13:24 -0800 | [diff] [blame] | 288 | public void requestCapabilities(int subId, String callingPackage, String callingFeatureId, |
| 289 | List<Uri> contactNumbers, IRcsUceControllerCallback c) { |
James.cf Lin | 051dd25 | 2021-01-21 03:30:54 +0800 | [diff] [blame] | 290 | enforceAccessUserCapabilityExchangePermission("requestCapabilities"); |
| 291 | enforceReadContactsPermission("requestCapabilities"); |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 292 | final long token = Binder.clearCallingIdentity(); |
| 293 | try { |
James.cf Lin | 99a360d | 2020-11-04 10:48:37 +0800 | [diff] [blame] | 294 | UceControllerManager uceCtrlManager = getRcsFeatureController(subId).getFeature( |
| 295 | UceControllerManager.class); |
| 296 | if (uceCtrlManager == null) { |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 297 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 298 | "This subscription does not support UCE."); |
| 299 | } |
James.cf Lin | 99a360d | 2020-11-04 10:48:37 +0800 | [diff] [blame] | 300 | uceCtrlManager.requestCapabilities(contactNumbers, c); |
| 301 | } catch (ImsException e) { |
| 302 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 303 | } finally { |
| 304 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 1aa9499 | 2020-01-22 14:17:23 -0800 | [diff] [blame] | 305 | } |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | @Override |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 309 | public void requestAvailability(int subId, String callingPackage, |
James.cf Lin | 64e9121 | 2020-10-30 01:09:52 +0800 | [diff] [blame] | 310 | String callingFeatureId, Uri contactNumber, IRcsUceControllerCallback c) { |
James.cf Lin | 051dd25 | 2021-01-21 03:30:54 +0800 | [diff] [blame] | 311 | enforceAccessUserCapabilityExchangePermission("requestAvailability"); |
| 312 | enforceReadContactsPermission("requestAvailability"); |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 313 | final long token = Binder.clearCallingIdentity(); |
| 314 | try { |
James.cf Lin | 99a360d | 2020-11-04 10:48:37 +0800 | [diff] [blame] | 315 | UceControllerManager uceCtrlManager = getRcsFeatureController(subId).getFeature( |
| 316 | UceControllerManager.class); |
| 317 | if (uceCtrlManager == null) { |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 318 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 319 | "This subscription does not support UCE."); |
| 320 | } |
James.cf Lin | 99a360d | 2020-11-04 10:48:37 +0800 | [diff] [blame] | 321 | uceCtrlManager.requestNetworkAvailability(contactNumber, c); |
| 322 | } catch (ImsException e) { |
| 323 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 324 | } finally { |
| 325 | Binder.restoreCallingIdentity(token); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | @Override |
| 330 | public @PublishState int getUcePublishState(int subId) { |
| 331 | enforceReadPrivilegedPermission("getUcePublishState"); |
Hyunho | 8ea90f3 | 2021-11-16 08:53:02 +0000 | [diff] [blame] | 332 | final int uid = Binder.getCallingUid(); |
James.cf Lin | 99a360d | 2020-11-04 10:48:37 +0800 | [diff] [blame] | 333 | final long token = Binder.clearCallingIdentity(); |
Hyunho | 8ea90f3 | 2021-11-16 08:53:02 +0000 | [diff] [blame] | 334 | boolean isSupportPublishingState = false; |
James.cf Lin | 99a360d | 2020-11-04 10:48:37 +0800 | [diff] [blame] | 335 | try { |
| 336 | UceControllerManager uceCtrlManager = getRcsFeatureController(subId).getFeature( |
| 337 | UceControllerManager.class); |
| 338 | if (uceCtrlManager == null) { |
| 339 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 340 | "This subscription does not support UCE."); |
| 341 | } |
Hyunho | 8ea90f3 | 2021-11-16 08:53:02 +0000 | [diff] [blame] | 342 | if (CompatChanges.isChangeEnabled(SUPPORT_PUBLISHING_STATE, uid)) { |
| 343 | isSupportPublishingState = true; |
| 344 | } |
| 345 | return uceCtrlManager.getUcePublishState(isSupportPublishingState); |
James.cf Lin | 99a360d | 2020-11-04 10:48:37 +0800 | [diff] [blame] | 346 | } catch (ImsException e) { |
| 347 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 348 | } finally { |
| 349 | Binder.restoreCallingIdentity(token); |
| 350 | } |
| 351 | } |
| 352 | |
Brad Ebinger | d4c5bde | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 353 | /** |
| 354 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 355 | */ |
| 356 | // Used for SHELL command only right now. |
| 357 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 358 | Set<String> featureTags) throws ImsException { |
| 359 | // Permission check happening in PhoneInterfaceManager. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 360 | try { |
| 361 | UceControllerManager uceCtrlManager = getRcsFeatureController(subId).getFeature( |
| 362 | UceControllerManager.class); |
| 363 | if (uceCtrlManager == null) { |
| 364 | return null; |
| 365 | } |
| 366 | return uceCtrlManager.addUceRegistrationOverride(featureTags); |
| 367 | } catch (ServiceSpecificException e) { |
| 368 | throw new ImsException(e.getMessage(), e.errorCode); |
Brad Ebinger | d4c5bde | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 369 | } |
Brad Ebinger | d4c5bde | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | /** |
| 373 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 374 | */ |
| 375 | // Used for SHELL command only right now. |
| 376 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 377 | Set<String> featureTags) throws ImsException { |
| 378 | // Permission check happening in PhoneInterfaceManager. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 379 | try { |
| 380 | UceControllerManager uceCtrlManager = getRcsFeatureController(subId).getFeature( |
| 381 | UceControllerManager.class); |
| 382 | if (uceCtrlManager == null) { |
| 383 | return null; |
| 384 | } |
| 385 | return uceCtrlManager.removeUceRegistrationOverride(featureTags); |
| 386 | } catch (ServiceSpecificException e) { |
| 387 | throw new ImsException(e.getMessage(), e.errorCode); |
Brad Ebinger | d4c5bde | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 388 | } |
Brad Ebinger | d4c5bde | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | /** |
| 392 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 393 | */ |
| 394 | // Used for SHELL command only right now. |
| 395 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) |
| 396 | throws ImsException { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 397 | try { |
| 398 | // Permission check happening in PhoneInterfaceManager. |
| 399 | UceControllerManager uceCtrlManager = getRcsFeatureController(subId).getFeature( |
| 400 | UceControllerManager.class); |
| 401 | if (uceCtrlManager == null) { |
| 402 | return null; |
| 403 | } |
| 404 | return uceCtrlManager.clearUceRegistrationOverride(); |
| 405 | } catch (ServiceSpecificException e) { |
| 406 | throw new ImsException(e.getMessage(), e.errorCode); |
Brad Ebinger | d4c5bde | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 407 | } |
Brad Ebinger | d4c5bde | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | /** |
| 411 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 412 | */ |
| 413 | // Used for SHELL command only right now. |
| 414 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) |
| 415 | throws ImsException { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 416 | try { |
| 417 | // Permission check happening in PhoneInterfaceManager. |
| 418 | UceControllerManager uceCtrlManager = getRcsFeatureController(subId).getFeature( |
| 419 | UceControllerManager.class); |
| 420 | if (uceCtrlManager == null) { |
| 421 | return null; |
| 422 | } |
| 423 | return uceCtrlManager.getLatestRcsContactUceCapability(); |
| 424 | } catch (ServiceSpecificException e) { |
| 425 | throw new ImsException(e.getMessage(), e.errorCode); |
Brad Ebinger | d4c5bde | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 426 | } |
Brad Ebinger | d4c5bde | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | /** |
| 430 | * @return the PIDf XML used in the last PUBLISH procedure or "none" if the device is not |
| 431 | * published. Returns {@code null} if the operation failed due to an error. |
| 432 | */ |
| 433 | // Used for SHELL command only right now. |
| 434 | public String getLastUcePidfXmlShell(int subId) throws ImsException { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 435 | try { |
| 436 | // Permission check happening in PhoneInterfaceManager. |
| 437 | UceControllerManager uceCtrlManager = getRcsFeatureController(subId).getFeature( |
| 438 | UceControllerManager.class); |
| 439 | if (uceCtrlManager == null) { |
| 440 | return null; |
| 441 | } |
| 442 | String pidfXml = uceCtrlManager.getLastPidfXml(); |
| 443 | return pidfXml == null ? "none" : pidfXml; |
| 444 | } catch (ServiceSpecificException e) { |
| 445 | throw new ImsException(e.getMessage(), e.errorCode); |
Brad Ebinger | d4c5bde | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 446 | } |
Brad Ebinger | d4c5bde | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 447 | } |
| 448 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 449 | /** |
| 450 | * Remove UCE requests cannot be sent to the network status. |
| 451 | * @return true if this command is successful. |
| 452 | */ |
| 453 | // Used for SHELL command only right now. |
| 454 | public boolean removeUceRequestDisallowedStatus(int subId) throws ImsException { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 455 | try { |
James.cf Lin | c6b449f | 2021-06-05 01:11:15 +0800 | [diff] [blame] | 456 | UceControllerManager uceCtrlManager = getRcsFeatureController(subId, true).getFeature( |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 457 | UceControllerManager.class); |
| 458 | if (uceCtrlManager == null) { |
| 459 | return false; |
| 460 | } |
| 461 | return uceCtrlManager.removeUceRequestDisallowedStatus(); |
| 462 | } catch (ServiceSpecificException e) { |
| 463 | throw new ImsException(e.getMessage(), e.errorCode); |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 464 | } |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 465 | } |
| 466 | |
James.cf Lin | 0fc71b0 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 467 | /** |
| 468 | * Set the timeout for contact capabilities request. |
| 469 | */ |
| 470 | // Used for SHELL command only right now. |
| 471 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfter) throws ImsException { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 472 | try { |
James.cf Lin | c6b449f | 2021-06-05 01:11:15 +0800 | [diff] [blame] | 473 | UceControllerManager uceCtrlManager = getRcsFeatureController(subId, true).getFeature( |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 474 | UceControllerManager.class); |
| 475 | if (uceCtrlManager == null) { |
| 476 | return false; |
| 477 | } |
| 478 | return uceCtrlManager.setCapabilitiesRequestTimeout(timeoutAfter); |
| 479 | } catch (ServiceSpecificException e) { |
| 480 | throw new ImsException(e.getMessage(), e.errorCode); |
James.cf Lin | 0fc71b0 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 481 | } |
James.cf Lin | 0fc71b0 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 482 | } |
| 483 | |
James.cf Lin | 99a360d | 2020-11-04 10:48:37 +0800 | [diff] [blame] | 484 | @Override |
| 485 | public void registerUcePublishStateCallback(int subId, IRcsUcePublishStateCallback c) { |
| 486 | enforceReadPrivilegedPermission("registerUcePublishStateCallback"); |
Hyunho | 8ea90f3 | 2021-11-16 08:53:02 +0000 | [diff] [blame] | 487 | final int uid = Binder.getCallingUid(); |
James.cf Lin | 99a360d | 2020-11-04 10:48:37 +0800 | [diff] [blame] | 488 | final long token = Binder.clearCallingIdentity(); |
Hyunho | 8ea90f3 | 2021-11-16 08:53:02 +0000 | [diff] [blame] | 489 | boolean isSupportPublishingState = false; |
James.cf Lin | 99a360d | 2020-11-04 10:48:37 +0800 | [diff] [blame] | 490 | try { |
| 491 | UceControllerManager uceCtrlManager = getRcsFeatureController(subId).getFeature( |
| 492 | UceControllerManager.class); |
| 493 | if (uceCtrlManager == null) { |
| 494 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 495 | "This subscription does not support UCE."); |
| 496 | } |
Hyunho | 8ea90f3 | 2021-11-16 08:53:02 +0000 | [diff] [blame] | 497 | |
| 498 | if (CompatChanges.isChangeEnabled(SUPPORT_PUBLISHING_STATE, uid)) { |
| 499 | isSupportPublishingState = true; |
| 500 | } |
| 501 | uceCtrlManager.registerPublishStateCallback(c, isSupportPublishingState); |
James.cf Lin | 99a360d | 2020-11-04 10:48:37 +0800 | [diff] [blame] | 502 | } catch (ImsException e) { |
| 503 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 504 | } finally { |
| 505 | Binder.restoreCallingIdentity(token); |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | @Override |
| 510 | public void unregisterUcePublishStateCallback(int subId, IRcsUcePublishStateCallback c) { |
| 511 | enforceReadPrivilegedPermission("unregisterUcePublishStateCallback"); |
| 512 | final long token = Binder.clearCallingIdentity(); |
| 513 | try { |
| 514 | UceControllerManager uceCtrlManager = getRcsFeatureController(subId).getFeature( |
| 515 | UceControllerManager.class); |
| 516 | if (uceCtrlManager == null) { |
| 517 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 518 | "This subscription does not support UCE."); |
| 519 | } |
| 520 | uceCtrlManager.unregisterPublishStateCallback(c); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 521 | } catch (ServiceSpecificException e) { |
| 522 | Log.e(TAG, "unregisterUcePublishStateCallback: error=" + e.errorCode); |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 523 | } finally { |
| 524 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 1aa9499 | 2020-01-22 14:17:23 -0800 | [diff] [blame] | 525 | } |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | @Override |
Brad Ebinger | 8b79edc | 2020-02-27 19:13:24 -0800 | [diff] [blame] | 529 | public boolean isUceSettingEnabled(int subId, String callingPackage, String callingFeatureId) { |
| 530 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 531 | mApp, subId, callingPackage, callingFeatureId, "isUceSettingEnabled")) { |
| 532 | Log.w(TAG, "isUceSettingEnabled: READ_PHONE_STATE app op disabled when accessing " |
| 533 | + "isUceSettingEnabled"); |
| 534 | return false; |
| 535 | } |
| 536 | final long token = Binder.clearCallingIdentity(); |
| 537 | try { |
| 538 | return SubscriptionManager.getBooleanSubscriptionProperty(subId, |
| 539 | SubscriptionManager.IMS_RCS_UCE_ENABLED, false /*defaultValue*/, mApp); |
| 540 | } finally { |
| 541 | Binder.restoreCallingIdentity(token); |
| 542 | } |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | @Override |
| 546 | public void setUceSettingEnabled(int subId, boolean isEnabled) { |
| 547 | enforceModifyPermission(); |
Brad Ebinger | 8b79edc | 2020-02-27 19:13:24 -0800 | [diff] [blame] | 548 | final long token = Binder.clearCallingIdentity(); |
| 549 | try { |
| 550 | SubscriptionManager.setSubscriptionProperty(subId, |
| 551 | SubscriptionManager.IMS_RCS_UCE_ENABLED, (isEnabled ? "1" : "0")); |
| 552 | } finally { |
| 553 | Binder.restoreCallingIdentity(token); |
| 554 | } |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 555 | } |
| 556 | |
Brad Ebinger | b989c7c | 2020-09-23 17:03:48 -0700 | [diff] [blame] | 557 | @Override |
| 558 | public boolean isSipDelegateSupported(int subId) { |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 559 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 560 | "isSipDelegateSupported", |
| 561 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 562 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 563 | if (!isImsSingleRegistrationSupportedOnDevice()) { |
| 564 | return false; |
| 565 | } |
Brad Ebinger | b989c7c | 2020-09-23 17:03:48 -0700 | [diff] [blame] | 566 | final long token = Binder.clearCallingIdentity(); |
| 567 | try { |
| 568 | SipTransportController transport = getRcsFeatureController(subId).getFeature( |
| 569 | SipTransportController.class); |
| 570 | if (transport == null) { |
| 571 | return false; |
| 572 | } |
| 573 | return transport.isSupported(subId); |
| 574 | } catch (ImsException e) { |
| 575 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 576 | } catch (ServiceSpecificException e) { |
| 577 | if (e.errorCode == ImsException.CODE_ERROR_UNSUPPORTED_OPERATION) { |
| 578 | return false; |
| 579 | } |
| 580 | throw e; |
| 581 | } finally { |
| 582 | Binder.restoreCallingIdentity(token); |
| 583 | } |
| 584 | } |
| 585 | |
Brad Ebinger | af1e983 | 2020-10-14 10:49:28 -0700 | [diff] [blame] | 586 | @Override |
Brad Ebinger | 63b6f5a | 2020-10-27 11:43:35 -0700 | [diff] [blame] | 587 | public void createSipDelegate(int subId, DelegateRequest request, String packageName, |
Brad Ebinger | af1e983 | 2020-10-14 10:49:28 -0700 | [diff] [blame] | 588 | ISipDelegateConnectionStateCallback delegateState, |
| 589 | ISipDelegateMessageCallback delegateMessage) { |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 590 | enforceImsSingleRegistrationPermission("createSipDelegate"); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 591 | if (!isImsSingleRegistrationSupportedOnDevice()) { |
| 592 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 593 | "SipDelegate creation is only supported for devices supporting IMS single " |
| 594 | + "registration"); |
| 595 | } |
Brad Ebinger | 63b6f5a | 2020-10-27 11:43:35 -0700 | [diff] [blame] | 596 | if (!UserHandle.getUserHandleForUid(Binder.getCallingUid()).isSystem()) { |
| 597 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 598 | "SipDelegate creation is only available to primary user."); |
| 599 | } |
| 600 | try { |
| 601 | int remoteUid = mApp.getPackageManager().getPackageUid(packageName, 0 /*flags*/); |
| 602 | if (Binder.getCallingUid() != remoteUid) { |
| 603 | throw new SecurityException("passed in packageName does not match the caller"); |
| 604 | } |
| 605 | } catch (PackageManager.NameNotFoundException e) { |
| 606 | throw new SecurityException("Passed in PackageName can not be found on device"); |
| 607 | } |
Brad Ebinger | af1e983 | 2020-10-14 10:49:28 -0700 | [diff] [blame] | 608 | |
Jinyoung Jeong | ca77e1c | 2021-10-21 04:34:46 +0000 | [diff] [blame] | 609 | final int uid = Binder.getCallingUid(); |
Brad Ebinger | af1e983 | 2020-10-14 10:49:28 -0700 | [diff] [blame] | 610 | final long identity = Binder.clearCallingIdentity(); |
| 611 | SipTransportController transport = getRcsFeatureController(subId).getFeature( |
| 612 | SipTransportController.class); |
| 613 | if (transport == null) { |
| 614 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 615 | "This subscription does not support the creation of SIP delegates"); |
| 616 | } |
| 617 | try { |
Jinyoung Jeong | ca77e1c | 2021-10-21 04:34:46 +0000 | [diff] [blame] | 618 | transport.createSipDelegate(subId, uid, request, packageName, delegateState, |
Brad Ebinger | 63b6f5a | 2020-10-27 11:43:35 -0700 | [diff] [blame] | 619 | delegateMessage); |
Brad Ebinger | af1e983 | 2020-10-14 10:49:28 -0700 | [diff] [blame] | 620 | } catch (ImsException e) { |
| 621 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 622 | } finally { |
| 623 | Binder.restoreCallingIdentity(identity); |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | @Override |
| 628 | public void destroySipDelegate(int subId, ISipDelegate connection, int reason) { |
Brad Ebinger | 652411e | 2021-06-30 09:30:35 -0700 | [diff] [blame] | 629 | // Do not check permissions here - the caller needs to have a connection already from the |
| 630 | // create method to call this method. |
| 631 | if (connection == null) { |
| 632 | return; |
| 633 | } |
Brad Ebinger | af1e983 | 2020-10-14 10:49:28 -0700 | [diff] [blame] | 634 | final long identity = Binder.clearCallingIdentity(); |
| 635 | try { |
Brad Ebinger | 63b6f5a | 2020-10-27 11:43:35 -0700 | [diff] [blame] | 636 | SipTransportController transport = getRcsFeatureController(subId).getFeature( |
| 637 | SipTransportController.class); |
| 638 | if (transport == null) { |
| 639 | return; |
| 640 | } |
| 641 | transport.destroySipDelegate(subId, connection, reason); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 642 | } catch (ServiceSpecificException e) { |
| 643 | Log.e(TAG, "destroySipDelegate: error=" + e.errorCode); |
Brad Ebinger | af1e983 | 2020-10-14 10:49:28 -0700 | [diff] [blame] | 644 | } finally { |
| 645 | Binder.restoreCallingIdentity(identity); |
| 646 | } |
| 647 | } |
| 648 | |
Brad Ebinger | 3622138 | 2020-12-09 00:33:39 +0000 | [diff] [blame] | 649 | @Override |
| 650 | public void triggerNetworkRegistration(int subId, ISipDelegate connection, int sipCode, |
| 651 | String sipReason) { |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 652 | enforceImsSingleRegistrationPermission("triggerNetworkRegistration"); |
Brad Ebinger | 3622138 | 2020-12-09 00:33:39 +0000 | [diff] [blame] | 653 | |
| 654 | final long identity = Binder.clearCallingIdentity(); |
| 655 | try { |
| 656 | SipTransportController transport = getRcsFeatureController(subId).getFeature( |
| 657 | SipTransportController.class); |
| 658 | if (transport == null) { |
| 659 | return; |
| 660 | } |
| 661 | transport.triggerFullNetworkRegistration(subId, connection, sipCode, sipReason); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 662 | } catch (ServiceSpecificException e) { |
| 663 | Log.e(TAG, "triggerNetworkRegistration: error=" + e.errorCode); |
Brad Ebinger | 3622138 | 2020-12-09 00:33:39 +0000 | [diff] [blame] | 664 | } finally { |
| 665 | Binder.restoreCallingIdentity(identity); |
| 666 | } |
| 667 | } |
| 668 | |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 669 | /** |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 670 | * Registers for updates to the RcsFeature connection through the IImsServiceFeatureCallback |
| 671 | * callback. |
| 672 | */ |
| 673 | @Override |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 674 | public void registerRcsFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 675 | enforceModifyPermission(); |
| 676 | |
| 677 | final long identity = Binder.clearCallingIdentity(); |
| 678 | try { |
| 679 | if (mImsResolver == null) { |
| 680 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 681 | "Device does not support IMS"); |
| 682 | } |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 683 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_RCS, callback); |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 684 | } finally { |
| 685 | Binder.restoreCallingIdentity(identity); |
| 686 | } |
| 687 | } |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 688 | |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 689 | /** |
| 690 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 691 | */ |
| 692 | @Override |
| 693 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
| 694 | enforceModifyPermission(); |
| 695 | |
| 696 | final long identity = Binder.clearCallingIdentity(); |
| 697 | try { |
| 698 | if (mImsResolver == null) return; |
| 699 | mImsResolver.unregisterImsFeatureCallback(callback); |
| 700 | } finally { |
| 701 | Binder.restoreCallingIdentity(identity); |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | /** |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 706 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 707 | * |
| 708 | * @throws SecurityException if the caller does not have the required permission |
| 709 | */ |
| 710 | private void enforceReadPrivilegedPermission(String message) { |
| 711 | mApp.enforceCallingOrSelfPermission( |
| 712 | android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message); |
| 713 | } |
| 714 | |
| 715 | /** |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 716 | * @throws SecurityException if the caller does not have the required |
| 717 | * PERFORM_IMS_SINGLE_REGISTRATION permission. |
| 718 | */ |
| 719 | private void enforceImsSingleRegistrationPermission(String message) { |
| 720 | mApp.enforceCallingOrSelfPermission( |
| 721 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, message); |
| 722 | } |
| 723 | |
| 724 | /** |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 725 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 726 | * |
| 727 | * @throws SecurityException if the caller does not have the required permission |
| 728 | */ |
| 729 | private void enforceModifyPermission() { |
| 730 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 731 | } |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 732 | |
| 733 | /** |
James.cf Lin | 051dd25 | 2021-01-21 03:30:54 +0800 | [diff] [blame] | 734 | * Make sure the caller has the ACCESS_RCS_USER_CAPABILITY_EXCHANGE permission. |
| 735 | * |
| 736 | * @throws SecurityException if the caller does not have the required permission. |
| 737 | */ |
| 738 | private void enforceAccessUserCapabilityExchangePermission(String message) { |
| 739 | mApp.enforceCallingOrSelfPermission( |
| 740 | android.Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, message); |
| 741 | } |
| 742 | |
| 743 | /** |
| 744 | * Make sure the caller has the READ_CONTACTS permission. |
| 745 | * |
| 746 | * @throws SecurityException if the caller does not have the required permission. |
| 747 | */ |
| 748 | private void enforceReadContactsPermission(String message) { |
| 749 | mApp.enforceCallingOrSelfPermission( |
| 750 | android.Manifest.permission.READ_CONTACTS, message); |
| 751 | } |
| 752 | |
| 753 | /** |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 754 | * Retrieve RcsFeatureManager instance. |
| 755 | * |
| 756 | * @param subId the subscription ID |
| 757 | * @return The RcsFeatureManager instance |
| 758 | * @throws ServiceSpecificException if getting RcsFeatureManager instance failed. |
| 759 | */ |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 760 | private RcsFeatureController getRcsFeatureController(int subId) { |
James.cf Lin | c6b449f | 2021-06-05 01:11:15 +0800 | [diff] [blame] | 761 | return getRcsFeatureController(subId, false /* skipVerifyingConfig */); |
| 762 | } |
| 763 | |
| 764 | /** |
| 765 | * Retrieve RcsFeatureManager instance. |
| 766 | * |
| 767 | * @param subId the subscription ID |
| 768 | * @param skipVerifyingConfig If the RCS configuration can be skip. |
| 769 | * @return The RcsFeatureManager instance |
| 770 | * @throws ServiceSpecificException if getting RcsFeatureManager instance failed. |
| 771 | */ |
| 772 | private RcsFeatureController getRcsFeatureController(int subId, boolean skipVerifyingConfig) { |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 773 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 774 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 775 | "IMS is not available on device."); |
| 776 | } |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 777 | if (mRcsService == null) { |
| 778 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 779 | "IMS is not available on device."); |
| 780 | } |
James.cf Lin | dc2d542 | 2019-12-31 14:40:25 +0800 | [diff] [blame] | 781 | Phone phone = PhoneGlobals.getPhone(subId); |
| 782 | if (phone == null) { |
| 783 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 784 | "Invalid subscription Id: " + subId); |
| 785 | } |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 786 | int slotId = phone.getPhoneId(); |
James.cf Lin | c6b449f | 2021-06-05 01:11:15 +0800 | [diff] [blame] | 787 | if (!skipVerifyingConfig) { |
| 788 | verifyImsRcsConfiguredOrThrow(slotId); |
Brad Ebinger | e3885b2 | 2022-02-16 13:18:59 -0800 | [diff] [blame] | 789 | verifyRcsSubIdActiveOrThrow(slotId, subId); |
James.cf Lin | c6b449f | 2021-06-05 01:11:15 +0800 | [diff] [blame] | 790 | } |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 791 | RcsFeatureController c = mRcsService.getFeatureController(slotId); |
| 792 | if (c == null) { |
Brad Ebinger | e3885b2 | 2022-02-16 13:18:59 -0800 | [diff] [blame] | 793 | // If we hit this case, we have verified that TelephonyRcsService has processed any |
| 794 | // subId changes for the associated slot and applied configs. In this case, the configs |
| 795 | // do not have the RCS feature enabled. |
Brad Ebinger | 036dc9e | 2020-02-06 15:49:06 -0800 | [diff] [blame] | 796 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 797 | "The requested operation is not supported for subId " + subId); |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 798 | } |
Brad Ebinger | e3885b2 | 2022-02-16 13:18:59 -0800 | [diff] [blame] | 799 | if (!skipVerifyingConfig && c.getAssociatedSubId() != subId) { |
| 800 | // If we hit this case, the ImsFeature has not finished setting up the RCS feature yet |
| 801 | // or the RCS feature has crashed and is being set up again. |
| 802 | Log.w(TAG, "getRcsFeatureController: service unavailable on slot " + slotId |
| 803 | + " for subId " + subId); |
| 804 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 805 | "The ImsService is not currently available for subid " + subId |
| 806 | + ", please try again"); |
| 807 | } |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 808 | return c; |
James.cf Lin | cad981c | 2019-12-10 20:37:56 +0800 | [diff] [blame] | 809 | } |
James.cf Lin | c9f35a4 | 2020-01-15 02:35:22 +0800 | [diff] [blame] | 810 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 811 | /** |
Brad Ebinger | e3885b2 | 2022-02-16 13:18:59 -0800 | [diff] [blame] | 812 | * Ensure the TelephonyRcsService is tracking the supplied subId for the supplied slotId and has |
| 813 | * set up the stack. |
| 814 | */ |
| 815 | private void verifyRcsSubIdActiveOrThrow(int slotId, int subId) { |
| 816 | if (mRcsService.verifyActiveSubId(slotId, subId)) return; |
| 817 | |
| 818 | Log.w(TAG, "verifyRcsSubIdActiveOrThrow: verify failed, service not set up yet on " |
| 819 | + "slot " + slotId + " for subId " + subId); |
| 820 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 821 | "ImsService set up in progress for subId " + subId |
| 822 | + ", please try again"); |
| 823 | } |
| 824 | |
| 825 | /** |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 826 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for RCS |
| 827 | * for the given slot ID or no ImsResolver instance has been created. |
| 828 | * @param slotId The slot ID that the IMS service is created for. |
| 829 | * @throws ServiceSpecificException If there is no ImsService configured for this slot. |
| 830 | */ |
| 831 | private void verifyImsRcsConfiguredOrThrow(int slotId) { |
| 832 | if (mImsResolver == null |
| 833 | || !mImsResolver.isImsServiceConfiguredForFeature(slotId, ImsFeature.FEATURE_RCS)) { |
| 834 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 835 | "This subscription does not support RCS"); |
| 836 | } |
| 837 | } |
| 838 | |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 839 | private boolean isImsSingleRegistrationSupportedOnDevice() { |
| 840 | return mSingleRegistrationOverride != null ? mSingleRegistrationOverride |
| 841 | : mApp.getPackageManager().hasSystemFeature( |
| 842 | PackageManager.FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION); |
| 843 | } |
| 844 | |
James.cf Lin | c9f35a4 | 2020-01-15 02:35:22 +0800 | [diff] [blame] | 845 | void setRcsService(TelephonyRcsService rcsService) { |
| 846 | mRcsService = rcsService; |
| 847 | } |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 848 | |
| 849 | /** |
| 850 | * Override device RCS single registration support check for CTS testing or remove override |
| 851 | * if the Boolean is set to null. |
| 852 | */ |
| 853 | void setDeviceSingleRegistrationSupportOverride(Boolean deviceOverrideValue) { |
| 854 | mSingleRegistrationOverride = deviceOverrideValue; |
| 855 | } |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 856 | } |