Extract arch-specific updater binary if present

Check for and extract arch specific updater binary based on
ro.product.cpu.abilist and use ro.product.cpu.abi as a fall back.
If no arch specific updater binary is present then use the regular
update-binary file. Note that a file named update-binary must be
present in the zip still even if it is a 0 byte file.

Change-Id: Iabb2156e68d40c5b99d55ea8e4a9a553eb26600a
diff --git a/twinstall.cpp b/twinstall.cpp
index e4b11a7..8bbafca 100755
--- a/twinstall.cpp
+++ b/twinstall.cpp
@@ -32,6 +32,7 @@
 
 #include <string.h>
 #include <stdio.h>
+#include <cutils/properties.h>
 
 #include "twcommon.h"
 #include "mtdutils/mounts.h"
@@ -154,7 +155,24 @@
 }
 
 static int Prepare_Update_Binary(const char *path, ZipWrap *Zip, int* wipe_cache) {
-	if (!Zip->ExtractEntry(ASSUMED_UPDATE_BINARY_NAME, TMP_UPDATER_BINARY_PATH, 0755)) {
+	char arches[PATH_MAX];
+	std::string binary_name = ASSUMED_UPDATE_BINARY_NAME;
+	property_get("ro.product.cpu.abilist", arches, "error");
+	if (strcmp(arches, "error") == 0)
+		property_get("ro.product.cpu.abi", arches, "error");
+	vector<string> split = TWFunc::split_string(arches, ',', true);
+	std::vector<string>::iterator arch;
+	std::string base_name = binary_name;
+	base_name += "-";
+	for (arch = split.begin(); arch != split.end(); arch++) {
+		std::string temp = base_name + *arch;
+		if (Zip->EntryExists(temp)) {
+			binary_name = temp;
+			break;
+		}
+	}
+	LOGINFO("Extracting updater binary '%s'\n", binary_name.c_str());
+	if (!Zip->ExtractEntry(binary_name.c_str(), TMP_UPDATER_BINARY_PATH, 0755)) {
 		Zip->Close();
 		LOGERR("Could not extract '%s'\n", ASSUMED_UPDATE_BINARY_NAME);
 		return INSTALL_ERROR;