run an executable and script during Android bootup

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

run an executable and script during Android bootup

5,882 Views
msingh1920
Contributor V

Hi Sir,

I am using iMX8M EVK with Android 9.0 running on it. I downloaded and build the AOSP 9.0 for iMX8M and now using it with my EVK board. 

I have created a executable and After Android boots up i can copy my executable into /data/local/tmp directory and run it using adb. 

for e.g. - In data/local/tmp i can run my executable as => ./my_executable

But Now i want to run my executable during Android boot up time. 

I mean to say instead of manually copying and running the executable i want to make it part of AOSP and when AOSP boot up that time only my executable should also run. 

In below thread they given the solution to do changes in /etc/rc.local script for Linux

https://community.nxp.com/message/820999?commentID=820999#comment-820999 

But for Android / AOSP how can i do that ??

Thanks,

Maneesh

0 Kudos
7 Replies

4,537 Views
vinothkumars
Senior Contributor IV

Hi maneeshsingh‌,

You need to create the service and defined the selinux policy.

For your reference,

https://community.nxp.com/thread/513396 

Regards,

VinothS,

Regards,
Vinothkumar Sekar
0 Kudos

4,537 Views
gusarambula
NXP TechSupport
NXP TechSupport

Hello Maneesh,

There is also an init.rc file in Android, albeit it is handled a bit differently. You can see how it works on the following document from Google’s repositories.

https://android.googlesource.com/platform/system/core/+/master/init/README.md

You could the exec command or create a service that runs your application.

I hope this helps!

Regards,

0 Kudos

4,537 Views
msingh1920
Contributor V

Hi Gusarambula,

Thanks for your reply.

1. how can I use exec command to run my application ?

2. And you said I can  create a service to run the application ? so what is the steps for

    creating a service to run the applications ? for creating service we may face some selinux related issues

    hence is there any simpler way by which i can run my application ? 

3. Is there any reference which i can refer for creating service to run application at bootup ?

Thanks,

Maneesh

0 Kudos

4,537 Views
gusarambula
NXP TechSupport
NXP TechSupport

Hello Maneesh,

There is some interesting documentation on the Android Developers documentation and forums, like for example:

https://android.googlesource.com/platform/system/core/+/master/init/README.md

https://developer.android.com/training/run-background-service/create-service

I would recommend looking for more guidelines there as NXP documentation does not cover these topics.

I hope this helps!

Regards,

0 Kudos

4,537 Views
msingh1920
Contributor V

Hi Gusarambula,

Thanks for your reply.

I am looking into the Links provided by you and doing some search on internet also for the same.

I just to want to update you that i am able to make some progress but still got stuck at some place.

here is the steps which i am doing -

1. I added following lines in init.rc file of  AOSP /device/fsl/imx8m/evk_8mm ->

on property:dev.bootcomplete=1
    exec u:r:shell:s0 shell shell input log adb sdcard_rw sdcard_r net_bt_admin net_bt inet net_bw_stats -- /system/bin/sh /system/bin/myScript start -n com.example.package/com.example.package.MainActivity

2. And i created a myScript file and added following line into it - 

--------------------------------------------------------------------

   #!/system/bin/sh

      mkdir /data/local/tmp/DirFromMyScript
      #Run My Application in background
      exec helloApp &

---------------------------------------------------------------------

3. NOTE -  I kept this myScript and helloApp executable files in AOSP /out/target/product/evk_8mm/system/bin  directory.

4. After that i compiled the AOSP and flashed it on SDCARD.

5. When i Boot the AOSP on my iMX8M mini EVK i am able to see DirFromMyScript Directory in /data/local/tmp  created by myScript

but i am not able to see 'helloApp' running.

when i run 'ps' command i dind't see my executable 'helloApp' name there.  not with top command also.

NOTE - in my executable - helloApp i do lots of stuff like file creation, directory creation etc..

             so i can see 1 or 2 file is created by  'helloApp' but after that i think its getting existed.

             it means helloApp did run but it is getting terminated or existed hence not able to complete all the task.

6. NOTE - When I manually run myScript  that time my executable 'helloApp'  runs properly and it completes all the task. .

7. I want to run this executable in background from myScript during boot time. but i am not able to understand how to do that.

Any suggestion how can run executable binary from myScript ??

Thanks,

Maneesh

0 Kudos

4,537 Views
gusarambula
NXP TechSupport
NXP TechSupport

Hello Maneesh,

The steps look okay, but I’m afraid we do not have documentation that covers this, so your safest bet would be posting a question on the Android Developer forums especially as Android 9 is relatively new and each release changes somewhat how permissions and services work.

My apologies for the inconvenience,

Regards,

0 Kudos

4,537 Views
msingh1920
Contributor V

Hi,

Any suggestion or update over this ?

Thanks,

Maneesh

0 Kudos