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

Commit d9a172d

Browse files
Fixed: Fix potential conflicting PendingIntent for execution commands sent to TermuxService due to same request code being used
1 parent 705361e commit d9a172d

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ dependencies {
6262
implementation 'com.google.android.material:material:1.4.0'
6363
implementation 'com.google.guava:guava:24.1-jre'
6464

65-
implementation 'com.termux.termux-app:termux-shared:f00738fe3a'
65+
implementation 'com.termux.termux-app:termux-shared:ac32fbc53d'
6666

6767
// Use if below libraries are published locally by termux-app with `./gradlew publishReleasePublicationToMavenLocal` and used with `mavenLocal()`.
6868
// If updates are done, republish there and sync project with gradle files here

app/src/main/java/com/termux/tasker/utils/PluginUtils.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import com.termux.shared.models.ResultConfig;
1818
import com.termux.shared.models.ResultData;
1919
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;
2022
import com.termux.shared.shell.ResultSender;
2123
import com.termux.tasker.FireReceiver;
2224
import com.termux.tasker.PluginResultsService;
@@ -156,7 +158,7 @@ public static void sendExecuteIntentToExecuteService(final Context context, fina
156158
pluginResultsServiceIntent.putExtra(EXTRA_ORIGINAL_INTENT, originalIntent);
157159

158160
// 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);
160162
executionIntent.putExtra(TERMUX_SERVICE.EXTRA_PENDING_INTENT, pendingIntent);
161163
} else {
162164
// 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
450452
return errmsg;
451453
}
452454

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+
453480
}

0 commit comments

Comments
 (0)