本文介绍了每次调试运行时都禁用辅助功能服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 每次启动新的调试实例时,我的辅助功能都会重置为禁用状态。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.我的日志中有可疑行:10:47:32.801 31669-31669/? E/AffinityControl: AffinityControl: registerfunction enter10:47:32.821 3650-3690/? I/ActivityManager: Force stopping com.test.testaccessibilityservice appid=10241 user=0: from pid 3166910:47:32.821 3650-3690/? I/ActivityManager: Killing 31271:com.test.testaccessibilityservice/u0a241 (adj 1): stop com.test.testaccessibilityservice cause from pid10:47:32.821 3650-3690/? W/ActivityManager: Scheduling restart of crashed service com.test.testaccessibilityservice/.MyAccessibilityService in 1000ms10:47:32.821 3650-3690/? I/ActivityManager: Force stopping service ServiceRecord{3f5e1fc4 u0 com.test.testaccessibilityservice/.MyAccessibilityService}因此 注意: 如果重新启动电话,则该服务将启动。 我与 ApiDemos示例和ClockBackService(也是QueryBackService):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 1938218:07:15.871 3523-4251/? I/ActivityManager: Killing 16542:com.example.android.apis/u0a242 (adj 1): stop com.example.android.apis cause from pid 1938218:07:15.871 3523-4251/? W/ActivityManager: Scheduling restart of crashed service com.example.android.apis/.accessibility.ClockBackService in 1000ms18: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尝试通过覆盖onStartCommand来返回START_STICKY,而没有进行任何更改。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.我填写了有关AOSP的此错误报告 。推荐答案这可能有助于解释和减轻问题(但不是导致您的强制停止的原因)。This might go some way to explain and mitigate your problem (but not what causes your Force stop).在 Android 3.1之后,系统会在所有广播意图上设置 FLAG_EXCLUDE_STOPPED_PACKAGES 。因此,在3.1之后,所有应用程序都将在启动时停止。为什么?出于安全原因。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.有一些规则关闭标志 FLAG_EXCLUDE_STOPPED_PACKAGES 。 (1)如果应用获取了强制停止或无响应的应用程序按钮,会设置标志。(1) If the app get's a Force stop from settings OR unresponsive app button, the flag is set.(2)您的应用程序必须位于 Phone中存储,不 外部存储(例如 sdcard ),否则标志集。 BOOT_COMPLETE 是在安装外部存储之前发送的。因此,如果将应用程序安装到外部存储,则它将不会收到BOOT_COMPLETE广播消息。(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)如果从未运行过该应用程序,则将标志设置为(永不相对于当前的引导状态; O)永远不要在此引导中进行操作,否则您在上次引导状态下会使标志无效)。(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).一种快速方法(根据需要编写脚本)假设 BOOT_COMPLETED 接收器,在强制停止后重新启用您的服务(我猜之所以这样,是因为重启后可以正常使用):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请参见启动控件 这篇关于每次调试运行时都禁用辅助功能服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-11 23:38