1 /* 2 * Copyright (C) 2018 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 package android.telephony.ims; 17 18 import android.annotation.IntDef; 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.SystemApi; 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 25 import com.android.telephony.Rlog; 26 27 import java.lang.annotation.Retention; 28 import java.lang.annotation.RetentionPolicy; 29 import java.util.ArrayList; 30 import java.util.Arrays; 31 import java.util.List; 32 33 /** 34 * Provides STK Call Control Supplementary Service information. 35 * 36 * {@hide} 37 */ 38 @SystemApi 39 public final class ImsSsData implements Parcelable { 40 41 private static final String TAG = ImsSsData.class.getCanonicalName(); 42 43 // Supplementary Service Type 44 // Call Forwarding 45 public static final int SS_CFU = 0; 46 public static final int SS_CF_BUSY = 1; 47 public static final int SS_CF_NO_REPLY = 2; 48 public static final int SS_CF_NOT_REACHABLE = 3; 49 public static final int SS_CF_ALL = 4; 50 public static final int SS_CF_ALL_CONDITIONAL = 5; 51 public static final int SS_CFUT = 6; 52 // Called Line Presentation 53 public static final int SS_CLIP = 7; 54 public static final int SS_CLIR = 8; 55 public static final int SS_COLP = 9; 56 public static final int SS_COLR = 10; 57 // Calling Name Presentation 58 public static final int SS_CNAP = 11; 59 // Call Waiting 60 public static final int SS_WAIT = 12; 61 // Call Barring 62 public static final int SS_BAOC = 13; 63 public static final int SS_BAOIC = 14; 64 public static final int SS_BAOIC_EXC_HOME = 15; 65 public static final int SS_BAIC = 16; 66 public static final int SS_BAIC_ROAMING = 17; 67 public static final int SS_ALL_BARRING = 18; 68 public static final int SS_OUTGOING_BARRING = 19; 69 public static final int SS_INCOMING_BARRING = 20; 70 public static final int SS_INCOMING_BARRING_DN = 21; 71 public static final int SS_INCOMING_BARRING_ANONYMOUS = 22; 72 73 74 /**@hide*/ 75 @IntDef(prefix = {"SS_"}, value = { 76 SS_ACTIVATION, 77 SS_DEACTIVATION, 78 SS_INTERROGATION, 79 SS_REGISTRATION, 80 SS_ERASURE}) 81 @Retention(RetentionPolicy.SOURCE) 82 public @interface RequestType{} 83 84 //Supplementary Service Request Types 85 public static final int SS_ACTIVATION = 0; 86 public static final int SS_DEACTIVATION = 1; 87 public static final int SS_INTERROGATION = 2; 88 public static final int SS_REGISTRATION = 3; 89 public static final int SS_ERASURE = 4; 90 91 /**@hide*/ 92 @IntDef(prefix = {"SS_"}, value = { 93 SS_ALL_TELE_AND_BEARER_SERVICES, 94 SS_ALL_TELESEVICES, 95 SS_TELEPHONY, 96 SS_ALL_DATA_TELESERVICES, 97 SS_SMS_SERVICES, 98 SS_ALL_TELESERVICES_EXCEPT_SMS}) 99 @Retention(RetentionPolicy.SOURCE) 100 public @interface TeleserviceType{} 101 102 // Supplementary Service Teleservice Type 103 public static final int SS_ALL_TELE_AND_BEARER_SERVICES = 0; 104 public static final int SS_ALL_TELESEVICES = 1; 105 public static final int SS_TELEPHONY = 2; 106 public static final int SS_ALL_DATA_TELESERVICES = 3; 107 public static final int SS_SMS_SERVICES = 4; 108 public static final int SS_ALL_TELESERVICES_EXCEPT_SMS = 5; 109 110 /** 111 * No call forwarding service class defined. 112 * 113 * See TS 27.007 7.11 (+CCFC) and 7.4 (CLCK) 114 */ 115 public static final int SERVICE_CLASS_NONE = 0; 116 117 /** 118 * Service class flag for voice telephony. 119 * 120 * See TS 27.007 7.11 (+CCFC) and 7.4 (CLCK) 121 */ 122 public static final int SERVICE_CLASS_VOICE = 1; 123 124 /** 125 * Service class flag for all data bearers (including 126 * {@link #SERVICE_CLASS_DATA_CIRCUIT_SYNC, 127 * {@link #SERVICE_CLASS_DATA_CIRCUIT_ASYNC}, {@link #SERVICE_CLASS_PACKET_ACCESS}, 128 * {@link #SERVICE_CLASS_PAD}}) if supported by the carrier. 129 * 130 * See TS 27.007 7.11 (+CCFC) and 7.4 (CLCK) 131 */ 132 public static final int SERVICE_CLASS_DATA = (1 << 1); 133 /** 134 * Service class flag for fax services. 135 * 136 * See TS 27.007 7.11 (+CCFC) and 7.4 (CLCK) 137 */ 138 public static final int SERVICE_CLASS_FAX = (1 << 2); 139 /** 140 * Service class flag for SMS services. 141 * 142 * See TS 27.007 7.11 (+CCFC) and 7.4 (CLCK) 143 */ 144 public static final int SERVICE_CLASS_SMS = (1 << 3); 145 /** 146 * Service class flag for the synchronous bearer service. 147 * 148 * See TS 27.007 7.11 (+CCFC) and 7.4 (CLCK) 149 */ 150 public static final int SERVICE_CLASS_DATA_CIRCUIT_SYNC = (1 << 4); 151 152 /** 153 * Service class flag for the asynchronous bearer service. 154 * 155 * See TS 27.007 7.11 (+CCFC) and 7.4 (CLCK) 156 */ 157 public static final int SERVICE_CLASS_DATA_CIRCUIT_ASYNC = (1 << 5); 158 159 /** 160 * Service class flag for the packet access bearer service. 161 * 162 * See TS 27.007 7.11 (+CCFC) and 7.4 (CLCK) 163 */ 164 public static final int SERVICE_CLASS_DATA_PACKET_ACCESS = (1 << 6); 165 166 /** 167 * Service class flag for the Packet Assembly/Disassembly bearer service. 168 * 169 * See TS 27.007 7.11 (+CCFC) and 7.4 (CLCK) 170 */ 171 public static final int SERVICE_CLASS_DATA_PAD = (1 << 7); 172 173 /**@hide*/ 174 @IntDef(flag = true, prefix = {"SERVICE_CLASS_"}, value = { 175 SERVICE_CLASS_NONE, 176 SERVICE_CLASS_VOICE, 177 SERVICE_CLASS_DATA, 178 SERVICE_CLASS_FAX, 179 SERVICE_CLASS_SMS, 180 SERVICE_CLASS_DATA_CIRCUIT_SYNC, 181 SERVICE_CLASS_DATA_CIRCUIT_ASYNC, 182 SERVICE_CLASS_DATA_PACKET_ACCESS, 183 SERVICE_CLASS_DATA_PAD}) 184 @Retention(RetentionPolicy.SOURCE) 185 public @interface ServiceClassFlags{} 186 187 /** 188 * Result code used if the operation was successful. See {@link #getResult()}. 189 */ 190 public static final int RESULT_SUCCESS = 0; 191 192 /** @hide */ 193 @IntDef(prefix = { "SS_" }, value = { 194 SS_CFU, 195 SS_CF_BUSY, 196 SS_CF_NO_REPLY, 197 SS_CF_NOT_REACHABLE, 198 SS_CF_ALL, 199 SS_CF_ALL_CONDITIONAL, 200 SS_CFUT, 201 SS_CLIP, 202 SS_CLIR, 203 SS_COLP, 204 SS_COLR, 205 SS_CNAP, 206 SS_WAIT, 207 SS_BAOC, 208 SS_BAOIC, 209 SS_BAOIC_EXC_HOME, 210 SS_BAIC, 211 SS_BAIC_ROAMING, 212 SS_ALL_BARRING, 213 SS_OUTGOING_BARRING, 214 SS_INCOMING_BARRING, 215 SS_INCOMING_BARRING_DN, 216 SS_INCOMING_BARRING_ANONYMOUS 217 }) 218 @Retention(RetentionPolicy.SOURCE) 219 public @interface ServiceType{} 220 221 /** 222 * The Service type of this Supplementary service. 223 * @hide 224 */ 225 public final @ServiceType int serviceType; 226 227 /** 228 * Supplementary Service request Type: 229 * {@link #SS_ACTIVATION), 230 * {@link #SS_DEACTIVATION}, 231 * {@link #SS_INTERROGATION}, 232 * {@link #SS_REGISTRATION}, 233 * {@link #SS_ERASURE} 234 * @hide 235 */ 236 public final @RequestType int requestType; 237 238 /** 239 * Supplementary Service teleservice type: 240 * {@link #SS_ALL_TELE_AND_BEARER_SERVICES}, 241 * {@link #SS_ALL_TELESEVICES}, 242 * {@link #SS_TELEPHONY}, 243 * {@link #SS_ALL_DATA_TELESERVICES}, 244 * {@link #SS_SMS_SERVICES}, 245 * {@link #SS_ALL_TELESERVICES_EXCEPT_SMS} 246 * 247 * @hide 248 */ 249 public final @TeleserviceType int teleserviceType; 250 251 /** 252 * Supplementary Service service class. 253 * 254 * @hide 255 */ 256 public final @ServiceClassFlags int serviceClass; 257 258 /** 259 * Result of Supplementary Service operation. Valid values are: 260 * {@link #RESULT_SUCCESS} if the result is success, or 261 * ImsReasonInfo code if the result is a failure. 262 * 263 * @hide 264 */ 265 public final int result; 266 267 private int[] mSsInfo; 268 private List<ImsCallForwardInfo> mCfInfo; 269 private List<ImsSsInfo> mImsSsInfo; 270 271 /** 272 * Builder for optional ImsSsData parameters. 273 */ 274 public static final class Builder { 275 private ImsSsData mImsSsData; 276 277 /** 278 * Generate IMS Supplementary Service information. 279 * @param serviceType The Supplementary Service type. 280 * @param requestType Supplementary Service request Type: 281 * {@link #SS_ACTIVATION}, 282 * {@link #SS_DEACTIVATION}, 283 * {@link #SS_INTERROGATION}, 284 * {@link #SS_REGISTRATION}, 285 * {@link #SS_ERASURE} 286 * @param teleserviceType Supplementary Service teleservice type: 287 * {@link #SS_ALL_TELE_AND_BEARER_SERVICES}, 288 * {@link #SS_ALL_TELESEVICES}, 289 * {@link #SS_TELEPHONY}, 290 * {@link #SS_ALL_DATA_TELESERVICES}, 291 * {@link #SS_SMS_SERVICES}, 292 * {@link #SS_ALL_TELESERVICES_EXCEPT_SMS} 293 * @param serviceClass Supplementary Service service class. See See 27.007 +CCFC or +CLCK. 294 * @param result Result of Supplementary Service operation. Valid values are 0 if the result 295 * is success, or {@link ImsReasonInfo} code if the result is a failure. 296 * @return this Builder instance for further constructing. 297 * @see #build() 298 */ Builder(@erviceType int serviceType, int requestType, int teleserviceType, @ServiceClassFlags int serviceClass, int result)299 public Builder(@ServiceType int serviceType, int requestType, int teleserviceType, 300 @ServiceClassFlags int serviceClass, int result) { 301 mImsSsData = new ImsSsData(serviceType, requestType, teleserviceType, serviceClass, 302 result); 303 } 304 305 /** 306 * Set the array of {@link ImsSsInfo}s that are associated with this supplementary service 307 * data. 308 */ setSuppServiceInfo(@onNull List<ImsSsInfo> imsSsInfos)309 public @NonNull Builder setSuppServiceInfo(@NonNull List<ImsSsInfo> imsSsInfos) { 310 mImsSsData.mImsSsInfo = imsSsInfos; 311 return this; 312 } 313 314 /** 315 * Set the array of {@link ImsCallForwardInfo}s that are associated with this supplementary 316 * service data. 317 */ setCallForwardingInfo( @onNull List<ImsCallForwardInfo> imsCallForwardInfos)318 public @NonNull Builder setCallForwardingInfo( 319 @NonNull List<ImsCallForwardInfo> imsCallForwardInfos) { 320 mImsSsData.mCfInfo = imsCallForwardInfos; 321 return this; 322 } 323 324 /** 325 * @return an {@link ImsSsData} containing optional parameters. 326 */ build()327 public @NonNull ImsSsData build() { 328 return mImsSsData; 329 } 330 } 331 332 /** 333 * Generate IMS Supplementary Service information. 334 * @param serviceType The Supplementary Service type. 335 * @param requestType Supplementary Service request Type. Valid values are: 336 * {@link #SS_ACTIVATION}, 337 * {@link #SS_DEACTIVATION}, 338 * {@link #SS_INTERROGATION}, 339 * {@link #SS_REGISTRATION}, 340 * {@link #SS_ERASURE} 341 * @param teleserviceType Supplementary Service teleservice type: 342 * {@link #SS_ALL_TELE_AND_BEARER_SERVICES}, 343 * {@link #SS_ALL_TELESEVICES}, 344 * {@link #SS_TELEPHONY}, 345 * {@link #SS_ALL_DATA_TELESERVICES}, 346 * {@link #SS_SMS_SERVICES}, 347 * {@link #SS_ALL_TELESERVICES_EXCEPT_SMS} 348 * @param serviceClass Supplementary Service service class. See See 27.007 +CCFC or +CLCK. 349 * @param result Result of Supplementary Service operation. Valid values are 0 if the result is 350 * success, or ImsReasonInfo code if the result is a failure. 351 */ ImsSsData(@erviceType int serviceType, int requestType, int teleserviceType, @ServiceClassFlags int serviceClass, int result)352 public ImsSsData(@ServiceType int serviceType, int requestType, int teleserviceType, 353 @ServiceClassFlags int serviceClass, int result) { 354 this.serviceType = serviceType; 355 this.requestType = requestType; 356 this.teleserviceType = teleserviceType; 357 this.serviceClass = serviceClass; 358 this.result = result; 359 } 360 ImsSsData(Parcel in)361 private ImsSsData(Parcel in) { 362 serviceType = in.readInt(); 363 requestType = in.readInt(); 364 teleserviceType = in.readInt(); 365 serviceClass = in.readInt(); 366 result = in.readInt(); 367 mSsInfo = in.createIntArray(); 368 mCfInfo = in.readParcelableList(new ArrayList<>(), this.getClass().getClassLoader(), android.telephony.ims.ImsCallForwardInfo.class); 369 mImsSsInfo = in.readParcelableList(new ArrayList<>(), this.getClass().getClassLoader(), android.telephony.ims.ImsSsInfo.class); 370 } 371 372 public static final @android.annotation.NonNull Creator<ImsSsData> CREATOR = new Creator<ImsSsData>() { 373 @Override 374 public ImsSsData createFromParcel(Parcel in) { 375 return new ImsSsData(in); 376 } 377 378 @Override 379 public ImsSsData[] newArray(int size) { 380 return new ImsSsData[size]; 381 } 382 }; 383 384 @Override writeToParcel(Parcel out, int flags)385 public void writeToParcel(Parcel out, int flags) { 386 out.writeInt(getServiceType()); 387 out.writeInt(getRequestType()); 388 out.writeInt(getTeleserviceType()); 389 out.writeInt(getServiceClass()); 390 out.writeInt(getResult()); 391 out.writeIntArray(mSsInfo); 392 out.writeParcelableList(mCfInfo, 0); 393 out.writeParcelableList(mImsSsInfo, 0); 394 } 395 396 @Override describeContents()397 public int describeContents() { 398 return 0; 399 } 400 401 /** 402 * Old method, kept for compatibility. See {@link #isTypeCf()} 403 * @hide 404 */ isTypeCF()405 public boolean isTypeCF() { 406 return (getServiceType() == SS_CFU || getServiceType() == SS_CF_BUSY 407 || getServiceType() == SS_CF_NO_REPLY || getServiceType() == SS_CF_NOT_REACHABLE 408 || getServiceType() == SS_CF_ALL || getServiceType() == SS_CF_ALL_CONDITIONAL); 409 } 410 isTypeCf()411 public boolean isTypeCf() { 412 return isTypeCF(); 413 } 414 isTypeUnConditional()415 public boolean isTypeUnConditional() { 416 return (getServiceType() == SS_CFU || getServiceType() == SS_CF_ALL); 417 } 418 419 /** 420 * Old method, kept for compatibility. See {@link #isTypeCf()} 421 * @hide 422 */ isTypeCW()423 public boolean isTypeCW() { 424 return (getServiceType() == SS_WAIT); 425 } 426 isTypeCw()427 public boolean isTypeCw() { 428 return isTypeCW(); 429 } 430 isTypeClip()431 public boolean isTypeClip() { 432 return (getServiceType() == SS_CLIP); 433 } 434 isTypeColr()435 public boolean isTypeColr() { 436 return (getServiceType() == SS_COLR); 437 } 438 isTypeColp()439 public boolean isTypeColp() { 440 return (getServiceType() == SS_COLP); 441 } 442 isTypeClir()443 public boolean isTypeClir() { 444 return (getServiceType() == SS_CLIR); 445 } 446 isTypeIcb()447 public boolean isTypeIcb() { 448 return (getServiceType() == SS_INCOMING_BARRING_DN 449 || getServiceType() == SS_INCOMING_BARRING_ANONYMOUS); 450 } 451 isTypeBarring()452 public boolean isTypeBarring() { 453 return (getServiceType() == SS_BAOC || getServiceType() == SS_BAOIC 454 || getServiceType() == SS_BAOIC_EXC_HOME || getServiceType() == SS_BAIC 455 || getServiceType() == SS_BAIC_ROAMING || getServiceType() == SS_ALL_BARRING 456 || getServiceType() == SS_OUTGOING_BARRING 457 || getServiceType() == SS_INCOMING_BARRING); 458 } 459 isTypeInterrogation()460 public boolean isTypeInterrogation() { 461 return (getRequestType() == SS_INTERROGATION); 462 } 463 464 /** 465 * Supplementary Service request Type. 466 */ getRequestType()467 public @RequestType int getRequestType() { 468 return requestType; 469 } 470 471 /** 472 * The Service type of this Supplementary service. 473 */ getServiceType()474 public @ServiceType int getServiceType() { 475 return serviceType; 476 } 477 478 /** 479 * Supplementary Service teleservice type. 480 */ getTeleserviceType()481 public @TeleserviceType int getTeleserviceType() { 482 return teleserviceType; 483 } 484 485 /** 486 * Supplementary Service service class. 487 */ getServiceClass()488 public @ServiceClassFlags int getServiceClass() { 489 return serviceClass; 490 } 491 492 /** 493 * Result of Supplementary Service operation. Valid values are: 494 * {@link #RESULT_SUCCESS} if the result is success, or 495 * {@link ImsReasonInfo.UtReason} code if the result is a failure. 496 */ getResult()497 public @ImsReasonInfo.UtReason int getResult() { 498 return result; 499 } 500 501 /** @hide */ setSuppServiceInfo(int[] ssInfo)502 public void setSuppServiceInfo(int[] ssInfo) { 503 mSsInfo = ssInfo; 504 } 505 506 /** @hide */ setImsSpecificSuppServiceInfo(ImsSsInfo[] imsSsInfo)507 public void setImsSpecificSuppServiceInfo(ImsSsInfo[] imsSsInfo) { 508 mImsSsInfo = Arrays.asList(imsSsInfo); 509 } 510 511 /** @hide */ setCallForwardingInfo(ImsCallForwardInfo[] cfInfo)512 public void setCallForwardingInfo(ImsCallForwardInfo[] cfInfo) { 513 mCfInfo = Arrays.asList(cfInfo); 514 } 515 516 /** 517 * This is a compatibility function to transform the public API to a form that can be processed 518 * by telephony. 519 * 520 * @hide 521 */ 522 //TODO: Refactor Telephony to use well defined classes instead of an int[] to process SS. getSuppServiceInfoCompat()523 public int[] getSuppServiceInfoCompat() { 524 if (mSsInfo != null) { 525 // Something has set the ssInfo using hidden APIs, so for compatibility just return that 526 // structure directly. 527 return mSsInfo; 528 } 529 530 531 int[] result = new int[2]; 532 if (mImsSsInfo == null || mImsSsInfo.size() == 0) { 533 Rlog.e(TAG, "getSuppServiceInfoCompat: Could not parse mImsSsInfo, returning empty " 534 + "int[]"); 535 return result; 536 } 537 538 // Convert ImsSsInfo into a form that telephony can read (as per 3GPP 27.007) 539 // CLIR (section 7.7) 540 if (isTypeClir()) { 541 // Assume there will only be one ImsSsInfo. 542 // contains {"n","m"} parameters 543 result[0] = mImsSsInfo.get(0).getClirOutgoingState(); 544 result[1] = mImsSsInfo.get(0).getClirInterrogationStatus(); 545 return result; 546 } 547 // COLR 7.31 548 if (isTypeColr()) { 549 result[0] = mImsSsInfo.get(0).getProvisionStatus(); 550 } 551 // Facility Lock CLCK 7.4 (for call barring), CLIP 7.6, COLP 7.8, as well as any 552 // other result, just return the status for the "n" parameter and provisioning status for 553 // "m" as the default. 554 result[0] = mImsSsInfo.get(0).getStatus(); 555 result[1] = mImsSsInfo.get(0).getProvisionStatus(); 556 return result; 557 } 558 559 /** 560 * @return an array of {@link ImsSsInfo}s associated with this supplementary service data. 561 */ getSuppServiceInfo()562 public @NonNull List<ImsSsInfo> getSuppServiceInfo() { 563 return mImsSsInfo; 564 } 565 566 /** 567 * @return an array of {@link ImsCallForwardInfo}s associated with this supplementary service 568 * data. 569 **/ getCallForwardInfo()570 public @Nullable List<ImsCallForwardInfo> getCallForwardInfo() { 571 return mCfInfo; 572 } 573 574 @NonNull 575 @Override toString()576 public String toString() { 577 return "[ImsSsData] " + "ServiceType: " + getServiceType() 578 + " RequestType: " + getRequestType() 579 + " TeleserviceType: " + getTeleserviceType() 580 + " ServiceClass: " + getServiceClass() 581 + " Result: " + getResult(); 582 } 583 } 584