1 /* 2 * Copyright (C) 2021 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.internal.telephony; 18 19 import static android.telephony.TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE; 20 import static android.telephony.TelephonyManager.CAPABILITY_PHYSICAL_CHANNEL_CONFIG_1_6_SUPPORTED; 21 import static android.telephony.TelephonyManager.CAPABILITY_SECONDARY_LINK_BANDWIDTH_VISIBLE; 22 import static android.telephony.TelephonyManager.CAPABILITY_SIM_PHONEBOOK_IN_MODEM; 23 import static android.telephony.TelephonyManager.CAPABILITY_SLICING_CONFIG_SUPPORTED; 24 import static android.telephony.TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING; 25 import static android.telephony.TelephonyManager.CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK; 26 27 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU; 28 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ALLOCATE_PDU_SESSION_ID; 29 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ALLOW_DATA; 30 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ANSWER; 31 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_BASEBAND_VERSION; 32 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CANCEL_EMERGENCY_NETWORK_SCAN; 33 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CANCEL_HANDOVER; 34 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CANCEL_USSD; 35 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CDMA_BROADCAST_ACTIVATION; 36 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CDMA_BURST_DTMF; 37 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM; 38 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CDMA_FLASH; 39 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CDMA_GET_BROADCAST_CONFIG; 40 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE; 41 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE; 42 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE; 43 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CDMA_SEND_SMS; 44 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CDMA_SEND_SMS_EXPECT_MORE; 45 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CDMA_SET_BROADCAST_CONFIG; 46 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE; 47 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE; 48 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE; 49 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE; 50 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CDMA_SUBSCRIPTION; 51 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY; 52 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM; 53 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CHANGE_BARRING_PASSWORD; 54 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CHANGE_SIM_PIN; 55 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CHANGE_SIM_PIN2; 56 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CONFERENCE; 57 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_DATA_CALL_LIST; 58 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_DATA_REGISTRATION_STATE; 59 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_DEACTIVATE_DATA_CALL; 60 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_DELETE_SMS_ON_SIM; 61 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_DEVICE_IDENTITY; 62 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_DEVICE_IMEI; 63 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_DIAL; 64 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_DTMF; 65 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_DTMF_START; 66 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_DTMF_STOP; 67 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_EMERGENCY_DIAL; 68 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ENABLE_MODEM; 69 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ENABLE_NR_DUAL_CONNECTIVITY; 70 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ENABLE_UICC_APPLICATIONS; 71 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ENABLE_VONR; 72 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION; 73 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ENTER_SIM_DEPERSONALIZATION; 74 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ENTER_SIM_PIN; 75 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ENTER_SIM_PIN2; 76 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ENTER_SIM_PUK; 77 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ENTER_SIM_PUK2; 78 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE; 79 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_EXIT_EMERGENCY_MODE; 80 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_EXPLICIT_CALL_TRANSFER; 81 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_ACTIVITY_INFO; 82 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_ALLOWED_CARRIERS; 83 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_ALLOWED_NETWORK_TYPES_BITMAP; 84 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_BARRING_INFO; 85 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_CELL_INFO_LIST; 86 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_CLIR; 87 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_CURRENT_CALLS; 88 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_DC_RT_INFO; 89 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_HAL_DEVICE_CAPABILITIES; 90 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_HARDWARE_CONFIG; 91 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_IMEI; 92 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_IMEISV; 93 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_IMSI; 94 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_LOCATION_PRIVACY_SETTING; 95 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_MODEM_STATUS; 96 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_MUTE; 97 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_NEIGHBORING_CELL_IDS; 98 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_PHONE_CAPABILITY; 99 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE; 100 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_RADIO_CAPABILITY; 101 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_SIMULTANEOUS_CALLING_SUPPORT; 102 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_SIM_PHONEBOOK_CAPACITY; 103 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_SIM_PHONEBOOK_RECORDS; 104 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_SIM_STATUS; 105 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_SLICING_CONFIG; 106 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_SLOT_STATUS; 107 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_SMSC_ADDRESS; 108 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_SYSTEM_SELECTION_CHANNELS; 109 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_UICC_APPLICATIONS_ENABLEMENT; 110 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_USAGE_SETTING; 111 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GSM_BROADCAST_ACTIVATION; 112 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GSM_GET_BROADCAST_CONFIG; 113 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GSM_SET_BROADCAST_CONFIG; 114 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_HANGUP; 115 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND; 116 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND; 117 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_IMS_REGISTRATION_STATE; 118 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_IMS_SEND_SMS; 119 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ISIM_AUTHENTICATION; 120 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_IS_CELLULAR_IDENTIFIER_DISCLOSED_ENABLED; 121 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_IS_N1_MODE_ENABLED; 122 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_IS_NR_DUAL_CONNECTIVITY_ENABLED; 123 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_IS_NULL_CIPHER_AND_INTEGRITY_ENABLED; 124 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_IS_SATELLITE_ENABLED_FOR_CARRIER; 125 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_IS_SECURITY_ALGORITHMS_UPDATED_ENABLED; 126 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_IS_VONR_ENABLED; 127 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_LAST_CALL_FAIL_CAUSE; 128 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE; 129 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_NV_READ_ITEM; 130 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_NV_RESET_CONFIG; 131 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_NV_WRITE_CDMA_PRL; 132 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_NV_WRITE_ITEM; 133 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_OEM_HOOK_RAW; 134 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_OEM_HOOK_STRINGS; 135 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_OPERATOR; 136 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_PULL_LCEDATA; 137 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE; 138 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_QUERY_AVAILABLE_NETWORKS; 139 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_QUERY_CALL_FORWARD_STATUS; 140 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_QUERY_CALL_WAITING; 141 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_QUERY_CLIP; 142 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_QUERY_FACILITY_LOCK; 143 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE; 144 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_QUERY_TTY_MODE; 145 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_RADIO_POWER; 146 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_RELEASE_PDU_SESSION_ID; 147 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_REPORT_SMS_MEMORY_STATUS; 148 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING; 149 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_RESET_RADIO; 150 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SCREEN_STATE; 151 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SEND_ANBR_QUERY; 152 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SEND_DEVICE_STATE; 153 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SEND_SMS; 154 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SEND_SMS_EXPECT_MORE; 155 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SEND_USSD; 156 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SEPARATE_CONNECTION; 157 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SETUP_DATA_CALL; 158 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_ALLOWED_CARRIERS; 159 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_ALLOWED_NETWORK_TYPES_BITMAP; 160 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_BAND_MODE; 161 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_CALL_FORWARD; 162 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_CALL_WAITING; 163 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_CARRIER_INFO_IMSI_ENCRYPTION; 164 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_CELLULAR_IDENTIFIER_DISCLOSED_ENABLED; 165 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_CLIR; 166 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_DATA_PROFILE; 167 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_DATA_THROTTLING; 168 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_DC_RT_INFO_RATE; 169 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_EMERGENCY_MODE; 170 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_FACILITY_LOCK; 171 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_INITIAL_ATTACH_APN; 172 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_LINK_CAPACITY_REPORTING_CRITERIA; 173 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_LOCATION_PRIVACY_SETTING; 174 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_LOCATION_UPDATES; 175 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_LOGICAL_TO_PHYSICAL_SLOT_MAPPING; 176 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_MUTE; 177 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_N1_MODE_ENABLED; 178 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC; 179 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL; 180 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_NULL_CIPHER_AND_INTEGRITY_ENABLED; 181 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_PREFERRED_DATA_MODEM; 182 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE; 183 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_RADIO_CAPABILITY; 184 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_SATELLITE_ENABLED_FOR_CARRIER; 185 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_SATELLITE_PLMN; 186 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_SECURITY_ALGORITHMS_UPDATED_ENABLED; 187 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_SIGNAL_STRENGTH_REPORTING_CRITERIA; 188 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_SIM_CARD_POWER; 189 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_SMSC_ADDRESS; 190 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_SRVCC_CALL_INFO; 191 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION; 192 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_SYSTEM_SELECTION_CHANNELS; 193 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_TTY_MODE; 194 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_UICC_SUBSCRIPTION; 195 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER; 196 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE; 197 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_USAGE_SETTING; 198 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SHUTDOWN; 199 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SIGNAL_STRENGTH; 200 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SIM_AUTHENTICATION; 201 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SIM_CLOSE_CHANNEL; 202 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SIM_IO; 203 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SIM_OPEN_CHANNEL; 204 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC; 205 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL; 206 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SMS_ACKNOWLEDGE; 207 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_START_HANDOVER; 208 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_START_IMS_TRAFFIC; 209 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_START_KEEPALIVE; 210 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_START_LCE; 211 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_START_NETWORK_SCAN; 212 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_STK_GET_PROFILE; 213 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM; 214 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND; 215 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS; 216 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE; 217 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_STK_SET_PROFILE; 218 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_STOP_IMS_TRAFFIC; 219 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_STOP_KEEPALIVE; 220 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_STOP_LCE; 221 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_STOP_NETWORK_SCAN; 222 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SWITCH_DUAL_SIM_CONFIG; 223 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE; 224 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_TRIGGER_EMERGENCY_NETWORK_SCAN; 225 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_TRIGGER_EPS_FALLBACK; 226 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_UDUB; 227 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_UPDATE_IMS_CALL_STATUS; 228 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_UPDATE_IMS_REGISTRATION_INFO; 229 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_UPDATE_SIM_PHONEBOOK_RECORD; 230 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_VOICE_RADIO_TECH; 231 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_VOICE_REGISTRATION_STATE; 232 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_WRITE_SMS_TO_SIM; 233 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_BARRING_INFO_CHANGED; 234 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_CALL_RING; 235 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_CARRIER_INFO_IMSI_ENCRYPTION; 236 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_CDMA_CALL_WAITING; 237 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_CDMA_INFO_REC; 238 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_CDMA_OTA_PROVISION_STATUS; 239 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_CDMA_PRL_CHANGED; 240 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL; 241 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED; 242 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_CELLULAR_IDENTIFIER_DISCLOSED; 243 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_CELL_INFO_LIST; 244 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_CONNECTION_SETUP_FAILURE; 245 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_DATA_CALL_LIST_CHANGED; 246 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_DC_RT_INFO_CHANGED; 247 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_EMERGENCY_NETWORK_SCAN_RESULT; 248 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_EMERGENCY_NUMBER_LIST; 249 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE; 250 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE; 251 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_HARDWARE_CONFIG_CHANGED; 252 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_ICC_SLOT_STATUS; 253 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_IMEI_MAPPING_CHANGED; 254 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_KEEPALIVE_STATUS; 255 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_LCEDATA_RECV; 256 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_MODEM_RESTART; 257 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_NETWORK_SCAN_RESULT; 258 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_NITZ_TIME_RECEIVED; 259 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_NOTIFY_ANBR; 260 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_OEM_HOOK_RAW; 261 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_ON_SS; 262 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_ON_USSD; 263 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_ON_USSD_REQUEST; 264 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_PCO_DATA; 265 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_PHYSICAL_CHANNEL_CONFIG; 266 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_RADIO_CAPABILITY; 267 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_REGISTRATION_FAILED; 268 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_RESEND_INCALL_MUTE; 269 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED; 270 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_RESPONSE_CDMA_NEW_SMS; 271 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED; 272 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_RESPONSE_NETWORK_STATE_CHANGED; 273 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS; 274 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_RESPONSE_NEW_SMS; 275 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM; 276 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT; 277 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED; 278 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_RESPONSE_SIM_PHONEBOOK_CHANGED; 279 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_RESPONSE_SIM_PHONEBOOK_RECORDS_RECEIVED; 280 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED; 281 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_RESTRICTED_STATE_CHANGED; 282 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_RIL_CONNECTED; 283 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_RINGBACK_TONE; 284 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_SECURITY_ALGORITHMS_UPDATED; 285 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_SIGNAL_STRENGTH; 286 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_SIMULTANEOUS_CALLING_SUPPORT_CHANGED; 287 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_SIM_REFRESH; 288 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_SIM_SMS_STORAGE_FULL; 289 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_SLICING_CONFIG_CHANGED; 290 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_SRVCC_STATE_NOTIFY; 291 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_STK_CALL_SETUP; 292 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_STK_CC_ALPHA_NOTIFY; 293 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_STK_EVENT_NOTIFY; 294 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_STK_PROACTIVE_COMMAND; 295 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_STK_SESSION_END; 296 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_SUPP_SVC_NOTIFICATION; 297 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_TRIGGER_IMS_DEREGISTRATION; 298 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_UICC_APPLICATIONS_ENABLEMENT_CHANGED; 299 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED; 300 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_UNTHROTTLE_APN; 301 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_VOICE_RADIO_TECH_CHANGED; 302 303 import android.annotation.NonNull; 304 import android.annotation.Nullable; 305 import android.hardware.radio.data.SliceInfo; 306 import android.net.InetAddresses; 307 import android.net.LinkAddress; 308 import android.net.LinkProperties; 309 import android.os.SystemClock; 310 import android.service.carrier.CarrierIdentifier; 311 import android.telephony.AccessNetworkConstants; 312 import android.telephony.Annotation; 313 import android.telephony.BarringInfo; 314 import android.telephony.CarrierInfo; 315 import android.telephony.CarrierRestrictionRules; 316 import android.telephony.CellConfigLte; 317 import android.telephony.CellIdentity; 318 import android.telephony.CellIdentityCdma; 319 import android.telephony.CellIdentityGsm; 320 import android.telephony.CellIdentityLte; 321 import android.telephony.CellIdentityNr; 322 import android.telephony.CellIdentityTdscdma; 323 import android.telephony.CellIdentityWcdma; 324 import android.telephony.CellInfo; 325 import android.telephony.CellInfoCdma; 326 import android.telephony.CellInfoGsm; 327 import android.telephony.CellInfoLte; 328 import android.telephony.CellInfoNr; 329 import android.telephony.CellInfoTdscdma; 330 import android.telephony.CellInfoWcdma; 331 import android.telephony.CellSignalStrength; 332 import android.telephony.CellSignalStrengthCdma; 333 import android.telephony.CellSignalStrengthGsm; 334 import android.telephony.CellSignalStrengthLte; 335 import android.telephony.CellSignalStrengthNr; 336 import android.telephony.CellSignalStrengthTdscdma; 337 import android.telephony.CellSignalStrengthWcdma; 338 import android.telephony.CellularIdentifierDisclosure; 339 import android.telephony.ClosedSubscriberGroupInfo; 340 import android.telephony.DomainSelectionService; 341 import android.telephony.EmergencyRegistrationResult; 342 import android.telephony.LinkCapacityEstimate; 343 import android.telephony.ModemInfo; 344 import android.telephony.NetworkRegistrationInfo; 345 import android.telephony.PhoneCapability; 346 import android.telephony.PhoneNumberUtils; 347 import android.telephony.PhysicalChannelConfig; 348 import android.telephony.RadioAccessSpecifier; 349 import android.telephony.SecurityAlgorithmUpdate; 350 import android.telephony.ServiceState; 351 import android.telephony.SignalStrength; 352 import android.telephony.SignalThresholdInfo; 353 import android.telephony.SmsManager; 354 import android.telephony.TelephonyManager; 355 import android.telephony.UiccSlotMapping; 356 import android.telephony.data.ApnSetting; 357 import android.telephony.data.DataCallResponse; 358 import android.telephony.data.DataProfile; 359 import android.telephony.data.DataService; 360 import android.telephony.data.DataService.DeactivateDataReason; 361 import android.telephony.data.DataService.SetupDataReason; 362 import android.telephony.data.EpsQos; 363 import android.telephony.data.NetworkSliceInfo; 364 import android.telephony.data.NetworkSlicingConfig; 365 import android.telephony.data.NrQos; 366 import android.telephony.data.Qos; 367 import android.telephony.data.QosBearerFilter; 368 import android.telephony.data.QosBearerSession; 369 import android.telephony.data.RouteSelectionDescriptor; 370 import android.telephony.data.TrafficDescriptor; 371 import android.telephony.data.UrspRule; 372 import android.telephony.ims.RegistrationManager; 373 import android.telephony.ims.feature.ConnectionFailureInfo; 374 import android.telephony.ims.feature.MmTelFeature; 375 import android.telephony.ims.stub.ImsRegistrationImplBase; 376 import android.telephony.ims.stub.ImsRegistrationImplBase.ImsDeregistrationReason; 377 import android.text.TextUtils; 378 import android.util.ArraySet; 379 import android.util.SparseArray; 380 381 import com.android.internal.annotations.VisibleForTesting; 382 import com.android.internal.telephony.cat.ComprehensionTlv; 383 import com.android.internal.telephony.cat.ComprehensionTlvTag; 384 import com.android.internal.telephony.cdma.SmsMessage; 385 import com.android.internal.telephony.cdma.sms.CdmaSmsAddress; 386 import com.android.internal.telephony.cdma.sms.CdmaSmsSubaddress; 387 import com.android.internal.telephony.cdma.sms.SmsEnvelope; 388 import com.android.internal.telephony.data.KeepaliveStatus; 389 import com.android.internal.telephony.data.KeepaliveStatus.KeepaliveStatusCode; 390 import com.android.internal.telephony.flags.Flags; 391 import com.android.internal.telephony.imsphone.ImsCallInfo; 392 import com.android.internal.telephony.uicc.AdnCapacity; 393 import com.android.internal.telephony.uicc.IccCardApplicationStatus; 394 import com.android.internal.telephony.uicc.IccCardStatus; 395 import com.android.internal.telephony.uicc.IccSimPortInfo; 396 import com.android.internal.telephony.uicc.IccSlotPortMapping; 397 import com.android.internal.telephony.uicc.IccSlotStatus; 398 import com.android.internal.telephony.uicc.IccUtils; 399 import com.android.internal.telephony.uicc.PortUtils; 400 import com.android.internal.telephony.uicc.SimPhonebookRecord; 401 import com.android.internal.telephony.uicc.SimTypeInfo; 402 import com.android.telephony.Rlog; 403 404 import java.io.ByteArrayInputStream; 405 import java.io.DataInputStream; 406 import java.io.IOException; 407 import java.lang.reflect.Array; 408 import java.lang.reflect.Field; 409 import java.lang.reflect.InvocationTargetException; 410 import java.lang.reflect.Method; 411 import java.lang.reflect.Modifier; 412 import java.net.Inet4Address; 413 import java.net.InetAddress; 414 import java.util.ArrayList; 415 import java.util.Arrays; 416 import java.util.Collections; 417 import java.util.HashSet; 418 import java.util.List; 419 import java.util.Locale; 420 import java.util.Objects; 421 import java.util.Set; 422 import java.util.stream.Collectors; 423 424 /** 425 * Utils class for HAL <-> RIL conversions 426 */ 427 public class RILUtils { 428 private static final String TAG = "RILUtils"; 429 430 // The number of required config values for broadcast SMS stored in RIL_CdmaBroadcastServiceInfo 431 public static final int CDMA_BSI_NO_OF_INTS_STRUCT = 3; 432 // The number of service categories for broadcast SMS 433 public static final int CDMA_BROADCAST_SMS_NO_OF_SERVICE_CATEGORIES = 31; 434 435 // Radio power failure UUIDs 436 public static final String RADIO_POWER_FAILURE_BUGREPORT_UUID = 437 "316f3801-fa21-4954-a42f-0041eada3b31"; 438 public static final String RADIO_POWER_FAILURE_RF_HARDWARE_ISSUE_UUID = 439 "316f3801-fa21-4954-a42f-0041eada3b32"; 440 public static final String RADIO_POWER_FAILURE_NO_RF_CALIBRATION_UUID = 441 "316f3801-fa21-4954-a42f-0041eada3b33"; 442 443 private static final Set<Class> WRAPPER_CLASSES = new HashSet(Arrays.asList( 444 Boolean.class, Character.class, Byte.class, Short.class, Integer.class, Long.class, 445 Float.class, Double.class)); 446 447 /** 448 * Convert to PersoSubstate defined in radio/1.5/types.hal 449 * @param persoType PersoSubState type 450 * @return The converted PersoSubstate 451 */ convertToHalPersoType( IccCardApplicationStatus.PersoSubState persoType)452 public static int convertToHalPersoType( 453 IccCardApplicationStatus.PersoSubState persoType) { 454 switch (persoType) { 455 case PERSOSUBSTATE_IN_PROGRESS: 456 return android.hardware.radio.V1_5.PersoSubstate.IN_PROGRESS; 457 case PERSOSUBSTATE_READY: 458 return android.hardware.radio.V1_5.PersoSubstate.READY; 459 case PERSOSUBSTATE_SIM_NETWORK: 460 return android.hardware.radio.V1_5.PersoSubstate.SIM_NETWORK; 461 case PERSOSUBSTATE_SIM_NETWORK_SUBSET: 462 return android.hardware.radio.V1_5.PersoSubstate.SIM_NETWORK_SUBSET; 463 case PERSOSUBSTATE_SIM_CORPORATE: 464 return android.hardware.radio.V1_5.PersoSubstate.SIM_CORPORATE; 465 case PERSOSUBSTATE_SIM_SERVICE_PROVIDER: 466 return android.hardware.radio.V1_5.PersoSubstate.SIM_SERVICE_PROVIDER; 467 case PERSOSUBSTATE_SIM_SIM: 468 return android.hardware.radio.V1_5.PersoSubstate.SIM_SIM; 469 case PERSOSUBSTATE_SIM_NETWORK_PUK: 470 return android.hardware.radio.V1_5.PersoSubstate.SIM_NETWORK_PUK; 471 case PERSOSUBSTATE_SIM_NETWORK_SUBSET_PUK: 472 return android.hardware.radio.V1_5.PersoSubstate.SIM_NETWORK_SUBSET_PUK; 473 case PERSOSUBSTATE_SIM_CORPORATE_PUK: 474 return android.hardware.radio.V1_5.PersoSubstate.SIM_CORPORATE_PUK; 475 case PERSOSUBSTATE_SIM_SERVICE_PROVIDER_PUK: 476 return android.hardware.radio.V1_5.PersoSubstate.SIM_SERVICE_PROVIDER_PUK; 477 case PERSOSUBSTATE_SIM_SIM_PUK: 478 return android.hardware.radio.V1_5.PersoSubstate.SIM_SIM_PUK; 479 case PERSOSUBSTATE_RUIM_NETWORK1: 480 return android.hardware.radio.V1_5.PersoSubstate.RUIM_NETWORK1; 481 case PERSOSUBSTATE_RUIM_NETWORK2: 482 return android.hardware.radio.V1_5.PersoSubstate.RUIM_NETWORK2; 483 case PERSOSUBSTATE_RUIM_HRPD: 484 return android.hardware.radio.V1_5.PersoSubstate.RUIM_HRPD; 485 case PERSOSUBSTATE_RUIM_CORPORATE: 486 return android.hardware.radio.V1_5.PersoSubstate.RUIM_CORPORATE; 487 case PERSOSUBSTATE_RUIM_SERVICE_PROVIDER: 488 return android.hardware.radio.V1_5.PersoSubstate.RUIM_SERVICE_PROVIDER; 489 case PERSOSUBSTATE_RUIM_RUIM: 490 return android.hardware.radio.V1_5.PersoSubstate.RUIM_RUIM; 491 case PERSOSUBSTATE_RUIM_NETWORK1_PUK: 492 return android.hardware.radio.V1_5.PersoSubstate.RUIM_NETWORK1_PUK; 493 case PERSOSUBSTATE_RUIM_NETWORK2_PUK: 494 return android.hardware.radio.V1_5.PersoSubstate.RUIM_NETWORK2_PUK; 495 case PERSOSUBSTATE_RUIM_HRPD_PUK: 496 return android.hardware.radio.V1_5.PersoSubstate.RUIM_HRPD_PUK; 497 case PERSOSUBSTATE_RUIM_CORPORATE_PUK: 498 return android.hardware.radio.V1_5.PersoSubstate.RUIM_CORPORATE_PUK; 499 case PERSOSUBSTATE_RUIM_SERVICE_PROVIDER_PUK: 500 return android.hardware.radio.V1_5.PersoSubstate.RUIM_SERVICE_PROVIDER_PUK; 501 case PERSOSUBSTATE_RUIM_RUIM_PUK: 502 return android.hardware.radio.V1_5.PersoSubstate.RUIM_RUIM_PUK; 503 case PERSOSUBSTATE_SIM_SPN: 504 return android.hardware.radio.V1_5.PersoSubstate.SIM_SPN; 505 case PERSOSUBSTATE_SIM_SPN_PUK: 506 return android.hardware.radio.V1_5.PersoSubstate.SIM_SPN_PUK; 507 case PERSOSUBSTATE_SIM_SP_EHPLMN: 508 return android.hardware.radio.V1_5.PersoSubstate.SIM_SP_EHPLMN; 509 case PERSOSUBSTATE_SIM_SP_EHPLMN_PUK: 510 return android.hardware.radio.V1_5.PersoSubstate.SIM_SP_EHPLMN_PUK; 511 case PERSOSUBSTATE_SIM_ICCID: 512 return android.hardware.radio.V1_5.PersoSubstate.SIM_ICCID; 513 case PERSOSUBSTATE_SIM_ICCID_PUK: 514 return android.hardware.radio.V1_5.PersoSubstate.SIM_ICCID_PUK; 515 case PERSOSUBSTATE_SIM_IMPI: 516 return android.hardware.radio.V1_5.PersoSubstate.SIM_IMPI; 517 case PERSOSUBSTATE_SIM_IMPI_PUK: 518 return android.hardware.radio.V1_5.PersoSubstate.SIM_IMPI_PUK; 519 case PERSOSUBSTATE_SIM_NS_SP: 520 return android.hardware.radio.V1_5.PersoSubstate.SIM_NS_SP; 521 case PERSOSUBSTATE_SIM_NS_SP_PUK: 522 return android.hardware.radio.V1_5.PersoSubstate.SIM_NS_SP_PUK; 523 default: 524 return android.hardware.radio.V1_5.PersoSubstate.UNKNOWN; 525 } 526 } 527 528 /** 529 * Convert to PersoSubstate.aidl 530 * @param persoType PersoSubState type 531 * @return The converted PersoSubstate 532 */ convertToHalPersoTypeAidl( IccCardApplicationStatus.PersoSubState persoType)533 public static int convertToHalPersoTypeAidl( 534 IccCardApplicationStatus.PersoSubState persoType) { 535 switch (persoType) { 536 case PERSOSUBSTATE_IN_PROGRESS: 537 return android.hardware.radio.sim.PersoSubstate.IN_PROGRESS; 538 case PERSOSUBSTATE_READY: 539 return android.hardware.radio.sim.PersoSubstate.READY; 540 case PERSOSUBSTATE_SIM_NETWORK: 541 return android.hardware.radio.sim.PersoSubstate.SIM_NETWORK; 542 case PERSOSUBSTATE_SIM_NETWORK_SUBSET: 543 return android.hardware.radio.sim.PersoSubstate.SIM_NETWORK_SUBSET; 544 case PERSOSUBSTATE_SIM_CORPORATE: 545 return android.hardware.radio.sim.PersoSubstate.SIM_CORPORATE; 546 case PERSOSUBSTATE_SIM_SERVICE_PROVIDER: 547 return android.hardware.radio.sim.PersoSubstate.SIM_SERVICE_PROVIDER; 548 case PERSOSUBSTATE_SIM_SIM: 549 return android.hardware.radio.sim.PersoSubstate.SIM_SIM; 550 case PERSOSUBSTATE_SIM_NETWORK_PUK: 551 return android.hardware.radio.sim.PersoSubstate.SIM_NETWORK_PUK; 552 case PERSOSUBSTATE_SIM_NETWORK_SUBSET_PUK: 553 return android.hardware.radio.sim.PersoSubstate.SIM_NETWORK_SUBSET_PUK; 554 case PERSOSUBSTATE_SIM_CORPORATE_PUK: 555 return android.hardware.radio.sim.PersoSubstate.SIM_CORPORATE_PUK; 556 case PERSOSUBSTATE_SIM_SERVICE_PROVIDER_PUK: 557 return android.hardware.radio.sim.PersoSubstate.SIM_SERVICE_PROVIDER_PUK; 558 case PERSOSUBSTATE_SIM_SIM_PUK: 559 return android.hardware.radio.sim.PersoSubstate.SIM_SIM_PUK; 560 case PERSOSUBSTATE_RUIM_NETWORK1: 561 return android.hardware.radio.sim.PersoSubstate.RUIM_NETWORK1; 562 case PERSOSUBSTATE_RUIM_NETWORK2: 563 return android.hardware.radio.sim.PersoSubstate.RUIM_NETWORK2; 564 case PERSOSUBSTATE_RUIM_HRPD: 565 return android.hardware.radio.sim.PersoSubstate.RUIM_HRPD; 566 case PERSOSUBSTATE_RUIM_CORPORATE: 567 return android.hardware.radio.sim.PersoSubstate.RUIM_CORPORATE; 568 case PERSOSUBSTATE_RUIM_SERVICE_PROVIDER: 569 return android.hardware.radio.sim.PersoSubstate.RUIM_SERVICE_PROVIDER; 570 case PERSOSUBSTATE_RUIM_RUIM: 571 return android.hardware.radio.sim.PersoSubstate.RUIM_RUIM; 572 case PERSOSUBSTATE_RUIM_NETWORK1_PUK: 573 return android.hardware.radio.sim.PersoSubstate.RUIM_NETWORK1_PUK; 574 case PERSOSUBSTATE_RUIM_NETWORK2_PUK: 575 return android.hardware.radio.sim.PersoSubstate.RUIM_NETWORK2_PUK; 576 case PERSOSUBSTATE_RUIM_HRPD_PUK: 577 return android.hardware.radio.sim.PersoSubstate.RUIM_HRPD_PUK; 578 case PERSOSUBSTATE_RUIM_CORPORATE_PUK: 579 return android.hardware.radio.sim.PersoSubstate.RUIM_CORPORATE_PUK; 580 case PERSOSUBSTATE_RUIM_SERVICE_PROVIDER_PUK: 581 return android.hardware.radio.sim.PersoSubstate.RUIM_SERVICE_PROVIDER_PUK; 582 case PERSOSUBSTATE_RUIM_RUIM_PUK: 583 return android.hardware.radio.sim.PersoSubstate.RUIM_RUIM_PUK; 584 case PERSOSUBSTATE_SIM_SPN: 585 return android.hardware.radio.sim.PersoSubstate.SIM_SPN; 586 case PERSOSUBSTATE_SIM_SPN_PUK: 587 return android.hardware.radio.sim.PersoSubstate.SIM_SPN_PUK; 588 case PERSOSUBSTATE_SIM_SP_EHPLMN: 589 return android.hardware.radio.sim.PersoSubstate.SIM_SP_EHPLMN; 590 case PERSOSUBSTATE_SIM_SP_EHPLMN_PUK: 591 return android.hardware.radio.sim.PersoSubstate.SIM_SP_EHPLMN_PUK; 592 case PERSOSUBSTATE_SIM_ICCID: 593 return android.hardware.radio.sim.PersoSubstate.SIM_ICCID; 594 case PERSOSUBSTATE_SIM_ICCID_PUK: 595 return android.hardware.radio.sim.PersoSubstate.SIM_ICCID_PUK; 596 case PERSOSUBSTATE_SIM_IMPI: 597 return android.hardware.radio.sim.PersoSubstate.SIM_IMPI; 598 case PERSOSUBSTATE_SIM_IMPI_PUK: 599 return android.hardware.radio.sim.PersoSubstate.SIM_IMPI_PUK; 600 case PERSOSUBSTATE_SIM_NS_SP: 601 return android.hardware.radio.sim.PersoSubstate.SIM_NS_SP; 602 case PERSOSUBSTATE_SIM_NS_SP_PUK: 603 return android.hardware.radio.sim.PersoSubstate.SIM_NS_SP_PUK; 604 default: 605 return android.hardware.radio.sim.PersoSubstate.UNKNOWN; 606 } 607 } 608 609 /** 610 * Convert to GsmSmsMessage defined in radio/1.0/types.hal 611 * @param smscPdu SMSC address 612 * @param pdu SMS in PDU format 613 * @return A converted GsmSmsMessage 614 */ convertToHalGsmSmsMessage( String smscPdu, String pdu)615 public static android.hardware.radio.V1_0.GsmSmsMessage convertToHalGsmSmsMessage( 616 String smscPdu, String pdu) { 617 android.hardware.radio.V1_0.GsmSmsMessage msg = 618 new android.hardware.radio.V1_0.GsmSmsMessage(); 619 msg.smscPdu = smscPdu == null ? "" : smscPdu; 620 msg.pdu = pdu == null ? "" : pdu; 621 return msg; 622 } 623 624 /** 625 * Convert to GsmSmsMessage.aidl 626 * @param smscPdu SMSC address 627 * @param pdu SMS in PDU format 628 * @return A converted GsmSmsMessage 629 */ convertToHalGsmSmsMessageAidl( String smscPdu, String pdu)630 public static android.hardware.radio.messaging.GsmSmsMessage convertToHalGsmSmsMessageAidl( 631 String smscPdu, String pdu) { 632 android.hardware.radio.messaging.GsmSmsMessage msg = 633 new android.hardware.radio.messaging.GsmSmsMessage(); 634 msg.smscPdu = convertNullToEmptyString(smscPdu); 635 msg.pdu = convertNullToEmptyString(pdu); 636 return msg; 637 } 638 639 /** 640 * Convert to CdmaSmsMessage defined in radio/1.0/types.hal 641 * @param pdu SMS in PDU format 642 * @return A converted CdmaSmsMessage 643 */ convertToHalCdmaSmsMessage( byte[] pdu)644 public static android.hardware.radio.V1_0.CdmaSmsMessage convertToHalCdmaSmsMessage( 645 byte[] pdu) { 646 android.hardware.radio.V1_0.CdmaSmsMessage msg = 647 new android.hardware.radio.V1_0.CdmaSmsMessage(); 648 int addrNbrOfDigits; 649 int subaddrNbrOfDigits; 650 int bearerDataLength; 651 ByteArrayInputStream bais = new ByteArrayInputStream(pdu); 652 DataInputStream dis = new DataInputStream(bais); 653 654 try { 655 msg.teleserviceId = dis.readInt(); // teleServiceId 656 msg.isServicePresent = (byte) dis.readInt() == 1; // servicePresent 657 msg.serviceCategory = dis.readInt(); // serviceCategory 658 msg.address.digitMode = dis.read(); // address digit mode 659 msg.address.numberMode = dis.read(); // address number mode 660 msg.address.numberType = dis.read(); // address number type 661 msg.address.numberPlan = dis.read(); // address number plan 662 addrNbrOfDigits = (byte) dis.read(); 663 for (int i = 0; i < addrNbrOfDigits; i++) { 664 msg.address.digits.add(dis.readByte()); // address_orig_bytes[i] 665 } 666 msg.subAddress.subaddressType = dis.read(); //subaddressType 667 msg.subAddress.odd = (byte) dis.read() == 1; //subaddr odd 668 subaddrNbrOfDigits = (byte) dis.read(); 669 for (int i = 0; i < subaddrNbrOfDigits; i++) { 670 msg.subAddress.digits.add(dis.readByte()); //subaddr_orig_bytes[i] 671 } 672 673 bearerDataLength = dis.read(); 674 for (int i = 0; i < bearerDataLength; i++) { 675 msg.bearerData.add(dis.readByte()); //bearerData[i] 676 } 677 } catch (IOException ex) { 678 } 679 return msg; 680 } 681 682 /** 683 * Convert to CdmaSmsMessage.aidl 684 * @param pdu SMS in PDU format 685 * @return The converted CdmaSmsMessage 686 */ convertToHalCdmaSmsMessageAidl( byte[] pdu)687 public static android.hardware.radio.messaging.CdmaSmsMessage convertToHalCdmaSmsMessageAidl( 688 byte[] pdu) { 689 android.hardware.radio.messaging.CdmaSmsMessage msg = 690 new android.hardware.radio.messaging.CdmaSmsMessage(); 691 msg.address = new android.hardware.radio.messaging.CdmaSmsAddress(); 692 msg.subAddress = new android.hardware.radio.messaging.CdmaSmsSubaddress(); 693 int addrNbrOfDigits; 694 int subaddrNbrOfDigits; 695 int bearerDataLength; 696 ByteArrayInputStream bais = new ByteArrayInputStream(pdu); 697 DataInputStream dis = new DataInputStream(bais); 698 699 try { 700 msg.teleserviceId = dis.readInt(); // teleServiceId 701 msg.isServicePresent = (byte) dis.readInt() == 1; // servicePresent 702 msg.serviceCategory = dis.readInt(); // serviceCategory 703 msg.address.digitMode = dis.read(); // address digit mode 704 msg.address.isNumberModeDataNetwork = 705 dis.read() == CdmaSmsAddress.NUMBER_MODE_DATA_NETWORK; // address number mode 706 msg.address.numberType = dis.read(); // address number type 707 msg.address.numberPlan = dis.read(); // address number plan 708 addrNbrOfDigits = (byte) dis.read(); 709 byte[] digits = new byte[addrNbrOfDigits]; 710 for (int i = 0; i < addrNbrOfDigits; i++) { 711 digits[i] = dis.readByte(); // address_orig_bytes[i] 712 } 713 msg.address.digits = digits; 714 msg.subAddress.subaddressType = dis.read(); //subaddressType 715 msg.subAddress.odd = (byte) dis.read() == 1; //subaddr odd 716 subaddrNbrOfDigits = (byte) dis.read(); 717 digits = new byte[subaddrNbrOfDigits]; 718 for (int i = 0; i < subaddrNbrOfDigits; i++) { 719 digits[i] = dis.readByte(); //subaddr_orig_bytes[i] 720 } 721 msg.subAddress.digits = digits; 722 723 bearerDataLength = dis.read(); 724 byte[] bearerData = new byte[bearerDataLength]; 725 for (int i = 0; i < bearerDataLength; i++) { 726 bearerData[i] = dis.readByte(); //bearerData[i] 727 } 728 msg.bearerData = bearerData; 729 } catch (IOException ex) { 730 } 731 return msg; 732 } 733 734 /** 735 * Convert CdmaSmsMessage defined in radio/1.0/types.hal to SmsMessage 736 * Note only primitive fields are set 737 * @param cdmaSmsMessage CdmaSmsMessage defined in radio/1.0/types.hal 738 * @return A converted SmsMessage 739 */ convertHalCdmaSmsMessage( android.hardware.radio.V1_0.CdmaSmsMessage cdmaSmsMessage)740 public static SmsMessage convertHalCdmaSmsMessage( 741 android.hardware.radio.V1_0.CdmaSmsMessage cdmaSmsMessage) { 742 // Note: Parcel.readByte actually reads one Int and masks to byte 743 SmsEnvelope env = new SmsEnvelope(); 744 CdmaSmsAddress addr = new CdmaSmsAddress(); 745 CdmaSmsSubaddress subaddr = new CdmaSmsSubaddress(); 746 byte[] data; 747 byte count; 748 int countInt; 749 int addressDigitMode; 750 751 //currently not supported by the modem-lib: env.mMessageType 752 env.teleService = cdmaSmsMessage.teleserviceId; 753 754 if (cdmaSmsMessage.isServicePresent) { 755 env.messageType = SmsEnvelope.MESSAGE_TYPE_BROADCAST; 756 } else { 757 if (SmsEnvelope.TELESERVICE_NOT_SET == env.teleService) { 758 // assume type ACK 759 env.messageType = SmsEnvelope.MESSAGE_TYPE_ACKNOWLEDGE; 760 } else { 761 env.messageType = SmsEnvelope.MESSAGE_TYPE_POINT_TO_POINT; 762 } 763 } 764 env.serviceCategory = cdmaSmsMessage.serviceCategory; 765 766 // address 767 addressDigitMode = cdmaSmsMessage.address.digitMode; 768 addr.digitMode = (byte) (0xFF & addressDigitMode); 769 addr.numberMode = (byte) (0xFF & cdmaSmsMessage.address.numberMode); 770 addr.ton = cdmaSmsMessage.address.numberType; 771 addr.numberPlan = (byte) (0xFF & cdmaSmsMessage.address.numberPlan); 772 count = (byte) cdmaSmsMessage.address.digits.size(); 773 addr.numberOfDigits = count; 774 data = new byte[count]; 775 for (int index = 0; index < count; index++) { 776 data[index] = cdmaSmsMessage.address.digits.get(index); 777 778 // convert the value if it is 4-bit DTMF to 8 bit 779 if (addressDigitMode == CdmaSmsAddress.DIGIT_MODE_4BIT_DTMF) { 780 data[index] = SmsMessage.convertDtmfToAscii(data[index]); 781 } 782 } 783 784 addr.origBytes = data; 785 786 subaddr.type = cdmaSmsMessage.subAddress.subaddressType; 787 subaddr.odd = (byte) (cdmaSmsMessage.subAddress.odd ? 1 : 0); 788 count = (byte) cdmaSmsMessage.subAddress.digits.size(); 789 790 if (count < 0) { 791 count = 0; 792 } 793 794 // p_cur->sSubAddress.digits[digitCount] : 795 796 data = new byte[count]; 797 798 for (int index = 0; index < count; ++index) { 799 data[index] = cdmaSmsMessage.subAddress.digits.get(index); 800 } 801 802 subaddr.origBytes = data; 803 804 /* currently not supported by the modem-lib: 805 env.bearerReply 806 env.replySeqNo 807 env.errorClass 808 env.causeCode 809 */ 810 811 // bearer data 812 countInt = cdmaSmsMessage.bearerData.size(); 813 if (countInt < 0) { 814 countInt = 0; 815 } 816 817 data = new byte[countInt]; 818 for (int index = 0; index < countInt; index++) { 819 data[index] = cdmaSmsMessage.bearerData.get(index); 820 } 821 // BD gets further decoded when accessed in SMSDispatcher 822 env.bearerData = data; 823 824 // link the filled objects to the SMS 825 env.origAddress = addr; 826 env.origSubaddress = subaddr; 827 828 SmsMessage msg = new SmsMessage(addr, env); 829 830 return msg; 831 } 832 833 /** 834 * Convert CdmaSmsMessage defined in CdmaSmsMessage.aidl to SmsMessage 835 * Note only primitive fields are set 836 * @param msg CdmaSmsMessage defined in CdmaSmsMessage.aidl 837 * @return A converted SmsMessage 838 */ convertHalCdmaSmsMessage( android.hardware.radio.messaging.CdmaSmsMessage msg)839 public static SmsMessage convertHalCdmaSmsMessage( 840 android.hardware.radio.messaging.CdmaSmsMessage msg) { 841 // Note: Parcel.readByte actually reads one Int and masks to byte 842 SmsEnvelope env = new SmsEnvelope(); 843 CdmaSmsAddress addr = new CdmaSmsAddress(); 844 CdmaSmsSubaddress subaddr = new CdmaSmsSubaddress(); 845 846 // address 847 int addressDigitMode = msg.address.digitMode; 848 addr.digitMode = (byte) (0xFF & addressDigitMode); 849 addr.numberMode = (byte) (0xFF & (msg.address.isNumberModeDataNetwork ? 1 : 0)); 850 addr.ton = msg.address.numberType; 851 addr.numberPlan = (byte) (0xFF & msg.address.numberPlan); 852 addr.numberOfDigits = msg.address.digits.length; 853 byte[] data = new byte[msg.address.digits.length]; 854 for (int index = 0; index < data.length; index++) { 855 data[index] = msg.address.digits[index]; 856 // convert the value if it is 4-bit DTMF to 8 bit 857 if (addressDigitMode == CdmaSmsAddress.DIGIT_MODE_4BIT_DTMF) { 858 data[index] = SmsMessage.convertDtmfToAscii(data[index]); 859 } 860 } 861 addr.origBytes = data; 862 863 // subaddress 864 subaddr.type = msg.subAddress.subaddressType; 865 subaddr.odd = (byte) (msg.subAddress.odd ? 1 : 0); 866 subaddr.origBytes = msg.subAddress.digits; 867 868 // envelope 869 // currently not supported by the modem-lib: env.bearerReply, env.replySeqNo, 870 // env.errorClass, env.causeCode, env.mMessageType 871 env.teleService = msg.teleserviceId; 872 if (msg.isServicePresent) { 873 env.messageType = SmsEnvelope.MESSAGE_TYPE_BROADCAST; 874 } else { 875 if (SmsEnvelope.TELESERVICE_NOT_SET == env.teleService) { 876 // assume type ACK 877 env.messageType = SmsEnvelope.MESSAGE_TYPE_ACKNOWLEDGE; 878 } else { 879 env.messageType = SmsEnvelope.MESSAGE_TYPE_POINT_TO_POINT; 880 } 881 } 882 env.serviceCategory = msg.serviceCategory; 883 884 // bearer data is further decoded when accessed in SmsDispatcher 885 env.bearerData = msg.bearerData; 886 887 // link the filled objects to the SMS 888 env.origAddress = addr; 889 env.origSubaddress = subaddr; 890 891 return new SmsMessage(addr, env); 892 } 893 894 /** 895 * Convert to DataProfileInfo defined in radio/1.4/types.hal 896 * @param dp Data profile 897 * @return The converted DataProfileInfo 898 */ convertToHalDataProfile14( DataProfile dp)899 public static android.hardware.radio.V1_4.DataProfileInfo convertToHalDataProfile14( 900 DataProfile dp) { 901 android.hardware.radio.V1_4.DataProfileInfo dpi = 902 new android.hardware.radio.V1_4.DataProfileInfo(); 903 904 dpi.apn = dp.getApn(); 905 dpi.protocol = dp.getProtocolType(); 906 dpi.roamingProtocol = dp.getRoamingProtocolType(); 907 dpi.authType = dp.getAuthType(); 908 dpi.user = TextUtils.emptyIfNull(dp.getUserName()); 909 dpi.password = TextUtils.emptyIfNull(dp.getPassword()); 910 dpi.type = dp.getType(); 911 dpi.maxConnsTime = dp.getMaxConnectionsTime(); 912 dpi.maxConns = dp.getMaxConnections(); 913 dpi.waitTime = dp.getWaitTime(); 914 dpi.enabled = dp.isEnabled(); 915 dpi.supportedApnTypesBitmap = dp.getSupportedApnTypesBitmask(); 916 // Shift by 1 bit due to the discrepancy between 917 // android.hardware.radio.V1_0.RadioAccessFamily and the bitmask version of 918 // ServiceState.RIL_RADIO_TECHNOLOGY_XXXX. 919 dpi.bearerBitmap = ServiceState.convertNetworkTypeBitmaskToBearerBitmask( 920 dp.getBearerBitmask()) << 1; 921 dpi.mtu = dp.getMtuV4(); 922 dpi.persistent = dp.isPersistent(); 923 dpi.preferred = dp.isPreferred(); 924 925 // profile id is only meaningful when it's persistent on the modem. 926 dpi.profileId = (dpi.persistent) ? dp.getProfileId() 927 : android.hardware.radio.V1_0.DataProfileId.INVALID; 928 929 return dpi; 930 } 931 932 /** 933 * Convert to DataProfileInfo defined in radio/1.5/types.hal 934 * @param dp Data profile 935 * @return The converted DataProfileInfo 936 */ convertToHalDataProfile15( DataProfile dp)937 public static android.hardware.radio.V1_5.DataProfileInfo convertToHalDataProfile15( 938 DataProfile dp) { 939 android.hardware.radio.V1_5.DataProfileInfo dpi = 940 new android.hardware.radio.V1_5.DataProfileInfo(); 941 942 dpi.apn = dp.getApn(); 943 dpi.protocol = dp.getProtocolType(); 944 dpi.roamingProtocol = dp.getRoamingProtocolType(); 945 dpi.authType = dp.getAuthType(); 946 dpi.user = TextUtils.emptyIfNull(dp.getUserName()); 947 dpi.password = TextUtils.emptyIfNull(dp.getPassword()); 948 dpi.type = dp.getType(); 949 dpi.maxConnsTime = dp.getMaxConnectionsTime(); 950 dpi.maxConns = dp.getMaxConnections(); 951 dpi.waitTime = dp.getWaitTime(); 952 dpi.enabled = dp.isEnabled(); 953 dpi.supportedApnTypesBitmap = dp.getSupportedApnTypesBitmask(); 954 // Shift by 1 bit due to the discrepancy between 955 // android.hardware.radio.V1_0.RadioAccessFamily and the bitmask version of 956 // ServiceState.RIL_RADIO_TECHNOLOGY_XXXX. 957 dpi.bearerBitmap = ServiceState.convertNetworkTypeBitmaskToBearerBitmask( 958 dp.getBearerBitmask()) << 1; 959 dpi.mtuV4 = dp.getMtuV4(); 960 dpi.mtuV6 = dp.getMtuV6(); 961 dpi.persistent = dp.isPersistent(); 962 dpi.preferred = dp.isPreferred(); 963 964 // profile id is only meaningful when it's persistent on the modem. 965 dpi.profileId = (dpi.persistent) ? dp.getProfileId() 966 : android.hardware.radio.V1_0.DataProfileId.INVALID; 967 968 return dpi; 969 } 970 971 /** 972 * Convert to DataProfileInfo.aidl 973 * @param dp Data profile 974 * @return The converted DataProfileInfo 975 */ convertToHalDataProfile( @ullable DataProfile dp)976 public static android.hardware.radio.data.DataProfileInfo convertToHalDataProfile( 977 @Nullable DataProfile dp) { 978 if (dp == null) return null; 979 android.hardware.radio.data.DataProfileInfo dpi = 980 new android.hardware.radio.data.DataProfileInfo(); 981 982 dpi.apn = dp.getApn(); 983 dpi.protocol = dp.getProtocolType(); 984 dpi.roamingProtocol = dp.getRoamingProtocolType(); 985 dpi.authType = dp.getAuthType(); 986 dpi.user = convertNullToEmptyString(dp.getUserName()); 987 dpi.password = convertNullToEmptyString(dp.getPassword()); 988 dpi.type = dp.getType(); 989 dpi.maxConnsTime = dp.getMaxConnectionsTime(); 990 dpi.maxConns = dp.getMaxConnections(); 991 dpi.waitTime = dp.getWaitTime(); 992 dpi.enabled = dp.isEnabled(); 993 dpi.supportedApnTypesBitmap = dp.getSupportedApnTypesBitmask(); 994 // Shift by 1 bit due to the discrepancy between RadioAccessFamily.aidl and the bitmask 995 // version of ServiceState.RIL_RADIO_TECHNOLOGY_XXXX. 996 dpi.bearerBitmap = ServiceState.convertNetworkTypeBitmaskToBearerBitmask( 997 dp.getBearerBitmask()) << 1; 998 dpi.mtuV4 = dp.getMtuV4(); 999 dpi.mtuV6 = dp.getMtuV6(); 1000 dpi.persistent = dp.isPersistent(); 1001 dpi.preferred = dp.isPreferred(); 1002 dpi.alwaysOn = false; 1003 dpi.infrastructureBitmap = android.hardware.radio.data.DataProfileInfo 1004 .INFRASTRUCTURE_CELLULAR; 1005 if (dp.getApnSetting() != null) { 1006 dpi.alwaysOn = dp.getApnSetting().isAlwaysOn(); 1007 dpi.infrastructureBitmap = dp.getApnSetting().getInfrastructureBitmask(); 1008 } 1009 dpi.trafficDescriptor = convertToHalTrafficDescriptorAidl(dp.getTrafficDescriptor()); 1010 1011 // profile id is only meaningful when it's persistent on the modem. 1012 dpi.profileId = (dpi.persistent) ? dp.getProfileId() 1013 : android.hardware.radio.data.DataProfileInfo.ID_INVALID; 1014 1015 return dpi; 1016 } 1017 1018 /** 1019 * Convert from DataProfileInfo.aidl to DataProfile 1020 * @param dpi DataProfileInfo 1021 * @return The converted DataProfile 1022 */ convertToDataProfile( android.hardware.radio.data.DataProfileInfo dpi)1023 public static DataProfile convertToDataProfile( 1024 android.hardware.radio.data.DataProfileInfo dpi) { 1025 ApnSetting apnSetting = new ApnSetting.Builder() 1026 .setEntryName(dpi.apn) 1027 .setApnName(dpi.apn) 1028 .setApnTypeBitmask(dpi.supportedApnTypesBitmap) 1029 .setAuthType(dpi.authType) 1030 .setMaxConnsTime(dpi.maxConnsTime) 1031 .setMaxConns(dpi.maxConns) 1032 .setWaitTime(dpi.waitTime) 1033 .setCarrierEnabled(dpi.enabled) 1034 .setModemCognitive(dpi.persistent) 1035 .setMtuV4(dpi.mtuV4) 1036 .setMtuV6(dpi.mtuV6) 1037 .setNetworkTypeBitmask(ServiceState.convertBearerBitmaskToNetworkTypeBitmask( 1038 dpi.bearerBitmap) >> 1) 1039 .setProfileId(dpi.profileId) 1040 .setPassword(dpi.password) 1041 .setProtocol(dpi.protocol) 1042 .setRoamingProtocol(dpi.roamingProtocol) 1043 .setUser(dpi.user) 1044 .setAlwaysOn(dpi.alwaysOn) 1045 .setInfrastructureBitmask(dpi.infrastructureBitmap) 1046 .build(); 1047 1048 TrafficDescriptor td; 1049 try { 1050 td = convertHalTrafficDescriptor(dpi.trafficDescriptor); 1051 } catch (IllegalArgumentException e) { 1052 loge("convertToDataProfile: Failed to convert traffic descriptor. e=" + e); 1053 td = null; 1054 } 1055 1056 return new DataProfile.Builder() 1057 .setType(dpi.type) 1058 .setPreferred(dpi.preferred) 1059 .setTrafficDescriptor(td) 1060 .setApnSetting(apnSetting) 1061 .build(); 1062 } 1063 1064 /** 1065 * Convert to OptionalSliceInfo defined in radio/1.6/types.hal 1066 * @param sliceInfo Slice info 1067 * @return The converted OptionalSliceInfo 1068 */ convertToHalSliceInfo( @ullable NetworkSliceInfo sliceInfo)1069 public static android.hardware.radio.V1_6.OptionalSliceInfo convertToHalSliceInfo( 1070 @Nullable NetworkSliceInfo sliceInfo) { 1071 android.hardware.radio.V1_6.OptionalSliceInfo optionalSliceInfo = 1072 new android.hardware.radio.V1_6.OptionalSliceInfo(); 1073 if (sliceInfo == null) { 1074 return optionalSliceInfo; 1075 } 1076 1077 android.hardware.radio.V1_6.SliceInfo si = new android.hardware.radio.V1_6.SliceInfo(); 1078 si.sst = (byte) sliceInfo.getSliceServiceType(); 1079 si.mappedHplmnSst = (byte) sliceInfo.getMappedHplmnSliceServiceType(); 1080 si.sliceDifferentiator = sliceInfo.getSliceDifferentiator(); 1081 si.mappedHplmnSD = sliceInfo.getMappedHplmnSliceDifferentiator(); 1082 optionalSliceInfo.value(si); 1083 return optionalSliceInfo; 1084 } 1085 1086 /** 1087 * Convert to SliceInfo.aidl 1088 * @param sliceInfo Slice info 1089 * @return The converted SliceInfo 1090 */ convertToHalSliceInfoAidl( @ullable NetworkSliceInfo sliceInfo)1091 public static android.hardware.radio.data.SliceInfo convertToHalSliceInfoAidl( 1092 @Nullable NetworkSliceInfo sliceInfo) { 1093 if (sliceInfo == null) { 1094 return null; 1095 } 1096 1097 android.hardware.radio.data.SliceInfo si = new android.hardware.radio.data.SliceInfo(); 1098 si.sliceServiceType = (byte) sliceInfo.getSliceServiceType(); 1099 si.mappedHplmnSst = (byte) sliceInfo.getMappedHplmnSliceServiceType(); 1100 si.sliceDifferentiator = sliceInfo.getSliceDifferentiator(); 1101 si.mappedHplmnSd = sliceInfo.getMappedHplmnSliceDifferentiator(); 1102 return si; 1103 } 1104 1105 /** 1106 * Convert to OptionalTrafficDescriptor defined in radio/1.6/types.hal 1107 * @param trafficDescriptor Traffic descriptor 1108 * @return The converted OptionalTrafficDescriptor 1109 */ 1110 public static android.hardware.radio.V1_6.OptionalTrafficDescriptor convertToHalTrafficDescriptor(@ullable TrafficDescriptor trafficDescriptor)1111 convertToHalTrafficDescriptor(@Nullable TrafficDescriptor trafficDescriptor) { 1112 android.hardware.radio.V1_6.OptionalTrafficDescriptor optionalTrafficDescriptor = 1113 new android.hardware.radio.V1_6.OptionalTrafficDescriptor(); 1114 if (trafficDescriptor == null) { 1115 return optionalTrafficDescriptor; 1116 } 1117 1118 android.hardware.radio.V1_6.TrafficDescriptor td = 1119 new android.hardware.radio.V1_6.TrafficDescriptor(); 1120 1121 android.hardware.radio.V1_6.OptionalDnn optionalDnn = 1122 new android.hardware.radio.V1_6.OptionalDnn(); 1123 if (trafficDescriptor.getDataNetworkName() != null) { 1124 optionalDnn.value(trafficDescriptor.getDataNetworkName()); 1125 } 1126 td.dnn = optionalDnn; 1127 1128 android.hardware.radio.V1_6.OptionalOsAppId optionalOsAppId = 1129 new android.hardware.radio.V1_6.OptionalOsAppId(); 1130 if (trafficDescriptor.getOsAppId() != null) { 1131 android.hardware.radio.V1_6.OsAppId osAppId = new android.hardware.radio.V1_6.OsAppId(); 1132 osAppId.osAppId = primitiveArrayToArrayList(trafficDescriptor.getOsAppId()); 1133 optionalOsAppId.value(osAppId); 1134 } 1135 td.osAppId = optionalOsAppId; 1136 1137 optionalTrafficDescriptor.value(td); 1138 return optionalTrafficDescriptor; 1139 } 1140 1141 /** 1142 * Convert to TrafficDescriptor.aidl 1143 * @param trafficDescriptor Traffic descriptor 1144 * @return The converted TrafficDescriptor 1145 */ 1146 public static android.hardware.radio.data.TrafficDescriptor convertToHalTrafficDescriptorAidl(@ullable TrafficDescriptor trafficDescriptor)1147 convertToHalTrafficDescriptorAidl(@Nullable TrafficDescriptor trafficDescriptor) { 1148 if (trafficDescriptor == null) { 1149 return new android.hardware.radio.data.TrafficDescriptor(); 1150 } 1151 1152 android.hardware.radio.data.TrafficDescriptor td = 1153 new android.hardware.radio.data.TrafficDescriptor(); 1154 td.dnn = trafficDescriptor.getDataNetworkName(); 1155 if (trafficDescriptor.getOsAppId() == null) { 1156 td.osAppId = null; 1157 } else { 1158 android.hardware.radio.data.OsAppId osAppId = new android.hardware.radio.data.OsAppId(); 1159 osAppId.osAppId = trafficDescriptor.getOsAppId(); 1160 td.osAppId = osAppId; 1161 } 1162 return td; 1163 } 1164 1165 /** 1166 * Convert to ResetNvType defined in radio/1.0/types.hal 1167 * @param resetType NV reset type 1168 * @return The converted reset type in integer or -1 if param is invalid 1169 */ convertToHalResetNvType(int resetType)1170 public static int convertToHalResetNvType(int resetType) { 1171 /** 1172 * resetType values 1173 * 1 - reload all NV items 1174 * 2 - erase NV reset (SCRTN) 1175 * 3 - factory reset (RTN) 1176 */ 1177 if (Flags.cleanupCdma()) { 1178 if (resetType == 1) return android.hardware.radio.V1_0.ResetNvType.RELOAD; 1179 return -1; 1180 } 1181 switch (resetType) { 1182 case 1: return android.hardware.radio.V1_0.ResetNvType.RELOAD; 1183 case 2: return android.hardware.radio.V1_0.ResetNvType.ERASE; 1184 case 3: return android.hardware.radio.V1_0.ResetNvType.FACTORY_RESET; 1185 } 1186 return -1; 1187 } 1188 1189 /** 1190 * Convert to ResetNvType.aidl 1191 * @param resetType NV reset type 1192 * @return The converted reset type in integer or -1 if param is invalid 1193 */ convertToHalResetNvTypeAidl(int resetType)1194 public static int convertToHalResetNvTypeAidl(int resetType) { 1195 /** 1196 * resetType values 1197 * 1 - reload all NV items 1198 * 2 - erase NV reset (SCRTN) 1199 * 3 - factory reset (RTN) 1200 */ 1201 if (Flags.cleanupCdma()) { 1202 if (resetType == 1) return android.hardware.radio.modem.ResetNvType.RELOAD; 1203 return -1; 1204 } 1205 switch (resetType) { 1206 case 1: return android.hardware.radio.modem.ResetNvType.RELOAD; 1207 case 2: return android.hardware.radio.modem.ResetNvType.ERASE; 1208 case 3: return android.hardware.radio.modem.ResetNvType.FACTORY_RESET; 1209 } 1210 return -1; 1211 } 1212 1213 /** 1214 * Convert to a list of LinkAddress defined in radio/1.5/types.hal 1215 * @param linkProperties Link properties 1216 * @return The converted list of LinkAddresses 1217 */ convertToHalLinkProperties15( LinkProperties linkProperties)1218 public static ArrayList<android.hardware.radio.V1_5.LinkAddress> convertToHalLinkProperties15( 1219 LinkProperties linkProperties) { 1220 ArrayList<android.hardware.radio.V1_5.LinkAddress> addresses15 = new ArrayList<>(); 1221 if (linkProperties != null) { 1222 for (android.net.LinkAddress la : linkProperties.getAllLinkAddresses()) { 1223 android.hardware.radio.V1_5.LinkAddress linkAddress = 1224 new android.hardware.radio.V1_5.LinkAddress(); 1225 linkAddress.address = la.getAddress().getHostAddress(); 1226 linkAddress.properties = la.getFlags(); 1227 linkAddress.deprecationTime = la.getDeprecationTime(); 1228 linkAddress.expirationTime = la.getExpirationTime(); 1229 addresses15.add(linkAddress); 1230 } 1231 } 1232 return addresses15; 1233 } 1234 1235 /** 1236 * Convert to a list of LinkAddress.aidl 1237 * @param linkProperties Link properties 1238 * @return The converted list of LinkAddresses 1239 */ convertToHalLinkProperties( LinkProperties linkProperties)1240 public static android.hardware.radio.data.LinkAddress[] convertToHalLinkProperties( 1241 LinkProperties linkProperties) { 1242 if (linkProperties == null) { 1243 return new android.hardware.radio.data.LinkAddress[0]; 1244 } 1245 android.hardware.radio.data.LinkAddress[] addresses = 1246 new android.hardware.radio.data.LinkAddress[ 1247 linkProperties.getAllLinkAddresses().size()]; 1248 for (int i = 0; i < linkProperties.getAllLinkAddresses().size(); i++) { 1249 LinkAddress la = linkProperties.getAllLinkAddresses().get(i); 1250 android.hardware.radio.data.LinkAddress linkAddress = 1251 new android.hardware.radio.data.LinkAddress(); 1252 linkAddress.address = la.getAddress().getHostAddress(); 1253 linkAddress.addressProperties = la.getFlags(); 1254 linkAddress.deprecationTime = la.getDeprecationTime(); 1255 linkAddress.expirationTime = la.getExpirationTime(); 1256 addresses[i] = linkAddress; 1257 } 1258 return addresses; 1259 } 1260 1261 /** 1262 * Convert RadioAccessSpecifier defined in radio/1.5/types.hal to RadioAccessSpecifier 1263 * @param specifier RadioAccessSpecifier defined in radio/1.5/types.hal 1264 * @return The converted RadioAccessSpecifier 1265 */ convertHalRadioAccessSpecifier( android.hardware.radio.V1_5.RadioAccessSpecifier specifier)1266 public static RadioAccessSpecifier convertHalRadioAccessSpecifier( 1267 android.hardware.radio.V1_5.RadioAccessSpecifier specifier) { 1268 if (specifier == null) return null; 1269 ArrayList<Integer> halBands = new ArrayList<>(); 1270 switch (specifier.bands.getDiscriminator()) { 1271 case android.hardware.radio.V1_5.RadioAccessSpecifier.Bands.hidl_discriminator 1272 .geranBands: 1273 halBands = specifier.bands.geranBands(); 1274 break; 1275 case android.hardware.radio.V1_5.RadioAccessSpecifier.Bands.hidl_discriminator 1276 .utranBands: 1277 halBands = specifier.bands.utranBands(); 1278 break; 1279 case android.hardware.radio.V1_5.RadioAccessSpecifier.Bands.hidl_discriminator 1280 .eutranBands: 1281 halBands = specifier.bands.eutranBands(); 1282 break; 1283 case android.hardware.radio.V1_5.RadioAccessSpecifier.Bands.hidl_discriminator 1284 .ngranBands: 1285 halBands = specifier.bands.ngranBands(); 1286 break; 1287 } 1288 return new RadioAccessSpecifier(convertHalRadioAccessNetworks(specifier.radioAccessNetwork), 1289 halBands.stream().mapToInt(Integer::intValue).toArray(), 1290 specifier.channels.stream().mapToInt(Integer::intValue).toArray()); 1291 } 1292 1293 /** 1294 * Convert RadioAccessSpecifier defined in RadioAccessSpecifier.aidl to RadioAccessSpecifier 1295 * @param specifier RadioAccessSpecifier defined in RadioAccessSpecifier.aidl 1296 * @return The converted RadioAccessSpecifier 1297 */ convertHalRadioAccessSpecifier( android.hardware.radio.network.RadioAccessSpecifier specifier)1298 public static RadioAccessSpecifier convertHalRadioAccessSpecifier( 1299 android.hardware.radio.network.RadioAccessSpecifier specifier) { 1300 if (specifier == null) return null; 1301 int[] halBands = null; 1302 switch (specifier.bands.getTag()) { 1303 case android.hardware.radio.network.RadioAccessSpecifierBands.geranBands: 1304 halBands = specifier.bands.getGeranBands(); 1305 break; 1306 case android.hardware.radio.network.RadioAccessSpecifierBands.utranBands: 1307 halBands = specifier.bands.getUtranBands(); 1308 break; 1309 case android.hardware.radio.network.RadioAccessSpecifierBands.eutranBands: 1310 halBands = specifier.bands.getEutranBands(); 1311 break; 1312 case android.hardware.radio.network.RadioAccessSpecifierBands.ngranBands: 1313 halBands = specifier.bands.getNgranBands(); 1314 break; 1315 } 1316 return new RadioAccessSpecifier(specifier.accessNetwork, halBands, specifier.channels); 1317 } 1318 1319 /** 1320 * Convert to RadioAccessSpecifier defined in radio/1.1/types.hal 1321 * @param ras Radio access specifier 1322 * @return The converted RadioAccessSpecifier 1323 */ 1324 public static android.hardware.radio.V1_1.RadioAccessSpecifier convertToHalRadioAccessSpecifier11(RadioAccessSpecifier ras)1325 convertToHalRadioAccessSpecifier11(RadioAccessSpecifier ras) { 1326 android.hardware.radio.V1_1.RadioAccessSpecifier rasInHalFormat = 1327 new android.hardware.radio.V1_1.RadioAccessSpecifier(); 1328 rasInHalFormat.radioAccessNetwork = ras.getRadioAccessNetwork(); 1329 ArrayList<Integer> bands = new ArrayList<>(); 1330 if (ras.getBands() != null) { 1331 for (int band : ras.getBands()) { 1332 bands.add(band); 1333 } 1334 } 1335 switch (ras.getRadioAccessNetwork()) { 1336 case AccessNetworkConstants.AccessNetworkType.GERAN: 1337 rasInHalFormat.geranBands = bands; 1338 break; 1339 case AccessNetworkConstants.AccessNetworkType.UTRAN: 1340 rasInHalFormat.utranBands = bands; 1341 break; 1342 case AccessNetworkConstants.AccessNetworkType.EUTRAN: 1343 rasInHalFormat.eutranBands = bands; 1344 break; 1345 default: 1346 return null; 1347 } 1348 1349 if (ras.getChannels() != null) { 1350 for (int channel : ras.getChannels()) { 1351 rasInHalFormat.channels.add(channel); 1352 } 1353 } 1354 1355 return rasInHalFormat; 1356 } 1357 1358 /** 1359 * Convert to RadioAccessSpecifier defined in radio/1.5/types.hal 1360 * @param ras Radio access specifier 1361 * @return The converted RadioAccessSpecifier 1362 */ 1363 public static android.hardware.radio.V1_5.RadioAccessSpecifier convertToHalRadioAccessSpecifier15(RadioAccessSpecifier ras)1364 convertToHalRadioAccessSpecifier15(RadioAccessSpecifier ras) { 1365 android.hardware.radio.V1_5.RadioAccessSpecifier rasInHalFormat = 1366 new android.hardware.radio.V1_5.RadioAccessSpecifier(); 1367 android.hardware.radio.V1_5.RadioAccessSpecifier.Bands bandsInHalFormat = 1368 new android.hardware.radio.V1_5.RadioAccessSpecifier.Bands(); 1369 rasInHalFormat.radioAccessNetwork = convertToHalRadioAccessNetworks( 1370 ras.getRadioAccessNetwork()); 1371 ArrayList<Integer> bands = new ArrayList<>(); 1372 if (ras.getBands() != null) { 1373 for (int band : ras.getBands()) { 1374 bands.add(band); 1375 } 1376 } 1377 switch (ras.getRadioAccessNetwork()) { 1378 case AccessNetworkConstants.AccessNetworkType.GERAN: 1379 bandsInHalFormat.geranBands(bands); 1380 break; 1381 case AccessNetworkConstants.AccessNetworkType.UTRAN: 1382 bandsInHalFormat.utranBands(bands); 1383 break; 1384 case AccessNetworkConstants.AccessNetworkType.EUTRAN: 1385 bandsInHalFormat.eutranBands(bands); 1386 break; 1387 case AccessNetworkConstants.AccessNetworkType.NGRAN: 1388 bandsInHalFormat.ngranBands(bands); 1389 break; 1390 default: 1391 return null; 1392 } 1393 rasInHalFormat.bands = bandsInHalFormat; 1394 1395 if (ras.getChannels() != null) { 1396 for (int channel : ras.getChannels()) { 1397 rasInHalFormat.channels.add(channel); 1398 } 1399 } 1400 1401 return rasInHalFormat; 1402 } 1403 1404 /** 1405 * Convert to RadioAccessSpecifier.aidl 1406 * @param ras Radio access specifier 1407 * @return The converted RadioAccessSpecifier 1408 */ 1409 public static android.hardware.radio.network.RadioAccessSpecifier convertToHalRadioAccessSpecifierAidl(RadioAccessSpecifier ras)1410 convertToHalRadioAccessSpecifierAidl(RadioAccessSpecifier ras) { 1411 android.hardware.radio.network.RadioAccessSpecifier rasInHalFormat = 1412 new android.hardware.radio.network.RadioAccessSpecifier(); 1413 android.hardware.radio.network.RadioAccessSpecifierBands bandsInHalFormat = 1414 new android.hardware.radio.network.RadioAccessSpecifierBands(); 1415 rasInHalFormat.accessNetwork = convertToHalAccessNetworkAidl(ras.getRadioAccessNetwork()); 1416 int[] bands; 1417 if (ras.getBands() != null) { 1418 bands = new int[ras.getBands().length]; 1419 for (int i = 0; i < ras.getBands().length; i++) { 1420 bands[i] = ras.getBands()[i]; 1421 } 1422 } else { 1423 bands = new int[0]; 1424 } 1425 switch (ras.getRadioAccessNetwork()) { 1426 case AccessNetworkConstants.AccessNetworkType.GERAN: 1427 bandsInHalFormat.setGeranBands(bands); 1428 break; 1429 case AccessNetworkConstants.AccessNetworkType.UTRAN: 1430 bandsInHalFormat.setUtranBands(bands); 1431 break; 1432 case AccessNetworkConstants.AccessNetworkType.EUTRAN: 1433 bandsInHalFormat.setEutranBands(bands); 1434 break; 1435 case AccessNetworkConstants.AccessNetworkType.NGRAN: 1436 bandsInHalFormat.setNgranBands(bands); 1437 break; 1438 default: 1439 return null; 1440 } 1441 rasInHalFormat.bands = bandsInHalFormat; 1442 1443 int[] channels; 1444 if (ras.getChannels() != null) { 1445 channels = new int[ras.getChannels().length]; 1446 for (int i = 0; i < ras.getChannels().length; i++) { 1447 channels[i] = ras.getChannels()[i]; 1448 } 1449 } else { 1450 channels = new int[0]; 1451 } 1452 rasInHalFormat.channels = channels; 1453 1454 return rasInHalFormat; 1455 } 1456 1457 /** 1458 * Convert to censored terminal response 1459 * @param terminalResponse Terminal response 1460 * @return The converted censored terminal response 1461 */ convertToCensoredTerminalResponse(String terminalResponse)1462 public static String convertToCensoredTerminalResponse(String terminalResponse) { 1463 try { 1464 byte[] bytes = IccUtils.hexStringToBytes(terminalResponse); 1465 if (bytes != null) { 1466 List<ComprehensionTlv> ctlvs = ComprehensionTlv.decodeMany(bytes, 0); 1467 int from = 0; 1468 for (ComprehensionTlv ctlv : ctlvs) { 1469 // Find text strings which might be personal information input by user, 1470 // then replace it with "********". 1471 if (ComprehensionTlvTag.TEXT_STRING.value() == ctlv.getTag()) { 1472 byte[] target = Arrays.copyOfRange(ctlv.getRawValue(), from, 1473 ctlv.getValueIndex() + ctlv.getLength()); 1474 terminalResponse = terminalResponse.toLowerCase(Locale.ROOT).replace( 1475 IccUtils.bytesToHexString(target).toLowerCase(Locale.ROOT), 1476 "********"); 1477 } 1478 // The text string tag and the length field should also be hidden. 1479 from = ctlv.getValueIndex() + ctlv.getLength(); 1480 } 1481 } 1482 } catch (Exception e) { 1483 terminalResponse = null; 1484 } 1485 1486 return terminalResponse; 1487 } 1488 1489 /** 1490 * Convert to {@link TelephonyManager.NetworkTypeBitMask}, the bitmask represented by 1491 * {@link android.telephony.Annotation.NetworkType}. 1492 * 1493 * @param raf {@link android.hardware.radio.V1_0.RadioAccessFamily} 1494 * @return {@link TelephonyManager.NetworkTypeBitMask} 1495 */ 1496 @TelephonyManager.NetworkTypeBitMask convertHalNetworkTypeBitMask(int raf)1497 public static int convertHalNetworkTypeBitMask(int raf) { 1498 int networkTypeRaf = 0; 1499 1500 if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.GSM) != 0) { 1501 networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_GSM; 1502 } 1503 if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.GPRS) != 0) { 1504 networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_GPRS; 1505 } 1506 if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.EDGE) != 0) { 1507 networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_EDGE; 1508 } 1509 // convert both IS95A/IS95B to CDMA as network mode doesn't support CDMA 1510 if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.IS95A) != 0) { 1511 networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_CDMA; 1512 } 1513 if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.IS95B) != 0) { 1514 networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_CDMA; 1515 } 1516 if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.ONE_X_RTT) != 0) { 1517 networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_1xRTT; 1518 } 1519 if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.EVDO_0) != 0) { 1520 networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_EVDO_0; 1521 } 1522 if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.EVDO_A) != 0) { 1523 networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_EVDO_A; 1524 } 1525 if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.EVDO_B) != 0) { 1526 networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_EVDO_B; 1527 } 1528 if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.EHRPD) != 0) { 1529 networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_EHRPD; 1530 } 1531 if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.HSUPA) != 0) { 1532 networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_HSUPA; 1533 } 1534 if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.HSDPA) != 0) { 1535 networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_HSDPA; 1536 } 1537 if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.HSPA) != 0) { 1538 networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_HSPA; 1539 } 1540 if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.HSPAP) != 0) { 1541 networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_HSPAP; 1542 } 1543 if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.UMTS) != 0) { 1544 networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_UMTS; 1545 } 1546 if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.TD_SCDMA) != 0) { 1547 networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_TD_SCDMA; 1548 } 1549 if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.LTE) != 0) { 1550 networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_LTE; 1551 } 1552 if ((raf & android.hardware.radio.V1_0.RadioAccessFamily.LTE_CA) != 0) { 1553 networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_LTE_CA; 1554 } 1555 if ((raf & android.hardware.radio.V1_4.RadioAccessFamily.NR) != 0) { 1556 networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_NR; 1557 } 1558 if ((raf & (1 << ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN)) != 0) { 1559 networkTypeRaf |= TelephonyManager.NETWORK_TYPE_BITMASK_IWLAN; 1560 } 1561 return (networkTypeRaf == 0) ? TelephonyManager.NETWORK_TYPE_UNKNOWN : networkTypeRaf; 1562 } 1563 1564 /** 1565 * Convert to RadioAccessFamily defined in radio/1.4/types.hal 1566 * @param networkTypeBitmask {@link TelephonyManager.NetworkTypeBitMask}, the bitmask 1567 * represented by {@link android.telephony.Annotation.NetworkType} 1568 * @return The converted RadioAccessFamily 1569 */ convertToHalRadioAccessFamily( @elephonyManager.NetworkTypeBitMask int networkTypeBitmask)1570 public static int convertToHalRadioAccessFamily( 1571 @TelephonyManager.NetworkTypeBitMask int networkTypeBitmask) { 1572 int raf = 0; 1573 1574 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_GSM) != 0) { 1575 raf |= android.hardware.radio.V1_0.RadioAccessFamily.GSM; 1576 } 1577 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_GPRS) != 0) { 1578 raf |= android.hardware.radio.V1_0.RadioAccessFamily.GPRS; 1579 } 1580 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_EDGE) != 0) { 1581 raf |= android.hardware.radio.V1_0.RadioAccessFamily.EDGE; 1582 } 1583 // convert CDMA to IS95A, consistent with ServiceState.networkTypeToRilRadioTechnology 1584 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_CDMA) != 0) { 1585 raf |= android.hardware.radio.V1_0.RadioAccessFamily.IS95A; 1586 } 1587 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_1xRTT) != 0) { 1588 raf |= android.hardware.radio.V1_0.RadioAccessFamily.ONE_X_RTT; 1589 } 1590 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_EVDO_0) != 0) { 1591 raf |= android.hardware.radio.V1_0.RadioAccessFamily.EVDO_0; 1592 } 1593 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_EVDO_A) != 0) { 1594 raf |= android.hardware.radio.V1_0.RadioAccessFamily.EVDO_A; 1595 } 1596 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_EVDO_B) != 0) { 1597 raf |= android.hardware.radio.V1_0.RadioAccessFamily.EVDO_B; 1598 } 1599 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_EHRPD) != 0) { 1600 raf |= android.hardware.radio.V1_0.RadioAccessFamily.EHRPD; 1601 } 1602 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_HSUPA) != 0) { 1603 raf |= android.hardware.radio.V1_0.RadioAccessFamily.HSUPA; 1604 } 1605 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_HSDPA) != 0) { 1606 raf |= android.hardware.radio.V1_0.RadioAccessFamily.HSDPA; 1607 } 1608 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_HSPA) != 0) { 1609 raf |= android.hardware.radio.V1_0.RadioAccessFamily.HSPA; 1610 } 1611 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_HSPAP) != 0) { 1612 raf |= android.hardware.radio.V1_0.RadioAccessFamily.HSPAP; 1613 } 1614 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_UMTS) != 0) { 1615 raf |= android.hardware.radio.V1_0.RadioAccessFamily.UMTS; 1616 } 1617 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_TD_SCDMA) != 0) { 1618 raf |= android.hardware.radio.V1_0.RadioAccessFamily.TD_SCDMA; 1619 } 1620 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_IWLAN) != 0) { 1621 raf |= (1 << android.hardware.radio.V1_4.RadioTechnology.IWLAN); 1622 } 1623 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_LTE) != 0) { 1624 raf |= android.hardware.radio.V1_0.RadioAccessFamily.LTE; 1625 } 1626 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_LTE_CA) != 0) { 1627 raf |= android.hardware.radio.V1_0.RadioAccessFamily.LTE_CA; 1628 } 1629 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_NR) != 0) { 1630 raf |= android.hardware.radio.V1_4.RadioAccessFamily.NR; 1631 } 1632 return (raf == 0) ? android.hardware.radio.V1_4.RadioAccessFamily.UNKNOWN : raf; 1633 } 1634 1635 /** 1636 * Convert to RadioAccessFamily.aidl 1637 * @param networkTypeBitmask {@link TelephonyManager.NetworkTypeBitMask}, the bitmask 1638 * represented by {@link android.telephony.Annotation.NetworkType} 1639 * @return The converted RadioAccessFamily 1640 */ convertToHalRadioAccessFamilyAidl( @elephonyManager.NetworkTypeBitMask int networkTypeBitmask)1641 public static int convertToHalRadioAccessFamilyAidl( 1642 @TelephonyManager.NetworkTypeBitMask int networkTypeBitmask) { 1643 int raf = 0; 1644 1645 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_GSM) != 0) { 1646 raf |= android.hardware.radio.RadioAccessFamily.GSM; 1647 } 1648 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_GPRS) != 0) { 1649 raf |= android.hardware.radio.RadioAccessFamily.GPRS; 1650 } 1651 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_EDGE) != 0) { 1652 raf |= android.hardware.radio.RadioAccessFamily.EDGE; 1653 } 1654 // convert CDMA to IS95A, consistent with ServiceState.networkTypeToRilRadioTechnology 1655 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_CDMA) != 0) { 1656 raf |= android.hardware.radio.RadioAccessFamily.IS95A; 1657 } 1658 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_1xRTT) != 0) { 1659 raf |= android.hardware.radio.RadioAccessFamily.ONE_X_RTT; 1660 } 1661 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_EVDO_0) != 0) { 1662 raf |= android.hardware.radio.RadioAccessFamily.EVDO_0; 1663 } 1664 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_EVDO_A) != 0) { 1665 raf |= android.hardware.radio.RadioAccessFamily.EVDO_A; 1666 } 1667 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_EVDO_B) != 0) { 1668 raf |= android.hardware.radio.RadioAccessFamily.EVDO_B; 1669 } 1670 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_EHRPD) != 0) { 1671 raf |= android.hardware.radio.RadioAccessFamily.EHRPD; 1672 } 1673 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_HSUPA) != 0) { 1674 raf |= android.hardware.radio.RadioAccessFamily.HSUPA; 1675 } 1676 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_HSDPA) != 0) { 1677 raf |= android.hardware.radio.RadioAccessFamily.HSDPA; 1678 } 1679 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_HSPA) != 0) { 1680 raf |= android.hardware.radio.RadioAccessFamily.HSPA; 1681 } 1682 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_HSPAP) != 0) { 1683 raf |= android.hardware.radio.RadioAccessFamily.HSPAP; 1684 } 1685 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_UMTS) != 0) { 1686 raf |= android.hardware.radio.RadioAccessFamily.UMTS; 1687 } 1688 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_TD_SCDMA) != 0) { 1689 raf |= android.hardware.radio.RadioAccessFamily.TD_SCDMA; 1690 } 1691 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_IWLAN) != 0) { 1692 raf |= android.hardware.radio.RadioAccessFamily.IWLAN; 1693 } 1694 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_LTE) != 0 1695 || (networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_LTE_CA) != 0) { 1696 raf |= android.hardware.radio.RadioAccessFamily.LTE; 1697 } 1698 if ((networkTypeBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_NR) != 0) { 1699 raf |= android.hardware.radio.RadioAccessFamily.NR; 1700 } 1701 return (raf == 0) ? android.hardware.radio.RadioAccessFamily.UNKNOWN : raf; 1702 } 1703 1704 /** 1705 * Convert AccessNetworkType to AccessNetwork defined in radio/1.5/types.hal 1706 * @param accessNetworkType Access network type 1707 * @return The converted AccessNetwork 1708 */ convertToHalAccessNetwork(int accessNetworkType)1709 public static int convertToHalAccessNetwork(int accessNetworkType) { 1710 switch (accessNetworkType) { 1711 case AccessNetworkConstants.AccessNetworkType.GERAN: 1712 return android.hardware.radio.V1_5.AccessNetwork.GERAN; 1713 case AccessNetworkConstants.AccessNetworkType.UTRAN: 1714 return android.hardware.radio.V1_5.AccessNetwork.UTRAN; 1715 case AccessNetworkConstants.AccessNetworkType.EUTRAN: 1716 return android.hardware.radio.V1_5.AccessNetwork.EUTRAN; 1717 case AccessNetworkConstants.AccessNetworkType.CDMA2000: 1718 return android.hardware.radio.V1_5.AccessNetwork.CDMA2000; 1719 case AccessNetworkConstants.AccessNetworkType.IWLAN: 1720 return android.hardware.radio.V1_5.AccessNetwork.IWLAN; 1721 case AccessNetworkConstants.AccessNetworkType.NGRAN: 1722 return android.hardware.radio.V1_5.AccessNetwork.NGRAN; 1723 case AccessNetworkConstants.AccessNetworkType.UNKNOWN: 1724 default: 1725 return android.hardware.radio.V1_5.AccessNetwork.UNKNOWN; 1726 } 1727 } 1728 1729 /** 1730 * Convert to AccessNetwork.aidl 1731 * @param accessNetworkType Access network type 1732 * @return The converted AccessNetwork 1733 */ convertToHalAccessNetworkAidl(int accessNetworkType)1734 public static int convertToHalAccessNetworkAidl(int accessNetworkType) { 1735 switch (accessNetworkType) { 1736 case AccessNetworkConstants.AccessNetworkType.GERAN: 1737 return android.hardware.radio.AccessNetwork.GERAN; 1738 case AccessNetworkConstants.AccessNetworkType.UTRAN: 1739 return android.hardware.radio.AccessNetwork.UTRAN; 1740 case AccessNetworkConstants.AccessNetworkType.EUTRAN: 1741 return android.hardware.radio.AccessNetwork.EUTRAN; 1742 case AccessNetworkConstants.AccessNetworkType.CDMA2000: 1743 return android.hardware.radio.AccessNetwork.CDMA2000; 1744 case AccessNetworkConstants.AccessNetworkType.IWLAN: 1745 return android.hardware.radio.AccessNetwork.IWLAN; 1746 case AccessNetworkConstants.AccessNetworkType.NGRAN: 1747 return android.hardware.radio.AccessNetwork.NGRAN; 1748 case AccessNetworkConstants.AccessNetworkType.UNKNOWN: 1749 default: 1750 return android.hardware.radio.AccessNetwork.UNKNOWN; 1751 } 1752 } 1753 1754 /** 1755 * Convert to RadioAccessNetwork defined in radio/1.1/types.hal 1756 * @param accessNetworkType Access network type 1757 * @return The converted RadioAccessNetwork 1758 */ convertToHalRadioAccessNetworks(int accessNetworkType)1759 public static int convertToHalRadioAccessNetworks(int accessNetworkType) { 1760 switch (accessNetworkType) { 1761 case AccessNetworkConstants.AccessNetworkType.GERAN: 1762 return android.hardware.radio.V1_1.RadioAccessNetworks.GERAN; 1763 case AccessNetworkConstants.AccessNetworkType.UTRAN: 1764 return android.hardware.radio.V1_1.RadioAccessNetworks.UTRAN; 1765 case AccessNetworkConstants.AccessNetworkType.EUTRAN: 1766 return android.hardware.radio.V1_1.RadioAccessNetworks.EUTRAN; 1767 case AccessNetworkConstants.AccessNetworkType.NGRAN: 1768 return android.hardware.radio.V1_5.RadioAccessNetworks.NGRAN; 1769 case AccessNetworkConstants.AccessNetworkType.CDMA2000: 1770 return android.hardware.radio.V1_5.RadioAccessNetworks.CDMA2000; 1771 case AccessNetworkConstants.AccessNetworkType.UNKNOWN: 1772 default: 1773 return android.hardware.radio.V1_5.RadioAccessNetworks.UNKNOWN; 1774 } 1775 } 1776 1777 /** 1778 * Convert RadioAccessNetworks defined in radio/1.5/types.hal to AccessNetworkType 1779 * @param ran RadioAccessNetwork defined in radio/1.5/types.hal 1780 * @return The converted AccessNetworkType 1781 */ convertHalRadioAccessNetworks(int ran)1782 public static int convertHalRadioAccessNetworks(int ran) { 1783 switch (ran) { 1784 case android.hardware.radio.V1_5.RadioAccessNetworks.GERAN: 1785 return AccessNetworkConstants.AccessNetworkType.GERAN; 1786 case android.hardware.radio.V1_5.RadioAccessNetworks.UTRAN: 1787 return AccessNetworkConstants.AccessNetworkType.UTRAN; 1788 case android.hardware.radio.V1_5.RadioAccessNetworks.EUTRAN: 1789 return AccessNetworkConstants.AccessNetworkType.EUTRAN; 1790 case android.hardware.radio.V1_5.RadioAccessNetworks.NGRAN: 1791 return AccessNetworkConstants.AccessNetworkType.NGRAN; 1792 case android.hardware.radio.V1_5.RadioAccessNetworks.CDMA2000: 1793 return AccessNetworkConstants.AccessNetworkType.CDMA2000; 1794 case android.hardware.radio.V1_5.RadioAccessNetworks.UNKNOWN: 1795 default: 1796 return AccessNetworkConstants.AccessNetworkType.UNKNOWN; 1797 } 1798 } 1799 1800 /** 1801 * Convert to SimApdu defined in radio/1.0/types.hal 1802 * @param channel channel 1803 * @param cla cla 1804 * @param instruction instruction 1805 * @param p1 p1 1806 * @param p2 p2 1807 * @param p3 p3 1808 * @param data data 1809 * @return The converted SimApdu 1810 */ convertToHalSimApdu(int channel, int cla, int instruction, int p1, int p2, int p3, String data)1811 public static android.hardware.radio.V1_0.SimApdu convertToHalSimApdu(int channel, int cla, 1812 int instruction, int p1, int p2, int p3, String data) { 1813 android.hardware.radio.V1_0.SimApdu msg = new android.hardware.radio.V1_0.SimApdu(); 1814 msg.sessionId = channel; 1815 msg.cla = cla; 1816 msg.instruction = instruction; 1817 msg.p1 = p1; 1818 msg.p2 = p2; 1819 msg.p3 = p3; 1820 msg.data = convertNullToEmptyString(data); 1821 return msg; 1822 } 1823 1824 /** 1825 * Convert to SimApdu.aidl 1826 * @param channel channel 1827 * @param cla cla 1828 * @param instruction instruction 1829 * @param p1 p1 1830 * @param p2 p2 1831 * @param p3 p3 1832 * @param data data 1833 * @param radioHalVersion radio hal version 1834 * @return The converted SimApdu 1835 */ convertToHalSimApduAidl(int channel, int cla, int instruction, int p1, int p2, int p3, String data, boolean isEs10Command, HalVersion radioHalVersion)1836 public static android.hardware.radio.sim.SimApdu convertToHalSimApduAidl(int channel, int cla, 1837 int instruction, int p1, int p2, int p3, String data, boolean isEs10Command, 1838 HalVersion radioHalVersion) { 1839 android.hardware.radio.sim.SimApdu msg = new android.hardware.radio.sim.SimApdu(); 1840 msg.sessionId = channel; 1841 msg.cla = cla; 1842 msg.instruction = instruction; 1843 msg.p1 = p1; 1844 msg.p2 = p2; 1845 msg.p3 = p3; 1846 msg.data = convertNullToEmptyString(data); 1847 if (radioHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_2_1)) { 1848 msg.isEs10 = isEs10Command; 1849 } 1850 return msg; 1851 } 1852 1853 /** 1854 * Convert to SimLockMultiSimPolicy defined in radio/1.4/types.hal 1855 * @param policy Multi SIM policy 1856 * @return The converted SimLockMultiSimPolicy 1857 */ convertToHalSimLockMultiSimPolicy(int policy)1858 public static int convertToHalSimLockMultiSimPolicy(int policy) { 1859 switch (policy) { 1860 case CarrierRestrictionRules.MULTISIM_POLICY_ONE_VALID_SIM_MUST_BE_PRESENT: 1861 return android.hardware.radio.V1_4.SimLockMultiSimPolicy 1862 .ONE_VALID_SIM_MUST_BE_PRESENT; 1863 case CarrierRestrictionRules.MULTISIM_POLICY_NONE: 1864 // fallthrough 1865 default: 1866 return android.hardware.radio.V1_4.SimLockMultiSimPolicy.NO_MULTISIM_POLICY; 1867 1868 } 1869 } 1870 1871 /** 1872 * Convert to SimLockMultiSimPolicy.aidl 1873 * @param policy Multi SIM policy 1874 * @return The converted SimLockMultiSimPolicy 1875 */ convertToHalSimLockMultiSimPolicyAidl(int policy)1876 public static int convertToHalSimLockMultiSimPolicyAidl(int policy) { 1877 switch (policy) { 1878 case CarrierRestrictionRules.MULTISIM_POLICY_ONE_VALID_SIM_MUST_BE_PRESENT: 1879 return android.hardware.radio.sim.SimLockMultiSimPolicy 1880 .ONE_VALID_SIM_MUST_BE_PRESENT; 1881 case CarrierRestrictionRules.MULTISIM_POLICY_NONE: 1882 // fallthrough 1883 default: 1884 return android.hardware.radio.sim.SimLockMultiSimPolicy.NO_MULTISIM_POLICY; 1885 1886 } 1887 } 1888 1889 /** 1890 * Convert a list of CarrierIdentifiers into a list of Carriers defined in radio/1.0/types.hal 1891 * @param carriers List of CarrierIdentifiers 1892 * @return The converted list of Carriers 1893 */ convertToHalCarrierRestrictionList( List<CarrierIdentifier> carriers)1894 public static ArrayList<android.hardware.radio.V1_0.Carrier> convertToHalCarrierRestrictionList( 1895 List<CarrierIdentifier> carriers) { 1896 ArrayList<android.hardware.radio.V1_0.Carrier> result = new ArrayList<>(); 1897 for (CarrierIdentifier ci : carriers) { 1898 android.hardware.radio.V1_0.Carrier c = new android.hardware.radio.V1_0.Carrier(); 1899 c.mcc = convertNullToEmptyString(ci.getMcc()); 1900 c.mnc = convertNullToEmptyString(ci.getMnc()); 1901 int matchType = CarrierIdentifier.MatchType.ALL; 1902 String matchData = null; 1903 if (!TextUtils.isEmpty(ci.getSpn())) { 1904 matchType = CarrierIdentifier.MatchType.SPN; 1905 matchData = ci.getSpn(); 1906 } else if (!TextUtils.isEmpty(ci.getImsi())) { 1907 matchType = CarrierIdentifier.MatchType.IMSI_PREFIX; 1908 matchData = ci.getImsi(); 1909 } else if (!TextUtils.isEmpty(ci.getGid1())) { 1910 matchType = CarrierIdentifier.MatchType.GID1; 1911 matchData = ci.getGid1(); 1912 } else if (!TextUtils.isEmpty(ci.getGid2())) { 1913 matchType = CarrierIdentifier.MatchType.GID2; 1914 matchData = ci.getGid2(); 1915 } 1916 c.matchType = matchType; 1917 c.matchData = convertNullToEmptyString(matchData); 1918 result.add(c); 1919 } 1920 return result; 1921 } 1922 1923 /** 1924 * Convert a list of CarrierIdentifiers into an array of Carrier.aidl 1925 * @param carriers List of CarrierIdentifiers 1926 * @return The converted array of Carriers 1927 */ convertToHalCarrierRestrictionListAidl( List<CarrierIdentifier> carriers)1928 public static android.hardware.radio.sim.Carrier[] convertToHalCarrierRestrictionListAidl( 1929 List<CarrierIdentifier> carriers) { 1930 android.hardware.radio.sim.Carrier[] result = 1931 new android.hardware.radio.sim.Carrier[carriers.size()]; 1932 for (int i = 0; i < carriers.size(); i++) { 1933 CarrierIdentifier ci = carriers.get(i); 1934 android.hardware.radio.sim.Carrier carrier = new android.hardware.radio.sim.Carrier(); 1935 carrier.mcc = convertNullToEmptyString(ci.getMcc()); 1936 carrier.mnc = convertNullToEmptyString(ci.getMnc()); 1937 int matchType = CarrierIdentifier.MatchType.ALL; 1938 String matchData = null; 1939 if (!TextUtils.isEmpty(ci.getSpn())) { 1940 matchType = CarrierIdentifier.MatchType.SPN; 1941 matchData = ci.getSpn(); 1942 } else if (!TextUtils.isEmpty(ci.getImsi())) { 1943 matchType = CarrierIdentifier.MatchType.IMSI_PREFIX; 1944 matchData = ci.getImsi(); 1945 } else if (!TextUtils.isEmpty(ci.getGid1())) { 1946 matchType = CarrierIdentifier.MatchType.GID1; 1947 matchData = ci.getGid1(); 1948 } else if (!TextUtils.isEmpty(ci.getGid2())) { 1949 matchType = CarrierIdentifier.MatchType.GID2; 1950 matchData = ci.getGid2(); 1951 } 1952 carrier.matchType = matchType; 1953 carrier.matchData = convertNullToEmptyString(matchData); 1954 result[i] = carrier; 1955 } 1956 return result; 1957 } 1958 1959 /** 1960 * Convert a list of CarrierIdentifiers into an array of CarrierInfo.aidl 1961 * 1962 * @param carriers List of CarrierIdentifiers 1963 * @return The converted array of CarrierInfos. 1964 */ convertToHalCarrierInfoListAidl( List<CarrierIdentifier> carriers)1965 public static android.hardware.radio.sim.CarrierInfo[] convertToHalCarrierInfoListAidl( 1966 List<CarrierIdentifier> carriers) { 1967 android.hardware.radio.sim.CarrierInfo[] result = 1968 new android.hardware.radio.sim.CarrierInfo[carriers.size()]; 1969 for (int i = 0; i < carriers.size(); i++) { 1970 CarrierIdentifier ci = carriers.get(i); 1971 android.hardware.radio.sim.CarrierInfo carrierInfo = 1972 new android.hardware.radio.sim.CarrierInfo(); 1973 carrierInfo.mcc = convertNullToEmptyString(ci.getMcc()); 1974 carrierInfo.mnc = convertNullToEmptyString(ci.getMnc()); 1975 carrierInfo.spn = ci.getSpn(); 1976 carrierInfo.imsiPrefix = ci.getImsi(); 1977 carrierInfo.gid1 = ci.getGid1(); 1978 carrierInfo.gid2 = ci.getGid2(); 1979 result[i] = carrierInfo; 1980 } 1981 return result; 1982 } 1983 1984 /** 1985 * Convert to Dial defined in radio/1.0/types.hal 1986 * @param address Address 1987 * @param clirMode CLIR mode 1988 * @param uusInfo UUS info 1989 * @return The converted Dial 1990 */ convertToHalDial(String address, int clirMode, UUSInfo uusInfo)1991 public static android.hardware.radio.V1_0.Dial convertToHalDial(String address, int clirMode, 1992 UUSInfo uusInfo) { 1993 android.hardware.radio.V1_0.Dial dial = new android.hardware.radio.V1_0.Dial(); 1994 dial.address = convertNullToEmptyString(address); 1995 dial.clir = clirMode; 1996 if (uusInfo != null) { 1997 android.hardware.radio.V1_0.UusInfo info = new android.hardware.radio.V1_0.UusInfo(); 1998 info.uusType = uusInfo.getType(); 1999 info.uusDcs = uusInfo.getDcs(); 2000 info.uusData = new String(uusInfo.getUserData()); 2001 dial.uusInfo.add(info); 2002 } 2003 return dial; 2004 } 2005 2006 /** 2007 * Convert to Dial.aidl 2008 * @param address Address 2009 * @param clirMode CLIR mode 2010 * @param uusInfo UUS info 2011 * @return The converted Dial.aidl 2012 */ convertToHalDialAidl(String address, int clirMode, UUSInfo uusInfo)2013 public static android.hardware.radio.voice.Dial convertToHalDialAidl(String address, 2014 int clirMode, UUSInfo uusInfo) { 2015 android.hardware.radio.voice.Dial dial = new android.hardware.radio.voice.Dial(); 2016 dial.address = convertNullToEmptyString(address); 2017 dial.clir = clirMode; 2018 if (uusInfo != null) { 2019 android.hardware.radio.voice.UusInfo info = new android.hardware.radio.voice.UusInfo(); 2020 info.uusType = uusInfo.getType(); 2021 info.uusDcs = uusInfo.getDcs(); 2022 info.uusData = new String(uusInfo.getUserData()); 2023 dial.uusInfo = new android.hardware.radio.voice.UusInfo[] {info}; 2024 } else { 2025 dial.uusInfo = new android.hardware.radio.voice.UusInfo[0]; 2026 } 2027 return dial; 2028 } 2029 2030 /** 2031 * Convert to SignalThresholdInfo defined in radio/1.5/types.hal 2032 * @param signalThresholdInfo Signal threshold info 2033 * @return The converted SignalThresholdInfo 2034 */ convertToHalSignalThresholdInfo( SignalThresholdInfo signalThresholdInfo)2035 public static android.hardware.radio.V1_5.SignalThresholdInfo convertToHalSignalThresholdInfo( 2036 SignalThresholdInfo signalThresholdInfo) { 2037 android.hardware.radio.V1_5.SignalThresholdInfo signalThresholdInfoHal = 2038 new android.hardware.radio.V1_5.SignalThresholdInfo(); 2039 signalThresholdInfoHal.signalMeasurement = signalThresholdInfo.getSignalMeasurementType(); 2040 signalThresholdInfoHal.hysteresisMs = signalThresholdInfo.getHysteresisMs(); 2041 signalThresholdInfoHal.hysteresisDb = signalThresholdInfo.getHysteresisDb(); 2042 signalThresholdInfoHal.thresholds = primitiveArrayToArrayList( 2043 signalThresholdInfo.getThresholds()); 2044 signalThresholdInfoHal.isEnabled = signalThresholdInfo.isEnabled(); 2045 return signalThresholdInfoHal; 2046 } 2047 2048 /** 2049 * Convert to SignalThresholdInfo.aidl 2050 * @param signalThresholdInfo Signal threshold info 2051 * @return The converted SignalThresholdInfo 2052 */ 2053 public static android.hardware.radio.network.SignalThresholdInfo convertToHalSignalThresholdInfoAidl(SignalThresholdInfo signalThresholdInfo)2054 convertToHalSignalThresholdInfoAidl(SignalThresholdInfo signalThresholdInfo) { 2055 android.hardware.radio.network.SignalThresholdInfo signalThresholdInfoHal = 2056 new android.hardware.radio.network.SignalThresholdInfo(); 2057 signalThresholdInfoHal.signalMeasurement = signalThresholdInfo.getSignalMeasurementType(); 2058 signalThresholdInfoHal.hysteresisMs = signalThresholdInfo.getHysteresisMs(); 2059 signalThresholdInfoHal.hysteresisDb = signalThresholdInfo.getHysteresisDb(); 2060 signalThresholdInfoHal.thresholds = signalThresholdInfo.getThresholds(); 2061 signalThresholdInfoHal.isEnabled = signalThresholdInfo.isEnabled(); 2062 signalThresholdInfoHal.ran = signalThresholdInfo.getRadioAccessNetworkType(); 2063 return signalThresholdInfoHal; 2064 } 2065 2066 /** 2067 * Convert to SmsWriteArgsStatus defined in radio/1.0/types.hal 2068 * @param status StatusOnIcc 2069 * @return The converted SmsWriteArgsStatus defined in radio/1.0/types.hal 2070 */ convertToHalSmsWriteArgsStatus(int status)2071 public static int convertToHalSmsWriteArgsStatus(int status) { 2072 switch (status & 0x7) { 2073 case SmsManager.STATUS_ON_ICC_READ: 2074 return android.hardware.radio.V1_0.SmsWriteArgsStatus.REC_READ; 2075 case SmsManager.STATUS_ON_ICC_UNREAD: 2076 return android.hardware.radio.V1_0.SmsWriteArgsStatus.REC_UNREAD; 2077 case SmsManager.STATUS_ON_ICC_SENT: 2078 return android.hardware.radio.V1_0.SmsWriteArgsStatus.STO_SENT; 2079 case SmsManager.STATUS_ON_ICC_UNSENT: 2080 return android.hardware.radio.V1_0.SmsWriteArgsStatus.STO_UNSENT; 2081 default: 2082 return android.hardware.radio.V1_0.SmsWriteArgsStatus.REC_READ; 2083 } 2084 } 2085 2086 /** 2087 * Convert to statuses defined in SmsWriteArgs.aidl 2088 * @param status StatusOnIcc 2089 * @return The converted statuses defined in SmsWriteArgs.aidl 2090 */ convertToHalSmsWriteArgsStatusAidl(int status)2091 public static int convertToHalSmsWriteArgsStatusAidl(int status) { 2092 switch (status & 0x7) { 2093 case SmsManager.STATUS_ON_ICC_READ: 2094 return android.hardware.radio.messaging.SmsWriteArgs.STATUS_REC_READ; 2095 case SmsManager.STATUS_ON_ICC_UNREAD: 2096 return android.hardware.radio.messaging.SmsWriteArgs.STATUS_REC_UNREAD; 2097 case SmsManager.STATUS_ON_ICC_SENT: 2098 return android.hardware.radio.messaging.SmsWriteArgs.STATUS_STO_SENT; 2099 case SmsManager.STATUS_ON_ICC_UNSENT: 2100 return android.hardware.radio.messaging.SmsWriteArgs.STATUS_STO_UNSENT; 2101 default: 2102 return android.hardware.radio.messaging.SmsWriteArgs.STATUS_REC_READ; 2103 } 2104 } 2105 2106 /** 2107 * Convert a list of HardwareConfig defined in radio/1.0/types.hal to a list of HardwareConfig 2108 * @param hwListRil List of HardwareConfig defined in radio/1.0/types.hal 2109 * @return The converted list of HardwareConfig 2110 */ convertHalHardwareConfigList( ArrayList<android.hardware.radio.V1_0.HardwareConfig> hwListRil)2111 public static ArrayList<HardwareConfig> convertHalHardwareConfigList( 2112 ArrayList<android.hardware.radio.V1_0.HardwareConfig> hwListRil) { 2113 int num; 2114 ArrayList<HardwareConfig> response; 2115 HardwareConfig hw; 2116 2117 num = hwListRil.size(); 2118 response = new ArrayList<>(num); 2119 2120 for (android.hardware.radio.V1_0.HardwareConfig hwRil : hwListRil) { 2121 int type = hwRil.type; 2122 switch(type) { 2123 case HardwareConfig.DEV_HARDWARE_TYPE_MODEM: { 2124 hw = new HardwareConfig(type); 2125 android.hardware.radio.V1_0.HardwareConfigModem hwModem = hwRil.modem.get(0); 2126 hw.assignModem(hwRil.uuid, hwRil.state, hwModem.rilModel, hwModem.rat, 2127 hwModem.maxVoice, hwModem.maxData, hwModem.maxStandby); 2128 break; 2129 } 2130 case HardwareConfig.DEV_HARDWARE_TYPE_SIM: { 2131 hw = new HardwareConfig(type); 2132 hw.assignSim(hwRil.uuid, hwRil.state, hwRil.sim.get(0).modemUuid); 2133 break; 2134 } 2135 default: { 2136 throw new RuntimeException( 2137 "RIL_REQUEST_GET_HARDWARE_CONFIG invalid hardware type:" + type); 2138 } 2139 } 2140 response.add(hw); 2141 } 2142 return response; 2143 } 2144 2145 /** 2146 * Convert a list of HardwareConfig defined in HardwareConfig.aidl to a list of HardwareConfig 2147 * @param hwListRil List of HardwareConfig defined in HardwareConfig.aidl 2148 * @return The converted list of HardwareConfig 2149 */ convertHalHardwareConfigList( android.hardware.radio.modem.HardwareConfig[] hwListRil)2150 public static ArrayList<HardwareConfig> convertHalHardwareConfigList( 2151 android.hardware.radio.modem.HardwareConfig[] hwListRil) { 2152 ArrayList<HardwareConfig> response = new ArrayList<>(hwListRil.length); 2153 HardwareConfig hw; 2154 2155 for (android.hardware.radio.modem.HardwareConfig hwRil : hwListRil) { 2156 int type = hwRil.type; 2157 switch (type) { 2158 case HardwareConfig.DEV_HARDWARE_TYPE_MODEM: { 2159 hw = new HardwareConfig(type); 2160 android.hardware.radio.modem.HardwareConfigModem hwModem = hwRil.modem[0]; 2161 hw.assignModem(hwRil.uuid, hwRil.state, hwModem.rilModel, hwModem.rat, 2162 hwModem.maxVoiceCalls, hwModem.maxDataCalls, hwModem.maxStandby); 2163 break; 2164 } 2165 case HardwareConfig.DEV_HARDWARE_TYPE_SIM: { 2166 hw = new HardwareConfig(type); 2167 hw.assignSim(hwRil.uuid, hwRil.state, hwRil.sim[0].modemUuid); 2168 break; 2169 } 2170 default: { 2171 throw new RuntimeException( 2172 "RIL_REQUEST_GET_HARDWARE_CONFIG invalid hardware type:" + type); 2173 } 2174 } 2175 response.add(hw); 2176 } 2177 return response; 2178 } 2179 2180 /** 2181 * Convert RadioCapability defined in radio/1.0/types.hal to RadioCapability 2182 * @param rc RadioCapability defined in radio/1.0/types.hal 2183 * @param ril RIL 2184 * @return The converted RadioCapability 2185 */ convertHalRadioCapability( android.hardware.radio.V1_0.RadioCapability rc, RIL ril)2186 public static RadioCapability convertHalRadioCapability( 2187 android.hardware.radio.V1_0.RadioCapability rc, RIL ril) { 2188 int session = rc.session; 2189 int phase = rc.phase; 2190 int rat = convertHalNetworkTypeBitMask(rc.raf); 2191 String logicModemUuid = rc.logicalModemUuid; 2192 int status = rc.status; 2193 2194 ril.riljLog("convertHalRadioCapability: session=" + session + ", phase=" + phase + ", rat=" 2195 + rat + ", logicModemUuid=" + logicModemUuid + ", status=" + status + ", rcRil.raf=" 2196 + rc.raf); 2197 return new RadioCapability(ril.mPhoneId, session, phase, rat, logicModemUuid, status); 2198 } 2199 2200 /** 2201 * Convert RadioCapability defined in RadioCapability.aidl to RadioCapability 2202 * @param rc RadioCapability defined in RadioCapability.aidl 2203 * @param ril RIL 2204 * @return The converted RadioCapability 2205 */ convertHalRadioCapability( android.hardware.radio.modem.RadioCapability rc, RIL ril)2206 public static RadioCapability convertHalRadioCapability( 2207 android.hardware.radio.modem.RadioCapability rc, RIL ril) { 2208 int session = rc.session; 2209 int phase = rc.phase; 2210 int rat = convertHalNetworkTypeBitMask(rc.raf); 2211 String logicModemUuid = rc.logicalModemUuid; 2212 int status = rc.status; 2213 2214 ril.riljLog("convertHalRadioCapability: session=" + session + ", phase=" + phase + ", rat=" 2215 + rat + ", logicModemUuid=" + logicModemUuid + ", status=" + status + ", rcRil.raf=" 2216 + rc.raf); 2217 return new RadioCapability(ril.mPhoneId, session, phase, rat, logicModemUuid, status); 2218 } 2219 2220 /** 2221 * Convert LinkCapacityEstimate defined in radio/1.2, 1.6/types.hal to 2222 * a list of LinkCapacityEstimates 2223 * @param lceObj LinkCapacityEstimate defined in radio/1.2, 1.6/types.hal 2224 * @return The converted list of LinkCapacityEstimates 2225 */ convertHalLinkCapacityEstimate(Object lceObj)2226 public static List<LinkCapacityEstimate> convertHalLinkCapacityEstimate(Object lceObj) { 2227 final List<LinkCapacityEstimate> lceList = new ArrayList<>(); 2228 if (lceObj == null) return lceList; 2229 if (lceObj instanceof android.hardware.radio.V1_2.LinkCapacityEstimate) { 2230 android.hardware.radio.V1_2.LinkCapacityEstimate lce = 2231 (android.hardware.radio.V1_2.LinkCapacityEstimate) lceObj; 2232 lceList.add(new LinkCapacityEstimate(LinkCapacityEstimate.LCE_TYPE_COMBINED, 2233 lce.downlinkCapacityKbps, lce.uplinkCapacityKbps)); 2234 } else if (lceObj instanceof android.hardware.radio.V1_6.LinkCapacityEstimate) { 2235 android.hardware.radio.V1_6.LinkCapacityEstimate lce = 2236 (android.hardware.radio.V1_6.LinkCapacityEstimate) lceObj; 2237 int primaryDownlinkCapacityKbps = lce.downlinkCapacityKbps; 2238 int primaryUplinkCapacityKbps = lce.uplinkCapacityKbps; 2239 if (primaryDownlinkCapacityKbps != LinkCapacityEstimate.INVALID 2240 && lce.secondaryDownlinkCapacityKbps != LinkCapacityEstimate.INVALID) { 2241 primaryDownlinkCapacityKbps = 2242 lce.downlinkCapacityKbps - lce.secondaryDownlinkCapacityKbps; 2243 } 2244 if (primaryUplinkCapacityKbps != LinkCapacityEstimate.INVALID 2245 && lce.secondaryUplinkCapacityKbps != LinkCapacityEstimate.INVALID) { 2246 primaryUplinkCapacityKbps = 2247 lce.uplinkCapacityKbps - lce.secondaryUplinkCapacityKbps; 2248 } 2249 lceList.add(new LinkCapacityEstimate(LinkCapacityEstimate.LCE_TYPE_PRIMARY, 2250 primaryDownlinkCapacityKbps, primaryUplinkCapacityKbps)); 2251 lceList.add(new LinkCapacityEstimate(LinkCapacityEstimate.LCE_TYPE_SECONDARY, 2252 lce.secondaryDownlinkCapacityKbps, lce.secondaryUplinkCapacityKbps)); 2253 } 2254 return lceList; 2255 } 2256 2257 /** 2258 * Convert LinkCapacityEstimate defined in LinkCapacityEstimate.aidl to a list of 2259 * LinkCapacityEstimates 2260 * @param lce LinkCapacityEstimate defined in LinkCapacityEstimate.aidl 2261 * @return The converted list of LinkCapacityEstimates 2262 */ convertHalLinkCapacityEstimate( android.hardware.radio.network.LinkCapacityEstimate lce)2263 public static List<LinkCapacityEstimate> convertHalLinkCapacityEstimate( 2264 android.hardware.radio.network.LinkCapacityEstimate lce) { 2265 final List<LinkCapacityEstimate> lceList = new ArrayList<>(); 2266 int primaryDownlinkCapacityKbps = lce.downlinkCapacityKbps; 2267 int primaryUplinkCapacityKbps = lce.uplinkCapacityKbps; 2268 if (primaryDownlinkCapacityKbps != LinkCapacityEstimate.INVALID 2269 && lce.secondaryDownlinkCapacityKbps != LinkCapacityEstimate.INVALID) { 2270 primaryDownlinkCapacityKbps = 2271 lce.downlinkCapacityKbps - lce.secondaryDownlinkCapacityKbps; 2272 } 2273 if (primaryUplinkCapacityKbps != LinkCapacityEstimate.INVALID 2274 && lce.secondaryUplinkCapacityKbps != LinkCapacityEstimate.INVALID) { 2275 primaryUplinkCapacityKbps = 2276 lce.uplinkCapacityKbps - lce.secondaryUplinkCapacityKbps; 2277 } 2278 lceList.add(new LinkCapacityEstimate(LinkCapacityEstimate.LCE_TYPE_PRIMARY, 2279 primaryDownlinkCapacityKbps, primaryUplinkCapacityKbps)); 2280 lceList.add(new LinkCapacityEstimate(LinkCapacityEstimate.LCE_TYPE_SECONDARY, 2281 lce.secondaryDownlinkCapacityKbps, lce.secondaryUplinkCapacityKbps)); 2282 return lceList; 2283 } 2284 2285 2286 /** 2287 * Convert a list of CellInfo defined in radio/1.4, 1.5, 1.6/types.hal to a list of 2288 * CellInfos 2289 * @param records List of CellInfo defined in radio/1.4, 1.5, 1.6/types.hal 2290 * @return The converted list of CellInfos 2291 */ convertHalCellInfoList(ArrayList<Object> records)2292 public static ArrayList<CellInfo> convertHalCellInfoList(ArrayList<Object> records) { 2293 ArrayList<CellInfo> response = new ArrayList<>(records.size()); 2294 if (records.isEmpty()) return response; 2295 final long nanotime = SystemClock.elapsedRealtimeNanos(); 2296 for (Object obj : records) { 2297 response.add(convertHalCellInfo(obj, nanotime)); 2298 } 2299 return response; 2300 } 2301 2302 /** 2303 * Convert a list of CellInfo defined in CellInfo.aidl to a list of CellInfos 2304 * @param records List of CellInfo defined in CellInfo.aidl 2305 * @return The converted list of CellInfos 2306 */ convertHalCellInfoList( android.hardware.radio.network.CellInfo[] records)2307 public static ArrayList<CellInfo> convertHalCellInfoList( 2308 android.hardware.radio.network.CellInfo[] records) { 2309 ArrayList<CellInfo> response = new ArrayList<>(records.length); 2310 if (records.length == 0) return response; 2311 final long nanotime = SystemClock.elapsedRealtimeNanos(); 2312 for (android.hardware.radio.network.CellInfo ci : records) { 2313 response.add(convertHalCellInfo(ci, nanotime)); 2314 } 2315 return response; 2316 } 2317 2318 /** 2319 * Convert a CellInfo defined in radio/1.4, 1.5, 1.6/types.hal to CellInfo 2320 * @param cellInfo CellInfo defined in radio/1.4, 1.5, 1.6/types.hal 2321 * @param nanotime time the CellInfo was created 2322 * @return The converted CellInfo 2323 */ convertHalCellInfo(Object cellInfo, long nanotime)2324 private static CellInfo convertHalCellInfo(Object cellInfo, long nanotime) { 2325 if (cellInfo == null) return null; 2326 int type; 2327 int connectionStatus; 2328 boolean registered; 2329 CellIdentityGsm gsmCi = null; 2330 CellSignalStrengthGsm gsmSs = null; 2331 CellIdentityCdma cdmaCi = null; 2332 CellSignalStrengthCdma cdmaSs = null; 2333 CellIdentityLte lteCi = null; 2334 CellSignalStrengthLte lteSs = null; 2335 CellConfigLte lteCc = null; 2336 CellIdentityWcdma wcdmaCi = null; 2337 CellSignalStrengthWcdma wcdmaSs = null; 2338 CellIdentityTdscdma tdscdmaCi = null; 2339 CellSignalStrengthTdscdma tdscdmaSs = null; 2340 CellIdentityNr nrCi = null; 2341 CellSignalStrengthNr nrSs = null; 2342 if (cellInfo instanceof android.hardware.radio.V1_4.CellInfo) { 2343 final android.hardware.radio.V1_4.CellInfo record = 2344 (android.hardware.radio.V1_4.CellInfo) cellInfo; 2345 connectionStatus = record.connectionStatus; 2346 registered = record.isRegistered; 2347 switch (record.info.getDiscriminator()) { 2348 case android.hardware.radio.V1_4.CellInfo.Info.hidl_discriminator.gsm: 2349 type = CellInfo.TYPE_GSM; 2350 android.hardware.radio.V1_2.CellInfoGsm gsm = record.info.gsm(); 2351 gsmCi = convertHalCellIdentityGsm(gsm.cellIdentityGsm); 2352 gsmSs = convertHalGsmSignalStrength(gsm.signalStrengthGsm); 2353 break; 2354 case android.hardware.radio.V1_4.CellInfo.Info.hidl_discriminator.cdma: 2355 type = CellInfo.TYPE_CDMA; 2356 android.hardware.radio.V1_2.CellInfoCdma cdma = record.info.cdma(); 2357 cdmaCi = convertHalCellIdentityCdma(cdma.cellIdentityCdma); 2358 cdmaSs = convertHalCdmaSignalStrength( 2359 cdma.signalStrengthCdma, cdma.signalStrengthEvdo); 2360 break; 2361 case android.hardware.radio.V1_4.CellInfo.Info.hidl_discriminator.lte: 2362 type = CellInfo.TYPE_LTE; 2363 android.hardware.radio.V1_4.CellInfoLte lte = record.info.lte(); 2364 lteCi = convertHalCellIdentityLte(lte.base.cellIdentityLte); 2365 lteSs = convertHalLteSignalStrength(lte.base.signalStrengthLte); 2366 lteCc = new CellConfigLte(lte.cellConfig.isEndcAvailable); 2367 break; 2368 case android.hardware.radio.V1_4.CellInfo.Info.hidl_discriminator.wcdma: 2369 type = CellInfo.TYPE_WCDMA; 2370 android.hardware.radio.V1_2.CellInfoWcdma wcdma = record.info.wcdma(); 2371 wcdmaCi = convertHalCellIdentityWcdma(wcdma.cellIdentityWcdma); 2372 wcdmaSs = convertHalWcdmaSignalStrength(wcdma.signalStrengthWcdma); 2373 break; 2374 case android.hardware.radio.V1_4.CellInfo.Info.hidl_discriminator.tdscdma: 2375 type = CellInfo.TYPE_TDSCDMA; 2376 android.hardware.radio.V1_2.CellInfoTdscdma tdscdma = record.info.tdscdma(); 2377 tdscdmaCi = convertHalCellIdentityTdscdma(tdscdma.cellIdentityTdscdma); 2378 tdscdmaSs = convertHalTdscdmaSignalStrength(tdscdma.signalStrengthTdscdma); 2379 break; 2380 case android.hardware.radio.V1_4.CellInfo.Info.hidl_discriminator.nr: 2381 type = CellInfo.TYPE_NR; 2382 android.hardware.radio.V1_4.CellInfoNr nr = record.info.nr(); 2383 nrCi = convertHalCellIdentityNr(nr.cellidentity); 2384 nrSs = convertHalNrSignalStrength(nr.signalStrength); 2385 break; 2386 default: return null; 2387 } 2388 } else if (cellInfo instanceof android.hardware.radio.V1_5.CellInfo) { 2389 final android.hardware.radio.V1_5.CellInfo record = 2390 (android.hardware.radio.V1_5.CellInfo) cellInfo; 2391 connectionStatus = record.connectionStatus; 2392 registered = record.registered; 2393 switch (record.ratSpecificInfo.getDiscriminator()) { 2394 case android.hardware.radio.V1_5.CellInfo 2395 .CellInfoRatSpecificInfo.hidl_discriminator.gsm: 2396 type = CellInfo.TYPE_GSM; 2397 android.hardware.radio.V1_5.CellInfoGsm gsm = record.ratSpecificInfo.gsm(); 2398 gsmCi = convertHalCellIdentityGsm(gsm.cellIdentityGsm); 2399 gsmSs = convertHalGsmSignalStrength(gsm.signalStrengthGsm); 2400 break; 2401 case android.hardware.radio.V1_5.CellInfo 2402 .CellInfoRatSpecificInfo.hidl_discriminator.cdma: 2403 type = CellInfo.TYPE_CDMA; 2404 android.hardware.radio.V1_2.CellInfoCdma cdma = record.ratSpecificInfo.cdma(); 2405 cdmaCi = convertHalCellIdentityCdma(cdma.cellIdentityCdma); 2406 cdmaSs = convertHalCdmaSignalStrength( 2407 cdma.signalStrengthCdma, cdma.signalStrengthEvdo); 2408 break; 2409 case android.hardware.radio.V1_5.CellInfo 2410 .CellInfoRatSpecificInfo.hidl_discriminator.lte: 2411 type = CellInfo.TYPE_LTE; 2412 android.hardware.radio.V1_5.CellInfoLte lte = record.ratSpecificInfo.lte(); 2413 lteCi = convertHalCellIdentityLte(lte.cellIdentityLte); 2414 lteSs = convertHalLteSignalStrength(lte.signalStrengthLte); 2415 lteCc = new CellConfigLte(); 2416 break; 2417 case android.hardware.radio.V1_5.CellInfo 2418 .CellInfoRatSpecificInfo.hidl_discriminator.wcdma: 2419 type = CellInfo.TYPE_WCDMA; 2420 android.hardware.radio.V1_5.CellInfoWcdma wcdma = 2421 record.ratSpecificInfo.wcdma(); 2422 wcdmaCi = convertHalCellIdentityWcdma(wcdma.cellIdentityWcdma); 2423 wcdmaSs = convertHalWcdmaSignalStrength(wcdma.signalStrengthWcdma); 2424 break; 2425 case android.hardware.radio.V1_5.CellInfo 2426 .CellInfoRatSpecificInfo.hidl_discriminator.tdscdma: 2427 type = CellInfo.TYPE_TDSCDMA; 2428 android.hardware.radio.V1_5.CellInfoTdscdma tdscdma = 2429 record.ratSpecificInfo.tdscdma(); 2430 tdscdmaCi = convertHalCellIdentityTdscdma(tdscdma.cellIdentityTdscdma); 2431 tdscdmaSs = convertHalTdscdmaSignalStrength(tdscdma.signalStrengthTdscdma); 2432 break; 2433 case android.hardware.radio.V1_5.CellInfo 2434 .CellInfoRatSpecificInfo.hidl_discriminator.nr: 2435 type = CellInfo.TYPE_NR; 2436 android.hardware.radio.V1_5.CellInfoNr nr = record.ratSpecificInfo.nr(); 2437 nrCi = convertHalCellIdentityNr(nr.cellIdentityNr); 2438 nrSs = convertHalNrSignalStrength(nr.signalStrengthNr); 2439 break; 2440 default: return null; 2441 } 2442 } else if (cellInfo instanceof android.hardware.radio.V1_6.CellInfo) { 2443 final android.hardware.radio.V1_6.CellInfo record = 2444 (android.hardware.radio.V1_6.CellInfo) cellInfo; 2445 connectionStatus = record.connectionStatus; 2446 registered = record.registered; 2447 switch (record.ratSpecificInfo.getDiscriminator()) { 2448 case android.hardware.radio.V1_6.CellInfo 2449 .CellInfoRatSpecificInfo.hidl_discriminator.gsm: 2450 type = CellInfo.TYPE_GSM; 2451 android.hardware.radio.V1_5.CellInfoGsm gsm = record.ratSpecificInfo.gsm(); 2452 gsmCi = convertHalCellIdentityGsm(gsm.cellIdentityGsm); 2453 gsmSs = convertHalGsmSignalStrength(gsm.signalStrengthGsm); 2454 break; 2455 case android.hardware.radio.V1_6.CellInfo 2456 .CellInfoRatSpecificInfo.hidl_discriminator.cdma: 2457 type = CellInfo.TYPE_CDMA; 2458 android.hardware.radio.V1_2.CellInfoCdma cdma = record.ratSpecificInfo.cdma(); 2459 cdmaCi = convertHalCellIdentityCdma(cdma.cellIdentityCdma); 2460 cdmaSs = convertHalCdmaSignalStrength( 2461 cdma.signalStrengthCdma, cdma.signalStrengthEvdo); 2462 break; 2463 case android.hardware.radio.V1_6.CellInfo 2464 .CellInfoRatSpecificInfo.hidl_discriminator.lte: 2465 type = CellInfo.TYPE_LTE; 2466 android.hardware.radio.V1_6.CellInfoLte lte = record.ratSpecificInfo.lte(); 2467 lteCi = convertHalCellIdentityLte(lte.cellIdentityLte); 2468 lteSs = convertHalLteSignalStrength(lte.signalStrengthLte); 2469 lteCc = new CellConfigLte(); 2470 break; 2471 case android.hardware.radio.V1_6.CellInfo 2472 .CellInfoRatSpecificInfo.hidl_discriminator.wcdma: 2473 type = CellInfo.TYPE_WCDMA; 2474 android.hardware.radio.V1_5.CellInfoWcdma wcdma = 2475 record.ratSpecificInfo.wcdma(); 2476 wcdmaCi = convertHalCellIdentityWcdma(wcdma.cellIdentityWcdma); 2477 wcdmaSs = convertHalWcdmaSignalStrength(wcdma.signalStrengthWcdma); 2478 break; 2479 case android.hardware.radio.V1_6.CellInfo 2480 .CellInfoRatSpecificInfo.hidl_discriminator.tdscdma: 2481 type = CellInfo.TYPE_TDSCDMA; 2482 android.hardware.radio.V1_5.CellInfoTdscdma tdscdma = 2483 record.ratSpecificInfo.tdscdma(); 2484 tdscdmaCi = convertHalCellIdentityTdscdma(tdscdma.cellIdentityTdscdma); 2485 tdscdmaSs = convertHalTdscdmaSignalStrength(tdscdma.signalStrengthTdscdma); 2486 break; 2487 case android.hardware.radio.V1_6.CellInfo 2488 .CellInfoRatSpecificInfo.hidl_discriminator.nr: 2489 type = CellInfo.TYPE_NR; 2490 android.hardware.radio.V1_6.CellInfoNr nr = record.ratSpecificInfo.nr(); 2491 nrCi = convertHalCellIdentityNr(nr.cellIdentityNr); 2492 nrSs = convertHalNrSignalStrength(nr.signalStrengthNr); 2493 break; 2494 default: return null; 2495 } 2496 } else { 2497 return null; 2498 } 2499 2500 switch (type) { 2501 case CellInfo.TYPE_GSM: 2502 return new CellInfoGsm(connectionStatus, registered, nanotime, gsmCi, gsmSs); 2503 case CellInfo.TYPE_CDMA: 2504 return new CellInfoCdma(connectionStatus, registered, nanotime, cdmaCi, cdmaSs); 2505 case CellInfo.TYPE_LTE: 2506 return new CellInfoLte(connectionStatus, registered, nanotime, lteCi, lteSs, lteCc); 2507 case CellInfo.TYPE_WCDMA: 2508 return new CellInfoWcdma(connectionStatus, registered, nanotime, wcdmaCi, wcdmaSs); 2509 case CellInfo.TYPE_TDSCDMA: 2510 return new CellInfoTdscdma(connectionStatus, registered, nanotime, tdscdmaCi, 2511 tdscdmaSs); 2512 case CellInfo.TYPE_NR: 2513 return new CellInfoNr(connectionStatus, registered, nanotime, nrCi, nrSs); 2514 case CellInfo.TYPE_UNKNOWN: 2515 default: 2516 return null; 2517 } 2518 } 2519 2520 /** 2521 * Convert a CellInfo defined in CellInfo.aidl to CellInfo 2522 * @param cellInfo CellInfo defined in CellInfo.aidl 2523 * @param nanotime time the CellInfo was created 2524 * @return The converted CellInfo 2525 */ convertHalCellInfo(android.hardware.radio.network.CellInfo cellInfo, long nanotime)2526 private static CellInfo convertHalCellInfo(android.hardware.radio.network.CellInfo cellInfo, 2527 long nanotime) { 2528 if (cellInfo == null) return null; 2529 int connectionStatus = cellInfo.connectionStatus; 2530 boolean registered = cellInfo.registered; 2531 switch (cellInfo.ratSpecificInfo.getTag()) { 2532 case android.hardware.radio.network.CellInfoRatSpecificInfo.gsm: 2533 android.hardware.radio.network.CellInfoGsm gsm = cellInfo.ratSpecificInfo.getGsm(); 2534 return new CellInfoGsm(connectionStatus, registered, nanotime, 2535 convertHalCellIdentityGsm(gsm.cellIdentityGsm), 2536 convertHalGsmSignalStrength(gsm.signalStrengthGsm)); 2537 case android.hardware.radio.network.CellInfoRatSpecificInfo.cdma: 2538 android.hardware.radio.network.CellInfoCdma cdma = 2539 cellInfo.ratSpecificInfo.getCdma(); 2540 return new CellInfoCdma(connectionStatus, registered, nanotime, 2541 convertHalCellIdentityCdma(cdma.cellIdentityCdma), 2542 convertHalCdmaSignalStrength(cdma.signalStrengthCdma, 2543 cdma.signalStrengthEvdo)); 2544 case android.hardware.radio.network.CellInfoRatSpecificInfo.lte: 2545 android.hardware.radio.network.CellInfoLte lte = cellInfo.ratSpecificInfo.getLte(); 2546 return new CellInfoLte(connectionStatus, registered, nanotime, 2547 convertHalCellIdentityLte(lte.cellIdentityLte), 2548 convertHalLteSignalStrength(lte.signalStrengthLte), new CellConfigLte()); 2549 case android.hardware.radio.network.CellInfoRatSpecificInfo.wcdma: 2550 android.hardware.radio.network.CellInfoWcdma wcdma = 2551 cellInfo.ratSpecificInfo.getWcdma(); 2552 return new CellInfoWcdma(connectionStatus, registered, nanotime, 2553 convertHalCellIdentityWcdma(wcdma.cellIdentityWcdma), 2554 convertHalWcdmaSignalStrength(wcdma.signalStrengthWcdma)); 2555 case android.hardware.radio.network.CellInfoRatSpecificInfo.tdscdma: 2556 android.hardware.radio.network.CellInfoTdscdma tdscdma = 2557 cellInfo.ratSpecificInfo.getTdscdma(); 2558 return new CellInfoTdscdma(connectionStatus, registered, nanotime, 2559 convertHalCellIdentityTdscdma(tdscdma.cellIdentityTdscdma), 2560 convertHalTdscdmaSignalStrength(tdscdma.signalStrengthTdscdma)); 2561 case android.hardware.radio.network.CellInfoRatSpecificInfo.nr: 2562 android.hardware.radio.network.CellInfoNr nr = cellInfo.ratSpecificInfo.getNr(); 2563 return new CellInfoNr(connectionStatus, registered, nanotime, 2564 convertHalCellIdentityNr(nr.cellIdentityNr), 2565 convertHalNrSignalStrength(nr.signalStrengthNr)); 2566 default: 2567 return null; 2568 } 2569 } 2570 2571 /** 2572 * Convert a CellIdentity defined in radio/1.2, 1.5/types.hal to CellIdentity 2573 * @param halCi CellIdentity defined in radio/1.2, 1.5/types.hal 2574 * @return The converted CellIdentity 2575 */ convertHalCellIdentity(Object halCi)2576 public static CellIdentity convertHalCellIdentity(Object halCi) { 2577 if (halCi == null) return null; 2578 if (halCi instanceof android.hardware.radio.V1_2.CellIdentity) { 2579 android.hardware.radio.V1_2.CellIdentity ci = 2580 (android.hardware.radio.V1_2.CellIdentity) halCi; 2581 switch (ci.cellInfoType) { 2582 case CellInfo.TYPE_GSM: 2583 if (ci.cellIdentityGsm.size() == 1) { 2584 return convertHalCellIdentityGsm(ci.cellIdentityGsm.get(0)); 2585 } 2586 break; 2587 case CellInfo.TYPE_CDMA: 2588 if (ci.cellIdentityCdma.size() == 1) { 2589 return convertHalCellIdentityCdma(ci.cellIdentityCdma.get(0)); 2590 } 2591 break; 2592 case CellInfo.TYPE_LTE: 2593 if (ci.cellIdentityLte.size() == 1) { 2594 return convertHalCellIdentityLte(ci.cellIdentityLte.get(0)); 2595 } 2596 break; 2597 case CellInfo.TYPE_WCDMA: 2598 if (ci.cellIdentityWcdma.size() == 1) { 2599 return convertHalCellIdentityWcdma(ci.cellIdentityWcdma.get(0)); 2600 } 2601 break; 2602 case CellInfo.TYPE_TDSCDMA: 2603 if (ci.cellIdentityTdscdma.size() == 1) { 2604 return convertHalCellIdentityTdscdma(ci.cellIdentityTdscdma.get(0)); 2605 } 2606 break; 2607 } 2608 } else if (halCi instanceof android.hardware.radio.V1_5.CellIdentity) { 2609 android.hardware.radio.V1_5.CellIdentity ci = 2610 (android.hardware.radio.V1_5.CellIdentity) halCi; 2611 switch (ci.getDiscriminator()) { 2612 case android.hardware.radio.V1_5.CellIdentity.hidl_discriminator.gsm: 2613 return convertHalCellIdentityGsm(ci.gsm()); 2614 case android.hardware.radio.V1_5.CellIdentity.hidl_discriminator.cdma: 2615 return convertHalCellIdentityCdma(ci.cdma()); 2616 case android.hardware.radio.V1_5.CellIdentity.hidl_discriminator.lte: 2617 return convertHalCellIdentityLte(ci.lte()); 2618 case android.hardware.radio.V1_5.CellIdentity.hidl_discriminator.wcdma: 2619 return convertHalCellIdentityWcdma(ci.wcdma()); 2620 case android.hardware.radio.V1_5.CellIdentity.hidl_discriminator.tdscdma: 2621 return convertHalCellIdentityTdscdma(ci.tdscdma()); 2622 case android.hardware.radio.V1_5.CellIdentity.hidl_discriminator.nr: 2623 return convertHalCellIdentityNr(ci.nr()); 2624 } 2625 } 2626 return null; 2627 } 2628 2629 /** 2630 * Convert a CellIdentity defined in CellIdentity.aidl to CellInfo 2631 * @param ci CellIdentity defined in CellIdentity.aidl 2632 * @return The converted CellIdentity 2633 */ convertHalCellIdentity( android.hardware.radio.network.CellIdentity ci)2634 public static CellIdentity convertHalCellIdentity( 2635 android.hardware.radio.network.CellIdentity ci) { 2636 if (ci == null) return null; 2637 switch (ci.getTag()) { 2638 case android.hardware.radio.network.CellIdentity.gsm: 2639 return convertHalCellIdentityGsm(ci.getGsm()); 2640 case android.hardware.radio.network.CellIdentity.cdma: 2641 return convertHalCellIdentityCdma(ci.getCdma()); 2642 case android.hardware.radio.network.CellIdentity.lte: 2643 return convertHalCellIdentityLte(ci.getLte()); 2644 case android.hardware.radio.network.CellIdentity.wcdma: 2645 return convertHalCellIdentityWcdma(ci.getWcdma()); 2646 case android.hardware.radio.network.CellIdentity.tdscdma: 2647 return convertHalCellIdentityTdscdma(ci.getTdscdma()); 2648 case android.hardware.radio.network.CellIdentity.nr: 2649 return convertHalCellIdentityNr(ci.getNr()); 2650 default: return null; 2651 } 2652 } 2653 2654 /** 2655 * Convert a CellIdentityGsm defined in radio/1.2, 1.5/types.hal to CellIdentityGsm 2656 * @param gsm CellIdentityGsm defined in radio/1.2, 1.5/types.hal 2657 * @return The converted CellIdentityGsm 2658 */ convertHalCellIdentityGsm(Object gsm)2659 public static CellIdentityGsm convertHalCellIdentityGsm(Object gsm) { 2660 if (gsm == null) return null; 2661 if (gsm instanceof android.hardware.radio.V1_2.CellIdentityGsm) { 2662 android.hardware.radio.V1_2.CellIdentityGsm ci = 2663 (android.hardware.radio.V1_2.CellIdentityGsm) gsm; 2664 return new CellIdentityGsm(ci.base.lac, ci.base.cid, ci.base.arfcn, 2665 ci.base.bsic == (byte) 0xFF ? CellInfo.UNAVAILABLE : ci.base.bsic, ci.base.mcc, 2666 ci.base.mnc, ci.operatorNames.alphaLong, ci.operatorNames.alphaShort, 2667 new ArraySet<>()); 2668 } else if (gsm instanceof android.hardware.radio.V1_5.CellIdentityGsm) { 2669 android.hardware.radio.V1_5.CellIdentityGsm ci = 2670 (android.hardware.radio.V1_5.CellIdentityGsm) gsm; 2671 return new CellIdentityGsm(ci.base.base.lac, ci.base.base.cid, ci.base.base.arfcn, 2672 ci.base.base.bsic == (byte) 0xFF ? CellInfo.UNAVAILABLE 2673 : ci.base.base.bsic, ci.base.base.mcc, ci.base.base.mnc, 2674 ci.base.operatorNames.alphaLong, ci.base.operatorNames.alphaShort, 2675 ci.additionalPlmns); 2676 } else { 2677 return null; 2678 } 2679 } 2680 2681 /** 2682 * Convert a CellIdentityGsm defined in CellIdentityGsm.aidl to CellIdentityGsm 2683 * @param cid CellIdentityGsm defined in CellIdentityGsm.aidl 2684 * @return The converted CellIdentityGsm 2685 */ convertHalCellIdentityGsm( android.hardware.radio.network.CellIdentityGsm cid)2686 public static CellIdentityGsm convertHalCellIdentityGsm( 2687 android.hardware.radio.network.CellIdentityGsm cid) { 2688 return new CellIdentityGsm(cid.lac, cid.cid, cid.arfcn, 2689 cid.bsic == (byte) 0xFF ? CellInfo.UNAVAILABLE : cid.bsic, cid.mcc, cid.mnc, 2690 cid.operatorNames.alphaLong, cid.operatorNames.alphaShort, new ArraySet<>()); 2691 } 2692 2693 /** 2694 * Convert a CellIdentityCdma defined in radio/1.2/types.hal to CellIdentityCdma 2695 * @param cdma CellIdentityCdma defined in radio/1.2/types.hal 2696 * @return The converted CellIdentityCdma 2697 */ convertHalCellIdentityCdma(Object cdma)2698 public static CellIdentityCdma convertHalCellIdentityCdma(Object cdma) { 2699 if (cdma == null) return null; 2700 if (cdma instanceof android.hardware.radio.V1_2.CellIdentityCdma) { 2701 android.hardware.radio.V1_2.CellIdentityCdma ci = 2702 (android.hardware.radio.V1_2.CellIdentityCdma) cdma; 2703 return new CellIdentityCdma(ci.base.networkId, ci.base.systemId, ci.base.baseStationId, 2704 ci.base.longitude, ci.base.latitude, ci.operatorNames.alphaLong, 2705 ci.operatorNames.alphaShort); 2706 } else { 2707 return null; 2708 } 2709 } 2710 2711 /** 2712 * Convert a CellIdentityCdma defined in CellIdentityCdma.aidl to CellIdentityCdma 2713 * @param cid CellIdentityCdma defined in CelIdentityCdma.aidl 2714 * @return The converted CellIdentityCdma 2715 */ convertHalCellIdentityCdma( android.hardware.radio.network.CellIdentityCdma cid)2716 public static CellIdentityCdma convertHalCellIdentityCdma( 2717 android.hardware.radio.network.CellIdentityCdma cid) { 2718 return new CellIdentityCdma(cid.networkId, cid.systemId, cid.baseStationId, cid.longitude, 2719 cid.latitude, cid.operatorNames.alphaLong, cid.operatorNames.alphaShort); 2720 } 2721 2722 /** 2723 * Convert a CellIdentityLte defined in radio/1.2, 1.5/types.hal to CellIdentityLte 2724 * @param lte CellIdentityLte defined in radio/1.2, 1.5/types.hal 2725 * @return The converted CellIdentityLte 2726 */ convertHalCellIdentityLte(Object lte)2727 public static CellIdentityLte convertHalCellIdentityLte(Object lte) { 2728 if (lte == null) return null; 2729 if (lte instanceof android.hardware.radio.V1_2.CellIdentityLte) { 2730 android.hardware.radio.V1_2.CellIdentityLte ci = 2731 (android.hardware.radio.V1_2.CellIdentityLte) lte; 2732 return new CellIdentityLte(ci.base.ci, ci.base.pci, ci.base.tac, ci.base.earfcn, 2733 new int[] {}, ci.bandwidth, ci.base.mcc, ci.base.mnc, 2734 ci.operatorNames.alphaLong, ci.operatorNames.alphaShort, new ArraySet<>(), 2735 null); 2736 } else if (lte instanceof android.hardware.radio.V1_5.CellIdentityLte) { 2737 android.hardware.radio.V1_5.CellIdentityLte ci = 2738 (android.hardware.radio.V1_5.CellIdentityLte) lte; 2739 return new CellIdentityLte(ci.base.base.ci, ci.base.base.pci, ci.base.base.tac, 2740 ci.base.base.earfcn, ci.bands.stream().mapToInt(Integer::intValue).toArray(), 2741 ci.base.bandwidth, ci.base.base.mcc, ci.base.base.mnc, 2742 ci.base.operatorNames.alphaLong, ci.base.operatorNames.alphaShort, 2743 ci.additionalPlmns, convertHalClosedSubscriberGroupInfo(ci.optionalCsgInfo)); 2744 } else { 2745 return null; 2746 } 2747 } 2748 2749 /** 2750 * Convert a CellIdentityLte defined in CellIdentityLte.aidl to CellIdentityLte 2751 * @param cid CellIdentityLte defined in CellIdentityLte.aidl 2752 * @return The converted CellIdentityLte 2753 */ convertHalCellIdentityLte( android.hardware.radio.network.CellIdentityLte cid)2754 public static CellIdentityLte convertHalCellIdentityLte( 2755 android.hardware.radio.network.CellIdentityLte cid) { 2756 return new CellIdentityLte(cid.ci, cid.pci, cid.tac, cid.earfcn, cid.bands, cid.bandwidth, 2757 cid.mcc, cid.mnc, cid.operatorNames.alphaLong, cid.operatorNames.alphaShort, 2758 primitiveArrayToArrayList(cid.additionalPlmns), 2759 convertHalClosedSubscriberGroupInfo(cid.csgInfo)); 2760 } 2761 2762 /** 2763 * Convert a CellIdentityWcdma defined in radio/1.2, 1.5/types.hal to CellIdentityWcdma 2764 * @param wcdma CellIdentityWcdma defined in radio/1.2, 1.5/types.hal 2765 * @return The converted CellIdentityWcdma 2766 */ convertHalCellIdentityWcdma(Object wcdma)2767 public static CellIdentityWcdma convertHalCellIdentityWcdma(Object wcdma) { 2768 if (wcdma == null) return null; 2769 if (wcdma instanceof android.hardware.radio.V1_2.CellIdentityWcdma) { 2770 android.hardware.radio.V1_2.CellIdentityWcdma ci = 2771 (android.hardware.radio.V1_2.CellIdentityWcdma) wcdma; 2772 return new CellIdentityWcdma(ci.base.lac, ci.base.cid, ci.base.psc, ci.base.uarfcn, 2773 ci.base.mcc, ci.base.mnc, ci.operatorNames.alphaLong, 2774 ci.operatorNames.alphaShort, new ArraySet<>(), null); 2775 } else if (wcdma instanceof android.hardware.radio.V1_5.CellIdentityWcdma) { 2776 android.hardware.radio.V1_5.CellIdentityWcdma ci = 2777 (android.hardware.radio.V1_5.CellIdentityWcdma) wcdma; 2778 return new CellIdentityWcdma(ci.base.base.lac, ci.base.base.cid, ci.base.base.psc, 2779 ci.base.base.uarfcn, ci.base.base.mcc, ci.base.base.mnc, 2780 ci.base.operatorNames.alphaLong, ci.base.operatorNames.alphaShort, 2781 ci.additionalPlmns, convertHalClosedSubscriberGroupInfo(ci.optionalCsgInfo)); 2782 } else { 2783 return null; 2784 } 2785 } 2786 2787 /** 2788 * Convert a CellIdentityWcdma defined in CellIdentityWcdma.aidl to CellIdentityWcdma 2789 * @param cid CellIdentityWcdma defined in CellIdentityWcdma.aidl 2790 * @return The converted CellIdentityWcdma 2791 */ convertHalCellIdentityWcdma( android.hardware.radio.network.CellIdentityWcdma cid)2792 public static CellIdentityWcdma convertHalCellIdentityWcdma( 2793 android.hardware.radio.network.CellIdentityWcdma cid) { 2794 return new CellIdentityWcdma(cid.lac, cid.cid, cid.psc, cid.uarfcn, cid.mcc, cid.mnc, 2795 cid.operatorNames.alphaLong, cid.operatorNames.alphaShort, 2796 primitiveArrayToArrayList(cid.additionalPlmns), 2797 convertHalClosedSubscriberGroupInfo(cid.csgInfo)); 2798 } 2799 2800 /** 2801 * Convert a CellIdentityTdscdma defined in radio/1.2, 1.5/types.hal to CellIdentityTdscdma 2802 * @param tdscdma CellIdentityTdscdma defined in radio/1.2, 1.5/types.hal 2803 * @return The converted CellIdentityTdscdma 2804 */ convertHalCellIdentityTdscdma(Object tdscdma)2805 public static CellIdentityTdscdma convertHalCellIdentityTdscdma(Object tdscdma) { 2806 if (tdscdma == null) return null; 2807 if (tdscdma instanceof android.hardware.radio.V1_2.CellIdentityTdscdma) { 2808 android.hardware.radio.V1_2.CellIdentityTdscdma ci = 2809 (android.hardware.radio.V1_2.CellIdentityTdscdma) tdscdma; 2810 return new CellIdentityTdscdma(ci.base.mcc, ci.base.mnc, ci.base.lac, ci.base.cid, 2811 ci.base.cpid, ci.uarfcn, ci.operatorNames.alphaLong, 2812 ci.operatorNames.alphaShort, Collections.emptyList(), null); 2813 } else if (tdscdma instanceof android.hardware.radio.V1_5.CellIdentityTdscdma) { 2814 android.hardware.radio.V1_5.CellIdentityTdscdma ci = 2815 (android.hardware.radio.V1_5.CellIdentityTdscdma) tdscdma; 2816 return new CellIdentityTdscdma(ci.base.base.mcc, ci.base.base.mnc, ci.base.base.lac, 2817 ci.base.base.cid, ci.base.base.cpid, ci.base.uarfcn, 2818 ci.base.operatorNames.alphaLong, ci.base.operatorNames.alphaShort, 2819 ci.additionalPlmns, convertHalClosedSubscriberGroupInfo(ci.optionalCsgInfo)); 2820 } else { 2821 return null; 2822 } 2823 } 2824 2825 /** 2826 * Convert a CellIdentityTdscdma defined in CellIdentityTdscdma.aidl to CellIdentityTdscdma 2827 * @param cid CellIdentityTdscdma defined in radio/1.2, 1.5/types.hal 2828 * @return The converted CellIdentityTdscdma 2829 */ convertHalCellIdentityTdscdma( android.hardware.radio.network.CellIdentityTdscdma cid)2830 public static CellIdentityTdscdma convertHalCellIdentityTdscdma( 2831 android.hardware.radio.network.CellIdentityTdscdma cid) { 2832 return new CellIdentityTdscdma(cid.mcc, cid.mnc, cid.lac, cid.cid, cid.cpid, cid.uarfcn, 2833 cid.operatorNames.alphaLong, cid.operatorNames.alphaShort, 2834 primitiveArrayToArrayList(cid.additionalPlmns), 2835 convertHalClosedSubscriberGroupInfo(cid.csgInfo)); 2836 } 2837 2838 /** 2839 * Convert a CellIdentityNr defined in radio/1.4, 1.5/types.hal to CellIdentityNr 2840 * @param nr CellIdentityNr defined in radio/1.4 1.5/types.hal 2841 * @return The converted CellIdentityNr 2842 */ convertHalCellIdentityNr(Object nr)2843 public static CellIdentityNr convertHalCellIdentityNr(Object nr) { 2844 if (nr == null) return null; 2845 if (nr instanceof android.hardware.radio.V1_4.CellIdentityNr) { 2846 android.hardware.radio.V1_4.CellIdentityNr ci = 2847 (android.hardware.radio.V1_4.CellIdentityNr) nr; 2848 return new CellIdentityNr(ci.pci, ci.tac, ci.nrarfcn, new int[] {}, ci.mcc, ci.mnc, 2849 ci.nci, ci.operatorNames.alphaLong, ci.operatorNames.alphaShort, 2850 new ArraySet<>()); 2851 } else if (nr instanceof android.hardware.radio.V1_5.CellIdentityNr) { 2852 android.hardware.radio.V1_5.CellIdentityNr ci = 2853 (android.hardware.radio.V1_5.CellIdentityNr) nr; 2854 return new CellIdentityNr(ci.base.pci, ci.base.tac, ci.base.nrarfcn, 2855 ci.bands.stream().mapToInt(Integer::intValue).toArray(), ci.base.mcc, 2856 ci.base.mnc, ci.base.nci, ci.base.operatorNames.alphaLong, 2857 ci.base.operatorNames.alphaShort, ci.additionalPlmns); 2858 } else { 2859 return null; 2860 } 2861 } 2862 2863 /** 2864 * Convert a CellIdentityNr defined in CellIdentityNr.aidl to CellIdentityNr 2865 * @param cid CellIdentityNr defined in CellIdentityNr.aidl 2866 * @return The converted CellIdentityNr 2867 */ convertHalCellIdentityNr( android.hardware.radio.network.CellIdentityNr cid)2868 public static CellIdentityNr convertHalCellIdentityNr( 2869 android.hardware.radio.network.CellIdentityNr cid) { 2870 return new CellIdentityNr(cid.pci, cid.tac, cid.nrarfcn, cid.bands, cid.mcc, cid.mnc, 2871 cid.nci, cid.operatorNames.alphaLong, cid.operatorNames.alphaShort, 2872 primitiveArrayToArrayList(cid.additionalPlmns)); 2873 } 2874 2875 /** 2876 * Convert a SignalStrength defined in radio/1.4, 1.6/types.hal to SignalStrength 2877 * @param ss SignalStrength defined in radio/1.4, 1.6/types.hal 2878 * @return The converted SignalStrength 2879 */ convertHalSignalStrength(Object ss)2880 public static SignalStrength convertHalSignalStrength(Object ss) { 2881 if (ss == null) return null; 2882 if (ss instanceof android.hardware.radio.V1_4.SignalStrength) { 2883 android.hardware.radio.V1_4.SignalStrength signalStrength = 2884 (android.hardware.radio.V1_4.SignalStrength) ss; 2885 return new SignalStrength( 2886 convertHalCdmaSignalStrength(signalStrength.cdma, signalStrength.evdo), 2887 convertHalGsmSignalStrength(signalStrength.gsm), 2888 convertHalWcdmaSignalStrength(signalStrength.wcdma), 2889 convertHalTdscdmaSignalStrength(signalStrength.tdscdma), 2890 convertHalLteSignalStrength(signalStrength.lte), 2891 convertHalNrSignalStrength(signalStrength.nr)); 2892 } else if (ss instanceof android.hardware.radio.V1_6.SignalStrength) { 2893 android.hardware.radio.V1_6.SignalStrength signalStrength = 2894 (android.hardware.radio.V1_6.SignalStrength) ss; 2895 return new SignalStrength( 2896 convertHalCdmaSignalStrength(signalStrength.cdma, signalStrength.evdo), 2897 convertHalGsmSignalStrength(signalStrength.gsm), 2898 convertHalWcdmaSignalStrength(signalStrength.wcdma), 2899 convertHalTdscdmaSignalStrength(signalStrength.tdscdma), 2900 convertHalLteSignalStrength(signalStrength.lte), 2901 convertHalNrSignalStrength(signalStrength.nr)); 2902 } 2903 return null; 2904 } 2905 2906 /** 2907 * Convert a SignalStrength defined in SignalStrength.aidl to SignalStrength 2908 * @param signalStrength SignalStrength defined in SignalStrength.aidl 2909 * @return The converted SignalStrength 2910 */ convertHalSignalStrength( android.hardware.radio.network.SignalStrength signalStrength)2911 public static SignalStrength convertHalSignalStrength( 2912 android.hardware.radio.network.SignalStrength signalStrength) { 2913 return new SignalStrength( 2914 convertHalCdmaSignalStrength(signalStrength.cdma, signalStrength.evdo), 2915 convertHalGsmSignalStrength(signalStrength.gsm), 2916 convertHalWcdmaSignalStrength(signalStrength.wcdma), 2917 convertHalTdscdmaSignalStrength(signalStrength.tdscdma), 2918 convertHalLteSignalStrength(signalStrength.lte), 2919 convertHalNrSignalStrength(signalStrength.nr)); 2920 } 2921 2922 /** 2923 * Convert a GsmSignalStrength defined in radio/1.0/types.hal to CellSignalStrengthGsm 2924 * @param ss GsmSignalStrength defined in radio/1.0/types.hal 2925 * @return The converted CellSignalStrengthGsm 2926 */ convertHalGsmSignalStrength( android.hardware.radio.V1_0.GsmSignalStrength ss)2927 public static CellSignalStrengthGsm convertHalGsmSignalStrength( 2928 android.hardware.radio.V1_0.GsmSignalStrength ss) { 2929 if (ss == null) return new CellSignalStrengthGsm(); 2930 CellSignalStrengthGsm ret = new CellSignalStrengthGsm( 2931 CellSignalStrength.getRssiDbmFromAsu(ss.signalStrength), ss.bitErrorRate, 2932 ss.timingAdvance); 2933 if (ret.getRssi() == CellInfo.UNAVAILABLE) { 2934 ret.setDefaultValues(); 2935 ret.updateLevel(null, null); 2936 } 2937 return ret; 2938 } 2939 2940 /** 2941 * Convert a GsmSignalStrength defined in GsmSignalStrength.aidl to CellSignalStrengthGsm 2942 * @param ss GsmSignalStrength defined in GsmSignalStrength.aidl 2943 * @return The converted CellSignalStrengthGsm 2944 */ convertHalGsmSignalStrength( android.hardware.radio.network.GsmSignalStrength ss)2945 public static CellSignalStrengthGsm convertHalGsmSignalStrength( 2946 android.hardware.radio.network.GsmSignalStrength ss) { 2947 if (ss == null) return new CellSignalStrengthGsm(); 2948 CellSignalStrengthGsm ret = new CellSignalStrengthGsm( 2949 CellSignalStrength.getRssiDbmFromAsu(ss.signalStrength), ss.bitErrorRate, 2950 ss.timingAdvance); 2951 if (ret.getRssi() == CellInfo.UNAVAILABLE) { 2952 ret.setDefaultValues(); 2953 ret.updateLevel(null, null); 2954 } 2955 return ret; 2956 } 2957 2958 /** 2959 * Convert a CdmaSignalStrength and EvdoSignalStrength defined in radio/1.0/types.hal to 2960 * CellSignalStrengthCdma 2961 * @param cdma CdmaSignalStrength defined in radio/1.0/types.hal 2962 * @param evdo EvdoSignalStrength defined in radio/1.0/types.hal 2963 * @return The converted CellSignalStrengthCdma 2964 */ convertHalCdmaSignalStrength( android.hardware.radio.V1_0.CdmaSignalStrength cdma, android.hardware.radio.V1_0.EvdoSignalStrength evdo)2965 public static CellSignalStrengthCdma convertHalCdmaSignalStrength( 2966 android.hardware.radio.V1_0.CdmaSignalStrength cdma, 2967 android.hardware.radio.V1_0.EvdoSignalStrength evdo) { 2968 if (cdma == null || evdo == null) return new CellSignalStrengthCdma(); 2969 return new CellSignalStrengthCdma(-cdma.dbm, -cdma.ecio, -evdo.dbm, -evdo.ecio, 2970 evdo.signalNoiseRatio); 2971 } 2972 2973 /** 2974 * Convert a CdmaSignalStrength and EvdoSignalStrength defined in radio/network to 2975 * CellSignalStrengthCdma 2976 * @param cdma CdmaSignalStrength defined in CdmaSignalStrength.aidl 2977 * @param evdo EvdoSignalStrength defined in EvdoSignalStrength.aidl 2978 * @return The converted CellSignalStrengthCdma 2979 */ convertHalCdmaSignalStrength( android.hardware.radio.network.CdmaSignalStrength cdma, android.hardware.radio.network.EvdoSignalStrength evdo)2980 public static CellSignalStrengthCdma convertHalCdmaSignalStrength( 2981 android.hardware.radio.network.CdmaSignalStrength cdma, 2982 android.hardware.radio.network.EvdoSignalStrength evdo) { 2983 if (cdma == null || evdo == null) return new CellSignalStrengthCdma(); 2984 return new CellSignalStrengthCdma(-cdma.dbm, -cdma.ecio, -evdo.dbm, -evdo.ecio, 2985 evdo.signalNoiseRatio); 2986 } 2987 2988 /** 2989 * Convert a LteSignalStrength defined in radio/1.0, 1.6/types.hal to CellSignalStrengthLte 2990 * @param lte LteSignalStrength defined in radio/1.0, 1.6/types.hal 2991 * @return The converted CellSignalStrengthLte 2992 */ convertHalLteSignalStrength(Object lte)2993 public static CellSignalStrengthLte convertHalLteSignalStrength(Object lte) { 2994 if (lte == null) return null; 2995 if (lte instanceof android.hardware.radio.V1_0.LteSignalStrength) { 2996 android.hardware.radio.V1_0.LteSignalStrength ss = 2997 (android.hardware.radio.V1_0.LteSignalStrength) lte; 2998 return new CellSignalStrengthLte( 2999 CellSignalStrengthLte.convertRssiAsuToDBm(ss.signalStrength), 3000 ss.rsrp != CellInfo.UNAVAILABLE ? -ss.rsrp : ss.rsrp, 3001 ss.rsrq != CellInfo.UNAVAILABLE ? -ss.rsrq : ss.rsrq, 3002 CellSignalStrengthLte.convertRssnrUnitFromTenDbToDB(ss.rssnr), ss.cqi, 3003 ss.timingAdvance); 3004 } else if (lte instanceof android.hardware.radio.V1_6.LteSignalStrength) { 3005 android.hardware.radio.V1_6.LteSignalStrength ss = 3006 (android.hardware.radio.V1_6.LteSignalStrength) lte; 3007 return new CellSignalStrengthLte( 3008 CellSignalStrengthLte.convertRssiAsuToDBm(ss.base.signalStrength), 3009 ss.base.rsrp != CellInfo.UNAVAILABLE ? -ss.base.rsrp : ss.base.rsrp, 3010 ss.base.rsrq != CellInfo.UNAVAILABLE ? -ss.base.rsrq : ss.base.rsrq, 3011 CellSignalStrengthLte.convertRssnrUnitFromTenDbToDB(ss.base.rssnr), 3012 ss.cqiTableIndex, ss.base.cqi, ss.base.timingAdvance); 3013 } else { 3014 return null; 3015 } 3016 } 3017 3018 /** 3019 * Convert a LteSignalStrength defined in LteSignalStrength.aidl to CellSignalStrengthLte 3020 * @param ss LteSignalStrength defined in LteSignalStrength.aidl 3021 * @return The converted CellSignalStrengthLte 3022 */ convertHalLteSignalStrength( android.hardware.radio.network.LteSignalStrength ss)3023 public static CellSignalStrengthLte convertHalLteSignalStrength( 3024 android.hardware.radio.network.LteSignalStrength ss) { 3025 return new CellSignalStrengthLte( 3026 CellSignalStrengthLte.convertRssiAsuToDBm(ss.signalStrength), 3027 ss.rsrp != CellInfo.UNAVAILABLE ? -ss.rsrp : ss.rsrp, 3028 ss.rsrq != CellInfo.UNAVAILABLE ? -ss.rsrq : ss.rsrq, 3029 CellSignalStrengthLte.convertRssnrUnitFromTenDbToDB(ss.rssnr), ss.cqiTableIndex, 3030 ss.cqi, ss.timingAdvance); 3031 } 3032 3033 /** 3034 * Convert a WcdmaSignalStrength defined in radio/1.2/types.hal to CellSignalStrengthWcdma 3035 * @param wcdma WcdmaSignalStrength defined in radio/1.2/types.hal 3036 * @return The converted CellSignalStrengthWcdma 3037 */ convertHalWcdmaSignalStrength(Object wcdma)3038 public static CellSignalStrengthWcdma convertHalWcdmaSignalStrength(Object wcdma) { 3039 if (wcdma == null) return null; 3040 android.hardware.radio.V1_2.WcdmaSignalStrength ss = 3041 (android.hardware.radio.V1_2.WcdmaSignalStrength) wcdma; 3042 CellSignalStrengthWcdma ret = new CellSignalStrengthWcdma( 3043 CellSignalStrength.getRssiDbmFromAsu(ss.base.signalStrength), 3044 ss.base.bitErrorRate, CellSignalStrength.getRscpDbmFromAsu(ss.rscp), 3045 CellSignalStrength.getEcNoDbFromAsu(ss.ecno)); 3046 if (ret.getRssi() == CellInfo.UNAVAILABLE && ret.getRscp() == CellInfo.UNAVAILABLE) { 3047 ret.setDefaultValues(); 3048 ret.updateLevel(null, null); 3049 } 3050 return ret; 3051 } 3052 3053 /** 3054 * Convert a WcdmaSignalStrength defined in WcdmaSignalStrength.aidl to CellSignalStrengthWcdma 3055 * @param ss WcdmaSignalStrength defined in WcdmaSignalStrength.aidl 3056 * @return The converted CellSignalStrengthWcdma 3057 */ convertHalWcdmaSignalStrength( android.hardware.radio.network.WcdmaSignalStrength ss)3058 public static CellSignalStrengthWcdma convertHalWcdmaSignalStrength( 3059 android.hardware.radio.network.WcdmaSignalStrength ss) { 3060 CellSignalStrengthWcdma ret = new CellSignalStrengthWcdma( 3061 CellSignalStrength.getRssiDbmFromAsu(ss.signalStrength), 3062 ss.bitErrorRate, CellSignalStrength.getRscpDbmFromAsu(ss.rscp), 3063 CellSignalStrength.getEcNoDbFromAsu(ss.ecno)); 3064 if (ret.getRssi() == CellInfo.UNAVAILABLE && ret.getRscp() == CellInfo.UNAVAILABLE) { 3065 ret.setDefaultValues(); 3066 ret.updateLevel(null, null); 3067 } 3068 return ret; 3069 } 3070 3071 /** 3072 * Convert a TdscdmaSignalStrength defined in radio/1.2/types.hal to CellSignalStrengthTdscdma 3073 * @param tdscdma TdscdmaSignalStrength defined in radio/1.2/types.hal 3074 * @return The converted CellSignalStrengthTdscdma 3075 */ convertHalTdscdmaSignalStrength(Object tdscdma)3076 public static CellSignalStrengthTdscdma convertHalTdscdmaSignalStrength(Object tdscdma) { 3077 if (tdscdma == null) return null; 3078 android.hardware.radio.V1_2.TdscdmaSignalStrength ss = 3079 (android.hardware.radio.V1_2.TdscdmaSignalStrength) tdscdma; 3080 CellSignalStrengthTdscdma ret = new CellSignalStrengthTdscdma( 3081 CellSignalStrength.getRssiDbmFromAsu(ss.signalStrength), ss.bitErrorRate, 3082 CellSignalStrength.getRscpDbmFromAsu(ss.rscp)); 3083 if (ret.getRssi() == CellInfo.UNAVAILABLE && ret.getRscp() == CellInfo.UNAVAILABLE) { 3084 ret.setDefaultValues(); 3085 ret.updateLevel(null, null); 3086 } 3087 return ret; 3088 } 3089 3090 /** 3091 * Convert a TdscdmaSignalStrength defined in TdscdmaSignalStrength.aidl to 3092 * CellSignalStrengthTdscdma 3093 * @param ss TdscdmaSignalStrength defined in TdscdmaSignalStrength.aidl 3094 * @return The converted CellSignalStrengthTdscdma 3095 */ convertHalTdscdmaSignalStrength( android.hardware.radio.network.TdscdmaSignalStrength ss)3096 public static CellSignalStrengthTdscdma convertHalTdscdmaSignalStrength( 3097 android.hardware.radio.network.TdscdmaSignalStrength ss) { 3098 CellSignalStrengthTdscdma ret = new CellSignalStrengthTdscdma( 3099 CellSignalStrength.getRssiDbmFromAsu(ss.signalStrength), 3100 ss.bitErrorRate, CellSignalStrength.getRscpDbmFromAsu(ss.rscp)); 3101 if (ret.getRssi() == CellInfo.UNAVAILABLE && ret.getRscp() == CellInfo.UNAVAILABLE) { 3102 ret.setDefaultValues(); 3103 ret.updateLevel(null, null); 3104 } 3105 return ret; 3106 } 3107 3108 /** 3109 * Convert a NrSignalStrength defined in radio/1.4, 1.6/types.hal to CellSignalStrengthNr 3110 * @param nr NrSignalStrength defined in radio/1.4, 1.6/types.hal 3111 * @return The converted CellSignalStrengthNr 3112 */ convertHalNrSignalStrength(Object nr)3113 public static CellSignalStrengthNr convertHalNrSignalStrength(Object nr) { 3114 if (nr == null) return null; 3115 if (nr instanceof android.hardware.radio.V1_4.NrSignalStrength) { 3116 android.hardware.radio.V1_4.NrSignalStrength ss = 3117 (android.hardware.radio.V1_4.NrSignalStrength) nr; 3118 return new CellSignalStrengthNr(CellSignalStrengthNr.flip(ss.csiRsrp), 3119 CellSignalStrengthNr.flip(ss.csiRsrq), ss.csiSinr, 3120 CellSignalStrengthNr.flip(ss.ssRsrp), CellSignalStrengthNr.flip(ss.ssRsrq), 3121 ss.ssSinr); 3122 } else if (nr instanceof android.hardware.radio.V1_6.NrSignalStrength) { 3123 android.hardware.radio.V1_6.NrSignalStrength ss = 3124 (android.hardware.radio.V1_6.NrSignalStrength) nr; 3125 return new CellSignalStrengthNr(CellSignalStrengthNr.flip(ss.base.csiRsrp), 3126 CellSignalStrengthNr.flip(ss.base.csiRsrq), ss.base.csiSinr, 3127 ss.csiCqiTableIndex, ss.csiCqiReport, CellSignalStrengthNr.flip(ss.base.ssRsrp), 3128 CellSignalStrengthNr.flip(ss.base.ssRsrq), ss.base.ssSinr, 3129 CellInfo.UNAVAILABLE); 3130 } 3131 return null; 3132 } 3133 3134 /** 3135 * Convert a NrSignalStrength defined in NrSignalStrength.aidl to CellSignalStrengthNr 3136 * @param ss NrSignalStrength defined in NrSignalStrength.aidl 3137 * @return The converted CellSignalStrengthNr 3138 */ convertHalNrSignalStrength( android.hardware.radio.network.NrSignalStrength ss)3139 public static CellSignalStrengthNr convertHalNrSignalStrength( 3140 android.hardware.radio.network.NrSignalStrength ss) { 3141 return new CellSignalStrengthNr(CellSignalStrengthNr.flip(ss.csiRsrp), 3142 CellSignalStrengthNr.flip(ss.csiRsrq), ss.csiSinr, ss.csiCqiTableIndex, 3143 primitiveArrayToArrayList(ss.csiCqiReport), CellSignalStrengthNr.flip(ss.ssRsrp), 3144 CellSignalStrengthNr.flip(ss.ssRsrq), ss.ssSinr, ss.timingAdvance); 3145 } 3146 convertHalClosedSubscriberGroupInfo( android.hardware.radio.V1_5.OptionalCsgInfo optionalCsgInfo)3147 private static ClosedSubscriberGroupInfo convertHalClosedSubscriberGroupInfo( 3148 android.hardware.radio.V1_5.OptionalCsgInfo optionalCsgInfo) { 3149 android.hardware.radio.V1_5.ClosedSubscriberGroupInfo csgInfo = 3150 optionalCsgInfo.getDiscriminator() 3151 == android.hardware.radio.V1_5.OptionalCsgInfo.hidl_discriminator.csgInfo 3152 ? optionalCsgInfo.csgInfo() : null; 3153 if (csgInfo == null) return null; 3154 return new ClosedSubscriberGroupInfo(csgInfo.csgIndication, csgInfo.homeNodebName, 3155 csgInfo.csgIdentity); 3156 } 3157 convertHalClosedSubscriberGroupInfo( android.hardware.radio.network.ClosedSubscriberGroupInfo csgInfo)3158 private static ClosedSubscriberGroupInfo convertHalClosedSubscriberGroupInfo( 3159 android.hardware.radio.network.ClosedSubscriberGroupInfo csgInfo) { 3160 if (csgInfo == null) return null; 3161 return new ClosedSubscriberGroupInfo(csgInfo.csgIndication, csgInfo.homeNodebName, 3162 csgInfo.csgIdentity); 3163 } 3164 3165 /** 3166 * Convert a list of BarringInfo defined in radio/1.5/types.hal to a sparse array of 3167 * BarringServiceInfos 3168 * @param halBarringInfos List of BarringInfos defined in radio/1.5/types.hal 3169 * @return The converted sparse array of BarringServiceInfos 3170 */ convertHalBarringInfoList( List<android.hardware.radio.V1_5.BarringInfo> halBarringInfos)3171 public static SparseArray<BarringInfo.BarringServiceInfo> convertHalBarringInfoList( 3172 List<android.hardware.radio.V1_5.BarringInfo> halBarringInfos) { 3173 SparseArray<BarringInfo.BarringServiceInfo> serviceInfos = new SparseArray<>(); 3174 for (android.hardware.radio.V1_5.BarringInfo halBarringInfo : halBarringInfos) { 3175 if (halBarringInfo.barringType 3176 == android.hardware.radio.V1_5.BarringInfo.BarringType.CONDITIONAL) { 3177 if (halBarringInfo.barringTypeSpecificInfo.getDiscriminator() 3178 != android.hardware.radio.V1_5.BarringInfo.BarringTypeSpecificInfo 3179 .hidl_discriminator.conditional) { 3180 // this is an error case where the barring info is conditional but the 3181 // conditional barring fields weren't included 3182 continue; 3183 } 3184 android.hardware.radio.V1_5.BarringInfo.BarringTypeSpecificInfo 3185 .Conditional conditionalInfo = 3186 halBarringInfo.barringTypeSpecificInfo.conditional(); 3187 serviceInfos.put( 3188 halBarringInfo.serviceType, new BarringInfo.BarringServiceInfo( 3189 halBarringInfo.barringType, // will always be CONDITIONAL here 3190 conditionalInfo.isBarred, 3191 conditionalInfo.factor, 3192 conditionalInfo.timeSeconds)); 3193 } else { 3194 // Barring type is either NONE or UNCONDITIONAL 3195 serviceInfos.put( 3196 halBarringInfo.serviceType, new BarringInfo.BarringServiceInfo( 3197 halBarringInfo.barringType, false, 0, 0)); 3198 } 3199 } 3200 return serviceInfos; 3201 } 3202 3203 /** 3204 * Convert a list of BarringInfo defined in BarringInfo.aidl to a sparse array of 3205 * BarringServiceInfos 3206 * @param halBarringInfos List of BarringInfos defined in BarringInfo.aidl 3207 * @return The converted sparse array of BarringServiceInfos 3208 */ convertHalBarringInfoList( android.hardware.radio.network.BarringInfo[] halBarringInfos)3209 public static SparseArray<BarringInfo.BarringServiceInfo> convertHalBarringInfoList( 3210 android.hardware.radio.network.BarringInfo[] halBarringInfos) { 3211 SparseArray<BarringInfo.BarringServiceInfo> serviceInfos = new SparseArray<>(); 3212 for (android.hardware.radio.network.BarringInfo halBarringInfo : halBarringInfos) { 3213 if (halBarringInfo.barringType 3214 == android.hardware.radio.network.BarringInfo.BARRING_TYPE_CONDITIONAL) { 3215 if (halBarringInfo.barringTypeSpecificInfo == null) { 3216 // this is an error case where the barring info is conditional but the 3217 // conditional barring fields weren't included 3218 continue; 3219 } 3220 serviceInfos.put( 3221 halBarringInfo.serviceType, new BarringInfo.BarringServiceInfo( 3222 halBarringInfo.barringType, // will always be CONDITIONAL here 3223 halBarringInfo.barringTypeSpecificInfo.isBarred, 3224 halBarringInfo.barringTypeSpecificInfo.factor, 3225 halBarringInfo.barringTypeSpecificInfo.timeSeconds)); 3226 } else { 3227 // Barring type is either NONE or UNCONDITIONAL 3228 serviceInfos.put(halBarringInfo.serviceType, new BarringInfo.BarringServiceInfo( 3229 halBarringInfo.barringType, false, 0, 0)); 3230 } 3231 } 3232 return serviceInfos; 3233 } 3234 convertToLinkAddress(String addressString)3235 private static LinkAddress convertToLinkAddress(String addressString) { 3236 return convertToLinkAddress(addressString, 0, LinkAddress.LIFETIME_UNKNOWN, 3237 LinkAddress.LIFETIME_UNKNOWN); 3238 } 3239 convertToLinkAddress(String addressString, int properties, long deprecationTime, long expirationTime)3240 private static LinkAddress convertToLinkAddress(String addressString, int properties, 3241 long deprecationTime, long expirationTime) { 3242 addressString = addressString.trim(); 3243 InetAddress address = null; 3244 int prefixLength = -1; 3245 try { 3246 String[] pieces = addressString.split("/", 2); 3247 address = InetAddresses.parseNumericAddress(pieces[0]); 3248 if (pieces.length == 1) { 3249 prefixLength = (address instanceof Inet4Address) ? 32 : 128; 3250 } else if (pieces.length == 2) { 3251 prefixLength = Integer.parseInt(pieces[1]); 3252 } 3253 } catch (NullPointerException e) { // Null string. 3254 } catch (ArrayIndexOutOfBoundsException e) { // No prefix length. 3255 } catch (NumberFormatException e) { // Non-numeric prefix. 3256 } catch (IllegalArgumentException e) { // Invalid IP address. 3257 } 3258 3259 if (address == null || prefixLength == -1) { 3260 throw new IllegalArgumentException("Invalid link address " + addressString); 3261 } 3262 3263 return new LinkAddress(address, prefixLength, properties, 0, deprecationTime, 3264 expirationTime); 3265 } 3266 3267 /** 3268 * Convert SetupDataCallResult defined in radio/1.4, 1.5, 1.6/types.hal into 3269 * DataCallResponse 3270 * @param dcResult SetupDataCallResult defined in radio/1.4, 1.5, 1.6/types.hal 3271 * @return The converted DataCallResponse 3272 */ 3273 @VisibleForTesting convertHalDataCallResult(Object dcResult)3274 public static DataCallResponse convertHalDataCallResult(Object dcResult) { 3275 if (dcResult == null) return null; 3276 3277 int cause, cid, active, mtu, mtuV4, mtuV6; 3278 long suggestedRetryTime; 3279 String ifname; 3280 int protocolType; 3281 String[] addresses; 3282 String[] dnses; 3283 String[] gateways; 3284 String[] pcscfs; 3285 Qos defaultQos = null; 3286 @DataCallResponse.HandoverFailureMode 3287 int handoverFailureMode = DataCallResponse.HANDOVER_FAILURE_MODE_LEGACY; 3288 int pduSessionId = DataCallResponse.PDU_SESSION_ID_NOT_SET; 3289 List<LinkAddress> laList = new ArrayList<>(); 3290 List<QosBearerSession> qosSessions = new ArrayList<>(); 3291 NetworkSliceInfo sliceInfo = null; 3292 List<TrafficDescriptor> trafficDescriptors = new ArrayList<>(); 3293 3294 if (dcResult instanceof android.hardware.radio.V1_4.SetupDataCallResult) { 3295 final android.hardware.radio.V1_4.SetupDataCallResult result = 3296 (android.hardware.radio.V1_4.SetupDataCallResult) dcResult; 3297 cause = result.cause; 3298 suggestedRetryTime = result.suggestedRetryTime; 3299 cid = result.cid; 3300 active = result.active; 3301 protocolType = result.type; 3302 ifname = result.ifname; 3303 addresses = result.addresses.toArray(new String[0]); 3304 dnses = result.dnses.toArray(new String[0]); 3305 gateways = result.gateways.toArray(new String[0]); 3306 pcscfs = result.pcscf.toArray(new String[0]); 3307 mtu = mtuV4 = mtuV6 = result.mtu; 3308 if (addresses != null) { 3309 for (String address : addresses) { 3310 laList.add(convertToLinkAddress(address)); 3311 } 3312 } 3313 } else if (dcResult instanceof android.hardware.radio.V1_5.SetupDataCallResult) { 3314 final android.hardware.radio.V1_5.SetupDataCallResult result = 3315 (android.hardware.radio.V1_5.SetupDataCallResult) dcResult; 3316 cause = result.cause; 3317 suggestedRetryTime = result.suggestedRetryTime; 3318 cid = result.cid; 3319 active = result.active; 3320 protocolType = result.type; 3321 ifname = result.ifname; 3322 laList = result.addresses.stream().map(la -> convertToLinkAddress( 3323 la.address, la.properties, la.deprecationTime, la.expirationTime)) 3324 .collect(Collectors.toList()); 3325 dnses = result.dnses.toArray(new String[0]); 3326 gateways = result.gateways.toArray(new String[0]); 3327 pcscfs = result.pcscf.toArray(new String[0]); 3328 mtu = Math.max(result.mtuV4, result.mtuV6); 3329 mtuV4 = result.mtuV4; 3330 mtuV6 = result.mtuV6; 3331 } else if (dcResult instanceof android.hardware.radio.V1_6.SetupDataCallResult) { 3332 final android.hardware.radio.V1_6.SetupDataCallResult result = 3333 (android.hardware.radio.V1_6.SetupDataCallResult) dcResult; 3334 cause = result.cause; 3335 suggestedRetryTime = result.suggestedRetryTime; 3336 cid = result.cid; 3337 active = result.active; 3338 protocolType = result.type; 3339 ifname = result.ifname; 3340 laList = result.addresses.stream().map(la -> convertToLinkAddress( 3341 la.address, la.properties, la.deprecationTime, la.expirationTime)) 3342 .collect(Collectors.toList()); 3343 dnses = result.dnses.toArray(new String[0]); 3344 gateways = result.gateways.toArray(new String[0]); 3345 pcscfs = result.pcscf.toArray(new String[0]); 3346 mtu = Math.max(result.mtuV4, result.mtuV6); 3347 mtuV4 = result.mtuV4; 3348 mtuV6 = result.mtuV6; 3349 handoverFailureMode = result.handoverFailureMode; 3350 pduSessionId = result.pduSessionId; 3351 defaultQos = convertHalQos(result.defaultQos); 3352 qosSessions = result.qosSessions.stream().map(RILUtils::convertHalQosBearerSession) 3353 .collect(Collectors.toList()); 3354 sliceInfo = result.sliceInfo.getDiscriminator() 3355 == android.hardware.radio.V1_6.OptionalSliceInfo.hidl_discriminator.noinit 3356 ? null : convertHalSliceInfo(result.sliceInfo.value()); 3357 for (android.hardware.radio.V1_6.TrafficDescriptor td : result.trafficDescriptors) { 3358 try { 3359 trafficDescriptors.add(RILUtils.convertHalTrafficDescriptor(td)); 3360 } catch (IllegalArgumentException e) { 3361 loge("convertHalDataCallResult: Failed to convert traffic descriptor. e=" + e); 3362 } 3363 } 3364 } else { 3365 loge("Unsupported SetupDataCallResult " + dcResult); 3366 return null; 3367 } 3368 3369 // Process dns 3370 List<InetAddress> dnsList = new ArrayList<>(); 3371 if (dnses != null) { 3372 for (String dns : dnses) { 3373 dns = dns.trim(); 3374 InetAddress ia; 3375 try { 3376 ia = InetAddresses.parseNumericAddress(dns); 3377 dnsList.add(ia); 3378 } catch (IllegalArgumentException e) { 3379 Rlog.e(TAG, "Unknown dns: " + dns, e); 3380 } 3381 } 3382 } 3383 3384 // Process gateway 3385 List<InetAddress> gatewayList = new ArrayList<>(); 3386 if (gateways != null) { 3387 for (String gateway : gateways) { 3388 gateway = gateway.trim(); 3389 InetAddress ia; 3390 try { 3391 ia = InetAddresses.parseNumericAddress(gateway); 3392 gatewayList.add(ia); 3393 } catch (IllegalArgumentException e) { 3394 Rlog.e(TAG, "Unknown gateway: " + gateway, e); 3395 } 3396 } 3397 } 3398 3399 // Process gateway 3400 List<InetAddress> pcscfList = new ArrayList<>(); 3401 if (pcscfs != null) { 3402 for (String pcscf : pcscfs) { 3403 pcscf = pcscf.trim(); 3404 InetAddress ia; 3405 try { 3406 ia = InetAddresses.parseNumericAddress(pcscf); 3407 pcscfList.add(ia); 3408 } catch (IllegalArgumentException e) { 3409 Rlog.e(TAG, "Unknown pcscf: " + pcscf, e); 3410 } 3411 } 3412 } 3413 3414 return new DataCallResponse.Builder() 3415 .setCause(cause) 3416 .setRetryDurationMillis(suggestedRetryTime) 3417 .setId(cid) 3418 .setLinkStatus(active) 3419 .setProtocolType(protocolType) 3420 .setInterfaceName(ifname) 3421 .setAddresses(laList) 3422 .setDnsAddresses(dnsList) 3423 .setGatewayAddresses(gatewayList) 3424 .setPcscfAddresses(pcscfList) 3425 .setMtu(mtu) 3426 .setMtuV4(mtuV4) 3427 .setMtuV6(mtuV6) 3428 .setHandoverFailureMode(handoverFailureMode) 3429 .setPduSessionId(pduSessionId) 3430 .setDefaultQos(defaultQos) 3431 .setQosBearerSessions(qosSessions) 3432 .setSliceInfo(sliceInfo) 3433 .setTrafficDescriptors(trafficDescriptors) 3434 .build(); 3435 } 3436 3437 /** 3438 * Convert SetupDataCallResult defined in SetupDataCallResult.aidl into DataCallResponse 3439 * @param result SetupDataCallResult defined in SetupDataCallResult.aidl 3440 * @return The converted DataCallResponse 3441 */ 3442 @VisibleForTesting convertHalDataCallResult( android.hardware.radio.data.SetupDataCallResult result)3443 public static DataCallResponse convertHalDataCallResult( 3444 android.hardware.radio.data.SetupDataCallResult result) { 3445 if (result == null) return null; 3446 List<LinkAddress> laList = new ArrayList<>(); 3447 if (result.addresses != null) { 3448 for (android.hardware.radio.data.LinkAddress la : result.addresses) { 3449 laList.add(convertToLinkAddress(la.address, la.addressProperties, 3450 la.deprecationTime, la.expirationTime)); 3451 } 3452 } 3453 List<InetAddress> dnsList = new ArrayList<>(); 3454 if (result.dnses != null) { 3455 for (String dns : result.dnses) { 3456 dns = dns.trim(); 3457 InetAddress ia; 3458 try { 3459 ia = InetAddresses.parseNumericAddress(dns); 3460 dnsList.add(ia); 3461 } catch (IllegalArgumentException e) { 3462 Rlog.e(TAG, "Unknown dns: " + dns, e); 3463 } 3464 } 3465 } 3466 List<InetAddress> gatewayList = new ArrayList<>(); 3467 if (result.gateways != null) { 3468 for (String gateway : result.gateways) { 3469 gateway = gateway.trim(); 3470 InetAddress ia; 3471 try { 3472 ia = InetAddresses.parseNumericAddress(gateway); 3473 gatewayList.add(ia); 3474 } catch (IllegalArgumentException e) { 3475 Rlog.e(TAG, "Unknown gateway: " + gateway, e); 3476 } 3477 } 3478 } 3479 List<InetAddress> pcscfList = new ArrayList<>(); 3480 if (result.pcscf != null) { 3481 for (String pcscf : result.pcscf) { 3482 pcscf = pcscf.trim(); 3483 InetAddress ia; 3484 try { 3485 ia = InetAddresses.parseNumericAddress(pcscf); 3486 pcscfList.add(ia); 3487 } catch (IllegalArgumentException e) { 3488 Rlog.e(TAG, "Unknown pcscf: " + pcscf, e); 3489 } 3490 } 3491 } 3492 List<QosBearerSession> qosSessions = new ArrayList<>(); 3493 if (result.qosSessions != null) { 3494 for (android.hardware.radio.data.QosSession session : result.qosSessions) { 3495 qosSessions.add(convertHalQosBearerSession(session)); 3496 } 3497 } 3498 List<TrafficDescriptor> trafficDescriptors = new ArrayList<>(); 3499 if (result.trafficDescriptors != null) { 3500 for (android.hardware.radio.data.TrafficDescriptor td : result.trafficDescriptors) { 3501 try { 3502 trafficDescriptors.add(convertHalTrafficDescriptor(td)); 3503 } catch (IllegalArgumentException e) { 3504 loge("convertHalDataCallResult: Failed to convert traffic descriptor. e=" + e); 3505 } 3506 } 3507 } 3508 3509 return new DataCallResponse.Builder() 3510 .setCause(result.cause) 3511 .setRetryDurationMillis(result.suggestedRetryTime) 3512 .setId(result.cid) 3513 .setLinkStatus(result.active) 3514 .setProtocolType(result.type) 3515 .setInterfaceName(result.ifname) 3516 .setAddresses(laList) 3517 .setDnsAddresses(dnsList) 3518 .setGatewayAddresses(gatewayList) 3519 .setPcscfAddresses(pcscfList) 3520 .setMtu(Math.max(result.mtuV4, result.mtuV6)) 3521 .setMtuV4(result.mtuV4) 3522 .setMtuV6(result.mtuV6) 3523 .setHandoverFailureMode(result.handoverFailureMode) 3524 .setPduSessionId(result.pduSessionId) 3525 .setDefaultQos(convertHalQos(result.defaultQos)) 3526 .setQosBearerSessions(qosSessions) 3527 .setSliceInfo(result.sliceInfo == null ? null 3528 : convertHalSliceInfo(result.sliceInfo)) 3529 .setTrafficDescriptors(trafficDescriptors) 3530 .build(); 3531 } 3532 convertHalSliceInfo(android.hardware.radio.V1_6.SliceInfo si)3533 private static NetworkSliceInfo convertHalSliceInfo(android.hardware.radio.V1_6.SliceInfo si) { 3534 NetworkSliceInfo.Builder builder = new NetworkSliceInfo.Builder() 3535 .setSliceServiceType(si.sst) 3536 .setMappedHplmnSliceServiceType(si.mappedHplmnSst) 3537 .setStatus(convertHalSliceStatus(si.status)); 3538 if (si.sliceDifferentiator != NetworkSliceInfo.SLICE_DIFFERENTIATOR_NO_SLICE) { 3539 builder.setSliceDifferentiator(si.sliceDifferentiator) 3540 .setMappedHplmnSliceDifferentiator(si.mappedHplmnSD); 3541 } 3542 return builder.build(); 3543 } 3544 convertHalSliceInfo(android.hardware.radio.data.SliceInfo si)3545 private static NetworkSliceInfo convertHalSliceInfo(android.hardware.radio.data.SliceInfo si) { 3546 NetworkSliceInfo.Builder builder = new NetworkSliceInfo.Builder() 3547 .setSliceServiceType(si.sliceServiceType) 3548 .setMappedHplmnSliceServiceType(si.mappedHplmnSst) 3549 .setStatus(convertHalSliceStatus(si.status)); 3550 if (si.sliceDifferentiator != NetworkSliceInfo.SLICE_DIFFERENTIATOR_NO_SLICE) { 3551 builder.setSliceDifferentiator(si.sliceDifferentiator) 3552 .setMappedHplmnSliceDifferentiator(si.mappedHplmnSd); 3553 } 3554 return builder.build(); 3555 } 3556 convertHalSliceStatus(byte status)3557 @NetworkSliceInfo.SliceStatus private static int convertHalSliceStatus(byte status) { 3558 switch (status) { 3559 case SliceInfo.STATUS_CONFIGURED: 3560 return NetworkSliceInfo.SLICE_STATUS_CONFIGURED; 3561 case SliceInfo.STATUS_ALLOWED: 3562 return NetworkSliceInfo.SLICE_STATUS_ALLOWED; 3563 case SliceInfo.STATUS_REJECTED_NOT_AVAILABLE_IN_PLMN: 3564 return NetworkSliceInfo.SLICE_STATUS_REJECTED_NOT_AVAILABLE_IN_PLMN; 3565 case SliceInfo.STATUS_REJECTED_NOT_AVAILABLE_IN_REG_AREA: 3566 return NetworkSliceInfo.SLICE_STATUS_REJECTED_NOT_AVAILABLE_IN_REGISTERED_AREA; 3567 case SliceInfo.STATUS_DEFAULT_CONFIGURED: 3568 return NetworkSliceInfo.SLICE_STATUS_DEFAULT_CONFIGURED; 3569 default: 3570 return NetworkSliceInfo.SLICE_STATUS_UNKNOWN; 3571 } 3572 } 3573 convertHalTrafficDescriptor( android.hardware.radio.V1_6.TrafficDescriptor td)3574 private static TrafficDescriptor convertHalTrafficDescriptor( 3575 android.hardware.radio.V1_6.TrafficDescriptor td) throws IllegalArgumentException { 3576 String dnn = td.dnn.getDiscriminator() 3577 == android.hardware.radio.V1_6.OptionalDnn.hidl_discriminator.noinit 3578 ? null : td.dnn.value(); 3579 byte[] osAppId = td.osAppId.getDiscriminator() 3580 == android.hardware.radio.V1_6.OptionalOsAppId.hidl_discriminator.noinit 3581 ? null : arrayListToPrimitiveArray(td.osAppId.value().osAppId); 3582 3583 TrafficDescriptor.Builder builder = new TrafficDescriptor.Builder(); 3584 if (dnn != null) { 3585 builder.setDataNetworkName(dnn); 3586 } 3587 if (osAppId != null) { 3588 builder.setOsAppId(osAppId); 3589 } 3590 return builder.build(); 3591 } 3592 convertHalTrafficDescriptor( android.hardware.radio.data.TrafficDescriptor td)3593 private static TrafficDescriptor convertHalTrafficDescriptor( 3594 android.hardware.radio.data.TrafficDescriptor td) throws IllegalArgumentException { 3595 String dnn = td.dnn; 3596 byte[] osAppId = td.osAppId == null ? null : td.osAppId.osAppId; 3597 TrafficDescriptor.Builder builder = new TrafficDescriptor.Builder(); 3598 if (dnn != null) { 3599 builder.setDataNetworkName(dnn); 3600 } 3601 if (osAppId != null) { 3602 builder.setOsAppId(osAppId); 3603 } 3604 return builder.build(); 3605 } 3606 3607 /** 3608 * Convert SlicingConfig defined in radio/1.6/types.hal to NetworkSlicingConfig 3609 * @param sc SlicingConfig defined in radio/1.6/types.hal 3610 * @return The converted NetworkSlicingConfig 3611 */ convertHalSlicingConfig( android.hardware.radio.V1_6.SlicingConfig sc)3612 public static NetworkSlicingConfig convertHalSlicingConfig( 3613 android.hardware.radio.V1_6.SlicingConfig sc) { 3614 List<UrspRule> urspRules = sc.urspRules.stream().map(ur -> new UrspRule(ur.precedence, 3615 ur.trafficDescriptors.stream() 3616 .map(td -> { 3617 try { 3618 return convertHalTrafficDescriptor(td); 3619 } catch (IllegalArgumentException e) { 3620 loge("convertHalSlicingConfig: Failed to convert traffic " 3621 + "descriptor. e=" + e); 3622 return null; 3623 } 3624 }) 3625 .filter(Objects::nonNull) 3626 .collect(Collectors.toList()), 3627 ur.routeSelectionDescriptor.stream().map( 3628 rsd -> new RouteSelectionDescriptor(rsd.precedence, 3629 rsd.sessionType.value(), rsd.sscMode.value(), 3630 rsd.sliceInfo.stream().map(RILUtils::convertHalSliceInfo) 3631 .collect(Collectors.toList()), 3632 rsd.dnn)).collect(Collectors.toList()))) 3633 .collect(Collectors.toList()); 3634 return new NetworkSlicingConfig(urspRules, sc.sliceInfo.stream() 3635 .map(RILUtils::convertHalSliceInfo).collect(Collectors.toList())); 3636 } 3637 3638 /** 3639 * Convert SlicingConfig defined in SlicingConfig.aidl to NetworkSlicingConfig 3640 * @param sc SlicingConfig defined in SlicingConfig.aidl 3641 * @return The converted NetworkSlicingConfig 3642 */ convertHalSlicingConfig( android.hardware.radio.data.SlicingConfig sc)3643 public static NetworkSlicingConfig convertHalSlicingConfig( 3644 android.hardware.radio.data.SlicingConfig sc) { 3645 List<UrspRule> urspRules = new ArrayList<>(); 3646 for (android.hardware.radio.data.UrspRule ur : sc.urspRules) { 3647 List<TrafficDescriptor> tds = new ArrayList<>(); 3648 for (android.hardware.radio.data.TrafficDescriptor td : ur.trafficDescriptors) { 3649 try { 3650 tds.add(convertHalTrafficDescriptor(td)); 3651 } catch (IllegalArgumentException e) { 3652 loge("convertHalTrafficDescriptor: " + e); 3653 } 3654 } 3655 List<RouteSelectionDescriptor> rsds = new ArrayList<>(); 3656 for (android.hardware.radio.data.RouteSelectionDescriptor rsd 3657 : ur.routeSelectionDescriptor) { 3658 List<NetworkSliceInfo> sliceInfo = new ArrayList<>(); 3659 for (android.hardware.radio.data.SliceInfo si : rsd.sliceInfo) { 3660 sliceInfo.add(convertHalSliceInfo(si)); 3661 } 3662 rsds.add(new RouteSelectionDescriptor(rsd.precedence, rsd.sessionType, rsd.sscMode, 3663 sliceInfo, primitiveArrayToArrayList(rsd.dnn))); 3664 } 3665 urspRules.add(new UrspRule(ur.precedence, tds, rsds)); 3666 } 3667 List<NetworkSliceInfo> sliceInfo = new ArrayList<>(); 3668 for (android.hardware.radio.data.SliceInfo si : sc.sliceInfo) { 3669 sliceInfo.add(convertHalSliceInfo(si)); 3670 } 3671 return new NetworkSlicingConfig(urspRules, sliceInfo); 3672 } 3673 convertHalQosBandwidth( android.hardware.radio.V1_6.QosBandwidth bandwidth)3674 private static Qos.QosBandwidth convertHalQosBandwidth( 3675 android.hardware.radio.V1_6.QosBandwidth bandwidth) { 3676 return new Qos.QosBandwidth(bandwidth.maxBitrateKbps, bandwidth.guaranteedBitrateKbps); 3677 } 3678 convertHalQosBandwidth( android.hardware.radio.data.QosBandwidth bandwidth)3679 private static Qos.QosBandwidth convertHalQosBandwidth( 3680 android.hardware.radio.data.QosBandwidth bandwidth) { 3681 return new Qos.QosBandwidth(bandwidth.maxBitrateKbps, bandwidth.guaranteedBitrateKbps); 3682 } 3683 convertHalQos(android.hardware.radio.V1_6.Qos qos)3684 private static Qos convertHalQos(android.hardware.radio.V1_6.Qos qos) { 3685 if (qos == null) return null; 3686 switch (qos.getDiscriminator()) { 3687 case android.hardware.radio.V1_6.Qos.hidl_discriminator.eps: 3688 android.hardware.radio.V1_6.EpsQos eps = qos.eps(); 3689 return new EpsQos(convertHalQosBandwidth(eps.downlink), 3690 convertHalQosBandwidth(eps.uplink), eps.qci); 3691 case android.hardware.radio.V1_6.Qos.hidl_discriminator.nr: 3692 android.hardware.radio.V1_6.NrQos nr = qos.nr(); 3693 return new NrQos(convertHalQosBandwidth(nr.downlink), 3694 convertHalQosBandwidth(nr.uplink), nr.qfi, nr.fiveQi, nr.averagingWindowMs); 3695 default: 3696 return null; 3697 } 3698 } 3699 convertHalQos(android.hardware.radio.data.Qos qos)3700 private static Qos convertHalQos(android.hardware.radio.data.Qos qos) { 3701 if (qos == null) return null; 3702 switch (qos.getTag()) { 3703 case android.hardware.radio.data.Qos.eps: 3704 android.hardware.radio.data.EpsQos eps = qos.getEps(); 3705 return new EpsQos(convertHalQosBandwidth(eps.downlink), 3706 convertHalQosBandwidth(eps.uplink), eps.qci); 3707 case android.hardware.radio.data.Qos.nr: 3708 android.hardware.radio.data.NrQos nr = qos.getNr(); 3709 int averagingWindowMs = nr.averagingWindowMillis; 3710 if (averagingWindowMs 3711 == android.hardware.radio.data.NrQos.AVERAGING_WINDOW_UNKNOWN) { 3712 averagingWindowMs = nr.averagingWindowMs; 3713 } 3714 return new NrQos(convertHalQosBandwidth(nr.downlink), 3715 convertHalQosBandwidth(nr.uplink), nr.qfi, nr.fiveQi, averagingWindowMs); 3716 default: 3717 return null; 3718 } 3719 } 3720 convertHalQosBearerFilter( android.hardware.radio.V1_6.QosFilter qosFilter)3721 private static QosBearerFilter convertHalQosBearerFilter( 3722 android.hardware.radio.V1_6.QosFilter qosFilter) { 3723 List<LinkAddress> localAddressList = new ArrayList<>(); 3724 String[] localAddresses = qosFilter.localAddresses.toArray(new String[0]); 3725 if (localAddresses != null) { 3726 for (String address : localAddresses) { 3727 localAddressList.add(convertToLinkAddress(address)); 3728 } 3729 } 3730 List<LinkAddress> remoteAddressList = new ArrayList<>(); 3731 String[] remoteAddresses = qosFilter.remoteAddresses.toArray(new String[0]); 3732 if (remoteAddresses != null) { 3733 for (String address : remoteAddresses) { 3734 remoteAddressList.add(convertToLinkAddress(address)); 3735 } 3736 } 3737 QosBearerFilter.PortRange localPort = null; 3738 if (qosFilter.localPort != null) { 3739 if (qosFilter.localPort.getDiscriminator() 3740 == android.hardware.radio.V1_6.MaybePort.hidl_discriminator.range) { 3741 final android.hardware.radio.V1_6.PortRange portRange = qosFilter.localPort.range(); 3742 localPort = new QosBearerFilter.PortRange(portRange.start, portRange.end); 3743 } 3744 } 3745 QosBearerFilter.PortRange remotePort = null; 3746 if (qosFilter.remotePort != null) { 3747 if (qosFilter.remotePort.getDiscriminator() 3748 == android.hardware.radio.V1_6.MaybePort.hidl_discriminator.range) { 3749 final android.hardware.radio.V1_6.PortRange portRange = 3750 qosFilter.remotePort.range(); 3751 remotePort = new QosBearerFilter.PortRange(portRange.start, portRange.end); 3752 } 3753 } 3754 int tos = -1; 3755 if (qosFilter.tos != null) { 3756 if (qosFilter.tos.getDiscriminator() == android.hardware.radio.V1_6.QosFilter 3757 .TypeOfService.hidl_discriminator.value) { 3758 tos = qosFilter.tos.value(); 3759 } 3760 } 3761 long flowLabel = -1; 3762 if (qosFilter.flowLabel != null) { 3763 if (qosFilter.flowLabel.getDiscriminator() == android.hardware.radio.V1_6.QosFilter 3764 .Ipv6FlowLabel.hidl_discriminator.value) { 3765 flowLabel = qosFilter.flowLabel.value(); 3766 } 3767 } 3768 long spi = -1; 3769 if (qosFilter.spi != null) { 3770 if (qosFilter.spi.getDiscriminator() 3771 == android.hardware.radio.V1_6.QosFilter.IpsecSpi.hidl_discriminator.value) { 3772 spi = qosFilter.spi.value(); 3773 } 3774 } 3775 return new QosBearerFilter(localAddressList, remoteAddressList, localPort, remotePort, 3776 qosFilter.protocol, tos, flowLabel, spi, qosFilter.direction, qosFilter.precedence); 3777 } 3778 convertHalQosBearerFilter( android.hardware.radio.data.QosFilter qosFilter)3779 private static QosBearerFilter convertHalQosBearerFilter( 3780 android.hardware.radio.data.QosFilter qosFilter) { 3781 List<LinkAddress> localAddressList = new ArrayList<>(); 3782 String[] localAddresses = qosFilter.localAddresses; 3783 if (localAddresses != null) { 3784 for (String address : localAddresses) { 3785 localAddressList.add(convertToLinkAddress(address)); 3786 } 3787 } 3788 List<LinkAddress> remoteAddressList = new ArrayList<>(); 3789 String[] remoteAddresses = qosFilter.remoteAddresses; 3790 if (remoteAddresses != null) { 3791 for (String address : remoteAddresses) { 3792 remoteAddressList.add(convertToLinkAddress(address)); 3793 } 3794 } 3795 QosBearerFilter.PortRange localPort = null; 3796 if (qosFilter.localPort != null) { 3797 localPort = new QosBearerFilter.PortRange( 3798 qosFilter.localPort.start, qosFilter.localPort.end); 3799 } 3800 QosBearerFilter.PortRange remotePort = null; 3801 if (qosFilter.remotePort != null) { 3802 remotePort = new QosBearerFilter.PortRange( 3803 qosFilter.remotePort.start, qosFilter.remotePort.end); 3804 } 3805 int tos = -1; 3806 if (qosFilter.tos != null) { 3807 if (qosFilter.tos.getTag() 3808 == android.hardware.radio.data.QosFilterTypeOfService.value) { 3809 tos = qosFilter.tos.value; 3810 } 3811 } 3812 long flowLabel = -1; 3813 if (qosFilter.flowLabel != null) { 3814 if (qosFilter.flowLabel.getTag() 3815 == android.hardware.radio.data.QosFilterIpv6FlowLabel.value) { 3816 flowLabel = qosFilter.flowLabel.value; 3817 } 3818 } 3819 long spi = -1; 3820 if (qosFilter.spi != null) { 3821 if (qosFilter.spi.getTag() 3822 == android.hardware.radio.data.QosFilterIpsecSpi.value) { 3823 spi = qosFilter.spi.value; 3824 } 3825 } 3826 return new QosBearerFilter(localAddressList, remoteAddressList, localPort, remotePort, 3827 qosFilter.protocol, tos, flowLabel, spi, qosFilter.direction, qosFilter.precedence); 3828 } 3829 convertHalQosBearerSession( android.hardware.radio.V1_6.QosSession qosSession)3830 private static QosBearerSession convertHalQosBearerSession( 3831 android.hardware.radio.V1_6.QosSession qosSession) { 3832 List<QosBearerFilter> qosBearerFilters = new ArrayList<>(); 3833 if (qosSession.qosFilters != null) { 3834 for (android.hardware.radio.V1_6.QosFilter filter : qosSession.qosFilters) { 3835 qosBearerFilters.add(convertHalQosBearerFilter(filter)); 3836 } 3837 } 3838 return new QosBearerSession(qosSession.qosSessionId, convertHalQos(qosSession.qos), 3839 qosBearerFilters); 3840 } 3841 convertHalQosBearerSession( android.hardware.radio.data.QosSession qosSession)3842 private static QosBearerSession convertHalQosBearerSession( 3843 android.hardware.radio.data.QosSession qosSession) { 3844 List<QosBearerFilter> qosBearerFilters = new ArrayList<>(); 3845 if (qosSession.qosFilters != null) { 3846 for (android.hardware.radio.data.QosFilter filter : qosSession.qosFilters) { 3847 qosBearerFilters.add(convertHalQosBearerFilter(filter)); 3848 } 3849 } 3850 return new QosBearerSession(qosSession.qosSessionId, convertHalQos(qosSession.qos), 3851 qosBearerFilters); 3852 } 3853 3854 /** 3855 * Convert a list of SetupDataCallResult defined in radio/1.4, 1.5, 1.6/types.hal into 3856 * a list of DataCallResponse 3857 * @param dataCallResultList List of SetupDataCallResult defined in 3858 * radio/1.4, 1.5, 1.6/types.hal 3859 * @return The converted list of DataCallResponses 3860 */ 3861 @VisibleForTesting convertHalDataCallResultList( List<? extends Object> dataCallResultList)3862 public static ArrayList<DataCallResponse> convertHalDataCallResultList( 3863 List<? extends Object> dataCallResultList) { 3864 ArrayList<DataCallResponse> response = new ArrayList<>(dataCallResultList.size()); 3865 3866 for (Object obj : dataCallResultList) { 3867 response.add(convertHalDataCallResult(obj)); 3868 } 3869 return response; 3870 } 3871 3872 /** 3873 * Convert a list of SetupDataCallResult defined in SetupDataCallResult.aidl into a list of 3874 * DataCallResponse 3875 * @param dataCallResultList Array of SetupDataCallResult defined in SetupDataCallResult.aidl 3876 * @return The converted list of DataCallResponses 3877 */ 3878 @VisibleForTesting convertHalDataCallResultList( android.hardware.radio.data.SetupDataCallResult[] dataCallResultList)3879 public static ArrayList<DataCallResponse> convertHalDataCallResultList( 3880 android.hardware.radio.data.SetupDataCallResult[] dataCallResultList) { 3881 ArrayList<DataCallResponse> response = new ArrayList<>(dataCallResultList.length); 3882 3883 for (android.hardware.radio.data.SetupDataCallResult result : dataCallResultList) { 3884 response.add(convertHalDataCallResult(result)); 3885 } 3886 return response; 3887 } 3888 3889 /** 3890 * Convert KeepaliveStatusCode defined in radio/1.1/types.hal and KeepaliveStatus.aidl 3891 * to KeepaliveStatus 3892 * @param halCode KeepaliveStatus code defined in radio/1.1/types.hal or KeepaliveStatus.aidl 3893 * @return The converted KeepaliveStatus 3894 */ convertHalKeepaliveStatusCode(int halCode)3895 public static @KeepaliveStatusCode int convertHalKeepaliveStatusCode(int halCode) { 3896 switch (halCode) { 3897 case android.hardware.radio.V1_1.KeepaliveStatusCode.ACTIVE: 3898 return KeepaliveStatus.STATUS_ACTIVE; 3899 case android.hardware.radio.V1_1.KeepaliveStatusCode.INACTIVE: 3900 return KeepaliveStatus.STATUS_INACTIVE; 3901 case android.hardware.radio.V1_1.KeepaliveStatusCode.PENDING: 3902 return KeepaliveStatus.STATUS_PENDING; 3903 default: 3904 return -1; 3905 } 3906 } 3907 3908 /** 3909 * Convert RadioState defined in radio/1.0/types.hal and RadioState.aidl to RadioPowerState 3910 * @param stateInt Radio state defined in radio/1.0/types.hal or RadioState.aidl 3911 * @return The converted {@link Annotation.RadioPowerState RadioPowerState} 3912 */ convertHalRadioState(int stateInt)3913 public static @Annotation.RadioPowerState int convertHalRadioState(int stateInt) { 3914 int state; 3915 switch(stateInt) { 3916 case android.hardware.radio.V1_0.RadioState.OFF: 3917 state = TelephonyManager.RADIO_POWER_OFF; 3918 break; 3919 case android.hardware.radio.V1_0.RadioState.UNAVAILABLE: 3920 state = TelephonyManager.RADIO_POWER_UNAVAILABLE; 3921 break; 3922 case android.hardware.radio.V1_0.RadioState.ON: 3923 state = TelephonyManager.RADIO_POWER_ON; 3924 break; 3925 default: 3926 throw new RuntimeException("Unrecognized RadioState: " + stateInt); 3927 } 3928 return state; 3929 } 3930 3931 /** 3932 * Convert CellConnectionStatus defined in radio/1.2/types.hal to ConnectionStatus 3933 * @param status Cell connection status defined in radio/1.2/types.hal 3934 * @return The converted ConnectionStatus 3935 */ convertHalCellConnectionStatus(int status)3936 public static int convertHalCellConnectionStatus(int status) { 3937 switch (status) { 3938 case android.hardware.radio.V1_2.CellConnectionStatus.PRIMARY_SERVING: 3939 return PhysicalChannelConfig.CONNECTION_PRIMARY_SERVING; 3940 case android.hardware.radio.V1_2.CellConnectionStatus.SECONDARY_SERVING: 3941 return PhysicalChannelConfig.CONNECTION_SECONDARY_SERVING; 3942 default: 3943 return PhysicalChannelConfig.CONNECTION_UNKNOWN; 3944 } 3945 } 3946 3947 /** 3948 * Convert Call defined in radio/1.2, 1.6/types.hal to DriverCall 3949 * @param halCall Call defined in radio/1.2, 1.6/types.hal 3950 * @return The converted DriverCall 3951 */ convertToDriverCall(Object halCall)3952 public static DriverCall convertToDriverCall(Object halCall) { 3953 DriverCall dc = new DriverCall(); 3954 final android.hardware.radio.V1_6.Call call16; 3955 final android.hardware.radio.V1_2.Call call12; 3956 final android.hardware.radio.V1_0.Call call10; 3957 if (halCall instanceof android.hardware.radio.V1_6.Call) { 3958 call16 = (android.hardware.radio.V1_6.Call) halCall; 3959 call12 = call16.base; 3960 call10 = call12.base; 3961 } else if (halCall instanceof android.hardware.radio.V1_2.Call) { 3962 call16 = null; 3963 call12 = (android.hardware.radio.V1_2.Call) halCall; 3964 call10 = call12.base; 3965 } else { 3966 call16 = null; 3967 call12 = null; 3968 call10 = null; 3969 } 3970 if (call10 != null) { 3971 dc.state = DriverCall.stateFromCLCC(call10.state); 3972 dc.index = call10.index; 3973 dc.TOA = call10.toa; 3974 dc.isMpty = call10.isMpty; 3975 dc.isMT = call10.isMT; 3976 dc.als = call10.als; 3977 dc.isVoice = call10.isVoice; 3978 dc.isVoicePrivacy = call10.isVoicePrivacy; 3979 dc.number = call10.number; 3980 dc.numberPresentation = DriverCall.presentationFromCLIP(call10.numberPresentation); 3981 dc.name = call10.name; 3982 dc.namePresentation = DriverCall.presentationFromCLIP(call10.namePresentation); 3983 if (call10.uusInfo.size() == 1) { 3984 dc.uusInfo = new UUSInfo(); 3985 dc.uusInfo.setType(call10.uusInfo.get(0).uusType); 3986 dc.uusInfo.setDcs(call10.uusInfo.get(0).uusDcs); 3987 if (!TextUtils.isEmpty(call10.uusInfo.get(0).uusData)) { 3988 byte[] userData = call10.uusInfo.get(0).uusData.getBytes(); 3989 dc.uusInfo.setUserData(userData); 3990 } 3991 } 3992 // Make sure there's a leading + on addresses with a TOA of 145 3993 dc.number = PhoneNumberUtils.stringFromStringAndTOA(dc.number, dc.TOA); 3994 } 3995 if (call12 != null) { 3996 dc.audioQuality = call12.audioQuality; 3997 } 3998 if (call16 != null) { 3999 dc.forwardedNumber = call16.forwardedNumber; 4000 } 4001 return dc; 4002 } 4003 4004 /** 4005 * Convert Call defined in Call.aidl to DriverCall 4006 * @param halCall Call defined in Call.aidl 4007 * @return The converted DriverCall 4008 */ convertToDriverCall(android.hardware.radio.voice.Call halCall)4009 public static DriverCall convertToDriverCall(android.hardware.radio.voice.Call halCall) { 4010 DriverCall dc = new DriverCall(); 4011 dc.state = DriverCall.stateFromCLCC(halCall.state); 4012 dc.index = halCall.index; 4013 dc.TOA = halCall.toa; 4014 dc.isMpty = halCall.isMpty; 4015 dc.isMT = halCall.isMT; 4016 dc.als = halCall.als; 4017 dc.isVoice = halCall.isVoice; 4018 dc.isVoicePrivacy = halCall.isVoicePrivacy; 4019 dc.number = halCall.number; 4020 dc.numberPresentation = DriverCall.presentationFromCLIP(halCall.numberPresentation); 4021 dc.name = halCall.name; 4022 dc.namePresentation = DriverCall.presentationFromCLIP(halCall.namePresentation); 4023 if (halCall.uusInfo.length == 1) { 4024 dc.uusInfo = new UUSInfo(); 4025 dc.uusInfo.setType(halCall.uusInfo[0].uusType); 4026 dc.uusInfo.setDcs(halCall.uusInfo[0].uusDcs); 4027 if (!TextUtils.isEmpty(halCall.uusInfo[0].uusData)) { 4028 dc.uusInfo.setUserData(halCall.uusInfo[0].uusData.getBytes()); 4029 } 4030 } 4031 // Make sure there's a leading + on addresses with a TOA of 145 4032 dc.number = PhoneNumberUtils.stringFromStringAndTOA(dc.number, dc.TOA); 4033 dc.audioQuality = halCall.audioQuality; 4034 dc.forwardedNumber = halCall.forwardedNumber; 4035 return dc; 4036 } 4037 4038 /** 4039 * Convert OperatorStatus defined in radio/1.0/types.hal to OperatorInfo.State 4040 * @param status Operator status defined in radio/1.0/types.hal 4041 * @return The converted OperatorStatus as a String 4042 */ convertHalOperatorStatus(int status)4043 public static String convertHalOperatorStatus(int status) { 4044 if (status == android.hardware.radio.V1_0.OperatorStatus.UNKNOWN) { 4045 return "unknown"; 4046 } else if (status == android.hardware.radio.V1_0.OperatorStatus.AVAILABLE) { 4047 return "available"; 4048 } else if (status == android.hardware.radio.V1_0.OperatorStatus.CURRENT) { 4049 return "current"; 4050 } else if (status == android.hardware.radio.V1_0.OperatorStatus.FORBIDDEN) { 4051 return "forbidden"; 4052 } else { 4053 return ""; 4054 } 4055 } 4056 4057 /** 4058 * Convert a list of Carriers defined in radio/1.0/types.hal to a list of CarrierIdentifiers 4059 * @param carrierList List of Carriers defined in radio/1.0/types.hal 4060 * @return The converted list of CarrierIdentifiers 4061 */ convertHalCarrierList( List<android.hardware.radio.V1_0.Carrier> carrierList)4062 public static List<CarrierIdentifier> convertHalCarrierList( 4063 List<android.hardware.radio.V1_0.Carrier> carrierList) { 4064 List<CarrierIdentifier> ret = new ArrayList<>(); 4065 for (int i = 0; i < carrierList.size(); i++) { 4066 String mcc = carrierList.get(i).mcc; 4067 String mnc = carrierList.get(i).mnc; 4068 String spn = null, imsi = null, gid1 = null, gid2 = null; 4069 int matchType = carrierList.get(i).matchType; 4070 String matchData = carrierList.get(i).matchData; 4071 if (matchType == CarrierIdentifier.MatchType.SPN) { 4072 spn = matchData; 4073 } else if (matchType == CarrierIdentifier.MatchType.IMSI_PREFIX) { 4074 imsi = matchData; 4075 } else if (matchType == CarrierIdentifier.MatchType.GID1) { 4076 gid1 = matchData; 4077 } else if (matchType == CarrierIdentifier.MatchType.GID2) { 4078 gid2 = matchData; 4079 } 4080 ret.add(new CarrierIdentifier(mcc, mnc, spn, imsi, gid1, gid2)); 4081 } 4082 return ret; 4083 } 4084 4085 /** 4086 * Convert a list of Carriers defined in radio/1.0/types.hal to a list of CarrierIdentifiers 4087 * @param carrierList List of Carriers defined in radio/1.0/types.hal 4088 * @return The converted list of CarrierIdentifiers 4089 */ convertHalCarrierList( android.hardware.radio.sim.Carrier[] carrierList)4090 public static List<CarrierIdentifier> convertHalCarrierList( 4091 android.hardware.radio.sim.Carrier[] carrierList) { 4092 List<CarrierIdentifier> ret = new ArrayList<>(); 4093 if (carrierList == null) { 4094 return ret; 4095 } 4096 for (int i = 0; i < carrierList.length; i++) { 4097 String mcc = carrierList[i].mcc; 4098 String mnc = carrierList[i].mnc; 4099 String spn = null, imsi = null, gid1 = null, gid2 = null; 4100 int matchType = carrierList[i].matchType; 4101 String matchData = carrierList[i].matchData; 4102 if (matchType == CarrierIdentifier.MatchType.SPN) { 4103 spn = matchData; 4104 } else if (matchType == CarrierIdentifier.MatchType.IMSI_PREFIX) { 4105 imsi = matchData; 4106 } else if (matchType == CarrierIdentifier.MatchType.GID1) { 4107 gid1 = matchData; 4108 } else if (matchType == CarrierIdentifier.MatchType.GID2) { 4109 gid2 = matchData; 4110 } 4111 ret.add(new CarrierIdentifier(mcc, mnc, spn, imsi, gid1, gid2)); 4112 } 4113 return ret; 4114 } 4115 4116 /** 4117 * Convert an array of CarrierInfo defined in 4118 * radio/aidl/android/hardware/radio/sim/CarrierInfo.aidl to a list of CarrierInfo 4119 * defined in android/service/carrier/CarrierInfo.java 4120 * 4121 * @param carrierInfos array of CarrierInfo defined in 4122 * radio/aidl/android/hardware/radio/sim/CarrierInfo.aidl 4123 * @return The converted list of CarrierInfo 4124 */ convertAidlCarrierInfoList( android.hardware.radio.sim.CarrierInfo[] carrierInfos)4125 public static List<CarrierInfo> convertAidlCarrierInfoList( 4126 android.hardware.radio.sim.CarrierInfo[] carrierInfos) { 4127 List<CarrierInfo> carrierInfoList = new ArrayList<>(); 4128 if (carrierInfos == null) { 4129 loge("convertAidlCarrierInfoList received NULL carrierInfos"); 4130 return carrierInfoList; 4131 } 4132 for (int index = 0; index < carrierInfos.length; index++) { 4133 String mcc = carrierInfos[index].mcc; 4134 String mnc = carrierInfos[index].mnc; 4135 String spn = carrierInfos[index].spn; 4136 String gid1 = carrierInfos[index].gid1; 4137 String gid2 = carrierInfos[index].gid2; 4138 String imsi = carrierInfos[index].imsiPrefix; 4139 String iccid = carrierInfos[index].iccid; 4140 String impi = carrierInfos[index].impi; 4141 List<android.hardware.radio.sim.Plmn> halEhplmn = carrierInfos[index].ehplmn; 4142 List<String> eHplmnList = new ArrayList<>(); 4143 if (halEhplmn != null) { 4144 for (int plmnIndex = 0; plmnIndex < halEhplmn.size(); plmnIndex++) { 4145 String ehplmnMcc = halEhplmn.get(plmnIndex).mcc; 4146 String ehplmnMnc = halEhplmn.get(plmnIndex).mnc; 4147 eHplmnList.add(ehplmnMcc + "," + ehplmnMnc); 4148 } 4149 } else { 4150 loge("convertAidlCarrierInfoList ehplmList is NULL"); 4151 } 4152 CarrierInfo carrierInfo = new CarrierInfo(mcc, mnc, spn, gid1, gid2, imsi, iccid, impi, 4153 eHplmnList); 4154 carrierInfoList.add(carrierInfo); 4155 } 4156 return carrierInfoList; 4157 } 4158 4159 /** 4160 * This API is for fallback to support getAllowedCarriers too. 4161 * 4162 * Convert an array of CarrierInfo defined in 4163 * radio/aidl/android/hardware/radio/sim/CarrierInfo.aidl to a list of CarrierIdentifiers. 4164 * 4165 * @param carrierInfos array of CarrierInfo defined in 4166 * radio/aidl/android/hardware/radio/sim/CarrierInfo.aidl 4167 * @return The converted list of CarrierIdentifiers 4168 */ convertAidlCarrierInfoListToHalCarrierList( android.hardware.radio.sim.CarrierInfo[] carrierInfos)4169 public static List<CarrierIdentifier> convertAidlCarrierInfoListToHalCarrierList( 4170 android.hardware.radio.sim.CarrierInfo[] carrierInfos) { 4171 List<CarrierIdentifier> ret = new ArrayList<>(); 4172 if (carrierInfos == null) { 4173 return ret; 4174 } 4175 for (android.hardware.radio.sim.CarrierInfo carrierInfo : carrierInfos) { 4176 String mcc = carrierInfo.mcc; 4177 String mnc = carrierInfo.mnc; 4178 String spn = carrierInfo.spn; 4179 String imsi = carrierInfo.imsiPrefix; 4180 String gid1 = carrierInfo.gid1; 4181 String gid2 = carrierInfo.gid2; 4182 ret.add(new CarrierIdentifier(mcc, mnc, spn, imsi, gid1, gid2)); 4183 } 4184 return ret; 4185 } 4186 4187 /** 4188 * Convert the sim policy defined in 4189 * radio/aidl/android/hardware/radio/sim/SimLockMultiSimPolicy.aidl to the equivalent sim 4190 * policy defined in android.telephony/CarrierRestrictionRules.MultiSimPolicy 4191 * 4192 * @param multiSimPolicy of type defined in SimLockMultiSimPolicy.aidl 4193 * @return int of type CarrierRestrictionRules.MultiSimPolicy 4194 */ convertAidlSimLockMultiSimPolicy( int multiSimPolicy)4195 public static @CarrierRestrictionRules.MultiSimPolicy int convertAidlSimLockMultiSimPolicy( 4196 int multiSimPolicy) { 4197 switch (multiSimPolicy) { 4198 case android.hardware.radio.sim.SimLockMultiSimPolicy.ONE_VALID_SIM_MUST_BE_PRESENT: 4199 return CarrierRestrictionRules.MULTISIM_POLICY_ONE_VALID_SIM_MUST_BE_PRESENT; 4200 case android.hardware.radio.sim.SimLockMultiSimPolicy.APPLY_TO_ALL_SLOTS: 4201 return CarrierRestrictionRules.MULTISIM_POLICY_APPLY_TO_ALL_SLOTS; 4202 case android.hardware.radio.sim.SimLockMultiSimPolicy.APPLY_TO_ONLY_SLOT_1: 4203 return CarrierRestrictionRules.MULTISIM_POLICY_APPLY_TO_ONLY_SLOT_1; 4204 case android.hardware.radio.sim.SimLockMultiSimPolicy.VALID_SIM_MUST_PRESENT_ON_SLOT_1: 4205 return CarrierRestrictionRules.MULTISIM_POLICY_VALID_SIM_MUST_PRESENT_ON_SLOT_1; 4206 case android.hardware.radio.sim.SimLockMultiSimPolicy. 4207 ACTIVE_SERVICE_ON_SLOT_1_TO_UNBLOCK_OTHER_SLOTS: 4208 return CarrierRestrictionRules. 4209 MULTISIM_POLICY_ACTIVE_SERVICE_ON_SLOT_1_TO_UNBLOCK_OTHER_SLOTS; 4210 case android.hardware.radio.sim.SimLockMultiSimPolicy. 4211 ACTIVE_SERVICE_ON_ANY_SLOT_TO_UNBLOCK_OTHER_SLOTS: 4212 return CarrierRestrictionRules. 4213 MULTISIM_POLICY_ACTIVE_SERVICE_ON_ANY_SLOT_TO_UNBLOCK_OTHER_SLOTS; 4214 case android.hardware.radio.sim.SimLockMultiSimPolicy.ALL_SIMS_MUST_BE_VALID: 4215 return CarrierRestrictionRules.MULTISIM_POLICY_ALL_SIMS_MUST_BE_VALID; 4216 case android.hardware.radio.sim.SimLockMultiSimPolicy.SLOT_POLICY_OTHER: 4217 return CarrierRestrictionRules.MULTISIM_POLICY_SLOT_POLICY_OTHER; 4218 default: 4219 return CarrierRestrictionRules.MULTISIM_POLICY_NONE; 4220 } 4221 } 4222 4223 /** 4224 * Convert CardStatus defined in radio/1.0, 1.5/types.hal to IccCardStatus 4225 * @param cardStatus CardStatus defined in radio/1.0, 1.5/types.hal 4226 * @return The converted IccCardStatus 4227 */ convertHalCardStatus(Object cardStatus)4228 public static IccCardStatus convertHalCardStatus(Object cardStatus) { 4229 final android.hardware.radio.V1_0.CardStatus cardStatus10; 4230 final android.hardware.radio.V1_5.CardStatus cardStatus15; 4231 if (cardStatus instanceof android.hardware.radio.V1_5.CardStatus) { 4232 cardStatus15 = (android.hardware.radio.V1_5.CardStatus) cardStatus; 4233 cardStatus10 = cardStatus15.base.base.base; 4234 } else if (cardStatus instanceof android.hardware.radio.V1_0.CardStatus) { 4235 cardStatus15 = null; 4236 cardStatus10 = (android.hardware.radio.V1_0.CardStatus) cardStatus; 4237 } else { 4238 cardStatus15 = null; 4239 cardStatus10 = null; 4240 } 4241 4242 IccCardStatus iccCardStatus = new IccCardStatus(); 4243 if (cardStatus10 != null) { 4244 iccCardStatus.setCardState(cardStatus10.cardState); 4245 iccCardStatus.setUniversalPinState(cardStatus10.universalPinState); 4246 iccCardStatus.mGsmUmtsSubscriptionAppIndex = cardStatus10.gsmUmtsSubscriptionAppIndex; 4247 iccCardStatus.mCdmaSubscriptionAppIndex = 4248 Flags.cleanupCdma() ? -1 : cardStatus10.cdmaSubscriptionAppIndex; 4249 iccCardStatus.mImsSubscriptionAppIndex = cardStatus10.imsSubscriptionAppIndex; 4250 int numApplications = cardStatus10.applications.size(); 4251 4252 // limit to maximum allowed applications 4253 if (numApplications > com.android.internal.telephony.uicc.IccCardStatus.CARD_MAX_APPS) { 4254 numApplications = com.android.internal.telephony.uicc.IccCardStatus.CARD_MAX_APPS; 4255 } 4256 iccCardStatus.mApplications = new IccCardApplicationStatus[numApplications]; 4257 for (int i = 0; i < numApplications; i++) { 4258 android.hardware.radio.V1_0.AppStatus rilAppStatus = 4259 cardStatus10.applications.get(i); 4260 IccCardApplicationStatus appStatus = new IccCardApplicationStatus(); 4261 appStatus.app_type = appStatus.AppTypeFromRILInt(rilAppStatus.appType); 4262 appStatus.app_state = appStatus.AppStateFromRILInt(rilAppStatus.appState); 4263 appStatus.perso_substate = appStatus.PersoSubstateFromRILInt( 4264 rilAppStatus.persoSubstate); 4265 appStatus.aid = rilAppStatus.aidPtr; 4266 appStatus.app_label = rilAppStatus.appLabelPtr; 4267 appStatus.pin1_replaced = rilAppStatus.pin1Replaced != 0; 4268 appStatus.pin1 = appStatus.PinStateFromRILInt(rilAppStatus.pin1); 4269 appStatus.pin2 = appStatus.PinStateFromRILInt(rilAppStatus.pin2); 4270 iccCardStatus.mApplications[i] = appStatus; 4271 } 4272 } 4273 if (cardStatus15 != null) { 4274 IccSlotPortMapping slotPortMapping = new IccSlotPortMapping(); 4275 slotPortMapping.mPhysicalSlotIndex = cardStatus15.base.base.physicalSlotId; 4276 iccCardStatus.mSlotPortMapping = slotPortMapping; 4277 iccCardStatus.atr = cardStatus15.base.base.atr; 4278 iccCardStatus.iccid = cardStatus15.base.base.iccid; 4279 iccCardStatus.eid = cardStatus15.base.eid; 4280 int numApplications = cardStatus15.applications.size(); 4281 4282 // limit to maximum allowed applications 4283 if (numApplications > com.android.internal.telephony.uicc.IccCardStatus.CARD_MAX_APPS) { 4284 numApplications = com.android.internal.telephony.uicc.IccCardStatus.CARD_MAX_APPS; 4285 } 4286 iccCardStatus.mApplications = new IccCardApplicationStatus[numApplications]; 4287 for (int i = 0; i < numApplications; i++) { 4288 android.hardware.radio.V1_5.AppStatus rilAppStatus = 4289 cardStatus15.applications.get(i); 4290 IccCardApplicationStatus appStatus = new IccCardApplicationStatus(); 4291 appStatus.app_type = appStatus.AppTypeFromRILInt(rilAppStatus.base.appType); 4292 appStatus.app_state = appStatus.AppStateFromRILInt(rilAppStatus.base.appState); 4293 appStatus.perso_substate = appStatus.PersoSubstateFromRILInt( 4294 rilAppStatus.persoSubstate); 4295 appStatus.aid = rilAppStatus.base.aidPtr; 4296 appStatus.app_label = rilAppStatus.base.appLabelPtr; 4297 appStatus.pin1_replaced = rilAppStatus.base.pin1Replaced != 0; 4298 appStatus.pin1 = appStatus.PinStateFromRILInt(rilAppStatus.base.pin1); 4299 appStatus.pin2 = appStatus.PinStateFromRILInt(rilAppStatus.base.pin2); 4300 iccCardStatus.mApplications[i] = appStatus; 4301 } 4302 } 4303 return iccCardStatus; 4304 } 4305 4306 /** 4307 * Convert CardStatus defined in CardStatus.aidl to IccCardStatus 4308 * @param cardStatus CardStatus defined in CardStatus.aidl 4309 * @return The converted IccCardStatus 4310 */ convertHalCardStatus( android.hardware.radio.sim.CardStatus cardStatus)4311 public static IccCardStatus convertHalCardStatus( 4312 android.hardware.radio.sim.CardStatus cardStatus) { 4313 IccCardStatus iccCardStatus = new IccCardStatus(); 4314 iccCardStatus.setCardState(cardStatus.cardState); 4315 iccCardStatus.setMultipleEnabledProfilesMode(cardStatus.supportedMepMode); 4316 iccCardStatus.setUniversalPinState(cardStatus.universalPinState); 4317 iccCardStatus.mGsmUmtsSubscriptionAppIndex = cardStatus.gsmUmtsSubscriptionAppIndex; 4318 iccCardStatus.mCdmaSubscriptionAppIndex = 4319 Flags.cleanupCdma() ? -1 : cardStatus.cdmaSubscriptionAppIndex; 4320 iccCardStatus.mImsSubscriptionAppIndex = cardStatus.imsSubscriptionAppIndex; 4321 iccCardStatus.atr = cardStatus.atr; 4322 iccCardStatus.iccid = cardStatus.iccid; 4323 iccCardStatus.eid = cardStatus.eid; 4324 4325 int numApplications = Math.min(cardStatus.applications.length, 4326 com.android.internal.telephony.uicc.IccCardStatus.CARD_MAX_APPS); 4327 iccCardStatus.mApplications = new IccCardApplicationStatus[numApplications]; 4328 for (int i = 0; i < numApplications; i++) { 4329 android.hardware.radio.sim.AppStatus rilAppStatus = cardStatus.applications[i]; 4330 IccCardApplicationStatus appStatus = new IccCardApplicationStatus(); 4331 appStatus.app_type = appStatus.AppTypeFromRILInt(rilAppStatus.appType); 4332 appStatus.app_state = appStatus.AppStateFromRILInt(rilAppStatus.appState); 4333 appStatus.perso_substate = appStatus.PersoSubstateFromRILInt( 4334 rilAppStatus.persoSubstate); 4335 appStatus.aid = rilAppStatus.aidPtr; 4336 appStatus.app_label = rilAppStatus.appLabelPtr; 4337 appStatus.pin1_replaced = rilAppStatus.pin1Replaced; 4338 appStatus.pin1 = appStatus.PinStateFromRILInt(rilAppStatus.pin1); 4339 appStatus.pin2 = appStatus.PinStateFromRILInt(rilAppStatus.pin2); 4340 iccCardStatus.mApplications[i] = appStatus; 4341 } 4342 IccSlotPortMapping slotPortMapping = new IccSlotPortMapping(); 4343 slotPortMapping.mPhysicalSlotIndex = cardStatus.slotMap.physicalSlotId; 4344 slotPortMapping.mPortIndex = PortUtils.convertFromHalPortIndex( 4345 cardStatus.slotMap.physicalSlotId, cardStatus.slotMap.portId, 4346 iccCardStatus.mCardState, iccCardStatus.mSupportedMepMode); 4347 iccCardStatus.mSlotPortMapping = slotPortMapping; 4348 return iccCardStatus; 4349 } 4350 4351 /** 4352 * Convert PhonebookCapacity defined in radio/1.6/types.hal to AdnCapacity 4353 * @param pbCap PhonebookCapacity defined in radio/1.6/types.hal 4354 * @return The converted AdnCapacity 4355 */ convertHalPhonebookCapacity( android.hardware.radio.V1_6.PhonebookCapacity pbCap)4356 public static AdnCapacity convertHalPhonebookCapacity( 4357 android.hardware.radio.V1_6.PhonebookCapacity pbCap) { 4358 if (pbCap != null) { 4359 return new AdnCapacity(pbCap.maxAdnRecords, pbCap.usedAdnRecords, pbCap.maxEmailRecords, 4360 pbCap.usedEmailRecords, pbCap.maxAdditionalNumberRecords, 4361 pbCap.usedAdditionalNumberRecords, pbCap.maxNameLen, pbCap.maxNumberLen, 4362 pbCap.maxEmailLen, pbCap.maxAdditionalNumberLen); 4363 } 4364 return null; 4365 } 4366 4367 /** 4368 * Convert PhonebookCapacity defined in PhonebookCapacity.aidl to AdnCapacity 4369 * @param pbCap PhonebookCapacity defined in PhonebookCapacity.aidl 4370 * @return The converted AdnCapacity 4371 */ convertHalPhonebookCapacity( android.hardware.radio.sim.PhonebookCapacity pbCap)4372 public static AdnCapacity convertHalPhonebookCapacity( 4373 android.hardware.radio.sim.PhonebookCapacity pbCap) { 4374 if (pbCap != null) { 4375 return new AdnCapacity(pbCap.maxAdnRecords, pbCap.usedAdnRecords, pbCap.maxEmailRecords, 4376 pbCap.usedEmailRecords, pbCap.maxAdditionalNumberRecords, 4377 pbCap.usedAdditionalNumberRecords, pbCap.maxNameLen, pbCap.maxNumberLen, 4378 pbCap.maxEmailLen, pbCap.maxAdditionalNumberLen); 4379 } 4380 return null; 4381 } 4382 4383 /** 4384 * Convert PhonebookRecordInfo defined in radio/1.6/types.hal to SimPhonebookRecord 4385 * @param recInfo PhonebookRecordInfo defined in radio/1.6/types.hal 4386 * @return The converted SimPhonebookRecord 4387 */ convertHalPhonebookRecordInfo( android.hardware.radio.V1_6.PhonebookRecordInfo recInfo)4388 public static SimPhonebookRecord convertHalPhonebookRecordInfo( 4389 android.hardware.radio.V1_6.PhonebookRecordInfo recInfo) { 4390 String[] emails = recInfo.emails == null ? null 4391 : recInfo.emails.toArray(new String[recInfo.emails.size()]); 4392 String[] numbers = recInfo.additionalNumbers == null ? null 4393 : recInfo.additionalNumbers.toArray(new String[recInfo.additionalNumbers.size()]); 4394 return new SimPhonebookRecord(recInfo.recordId, recInfo.name, recInfo.number, emails, 4395 numbers); 4396 } 4397 4398 /** 4399 * Convert PhonebookRecordInfo defined in PhonebookRecordInfo.aidl to SimPhonebookRecord 4400 * @param recInfo PhonebookRecordInfo defined in PhonebookRecordInfo.aidl 4401 * @return The converted SimPhonebookRecord 4402 */ convertHalPhonebookRecordInfo( android.hardware.radio.sim.PhonebookRecordInfo recInfo)4403 public static SimPhonebookRecord convertHalPhonebookRecordInfo( 4404 android.hardware.radio.sim.PhonebookRecordInfo recInfo) { 4405 return new SimPhonebookRecord(recInfo.recordId, recInfo.name, recInfo.number, 4406 recInfo.emails, recInfo.additionalNumbers); 4407 } 4408 4409 /** 4410 * Convert to PhonebookRecordInfo defined in radio/1.6/types.hal 4411 * @param record SimPhonebookRecord to convert 4412 * @return The converted PhonebookRecordInfo defined in radio/1.6/types.hal 4413 */ convertToHalPhonebookRecordInfo( SimPhonebookRecord record)4414 public static android.hardware.radio.V1_6.PhonebookRecordInfo convertToHalPhonebookRecordInfo( 4415 SimPhonebookRecord record) { 4416 if (record != null) { 4417 return record.toPhonebookRecordInfo(); 4418 } 4419 return null; 4420 } 4421 4422 /** 4423 * Convert to PhonebookRecordInfo.aidl 4424 * @param record SimPhonebookRecord to convert 4425 * @return The converted PhonebookRecordInfo 4426 */ 4427 public static android.hardware.radio.sim.PhonebookRecordInfo convertToHalPhonebookRecordInfoAidl(SimPhonebookRecord record)4428 convertToHalPhonebookRecordInfoAidl(SimPhonebookRecord record) { 4429 if (record != null) { 4430 return record.toPhonebookRecordInfoAidl(); 4431 } 4432 return new android.hardware.radio.sim.PhonebookRecordInfo(); 4433 } 4434 4435 /** 4436 * Convert array of SimSlotStatus to IccSlotStatus 4437 * @param o object that represents array/list of SimSlotStatus 4438 * @return ArrayList of IccSlotStatus 4439 */ convertHalSlotStatus(Object o)4440 public static ArrayList<IccSlotStatus> convertHalSlotStatus(Object o) { 4441 ArrayList<IccSlotStatus> response = new ArrayList<>(); 4442 try { 4443 final android.hardware.radio.config.SimSlotStatus[] halSlotStatusArray = 4444 (android.hardware.radio.config.SimSlotStatus[]) o; 4445 for (android.hardware.radio.config.SimSlotStatus slotStatus : halSlotStatusArray) { 4446 IccSlotStatus iccSlotStatus = new IccSlotStatus(); 4447 iccSlotStatus.setCardState(slotStatus.cardState); 4448 int portCount = slotStatus.portInfo.length; 4449 iccSlotStatus.mSimPortInfos = new IccSimPortInfo[portCount]; 4450 for (int i = 0; i < portCount; i++) { 4451 IccSimPortInfo simPortInfo = new IccSimPortInfo(); 4452 simPortInfo.mIccId = slotStatus.portInfo[i].iccId; 4453 // If port is not active, set invalid logical slot index(-1) irrespective of 4454 // the modem response. For more info, check http://b/209035150 4455 simPortInfo.mLogicalSlotIndex = slotStatus.portInfo[i].portActive 4456 ? slotStatus.portInfo[i].logicalSlotId : -1; 4457 simPortInfo.mPortActive = slotStatus.portInfo[i].portActive; 4458 iccSlotStatus.mSimPortInfos[i] = simPortInfo; 4459 } 4460 iccSlotStatus.atr = slotStatus.atr; 4461 iccSlotStatus.eid = slotStatus.eid; 4462 iccSlotStatus.setMultipleEnabledProfilesMode(slotStatus.supportedMepMode); 4463 response.add(iccSlotStatus); 4464 } 4465 return response; 4466 } catch (ClassCastException ignore) { } 4467 try { 4468 final ArrayList<android.hardware.radio.config.V1_2.SimSlotStatus> 4469 halSlotStatusArray = 4470 (ArrayList<android.hardware.radio.config.V1_2.SimSlotStatus>) o; 4471 for (android.hardware.radio.config.V1_2.SimSlotStatus slotStatus : 4472 halSlotStatusArray) { 4473 IccSlotStatus iccSlotStatus = new IccSlotStatus(); 4474 iccSlotStatus.setCardState(slotStatus.base.cardState); 4475 // Old HAL versions does not support MEP, so only one port is available. 4476 iccSlotStatus.mSimPortInfos = new IccSimPortInfo[1]; 4477 IccSimPortInfo simPortInfo = new IccSimPortInfo(); 4478 simPortInfo.mIccId = slotStatus.base.iccid; 4479 simPortInfo.mPortActive = (slotStatus.base.slotState == IccSlotStatus.STATE_ACTIVE); 4480 // If port/slot is not active, set invalid logical slot index(-1) irrespective of 4481 // the modem response. For more info, check http://b/209035150 4482 simPortInfo.mLogicalSlotIndex = simPortInfo.mPortActive 4483 ? slotStatus.base.logicalSlotId : -1; 4484 iccSlotStatus.mSimPortInfos[TelephonyManager.DEFAULT_PORT_INDEX] = simPortInfo; 4485 iccSlotStatus.atr = slotStatus.base.atr; 4486 iccSlotStatus.eid = slotStatus.eid; 4487 response.add(iccSlotStatus); 4488 } 4489 return response; 4490 } catch (ClassCastException ignore) { } 4491 try { 4492 final ArrayList<android.hardware.radio.config.V1_0.SimSlotStatus> 4493 halSlotStatusArray = 4494 (ArrayList<android.hardware.radio.config.V1_0.SimSlotStatus>) o; 4495 for (android.hardware.radio.config.V1_0.SimSlotStatus slotStatus : 4496 halSlotStatusArray) { 4497 IccSlotStatus iccSlotStatus = new IccSlotStatus(); 4498 iccSlotStatus.setCardState(slotStatus.cardState); 4499 // Old HAL versions does not support MEP, so only one port is available. 4500 iccSlotStatus.mSimPortInfos = new IccSimPortInfo[1]; 4501 IccSimPortInfo simPortInfo = new IccSimPortInfo(); 4502 simPortInfo.mIccId = slotStatus.iccid; 4503 simPortInfo.mPortActive = (slotStatus.slotState == IccSlotStatus.STATE_ACTIVE); 4504 // If port/slot is not active, set invalid logical slot index(-1) irrespective of 4505 // the modem response. For more info, check http://b/209035150 4506 simPortInfo.mLogicalSlotIndex = simPortInfo.mPortActive 4507 ? slotStatus.logicalSlotId : -1; 4508 iccSlotStatus.mSimPortInfos[TelephonyManager.DEFAULT_PORT_INDEX] = simPortInfo; 4509 iccSlotStatus.atr = slotStatus.atr; 4510 response.add(iccSlotStatus); 4511 } 4512 return response; 4513 } catch (ClassCastException ignore) { } 4514 return response; 4515 } 4516 4517 /** 4518 * Convert List<UiccSlotMapping> list to SlotPortMapping[] 4519 * @param slotMapping List<UiccSlotMapping> of slots mapping 4520 * @return SlotPortMapping[] of slots mapping 4521 */ convertSimSlotsMapping( List<UiccSlotMapping> slotMapping)4522 public static android.hardware.radio.config.SlotPortMapping[] convertSimSlotsMapping( 4523 List<UiccSlotMapping> slotMapping) { 4524 android.hardware.radio.config.SlotPortMapping[] res = 4525 new android.hardware.radio.config.SlotPortMapping[slotMapping.size()]; 4526 for (UiccSlotMapping mapping : slotMapping) { 4527 int logicalSlotIdx = mapping.getLogicalSlotIndex(); 4528 res[logicalSlotIdx] = new android.hardware.radio.config.SlotPortMapping(); 4529 res[logicalSlotIdx].physicalSlotId = mapping.getPhysicalSlotIndex(); 4530 res[logicalSlotIdx].portId = PortUtils.convertToHalPortIndex( 4531 mapping.getPhysicalSlotIndex(), mapping.getPortIndex()); 4532 } 4533 return res; 4534 } 4535 4536 /** Convert a list of UiccSlotMapping to an ArrayList<Integer>.*/ convertSlotMappingToList( List<UiccSlotMapping> slotMapping)4537 public static ArrayList<Integer> convertSlotMappingToList( 4538 List<UiccSlotMapping> slotMapping) { 4539 int[] physicalSlots = new int[slotMapping.size()]; 4540 for (UiccSlotMapping mapping : slotMapping) { 4541 physicalSlots[mapping.getLogicalSlotIndex()] = mapping.getPhysicalSlotIndex(); 4542 } 4543 return primitiveArrayToArrayList(physicalSlots); 4544 } 4545 4546 4547 /** 4548 * Convert PhoneCapability to telephony PhoneCapability. 4549 * @param deviceNrCapabilities device's nr capability array 4550 * @param o PhoneCapability to convert 4551 * @return converted PhoneCapability 4552 */ convertHalPhoneCapability(int[] deviceNrCapabilities, Object o)4553 public static PhoneCapability convertHalPhoneCapability(int[] deviceNrCapabilities, Object o) { 4554 int maxActiveVoiceCalls = 0; 4555 int maxActiveData = 0; 4556 boolean validationBeforeSwitchSupported = false; 4557 List<ModemInfo> logicalModemList = new ArrayList<>(); 4558 if (o instanceof android.hardware.radio.config.PhoneCapability) { 4559 final android.hardware.radio.config.PhoneCapability phoneCapability = 4560 (android.hardware.radio.config.PhoneCapability) o; 4561 maxActiveData = phoneCapability.maxActiveData; 4562 // If the maxActiveVoice field has been set, use that value. Otherwise, default to the 4563 // legacy behavior and rely on the maxActiveInternetData field: 4564 if (phoneCapability.maxActiveVoice == 4565 android.hardware.radio.config.PhoneCapability.UNKNOWN) { 4566 maxActiveVoiceCalls = phoneCapability.maxActiveInternetData; 4567 } else { 4568 maxActiveVoiceCalls = phoneCapability.maxActiveVoice; 4569 } 4570 validationBeforeSwitchSupported = phoneCapability.isInternetLingeringSupported; 4571 for (int modemId : phoneCapability.logicalModemIds) { 4572 logicalModemList.add(new ModemInfo(modemId)); 4573 } 4574 } else if (o instanceof android.hardware.radio.config.V1_1.PhoneCapability) { 4575 final android.hardware.radio.config.V1_1.PhoneCapability phoneCapability = 4576 (android.hardware.radio.config.V1_1.PhoneCapability) o; 4577 maxActiveData = phoneCapability.maxActiveData; 4578 // maxActiveInternetData defines how many logical modems can have internet PDN 4579 // connections simultaneously. For L+L DSDS modem it’s 1, and for DSDA modem it’s 2. 4580 maxActiveVoiceCalls = phoneCapability.maxActiveInternetData; 4581 validationBeforeSwitchSupported = phoneCapability.isInternetLingeringSupported; 4582 for (android.hardware.radio.config.V1_1.ModemInfo modemInfo : 4583 phoneCapability.logicalModemList) { 4584 logicalModemList.add(new ModemInfo(modemInfo.modemId)); 4585 } 4586 } 4587 return new PhoneCapability(maxActiveVoiceCalls, maxActiveData, logicalModemList, 4588 validationBeforeSwitchSupported, deviceNrCapabilities); 4589 } 4590 4591 /** 4592 * Convert network scan type 4593 * @param scanType The network scan type 4594 * @return The converted EmergencyScanType 4595 */ convertEmergencyScanType(int scanType)4596 public static int convertEmergencyScanType(int scanType) { 4597 switch (scanType) { 4598 case DomainSelectionService.SCAN_TYPE_LIMITED_SERVICE: 4599 return android.hardware.radio.network.EmergencyScanType.LIMITED_SERVICE; 4600 case DomainSelectionService.SCAN_TYPE_FULL_SERVICE: 4601 return android.hardware.radio.network.EmergencyScanType.FULL_SERVICE; 4602 default: 4603 return android.hardware.radio.network.EmergencyScanType.NO_PREFERENCE; 4604 } 4605 } 4606 4607 /** 4608 * Convert to EmergencyNetworkScanTrigger 4609 * @param accessNetwork The list of access network types 4610 * @param scanType The network scan type 4611 * @return The converted EmergencyNetworkScanTrigger 4612 */ 4613 public static android.hardware.radio.network.EmergencyNetworkScanTrigger convertEmergencyNetworkScanTrigger(@onNull int[] accessNetwork, int scanType)4614 convertEmergencyNetworkScanTrigger(@NonNull int[] accessNetwork, int scanType) { 4615 int[] halAccessNetwork = new int[accessNetwork.length]; 4616 for (int i = 0; i < accessNetwork.length; i++) { 4617 halAccessNetwork[i] = convertToHalAccessNetworkAidl(accessNetwork[i]); 4618 } 4619 4620 android.hardware.radio.network.EmergencyNetworkScanTrigger scanRequest = 4621 new android.hardware.radio.network.EmergencyNetworkScanTrigger(); 4622 4623 scanRequest.accessNetwork = halAccessNetwork; 4624 scanRequest.scanType = convertEmergencyScanType(scanType); 4625 return scanRequest; 4626 } 4627 4628 /** 4629 * Convert EmergencyRegResult.aidl to EmergencyRegistrationResult. 4630 * @param halResult EmergencyRegResult.aidl in HAL. 4631 * @return Converted EmergencyRegistrationResult. 4632 */ convertHalEmergencyRegResult( android.hardware.radio.network.EmergencyRegResult halResult)4633 public static EmergencyRegistrationResult convertHalEmergencyRegResult( 4634 android.hardware.radio.network.EmergencyRegResult halResult) { 4635 return new EmergencyRegistrationResult( 4636 halResult.accessNetwork, 4637 convertHalRegState(halResult.regState), 4638 halResult.emcDomain, 4639 halResult.isVopsSupported, 4640 halResult.isEmcBearerSupported, 4641 halResult.nwProvidedEmc, 4642 halResult.nwProvidedEmf, 4643 halResult.mcc, 4644 halResult.mnc, 4645 getCountryCodeForMccMnc(halResult.mcc, halResult.mnc)); 4646 } 4647 getCountryCodeForMccMnc( @onNull String mcc, @NonNull String mnc)4648 private static @NonNull String getCountryCodeForMccMnc( 4649 @NonNull String mcc, @NonNull String mnc) { 4650 if (TextUtils.isEmpty(mcc)) return ""; 4651 if (TextUtils.isEmpty(mnc)) mnc = "000"; 4652 String operatorNumeric = TextUtils.concat(mcc, mnc).toString(); 4653 4654 MccTable.MccMnc mccMnc = MccTable.MccMnc.fromOperatorNumeric(operatorNumeric); 4655 return MccTable.geoCountryCodeForMccMnc(mccMnc); 4656 } 4657 4658 /** 4659 * Convert RegResult.aidl to RegistrationState. 4660 * @param halRegState RegResult in HAL. 4661 * @return Converted RegistrationState. 4662 */ convertHalRegState( int halRegState)4663 public static @NetworkRegistrationInfo.RegistrationState int convertHalRegState( 4664 int halRegState) { 4665 switch (halRegState) { 4666 case android.hardware.radio.network.RegState.NOT_REG_MT_NOT_SEARCHING_OP: 4667 case android.hardware.radio.network.RegState.NOT_REG_MT_NOT_SEARCHING_OP_EM: 4668 return NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_OR_SEARCHING; 4669 case android.hardware.radio.network.RegState.REG_HOME: 4670 return NetworkRegistrationInfo.REGISTRATION_STATE_HOME; 4671 case android.hardware.radio.network.RegState.NOT_REG_MT_SEARCHING_OP: 4672 case android.hardware.radio.network.RegState.NOT_REG_MT_SEARCHING_OP_EM: 4673 return NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_SEARCHING; 4674 case android.hardware.radio.network.RegState.REG_DENIED: 4675 case android.hardware.radio.network.RegState.REG_DENIED_EM: 4676 return NetworkRegistrationInfo.REGISTRATION_STATE_DENIED; 4677 case android.hardware.radio.network.RegState.UNKNOWN: 4678 case android.hardware.radio.network.RegState.UNKNOWN_EM: 4679 return NetworkRegistrationInfo.REGISTRATION_STATE_UNKNOWN; 4680 case android.hardware.radio.network.RegState.REG_ROAMING: 4681 return NetworkRegistrationInfo.REGISTRATION_STATE_ROAMING; 4682 default: 4683 return NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_OR_SEARCHING; 4684 } 4685 } 4686 4687 /** Converts the array of network types to readable String array */ accessNetworkTypesToString( @onNull @ccessNetworkConstants.RadioAccessNetworkType int[] accessNetworkTypes)4688 public static @NonNull String accessNetworkTypesToString( 4689 @NonNull @AccessNetworkConstants.RadioAccessNetworkType int[] accessNetworkTypes) { 4690 int length = accessNetworkTypes.length; 4691 StringBuilder sb = new StringBuilder("{"); 4692 if (length > 0) { 4693 sb.append(Arrays.stream(accessNetworkTypes) 4694 .mapToObj(RILUtils::accessNetworkTypeToString) 4695 .collect(Collectors.joining(","))); 4696 } 4697 sb.append("}"); 4698 return sb.toString(); 4699 } 4700 accessNetworkTypeToString( @ccessNetworkConstants.RadioAccessNetworkType int accessNetworkType)4701 private static @NonNull String accessNetworkTypeToString( 4702 @AccessNetworkConstants.RadioAccessNetworkType int accessNetworkType) { 4703 switch (accessNetworkType) { 4704 case AccessNetworkConstants.AccessNetworkType.UNKNOWN: return "UNKNOWN"; 4705 case AccessNetworkConstants.AccessNetworkType.GERAN: return "GERAN"; 4706 case AccessNetworkConstants.AccessNetworkType.UTRAN: return "UTRAN"; 4707 case AccessNetworkConstants.AccessNetworkType.EUTRAN: return "EUTRAN"; 4708 case AccessNetworkConstants.AccessNetworkType.CDMA2000: return "CDMA2000"; 4709 case AccessNetworkConstants.AccessNetworkType.IWLAN: return "IWLAN"; 4710 case AccessNetworkConstants.AccessNetworkType.NGRAN: return "NGRAN"; 4711 default: return Integer.toString(accessNetworkType); 4712 } 4713 } 4714 4715 /** Converts scan type to readable String */ scanTypeToString( @omainSelectionService.EmergencyScanType int scanType)4716 public static @NonNull String scanTypeToString( 4717 @DomainSelectionService.EmergencyScanType int scanType) { 4718 switch (scanType) { 4719 case DomainSelectionService.SCAN_TYPE_LIMITED_SERVICE: 4720 return "LIMITED_SERVICE"; 4721 case DomainSelectionService.SCAN_TYPE_FULL_SERVICE: 4722 return "FULL_SERVICE"; 4723 default: 4724 return "NO_PREFERENCE"; 4725 } 4726 } 4727 4728 /** Convert IMS deregistration reason */ convertHalDeregistrationReason(int reason)4729 public static @ImsDeregistrationReason int convertHalDeregistrationReason(int reason) { 4730 switch (reason) { 4731 case android.hardware.radio.ims.ImsDeregistrationReason.REASON_SIM_REMOVED: 4732 return ImsRegistrationImplBase.REASON_SIM_REMOVED; 4733 case android.hardware.radio.ims.ImsDeregistrationReason.REASON_SIM_REFRESH: 4734 return ImsRegistrationImplBase.REASON_SIM_REFRESH; 4735 case android.hardware.radio.ims.ImsDeregistrationReason 4736 .REASON_ALLOWED_NETWORK_TYPES_CHANGED: 4737 return ImsRegistrationImplBase.REASON_ALLOWED_NETWORK_TYPES_CHANGED; 4738 default: 4739 return ImsRegistrationImplBase.REASON_UNKNOWN; 4740 } 4741 } 4742 4743 /** 4744 * Convert the IMS traffic type. 4745 * @param trafficType IMS traffic type like registration, voice, video, SMS, emergency, and etc. 4746 * @return The converted IMS traffic type. 4747 */ convertImsTrafficType(@mTelFeature.ImsTrafficType int trafficType)4748 public static int convertImsTrafficType(@MmTelFeature.ImsTrafficType int trafficType) { 4749 switch (trafficType) { 4750 case MmTelFeature.IMS_TRAFFIC_TYPE_EMERGENCY: 4751 return android.hardware.radio.ims.ImsTrafficType.EMERGENCY; 4752 case MmTelFeature.IMS_TRAFFIC_TYPE_EMERGENCY_SMS: 4753 return android.hardware.radio.ims.ImsTrafficType.EMERGENCY_SMS; 4754 case MmTelFeature.IMS_TRAFFIC_TYPE_VOICE: 4755 return android.hardware.radio.ims.ImsTrafficType.VOICE; 4756 case MmTelFeature.IMS_TRAFFIC_TYPE_VIDEO: 4757 return android.hardware.radio.ims.ImsTrafficType.VIDEO; 4758 case MmTelFeature.IMS_TRAFFIC_TYPE_SMS: 4759 return android.hardware.radio.ims.ImsTrafficType.SMS; 4760 case MmTelFeature.IMS_TRAFFIC_TYPE_REGISTRATION: 4761 return android.hardware.radio.ims.ImsTrafficType.REGISTRATION; 4762 } 4763 return android.hardware.radio.ims.ImsTrafficType.UT_XCAP; 4764 } 4765 4766 /** 4767 * Convert the IMS traffic direction. 4768 * @param trafficDirection Indicates the traffic direction. 4769 * @return The converted IMS traffic direction. 4770 */ convertImsTrafficDirection( @mTelFeature.ImsTrafficDirection int trafficDirection)4771 public static int convertImsTrafficDirection( 4772 @MmTelFeature.ImsTrafficDirection int trafficDirection) { 4773 switch (trafficDirection) { 4774 case MmTelFeature.IMS_TRAFFIC_DIRECTION_INCOMING: 4775 return android.hardware.radio.ims.ImsCall.Direction.INCOMING; 4776 default: 4777 return android.hardware.radio.ims.ImsCall.Direction.OUTGOING; 4778 } 4779 } 4780 4781 /** 4782 * Convert the IMS connection failure reason. 4783 * @param halReason Specifies the reason that IMS connection failed. 4784 * @return The converted IMS connection failure reason. 4785 */ convertHalConnectionFailureReason( int halReason)4786 public static @ConnectionFailureInfo.FailureReason int convertHalConnectionFailureReason( 4787 int halReason) { 4788 switch (halReason) { 4789 case android.hardware.radio.ims.ConnectionFailureInfo 4790 .ConnectionFailureReason.REASON_ACCESS_DENIED: 4791 return ConnectionFailureInfo.REASON_ACCESS_DENIED; 4792 case android.hardware.radio.ims.ConnectionFailureInfo 4793 .ConnectionFailureReason.REASON_NAS_FAILURE: 4794 return ConnectionFailureInfo.REASON_NAS_FAILURE; 4795 case android.hardware.radio.ims.ConnectionFailureInfo 4796 .ConnectionFailureReason.REASON_RACH_FAILURE: 4797 return ConnectionFailureInfo.REASON_RACH_FAILURE; 4798 case android.hardware.radio.ims.ConnectionFailureInfo 4799 .ConnectionFailureReason.REASON_RLC_FAILURE: 4800 return ConnectionFailureInfo.REASON_RLC_FAILURE; 4801 case android.hardware.radio.ims.ConnectionFailureInfo 4802 .ConnectionFailureReason.REASON_RRC_REJECT: 4803 return ConnectionFailureInfo.REASON_RRC_REJECT; 4804 case android.hardware.radio.ims.ConnectionFailureInfo 4805 .ConnectionFailureReason.REASON_RRC_TIMEOUT: 4806 return ConnectionFailureInfo.REASON_RRC_TIMEOUT; 4807 case android.hardware.radio.ims.ConnectionFailureInfo 4808 .ConnectionFailureReason.REASON_NO_SERVICE: 4809 return ConnectionFailureInfo.REASON_NO_SERVICE; 4810 case android.hardware.radio.ims.ConnectionFailureInfo 4811 .ConnectionFailureReason.REASON_PDN_NOT_AVAILABLE: 4812 return ConnectionFailureInfo.REASON_PDN_NOT_AVAILABLE; 4813 case android.hardware.radio.ims.ConnectionFailureInfo 4814 .ConnectionFailureReason.REASON_RF_BUSY: 4815 return ConnectionFailureInfo.REASON_RF_BUSY; 4816 } 4817 return ConnectionFailureInfo.REASON_UNSPECIFIED; 4818 } 4819 4820 /** Append the data to the end of an ArrayList */ appendPrimitiveArrayToArrayList(byte[] src, ArrayList<Byte> dst)4821 public static void appendPrimitiveArrayToArrayList(byte[] src, ArrayList<Byte> dst) { 4822 for (byte b : src) { 4823 dst.add(b); 4824 } 4825 } 4826 4827 /** Convert a primitive byte array to an ArrayList<Integer>. */ primitiveArrayToArrayList(byte[] arr)4828 public static ArrayList<Byte> primitiveArrayToArrayList(byte[] arr) { 4829 ArrayList<Byte> arrayList = new ArrayList<>(arr.length); 4830 for (byte b : arr) { 4831 arrayList.add(b); 4832 } 4833 return arrayList; 4834 } 4835 4836 /** Convert a primitive int array to an ArrayList<Integer>. */ primitiveArrayToArrayList(int[] arr)4837 public static ArrayList<Integer> primitiveArrayToArrayList(int[] arr) { 4838 ArrayList<Integer> arrayList = new ArrayList<>(arr.length); 4839 for (int i : arr) { 4840 arrayList.add(i); 4841 } 4842 return arrayList; 4843 } 4844 4845 /** Convert a primitive String array to an ArrayList<String>. */ primitiveArrayToArrayList(String[] arr)4846 public static ArrayList<String> primitiveArrayToArrayList(String[] arr) { 4847 return new ArrayList<>(Arrays.asList(arr)); 4848 } 4849 4850 /** Convert an ArrayList of Bytes to an exactly-sized primitive array */ arrayListToPrimitiveArray(ArrayList<Byte> bytes)4851 public static byte[] arrayListToPrimitiveArray(ArrayList<Byte> bytes) { 4852 byte[] ret = new byte[bytes.size()]; 4853 for (int i = 0; i < ret.length; i++) { 4854 ret[i] = bytes.get(i); 4855 } 4856 return ret; 4857 } 4858 4859 /** Convert null to an empty String */ convertNullToEmptyString(String string)4860 public static String convertNullToEmptyString(String string) { 4861 return string != null ? string : ""; 4862 } 4863 4864 /** 4865 * Convert setup data reason to string. 4866 * 4867 * @param reason The reason for setup data call. 4868 * @return The reason in string format. 4869 */ setupDataReasonToString(@etupDataReason int reason)4870 public static String setupDataReasonToString(@SetupDataReason int reason) { 4871 switch (reason) { 4872 case DataService.REQUEST_REASON_NORMAL: 4873 return "NORMAL"; 4874 case DataService.REQUEST_REASON_HANDOVER: 4875 return "HANDOVER"; 4876 case DataService.REQUEST_REASON_UNKNOWN: 4877 return "UNKNOWN"; 4878 default: 4879 return "UNKNOWN(" + reason + ")"; 4880 } 4881 } 4882 4883 /** 4884 * Convert deactivate data reason to string. 4885 * 4886 * @param reason The reason for deactivate data call. 4887 * @return The reason in string format. 4888 */ deactivateDataReasonToString(@eactivateDataReason int reason)4889 public static String deactivateDataReasonToString(@DeactivateDataReason int reason) { 4890 switch (reason) { 4891 case DataService.REQUEST_REASON_NORMAL: 4892 return "NORMAL"; 4893 case DataService.REQUEST_REASON_HANDOVER: 4894 return "HANDOVER"; 4895 case DataService.REQUEST_REASON_SHUTDOWN: 4896 return "SHUTDOWN"; 4897 case DataService.REQUEST_REASON_UNKNOWN: 4898 return "UNKNOWN"; 4899 default: 4900 return "UNKNOWN(" + reason + ")"; 4901 } 4902 } 4903 4904 /** 4905 * RIL request to String 4906 * @param request request 4907 * @return The converted String request 4908 */ requestToString(int request)4909 public static String requestToString(int request) { 4910 switch(request) { 4911 case RIL_REQUEST_GET_SIM_STATUS: 4912 return "GET_SIM_STATUS"; 4913 case RIL_REQUEST_ENTER_SIM_PIN: 4914 return "ENTER_SIM_PIN"; 4915 case RIL_REQUEST_ENTER_SIM_PUK: 4916 return "ENTER_SIM_PUK"; 4917 case RIL_REQUEST_ENTER_SIM_PIN2: 4918 return "ENTER_SIM_PIN2"; 4919 case RIL_REQUEST_ENTER_SIM_PUK2: 4920 return "ENTER_SIM_PUK2"; 4921 case RIL_REQUEST_CHANGE_SIM_PIN: 4922 return "CHANGE_SIM_PIN"; 4923 case RIL_REQUEST_CHANGE_SIM_PIN2: 4924 return "CHANGE_SIM_PIN2"; 4925 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: 4926 return "ENTER_NETWORK_DEPERSONALIZATION"; 4927 case RIL_REQUEST_GET_CURRENT_CALLS: 4928 return "GET_CURRENT_CALLS"; 4929 case RIL_REQUEST_DIAL: 4930 return "DIAL"; 4931 case RIL_REQUEST_GET_IMSI: 4932 return "GET_IMSI"; 4933 case RIL_REQUEST_HANGUP: 4934 return "HANGUP"; 4935 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: 4936 return "HANGUP_WAITING_OR_BACKGROUND"; 4937 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: 4938 return "HANGUP_FOREGROUND_RESUME_BACKGROUND"; 4939 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: 4940 return "REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE"; 4941 case RIL_REQUEST_CONFERENCE: 4942 return "CONFERENCE"; 4943 case RIL_REQUEST_UDUB: 4944 return "UDUB"; 4945 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: 4946 return "LAST_CALL_FAIL_CAUSE"; 4947 case RIL_REQUEST_SIGNAL_STRENGTH: 4948 return "SIGNAL_STRENGTH"; 4949 case RIL_REQUEST_VOICE_REGISTRATION_STATE: 4950 return "VOICE_REGISTRATION_STATE"; 4951 case RIL_REQUEST_DATA_REGISTRATION_STATE: 4952 return "DATA_REGISTRATION_STATE"; 4953 case RIL_REQUEST_OPERATOR: 4954 return "OPERATOR"; 4955 case RIL_REQUEST_RADIO_POWER: 4956 return "RADIO_POWER"; 4957 case RIL_REQUEST_DTMF: 4958 return "DTMF"; 4959 case RIL_REQUEST_SEND_SMS: 4960 return "SEND_SMS"; 4961 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: 4962 return "SEND_SMS_EXPECT_MORE"; 4963 case RIL_REQUEST_SETUP_DATA_CALL: 4964 return "SETUP_DATA_CALL"; 4965 case RIL_REQUEST_SIM_IO: 4966 return "SIM_IO"; 4967 case RIL_REQUEST_SEND_USSD: 4968 return "SEND_USSD"; 4969 case RIL_REQUEST_CANCEL_USSD: 4970 return "CANCEL_USSD"; 4971 case RIL_REQUEST_GET_CLIR: 4972 return "GET_CLIR"; 4973 case RIL_REQUEST_SET_CLIR: 4974 return "SET_CLIR"; 4975 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: 4976 return "QUERY_CALL_FORWARD_STATUS"; 4977 case RIL_REQUEST_SET_CALL_FORWARD: 4978 return "SET_CALL_FORWARD"; 4979 case RIL_REQUEST_QUERY_CALL_WAITING: 4980 return "QUERY_CALL_WAITING"; 4981 case RIL_REQUEST_SET_CALL_WAITING: 4982 return "SET_CALL_WAITING"; 4983 case RIL_REQUEST_SMS_ACKNOWLEDGE: 4984 return "SMS_ACKNOWLEDGE"; 4985 case RIL_REQUEST_GET_IMEI: 4986 return "GET_IMEI"; 4987 case RIL_REQUEST_GET_IMEISV: 4988 return "GET_IMEISV"; 4989 case RIL_REQUEST_ANSWER: 4990 return "ANSWER"; 4991 case RIL_REQUEST_DEACTIVATE_DATA_CALL: 4992 return "DEACTIVATE_DATA_CALL"; 4993 case RIL_REQUEST_QUERY_FACILITY_LOCK: 4994 return "QUERY_FACILITY_LOCK"; 4995 case RIL_REQUEST_SET_FACILITY_LOCK: 4996 return "SET_FACILITY_LOCK"; 4997 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: 4998 return "CHANGE_BARRING_PASSWORD"; 4999 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: 5000 return "QUERY_NETWORK_SELECTION_MODE"; 5001 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: 5002 return "SET_NETWORK_SELECTION_AUTOMATIC"; 5003 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: 5004 return "SET_NETWORK_SELECTION_MANUAL"; 5005 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : 5006 return "QUERY_AVAILABLE_NETWORKS "; 5007 case RIL_REQUEST_DTMF_START: 5008 return "DTMF_START"; 5009 case RIL_REQUEST_DTMF_STOP: 5010 return "DTMF_STOP"; 5011 case RIL_REQUEST_BASEBAND_VERSION: 5012 return "BASEBAND_VERSION"; 5013 case RIL_REQUEST_SEPARATE_CONNECTION: 5014 return "SEPARATE_CONNECTION"; 5015 case RIL_REQUEST_SET_MUTE: 5016 return "SET_MUTE"; 5017 case RIL_REQUEST_GET_MUTE: 5018 return "GET_MUTE"; 5019 case RIL_REQUEST_QUERY_CLIP: 5020 return "QUERY_CLIP"; 5021 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: 5022 return "LAST_DATA_CALL_FAIL_CAUSE"; 5023 case RIL_REQUEST_DATA_CALL_LIST: 5024 return "DATA_CALL_LIST"; 5025 case RIL_REQUEST_RESET_RADIO: 5026 return "RESET_RADIO"; 5027 case RIL_REQUEST_OEM_HOOK_RAW: 5028 return "OEM_HOOK_RAW"; 5029 case RIL_REQUEST_OEM_HOOK_STRINGS: 5030 return "OEM_HOOK_STRINGS"; 5031 case RIL_REQUEST_SCREEN_STATE: 5032 return "SCREEN_STATE"; 5033 case RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION: 5034 return "SET_SUPP_SVC_NOTIFICATION"; 5035 case RIL_REQUEST_WRITE_SMS_TO_SIM: 5036 return "WRITE_SMS_TO_SIM"; 5037 case RIL_REQUEST_DELETE_SMS_ON_SIM: 5038 return "DELETE_SMS_ON_SIM"; 5039 case RIL_REQUEST_SET_BAND_MODE: 5040 return "SET_BAND_MODE"; 5041 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: 5042 return "QUERY_AVAILABLE_BAND_MODE"; 5043 case RIL_REQUEST_STK_GET_PROFILE: 5044 return "STK_GET_PROFILE"; 5045 case RIL_REQUEST_STK_SET_PROFILE: 5046 return "STK_SET_PROFILE"; 5047 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: 5048 return "STK_SEND_ENVELOPE_COMMAND"; 5049 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: 5050 return "STK_SEND_TERMINAL_RESPONSE"; 5051 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: 5052 return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM"; 5053 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: 5054 return "EXPLICIT_CALL_TRANSFER"; 5055 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: 5056 return "SET_PREFERRED_NETWORK_TYPE"; 5057 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: 5058 return "GET_PREFERRED_NETWORK_TYPE"; 5059 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: 5060 return "GET_NEIGHBORING_CELL_IDS"; 5061 case RIL_REQUEST_SET_LOCATION_UPDATES: 5062 return "SET_LOCATION_UPDATES"; 5063 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE: 5064 return "CDMA_SET_SUBSCRIPTION_SOURCE"; 5065 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE: 5066 return "CDMA_SET_ROAMING_PREFERENCE"; 5067 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE: 5068 return "CDMA_QUERY_ROAMING_PREFERENCE"; 5069 case RIL_REQUEST_SET_TTY_MODE: 5070 return "SET_TTY_MODE"; 5071 case RIL_REQUEST_QUERY_TTY_MODE: 5072 return "QUERY_TTY_MODE"; 5073 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE: 5074 return "CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE"; 5075 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE: 5076 return "CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE"; 5077 case RIL_REQUEST_CDMA_FLASH: 5078 return "CDMA_FLASH"; 5079 case RIL_REQUEST_CDMA_BURST_DTMF: 5080 return "CDMA_BURST_DTMF"; 5081 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: 5082 return "CDMA_VALIDATE_AND_WRITE_AKEY"; 5083 case RIL_REQUEST_CDMA_SEND_SMS: 5084 return "CDMA_SEND_SMS"; 5085 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE: 5086 return "CDMA_SMS_ACKNOWLEDGE"; 5087 case RIL_REQUEST_GSM_GET_BROADCAST_CONFIG: 5088 return "GSM_GET_BROADCAST_CONFIG"; 5089 case RIL_REQUEST_GSM_SET_BROADCAST_CONFIG: 5090 return "GSM_SET_BROADCAST_CONFIG"; 5091 case RIL_REQUEST_GSM_BROADCAST_ACTIVATION: 5092 return "GSM_BROADCAST_ACTIVATION"; 5093 case RIL_REQUEST_CDMA_GET_BROADCAST_CONFIG: 5094 return "CDMA_GET_BROADCAST_CONFIG"; 5095 case RIL_REQUEST_CDMA_SET_BROADCAST_CONFIG: 5096 return "CDMA_SET_BROADCAST_CONFIG"; 5097 case RIL_REQUEST_CDMA_BROADCAST_ACTIVATION: 5098 return "CDMA_BROADCAST_ACTIVATION"; 5099 case RIL_REQUEST_CDMA_SUBSCRIPTION: 5100 return "CDMA_SUBSCRIPTION"; 5101 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: 5102 return "CDMA_WRITE_SMS_TO_RUIM"; 5103 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: 5104 return "CDMA_DELETE_SMS_ON_RUIM"; 5105 case RIL_REQUEST_DEVICE_IDENTITY: 5106 return "DEVICE_IDENTITY"; 5107 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: 5108 return "EXIT_EMERGENCY_CALLBACK_MODE"; 5109 case RIL_REQUEST_GET_SMSC_ADDRESS: 5110 return "GET_SMSC_ADDRESS"; 5111 case RIL_REQUEST_SET_SMSC_ADDRESS: 5112 return "SET_SMSC_ADDRESS"; 5113 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: 5114 return "REPORT_SMS_MEMORY_STATUS"; 5115 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: 5116 return "REPORT_STK_SERVICE_IS_RUNNING"; 5117 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: 5118 return "CDMA_GET_SUBSCRIPTION_SOURCE"; 5119 case RIL_REQUEST_ISIM_AUTHENTICATION: 5120 return "ISIM_AUTHENTICATION"; 5121 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: 5122 return "ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU"; 5123 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: 5124 return "STK_SEND_ENVELOPE_WITH_STATUS"; 5125 case RIL_REQUEST_VOICE_RADIO_TECH: 5126 return "VOICE_RADIO_TECH"; 5127 case RIL_REQUEST_GET_CELL_INFO_LIST: 5128 return "GET_CELL_INFO_LIST"; 5129 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: 5130 return "SET_CELL_INFO_LIST_RATE"; 5131 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: 5132 return "SET_INITIAL_ATTACH_APN"; 5133 case RIL_REQUEST_IMS_REGISTRATION_STATE: 5134 return "IMS_REGISTRATION_STATE"; 5135 case RIL_REQUEST_IMS_SEND_SMS: 5136 return "IMS_SEND_SMS"; 5137 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: 5138 return "SIM_TRANSMIT_APDU_BASIC"; 5139 case RIL_REQUEST_SIM_OPEN_CHANNEL: 5140 return "SIM_OPEN_CHANNEL"; 5141 case RIL_REQUEST_SIM_CLOSE_CHANNEL: 5142 return "SIM_CLOSE_CHANNEL"; 5143 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: 5144 return "SIM_TRANSMIT_APDU_CHANNEL"; 5145 case RIL_REQUEST_NV_READ_ITEM: 5146 return "NV_READ_ITEM"; 5147 case RIL_REQUEST_NV_WRITE_ITEM: 5148 return "NV_WRITE_ITEM"; 5149 case RIL_REQUEST_NV_WRITE_CDMA_PRL: 5150 return "NV_WRITE_CDMA_PRL"; 5151 case RIL_REQUEST_NV_RESET_CONFIG: 5152 return "NV_RESET_CONFIG"; 5153 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: 5154 return "SET_UICC_SUBSCRIPTION"; 5155 case RIL_REQUEST_ALLOW_DATA: 5156 return "ALLOW_DATA"; 5157 case RIL_REQUEST_GET_HARDWARE_CONFIG: 5158 return "GET_HARDWARE_CONFIG"; 5159 case RIL_REQUEST_SIM_AUTHENTICATION: 5160 return "SIM_AUTHENTICATION"; 5161 case RIL_REQUEST_GET_DC_RT_INFO: 5162 return "GET_DC_RT_INFO"; 5163 case RIL_REQUEST_SET_DC_RT_INFO_RATE: 5164 return "SET_DC_RT_INFO_RATE"; 5165 case RIL_REQUEST_SET_DATA_PROFILE: 5166 return "SET_DATA_PROFILE"; 5167 case RIL_REQUEST_SHUTDOWN: 5168 return "SHUTDOWN"; 5169 case RIL_REQUEST_GET_RADIO_CAPABILITY: 5170 return "GET_RADIO_CAPABILITY"; 5171 case RIL_REQUEST_SET_RADIO_CAPABILITY: 5172 return "SET_RADIO_CAPABILITY"; 5173 case RIL_REQUEST_START_LCE: 5174 return "START_LCE"; 5175 case RIL_REQUEST_STOP_LCE: 5176 return "STOP_LCE"; 5177 case RIL_REQUEST_PULL_LCEDATA: 5178 return "PULL_LCEDATA"; 5179 case RIL_REQUEST_GET_ACTIVITY_INFO: 5180 return "GET_ACTIVITY_INFO"; 5181 case RIL_REQUEST_SET_ALLOWED_CARRIERS: 5182 return "SET_ALLOWED_CARRIERS"; 5183 case RIL_REQUEST_GET_ALLOWED_CARRIERS: 5184 return "GET_ALLOWED_CARRIERS"; 5185 case RIL_REQUEST_SEND_DEVICE_STATE: 5186 return "SEND_DEVICE_STATE"; 5187 case RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER: 5188 return "SET_UNSOLICITED_RESPONSE_FILTER"; 5189 case RIL_REQUEST_SET_SIM_CARD_POWER: 5190 return "SET_SIM_CARD_POWER"; 5191 case RIL_REQUEST_SET_CARRIER_INFO_IMSI_ENCRYPTION: 5192 return "SET_CARRIER_INFO_IMSI_ENCRYPTION"; 5193 case RIL_REQUEST_START_NETWORK_SCAN: 5194 return "START_NETWORK_SCAN"; 5195 case RIL_REQUEST_STOP_NETWORK_SCAN: 5196 return "STOP_NETWORK_SCAN"; 5197 case RIL_REQUEST_START_KEEPALIVE: 5198 return "START_KEEPALIVE"; 5199 case RIL_REQUEST_STOP_KEEPALIVE: 5200 return "STOP_KEEPALIVE"; 5201 case RIL_REQUEST_ENABLE_MODEM: 5202 return "ENABLE_MODEM"; 5203 case RIL_REQUEST_GET_MODEM_STATUS: 5204 return "GET_MODEM_STATUS"; 5205 case RIL_REQUEST_CDMA_SEND_SMS_EXPECT_MORE: 5206 return "CDMA_SEND_SMS_EXPECT_MORE"; 5207 case RIL_REQUEST_GET_SIM_PHONEBOOK_CAPACITY: 5208 return "GET_SIM_PHONEBOOK_CAPACITY"; 5209 case RIL_REQUEST_GET_SIM_PHONEBOOK_RECORDS: 5210 return "GET_SIM_PHONEBOOK_RECORDS"; 5211 case RIL_REQUEST_UPDATE_SIM_PHONEBOOK_RECORD: 5212 return "UPDATE_SIM_PHONEBOOK_RECORD"; 5213 case RIL_REQUEST_DEVICE_IMEI: 5214 return "DEVICE_IMEI"; 5215 /* The following requests are not defined in RIL.h */ 5216 case RIL_REQUEST_GET_SLOT_STATUS: 5217 return "GET_SLOT_STATUS"; 5218 case RIL_REQUEST_SET_LOGICAL_TO_PHYSICAL_SLOT_MAPPING: 5219 return "SET_LOGICAL_TO_PHYSICAL_SLOT_MAPPING"; 5220 case RIL_REQUEST_SET_SIGNAL_STRENGTH_REPORTING_CRITERIA: 5221 return "SET_SIGNAL_STRENGTH_REPORTING_CRITERIA"; 5222 case RIL_REQUEST_SET_LINK_CAPACITY_REPORTING_CRITERIA: 5223 return "SET_LINK_CAPACITY_REPORTING_CRITERIA"; 5224 case RIL_REQUEST_SET_PREFERRED_DATA_MODEM: 5225 return "SET_PREFERRED_DATA_MODEM"; 5226 case RIL_REQUEST_EMERGENCY_DIAL: 5227 return "EMERGENCY_DIAL"; 5228 case RIL_REQUEST_GET_PHONE_CAPABILITY: 5229 return "GET_PHONE_CAPABILITY"; 5230 case RIL_REQUEST_SWITCH_DUAL_SIM_CONFIG: 5231 return "SWITCH_DUAL_SIM_CONFIG"; 5232 case RIL_REQUEST_ENABLE_UICC_APPLICATIONS: 5233 return "ENABLE_UICC_APPLICATIONS"; 5234 case RIL_REQUEST_GET_UICC_APPLICATIONS_ENABLEMENT: 5235 return "GET_UICC_APPLICATIONS_ENABLEMENT"; 5236 case RIL_REQUEST_SET_SYSTEM_SELECTION_CHANNELS: 5237 return "SET_SYSTEM_SELECTION_CHANNELS"; 5238 case RIL_REQUEST_GET_BARRING_INFO: 5239 return "GET_BARRING_INFO"; 5240 case RIL_REQUEST_ENTER_SIM_DEPERSONALIZATION: 5241 return "ENTER_SIM_DEPERSONALIZATION"; 5242 case RIL_REQUEST_ENABLE_NR_DUAL_CONNECTIVITY: 5243 return "ENABLE_NR_DUAL_CONNECTIVITY"; 5244 case RIL_REQUEST_IS_NR_DUAL_CONNECTIVITY_ENABLED: 5245 return "IS_NR_DUAL_CONNECTIVITY_ENABLED"; 5246 case RIL_REQUEST_ALLOCATE_PDU_SESSION_ID: 5247 return "ALLOCATE_PDU_SESSION_ID"; 5248 case RIL_REQUEST_RELEASE_PDU_SESSION_ID: 5249 return "RELEASE_PDU_SESSION_ID"; 5250 case RIL_REQUEST_START_HANDOVER: 5251 return "START_HANDOVER"; 5252 case RIL_REQUEST_CANCEL_HANDOVER: 5253 return "CANCEL_HANDOVER"; 5254 case RIL_REQUEST_GET_SYSTEM_SELECTION_CHANNELS: 5255 return "GET_SYSTEM_SELECTION_CHANNELS"; 5256 case RIL_REQUEST_GET_HAL_DEVICE_CAPABILITIES: 5257 return "GET_HAL_DEVICE_CAPABILITIES"; 5258 case RIL_REQUEST_SET_DATA_THROTTLING: 5259 return "SET_DATA_THROTTLING"; 5260 case RIL_REQUEST_SET_ALLOWED_NETWORK_TYPES_BITMAP: 5261 return "SET_ALLOWED_NETWORK_TYPES_BITMAP"; 5262 case RIL_REQUEST_GET_ALLOWED_NETWORK_TYPES_BITMAP: 5263 return "GET_ALLOWED_NETWORK_TYPES_BITMAP"; 5264 case RIL_REQUEST_GET_SLICING_CONFIG: 5265 return "GET_SLICING_CONFIG"; 5266 case RIL_REQUEST_ENABLE_VONR: 5267 return "ENABLE_VONR"; 5268 case RIL_REQUEST_IS_VONR_ENABLED: 5269 return "IS_VONR_ENABLED"; 5270 case RIL_REQUEST_SET_USAGE_SETTING: 5271 return "SET_USAGE_SETTING"; 5272 case RIL_REQUEST_GET_USAGE_SETTING: 5273 return "GET_USAGE_SETTING"; 5274 case RIL_REQUEST_SET_EMERGENCY_MODE: 5275 return "SET_EMERGENCY_MODE"; 5276 case RIL_REQUEST_TRIGGER_EMERGENCY_NETWORK_SCAN: 5277 return "TRIGGER_EMERGENCY_NETWORK_SCAN"; 5278 case RIL_REQUEST_CANCEL_EMERGENCY_NETWORK_SCAN: 5279 return "CANCEL_EMERGENCY_NETWORK_SCAN"; 5280 case RIL_REQUEST_EXIT_EMERGENCY_MODE: 5281 return "EXIT_EMERGENCY_MODE"; 5282 case RIL_REQUEST_SET_SRVCC_CALL_INFO: 5283 return "SET_SRVCC_CALL_INFO"; 5284 case RIL_REQUEST_UPDATE_IMS_REGISTRATION_INFO: 5285 return "UPDATE_IMS_REGISTRATION_INFO"; 5286 case RIL_REQUEST_START_IMS_TRAFFIC: 5287 return "START_IMS_TRAFFIC"; 5288 case RIL_REQUEST_STOP_IMS_TRAFFIC: 5289 return "STOP_IMS_TRAFFIC"; 5290 case RIL_REQUEST_SEND_ANBR_QUERY: 5291 return "SEND_ANBR_QUERY"; 5292 case RIL_REQUEST_TRIGGER_EPS_FALLBACK: 5293 return "TRIGGER_EPS_FALLBACK"; 5294 case RIL_REQUEST_SET_NULL_CIPHER_AND_INTEGRITY_ENABLED: 5295 return "SET_NULL_CIPHER_AND_INTEGRITY_ENABLED"; 5296 case RIL_REQUEST_IS_NULL_CIPHER_AND_INTEGRITY_ENABLED: 5297 return "IS_NULL_CIPHER_AND_INTEGRITY_ENABLED"; 5298 case RIL_REQUEST_UPDATE_IMS_CALL_STATUS: 5299 return "UPDATE_IMS_CALL_STATUS"; 5300 case RIL_REQUEST_SET_N1_MODE_ENABLED: 5301 return "SET_N1_MODE_ENABLED"; 5302 case RIL_REQUEST_IS_N1_MODE_ENABLED: 5303 return "IS_N1_MODE_ENABLED"; 5304 case RIL_REQUEST_SET_LOCATION_PRIVACY_SETTING: 5305 return "SET_LOCATION_PRIVACY_SETTING"; 5306 case RIL_REQUEST_GET_LOCATION_PRIVACY_SETTING: 5307 return "GET_LOCATION_PRIVACY_SETTING"; 5308 case RIL_REQUEST_IS_CELLULAR_IDENTIFIER_DISCLOSED_ENABLED: 5309 return "IS_CELLULAR_IDENTIFIER_DISCLOSED_ENABLED"; 5310 case RIL_REQUEST_SET_CELLULAR_IDENTIFIER_DISCLOSED_ENABLED: 5311 return "SET_CELLULAR_IDENTIFIER_DISCLOSED_ENABLED"; 5312 case RIL_REQUEST_SET_SECURITY_ALGORITHMS_UPDATED_ENABLED: 5313 return "SET_SECURITY_ALGORITHMS_UPDATED_ENABLED"; 5314 case RIL_REQUEST_IS_SECURITY_ALGORITHMS_UPDATED_ENABLED: 5315 return "IS_SECURITY_ALGORITHMS_UPDATED_ENABLED"; 5316 case RIL_REQUEST_GET_SIMULTANEOUS_CALLING_SUPPORT: 5317 return "GET_SIMULTANEOUS_CALLING_SUPPORT"; 5318 case RIL_REQUEST_SET_SATELLITE_PLMN: 5319 return "SET_SATELLITE_PLMN"; 5320 case RIL_REQUEST_SET_SATELLITE_ENABLED_FOR_CARRIER: 5321 return "SET_SATELLITE_ENABLED_FOR_CARRIER"; 5322 case RIL_REQUEST_IS_SATELLITE_ENABLED_FOR_CARRIER: 5323 return "IS_SATELLITE_ENABLED_FOR_CARRIER"; 5324 default: 5325 return "<unknown request " + request + ">"; 5326 } 5327 } 5328 5329 /** 5330 * RIL response to String 5331 * @param response response 5332 * @return The converted String response 5333 */ responseToString(int response)5334 public static String responseToString(int response) { 5335 switch (response) { 5336 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: 5337 return "UNSOL_RESPONSE_RADIO_STATE_CHANGED"; 5338 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: 5339 return "UNSOL_RESPONSE_CALL_STATE_CHANGED"; 5340 case RIL_UNSOL_RESPONSE_NETWORK_STATE_CHANGED: 5341 return "UNSOL_RESPONSE_NETWORK_STATE_CHANGED"; 5342 case RIL_UNSOL_RESPONSE_NEW_SMS: 5343 return "UNSOL_RESPONSE_NEW_SMS"; 5344 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: 5345 return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT"; 5346 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: 5347 return "UNSOL_RESPONSE_NEW_SMS_ON_SIM"; 5348 case RIL_UNSOL_ON_USSD: 5349 return "UNSOL_ON_USSD"; 5350 case RIL_UNSOL_ON_USSD_REQUEST: 5351 return "UNSOL_ON_USSD_REQUEST"; 5352 case RIL_UNSOL_NITZ_TIME_RECEIVED: 5353 return "UNSOL_NITZ_TIME_RECEIVED"; 5354 case RIL_UNSOL_SIGNAL_STRENGTH: 5355 return "UNSOL_SIGNAL_STRENGTH"; 5356 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: 5357 return "UNSOL_DATA_CALL_LIST_CHANGED"; 5358 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: 5359 return "UNSOL_SUPP_SVC_NOTIFICATION"; 5360 case RIL_UNSOL_STK_SESSION_END: 5361 return "UNSOL_STK_SESSION_END"; 5362 case RIL_UNSOL_STK_PROACTIVE_COMMAND: 5363 return "UNSOL_STK_PROACTIVE_COMMAND"; 5364 case RIL_UNSOL_STK_EVENT_NOTIFY: 5365 return "UNSOL_STK_EVENT_NOTIFY"; 5366 case RIL_UNSOL_STK_CALL_SETUP: 5367 return "UNSOL_STK_CALL_SETUP"; 5368 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: 5369 return "UNSOL_SIM_SMS_STORAGE_FULL"; 5370 case RIL_UNSOL_SIM_REFRESH: 5371 return "UNSOL_SIM_REFRESH"; 5372 case RIL_UNSOL_CALL_RING: 5373 return "UNSOL_CALL_RING"; 5374 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: 5375 return "UNSOL_RESPONSE_SIM_STATUS_CHANGED"; 5376 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: 5377 return "UNSOL_RESPONSE_CDMA_NEW_SMS"; 5378 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: 5379 return "UNSOL_RESPONSE_NEW_BROADCAST_SMS"; 5380 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: 5381 return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL"; 5382 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: 5383 return "UNSOL_RESTRICTED_STATE_CHANGED"; 5384 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: 5385 return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE"; 5386 case RIL_UNSOL_CDMA_CALL_WAITING: 5387 return "UNSOL_CDMA_CALL_WAITING"; 5388 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: 5389 return "UNSOL_CDMA_OTA_PROVISION_STATUS"; 5390 case RIL_UNSOL_CDMA_INFO_REC: 5391 return "UNSOL_CDMA_INFO_REC"; 5392 case RIL_UNSOL_OEM_HOOK_RAW: 5393 return "UNSOL_OEM_HOOK_RAW"; 5394 case RIL_UNSOL_RINGBACK_TONE: 5395 return "UNSOL_RINGBACK_TONE"; 5396 case RIL_UNSOL_RESEND_INCALL_MUTE: 5397 return "UNSOL_RESEND_INCALL_MUTE"; 5398 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: 5399 return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED"; 5400 case RIL_UNSOL_CDMA_PRL_CHANGED: 5401 return "UNSOL_CDMA_PRL_CHANGED"; 5402 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: 5403 return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE"; 5404 case RIL_UNSOL_RIL_CONNECTED: 5405 return "UNSOL_RIL_CONNECTED"; 5406 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: 5407 return "UNSOL_VOICE_RADIO_TECH_CHANGED"; 5408 case RIL_UNSOL_CELL_INFO_LIST: 5409 return "UNSOL_CELL_INFO_LIST"; 5410 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: 5411 return "UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED"; 5412 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: 5413 return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED"; 5414 case RIL_UNSOL_SRVCC_STATE_NOTIFY: 5415 return "UNSOL_SRVCC_STATE_NOTIFY"; 5416 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: 5417 return "UNSOL_HARDWARE_CONFIG_CHANGED"; 5418 case RIL_UNSOL_DC_RT_INFO_CHANGED: 5419 return "UNSOL_DC_RT_INFO_CHANGED"; 5420 case RIL_UNSOL_RADIO_CAPABILITY: 5421 return "UNSOL_RADIO_CAPABILITY"; 5422 case RIL_UNSOL_ON_SS: 5423 return "UNSOL_ON_SS"; 5424 case RIL_UNSOL_STK_CC_ALPHA_NOTIFY: 5425 return "UNSOL_STK_CC_ALPHA_NOTIFY"; 5426 case RIL_UNSOL_LCEDATA_RECV: 5427 return "UNSOL_LCE_INFO_RECV"; 5428 case RIL_UNSOL_PCO_DATA: 5429 return "UNSOL_PCO_DATA"; 5430 case RIL_UNSOL_MODEM_RESTART: 5431 return "UNSOL_MODEM_RESTART"; 5432 case RIL_UNSOL_CARRIER_INFO_IMSI_ENCRYPTION: 5433 return "UNSOL_CARRIER_INFO_IMSI_ENCRYPTION"; 5434 case RIL_UNSOL_NETWORK_SCAN_RESULT: 5435 return "UNSOL_NETWORK_SCAN_RESULT"; 5436 case RIL_UNSOL_KEEPALIVE_STATUS: 5437 return "UNSOL_KEEPALIVE_STATUS"; 5438 case RIL_UNSOL_UNTHROTTLE_APN: 5439 return "UNSOL_UNTHROTTLE_APN"; 5440 case RIL_UNSOL_RESPONSE_SIM_PHONEBOOK_CHANGED: 5441 return "UNSOL_RESPONSE_SIM_PHONEBOOK_CHANGED"; 5442 case RIL_UNSOL_RESPONSE_SIM_PHONEBOOK_RECORDS_RECEIVED: 5443 return "UNSOL_RESPONSE_SIM_PHONEBOOK_RECORDS_RECEIVED"; 5444 case RIL_UNSOL_SLICING_CONFIG_CHANGED: 5445 return "UNSOL_SLICING_CONFIG_CHANGED"; 5446 case RIL_UNSOL_CELLULAR_IDENTIFIER_DISCLOSED: 5447 return "UNSOL_CELLULAR_IDENTIFIER_DISCLOSED"; 5448 case RIL_UNSOL_SECURITY_ALGORITHMS_UPDATED: 5449 return "UNSOL_SECURITY_ALGORITHMS_UPDATED"; 5450 /* The follow unsols are not defined in RIL.h */ 5451 case RIL_UNSOL_ICC_SLOT_STATUS: 5452 return "UNSOL_ICC_SLOT_STATUS"; 5453 case RIL_UNSOL_PHYSICAL_CHANNEL_CONFIG: 5454 return "UNSOL_PHYSICAL_CHANNEL_CONFIG"; 5455 case RIL_UNSOL_EMERGENCY_NUMBER_LIST: 5456 return "UNSOL_EMERGENCY_NUMBER_LIST"; 5457 case RIL_UNSOL_UICC_APPLICATIONS_ENABLEMENT_CHANGED: 5458 return "UNSOL_UICC_APPLICATIONS_ENABLEMENT_CHANGED"; 5459 case RIL_UNSOL_REGISTRATION_FAILED: 5460 return "UNSOL_REGISTRATION_FAILED"; 5461 case RIL_UNSOL_BARRING_INFO_CHANGED: 5462 return "UNSOL_BARRING_INFO_CHANGED"; 5463 case RIL_UNSOL_EMERGENCY_NETWORK_SCAN_RESULT: 5464 return "UNSOL_EMERGENCY_NETWORK_SCAN_RESULT"; 5465 case RIL_UNSOL_CONNECTION_SETUP_FAILURE: 5466 return "UNSOL_CONNECTION_SETUP_FAILURE"; 5467 case RIL_UNSOL_NOTIFY_ANBR: 5468 return "UNSOL_NOTIFY_ANBR"; 5469 case RIL_UNSOL_TRIGGER_IMS_DEREGISTRATION: 5470 return "UNSOL_TRIGGER_IMS_DEREGISTRATION"; 5471 case RIL_UNSOL_IMEI_MAPPING_CHANGED: 5472 return "UNSOL_IMEI_MAPPING_CHANGED"; 5473 case RIL_UNSOL_SIMULTANEOUS_CALLING_SUPPORT_CHANGED: 5474 return "UNSOL_SIMULTANEOUS_CALLING_SUPPORT_CHANGED"; 5475 default: 5476 return "<unknown response " + response + ">"; 5477 } 5478 } 5479 5480 /** 5481 * Create capabilities based off of the radio hal version and feature set configurations. 5482 * @param radioHalVersion radio hal version 5483 * @param modemReducedFeatureSet1 reduced feature set 5484 * @return set of capabilities 5485 */ 5486 @VisibleForTesting getCaps(HalVersion radioHalVersion, boolean modemReducedFeatureSet1)5487 public static Set<String> getCaps(HalVersion radioHalVersion, boolean modemReducedFeatureSet1) { 5488 final Set<String> caps = new HashSet<>(); 5489 5490 if (radioHalVersion.equals(RIL.RADIO_HAL_VERSION_UNKNOWN)) { 5491 // If the Radio HAL is UNKNOWN, no capabilities will present themselves. 5492 loge("Radio Hal Version is UNKNOWN!"); 5493 } 5494 5495 logd("Radio Hal Version = " + radioHalVersion.toString()); 5496 if (radioHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) { 5497 caps.add(CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK); 5498 logd("CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK"); 5499 5500 if (!modemReducedFeatureSet1) { 5501 caps.add(CAPABILITY_SECONDARY_LINK_BANDWIDTH_VISIBLE); 5502 logd("CAPABILITY_SECONDARY_LINK_BANDWIDTH_VISIBLE"); 5503 caps.add(CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE); 5504 logd("CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE"); 5505 caps.add(CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); 5506 logd("CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING"); 5507 caps.add(CAPABILITY_SLICING_CONFIG_SUPPORTED); 5508 logd("CAPABILITY_SLICING_CONFIG_SUPPORTED"); 5509 caps.add(CAPABILITY_PHYSICAL_CHANNEL_CONFIG_1_6_SUPPORTED); 5510 logd("CAPABILITY_PHYSICAL_CHANNEL_CONFIG_1_6_SUPPORTED"); 5511 } else { 5512 caps.add(CAPABILITY_SIM_PHONEBOOK_IN_MODEM); 5513 logd("CAPABILITY_SIM_PHONEBOOK_IN_MODEM"); 5514 } 5515 } 5516 return caps; 5517 } 5518 isPrimitiveOrWrapper(Class c)5519 private static boolean isPrimitiveOrWrapper(Class c) { 5520 return c.isPrimitive() || WRAPPER_CLASSES.contains(c); 5521 } 5522 5523 /** 5524 * Return a general String representation of a class 5525 * @param o The object to convert to String 5526 * @return A string containing all public non-static local variables of a class 5527 */ convertToString(Object o)5528 public static String convertToString(Object o) { 5529 boolean toStringExists = false; 5530 try { 5531 toStringExists = o.getClass().getMethod("toString").getDeclaringClass() != Object.class; 5532 } catch (NoSuchMethodException e) { 5533 loge(e.toString()); 5534 } 5535 if (toStringExists || isPrimitiveOrWrapper(o.getClass()) || o instanceof ArrayList) { 5536 return o.toString(); 5537 } 5538 if (o.getClass().isArray()) { 5539 // Special handling for arrays 5540 StringBuilder sb = new StringBuilder("["); 5541 boolean added = false; 5542 if (isPrimitiveOrWrapper(o.getClass().getComponentType())) { 5543 for (int i = 0; i < Array.getLength(o); i++) { 5544 sb.append(convertToString(Array.get(o, i))).append(", "); 5545 added = true; 5546 } 5547 } else { 5548 for (Object element : (Object[]) o) { 5549 sb.append(convertToString(element)).append(", "); 5550 added = true; 5551 } 5552 } 5553 if (added) { 5554 // Remove extra , 5555 sb.delete(sb.length() - 2, sb.length()); 5556 } 5557 sb.append("]"); 5558 return sb.toString(); 5559 } 5560 StringBuilder sb = new StringBuilder(o.getClass().getSimpleName()); 5561 sb.append("{"); 5562 Field[] fields = o.getClass().getDeclaredFields(); 5563 int tag = -1; 5564 try { 5565 tag = (int) o.getClass().getDeclaredMethod("getTag").invoke(o); 5566 } catch (IllegalAccessException | InvocationTargetException e) { 5567 loge(e.toString()); 5568 } catch (NoSuchMethodException ignored) { 5569 // Ignored since only unions have the getTag method 5570 } 5571 if (tag != -1) { 5572 // Special handling for unions 5573 String tagName = null; 5574 try { 5575 Method method = o.getClass().getDeclaredMethod("_tagString", int.class); 5576 method.setAccessible(true); 5577 tagName = (String) method.invoke(o, tag); 5578 } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { 5579 loge(e.toString()); 5580 } 5581 if (tagName != null) { 5582 sb.append(tagName); 5583 sb.append("="); 5584 // From tag, create method name getTag 5585 String getTagMethod = "get" + tagName.substring(0, 1).toUpperCase(Locale.ROOT) 5586 + tagName.substring(1); 5587 Object val = null; 5588 try { 5589 val = o.getClass().getDeclaredMethod(getTagMethod).invoke(o); 5590 } catch (NoSuchMethodException | IllegalAccessException 5591 | InvocationTargetException e) { 5592 loge(e.toString()); 5593 } 5594 if (val != null) { 5595 sb.append(convertToString(val)); 5596 } 5597 } 5598 } else { 5599 boolean added = false; 5600 for (Field field : fields) { 5601 // Ignore static variables 5602 if (Modifier.isStatic(field.getModifiers())) continue; 5603 sb.append(field.getName()).append("="); 5604 Object val = null; 5605 try { 5606 val = field.get(o); 5607 } catch (IllegalAccessException e) { 5608 loge(e.toString()); 5609 } 5610 if (val == null) continue; 5611 sb.append(convertToString(val)).append(", "); 5612 added = true; 5613 } 5614 if (added) { 5615 // Remove extra , 5616 sb.delete(sb.length() - 2, sb.length()); 5617 } 5618 } 5619 sb.append("}"); 5620 return sb.toString(); 5621 } 5622 5623 /** 5624 * Converts the list of call information for Single Radio Voice Call Continuity(SRVCC). 5625 * 5626 * @param srvccConnections The list of call information for SRVCC. 5627 * @return The converted list of call information. 5628 */ convertToHalSrvccCall( SrvccConnection[] srvccConnections)5629 public static android.hardware.radio.ims.SrvccCall[] convertToHalSrvccCall( 5630 SrvccConnection[] srvccConnections) { 5631 if (srvccConnections == null) { 5632 return new android.hardware.radio.ims.SrvccCall[0]; 5633 } 5634 5635 int length = srvccConnections.length; 5636 android.hardware.radio.ims.SrvccCall[] srvccCalls = 5637 new android.hardware.radio.ims.SrvccCall[length]; 5638 5639 for (int i = 0; i < length; i++) { 5640 srvccCalls[i] = new android.hardware.radio.ims.SrvccCall(); 5641 srvccCalls[i].index = i + 1; 5642 srvccCalls[i].callType = convertSrvccCallType(srvccConnections[i].getType()); 5643 srvccCalls[i].callState = convertCallState(srvccConnections[i].getState()); 5644 srvccCalls[i].callSubstate = 5645 convertSrvccCallSubState(srvccConnections[i].getSubState()); 5646 srvccCalls[i].ringbackToneType = 5647 convertSrvccCallRingbackToneType(srvccConnections[i].getRingbackToneType()); 5648 srvccCalls[i].isMpty = srvccConnections[i].isMultiParty(); 5649 srvccCalls[i].isMT = srvccConnections[i].isIncoming(); 5650 srvccCalls[i].number = TextUtils.emptyIfNull(srvccConnections[i].getNumber()); 5651 srvccCalls[i].numPresentation = 5652 convertPresentation(srvccConnections[i].getNumberPresentation()); 5653 srvccCalls[i].name = TextUtils.emptyIfNull(srvccConnections[i].getName()); 5654 srvccCalls[i].namePresentation = 5655 convertPresentation(srvccConnections[i].getNamePresentation()); 5656 } 5657 5658 return srvccCalls; 5659 } 5660 5661 /** 5662 * Converts the call type. 5663 * 5664 * @param type The call type. 5665 * @return The converted call type. 5666 */ convertSrvccCallType(int type)5667 public static int convertSrvccCallType(int type) { 5668 switch (type) { 5669 case SrvccConnection.CALL_TYPE_NORMAL: 5670 return android.hardware.radio.ims.SrvccCall.CallType.NORMAL; 5671 case SrvccConnection.CALL_TYPE_EMERGENCY: 5672 return android.hardware.radio.ims.SrvccCall.CallType.EMERGENCY; 5673 default: 5674 throw new RuntimeException("illegal call type " + type); 5675 } 5676 } 5677 5678 /** 5679 * Converts the call state. 5680 * 5681 * @param state The call state. 5682 * @return The converted call state. 5683 */ convertCallState(Call.State state)5684 public static int convertCallState(Call.State state) { 5685 switch (state) { 5686 case ACTIVE: return android.hardware.radio.voice.Call.STATE_ACTIVE; 5687 case HOLDING: return android.hardware.radio.voice.Call.STATE_HOLDING; 5688 case DIALING: return android.hardware.radio.voice.Call.STATE_DIALING; 5689 case ALERTING: return android.hardware.radio.voice.Call.STATE_ALERTING; 5690 case INCOMING: return android.hardware.radio.voice.Call.STATE_INCOMING; 5691 case WAITING: return android.hardware.radio.voice.Call.STATE_WAITING; 5692 default: 5693 throw new RuntimeException("illegal state " + state); 5694 } 5695 } 5696 5697 /** 5698 * Converts the substate of a call. 5699 * 5700 * @param state The substate of a call. 5701 * @return The converted substate. 5702 */ convertSrvccCallSubState(int state)5703 public static int convertSrvccCallSubState(int state) { 5704 switch (state) { 5705 case SrvccConnection.SUBSTATE_NONE: 5706 return android.hardware.radio.ims.SrvccCall.CallSubState.NONE; 5707 case SrvccConnection.SUBSTATE_PREALERTING: 5708 return android.hardware.radio.ims.SrvccCall.CallSubState.PREALERTING; 5709 default: 5710 throw new RuntimeException("illegal substate " + state); 5711 } 5712 } 5713 5714 /** 5715 * Converts the ringback tone type. 5716 * 5717 * @param type The ringback tone type. 5718 * @return The converted ringback tone type. 5719 */ convertSrvccCallRingbackToneType(int type)5720 public static int convertSrvccCallRingbackToneType(int type) { 5721 switch (type) { 5722 case SrvccConnection.TONE_NONE: 5723 return android.hardware.radio.ims.SrvccCall.ToneType.NONE; 5724 case SrvccConnection.TONE_LOCAL: 5725 return android.hardware.radio.ims.SrvccCall.ToneType.LOCAL; 5726 case SrvccConnection.TONE_NETWORK: 5727 return android.hardware.radio.ims.SrvccCall.ToneType.NETWORK; 5728 default: 5729 throw new RuntimeException("illegal ringback tone type " + type); 5730 } 5731 } 5732 5733 /** 5734 * Converts the number presentation type for caller id display. 5735 * 5736 * @param presentation The number presentation type. 5737 * @return The converted presentation type. 5738 */ convertPresentation(int presentation)5739 public static int convertPresentation(int presentation) { 5740 switch (presentation) { 5741 case PhoneConstants.PRESENTATION_ALLOWED: 5742 return android.hardware.radio.voice.Call.PRESENTATION_ALLOWED; 5743 case PhoneConstants.PRESENTATION_RESTRICTED: 5744 return android.hardware.radio.voice.Call.PRESENTATION_RESTRICTED; 5745 case PhoneConstants.PRESENTATION_UNKNOWN: 5746 return android.hardware.radio.voice.Call.PRESENTATION_UNKNOWN; 5747 case PhoneConstants.PRESENTATION_PAYPHONE: 5748 return android.hardware.radio.voice.Call.PRESENTATION_PAYPHONE; 5749 default: 5750 throw new RuntimeException("illegal presentation " + presentation); 5751 } 5752 } 5753 5754 /** 5755 * Converts IMS registration state. 5756 * 5757 * @param state The IMS registration state. 5758 * @return The converted HAL IMS registration state. 5759 */ convertImsRegistrationState(int state)5760 public static int convertImsRegistrationState(int state) { 5761 switch (state) { 5762 case RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED: 5763 return android.hardware.radio.ims.ImsRegistrationState.NOT_REGISTERED; 5764 case RegistrationManager.REGISTRATION_STATE_REGISTERED: 5765 return android.hardware.radio.ims.ImsRegistrationState.REGISTERED; 5766 default: 5767 throw new RuntimeException("illegal state " + state); 5768 } 5769 } 5770 5771 /** 5772 * Converts IMS service radio technology. 5773 * 5774 * @param imsRadioTech The IMS service radio technology. 5775 * @return The converted HAL access network type. 5776 */ 5777 convertImsRegistrationTech( @msRegistrationImplBase.ImsRegistrationTech int imsRadioTech)5778 public static int convertImsRegistrationTech( 5779 @ImsRegistrationImplBase.ImsRegistrationTech int imsRadioTech) { 5780 switch (imsRadioTech) { 5781 case ImsRegistrationImplBase.REGISTRATION_TECH_LTE: 5782 return android.hardware.radio.AccessNetwork.EUTRAN; 5783 case ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN: 5784 return android.hardware.radio.AccessNetwork.IWLAN; 5785 case ImsRegistrationImplBase.REGISTRATION_TECH_NR: 5786 return android.hardware.radio.AccessNetwork.NGRAN; 5787 case ImsRegistrationImplBase.REGISTRATION_TECH_3G: 5788 return android.hardware.radio.AccessNetwork.UTRAN; 5789 default: 5790 return android.hardware.radio.AccessNetwork.UNKNOWN; 5791 } 5792 } 5793 5794 /** 5795 * Converts IMS capabilities. 5796 * 5797 * @param capabilities The IMS capabilities. 5798 * @return The converted HAL IMS capabilities. 5799 */ convertImsCapability(int capabilities)5800 public static int convertImsCapability(int capabilities) { 5801 int halCapabilities = android.hardware.radio.ims.ImsRegistration.IMS_MMTEL_CAPABILITY_NONE; 5802 if ((capabilities & CommandsInterface.IMS_MMTEL_CAPABILITY_VOICE) > 0) { 5803 halCapabilities |= 5804 android.hardware.radio.ims.ImsRegistration.IMS_MMTEL_CAPABILITY_VOICE; 5805 } 5806 if ((capabilities & CommandsInterface.IMS_MMTEL_CAPABILITY_VIDEO) > 0) { 5807 halCapabilities |= 5808 android.hardware.radio.ims.ImsRegistration.IMS_MMTEL_CAPABILITY_VIDEO; 5809 } 5810 if ((capabilities & CommandsInterface.IMS_MMTEL_CAPABILITY_SMS) > 0) { 5811 halCapabilities |= android.hardware.radio.ims.ImsRegistration.IMS_MMTEL_CAPABILITY_SMS; 5812 } 5813 if ((capabilities & CommandsInterface.IMS_RCS_CAPABILITIES) > 0) { 5814 halCapabilities |= android.hardware.radio.ims.ImsRegistration.IMS_RCS_CAPABILITIES; 5815 } 5816 return halCapabilities; 5817 } 5818 5819 /** Converts the ImsCallInfo instances to HAL ImsCall instances. */ convertImsCallInfo( List<ImsCallInfo> imsCallInfos)5820 public static android.hardware.radio.ims.ImsCall[] convertImsCallInfo( 5821 List<ImsCallInfo> imsCallInfos) { 5822 if (imsCallInfos == null) { 5823 return new android.hardware.radio.ims.ImsCall[0]; 5824 } 5825 5826 int length = 0; 5827 for (int i = 0; i < imsCallInfos.size(); i++) { 5828 if (imsCallInfos.get(i) != null) length++; 5829 } 5830 if (length == 0) { 5831 return new android.hardware.radio.ims.ImsCall[0]; 5832 } 5833 5834 android.hardware.radio.ims.ImsCall[] halInfos = 5835 new android.hardware.radio.ims.ImsCall[length]; 5836 5837 int index = 0; 5838 for (int i = 0; i < imsCallInfos.size(); i++) { 5839 ImsCallInfo info = imsCallInfos.get(i); 5840 if (info == null) continue; 5841 5842 halInfos[index] = new android.hardware.radio.ims.ImsCall(); 5843 halInfos[index].index = info.getIndex(); 5844 halInfos[index].callState = convertToHalImsCallState(info.getCallState()); 5845 halInfos[index].callType = info.isEmergencyCall() 5846 ? android.hardware.radio.ims.ImsCall.CallType.EMERGENCY 5847 : android.hardware.radio.ims.ImsCall.CallType.NORMAL; 5848 halInfos[index].accessNetwork = convertToHalAccessNetworkAidl(info.getCallRadioTech()); 5849 halInfos[index].direction = info.isIncoming() 5850 ? android.hardware.radio.ims.ImsCall.Direction.INCOMING 5851 : android.hardware.radio.ims.ImsCall.Direction.OUTGOING; 5852 halInfos[index].isHeldByRemote = info.isHeldByRemote(); 5853 index++; 5854 } 5855 5856 return halInfos; 5857 } 5858 5859 /** 5860 * Converts the call state to HAL IMS call state. 5861 * 5862 * @param state The {@link Call.State}. 5863 * @return The converted {@link android.hardware.radio.ims.ImsCall.CallState}. 5864 */ convertToHalImsCallState(Call.State state)5865 private static int convertToHalImsCallState(Call.State state) { 5866 switch (state) { 5867 case ACTIVE: return android.hardware.radio.ims.ImsCall.CallState.ACTIVE; 5868 case HOLDING: return android.hardware.radio.ims.ImsCall.CallState.HOLDING; 5869 case DIALING: return android.hardware.radio.ims.ImsCall.CallState.DIALING; 5870 case ALERTING: return android.hardware.radio.ims.ImsCall.CallState.ALERTING; 5871 case INCOMING: return android.hardware.radio.ims.ImsCall.CallState.INCOMING; 5872 case WAITING: return android.hardware.radio.ims.ImsCall.CallState.WAITING; 5873 case DISCONNECTING: return android.hardware.radio.ims.ImsCall.CallState.DISCONNECTING; 5874 default: return android.hardware.radio.ims.ImsCall.CallState.DISCONNECTED; 5875 } 5876 } 5877 5878 /** Convert an AIDL-based CellularIdentifierDisclosure to its Java wrapper. */ convertCellularIdentifierDisclosure( android.hardware.radio.network.CellularIdentifierDisclosure identifierDisclsoure)5879 public static CellularIdentifierDisclosure convertCellularIdentifierDisclosure( 5880 android.hardware.radio.network.CellularIdentifierDisclosure identifierDisclsoure) { 5881 if (identifierDisclsoure == null) { 5882 return null; 5883 } 5884 5885 return new CellularIdentifierDisclosure( 5886 identifierDisclsoure.protocolMessage, 5887 identifierDisclsoure.identifier, 5888 identifierDisclsoure.plmn, 5889 identifierDisclsoure.isEmergency); 5890 } 5891 5892 /** Convert an AIDL-based SecurityAlgorithmUpdate to its Java wrapper. */ convertSecurityAlgorithmUpdate( android.hardware.radio.network.SecurityAlgorithmUpdate securityAlgorithmUpdate)5893 public static SecurityAlgorithmUpdate convertSecurityAlgorithmUpdate( 5894 android.hardware.radio.network.SecurityAlgorithmUpdate securityAlgorithmUpdate) { 5895 if (securityAlgorithmUpdate == null) { 5896 return null; 5897 } 5898 5899 return new SecurityAlgorithmUpdate( 5900 securityAlgorithmUpdate.connectionEvent, 5901 securityAlgorithmUpdate.encryption, 5902 securityAlgorithmUpdate.integrity, 5903 securityAlgorithmUpdate.isUnprotectedEmergency); 5904 } 5905 5906 /** Convert an AIDL-based SimTypeInfo to its Java wrapper. */ convertAidlSimTypeInfo( android.hardware.radio.config.SimTypeInfo[] simTypeInfos)5907 public static ArrayList<SimTypeInfo> convertAidlSimTypeInfo( 5908 android.hardware.radio.config.SimTypeInfo[] simTypeInfos) { 5909 ArrayList<SimTypeInfo> response = new ArrayList<>(); 5910 if (simTypeInfos == null) { 5911 loge("convertAidlSimTypeInfo received NULL simTypeInfos"); 5912 return response; 5913 } 5914 for (android.hardware.radio.config.SimTypeInfo simTypeInfo : simTypeInfos) { 5915 SimTypeInfo info = new SimTypeInfo(); 5916 info.mSupportedSimTypes = simTypeInfo.supportedSimTypes; 5917 info.setCurrentSimType(simTypeInfo.currentSimType); 5918 response.add(info); 5919 } 5920 return response; 5921 } 5922 logd(String log)5923 private static void logd(String log) { 5924 Rlog.d("RILUtils", log); 5925 } 5926 loge(String log)5927 private static void loge(String log) { 5928 Rlog.e("RILUtils", log); 5929 } 5930 } 5931