Android Question #Extend, Accessibility Service, Starter Service - oddities

OliverA

Expert
Licensed User
Longtime User
Note: I'm playing around with #Extend to extend a B4A service directly with Android's AccessibilityService abstract class. Initially when the application is installed via the IDE, everything seems to work, and the inline Java routine onAccessibilityEvent calls the B4A's svc_accessibility service's accessibility_event method. Awesome! You can also properly call the svc_accessibility's HelloWorld method from Main via CallSubDelayed.
Now it gets interesting. Re-install the app via the IDE and suddenly, the accessibility_event method is not fired again. Also trying to access the HelloWorld method via CallSubDelayed produces the following log entries:
sending message to waiting queue (CallSubDelayed - HelloWorld)
Then start the svc_accessibility service via StartService and something strange happens:
*** Service (starter) Create ***
Starter Service_Create with counter: 1. 02/25/2020 23:01:30
** Service (starter) Start **
Starter Service_Start. 02/25/2020 23:01:30
** Service (svc_accessibility) Create **
svc_accessibility Service_Create with counter: 1. 02/25/2020 23:01:30
** Service (svc_accessibility) Start **
svc_accessibility Service_Start! 02/25/2020 23:01:30
The starter service is started! BTW, now the accessibility_event method is called properly again and HelloWorld works once more via CallSubDelayed.

So looking back through the logs, when the app was re-installed via the IDE, the Activity was started, but not the starter service! Huh?
onAccessibilityEvent. Event is 2048
processBA is not null!
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Checking Accessibility permission
accessibilityEnabled = 1
***ACCESSIBILITY IS ENABLED*** -----------------
-------------- > accessibilityService :: b4a.accessibility.example/b4a.accessibility.example.svc_accessibility b4a.accessibility.example/b4a.accessibility.example.svc_accessibility
We've found the correct setting - accessibility is switched on!
Accessibility enabled
onAccessibilityEvent. Event is 2048
processBA is not null!

Final oddity, it does not seem that one can stop the svc_accessibility via StopService.

One not really satisfying work around:
If I put the following in Activity_Create
B4X:
    If FirstTime Then
        StartService(svc_accessibility)
    End If
I can get the accessibility_event method to be called every time the application is installed/run.

I'm attaching an example application that can be used to see what I'm talking about. The StartService in the Activity_Create method has been commented out. There are three buttons (Start Service, CallSubDelayed, Stop Service) that can be used to recreated the cases mentioned above.

So what question(s) do I have? Can #Extend be used in the way I'm trying to use it and still have B4A's services start properly? Currently I seem to be breaking the execution of the starter service. Is there a way to fix that (on my end?).
 

Attachments

  • extends_20200225.tock.zip
    15 KB · Views: 362

zhousongke

Member
Licensed User
Longtime User
Note: I'm playing around with #Extend to extend a B4A service directly with Android's AccessibilityService abstract class. Initially when the application is installed via the IDE, everything seems to work, and the inline Java routine onAccessibilityEvent calls the B4A's svc_accessibility service's accessibility_event method. Awesome! You can also properly call the svc_accessibility's HelloWorld method from Main via CallSubDelayed.
Now it gets interesting. Re-install the app via the IDE and suddenly, the accessibility_event method is not fired again. Also trying to access the HelloWorld method via CallSubDelayed produces the following log entries:

Then start the svc_accessibility service via StartService and something strange happens:

The starter service is started! BTW, now the accessibility_event method is called properly again and HelloWorld works once more via CallSubDelayed.

So looking back through the logs, when the app was re-installed via the IDE, the Activity was started, but not the starter service! Huh?


Final oddity, it does not seem that one can stop the svc_accessibility via StopService.

One not really satisfying work around:
If I put the following in Activity_Create
B4X:
    If FirstTime Then
        StartService(svc_accessibility)
    End If
I can get the accessibility_event method to be called every time the application is installed/run.

I'm attaching an example application that can be used to see what I'm talking about. The StartService in the Activity_Create method has been commented out. There are three buttons (Start Service, CallSubDelayed, Stop Service) that can be used to recreated the cases mentioned above.

So what question(s) do I have? Can #Extend be used in the way I'm trying to use it and still have B4A's services start properly? Currently I seem to be breaking the execution of the starter service. Is there a way to fix that (on my end?).

Hi, OliverA.

Thank you for sharing an example of AccessibilityServices. I added the performGlobalAction and dispatchGesture methods. The performGlobalAction method correctly performs actions such as Back / Recent / Screen Capture. The dispatchGesture method returns true, but the gesture does not occur. Why?
 

Attachments

  • extends_20200225.tock+PerformGlobalAction+DispatchGesture.zip
    101 KB · Views: 366
Upvote 0
Top