package com.android.reverse.mod;

import java.util.List;

import com.android.reverse.request.CommandHandler;
import com.android.reverse.request.CommandHandlerParser;
import com.android.reverse.util.Logger;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class CommandBroadcastReceiver extends BroadcastReceiver {

	public static String INTENT_ACTION = "com.zjdroid.invoke";
	public static String TARGET_KEY = "target";
	public static String COMMAND_NAME_KEY = "cmd";

	@Override
	public void onReceive(final Context arg0, Intent arg1) {
		// TODO Auto-generated method stub
		if (INTENT_ACTION.equals(arg1.getAction())) {
			try {
				int pid = arg1.getIntExtra(TARGET_KEY, 0);
				if (pid == android.os.Process.myPid()) {
					String cmd = arg1.getStringExtra(COMMAND_NAME_KEY);
					final CommandHandler handler = CommandHandlerParser
							.parserCommand(cmd);
					if (handler != null) {
						new Thread(new Runnable() {
							@Override
							public void run() {
								// TODO Auto-generated method stub
								handler.doAction();
							}
						}).start();
					}else{
						Logger.log("the cmd is invalid");
					}
				}
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
}

@@ -578,12 +578,11 @@
 ext 
-arg0
+ctx
 , In
@@ -590,59 +590,24 @@
 ent 
-arg1) %7B%0A%09%09// TODO Auto-generated method stub
+intent) %7B
 %0A%09%09if
- 
 (
+!
 INTE
@@ -626,13 +626,25 @@
 uals
-(arg1
+IgnoreCase(intent
 .get
@@ -657,24 +657,33 @@
 ()))
- 
 %7B%0A%09%09%09
-try %7B%0A%09%09%09%09
+return;%0A%09%09%7D%0A        
 int 
@@ -684,28 +684,30 @@
   int pid = 
-arg1
+intent
 .getIntExtra
@@ -727,22 +727,27 @@
 0);%0A
-%09%09%09%09if (p
+        int myP
 id =
-=
  and
@@ -769,25 +769,100 @@
 .myPid()
-) %7B%0A%09%09%09%09%09
+;%0A        if(pid != myPid)%7B%0A            return;%0A        %7D%0A        try %7B%0A            
 String c
@@ -870,12 +870,14 @@
 d = 
-arg1
+intent
 .get
@@ -907,21 +907,28 @@
 E_KEY);%0A
-%09%09%09%09%09
+            
 final Co
@@ -971,23 +971,36 @@
 rParser%0A
-%09%09%09%09%09%09%09
+                    
 .parserC
@@ -1012,21 +1012,28 @@
 d(cmd);%0A
-%09%09%09%09%09
+            
 if (hand
@@ -1047,22 +1047,32 @@
 null) %7B%0A
-%09%09%09%09%09%09
+                
 new Thre
@@ -1095,168 +1095,207 @@
 ) %7B%0A
-%09%09%09%09%09%09%09@Override%0A%09%09%09%09%09%09%09public void run() %7B%0A%09%09%09%09%09%09%09%09// TODO Auto-generated method stub%0A%09%09%09%09%09%09%09%09handler.doAction();%0A%09%09%09%09%09%09%09%7D%0A%09%09%09%09%09%09%7D).start();%0A%09%09%09%09%09%7Delse%7B%0A%09%09%09%09%09%09
+                    @Override%0A                    public void run() %7B%0A                        handler.doAction();%0A                    %7D%0A                %7D).start();%0A            %7Delse%7B%0A                
 Logg
@@ -1328,24 +1328,30 @@
 %22);%0A
-%09%09%09%09%09%7D%0A%09%09%09%09%7D%0A%09%09%09
+            %7D%0A        
 %7D ca
@@ -1374,51 +1374,20 @@
 ) %7B%0A
-%09%09%09%09// TODO Auto-generated catch block%0A%09%09%09%09
+            
 e.pr
@@ -1407,15 +1407,16 @@
 ();%0A
-%09%09%09%7D%0A%09%09
+        
 %7D%0A%09%7D

重构 CommandBroadcastReceiver 类代码