1#
2# Copyright (C) 2016 The Android Open-Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17on early-boot
18    mkdir /config/usb_gadget/g1 0770
19    mkdir /config/usb_gadget/g1/strings/0x409 0770
20    write /config/usb_gadget/g1/bcdUSB 0x0200
21    write /config/usb_gadget/g1/idVendor 0x18d1
22    write /config/usb_gadget/g1/bcdDevice 0x0440
23    write /config/usb_gadget/g1/strings/0x409/serialnumber ${ro.serialno}
24    write /config/usb_gadget/g1/strings/0x409/manufacturer ${ro.product.manufacturer}
25    write /config/usb_gadget/g1/strings/0x409/product ${ro.product.model}
26    mkdir /config/usb_gadget/g1/functions/accessory.gs2
27    mkdir /config/usb_gadget/g1/functions/audio_source.gs3
28    mkdir /config/usb_gadget/g1/functions/midi.gs5
29    mkdir /config/usb_gadget/g1/functions/ffs.adb
30    mkdir /config/usb_gadget/g1/functions/ffs.mtp
31    mkdir /config/usb_gadget/g1/functions/ffs.ptp
32    mkdir /config/usb_gadget/g1/functions/diag.diag
33    mkdir /config/usb_gadget/g1/functions/diag.diag_mdm
34    mkdir /config/usb_gadget/g1/functions/cser.dun.0
35    mkdir /config/usb_gadget/g1/functions/cser.nmea.1
36    mkdir /config/usb_gadget/g1/functions/gsi.rmnet
37    mkdir /config/usb_gadget/g1/functions/gsi.rndis
38    mkdir /config/usb_gadget/g1/functions/gsi.dpl
39    mkdir /config/usb_gadget/g1/functions/qdss.qdss
40    mkdir /config/usb_gadget/g1/functions/qdss.qdss_mdm
41    mkdir /config/usb_gadget/g1/configs/b.1 0770
42    write /config/usb_gadget/g1/os_desc/b_vendor_code 0x1
43    write /config/usb_gadget/g1/os_desc/qw_sign "MSFT100"
44    mkdir /dev/usb-ffs 0775 shell shell
45    mkdir /dev/usb-ffs/adb 0770 shell shell
46    mount functionfs adb /dev/usb-ffs/adb rmode=0770,fmode=0660,uid=2000,gid=2000,no_disconnect=1
47    mkdir /dev/usb-ffs/mtp 0770 mtp mtp
48    mkdir /dev/usb-ffs/ptp 0770 mtp mtp
49    mount functionfs mtp /dev/usb-ffs/mtp rmode=0770,fmode=0660,uid=1024,gid=1024,no_disconnect=1
50    mount functionfs ptp /dev/usb-ffs/ptp rmode=0770,fmode=0660,uid=1024,gid=1024,no_disconnect=1
51    setprop sys.usb.mtp.device_type 3
52    setprop sys.usb.controller "a600000.dwc3"
53    symlink /config/usb_gadget/g1/configs/b.1 /config/usb_gadget/g1/os_desc/b.1
54    write /sys/module/libcomposite/parameters/disable_l1_for_hs "y"
55    write /config/usb_gadget/g1/functions/gsi.rndis/rndis_class_id 1
56
57    # chown file/folder permission
58    chown system system /config/usb_gadget/
59    chown system system /config/usb_gadget/g1
60    chown system system /config/usb_gadget/g1/UDC
61    chown system system /config/usb_gadget/g1/bDeviceClass
62    chown system system /config/usb_gadget/g1/bDeviceProtocol
63    chown system system /config/usb_gadget/g1/bDeviceSubClass
64    chown system system /config/usb_gadget/g1/bMaxPacketSize0
65    chown system system /config/usb_gadget/g1/bcdDevice
66    chown system system /config/usb_gadget/g1/bcdUSB
67    chown system system /config/usb_gadget/g1/configs
68    chown system system /config/usb_gadget/g1/configs/b.1
69    chown system system /config/usb_gadget/g1/configs/b.1/MaxPower
70    chown system system /config/usb_gadget/g1/configs/b.1/bmAttributes
71    chown system system /config/usb_gadget/g1/configs/b.1/strings
72    chown system system /config/usb_gadget/g1/functions
73    chown system system /config/usb_gadget/g1/functions/accessory.gs2
74    chown system system /config/usb_gadget/g1/functions/audio_source.gs3
75    chown system system /config/usb_gadget/g1/functions/cser.dun.i0
76    chown system system /config/usb_gadget/g1/functions/cser.dun.i0/status
77    chown system system /config/usb_gadget/g1/functions/cser.nmea.1
78    chown system system /config/usb_gadget/g1/functions/cser.nmea.1/status
79    chown system system /config/usb_gadget/g1/functions/diag.diag
80    chown system system /config/usb_gadget/g1/functions/diag.diag_mdm
81    chown system system /config/usb_gadget/g1/functions/ffs.adb
82    chown system system /config/usb_gadget/g1/functions/ffs.mtp
83    chown system system /config/usb_gadget/g1/functions/ffs.ptp
84    chown system system /config/usb_gadget/g1/functions/gsi.dpl
85    chown system system /config/usb_gadget/g1/functions/gsi.dpl/info
86    chown system system /config/usb_gadget/g1/functions/gsi.rmnet
87    chown system system /config/usb_gadget/g1/functions/gsi.rmnet/info
88    chown system system /config/usb_gadget/g1/functions/gsi.rndis
89    chown system system /config/usb_gadget/g1/functions/gsi.rndis/info
90    chown system system /config/usb_gadget/g1/functions/gsi.rndis/rndis_class_id
91    chown system system /config/usb_gadget/g1/functions/midi.gs5
92    chown system system /config/usb_gadget/g1/functions/midi.gs5/buflen
93    chown system system /config/usb_gadget/g1/functions/midi.gs5/id
94    chown system system /config/usb_gadget/g1/functions/midi.gs5/in_ports
95    chown system system /config/usb_gadget/g1/functions/midi.gs5/index
96    chown system system /config/usb_gadget/g1/functions/midi.gs5/out_ports
97    chown system system /config/usb_gadget/g1/functions/midi.gs5/qlen
98    chown system system /config/usb_gadget/g1/functions/qdss.qdss
99    chown system system /config/usb_gadget/g1/functions/qdss.qdss/enable_debug_inface
100    chown system system /config/usb_gadget/g1/functions/qdss.qdss_mdm
101    chown system system /config/usb_gadget/g1/functions/qdss.qdss_mdm/enable_debug_inface
102    chown system system /config/usb_gadget/g1/idProduct
103    chown system system /config/usb_gadget/g1/idVendor
104    chown system system /config/usb_gadget/g1/max_speed
105    chown system system /config/usb_gadget/g1/os_desc
106    chown system system /config/usb_gadget/g1/os_desc/b.1
107    chown system system /config/usb_gadget/g1/os_desc/b.1/MaxPower
108    chown system system /config/usb_gadget/g1/os_desc/b.1/bmAttributes
109    chown system system /config/usb_gadget/g1/os_desc/b.1/strings
110    chown system system /config/usb_gadget/g1/os_desc/b_vendor_code
111    chown system system /config/usb_gadget/g1/os_desc/qw_sign
112    chown system system /config/usb_gadget/g1/os_desc/use
113    chown system system /config/usb_gadget/g1/strings
114    chown system system /config/usb_gadget/g1/strings/0x409
115    chown system system /config/usb_gadget/g1/strings/0x409/manufacturer
116    chown system system /config/usb_gadget/g1/strings/0x409/product
117    chown system system /config/usb_gadget/g1/strings/0x409/serialnumber
118
119on property:init.svc.console=running
120    write /sys/class/power_supply/usb/moisture_detection_enabled 0
121
122on property:init.svc.vendor.charger=running
123    write /sys/class/typec/port0/port_type sink
124
125on property:vendor.usb.contaminantdisable=true
126    write /sys/class/power_supply/usb/moisture_detection_enabled 0
127
128on boot
129    setprop sys.usb.configfs 2
130
131on property:sys.usb.config=none && property:sys.usb.configfs=1
132    rm /config/usb_gadget/g1/configs/b.1/f1
133    rm /config/usb_gadget/g1/configs/b.1/f2
134    rm /config/usb_gadget/g1/configs/b.1/f3
135    rm /config/usb_gadget/g1/configs/b.1/f4
136    rm /config/usb_gadget/g1/configs/b.1/f5
137    rm /config/usb_gadget/g1/configs/b.1/f6
138    rm /config/usb_gadget/g1/configs/b.1/f7
139    rm /config/usb_gadget/g1/configs/b.1/f8
140    rm /config/usb_gadget/g1/configs/b.1/f9
141
142on charger
143    mkdir /config/usb_gadget/g1 0770
144    mkdir /config/usb_gadget/g1/strings/0x409 0770
145    write /config/usb_gadget/g1/bcdUSB 0x0200
146    write /config/usb_gadget/g1/idVendor 0x18d1
147    write /config/usb_gadget/g1/bcdDevice 0x0440
148    write /config/usb_gadget/g1/strings/0x409/serialnumber ${ro.serialno}
149    write /config/usb_gadget/g1/strings/0x409/manufacturer Google
150    write /config/usb_gadget/g1/strings/0x409/product Pixel
151    mkdir /config/usb_gadget/g1/functions/midi.gs5
152    mkdir /config/usb_gadget/g1/configs/b.1 0770
153    mkdir /config/usb_gadget/g1/configs/b.1/strings/0x409 0770
154    symlink /config/usb_gadget/g1/configs/b.1 /config/usb_gadget/g1/os_desc/b.1
155    setprop sys.usb.controller "a600000.dwc3"
156
157on property:ro.bootmode=charger
158    setprop sys.usb.config midi
159
160on property:sys.usb.config=midi && property:sys.usb.configfs=1
161    write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "midi"
162    rm /config/usb_gadget/g1/configs/b.1/f1
163    rm /config/usb_gadget/g1/configs/b.1/f2
164    rm /config/usb_gadget/g1/configs/b.1/f3
165    rm /config/usb_gadget/g1/configs/b.1/f4
166    write /config/usb_gadget/g1/idVendor 0x18d1
167    write /config/usb_gadget/g1/idProduct 0x4eea
168    symlink /config/usb_gadget/g1/functions/midi.gs5 /config/usb_gadget/g1/configs/b.1/f1
169    write /config/usb_gadget/g1/UDC ${sys.usb.controller}
170    setprop sys.usb.state ${sys.usb.config}
171