Background
SAW (system alert window) permission can be used to draw content on top of other apps.
I was told a very long time ago that accessibility service can do this too, but I never found any tutorial, sample, documentation and even an app that does it... until recently:
https://play.google.com/store/apps/details?id=com.github.ericytsang.screenfilter.app.android
In fact, this app seems to be able to draw everywhere, as opposed to SAW permission. It draws even on top of the settings app and system dialogs, while SAW permission isn't allowed as such.
The problem
Sadly, as accessibility is quite a unique and rarely thing to use, just as I wrote, I couldn't find how such a thing works with drawing on top of other apps.
What I've found
The only thing I know is that this app somehow does it, and this is what it shows when it asks to grant it:
But that's not enough. I know that for some old POC I've made of using accessibility service, it showed the same, and checking it out, I can't see what triggers it. Pretty sure it's the minimal thing the users will see for any kind of accessibility service, so this won't help.
The questions
How does AccessibilityService draw on top of other apps?
Does it work the same as SAW permission ? Can you, for example, handle touch events on what it draws?
What are the restrictions of using it, if there are any ?

Using TYPE_ACCESSIBILITY_OVERLAY as
typein theWindowManager.LayoutParamswhen adding the view from within the accessibility service seems to do the trick. I did a quick test and the overlay window was shown even in the settings menu. The overlay window also received touch events. This worked also without theSYSTEM_ALERT_WINDOWpermission in the manifest and also without setting the "Display over other apps" permission interactively by the user. I did my testing using target SDK 29.Sorry, I cannot answer to your third question about what specific restrictions apply.
EDIT: By looking at the old tutorial of Google here, here's a short sample:
GlobalActionBarService.java
manifest
global_action_bar_service.xml
action_bar.xml