|
20 | 20 | import androidx.core.util.Pair; |
21 | 21 |
|
22 | 22 | import com.termux.api.R; |
| 23 | +import com.termux.api.TermuxAPIConstants; |
23 | 24 | import com.termux.api.TermuxApiReceiver; |
24 | 25 | import com.termux.api.util.ResultReturner; |
25 | 26 | import com.termux.shared.logger.Logger; |
| 27 | +import com.termux.shared.shell.command.ExecutionCommand; |
| 28 | +import com.termux.shared.termux.TermuxConstants; |
| 29 | +import com.termux.shared.termux.TermuxConstants.TERMUX_APP.TERMUX_SERVICE; |
26 | 30 |
|
27 | 31 | import java.io.File; |
28 | 32 | import java.io.PrintWriter; |
29 | 33 | import java.lang.reflect.Field; |
30 | 34 | import java.util.Objects; |
31 | 35 | import java.util.UUID; |
32 | 36 |
|
33 | | -import static com.termux.shared.termux.TermuxConstants.TERMUX_PREFIX_DIR_PATH; |
34 | | - |
35 | 37 | public class NotificationAPI { |
36 | 38 |
|
37 | 39 | private static final String LOG_TAG = "NotificationAPI"; |
38 | 40 |
|
39 | | - public static final String TERMUX_SERVICE = "com.termux.app.TermuxService"; |
40 | | - public static final String ACTION_EXECUTE = "com.termux.service_execute"; |
41 | | - public static final String EXTRA_ARGUMENTS = "com.termux.execute.arguments"; |
42 | | - public static final String BIN_SH = TERMUX_PREFIX_DIR_PATH+"/bin/sh"; |
43 | | - private static final String EXTRA_EXECUTE_IN_BACKGROUND = "com.termux.execute.background"; |
| 41 | + public static final String BIN_SH = TermuxConstants.TERMUX_PREFIX_DIR_PATH + "/bin/sh"; |
44 | 42 | private static final String CHANNEL_ID = "termux-notification"; |
45 | 43 | private static final String CHANNEL_TITLE = "Termux API notification channel"; |
46 | 44 | private static final String KEY_TEXT_REPLY = "TERMUX_TEXT_REPLY"; |
@@ -359,7 +357,7 @@ private static Intent getMessageReplyIntent(Intent oldIntent, |
359 | 357 | String buttonText, String buttonAction, |
360 | 358 | String notificationId) { |
361 | 359 | Intent intent = oldIntent. |
362 | | - setClassName("com.termux.api", "com.termux.api.TermuxApiReceiver"). |
| 360 | + setClassName(TermuxConstants.TERMUX_API_PACKAGE_NAME, TermuxAPIConstants.TERMUX_API_RECEIVER_NAME). |
363 | 361 | putExtra("api_method", "NotificationReply"). |
364 | 362 | putExtra("id", notificationId). |
365 | 363 | putExtra("action", buttonAction). |
@@ -410,16 +408,18 @@ public static void onReceiveReplyToNotification(TermuxApiReceiver termuxApiRecei |
410 | 408 | } |
411 | 409 |
|
412 | 410 | static Intent createExecuteIntent(String action){ |
413 | | - String[] arguments = new String[]{"-c", action}; |
414 | | - Uri executeUri = new Uri.Builder().scheme("com.termux.file") |
415 | | - .path(BIN_SH) |
416 | | - .appendQueryParameter("arguments", Arrays.toString(arguments)) |
417 | | - .build(); |
418 | | - Intent executeIntent = new Intent(ACTION_EXECUTE, executeUri); |
419 | | - executeIntent.setClassName("com.termux", TERMUX_SERVICE); |
420 | | - executeIntent.putExtra(EXTRA_EXECUTE_IN_BACKGROUND, true); |
421 | | - executeIntent.putExtra(EXTRA_ARGUMENTS, arguments); |
422 | | - return executeIntent; |
| 411 | + ExecutionCommand executionCommand = new ExecutionCommand(); |
| 412 | + executionCommand.executableUri = new Uri.Builder().scheme(TERMUX_SERVICE.URI_SCHEME_SERVICE_EXECUTE).path(BIN_SH).build(); |
| 413 | + executionCommand.arguments = new String[]{"-c", action}; |
| 414 | + executionCommand.runner = ExecutionCommand.Runner.APP_SHELL.getName(); |
| 415 | + |
| 416 | + // Create execution intent with the action TERMUX_SERVICE#ACTION_SERVICE_EXECUTE to be sent to the TERMUX_SERVICE |
| 417 | + Intent executionIntent = new Intent(TERMUX_SERVICE.ACTION_SERVICE_EXECUTE, executionCommand.executableUri); |
| 418 | + executionIntent.setClassName(TermuxConstants.TERMUX_PACKAGE_NAME, TermuxConstants.TERMUX_APP.TERMUX_SERVICE_NAME); |
| 419 | + executionIntent.putExtra(TERMUX_SERVICE.EXTRA_ARGUMENTS, executionCommand.arguments); |
| 420 | + executionIntent.putExtra(TERMUX_SERVICE.EXTRA_RUNNER, executionCommand.runner); |
| 421 | + executionIntent.putExtra(TERMUX_SERVICE.EXTRA_BACKGROUND, true); // Also pass in case user using termux-app version < 0.119.0 |
| 422 | + return executionIntent; |
423 | 423 | } |
424 | 424 |
|
425 | 425 | static PendingIntent createAction(final Context context, String action){ |
|
0 commit comments