Adding TARGET_OTA_ASSERT_DEVICE flag for custom device asserts

Should be handled via device tree's BoardConfig
Sample will be TARGET_OTA_ASSERT_DEVICE := le_zl1,zl1,lepro3,lex720,lex727,LEX720,LEX727 in BoardConfig
Only applicable for AB or VAB devices

Change-Id: I1fbe6155d3f79eee089a31dbe62ee9d04c33d65c
diff --git a/Android.mk b/Android.mk
index 67e7d4c..5f2916a 100755
--- a/Android.mk
+++ b/Android.mk
@@ -401,6 +401,9 @@
 ifeq ($(TW_EXCLUDE_NANO), true)
     LOCAL_CFLAGS += -DTW_EXCLUDE_NANO
 endif
+ifneq ($(TARGET_OTA_ASSERT_DEVICE),)
+    LOCAL_CFLAGS += -DTARGET_OTA_ASSERT_DEVICE='"$(TARGET_OTA_ASSERT_DEVICE)"'
+endif
 
 LOCAL_C_INCLUDES += system/vold \
 
diff --git a/twrp.cpp b/twrp.cpp
index 564454a..c84c99e 100644
--- a/twrp.cpp
+++ b/twrp.cpp
@@ -377,6 +377,10 @@
 	property_set("ro.twrp.boot", "1");
 	property_set("ro.twrp.version", TW_VERSION_STR);
 
+#ifdef TARGET_OTA_ASSERT_DEVICE
+	property_set("ro.twrp.target.devices", TARGET_OTA_ASSERT_DEVICE);
+#endif
+
 	time_t StartupTime = time(NULL);
 	printf("Starting TWRP %s-%s on %s (pid %d)\n", TW_VERSION_STR, TW_GIT_REVISION, ctime(&StartupTime), getpid());
 
diff --git a/twrpinstall/installcommand.cpp b/twrpinstall/installcommand.cpp
index d577b38..88c90f8 100755
--- a/twrpinstall/installcommand.cpp
+++ b/twrpinstall/installcommand.cpp
@@ -132,6 +132,15 @@
 
     bool deviceExists = false;
 
+    // twrp.target.devices
+    bool has_target_devices = false;
+    char tw_devices[PROPERTY_VALUE_MAX * 2];
+    property_get("ro.twrp.target.devices", tw_devices, "");
+    std::vector<std::string> TWRP_devices = android::base::Split(tw_devices, ",");
+    if (strlen(tw_devices) > 1) {
+       has_target_devices = true;
+    }
+
     for(const std::string& deviceAssert : assertResults)
     {
         std::string assertName = android::base::Trim(deviceAssert);
@@ -139,6 +148,17 @@
             deviceExists = true;
             break;
         }
+        // twrp.target.devices
+        else if (has_target_devices) {
+           for(const std::string& twrpDevice_x : TWRP_devices) {
+               std::string twrpName = android::base::Trim(twrpDevice_x);
+               if (!twrpName.empty() && !assertName.empty() && assertName == twrpName) {
+            	   deviceExists = true;
+            	   printf("Package is for product %s. The selected TWRP target device is %s\n", pkg_device.c_str(), twrpName.c_str());
+            	   break;
+               }
+           }
+        }
     }
 
     if (!deviceExists) {