/**
 * 
 */
package com.domker.marmot;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.PowerManager.WakeLock;

import com.domker.marmot.core.AsyncHandler;
import com.domker.marmot.core.CpuWakeLock;
import com.domker.marmot.core.Watcher;

/**
 * 系统启动之后的广播
 * 
 * @author wanlipeng
 * @date 2017年1月5日 下午5:49:41
 */
public class BootCompletedReceiver extends BroadcastReceiver {

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.content.BroadcastReceiver#onReceive(android.content.Context,
	 * android.content.Intent)
	 */
	@Override
	public void onReceive(final Context context, Intent intent) {
		final PendingResult result = goAsync();
		final WakeLock wl = CpuWakeLock.createPartialWakeLock(context);
		wl.acquire();

		AsyncHandler.post(new Runnable() {

			@Override
			public void run() {
				handleBoot(context);
				wl.release();
				result.finish();
			}
		});
	}

	/**
	 * 启动之后执行的操作
	 */
	private void handleBoot(Context context) {
		Intent intent = Watcher.createIntent(context, WatcherService.class);
		Watcher.startService(context, intent);
		Watcher.toast(context, "Service WatcherService start");
	}
}

@@ -34,24 +34,120 @@
 .marmot;%0D%0A%0D%0A
+import android.app.ActivityManager;%0D%0Aimport android.app.ActivityManager.RunningAppProcessInfo;%0D%0A
 import andro
@@ -173,24 +173,24 @@
 tReceiver;%0D%0A
-
 import andro
@@ -562,18 +562,93 @@
 iver %7B%0D%0A
+%09private ActivityManager am = null;%0D%0A%09private String processName = null;%0D%0A%09
 %0D%0A
-
 %09/*%0D%0A%09 *
@@ -859,16 +859,92 @@
 ent) %7B%0D%0A
+%09%09if (isServiceProcessAlive(context)) %7B%0D%0A%09%09%09// %E5%A6%82%E6%9E%9C%E8%BF%9B%E7%A8%8B%E5%AD%98%E5%9C%A8%EF%BC%8C%E5%88%99%E8%BF%94%E5%9B%9E%0D%0A%09%09%09return;%0D%0A%09%09%7D%0D%0A
 %09%09final 
@@ -1228,16 +1228,472 @@
 %0D%0A%09%7D%0D%0A%0D%0A
+%09/**%0D%0A%09 * %E5%88%A4%E6%96%AD%E6%9C%8D%E5%8A%A1%E8%BF%9B%E7%A8%8B%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8%0D%0A%09 * %0D%0A%09 * @param context%0D%0A%09 * @return%0D%0A%09 */%0D%0A%09private boolean isServiceProcessAlive(Context context) %7B%0D%0A%09%09if (am == null) %7B%0D%0A%09%09%09am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);%0D%0A%09%09%09processName = context.getString(R.string.watcher_process);%0D%0A%09%09%7D%0D%0A%09%09for (RunningAppProcessInfo p : am.getRunningAppProcesses()) %7B%0D%0A%09%09%09if (p.processName.equals(processName)) %7B%0D%0A%09%09%09%09return true;%0D%0A%09%09%09%7D%0D%0A%09%09%7D%0D%0A%09%09return false;%0D%0A%09%7D%0D%0A%09%0D%0A
 %09/**%0D%0A%09 

监控解锁屏幕保护进程，如果当前进程存在，则忽略操作。