| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742 |
- package com.wiipu.marketingrobot;
- import android.accessibilityservice.AccessibilityService;
- import android.accessibilityservice.AccessibilityServiceInfo;
- import android.annotation.TargetApi;
- import android.app.ActivityManager;
- import android.app.KeyguardManager;
- import android.app.Notification;
- import android.app.PendingIntent;
- import android.content.ComponentName;
- import android.content.Context;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.content.pm.PackageInfo;
- import android.content.pm.PackageManager;
- import android.os.Build;
- import android.os.PowerManager;
- import android.os.SystemClock;
- import android.text.TextUtils;
- import android.view.accessibility.AccessibilityEvent;
- import android.view.accessibility.AccessibilityManager;
- import android.view.accessibility.AccessibilityNodeInfo;
- import com.wiipu.marketingrobot.contract.getCommonValueContract;
- import com.wiipu.marketingrobot.function.addAutoReplyFunction;
- import com.wiipu.marketingrobot.function.addFriendFunction;
- import com.wiipu.marketingrobot.function.addGroupFunction;
- import com.wiipu.marketingrobot.function.eventClassFunction;
- import com.wiipu.marketingrobot.function.getMoneyFunction;
- import com.wiipu.marketingrobot.function.handleChatFunction;
- import com.wiipu.marketingrobot.presenter.getCommonValuePresenter;
- import com.wiipu.marketingrobot.response.CommonValueResponse;
- import com.wiipu.marketingrobot.response.enableAddFriendResponse;
- import com.wiipu.marketingrobot.widget.AccessibilityHelper;
- import com.wiipu.netlib.rxbus.RxBus;
- import com.wiipu.netlib.utils.LogUtils;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.List;
- import rx.Subscription;
- import rx.functions.Action1;
- import rx.subscriptions.CompositeSubscription;
- /**
- * Recoder: Axion
- * Description: 智能投股机器人主服务
- */
- public class AutoReplyService extends AccessibilityService implements getCommonValueContract.View {
- private final static String MM_PNAME = "com.tencent.mm";
- private static final String TAG = "maptrix";
- public static boolean hasAction = false;
- private String scontent;
- private static PackageInfo mWechatPackageInfo = null;
- boolean isGroupChat = false;
- public static boolean isInAction = false;
- public static ArrayList<String> msgList = new ArrayList<>();//事件列表
- public static String msgSenderName;
- private getMoneyFunction mGetMoney;
- private handleChatFunction mHandleChat;
- private addFriendFunction mAddFriendFunction;
- private addGroupFunction mAddGroupFunction;
- public static AutoReplyService mAutoReplyService;
- private addAutoReplyFunction mAddAutoReplyFunction;
- private CompositeSubscription mSubscription = new CompositeSubscription();
- private getCommonValuePresenter mGetCommonValuePresenter;
- public volatile static int enableFriendsCounts = 1;//为了防止程序初次运行时候出现bug,先置1
- private SharedPreferences pref;
- private boolean breakOutLoop = false;
- private static final String savedRobotNum = "robotNum";
- private static final String savedRobotId = "robotId";
- public static String allowedArea;
- private boolean inMineView = false; //标志页面在主页面“我的”模块
- private boolean msgView = false;//标志收到消息
- private AccessibilityEvent changeStateEvent = AccessibilityEvent.obtain();
- private AccessibilityEvent doInBackEvent = AccessibilityEvent.obtain();
- private AccessibilityEvent webViewEvent = AccessibilityEvent.obtain();
- private boolean undoWorkFlag = false;
- //temp
- public static boolean isInSeeRoomInfoUICanNotGoBack = false;
- public static boolean isSendingPermissionRequest = false;
- public enum actionType {
- isHongBao, isZhuanZhang, isChat, isAddFriend, isAddAutoReply, isNone, isGroupInvited
- }
- public static actionType mActionType = actionType.isNone;
- public enum windowAction {
- WINDOW_NONE, WINDOW_LUCKYMONEY_RECEIVEUI, WINDOW_LUCKYMONEY_DETAIL, WINDOW_LAUNCHER, WINDOW_OTHER
- }
- public static windowAction mWindowAction;
- @Override
- public void showCommonValue(CommonValueResponse commonValueResponse, String key) {
- if (key.equals(Constants.KEY_MAX_FRIEND_NUM)) {
- enableFriendsCounts = Integer.parseInt(commonValueResponse.getMsg());
- LogUtils.e(TAG + " 当前可添加最大好友数为 : " + enableFriendsCounts);
- }
- }
- @Override
- public void showAllowedArea(CommonValueResponse commonValueResponse) {
- allowedArea = commonValueResponse.getMsg();
- }
- @Override
- public void showEmpty() {
- }
- @Override
- public void showError(String message) {
- }
- @Override
- protected void onServiceConnected() {
- super.onServiceConnected();
- LogUtils.d(TAG + " onServiceConnected");
- mGetMoney = new getMoneyFunction(this);
- mHandleChat = new handleChatFunction(this);
- mAddFriendFunction = new addFriendFunction(this);
- mAddGroupFunction = new addGroupFunction(this);
- mAddAutoReplyFunction = new addAutoReplyFunction(this);
- mGetCommonValuePresenter = new getCommonValuePresenter(this);
- mGetCommonValuePresenter.getAllowedArea();
- pref = getSharedPreferences("robotData", Context.MODE_PRIVATE);
- mAutoReplyService = this;
- if (pref.getString(savedRobotId, null) != null) {
- mGetCommonValuePresenter.getValueByKey(pref.getString(savedRobotId, null), Constants.KEY_MAX_FRIEND_NUM);
- }
- Subscription subscription = RxBus.toObservable(eventClassFunction.class)
- .subscribe(new Action1<eventClassFunction>() {
- @Override
- public void call(eventClassFunction eventClassFunction) {
- if (eventClassFunction.isNeedToWork()) {
- doTheUndoWork();
- }
- }
- });
- //msgList.add("asd");
- mSubscription.add(subscription);
- updatePackageInfo();
- // App.getRefWatcher(this).watch(this);
- }
- /**
- * 必须重写的方法,响应各种事件,
- * 未获得机器人名之前,所有操作首先应获得机器人名 机器人聊天头像为lx
- * 查询股票/收钱,建立在加了好友的基础上,故在加好友方法内,添加是否获得机器人名的判断,
- * 若没有名字,则先发送“请稍等”,然后点开自己的头像来获得机器人名和微信号
- *
- * @param event
- */
- @Override
- public void onAccessibilityEvent(final AccessibilityEvent event) {
- // LogUtil.e(TAG, "onAccessibilityEvent: " + mEvent.getClassName());
- int eventType = event.getEventType();
- switch (eventType) {
- case AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED:// 通知栏事件,仅有在锁屏状态下, 或者亮屏后台状态下才会发送通知
- LogUtils.d("maptrix : get notification event");
- if (pref.getString(savedRobotId, null) != null) {
- mGetCommonValuePresenter.getValueByKey(pref.getString(savedRobotId, null), Constants.KEY_MAX_FRIEND_NUM);
- }
- List<CharSequence> texts = event.getText();
- if (!texts.isEmpty()) {
- for (CharSequence text : texts) {
- LogUtils.d("maptrix : onAccessibilityEvent: texts size is " + texts.size());
- String content = text.toString();
- LogUtils.d("maptrix : onAccessibilityEvent: content is " + content);
- if (!TextUtils.isEmpty(content)) {
- if (!isScreenOn()) {
- lightOnScreen();
- LogUtils.d("maptrix : the screen is black");
- sendNotifacationReply(event);
- } else {
- LogUtils.d("maptrix : the screen is on");
- sendNotifacationReply(event);
- }
- }
- }
- }
- break;
- case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
- LogUtils.d("maptrix : window_stat_changed,event name:" + event.getClassName());
- LogUtils.d(TAG + " onAccessibilityEvent: " + mActionType);
- if (event.getClassName().equals("com.tencent.mm.ui.base.p")) {
- /* if (isSendingPermissionRequest) {
- AutoReplyService.isInSeeRoomInfoUICanNotGoBack = false;
- } else {
- AutoReplyService.isInSeeRoomInfoUICanNotGoBack = true;
- }
- isSendingPermissionRequest = false;*/
- break;
- } else if (event.getClassName().equals("com.tencent.mm.plugin.profile.ui.ContactInfoUI")) {
- isSendingPermissionRequest = false;
- } else if (event.getClassName().equals("com.tencent.mm.ui.widget.a.c")) {
- if (mActionType == actionType.isGroupInvited) {
- //如果出现因为隐私原因拒绝添加好友的窗口,那么需要设置isFriendSend标志位为true,
- //当再次出现ContactUIINfo界面后,直接返回。
- LogUtils.d("TYPE_WINDOW_STATE_CHANGED,window:com.tencent.mm.ui.widget.a.c,setFriendSend = true");
- // mAddGroupFunction.setFriendSend(true);
- }
- }
- if (!hasAction) {
- LogUtils.d(TAG + " hasAction = false");
- break;
- }
- // mActionType = actionType.isGroupInvited;
- //mAddGroupFunction.setHasGetMMid(true);
- // mAddGroupFunction.addGroup(event);;
- judgeAction(event);
- break;
- case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED:
- LogUtils.d("maptrix : window content changed " + event.getClassName() + inMineView + msgView); //window content内容变化时候调用
- if (inMineView && msgView) {
- inMineView = false;
- msgView = false;
- changeStateEvent.setEventType(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
- changeStateEvent.setClassName("com.tencent.mm.ui.LauncherUI");
- SystemClock.sleep(500);
- onAccessibilityEvent(changeStateEvent);
- //SystemClock.sleep(500);
- }
- // if (mActionType == actionType.isGroupInvited && event.getClassName().equals("android.webkit.WebView") && !mAddGroupFunction.webViewFlag) {
- // SystemClock.sleep(2000);//用于界面更新
- // webViewEvent.setEventType(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
- // webViewEvent.setClassName("com.tencent.mm.plugin.webview.ui.tools.WebViewUI");
- // mAddGroupFunction.setWebViewFlag(true);
- // onAccessibilityEvent(webViewEvent);
- // }
- break;
- }
- }
- /**
- * 对事件进行判断
- */
- private void judgeAction(AccessibilityEvent event) {
- switch (mActionType) {
- case isChat:
- mHandleChat.setSenderName(msgSenderName);
- mHandleChat.handleChat(event, scontent);
- break;
- case isAddFriend:
- mAddFriendFunction.addFriend(event);
- break;
- case isHongBao:
- mGetMoney.setActionType(actionType.isHongBao);
- mGetMoney.openMoney(event);
- break;
- case isZhuanZhang:
- mGetMoney.setActionType(actionType.isZhuanZhang);
- mGetMoney.openMoney(event);
- break;
- case isGroupInvited:
- mAddGroupFunction.addGroup(event);
- break;
- case isAddAutoReply:
- mAddAutoReplyFunction.addAutoReply(event);
- break;
- default:
- break;
- }
- }
- /**
- * 消息冲突处理
- */
- private void doTheUndoWork() {
- /**
- * 解决思路
- * 当在动作进行中来消息了,就把消息的发送人和内容存起来,在动作结束后统一回到聊天页面,判断事件
- * 此处自行判断小红点然后处理事件
- */
- LogUtils.d(TAG + " doTheUndoWork: ");
- //遍历聊天列表,找没做的任务,右上角有数字的
- //coversationWithAppBrandListView(cwp)-->LinearLayout(b4m)-->...
- // 每一条名称部分的ID为b4o,名称下的消息缩略内容为b4q,头像右上角的带数字小红点为textview,Id为mm
- SystemClock.sleep(3000);
- AccessibilityNodeInfo root = getRootInActiveWindow();
- AccessibilityNodeInfo msgLists = AccessibilityHelper.findNodeInfosById(root, "com.tencent.mm:id/cwp");
- if (msgLists == null) {
- LogUtils.e(TAG + " doTheUndoWork: msg list size is null ");
- return;
- }
- List<AccessibilityNodeInfo> msg = msgLists.findAccessibilityNodeInfosByViewId("com.tencent.mm:id/b4m");
- LogUtils.e(TAG + " doTheUndoWork: " + msg.size());
- if (msg.size() == 0) {
- return;
- }
- for (int i = 0; i < msg.size(); i++) {
- AccessibilityNodeInfo perMsg = msg.get(i);
- AccessibilityNodeInfo redPoint = AccessibilityHelper.findNodeInfosById(perMsg, "com.tencent.mm:id/mm");
- if (redPoint == null) {
- LogUtils.e(TAG + " doTheUndoWork: the" + perMsg.getContentDescription() + " mm is null");
- continue;
- }
- int theMsgCount = Integer.parseInt(redPoint.getText().toString());
- LogUtils.e(TAG + " doTheUndoWork: " + theMsgCount);
- if (theMsgCount > 0) {
- AccessibilityNodeInfo underTextNode = AccessibilityHelper.findNodeInfosById(perMsg, "com.tencent.mm:id/b4q");
- AccessibilityNodeInfo theMsgName = AccessibilityHelper.findNodeInfosById(perMsg, "com.tencent.mm:id/b4o");
- if (underTextNode == null) {
- LogUtils.e(TAG + " doTheUndoWork: underTextNode is null");
- continue;
- }
- if (theMsgName == null) {
- LogUtils.e(TAG + " doTheUndoWork: the msgname is null");
- continue;
- }
- if (theMsgName.getText().toString().equals("腾讯新闻") || theMsgName.getText().toString().equals("服务通知")) {
- continue;
- }
- CharSequence underText = underTextNode.getText();
- CharSequence msgName = theMsgName.getText();
- judgeText(underText, msgName);
- doInBackEvent.setClassName("com.tencent.mm.ui.LauncherUI");
- AccessibilityHelper.performClick(perMsg);
- judgeAction(doInBackEvent);
- return;
- }
- }
- //在这判断是否有未加的好友
- //LauncherUIBottomTabView(bn)-->LinearLayout(child 0,无id)-->RelativeLayout(通讯录框框的布局,没有id,child 1,可点击)
- // -->TextView(d3s) 记录了通讯录未加好友数目
- if (hasUnAddFriend() && enableFriendsCounts != 0) {
- addUnaddFriend();
- return;
- }
- AccessibilityNodeInfo underTab = AccessibilityHelper.findNodeInfosById(root, "com.tencent.mm:id/bn");
- if (underTab == null) {
- LogUtils.e(TAG + " doTheUndoWork: under tab is null");
- performGlobalAction(GLOBAL_ACTION_HOME);
- return;
- }
- AccessibilityNodeInfo mineNode = underTab.getChild(0).getChild(3);
- if (mineNode == null) {
- LogUtils.e(TAG + " doTheUndoWork: mine node is null");
- performGlobalAction(GLOBAL_ACTION_HOME);
- return;
- }
- AccessibilityHelper.performClick(mineNode);
- inMineView = true;
- mActionType = actionType.isNone;
- hasAction = false;
- msgList.clear();
- LogUtils.e(TAG + " doTheUndoWork: " + inMineView);
- //performGlobalAction(GLOBAL_ACTION_HOME);
- }
- /**
- * 判断是否有没加的好友
- */
- private boolean hasUnAddFriend() {
- AccessibilityNodeInfo root = getRootInActiveWindow();
- AccessibilityNodeInfo underTabNode = AccessibilityHelper.findNodeInfosById(root, "com.tencent.mm:id/bn");
- if (underTabNode == null) {
- LogUtils.e(TAG + " doTheUndoWork: underTab is null");
- return false;
- }
- AccessibilityNodeInfo contractTabNode = underTabNode.getChild(0).getChild(1);
- if (contractTabNode == null) {
- LogUtils.e(TAG + " doTheUndoWork: contractNode is null");
- return false;
- }
- AccessibilityNodeInfo unAddFriendCountNode = AccessibilityHelper.findNodeInfosById(contractTabNode, "com.tencent.mm:id/d3s");
- if (unAddFriendCountNode == null) {
- LogUtils.e(TAG + " addUnaddFriend: unAddCountNode is null");
- return false;
- }
- CharSequence count = unAddFriendCountNode.getText();
- if (count == null) {
- return false;
- }
- String strCount = count.toString();
- AccessibilityHelper.performClick(contractTabNode);
- return true;
- }
- /**
- * 添加没加的好友
- */
- private void addUnaddFriend() {
- AccessibilityNodeInfo root = getRootInActiveWindow();
- mActionType = actionType.isAddFriend;
- //通讯录界面,整体是个list(m_),第一个子节点是朋友推荐list,包含未加好友那一行的布局id为brc
- AccessibilityNodeInfo listNode = AccessibilityHelper.findNodeInfosById(root, "com.tencent.mm:id/m_");
- if (listNode == null) {
- LogUtils.e(TAG + " addUnaddFriend: tab view list node is null");
- return;
- }
- AccessibilityNodeInfo unAddFriendNode = AccessibilityHelper.findNodeInfosById(listNode, "com.tencent.mm:id/brc");
- if (unAddFriendNode == null) {
- LogUtils.e(TAG + " addUnaddFriend: unaddFriend node is null");
- return;
- }
- AccessibilityEvent event2 = AccessibilityEvent.obtain();
- event2.setClassName("com.tencent.mm.plugin.subapp.ui.friend.FMessageConversationUI");
- AccessibilityHelper.performClick(unAddFriendNode);
- }
- /**
- * 在聊天列表通过聊天名称下的简略消息来判断消息内容
- */
- private void judgeText(CharSequence charSequence, CharSequence msgName) {
- if (charSequence == null) {
- mActionType = actionType.isChat;
- scontent = null;
- msgSenderName = msgName.toString();
- return;
- }
- scontent = charSequence.toString();
- msgSenderName = msgName.toString();
- String str = charSequence.toString();
- judgeMsgText(str);
- }
- private void findallchild(AccessibilityNodeInfo root) {
- if (root.getChildCount() != 0) {
- int size = root.getChildCount();
- for (int i = 0; i < size; i++) {
- AccessibilityNodeInfo child = root.getChild(i);
- LogUtils.d(TAG + " findallchild: " + child.getContentDescription() + " " + child.getClassName() + " " + child.getViewIdResourceName() + " " + child.getText());
- findallchild(child);
- }
- }
- }
- /**
- * 消息栏处理
- *
- * @param event TODO:找到获得消息标题的办法
- */
- private void sendNotifacationReply(AccessibilityEvent event) {
- //正常的弹框通知
- if (event.getParcelableData() != null
- && event.getParcelableData() instanceof Notification) {
- hasAction = true;
- if (isInAction) {
- //暂时无法获取到消息标题用作判断,将所有收到的消息都存下来,遍历列表时候能找到就找到找不到无所谓
- LogUtils.e(Constants.TAG_PREFIX + TAG + "sendNotifacationReply: in action");
- msgList.add(msgSenderName.length() + msgSenderName + mActionType);
- return;
- }
- Notification notification = (Notification) event
- .getParcelableData();
- String content = notification.tickerText.toString();
- if (content.contains(":")) {
- final String[] cc = content.split(":");
- msgSenderName = cc[0].trim();//发送者名字,非消息标题
- scontent = cc[1].trim();//发送内容
- } else {
- final String[] cc = content.split("请求添加");//加好友的时候会调用这边,基本没啥用
- msgSenderName = cc[0].trim();//发送者名字,非消息标题
- scontent = "请求添加你为朋友";
- }
- LogUtils.i("maptrix : sender name =" + msgSenderName);
- LogUtils.i("maptrix : sender content =" + scontent);
- judgeMsgText(scontent);
- if (inMineView) {
- msgView = true;
- }
- PendingIntent pendingIntent = notification.contentIntent;
- try {
- pendingIntent.send(); //执行点击
- LogUtils.e(TAG + " sendNotifacationReply: dowwwwwwnnnnnn");
- } catch (PendingIntent.CanceledException e) {
- e.printStackTrace();
- }
- }
- //Toast通知不走上面的if,下代码出现在加好友过频情况
- if (event.getText().get(0).toString().contains("操作过于频繁")) {
- //addFriendError = true;
- mHandleChat.setAddFriendError(true);
- mAddGroupFunction.setAddFriendError(true);
- }
- if (event.getText().get(0).toString().contains("已发送")) {
- //isFriendSend = true;
- mHandleChat.setFriendSend(true);
- mAddGroupFunction.setFriendSend(true);
- }
- if (event.getText().get(0).toString().contains("添加联系人失败")) {
- //do someting
- mHandleChat.setFriendSend(true);
- AccessibilityHelper.performBack(mAutoReplyService);
- }
- }
- /**
- * 判断消息是否包含特定的字符串
- */
- private void judgeMsgText(String content) {
- LogUtils.e(TAG + " judgeMsgText: " + content);
- if (content.contains("[微信红包]")) {
- mActionType = actionType.isHongBao;
- } else if (content.contains("[转账]")) {
- mActionType = actionType.isZhuanZhang;
- } else if (content.contains("请求添加你为朋友")) {
- if (enableFriendsCounts == 0) {
- return;
- }
- mActionType = actionType.isAddFriend;
- ;
- } else if (content.contains("邀请你加入群聊")) {
- if (enableFriendsCounts == 0) {
- return;
- }
- mActionType = actionType.isGroupInvited;
- } else if (content.contains("我通过了你的朋友验证请求")) {//由于长度的限制,不能留太长
- mActionType = actionType.isAddAutoReply;
- } else {
- mActionType = actionType.isChat;
- }
- mWindowAction = windowAction.WINDOW_LAUNCHER;
- }
- //基本无效的代码,无法判断微信是否在前台
- /**
- * 判断指定的应用是否在前台运行
- *
- * @param packageName
- * @return
- */
- private boolean isAppForeground(String packageName) {
- ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
- ComponentName cn = am.getRunningTasks(1).get(0).topActivity;
- String currentPackageName = cn.getPackageName();
- LogUtils.d("maptrix : isAppForeground: " + currentPackageName);
- if (!TextUtils.isEmpty(currentPackageName) && currentPackageName.equals(packageName)) {
- return true;
- }
- return false;
- }
- /**
- * 将当前应用运行到前台
- */
- private void bring2Front() {
- ActivityManager activtyManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
- List<ActivityManager.RunningTaskInfo> runningTaskInfos = activtyManager.getRunningTasks(3);
- for (ActivityManager.RunningTaskInfo runningTaskInfo : runningTaskInfos) {
- if (this.getPackageName().equals(runningTaskInfo.topActivity.getPackageName())) {
- activtyManager.moveTaskToFront(runningTaskInfo.id, ActivityManager.MOVE_TASK_WITH_HOME);
- return;
- }
- }
- }
- /**
- * 回到系统桌面
- */
- private void back2Home() {
- mWindowAction = windowAction.WINDOW_NONE;
- hasAction = false;
- mActionType = actionType.isNone;
- isGroupChat = false;
- Intent home = new Intent(Intent.ACTION_MAIN);
- home.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- home.addCategory(Intent.CATEGORY_HOME);
- startActivity(home);
- }
- /**
- * 判断系统是否为黑屏
- */
- private boolean isScreenOn() {
- LogUtils.e(TAG + " isScreenOn: ");
- PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
- return powerManager.isScreenOn();
- }
- /**
- * 点亮屏幕
- */
- private void lightOnScreen() {
- //获取电源管理器对象
- PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
- //获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是调试用的Tag
- PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "MarketingRobot");
- //点亮屏幕
- wl.acquire();
- }
- /**
- * 系统是否在锁屏状态
- *
- * @return
- */
- private boolean isScreenLocked() {
- KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
- return keyguardManager.inKeyguardRestrictedInputMode();
- }
- private void wakeAndUnlock() {
- LogUtils.e(TAG + " wakeAndUnlock: ");
- //获取电源管理器对象
- PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
- //获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是调试用的Tag
- PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "MarketingRobot");
- //点亮屏幕
- wl.acquire();
- //得到键盘锁管理器对象
- KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
- KeyguardManager.KeyguardLock kl = km.newKeyguardLock("unLock");
- //解锁
- kl.disableKeyguard();
- }
- /**
- * 判断当前服务是否正在运行
- */
- @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
- public static boolean isRunning() {
- if (mAutoReplyService == null) {
- return false;
- }
- AccessibilityManager accessibilityManager = (AccessibilityManager) mAutoReplyService.getSystemService(Context.ACCESSIBILITY_SERVICE);
- AccessibilityServiceInfo info = mAutoReplyService.getServiceInfo();
- if (info == null) {
- return false;
- }
- List<AccessibilityServiceInfo> list = accessibilityManager.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_GENERIC);
- Iterator<AccessibilityServiceInfo> iterator = list.iterator();
- boolean isConnect = false;
- while (iterator.hasNext()) {
- AccessibilityServiceInfo i = iterator.next();
- if (i.getId().equals(info.getId())) {
- isConnect = true;
- break;
- }
- }
- if (!isConnect) {
- return false;
- }
- return true;
- }
- /**
- * 获取微信的版本
- */
- public static int getWechatVersion() {
- if (mWechatPackageInfo == null) {
- return 0;
- }
- return mWechatPackageInfo.versionCode;
- }
- /**
- * 更新微信包信息
- */
- private void updatePackageInfo() {
- try {
- mWechatPackageInfo = getPackageManager().getPackageInfo(MM_PNAME, 0);
- } catch (PackageManager.NameNotFoundException e) {
- e.printStackTrace();
- }
- }
- @Override
- public void onInterrupt() {
- }
- }
|