// Reload enabledSubtypes from the framework.
 private void updateEnabledSubtypes() {
   final String currentMode = getCurrentSubtypeMode();
   boolean foundCurrentSubtypeBecameDisabled = true;
   mAllEnabledSubtypesOfCurrentInputMethod = mImm.getEnabledInputMethodSubtypeList(null, true);
   mEnabledLanguagesOfCurrentInputMethod.clear();
   mEnabledKeyboardSubtypesOfCurrentInputMethod.clear();
   for (InputMethodSubtypeCompatWrapper ims : mAllEnabledSubtypesOfCurrentInputMethod) {
     final String locale = getSubtypeLocale(ims);
     final String mode = ims.getMode();
     mLocaleSplitter.setString(locale);
     if (mLocaleSplitter.hasNext()) {
       mEnabledLanguagesOfCurrentInputMethod.add(mLocaleSplitter.next());
     }
     if (locale.equals(mInputLocaleStr) && mode.equals(currentMode)) {
       foundCurrentSubtypeBecameDisabled = false;
     }
     if (KEYBOARD_MODE.equals(ims.getMode())) {
       mEnabledKeyboardSubtypesOfCurrentInputMethod.add(ims);
     }
   }
   mNeedsToDisplayLanguage =
       !(getEnabledKeyboardLocaleCount() <= 1 && mIsSystemLanguageSameAsInputLanguage);
   if (foundCurrentSubtypeBecameDisabled) {
     if (DBG) {
       Log.w(TAG, "Current subtype: " + mInputLocaleStr + ", " + currentMode);
       Log.w(TAG, "Last subtype was disabled. Update to the current one.");
     }
     updateSubtype(mImm.getCurrentInputMethodSubtype());
   }
 }
  public void checkAccessibilityService() {
    int accessibilityEnabled = 0;
    boolean accessibilityFound = false;
    try {
      accessibilityEnabled =
          Settings.Secure.getInt(
              this.getContentResolver(), android.provider.Settings.Secure.ACCESSIBILITY_ENABLED);
    } catch (SettingNotFoundException e) {
    }

    TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');

    if (accessibilityEnabled == 1) {
      String settingValue =
          Settings.Secure.getString(
              getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
      if (settingValue != null) {
        TextUtils.SimpleStringSplitter splitter = mStringColonSplitter;
        splitter.setString(settingValue);
        while (splitter.hasNext()) {
          String accessabilityService = splitter.next();
          if (accessabilityService.equalsIgnoreCase(Constants.ACCESSIBILITY_SERVICE)) {
            accessibilityFound = true;
            break;
          }
        }
      }
    }
    if (!accessibilityFound) {
      findViewById(R.id.tvAccessibilityError).setVisibility(View.VISIBLE);
      findViewById(R.id.spMode).setVisibility(View.GONE);
      findViewById(R.id.tvMode).setVisibility(View.GONE);
      findViewById(android.R.id.empty).setVisibility(View.GONE);
      findViewById(R.id.listPackages).setEnabled(false);
      if (Constants.IS_LOGGABLE) {
        Log.i(Constants.LOG_TAG, "The accessibility service is NOT on!");
      }

    } else {
      findViewById(R.id.tvAccessibilityError).setVisibility(View.GONE);
      findViewById(R.id.spMode).setVisibility(View.VISIBLE);
      findViewById(R.id.tvMode).setVisibility(View.VISIBLE);
      findViewById(android.R.id.empty).setVisibility(View.VISIBLE);
      findViewById(R.id.listPackages).setEnabled(true);
      if (Constants.IS_LOGGABLE) {
        Log.i(Constants.LOG_TAG, "The accessibility service is on!");
      }
    }
  }
  /**
   * Check whether notification listener accessibility service is enabled for the specified context
   * and the specified service class name
   *
   * <p>solution taken from http://stackoverflow.com/a/5106419/527759
   *
   * @param context
   * @param serviceClass
   * @return
   */
  public static boolean isServiceEnabled(Context context, Class<?> serviceClass) {
    int accessibilityEnabled = 0;
    final String ACCESSIBILITY_SERVICE_NAME =
        context.getPackageName() + "/" + serviceClass.getName();
    boolean accessibilityFound = false;
    try {
      accessibilityEnabled =
          Settings.Secure.getInt(
              context.getContentResolver(), android.provider.Settings.Secure.ACCESSIBILITY_ENABLED);
      Timber.d("isServiceEnabled: ACCESSIBILITY: " + accessibilityEnabled);
    } catch (Settings.SettingNotFoundException e) {
      Timber.d(
          "isServiceEnabled: Error finding setting, default accessibility to not found: "
              + e.getMessage());
    }

    TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');

    if (accessibilityEnabled == 1) {
      Timber.d("isServiceEnabled: ***ACCESSIBILIY IS ENABLED***: ");

      String settingValue =
          Settings.Secure.getString(
              context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
      Timber.d("Setting: " + settingValue);
      if (settingValue != null) {
        TextUtils.SimpleStringSplitter splitter = mStringColonSplitter;
        splitter.setString(settingValue);
        while (splitter.hasNext()) {
          String accessabilityService = splitter.next();
          Timber.d("isServiceEnabled: Setting: " + accessabilityService);
          if (accessabilityService.equalsIgnoreCase(ACCESSIBILITY_SERVICE_NAME)) {
            Timber.d(
                "isServiceEnabled: We've found the correct setting - accessibility is switched on!");
            return true;
          }
        }
      }

      Timber.d("isServiceEnabled: ***END***");
    } else {
      Timber.d("isServiceEnabled: ***ACCESSIBILIY IS DISABLED***");
    }
    return accessibilityFound;
  }
示例#4
0
  /**
   * Check if Accessibility Service is enabled.
   *
   * @param mContext
   * @return <code>true</code> if Accessibility Service is ON, otherwise <code>false</code>
   */
  public static boolean isAccessibilitySettingsOn(Context mContext) {
    int accessibilityEnabled = 0;

    final String service =
        mContext.getPackageName() + "/com.mytest.accessibility.MyAccessibilityService";

    boolean accessibilityFound = false;
    try {
      accessibilityEnabled =
          Settings.Secure.getInt(
              mContext.getApplicationContext().getContentResolver(),
              Settings.Secure.ACCESSIBILITY_ENABLED);
      Log.v(TAG, "accessibilityEnabled = " + accessibilityEnabled);
    } catch (Settings.SettingNotFoundException e) {
      Log.e(TAG, "Error finding setting, default accessibility to not found: " + e.getMessage());
    }
    TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');

    if (accessibilityEnabled == 1) {
      Log.v(TAG, "***ACCESSIBILIY IS ENABLED*** -----------------");
      String settingValue =
          Settings.Secure.getString(
              mContext.getApplicationContext().getContentResolver(),
              Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
      if (settingValue != null) {
        TextUtils.SimpleStringSplitter splitter = mStringColonSplitter;
        splitter.setString(settingValue);
        while (splitter.hasNext()) {
          String accessabilityService = splitter.next();

          Log.v(TAG, "-------------- > accessabilityService :: " + accessabilityService);
          if (accessabilityService.equalsIgnoreCase(service)) {
            Log.v(TAG, "We've found the correct setting - accessibility is switched on!");
            return true;
          }
        }
      }
    } else {
      Log.v(TAG, "***ACCESSIBILIY IS DISABLED***");
    }

    return accessibilityFound;
  }
 // check which accessibility services are enabled
 private Set<ComponentName> getEnabledServicesFromSettings() {
   String enabledServicesSetting =
       Settings.Secure.getString(
           getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
   if (enabledServicesSetting == null) {
     enabledServicesSetting = "";
   }
   Set<ComponentName> enabledServices = new HashSet<ComponentName>();
   TextUtils.SimpleStringSplitter colonSplitter =
       new TextUtils.SimpleStringSplitter(ENABLED_ACCESSIBILITY_SERVICES_SEPARATOR);
   colonSplitter.setString(enabledServicesSetting);
   while (colonSplitter.hasNext()) {
     String componentNameString = colonSplitter.next();
     ComponentName enabledService = ComponentName.unflattenFromString(componentNameString);
     if (enabledService != null) {
       enabledServices.add(enabledService);
     }
   }
   return enabledServices;
 }