這篇文章介紹ril.cpp中實現部分代碼中的四個字串輸出函數及其相應的枚舉類型。首先看requestToString()函數的
代碼,它的功能是將將ril_command.h和ril_unsol_commands.h中的命令轉換成字串描述:
const char * requestToString(int request) {<br /> switch(request) {<br /> case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";<br /> case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";<br /> case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";<br /> case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";<br /> case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";<br /> case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";<br /> case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";<br /> case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";<br /> case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";<br /> case RIL_REQUEST_DIAL: return "DIAL";<br /> case RIL_REQUEST_GET_IMSI: return "GET_IMSI";<br /> case RIL_REQUEST_HANGUP: return "HANGUP";<br /> case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";<br /> case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";<br /> case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";<br /> case RIL_REQUEST_CONFERENCE: return "CONFERENCE";<br /> case RIL_REQUEST_UDUB: return "UDUB";<br /> case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";<br /> case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";<br /> case RIL_REQUEST_REGISTRATION_STATE: return "REGISTRATION_STATE";<br /> case RIL_REQUEST_GPRS_REGISTRATION_STATE: return "GPRS_REGISTRATION_STATE";<br /> case RIL_REQUEST_OPERATOR: return "OPERATOR";<br /> case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";<br /> case RIL_REQUEST_DTMF: return "DTMF";<br /> case RIL_REQUEST_SEND_SMS: return "SEND_SMS";<br /> case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";<br /> case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";<br /> case RIL_REQUEST_SIM_IO: return "SIM_IO";<br /> case RIL_REQUEST_SEND_USSD: return "SEND_USSD";<br /> case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";<br /> case RIL_REQUEST_GET_CLIR: return "GET_CLIR";<br /> case RIL_REQUEST_SET_CLIR: return "SET_CLIR";<br /> case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";<br /> case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";<br /> case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";<br /> case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";<br /> case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";<br /> case RIL_REQUEST_GET_IMEI: return "GET_IMEI";<br /> case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";<br /> case RIL_REQUEST_ANSWER: return "ANSWER";<br /> case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";<br /> case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";<br /> case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";<br /> case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";<br /> case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";<br /> case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";<br /> case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";<br /> case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";<br /> case RIL_REQUEST_DTMF_START: return "DTMF_START";<br /> case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";<br /> case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";<br /> case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";<br /> case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";<br /> case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";<br /> case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";<br /> case RIL_REQUEST_SET_MUTE: return "SET_MUTE";<br /> case RIL_REQUEST_GET_MUTE: return "GET_MUTE";<br /> case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";<br /> case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";<br /> case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";<br /> case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";<br /> case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";<br /> case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";<br /> case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";<br /> case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";<br /> case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";<br /> case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";<br /> case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";<br /> case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";<br /> case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";<br /> case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";<br /> case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";<br /> case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";<br /> case RIL_REQUEST_CDMA_SET_SUBSCRIPTION:return"CDMA_SET_SUBSCRIPTION";<br /> case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";<br /> case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";<br /> case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";<br /> case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";<br /> case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";<br /> case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";<br /> case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";<br /> case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";<br /> case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";<br /> case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";<br /> case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";<br /> case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";<br /> case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";<br /> case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";<br /> case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";<br /> case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";<br /> case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";<br /> case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";<br /> case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";<br /> case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";<br /> case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";<br /> case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";<br /> case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";<br /> case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";<br /> case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";<br /> case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";<br /> case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";<br /> case RIL_UNSOL_RESPONSE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_NETWORK_STATE_CHANGED";<br /> case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";<br /> case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";<br /> case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";<br /> case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";<br /> case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";<br /> case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";<br /> case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";<br /> case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";<br /> case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";<br /> case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";<br /> case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";<br /> case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";<br /> case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";<br /> case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";<br /> case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";<br /> case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";<br /> case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";<br /> case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";<br /> case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";<br /> case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";<br /> case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";<br /> case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";<br /> case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";<br /> case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";<br /> case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";<br /> case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";<br /> case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";<br /> default: return "<unknown request>";<br /> }<br />}
第二個函數是將枚舉類型RIL_Error中定義的錯誤碼轉換成字串形式,先看RIL_Error的代碼,它定義在
(hardware\ril\include\telephony\Ril.h)中:
typedef enum {<br /> RIL_E_SUCCESS = 0,<br /> RIL_E_RADIO_NOT_AVAILABLE = 1, /* 無線模組未開啟或者被重設 */<br /> RIL_E_GENERIC_FAILURE = 2, /* 一般錯誤 */<br /> RIL_E_PASSWORD_INCORRECT = 3, /* 只用於PIN/PIN2相關的函數 */<br /> RIL_E_SIM_PIN2 = 4, /* 指示本次操作需要輸入SIM PIN2碼 */<br /> RIL_E_SIM_PUK2 = 5, /* 指示本次操作需要輸入SIM PUK2碼 */<br /> RIL_E_REQUEST_NOT_SUPPORTED = 6, /* 請求類型不支援 */<br /> RIL_E_CANCELLED = 7, /* 操作被取消 */<br /> RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL = 8, /* C級GPRS裝置上不允許在語音通話期間進行資料操作 */<br /> RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW = 9, /* 在裝置註冊到網路前不允許資料操作 */<br /> RIL_E_SMS_SEND_FAIL_RETRY = 10, /* 傳送簡訊息失敗,需要重試 */<br /> RIL_E_SIM_ABSENT = 11, /* SIM卡或RUIM卡不存在,導致擷取CDMA套餐並設定位置失敗 */<br /> RIL_E_SUBSCRIPTION_NOT_AVAILABLE = 12, /* 從某一位置擷取CDMA套餐失敗 */<br /> RIL_E_MODE_NOT_SUPPORTED = 13, /* 首選網路類型不支援 */<br /> RIL_E_FDN_CHECK_FAILURE = 14, /* 接收者不在FDN列表中導致命令失效 */<br /> RIL_E_ILLEGAL_SIM_OR_ME = 15 /* 非法的SIM或者ME導致網路選擇失效 */<br />} RIL_Errno;</p><p>// 將枚舉類型RIL_Error中的值轉換成字串描述<br />const char * failCauseToString(RIL_Errno e) {<br /> switch(e) {<br /> case RIL_E_SUCCESS: return "E_SUCCESS";<br /> case RIL_E_RADIO_NOT_AVAILABLE: return "E_RAIDO_NOT_AVAILABLE";<br /> case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";<br /> case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";<br /> case RIL_E_SIM_PIN2: return "E_SIM_PIN2";<br /> case RIL_E_SIM_PUK2: return "E_SIM_PUK2";<br /> case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";<br /> case RIL_E_CANCELLED: return "E_CANCELLED";<br /> case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";<br /> case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";<br /> case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";<br /> case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";<br /> case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";<br />#ifdef FEATURE_MULTIMODE_ANDROID<br /> case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";<br /> case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";<br />#endif<br /> default: return "<unknown error>";<br /> }<br />}
第三個函數是將枚舉類型RIL_CallState中定義的值轉換成字串描述,先看枚舉類型的定義,同樣位於檔案
(hardware\ril\include\telephony\Ril.h)中:
typedef enum {<br /> RIL_CALL_ACTIVE = 0, /* 通話啟用 */<br /> RIL_CALL_HOLDING = 1, /* 保留 */<br /> RIL_CALL_DIALING = 2, /* 只適用MO(Mobile Original)呼叫 */<br /> RIL_CALL_ALERTING = 3, /* 只適用MO(Mobile Original)呼叫 */<br /> RIL_CALL_INCOMING = 4, /* 只適用MT(Mobile Terminated)呼叫 */<br /> RIL_CALL_WAITING = 5 /* 只適用MT(Mobile Terminated)呼叫 */<br />} RIL_CallState;</p><p>// 將枚舉類型RIL_CallState中的值轉換成字串描述<br />const char * callStateToString(RIL_CallState s) {<br /> switch(s) {<br /> case RIL_CALL_ACTIVE : return "ACTIVE";<br /> case RIL_CALL_HOLDING: return "HOLDING";<br /> case RIL_CALL_DIALING: return "DIALING";<br /> case RIL_CALL_ALERTING: return "ALERTING";<br /> case RIL_CALL_INCOMING: return "INCOMING";<br /> case RIL_CALL_WAITING: return "WAITING";<br /> default: return "<unknown state>";<br /> }<br />}
第四個函數是將枚舉類型RIL_RadioState中定義的值轉換成字串描述,枚舉類型定義如下,位於檔案
(hardware\ril\include\telephony\Ril.h)中:
typedef enum {<br /> RADIO_STATE_OFF = 0, /* 無線模組顯示掉電(如CFUN=0) */<br /> RADIO_STATE_UNAVAILABLE = 1, /* 無線模組不可用(如重設或沒啟動) */<br /> RADIO_STATE_SIM_NOT_READY = 2, /* 無線模組已啟動,但SIM介面未準備好 */<br /> RADIO_STATE_SIM_LOCKED_OR_ABSENT = 3, /* SIM 數字 PIN 碼被鎖定,需要輸入PUK碼,或者網路個人識別碼被鎖定,或者SIM卡不存在 */<br /> RADIO_STATE_SIM_READY = 4, /* 無線模組已啟動,SIM介面可用 */<br /> RADIO_STATE_RUIM_NOT_READY = 5, /* 無線模組已啟動,但RUIM介面未準備好 */<br /> RADIO_STATE_RUIM_READY = 6, /* 無線模組已啟動,RUIM介面可用 */<br /> RADIO_STATE_RUIM_LOCKED_OR_ABSENT = 7, /* RUIM 數字 PIN 碼被鎖定,需要輸入PUNK碼,或者網路個人識別碼被鎖定,或者RUIM卡不存在 */<br /> RADIO_STATE_NV_NOT_READY = 8, /* 無線模組已啟動,但NV介面未準備好 */<br /> RADIO_STATE_NV_READY = 9 /* 無線模組已啟動,NV介面可用 */<br />} RIL_RadioState;</p><p>// 將枚舉類型RIL_RadioState的值轉換成字串描述<br />const char * radioStateToString(RIL_RadioState s) {<br /> switch(s) {<br /> case RADIO_STATE_OFF: return "RADIO_OFF";<br /> case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";<br /> case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";<br /> case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";<br /> case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";<br /> case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";<br /> case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";<br /> case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";<br /> case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";<br /> case RADIO_STATE_NV_READY:return"RADIO_NV_READY";<br /> default: return "<unknown state>";<br /> }<br />}
To Be Continued