usb: Allow overriding device/controller names

Not all QC devices use the same paths, allow overriding them via props.
Default to the most used names according to device/qcom/sepolicy_vndr.

Change-Id: I67ec528ecf1efedb8ba9f6b7bae2e7edb28ae454
diff --git a/hal/Usb.cpp b/hal/Usb.cpp
index 8acea79..e30eaff 100644
--- a/hal/Usb.cpp
+++ b/hal/Usb.cpp
@@ -62,27 +62,27 @@
   ALOGI("Userspace turn %s USB data signaling", enable ? "on" : "off");
 
   if (enable) {
-    if (!WriteStringToFile("1", USB_DATA_PATH)) {
+    if (!WriteStringToFile("1", mDevicePath + USB_DATA_PATH)) {
       ALOGE("Not able to turn on usb connection notification");
       result = false;
     }
 
-    if (!WriteStringToFile(kGadgetName, PULLUP_PATH)) {
+    if (!WriteStringToFile(mGadgetName, PULLUP_PATH)) {
       ALOGE("Gadget cannot be pulled up");
       result = false;
     }
   } else {
-    if (!WriteStringToFile("1", ID_PATH)) {
+    if (!WriteStringToFile("1", mDevicePath + ID_PATH)) {
       ALOGE("Not able to turn off host mode");
       result = false;
     }
 
-    if (!WriteStringToFile("0", VBUS_PATH)) {
+    if (!WriteStringToFile("0", mDevicePath + VBUS_PATH)) {
       ALOGE("Not able to set Vbus state");
       result = false;
     }
 
-    if (!WriteStringToFile("0", USB_DATA_PATH)) {
+    if (!WriteStringToFile("0", mDevicePath + USB_DATA_PATH)) {
       ALOGE("Not able to turn off usb connection notification");
       result = false;
     }
@@ -276,12 +276,14 @@
   return roleSwitch;
 }
 
-Usb::Usb()
+Usb::Usb(std::string deviceName, std::string gadgetName)
         : mLock(PTHREAD_MUTEX_INITIALIZER),
           mRoleSwitchLock(PTHREAD_MUTEX_INITIALIZER),
           mPartnerLock(PTHREAD_MUTEX_INITIALIZER),
           mPartnerUp(false),
-          mContaminantPresence(false) {
+          mContaminantPresence(false),
+          mDevicePath(SOC_PATH + deviceName + "/"),
+          mGadgetName(gadgetName) {
     pthread_condattr_t attr;
     if (pthread_condattr_init(&attr)) {
         ALOGE("pthread_condattr_init failed: %s", strerror(errno));
@@ -1189,12 +1191,15 @@
 }  // namespace android
 
 int main() {
+  using android::base::GetProperty;
   using android::hardware::configureRpcThreadpool;
   using android::hardware::joinRpcThreadpool;
   using android::hardware::usb::V1_3::IUsb;
   using android::hardware::usb::V1_3::implementation::Usb;
 
-  android::sp<IUsb> service = new Usb();
+  android::sp<IUsb> service = new Usb(
+      GetProperty(USB_DEVICE_PROP, "a600000.ssusb"),
+      GetProperty(USB_CONTROLLER_PROP, "a600000.dwc3"));
 
   configureRpcThreadpool(1, true /*callerWillJoin*/);
   android::status_t status = service->registerAsService();
diff --git a/hal/Usb.h b/hal/Usb.h
index 61f5064..a64197f 100644
--- a/hal/Usb.h
+++ b/hal/Usb.h
@@ -16,6 +16,7 @@
 #pragma once
 
 #include <android-base/file.h>
+#include <android-base/properties.h>
 #include <android/hardware/usb/1.2/types.h>
 #include <android/hardware/usb/1.2/IUsbCallback.h>
 #include <android/hardware/usb/1.3/IUsb.h>
@@ -61,16 +62,18 @@
 using ::android::base::GetProperty;
 using ::android::base::WriteStringToFile;
 
-constexpr char kGadgetName[] = "a600000.dwc3";
-#define SOC_PATH "/sys/devices/platform/soc/a600000.ssusb/"
-#define ID_PATH SOC_PATH "id"
-#define VBUS_PATH SOC_PATH "b_sess"
-#define USB_DATA_PATH SOC_PATH "usb_data_enabled"
+#define USB_DEVICE_PROP "vendor.usb.device"
+#define SOC_PATH "/sys/devices/platform/soc/"
+#define ID_PATH "id"
+#define VBUS_PATH "b_sess"
+#define USB_DATA_PATH "usb_data_enabled"
+
+#define USB_CONTROLLER_PROP "vendor.usb.controller"
 #define GADGET_PATH "/config/usb_gadget/g1/"
 #define PULLUP_PATH GADGET_PATH "UDC"
 
 struct Usb : public IUsb {
-    Usb();
+    Usb(std::string deviceName, std::string gadgetName);
 
     Return<void> switchRole(const hidl_string& portName, const V1_0::PortRole& role) override;
     Return<void> setCallback(const sp<V1_0::IUsbCallback>& callback) override;
@@ -105,6 +108,9 @@
 
     private:
         pthread_t mPoll;
+
+        std::string mDevicePath;
+        std::string mGadgetName;
 };
 
 }  // namespace implementation