/** * native call back */ protected void onDaemonDead(){ IDaemonStrategy.Fetcher.fetchStrategy().onDaemonDead(); }
/** * you can override this method instead of {@link android.app.Application attachBaseContext} * @param base */ @Override public void attachBaseContextByDaemon(Context base) { super.attachBaseContextByDaemon(base); }
public DaemonApplication(){ mDaemonClient = new DaemonClient(getDaemonConfigurations()); }
/** * do some thing about daemon * @param base */ private void initDaemon(Context base) { if(!isDaemonPermitting(base) || mConfigurations == null){ return ; } String processName = getProcessName(); String packageName = base.getPackageName(); if(processName.startsWith(mConfigurations.PERSISTENT_CONFIG.PROCESS_NAME)){ IDaemonStrategy.Fetcher.fetchStrategy().onPersistentCreate(base, mConfigurations); }else if(processName.startsWith(mConfigurations.DAEMON_ASSISTANT_CONFIG.PROCESS_NAME)){ IDaemonStrategy.Fetcher.fetchStrategy().onDaemonAssistantCreate(base, mConfigurations); }else if(processName.startsWith(packageName)){ IDaemonStrategy.Fetcher.fetchStrategy().onInitialization(base); } releaseIO(); }
@Override public void onPersistentCreate(final Context context, DaemonConfigurations configs) { initAmsBinder(); initServiceParcel(context, configs.DAEMON_ASSISTANT_CONFIG.SERVICE_NAME); startServiceByAmsBinder(); Thread t = new Thread(){ public void run() { File indicatorDir = context.getDir(INDICATOR_DIR_NAME, Context.MODE_PRIVATE); new NativeDaemonAPI21(context).doDaemon( new File(indicatorDir, INDICATOR_PERSISTENT_FILENAME).getAbsolutePath(), new File(indicatorDir, INDICATOR_DAEMON_ASSISTANT_FILENAME).getAbsolutePath(), new File(indicatorDir, OBSERVER_PERSISTENT_FILENAME).getAbsolutePath(), new File(indicatorDir, OBSERVER_DAEMON_ASSISTANT_FILENAME).getAbsolutePath()); }; }; t.start(); if(configs != null && configs.LISTENER != null){ this.mConfigs = configs; configs.LISTENER.onPersistentStart(context); } }
@Override public void onDaemonAssistantCreate(final Context context, DaemonConfigurations configs) { initAmsBinder(); initServiceParcel(context, configs.PERSISTENT_CONFIG.SERVICE_NAME); startServiceByAmsBinder(); Thread t = new Thread(){ public void run() { File indicatorDir = context.getDir(INDICATOR_DIR_NAME, Context.MODE_PRIVATE); new NativeDaemonAPI21(context).doDaemon( new File(indicatorDir, INDICATOR_DAEMON_ASSISTANT_FILENAME).getAbsolutePath(), new File(indicatorDir, INDICATOR_PERSISTENT_FILENAME).getAbsolutePath(), new File(indicatorDir, OBSERVER_DAEMON_ASSISTANT_FILENAME).getAbsolutePath(), new File(indicatorDir, OBSERVER_PERSISTENT_FILENAME).getAbsolutePath()); }; }; t.start(); if(configs != null && configs.LISTENER != null){ this.mConfigs = configs; configs.LISTENER.onDaemonAssistantStart(context); } }
@Override public void onPersistentCreate(final Context context, final DaemonConfigurations configs) { initAmsBinder(); initServiceParcel(context, configs.DAEMON_ASSISTANT_CONFIG.SERVICE_NAME); Thread t = new Thread(){ public void run() { File binaryFile = new File(context.getDir(BINARY_DEST_DIR_NAME, Context.MODE_PRIVATE), BINARY_FILE_NAME); new NativeDaemonAPI20(context).doDaemon( context.getPackageName(), configs.DAEMON_ASSISTANT_CONFIG.SERVICE_NAME, binaryFile.getAbsolutePath()); }; }; t.setPriority(Thread.MAX_PRIORITY); t.start(); if(configs != null && configs.LISTENER != null){ this.mConfigs = configs; configs.LISTENER.onPersistentStart(context); } }
private DaemonConfigurations createDaemonConfigurations(){ DaemonConfigurations.DaemonConfiguration configuration1 = new DaemonConfigurations.DaemonConfiguration( "com.marswin89.marsdaemon.demo:process1", Service1.class.getCanonicalName(), Receiver1.class.getCanonicalName()); DaemonConfigurations.DaemonConfiguration configuration2 = new DaemonConfigurations.DaemonConfiguration( "com.marswin89.marsdaemon.demo:process2", Service2.class.getCanonicalName(), Receiver2.class.getCanonicalName()); DaemonConfigurations.DaemonListener listener = new MyDaemonListener(); //return new DaemonConfigurations(configuration1, configuration2);//listener can be null return new DaemonConfigurations(configuration1, configuration2, listener); }
/** * give the configuration to lib in this callback * @return */ @Override protected DaemonConfigurations getDaemonConfigurations() { DaemonConfigurations.DaemonConfiguration configuration1 = new DaemonConfigurations.DaemonConfiguration( "com.marswin89.marsdaemon.demo:process1", Service1.class.getCanonicalName(), Receiver1.class.getCanonicalName()); DaemonConfigurations.DaemonConfiguration configuration2 = new DaemonConfigurations.DaemonConfiguration( "com.marswin89.marsdaemon.demo:process2", Service2.class.getCanonicalName(), Receiver2.class.getCanonicalName()); DaemonConfigurations.DaemonListener listener = new MyDaemonListener(); //return new DaemonConfigurations(configuration1, configuration2);//listener can be null return new DaemonConfigurations(configuration1, configuration2, listener); }
@Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); mDaemonClient = new DaemonClient(createDaemonConfigurations()); mDaemonClient.onAttachBaseContext(base); }
@Override public final void attachBaseContext(Context base) { if(mHasAttachBaseContext){ return ; } mHasAttachBaseContext = true; super.attachBaseContext(base); mDaemonClient.onAttachBaseContext(base); attachBaseContextByDaemon(base); }
@Override public void onDaemonDead() { if(startServiceByAmsBinder()){ if(mConfigs != null && mConfigs.LISTENER != null){ mConfigs.LISTENER.onWatchDaemonDaed(); } android.os.Process.killProcess(android.os.Process.myPid()); } }
@Override public void onDaemonDead() { if(sendBroadcastByAmsBinder()){ if(mConfigs != null && mConfigs.LISTENER != null){ mConfigs.LISTENER.onWatchDaemonDaed(); } android.os.Process.killProcess(android.os.Process.myPid()); } }
@Override public void onDaemonDead() { if(startServiceByAmsBinder()){ if(mConfigs != null && mConfigs.LISTENER != null){ mConfigs.LISTENER.onWatchDaemonDaed(); } android.os.Process.killProcess(android.os.Process.myPid()); } }
@Override public void onPersistentCreate(final Context context, final DaemonConfigurations configs) { initAlarm(context, configs.DAEMON_ASSISTANT_CONFIG.SERVICE_NAME); Thread t = new Thread(){ public void run() { File binaryFile = new File(context.getDir(BINARY_DEST_DIR_NAME, Context.MODE_PRIVATE), BINARY_FILE_NAME); new NativeDaemonAPI20(context).doDaemon( context.getPackageName(), configs.DAEMON_ASSISTANT_CONFIG.SERVICE_NAME, binaryFile.getAbsolutePath()); }; }; t.setPriority(Thread.MAX_PRIORITY); t.start(); if(configs != null && configs.LISTENER != null){ configs.LISTENER.onPersistentStart(context); } }
@Override public void onDaemonAssistantCreate(final Context context, DaemonConfigurations configs) { Intent intent = new Intent(); ComponentName componentName = new ComponentName(context.getPackageName(), configs.PERSISTENT_CONFIG.SERVICE_NAME); intent.setComponent(componentName); context.startService(intent); initAlarm(context, configs.PERSISTENT_CONFIG.SERVICE_NAME); Thread t = new Thread(){ public void run() { File indicatorDir = context.getDir(INDICATOR_DIR_NAME, Context.MODE_PRIVATE); new NativeDaemonAPI21(context).doDaemon( new File(indicatorDir, INDICATOR_DAEMON_ASSISTANT_FILENAME).getAbsolutePath(), new File(indicatorDir, INDICATOR_PERSISTENT_FILENAME).getAbsolutePath(), new File(indicatorDir, OBSERVER_DAEMON_ASSISTANT_FILENAME).getAbsolutePath(), new File(indicatorDir, OBSERVER_PERSISTENT_FILENAME).getAbsolutePath()); }; }; t.setPriority(Thread.MAX_PRIORITY); t.start(); if(configs != null && configs.LISTENER != null){ this.mConfigs = configs; configs.LISTENER.onDaemonAssistantStart(context); } }
@Override public void onDaemonDead() { mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(), 100, mPendingIntent); if(mConfigs != null && mConfigs.LISTENER != null){ mConfigs.LISTENER.onWatchDaemonDaed(); } android.os.Process.killProcess(android.os.Process.myPid()); }
@Override public void onAttachBaseContext(Context base) { initDaemon(base); }
@Override public void onDaemonAssistantCreate(Context context, DaemonConfigurations configs) { Intent intent = new Intent(); ComponentName component = new ComponentName(context.getPackageName(), configs.PERSISTENT_CONFIG.SERVICE_NAME); intent.setComponent(component); context.startService(intent); if(configs != null && configs.LISTENER != null){ configs.LISTENER.onWatchDaemonDaed(); } android.os.Process.killProcess(android.os.Process.myPid()); }
@Override public void onDaemonAssistantCreate(Context context, DaemonConfigurations configs) { Intent intent = new Intent(); ComponentName component = new ComponentName(context.getPackageName(), configs.PERSISTENT_CONFIG.SERVICE_NAME); intent.setComponent(component); context.startService(intent); if(configs != null && configs.LISTENER != null){ configs.LISTENER.onWatchDaemonDaed(); } android.os.Process.killProcess(android.os.Process.myPid()); }