Need to add custom script as service in init.rc for Android 9

3,805 views
Skip to first unread message

VINOTHKUMAR S

unread,
Sep 20, 2019, 6:51:35 PM9/20/19
to android-platform

I am planning to add USB Re-flash (custom script) service in Android 9.

 

I done the below configuration to start the service. But, the service is not started. Please let me know if I miss anything.

 

Below are the configuration,

 

1. Copy this script (usb-update.sh) to the following location
            /device/fsl/imx6dq/sabresd_6dq

2. Add the following command
            /device/fsl/imx6dq/sabresd_6dq/usb-update.sh: system/bin/usb-update.sh
            To Copy command to copy usb-update.sh to /system/bin location in the following file sabresd_6dqr.mk under following section PRODUCT_COPY_FILES

 

3. Add USB-UPDATE into the PRODUCT_PACKAGE section of sabresd_6dqr.mk file

 

4. Define the service in file init.rc
            service usb-update /system/bin/ usb-update.sh
                     class main

                     user root

                     group root system
                     oneshot
                     seclabel u:r: usb-update:s0

 

5. Add a new Domain “usb-update

      a. Create the file in the following location,
               /device/fsl/imx6dq/sabresd_6dq/sepolicy/usb-update.te
              And add the following content,
                # USB-UPDATE service
               type usb-update, domain;
               type usb-update_exec, exec_type, file_type;

      

               init_deamon_domain(foo)

b. Add the Label “/system/bin/usb-update.sh” to device/fsl/imx6dq/sepolicy/ file_contexts
            /system/bin/usb-update     u:object_r: usb-update_exec:s0

 

 

 

Thanks & Regards,

VinothS.

Tommaso Merciai

unread,
Dec 17, 2019, 2:44:24 PM12/17/19
to android-platform
Hi Vinoth,
You can add new service that start on property change:

In init.board.rc add the service:

#service start on property change to 1
on property:vendor.customproperty=1
write /dev/kmesg "hello service"
start customservice


#declare service
service customservice vendor/bin/customservice.sh
oneshoot
user root


Add it to sepolicy file under device/vendor/board/sepolicy/file_contexts and add commands to copy it under out vendor/bin folder using boardconfig.mk in device/vendor/board/board.mk


Regards.
Tommaso Merciai

Tommaso Merciai

unread,
Dec 17, 2019, 2:44:43 PM12/17/19
to android-platform
Hi Vinoth,
Have you try to associate a custom property to start your service?

In device/manufacturer/product/board/init.board.rc declare new service:

on property:vendor.customproperty=1
     start customservice

on property:vendor.customproperty=0
     stop customservice

service customservice /vendor/bin/customservice.sh
    oneshot
    user root
    seclabel u:r:user_script:s0

In device/manufacturer/product/board/sepolicy/file_contexts append:

/vendor/bin/customservice.sh             u:object_r:user_script_exec:s0

Now if you want start your service just:

$ setprop vendor.customproperty 1

Stop it using:

$ setprop vendor.customproperty 0

Regards.
Tommaso Merciai

VINOTHKUMAR S

unread,
Dec 18, 2019, 10:48:38 AM12/18/19
to android-platform
Thank you Tommaso Merciai,

Whatever configuration I done. It's working fine. Issue resolved by removing spaces. But, I got new idea from you whatever you shared. May be I will use in feature.

Thanks & Regards,
VinothS,

Gianmaria Iaculo

unread,
Dec 20, 2019, 10:01:17 AM12/20/19
to android-platform
Hello Tommaso,
I'm using your solution for another task, my problem is similar, I have to start a sh script on android boot, but during compilation time i receive this message:

FAILED: out/target/product/dart_mx8mm/obj/ETC/vendor_file_contexts_intermediates/vendor_file_contexts
/bin/bash -c "(m4 -s     system/sepolicy/vendor/file_contexts  out/target/product/dart_mx8mm/obj/ETC/sectxfile_nl_intermediates/sectxfile_nl    device/fsl/imx8m/sepolicy/file_contexts  out/target/product/dart_mx8mm/obj/ETC/sectxfile_nl_intermediates/sectxfile_nl    device/variscite/imx8m/dart_mx8mm/sepolicy/file_contexts  out/target/product/dart_mx8mm/obj/ETC/sectxfile_nl_intermediates/sectxfile_nl    hardware/u-blox/gps/sepolicy/file_contexts  out/target/product/dart_mx8mm/obj/ETC/sectxfile_nl_intermediates/sectxfile_nl > out/target/product/dart_mx8mm/obj/ETC/vendor_file_contexts_intermediates/vendor_file_contexts.tmp ) && (out/host/linux-x86/bin/checkfc out/target/product/dart_mx8mm/obj/ETC/sepolicy_intermediates/sepolicy out/target/product/dart_mx8mm/obj/ETC/vendor_file_contexts_intermediates/vendor_file_contexts.tmp ) && (out/host/linux-x86/bin/fc_sort out/target/product/dart_mx8mm/obj/ETC/vendor_file_contexts_intermediates/vendor_file_contexts.tmp out/target/product/dart_mx8mm/obj/ETC/vendor_file_contexts_intermediates/vendor_file_contexts )"
libsepol.context_from_record: type user_script_exec is not defined
libsepol.context_from_record: could not create context structure

Any hint on how to solv this?

Regards,
Gianmaria

Tommaso Merciai

unread,
Dec 22, 2019, 11:41:51 AM12/22/19
to android-...@googlegroups.com
Hi Gianmaria:
Maybe this post from https://community.nxp.com/thread/513396 can help you:

 

1. Add the script to the following location
         /device/fsl/imx6dq/sabresd_6dq/usb-update.sh
2. Add the following command in the sabresd_6dqr.mk file under PRODUCT_COPY_FILES section,
         /device/fsl/imx6dq/sabresd_6dq/usb-update.sh: system/bin/usb-update.sh


3. Add USB-UPDATE into the PRODUCT_PACKAGE section of sabresd_6dqr.mk file

4. Modify PRODUCT_FULL_TREBLE_OVERRIDE := false in sabresd_6dqr.mk file
5. Define the service in init.rc file


         service usb-update /system/bin/ usb-update.sh
               class main
               user root

               oneshot
               seclabel u:r: usb-update:s0

6. Add a new Domain named as usb-update


   a. Create the file in the following location,
            /device/fsl/imx6dq/sabresd_6dq/sepolicy/usb-update.te
   And add the following content,
            # USB-UPDATE service
            type usb-update, domain;
            type usb-update_exec, exec_type, file_type;
            init_deamon_domain(foo)

            domain_auto_trans(init, shell_exec, usb-update)

   b. Add the Label “/system/bin/usb-update.sh” to device/fsl/imx6dq/sepolicy/ file_contexts

         /system/bin/usb-update seclabel u:r: usb-update:s0



Regards,

Tommaso


--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-platfo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-platform/dda6f816-758d-4663-9ed2-ad62c58af759%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages