@Override public void shutDown(boolean is) { // TODO Auto-generated method stub log("TeamView进程结束"); mTeamViewData.pidId = 0; // handler.removeCallbacksAndMessages(null); // handler.sendEmptyMessageDelayed(UPDATE_STARTEAM,5*60*1000); }
public boolean ReadyPCID(AccessibilityNodeInfo info) { if (info.getChildCount() == 4) { AccessibilityNodeInfo child = info.getChild(0); if (child != null && child.getChildCount() == 0 && child.getText() != null && child.getText().toString().trim().equals("允许远程支持吗?")) { String temp = info.getChild(1).getText().toString(); int postion = temp.indexOf("to remote support"); if (temp.contains("Would you like to allow")) { mTeamViewData.mPCIDTEXT = info.getChild(1).getText().toString().substring(24, postion).replace(" ", "").trim(); mTeamViewData.rejectButton = info.getChild(2); mTeamViewData.allowButton = info.getChild(3); return true; } } else { return false; } } return false; }
public int getProcessPid() { ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); List<RunningAppProcessInfo> procList = null; int result = -1; procList = activityManager.getRunningAppProcesses(); for (Iterator<RunningAppProcessInfo> iterator = procList.iterator(); iterator.hasNext(); ) { RunningAppProcessInfo procInfo = iterator.next(); // log("processName=" + procInfo.processName); if (procInfo.processName.equals("com.teamviewer.quicksupport.market")) { mTeamViewData.pidId = procInfo.pid; log("get pid success=" + mTeamViewData.pidId); processWatcher = new ProcessWatcher(mTeamViewData.pidId, shutDownListener); processWatcher.start(); break; } } return result; }
public void startTeamView() { log("startTeamView"); Intent mIntent = new Intent(); mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); ComponentName comp = new ComponentName(paName, MAIN_ACTIVITY); mIntent.setComponent(comp); mIntent.setAction("android.intent.action.VIEW"); startActivity(mIntent); state = STATE_BEGIN; mTeamViewData.pidId = 0; handler.removeMessages(UPDATE_BEGIN_ZHUANGTAI); handler.sendEmptyMessageDelayed(UPDATE_BEGIN_ZHUANGTAI, UPDATE_BEGIN_TIME_TIME); // 先删除上一次的启动tv handler.removeMessages(UPDATE_STARTEAM); // 自动打开 handler.removeMessages(OPEN); handler.sendEmptyMessageDelayed(OPEN, RESTART); }
public boolean ReadyID(AccessibilityNodeInfo info) { if (info.getChildCount() == 0) { if (info != null && info.getClassName().equals("android.widget.EditText")) { if (info.hashCode() == mTeamViewData.mIdTextHash) { if (!info.getText().toString().trim().equals("-")) { mTeamViewData.mIdText = info.getText().toString().replace(" ", "").trim(); return true; } } } } else { for (int i = 0; i < info.getChildCount(); i++) { if (info.getChild(i) != null) { if (ReadyID(info.getChild(i))) { return true; } } } } return false; }
public int findIDTextView(AccessibilityNodeInfo info) { if (info.getChildCount() == 0) { if (info != null && info.getClassName().equals("android.widget.EditText")) { if (info.getText().toString().trim().equals("正在激活")) { state = STATE_BEGIN; } if (info.getText().toString().trim().equals("-")) { mTeamViewData.mIdTextHash = info.hashCode(); return info.hashCode(); } } } else { for (int i = 0; i < info.getChildCount(); i++) { if (info.getChild(i) != null) { int hash = findIDTextView(info.getChild(i)); if (hash != 0) { return hash; } } } } return 0; }
@Override public void handleMessage(Message message) { // TODO Auto-generated method stub super.handleMessage(message); final String zhuangtai = (String) message.obj; switch (message.what) { case UPDATE_TIME: RequestParams params = new RequestParams(UrlData.URL_UPDATE_TIME); params.addBodyParameter("授权用户", UrlData.ADMIN_UID); params.addBodyParameter("密码", UrlData.ADMIN_PASSWORD); params.addBodyParameter("用户ID", mTeamViewData.mPCIDTEXT); params.addBodyParameter("设备ID", mTeamViewData.mIdText); params.addBodyParameter("使用时间", mTeamViewData.BEGIN_TIME); log( "用户ID=" + mTeamViewData.mPCIDTEXT + ";设备ID=" + mTeamViewData.mIdText + "连接判断=" + "使用时间=" + mTeamViewData.BEGIN_TIME); x.http() .post( params, new CommonCallback<String>() { @Override public void onSuccess(String result) { InputStream sbs = new ByteArrayInputStream(result.getBytes()); try { String response = XMLParse.parseResponseCheck(sbs); log("连接判断 response=" + response); if (response.equals("成功")) { handler.removeMessages(UPDATE_TIME); handler.sendEmptyMessageDelayed(UPDATE_TIME, UPDATE_TIME_TIME); } else { handler.removeMessages(UPDATE_TIME); handler.sendEmptyMessageDelayed(UPDATE_TIME, UPDATE_TIME_TIME); } } catch (Exception e) { } } @Override public void onError(Throwable ex, boolean isOnCallback) { log("连接判断 error" + ex.getMessage()); } @Override public void onCancelled(CancelledException cex) {} @Override public void onFinished() {} }); break; case SHUT_DOWN_TEAM: if (state == STATC_CONNECTION_SUCCESS) { handler.removeMessages(SHUT_DOWN_CONNECTION); handler.sendEmptyMessage(SHUT_DOWN_CONNECTION); } break; case UPDATE_STARTEAM: startTeamView(); break; case OPEN: log("restart state=" + state); if (state != STATC_CONNECTION_SUCCESS) { Intent mIntent = new Intent(); mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); ComponentName comp = new ComponentName(paName, MAIN_ACTIVITY); mIntent.setComponent(comp); mIntent.setAction("android.intent.action.VIEW"); startActivity(mIntent); } handler.removeMessages(OPEN); handler.sendEmptyMessageDelayed(OPEN, RESTART); break; case SHUT_DOWN_CONNECTION: state = STATC_CONNECTION_OVER; handler.removeCallbacksAndMessages(null); // 杀死进程,重启teamview log("kill killBackgroundProcesses"); try { Process suProcess = Runtime.getRuntime().exec("su"); DataOutputStream os = new DataOutputStream(suProcess.getOutputStream()); os.writeBytes("adb shell" + "\n"); os.flush(); os.writeBytes("am force-stop " + paName + "\n"); os.flush(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); log(e.getMessage()); } if (processWatcher != null) { processWatcher.stop(); } handler.removeMessages(UPDATE_STARTEAM); handler.sendEmptyMessageDelayed(UPDATE_STARTEAM, 1000 * 8); RequestParams params2 = new RequestParams(UrlData.URL_UPDATE_TIME_END); params2.addBodyParameter("授权用户", UrlData.ADMIN_UID); params2.addBodyParameter("密码", UrlData.ADMIN_PASSWORD); params2.addBodyParameter("用户ID", mTeamViewData.mPCIDTEXT); params2.addBodyParameter("设备ID", mTeamViewData.mIdText); params2.addBodyParameter("使用时间", mTeamViewData.BEGIN_TIME); log( "用户ID=" + mTeamViewData.mPCIDTEXT + ";设备ID=" + mTeamViewData.mIdText + "使用时间=" + mTeamViewData.BEGIN_TIME); x.http() .post( params2, new CommonCallback<String>() { @Override public void onSuccess(String result) { InputStream sbs = new ByteArrayInputStream(result.getBytes()); try { String response = XMLParse.parseResponseCheck(sbs); log("结束时间 response=" + response); if (response.equals("成功")) { // 结束的时候不用更改状态写入结束信息即可 // Message msg = new Message(); // msg.what = UPDATE_ZHUANGTAI; // msg.obj = (String) "空闲"; // handler.removeMessages(UPDATE_ZHUANGTAI); // handler.sendMessage(msg); handler.removeMessages(UPDATE_SHUTDOWN_ZHUANGTAI); handler.sendEmptyMessage(UPDATE_SHUTDOWN_ZHUANGTAI); } } catch (Exception e) { } } @Override public void onError(Throwable ex, boolean isOnCallback) { log("结束时间 error" + ex.getMessage()); } @Override public void onCancelled(CancelledException cex) {} @Override public void onFinished() {} }); break; case UPDATE_ZHUANGTAI: log("连接状态=" + zhuangtai); RequestParams params3 = new RequestParams(UrlData.URL_UPDATE_ZHUANGTAI); params3.addBodyParameter("授权用户", UrlData.ADMIN_UID); params3.addBodyParameter("密码", UrlData.ADMIN_PASSWORD); params3.addBodyParameter("连接状态", zhuangtai); params3.addBodyParameter("设备ID", mTeamViewData.mIdText); log("连接状态=" + zhuangtai + ";设备ID=" + mTeamViewData.mIdText); x.http() .post( params3, new CommonCallback<String>() { @Override public void onSuccess(String result) { InputStream sbs = new ByteArrayInputStream(result.getBytes()); try { String response = XMLParse.parseResponseCheck(sbs); log("更新状态 response=" + response); if (response.equals("成功")) { zhuangtaiTimes = 0; } else { if (zhuangtaiTimes < TIMES) { Message msg = new Message(); msg.what = UPDATE_ZHUANGTAI; msg.obj = zhuangtai; handler.removeMessages(UPDATE_ZHUANGTAI); handler.sendMessageDelayed(msg, TRY_TIME); zhuangtaiTimes++; } } } catch (Exception e) { log("ZHUANGTAI=" + e.getMessage()); } } @Override public void onError(Throwable ex, boolean isOnCallback) { log("更新状态 error" + ex.getMessage()); } @Override public void onCancelled(CancelledException cex) {} @Override public void onFinished() {} }); break; case UPDATE_SHUTDOWN_ZHUANGTAI: RequestParams params4 = new RequestParams(UrlData.URL_SHUT_DOWN_ZHUANGTAI); params4.addBodyParameter("授权用户", UrlData.ADMIN_UID); params4.addBodyParameter("密码", UrlData.ADMIN_PASSWORD); params4.addBodyParameter("设备ID", mTeamViewData.mIdText); log("设备ID=" + mTeamViewData.mIdText); x.http() .post( params4, new CommonCallback<String>() { @Override public void onSuccess(String result) { InputStream sbs = new ByteArrayInputStream(result.getBytes()); try { String response = XMLParse.parseResponseCheck(sbs); log("更新结束信息 response=" + response); if (response.equals("成功")) { shutDownTimes = 0; mTeamViewData.mPCIDTEXT = ""; state = STATE_BEGIN; } else { if (shutDownTimes < TIMES) { handler.removeMessages(UPDATE_SHUTDOWN_ZHUANGTAI); handler.sendEmptyMessageDelayed( UPDATE_SHUTDOWN_ZHUANGTAI, TRY_TIME); shutDownTimes++; } } } catch (Exception e) { } } @Override public void onError(Throwable ex, boolean isOnCallback) { log("更新结束信息 error" + ex.getMessage()); } @Override public void onCancelled(CancelledException cex) {} @Override public void onFinished() {} }); break; case UPDATE_BEGIN_ZHUANGTAI: // 写状态时直接调用状态的handler即可 log("UPDATE_BEGIN_ZHUANGTAI=" + state + ";id=" + mTeamViewData.mIdText); if (state == STATE_BEGIN || state == STATE_ACTIVATIONING) // 没有获取到id,正在激活,离线状态 { // 没有获取到id,写入离线状态,并同时再次进行此handler // 如果没有获取到id,如何写离线状态?怎么找到对应id的记录写呢? mTeamViewData.mIdText = Dbmanager.getUserId(); Message msg = new Message(); msg.what = UPDATE_ZHUANGTAI; msg.obj = (String) "离线"; handler.removeMessages(UPDATE_ZHUANGTAI); handler.sendMessage(msg); handler.removeMessages(UPDATE_BEGIN_ZHUANGTAI); handler.sendEmptyMessageDelayed(UPDATE_BEGIN_ZHUANGTAI, UPDATE_BEGIN_TIME_TIME); } else if (state == STATE_GET_ID_SUCCESS) // 获取到id,正在空闲状态 { // 成功获取到id,写入空闲状态,并停止handler Message msg = new Message(); msg.what = UPDATE_ZHUANGTAI; msg.obj = (String) "空闲"; handler.removeMessages(UPDATE_ZHUANGTAI); handler.sendMessage(msg); handler.removeMessages(UPDATE_BEGIN_ZHUANGTAI); handler.sendEmptyMessageDelayed(UPDATE_BEGIN_ZHUANGTAI, UPDATE_BEGIN_TIME_TIME); } break; case BEGIN_BEGIN: state = STATC_CONNECTION_SUCCESS; log("connection success"); RequestParams params5 = new RequestParams(UrlData.URL_BEGIN_CONNECT); params5.addBodyParameter("授权用户", UrlData.ADMIN_UID); params5.addBodyParameter("密码", UrlData.ADMIN_PASSWORD); params5.addBodyParameter("用户ID", mTeamViewData.mPCIDTEXT); params5.addBodyParameter("设备ID", mTeamViewData.mIdText); params5.addBodyParameter("使用时间", mTeamViewData.BEGIN_TIME); log( "用户ID=" + mTeamViewData.mPCIDTEXT + ";设备ID=" + mTeamViewData.mIdText + "使用时间=" + mTeamViewData.BEGIN_TIME); x.http() .post( params5, new CommonCallback<String>() { @Override public void onSuccess(String result) { InputStream sbs = new ByteArrayInputStream(result.getBytes()); try { String response = XMLParse.parseResponseCheck(sbs); Log.d("DemoLog", "开始时间 response=" + response); if (response.equals("成功")) { // 点击自动允许 if (mTeamViewData.allowButton != null) { mTeamViewData.allowButton.performAction( AccessibilityNodeInfo.ACTION_CLICK); // state = STATE_ALLOW; } else { log("allowButton==null"); } Message msg = new Message(); msg.what = UPDATE_ZHUANGTAI; msg.obj = (String) "忙碌"; handler.removeMessages(UPDATE_ZHUANGTAI); handler.sendMessage(msg); handler.removeMessages(UPDATE_TIME); handler.sendEmptyMessageDelayed(UPDATE_TIME, UPDATE_TIME_TIME); handler.removeMessages(SHUT_DOWN_TEAM); handler.sendEmptyMessageDelayed(SHUT_DOWN_TEAM, SHUT_DOWN_TEAM_TIME); Intent i = new Intent(Intent.ACTION_MAIN); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.addCategory(Intent.CATEGORY_HOME); startActivity(i); } } catch (Exception e) { log(e.getMessage()); } } @Override public void onError(Throwable ex, boolean isOnCallback) { Log.d("DemoLog", "开始时间 error" + ex.getMessage()); } @Override public void onCancelled(CancelledException cex) {} @Override public void onFinished() {} }); break; } }