Each time I start a new debug instance, my accessibility service resets to the disabled state.
Is there any 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)?
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.