1 /* 2 * Copyright (C) 2020 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.ims.rcs.uce.util; 18 19 import android.telephony.ims.RcsUceAdapter; 20 21 import com.android.ims.rcs.uce.UceController; 22 import com.android.ims.rcs.uce.UceController.RequestType; 23 24 /** 25 * Define the network sip code and the reason. 26 */ 27 public class NetworkSipCode { 28 public static final int SIP_CODE_OK = 200; 29 public static final int SIP_CODE_ACCEPTED = 202; 30 public static final int SIP_CODE_BAD_REQUEST = 400; 31 public static final int SIP_CODE_FORBIDDEN = 403; 32 public static final int SIP_CODE_NOT_FOUND = 404; 33 public static final int SIP_CODE_METHOD_NOT_ALLOWED = 405; 34 public static final int SIP_CODE_REQUEST_TIMEOUT = 408; 35 public static final int SIP_CODE_INTERVAL_TOO_BRIEF = 423; 36 public static final int SIP_CODE_TEMPORARILY_UNAVAILABLE = 480; 37 public static final int SIP_CODE_BAD_EVENT = 489; 38 public static final int SIP_CODE_BUSY = 486; 39 public static final int SIP_CODE_SERVER_INTERNAL_ERROR = 500; 40 public static final int SIP_CODE_SERVICE_UNAVAILABLE = 503; 41 public static final int SIP_CODE_SERVER_TIMEOUT = 504; 42 public static final int SIP_CODE_BUSY_EVERYWHERE = 600; 43 public static final int SIP_CODE_DECLINE = 603; 44 public static final int SIP_CODE_DOES_NOT_EXIST_ANYWHERE = 604; 45 46 public static final String SIP_OK = "OK"; 47 public static final String SIP_ACCEPTED = "Accepted"; 48 public static final String SIP_BAD_REQUEST = "Bad Request"; 49 public static final String SIP_SERVICE_UNAVAILABLE = "Service Unavailable"; 50 public static final String SIP_INTERNAL_SERVER_ERROR = "Internal Server Error"; 51 public static final String SIP_NOT_REGISTERED = "User not registered"; 52 public static final String SIP_NOT_AUTHORIZED_FOR_PRESENCE = "not authorized for presence"; 53 54 /** 55 * Convert the given SIP CODE to the Contact uce capabilities error. 56 * @param sipCode The SIP code of the request response. 57 * @param reason The reason of the request response. 58 * @param requestType The type of this request. 59 * @return The RCS contact UCE capabilities error which is defined in RcsUceAdapter. 60 */ getCapabilityErrorFromSipCode(int sipCode, String reason, @RequestType int requestType)61 public static int getCapabilityErrorFromSipCode(int sipCode, String reason, 62 @RequestType int requestType) { 63 int uceError; 64 switch (sipCode) { 65 case NetworkSipCode.SIP_CODE_FORBIDDEN: // 403 66 if(requestType == UceController.REQUEST_TYPE_PUBLISH) { 67 // Not provisioned for PUBLISH request. 68 uceError = RcsUceAdapter.ERROR_NOT_AUTHORIZED; 69 } else { 70 // Check the reason for CAPABILITY request 71 if (NetworkSipCode.SIP_NOT_REGISTERED.equalsIgnoreCase(reason)) { 72 // Not registered with IMS. Device shall register to IMS. 73 uceError = RcsUceAdapter.ERROR_NOT_REGISTERED; 74 } else if (NetworkSipCode.SIP_NOT_AUTHORIZED_FOR_PRESENCE.equalsIgnoreCase( 75 reason)) { 76 // Not provisioned for EAB. Device shall not retry. 77 uceError = RcsUceAdapter.ERROR_NOT_AUTHORIZED; 78 } else { 79 // The network has responded SIP 403 error with no reason. 80 uceError = RcsUceAdapter.ERROR_FORBIDDEN; 81 } 82 } 83 break; 84 case NetworkSipCode.SIP_CODE_NOT_FOUND: // 404 85 if(requestType == UceController.REQUEST_TYPE_PUBLISH) { 86 // Not provisioned for PUBLISH request. 87 uceError = RcsUceAdapter.ERROR_NOT_AUTHORIZED; 88 } else { 89 uceError = RcsUceAdapter.ERROR_NOT_FOUND; 90 } 91 break; 92 case NetworkSipCode.SIP_CODE_REQUEST_TIMEOUT: // 408 93 uceError = RcsUceAdapter.ERROR_REQUEST_TIMEOUT; 94 break; 95 case NetworkSipCode.SIP_CODE_INTERVAL_TOO_BRIEF: // 423 96 // Rejected by the network because the requested expiry interval is too short. 97 uceError = RcsUceAdapter.ERROR_GENERIC_FAILURE; 98 break; 99 case NetworkSipCode.SIP_CODE_BAD_EVENT: 100 uceError = RcsUceAdapter.ERROR_FORBIDDEN; // 489 101 break; 102 case NetworkSipCode.SIP_CODE_SERVER_INTERNAL_ERROR: // 500 103 case NetworkSipCode.SIP_CODE_SERVICE_UNAVAILABLE: // 503 104 // The network is temporarily unavailable or busy. 105 uceError = RcsUceAdapter.ERROR_SERVER_UNAVAILABLE; 106 break; 107 default: 108 uceError = RcsUceAdapter.ERROR_GENERIC_FAILURE; 109 break; 110 } 111 return uceError; 112 } 113 } 114