|
17 | 17 | import com.termux.shared.models.ResultConfig; |
18 | 18 | import com.termux.shared.models.ResultData; |
19 | 19 | import com.termux.shared.models.errors.Errno; |
| 20 | +import com.termux.shared.settings.preferences.TermuxPreferenceConstants.TERMUX_TASKER_APP; |
| 21 | +import com.termux.shared.settings.preferences.TermuxTaskerAppSharedPreferences; |
20 | 22 | import com.termux.shared.shell.ResultSender; |
21 | 23 | import com.termux.tasker.FireReceiver; |
22 | 24 | import com.termux.tasker.PluginResultsService; |
@@ -156,7 +158,7 @@ public static void sendExecuteIntentToExecuteService(final Context context, fina |
156 | 158 | pluginResultsServiceIntent.putExtra(EXTRA_ORIGINAL_INTENT, originalIntent); |
157 | 159 |
|
158 | 160 | // Create PendingIntent that can be used by execution service to send result of commands back to PluginResultsService |
159 | | - PendingIntent pendingIntent = PendingIntent.getService(context, 1, pluginResultsServiceIntent, PendingIntent.FLAG_ONE_SHOT); |
| 161 | + PendingIntent pendingIntent = PendingIntent.getService(context, getLastPendingIntentRequestCode(context), pluginResultsServiceIntent, PendingIntent.FLAG_ONE_SHOT); |
160 | 162 | executionIntent.putExtra(TERMUX_SERVICE.EXTRA_PENDING_INTENT, pendingIntent); |
161 | 163 | } else { |
162 | 164 | // If execute in background is not enabled, do not expect results back from execution service and return result now so that plugin action does not timeout |
@@ -450,4 +452,29 @@ public static String checkIfTermuxTaskerAllowExternalAppsPolicyIsViolated(final |
450 | 452 | return errmsg; |
451 | 453 | } |
452 | 454 |
|
| 455 | + /** |
| 456 | + * Try to get the next unique {@link PendingIntent} request code that isn't already being used by |
| 457 | + * the app and which would create a unique {@link PendingIntent} that doesn't conflict with that |
| 458 | + * of any other execution commands. |
| 459 | + * |
| 460 | + * @param context The {@link Context} for operations. |
| 461 | + * @return Returns the request code that should be safe to use. |
| 462 | + */ |
| 463 | + public synchronized static int getLastPendingIntentRequestCode(final Context context) { |
| 464 | + if (context == null) return TERMUX_TASKER_APP.DEFAULT_VALUE_KEY_LAST_PENDING_INTENT_REQUEST_CODE; |
| 465 | + |
| 466 | + TermuxTaskerAppSharedPreferences preferences = TermuxTaskerAppSharedPreferences.build(context); |
| 467 | + if (preferences == null) return TERMUX_TASKER_APP.DEFAULT_VALUE_KEY_LAST_PENDING_INTENT_REQUEST_CODE; |
| 468 | + |
| 469 | + int lastPendingIntentRequestCode = preferences.getLastPendingIntentRequestCode(); |
| 470 | + |
| 471 | + int nextPendingIntentRequestCode = lastPendingIntentRequestCode + 1; |
| 472 | + |
| 473 | + if (nextPendingIntentRequestCode == Integer.MAX_VALUE || nextPendingIntentRequestCode < 0) |
| 474 | + nextPendingIntentRequestCode = TERMUX_TASKER_APP.DEFAULT_VALUE_KEY_LAST_PENDING_INTENT_REQUEST_CODE; |
| 475 | + |
| 476 | + preferences.setLastPendingIntentRequestCode(nextPendingIntentRequestCode); |
| 477 | + return nextPendingIntentRequestCode; |
| 478 | + } |
| 479 | + |
453 | 480 | } |
0 commit comments