Example usage for android.view.accessibility AccessibilityEvent getPackageName

List of usage examples for android.view.accessibility AccessibilityEvent getPackageName

Introduction

In this page you can find the example usage for android.view.accessibility AccessibilityEvent getPackageName.

Prototype

public CharSequence getPackageName() 

Source Link

Document

Gets the package name of the source.

Usage

From source file:Main.java

/**
 * @return If the <code>first</code> event is equal to the <code>second</code>.
 *//*from ww  w. j  a  v a2s. c  o  m*/
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;
}

From source file:com.hrs.filltheform.service.ServiceEventResolver.java

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    if (APP_PACKAGE_NAME.equals(event.getPackageName())) {
        return;//w  w w.  j  av  a2  s. c  o  m
    } else if (ANDROID_SYSTEM_UI_PREFIX.equals(event.getPackageName())) {
        return;
    }

    String eventPackageName = null;

    for (int i = 0; i < configuration.getPackageNames().size(); i++) {
        if (event.getPackageName().equals(configuration.getPackageNames().get(i))) {
            eventPackageName = configuration.getPackageNames().get(i);
            break;
        }
    }

    if (eventPackageName == null) {
        return;
    }

    final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
    final AccessibilityNodeInfoCompat node = record.getSource();

    if (node == null) {
        return;
    }

    boolean found = false;
    for (int i = 0; i < configuration.getIdGroups().size(); i++) {
        String idGroupKey = configuration.getIdGroups().keyAt(i);
        String targetViewId = eventPackageName + ":id/" + idGroupKey;
        if (targetViewId.equals(node.getViewIdResourceName())) {
            found = true;
            notifyEventResolverListener(node, event, idGroupKey);
            break;
        } else {
            List<AccessibilityNodeInfoCompat> nodeInfoList = node
                    .findAccessibilityNodeInfosByViewId(targetViewId);
            if (nodeInfoList != null && nodeInfoList.size() > 0) {
                AccessibilityNodeInfoCompat nodeInfo = nodeInfoList.get(0);
                found = true;
                notifyEventResolverListener(nodeInfo, event, idGroupKey);
                break;
            }
        }
    }
    if (!found) {
        if (eventResolverListener != null) {
            eventResolverListener.onDataForSelectedNodeNotAvailable(node);
        }
    }
}

From source file:me.spadival.podmode.PodNotifyService.java

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {

    String notifyPackage = (String) event.getPackageName();

    if (!event.getClassName().equals(NOTIFICATION_CLASS))
        return;//from  w ww.j  av  a2 s .  c o  m

    if (notifyPackage.equals(SYSTEMUI_PACKAGE) || notifyPackage.equals(THIS_PACKAGE)
            || notifyPackage.equals(ANDROID_PACKAGE))
        return;

    PackageManager pm = getPackageManager();

    String notifyAppName = null;

    try {
        notifyAppName = (String) pm.getApplicationLabel(pm.getApplicationInfo(notifyPackage, 0));
    } catch (NameNotFoundException e1) {
        e1.printStackTrace();
    }

    if (notifyAppName == null)
        return;

    if (notifyPackage.equals(GMAPS_PACKAGE))
        notifyAppName = getString(R.string.nav_appname);

    if (notifyPackage.equals(GNOW_PACKAGE))
        notifyAppName = "Google Now";

    List<CharSequence> textList = event.getText();

    String notifyText = "";

    if (textList.size() > 0)
        notifyText = textList.get(0).toString();

    if (notifyText.equals("") || notifyPackage.equals(GMAIL_PACKAGE)) {
        Notification eventNotification = (Notification) event.getParcelableData();

        RemoteViews notifyView = eventNotification.contentView;
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        ViewGroup localView = null;
        try {
            localView = (ViewGroup) inflater.inflate(notifyView.getLayoutId(), null);
        } catch (Exception e) {
            //      e.printStackTrace();
            return;
        }

        try {

            notifyView.reapply(getApplicationContext(), localView);
        } catch (NotFoundException e) {
            //         e.printStackTrace();
        }

        View tv = localView.findViewById(android.R.id.title);
        if (tv != null && tv instanceof TextView) {
            if (notifyPackage.equals(GNOW_PACKAGE) || notifyPackage.equals(PANDORA_PACKAGE))
                notifyText = ((TextView) tv).getText().toString();
            else
                notifyAppName += ": " + ((TextView) tv).getText().toString();
        }

        if (!notifyPackage.equals(GNOW_PACKAGE)) {

            tv = localView.findViewById(16908358);
            if (tv != null && tv instanceof TextView)
                if (notifyPackage.equals(PANDORA_PACKAGE))
                    notifyAppName += ": " + ((TextView) tv).getText().toString();
                else
                    notifyText = (String) ((TextView) tv).getText().toString();
        }

        if (notifyPackage.equals(GMAIL_PACKAGE)) {
            tv = localView.findViewById(android.R.id.text2);
            if (tv != null && tv instanceof TextView)
                notifyText = (String) ((TextView) tv).getText().toString();
        }
    }

    Intent localIntent = new Intent(PodModeService.NOTIFYACTION);
    localIntent.putExtra("package", notifyPackage);
    localIntent.putExtra("appname", notifyAppName);
    localIntent.putExtra("text", notifyText);

    LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);

}

From source file:com.googlecode.eyesfree.brailleback.IMEHelper.java

private void checkIMEPicker(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
            && "android".equals(event.getPackageName())
            && "android.app.AlertDialog".equals(event.getClassName())) {
        AccessibilityNodeInfo node = event.getSource();
        if (node == null) {
            return;
        }/*from www . j  a va 2  s. c om*/
        String IMETitle = mContext.getString(R.string.braille_ime_name);
        List<AccessibilityNodeInfo> found = node.findAccessibilityNodeInfosByText(IMETitle);
        if (found.size() == 0) {
            return;
        }
        AccessibilityNodeInfo firstFound = found.get(0);
        AccessibilityNodeInfo toFocus = firstFound.getParent();
        if (toFocus != null) {
            toFocus.performAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
        }
    }
}

From source file:com.myStress.handlers.NotificationHandlerService.java

/**
 * Called when an accessibility event occurs - here, we check the particular component packages that fired the event, filtering out the ones we support
 * @param event Reference to the fired {android.view.accessibility.AccessibilityEvent}
 * @see android.accessibilityservice.AccessibilityService#onAccessibilityEvent(android.view.accessibility.AccessibilityEvent)
 *//*from ww w. jav a 2  s .c om*/
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    try {
        int eventType = event.getEventType();
        String packageName = event.getPackageName().toString();
        String className = event.getClassName().toString();

        if (eventType == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
            processNotification(event);
        } else if (eventType == AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED) {
            if (event.isPassword())
                return;

            String text = event.getText().toString();
            String beforeText = "";
            if (event.getBeforeText() != null)
                beforeText = event.getBeforeText().toString();
            text = text.substring(1, text.length() - 1);

            if (packageName.equals("com.whatsapp")) {
                if (wasending1 && text.length() == 1) {
                    wasending2 = true;
                    sendButtonClicked(packageName);
                }
            }
            //            else if(packageName.equals("com.facebook.orca")){
            //               wasending1 = false;
            //            }
            //            else if(packageName.equals("com.facebook.katana")){
            //               wasending1 = false;
            //            }
            //            else if(packageName.equals("com.android.email")){
            //               wasending1=false;
            //            }
            else {
                wasending1 = false;
                //               if(text.length() == 0){
                //                  sending = true;
                //                  sendButtonClicked(packageName);
                //               }
            }

            boolean del;
            int length_diff = text.length() - beforeText.length();
            typedText = text;

            if (length_diff == 1 && text.length() == 1) {
                typingStartTime = (double) System.currentTimeMillis();
                typingEndTime = typingStartTime;
            } else {
                typingEndTime = (double) System.currentTimeMillis();
            }

            if (text.length() < beforeText.length()) {
                del = true;
                length_diff = -length_diff;
            } else {
                del = false;
            }

            if (del == true) {
                Intent intent = new Intent("com.myStress.accessibility");
                intent.putExtra("KeyLogger", packageName + ":" + length_diff);
                sendBroadcast(intent);
            }
        } else if (eventType == AccessibilityEvent.TYPE_VIEW_CLICKED) {
            if (packageName.equals("com.whatsapp")) {
                if (className.equals("android.widget.ImageButton")) {
                    wasending1 = true;
                } else if (className.equals("com.whatsapp.EmojiPicker$EmojiImageView")) {
                    wasending1 = false;
                    wasending2 = false;
                } else if (className.equals("android.widget.ListView")
                        || className.equals("android.widget.ImageView"))
                    ;
                else {
                    if (wasending1)
                        wasending2 = true;
                    sendButtonClicked(packageName);
                }
            } else {
                if (wasending1) {
                    wasending2 = true;
                    sendButtonClicked(packageName);
                } else if (packageName.equals("com.facebook.orca")) {
                    if (event.getContentDescription() != null) {
                        if (event.getContentDescription().toString().toLowerCase().contains("send")) {
                            sending = true;
                            sendButtonClicked(packageName);
                        }
                    } else {
                        if (className.equals("com.facebook.orca.compose.ComposerButton")) {
                            sending = true;
                            sendButtonClicked(packageName);
                        }
                    }
                } else if (packageName.equals("com.facebook.katana")) {
                    if (event.getContentDescription() != null) {
                        if (event.getContentDescription().toString().toLowerCase().contains("post")) {
                            sending = true;
                            sendButtonClicked(packageName);
                        }
                    } else {
                        if (className.equals("com.facebook.widget.text.SimpleVariableTextLayoutView")) {
                            sending = true;
                            sendButtonClicked(packageName);
                        }
                    }
                } else if (packageName.toLowerCase().contains("mail")) {
                    if (event.getContentDescription() != null) {
                        if (event.getContentDescription().toString().toLowerCase().contains("send")) {
                            sending = true;
                            sendButtonClicked(packageName);
                        }
                    } else {
                        if (className.equals("android.widget.ImageButton")) {
                            if (!event.getText().toString().equals("")) {
                                sending = true;
                                sendButtonClicked(packageName);
                            }
                        }
                    }
                }
            }
        } else if (eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
            if (wasending1) {
                wasending2 = true;
                sendButtonClicked(packageName);
            }

            if (packageName.equals("com.android.mms")) {
                if (className.equals("android.app.ProgressDialog")) {
                    sending = true;
                    sendButtonClicked(packageName);
                }
            }
        }

        //reset variables
        sending = false;
    } catch (Exception e) {
    }
}

From source file:net.grayswander.rotationmanager.RotationManagerService.java

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {

    if (event == null) {
        debug("Null event");
        return;// ww w  .java 2s .  c o m
    }

    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {

        String package_name;
        String class_name;
        try {
            package_name = event.getPackageName().toString();
            class_name = event.getClassName().toString();
        } catch (Exception e) {
            debug("Unable to get component");
            return;
        }

        ComponentName componentName = new ComponentName(package_name, class_name);

        Log.d("Service",
                "Package: " + componentName.getPackageName() + " Class: " + componentName.getClassName());

        ActivityInfo activityInfo = tryGetActivity(componentName);
        boolean isActivity = activityInfo != null;
        if (!isActivity) {
            debug("Received event with NULL activity.");
            return;
        }

        debug("Received app " + package_name);

        if (package_name.equals(this.currentPackage)) {
            debug("App has not been changed");
            return;
        }

        debug("App has been changed");

        boolean is_rotation_enabled = this.getAutoOrientationEnabled();

        debug("Rotation: " + is_rotation_enabled);
        if (!appStartedFullScreen) {
            Log.d("Service", "Saving rotation settings, as fullscreen hack is inactive");
            if (is_rotation_enabled != this.lastSetRotation) {
                debug("Setting rotation " + is_rotation_enabled + " for " + this.currentPackage);
                this.configuration.setRotationSetting(this.currentPackage, is_rotation_enabled);
            }
        } else {
            Log.d("Service", "Not saving rotation settings, as fullscreen hack is active");
        }

        this.appStartedFullScreen = false;

        if (this.configuration.isForFullscreenWatcher(package_name)) {
            this.startFullscreenWatcher();
        } else {
            if (this.configuration.isForFullscreenWatcher(this.currentPackage)) {
                this.stopFullscreenWatcher();
            }
        }

        this.currentPackage = package_name;

        boolean app_rotation_setting = this.getAppRotationSetting(componentName);

        debug("Got rotation " + app_rotation_setting + " for " + package_name);

        if (is_rotation_enabled != app_rotation_setting) {
            debug("Setting rotation " + app_rotation_setting);
            this.setAutoOrientationEnabled(app_rotation_setting);
        }

    }

}

From source file:com.mattprecious.notisync.service.NotificationService.java

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    MyLog.d(TAG, "onAcessibilityEvent()");
    if (!Preferences.isPrimary(this)) {
        MyLog.d(TAG, "not primary mode");
        return;//  w w w .j  a  v a2s  . c  om
    }

    if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
        String packageName = (String) event.getPackageName();
        Notification notification = (Notification) event.getParcelableData();
        if (notification == null) {
            MyLog.d(TAG, "notification is null");
            return;
        }

        CharSequence tickerText = notification.tickerText;

        if (packageName == null) {
            return;
        }

        // handle gtalk messages
        if (gtalkPackageNames.contains(packageName)) {
            if (!Preferences.getPrimaryGtalkEnabled(this)) {
                return;
            }

            if (tickerText == null) {
                MyLog.e(TAG, "gtalk ticker text is null");
                return;
            }

            Matcher matcher = gtalkPattern.matcher(tickerText);
            if (matcher.matches()) {
                String sender = matcher.group(1);
                String message = matcher.group(2);

                GtalkMessage gtalkMessage = new GtalkMessage.Builder().sender(sender).message(message).build();

                sendMessage(gtalkMessage);
            } else {
                MyLog.d(TAG, "Pattern does not match: " + tickerText);
            }
            return;
        } else {
            dbAdapter.openReadable();
            PrimaryProfile profile = dbAdapter.getPrimaryProfileByPackage(packageName);
            dbAdapter.close();

            if (profile != null && profile.isEnabled()) {
                /*String message = notification.tickerText == null ? null
                      : notification.tickerText.toString();
                CustomMessage customMessage = new CustomMessage.Builder()
                .tag(profile.getTag())
                .appName(profile.getName())
                .messageTitle(message)
                .build();*/

                CustomMessage customMessage = getCustomMessage(profile, notification, packageName);

                sendMessage(customMessage);
            }
        }

        MyLog.d(TAG, "packageName: " + packageName);
    }

}

From source file:com.myStress.handlers.NotificationHandlerService.java

public void processNotification(AccessibilityEvent event) {
    // get notification shown
    Notification notification = (Notification) event.getParcelableData();

    if (notification != null) {
        // now broadcast the capturing of the accessibility service to the handler
        Intent intent = new Intent("com.myStress.accessibility");
        intent.putExtra("NotifyText", event.getPackageName());//::" + notification.tickerText);
        sendBroadcast(intent);/*from  w  w  w .j  av  a  2 s  .co m*/
    }
}

From source file:com.linroid.pushapp.service.ApkAutoInstallService.java

private void onProcessAccessibilityEvent(AccessibilityEvent event) {
    if (event.getSource() == null) {
        return;/*w w  w  .  j  a v  a2 s  . co  m*/
    }
    String packageName = event.getPackageName().toString();
    String className = event.getClassName().toString();
    String sourceText = event.getSource().getText() == null ? BuildConfig.VERSION_NAME
            : event.getSource().getText().toString().trim();
    if (packageName.equals(CLASS_NAME_PACKAGE_INSTALLER)
            || packageName.equals(CLASS_NAME_GOOGLE_PACKAGE_INSTALLER)) {
        if (isApplicationInstallEvent(event, className, sourceText)) {
            // 
            onApplicationInstall(event);
        } else if (hasAccessibilityNodeInfoByText(event,
                getString(R.string.str_accessibility_install_blocked))) {
            // 
            onApplicationInstall(event, false);
        } else if (isApplicationInstalledEvent(event, className, sourceText)) {
            // ?
            onApplicationInstalled(event);
        } else if (isApplicationInstallFailedEvent(event, className, sourceText)) {
            // 
            onInstallFail(event);
        } else if (className.equalsIgnoreCase(CLASS_NAME_APP_ALERT_DIALOG)) {
            // ??
            processAlertDialogEvent(event, className, sourceText);
        } else if (isApplicationUninstallEvent(event, className, sourceText)) {
            // ?
            onApplicationUninstall(event);
        } else if (isApplicationUninstalledEvent(event, className, sourceText)) {
            // ??
            onApplicationUninstalled(event);
        }
    } else if (packageName.equals(CLASS_NAME_LENOVO_SAFECENTER)) {
        processLenovoEvent(event, className, sourceText);
    }
}

From source file:com.ucmap.dingdinghelper.services.DingDingHelperAccessibilityService.java

/**
 * ???//from  w  ww  .  jav  a 2s. c om
 */
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    tag_callback_time = System.currentTimeMillis();
    int eventType = event.getEventType();

    Log.i("Info",
            " eventType: " + eventType + "   getEventTime:  " + event.getEventTime() + "     getAction"
                    + event.getAction() + "getContentChangeTypes:" + event.getContentChangeTypes()
                    + " getText :" + event.getText().toString() + "getPackageName :" + event.getPackageName()
                    + "getRecordCount : " + event.getRecordCount() + "  getClassName:" + event.getClassName()
                    + "  :" + event.getClass() + "   getParcelableData:" + event.getParcelableData());

    switch (eventType) {
    /*??*/
    case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED:
        windowContentChanged();
        break;
    //???
    case AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED:
        notificationChanged(event);
        break;
    //Activity???
    case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
        windowChanged(event);
        break;
    }
}