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

The following examples show how to use android.view.accessibility.AccessibilityEvent#getEventType() . 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: DefaultNavigationMode.java    From brailleback with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onAccessibilityEvent(AccessibilityEvent event) {
    switch (event.getEventType()) {
        case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED:
            brailleNodeFromEvent(event);
            break;
        case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED:
            brailleFocusedNode();
            break;
        case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
            if (!brailleFocusedNode()) {
                // Since focus is typically not set in a newly opened
                // window, so braille the window as-if the first focusable
                // node had focus.  We don't update the focus because that
                // will make other services (e.g. talkback) reflect this
                // change, which is not desired.
                brailleFirstFocusableNode();
            }
            break;
    }
    return true;
}
 
Example 2
Source File: WASenderAccSvc.java    From WhatsApp-Bulk-Sender with MIT License 6 votes vote down vote up
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    if (!PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("running", false)) {
        return;
    }
    if (AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED == event.getEventType()) {
        String actname = event.getClassName().toString();
        if (actname.equals("com.whatsapp.Conversation")) {
            List<AccessibilityNodeInfo> nodes = getRootInActiveWindow().findAccessibilityNodeInfosByViewId("com.whatsapp:id/send");
            if (nodes.size()>0) {
                nodes.get(0).performAction(ACTION_CLICK);
            }
            performGlobalAction(GLOBAL_ACTION_BACK);
        } else if (actname.equals("com.whatsapp.HomeActivity")) {
            sendNext();
        } else if (actname.equals("com.whatsapp.ContactPicker")) {
            Toast.makeText(this,"Unable to find contacts in your list! Skipping!!!", Toast.LENGTH_SHORT).show();
            performGlobalAction(GLOBAL_ACTION_BACK);
        }
    }
}
 
Example 3
Source File: SearchNavigationMode.java    From brailleback with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onAccessibilityEvent(AccessibilityEvent event) {
    switch (event.getEventType()) {
        case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED:
            DisplayManager.Content content = formatEventToBraille(event);
            if (content != null) {
                mDisplayManager.setContent(content);
            }
            return true;
        case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
            finishSearch();
            // Let it fall through so other navigation mode can
            // receive the window_state_changed event.
            return false;
        case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED:
            // This will re-evaluate the search and refocus if necessary.
            mMatchedNode.reset(AccessibilityNodeInfoUtils.refreshNode(
                    mMatchedNode.get()));
            evaluateSearch();
            return true;
    }
    // Don't let fall through.
    return true;
}
 
Example 4
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 5
Source File: fool.java    From styT with Apache License 2.0 6 votes vote down vote up
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    AccessibilityNodeInfo nodeInfo = event.getSource();
    if (nodeInfo != null) {
        int eventType = event.getEventType();
        if (eventType== AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED ||
                eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
            if (handledMap.get(event.getWindowId()) == null) {
                boolean handled = iterateNodesAndHandle(nodeInfo);
                if (handled) {
                    handledMap.put(event.getWindowId(), true);
                }
            }
        }
    }
}
 
Example 6
Source File: CustomViewPager.java    From AsteroidOSSync with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    // Dispatch scroll events from this ViewPager.
    if (event.getEventType() == AccessibilityEventCompat.TYPE_VIEW_SCROLLED) {
        return super.dispatchPopulateAccessibilityEvent(event);
    }

    // Dispatch all other accessibility events from the current page.
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() == VISIBLE) {
            final ItemInfo ii = infoForChild(child);
            if (ii != null && ii.position == mCurItem
                    && child.dispatchPopulateAccessibilityEvent(event)) {
                return true;
            }
        }
    }

    return false;
}
 
Example 7
Source File: AccessibilityFocusManager.java    From talkback with Apache License 2.0 6 votes vote down vote up
/** Called by EventFilter. */
@Nullable
@Override
public AccessibilityFocusEventInterpretation interpret(AccessibilityEvent event) {
  FocusActionInfo info = getFocusActionInfoFromEvent(event);
  if (info == null) {
    return null;
  }
  AccessibilityFocusEventInterpretation interpretation =
      new AccessibilityFocusEventInterpretation(event.getEventType());
  interpretation.setForceFeedbackAudioPlaybackActive(info.isForcedFeedbackAudioPlaybackActive());
  interpretation.setForceFeedbackMicrophoneActive(info.isForcedFeedbackMicrophoneActive());
  interpretation.setForceFeedbackSsbActive(info.isForcedFeedbackSsbActive());
  interpretation.setShouldMuteFeedback(info.forceMuteFeedback);
  interpretation.setIsInitialFocusAfterScreenStateChange(
      info.sourceAction == FocusActionInfo.SCREEN_STATE_CHANGE);
  return interpretation;
}
 
Example 8
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 9
Source File: TextCursorManager.java    From talkback with Apache License 2.0 5 votes vote down vote up
@Override
public void onAccessibilityEvent(AccessibilityEvent event, EventId eventId) {
  if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED) {
    processTextSelectionChange(event);
  } else if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) {
    processViewInputFocused(event);
  }
}
 
Example 10
Source File: AccessibilityEventUtils.java    From talkback with Apache License 2.0 5 votes vote down vote up
/** Returns whether the {@link AccessibilityEvent} contains {@link Notification} data. */
public static boolean isNotificationEvent(AccessibilityEvent event) {
  // Real notification events always have parcelable data.
  return event != null
      && event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED
      && event.getParcelableData() != null;
}
 
Example 11
Source File: ViewPager.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
    super.onInitializeAccessibilityEvent(host, event);
    event.setClassName(ViewPager.class.getName());
    final AccessibilityRecordCompat recordCompat = AccessibilityRecordCompat.obtain();
    recordCompat.setScrollable(canScroll());
    if (event.getEventType() == AccessibilityEventCompat.TYPE_VIEW_SCROLLED
            && mAdapter != null) {
        recordCompat.setItemCount(mAdapter.getCount());
        recordCompat.setFromIndex(mCurItem);
        recordCompat.setToIndex(mCurItem);
    }
}
 
Example 12
Source File: MD5_jni.java    From stynico with MIT License 5 votes vote down vote up
@Override
public void onAccessibilityEvent(AccessibilityEvent event)
{
	final int eventType = event.getEventType(); // ClassName:
	// com.tencent.mm.ui.LauncherUI

	// 通知栏事件
	if (eventType == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED)
	{
		List<CharSequence> texts = event.getText();
		if (!texts.isEmpty())
		{
			for (CharSequence t : texts)
			{
				String text = String.valueOf(t);
				if (text.contains(WX_HONGBAO_TEXT_KEY) || text.contains(QQ_HONGBAO_TEXT_KEY))
				{
					openNotify(event);
					break;
				}
			}
		}
	} else if (eventType == AccessibilityEvent.CONTENT_CHANGE_TYPE_SUBTREE)
	{
		// 从微信主界面进入聊天界面
		openHongBao(event);
	} else if (eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED)
	{
		// 处理微信聊天界面
		openHongBao(event);
	}
}
 
Example 13
Source File: DropdownMenuEndIconDelegate.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onPopulateAccessibilityEvent(View host, @NonNull AccessibilityEvent event) {
  super.onPopulateAccessibilityEvent(host, event);
  AutoCompleteTextView editText =
      castAutoCompleteTextViewOrThrow(textInputLayout.getEditText());

  if (event.getEventType() == TYPE_VIEW_CLICKED
      && accessibilityManager.isTouchExplorationEnabled()) {
    showHideDropdown(editText);
  }
}
 
Example 14
Source File: NotificationListener.java    From appium-uiautomator2-server with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void onAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
        Logger.debug("Catch toast message: " + event);
        List<CharSequence> text = event.getText();
        if (text != null && !text.isEmpty()) {
            setToastMessage(text);
        }
    }

    if (originalListener != null) {
        originalListener.onAccessibilityEvent(event);
    }
}
 
Example 15
Source File: IMENavigationMode.java    From brailleback with Apache License 2.0 5 votes vote down vote up
@Override
public void onObserveAccessibilityEvent(AccessibilityEvent event) {
    if ((event.getEventType() & UPDATE_STATE_EVENT_MASK) != 0) {
        updateState();
    }
    mNext.onObserveAccessibilityEvent(event);
}
 
Example 16
Source File: ViewPagerEx.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
    super.onInitializeAccessibilityEvent(host, event);
    event.setClassName(ViewPagerEx.class.getName());
    final AccessibilityRecordCompat recordCompat = AccessibilityRecordCompat.obtain();
    recordCompat.setScrollable(canScroll());
    if (event.getEventType() == AccessibilityEventCompat.TYPE_VIEW_SCROLLED
            && mAdapter != null) {
        recordCompat.setItemCount(mAdapter.getCount());
        recordCompat.setFromIndex(mCurItem);
        recordCompat.setToIndex(mCurItem);
    }
}
 
Example 17
Source File: AccessibilityEventProcessor.java    From talkback with Apache License 2.0 4 votes vote down vote up
public void onAccessibilityEvent(AccessibilityEvent event, EventId eventId) {

    if (testingListener != null) {
      testingListener.onAccessibilityEvent(event);
    }

    if ((dumpEventMask & event.getEventType()) != 0) {
      LogUtils.v(TAG, DUMP_EVENT_LOG_FORMAT, event);
    }

    if (shouldDropRefocusEvent(event)) {
      return;
    }

    if (shouldDropEvent(event)) {
      return;
    }

    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
      lastWindowStateChanged = SystemClock.uptimeMillis();
    }

    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED
        || event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
        || event.getEventType() == AccessibilityEvent.TYPE_WINDOWS_CHANGED) {
      service.setRootDirty(true);
    }

    // We need to save the last focused event so that we can filter out related selected events.
    if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) {
      if (lastFocusedEvent != null) {
        lastFocusedEvent.recycle();
      }

      lastFocusedEvent = AccessibilityEvent.obtain(event);
    }

    if (AccessibilityEventUtils.eventMatchesAnyType(event, MASK_DELAYED_EVENT_TYPES)) {
      handler.postProcessEvent(event, eventId);
    } else {
      processEvent(event, eventId);
    }

    if (testingListener != null) {
      testingListener.afterAccessibilityEvent(event);
    }
  }
 
Example 18
Source File: ScrollEventInterpreter.java    From talkback with Apache License 2.0 4 votes vote down vote up
private ScrollEventInterpretation interpret(AccessibilityEvent event) {
  AccessibilityNodeInfo sourceNode = event.getSource();
  if (sourceNode == null) {
    return ScrollEventInterpretation.DEFAULT_INTERPRETATION;
  }

  // . We get scroll position WINDOW_CONTENT_CHANGED events to provide more fine-grained
  // scroll action detection. We need to carefully handle these events. Event if the position
  // changes, it might not result from scroll action. We need a solid strategy to protect against
  // this issue. It's difficult. The least effort we can do is to filter out non-scrollable node.
  if ((event.getEventType() == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED)
      && !AccessibilityNodeInfoUtils.isScrollable(AccessibilityNodeInfoCompat.wrap(sourceNode))) {
    return ScrollEventInterpretation.DEFAULT_INTERPRETATION;
  }

  final NodeIdentifier sourceNodeIdentifier = new NodeIdentifier(sourceNode);
  AccessibilityNodeInfoUtils.recycleNodes(sourceNode);

  @SearchDirectionOrUnknown
  final int scrollDirection = getScrollDirection(sourceNodeIdentifier, event);
  @UserAction final int userAction;
  final int scrollInstanceId;

  @Nullable AutoScrollRecord autoScrollRecord = isFromAutoScrollAction(event);
  if (autoScrollRecord == null) {
    scrollInstanceId = SCROLL_INSTANCE_ID_UNDEFINED;
    // Note that TYPE_WINDOW_CONTENT_CHANGED events can also be interpreted as manual scroll
    // action. TYPE_VIEW_SCROLLED events are filed at very coarse granularity. If we rely only on
    // TYPE_VIEW_SCROLLED events to detect manual scroll action, it happens when the user slightly
    // scroll a list and accessibility focus goes off screen, we don't receive
    // TYPE_VIEW_SCROLLED event thus we don't update accessibility focus. If user performs linear
    // navigation after that, accessibility focus might go to the beginning of screen.
    // We take into account TYPE_WINDOW_CONTENT_CHANGED events to provide more
    // fine-grained manual scroll callback.
    userAction =
        scrollDirection == TraversalStrategy.SEARCH_FOCUS_UNKNOWN
            ? ACTION_UNKNOWN
            : ACTION_MANUAL_SCROLL;
  } else {
    scrollInstanceId = autoScrollRecord.scrollInstanceId;
    userAction = autoScrollRecord.userAction;
  }

  final boolean hasValidIndex = hasValidIndex(event);
  final boolean isDuplicateEvent = hasValidIndex && isDuplicateEvent(sourceNodeIdentifier, event);

  return new ScrollEventInterpretation(
      userAction, scrollDirection, hasValidIndex, isDuplicateEvent, scrollInstanceId);
}
 
Example 19
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;
    }
}