diff --git a/FP2.mk b/FP2.mk index e9d3d34..3421214 100644 --- a/FP2.mk +++ b/FP2.mk @@ -27,6 +27,11 @@ PRODUCT_COPY_FILES += \ $(LOCAL_PATH)/media/media_codecs_performance.xml:system/etc/media_codecs_performance.xml \ $(LOCAL_PATH)/media/media_profiles_8974.xml:system/etc/media_profiles.xml +# Ubuntu Touch: USB port handling +PRODUCT_COPY_FILES += \ + $(LOCAL_PATH)/setupusb:system/bin/setupusb \ + $(LOCAL_PATH)/mtp-state.conf:system/halium/etc/init/mtp-state.conf + # IPC router PRODUCT_COPY_FILES += \ $(LOCAL_PATH)/configs/sec_config:system/etc/sec_config diff --git a/halium-overlay/lib/udev/rules.d/70-android.rules b/halium-overlay/lib/udev/rules.d/70-android.rules index 1105745..4a82d19 100644 --- a/halium-overlay/lib/udev/rules.d/70-android.rules +++ b/halium-overlay/lib/udev/rules.d/70-android.rules @@ -193,7 +193,7 @@ ACTION=="add", KERNEL=="qmi0", OWNER="radio", GROUP="radio", MODE="0640" ACTION=="add", KERNEL=="qmi1", OWNER="radio", GROUP="radio", MODE="0640" ACTION=="add", KERNEL=="qmi2", OWNER="radio", GROUP="radio", MODE="0640" ACTION=="add", KERNEL=="bus/usb/*", OWNER="root", GROUP="usb", MODE="0660" -ACTION=="add", KERNEL=="mtp_usb", OWNER="root", GROUP="mtp", MODE="0660" +ACTION=="add", KERNEL=="mtp_usb", OWNER="root", GROUP="plugdev", MODE="0660" ACTION=="add", KERNEL=="usb_accessory", OWNER="root", GROUP="usb", MODE="0660" ACTION=="add", KERNEL=="tun", OWNER="system", GROUP="vpn", MODE="0660" ACTION=="add", KERNEL=="ts0710mux*", OWNER="radio", GROUP="radio", MODE="0640" diff --git a/mtp-state.conf b/mtp-state.conf new file mode 100644 index 0000000..02eab5b --- /dev/null +++ b/mtp-state.conf @@ -0,0 +1,21 @@ +start on (android-container persist.sys.usb.config=* or android) and started lightdm + +task + +script + VAL=$(getprop persist.sys.usb.config) + case ${VAL} in + mtp) + /bin/bash /system/bin/setupusb mtp + echo "mtp" + ;; + adb,mtp) + /bin/bash /system/bin/setupusb mtp_adb + echo "adb,mtp" + ;; + *) + echo "off" + ;; + esac +end script + diff --git a/setupusb b/setupusb new file mode 100644 index 0000000..f69c574 --- /dev/null +++ b/setupusb @@ -0,0 +1,97 @@ +SERIALNUMBER=`getprop ro.serialno` +MANUFACTURER=`getprop ro.product.manufacturer` +PRODUCT=`getprop ro.product.model` +PRODUCT_ID_SUFFIX=`getprop ro.usb.pid_suffix` +CONTROLLER=`getprop sys.usb.controller` +ANDROID_USB=/sys/class/android_usb/android0 + +write() { + if [ ! -e "$1" ]; then + return + fi + echo -n "$2" >"$1" +} + +symlink() { + ln -s "$1" "$2" +} + +setup_mtp() { + write $ANDROID_USB/enable 0 + write $ANDROID_USB/android0/iSerial $SERIALNUMBER + write $ANDROID_USB/idVendor 05C6 + write $ANDROID_USB/idProduct F003 + write $ANDROID_USB/functions mtp + write $ANDROID_USB/enable 1 + setprop sys.usb.state mtp +} + +setup_adb() { + setprop sys.usb.config adb +} + +setup_mtp_adb() { + write $ANDROID_USB/enable 0 + write $ANDROID_USB/functions "" + write $ANDROID_USB/enable 1 + sleep 10 # 0.5 delay to attempt to remove rndis function + write $ANDROID_USB/enable 0 + write $ANDROID_USB/idVendor 1004 + write $ANDROID_USB/idProduct 62CE + write $ANDROID_USB/iManufacturer "Mer Boat Loader" + write $ANDROID_USB/iProduct "$PRODUCT" + write $ANDROID_USB/iSerial "$SERIALNUMBER" + write $ANDROID_USB/functions mtp,adb:mtp,acm,diag,adb + write $ANDROID_USB/enable 1 + # setprop sys.usb.state mtp,adb +} + +setup_rndis() { + write $ANDROID_USB/enable 0 + write $ANDROID_USB/functions "" + write $ANDROID_USB/enable 1 + sleep 10 # 0.5 delay to attempt to remove rndis function + write $ANDROID_USB/enable 0 + write $ANDROID_USB/idVendor 1004 + write $ANDROID_USB/idProduct 62CE + write $ANDROID_USB/iManufacturer "Mer Boat Loader" + write $ANDROID_USB/iProduct "$PRODUCT" + write $ANDROID_USB/iSerial "$SERIALNUMBER" + write $ANDROID_USB/functions rndis + write $ANDROID_USB/enable 1 + # setprop sys.usb.state rndis +} + +reset_usb() { + write $ANDROID_USB/enable 0 + write $ANDROID_USB/functions "" + write $ANDROID_USB/enable 1 +} + +setup_boot() { + if [ -e /dev/.usb_setup_done ]; then + echo "Boot setup done" + return + fi + + touch /dev/.usb_setup_done +} + +setup_boot + +if [ "$1" == "rndis" ]; then + setup_rndis +elif [ "$1" == "mtp" ]; then + setup_mtp +elif [ "$1" == "adb" ]; then + setup_adb +elif [ "$1" == "mtp_adb" ]; then + setup_mtp_adb +elif [ "$1" == "reset" ]; then + reset_usb +else + echo "No configuration selected." +fi + +exit 0 +