Esempio n. 1
0
    String toString(AccessibilityEvent event) {
      String str = "";
      str += "eventtype: " + AccessibilityEvent.eventTypeToString(event.getEventType());
      str += "\nsource: " + event.getSource();
      str += "\npackagename: " + event.getPackageName();
      str += "\nclassname: " + event.getClassName();

      return str;
    }
  @Override
  public void onAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() != AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) return;

    if (!Helper.GOOGLE_VOICE_PACKAGE.equals(event.getPackageName())) return;

    clearGoogleVoiceNotifications();

    startRefresh();
  }
Esempio n. 3
0
  @Override
  public void onAccessibilityEvent(AccessibilityEvent event) {
    // Load DrawerSettings pref data
    final boolean draweron =
        getSharedPreferences("pref", Context.MODE_PRIVATE).getBoolean("toggledata", true);

    // Load BlackList
    mHelper = new AppBlackListDBhelper(this);
    mCursor =
        mHelper
            .getWritableDatabase()
            .rawQuery("SELECT _ID, pkgname FROM appblacklist ORDER BY pkgname", null);

    List<String> array = new ArrayList<String>();
    while (mCursor.moveToNext()) {
      String uname = mCursor.getString(mCursor.getColumnIndex("pkgname"));
      array.add(uname);
    }
    mCursor.close();
    mHelper.close();

    Log.d("DBVALUES", array.toString());
    System.out.println("onAccessibilityEvent");
    if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
      System.out.println("notification: " + event.getText());

      String pkgnameforfilter = event.getPackageName().toString();
      String pkgitself = "com.simpleminds.popbell";

      // Filtering Package Name from Notification
      if (pkgnameforfilter.equals(pkgitself)) {
        // Do Nothing
        Log.d("SYSNOTIDETECTOR", "BLOCKED : PKG_ITSELF");
      } else if (array.toString().contains(pkgnameforfilter)) {
        // Do Nothing
        Log.d("SYSNOTIDETECTOR", "BLOCKED : PKG_BLACKLISTED");
      } else {
        try {
          // Get app name
          final PackageManager pm = getApplicationContext().getPackageManager();
          ApplicationInfo ai;
          try {
            ai = pm.getApplicationInfo((String) event.getPackageName().toString(), 0);
          } catch (final NameNotFoundException e) {
            ai = null;
          }
          final String applicationName =
              (String) (ai != null ? pm.getApplicationLabel(ai) : "(unknown)");

          // put values to db
          mHelper2 = new NotiListDBhelper(this);
          mCursor2 =
              mHelper2
                  .getWritableDatabase()
                  .rawQuery("SELECT _ID, title, desc FROM notilist ORDER BY title", null);
          ContentValues values = new ContentValues();
          values.put(NotiListDBhelper.TITLE, applicationName.toString());
          values.put(NotiListDBhelper.DESC, event.getText().toString());
          mHelper2.getWritableDatabase().insert("notilist", NotiListDBhelper.TITLE, values);
          mCursor2.requery();
          mCursor2.close();
          mHelper2.close();

          // Close and Open Dialog Window
          StandOutWindow.closeAll(this, DialogWindow.class);
          StandOutWindow.closeAll(this, TouchTrigger.class);
          StandOutWindow.show(this, DialogWindow.class, StandOutWindow.DEFAULT_ID);
          if (draweron) {
            StandOutWindow.show(this, TouchTrigger.class, StandOutWindow.DEFAULT_ID);
          } else {
          }

          // Create Bundle and put data
          Bundle dataBundle = new Bundle();
          // Get and Put Notification text
          dataBundle.putString("sysnotitext", event.getText().toString());
          // Put App Name
          dataBundle.putString("pkgname", event.getPackageName().toString());
          dataBundle.putParcelable("ParcelableData", event.getParcelableData());
          // Send data to DialogWindow
          StandOutWindow.sendData(
              this, DialogWindow.class, StandOutWindow.DEFAULT_ID, 1, dataBundle, null, 0);
          // Close DialogWindow in a few seconds
          mTask =
              new TimerTask() {
                @Override
                public void run() {
                  stopService(new Intent(NotiDetector.this, DialogWindow.class));
                  stopService(new Intent(NotiDetector.this, TouchTrigger.class));
                  StandOutWindow.closeAll(NotiDetector.this, DialogWindow.class);
                  StandOutWindow.closeAll(NotiDetector.this, TouchTrigger.class);
                }
              };
          mTimer = new Timer();
          mTimer.schedule(mTask, 5000);
        } catch (Exception e) {
          Log.e("SYSNOTIDETECTOR", "ERROR IN CODE:" + e.toString());
        }
      }
    }
  }
Esempio n. 4
0
    @Override
    public void onAccessibilityEvent(AccessibilityService service, AccessibilityEvent event) {

      Log.d(TAG, "event: " + event);
      //            Log.d(TAG, "event: " + toString(event));

      AccessibilityNodeInfo node = event.getSource();
      CharSequence packageName = event.getPackageName();
      int type = event.getEventType();
      int windowId = event.getWindowId();

      if (null == node) {
        Log.w(TAG, "node is null, ^~^");
        return;
      }

      if ("com.android.settings".equals(packageName)) {
        // http://stackoverflow.com/questions/3873659/android-how-can-i-get-the-current-foreground-activity-from-a-service
        if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
          mLastComponentName =
              new ComponentName(event.getPackageName().toString(), event.getClassName().toString());
          Log.i(TAG, "last activity: " + mLastComponentName);

          // from QueryController
          if (event.getText() != null && event.getText().size() > 0) {
            if (event.getText().get(0) != null) {
              String lastActivityName = event.getText().get(0).toString();
              //                            Log.i(TAG, "last activity name: " + lastActivityName);
            }
          }
        }

        if (AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED == type) {

          AccessibilityNodeInfo rootNode = node;
          rootNode = service.getRootInActiveWindow();

          List<AccessibilityNodeInfo> nodes =
              rootNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/dashboard");
          //                    nodes = rootNode.findAccessibilityNodeInfosByText("设置");
          boolean settingActivity = nodes != null && nodes.size() > 0;

          nodes = rootNode.findAccessibilityNodeInfosByText("开发者选项");
          boolean devActivity = nodes != null && nodes.size() == 1;

          settingActivity =
              new ComponentName("com.android.settings", "com.android.settings.Settings")
                  .equals(mLastComponentName);
          devActivity =
              new ComponentName("com.android.settings", "com.android.settings.SubSettings")
                  .equals(mLastComponentName);

          Log.d(TAG, "settingActivity: " + settingActivity + " devActivity: " + devActivity);
          if (settingActivity) {
            Log.d(TAG, "scroll to bottom");
            nodes =
                rootNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/dashboard");
            nodes.get(0).performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
            nodes.get(0).performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
            nodes.get(0).performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
            nodes.get(0).performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);

            nodes = rootNode.findAccessibilityNodeInfosByText("开发者选项");
            if (null != nodes && nodes.size() > 0) {
              Log.d(TAG, "open developer's setting");
              nodes.get(0).getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
            }
          } else if (devActivity) {
            nodes = rootNode.findAccessibilityNodeInfosByText("开启");

            AccessibilityNodeInfo open =
                AccessibilityNodeInfoFinder.find(rootNode, new UiSelector().text("开启"));
            Log.d(TAG, "open: " + open);
            open = open.getParent().getChild(1);
            if (!open.isChecked()) {
              //                            open.setChecked(true);
              open.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
            } else {
              Log.i(TAG, "adb is open yet.");
            }

            AccessibilityNodeInfo usb =
                AccessibilityNodeInfoFinder.find(rootNode, new UiSelector().text("USB调试"));
            if (null == usb) {
              AccessibilityNodeInfo listview =
                  AccessibilityNodeInfoFinder.find(
                      rootNode, new UiSelector().className("android.widget.ListView"));
              listview.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
            }
            usb = AccessibilityNodeInfoFinder.find(rootNode, new UiSelector().text("USB调试"));
            Log.i(TAG, "usb: " + usb);
            Log.i(TAG, "p: " + usb.getParent());
            Log.i(TAG, "pp: " + usb.getParent().getParent());
            AccessibilityNodeInfo debug = usb.getParent().getParent().getChild(1).getChild(0);
            Log.i(TAG, "debug: " + debug);

            debug =
                AccessibilityNodeInfoFinder.find(
                    rootNode,
                    new UiSelector()
                        .className("android.widget.Switch")
                        .fromParent(new UiSelector().className("android.widget.LinearLayout")));
            Log.i(TAG, "debug: " + debug);

            usb = AccessibilityNodeInfoFinder.find(rootNode, new UiSelector().text("调试"));
            int index = 0;
            for (int i = 0; i < usb.getParent().getChildCount(); i++) {
              if ("调试".equals(usb.getParent().getChild(i).getText())) {
                index = i;
                break;
              }
            }
            usb = usb.getParent().getChild(index + 1);
            Log.i(TAG, "debug: " + debug);

            //                        if (!debug.isChecked()) {
            //                            debug.performAction(AccessibilityNodeInfo.ACTION_CLICK);
            //                        } else {
            //                            Log.i(TAG, "adb debug is open yet.");
            //                        }

            //                        if (null != nodes && nodes.size() > 0) {
            //                            Log.d(TAG, nodes.size() + " node found.");
            //                            Log.d(TAG, "open developer's option");
            //
            // nodes.get(0).getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
            //                        } else {
            //                            return;
            //                        }
          }
        }
      }

      //        node.recycle();
    }
Esempio n. 5
0
    @Override
    public void onAccessibilityEvent(AccessibilityService service, AccessibilityEvent event) {

      Log.d(TAG, "event: " + event);
      //            Log.d(TAG, "event: " + toString(event));

      AccessibilityNodeInfo node = event.getSource();
      CharSequence packageName = event.getPackageName();
      int type = event.getEventType();
      int windowId = event.getWindowId();

      if (null == node) {
        Log.w(TAG, "node is null, ^~^");
        return;
      }

      if ("com.android.settings".equals(packageName)) {
        // http://stackoverflow.com/questions/3873659/android-how-can-i-get-the-current-foreground-activity-from-a-service
        if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
          mLastComponentName =
              new ComponentName(event.getPackageName().toString(), event.getClassName().toString());
          Log.i(TAG, "last activity: " + mLastComponentName);

          // from QueryController
          if (event.getText() != null && event.getText().size() > 0) {
            if (event.getText().get(0) != null) {
              String lastActivityName = event.getText().get(0).toString();
              //                            Log.i(TAG, "last activity name: " + lastActivityName);
            }
          }

          boolean appDetail =
              new ComponentName(
                      "com.android.settings",
                      "com.android.settings.applications.InstalledAppDetailsTop")
                  .equals(mLastComponentName);
          boolean stopConfirm =
              new ComponentName("com.android.settings", "android.app.AlertDialog")
                  .equals(mLastComponentName);
          Log.d(TAG, "appDetail: " + appDetail + " stopConfirm: " + stopConfirm);
          if (appDetail) {
            AccessibilityNodeInfo stop =
                AccessibilityNodeInfoFinder.find(
                    service.getRootInActiveWindow(), new UiSelector().text("强行停止"));
            if (stop.isEnabled()) {
              stop.performAction(AccessibilityNodeInfo.ACTION_CLICK);
            } else {
              Log.i(TAG, "app has stop yet.");
            }
          }
          if (stopConfirm) {
            AccessibilityNodeInfo confirm =
                AccessibilityNodeInfoFinder.find(
                    service.getRootInActiveWindow(), new UiSelector().text("确定"));
            confirm.performAction(AccessibilityNodeInfo.ACTION_CLICK);

            Intent self = new Intent(service, MainActivity.class);
            self.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            service.startActivity(self);
          }
        }
      }
    }