Use vport_trigger tool in init.vsoc.rc.

Switch over to chaining the start of the seriallogging and usbforward
services from the vport_trigger tool. This tool makes sure that the
sys.cf.ser.<qemuport> properties are set up to specify the device node
that should be used. The init script symlinks the encoded vportXpY names
to the qemuport name set up by the tool, then enables the applicable
services.

If run on a kernel with the hack which renamed the virtio serial devices
to the qemu name, the tool does has no effect, and the symlink command
will do nothing (as per 'man symlink', "If linkpath exists, it will not
be overwritten.").

This replaces a kernel hack that had a similar effect, without using
symlinks. (This hack cannot be upstreamed.)

Bug: 77656836
Change-Id: Ic9a127994030f6676512196b7b4987808876c85d
diff --git a/shared/config/init.vsoc.rc b/shared/config/init.vsoc.rc
index 5b87b4f..759a1a2 100644
--- a/shared/config/init.vsoc.rc
+++ b/shared/config/init.vsoc.rc
@@ -55,7 +55,7 @@
     mkdir /data/dalvik-cache/x86 0771 root system
     mkdir /data/misc/dhcp-6.8.2 0755 dhcp root
     start gce_fs_monitor
-    start seriallogging
+    start vport_trigger
 
 
 on early-boot
@@ -87,6 +87,20 @@
 service socket_forward_proxy /vendor/bin/socket_forward_proxy
 
 
+service vport_trigger /vendor/bin/vport_trigger
+    oneshot
+
+
+on property:sys.cf.ser.cf-logcat=*
+    symlink ${sys.cf.ser.cf-logcat} /dev/cf-logcat
+    enable seriallogging
+
+
+on property:sys.cf.ser.cf-gadget-usb-v1=*
+    symlink ${sys.cf.ser.cf-gadget-usb-v1} /dev/cf-gadget-usb-v1
+    enable usbforward
+
+
 service seriallogging /system/bin/logcat -b all -v threadtime -f /dev/cf-logcat *:V
     class main
     user root
@@ -111,6 +125,7 @@
 service usbforward /vendor/bin/usbforward /dev/cf-gadget-usb-v1
     class late_start
     user root
+    disabled
 
 
 service wifi_relay /vendor/bin/wifi_relay
diff --git a/shared/device.mk b/shared/device.mk
index ddfcd77..450bc26 100644
--- a/shared/device.mk
+++ b/shared/device.mk
@@ -65,6 +65,7 @@
     wifi_relay \
     wpa_supplicant.vsoc.conf \
     vsoc_input_service \
+    vport_trigger
 
 #
 # Packages for AOSP-available stuff we use from the framework
diff --git a/shared/sepolicy/file_contexts b/shared/sepolicy/file_contexts
index af6c95d..4cf3c06 100644
--- a/shared/sepolicy/file_contexts
+++ b/shared/sepolicy/file_contexts
@@ -34,6 +34,7 @@
 /vendor/bin/wificlient  u:object_r:wificlient_exec:s0
 /vendor/bin/wifirouter  u:object_r:wifirouter_exec:s0
 /vendor/bin/wifi_relay  u:object_r:wifi_relay_exec:s0
+/vendor/bin/vport_trigger  u:object_r:vport_trigger_exec:s0
 /vendor/bin/hw/android\.hardware\.bluetooth@1\.0-service\.sim             u:object_r:hal_bluetooth_sim_exec:s0
 /vendor/bin/hw/android\.hardware\.dumpstate@1\.0-service\.cuttlefish      u:object_r:hal_dumpstate_impl_exec:s0
 /vendor/bin/hw/android\.hardware\.health@2\.0-service.cuttlefish          u:object_r:hal_health_default_exec:s0
diff --git a/shared/sepolicy/property_contexts b/shared/sepolicy/property_contexts
new file mode 100644
index 0000000..fc2a087
--- /dev/null
+++ b/shared/sepolicy/property_contexts
@@ -0,0 +1 @@
+sys.cf.ser.  u:object_r:sys_cf_ser_prop:s0
diff --git a/shared/sepolicy/vport_trigger.te b/shared/sepolicy/vport_trigger.te
new file mode 100644
index 0000000..4a2e874
--- /dev/null
+++ b/shared/sepolicy/vport_trigger.te
@@ -0,0 +1,10 @@
+type vport_trigger, domain;
+type vport_trigger_exec, exec_type, vendor_file_type, file_type;
+
+type sys_cf_ser_prop, property_type;
+
+init_daemon_domain(vport_trigger)
+
+r_dir_file(vport_trigger, sysfs_type)
+
+set_prop(vport_trigger, sys_cf_ser_prop)