In my Application there is a Service and an AccessibilityService. Now the Service is bound by the accessibility Service in order to receive information.
My Service periodically checks if the AccessibilityService is enabled, and if it is not, it sends a notification to the user that it has to enable it.
Once enabled, AccessibilityService starts to work. First it binds to my Service, and after, it begins to send information.
The problem is if AccessibilityService crashes. It remains enabled but there is no running instance. So my Service finds it enabled but actually the AccessibilityService is not running.
How Check AccessibilityService
public boolean checkAccesibilityService()
{
int accessibilityEnabled = 0;
boolean accessibilityFound = false;
try {
accessibilityEnabled = Settings.Secure.getInt(
mContext.getApplicationContext().getContentResolver(),
android.provider.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());
}
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) {
if(TextUtils.isEmpty(settingValue)) {
Log.i(TAG, "Nessun servizio abilitato!");
return false;
}
TextUtils.SimpleStringSplitter splitter = new TextUtils.SimpleStringSplitter(':');
splitter.setString(settingValue);
while (splitter.hasNext()) {
String accessabilityService = splitter.next();
//Log.v(TAG, "-------------- > accessabilityService :: " + accessabilityService);
if (accessabilityService.equalsIgnoreCase(ACCESSIBILITY_SERVCE)) {
//Log.v(TAG, "Accessibility Service Attivato!");
return true;
}
}
Log.v(TAG, "Accesibility Service non abilitato!");
return false;
}
} else {
Log.v(TAG, "***ACCESSIBILIY IS DISABLED***");
}
return accessibilityFound;
}
Q1: Why when the AccessibilityService crashes does the Android OS not restart it?
Q2: Can I change my code to check if the AccessibilityService is enabled but also has a running instance?