mirror of
				https://github.com/fankes/termux-app.git
				synced 2025-10-25 13:19:21 +08:00 
			
		
		
		
	Replace "if(" with "if ("
This commit is contained in:
		| @@ -178,7 +178,7 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas | ||||
|         // Since we cannot rely on {@link TermuxActivity.onDestroy()} to always complete, | ||||
|         // we unset clients here as well if it failed, so that we do not leave service and session | ||||
|         // clients with references to the activity. | ||||
|         if(mTermuxSessionClient != null) | ||||
|         if (mTermuxSessionClient != null) | ||||
|             unsetTermuxSessionClient(); | ||||
|         return false; | ||||
|     } | ||||
| @@ -258,14 +258,14 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas | ||||
|         List<TermuxTask> termuxTasks = new ArrayList<>(mTermuxTasks); | ||||
|         for (int i = 0; i < termuxTasks.size(); i++) { | ||||
|             ExecutionCommand executionCommand = termuxTasks.get(i).getExecutionCommand(); | ||||
|             if(executionCommand.isPluginExecutionCommand && executionCommand.pluginPendingIntent != null) | ||||
|             if (executionCommand.isPluginExecutionCommand && executionCommand.pluginPendingIntent != null) | ||||
|                 termuxTasks.get(i).killIfExecuting(this, true); | ||||
|         } | ||||
|  | ||||
|         List<ExecutionCommand> pendingPluginExecutionCommands = new ArrayList<>(mPendingPluginExecutionCommands); | ||||
|         for (int i = 0; i < pendingPluginExecutionCommands.size(); i++) { | ||||
|             ExecutionCommand executionCommand = pendingPluginExecutionCommands.get(i); | ||||
|             if(!executionCommand.shouldNotProcessResults() && executionCommand.pluginPendingIntent != null) { | ||||
|             if (!executionCommand.shouldNotProcessResults() && executionCommand.pluginPendingIntent != null) { | ||||
|                 if (executionCommand.setStateFailed(ExecutionCommand.RESULT_CODE_CANCELED, this.getString(com.termux.shared.R.string.error_execution_cancelled), null)) { | ||||
|                     PluginUtils.processPluginExecutionCommandResult(this, LOG_TAG, executionCommand); | ||||
|                 } | ||||
| @@ -316,7 +316,7 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas | ||||
|  | ||||
|     /** Process action to release Power and Wi-Fi WakeLocks. */ | ||||
|     private void actionReleaseWakeLock(boolean updateNotification) { | ||||
|         if (mWakeLock == null && mWifiLock == null){ | ||||
|         if (mWakeLock == null && mWifiLock == null) { | ||||
|             Logger.logDebug(LOG_TAG, "Ignoring releasing WakeLocks since none are already held"); | ||||
|             return; | ||||
|         } | ||||
| @@ -333,7 +333,7 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas | ||||
|             mWifiLock = null; | ||||
|         } | ||||
|  | ||||
|         if(updateNotification) | ||||
|         if (updateNotification) | ||||
|             updateNotification(); | ||||
|  | ||||
|         Logger.logDebug(LOG_TAG, "WakeLocks released successfully"); | ||||
| @@ -342,7 +342,7 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas | ||||
|     /** Process {@link TERMUX_SERVICE#ACTION_SERVICE_EXECUTE} intent to execute a shell command in | ||||
|      * a foreground TermuxSession or in a background TermuxTask. */ | ||||
|     private void actionServiceExecute(Intent intent) { | ||||
|         if (intent == null){ | ||||
|         if (intent == null) { | ||||
|             Logger.logError(LOG_TAG, "Ignoring null intent to actionServiceExecute"); | ||||
|             return; | ||||
|         } | ||||
| @@ -351,7 +351,7 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas | ||||
|  | ||||
|         executionCommand.executableUri = intent.getData(); | ||||
|  | ||||
|         if(executionCommand.executableUri != null) { | ||||
|         if (executionCommand.executableUri != null) { | ||||
|             executionCommand.executable = executionCommand.executableUri.getPath(); | ||||
|             executionCommand.arguments = intent.getStringArrayExtra(TERMUX_SERVICE.EXTRA_ARGUMENTS); | ||||
|         } | ||||
| @@ -408,7 +408,7 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas | ||||
|             return null; | ||||
|         } | ||||
|  | ||||
|         if(Logger.getLogLevel() >= Logger.LOG_LEVEL_VERBOSE) | ||||
|         if (Logger.getLogLevel() >= Logger.LOG_LEVEL_VERBOSE) | ||||
|             Logger.logVerbose(LOG_TAG, executionCommand.toString()); | ||||
|  | ||||
|         TermuxTask newTermuxTask = TermuxTask.execute(this, executionCommand, this, false); | ||||
| @@ -421,7 +421,7 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas | ||||
|  | ||||
|         // Remove the execution command from the pending plugin execution commands list since it has | ||||
|         // now been processed | ||||
|         if(executionCommand.isPluginExecutionCommand) | ||||
|         if (executionCommand.isPluginExecutionCommand) | ||||
|             mPendingPluginExecutionCommands.remove(executionCommand); | ||||
|  | ||||
|         updateNotification(); | ||||
| @@ -433,13 +433,13 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas | ||||
|     @Override | ||||
|     public void onTermuxTaskExited(final TermuxTask termuxTask) { | ||||
|         mHandler.post(() -> { | ||||
|             if(termuxTask != null) { | ||||
|             if (termuxTask != null) { | ||||
|                 ExecutionCommand executionCommand = termuxTask.getExecutionCommand(); | ||||
|  | ||||
|                 Logger.logVerbose(LOG_TAG, "The onTermuxTaskExited() callback called for \"" + executionCommand.getCommandIdAndLabelLogString() + "\" TermuxTask command"); | ||||
|  | ||||
|                 // If the execution command was started for a plugin, then process the results | ||||
|                 if(executionCommand != null && executionCommand.isPluginExecutionCommand) | ||||
|                 if (executionCommand != null && executionCommand.isPluginExecutionCommand) | ||||
|                     PluginUtils.processPluginExecutionCommandResult(this, LOG_TAG, executionCommand); | ||||
|  | ||||
|                 mTermuxTasks.remove(termuxTask); | ||||
| @@ -495,7 +495,7 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas | ||||
|             return null; | ||||
|         } | ||||
|  | ||||
|         if(Logger.getLogLevel() >= Logger.LOG_LEVEL_VERBOSE) | ||||
|         if (Logger.getLogLevel() >= Logger.LOG_LEVEL_VERBOSE) | ||||
|             Logger.logVerbose(LOG_TAG, executionCommand.toString()); | ||||
|  | ||||
|         // If the execution command was started for a plugin, only then will the stdout be set | ||||
| @@ -511,12 +511,12 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas | ||||
|  | ||||
|         // Remove the execution command from the pending plugin execution commands list since it has | ||||
|         // now been processed | ||||
|         if(executionCommand.isPluginExecutionCommand) | ||||
|         if (executionCommand.isPluginExecutionCommand) | ||||
|             mPendingPluginExecutionCommands.remove(executionCommand); | ||||
|  | ||||
|         // Notify {@link TermuxSessionsListViewController} that sessions list has been updated if | ||||
|         // activity in is foreground | ||||
|         if(mTermuxSessionClient != null) | ||||
|         if (mTermuxSessionClient != null) | ||||
|             mTermuxSessionClient.termuxSessionListNotifyUpdated(); | ||||
|  | ||||
|         updateNotification(); | ||||
| @@ -529,7 +529,7 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas | ||||
|     public synchronized int removeTermuxSession(TerminalSession sessionToRemove) { | ||||
|         int index = getIndexOfSession(sessionToRemove); | ||||
|  | ||||
|         if(index >= 0) | ||||
|         if (index >= 0) | ||||
|             mTermuxSessions.get(index).finish(); | ||||
|  | ||||
|         return index; | ||||
| @@ -538,20 +538,20 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas | ||||
|     /** Callback received when a {@link TermuxSession} finishes. */ | ||||
|     @Override | ||||
|     public void onTermuxSessionExited(final TermuxSession termuxSession) { | ||||
|         if(termuxSession != null) { | ||||
|         if (termuxSession != null) { | ||||
|             ExecutionCommand executionCommand = termuxSession.getExecutionCommand(); | ||||
|  | ||||
|             Logger.logVerbose(LOG_TAG, "The onTermuxSessionExited() callback called for \"" + executionCommand.getCommandIdAndLabelLogString() + "\" TermuxSession command"); | ||||
|  | ||||
|             // If the execution command was started for a plugin, then process the results | ||||
|             if(executionCommand != null && executionCommand.isPluginExecutionCommand) | ||||
|             if (executionCommand != null && executionCommand.isPluginExecutionCommand) | ||||
|                 PluginUtils.processPluginExecutionCommandResult(this, LOG_TAG, executionCommand); | ||||
|  | ||||
|             mTermuxSessions.remove(termuxSession); | ||||
|  | ||||
|             // Notify {@link TermuxSessionsListViewController} that sessions list has been updated if | ||||
|             // activity in is foreground | ||||
|             if(mTermuxSessionClient != null) | ||||
|             if (mTermuxSessionClient != null) | ||||
|                 mTermuxSessionClient.termuxSessionListNotifyUpdated(); | ||||
|         } | ||||
|  | ||||
| @@ -575,22 +575,22 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas | ||||
|         switch (sessionAction) { | ||||
|             case TERMUX_SERVICE.VALUE_EXTRA_SESSION_ACTION_SWITCH_TO_NEW_SESSION_AND_OPEN_ACTIVITY: | ||||
|                 setCurrentStoredTerminalSession(newTerminalSession); | ||||
|                 if(mTermuxSessionClient != null) | ||||
|                 if (mTermuxSessionClient != null) | ||||
|                     mTermuxSessionClient.setCurrentSession(newTerminalSession); | ||||
|                 startTermuxActivity(); | ||||
|                 break; | ||||
|             case TERMUX_SERVICE.VALUE_EXTRA_SESSION_ACTION_KEEP_CURRENT_SESSION_AND_OPEN_ACTIVITY: | ||||
|                 if(getTermuxSessionsSize() == 1) | ||||
|                 if (getTermuxSessionsSize() == 1) | ||||
|                     setCurrentStoredTerminalSession(newTerminalSession); | ||||
|                 startTermuxActivity(); | ||||
|                 break; | ||||
|             case TERMUX_SERVICE.VALUE_EXTRA_SESSION_ACTION_SWITCH_TO_NEW_SESSION_AND_DONT_OPEN_ACTIVITY: | ||||
|                 setCurrentStoredTerminalSession(newTerminalSession); | ||||
|                 if(mTermuxSessionClient != null) | ||||
|                 if (mTermuxSessionClient != null) | ||||
|                     mTermuxSessionClient.setCurrentSession(newTerminalSession); | ||||
|                 break; | ||||
|             case TERMUX_SERVICE.VALUE_EXTRA_SESSION_ACTION_KEEP_CURRENT_SESSION_AND_DONT_OPEN_ACTIVITY: | ||||
|                 if(getTermuxSessionsSize() == 1) | ||||
|                 if (getTermuxSessionsSize() == 1) | ||||
|                     setCurrentStoredTerminalSession(newTerminalSession); | ||||
|                 break; | ||||
|             default: | ||||
| @@ -605,7 +605,7 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas | ||||
|         // For android >= 10, apps require Display over other apps permission to start foreground activities | ||||
|         // from background (services). If it is not granted, then TermuxSessions that are started will | ||||
|         // show in Termux notification but will not run until user manually clicks the notification. | ||||
|         if(PermissionUtils.validateDisplayOverOtherAppsPermissionForPostAndroid10(this)) { | ||||
|         if (PermissionUtils.validateDisplayOverOtherAppsPermissionForPostAndroid10(this)) { | ||||
|             TermuxActivity.startTermuxActivity(this); | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -43,7 +43,7 @@ public class ExtraKeysInfo { | ||||
|  | ||||
|                 ExtraKeyButton button; | ||||
|  | ||||
|                 if(! jobject.has("popup")) { | ||||
|                 if (! jobject.has("popup")) { | ||||
|                     // no popup | ||||
|                     button = new ExtraKeyButton(getSelectedCharMap(), jobject); | ||||
|                 } else { | ||||
| @@ -63,10 +63,10 @@ public class ExtraKeysInfo { | ||||
|      */ | ||||
|     private static JSONObject normalizeKeyConfig(Object key) throws JSONException { | ||||
|         JSONObject jobject; | ||||
|         if(key instanceof String) { | ||||
|         if (key instanceof String) { | ||||
|             jobject = new JSONObject(); | ||||
|             jobject.put("key", key); | ||||
|         } else if(key instanceof JSONObject) { | ||||
|         } else if (key instanceof JSONObject) { | ||||
|             jobject = (JSONObject) key; | ||||
|         } else { | ||||
|             throw new JSONException("An key in the extra-key matrix must be a string or an object"); | ||||
| @@ -84,7 +84,7 @@ public class ExtraKeysInfo { | ||||
|      */ | ||||
|     static class CleverMap<K,V> extends HashMap<K,V> { | ||||
|         V get(K key, V defaultValue) { | ||||
|             if(containsKey(key)) | ||||
|             if (containsKey(key)) | ||||
|                 return get(key); | ||||
|             else | ||||
|                 return defaultValue; | ||||
|   | ||||
| @@ -55,7 +55,7 @@ public class PluginUtils { | ||||
|  | ||||
|         logTag = DataUtils.getDefaultIfNull(logTag, LOG_TAG); | ||||
|  | ||||
|         if(!executionCommand.hasExecuted()) { | ||||
|         if (!executionCommand.hasExecuted()) { | ||||
|             Logger.logWarn(logTag, "Ignoring call to processPluginExecutionCommandResult() since the execution command state is not higher than the ExecutionState.EXECUTED"); | ||||
|             return; | ||||
|         } | ||||
| @@ -66,7 +66,7 @@ public class PluginUtils { | ||||
|  | ||||
|         // If isPluginExecutionCommand is true and pluginPendingIntent is not null, then | ||||
|         // send pluginPendingIntent to its creator with the result | ||||
|         if(executionCommand.isPluginExecutionCommand && executionCommand.pluginPendingIntent != null) { | ||||
|         if (executionCommand.isPluginExecutionCommand && executionCommand.pluginPendingIntent != null) { | ||||
|             String errmsg = executionCommand.errmsg; | ||||
|  | ||||
|             //Combine errmsg and stacktraces | ||||
| @@ -78,7 +78,7 @@ public class PluginUtils { | ||||
|             result = sendPluginExecutionCommandResultPendingIntent(context, logTag, executionCommand.getCommandIdAndLabelLogString(), executionCommand.stdout, executionCommand.stderr, executionCommand.exitCode, executionCommand.errCode, errmsg, executionCommand.pluginPendingIntent); | ||||
|         } | ||||
|  | ||||
|         if(!executionCommand.isStateFailed() && result) | ||||
|         if (!executionCommand.isStateFailed() && result) | ||||
|             executionCommand.setState(ExecutionCommand.ExecutionState.SUCCESS); | ||||
|     } | ||||
|  | ||||
| @@ -109,11 +109,11 @@ public class PluginUtils { | ||||
|      *                          is {@code false}. | ||||
|      */ | ||||
|     public static void processPluginExecutionCommandError(final Context context, String logTag, final ExecutionCommand executionCommand, boolean forceNotification) { | ||||
|         if(context == null || executionCommand == null) return; | ||||
|         if (context == null || executionCommand == null) return; | ||||
|  | ||||
|         logTag = DataUtils.getDefaultIfNull(logTag, LOG_TAG); | ||||
|  | ||||
|         if(!executionCommand.isStateFailed()) { | ||||
|         if (!executionCommand.isStateFailed()) { | ||||
|             Logger.logWarn(logTag, "Ignoring call to processPluginExecutionCommandError() since the execution command is not in ExecutionState.FAILED"); | ||||
|             return; | ||||
|         } | ||||
| @@ -124,7 +124,7 @@ public class PluginUtils { | ||||
|  | ||||
|         // If isPluginExecutionCommand is true and pluginPendingIntent is not null, then | ||||
|         // send pluginPendingIntent to its creator with the errors | ||||
|         if(executionCommand.isPluginExecutionCommand && executionCommand.pluginPendingIntent != null) { | ||||
|         if (executionCommand.isPluginExecutionCommand && executionCommand.pluginPendingIntent != null) { | ||||
|             String errmsg = executionCommand.errmsg; | ||||
|  | ||||
|             //Combine errmsg and stacktraces | ||||
| @@ -169,12 +169,12 @@ public class PluginUtils { | ||||
|  | ||||
|         // Build the notification | ||||
|         Notification.Builder builder = getPluginCommandErrorsNotificationBuilder(context, title, notificationText, notificationText, pendingIntent, NotificationUtils.NOTIFICATION_MODE_VIBRATE); | ||||
|         if(builder == null)  return; | ||||
|         if (builder == null)  return; | ||||
|  | ||||
|         // Send the notification | ||||
|         int nextNotificationId = NotificationUtils.getNextNotificationId(context); | ||||
|         NotificationManager notificationManager = NotificationUtils.getNotificationManager(context); | ||||
|         if(notificationManager != null) | ||||
|         if (notificationManager != null) | ||||
|             notificationManager.notify(nextNotificationId, builder.build()); | ||||
|  | ||||
|     } | ||||
| @@ -196,7 +196,7 @@ public class PluginUtils { | ||||
|      * @return Returns {@code true} if pluginPendingIntent was successfully send, otherwise [@code false}. | ||||
|      */ | ||||
|     public static boolean sendPluginExecutionCommandResultPendingIntent(Context context, String logTag, String label, String stdout, String stderr, Integer exitCode, Integer errCode, String errmsg, PendingIntent pluginPendingIntent) { | ||||
|         if(context == null || pluginPendingIntent == null) return false; | ||||
|         if (context == null || pluginPendingIntent == null) return false; | ||||
|  | ||||
|         logTag = DataUtils.getDefaultIfNull(logTag, LOG_TAG); | ||||
|  | ||||
| @@ -209,7 +209,7 @@ public class PluginUtils { | ||||
|         String stderrOriginalLength = (stderr == null) ? null: String.valueOf(stderr.length()); | ||||
|  | ||||
|         // Truncate stdout and stdout to max TRANSACTION_SIZE_LIMIT_IN_BYTES | ||||
|         if(stderr == null || stderr.isEmpty()) { | ||||
|         if (stderr == null || stderr.isEmpty()) { | ||||
|             truncatedStdout = DataUtils.getTruncatedCommandOutput(stdout, DataUtils.TRANSACTION_SIZE_LIMIT_IN_BYTES, false, false, false); | ||||
|         } else if (stdout == null || stdout.isEmpty()) { | ||||
|             truncatedStderr = DataUtils.getTruncatedCommandOutput(stderr, DataUtils.TRANSACTION_SIZE_LIMIT_IN_BYTES, false, false, false); | ||||
| @@ -218,12 +218,12 @@ public class PluginUtils { | ||||
|             truncatedStderr = DataUtils.getTruncatedCommandOutput(stderr, DataUtils.TRANSACTION_SIZE_LIMIT_IN_BYTES / 2, false, false, false); | ||||
|         } | ||||
|  | ||||
|         if(truncatedStdout != null && truncatedStdout.length() < stdout.length()){ | ||||
|         if (truncatedStdout != null && truncatedStdout.length() < stdout.length()) { | ||||
|             Logger.logWarn(logTag, "Execution Result for Execution Command \"" + label +  "\" stdout length truncated from " + stdoutOriginalLength + " to " + truncatedStdout.length()); | ||||
|             stdout = truncatedStdout; | ||||
|         } | ||||
|  | ||||
|         if(truncatedStderr != null && truncatedStderr.length() < stderr.length()){ | ||||
|         if (truncatedStderr != null && truncatedStderr.length() < stderr.length()) { | ||||
|             Logger.logWarn(logTag, "Execution Result for Execution Command \"" + label +  "\" stderr length truncated from " + stderrOriginalLength + " to " + truncatedStderr.length()); | ||||
|             stderr = truncatedStderr; | ||||
|         } | ||||
| @@ -233,7 +233,7 @@ public class PluginUtils { | ||||
|         // Truncate errmsg to max TRANSACTION_SIZE_LIMIT_IN_BYTES / 4 | ||||
|         // trim from end to preserve start of stacktraces | ||||
|         String truncatedErrmsg = DataUtils.getTruncatedCommandOutput(errmsg, DataUtils.TRANSACTION_SIZE_LIMIT_IN_BYTES / 4, true, false, false); | ||||
|         if(truncatedErrmsg != null && truncatedErrmsg.length() < errmsg.length()){ | ||||
|         if (truncatedErrmsg != null && truncatedErrmsg.length() < errmsg.length()) { | ||||
|             Logger.logWarn(logTag, "Execution Result for Execution Command \"" + label +  "\" errmsg length truncated from " + errmsgOriginalLength + " to " + truncatedErrmsg.length()); | ||||
|             errmsg = truncatedErrmsg; | ||||
|         } | ||||
| @@ -282,7 +282,7 @@ public class PluginUtils { | ||||
|             TermuxConstants.TERMUX_PLUGIN_COMMAND_ERRORS_NOTIFICATION_CHANNEL_ID, Notification.PRIORITY_HIGH, | ||||
|             title, notificationText, notificationBigText, pendingIntent, notificationMode); | ||||
|  | ||||
|         if(builder == null)  return null; | ||||
|         if (builder == null)  return null; | ||||
|  | ||||
|         // Enable timestamp | ||||
|         builder.setShowWhen(true); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user