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:
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.
An Accessibility Service assists users with disabilities in using Android devices and apps. It is a long-running privileged service that helps users process information on the screen and lets them to interact meaningfully with a device.
An accessibility service is an application that provides user interface enhancements to assist users with disabilities, or who may temporarily be unable to fully interact with a device.
This might go some way to explain and mitigate your problem (but not what causes your Force stop
).
After Android 3.1
" the system sets FLAG_EXCLUDE_STOPPED_PACKAGES
on all broadcast intents." So after 3.1 , all apps are stopped on boot. Why ?. For security reasons.
There are RULES to turn the flag off FLAG_EXCLUDE_STOPPED_PACKAGES
.
(1) If the app get's a Force stop
from settings OR unresponsive app
button, the flag is set.
(2) Your app needs to be in Phone Storage
, NOT external storage
(e.g. sdcard
) otherwise the flag set. The BOOT_COMPLETE
is sent before external storage is mounted. So, if app is installed to external storage it won't receive BOOT_COMPLETE broadcast message.
(3) If the application has never been run, the flag is set (never is relative to current boot state ;O) NEVER means in THIS boot OR you invalidated the flag in the last boot state).
A quick way (scripted if you like) to re-enable your service after Force stop
assuming BOOT_COMPLETED
receiver (I'm guessing you have this, because your fine after reboot):
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" adb shell am broadcast -a android.intent.action.BOOT_COMPLETED
See launchcontrols
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With