Beispiel #1
0
 @Override
 protected void onServiceConnected() {
   System.out.println("onServiceConnected");
   AccessibilityServiceInfo info = new AccessibilityServiceInfo();
   info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED;
   info.notificationTimeout = 100;
   info.feedbackType = AccessibilityEvent.TYPES_ALL_MASK;
   setServiceInfo(info);
 }
 /**
  * Returns the {@link ServiceInfo}s of the installed accessibility services.
  *
  * @return An unmodifiable list with {@link ServiceInfo}s.
  * @deprecated Use {@link #getInstalledAccessibilityServiceList()}
  */
 @Deprecated
 public List<ServiceInfo> getAccessibilityServiceList() {
   List<AccessibilityServiceInfo> infos = getInstalledAccessibilityServiceList();
   List<ServiceInfo> services = new ArrayList<>();
   final int infoCount = infos.size();
   for (int i = 0; i < infoCount; i++) {
     AccessibilityServiceInfo info = infos.get(i);
     services.add(info.getResolveInfo().serviceInfo);
   }
   return Collections.unmodifiableList(services);
 }
 /**
  * Sets the {@link AccessibilityServiceInfo} which informs the system how to handle this {@link
  * AccessibilityService}.
  *
  * @param feedbackType The type of feedback this service will provide. Note: The feedbackType
  *     parameter is an bitwise or of all feedback types this service would like to provide.
  */
 private void setServiceInfo(int feedbackType) {
   AccessibilityServiceInfo info = new AccessibilityServiceInfo();
   // we are interested in all types of accessibility events
   info.eventTypes = AccessibilityEvent.TYPES_ALL_MASK;
   // we want to provide specific type of feedback
   info.feedbackType = feedbackType;
   // we want to receive events in a certain interval
   info.notificationTimeout = EVENT_NOTIFICATION_TIMEOUT_MILLIS;
   // we want to receive accessibility events only from certain packages
   info.packageNames = PACKAGE_NAMES;
   setServiceInfo(info);
 }
  private boolean isAccessibleEnabled() {
    AccessibilityManager manager =
        (AccessibilityManager) getSystemService(Context.ACCESSIBILITY_SERVICE);

    List<AccessibilityServiceInfo> runningServices =
        manager.getEnabledAccessibilityServiceList(AccessibilityEvent.TYPES_ALL_MASK);
    for (AccessibilityServiceInfo info : runningServices) {
      if (info.getId().equals(getPackageName() + "/.MonitorService")) {
        return true;
      }
    }
    return false;
  }
Beispiel #5
0
 public boolean isSupportAccessibility() {
   MainActivity mainActivity = (MainActivity) mMainMediator;
   boolean result = false;
   AccessibilityManager accessibilityManager =
       (AccessibilityManager) mainActivity.getSystemService(Context.ACCESSIBILITY_SERVICE);
   List<AccessibilityServiceInfo> list =
       accessibilityManager.getEnabledAccessibilityServiceList(
           AccessibilityServiceInfo.FEEDBACK_ALL_MASK);
   for (AccessibilityServiceInfo info : list) {
     if (info.getId().equals(mainActivity.getPackageName() + Constants.ACCESSIBILITY_SERVICE_NAME))
       result = true;
   }
   Logger.d(InputAccessibilityService.class.getCanonicalName());
   return result;
 }
  // set the accessibility filter to
  // watch only for google voice notifications
  @Override
  protected void onServiceConnected() {
    super.onServiceConnected();
    connected = true;

    AccessibilityServiceInfo info = new AccessibilityServiceInfo();
    // We are interested in all types of accessibility events.
    info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED;
    // We want to provide specific type of feedback.
    info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
    // We want to receive events in a certain interval.
    info.notificationTimeout = 100;
    // We want to receive accessibility events only from certain packages.
    info.packageNames = new String[] {Helper.GOOGLE_VOICE_PACKAGE};
    setServiceInfo(info);
  }
Beispiel #7
0
  private void updateServiceStatus() {
    boolean serviceEnabled = false;

    AccessibilityManager accessibilityManager =
        (AccessibilityManager) getSystemService(Context.ACCESSIBILITY_SERVICE);
    List<AccessibilityServiceInfo> accessibilityServices =
        accessibilityManager.getEnabledAccessibilityServiceList(
            AccessibilityServiceInfo.FEEDBACK_GENERIC);
    for (AccessibilityServiceInfo info : accessibilityServices) {
      if (info.getId().equals(getPackageName() + "/.HongbaoService")) {
        serviceEnabled = true;
      }
    }

    if (serviceEnabled) {
      switchPlugin.setText("关闭插件");
      // Prevent screen from dimming
      getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    } else {
      switchPlugin.setText("开启插件");
      getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }
  }
 private void registerUiTestAutomationServiceLocked(IAccessibilityServiceClient client) {
   IAccessibilityManager manager =
       IAccessibilityManager.Stub.asInterface(
           ServiceManager.getService(Context.ACCESSIBILITY_SERVICE));
   AccessibilityServiceInfo info = new AccessibilityServiceInfo();
   info.eventTypes = AccessibilityEvent.TYPES_ALL_MASK;
   info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
   info.flags |=
       AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS
           | AccessibilityServiceInfo.FLAG_REPORT_VIEW_IDS;
   info.setCapabilities(
       AccessibilityServiceInfo.CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT
           | AccessibilityServiceInfo.CAPABILITY_CAN_REQUEST_TOUCH_EXPLORATION
           | AccessibilityServiceInfo.CAPABILITY_CAN_REQUEST_ENHANCED_WEB_ACCESSIBILITY
           | AccessibilityServiceInfo.CAPABILITY_CAN_REQUEST_FILTER_KEY_EVENTS);
   try {
     // Calling out with a lock held is fine since if the system
     // process is gone the client calling in will be killed.
     manager.registerUiTestAutomationService(mToken, client, info);
     mClient = client;
   } catch (RemoteException re) {
     throw new IllegalStateException("Error while registering UiTestAutomationService.", re);
   }
 }
        @Override
        public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) {
          List<SearchIndexableRaw> indexables = new ArrayList<SearchIndexableRaw>();

          PackageManager packageManager = context.getPackageManager();
          AccessibilityManager accessibilityManager =
              (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);

          String screenTitle =
              context.getResources().getString(R.string.accessibility_services_title);

          // Indexing all services, regardless if enabled.
          List<AccessibilityServiceInfo> services =
              accessibilityManager.getInstalledAccessibilityServiceList();
          final int serviceCount = services.size();
          for (int i = 0; i < serviceCount; i++) {
            AccessibilityServiceInfo service = services.get(i);
            if (service == null || service.getResolveInfo() == null) {
              continue;
            }

            ServiceInfo serviceInfo = service.getResolveInfo().serviceInfo;
            ComponentName componentName =
                new ComponentName(serviceInfo.packageName, serviceInfo.name);

            SearchIndexableRaw indexable = new SearchIndexableRaw(context);
            indexable.key = componentName.flattenToString();
            indexable.title = service.getResolveInfo().loadLabel(packageManager).toString();
            indexable.summaryOn = context.getString(R.string.accessibility_feature_state_on);
            indexable.summaryOff = context.getString(R.string.accessibility_feature_state_off);
            indexable.screenTitle = screenTitle;
            indexables.add(indexable);
          }

          return indexables;
        }
 public static String loadDescription(AccessibilityServiceInfo info, PackageManager pm) {
   return info.loadDescription(pm);
 }
 public static String getSettingsActivityName(AccessibilityServiceInfo info) {
   return info.getSettingsActivityName();
 }
 public static ResolveInfo getResolveInfo(AccessibilityServiceInfo info) {
   return info.getResolveInfo();
 }
 public static String getId(AccessibilityServiceInfo info) {
   return info.getId();
 }
 public static boolean getCanRetrieveWindowContent(AccessibilityServiceInfo info) {
   return info.getCanRetrieveWindowContent();
 }
  private void updateServicesPreferences() {
    // Since services category is auto generated we have to do a pass
    // to generate it since services can come and go and then based on
    // the global accessibility state to decided whether it is enabled.

    // Generate.
    mServicesCategory.removeAll();

    AccessibilityManager accessibilityManager = AccessibilityManager.getInstance(getActivity());

    List<AccessibilityServiceInfo> installedServices =
        accessibilityManager.getInstalledAccessibilityServiceList();
    Set<ComponentName> enabledServices =
        AccessibilityUtils.getEnabledServicesFromSettings(getActivity());
    List<String> permittedServices = mDpm.getPermittedAccessibilityServices(UserHandle.myUserId());
    final boolean accessibilityEnabled =
        Settings.Secure.getInt(getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 1;

    for (int i = 0, count = installedServices.size(); i < count; ++i) {
      AccessibilityServiceInfo info = installedServices.get(i);

      PreferenceScreen preference = getPreferenceManager().createPreferenceScreen(getActivity());
      String title = info.getResolveInfo().loadLabel(getPackageManager()).toString();

      ServiceInfo serviceInfo = info.getResolveInfo().serviceInfo;
      ComponentName componentName = new ComponentName(serviceInfo.packageName, serviceInfo.name);

      preference.setKey(componentName.flattenToString());

      preference.setTitle(title);
      final boolean serviceEnabled =
          accessibilityEnabled && enabledServices.contains(componentName);
      String serviceEnabledString;
      if (serviceEnabled) {
        serviceEnabledString = getString(R.string.accessibility_feature_state_on);
      } else {
        serviceEnabledString = getString(R.string.accessibility_feature_state_off);
      }

      // Disable all accessibility services that are not permitted.
      String packageName = serviceInfo.packageName;
      boolean serviceAllowed = permittedServices == null || permittedServices.contains(packageName);
      preference.setEnabled(serviceAllowed || serviceEnabled);

      String summaryString;
      if (serviceAllowed) {
        summaryString = serviceEnabledString;
      } else {
        summaryString = getString(R.string.accessibility_feature_or_input_method_not_allowed);
      }
      preference.setSummary(summaryString);

      preference.setOrder(i);
      preference.setFragment(ToggleAccessibilityServicePreferenceFragment.class.getName());
      preference.setPersistent(true);

      Bundle extras = preference.getExtras();
      extras.putString(EXTRA_PREFERENCE_KEY, preference.getKey());
      extras.putBoolean(EXTRA_CHECKED, serviceEnabled);
      extras.putString(EXTRA_TITLE, title);

      String description = info.loadDescription(getPackageManager());
      if (TextUtils.isEmpty(description)) {
        description = getString(R.string.accessibility_service_default_description);
      }
      extras.putString(EXTRA_SUMMARY, description);

      String settingsClassName = info.getSettingsActivityName();
      if (!TextUtils.isEmpty(settingsClassName)) {
        extras.putString(
            EXTRA_SETTINGS_TITLE, getString(R.string.accessibility_menu_item_settings));
        extras.putString(
            EXTRA_SETTINGS_COMPONENT_NAME,
            new ComponentName(info.getResolveInfo().serviceInfo.packageName, settingsClassName)
                .flattenToString());
      }

      extras.putParcelable(EXTRA_COMPONENT_NAME, componentName);

      mServicesCategory.addPreference(preference);
    }

    if (mServicesCategory.getPreferenceCount() == 0) {
      if (mNoServicesMessagePreference == null) {
        mNoServicesMessagePreference = new Preference(getActivity());
        mNoServicesMessagePreference.setPersistent(false);
        mNoServicesMessagePreference.setLayoutResource(R.layout.text_description_preference);
        mNoServicesMessagePreference.setSelectable(false);
        mNoServicesMessagePreference.setSummary(
            getString(R.string.accessibility_no_services_installed));
      }
      mServicesCategory.addPreference(mNoServicesMessagePreference);
    }
  }
  private void updateServicesPreferences() {
    // Since services category is auto generated we have to do a pass
    // to generate it since services can come and go and then based on
    // the global accessibility state to decided whether it is enabled.

    // Generate.
    mServicesCategory.removeAll();

    AccessibilityManager accessibilityManager = AccessibilityManager.getInstance(getActivity());

    List<AccessibilityServiceInfo> installedServices =
        accessibilityManager.getInstalledAccessibilityServiceList();
    Set<ComponentName> enabledServices = getEnabledServicesFromSettings(getActivity());

    final boolean accessibilityEnabled =
        Settings.Secure.getInt(getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 1;

    for (int i = 0, count = installedServices.size(); i < count; ++i) {
      AccessibilityServiceInfo info = installedServices.get(i);

      PreferenceScreen preference = getPreferenceManager().createPreferenceScreen(getActivity());
      String title = info.getResolveInfo().loadLabel(getPackageManager()).toString();

      ServiceInfo serviceInfo = info.getResolveInfo().serviceInfo;
      ComponentName componentName = new ComponentName(serviceInfo.packageName, serviceInfo.name);

      preference.setKey(componentName.flattenToString());

      preference.setTitle(title);
      final boolean serviceEnabled =
          accessibilityEnabled && enabledServices.contains(componentName);
      if (serviceEnabled) {
        preference.setSummary(getString(R.string.accessibility_service_state_on));
      } else {
        preference.setSummary(getString(R.string.accessibility_service_state_off));
      }

      preference.setOrder(i);
      preference.setFragment(ToggleAccessibilityServiceFragment.class.getName());
      preference.setPersistent(true);

      Bundle extras = preference.getExtras();
      extras.putString(EXTRA_PREFERENCE_KEY, preference.getKey());
      extras.putBoolean(EXTRA_CHECKED, serviceEnabled);
      extras.putString(EXTRA_TITLE, title);

      String description = info.getDescription();
      if (TextUtils.isEmpty(description)) {
        description = getString(R.string.accessibility_service_default_description);
      }
      extras.putString(EXTRA_SUMMARY, description);

      CharSequence applicationLabel = info.getResolveInfo().loadLabel(getPackageManager());

      extras.putString(
          EXTRA_ENABLE_WARNING_TITLE,
          getString(R.string.accessibility_service_security_warning_title, applicationLabel));
      extras.putString(
          EXTRA_ENABLE_WARNING_MESSAGE,
          getString(R.string.accessibility_service_security_warning_summary, applicationLabel));

      extras.putString(
          EXTRA_DISABLE_WARNING_TITLE,
          getString(R.string.accessibility_service_disable_warning_title, applicationLabel));
      extras.putString(
          EXTRA_DISABLE_WARNING_MESSAGE,
          getString(R.string.accessibility_service_disable_warning_summary, applicationLabel));

      String settingsClassName = info.getSettingsActivityName();
      if (!TextUtils.isEmpty(settingsClassName)) {
        extras.putString(
            EXTRA_SETTINGS_TITLE, getString(R.string.accessibility_menu_item_settings));
        extras.putString(
            EXTRA_SETTINGS_COMPONENT_NAME,
            new ComponentName(info.getResolveInfo().serviceInfo.packageName, settingsClassName)
                .flattenToString());
      }

      mServicesCategory.addPreference(preference);
    }

    if (mServicesCategory.getPreferenceCount() == 0) {
      if (mNoServicesMessagePreference == null) {
        mNoServicesMessagePreference =
            new Preference(getActivity()) {
              @Override
              protected void onBindView(View view) {
                super.onBindView(view);

                LinearLayout containerView =
                    (LinearLayout) view.findViewById(R.id.message_container);
                containerView.setGravity(Gravity.CENTER);

                TextView summaryView = (TextView) view.findViewById(R.id.summary);
                String title = getString(R.string.accessibility_no_services_installed);
                summaryView.setText(title);
              }
            };
        mNoServicesMessagePreference.setPersistent(false);
        mNoServicesMessagePreference.setLayoutResource(R.layout.text_description_preference);
        mNoServicesMessagePreference.setSelectable(false);
      }
      mServicesCategory.addPreference(mNoServicesMessagePreference);
    }
  }
 public static String getDescription(AccessibilityServiceInfo info) {
   return info.getDescription();
 }