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

The following examples show how to use android.view.accessibility.AccessibilityEvent#getClassName() . 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: MD5_jni.java    From stynico with MIT License 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void openHongBao(AccessibilityEvent event)
{
	CharSequence className = event.getClassName();

	checkScreen(getApplicationContext());

	if ("com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyReceiveUI".equals(className))
	{
		// 点中了红包,下一步就是去拆红包
		checkKey1();
	} else if ("com.tencent.mm.ui.LauncherUI".equals(className) || "com.tencent.mobileqq.activity.ChatActivity".equals(className))
	{
		// 在聊天界面,去点中红包
		checkKey2();
	} else
	{
		// 在聊天界面,去点中红包
		checkKey2();
	}
}
 
Example 2
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 3
Source File: KeyBlockService.java    From KeyBlocker with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    if (!closeAdvancedFunction && mSp.getBoolean(Config.KEYBLOCK_ACTIVITY, false) && !RootScanActivity && !AdvancedScanActivity) {
        int eventType = event.getEventType();
        if (eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
            if (event.getClassName() != null) {
                CurrentActivityFix(event.getPackageName().toString(), event.getClassName().toString());
            }
        }
    }
}
 
Example 4
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 5
Source File: UnRootAccessibility.java    From rebootmenu with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
    CharSequence classNameCS = accessibilityEvent.getClassName();
    String className = null;
    if (classNameCS != null) className = classNameCS.toString();
    new DebugLog("SystemPowerDialog.onAccessibilityEvent className:" + className, DebugLog.LogLevel.V);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        //使用root模式就没有必要保留辅助服务
        if (RootMode.class.getName().equals(className))
            disableSelf();
            //Wear OS H 以下也没有必要
        else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P && SpecialSupport.isAndroidWearOS(this))
            disableSelf();
}
 
Example 6
Source File: AccessibilityEventUtils.java    From talkback with Apache License 2.0 5 votes vote down vote up
public static boolean isFromVolumeControlPanel(AccessibilityEvent event) {
  // Volume slider case.
  // TODO: Find better way to handle volume slider.
  CharSequence sourceClassName = event.getClassName();
  boolean isVolumeInAndroidP =
      BuildVersionUtils.isAtLeastP()
          && TextUtils.equals(sourceClassName, VOLUME_CONTROLS_CLASS_IN_ANDROID_P);
  boolean isVolumeInAndroidO =
      BuildVersionUtils.isAtLeastO()
          && (!BuildVersionUtils.isAtLeastP())
          && TextUtils.equals(sourceClassName, DIALOG_CLASS_NAME);
  return isVolumeInAndroidO || isVolumeInAndroidP;
}
 
Example 7
Source File: TutorialMainFragment.java    From talkback with Apache License 2.0 5 votes vote down vote up
@Override
public void onAccessibilityEvent(AccessibilityEvent event, EventId eventId) {
  if (offButton == null || parentLayout == null) {
    return;
  }

  // There are three types of areas that we're detecting: the button area, areas of the
  // activity that are a11y-focusable, and areas of the activity that are blank.
  // 1) The HoverTrackingButton keeps track of the button area.
  // 2) The HoverTrackingLinearLayout keeps track of blank activity areas.
  // 3) We use TYPE_VIEW_HOVER_ENTER to track a11y-focusable activity areas.
  // The user must begin and end the touch interaction within the Turn TalkBack Off button
  // without moving their finger into other areas of the activity in order to turn TB off.

  switch (event.getEventType()) {
    case AccessibilityEvent.TYPE_TOUCH_INTERACTION_START:
      otherViewHovered = false;
      offButton.clearTracking();
      parentLayout.clearTracking();
      break;
    case AccessibilityEvent.TYPE_TOUCH_INTERACTION_END:
      if (offButton.didHoverEnter() && !parentLayout.didHoverEnter() && !otherViewHovered) {
        if (TalkBackService.getInstance() != null) {
          TalkBackService.getInstance().disableTalkBackFromTutorial((EventId) null);
        }
      }
      break;
    case AccessibilityEvent.TYPE_VIEW_HOVER_ENTER:
      CharSequence className = event.getClassName();
      // Hovering over the button gives an event with TUTORIAL_CLASS_NAME class.
      // But empty areas of the activity should be tracked by HoverTrackingLinearLayout.
      if (className == null || !className.equals(TUTORIAL_CLASS_NAME)) {
        otherViewHovered = true;
      }
      break;
    default: // fall out
  }
}
 
Example 8
Source File: TimeCatMonitorService.java    From timecat with Apache License 2.0 4 votes vote down vote up
private synchronized void getText(AccessibilityEvent event) {
        LogUtil.d(TAG, "getText:" + event);
        if (!monitorClick || event == null) {
            return;
        }
        if (showFloatView && !isRun) {
            return;
        }
        int type = getClickType(event);
        CharSequence className = event.getClassName();
        if (mWindowClassName == null) {
            return;
        }
        if (mWindowClassName.toString().startsWith("com.time.timecat")) {
            //自己的应用不监控
            return;
        }
        if (mCurrentPackage.equals(event.getPackageName())) {
            if (type != mCurrentType) {
                //点击方式不匹配,直接返回
                return;
            }
        } else {
            //包名不匹配,直接返回
            return;
        }
        if (className == null || className.equals("android.widget.EditText")) {
            //输入框不监控
            return;
        }
        if (onlyText) {
            //onlyText方式下,只获取TextView的内容
            if (!className.equals("android.widget.TextView")) {
                if (!hasShowTipToast) {
                    ToastUtil.i(R.string.toast_tip_content);
                    hasShowTipToast = true;
                }
                return;
            }
        }
        AccessibilityNodeInfo info = event.getSource();
        if (info == null) {
            return;
        }
        CharSequence txt = info.getText();
        if (TextUtils.isEmpty(txt) && !onlyText) {
            //非onlyText方式下获取文字更多,但是可能并不是想要的文字
            //比如系统短信页面需要这样才能获取到内容。
            List<CharSequence> txts = event.getText();
            if (txts != null) {
                StringBuilder sb = new StringBuilder();
                for (CharSequence t : txts) {
                    sb.append(t);
                }
                txt = sb.toString();
            }
        }
        if (!TextUtils.isEmpty(txt)) {
            if (txt.length() <= 2) {
                //对于太短的词进行屏蔽,因为这些词往往是“发送”等功能按钮,其实应该根据不同的activity进行区分
                if (!hasShowTooShortToast) {
                    ToastUtil.w(R.string.too_short_to_split);
                    hasShowTooShortToast = true;
                }
                return;
            }
            Intent intent = new Intent(this, TimeCatActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.putExtra(TimeCatActivity.TO_SPLIT_STR, txt.toString());
//            startActivity(intent);
            //放到ArcTipViewController中触发试试
            ArcTipViewController.getInstance().showTipViewForStartActivity(intent);
        }
    }
 
Example 9
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 10
Source File: Role.java    From talkback with Apache License 2.0 4 votes vote down vote up
/** Find role from source event's class name string. */
private static @RoleName int sourceClassNameToRole(AccessibilityEvent event) {
  if (event == null) {
    return ROLE_NONE;
  }

  // Event TYPE_NOTIFICATION_STATE_CHANGED always has null source node.
  CharSequence eventClassName = event.getClassName();

  // When comparing event.getClassName() to class name of standard widgets, we should take care of
  // the order of the "if" statements: check subclasses before checking superclasses.

  // Toast.TN is a private class, thus we have to hard code the class name.
  if (ClassLoadingCache.checkInstanceOf(eventClassName, "android.widget.Toast$TN")) {
    return ROLE_TOAST;
  }

  // Some events have different value for getClassName() and getSource().getClass()
  if (ClassLoadingCache.checkInstanceOf(eventClassName, android.app.ActionBar.Tab.class)) {
    return ROLE_ACTION_BAR_TAB;
  }

  // //////////////////////////////////////////////////////////////////////////////////////////
  // Subclasses of ViewGroup.

  // Inheritance: View->ViewGroup->DrawerLayout
  if (ClassLoadingCache.checkInstanceOf(
          eventClassName, androidx.drawerlayout.widget.DrawerLayout.class)
      || ClassLoadingCache.checkInstanceOf(
          eventClassName, "android.support.v4.widget.DrawerLayout")) {
    return ROLE_DRAWER_LAYOUT;
  }

  // Inheritance: View->ViewGroup->SlidingDrawer
  if (ClassLoadingCache.checkInstanceOf(eventClassName, android.widget.SlidingDrawer.class)) {
    return ROLE_SLIDING_DRAWER;
  }

  // Inheritance: View->ViewGroup->IconMenuView
  // IconMenuView is a hidden class, thus we have to hard code the class name.
  if (ClassLoadingCache.checkInstanceOf(
      eventClassName, "com.android.internal.view.menu.IconMenuView")) {
    return ROLE_ICON_MENU;
  }

  // Inheritance: View->ViewGroup->FrameLayout->DatePicker
  if (ClassLoadingCache.checkInstanceOf(eventClassName, android.widget.DatePicker.class)) {
    return ROLE_DATE_PICKER;
  }

  // Inheritance: View->ViewGroup->FrameLayout->TimePicker
  if (ClassLoadingCache.checkInstanceOf(eventClassName, android.widget.TimePicker.class)) {
    return ROLE_TIME_PICKER;
  }

  // Inheritance: View->ViewGroup->LinearLayout->NumberPicker
  if (ClassLoadingCache.checkInstanceOf(eventClassName, android.widget.NumberPicker.class)) {
    return ROLE_NUMBER_PICKER;
  }

  // //////////////////////////////////////////////////////////////////////////////////////////
  // Subclasses of Dialog.
  // Inheritance: Dialog->AlertDialog->DatePickerDialog
  if (ClassLoadingCache.checkInstanceOf(eventClassName, android.app.DatePickerDialog.class)) {
    return ROLE_DATE_PICKER_DIALOG;
  }

  // Inheritance: Dialog->AlertDialog->TimePickerDialog
  if (ClassLoadingCache.checkInstanceOf(eventClassName, android.app.TimePickerDialog.class)) {
    return ROLE_TIME_PICKER_DIALOG;
  }

  // Inheritance: Dialog->AlertDialog
  if (ClassLoadingCache.checkInstanceOf(eventClassName, android.app.AlertDialog.class)
      || ClassLoadingCache.checkInstanceOf(
          eventClassName, "androidx.appcompat.app.AlertDialog")) {
    return ROLE_ALERT_DIALOG;
  }

  return ROLE_NONE;
}
 
Example 11
Source File: WechatAccService.java    From RedEnvelopeAssistant with MIT License 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
	@Override
	public void onAccessibilityEvent(AccessibilityEvent event) {
		if (event == null)
			return;
		if(SettingHelper.getREAutoMode()){
			handleNotificationChange(event);
		}
		AccessibilityNodeInfo nodeInfo = event.getSource();
		if (nodeInfo == null) {
			return;
		}

		AccessibilityNodeInfo rowNode = nodeInfo;// we can also use getRootInActiveWindow() instead;
		if (rowNode == null) {
			log( "noteInfo is null");
			return;
		}

		LogUtil.d("eventtype:" + event.getEventType());
		
		// String currentActivityName =
		// ActivityHelper.getTopActivityName(RedEnvelopeApplication.getInstance());
		if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
				|| event.getEventType() == AccessibilityEvent.TYPE_VIEW_CLICKED) {
//		if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) {
			CharSequence currentClassName = event.getClassName();
			LogUtil.d("currentClassName:" + currentClassName);
			if ("com.tencent.mm.ui.LauncherUI".equals(currentClassName) || "com.tencent.mm.ui.chatting.ChattingUI".equals(currentClassName)) {
				// 聊天以及主页 chat page and the main page
				LogUtil.d("Chat page");
				if (SettingHelper.getREAutoMode()) {
					handleChatPage(rowNode);
				}
			} else if ("com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyReceiveUI".equals(currentClassName)) {
				//打开红包主页 red envelope open page
				LogUtil.d("LuckyMoneyReceiveUI page");
				if (SettingHelper.getREAutoMode()
						|| SettingHelper.getRESafeMode()){
					handleLuckyMoneyReceivePage(rowNode);
					if(SettingHelper.isRESound()){
						((RedEnvelopeApplication) RedEnvelopeApplication
								.getInstance()).getSoundHelper()
								.playSoundRedEnvelopeComing();
					}
				}
			} else if ("com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyDetailUI".equals(currentClassName)) {
				// 红包详情主页 red envelope detail page
				LogUtil.d("red envelope detail page");
				if (SettingHelper.getREAutoMode()){
					handleLuckyMoneyDetailPage(rowNode);
				}
			} else {
				log( currentClassName + " page");
			}
		}
	}