LaunchAnalyzerReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (!ACTION.equals(intent.getAction())) { return; } String cmd_performance = intent.getStringExtra(CMD_PERFORMANCE); String cmd_tracker_standard = intent.getStringExtra(CMD_TRACKER_STANDARD); String cmd_tracker_polling = intent.getStringExtra(CMD_TRACKER_POLLING); String cmd_launch = intent.getStringExtra(CMD_LAUNCH); String cmd_wx_server = intent.getStringExtra(CMD_WX_SERVER); if(!TextUtils.isEmpty(cmd_performance)) { if(CMD_ON.equals(cmd_performance)) { performStart(context,AnalyzerService.ATS, null); } else if(CMD_OFF.equals(cmd_performance)) { performStop(context); } else{ Log.d(Constants.TAG,"illegal command. use [adb shell am broadcast -a com.taobao.weex.analyzer.LaunchService -e c on] to fetch performance data"); } } else if(!TextUtils.isEmpty(cmd_tracker_standard)) { if(CMD_ON.equals(cmd_tracker_standard)) { VDomController.isStandardMode = true; VDomController.isPollingMode = false; PollingVDomMonitor.shouldHighlight = false; } else if(CMD_OFF.equals(cmd_tracker_standard)) { VDomController.isStandardMode = false; } else { Log.d(Constants.TAG,"illegal command. use [adb shell am broadcast -a com.taobao.weex.analyzer.LaunchService -e d on] to start vdom tracker"); } } else if(!TextUtils.isEmpty(cmd_tracker_polling)) { String highlightEnabled = intent.getStringExtra("h"); if(CMD_ON.equals(cmd_tracker_polling)) { VDomController.isPollingMode = true; VDomController.isStandardMode = false; PollingVDomMonitor.shouldStop = false; PollingVDomMonitor.shouldHighlight = CMD_ON.equals(highlightEnabled); } else if(CMD_OFF.equals(cmd_tracker_polling)) { VDomController.isPollingMode = false; PollingVDomMonitor.shouldStop = true; PollingVDomMonitor.shouldHighlight = false; } else { Log.d(Constants.TAG,"illegal command. use [adb shell am broadcast -a com.taobao.weex.analyzer.LaunchService -e f on] to start vdom tracker(polling mode)"); } } else if(!TextUtils.isEmpty(cmd_launch)) { if(TRUE.equals(cmd_launch)) { String from = intent.getStringExtra(WeexDevOptions.EXTRA_FROM); String deviceId = intent.getStringExtra(WeexDevOptions.EXTRA_DEVICE_ID); String wsUrl = intent.getStringExtra(WeexDevOptions.EXTRA_WS_URL); WXLogUtils.d(Constants.TAG,"from:"+from+",deviceId:"+deviceId+",wxurl:"+wsUrl); Map<String,String> extras = new HashMap<>(); extras.put(WeexDevOptions.EXTRA_DEVICE_ID, deviceId); extras.put(WeexDevOptions.EXTRA_WS_URL,wsUrl); performStart(context,from,extras); } } else if(!TextUtils.isEmpty(cmd_wx_server)) { DebugTool.startRemoteDebug(cmd_wx_server); } }  @Override void onReceive(Context context, Intent intent);  }
@Test public void onReceive() throws Exception { ShadowApplication application = ShadowApplication.getInstance(); Intent intent = new Intent(ACTION); boolean result = application.hasReceiverForIntent(intent); assertTrue(result); List<BroadcastReceiver> receivers = application.getReceiversForIntent(intent); assertEquals(1,receivers.size()); intent.putExtra("c","off"); BroadcastReceiver targetReceiver = receivers.get(0); targetReceiver.onReceive(application.getApplicationContext(),intent); Intent serviceIntent = application.getNextStoppedService(); assertEquals(serviceIntent.getComponent().getClassName(),AnalyzerService.class.getCanonicalName()); }