Lab – Adding Native Service

1.create a stand alone service

  • Add a new directory in ~/aosp/external – mylogger
  • Create a makefile – (copy from netcat and make changes)
  • Add the following source:

  1. compile the rom, run the emulator and start the service using adb:
  • cd ~/aosp
  • source build/
  • lunch 1
  • make
  • emulator &
  • adb shell
  • cd data
  • mylogger &
  1. create android application to use it
  • create a simple activity with one button
  • implement click event: create and start a thread to run the following code:

  • add internet permissions to the project
  • run the application on the custom device

4. Edit init.rc file to make the service run on reset and test your work

5. Edit init.rc file to make the service start on system property myapp.logger=1 and stop on system property myapp.logger=0

6. Write a simple utility to set the above system property using libcutils property_set function. Use /system/core/reboot as an example