Accessibility service disabled upon each debug run

Each time I start a new debug instance, my accessibility service resets to disabled state.

Is there a way to keep it enabled across successive debug runs (as it is quite long & boring to enable it each time in order to debug the service)?

  • Drawing a square layout inside a circle
  • design a layout like below image with image buttons in android
  • How do I change the theme on an Android application?
  • HTTP Patch request from Android
  • Android API level < 19 and “try can use automatic resource management” warning
  • Using adb logcat with a real phone (and not the emulator)
  • I have the same behavior on real device and emulators.
    There is no exception in the service, I tried event with no code in the event handler.

    There are suspicious lines in my logs:

    10:47:32.801 31669-31669/? E/AffinityControl: AffinityControl: registerfunction enter
    10:47:32.821 3650-3690/? I/ActivityManager: Force stopping com.test.testaccessibilityservice appid=10241 user=0: from pid 31669
    10:47:32.821 3650-3690/? I/ActivityManager: Killing 31271:com.test.testaccessibilityservice/u0a241 (adj 1): stop com.test.testaccessibilityservice cause from pid     
    10:47:32.821 3650-3690/? W/ActivityManager: Scheduling restart of crashed service com.test.testaccessibilityservice/.MyAccessibilityService in 1000ms
    10:47:32.821 3650-3690/? I/ActivityManager:   Force stopping service ServiceRecord{3f5e1fc4 u0 com.test.testaccessibilityservice/.MyAccessibilityService}
    

    So the service is force stopped and never restarted.

    Notes:
    – If I reboot the phone, the service is started.
    – I have the same behavior with the ApiDemos sample and ClockBackService (QueryBackService too):

    18:07:15.871 3523-4251/? I/ActivityManager: Force stopping com.example.android.apis appid=10242 user=0: from pid 19382
    18:07:15.871 3523-4251/? I/ActivityManager: Killing 16542:com.example.android.apis/u0a242 (adj 1): stop com.example.android.apis cause from pid 19382
    18:07:15.871 3523-4251/? W/ActivityManager: Scheduling restart of crashed service com.example.android.apis/.accessibility.ClockBackService in 1000ms
    18:07:15.871 3523-4251/? I/ActivityManager:   Force finishing activity 3 ActivityRecord{2f907c7b u0 com.example.android.apis/.ApiDemos t8248}
    18:07:15.881 3523-4251/? I/ActivityManager:   Force finishing activity 3 ActivityRecord{190ca05c u0 com.example.android.apis/.ApiDemos t8248}
    18:07:15.881 3523-4251/? I/ActivityManager:   Force finishing activity 3 ActivityRecord{27ada6e8 u0 com.example.android.apis/.accessibility.ClockBackActivity t8248}
    18:07:15.881 3523-4251/? I/ActivityManager:   Force finishing activity 3 ActivityRecord{51f4c32 u0 com.android.settings/.Settings$AccessibilitySettingsActivity t8248}
    18:07:15.881 3523-4251/? I/ActivityManager:   Force stopping service ServiceRecord{113bf024 u0 com.example.android.apis/.accessibility.ClockBackService}
    18:07:15.891 19382-19382/? D/AndroidRuntime: Shutting down VM
    

    I’ve tried to return START_STICKY by overriding onStartCommand without any change.

    It is very closed to this old unanswered question How to debug accessibility service?, but in my case the service appears disabled, and I do not need to stop it and start it again.

    I filled out this bug report on AOSP.

    Related posts:

    Gradle build error, Error:Execution failed for task &#039;:app:transformResourcesWithMergeJavaRe...
    Android USB OTG: programmatically turn off power to the port
    Android: How to get return result from activity when calling from Fragment?
    Android - Expandable TextView with Animation
    Binding service by BroadcastReceiver
    How to get the number of unread gmail mails (on android)
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.