Start accessibility service in the second process of my app

Good morning!

I developed an application with my app accessibility service.
When the user turns it on, the accessibility service runs in the background and helps him.

The problem is that on Xiaomi devices the process of my app is destroyed when the user cleans up all tasks in the task manager. As well as the accessibility service is destroyed together.

The service doesn’t receive new events (I don’t see anything in logs). As well as on the destroy, I don’t receive any callbacks in the lifecycle methods available in the Accessibility service.

What is the most annoying, the service is marked as working in the system settings. And just turning it off and back on doesn’t fix the issue. The only reboot of the device helps, accessibility service is turned back on automatically.

So the question is: how I can separate the task of my app from the task of the accessibility service of my app. So if the user closes my app, the service continues to work. Is there a way to create separate process for it?

(I couldn’t select any category else than CWAC, but it is more likely about accessibility Service and Services, processes

Sorry, but I do not provide free support on arbitrary Android topics. This particular category is for my mostly-discontinued line of Android libraries, and questions about those are fine here. The “Android Development” category is publicly readable, but only subscribers can post, as part of the package of benefits that subscribers get beyond access to my books.

This page lists many public question-and-answer sites with public archives — you might want to try asking in one of those.

All that being said… you might try using android:process on your <service> element to get your service into a separate process.

Didn’t notice my subscription is over. Thank you for the response! (going to fix that)

And special thanks for the book, community support and help.

About the attribute in the manifest: thank you for the guess. I will try it!

(changed my subscription state)

I actually realized, that if I will start my accessibility Service in a separate process, I probably need to change the way how it communicates with the rest of the app.

The memory would be also its own, and the behavior subjects created in the model classes in the main process will not be accessible by accessibility service running in the isolated process. it looks like not so trivial solution.

But at the same time how do you think, if the isolated process would be killed when the user cleans up tasks in task manager?

Yes. That is one of the unfortunate side-effects: what had been just callbacks and reactive stuff now turns into IPC.

I agree.

In the end, Xiaomi will do whatever Xiaomi wants on Xiaomi hardware and with Xiaomi’s highly-customized version of Android. I cannot predict the outcome specifically for them.

What you might try is a scrap project:

  • Create a new project in your IDE
  • Add an activity
  • Add a stub accessibility service that does little more than logging
  • Have that service go in a separate process via android:process
  • See how that behaves with Xiaomi’s task manager

How the scrap project behaves is not a 100% guarantee that your main app will behave the same way. But if the scrap project’s accessibility service survives the task manager, there is a decent chance that your real project’s accessibility service will do the same, and it may be worth the investment in time in trying this approach with the real app.

Another thing you could try is to install some other app(s) that you know implement similar accessibility services, and see how the Xiaomi task manager handles them. You can use apps like this one to inspect the other apps’ manifests to see if they use android:process or not. I would avoid any really big app brands in this test, as they might have used :moneybag: to get Xiaomi to leave their app alone with respect to the task manager.

(BTW, thanks for renewing! I moved this thread into the “Android Development” category in the discussion board)