Merge "init.qcom.usb.sh: Extend UVC resolutions"
diff --git a/hal/Usb.cpp b/hal/Usb.cpp
index e522979..01fc78e 100644
--- a/hal/Usb.cpp
+++ b/hal/Usb.cpp
@@ -103,17 +103,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 "";
   }
 }
 
@@ -1024,9 +1030,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
diff --git a/hal/UsbGadget.cpp b/hal/UsbGadget.cpp
index 3757671..78e73d5 100644
--- a/hal/UsbGadget.cpp
+++ b/hal/UsbGadget.cpp
@@ -233,6 +233,8 @@
 
 Return<void> UsbGadget::getCurrentUsbFunctions(
     const sp<V1_0::IUsbGadgetCallback> &callback) {
+  if (!callback) return Void();
+
   Return<void> ret = callback->getCurrentUsbFunctionsCb(
       mCurrentUsbFunctions, mCurrentUsbFunctionsApplied
                                 ? Status::FUNCTIONS_APPLIED