mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-06 18:55:31 +08:00
Provide better errmsg if executable passed to RunCommandService is null or empty
Previously, the null or empty executable would be expanded to the literal root "/" string path by FileUtils.getCanonicalPath and then FileUtils.validateRegularFileExistenceAndPermissions() validation would fail since path will not be a regular file. So a user will be shown that "/" is not a regular file. Now we show that executable was not even passed.
This commit is contained in:
@@ -210,6 +210,8 @@ public class RunCommandService extends Service {
|
||||
if(!executionCommand.setState(ExecutionState.PRE_EXECUTION))
|
||||
return Service.START_NOT_STICKY;
|
||||
|
||||
|
||||
|
||||
// If "allow-external-apps" property to not set to "true", then just return
|
||||
errmsg = PluginUtils.checkIfRunCommandServiceAllowExternalAppsPolicyIsViolated(this);
|
||||
if (errmsg != null) {
|
||||
@@ -218,6 +220,16 @@ public class RunCommandService extends Service {
|
||||
return Service.START_NOT_STICKY;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// If executable is null or empty, then exit here instead of getting canonical path which would expand to "/"
|
||||
if (executionCommand.executable == null || executionCommand.executable.isEmpty()) {
|
||||
errmsg = this.getString(R.string.error_run_command_service_mandatory_extra_missing, RUN_COMMAND_SERVICE.EXTRA_COMMAND_PATH);
|
||||
executionCommand.setStateFailed(ExecutionCommand.RESULT_CODE_FAILED, errmsg, null);
|
||||
PluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand);
|
||||
return Service.START_NOT_STICKY;
|
||||
}
|
||||
|
||||
// Get canonical path of executable
|
||||
executionCommand.executable = FileUtils.getCanonicalPath(executionCommand.executable, null, true);
|
||||
|
||||
@@ -233,6 +245,8 @@ public class RunCommandService extends Service {
|
||||
return Service.START_NOT_STICKY;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// If workingDirectory is not null or empty
|
||||
if (executionCommand.workingDirectory != null && !executionCommand.workingDirectory.isEmpty()) {
|
||||
// Get canonical path of workingDirectory
|
||||
@@ -255,6 +269,8 @@ public class RunCommandService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
executionCommand.executableUri = new Uri.Builder().scheme(TERMUX_SERVICE.URI_SCHEME_SERVICE_EXECUTE).path(FileUtils.getExpandedTermuxPath(executionCommand.executable)).build();
|
||||
|
||||
Logger.logVerbose(LOG_TAG, executionCommand.toString());
|
||||
|
@@ -87,6 +87,7 @@
|
||||
|
||||
<!-- Termux RunCommandService -->
|
||||
<string name="error_run_command_service_invalid_intent_action">Invalid intent action to RunCommandService: `%1$s`</string>
|
||||
<string name="error_run_command_service_mandatory_extra_missing">Mandatory extra missing to RunCommandService: \"%1$s\"</string>
|
||||
<string name="error_run_command_service_allow_external_apps_ungranted">RunCommandService require `allow-external-apps` property to be set to `true` in `&TERMUX_PROPERTIES_PRIMARY_PATH_SHORT;` file.</string>
|
||||
<string name="error_run_command_service_api_help">Visit https://github.com/termux/termux-app/blob/master/app/src/main/java/com/termux/app/RunCommandService.java for more info on RUN_COMMAND Intent usage.</string>
|
||||
|
||||
|
Reference in New Issue
Block a user