Example #1
0
  // BEGIN_INCLUDE (on_populate_accessibility_event)
  @Override
  @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
  public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
    super.onPopulateAccessibilityEvent(event);

    // Detect what type of accessibility event is being passed in.
    int eventType = event.getEventType();

    // Common case: The user has interacted with our view in some way. State may or may not
    // have been changed. Read out the current status of the view.
    //
    // We also set some other metadata which is not used by TalkBack, but could be used by
    // other TTS engines.
    if (eventType == AccessibilityEvent.TYPE_VIEW_SELECTED
        || eventType == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) {
      event.getText().add("Mode selected: " + Integer.toString(mActiveSelection + 1) + ".");
      event.setItemCount(SELECTION_COUNT);
      event.setCurrentItemIndex(mActiveSelection);
    }

    // When a user first focuses on our view, we'll also read out some simple instructions to
    // make it clear that this is an interactive element.
    if (eventType == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) {
      event.getText().add("Tap to change.");
    }
  }
 public void onInitializeAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
   super.onInitializeAccessibilityEvent(accessibilityEvent);
   if (accessibilityEvent.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED) {
     accessibilityEvent.setFromIndex(0);
     accessibilityEvent.setToIndex(0);
   }
 }
Example #3
0
  @Override
  public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    boolean populated = false;
    // This is an exceptional case which occurs when a window gets the
    // focus and sends a focus event via its focused child to announce
    // current focus/selection. CarouselAdapter fires selection but not focus
    // events so we change the event type here.
    if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) {
      event.setEventType(AccessibilityEvent.TYPE_VIEW_SELECTED);
    }

    // we send selection events only from CarouselAdapter to avoid
    // generation of such event for each child
    View selectedView = getSelectedView();
    if (selectedView != null) {
      populated = selectedView.dispatchPopulateAccessibilityEvent(event);
    }

    if (!populated) {
      if (selectedView != null) {
        event.setEnabled(selectedView.isEnabled());
      }
      event.setItemCount(getCount());
      event.setCurrentItemIndex(getSelectedItemPosition());
    }

    return populated;
  }
Example #4
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 onInitializeAccessibilityEvent(AccessibilityEvent event) {
    super.onInitializeAccessibilityEvent(event);

    if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED) {
      event.setFromIndex(0);
      event.setToIndex(0);
    }
  }
Example #6
0
        @Override
        public boolean onRequestSendAccessibilityEvent(
            ViewGroup host, View child, AccessibilityEvent event) {
          if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED) {
            return false;
          }

          return super.onRequestSendAccessibilityEvent(host, child, event);
        }
  @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();
  }
 public void onInitializeAccessibilityEvent(
     View paramView, AccessibilityEvent paramAccessibilityEvent) {
   super.onInitializeAccessibilityEvent(paramView, paramAccessibilityEvent);
   paramAccessibilityEvent.setClassName(ViewPager.class.getName());
   paramView = android.support.v4.view.a.a.a(paramAccessibilityEvent);
   paramView.a(a());
   if ((paramAccessibilityEvent.getEventType() == 4096) && (ViewPager.access$200(a) != null)) {
     paramView.a(ViewPager.access$200(a).getCount());
     paramView.b(ViewPager.access$300(a));
     paramView.c(ViewPager.access$300(a));
   }
 }
Example #9
0
 @Override
 public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
   super.onPopulateAccessibilityEvent(host, event);
   if (sEventMessage != null) {
     populateEventFromJSON(event, sEventMessage);
     // No matter where the a11y focus is requested, we always force it back to the current vc
     // position.
     event.setSource(host, VIRTUAL_CURSOR_POSITION);
   }
   // We save the hover enter event so that we could reuse it for a subsequent accessibility
   // focus event.
   if (event.getEventType() != AccessibilityEvent.TYPE_VIEW_HOVER_ENTER) sEventMessage = null;
 }
Example #10
0
  public void dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
      dispatchPopulateAccessibilityEvent(event, mPrimaryName);
      dispatchPopulateAccessibilityEvent(event, mPhoneNumber);
      return;
    }
    dispatchPopulateAccessibilityEvent(event, mCallStateLabel);
    dispatchPopulateAccessibilityEvent(event, mPrimaryName);
    dispatchPopulateAccessibilityEvent(event, mPhoneNumber);
    dispatchPopulateAccessibilityEvent(event, mCallTypeLabel);
    dispatchPopulateAccessibilityEvent(event, mSecondaryCallName);

    return;
  }
 @Override
 public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
   if (Build.VERSION.SDK_INT >= 14) {
     if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
       // Action mode started
       event.setSource(this);
       event.setClassName(getClass().getName());
       event.setPackageName(getContext().getPackageName());
       event.setContentDescription(mTitle);
     } else {
       super.onInitializeAccessibilityEvent(event);
     }
   }
 }
  /** Announce the currently-selected date when launched. */
  @Override
  public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
      // Clear the event's current text so that only the current date will be spoken.
      event.getText().clear();
      int flags =
          DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_WEEKDAY;

      String dateString = DateUtils.formatDateTime(getContext(), mDateMillis, flags);
      event.getText().add(dateString);
      return true;
    }
    return super.dispatchPopulateAccessibilityEvent(event);
  }
Example #13
0
 public final boolean dispatchPopulateAccessibilityEvent(
     View view, AccessibilityEvent accessibilityevent) {
   if (accessibilityevent.getEventType() == 32) {
     view = accessibilityevent.getText();
     accessibilityevent = FixedDrawerLayout.a(a);
     if (accessibilityevent != null) {
       int i = a.c(accessibilityevent);
       accessibilityevent = a.a(i);
       if (accessibilityevent != null) {
         view.add(accessibilityevent);
       }
     }
     return true;
   } else {
     return super.dispatchPopulateAccessibilityEvent(view, accessibilityevent);
   }
 }
 /** Announce the currently-selected time when launched. */
 @Override
 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
   if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
     // Clear the event's current text so that only the current time will be spoken.
     event.getText().clear();
     Time time = new Time();
     time.hour = getHours();
     time.minute = getMinutes();
     long millis = time.normalize(true);
     int flags = DateUtils.FORMAT_SHOW_TIME;
     if (mIs24HourMode) {
       flags |= DateUtils.FORMAT_24HOUR;
     }
     String timeString = DateUtils.formatDateTime(getContext(), millis, flags);
     event.getText().add(timeString);
     return true;
   }
   return super.dispatchPopulateAccessibilityEvent(event);
 }
  @Override
  public void onReceiveJob(AccessibilityEvent event) {
    final int eventType = event.getEventType();

    // 通知栏事件
    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(HONGBAO_TEXT_KEY)) {
            openNotify(event);
            break;
          }
        }
      }
    } else if (eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
      openHongBao(event);
    }
  }
Example #16
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();
    }
Example #17
0
 /** Called so we can avoid detecting screen touches as side taps. */
 public void onAccessibilityEvent(AccessibilityEvent event) {
   if (event.getEventType() == AccessibilityEventCompat.TYPE_TOUCH_INTERACTION_START) {
     mLastTouchTime = System.nanoTime();
   }
 }
  @SuppressLint("NewApi")
  @Override
  public void onAccessibilityEvent(AccessibilityEvent event) {
    // TODO Auto-generated method stub
    int eventType = event.getEventType();
    // AccessibilityNodeInfo my = event.getSource();
    AccessibilityNodeInfo rowNode = getRootInActiveWindow();
    if (rowNode == null) {
      log("noteInfo is null", 1);
      return;
    } else {
      log("class=" + event.getClassName().toString(), 1);
      // List<AccessibilityNodeInfo> nodeInfos = rowNode
      // .findAccessibilityNodeInfosByText("稍后再说");
      // for (AccessibilityNodeInfo nodeInfo : nodeInfos) {
      // nodeInfo.performAction(AccessibilityNodeInfo.ACTION_CLICK);
      // }
      recycle(rowNode);
    }
    String eventText = "";
    if (mTeamViewData.pidId == 0) {
      getProcessPid();
    }
    log("==============Start====================", 1);
    switch (eventType) {
      case AccessibilityEvent.TYPE_VIEW_CLICKED:
        eventText = "TYPE_VIEW_CLICKED";
        break;
      case AccessibilityEvent.TYPE_VIEW_FOCUSED:
        eventText = "TYPE_VIEW_FOCUSED";
        break;
      case AccessibilityEvent.TYPE_VIEW_LONG_CLICKED:
        eventText = "TYPE_VIEW_LONG_CLICKED";
        break;
      case AccessibilityEvent.TYPE_VIEW_SELECTED:
        eventText = "TYPE_VIEW_SELECTED";
        break;
      case AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED:
        eventText = "TYPE_VIEW_TEXT_CHANGED";
        break;
      case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
        eventText = "TYPE_WINDOW_STATE_CHANGED";
        if (event.getClassName().toString().equals(MAIN_ACTIVITY)) {
          int hash = findIDTextView(rowNode);
          if (hash != 0) {
            log("have hash success=" + mTeamViewData.mIdTextHash);
            state = STATE_ACTIVATIONING;
          }
        }
        if (event.getClassName().toString().equals(GET_UID_PC)) {
          if (ReadyPCID(rowNode)) {
            log("have pcid success=" + mTeamViewData.mPCIDTEXT);
            // state = STATE_PC_ID_SUCCESS;
            RequestParams params = new RequestParams(UrlData.URL_CHECK_ID);
            params.addBodyParameter("授权用户", UrlData.ADMIN_UID);
            params.addBodyParameter("密码", UrlData.ADMIN_PASSWORD);
            params.addBodyParameter("用户ID", mTeamViewData.mPCIDTEXT);
            params.addBodyParameter("设备ID", mTeamViewData.mIdText);
            log("用户ID=" + mTeamViewData.mPCIDTEXT + ";设备ID=" + mTeamViewData.mIdText);
            x.http()
                .post(
                    params,
                    new Callback.CommonCallback<String>() {
                      @Override
                      public void onSuccess(String result) {
                        log("success");
                        InputStream sbs = new ByteArrayInputStream(result.getBytes());
                        try {
                          String response = XMLParse.parseResponseCheck(sbs);
                          log("response=" + response);
                          if (!response.equals("失败")) {
                            mTeamViewData.BEGIN_TIME = WatchService.toTime2(response);
                            log("mTeamViewData.BEGIN_TIME=" + mTeamViewData.BEGIN_TIME);
                            // 写开始时间
                            handler.removeMessages(BEGIN_BEGIN);
                            handler.sendEmptyMessage(BEGIN_BEGIN);
                          } else {
                            if (mTeamViewData.rejectButton != null) {
                              mTeamViewData.rejectButton.performAction(
                                  AccessibilityNodeInfo.ACTION_CLICK);
                              // state = STATE_REJECT;
                              Message msg = new Message();
                              msg.what = UPDATE_ZHUANGTAI;
                              msg.obj = (String) "空闲";
                              handler.removeMessages(UPDATE_ZHUANGTAI);
                              handler.sendMessage(msg);
                            } else {
                              log("rejectButton==null");
                            }
                          }
                        } catch (Exception e) {
                          log(e.getMessage());
                        }
                      }

                      @Override
                      public void onError(Throwable ex, boolean isOnCallback) {
                        log("error" + ex.getMessage());
                        Toast.makeText(x.app(), ex.getMessage(), Toast.LENGTH_LONG).show();
                      }

                      @Override
                      public void onCancelled(CancelledException cex) {
                        Toast.makeText(x.app(), "cancelled", Toast.LENGTH_LONG).show();
                      }

                      @Override
                      public void onFinished() {}
                    });
          }
        }
        break;
      case AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED:
        eventText = "TYPE_NOTIFICATION_STATE_CHANGED";
        Notification notification = (Notification) event.getParcelableData();
        List<String> textList = getText(notification);
        if (null != textList && textList.size() > 0) {
          for (String text : textList) {
            if (!TextUtils.isEmpty(text)) {
              log("Notification=" + text);
            }
            if (!TextUtils.isEmpty(text) && text.contains("会话已结束")) {
              log("会话已结束Service");
              handler.removeMessages(SHUT_DOWN_CONNECTION);
              handler.sendEmptyMessage(SHUT_DOWN_CONNECTION);
              break;
            }
          }
        }
        break;
      case AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_END:
        eventText = "TYPE_TOUCH_EXPLORATION_GESTURE_END";
        break;
      case AccessibilityEvent.TYPE_ANNOUNCEMENT:
        eventText = "TYPE_ANNOUNCEMENT";
        break;
      case AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_START:
        eventText = "TYPE_TOUCH_EXPLORATION_GESTURE_START";
        break;
      case AccessibilityEvent.TYPE_VIEW_HOVER_ENTER:
        eventText = "TYPE_VIEW_HOVER_ENTER";
        break;
      case AccessibilityEvent.TYPE_VIEW_HOVER_EXIT:
        eventText = "TYPE_VIEW_HOVER_EXIT";
        break;
      case AccessibilityEvent.TYPE_VIEW_SCROLLED:
        eventText = "TYPE_VIEW_SCROLLED";
        break;
      case AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED:
        eventText = "TYPE_VIEW_TEXT_SELECTION_CHANGED";
        break;
      case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED:
        eventText = "TYPE_WINDOW_CONTENT_CHANGED";
        log("event.getClassName().toString()=" + event.getClassName().toString());
        if (event.getClassName().toString().equals(GET_ID_CLASS)
            || event.getClassName().toString().equals(FRAMELAYOUT)
            || event.getClassName().toString().equals("android.widget.EditText")) {
          // if (mTeamViewData.mIdText.equals("")) {// 为空才判断
          if (ReadyID(rowNode)) {
            state = STATE_GET_ID_SUCCESS;
            log("have id success=" + mTeamViewData.mIdText);
            User user = new User();
            user.setmIdText(mTeamViewData.mIdText);
            Dbmanager.saveUser(user);
          }
          // }
        }
        if (event.getClassName().toString().equals("android.widget.FrameLayout")
            || event.getClassName().toString().equals(GET_ID_CLASS)) {
          if (state == STATE_ALLOW) {
            log("connection ing");
            if (ReadyLoad(rowNode)) // 连接成功
            {}
          }
        }
        break;
    }
    eventText = eventText + ":" + eventType;
    log(eventText, 1);
    log("=============END=====================", 1);
  }
Example #19
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());
        }
      }
    }
  }
Example #20
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);
          }
        }
      }
    }