chenxiaolong / PixelLight

A flashlight app for Google Pixel devices that uses private APIs to access high brightness modes
GNU General Public License v3.0
8 stars 1 forks source link

Quick settings tile crashes on Android 15 #3

Open chenxiaolong opened 14 hours ago

chenxiaolong commented 14 hours ago

Starting the TileService as a foreground service at all is no longer allowed by default in Android 15:

2024-10-16 23:29:27.044827 -0400 W/ActivityManager( 1264): Foreground service started from background can not have location/camera/microphone access: service com.chiller3.pixellight/.TorchTileService
2024-10-16 23:29:27.045089 -0400 E/ActivityManager( 1264): FGS logic changed: [WIU changed] [BFSL changed] Orig WIU:PROC_STATE_PERSISTENT_UI New WIU:DENIED Orig BFSL:PROC_STATE_PERSISTENT_UI New BFSL:DENIED cmp: {com.chiller3.pixellight/com.chiller3.pixellight.TorchTileService} sdk: 35
2024-10-16 23:29:27.045543 -0400 W/ActivityManager( 1264): Service.startForeground() not allowed due to mAllowStartForeground false: service com.chiller3.pixellight/.TorchTileService

If battery optimizations are disabled, it makes it further, but hits the while-in-use foreground service restrictions:

2024-10-17 00:05:48.357046 -0400 W/ActivityManager( 1264): Foreground service started from background can not have location/camera/microphone access: service com.chiller3.pixellight/.TorchTileService
2024-10-17 00:05:48.357126 -0400 E/ActivityManager( 1264): FGS logic changed: [WIU changed] Orig WIU:PROC_STATE_PERSISTENT_UI New WIU:DENIED Orig BFSL:PROC_STATE_PERSISTENT_UI New BFSL:SYSTEM_ALLOW_LISTED cmp: {com.chiller3.pixellight/com.chiller3.pixellight.TorchTileService} sdk: 35
2024-10-17 00:05:48.357320 -0400 I/ActivityManager( 1264): Background started FGS: Allowed [callingPackage: com.chiller3.pixellight; callingUid: 10179; uidState: SVC ; uidBFSL: n/a; intent: Intent { act=android.service.quicksettings.action.QS_TILE cmp=com.chiller3.pixellight/.TorchTileService }; code:SYSTEM_ALLOW_LISTED; tempAllowListReason:<,reasonCode:SYSTEM_ALLOW_LISTED,duration:9223372036854775807,callingUid:-1>; targetSdkVersion:35; callerTargetSdkVersion:35; startForegroundCount:0; bindFromPackage:null: isBindService:false]
...
2024-10-17 00:05:48.358848 -0400 E/AndroidRuntime(18050): java.lang.RuntimeException: Unable to create service com.chiller3.pixellight.TorchTileService: java.lang.SecurityException: Starting FGS with type camera callerApp=ProcessRecord{ce2415c 18050:com.chiller3.pixellight/u0a179} targetSDK=35 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_CAMERA] any of the permissions allOf=false [android.permission.CAMERA, android.permission.SYSTEM_CAMERA]  and the app must be in the eligible state/exemptions to access the foreground only permission

I haven't been able to find a workaround. Looks like the loophole for having a nice quick settings UI for PixelLight will no longer work. There's no longer way to have the tile service access the camera.

Maybe I can implement some janky thing, like spawning an transparent activity that toggles the light and then exits. If that doesn't work, I'll just remove the quick settings tile completely. Either way, it'll no longer be possible to use PixelLight from the lock screen. Thanks, Google.

chenxiaolong commented 14 hours ago

Workarounds like https://github.com/zhanghai/MaterialFiles/commit/7a2b228dfef8e5080d4cc887208b1ac5458c160e and https://stackoverflow.com/a/78754376 do not work for WIU foreground services:

2024-10-17 00:44:34.878581 -0400 E/AndroidRuntime(21348): FATAL EXCEPTION: main
2024-10-17 00:44:34.878581 -0400 E/AndroidRuntime(21348): Process: com.chiller3.pixellight, PID: 21348
2024-10-17 00:44:34.878581 -0400 E/AndroidRuntime(21348): java.lang.SecurityException: Starting FGS with type camera callerApp=ProcessRecord{8e02e14 21348:com.chiller3.pixellight/u0a179} targetSDK=35 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_CAMERA] any of the permissions allOf=false [android.permission.CAMERA, android.permission.SYSTEM_CAMERA]  and the app must be in the eligible state/exemptions to access the foreground only permission
2024-10-17 00:44:34.878581 -0400 E/AndroidRuntime(21348):       at android.os.Parcel.createExceptionOrNull(Parcel.java:3251)
2024-10-17 00:44:34.878581 -0400 E/AndroidRuntime(21348):       at android.os.Parcel.createException(Parcel.java:3235)
2024-10-17 00:44:34.878581 -0400 E/AndroidRuntime(21348):       at android.os.Parcel.readException(Parcel.java:3211)
2024-10-17 00:44:34.878581 -0400 E/AndroidRuntime(21348):       at android.os.Parcel.readException(Parcel.java:3153)
2024-10-17 00:44:34.878581 -0400 E/AndroidRuntime(21348):       at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:7231)
2024-10-17 00:44:34.878581 -0400 E/AndroidRuntime(21348):       at android.app.Service.startForeground(Service.java:879)
2024-10-17 00:44:34.878581 -0400 E/AndroidRuntime(21348):       at com.chiller3.pixellight.ServiceHelper.setTorchBrightness(Unknown Source:348)
2024-10-17 00:44:34.878581 -0400 E/AndroidRuntime(21348):       at com.chiller3.pixellight.TorchTileService$$ExternalSyntheticLambda1.onShow(Unknown Source:24)
2024-10-17 00:44:34.878581 -0400 E/AndroidRuntime(21348):       at android.app.Dialog$ListenersHandler.handleMessage(Dialog.java:1500)
2024-10-17 00:44:34.878581 -0400 E/AndroidRuntime(21348):       at android.os.Handler.dispatchMessage(Handler.java:107)
2024-10-17 00:44:34.878581 -0400 E/AndroidRuntime(21348):       at android.os.Looper.loopOnce(Looper.java:232)
2024-10-17 00:44:34.878581 -0400 E/AndroidRuntime(21348):       at android.os.Looper.loop(Looper.java:317)
2024-10-17 00:44:34.878581 -0400 E/AndroidRuntime(21348):       at android.app.ActivityThread.main(ActivityThread.java:8736)
2024-10-17 00:44:34.878581 -0400 E/AndroidRuntime(21348):       at java.lang.reflect.Method.invoke(Native Method)
2024-10-17 00:44:34.878581 -0400 E/AndroidRuntime(21348):       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
2024-10-17 00:44:34.878581 -0400 E/AndroidRuntime(21348):       at com.android.internal.os.ExecInit.main(ExecInit.java:50)
2024-10-17 00:44:34.878581 -0400 E/AndroidRuntime(21348):       at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
2024-10-17 00:44:34.878581 -0400 E/AndroidRuntime(21348):       at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:369)
2024-10-17 00:44:34.878581 -0400 E/AndroidRuntime(21348): Caused by: android.os.RemoteException: Remote stack trace:
2024-10-17 00:44:34.878581 -0400 E/AndroidRuntime(21348):       at com.android.server.am.ActiveServices.validateForegroundServiceType(ActiveServices.java:2905)
2024-10-17 00:44:34.878581 -0400 E/AndroidRuntime(21348):       at com.android.server.am.ActiveServices.setServiceForegroundInnerLocked(ActiveServices.java:2589)
2024-10-17 00:44:34.878581 -0400 E/AndroidRuntime(21348):       at com.android.server.am.ActiveServices.setServiceForegroundLocked(ActiveServices.java:1843)
2024-10-17 00:44:34.878581 -0400 E/AndroidRuntime(21348):       at com.android.server.am.ActivityManagerService.setServiceForeground(ActivityManagerService.java:14178)
2024-10-17 00:44:34.878581 -0400 E/AndroidRuntime(21348):       at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:3609)