diff --git a/ril/libril/ril_service.cpp b/ril/libril/ril_service.cpp index 76670df8..f2b77145 100644 --- a/ril/libril/ril_service.cpp +++ b/ril/libril/ril_service.cpp @@ -486,9 +486,9 @@ void sendErrorResponse(RequestInfo *pRI, RIL_Errno err) { * request with error RIL_E_NO_MEMORY. * Returns true on success, and false on failure. */ -bool copyHidlStringToRil(char **dest, const hidl_string &src, RequestInfo *pRI) { +bool copyHidlStringToRil(char **dest, const hidl_string &src, RequestInfo *pRI, bool allowEmpty) { size_t len = src.size(); - if (len == 0) { + if (len == 0 && !allowEmpty) { *dest = NULL; return true; } @@ -502,6 +502,10 @@ bool copyHidlStringToRil(char **dest, const hidl_string &src, RequestInfo *pRI) return true; } +bool copyHidlStringToRil(char **dest, const hidl_string &src, RequestInfo *pRI) { + return copyHidlStringToRil(dest, src, pRI, false); +} + hidl_string convertCharPtrToHidlString(const char *ptr) { hidl_string ret; if (ptr != NULL) { @@ -537,7 +541,7 @@ bool dispatchString(int serial, int slotId, int request, const char * str) { return true; } -bool dispatchStrings(int serial, int slotId, int request, int countStrings, ...) { +bool dispatchStrings(int serial, int slotId, int request, bool allowEmpty, int countStrings, ...) { RequestInfo *pRI = android::addRequestToList(serial, slotId, request); if (pRI == NULL) { return false; @@ -554,7 +558,7 @@ bool dispatchStrings(int serial, int slotId, int request, int countStrings, ...) va_start(ap, countStrings); for (int i = 0; i < countStrings; i++) { const char* str = va_arg(ap, const char *); - if (!copyHidlStringToRil(&pStrings[i], hidl_string(str), pRI)) { + if (!copyHidlStringToRil(&pStrings[i], hidl_string(str), pRI, allowEmpty)) { va_end(ap); for (int j = 0; j < i; j++) { memsetAndFreeStrings(1, pStrings[j]); @@ -798,7 +802,7 @@ Return RadioImpl::supplyIccPinForApp(int32_t serial, const hidl_string& pi #if VDBG RLOGD("supplyIccPinForApp: serial %d", serial); #endif - dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_SIM_PIN, + dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_SIM_PIN, true, 2, pin.c_str(), aid.c_str()); return Void(); } @@ -808,7 +812,7 @@ Return RadioImpl::supplyIccPukForApp(int32_t serial, const hidl_string& pu #if VDBG RLOGD("supplyIccPukForApp: serial %d", serial); #endif - dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_SIM_PUK, + dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_SIM_PUK, true, 3, puk.c_str(), pin.c_str(), aid.c_str()); return Void(); } @@ -818,7 +822,7 @@ Return RadioImpl::supplyIccPin2ForApp(int32_t serial, const hidl_string& p #if VDBG RLOGD("supplyIccPin2ForApp: serial %d", serial); #endif - dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_SIM_PIN2, + dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_SIM_PIN2, true, 2, pin2.c_str(), aid.c_str()); return Void(); } @@ -828,7 +832,7 @@ Return RadioImpl::supplyIccPuk2ForApp(int32_t serial, const hidl_string& p #if VDBG RLOGD("supplyIccPuk2ForApp: serial %d", serial); #endif - dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_SIM_PUK2, + dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_SIM_PUK2, true, 3, puk2.c_str(), pin2.c_str(), aid.c_str()); return Void(); } @@ -838,7 +842,7 @@ Return RadioImpl::changeIccPinForApp(int32_t serial, const hidl_string& ol #if VDBG RLOGD("changeIccPinForApp: serial %d", serial); #endif - dispatchStrings(serial, mSlotId, RIL_REQUEST_CHANGE_SIM_PIN, + dispatchStrings(serial, mSlotId, RIL_REQUEST_CHANGE_SIM_PIN, true, 3, oldPin.c_str(), newPin.c_str(), aid.c_str()); return Void(); } @@ -848,7 +852,7 @@ Return RadioImpl::changeIccPin2ForApp(int32_t serial, const hidl_string& o #if VDBG RLOGD("changeIccPin2ForApp: serial %d", serial); #endif - dispatchStrings(serial, mSlotId, RIL_REQUEST_CHANGE_SIM_PIN2, + dispatchStrings(serial, mSlotId, RIL_REQUEST_CHANGE_SIM_PIN2, true, 3, oldPin2.c_str(), newPin2.c_str(), aid.c_str()); return Void(); } @@ -858,7 +862,7 @@ Return RadioImpl::supplyNetworkDepersonalization(int32_t serial, #if VDBG RLOGD("supplyNetworkDepersonalization: serial %d", serial); #endif - dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION, + dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION, true, 1, netPin.c_str()); return Void(); } @@ -917,7 +921,7 @@ Return RadioImpl::getImsiForApp(int32_t serial, const hidl_string& aid) { #if VDBG RLOGD("getImsiForApp: serial %d", serial); #endif - dispatchStrings(serial, mSlotId, RIL_REQUEST_GET_IMSI, + dispatchStrings(serial, mSlotId, RIL_REQUEST_GET_IMSI, false, 1, aid.c_str()); return Void(); } @@ -1028,7 +1032,7 @@ Return RadioImpl::sendSms(int32_t serial, const GsmSmsMessage& message) { #if VDBG RLOGD("sendSms: serial %d", serial); #endif - dispatchStrings(serial, mSlotId, RIL_REQUEST_SEND_SMS, + dispatchStrings(serial, mSlotId, RIL_REQUEST_SEND_SMS, false, 2, message.smscPdu.c_str(), message.pdu.c_str()); return Void(); } @@ -1037,7 +1041,7 @@ Return RadioImpl::sendSMSExpectMore(int32_t serial, const GsmSmsMessage& m #if VDBG RLOGD("sendSMSExpectMore: serial %d", serial); #endif - dispatchStrings(serial, mSlotId, RIL_REQUEST_SEND_SMS_EXPECT_MORE, + dispatchStrings(serial, mSlotId, RIL_REQUEST_SEND_SMS_EXPECT_MORE, false, 2, message.smscPdu.c_str(), message.pdu.c_str()); return Void(); } @@ -1071,7 +1075,7 @@ Return RadioImpl::setupDataCall(int32_t serial, RadioTechnology radioTechn if (s_vendorFunctions->version >= 4 && s_vendorFunctions->version <= 14) { const hidl_string &protocol = (isRoaming ? dataProfileInfo.roamingProtocol : dataProfileInfo.protocol); - dispatchStrings(serial, mSlotId, RIL_REQUEST_SETUP_DATA_CALL, 7, + dispatchStrings(serial, mSlotId, RIL_REQUEST_SETUP_DATA_CALL, true, 7, std::to_string((int) radioTechnology + 2).c_str(), std::to_string((int) dataProfileInfo.profileId).c_str(), dataProfileInfo.apn.c_str(), @@ -1089,7 +1093,7 @@ Return RadioImpl::setupDataCall(int32_t serial, RadioTechnology radioTechn } return Void(); } - dispatchStrings(serial, mSlotId, RIL_REQUEST_SETUP_DATA_CALL, 15, + dispatchStrings(serial, mSlotId, RIL_REQUEST_SETUP_DATA_CALL, true, 15, std::to_string((int) radioTechnology + 2).c_str(), std::to_string((int) dataProfileInfo.profileId).c_str(), dataProfileInfo.apn.c_str(), @@ -1248,7 +1252,7 @@ Return RadioImpl::deactivateDataCall(int32_t serial, #if VDBG RLOGD("deactivateDataCall: serial %d", serial); #endif - dispatchStrings(serial, mSlotId, RIL_REQUEST_DEACTIVATE_DATA_CALL, + dispatchStrings(serial, mSlotId, RIL_REQUEST_DEACTIVATE_DATA_CALL, false, 2, (std::to_string(cid)).c_str(), reasonRadioShutDown ? "1" : "0"); return Void(); } @@ -1259,7 +1263,7 @@ Return RadioImpl::getFacilityLockForApp(int32_t serial, const hidl_string& #if VDBG RLOGD("getFacilityLockForApp: serial %d", serial); #endif - dispatchStrings(serial, mSlotId, RIL_REQUEST_QUERY_FACILITY_LOCK, + dispatchStrings(serial, mSlotId, RIL_REQUEST_QUERY_FACILITY_LOCK, true, 4, facility.c_str(), password.c_str(), (std::to_string(serviceClass)).c_str(), appId.c_str()); return Void(); @@ -1271,7 +1275,7 @@ Return RadioImpl::setFacilityLockForApp(int32_t serial, const hidl_string& #if VDBG RLOGD("setFacilityLockForApp: serial %d", serial); #endif - dispatchStrings(serial, mSlotId, RIL_REQUEST_SET_FACILITY_LOCK, + dispatchStrings(serial, mSlotId, RIL_REQUEST_SET_FACILITY_LOCK, true, 5, facility.c_str(), lockState ? "1" : "0", password.c_str(), (std::to_string(serviceClass)).c_str(), appId.c_str() ); return Void(); @@ -1283,7 +1287,7 @@ Return RadioImpl::setBarringPassword(int32_t serial, const hidl_string& fa #if VDBG RLOGD("setBarringPassword: serial %d", serial); #endif - dispatchStrings(serial, mSlotId, RIL_REQUEST_CHANGE_BARRING_PASSWORD, + dispatchStrings(serial, mSlotId, RIL_REQUEST_CHANGE_BARRING_PASSWORD, true, 3, facility.c_str(), oldPassword.c_str(), newPassword.c_str()); return Void(); } @@ -1587,7 +1591,7 @@ Return RadioImpl::sendBurstDtmf(int32_t serial, const hidl_string& dtmf, i #if VDBG RLOGD("sendBurstDtmf: serial %d", serial); #endif - dispatchStrings(serial, mSlotId, RIL_REQUEST_CDMA_BURST_DTMF, + dispatchStrings(serial, mSlotId, RIL_REQUEST_CDMA_BURST_DTMF, false, 3, dtmf.c_str(), (std::to_string(on)).c_str(), (std::to_string(off)).c_str()); return Void(); @@ -1856,7 +1860,7 @@ Return RadioImpl::acknowledgeIncomingGsmSmsWithPdu(int32_t serial, bool su #if VDBG RLOGD("acknowledgeIncomingGsmSmsWithPdu: serial %d", serial); #endif - dispatchStrings(serial, mSlotId, RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU, + dispatchStrings(serial, mSlotId, RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU, false, 2, success ? "1" : "0", ackPdu.c_str()); return Void(); } @@ -1908,19 +1912,8 @@ Return RadioImpl::setInitialAttachApn(int32_t serial, const DataProfileInf if (s_vendorFunctions->version <= 14) { RIL_InitialAttachApn iaa = {}; - if (dataProfileInfo.apn.size() == 0) { - iaa.apn = (char *) calloc(1, sizeof(char)); - if (iaa.apn == NULL) { - RLOGE("Memory allocation failed for request %s", - requestToString(pRI->pCI->requestNumber)); - sendErrorResponse(pRI, RIL_E_NO_MEMORY); - return Void(); - } - iaa.apn[0] = '\0'; - } else { - if (!copyHidlStringToRil(&iaa.apn, dataProfileInfo.apn, pRI)) { - return Void(); - } + if (!copyHidlStringToRil(&iaa.apn, dataProfileInfo.apn, pRI, true)) { + return Void(); } const hidl_string &protocol = @@ -1962,19 +1955,8 @@ Return RadioImpl::setInitialAttachApn(int32_t serial, const DataProfileInf } else { RIL_InitialAttachApn_v15 iaa = {}; - if (dataProfileInfo.apn.size() == 0) { - iaa.apn = (char *) calloc(1, sizeof(char)); - if (iaa.apn == NULL) { - RLOGE("Memory allocation failed for request %s", - requestToString(pRI->pCI->requestNumber)); - sendErrorResponse(pRI, RIL_E_NO_MEMORY); - return Void(); - } - iaa.apn[0] = '\0'; - } else { - if (!copyHidlStringToRil(&iaa.apn, dataProfileInfo.apn, pRI)) { - return Void(); - } + if (!copyHidlStringToRil(&iaa.apn, dataProfileInfo.apn, pRI, true)) { + return Void(); } if (!copyHidlStringToRil(&iaa.protocol, dataProfileInfo.protocol, pRI)) { @@ -2394,20 +2376,21 @@ Return RadioImpl::setDataProfile(int32_t serial, const hidl_vec RadioImpl::setDataProfile(int32_t serial, const hidl_vec