From c1a84560849fbcd6d8b4e48559a32ff4e1e2545b Mon Sep 17 00:00:00 2001 From: Pierre-Hugues Husson Date: Tue, 1 Oct 2019 13:32:49 +0200 Subject: [PATCH] Add asus-motor, to be called from cameraserver to control ZF6 cam --- base.mk | 2 ++ cmds/Android.bp | 7 +++++++ cmds/asus-motor.cpp | 30 ++++++++++++++++++++++++++++++ sepolicy/asus.te | 5 +++++ sepolicy/file_contexts | 1 + 5 files changed, 45 insertions(+) create mode 100644 cmds/asus-motor.cpp create mode 100644 sepolicy/asus.te diff --git a/base.mk b/base.mk index f1bf899..b1be3bc 100644 --- a/base.mk +++ b/base.mk @@ -143,3 +143,5 @@ PRODUCT_COPY_FILES += \ PRODUCT_COPY_FILES += \ device/phh/treble/ld.config.26.txt:system/etc/ld.config.26.txt \ +PRODUCT_PACKAGES += \ + asus-motor diff --git a/cmds/Android.bp b/cmds/Android.bp index 4c93c3a..f5aaeee 100644 --- a/cmds/Android.bp +++ b/cmds/Android.bp @@ -151,3 +151,10 @@ cc_binary { "libhidlbase", ], } + +cc_binary { + name: "asus-motor", + srcs: [ + "asus-motor.cpp", + ], +} diff --git a/cmds/asus-motor.cpp b/cmds/asus-motor.cpp new file mode 100644 index 0000000..7f18858 --- /dev/null +++ b/cmds/asus-motor.cpp @@ -0,0 +1,30 @@ +#include +#include +#include +#include +#include + +typedef struct { + int dir; + int angle; + int speed; +} motorDrvManualConfig_t; + +#define ASUS_MOTOR_NAME_SIZE 32 +#define ASUS_MOTOR_DATA_SIZE 4 + +#define ASUS_MOTOR_DRV_DEV_PATH ("/dev/asusMotoDrv") +#define ASUS_MOTOR_DRV_IOC_MAGIC ('M') +#define ASUS_MOTOR_DRV_AUTO_MODE _IOW(ASUS_MOTOR_DRV_IOC_MAGIC, 1, int) +#define ASUS_MOTOR_DRV_MANUAL_MODE _IOW(ASUS_MOTOR_DRV_IOC_MAGIC, 2, motorDrvManualConfig_t) + +int main(int argc, char **argv) { + if(argc != 2) return 1; + int fd = open("/dev/asusMotoDrv", O_RDWR); + motorDrvManualConfig_t cfg; + cfg.dir = atoi(argv[1]); + cfg.angle = 180; + cfg.speed = 4; + + ioctl(fd, ASUS_MOTOR_DRV_MANUAL_MODE, &cfg); +} diff --git a/sepolicy/asus.te b/sepolicy/asus.te new file mode 100644 index 0000000..64ff117 --- /dev/null +++ b/sepolicy/asus.te @@ -0,0 +1,5 @@ +allow cameraserver phhsu_exec:file rx_file_perms; + +type asus_motor_device, file_type; +allow cameraserver asus_motor_device:chr_file { open read write ioctl }; +allowxperm cameraserver asus_motor_device:chr_file ioctl { 0x4d02 }; diff --git a/sepolicy/file_contexts b/sepolicy/file_contexts index 0eeee34..edbe03e 100644 --- a/sepolicy/file_contexts +++ b/sepolicy/file_contexts @@ -3,6 +3,7 @@ /system/etc/usb_audio_policy_configuration.xml u:object_r:vendor_configs_file:s0 /system/bin/rw-system.sh u:object_r:phhsu_exec:s0 /system/bin/phh-on-boot.sh u:object_r:phhsu_exec:s0 +/system/bin/asus-motor u:object_r:phhsu_exec:s0 #/system/bin/fsck\.exfat u:object_r:fsck_exec:s0 /system/bin/fsck\.ntfs u:object_r:fsck_exec:s0