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