Sending empty strings instead of NULL for some RIL requests

Some vendor RILs expect empty string instead of NULL pointer
for certain RIL requets. For RIL_REQUEST_ENTER_SIM_PIN,
RIL_REQUEST_ENTER_SIM_PUK, RIL_REQUEST_ENTER_SIM_PIN2,
RIL_REQUEST_ENTER_SIM_PUK2, RIL_REQUEST_CHANGE_SIM_PIN,
RIL_REQUEST_CHANGE_SIM_PIN2,
RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION
RIL_REQUEST_SETUP_DATA_CALL,
RIL_REQUEST_SET_INITIAL_ATTACH_APN, RIL_REQUEST_SET_DATA_PROFILE,
RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION,
RIL_REQUEST_SET_FACILITY_LOCK,
RIL_REQUEST_CHANGE_BARRING_PASSWORD, sending empty string instead
of NULL.

Test: Manual
Bug: 37782683, 65653485
Change-Id: I6627c8a12e096b9ac8ebe08e734782cfa951c488
tirimbino
Ruthwar Kumar Ambeer 8 years ago committed by Stricted
parent a57421ca2b
commit 9c58ea3fc0
No known key found for this signature in database
GPG Key ID: 3E45BB95F7AD33DA
  1. 98
      ril/libril/ril_service.cpp

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

Loading…
Cancel
Save