Nain57 / Smart-AutoClicker

An open-source auto clicker on images for Android
GNU General Public License v3.0
2.05k stars 361 forks source link

Re-request screen recording permission when lost to another app #509

Open AlmightyCZ opened 2 months ago

AlmightyCZ commented 2 months ago

Describe the feature

Currently, when a scenario is selected from the list, the app requests permission to "record" the screen, which is necessary for its functionality. Once this permission is granted, only the floating control panel is shown. However, if another app (such as a screen recording tool or apps like Calcy IV or Poke Genie that use screenshots for game information) takes control of the screen recording permission, the app does not request it again. The "play" button becomes disabled, and the user must return to the main app screen and reselect the scenario to prompt the app to request the permission again.

I suggest that when the "play" button is disabled due to the loss of screen recording permission, clicking the button should prompt the app to request the permission again. This would streamline the process and make it easier to use the app in conjunction with other tools that require the same permission.

Describe the usage

This feature would benefit users who frequently switch between Smart AutoClicker and other apps that require screen recording or screenshot-based functionalities (like Calcy IV or Poke Genie in Pokémon GO). By allowing the app to request permission again when clicking the disabled "play" button, users wouldn't need to navigate back to the main app and reselect their scenario, making it easier to manage multiple tools at once. This would improve the user experience for those using Smart AutoClicker alongside other apps that temporarily take over screen permissions.

Is it a duplicate?

Nain57 commented 6 days ago

Hi and thank you for your feedback.

MediaProjection loss will now show the following dialog: Capture d'écran 2024-11-16 155108

Clicking on yes will start the Android permission request popup. Clicking on no will stop Klick'r.

Implemented by: https://github.com/Nain57/Smart-AutoClicker/pull/542/commits/59c5f74903cce22312faf92fbe5621aada9a3330

AlmightyCZ commented 6 days ago

Hi, thank you for looking into this request.

Does the dialog appear instantly when the permission is "overtaken" by another app, or only when I try to play the active scenario?

In the first case, it might not be ideal because when another app takes over the permission, I usually want to use that app for a while before returning to Klick'r. If the dialog appears immediately upon permission loss, it could interrupt the workflow with the other app.

Ideally, the dialog would appear when I attempt to play the active scenario after the permission has been lost. This way, it wouldn't interfere while I'm using the other app, and it would prompt me to regain the permission only when I return to Klick'r.

Thank you again for your attention to this matter.

Nain57 commented 5 days ago

Hi,

Dialog will happen when clicking on play or going into the config menu. If the scenario configuration was open during the permission loss, the ui will go back to the root floating menu automatically.

This has been included in the last beta, so you can take a closer look: https://github.com/Nain57/Smart-AutoClicker/releases/tag/3.1.0-beta01

AlmightyCZ commented 4 days ago

Hi,

Thank you for addressing this feature request and providing the beta version. I tested it, and I can confirm that the dialog appears when attempting to play the active scenario after the permission has been lost, which is exactly the behavior I was hoping for.

However, I've encountered an issue on my Samsung S23 running Android 14. It seems that when an app loses the screen recording permission to another app and then tries to regain it, the permission request needs to be made twice (in most cases) before it succeeds. Here's what happens:

https://github.com/user-attachments/assets/1da13cfb-c650-4404-b43c-8b95c8421c9a

1. Using Klick'r:

2. Using Calcy IV via Floating Icon:

3. Second Attempt with Calcy IV:

Resuming Klick'r from Floating Panel:

Additionally, I've noticed that the need for a second permission request seems to occur only if the app that took over the permission has obtained and used it. If I only select a scenario in Klick'r (and grant access to the permission) but do not run it, then Calcy IV works with just the first confirmation.

Suggestion: Would it be possible to modify Klick'r so that if the permission request fails, it allows for a second attempt rather than closing the app? This would align its behavior with apps like Calcy IV and improve usability on devices like mine where this issue occurs.

I've attached a video demonstrating this behavior for clarity.

Thank you again for your work on this amazing project and for your help in resolving this issue.

Nain57 commented 4 days ago

Hi and thank you for your feedback.

After some testing, it seems like Android doesn't like changing the casting permission from one app to another. After losing the permission to Calvi IV, when i'm requesting it again, it is granted for a few ms and then it get revoked automatically. This is not happening everytime (on my device at least), and seems to happen more when the Android permission dialog is accepted quickly.

Calvi IV has the same issue as Klick'r, according to the logs I can gather, they also have the "blinking" permission, that's why it ask you again for granting.

Klick'r doesn't ask again due to a bug, the overlay can sometimes not be correctly restored when this issue occurs, so Klick'r is still here, but invisible. I will fix it in beta02.

For the two requests issue, I can't do anything on my side, as this seems like an Android issue. I will open a bug on Google issue tracker for that, hoping for a fix.