binder: Add parcelable for iface params

Replace the |CreateInterface| method params from dictionary
to parcelable type.

BUG: 30066497
TEST: Ran the integration tests under |wificond|.
Change-Id: Iea0dbce3ce55df0735afa3de532fa25fe6802aa3
diff --git a/wpa_supplicant/Android.mk b/wpa_supplicant/Android.mk
index 1363d84..a54c45a 100644
--- a/wpa_supplicant/Android.mk
+++ b/wpa_supplicant/Android.mk
@@ -1655,6 +1655,7 @@
     $(LOCAL_PATH)/binder/include
 LOCAL_SRC_FILES := \
     binder/binder_constants.cpp \
+    binder/parcelable_iface_params.cpp \
     binder/fi/w1/wpa_supplicant/IIface.aidl \
     binder/fi/w1/wpa_supplicant/INetwork.aidl \
     binder/fi/w1/wpa_supplicant/ISupplicant.aidl \
diff --git a/wpa_supplicant/binder/fi/w1/wpa_supplicant/ISupplicant.aidl b/wpa_supplicant/binder/fi/w1/wpa_supplicant/ISupplicant.aidl
index 4ce92fb..84edc0a 100644
--- a/wpa_supplicant/binder/fi/w1/wpa_supplicant/ISupplicant.aidl
+++ b/wpa_supplicant/binder/fi/w1/wpa_supplicant/ISupplicant.aidl
@@ -9,7 +9,7 @@
 
 package fi.w1.wpa_supplicant;
 
-import android.os.PersistableBundle;
+import fi.w1.wpa_supplicant.ParcelableIfaceParams;
 import fi.w1.wpa_supplicant.IIface;
 
 /**
@@ -39,19 +39,12 @@
 	/**
 	 * Registers a wireless interface in wpa_supplicant.
 	 *
-	 * @param args A dictionary with arguments used to add the interface to
-	 *             wpa_supplicant.
-	 * The dictionary may contain the following entries:
-	 *   Ifname(String) Name of the network interface to control, e.g.,
-	 *   wlan0.
-	 *   BridgeIfname(String) Name of the bridge interface to control, e.g.,
-	 *   br0.
-	 *   Driver(String) Driver name which the interface uses, e.g., nl80211.
-	 *   ConfigFile(String) Configuration file path.
+	 * @param params Instance of |ParcelableIfaceParams| containing the
+	 *        parameters of the interface.
 	 *
 	 * @return Binder object representing the interface.
 	 */
-	IIface CreateInterface(in PersistableBundle args);
+	IIface CreateInterface(in ParcelableIfaceParams params);
 
 	/**
 	 * Deregisters a wireless interface from wpa_supplicant.
diff --git a/wpa_supplicant/binder/fi/w1/wpa_supplicant/ParcelableIfaceParams.aidl b/wpa_supplicant/binder/fi/w1/wpa_supplicant/ParcelableIfaceParams.aidl
new file mode 100644
index 0000000..59a9f31
--- /dev/null
+++ b/wpa_supplicant/binder/fi/w1/wpa_supplicant/ParcelableIfaceParams.aidl
@@ -0,0 +1,13 @@
+/*
+ * binder interface for wpa_supplicant daemon
+ * Copyright (c) 2004-2016, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2004-2016, Roshan Pius <rpius@google.com>
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+package fi.w1.wpa_supplicant;
+
+parcelable ParcelableIfaceParams cpp_header
+    "wpa_supplicant_binder/parcelable_iface_params.h";
diff --git a/wpa_supplicant/binder/include/wpa_supplicant_binder/parcelable_iface_params.h b/wpa_supplicant/binder/include/wpa_supplicant_binder/parcelable_iface_params.h
new file mode 100644
index 0000000..0fc063c
--- /dev/null
+++ b/wpa_supplicant/binder/include/wpa_supplicant_binder/parcelable_iface_params.h
@@ -0,0 +1,46 @@
+/*
+ * binder interface for wpa_supplicant daemon
+ * Copyright (c) 2004-2016, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2004-2016, Roshan Pius <rpius@google.com>
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#ifndef WPA_SUPPLICANT_BINDER_PARCELABLE_IFACE_PARAMS_H
+#define WPA_SUPPLICANT_BINDER_PARCELABLE_IFACE_PARAMS_H
+
+#include <binder/Parcelable.h>
+#include <utils/String8.h>
+
+namespace fi {
+namespace w1 {
+namespace wpa_supplicant {
+
+// Parcelable object containing the params used for creating a
+// new interface via |ISupplicant.CreateInterface| binder call.
+class ParcelableIfaceParams : public android::Parcelable
+{
+public:
+	ParcelableIfaceParams() = default;
+	virtual ~ParcelableIfaceParams() = default;
+
+	android::status_t writeToParcel(android::Parcel *parcel) const override;
+	android::status_t readFromParcel(const android::Parcel *parcel) override;
+
+	// Name of the network interface to control, e.g., wlan0.
+	android::String8 ifname_;
+	// BridgeIfname(String) Name of the bridge interface to control, e.g.,
+	// br0.
+	android::String8 bridge_ifname_;
+	// Driver name which the interface uses, e.g., nl80211.
+	android::String8 driver_;
+	// Configuration file path.
+	android::String8 config_file_;
+};
+
+} // namespace fi
+} // namespace w1
+} // namespace wpa_supplicant
+
+#endif // WPA_SUPPLICANT_BINDER_PARCELABLE_IFACE_PARAMS_H
diff --git a/wpa_supplicant/binder/parcelable_iface_params.cpp b/wpa_supplicant/binder/parcelable_iface_params.cpp
new file mode 100644
index 0000000..9bd24c7
--- /dev/null
+++ b/wpa_supplicant/binder/parcelable_iface_params.cpp
@@ -0,0 +1,57 @@
+/*
+ * binder interface for wpa_supplicant daemon
+ * Copyright (c) 2004-2016, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2004-2016, Roshan Pius <rpius@google.com>
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+#include <binder/Parcel.h>
+
+#include "wpa_supplicant_binder/parcelable_iface_params.h"
+
+namespace fi {
+namespace w1 {
+namespace wpa_supplicant {
+
+android::status_t
+ParcelableIfaceParams::writeToParcel(android::Parcel *parcel) const
+{
+	android::status_t status;
+	status = parcel->writeString8(ifname_);
+	if (status != android::OK) {
+		return status;
+	}
+	status = parcel->writeString8(bridge_ifname_);
+	if (status != android::OK) {
+		return status;
+	}
+	status = parcel->writeString8(driver_);
+	if (status != android::OK) {
+		return status;
+	}
+	return parcel->writeString8(config_file_);
+}
+
+android::status_t
+ParcelableIfaceParams::readFromParcel(const android::Parcel *parcel)
+{
+	android::status_t status;
+	status = parcel->readString8(&ifname_);
+	if (status != android::OK) {
+		return status;
+	}
+	status = parcel->readString8(&bridge_ifname_);
+	if (status != android::OK) {
+		return status;
+	}
+	status = parcel->readString8(&driver_);
+	if (status != android::OK) {
+		return status;
+	}
+	return parcel->readString8(&config_file_);
+}
+
+} // namespace fi
+} // namespace w1
+} // namespace wpa_supplicant
diff --git a/wpa_supplicant/binder/supplicant.cpp b/wpa_supplicant/binder/supplicant.cpp
index fccf9ca..38b7e44 100644
--- a/wpa_supplicant/binder/supplicant.cpp
+++ b/wpa_supplicant/binder/supplicant.cpp
@@ -15,28 +15,21 @@
 Supplicant::Supplicant(struct wpa_global *global) : wpa_global_(global) {}
 
 android::binder::Status Supplicant::CreateInterface(
-    const android::os::PersistableBundle &params,
+    const fi::w1::wpa_supplicant::ParcelableIfaceParams &params,
     android::sp<fi::w1::wpa_supplicant::IIface> *iface_object_out)
 {
-	android::String16 driver, ifname, confname, bridge_ifname;
-
 	/* Check if required Ifname argument is missing */
-	if (!params.getString(android::String16("Ifname"), &ifname)) {
+	if (params.ifname_.isEmpty()) {
 		return android::binder::Status::fromExceptionCode(
 		    android::binder::Status::EX_ILLEGAL_ARGUMENT,
 		    "Ifname missing in params.");
 	}
-	/* Retrieve the remaining params from the dictionary */
-	params.getString(android::String16("Driver"), &driver);
-	params.getString(android::String16("ConfigFile"), &confname);
-	params.getString(android::String16("BridgeIfname"), &bridge_ifname);
-
 	/*
 	 * Try to get the wpa_supplicant record for this iface, return
 	 * an error if we already control it.
 	 */
-	if (wpa_supplicant_get_iface(
-		wpa_global_, android::String8(ifname).string()) != NULL) {
+	if (wpa_supplicant_get_iface(wpa_global_, params.ifname_.string()) !=
+	    NULL) {
 		return android::binder::Status::fromServiceSpecificError(
 		    ERROR_IFACE_EXISTS,
 		    "wpa_supplicant already controls this interface.");
@@ -47,11 +40,10 @@
 	struct wpa_interface iface;
 
 	os_memset(&iface, 0, sizeof(iface));
-	iface.driver = os_strdup(android::String8(driver).string());
-	iface.ifname = os_strdup(android::String8(ifname).string());
-	iface.confname = os_strdup(android::String8(confname).string());
-	iface.bridge_ifname =
-	    os_strdup(android::String8(bridge_ifname).string());
+	iface.driver = os_strdup(params.driver_.string());
+	iface.ifname = os_strdup(params.ifname_.string());
+	iface.confname = os_strdup(params.config_file_.string());
+	iface.bridge_ifname = os_strdup(params.bridge_ifname_.string());
 	/* Otherwise, have wpa_supplicant attach to it. */
 	wpa_s = wpa_supplicant_add_iface(wpa_global_, &iface, NULL);
 	/* The supplicant core creates a corresponding binder object via
diff --git a/wpa_supplicant/binder/supplicant.h b/wpa_supplicant/binder/supplicant.h
index 10db25c..de85594 100644
--- a/wpa_supplicant/binder/supplicant.h
+++ b/wpa_supplicant/binder/supplicant.h
@@ -37,7 +37,7 @@
 
 	// Binder methods exposed in aidl.
 	android::binder::Status CreateInterface(
-	    const android::os::PersistableBundle &params,
+	    const fi::w1::wpa_supplicant::ParcelableIfaceParams &params,
 	    android::sp<fi::w1::wpa_supplicant::IIface> *iface_object_out)
 	    override;
 	android::binder::Status