Java Code Examples for android.view.accessibility.AccessibilityEvent#getPackageName()

The following examples show how to use android.view.accessibility.AccessibilityEvent#getPackageName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LgcAccessibilityService.java    From live-group-chat with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    if (!enabled) {
        return;
    }
    if (AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED == event.getEventType()) {
        Notification notification = (Notification) event.getParcelableData();
        if (notification != null) {
            LogUtils.d(TAG, "receive notification from " + event.getPackageName()
                    + "|title is " + notification.tickerText);
            LgcApp.getInstance().onNotification(event.getPackageName(), notification,
                    System.currentTimeMillis());
        }
    } else if (AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED == event.getEventType()) {
        // find in android sources event.getPackageName() will not be null, but crash collect
        // show it is may be null
        CharSequence package_name = event.getPackageName();
        if (package_name != null) {
            LogUtils.d(TAG, "current package is : " + package_name);
        }
    }
}
 
Example 2
Source File: TelevisionDPadManager.java    From talkback with Apache License 2.0 6 votes vote down vote up
@Override
public void onAccessibilityEvent(AccessibilityEvent event, Performance.EventId eventId) {
  if (event.getEventType() != AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
    return;
  }
  final String packageName =
      event.getPackageName() == null ? "" : event.getPackageName().toString();

  if (!TextUtils.equals(currentWindowPackageName, packageName)) {
    if (DEBUG) {
      LogUtils.d(
          TAG, "Window changed. " + "From: " + currentWindowPackageName + "; To: " + packageName);
    }
    currentWindowPackageName = packageName;
    onWindowChanged();
  }
}
 
Example 3
Source File: SwitchAccessScreenFeedbackManager.java    From talkback with Apache License 2.0 6 votes vote down vote up
@Override
public void onAccessibilityEvent(AccessibilityEvent event, @Nullable EventId eventId) {
  // Check whether the window event is triggered by the Switch Access Menu button overlay showing
  // up. If so, ignore this event. This is because when the Switch Access Menu button and the
  // underlying overlay show up on the screen, the button is highlighted at the same time. If we
  // do not ignore this event, "Switch Access Menu" will be announced twice. First for the Switch
  // Access Menu button overlay showing up, then for the highlighted Switch Access Menu button.
  //
  // We use two criteria to check if the window is the Switch Access Menu button overlay:
  // 1. The package of the event is the same as the Switch Access Accessibility Service.
  // 2. The text of the event is the same as the text of the menu button.
  CharSequence packageName = event.getPackageName();
  if (service.getPackageName().equals(packageName)) {
    CharSequence text = StringBuilderUtils.getAggregateText(event.getText());
    if (text != null
        && text.toString()
            .equals(service.getResources().getString(R.string.option_scanning_menu_button))) {
      return;
    }
  }

  interpreter.interpret(event, eventId);
}
 
Example 4
Source File: PerAppMonitor.java    From kernel_adiutor with Apache License 2.0 6 votes vote down vote up
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    AccessibilityServiceInfo serviceInfo = this.getServiceInfo();
    accessibilityId = serviceInfo.getId();

    PackageManager localPackageManager = getPackageManager();
    Intent intent = new Intent("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.HOME");
    String launcher = localPackageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY).activityInfo.packageName;

    if(event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED && event.getPackageName() != null) {
        sPackageName = event.getPackageName().toString();
        Log.d(TAG, "Package Name is "+sPackageName);
        if ((System.currentTimeMillis() - time) < 1000) {
            if (!sPackageName.equals(launcher) || !sPackageName.equals("com.android.systemui")) {
                process_window_change(sPackageName);
            }
        }
        else if ((System.currentTimeMillis() - time) >= 1000) {
            process_window_change(sPackageName);
        }
    }
}
 
Example 5
Source File: PerAppMonitor.java    From KA27 with Apache License 2.0 6 votes vote down vote up
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    AccessibilityServiceInfo serviceInfo = this.getServiceInfo();
    accessibilityId = serviceInfo.getId();

    if (event.getPackageName() == null || event.getEventType() != AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED)
        return;

    sPackageName = event.getPackageName().toString();
    Log.d(TAG, "Package Name is " + sPackageName);
    if (sPackageName.equals("com.android.systemui"))
        return;

    if ((System.currentTimeMillis() - time) < 2000) {
        if (!sPackageName.equals(UserLauncher())) {
            process_window_change(sPackageName);
        }
    } else {
        process_window_change(sPackageName);
    }

}
 
Example 6
Source File: DebugAccessibilityService.java    From DoraemonKit with Apache License 2.0 6 votes vote down vote up
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    CharSequence pkgName = event.getPackageName();
    if (pkgName == null) {
        return;
    }
    if (!pkgName.equals(getPackageName())) {
        return;
    }
    if (event.getEventType() != AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
        return;
    }
    if (!isActivityEvent(event)) {
        return;
    }
    AccessibilityNodeInfo info = event.getSource();
    if (info == null) {
        return;
    }
    Intent intent = new Intent(BroadcastAction.ACTION_ACCESSIBILITY_UPDATE);
    intent.putExtra(BundleKey.ACCESSIBILITY_DATA, info);
    LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent);
}
 
Example 7
Source File: AccessibilityEventUtils.java    From brailleback with Apache License 2.0 5 votes vote down vote up
/**
 * Determines if the generating class of an {@link AccessibilityEvent} is an
 * instance of a given {@link Class}.
 *
 * @param context The application context.
 * @param event An {@link AccessibilityEvent} dispatched by the
 *            accessibility framework.
 * @param referenceClassName The name of a {@link Class} to match by type or
 *            inherited type.
 * @return {@code true} if the {@link AccessibilityEvent} object matches the
 *         {@link Class} by type or inherited type, {@code false} otherwise.
 */
public static boolean eventMatchesClass(
        Context context, AccessibilityEvent event, String referenceClassName) {
    if (event == null) {
        return false;
    }

    final ClassLoadingManager loader = ClassLoadingManager.getInstance();
    final CharSequence eventClassName = event.getClassName();
    final CharSequence appPackage = event.getPackageName();

    return loader.checkInstanceOf(context, eventClassName, appPackage, referenceClassName);
}
 
Example 8
Source File: UiChangeHandler.java    From talkback with Apache License 2.0 5 votes vote down vote up
private void sendWindowChangeEventsToWindowChangedListener(
    WindowChangedListener windowChangedListener, List<AccessibilityEvent> windowChangeEventList) {
  if (isRunning) {
    while (!windowChangeEventList.isEmpty()) {
      AccessibilityEvent event = windowChangeEventList.get(0);

      CharSequence packageName = event.getPackageName();
      if (service.getPackageName().equals(packageName)) {
        AccessibilityNodeInfo info = event.getSource();
        if (info != null) {
          CharSequence className = info.getClassName();
          // Check whether the window events in the event list are triggered by opening the
          // Switch Access menu window. If so, clears the event list and calls
          // WindowChangeListener#onSwitchAccessMenuShown to generate screen feedback for
          // the Switch Access menu.
          //
          // We use two criteria to check if a window is a Switch Access menu window:
          // 1. The package of the event is the same as the Switch Access Accessibility
          //    Service.
          // 2. The source AccessibilityNodeInfoCompat of the event has the same class name
          //    as SwitchAccessMenuOverlay.
          if (switchAccessMenus.containsKey(className)) {
            windowChangedListener.onSwitchAccessMenuShown(switchAccessMenus.get(className));
            windowChangeEventList.clear();
            return;
          }
        }
      }

      windowChangedListener.onWindowChangedAndIsNowStable(
          windowChangeEventList.get(0), Performance.EVENT_ID_UNTRACKED);
      windowChangeEventList.remove(0);
    }
  }
}
 
Example 9
Source File: PerAppMonitor.java    From isu with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    context = this;
    accessibilityId = this.getServiceInfo().getId();
    isCMSU = Tools.SuVersionBool(Tools.SuVersion(context));

    if (Build.VERSION.SDK_INT >= 24 && !isCMSU) {
            Log.d(TAG, " disableSelf");
            disableSelf();
    }

    if (!isCMSU || event.getEventType() != AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED || event.getPackageName() == null)
        return;

    //delay check after su was changed using another tool
    bootTime = SystemClock.elapsedRealtime();
    allowdelay = Integer.valueOf(Tools.readString("allow_delay", "0", context));
    delaysResult = (Tools.getLong(Constants.SWITCH_DELAY, 0, context) + allowdelay);
    FileSwitchSuDelay = Tools.RoFileSwitchSuDelay(context) + allowdelay;

     Log.d(TAG, "FileSwitchSuDelay = " + FileSwitchSuDelay);

    if (delaysResult > System.currentTimeMillis())
        Log.d(TAG, "current delay result " +
            (delaysResult - System.currentTimeMillis()) + " mseconds");
    else if (FileSwitchSuDelay > System.currentTimeMillis())
        Log.d(TAG, "current delay result " +
            (FileSwitchSuDelay - System.currentTimeMillis()) + " mseconds");
    else {
        sPackageName = event.getPackageName().toString();
        Log.d(TAG, "Package Name is " + sPackageName + " time " + (System.currentTimeMillis() - time));
        if (sPackageName.equals("com.bhb27.isu") || sPackageName.equals("com.android.systemui"))
            return;
        else if ((System.currentTimeMillis() - time) < systemdelay) {
            if (!sPackageName.equals(UserLauncher()))
                process_window_change(sPackageName);
        } else
            process_window_change(sPackageName);
    }
}
 
Example 10
Source File: MainService.java    From Anti-recall with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
    public void onAccessibilityEvent(AccessibilityEvent event) {
        try {
            if (event.getPackageName() == null) {
                Log.d(TAG, "onAccessibilityEvent: package name is null, return");
                return;
            }
            packageName = event.getPackageName() + "";

//        if (!(packageName.equals(pkgTim) || packageName.equals(pkgQQ) || packageName.equals(pkgWX)))
//            return;

//            NodesInfo.show(event.getSource(), TAG, "d");
//            NodesInfo.show(root, TAG, "d");

            int eventType = event.getEventType();
            if (eventType != AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) {
                Log.w(TAG, AccessibilityEvent.eventTypeToString(eventType));
            } else
                Log.v(TAG, AccessibilityEvent.eventTypeToString(eventType));

            switch (eventType) {
                case AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED:
                    onNotification(event);
                    break;
                case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED:
                case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
                    autoLoginWX();
                    onContentChanged(event);
                    break;
                case AccessibilityEvent.TYPE_VIEW_CLICKED:
                    onClick(event);
                    break;

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
Example 11
Source File: DetectionService.java    From MiPushFramework with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 重载辅助功能事件回调函数,对窗口状态变化事件进行处理
 *
 * @param event event
 */
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
        CharSequence packageName = event.getPackageName();
        if (packageName != null) {
            foregroundPackageName = packageName.toString();
        }
    }
}
 
Example 12
Source File: AccEvent.java    From PrivacyStreams with Apache License 2.0 5 votes vote down vote up
AccEvent(AccessibilityEvent accessibilityEvent, AccessibilityNodeInfo rootNode) {
    this.setFieldValue(EVENT, accessibilityEvent);
    this.setFieldValue(EVENT_TIME, accessibilityEvent.getEventTime());
    this.setFieldValue(ROOT_NODE, rootNode);
    this.setFieldValue(EVENT_TYPE, accessibilityEvent.getEventType());
    CharSequence charSequence = accessibilityEvent.getPackageName();
    String packageName = charSequence == null ? "" : charSequence.toString();
    this.setFieldValue(PACKAGE_NAME, packageName);
}
 
Example 13
Source File: TimeCatMonitorService.java    From timecat with Apache License 2.0 5 votes vote down vote up
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    //虚拟手机按键处理,优先级高于是否点击分词的判断
    if ((event.getEventType() == TYPE_VIEW_LONG_CLICKED) && ("com.android.systemui".equals(event.getPackageName()))) {
        if (TextUtils.isEmpty(event.getContentDescription())) {
            return;
        }
        //长按虚拟机触发的,需要转到按键处理去
        if (!TextUtils.isEmpty(back) && event.getContentDescription().equals(back)) {
            KeyPressedTipViewController.getInstance().onKeyLongPress(KeyEvent.KEYCODE_BACK);
        } else if (!TextUtils.isEmpty(home) && event.getContentDescription().equals(home)) {
            KeyPressedTipViewController.getInstance().onKeyLongPress(KeyEvent.KEYCODE_HOME);
        } else if (!TextUtils.isEmpty(recent) && event.getContentDescription().equals(recent)) {
            KeyPressedTipViewController.getInstance().onKeyLongPress(KeyEvent.KEYCODE_APP_SWITCH);
        }
    }
    if (!isRun) {
        return;
    }
    LogUtil.d(TAG, "onAccessibilityEvent:" + event);
    int type = event.getEventType();
    switch (type) {
        case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
            mWindowClassName = event.getClassName();
            mCurrentPackage = event.getPackageName() == null ? "" : event.getPackageName().toString();
            Integer selectType = selections.get(mCurrentPackage);
            mCurrentType = selectType == null ? TYPE_VIEW_NONE : (selectType + 1);
            if ("com.tencent.mm.plugin.sns.ui.SnsTimeLineUI".equals(mWindowClassName)) {
                setCapabilities(true);
            } else {
                setCapabilities(false);
            }
            break;
        case TYPE_VIEW_CLICKED:
        case TYPE_VIEW_LONG_CLICKED:
            getText(event);
            break;
    }
}
 
Example 14
Source File: UiDevice.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
public String waitToast(final String pkg, final long timeout) {
	final StringBuffer result = new StringBuffer();
	final Runnable emptyRunnable = new Runnable() {
		@Override
		public void run() {
		}
	};
	final UiAutomation.AccessibilityEventFilter checkWindowUpdate = (UiAutomation.AccessibilityEventFilter) new UiAutomation.AccessibilityEventFilter() {
		public boolean accept(final AccessibilityEvent event) {
			if (event.getEventType() == 64) {
				final String sourcePackageName = (String) event
						.getPackageName();
				if (sourcePackageName.equals(pkg)) {
					final Parcelable parcelable = event.getParcelableData();
					if (!(parcelable instanceof Notification)) {
						final String toastMsg = (String) event.getText()
								.get(0);
						if (toastMsg != null) {
							result.append(toastMsg);
						}
						return true;
					}
				}
			}
			return false;
		}
	};
	try {
		this.getAutomatorBridge()
				.executeCommandAndWaitForAccessibilityEvent(emptyRunnable,
						checkWindowUpdate, timeout);
	} catch (TimeoutException ex) {
	} catch (Exception ex2) {
	}
	return result.toString();
}
 
Example 15
Source File: BaseDetectionEngine.java    From android-overlay-protection with Apache License 2.0 4 votes vote down vote up
@Override
public void handleEvent(AccessibilityEvent event) {
    // Avoid processing events when screen is locked
    if (_keyguardManager != null) {
        boolean locked = _keyguardManager.inKeyguardRestrictedInputMode();
        if (locked) {
            Log.i(TAG, "Screen locked, skipping overlay check!");
            return;
        }
    }

    Log.d(TAG, String.format("New event %s", event.toString()));
    _eventCounter.newEvent();
    _notifyService.updateNotificationCount(_eventCounter.getLastMinuteEventCount());
    if (_resultReceiver != null) {
        Bundle bundle = new Bundle();
        bundle.putLong("eventCount", _eventCounter.getLastMinuteEventCount());
        _resultReceiver.send(ServiceCommunication.MSG_EVENT_COUNT_UPDATE, bundle);
    }


    // When overlay is detected avoid performing useless computation
    if (_overlayState.isHasOverlay() || _overlayState.isPendingUninstall())
        return;

    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
        if (event.getPackageName() == null)
            return;

        String eventPackage = event.getPackageName().toString();
        ComponentName componentName = new ComponentName(
                eventPackage,
                event.getClassName().toString()
        );
        ActivityInfo activityInfo = tryGetActivity(componentName);
        boolean isActivity = activityInfo != null;
        if (isActivity) {
            LogPrinter logPrinter = new LogPrinter(Log.DEBUG, TAG);
            activityInfo.dump(logPrinter, "");
        }
        String className = event.getClassName().toString();

        // Perform detection
        boolean parentAvailable = event.getSource() != null ? event.getSource().getParent() != null : false;

        Log.d(TAG, String.format("Collected info isActivity %s, parentAvailable: %s", String.valueOf(isActivity), String.valueOf(parentAvailable)));

        if (_overlayState.getIgnoreOncePackage().equals(eventPackage)) {
            Log.d(TAG, String.format("Package %s ignored once", eventPackage));
        } else if (eventPackage.equals(previousEventPackage)) {
            Log.d(TAG, String.format("Last two event have the same package %s, skipping check!", eventPackage));
        } else if (_layoutClasses.contains(className) && !isActivity && !parentAvailable) {
            Log.d(TAG, String.format("Detected suspicious class %s without activity and parent for process %s, checking whitelist", className, eventPackage));
            if (!checkWhitelistHit(eventPackage)) {
                Log.d(TAG, "No whitelist entry found");
                if (checkSuspectedApps(eventPackage)) {
                    Log.d(TAG, String.format("******* VIEW OVERLAY DETECTED!!!"));
                    _overlayState.setOffender(eventPackage);
                    _overlayState.setProcess(_currentProcess);
                    _notifyService.processOverlayState(_overlayState);
                }
            } else {
                Log.d(TAG, "Whitelist hit skipping!");
            }
        } else if (isActivity && activityInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE && !parentAvailable) {
            Log.d(TAG, String.format("Detected suspicious activity %s with single instance flag, checking whitelist", activityInfo.packageName));
            if (!checkWhitelistHit(eventPackage)) {
                Log.d(TAG, "No whitelist entry found");
                if (checkSuspectedApps(eventPackage)) {
                    Log.d(TAG, String.format("******* ACTIVITY OVERLAY DETECTED!!!"));
                    _overlayState.setOffender(eventPackage);
                    _overlayState.setProcess(_currentProcess);
                    _notifyService.processOverlayState(_overlayState);
                }
            } else {
                Log.d(TAG, "Whitelist hit skipping!");
            }
        }
        previousEventPackage = eventPackage;
    }
}
 
Example 16
Source File: AccessibilityEventUtils.java    From brailleback with Apache License 2.0 4 votes vote down vote up
/**
 * @return If the <code>first</code> event is equal to the <code>second</code>.
 */
public static boolean eventEquals(AccessibilityEvent first, AccessibilityEvent second) {
    // TODO: The framework should implement AccessibilityEvent#equals()
    if (first == null || second == null) {
        return false;
    }
    if (first.getEventType() != second.getEventType()) {
        return false;
    }
    if (first.getPackageName() == null) {
        if (second.getPackageName() != null) {
            return false;
        }
    } else if (!first.getPackageName().equals(second.getPackageName())) {
        return false;
    }
    if (first.getClassName() == null) {
        if (second.getClassName() != null) {
            return false;
        }
    } else if (!first.getClassName().equals(second.getClassName())) {
        return false;
    }
    if (!first.getText().equals(second.getText())) {
        // The result of getText() is never null.
        return false;
    }
    if (first.getContentDescription() == null) {
        if (second.getContentDescription() != null) {
            return false;
        }
    } else if (!first.getContentDescription().equals(second.getContentDescription())) {
        return false;
    }
    if (first.getBeforeText() == null) {
        if (second.getBeforeText() != null) {
            return false;
        }
    } else if (!first.getBeforeText().equals(second.getBeforeText())) {
        return false;
    }
    if (first.getParcelableData() != null) {
        // Parcelable data may not implement equals() correctly.
        return false;
    }
    if (first.getAddedCount() != second.getAddedCount()) {
        return false;
    }
    if (first.isChecked() != second.isChecked()) {
        return false;
    }
    if (first.isEnabled() != second.isEnabled()) {
        return false;
    }
    if (first.getFromIndex() != second.getFromIndex()) {
        return false;
    }
    if (first.isFullScreen() != second.isFullScreen()) {
        return false;
    }
    if (first.getCurrentItemIndex() != second.getCurrentItemIndex()) {
        return false;
    }
    if (first.getItemCount() != second.getItemCount()) {
        return false;
    }
    if (first.isPassword() != second.isPassword()) {
        return false;
    }
    if (first.getRemovedCount() != second.getRemovedCount()) {
        return false;
    }
    if (first.getEventTime() != second.getEventTime()) {
        return false;
    }
    return true;
}
 
Example 17
Source File: AccessibilityService.java    From FreezeYou with Apache License 2.0 4 votes vote down vote up
@SuppressLint("SwitchIntDef")
@Override
public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
    int type = accessibilityEvent.getEventType();
    switch (type) {
        case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
            if (accessibilityEvent.isFullScreen()) {
                CharSequence pkgName = accessibilityEvent.getPackageName();
                if (pkgName != null) {
                    boolean isScreenOn = true;
                    PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
                    if (pm != null) {
                        isScreenOn = pm.isScreenOn();
                    }
                    String pkgNameString = pkgName.toString();
                    String previousPkg = MainApplication.getCurrentPackage();
                    if (isScreenOn &&
                            !"".equals(pkgNameString) &&
                            !"com.android.systemui".equals(pkgNameString) &&
                            !"com.android.packageinstaller".equals(pkgNameString) &&
                            !"android".equals(pkgNameString)) {
                        MainApplication.setCurrentPackage(pkgNameString);
                        if (!pkgNameString.equals(previousPkg)
                                && new AppPreferences(getApplicationContext()).getBoolean("freezeOnceQuit", false)
                                && OneKeyListUtils.existsInOneKeyList(getApplicationContext(), getString(R.string.sFreezeOnceQuit), previousPkg)) {
                            FUFUtils.processFreezeAction(getApplicationContext(), previousPkg, null, null, false, null, false);
                        }

                        onLeaveApplications(previousPkg, pkgNameString);//检测+执行
                    }

                    onApplicationsForeground(previousPkg, pkgNameString);//检测+执行

                    addUpUseTimes(pkgNameString);//使用次数计数(增加)

                }
            }
            break;
        default:
            break;
    }
}
 
Example 18
Source File: peService.java    From styT with Apache License 2.0 4 votes vote down vote up
/**
 * 描述:所有事件响应的时候会回调
 * 作者:卜俊文
 * 邮箱:[email protected]
 * 日期:2017/11/6 上午9:26
 */
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    SharedPreferences sharedPreferences = getSharedPreferences("nico.styTool_preferences", MODE_PRIVATE);
    boolean isFirstRun = sharedPreferences.getBoolean("ok_c", true);
    //Editor editor = sharedPreferences.edit();
    if (isFirstRun) {
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        builder.setSmallIcon(R.mipmap.ic_launcher);
        builder.setContentTitle("妮哩");
        builder.setContentText("QQ抢红包正在运行");
        builder.setOngoing(true);
        Notification notification = builder.build();
        NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        manager.notify(57, notification);
    } else {

    }
    //验证抢红包的开关
    if (!invalidEnable()) {
        return;
    }

    //事件类型
    int eventType = event.getEventType();

    //获取包名
    CharSequence packageName = event.getPackageName();
    if (TextUtils.isEmpty(packageName)) {
        return;
    }

    switch (eventType) {

        //状态栏变化
        case AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED:

            if (QQConstant.QQ_PACKAGE_NAME.equals(packageName)) {
                //处理状态栏上QQ的消息,如果是红包就跳转过去
                progressQQStatusBar(event);
            }
            break;

        //窗口切换的时候回调
        case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
        case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED:
            if (QQConstant.QQ_PACKAGE_NAME.equals(packageName)) {
                //处理正在QQ聊天窗口页面,有其他群或者人有新的红包提醒,跳转过去。
                progressNewMessage(event);
                //处理聊天页面的红包
                progressQQChat(event);
            }

            break;
    }


}