Merge "Radio Interface changes to allow the modem to query the framework for the key."
diff --git a/CleanSpec.mk b/CleanSpec.mk
index dbc726c..ffa18d5 100644
--- a/CleanSpec.mk
+++ b/CleanSpec.mk
@@ -50,3 +50,5 @@
 $(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/bin/rild)
 $(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/bin/rild)
 $(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/etc/init/rild.rc)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib/libril.so)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib64/libril.so)
diff --git a/libril/Android.mk b/libril/Android.mk
index 5d05d80..27083ef 100644
--- a/libril/Android.mk
+++ b/libril/Android.mk
@@ -3,6 +3,8 @@
 LOCAL_PATH:= $(call my-dir)
 include $(CLEAR_VARS)
 
+LOCAL_VENDOR_MODULE := true
+
 LOCAL_SRC_FILES:= \
     ril.cpp \
     ril_event.cpp\
diff --git a/libril/ril_internal.h b/libril/ril_internal.h
index 646d9b7..350791b 100644
--- a/libril/ril_internal.h
+++ b/libril/ril_internal.h
@@ -17,8 +17,6 @@
 #ifndef ANDROID_RIL_INTERNAL_H
 #define ANDROID_RIL_INTERNAL_H
 
-#include <binder/Parcel.h>
-
 namespace android {
 
 #define RIL_SERVICE_NAME_BASE "slot"
diff --git a/libril/ril_service.cpp b/libril/ril_service.cpp
index 3a35df9..cb28e71 100644
--- a/libril/ril_service.cpp
+++ b/libril/ril_service.cpp
@@ -686,8 +686,7 @@
         return false;
     }
 
-    RIL_SIM_APDU apdu;
-    memset (&apdu, 0, sizeof(RIL_SIM_APDU));
+    RIL_SIM_APDU apdu = {};
 
     apdu.sessionid = message.sessionId;
     apdu.cla = message.cla;
@@ -1117,7 +1116,7 @@
         return Void();
     }
 
-    RIL_SIM_IO_v6 rilIccIo;
+    RIL_SIM_IO_v6 rilIccIo = {};
     rilIccIo.command = iccIo.command;
     rilIccIo.fileid = iccIo.fileId;
     if (!copyHidlStringToRil(&rilIccIo.path, iccIo.path, pRI)) {
@@ -1587,8 +1586,6 @@
 }
 
 void constructCdmaSms(RIL_CDMA_SMS_Message &rcsm, const CdmaSmsMessage& sms) {
-    memset(&rcsm, 0, sizeof(rcsm));
-
     rcsm.uTeleserviceID = sms.teleserviceId;
     rcsm.bIsServicePresent = BOOL_TO_INT(sms.isServicePresent);
     rcsm.uServicecategory = sms.serviceCategory;
@@ -1628,7 +1625,7 @@
         return Void();
     }
 
-    RIL_CDMA_SMS_Message rcsm;
+    RIL_CDMA_SMS_Message rcsm = {};
     constructCdmaSms(rcsm, sms);
 
     s_vendorFunctions->onRequest(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm), pRI);
@@ -1911,13 +1908,16 @@
                 (isRoaming ? dataProfileInfo.roamingProtocol : dataProfileInfo.protocol);
 
         if (!copyHidlStringToRil(&iaa.protocol, protocol, pRI)) {
+            memsetAndFreeStrings(1, iaa.apn);
             return Void();
         }
         iaa.authtype = (int) dataProfileInfo.authType;
         if (!copyHidlStringToRil(&iaa.username, dataProfileInfo.user, pRI)) {
+            memsetAndFreeStrings(2, iaa.apn, iaa.protocol);
             return Void();
         }
         if (!copyHidlStringToRil(&iaa.password, dataProfileInfo.password, pRI)) {
+            memsetAndFreeStrings(3, iaa.apn, iaa.protocol, iaa.username);
             return Void();
         }
 
@@ -1931,16 +1931,20 @@
             return Void();
         }
         if (!copyHidlStringToRil(&iaa.protocol, dataProfileInfo.protocol, pRI)) {
+            memsetAndFreeStrings(1, iaa.apn);
             return Void();
         }
         if (!copyHidlStringToRil(&iaa.roamingProtocol, dataProfileInfo.roamingProtocol, pRI)) {
+            memsetAndFreeStrings(2, iaa.apn, iaa.protocol);
             return Void();
         }
         iaa.authtype = (int) dataProfileInfo.authType;
         if (!copyHidlStringToRil(&iaa.username, dataProfileInfo.user, pRI)) {
+            memsetAndFreeStrings(3, iaa.apn, iaa.protocol, iaa.roamingProtocol);
             return Void();
         }
         if (!copyHidlStringToRil(&iaa.password, dataProfileInfo.password, pRI)) {
+            memsetAndFreeStrings(4, iaa.apn, iaa.protocol, iaa.roamingProtocol, iaa.username);
             return Void();
         }
         iaa.supportedTypesBitmask = dataProfileInfo.supportedApnTypesBitmap;
@@ -1950,10 +1954,14 @@
 
         if (!convertMvnoTypeToString(dataProfileInfo.mvnoType, iaa.mvnoType)) {
             sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
+            memsetAndFreeStrings(5, iaa.apn, iaa.protocol, iaa.roamingProtocol, iaa.username,
+                    iaa.password);
             return Void();
         }
 
         if (!copyHidlStringToRil(&iaa.mvnoMatchData, dataProfileInfo.mvnoMatchData, pRI)) {
+            memsetAndFreeStrings(5, iaa.apn, iaa.protocol, iaa.roamingProtocol, iaa.username,
+                    iaa.password);
             return Void();
         }
 
@@ -2032,8 +2040,8 @@
 }
 
 bool dispatchImsCdmaSms(const ImsSmsMessage& message, RequestInfo *pRI) {
-    RIL_IMS_SMS_Message rism;
-    RIL_CDMA_SMS_Message rcsm;
+    RIL_IMS_SMS_Message rism = {};
+    RIL_CDMA_SMS_Message rcsm = {};
 
     if (message.cdmaMessage.size() != 1) {
         RLOGE("dispatchImsCdmaSms: Invalid len %s", requestToString(pRI->pCI->requestNumber));
@@ -2097,8 +2105,7 @@
             return Void();
         }
 
-        RIL_OpenChannelParams params;
-        memset (&params, 0, sizeof(RIL_OpenChannelParams));
+        RIL_OpenChannelParams params = {};
 
         params.p2 = p2;
 
@@ -2138,8 +2145,7 @@
         return Void();
     }
 
-    RIL_NV_ReadItem nvri;
-    memset (&nvri, 0, sizeof(nvri));
+    RIL_NV_ReadItem nvri = {};
     nvri.itemID = (RIL_NV_Item) itemId;
 
     s_vendorFunctions->onRequest(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI);
@@ -2155,8 +2161,7 @@
         return Void();
     }
 
-    RIL_NV_WriteItem nvwi;
-    memset (&nvwi, 0, sizeof(nvwi));
+    RIL_NV_WriteItem nvwi = {};
 
     nvwi.itemID = (RIL_NV_Item) item.itemId;
 
@@ -2233,8 +2238,7 @@
         return Void();
     }
 
-    RIL_SimAuthentication pf;
-    memset (&pf, 0, sizeof(pf));
+    RIL_SimAuthentication pf = {};
 
     pf.authContext = authContext;
 
@@ -2474,8 +2478,7 @@
         return Void();
     }
 
-    RIL_RadioCapability rilRc;
-    memset (&rilRc, 0, sizeof(rilRc));
+    RIL_RadioCapability rilRc = {};
 
     // TODO : set rilRc.version using HIDL version ?
     rilRc.session = rc.session;
@@ -3378,11 +3381,7 @@
         int numStrings, char** response) {
 
     RIL_CellIdentity_v16 rilCellIdentity;
-    int32_t *tmp = (int32_t*)&rilCellIdentity;
-
-    for (size_t i = 0; i < sizeof(RIL_CellIdentity_v16)/sizeof(int32_t); i++) {
-        tmp[i] = -1;
-    }
+    memset(&rilCellIdentity, -1, sizeof(RIL_CellIdentity_v16));
 
     rilCellIdentity.cellInfoType = getCellInfoTypeRadioTechnology(response[3]);
     switch(rilCellIdentity.cellInfoType) {
@@ -3447,11 +3446,7 @@
         int numStrings, char** response) {
 
     RIL_CellIdentity_v16 rilCellIdentity;
-    int32_t *tmp = (int32_t*)&rilCellIdentity;
-
-    for (size_t i = 0; i < sizeof(RIL_CellIdentity_v16)/sizeof(int32_t); i++) {
-        tmp[i] = -1;
-    }
+    memset(&rilCellIdentity, -1, sizeof(RIL_CellIdentity_v16));
 
     rilCellIdentity.cellInfoType = getCellInfoTypeRadioTechnology(response[3]);
     switch(rilCellIdentity.cellInfoType) {