Replace "if(" with "if ("

This commit is contained in:
agnostic-apollo
2021-04-12 14:32:02 +05:00
parent 0cd7cb8162
commit 24a5493ea5
11 changed files with 107 additions and 105 deletions

View File

@@ -153,7 +153,7 @@ clean {
} }
} }
task downloadBootstraps(){ task downloadBootstraps() {
doLast { doLast {
def version = "2021.02.19-r1" def version = "2021.02.19-r1"
downloadBootstrap("aarch64", "1e3d80bd8cc8771715845ab4a1e67fc125d84c4deda3a1a435116fe4d1f86160", version) downloadBootstrap("aarch64", "1e3d80bd8cc8771715845ab4a1e67fc125d84c4deda3a1a435116fe4d1f86160", version)

View File

@@ -178,7 +178,7 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas
// Since we cannot rely on {@link TermuxActivity.onDestroy()} to always complete, // 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 // we unset clients here as well if it failed, so that we do not leave service and session
// clients with references to the activity. // clients with references to the activity.
if(mTermuxSessionClient != null) if (mTermuxSessionClient != null)
unsetTermuxSessionClient(); unsetTermuxSessionClient();
return false; return false;
} }
@@ -258,14 +258,14 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas
List<TermuxTask> termuxTasks = new ArrayList<>(mTermuxTasks); List<TermuxTask> termuxTasks = new ArrayList<>(mTermuxTasks);
for (int i = 0; i < termuxTasks.size(); i++) { for (int i = 0; i < termuxTasks.size(); i++) {
ExecutionCommand executionCommand = termuxTasks.get(i).getExecutionCommand(); ExecutionCommand executionCommand = termuxTasks.get(i).getExecutionCommand();
if(executionCommand.isPluginExecutionCommand && executionCommand.pluginPendingIntent != null) if (executionCommand.isPluginExecutionCommand && executionCommand.pluginPendingIntent != null)
termuxTasks.get(i).killIfExecuting(this, true); termuxTasks.get(i).killIfExecuting(this, true);
} }
List<ExecutionCommand> pendingPluginExecutionCommands = new ArrayList<>(mPendingPluginExecutionCommands); List<ExecutionCommand> pendingPluginExecutionCommands = new ArrayList<>(mPendingPluginExecutionCommands);
for (int i = 0; i < pendingPluginExecutionCommands.size(); i++) { for (int i = 0; i < pendingPluginExecutionCommands.size(); i++) {
ExecutionCommand executionCommand = pendingPluginExecutionCommands.get(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)) { if (executionCommand.setStateFailed(ExecutionCommand.RESULT_CODE_CANCELED, this.getString(com.termux.shared.R.string.error_execution_cancelled), null)) {
PluginUtils.processPluginExecutionCommandResult(this, LOG_TAG, executionCommand); 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. */ /** Process action to release Power and Wi-Fi WakeLocks. */
private void actionReleaseWakeLock(boolean updateNotification) { 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"); Logger.logDebug(LOG_TAG, "Ignoring releasing WakeLocks since none are already held");
return; return;
} }
@@ -333,7 +333,7 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas
mWifiLock = null; mWifiLock = null;
} }
if(updateNotification) if (updateNotification)
updateNotification(); updateNotification();
Logger.logDebug(LOG_TAG, "WakeLocks released successfully"); 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 /** Process {@link TERMUX_SERVICE#ACTION_SERVICE_EXECUTE} intent to execute a shell command in
* a foreground TermuxSession or in a background TermuxTask. */ * a foreground TermuxSession or in a background TermuxTask. */
private void actionServiceExecute(Intent intent) { private void actionServiceExecute(Intent intent) {
if (intent == null){ if (intent == null) {
Logger.logError(LOG_TAG, "Ignoring null intent to actionServiceExecute"); Logger.logError(LOG_TAG, "Ignoring null intent to actionServiceExecute");
return; return;
} }
@@ -351,7 +351,7 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas
executionCommand.executableUri = intent.getData(); executionCommand.executableUri = intent.getData();
if(executionCommand.executableUri != null) { if (executionCommand.executableUri != null) {
executionCommand.executable = executionCommand.executableUri.getPath(); executionCommand.executable = executionCommand.executableUri.getPath();
executionCommand.arguments = intent.getStringArrayExtra(TERMUX_SERVICE.EXTRA_ARGUMENTS); executionCommand.arguments = intent.getStringArrayExtra(TERMUX_SERVICE.EXTRA_ARGUMENTS);
} }
@@ -408,7 +408,7 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas
return null; return null;
} }
if(Logger.getLogLevel() >= Logger.LOG_LEVEL_VERBOSE) if (Logger.getLogLevel() >= Logger.LOG_LEVEL_VERBOSE)
Logger.logVerbose(LOG_TAG, executionCommand.toString()); Logger.logVerbose(LOG_TAG, executionCommand.toString());
TermuxTask newTermuxTask = TermuxTask.execute(this, executionCommand, this, false); 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 // Remove the execution command from the pending plugin execution commands list since it has
// now been processed // now been processed
if(executionCommand.isPluginExecutionCommand) if (executionCommand.isPluginExecutionCommand)
mPendingPluginExecutionCommands.remove(executionCommand); mPendingPluginExecutionCommands.remove(executionCommand);
updateNotification(); updateNotification();
@@ -433,13 +433,13 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas
@Override @Override
public void onTermuxTaskExited(final TermuxTask termuxTask) { public void onTermuxTaskExited(final TermuxTask termuxTask) {
mHandler.post(() -> { mHandler.post(() -> {
if(termuxTask != null) { if (termuxTask != null) {
ExecutionCommand executionCommand = termuxTask.getExecutionCommand(); ExecutionCommand executionCommand = termuxTask.getExecutionCommand();
Logger.logVerbose(LOG_TAG, "The onTermuxTaskExited() callback called for \"" + executionCommand.getCommandIdAndLabelLogString() + "\" TermuxTask command"); 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 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); PluginUtils.processPluginExecutionCommandResult(this, LOG_TAG, executionCommand);
mTermuxTasks.remove(termuxTask); mTermuxTasks.remove(termuxTask);
@@ -495,7 +495,7 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas
return null; return null;
} }
if(Logger.getLogLevel() >= Logger.LOG_LEVEL_VERBOSE) if (Logger.getLogLevel() >= Logger.LOG_LEVEL_VERBOSE)
Logger.logVerbose(LOG_TAG, executionCommand.toString()); Logger.logVerbose(LOG_TAG, executionCommand.toString());
// If the execution command was started for a plugin, only then will the stdout be set // 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 // Remove the execution command from the pending plugin execution commands list since it has
// now been processed // now been processed
if(executionCommand.isPluginExecutionCommand) if (executionCommand.isPluginExecutionCommand)
mPendingPluginExecutionCommands.remove(executionCommand); mPendingPluginExecutionCommands.remove(executionCommand);
// Notify {@link TermuxSessionsListViewController} that sessions list has been updated if // Notify {@link TermuxSessionsListViewController} that sessions list has been updated if
// activity in is foreground // activity in is foreground
if(mTermuxSessionClient != null) if (mTermuxSessionClient != null)
mTermuxSessionClient.termuxSessionListNotifyUpdated(); mTermuxSessionClient.termuxSessionListNotifyUpdated();
updateNotification(); updateNotification();
@@ -529,7 +529,7 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas
public synchronized int removeTermuxSession(TerminalSession sessionToRemove) { public synchronized int removeTermuxSession(TerminalSession sessionToRemove) {
int index = getIndexOfSession(sessionToRemove); int index = getIndexOfSession(sessionToRemove);
if(index >= 0) if (index >= 0)
mTermuxSessions.get(index).finish(); mTermuxSessions.get(index).finish();
return index; return index;
@@ -538,20 +538,20 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas
/** Callback received when a {@link TermuxSession} finishes. */ /** Callback received when a {@link TermuxSession} finishes. */
@Override @Override
public void onTermuxSessionExited(final TermuxSession termuxSession) { public void onTermuxSessionExited(final TermuxSession termuxSession) {
if(termuxSession != null) { if (termuxSession != null) {
ExecutionCommand executionCommand = termuxSession.getExecutionCommand(); ExecutionCommand executionCommand = termuxSession.getExecutionCommand();
Logger.logVerbose(LOG_TAG, "The onTermuxSessionExited() callback called for \"" + executionCommand.getCommandIdAndLabelLogString() + "\" TermuxSession command"); 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 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); PluginUtils.processPluginExecutionCommandResult(this, LOG_TAG, executionCommand);
mTermuxSessions.remove(termuxSession); mTermuxSessions.remove(termuxSession);
// Notify {@link TermuxSessionsListViewController} that sessions list has been updated if // Notify {@link TermuxSessionsListViewController} that sessions list has been updated if
// activity in is foreground // activity in is foreground
if(mTermuxSessionClient != null) if (mTermuxSessionClient != null)
mTermuxSessionClient.termuxSessionListNotifyUpdated(); mTermuxSessionClient.termuxSessionListNotifyUpdated();
} }
@@ -575,22 +575,22 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas
switch (sessionAction) { switch (sessionAction) {
case TERMUX_SERVICE.VALUE_EXTRA_SESSION_ACTION_SWITCH_TO_NEW_SESSION_AND_OPEN_ACTIVITY: case TERMUX_SERVICE.VALUE_EXTRA_SESSION_ACTION_SWITCH_TO_NEW_SESSION_AND_OPEN_ACTIVITY:
setCurrentStoredTerminalSession(newTerminalSession); setCurrentStoredTerminalSession(newTerminalSession);
if(mTermuxSessionClient != null) if (mTermuxSessionClient != null)
mTermuxSessionClient.setCurrentSession(newTerminalSession); mTermuxSessionClient.setCurrentSession(newTerminalSession);
startTermuxActivity(); startTermuxActivity();
break; break;
case TERMUX_SERVICE.VALUE_EXTRA_SESSION_ACTION_KEEP_CURRENT_SESSION_AND_OPEN_ACTIVITY: case TERMUX_SERVICE.VALUE_EXTRA_SESSION_ACTION_KEEP_CURRENT_SESSION_AND_OPEN_ACTIVITY:
if(getTermuxSessionsSize() == 1) if (getTermuxSessionsSize() == 1)
setCurrentStoredTerminalSession(newTerminalSession); setCurrentStoredTerminalSession(newTerminalSession);
startTermuxActivity(); startTermuxActivity();
break; break;
case TERMUX_SERVICE.VALUE_EXTRA_SESSION_ACTION_SWITCH_TO_NEW_SESSION_AND_DONT_OPEN_ACTIVITY: case TERMUX_SERVICE.VALUE_EXTRA_SESSION_ACTION_SWITCH_TO_NEW_SESSION_AND_DONT_OPEN_ACTIVITY:
setCurrentStoredTerminalSession(newTerminalSession); setCurrentStoredTerminalSession(newTerminalSession);
if(mTermuxSessionClient != null) if (mTermuxSessionClient != null)
mTermuxSessionClient.setCurrentSession(newTerminalSession); mTermuxSessionClient.setCurrentSession(newTerminalSession);
break; break;
case TERMUX_SERVICE.VALUE_EXTRA_SESSION_ACTION_KEEP_CURRENT_SESSION_AND_DONT_OPEN_ACTIVITY: case TERMUX_SERVICE.VALUE_EXTRA_SESSION_ACTION_KEEP_CURRENT_SESSION_AND_DONT_OPEN_ACTIVITY:
if(getTermuxSessionsSize() == 1) if (getTermuxSessionsSize() == 1)
setCurrentStoredTerminalSession(newTerminalSession); setCurrentStoredTerminalSession(newTerminalSession);
break; break;
default: 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 // 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 // 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. // 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); TermuxActivity.startTermuxActivity(this);
} }
} }

View File

@@ -43,7 +43,7 @@ public class ExtraKeysInfo {
ExtraKeyButton button; ExtraKeyButton button;
if(! jobject.has("popup")) { if (! jobject.has("popup")) {
// no popup // no popup
button = new ExtraKeyButton(getSelectedCharMap(), jobject); button = new ExtraKeyButton(getSelectedCharMap(), jobject);
} else { } else {
@@ -63,10 +63,10 @@ public class ExtraKeysInfo {
*/ */
private static JSONObject normalizeKeyConfig(Object key) throws JSONException { private static JSONObject normalizeKeyConfig(Object key) throws JSONException {
JSONObject jobject; JSONObject jobject;
if(key instanceof String) { if (key instanceof String) {
jobject = new JSONObject(); jobject = new JSONObject();
jobject.put("key", key); jobject.put("key", key);
} else if(key instanceof JSONObject) { } else if (key instanceof JSONObject) {
jobject = (JSONObject) key; jobject = (JSONObject) key;
} else { } else {
throw new JSONException("An key in the extra-key matrix must be a string or an object"); 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> { static class CleverMap<K,V> extends HashMap<K,V> {
V get(K key, V defaultValue) { V get(K key, V defaultValue) {
if(containsKey(key)) if (containsKey(key))
return get(key); return get(key);
else else
return defaultValue; return defaultValue;

View File

@@ -55,7 +55,7 @@ public class PluginUtils {
logTag = DataUtils.getDefaultIfNull(logTag, LOG_TAG); 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"); Logger.logWarn(logTag, "Ignoring call to processPluginExecutionCommandResult() since the execution command state is not higher than the ExecutionState.EXECUTED");
return; return;
} }
@@ -66,7 +66,7 @@ public class PluginUtils {
// If isPluginExecutionCommand is true and pluginPendingIntent is not null, then // If isPluginExecutionCommand is true and pluginPendingIntent is not null, then
// send pluginPendingIntent to its creator with the result // send pluginPendingIntent to its creator with the result
if(executionCommand.isPluginExecutionCommand && executionCommand.pluginPendingIntent != null) { if (executionCommand.isPluginExecutionCommand && executionCommand.pluginPendingIntent != null) {
String errmsg = executionCommand.errmsg; String errmsg = executionCommand.errmsg;
//Combine errmsg and stacktraces //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); 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); executionCommand.setState(ExecutionCommand.ExecutionState.SUCCESS);
} }
@@ -109,11 +109,11 @@ public class PluginUtils {
* is {@code false}. * is {@code false}.
*/ */
public static void processPluginExecutionCommandError(final Context context, String logTag, final ExecutionCommand executionCommand, boolean forceNotification) { 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); 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"); Logger.logWarn(logTag, "Ignoring call to processPluginExecutionCommandError() since the execution command is not in ExecutionState.FAILED");
return; return;
} }
@@ -124,7 +124,7 @@ public class PluginUtils {
// If isPluginExecutionCommand is true and pluginPendingIntent is not null, then // If isPluginExecutionCommand is true and pluginPendingIntent is not null, then
// send pluginPendingIntent to its creator with the errors // send pluginPendingIntent to its creator with the errors
if(executionCommand.isPluginExecutionCommand && executionCommand.pluginPendingIntent != null) { if (executionCommand.isPluginExecutionCommand && executionCommand.pluginPendingIntent != null) {
String errmsg = executionCommand.errmsg; String errmsg = executionCommand.errmsg;
//Combine errmsg and stacktraces //Combine errmsg and stacktraces
@@ -169,12 +169,12 @@ public class PluginUtils {
// Build the notification // Build the notification
Notification.Builder builder = getPluginCommandErrorsNotificationBuilder(context, title, notificationText, notificationText, pendingIntent, NotificationUtils.NOTIFICATION_MODE_VIBRATE); Notification.Builder builder = getPluginCommandErrorsNotificationBuilder(context, title, notificationText, notificationText, pendingIntent, NotificationUtils.NOTIFICATION_MODE_VIBRATE);
if(builder == null) return; if (builder == null) return;
// Send the notification // Send the notification
int nextNotificationId = NotificationUtils.getNextNotificationId(context); int nextNotificationId = NotificationUtils.getNextNotificationId(context);
NotificationManager notificationManager = NotificationUtils.getNotificationManager(context); NotificationManager notificationManager = NotificationUtils.getNotificationManager(context);
if(notificationManager != null) if (notificationManager != null)
notificationManager.notify(nextNotificationId, builder.build()); notificationManager.notify(nextNotificationId, builder.build());
} }
@@ -196,7 +196,7 @@ public class PluginUtils {
* @return Returns {@code true} if pluginPendingIntent was successfully send, otherwise [@code false}. * @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) { 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); logTag = DataUtils.getDefaultIfNull(logTag, LOG_TAG);
@@ -209,7 +209,7 @@ public class PluginUtils {
String stderrOriginalLength = (stderr == null) ? null: String.valueOf(stderr.length()); String stderrOriginalLength = (stderr == null) ? null: String.valueOf(stderr.length());
// Truncate stdout and stdout to max TRANSACTION_SIZE_LIMIT_IN_BYTES // 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); truncatedStdout = DataUtils.getTruncatedCommandOutput(stdout, DataUtils.TRANSACTION_SIZE_LIMIT_IN_BYTES, false, false, false);
} else if (stdout == null || stdout.isEmpty()) { } else if (stdout == null || stdout.isEmpty()) {
truncatedStderr = DataUtils.getTruncatedCommandOutput(stderr, DataUtils.TRANSACTION_SIZE_LIMIT_IN_BYTES, false, false, false); 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); 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()); Logger.logWarn(logTag, "Execution Result for Execution Command \"" + label + "\" stdout length truncated from " + stdoutOriginalLength + " to " + truncatedStdout.length());
stdout = truncatedStdout; 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()); Logger.logWarn(logTag, "Execution Result for Execution Command \"" + label + "\" stderr length truncated from " + stderrOriginalLength + " to " + truncatedStderr.length());
stderr = truncatedStderr; stderr = truncatedStderr;
} }
@@ -233,7 +233,7 @@ public class PluginUtils {
// Truncate errmsg to max TRANSACTION_SIZE_LIMIT_IN_BYTES / 4 // Truncate errmsg to max TRANSACTION_SIZE_LIMIT_IN_BYTES / 4
// trim from end to preserve start of stacktraces // trim from end to preserve start of stacktraces
String truncatedErrmsg = DataUtils.getTruncatedCommandOutput(errmsg, DataUtils.TRANSACTION_SIZE_LIMIT_IN_BYTES / 4, true, false, false); 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()); Logger.logWarn(logTag, "Execution Result for Execution Command \"" + label + "\" errmsg length truncated from " + errmsgOriginalLength + " to " + truncatedErrmsg.length());
errmsg = truncatedErrmsg; errmsg = truncatedErrmsg;
} }
@@ -282,7 +282,7 @@ public class PluginUtils {
TermuxConstants.TERMUX_PLUGIN_COMMAND_ERRORS_NOTIFICATION_CHANNEL_ID, Notification.PRIORITY_HIGH, TermuxConstants.TERMUX_PLUGIN_COMMAND_ERRORS_NOTIFICATION_CHANNEL_ID, Notification.PRIORITY_HIGH,
title, notificationText, notificationBigText, pendingIntent, notificationMode); title, notificationText, notificationBigText, pendingIntent, notificationMode);
if(builder == null) return null; if (builder == null) return null;
// Enable timestamp // Enable timestamp
builder.setShowWhen(true); builder.setShowWhen(true);

View File

@@ -104,9 +104,9 @@ public class FileAttributes {
} }
public String file() { public String file() {
if(filePath != null) if (filePath != null)
return filePath; return filePath;
else if(fileDescriptor != null) else if (fileDescriptor != null)
return fileDescriptor.toString(); return fileDescriptor.toString();
else else
return null; return null;
@@ -397,7 +397,7 @@ public class FileAttributes {
logString.append("\n").append(fileAttributes.getInodeString()); logString.append("\n").append(fileAttributes.getInodeString());
logString.append("\n").append(fileAttributes.getLinksString()); logString.append("\n").append(fileAttributes.getLinksString());
if(fileAttributes.isBlock() || fileAttributes.isCharacter()) if (fileAttributes.isBlock() || fileAttributes.isCharacter())
logString.append("\n").append(fileAttributes.getDeviceTypeString()); logString.append("\n").append(fileAttributes.getDeviceTypeString());
logString.append("\n").append(fileAttributes.getOwnerString()); logString.append("\n").append(fileAttributes.getOwnerString());

View File

@@ -104,7 +104,7 @@ public class FileUtilsTests {
errmsg = FileUtils.clearDirectory(context, label, testRootDirectoryPath); errmsg = FileUtils.clearDirectory(context, label, testRootDirectoryPath);
assertEqual("Failed to create " + label + " directory file", null, errmsg); assertEqual("Failed to create " + label + " directory file", null, errmsg);
if(!FileUtils.directoryFileExists(testRootDirectoryPath, false)) if (!FileUtils.directoryFileExists(testRootDirectoryPath, false))
throwException("The " + label + " directory file does not exist as expected after creation"); throwException("The " + label + " directory file does not exist as expected after creation");
@@ -124,30 +124,30 @@ public class FileUtilsTests {
label = dir1__sub_dir1_label; path = dir1__sub_dir1_path; label = dir1__sub_dir1_label; path = dir1__sub_dir1_path;
errmsg = FileUtils.createDirectoryFile(context, label, path); errmsg = FileUtils.createDirectoryFile(context, label, path);
assertEqual("Failed to create " + label + " directory file", null, errmsg); assertEqual("Failed to create " + label + " directory file", null, errmsg);
if(!FileUtils.directoryFileExists(path, false)) if (!FileUtils.directoryFileExists(path, false))
throwException("The " + label + " directory file does not exist as expected after creation"); throwException("The " + label + " directory file does not exist as expected after creation");
// Create dir1/sub_reg1 regular file // Create dir1/sub_reg1 regular file
label = dir1__sub_reg1_label; path = dir1__sub_reg1_path; label = dir1__sub_reg1_label; path = dir1__sub_reg1_path;
errmsg = FileUtils.createRegularFile(context, label, path); errmsg = FileUtils.createRegularFile(context, label, path);
assertEqual("Failed to create " + label + " regular file", null, errmsg); assertEqual("Failed to create " + label + " regular file", null, errmsg);
if(!FileUtils.regularFileExists(path, false)) if (!FileUtils.regularFileExists(path, false))
throwException("The " + label + " regular file does not exist as expected after creation"); throwException("The " + label + " regular file does not exist as expected after creation");
// Create dir1/sub_sym1 -> dir2 absolute symlink file // Create dir1/sub_sym1 -> dir2 absolute symlink file
label = dir1__sub_sym1_label; path = dir1__sub_sym1_path; label = dir1__sub_sym1_label; path = dir1__sub_sym1_path;
errmsg = FileUtils.createSymlinkFile(context, label, dir2_path, path); errmsg = FileUtils.createSymlinkFile(context, label, dir2_path, path);
assertEqual("Failed to create " + label + " symlink file", null, errmsg); assertEqual("Failed to create " + label + " symlink file", null, errmsg);
if(!FileUtils.symlinkFileExists(path)) if (!FileUtils.symlinkFileExists(path))
throwException("The " + label + " symlink file does not exist as expected after creation"); throwException("The " + label + " symlink file does not exist as expected after creation");
// Copy dir1/sub_sym1 symlink file to dir1/sub_sym2 // Copy dir1/sub_sym1 symlink file to dir1/sub_sym2
label = dir1__sub_sym2_label; path = dir1__sub_sym2_path; label = dir1__sub_sym2_label; path = dir1__sub_sym2_path;
errmsg = FileUtils.copySymlinkFile(context, label, dir1__sub_sym1_path, path, false); errmsg = FileUtils.copySymlinkFile(context, label, dir1__sub_sym1_path, path, false);
assertEqual("Failed to copy " + dir1__sub_sym1_label + " symlink file to " + label, null, errmsg); assertEqual("Failed to copy " + dir1__sub_sym1_label + " symlink file to " + label, null, errmsg);
if(!FileUtils.symlinkFileExists(path)) if (!FileUtils.symlinkFileExists(path))
throwException("The " + label + " symlink file does not exist as expected after copying it from " + dir1__sub_sym1_label); throwException("The " + label + " symlink file does not exist as expected after copying it from " + dir1__sub_sym1_label);
if(!new File(path).getCanonicalPath().equals(dir2_path)) if (!new File(path).getCanonicalPath().equals(dir2_path))
throwException("The " + label + " symlink file does not point to " + dir2_label); throwException("The " + label + " symlink file does not point to " + dir2_label);
@@ -158,7 +158,7 @@ public class FileUtilsTests {
label = dir2__sub_reg1_label; path = dir2__sub_reg1_path; label = dir2__sub_reg1_label; path = dir2__sub_reg1_path;
errmsg = FileUtils.writeStringToFile(context, label, path, Charset.defaultCharset(), "line1", false); errmsg = FileUtils.writeStringToFile(context, label, path, Charset.defaultCharset(), "line1", false);
assertEqual("Failed to write string to " + label + " file with append mode false", null, errmsg); assertEqual("Failed to write string to " + label + " file with append mode false", null, errmsg);
if(!FileUtils.regularFileExists(path, false)) if (!FileUtils.regularFileExists(path, false))
throwException("The " + label + " file does not exist as expected after writing to it with append mode false"); throwException("The " + label + " file does not exist as expected after writing to it with append mode false");
// Write "line2" to dir2/sub_reg1 regular file // Write "line2" to dir2/sub_reg1 regular file
@@ -175,7 +175,7 @@ public class FileUtilsTests {
label = dir2__sub_reg2_label; path = dir2__sub_reg2_path; label = dir2__sub_reg2_label; path = dir2__sub_reg2_path;
errmsg = FileUtils.copyRegularFile(context, label, dir2__sub_reg1_path, path, false); errmsg = FileUtils.copyRegularFile(context, label, dir2__sub_reg1_path, path, false);
assertEqual("Failed to copy " + dir2__sub_reg1_label + " regular file to " + label, null, errmsg); assertEqual("Failed to copy " + dir2__sub_reg1_label + " regular file to " + label, null, errmsg);
if(!FileUtils.regularFileExists(path, false)) if (!FileUtils.regularFileExists(path, false))
throwException("The " + label + " regular file does not exist as expected after copying it from " + dir2__sub_reg1_label); throwException("The " + label + " regular file does not exist as expected after copying it from " + dir2__sub_reg1_label);
@@ -186,21 +186,21 @@ public class FileUtilsTests {
label = dir3_label; path = dir3_path; label = dir3_label; path = dir3_path;
errmsg = FileUtils.copyDirectoryFile(context, label, dir2_path, path, false); errmsg = FileUtils.copyDirectoryFile(context, label, dir2_path, path, false);
assertEqual("Failed to copy " + dir2_label + " directory file to " + label, null, errmsg); assertEqual("Failed to copy " + dir2_label + " directory file to " + label, null, errmsg);
if(!FileUtils.directoryFileExists(path, false)) if (!FileUtils.directoryFileExists(path, false))
throwException("The " + label + " directory file does not exist as expected after copying it from " + dir2_label); throwException("The " + label + " directory file does not exist as expected after copying it from " + dir2_label);
// Copy dir1 directory file to dir3 again to test overwrite // Copy dir1 directory file to dir3 again to test overwrite
label = dir3_label; path = dir3_path; label = dir3_label; path = dir3_path;
errmsg = FileUtils.copyDirectoryFile(context, label, dir2_path, path, false); errmsg = FileUtils.copyDirectoryFile(context, label, dir2_path, path, false);
assertEqual("Failed to copy " + dir2_label + " directory file to " + label, null, errmsg); assertEqual("Failed to copy " + dir2_label + " directory file to " + label, null, errmsg);
if(!FileUtils.directoryFileExists(path, false)) if (!FileUtils.directoryFileExists(path, false))
throwException("The " + label + " directory file does not exist as expected after copying it from " + dir2_label); throwException("The " + label + " directory file does not exist as expected after copying it from " + dir2_label);
// Move dir3 directory file to dir4 // Move dir3 directory file to dir4
label = dir4_label; path = dir4_path; label = dir4_label; path = dir4_path;
errmsg = FileUtils.moveDirectoryFile(context, label, dir3_path, path, false); errmsg = FileUtils.moveDirectoryFile(context, label, dir3_path, path, false);
assertEqual("Failed to move " + dir3_label + " directory file to " + label, null, errmsg); assertEqual("Failed to move " + dir3_label + " directory file to " + label, null, errmsg);
if(!FileUtils.directoryFileExists(path, false)) if (!FileUtils.directoryFileExists(path, false))
throwException("The " + label + " directory file does not exist as expected after copying it from " + dir3_label); throwException("The " + label + " directory file does not exist as expected after copying it from " + dir3_label);
@@ -211,7 +211,7 @@ public class FileUtilsTests {
label = dir1__sub_sym3_label; path = dir1__sub_sym3_path; label = dir1__sub_sym3_label; path = dir1__sub_sym3_path;
errmsg = FileUtils.createSymlinkFile(context, label, "../dir4", path); errmsg = FileUtils.createSymlinkFile(context, label, "../dir4", path);
assertEqual("Failed to create " + label + " symlink file", null, errmsg); assertEqual("Failed to create " + label + " symlink file", null, errmsg);
if(!FileUtils.symlinkFileExists(path)) if (!FileUtils.symlinkFileExists(path))
throwException("The " + label + " symlink file does not exist as expected after creation"); throwException("The " + label + " symlink file does not exist as expected after creation");
// Create dir1/sub_sym3 -> dirX relative dangling symlink file // Create dir1/sub_sym3 -> dirX relative dangling symlink file
@@ -219,7 +219,7 @@ public class FileUtilsTests {
label = dir1__sub_sym3_label; path = dir1__sub_sym3_path; label = dir1__sub_sym3_label; path = dir1__sub_sym3_path;
errmsg = FileUtils.createSymlinkFile(context, label, "../dirX", path); errmsg = FileUtils.createSymlinkFile(context, label, "../dirX", path);
assertEqual("Failed to create " + label + " symlink file", null, errmsg); assertEqual("Failed to create " + label + " symlink file", null, errmsg);
if(!FileUtils.symlinkFileExists(path)) if (!FileUtils.symlinkFileExists(path))
throwException("The " + label + " dangling symlink file does not exist as expected after creation"); throwException("The " + label + " dangling symlink file does not exist as expected after creation");
@@ -230,13 +230,13 @@ public class FileUtilsTests {
label = dir1__sub_sym2_label; path = dir1__sub_sym2_path; label = dir1__sub_sym2_label; path = dir1__sub_sym2_path;
errmsg = FileUtils.deleteSymlinkFile(context, label, path, false); errmsg = FileUtils.deleteSymlinkFile(context, label, path, false);
assertEqual("Failed to delete " + label + " symlink file", null, errmsg); assertEqual("Failed to delete " + label + " symlink file", null, errmsg);
if(FileUtils.fileExists(path, false)) if (FileUtils.fileExists(path, false))
throwException("The " + label + " symlink file still exist after deletion"); throwException("The " + label + " symlink file still exist after deletion");
// Check if dir2 directory file still exists after deletion of dir1/sub_sym2 since it was a symlink to dir2 // Check if dir2 directory file still exists after deletion of dir1/sub_sym2 since it was a symlink to dir2
// When deleting a symlink file, its target must not be deleted // When deleting a symlink file, its target must not be deleted
label = dir2_label; path = dir2_path; label = dir2_label; path = dir2_path;
if(!FileUtils.directoryFileExists(path, false)) if (!FileUtils.directoryFileExists(path, false))
throwException("The " + label + " directory file has unexpectedly been deleted after deletion of " + dir1__sub_sym2_label); throwException("The " + label + " directory file has unexpectedly been deleted after deletion of " + dir1__sub_sym2_label);
@@ -247,7 +247,7 @@ public class FileUtilsTests {
label = dir1_label; path = dir1_path; label = dir1_label; path = dir1_path;
errmsg = FileUtils.deleteDirectoryFile(context, label, path, false); errmsg = FileUtils.deleteDirectoryFile(context, label, path, false);
assertEqual("Failed to delete " + label + " directory file", null, errmsg); assertEqual("Failed to delete " + label + " directory file", null, errmsg);
if(FileUtils.fileExists(path, false)) if (FileUtils.fileExists(path, false))
throwException("The " + label + " directory file still exist after deletion"); throwException("The " + label + " directory file still exist after deletion");
@@ -255,10 +255,10 @@ public class FileUtilsTests {
// dir1 since there was a dir1/sub_sym1 symlink to dir2 in it // dir1 since there was a dir1/sub_sym1 symlink to dir2 in it
// When deleting a directory, any targets of symlinks must not be deleted when deleting symlink files // When deleting a directory, any targets of symlinks must not be deleted when deleting symlink files
label = dir2_label; path = dir2_path; label = dir2_label; path = dir2_path;
if(!FileUtils.directoryFileExists(path, false)) if (!FileUtils.directoryFileExists(path, false))
throwException("The " + label + " directory file has unexpectedly been deleted after deletion of " + dir1_label); throwException("The " + label + " directory file has unexpectedly been deleted after deletion of " + dir1_label);
label = dir2__sub_reg1_label; path = dir2__sub_reg1_path; label = dir2__sub_reg1_label; path = dir2__sub_reg1_path;
if(!FileUtils.fileExists(path, false)) if (!FileUtils.fileExists(path, false))
throwException("The " + label + " regular file has unexpectedly been deleted after deletion of " + dir1_label); throwException("The " + label + " regular file has unexpectedly been deleted after deletion of " + dir1_label);
@@ -269,7 +269,7 @@ public class FileUtilsTests {
label = dir2__sub_reg1_label; path = dir2__sub_reg1_path; label = dir2__sub_reg1_label; path = dir2__sub_reg1_path;
errmsg = FileUtils.deleteRegularFile(context, label, path, false); errmsg = FileUtils.deleteRegularFile(context, label, path, false);
assertEqual("Failed to delete " + label + " regular file", null, errmsg); assertEqual("Failed to delete " + label + " regular file", null, errmsg);
if(FileUtils.fileExists(path, false)) if (FileUtils.fileExists(path, false))
throwException("The " + label + " regular file still exist after deletion"); throwException("The " + label + " regular file still exist after deletion");
FileUtils.getFileType("/dev/ptmx", false); FileUtils.getFileType("/dev/ptmx", false);

View File

@@ -32,15 +32,15 @@ public class Logger {
public static void logMessage(int logLevel, String tag, String message) { public static void logMessage(int logLevel, String tag, String message) {
if(logLevel == Log.ERROR && CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL) if (logLevel == Log.ERROR && CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL)
Log.e(getFullTag(tag), message); Log.e(getFullTag(tag), message);
else if(logLevel == Log.WARN && CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL) else if (logLevel == Log.WARN && CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL)
Log.w(getFullTag(tag), message); Log.w(getFullTag(tag), message);
else if(logLevel == Log.INFO && CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL) else if (logLevel == Log.INFO && CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL)
Log.i(getFullTag(tag), message); Log.i(getFullTag(tag), message);
else if(logLevel == Log.DEBUG && CURRENT_LOG_LEVEL >= LOG_LEVEL_DEBUG) else if (logLevel == Log.DEBUG && CURRENT_LOG_LEVEL >= LOG_LEVEL_DEBUG)
Log.d(getFullTag(tag), message); Log.d(getFullTag(tag), message);
else if(logLevel == Log.VERBOSE && CURRENT_LOG_LEVEL >= LOG_LEVEL_VERBOSE) else if (logLevel == Log.VERBOSE && CURRENT_LOG_LEVEL >= LOG_LEVEL_VERBOSE)
Log.v(getFullTag(tag), message); Log.v(getFullTag(tag), message);
} }
@@ -99,7 +99,7 @@ public class Logger {
public static void logErrorAndShowToast(Context context, String tag, String message) { public static void logErrorAndShowToast(Context context, String tag, String message) {
if (context == null) return; if (context == null) return;
if(CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL) { if (CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL) {
logError(tag, message); logError(tag, message);
showToast(context, message, true); showToast(context, message, true);
} }
@@ -114,7 +114,7 @@ public class Logger {
public static void logDebugAndShowToast(Context context, String tag, String message) { public static void logDebugAndShowToast(Context context, String tag, String message) {
if (context == null) return; if (context == null) return;
if(CURRENT_LOG_LEVEL >= LOG_LEVEL_DEBUG) { if (CURRENT_LOG_LEVEL >= LOG_LEVEL_DEBUG) {
logDebug(tag, message); logDebug(tag, message);
showToast(context, message, true); showToast(context, message, true);
} }
@@ -127,7 +127,7 @@ public class Logger {
public static void logStackTraceWithMessage(String tag, String message, Throwable throwable) { public static void logStackTraceWithMessage(String tag, String message, Throwable throwable) {
if(CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL) if (CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL)
Log.e(getFullTag(tag), getMessageAndStackTraceString(message, throwable)); Log.e(getFullTag(tag), getMessageAndStackTraceString(message, throwable));
} }
@@ -144,12 +144,12 @@ public class Logger {
} }
public static void logStackTracesWithMessage(String tag, String message, List<Throwable> throwableList) { public static void logStackTracesWithMessage(String tag, String message, List<Throwable> throwableList) {
if(CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL) if (CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL)
Log.e(getFullTag(tag), getMessageAndStackTracesString(message, throwableList)); Log.e(getFullTag(tag), getMessageAndStackTracesString(message, throwableList));
} }
public static String getMessageAndStackTraceString(String message, Throwable throwable) { public static String getMessageAndStackTraceString(String message, Throwable throwable) {
if(message == null && throwable == null) if (message == null && throwable == null)
return null; return null;
else if(message != null && throwable != null) else if(message != null && throwable != null)
return message + ":\n" + getStackTraceString(throwable); return message + ":\n" + getStackTraceString(throwable);

View File

@@ -131,10 +131,10 @@ public class ExecutionCommand {
public ExecutionCommand(){ public ExecutionCommand() {
} }
public ExecutionCommand(Integer id){ public ExecutionCommand(Integer id) {
this.id = id; this.id = id;
} }

View File

@@ -52,7 +52,7 @@ public class SharedPreferenceUtils {
* default if failed to read a valid value, like in case of an exception. * default if failed to read a valid value, like in case of an exception.
*/ */
public static boolean getBoolean(SharedPreferences sharedPreferences, String key, boolean def) { public static boolean getBoolean(SharedPreferences sharedPreferences, String key, boolean def) {
if(sharedPreferences == null) { if (sharedPreferences == null) {
Logger.logError(LOG_TAG, "Error getting boolean value for the \"" + key + "\" key from null shared preferences. Returning default value \"" + def + "\"."); Logger.logError(LOG_TAG, "Error getting boolean value for the \"" + key + "\" key from null shared preferences. Returning default value \"" + def + "\".");
return def; return def;
} }
@@ -78,12 +78,12 @@ public class SharedPreferenceUtils {
*/ */
@SuppressLint("ApplySharedPref") @SuppressLint("ApplySharedPref")
public static void setBoolean(SharedPreferences sharedPreferences, String key, boolean value, boolean commitToFile) { public static void setBoolean(SharedPreferences sharedPreferences, String key, boolean value, boolean commitToFile) {
if(sharedPreferences == null) { if (sharedPreferences == null) {
Logger.logError(LOG_TAG, "Ignoring setting boolean value \"" + value + "\" for the \"" + key + "\" key into null shared preferences."); Logger.logError(LOG_TAG, "Ignoring setting boolean value \"" + value + "\" for the \"" + key + "\" key into null shared preferences.");
return; return;
} }
if(commitToFile) if (commitToFile)
sharedPreferences.edit().putBoolean(key, value).commit(); sharedPreferences.edit().putBoolean(key, value).commit();
else else
sharedPreferences.edit().putBoolean(key, value).apply(); sharedPreferences.edit().putBoolean(key, value).apply();
@@ -102,7 +102,7 @@ public class SharedPreferenceUtils {
* default if failed to read a valid value, like in case of an exception. * default if failed to read a valid value, like in case of an exception.
*/ */
public static float getFloat(SharedPreferences sharedPreferences, String key, float def) { public static float getFloat(SharedPreferences sharedPreferences, String key, float def) {
if(sharedPreferences == null) { if (sharedPreferences == null) {
Logger.logError(LOG_TAG, "Error getting float value for the \"" + key + "\" key from null shared preferences. Returning default value \"" + def + "\"."); Logger.logError(LOG_TAG, "Error getting float value for the \"" + key + "\" key from null shared preferences. Returning default value \"" + def + "\".");
return def; return def;
} }
@@ -128,12 +128,12 @@ public class SharedPreferenceUtils {
*/ */
@SuppressLint("ApplySharedPref") @SuppressLint("ApplySharedPref")
public static void setFloat(SharedPreferences sharedPreferences, String key, float value, boolean commitToFile) { public static void setFloat(SharedPreferences sharedPreferences, String key, float value, boolean commitToFile) {
if(sharedPreferences == null) { if (sharedPreferences == null) {
Logger.logError(LOG_TAG, "Ignoring setting float value \"" + value + "\" for the \"" + key + "\" key into null shared preferences."); Logger.logError(LOG_TAG, "Ignoring setting float value \"" + value + "\" for the \"" + key + "\" key into null shared preferences.");
return; return;
} }
if(commitToFile) if (commitToFile)
sharedPreferences.edit().putFloat(key, value).commit(); sharedPreferences.edit().putFloat(key, value).commit();
else else
sharedPreferences.edit().putFloat(key, value).apply(); sharedPreferences.edit().putFloat(key, value).apply();
@@ -151,7 +151,7 @@ public class SharedPreferenceUtils {
* default if failed to read a valid value, like in case of an exception. * default if failed to read a valid value, like in case of an exception.
*/ */
public static int getInt(SharedPreferences sharedPreferences, String key, int def) { public static int getInt(SharedPreferences sharedPreferences, String key, int def) {
if(sharedPreferences == null) { if (sharedPreferences == null) {
Logger.logError(LOG_TAG, "Error getting int value for the \"" + key + "\" key from null shared preferences. Returning default value \"" + def + "\"."); Logger.logError(LOG_TAG, "Error getting int value for the \"" + key + "\" key from null shared preferences. Returning default value \"" + def + "\".");
return def; return def;
} }
@@ -177,12 +177,12 @@ public class SharedPreferenceUtils {
*/ */
@SuppressLint("ApplySharedPref") @SuppressLint("ApplySharedPref")
public static void setInt(SharedPreferences sharedPreferences, String key, int value, boolean commitToFile) { public static void setInt(SharedPreferences sharedPreferences, String key, int value, boolean commitToFile) {
if(sharedPreferences == null) { if (sharedPreferences == null) {
Logger.logError(LOG_TAG, "Ignoring setting int value \"" + value + "\" for the \"" + key + "\" key into null shared preferences."); Logger.logError(LOG_TAG, "Ignoring setting int value \"" + value + "\" for the \"" + key + "\" key into null shared preferences.");
return; return;
} }
if(commitToFile) if (commitToFile)
sharedPreferences.edit().putInt(key, value).commit(); sharedPreferences.edit().putInt(key, value).commit();
else else
sharedPreferences.edit().putInt(key, value).apply(); sharedPreferences.edit().putInt(key, value).apply();
@@ -200,7 +200,7 @@ public class SharedPreferenceUtils {
* default if failed to read a valid value, like in case of an exception. * default if failed to read a valid value, like in case of an exception.
*/ */
public static long getLong(SharedPreferences sharedPreferences, String key, long def) { public static long getLong(SharedPreferences sharedPreferences, String key, long def) {
if(sharedPreferences == null) { if (sharedPreferences == null) {
Logger.logError(LOG_TAG, "Error getting long value for the \"" + key + "\" key from null shared preferences. Returning default value \"" + def + "\"."); Logger.logError(LOG_TAG, "Error getting long value for the \"" + key + "\" key from null shared preferences. Returning default value \"" + def + "\".");
return def; return def;
} }
@@ -226,12 +226,12 @@ public class SharedPreferenceUtils {
*/ */
@SuppressLint("ApplySharedPref") @SuppressLint("ApplySharedPref")
public static void setLong(SharedPreferences sharedPreferences, String key, long value, boolean commitToFile) { public static void setLong(SharedPreferences sharedPreferences, String key, long value, boolean commitToFile) {
if(sharedPreferences == null) { if (sharedPreferences == null) {
Logger.logError(LOG_TAG, "Ignoring setting long value \"" + value + "\" for the \"" + key + "\" key into null shared preferences."); Logger.logError(LOG_TAG, "Ignoring setting long value \"" + value + "\" for the \"" + key + "\" key into null shared preferences.");
return; return;
} }
if(commitToFile) if (commitToFile)
sharedPreferences.edit().putLong(key, value).commit(); sharedPreferences.edit().putLong(key, value).commit();
else else
sharedPreferences.edit().putLong(key, value).apply(); sharedPreferences.edit().putLong(key, value).apply();
@@ -249,7 +249,7 @@ public class SharedPreferenceUtils {
* default if failed to read a valid value, like in case of an exception. * default if failed to read a valid value, like in case of an exception.
*/ */
public static String getString(SharedPreferences sharedPreferences, String key, String def) { public static String getString(SharedPreferences sharedPreferences, String key, String def) {
if(sharedPreferences == null) { if (sharedPreferences == null) {
Logger.logError(LOG_TAG, "Error getting String value for the \"" + key + "\" key from null shared preferences. Returning default value \"" + def + "\"."); Logger.logError(LOG_TAG, "Error getting String value for the \"" + key + "\" key from null shared preferences. Returning default value \"" + def + "\".");
return def; return def;
} }
@@ -275,12 +275,12 @@ public class SharedPreferenceUtils {
*/ */
@SuppressLint("ApplySharedPref") @SuppressLint("ApplySharedPref")
public static void setString(SharedPreferences sharedPreferences, String key, String value, boolean commitToFile) { public static void setString(SharedPreferences sharedPreferences, String key, String value, boolean commitToFile) {
if(sharedPreferences == null) { if (sharedPreferences == null) {
Logger.logError(LOG_TAG, "Ignoring setting String value \"" + value + "\" for the \"" + key + "\" key into null shared preferences."); Logger.logError(LOG_TAG, "Ignoring setting String value \"" + value + "\" for the \"" + key + "\" key into null shared preferences.");
return; return;
} }
if(commitToFile) if (commitToFile)
sharedPreferences.edit().putString(key, value).commit(); sharedPreferences.edit().putString(key, value).commit();
else else
sharedPreferences.edit().putString(key, value).apply(); sharedPreferences.edit().putString(key, value).apply();
@@ -298,7 +298,7 @@ public class SharedPreferenceUtils {
* default if failed to read a valid value, like in case of an exception. * default if failed to read a valid value, like in case of an exception.
*/ */
public static Set<String> getStringSet(SharedPreferences sharedPreferences, String key, Set<String> def) { public static Set<String> getStringSet(SharedPreferences sharedPreferences, String key, Set<String> def) {
if(sharedPreferences == null) { if (sharedPreferences == null) {
Logger.logError(LOG_TAG, "Error getting Set<String> value for the \"" + key + "\" key from null shared preferences. Returning default value \"" + def + "\"."); Logger.logError(LOG_TAG, "Error getting Set<String> value for the \"" + key + "\" key from null shared preferences. Returning default value \"" + def + "\".");
return def; return def;
} }
@@ -324,12 +324,12 @@ public class SharedPreferenceUtils {
*/ */
@SuppressLint("ApplySharedPref") @SuppressLint("ApplySharedPref")
public static void setStringSet(SharedPreferences sharedPreferences, String key, Set<String> value, boolean commitToFile) { public static void setStringSet(SharedPreferences sharedPreferences, String key, Set<String> value, boolean commitToFile) {
if(sharedPreferences == null) { if (sharedPreferences == null) {
Logger.logError(LOG_TAG, "Ignoring setting Set<String> value \"" + value + "\" for the \"" + key + "\" key into null shared preferences."); Logger.logError(LOG_TAG, "Ignoring setting Set<String> value \"" + value + "\" for the \"" + key + "\" key into null shared preferences.");
return; return;
} }
if(commitToFile) if (commitToFile)
sharedPreferences.edit().putStringSet(key, value).commit(); sharedPreferences.edit().putStringSet(key, value).commit();
else else
sharedPreferences.edit().putStringSet(key, value).apply(); sharedPreferences.edit().putStringSet(key, value).apply();
@@ -348,7 +348,7 @@ public class SharedPreferenceUtils {
* like in case of an exception. * like in case of an exception.
*/ */
public static int getIntStoredAsString(SharedPreferences sharedPreferences, String key, int def) { public static int getIntStoredAsString(SharedPreferences sharedPreferences, String key, int def) {
if(sharedPreferences == null) { if (sharedPreferences == null) {
Logger.logError(LOG_TAG, "Error getting int value for the \"" + key + "\" key from null shared preferences. Returning default value \"" + def + "\"."); Logger.logError(LOG_TAG, "Error getting int value for the \"" + key + "\" key from null shared preferences. Returning default value \"" + def + "\".");
return def; return def;
} }
@@ -358,7 +358,7 @@ public class SharedPreferenceUtils {
try { try {
stringValue = sharedPreferences.getString(key, Integer.toString(def)); stringValue = sharedPreferences.getString(key, Integer.toString(def));
if(stringValue != null) if (stringValue != null)
intValue = Integer.parseInt(stringValue); intValue = Integer.parseInt(stringValue);
else else
intValue = def; intValue = def;
@@ -381,12 +381,12 @@ public class SharedPreferenceUtils {
*/ */
@SuppressLint("ApplySharedPref") @SuppressLint("ApplySharedPref")
public static void setIntStoredAsString(SharedPreferences sharedPreferences, String key, int value, boolean commitToFile) { public static void setIntStoredAsString(SharedPreferences sharedPreferences, String key, int value, boolean commitToFile) {
if(sharedPreferences == null) { if (sharedPreferences == null) {
Logger.logError(LOG_TAG, "Ignoring setting int value \"" + value + "\" for the \"" + key + "\" key into null shared preferences."); Logger.logError(LOG_TAG, "Ignoring setting int value \"" + value + "\" for the \"" + key + "\" key into null shared preferences.");
return; return;
} }
if(commitToFile) if (commitToFile)
sharedPreferences.edit().putString(key, Integer.toString(value)).commit(); sharedPreferences.edit().putString(key, Integer.toString(value)).commit();
else else
sharedPreferences.edit().putString(key, Integer.toString(value)).apply(); sharedPreferences.edit().putString(key, Integer.toString(value)).apply();

View File

@@ -38,7 +38,7 @@ public class TermuxTaskerAppSharedPreferences {
public int getLogLevel(boolean readFromFfile) { public int getLogLevel(boolean readFromFfile) {
if(readFromFfile) if (readFromFfile)
return SharedPreferenceUtils.getInt(mMultiProcessSharedPreferences, TERMUX_TASKER_APP.KEY_LOG_LEVEL, Logger.DEFAULT_LOG_LEVEL); return SharedPreferenceUtils.getInt(mMultiProcessSharedPreferences, TERMUX_TASKER_APP.KEY_LOG_LEVEL, Logger.DEFAULT_LOG_LEVEL);
else else
return SharedPreferenceUtils.getInt(mSharedPreferences, TERMUX_TASKER_APP.KEY_LOG_LEVEL, Logger.DEFAULT_LOG_LEVEL); return SharedPreferenceUtils.getInt(mSharedPreferences, TERMUX_TASKER_APP.KEY_LOG_LEVEL, Logger.DEFAULT_LOG_LEVEL);

View File

@@ -145,7 +145,7 @@ public class TermuxUtils {
String termuxPackageName = null; String termuxPackageName = null;
String termuxAppName = null; String termuxAppName = null;
if(termuxPackageContext != null) { if (termuxPackageContext != null) {
termuxPackageName = PackageUtils.getPackageNameForPackage(termuxPackageContext); termuxPackageName = PackageUtils.getPackageNameForPackage(termuxPackageContext);
termuxAppName = PackageUtils.getAppNameForPackage(termuxPackageContext); termuxAppName = PackageUtils.getAppNameForPackage(termuxPackageContext);
} }
@@ -156,13 +156,13 @@ public class TermuxUtils {
boolean isTermuxPackage = (termuxPackageName != null && termuxPackageName.equals(currentPackageName)); boolean isTermuxPackage = (termuxPackageName != null && termuxPackageName.equals(currentPackageName));
if(returnTermuxPackageInfoToo && !isTermuxPackage) if (returnTermuxPackageInfoToo && !isTermuxPackage)
markdownString.append("## ").append(currentAppName).append(" App Info (Current)\n"); markdownString.append("## ").append(currentAppName).append(" App Info (Current)\n");
else else
markdownString.append("## ").append(currentAppName).append(" App Info\n"); markdownString.append("## ").append(currentAppName).append(" App Info\n");
markdownString.append(getAppInfoMarkdownStringInner(currentPackageContext)); markdownString.append(getAppInfoMarkdownStringInner(currentPackageContext));
if(returnTermuxPackageInfoToo && !isTermuxPackage) { if (returnTermuxPackageInfoToo && !isTermuxPackage) {
markdownString.append("\n\n## ").append(termuxAppName).append(" App Info\n"); markdownString.append("\n\n## ").append(termuxAppName).append(" App Info\n");
markdownString.append(getAppInfoMarkdownStringInner(termuxPackageContext)); markdownString.append(getAppInfoMarkdownStringInner(termuxPackageContext));
} }
@@ -284,6 +284,8 @@ public class TermuxUtils {
return markdownString.toString(); return markdownString.toString();
} }
public static Properties getSystemProperties() { public static Properties getSystemProperties() {
Properties systemProperties = new Properties(); Properties systemProperties = new Properties();
@@ -311,7 +313,7 @@ public class TermuxUtils {
if (matcher.matches()) { if (matcher.matches()) {
key = matcher.group(1); key = matcher.group(1);
value = matcher.group(2); value = matcher.group(2);
if(key != null && value != null && !key.isEmpty() && !value.isEmpty()) if (key != null && value != null && !key.isEmpty() && !value.isEmpty())
systemProperties.put(key, value); systemProperties.put(key, value);
} }
} }
@@ -340,8 +342,8 @@ public class TermuxUtils {
} }
private static void appendPropertyToMarkdownIfSet(StringBuilder markdownString, String label, Object value) { private static void appendPropertyToMarkdownIfSet(StringBuilder markdownString, String label, Object value) {
if(value == null) return; if (value == null) return;
if(value instanceof String && (((String) value).isEmpty()) || "REL".equals(value)) return; if (value instanceof String && (((String) value).isEmpty()) || "REL".equals(value)) return;
markdownString.append("\n").append(getPropertyMarkdown(label, value)); markdownString.append("\n").append(getPropertyMarkdown(label, value));
} }