renyuneyun / Easer

User-defined explicit automation for Android
https://renyuneyun.github.io/Easer/
GNU General Public License v3.0
800 stars 91 forks source link

Launching activities from the background restricted in Android 10 #357

Open SpiritCroc opened 3 years ago

SpiritCroc commented 3 years ago

Due to restrictions introduced in Android 10, Easer can no longer launch activities unless the user has Easer open in the foreground.

According to the above linked site, one solution to fix this would be implementing an AccessibilityService, which was also considered for https://github.com/renyuneyun/Easer/issues/119. The easiest solution is probably requesting the android.permission.SYSTEM_ALERT_WINDOW permission instead. I was already able to successfully start an activity on boot by adding the permission to Easer's manifest (feel free to pick), and granting the permission with adb shell pm grant ryey.easer.beta android.permission.SYSTEM_ALERT_WINDOW. I suppose a proper fix would need to implement application logic for requesting this permission.

HawkEy33 commented 2 years ago

Is it planned to implement the SYSTEM_ALERT_WINDOW permission ? I'm running 0.8.2 on Android 11 and launching apps is also only possible with Easer open in the foreground which defeats the purpose.

Redsandro commented 2 years ago

@SpiritCroc this works, even though the note at the bottom of the resource you linked casts some doubt?

Note: Apps running on Android 10 (Go edition) cannot receive the SYSTEM_ALERT_WINDOW permission

If it works, it's a good idea to create a PR.

SpiritCroc commented 2 years ago

@SpiritCroc this works, even though the note at the bottom of the resource you linked casts some doubt?

Note: Apps running on Android 10 (Go edition) cannot receive the SYSTEM_ALERT_WINDOW permission

If it works, it's a good idea to create a PR.

I didn't PR because it's missing the user-facing permission request. So it only works if you know how to use adb and you know what you need in this particular case. I'm not interested in implemented the remaining parts right now, as I currently don't even use the app. But if anybody wants to pick my commit and PR it, they have my permission.

Back when I created the issue and commit, I successfully used it to launch an app automatically after boot on a Raspberry Pi if I remember correctly. Didn't try on any Go edition Android, it's expected to not work there I guess.

Redsandro commented 2 years ago

@SpiritCroc thank you for the update. So it's a bit more involved, and it worked on Raspberry Pi but may not work on Android 10+ after all.

I'm not sure how to build i.e. test this myself and I don't know if @renyuneyun would condone such a hack. So I'll use a root command in stead of launch app as a workaround:

# Launch app
am start com.app.name

# Or launch activity
am start -n com.app.name/com.app.name.Activity

I know you are no longer interested, but I'll leave this here for other people looking for a solution.

SpiritCroc commented 2 years ago

So it's a bit more involved, and it worked on Raspberry Pi but may not work on Android 10+ after all.

The Raspberry was running some Android, if that wasn't clear. I think I ended up using Android 11, but I don't really remember anymore, maybe it was Android 10.