mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-08 03:24:04 +08:00
Add logcat errors in RunCommandService
This commit adds `logcat` errors if an invalid intent action is passed or if `allow-external-apps` is not set to `true` while sending an intent to `RunCommandService`, so that users can detect issues.
This commit is contained in:
@@ -92,20 +92,30 @@ public class RunCommandService extends Service {
|
|||||||
// Run again in case service is already started and onCreate() is not called
|
// Run again in case service is already started and onCreate() is not called
|
||||||
runStartForeground();
|
runStartForeground();
|
||||||
|
|
||||||
if (allowExternalApps() && RUN_COMMAND_ACTION.equals(intent.getAction())) {
|
// If wrong action passed, then just return
|
||||||
Uri programUri = new Uri.Builder().scheme("com.termux.file").path(parsePath(intent.getStringExtra(RUN_COMMAND_PATH))).build();
|
if (!RUN_COMMAND_ACTION.equals(intent.getAction())) {
|
||||||
|
Log.e("termux", "Unexpected intent action to RunCommandService: " + intent.getAction());
|
||||||
|
return Service.START_NOT_STICKY;
|
||||||
|
}
|
||||||
|
|
||||||
Intent execIntent = new Intent(TermuxService.ACTION_EXECUTE, programUri);
|
// If allow-external-apps property to not set to "true"
|
||||||
execIntent.setClass(this, TermuxService.class);
|
if (!allowExternalApps()) {
|
||||||
execIntent.putExtra(TermuxService.EXTRA_ARGUMENTS, intent.getStringArrayExtra(RUN_COMMAND_ARGUMENTS));
|
Log.e("termux", "RunCommandService requires allow-external-apps property to be set to \"true\" in ~/.termux/termux.properties file.");
|
||||||
execIntent.putExtra(TermuxService.EXTRA_CURRENT_WORKING_DIRECTORY, parsePath(intent.getStringExtra(RUN_COMMAND_WORKDIR)));
|
return Service.START_NOT_STICKY;
|
||||||
execIntent.putExtra(TermuxService.EXTRA_EXECUTE_IN_BACKGROUND, intent.getBooleanExtra(RUN_COMMAND_BACKGROUND, false));
|
}
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
Uri programUri = new Uri.Builder().scheme("com.termux.file").path(parsePath(intent.getStringExtra(RUN_COMMAND_PATH))).build();
|
||||||
this.startForegroundService(execIntent);
|
|
||||||
} else {
|
Intent execIntent = new Intent(TermuxService.ACTION_EXECUTE, programUri);
|
||||||
this.startService(execIntent);
|
execIntent.setClass(this, TermuxService.class);
|
||||||
}
|
execIntent.putExtra(TermuxService.EXTRA_ARGUMENTS, intent.getStringArrayExtra(RUN_COMMAND_ARGUMENTS));
|
||||||
|
execIntent.putExtra(TermuxService.EXTRA_CURRENT_WORKING_DIRECTORY, parsePath(intent.getStringExtra(RUN_COMMAND_WORKDIR)));
|
||||||
|
execIntent.putExtra(TermuxService.EXTRA_EXECUTE_IN_BACKGROUND, intent.getBooleanExtra(RUN_COMMAND_BACKGROUND, false));
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
this.startForegroundService(execIntent);
|
||||||
|
} else {
|
||||||
|
this.startService(execIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
runStopForeground();
|
runStopForeground();
|
||||||
|
Reference in New Issue
Block a user