Java daemon process not started by zygote and monitoring system events

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Java daemon process not started by zygote and monitoring system events

Quentin Swain
Hi, 

 I am attempting to create a java service that runs outside of the system server and would be started from boot, which based on configuration can monitor an Android device and listen for broadcasts. I have not been able to find documentation on how to write a long running java service that runs as a process that isn't started by zygote. I am trying to modify the platform and this service would be added to a custom system.img generated by rebuilding the Android source.

The service would be started similar to the script used to run am from adb.

the idea would be to try and start the service as early as possible when device is booting with a script similar to the script that is used to run am or pm for instance 

The service would be started similar to the script used to run am from adb.

    base=/system

    export CLASSPATH=$base/framework/am.jar

    exec app_process $base/bin com.android.commands.am.Am "$@"


The only examples that I have found trying to add daemons have been to implement fully native services that run on the device. https://groups.google.com/forum/?fromgroups=#!topic/android-porting/xH3ufHVCGk4

Embedded Android describes Android Userspace and some of the native daemons that run there and how to create services and add them to init to start at device boot at least prior to Zygote and the System Server ect.   http://shop.oreilly.com/product/0636920021094.do?sortby=publicationDate


    public class Monitor{

        public static void main(String [] args){

            new Monitor.run();

        }

        public void run(){

             Application app = new Application();

             Context con = app.getApplicationContext();

             BroadcastReceiver receiver = new BroadcastReceiver(){

                 public void onReceive(Context context, Intent intent){

                     Log.i(TAG, "Received intent:"+ intent.getAction());

                 }   

             }

             IntentFilter filter = new IntentFilter("android.intent.action.TIME_TICK")

        }

    }


I also tried this based on a snippet of code from the ActivityManagerService. 

    public class Monitor{

        private Context mContext;


        Monitor(){

            Looper.prepare()

            ActivityThread at = ActivityThread.systemMain();

            mContext = at.getSystemContext();

        }

        public static void main(String [] args){

            new Monitor.run();

        }

        public void run(){

             BroadcastReceiver receiver = new BroadcastReceiver(){

                 public void onReceive(Context context, Intent intent){

                     Log.i(TAG, "Received intent:"+ intent.getAction());

                 }   

             }

             IntentFilter  filter = new IntentFiler("android.intent.action.AIRPLANE_MODE");

             mContext.registerReceiver(receiver,filter);

        }

    }


I that intents/broadcasts can be generated from the commandline using adb and am but is there anyway to receive broadcasts or would i have to try to modify the ActivityManager or other parts of the platform to detemine when intents are being sent. . Any advice or suggestion is appreciated.

[1]:


--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-platform/-/0HwIi6UKCJEJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: Java daemon process not started by zygote and monitoring system events

Ubuntu guy
Not without modifying this,

public Intent registerReceiver(IApplicationThread caller, String
callerPackage,
            IIntentReceiver receiver, IntentFilter filter, String
permission, int userId) {
        enforceNotIsolatedCaller("registerReceiver");
...
}

 Good luck !!!

On Dec 10, 12:33 pm, Quentin Swain <[hidden email]> wrote:

> Hi,
>
>  I am attempting to create a java service that runs outside of the system
> server and would be started from boot, which based on configuration can
> monitor an Android device and listen for broadcasts. I have not been able
> to find documentation on how to write a long running java service that runs
> as a process that isn't started by zygote. I am trying to modify the
> platform and this service would be added to a custom system.img generated
> by rebuilding the Android source.
>
> The service would be started similar to the script used to run am from adb.
>
> the idea would be to try and start the service as early as possible when
> device is booting with a script similar to the script that is used to run
> am or pm for instance
>
> The service would be started similar to the script used to run am from adb.
>
>     base=/system
>
>     export CLASSPATH=$base/framework/am.jar
>
>     exec app_process $base/bin com.android.commands.am.Am "$@"
>
> The only examples that I have found trying to add daemons have been to
> implement fully native services that run on the device.https://groups.google.com/forum/?fromgroups=#!topic/android-porting/x...
>
> Embedded Android describes Android Userspace and some of the native daemons
> that run there and how to create services and add them to init to start at
> device boot at least prior to Zygote and the System Server ect.  http://shop.oreilly.com/product/0636920021094.do?sortby=publicationDate
>
>     public class Monitor{
>
>         public static void main(String [] args){
>
>             new Monitor.run();
>
>         }
>
>         public void run(){
>
>              Application app = new Application();
>
>              Context con = app.getApplicationContext();
>
>              BroadcastReceiver receiver = new BroadcastReceiver(){
>
>                  public void onReceive(Context context, Intent intent){
>
>                      Log.i(TAG, "Received intent:"+ intent.getAction());
>
>                  }
>
>              }
>
>              IntentFilter filter = new
> IntentFilter("android.intent.action.TIME_TICK")
>
>         }
>
>     }
>
> I also tried this based on a snippet of code from the
> ActivityManagerService.
>
>     public class Monitor{
>
>         private Context mContext;
>
>         Monitor(){
>
>             Looper.prepare()
>
>             ActivityThread at = ActivityThread.systemMain();
>
>             mContext = at.getSystemContext();
>
>         }
>
>         public static void main(String [] args){
>
>             new Monitor.run();
>
>         }
>
>         public void run(){
>
>              BroadcastReceiver receiver = new BroadcastReceiver(){
>
>                  public void onReceive(Context context, Intent intent){
>
>                      Log.i(TAG, "Received intent:"+ intent.getAction());
>
>                  }
>
>              }
>
>              IntentFilter  filter = new
> IntentFiler("android.intent.action.AIRPLANE_MODE");
>
>              mContext.registerReceiver(receiver,filter);
>
>         }
>
>     }
>
> I that intents/broadcasts can be generated from the commandline using adb
> and am but is there anyway to receive broadcasts or would i have to try to
> modify the ActivityManager or other parts of the platform to detemine when
> intents are being sent. . Any advice or suggestion is appreciated.
>
> [1]:

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.

Reply | Threaded
Open this post in threaded view
|

android_pmem.h and ion.h

caryzou
Hi, all
     kernel 3.4 use ION replace pmem, So android_pmem.h has been moved
since 2012-01-28 on kernel-3.4 branch.  but
/frameworks/native/libs/binder/MemoryHeapBase.cpp still include it,
And also , kernel-3.4 is not merge to kernel-3.4-compat, cause
kernel-3.4-compat+android-4.2_r1 can't pass compile phase
(ION_FLAG_CACHED_NEEDS_SYNC not defined in ion.h), can anyone fix this,
I also submit a issue on Google
groups(http://code.google.com/p/android/issues/detail?id=41173)

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: Java daemon process not started by zygote and monitoring system events

Quentin Swain
In reply to this post by Ubuntu guy
Thanks for the reply. I took a look through the ActivityManager. I'm gonna try a slightly different approach to try and avoid making too many changes in the ActivityManager. I really appreciate the advice and your time thanks again

On Monday, December 10, 2012 10:07:50 PM UTC-5, Ubuntu guy wrote:
Not without modifying this,

public Intent registerReceiver(IApplicationThread caller, String
callerPackage,
            IIntentReceiver receiver, IntentFilter filter, String
permission, int userId) {
        enforceNotIsolatedCaller("registerReceiver");
...
}

 Good luck !!!

On Dec 10, 12:33 pm, Quentin Swain <[hidden email]> wrote:

> Hi,
>
>  I am attempting to create a java service that runs outside of the system
> server and would be started from boot, which based on configuration can
> monitor an Android device and listen for broadcasts. I have not been able
> to find documentation on how to write a long running java service that runs
> as a process that isn't started by zygote. I am trying to modify the
> platform and this service would be added to a custom system.img generated
> by rebuilding the Android source.
>
> The service would be started similar to the script used to run am from adb.
>
> the idea would be to try and start the service as early as possible when
> device is booting with a script similar to the script that is used to run
> am or pm for instance
>
> The service would be started similar to the script used to run am from adb.
>
>     base=/system
>
>     export CLASSPATH=$base/framework/am.jar
>
>     exec app_process $base/bin com.android.commands.am.Am "$@"
>
> The only examples that I have found trying to add daemons have been to
> implement fully native services that run on the device.https://groups.google.com/forum/?fromgroups=#!topic/android-porting/x...
>
> Embedded Android describes Android Userspace and some of the native daemons
> that run there and how to create services and add them to init to start at
> device boot at least prior to Zygote and the System Server ect.  http://shop.oreilly.com/product/0636920021094.do?sortby=publicationDate
>
>     public class Monitor{
>
>         public static void main(String [] args){
>
>             new Monitor.run();
>
>         }
>
>         public void run(){
>
>              Application app = new Application();
>
>              Context con = app.getApplicationContext();
>
>              BroadcastReceiver receiver = new BroadcastReceiver(){
>
>                  public void onReceive(Context context, Intent intent){
>
>                      Log.i(TAG, "Received intent:"+ intent.getAction());
>
>                  }
>
>              }
>
>              IntentFilter filter = new
> IntentFilter("android.intent.action.TIME_TICK")
>
>         }
>
>     }
>
> I also tried this based on a snippet of code from the
> ActivityManagerService.
>
>     public class Monitor{
>
>         private Context mContext;
>
>         Monitor(){
>
>             Looper.prepare()
>
>             ActivityThread at = ActivityThread.systemMain();
>
>             mContext = at.getSystemContext();
>
>         }
>
>         public static void main(String [] args){
>
>             new Monitor.run();
>
>         }
>
>         public void run(){
>
>              BroadcastReceiver receiver = new BroadcastReceiver(){
>
>                  public void onReceive(Context context, Intent intent){
>
>                      Log.i(TAG, "Received intent:"+ intent.getAction());
>
>                  }
>
>              }
>
>              IntentFilter  filter = new
> IntentFiler("android.intent.action.AIRPLANE_MODE");
>
>              mContext.registerReceiver(receiver,filter);
>
>         }
>
>     }
>
> I that intents/broadcasts can be generated from the commandline using adb
> and am but is there anyway to receive broadcasts or would i have to try to
> modify the ActivityManager or other parts of the platform to detemine when
> intents are being sent. . Any advice or suggestion is appreciated.
>
> [1]:

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-platform/-/1NLuuhWBDTcJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.