// 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; }
/** * 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; }
public void go(View view) { Intent intent = new Intent(); String targetActivityName = "com.allmycode.flags"; // + targetActivity.getText().toString().trim(); // Log.i(CLASSNAME, "Target activity: >>" + targetActivityName + "<<"); // try { // intent = new Intent(this, Class.forName(targetActivityName)); String fromEditText = targetActivity.getText().toString().trim(); String other = (fromEditText.contains("Other")) ? ".other" : ""; // if (!other.equals("")) { // targetActivityName += ".other"; // } targetActivityName += other; targetActivityName += ".FlagsDemoActivity"; targetActivityName += fromEditText; Log.i(CLASSNAME, "Target activity: >>" + targetActivityName + "<<"); intent.setClassName("com.allmycode.flags" + other, targetActivityName); // } catch (ClassNotFoundException e) { // Log.i(CLASSNAME, e.getMessage()); String allFlags = flags.getText().toString(); int flagsValue = 0; if (allFlags != "" && allFlags != null) { TextUtils.SimpleStringSplitter splitter = new TextUtils.SimpleStringSplitter('|'); splitter.setString(allFlags); boolean existErrors = false; for (String flagName : splitter) { Log.i(CLASSNAME, ">>" + flagName + "<<"); flagName = flagName.trim(); if (!flagName.equals("") && flagName != null) { // BARRY // need // both? if (isHex(flagName)) { Log.i(CLASSNAME, flagName + " is hex"); flagsValue |= Integer.parseInt(flagName.substring(2), 16); } else if (isDec(flagName)) { Log.i(CLASSNAME, flagName + " is decimal"); flagsValue |= Integer.parseInt(flagName); } else { Field flagsField = null; try { Log.i(CLASSNAME, "About to do reflection>>" + flagName + "<<"); flagsField = android.content.Intent.class.getField(flagName); Log.i(CLASSNAME, Integer.toString(flagsField.getInt(this))); flagsValue |= flagsField.getInt(this); } catch (SecurityException ex) { existErrors = true; ex.printStackTrace(); } catch (NoSuchFieldException ex) { existErrors = true; ex.printStackTrace(); } catch (IllegalAccessException ex) { existErrors = true; ex.printStackTrace(); } try { Log.i(CLASSNAME, Integer.toHexString(flagsValue)); if (flagsValue != 0) { intent.addFlags(flagsValue); } } catch (IllegalArgumentException e) { existErrors = true; e.printStackTrace(); } } } } if (flagsValue != 0) { intent.addFlags(flagsValue); } intent.putExtra("existErrors", existErrors); Log.i(CLASSNAME, "About to start " + intent.toString()); startActivity(intent); } // } }