[Android Q&A, Help & Troubleshooting] A.Yatulchik:
Hello yuweng!

I propose to change the script rc.init in TWRP 2.7.1.0 as follows:

import /init.recovery.${ro.hardware}.rc

on early-init

start ueventd

start healthd

on init

export PATH /sbin:/system/bin

export LD_LIBRARY_PATH .:/sbin

export ANDROID_ROOT /system

export ANDROID_DATA /data

export EXTERNAL_STORAGE /sdcard

symlink /system/etc /etc

mkdir /boot

mkdir /recovery

mkdir /system

mkdir /cache

mkdir /data

mkdir /emmc

mkdir /sdcard

mount /tmp /tmp tmpfs

insmod /sec.ko

mknod /dev/sec c 182 0

chmod 0660 /dev/sec

chown root shell /tmp

chmod 0775 /tmp

write /sys/class/android_usb/android0/enable 0

write /sys/class/android_usb/android0/idVendor 18D1

write /sys/class/android_usb/android0/idProduct D001

write /sys/class/android_usb/android0/functions adb

write /sys/class/android_usb/android0/iManufacturer ${ro.product.manufacturer}

write /sys/class/android_usb/android0/iProduct ${ro.product.model}

write /sys/class/android_usb/android0/iSerial ${ro.serialno}

on boot

ifup lo

hostname localhost

domainname localdomain

class_start default

on property:sys.powerctl=*

powerctl ${sys.powerctl}

on property:sys.storage.ums_enabled=1

write /sys/class/android_usb/android0/enable 0

write /sys/class/android_usb/android0/idVendor 0bb4

write /sys/class/android_usb/android0/idProduct 0005

write /sys/class/android_usb/android0/functions mass_storage,adb

write /sys/class/android_usb/android0/enable 1

on property:sys.storage.ums_enabled=0

write /sys/class/android_usb/android0/enable 0

write /sys/class/android_usb/android0/idVendor 18D1

write /sys/class/android_usb/android0/idProduct D001

write /sys/class/android_usb/android0/functions adb

write /sys/class/android_usb/android0/enable 1

service ueventd /sbin/ueventd

critical

service healthd /sbin/healthd -n

critical

service recovery /sbin/recovery

service adbd /sbin/adbd recovery

disabled

socket adbd stream 660 system system

# Always start adbd on userdebug and eng builds

on property:ro.debuggable=1

#write /sys/class/android_usb/android0/enable 1

#start adbd

setprop service.adb.root 1

# Restart adbd so it can run as root

on property:service.adb.root=1

write /sys/class/android_usb/android0/enable 0

restart adbd

write /sys/class/android_usb/android0/enable 1

my recovery.fstab:

# mount point	fstype device	[device2]

/misc	emmc /dev/misc

/system	ext4 /dev/block/mmcblk0p3

/data	ext4 /dev/block/mmcblk0p5

/cache	ext4 /dev/block/mmcblk0p4

/boot emmc /dev/bootimg

/recovery emmc /dev/recovery flags=display="Recovery";backup=1

/uboot emmc /dev/uboot flags=display="uboot";backup=1

/nvram emmc /dev/nvram flags=display="nvram";backup=1

/emmc	vfat /dev/block/mmcblk0p6	flags=display="Internal SD-card";storage;wipeingui;backup=1

/sdcard vfat /dev/block/mmcblk1p1 /dev/block/mmcblk1	flags=display="External SD-card";storage;wipeingui;removable

The result is:

1. ADB works when phone connected to a computer

2. After pressing the "Mount USB Storage" button - works ADB and USB storage (you can browse phone via ADB and via filemanager)

3 After pressing the "Unmount" button - ADB works without USB storage, but phone still accessible via ADB.

The default script does not give such functional and works is not entirely correct.