这是indexloc提供的服务,不要输入任何密码
Skip to content

Commit e994de5

Browse files
Fixed: Fix exception in ResultReturner while setting result for a non-ordered broadcast
``` 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) ```
1 parent 4159c62 commit e994de5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

app/src/main/java/com/termux/api/util/ResultReturner.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ public static void copyIntentExtras(Intent origIntent, Intent newIntent) {
144144
* Run in a separate thread, unless the context is an IntentService.
145145
*/
146146
public static void returnData(Object context, final Intent intent, final ResultWriter resultWriter) {
147-
final PendingResult asyncResult = (context instanceof BroadcastReceiver) ? ((BroadcastReceiver) context)
148-
.goAsync() : null;
147+
final BroadcastReceiver receiver = (BroadcastReceiver) ((context instanceof BroadcastReceiver) ? context : null);
149148
final Activity activity = (Activity) ((context instanceof Activity) ? context : null);
149+
final PendingResult asyncResult = receiver != null ? receiver.goAsync() : null;
150150

151151
final Runnable runnable = () -> {
152152
PrintWriter writer = null;
@@ -192,7 +192,7 @@ public static void returnData(Object context, final Intent intent, final ResultW
192192
pfds[0].close();
193193
}
194194

195-
if (asyncResult != null) {
195+
if (asyncResult != null && receiver.isOrderedBroadcast()) {
196196
asyncResult.setResultCode(0);
197197
} else if (activity != null) {
198198
activity.setResult(0);
@@ -204,7 +204,7 @@ public static void returnData(Object context, final Intent intent, final ResultW
204204
TermuxPluginUtils.sendPluginCommandErrorNotification(ResultReturner.context, LOG_TAG,
205205
TermuxConstants.TERMUX_API_APP_NAME + " Error", message, t);
206206

207-
if (asyncResult != null) {
207+
if (asyncResult != null && receiver != null && receiver.isOrderedBroadcast()) {
208208
asyncResult.setResultCode(1);
209209
} else if (activity != null) {
210210
activity.setResult(1);

0 commit comments

Comments
 (0)