usb: 1.3-basic: Implement enableUsbDataSignal method for legacy USB restrict

Change-Id: I657b2595777327c92ec88c168e93ff988162f546
diff --git a/usb/1.3-basic/Usb.cpp b/usb/1.3-basic/Usb.cpp
index 0edb0d4..4592dbd 100644
--- a/usb/1.3-basic/Usb.cpp
+++ b/usb/1.3-basic/Usb.cpp
@@ -19,6 +19,7 @@
 
 #define LOG_TAG "android.hardware.usb@1.3-service-basic"
 
+#include <android-base/file.h>
 #include <android-base/logging.h>
 #include <utils/Errors.h>
 #include <utils/StrongPointer.h>
@@ -131,9 +132,14 @@
 }
 
 // Methods from ::android::hardware::usb::V1_3::IUsb follow.
-Return<bool> Usb::enableUsbDataSignal(bool enable __unused) {
-    // TODO implement
-    return bool{};
+Return<bool> Usb::enableUsbDataSignal(bool enable) {
+    bool success =
+            android::base::WriteStringToFile(enable ? "0" : "1", "/proc/sys/kernel/deny_new_usb");
+    if (success)
+        queryPortStatus();
+    else
+        LOG(ERROR) << __func__ << ": Failed to " << (enable ? "enable" : "disable");
+    return success;
 }
 
 }  // namespace implementation
diff --git a/usb/1.3-basic/android.hardware.usb@1.3-service.basic.rc b/usb/1.3-basic/android.hardware.usb@1.3-service.basic.rc
index d0ff95f..afa9293 100644
--- a/usb/1.3-basic/android.hardware.usb@1.3-service.basic.rc
+++ b/usb/1.3-basic/android.hardware.usb@1.3-service.basic.rc
@@ -4,5 +4,7 @@
     interface android.hardware.usb@1.2::IUsb default
     interface android.hardware.usb@1.3::IUsb default
     class hal
-    user system
-    group system
+    user root
+    group root
+
+# Note: Running as root user is required for writing to /proc/sys/kernel/deny_new_usb