Merge 710ecf85c546bfd70337e52e678793515850f37e on remote branch

Change-Id: If86035ceb33009945fa15af34a40d9200a68feaa
diff --git a/etc/init.qcom.usb.rc b/etc/init.qcom.usb.rc
index 2653ee3..19896b0 100644
--- a/etc/init.qcom.usb.rc
+++ b/etc/init.qcom.usb.rc
@@ -42,7 +42,7 @@
     setprop sys.usb.config mass_storage
     setprop sys.usb.configfs 1
 
-on boot
+on post-fs
     mount configfs none /config
     mkdir /config/usb_gadget/g1 0770
     mkdir /config/usb_gadget/g2 0770
@@ -108,9 +108,8 @@
     exec u:r:vendor_qti_init_shell:s0 -- /vendor/bin/init.qcom.usb.sh
     write /config/usb_gadget/g1/strings/0x409/product ${vendor.usb.product_string}
     write /config/usb_gadget/g2/strings/0x409/product ${vendor.usb.product_string}
-    setprop sys.usb.config ${persist.vendor.usb.config}
 
-on boot && property:vendor.usb.use_ffs_mtp=1
+on post-fs && property:vendor.usb.use_ffs_mtp=1
    mkdir /config/usb_gadget/g1/functions/ffs.mtp
    mkdir /config/usb_gadget/g1/functions/ffs.ptp
    mkdir /dev/usb-ffs/mtp 0770 mtp mtp
@@ -118,6 +117,9 @@
    mkdir /dev/usb-ffs/ptp 0770 mtp mtp
    mount functionfs ptp /dev/usb-ffs/ptp rmode=0770,fmode=0660,uid=1024,gid=1024,no_disconnect=1
 
+on boot
+    setprop sys.usb.config ${persist.vendor.usb.config}
+
 on boot && property:vendor.usb.use_gadget_hal=1
    setprop sys.usb.configfs 2
 
diff --git a/etc/init.qti.usb.debug.sh b/etc/init.qti.usb.debug.sh
index 203679d..29b4421 100644
--- a/etc/init.qti.usb.debug.sh
+++ b/etc/init.qti.usb.debug.sh
@@ -27,8 +27,10 @@
 # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #
 
+prop_enabled=`getprop persist.vendor.usb.enable_ftrace 0`
+
 # bail out if its perf config
-if [ ! -d /sys/module/msm_rtb ]; then
+if [ "$prop_enabled" == "0" -a ! -d /sys/module/msm_rtb ]; then
     return
 fi
 
diff --git a/hal/UsbGadget.cpp b/hal/UsbGadget.cpp
index f9284b7..eebd889 100644
--- a/hal/UsbGadget.cpp
+++ b/hal/UsbGadget.cpp
@@ -43,6 +43,7 @@
 #define PERSIST_VENDOR_USB_PROP "persist.vendor.usb.config"
 #define PERSIST_VENDOR_USB_EXTRA_PROP "persist.vendor.usb.config.extra"
 #define QDSS_INST_NAME_PROP "vendor.usb.qdss.inst.name"
+#define CONFIG_STRING CONFIG_PATH "strings/0x409/configuration"
 
 namespace android {
 namespace hardware {
@@ -246,6 +247,8 @@
   if (actual_order != nullptr)
     prop = actual_order;
 
+  WriteStringToFile(prop, CONFIG_STRING);
+
   // tokenize the prop string and add each function individually
   for (size_t start = 0; start != std::string::npos; ) {
     size_t end = prop.find_first_of(',', start);
@@ -388,6 +391,8 @@
       if (addAdb(&mMonitorFfs, &i) != Status::SUCCESS) return Status::ERROR;
     }
   } else { // standard Android supported functions
+    WriteStringToFile("android", CONFIG_STRING);
+
     if (addGenericAndroidFunctions(&mMonitorFfs, functions, &ffsEnabled, &i)
               != Status::SUCCESS)
       return Status::ERROR;
diff --git a/vendor_product.mk b/vendor_product.mk
index e78ed7c..1174317 100644
--- a/vendor_product.mk
+++ b/vendor_product.mk
@@ -42,6 +42,7 @@
 
 ifneq ($(TARGET_KERNEL_VERSION),$(filter $(TARGET_KERNEL_VERSION),4.9 4.14 4.19))
   PRODUCT_PROPERTY_OVERRIDES += vendor.usb.use_ffs_mtp=1
+  PRODUCT_PROPERTY_OVERRIDES += sys.usb.mtp.batchcancel=1
 else
   PRODUCT_PROPERTY_OVERRIDES += vendor.usb.use_ffs_mtp=0
 endif