Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed|Revert: Revert and still use
TermuxAm
for broadcast commands …
…on Android `>= 14` but do not wait for result and always exit with exit code 0 When `broadcastIntent()` is called with a `IIntentReceiver resultTo` to be able to get back the broadcast result, Android uses the `IApplicationThread caller` passed to get the `ProcessRecord` of the app from its internal cache (`getRecordForAppLOSP()`) based on the `caller`. Since `TermuxAm` uses a fake `IApplicationThread` that does not belong to an app, the `resultToApp` would not be found. For this, android logs the `Sending broadcast <action> with resultTo requires resultToApp` exception and terminates the process. To prevent this from happening, we do not pass the `resultTo` so that Android uses the `system_server` `ProcessRecord` instead at the cost of not being able to get back the result for the broadcast. This will trigger the following exception in `logcat`, but if broadcast was valid, then it will still have been sent. ``` java.lang.RuntimeException: BroadcastReceiver trying to return result during a non-ordered broadcast at android.content.BroadcastReceiver$PendingResult.checkSynchronousHint(BroadcastReceiver.java:351) at android.content.BroadcastReceiver$PendingResult.setResultCode(BroadcastReceiver.java:154) at com.termux.api.util.ResultReturner.lambda$returnData$0(ResultReturner.java:196) at com.termux.api.util.ResultReturner$$ExternalSyntheticLambda0.run(Unknown Source:8) at java.lang.Thread.run(Thread.java:1012) ``` - https://cs.android.com/android/_/android/platform/frameworks/base/+/a51563231919be01f2d3de53a88df70154ac8992 - https://cs.android.com/android/platform/superproject/+/android-14.0.0_r1:frameworks/base/core/java/android/content/BroadcastReceiver.java;l=350 - https://cs.android.com/android/platform/superproject/+/android-14.0.0_r1:frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java;l=14391 https://cs.android.com/android/platform/superproject/+/android-14.0.0_r1:frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java;l=15309 We cannot use `/system/bin/am` on Android `14` December security patch as `am` commands can only be run with `adb` and `root` users now. Normally, no output will be received when the command will be run and exit code will be `255`. I got the exception once, not sure how to reproduce, there is likely some AOSP bug, using subshell hack and even disabling selinux does not work, but it did get logged while selinux was disabled. - https://cs.android.com/android/_/android/platform/frameworks/base/+/3ef3f18ba3094c4cc4f954ba23d1da421f9ca8b0 ``` java.lang.SecurityException: Shell commands are only callable by root or shell at android.os.Parcel.createExceptionOrNull(Parcel.java:3057) at android.os.Parcel.createException(Parcel.java:3041) at android.os.Parcel.readException(Parcel.java:3024) at android.os.Parcel.readException(Parcel.java:2966) at android.os.BinderProxy.shellCommand(BinderProxy.java:692) at com.android.commands.am.Am.runAmCmd(Am.java:146) at com.android.commands.am.Am.onRun(Am.java:87) at com.android.internal.os.BaseCommand.run(BaseCommand.java:62) at com.android.commands.am.Am.main(Am.java:54) at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method) at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:359) Caused by: android.os.RemoteException: Remote stack trace: at com.android.server.am.ActivityManagerService.onShellCommand(ActivityManagerService.java:9763) at android.os.Binder.shellCommand(Binder.java:1071) at android.os.Binder.onTransact(Binder.java:888) at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:5267) at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2763) ``` Closes termux/termux-app#3754 Related termux/termux-app#3647, termux/termux-api#638
- Loading branch information