How to debug accessibility service? - android

I have some problem with debugging AccessibilityService and can not find a solution - with every deployment/debug from Eclipse the service is not restarted automatically and it requires the manual action of restarting the service.
What I am forced to do now:
I am adding some new code and deploying/debugging with Eclipse.
Application is deployed correctly and started but the new version of service is not started (messages from service are not shown and breakpoints are not working).
I am manually opening settings -> accessibility and see that my service runs.
I am manually stopping and starting service - now service is working.
I want to do it in a faster way:
I am adding some code and deploying, service is restarted, and then the breakpoint works without any manual boring restarting!
Could you suggest how to debug accessibility service without manually restarting?

Related

AccessibilityService gets unbinded when powered off and is not rebinded after reboot

I am facing an issue with AccessibilityService. When I power off my device AccessibilityService gets unbinded by invoking onUnbind. But when I start my device again, AccessibilityService is not rebinded and onRebind service is not called. I have checked using adb command adb shell dumpsys activity service .MyPackage.AccessibilityService and found my service is alive but is not receiving AccessibilityEvent as service is not rebounded. Everything starts working fine again after I stop and restart my AccessibilityService from settings. How can I fix this issue..? I though about using disableself at onUnbind that because it will force user to start the service from settings, but this call is available from API 24 . So, what should I do..?
I have searched a lot and tried almost everything could be done. Finally I came to a conclusion that this is a android bug, as this problem is not occurring on API 19 or later. For other developers who is suffering from this problem, I suggest you to use preference to store state of your service that it is rebinded or not. Now before you try to use your service check if your service is rebinded or not. If not, tell user that he/she will have to restart the service before using it.
I provided a more detailed answer here. check this out if you are still confused.

Can't use debugger with NotificationListenerService

I have an app that also has a NotificationListenerService. When I add breakpoints in that NotificationListenerService, it appears that the breakpoints halt the execution, but the debugger does not recognize it.
The debugger does not seem to see that the execution has paused, and does not activate the continue button nor does it show anything in the service as far as variables. Once this happens the first time, it appears that the service is stopped permanently.
A reboot seems to get things going again sometimes but only if you run the app in normal mode (not debugger mode) before you shut the device off. I tried reattaching the debugger as well, and that does not seem to work. Strangely, I did get it working once or twice. Not sure how.
Does anyone know how to attach the debugger correctly so you can debug the NotificationListenerService?
I found this potentially related question:
NotificationListenerService stopping and can't be restarted without a reboot
Why is this NotificationListenerService not working
, but neither have good answers and neither discuss using the debugger.
The NotificationListenerService runs on your main application thread. So to debug first set the debug points and then from Android studio toolbar select "Attach debugger to Android process".
Select your application main process. Now you will be able to debug your service. Hope it helps!
Cheers

BootComplete is not working in android 4.4 (app with no activity)

I am having android application which is having only background service. Service needs to run on boot complete. I declared receiver in manifest file. It is perfectly running in android 4.0 but not able to run in 4.4. Don't know Why ?
Is there any dependency that we should run app at least once to capture boot event ?
Your app needs to be started at least one time. This is necessary for the receiver to register and start responding to android.intent.action.BOOT_COMPLETED.
As far as I know there is no difference between how 4.0 and 4.4 handling the on boot completed. Maybe you can create an Activity that launches the service the first time. You can make this a background Activity.

Android: how to debug app's start-up process

I am investigating some issues which happen during my app's startup process, but DDMS won't start the debug mode until the process has started, is there a way I can capture the events earlier?
I know that this is a couple of years late, but for any future searches:
Putting WaitForDebugger into your code is one way.
Unlocking developer options (by tapping on the build number in system information on the android device) in Settings allows us to select an application for debugging and then opt to wait for a debugger whenever the program is launched. This allows us do the equivalent of adding and removing WaitForDebugger without modifying and reinstalling the code each time.
For Android Studio, here is what worked for me:
Add
android.os.Debug.waitForDebugger();
Where you want to start debugging.
Then add a breakpoint just after it in your code
Compile your app and pass it to your device
Restart your device
Once it's up, attach the debugger:
Start debugging
You should implement your own Application class which extends
Application and override the methods onCreate and so.. . This class will be your starting point of your app.
also set it as your application in the manifest.
Android can wait for the debugger to attach to your application before the app gets launched. This is a developer option called Wait for debugger.
Steps
Enable developer options (tap build version 7 times)
Enable USB debugging
Install your application onto your device using debug mode
In developer options: Press Select debug app and select the app
Enable Wait for debugger, as shown in screenshot:
Launch your app:
e.g. If testing app launch from terminated state from a push notification, send that push notification to the device.
e.g. If testing app launch from Google Assistant, use the Google Assistant to trigger this.
The app would not launch yet, instead a dialog would show up:
Attach the debugger, by pressing the Attach Debugger to Android Process button
My situation
For anyone interested/ for my future reference: I wanted to debug my Android application receiving a push notification message when the app was in the terminated state. It was actually a Flutter app running on Android, so this is relevant for both Android and Flutter.
I have revoked the API key revealed in this GIF.
Tip
If Wait for debugger is enabled, sometimes you need to detach or close Android Studio's debugger and re-attach it if you want to handle a subsequent application launch successfully. Otherwise, the app would never launch.
Notice, I send a push notification from a device (left device, iOS), and the push notification causes the app to launch on the (right device, Android). Then I attach the debugger, and the program pauses at the breakpoint I set inside FirebaseMessagingReceiver.
I wrote another version of these steps here.

Service does not launch after install?

I have followed the tutorial here :
http://blog.sptechnolab.com/2011/09/14/android/starting-an-android-service-after-boot/
about creating a service, which is activating after boot of Android.
Anyway It practically never started.
I found in here : How to start a Service when .apk is Installed for the first time
that it is not anymore possible since Android 3.0+.
My question is :
How to start a boot service once installed ?
but how to start manually a service, since it does not have any visual elements ?
Add "visual elements", in the form of an activity.
You need an activity anyway, for:
Settings for managing the behavior of this service
Help and instructions for getting support
License agreement
So, write the activity. After the user has launched your activity, your manifest-registered BroadcastReceivers, such as your BOOT_COMPLETED receiver, will work again on Android 3.1+ devices.
In lates android versions you can launch on boot only when user manually started application.

Categories

Resources