@@ -92,20 +92,30 @@ public int onStartCommand(Intent intent, int flags, int startId) {
92
92
// Run again in case service is already started and onCreate() is not called
93
93
runStartForeground ();
94
94
95
- if (allowExternalApps () && RUN_COMMAND_ACTION .equals (intent .getAction ())) {
96
- Uri programUri = new Uri .Builder ().scheme ("com.termux.file" ).path (parsePath (intent .getStringExtra (RUN_COMMAND_PATH ))).build ();
97
-
98
- Intent execIntent = new Intent (TermuxService .ACTION_EXECUTE , programUri );
99
- execIntent .setClass (this , TermuxService .class );
100
- execIntent .putExtra (TermuxService .EXTRA_ARGUMENTS , intent .getStringArrayExtra (RUN_COMMAND_ARGUMENTS ));
101
- execIntent .putExtra (TermuxService .EXTRA_CURRENT_WORKING_DIRECTORY , parsePath (intent .getStringExtra (RUN_COMMAND_WORKDIR )));
102
- execIntent .putExtra (TermuxService .EXTRA_EXECUTE_IN_BACKGROUND , intent .getBooleanExtra (RUN_COMMAND_BACKGROUND , false ));
103
-
104
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
105
- this .startForegroundService (execIntent );
106
- } else {
107
- this .startService (execIntent );
108
- }
95
+ // If wrong action passed, then just return
96
+ if (!RUN_COMMAND_ACTION .equals (intent .getAction ())) {
97
+ Log .e ("termux" , "Unexpected intent action to RunCommandService: " + intent .getAction ());
98
+ return Service .START_NOT_STICKY ;
99
+ }
100
+
101
+ // If allow-external-apps property to not set to "true"
102
+ if (!allowExternalApps ()) {
103
+ Log .e ("termux" , "RunCommandService requires allow-external-apps property to be set to \" true\" in ~/.termux/termux.properties file." );
104
+ return Service .START_NOT_STICKY ;
105
+ }
106
+
107
+ Uri programUri = new Uri .Builder ().scheme ("com.termux.file" ).path (parsePath (intent .getStringExtra (RUN_COMMAND_PATH ))).build ();
108
+
109
+ Intent execIntent = new Intent (TermuxService .ACTION_EXECUTE , programUri );
110
+ execIntent .setClass (this , TermuxService .class );
111
+ execIntent .putExtra (TermuxService .EXTRA_ARGUMENTS , intent .getStringArrayExtra (RUN_COMMAND_ARGUMENTS ));
112
+ execIntent .putExtra (TermuxService .EXTRA_CURRENT_WORKING_DIRECTORY , parsePath (intent .getStringExtra (RUN_COMMAND_WORKDIR )));
113
+ execIntent .putExtra (TermuxService .EXTRA_EXECUTE_IN_BACKGROUND , intent .getBooleanExtra (RUN_COMMAND_BACKGROUND , false ));
114
+
115
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
116
+ this .startForegroundService (execIntent );
117
+ } else {
118
+ this .startService (execIntent );
109
119
}
110
120
111
121
runStopForeground ();
0 commit comments