16

I have a perfectly running application with an accessibility service. It has been working as expected so far. The problem came out at the moment when I tried to build a new updated version. Nothing has been changed in the code related to the accessibility service. But the service is no longer binding to the updated application. There is no errors or warnings in logs. Here is the part of the manifest.xml:

...
<uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE" />

<application
    android:name=".AppState"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:allowBackup="true">

    // ... several activities, services and bootup receiver goes here...

    <service android:name=".ForegroundMonitor"
      android:label="@string/foreground_monitor_label"
      android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
      <intent-filter>
        <action android:name="android.accessibilityservice.AccessibilityService" />
      </intent-filter>
      <meta-data android:name="android.accessibilityservice" android:resource="@xml/serviceconfig" />
    </service>
</application>

And here is the serviceconfig.xml:

<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
   android:accessibilityEventTypes="typeViewClicked|typeViewFocused|typeWindowStateChanged"
     android:accessibilityFeedbackType="feedbackGeneric"
     android:notificationTimeout="1000"
     android:canRetrieveWindowContent="false"
     android:description="@string/foreground_monitor_about"
/>

The accessibility service is registered according to the system, can be started or stopped, and the service settings get changed if I change them in the app and reinstall the app.

But the service is not binding to my app anymore. The onServiceConnected method of the ForegroundMonitor is not called.

I have found some similar questions here on SO:

I've tried the only suggested solution, but it does not work in my case.

According to my tests, the problem occurs only on Android 5.0.1. On Android 2.3.3 the app works normally, and the service is bound successfully.

Could someone share a solution for this issue, which is presumably an Android bug?

UPDATE

I have just found a workaround: it's sufficient to rename the class that extends AccessibilityService (ForegroundMonitor in my case), for example by adding a versioning suffix. The drawback of this method is that users must reenable the new accessibility service in the system, because it is treated as another one. Ideally, update of an app should not require this if the service was once enabled.

So I'm still interested in a solution - more convenient solution.

Thanks in advance.

Community
  • 1
  • 1
Stan
  • 8,683
  • 9
  • 58
  • 102
  • How you are trying to bind this service in your application? From Android 5.0 onwards Explicit intent is required. Please check if it helps you – Vikasdeep Singh Jan 02 '15 at 20:33
  • @VicJordan, please provide an example. The app has been built according to Android docs (http://developer.android.com/training/accessibility/service.html, http://developer.android.com/guide/topics/ui/accessibility/services.html) and it was released for Android 5.0.1. It worked like a charm until update. I don't see in the docs any other intent use except for intent-filter which is present in my code as you may see. Please bear in mide this is an accessibility service - instantiated by system, not an ordinary service. – Stan Jan 02 '15 at 20:38
  • Your workaround is right. I also faced this issue, but in my case, enabling the accessibility service from settings ** Settings -> Device -> Accessibility -> Turn ON your Accessibility service once** I got this workaround for Samsung Galaxy S4 with Android 5.0.1 – Kushal Mar 13 '15 at 04:53
  • I had the same issue, the work around suggested here to rename AccessibilityService extension class worked for me. To make things easier I simply created new class that extend my class, and registered it as the service, so I will be able to rename only this class in the future and not the actual service. – Tamir Oct 26 '15 at 11:14
  • @Tamir, thank you for the tip. You method is good as well. Today, built-in refactoring tools are so easy to use, that I type newly changed name only once and IDE makes all the rest for me. Actually, even in your case you should change the name twice: in the class and in the manifest. – Stan Oct 27 '15 at 20:41
  • Sure, I'm using refactor, renaming the new class and it's automatically changed also in manifest. It's just annoying that I should keep remaining it, (increasing version number) once in a while, whenever after reinstall the service is not connected... – Tamir Oct 28 '15 at 07:45
  • Any news on this subject? I think I am experiencing the same problem. – Ian Medeiros Dec 08 '15 at 17:43
  • 2
    @IanMedeiros, Unfortunately, no. Android gets worse in many aspects with every new release. – Stan Dec 09 '15 at 09:55
  • I wasted hours of time identifying this problem then I came across this question. The problem was I moved my AccessibilityService class from one package to another and it was asking me to enable it again from settings on the app update. – Ali Asjad Jan 20 '23 at 05:48

0 Answers0