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