Merge 721d2e2a198247090c59379546af81e83c710321 on remote branch

Change-Id: I275aab7c4206b31743d3221e0a3e57abff4e54a9
diff --git a/etc/init.qcom.usb.sh b/etc/init.qcom.usb.sh
index aa9cc21..a5ceb48 100644
--- a/etc/init.qcom.usb.sh
+++ b/etc/init.qcom.usb.sh
@@ -97,6 +97,9 @@
 	              "msm8998" | "sdm660" | "apq8098_latv")
 		          setprop persist.vendor.usb.config diag,serial_cdev,rmnet,adb
 		      ;;
+	              "monaco")
+		          setprop persist.vendor.usb.config diag,qdss,rmnet,adb
+		      ;;
 	              "sdm845" | "sdm710")
 		          setprop persist.vendor.usb.config diag,serial_cdev,rmnet,dpl,adb
 		      ;;
diff --git a/hal/Usb.cpp b/hal/Usb.cpp
index 8a4afae..083ad73 100644
--- a/hal/Usb.cpp
+++ b/hal/Usb.cpp
@@ -107,17 +107,23 @@
 
 std::string appendRoleNodeHelper(const std::string &portName,
                                  PortRoleType type) {
-  std::string node("/sys/class/typec/" + portName);
 
-  switch (type) {
-    case PortRoleType::DATA_ROLE:
-      return node + "/data_role";
-    case PortRoleType::POWER_ROLE:
-      return node + "/power_role";
-    case PortRoleType::MODE:
-      return node + "/port_type";
-    default:
-      return "";
+    if ((portName == "..") || (portName.find('/') != std::string::npos)) {
+       ALOGE("Fatal: invalid portName");
+       return "";
+    }
+
+    std::string node("/sys/class/typec/" + portName);
+
+    switch (type) {
+      case PortRoleType::DATA_ROLE:
+        return node + "/data_role";
+      case PortRoleType::POWER_ROLE:
+        return node + "/power_role";
+      case PortRoleType::MODE:
+        return node + "/port_type";
+      default:
+        return "";
   }
 }
 
@@ -1058,9 +1064,16 @@
 static bool checkUsbInterfaceAutoSuspend(const std::string& devicePath,
         const std::string &intf) {
   std::string bInterfaceClass;
-  int interfaceClass, ret = -1;
+  int interfaceClass, ret = -1, retry = 3;
 
-  readFile(devicePath + "/" + intf + "/bInterfaceClass", &bInterfaceClass);
+  do {
+	  readFile(devicePath + "/" + intf + "/bInterfaceClass",
+			  &bInterfaceClass);
+  } while ((--retry > 0) && (bInterfaceClass.length() == 0));
+
+  if (bInterfaceClass.length() == 0) {
+	  return false;
+  }
   interfaceClass = std::stoi(bInterfaceClass, 0, 16);
 
   // allow autosuspend for certain class devices