warren-bank / Android-ExoPlayer-AirPlay-Receiver

Android app to run on a set-top box and play video URLs "cast" to it with a stateless HTTP API (based on AirPlay v1).
http://webcast-reloaded.surge.sh/airplay_sender.html
GNU General Public License v2.0
154 stars 24 forks source link

App does not work under Android 11 API-Level 30 (FireOS 8), problem with MANAGE_OVERLAY_PERMISSION #11

Open jmber opened 6 months ago

jmber commented 6 months ago

Hi, there is a problem with the MANAGE_OVERLAY_PERMISSION under Android 11, Service cannot register...

ADB Logcat: --------- beginning of crash 04-08 12:19:42.506 5319 5319 E AndroidRuntime: FATAL EXCEPTION: main 04-08 12:19:42.506 5319 5319 E AndroidRuntime: Process: com.github.warren_bank.exoplayer_airplay_receiver, PID: 5319 04-08 12:19:42.506 5319 5319 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.github.warren_bank.exoplayer_airplay_receiver/com.github.warren_bank.exoplayer_airplay_receiver.ui.StartNetworkingServiceActivity}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.action.MANAGE_OVERLAY_PERMISSION dat=package:com.github.warren_bank.exoplayer_airplay_receiver } 04-08 12:19:42.506 5319 5319 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3468) 04-08 12:19:42.506 5319 5319 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3626) 04-08 12:19:42.506 5319 5319 E AndroidRuntime: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 04-08 12:19:42.506 5319 5319 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 04-08 12:19:42.506 5319 5319 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 04-08 12:19:42.506 5319 5319 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2081) 04-08 12:19:42.506 5319 5319 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106) 04-08 12:19:42.506 5319 5319 E AndroidRuntime: at android.os.Looper.loop(Looper.java:223) 04-08 12:19:42.506 5319 5319 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7719) 04-08 12:19:42.506 5319 5319 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 04-08 12:19:42.506 5319 5319 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 04-08 12:19:42.506 5319 5319 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 04-08 12:19:42.506 5319 5319 E AndroidRuntime: Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.action.MANAGE_OVERLAY_PERMISSION dat=package:com.github.warren_bank.exoplayer_airplay_receiver } 04-08 12:19:42.506 5319 5319 E AndroidRuntime: at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2067) 04-08 12:19:42.506 5319 5319 E AndroidRuntime: at android.app.Instrumentation.execStartActivity(Instrumentation.java:1727) 04-08 12:19:42.506 5319 5319 E AndroidRuntime: at android.app.Activity.startActivityForResult(Activity.java:5337) 04-08 12:19:42.506 5319 5319 E AndroidRuntime: at android.app.Activity.startActivityForResult(Activity.java:5295) 04-08 12:19:42.506 5319 5319 E AndroidRuntime: at com.github.warren_bank.exoplayer_airplay_receiver.utils.RuntimePermissionUtils.showDrawOverlayPermissions(SourceFile:32) 04-08 12:19:42.506 5319 5319 E AndroidRuntime: at com.github.warren_bank.exoplayer_airplay_receiver.utils.RuntimePermissionUtils.showDrawOverlayPermissions(Unknown Source:1) 04-08 12:19:42.506 5319 5319 E AndroidRuntime: at com.github.warren_bank.exoplayer_airplay_receiver.ui.StartNetworkingServiceActivity.requestPermissions(Unknown Source:25) 04-08 12:19:42.506 5319 5319 E AndroidRuntime: at com.github.warren_bank.exoplayer_airplay_receiver.ui.StartNetworkingServiceActivity.onCreate(Unknown Source:3) 04-08 12:19:42.506 5319 5319 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:8019) 04-08 12:19:42.506 5319 5319 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:8002) 04-08 12:19:42.506 5319 5319 E AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) 04-08 12:19:42.506 5319 5319 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3441) 04-08 12:19:42.506 5319 5319 E AndroidRuntime: ... 11 more 04-08 12:20:55.637 9020 9063 E AndroidRuntime: FATAL EXCEPTION: Thread-3

jmber commented 6 months ago

Take a look at https://developer.android.com/about/versions/11/privacy/permissions:

System alert window changes

Android 11 makes several changes to how apps are granted the SYSTEM_ALERT_WINDOW permission. The changes are intended to protect users by making the permission grant more intentional. Certain apps are automatically granted SYSTEM_ALERT_WINDOW permission upon request

Certain classes of apps are automatically granted the SYSTEM_ALERT_WINDOW permission upon request:

Any app that has [ROLE_CALL_SCREENING](https://developer.android.com/reference/android/app/role/RoleManager#ROLE_CALL_SCREENING) and requests SYSTEM_ALERT_WINDOW is automatically granted the permission. If the app loses ROLE_CALL_SCREENING, it loses the permission.

Any app that is capturing the screen via a [MediaProjection](https://developer.android.com/reference/android/media/projection/MediaProjection) and requests SYSTEM_ALERT_WINDOW is automatically granted the permission unless the user has explicitly denied the permission to the app. When the app stops capturing the screen, it loses the permission. This use case is primarily intended for game livestreaming apps.

These apps do not need to send ACTION_MANAGE_OVERLAY_PERMISSION to get the SYSTEM_ALERT_WINDOW permission; the apps can simply request SYSTEM_ALERT_WINDOW directly. MANAGE_OVERLAY_PERMISSION intents always bring user to system permissions screen

Beginning with Android 11, ACTION_MANAGE_OVERLAY_PERMISSION intents always bring the user to the top-level Settings screen, where the user can grant or revoke the SYSTEM_ALERT_WINDOW permissions for apps. Any package: data in the intent is ignored.

In earlier versions of Android, the ACTION_MANAGE_OVERLAY_PERMISSION intent could specify a package, which would bring the user to an app-specific screen for managing the permission. This functionality isn't supported as of Android 11. Instead, the user must first select the app they wish to grant or revoke the permission to. This change is intended to protect users by making the permission grant more intentional.

warren-bank commented 6 months ago

darnit.. I appreciate your reporting this.

I'm a little in the weeds on something else right now, but I'll definitely circle back and do a deep dive into this when I can.

Admittedly, I haven't given this project much attention in a while. I do, however, use this app on my TV box (Android 7) every day. I could've sworn that I tested it on phones with (LineageOS) Android 12 and 13.. but maybe not, I honestly can't remember. And, even if I did, I suppose that's no guarantee that it would work on Android 11.. every version breaks user space in new/fun/interesting ways.. which is a constant headache.

I'll let you know when I've made any progress. Thanks again, truly.

warren-bank commented 6 months ago

just a quick update..

jmber commented 6 months ago

first of all, thank you for this very helpful app and yout quick reply. On fireOS you can only set the Storage Permission via UI.

But i did it via adb shell: pm grant com.github.warren_bank.exoplayer_airplay_receiver android.permission.SYSTEM_ALERT_WINDOW

And now it works ;-)

warren-bank commented 6 months ago

clever! ..I'm more than a little embarrassed that I didn't think to do that.

I've never used/tested FireOS; really glad that's all it took to get it working.