Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MTP #2

Open
wants to merge 1 commit into
base: halium-7.1_ubuntu
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions FP2.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion halium-overlay/lib/udev/rules.d/70-android.rules
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 21 additions & 0 deletions mtp-state.conf
Original file line number Diff line number Diff line change
@@ -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"
;;
mtp,adb)
/bin/bash /system/bin/setupusb mtp_adb
echo "mtp,adb"
;;
*)
echo "off"
;;
esac
end script

97 changes: 97 additions & 0 deletions setupusb
Original file line number Diff line number Diff line change
@@ -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