mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-06 18:55:31 +08:00
Replace "if(" with "if ("
This commit is contained in:
@@ -52,7 +52,7 @@ public class RunCommandService extends Service {
|
|||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
Logger.logDebug(LOG_TAG, "onStartCommand");
|
Logger.logDebug(LOG_TAG, "onStartCommand");
|
||||||
|
|
||||||
if(intent == null) return Service.START_NOT_STICKY;
|
if (intent == null) return Service.START_NOT_STICKY;
|
||||||
|
|
||||||
// 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();
|
||||||
@@ -195,7 +195,7 @@ public class RunCommandService extends Service {
|
|||||||
TermuxConstants.TERMUX_RUN_COMMAND_NOTIFICATION_CHANNEL_ID, Notification.PRIORITY_LOW,
|
TermuxConstants.TERMUX_RUN_COMMAND_NOTIFICATION_CHANNEL_ID, Notification.PRIORITY_LOW,
|
||||||
TermuxConstants.TERMUX_RUN_COMMAND_NOTIFICATION_CHANNEL_NAME, null, null,
|
TermuxConstants.TERMUX_RUN_COMMAND_NOTIFICATION_CHANNEL_NAME, null, null,
|
||||||
null, NotificationUtils.NOTIFICATION_MODE_SILENT);
|
null, NotificationUtils.NOTIFICATION_MODE_SILENT);
|
||||||
if(builder == null) return null;
|
if (builder == null) return null;
|
||||||
|
|
||||||
// No need to show a timestamp:
|
// No need to show a timestamp:
|
||||||
builder.setShowWhen(false);
|
builder.setShowWhen(false);
|
||||||
|
@@ -362,7 +362,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
setTerminalToolbarHeight();
|
setTerminalToolbarHeight();
|
||||||
|
|
||||||
String savedTextInput = null;
|
String savedTextInput = null;
|
||||||
if(savedInstanceState != null)
|
if (savedInstanceState != null)
|
||||||
savedTextInput = savedInstanceState.getString(ARG_TERMINAL_TOOLBAR_TEXT_INPUT);
|
savedTextInput = savedInstanceState.getString(ARG_TERMINAL_TOOLBAR_TEXT_INPUT);
|
||||||
|
|
||||||
terminalToolbarViewPager.setAdapter(new TerminalToolbarViewPager.PageAdapter(this, savedTextInput));
|
terminalToolbarViewPager.setAdapter(new TerminalToolbarViewPager.PageAdapter(this, savedTextInput));
|
||||||
@@ -371,7 +371,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
|
|
||||||
private void setTerminalToolbarHeight() {
|
private void setTerminalToolbarHeight() {
|
||||||
final ViewPager terminalToolbarViewPager = findViewById(R.id.terminal_toolbar_view_pager);
|
final ViewPager terminalToolbarViewPager = findViewById(R.id.terminal_toolbar_view_pager);
|
||||||
if(terminalToolbarViewPager == null) return;
|
if (terminalToolbarViewPager == null) return;
|
||||||
ViewGroup.LayoutParams layoutParams = terminalToolbarViewPager.getLayoutParams();
|
ViewGroup.LayoutParams layoutParams = terminalToolbarViewPager.getLayoutParams();
|
||||||
layoutParams.height = (int) Math.round(mTerminalToolbarDefaultHeight *
|
layoutParams.height = (int) Math.round(mTerminalToolbarDefaultHeight *
|
||||||
(mProperties.getExtraKeysInfo() == null ? 0 : mProperties.getExtraKeysInfo().getMatrix().length) *
|
(mProperties.getExtraKeysInfo() == null ? 0 : mProperties.getExtraKeysInfo().getMatrix().length) *
|
||||||
@@ -381,7 +381,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
|
|
||||||
public void toggleTerminalToolbar() {
|
public void toggleTerminalToolbar() {
|
||||||
final ViewPager terminalToolbarViewPager = findViewById(R.id.terminal_toolbar_view_pager);
|
final ViewPager terminalToolbarViewPager = findViewById(R.id.terminal_toolbar_view_pager);
|
||||||
if(terminalToolbarViewPager == null) return;
|
if (terminalToolbarViewPager == null) return;
|
||||||
|
|
||||||
final boolean showNow = mPreferences.toogleShowTerminalToolbar();
|
final boolean showNow = mPreferences.toogleShowTerminalToolbar();
|
||||||
Logger.showToast(this, (showNow ? getString(R.string.msg_enabling_terminal_toolbar) : getString(R.string.msg_disabling_terminal_toolbar)), true);
|
Logger.showToast(this, (showNow ? getString(R.string.msg_enabling_terminal_toolbar) : getString(R.string.msg_disabling_terminal_toolbar)), true);
|
||||||
@@ -393,12 +393,12 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void saveTerminalToolbarTextInput(Bundle savedInstanceState) {
|
private void saveTerminalToolbarTextInput(Bundle savedInstanceState) {
|
||||||
if(savedInstanceState == null) return;
|
if (savedInstanceState == null) return;
|
||||||
|
|
||||||
final EditText textInputView = findViewById(R.id.terminal_toolbar_text_input);
|
final EditText textInputView = findViewById(R.id.terminal_toolbar_text_input);
|
||||||
if(textInputView != null) {
|
if (textInputView != null) {
|
||||||
String textInput = textInputView.getText().toString();
|
String textInput = textInputView.getText().toString();
|
||||||
if(!textInput.isEmpty()) savedInstanceState.putString(ARG_TERMINAL_TOOLBAR_TEXT_INPUT, textInput);
|
if (!textInput.isEmpty()) savedInstanceState.putString(ARG_TERMINAL_TOOLBAR_TEXT_INPUT, textInput);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -431,14 +431,14 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
|
|
||||||
private void setSoftKeyboardState() {
|
private void setSoftKeyboardState() {
|
||||||
// If soft keyboard is to disabled
|
// If soft keyboard is to disabled
|
||||||
if(!mPreferences.getSoftKeyboardEnabled()) {
|
if (!mPreferences.getSoftKeyboardEnabled()) {
|
||||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
|
||||||
} else {
|
} else {
|
||||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
|
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If soft keyboard is to be hidden on startup
|
// If soft keyboard is to be hidden on startup
|
||||||
if(mProperties.shouldSoftKeyboardBeHiddenOnStartup()) {
|
if (mProperties.shouldSoftKeyboardBeHiddenOnStartup()) {
|
||||||
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
|
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -496,7 +496,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
|
|
||||||
/** Show a toast and dismiss the last one if still visible. */
|
/** Show a toast and dismiss the last one if still visible. */
|
||||||
public void showToast(String text, boolean longDuration) {
|
public void showToast(String text, boolean longDuration) {
|
||||||
if(text == null || text.isEmpty()) return;
|
if (text == null || text.isEmpty()) return;
|
||||||
if (mLastToast != null) mLastToast.cancel();
|
if (mLastToast != null) mLastToast.cancel();
|
||||||
mLastToast = Toast.makeText(TermuxActivity.this, text, longDuration ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT);
|
mLastToast = Toast.makeText(TermuxActivity.this, text, longDuration ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT);
|
||||||
mLastToast.setGravity(Gravity.TOP, 0, 0);
|
mLastToast.setGravity(Gravity.TOP, 0, 0);
|
||||||
@@ -611,7 +611,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void toggleKeepScreenOn() {
|
private void toggleKeepScreenOn() {
|
||||||
if(mTerminalView.getKeepScreenOn()) {
|
if (mTerminalView.getKeepScreenOn()) {
|
||||||
mTerminalView.setKeepScreenOn(false);
|
mTerminalView.setKeepScreenOn(false);
|
||||||
mPreferences.setKeepScreenOn(false);
|
mPreferences.setKeepScreenOn(false);
|
||||||
} else {
|
} else {
|
||||||
@@ -696,7 +696,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public TerminalSession getCurrentSession() {
|
public TerminalSession getCurrentSession() {
|
||||||
if(mTerminalView != null)
|
if (mTerminalView != null)
|
||||||
return mTerminalView.getCurrentSession();
|
return mTerminalView.getCurrentSession();
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
@@ -766,11 +766,11 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void reloadTermuxActivityStyling() {
|
private void reloadTermuxActivityStyling() {
|
||||||
if(mTermuxTerminalSessionClient != null) {
|
if (mTermuxTerminalSessionClient != null) {
|
||||||
mTermuxTerminalSessionClient.checkForFontAndColors();
|
mTermuxTerminalSessionClient.checkForFontAndColors();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mProperties!= null) {
|
if (mProperties!= null) {
|
||||||
mProperties.loadTermuxPropertiesFromDisk();
|
mProperties.loadTermuxPropertiesFromDisk();
|
||||||
|
|
||||||
if (mExtraKeysView != null) {
|
if (mExtraKeysView != null) {
|
||||||
|
@@ -689,7 +689,7 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas
|
|||||||
TermuxConstants.TERMUX_APP_NOTIFICATION_CHANNEL_ID, priority,
|
TermuxConstants.TERMUX_APP_NOTIFICATION_CHANNEL_ID, priority,
|
||||||
getText(R.string.application_name), notificationText, null,
|
getText(R.string.application_name), notificationText, null,
|
||||||
pendingIntent, NotificationUtils.NOTIFICATION_MODE_SILENT);
|
pendingIntent, NotificationUtils.NOTIFICATION_MODE_SILENT);
|
||||||
if(builder == null) return null;
|
if (builder == null) return null;
|
||||||
|
|
||||||
// No need to show a timestamp:
|
// No need to show a timestamp:
|
||||||
builder.setShowWhen(false);
|
builder.setShowWhen(false);
|
||||||
@@ -742,7 +742,7 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas
|
|||||||
|
|
||||||
|
|
||||||
private void setCurrentStoredTerminalSession(TerminalSession session) {
|
private void setCurrentStoredTerminalSession(TerminalSession session) {
|
||||||
if(session == null) return;
|
if (session == null) return;
|
||||||
// Make the newly created session the current one to be displayed:
|
// Make the newly created session the current one to be displayed:
|
||||||
TermuxAppSharedPreferences preferences = new TermuxAppSharedPreferences(this);
|
TermuxAppSharedPreferences preferences = new TermuxAppSharedPreferences(this);
|
||||||
preferences.setCurrentSession(session.mHandle);
|
preferences.setCurrentSession(session.mHandle);
|
||||||
@@ -762,7 +762,7 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public synchronized TermuxSession getTermuxSession(int index) {
|
public synchronized TermuxSession getTermuxSession(int index) {
|
||||||
if(index >= 0 && index < mTermuxSessions.size())
|
if (index >= 0 && index < mTermuxSessions.size())
|
||||||
return mTermuxSessions.get(index);
|
return mTermuxSessions.get(index);
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
|
@@ -32,7 +32,7 @@ public class DebuggingPreferencesFragment extends PreferenceFragmentCompat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected ListPreference setLogLevelListPreferenceData(ListPreference logLevelListPreference, Context context) {
|
protected ListPreference setLogLevelListPreferenceData(ListPreference logLevelListPreference, Context context) {
|
||||||
if(logLevelListPreference == null)
|
if (logLevelListPreference == null)
|
||||||
logLevelListPreference = new ListPreference(context);
|
logLevelListPreference = new ListPreference(context);
|
||||||
|
|
||||||
CharSequence[] logLevels = Logger.getLogLevelsArray();
|
CharSequence[] logLevels = Logger.getLogLevelsArray();
|
||||||
@@ -73,7 +73,7 @@ class DebuggingPreferencesDataStore extends PreferenceDataStore {
|
|||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getString(String key, @Nullable String defValue) {
|
public String getString(String key, @Nullable String defValue) {
|
||||||
if(key == null) return null;
|
if (key == null) return null;
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case "log_level":
|
case "log_level":
|
||||||
@@ -85,7 +85,7 @@ class DebuggingPreferencesDataStore extends PreferenceDataStore {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void putString(String key, @Nullable String value) {
|
public void putString(String key, @Nullable String value) {
|
||||||
if(key == null) return;
|
if (key == null) return;
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case "log_level":
|
case "log_level":
|
||||||
@@ -102,7 +102,7 @@ class DebuggingPreferencesDataStore extends PreferenceDataStore {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void putBoolean(String key, boolean value) {
|
public void putBoolean(String key, boolean value) {
|
||||||
if(key == null) return;
|
if (key == null) return;
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case "terminal_view_key_logging_enabled":
|
case "terminal_view_key_logging_enabled":
|
||||||
|
@@ -45,7 +45,7 @@ class TerminalIOPreferencesDataStore extends PreferenceDataStore {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void putBoolean(String key, boolean value) {
|
public void putBoolean(String key, boolean value) {
|
||||||
if(key == null) return;
|
if (key == null) return;
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case "soft_keyboard_enabled":
|
case "soft_keyboard_enabled":
|
||||||
|
@@ -70,7 +70,7 @@ public class TermuxAppSharedProperties extends TermuxSharedProperties implements
|
|||||||
* Set the terminal sessions shortcuts.
|
* Set the terminal sessions shortcuts.
|
||||||
*/
|
*/
|
||||||
private void setSessionShortcuts() {
|
private void setSessionShortcuts() {
|
||||||
if(mSessionShortcuts == null)
|
if (mSessionShortcuts == null)
|
||||||
mSessionShortcuts = new ArrayList<>();
|
mSessionShortcuts = new ArrayList<>();
|
||||||
else
|
else
|
||||||
mSessionShortcuts.clear();
|
mSessionShortcuts.clear();
|
||||||
|
@@ -188,7 +188,7 @@ public final class ExtraKeysView extends GridLayout {
|
|||||||
int width = view.getMeasuredWidth();
|
int width = view.getMeasuredWidth();
|
||||||
int height = view.getMeasuredHeight();
|
int height = view.getMeasuredHeight();
|
||||||
Button button;
|
Button button;
|
||||||
if(isSpecialButton(extraButton)) {
|
if (isSpecialButton(extraButton)) {
|
||||||
button = createSpecialButton(extraButton.getKey(), false);
|
button = createSpecialButton(extraButton.getKey(), false);
|
||||||
if (button == null) return;
|
if (button == null) return;
|
||||||
} else {
|
} else {
|
||||||
@@ -240,7 +240,7 @@ public final class ExtraKeysView extends GridLayout {
|
|||||||
*/
|
*/
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
public void reload(ExtraKeysInfo infos) {
|
public void reload(ExtraKeysInfo infos) {
|
||||||
if(infos == null)
|
if (infos == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for(SpecialButtonState state : specialButtons.values())
|
for(SpecialButtonState state : specialButtons.values())
|
||||||
@@ -258,7 +258,7 @@ public final class ExtraKeysView extends GridLayout {
|
|||||||
final ExtraKeyButton buttonInfo = buttons[row][col];
|
final ExtraKeyButton buttonInfo = buttons[row][col];
|
||||||
|
|
||||||
Button button;
|
Button button;
|
||||||
if(isSpecialButton(buttonInfo)) {
|
if (isSpecialButton(buttonInfo)) {
|
||||||
button = createSpecialButton(buttonInfo.getKey(), true);
|
button = createSpecialButton(buttonInfo.getKey(), true);
|
||||||
if (button == null) return;
|
if (button == null) return;
|
||||||
} else {
|
} else {
|
||||||
|
@@ -88,7 +88,7 @@ static int create_subprocess(JNIEnv* env,
|
|||||||
struct dirent* entry;
|
struct dirent* entry;
|
||||||
while ((entry = readdir(self_dir)) != NULL) {
|
while ((entry = readdir(self_dir)) != NULL) {
|
||||||
int fd = atoi(entry->d_name);
|
int fd = atoi(entry->d_name);
|
||||||
if(fd > 2 && fd != self_dir_fd) close(fd);
|
if (fd > 2 && fd != self_dir_fd) close(fd);
|
||||||
}
|
}
|
||||||
closedir(self_dir);
|
closedir(self_dir);
|
||||||
}
|
}
|
||||||
|
@@ -21,7 +21,7 @@ public class ShareUtils {
|
|||||||
* @param title The title for choose menu.
|
* @param title The title for choose menu.
|
||||||
*/
|
*/
|
||||||
private static void openSystemAppChooser(final Context context, final Intent intent, final String title) {
|
private static void openSystemAppChooser(final Context context, final Intent intent, final String title) {
|
||||||
if(context == null) return;
|
if (context == null) return;
|
||||||
|
|
||||||
final Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
|
final Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
|
||||||
chooserIntent.putExtra(Intent.EXTRA_INTENT, intent);
|
chooserIntent.putExtra(Intent.EXTRA_INTENT, intent);
|
||||||
@@ -38,7 +38,7 @@ public class ShareUtils {
|
|||||||
* @param text The text to share.
|
* @param text The text to share.
|
||||||
*/
|
*/
|
||||||
public static void shareText(final Context context, final String subject, final String text) {
|
public static void shareText(final Context context, final String subject, final String text) {
|
||||||
if(context == null) return;
|
if (context == null) return;
|
||||||
|
|
||||||
final Intent shareTextIntent = new Intent(Intent.ACTION_SEND);
|
final Intent shareTextIntent = new Intent(Intent.ACTION_SEND);
|
||||||
shareTextIntent.setType("text/plain");
|
shareTextIntent.setType("text/plain");
|
||||||
@@ -57,7 +57,7 @@ public class ShareUtils {
|
|||||||
* clipboard is successful.
|
* clipboard is successful.
|
||||||
*/
|
*/
|
||||||
public static void copyTextToClipboard(final Context context, final String text, final String toastString) {
|
public static void copyTextToClipboard(final Context context, final String text, final String toastString) {
|
||||||
if(context == null) return;
|
if (context == null) return;
|
||||||
|
|
||||||
final ClipboardManager clipboardManager = ContextCompat.getSystemService(context, ClipboardManager.class);
|
final ClipboardManager clipboardManager = ContextCompat.getSystemService(context, ClipboardManager.class);
|
||||||
|
|
||||||
|
@@ -151,27 +151,27 @@ public class Logger {
|
|||||||
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);
|
||||||
else if(throwable == null)
|
else if (throwable == null)
|
||||||
return message;
|
return message;
|
||||||
else
|
else
|
||||||
return getStackTraceString(throwable);
|
return getStackTraceString(throwable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getMessageAndStackTracesString(String message, List<Throwable> throwableList) {
|
public static String getMessageAndStackTracesString(String message, List<Throwable> throwableList) {
|
||||||
if(message == null && (throwableList == null || throwableList.size() == 0))
|
if (message == null && (throwableList == null || throwableList.size() == 0))
|
||||||
return null;
|
return null;
|
||||||
else if(message != null && (throwableList != null && throwableList.size() != 0))
|
else if (message != null && (throwableList != null && throwableList.size() != 0))
|
||||||
return message + ":\n" + getStackTracesString(null, getStackTraceStringArray(throwableList));
|
return message + ":\n" + getStackTracesString(null, getStackTraceStringArray(throwableList));
|
||||||
else if(throwableList == null || throwableList.size() == 0)
|
else if (throwableList == null || throwableList.size() == 0)
|
||||||
return message;
|
return message;
|
||||||
else
|
else
|
||||||
return getStackTracesString(null, getStackTraceStringArray(throwableList));
|
return getStackTracesString(null, getStackTraceStringArray(throwableList));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getStackTraceString(Throwable throwable) {
|
public static String getStackTraceString(Throwable throwable) {
|
||||||
if(throwable == null) return null;
|
if (throwable == null) return null;
|
||||||
|
|
||||||
String stackTraceString = null;
|
String stackTraceString = null;
|
||||||
|
|
||||||
@@ -204,14 +204,14 @@ public class Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getStackTracesString(String label, String[] stackTraceStringArray) {
|
public static String getStackTracesString(String label, String[] stackTraceStringArray) {
|
||||||
if(label == null) label = "StackTraces:";
|
if (label == null) label = "StackTraces:";
|
||||||
StringBuilder stackTracesString = new StringBuilder(label);
|
StringBuilder stackTracesString = new StringBuilder(label);
|
||||||
|
|
||||||
if (stackTraceStringArray == null || stackTraceStringArray.length == 0) {
|
if (stackTraceStringArray == null || stackTraceStringArray.length == 0) {
|
||||||
stackTracesString.append(" -");
|
stackTracesString.append(" -");
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i != stackTraceStringArray.length; i++) {
|
for (int i = 0; i != stackTraceStringArray.length; i++) {
|
||||||
if(stackTraceStringArray.length > 1)
|
if (stackTraceStringArray.length > 1)
|
||||||
stackTracesString.append("\n\nStacktrace ").append(i + 1);
|
stackTracesString.append("\n\nStacktrace ").append(i + 1);
|
||||||
|
|
||||||
stackTracesString.append("\n```\n").append(stackTraceStringArray[i]).append("\n```\n");
|
stackTracesString.append("\n```\n").append(stackTraceStringArray[i]).append("\n```\n");
|
||||||
@@ -222,14 +222,14 @@ public class Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getStackTracesMarkdownString(String label, String[] stackTraceStringArray) {
|
public static String getStackTracesMarkdownString(String label, String[] stackTraceStringArray) {
|
||||||
if(label == null) label = "StackTraces";
|
if (label == null) label = "StackTraces";
|
||||||
StringBuilder stackTracesString = new StringBuilder("### " + label);
|
StringBuilder stackTracesString = new StringBuilder("### " + label);
|
||||||
|
|
||||||
if (stackTraceStringArray == null || stackTraceStringArray.length == 0) {
|
if (stackTraceStringArray == null || stackTraceStringArray.length == 0) {
|
||||||
stackTracesString.append("\n\n`-`");
|
stackTracesString.append("\n\n`-`");
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i != stackTraceStringArray.length; i++) {
|
for (int i = 0; i != stackTraceStringArray.length; i++) {
|
||||||
if(stackTraceStringArray.length > 1)
|
if (stackTraceStringArray.length > 1)
|
||||||
stackTracesString.append("\n\n\n#### Stacktrace ").append(i + 1);
|
stackTracesString.append("\n\n\n#### Stacktrace ").append(i + 1);
|
||||||
|
|
||||||
stackTracesString.append("\n\n```\n").append(stackTraceStringArray[i]).append("\n```");
|
stackTracesString.append("\n\n```\n").append(stackTraceStringArray[i]).append("\n```");
|
||||||
@@ -309,19 +309,19 @@ public class Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int setLogLevel(Context context, int logLevel) {
|
public static int setLogLevel(Context context, int logLevel) {
|
||||||
if(logLevel >= LOG_LEVEL_OFF && logLevel <= LOG_LEVEL_VERBOSE)
|
if (logLevel >= LOG_LEVEL_OFF && logLevel <= LOG_LEVEL_VERBOSE)
|
||||||
CURRENT_LOG_LEVEL = logLevel;
|
CURRENT_LOG_LEVEL = logLevel;
|
||||||
else
|
else
|
||||||
CURRENT_LOG_LEVEL = DEFAULT_LOG_LEVEL;
|
CURRENT_LOG_LEVEL = DEFAULT_LOG_LEVEL;
|
||||||
|
|
||||||
if(context != null)
|
if (context != null)
|
||||||
showToast(context, context.getString(R.string.log_level_value, getLogLevelLabel(context, CURRENT_LOG_LEVEL, false)),true);
|
showToast(context, context.getString(R.string.log_level_value, getLogLevelLabel(context, CURRENT_LOG_LEVEL, false)),true);
|
||||||
|
|
||||||
return CURRENT_LOG_LEVEL;
|
return CURRENT_LOG_LEVEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getFullTag(String tag) {
|
public static String getFullTag(String tag) {
|
||||||
if(DEFAULT_LOG_TAG.equals(tag))
|
if (DEFAULT_LOG_TAG.equals(tag))
|
||||||
return tag;
|
return tag;
|
||||||
else
|
else
|
||||||
return DEFAULT_LOG_TAG + ":" + tag;
|
return DEFAULT_LOG_TAG + ":" + tag;
|
||||||
|
@@ -50,15 +50,15 @@ public class MarkdownUtils {
|
|||||||
* @return Returns the markdown code {@link String}.
|
* @return Returns the markdown code {@link String}.
|
||||||
*/
|
*/
|
||||||
public static String getMarkdownCodeForString(String string, boolean codeBlock) {
|
public static String getMarkdownCodeForString(String string, boolean codeBlock) {
|
||||||
if(string == null) return null;
|
if (string == null) return null;
|
||||||
if(string.isEmpty()) return "";
|
if (string.isEmpty()) return "";
|
||||||
|
|
||||||
int maxConsecutiveBackTicksCount = getMaxConsecutiveBackTicksCount(string);
|
int maxConsecutiveBackTicksCount = getMaxConsecutiveBackTicksCount(string);
|
||||||
|
|
||||||
// markdown requires surrounding backticks count to be at least one more than the count
|
// markdown requires surrounding backticks count to be at least one more than the count
|
||||||
// of consecutive ticks in the string itself
|
// of consecutive ticks in the string itself
|
||||||
int backticksCountToUse;
|
int backticksCountToUse;
|
||||||
if(codeBlock)
|
if (codeBlock)
|
||||||
backticksCountToUse = maxConsecutiveBackTicksCount + 3;
|
backticksCountToUse = maxConsecutiveBackTicksCount + 3;
|
||||||
else
|
else
|
||||||
backticksCountToUse = maxConsecutiveBackTicksCount + 1;
|
backticksCountToUse = maxConsecutiveBackTicksCount + 1;
|
||||||
@@ -66,13 +66,13 @@ public class MarkdownUtils {
|
|||||||
// create a string with n backticks where n==backticksCountToUse
|
// create a string with n backticks where n==backticksCountToUse
|
||||||
String backticksToUse = Strings.repeat(backtick, backticksCountToUse);
|
String backticksToUse = Strings.repeat(backtick, backticksCountToUse);
|
||||||
|
|
||||||
if(codeBlock)
|
if (codeBlock)
|
||||||
return backticksToUse + "\n" + string + "\n" + backticksToUse;
|
return backticksToUse + "\n" + string + "\n" + backticksToUse;
|
||||||
else {
|
else {
|
||||||
// add a space to any prefixed or suffixed backtick characters
|
// add a space to any prefixed or suffixed backtick characters
|
||||||
if(string.startsWith(backtick))
|
if (string.startsWith(backtick))
|
||||||
string = " " + string;
|
string = " " + string;
|
||||||
if(string.endsWith(backtick))
|
if (string.endsWith(backtick))
|
||||||
string = string + " ";
|
string = string + " ";
|
||||||
|
|
||||||
return backticksToUse + string + backticksToUse;
|
return backticksToUse + string + backticksToUse;
|
||||||
@@ -86,7 +86,7 @@ public class MarkdownUtils {
|
|||||||
* @return Returns the max consecutive backticks count.
|
* @return Returns the max consecutive backticks count.
|
||||||
*/
|
*/
|
||||||
public static int getMaxConsecutiveBackTicksCount(String string) {
|
public static int getMaxConsecutiveBackTicksCount(String string) {
|
||||||
if(string == null || string.isEmpty()) return 0;
|
if (string == null || string.isEmpty()) return 0;
|
||||||
|
|
||||||
int maxCount = 0;
|
int maxCount = 0;
|
||||||
int matchCount;
|
int matchCount;
|
||||||
@@ -94,7 +94,7 @@ public class MarkdownUtils {
|
|||||||
Matcher matcher = backticksPattern.matcher(string);
|
Matcher matcher = backticksPattern.matcher(string);
|
||||||
while(matcher.find()) {
|
while(matcher.find()) {
|
||||||
matchCount = matcher.group(1).length();
|
matchCount = matcher.group(1).length();
|
||||||
if(matchCount > maxCount)
|
if (matchCount > maxCount)
|
||||||
maxCount = matchCount;
|
maxCount = matchCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -45,7 +45,7 @@ public class NotificationUtils {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static NotificationManager getNotificationManager(final Context context) {
|
public static NotificationManager getNotificationManager(final Context context) {
|
||||||
if(context == null) return null;
|
if (context == null) return null;
|
||||||
return (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
return (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ public class NotificationUtils {
|
|||||||
* @return Returns the notification id that should be safe to use.
|
* @return Returns the notification id that should be safe to use.
|
||||||
*/
|
*/
|
||||||
public synchronized static int getNextNotificationId(final Context context) {
|
public synchronized static int getNextNotificationId(final Context context) {
|
||||||
if(context == null) return TermuxPreferenceConstants.TERMUX_APP.DEFAULT_VALUE_KEY_LAST_NOTIFICATION_ID;
|
if (context == null) return TermuxPreferenceConstants.TERMUX_APP.DEFAULT_VALUE_KEY_LAST_NOTIFICATION_ID;
|
||||||
|
|
||||||
TermuxAppSharedPreferences preferences = new TermuxAppSharedPreferences(context);
|
TermuxAppSharedPreferences preferences = new TermuxAppSharedPreferences(context);
|
||||||
int lastNotificationId = preferences.getLastNotificationId();
|
int lastNotificationId = preferences.getLastNotificationId();
|
||||||
@@ -69,7 +69,7 @@ public class NotificationUtils {
|
|||||||
nextNotificationId++;
|
nextNotificationId++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(nextNotificationId == Integer.MAX_VALUE || nextNotificationId < 0)
|
if (nextNotificationId == Integer.MAX_VALUE || nextNotificationId < 0)
|
||||||
nextNotificationId = TermuxPreferenceConstants.TERMUX_APP.DEFAULT_VALUE_KEY_LAST_NOTIFICATION_ID;
|
nextNotificationId = TermuxPreferenceConstants.TERMUX_APP.DEFAULT_VALUE_KEY_LAST_NOTIFICATION_ID;
|
||||||
|
|
||||||
preferences.setLastNotificationId(nextNotificationId);
|
preferences.setLastNotificationId(nextNotificationId);
|
||||||
@@ -91,7 +91,7 @@ public class NotificationUtils {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Notification.Builder geNotificationBuilder(final Context context, final String channelId, final int priority, final CharSequence title, final CharSequence notifiationText, final CharSequence notificationBigText, final PendingIntent pendingIntent, final int notificationMode) {
|
public static Notification.Builder geNotificationBuilder(final Context context, final String channelId, final int priority, final CharSequence title, final CharSequence notifiationText, final CharSequence notificationBigText, final PendingIntent pendingIntent, final int notificationMode) {
|
||||||
if(context == null) return null;
|
if (context == null) return null;
|
||||||
Notification.Builder builder = new Notification.Builder(context);
|
Notification.Builder builder = new Notification.Builder(context);
|
||||||
builder.setContentTitle(title);
|
builder.setContentTitle(title);
|
||||||
builder.setContentText(notifiationText);
|
builder.setContentText(notifiationText);
|
||||||
@@ -124,7 +124,7 @@ public class NotificationUtils {
|
|||||||
NotificationChannel channel = new NotificationChannel(channelId, channelName, importance);
|
NotificationChannel channel = new NotificationChannel(channelId, channelName, importance);
|
||||||
|
|
||||||
NotificationManager notificationManager = getNotificationManager(context);
|
NotificationManager notificationManager = getNotificationManager(context);
|
||||||
if(notificationManager != null)
|
if (notificationManager != null)
|
||||||
notificationManager.createNotificationChannel(channel);
|
notificationManager.createNotificationChannel(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -36,7 +36,7 @@ public class PermissionUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void askPermissions(Activity context, String[] permissions) {
|
public static void askPermissions(Activity context, String[] permissions) {
|
||||||
if(context == null || permissions == null) return;
|
if (context == null || permissions == null) return;
|
||||||
|
|
||||||
int result;
|
int result;
|
||||||
Logger.showToast(context, context.getString(R.string.message_sudo_please_grant_permissions), true);
|
Logger.showToast(context, context.getString(R.string.message_sudo_please_grant_permissions), true);
|
||||||
@@ -74,9 +74,9 @@ public class PermissionUtils {
|
|||||||
public static boolean validateDisplayOverOtherAppsPermissionForPostAndroid10(Context context) {
|
public static boolean validateDisplayOverOtherAppsPermissionForPostAndroid10(Context context) {
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) return true;
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) return true;
|
||||||
|
|
||||||
if(!PermissionUtils.checkDisplayOverOtherAppsPermission(context)) {
|
if (!PermissionUtils.checkDisplayOverOtherAppsPermission(context)) {
|
||||||
TermuxAppSharedPreferences preferences = new TermuxAppSharedPreferences(context);
|
TermuxAppSharedPreferences preferences = new TermuxAppSharedPreferences(context);
|
||||||
if(preferences.getPluginErrorNotificationsEnabled())
|
if (preferences.getPluginErrorNotificationsEnabled())
|
||||||
Logger.showToast(context, context.getString(R.string.error_display_over_other_apps_permission_not_granted), true);
|
Logger.showToast(context, context.getString(R.string.error_display_over_other_apps_permission_not_granted), true);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
@@ -32,9 +32,9 @@ public class ShellUtils {
|
|||||||
|
|
||||||
// This function may be called by a different package like a plugin, so we get version for Termux package via its context
|
// This function may be called by a different package like a plugin, so we get version for Termux package via its context
|
||||||
Context termuxPackageContext = TermuxUtils.getTermuxPackageContext(currentPackageContext);
|
Context termuxPackageContext = TermuxUtils.getTermuxPackageContext(currentPackageContext);
|
||||||
if(termuxPackageContext != null) {
|
if (termuxPackageContext != null) {
|
||||||
String termuxVersionName = PackageUtils.getVersionNameForPackage(termuxPackageContext);
|
String termuxVersionName = PackageUtils.getVersionNameForPackage(termuxPackageContext);
|
||||||
if(termuxVersionName != null)
|
if (termuxVersionName != null)
|
||||||
environment.add("TERMUX_VERSION=" + termuxVersionName);
|
environment.add("TERMUX_VERSION=" + termuxVersionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,7 +145,7 @@ public class ShellUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getExecutableBasename(String executable) {
|
public static String getExecutableBasename(String executable) {
|
||||||
if(executable == null) return null;
|
if (executable == null) return null;
|
||||||
int lastSlash = executable.lastIndexOf('/');
|
int lastSlash = executable.lastIndexOf('/');
|
||||||
return (lastSlash == -1) ? executable : executable.substring(lastSlash + 1);
|
return (lastSlash == -1) ? executable : executable.substring(lastSlash + 1);
|
||||||
}
|
}
|
||||||
@@ -169,14 +169,14 @@ public class ShellUtils {
|
|||||||
|
|
||||||
String transcriptText;
|
String transcriptText;
|
||||||
|
|
||||||
if(linesJoined)
|
if (linesJoined)
|
||||||
transcriptText = terminalBuffer.getTranscriptTextWithFullLinesJoined();
|
transcriptText = terminalBuffer.getTranscriptTextWithFullLinesJoined();
|
||||||
else
|
else
|
||||||
transcriptText = terminalBuffer.getTranscriptTextWithoutJoinedLines();
|
transcriptText = terminalBuffer.getTranscriptTextWithoutJoinedLines();
|
||||||
|
|
||||||
if (transcriptText == null) return null;
|
if (transcriptText == null) return null;
|
||||||
|
|
||||||
if(trim)
|
if (trim)
|
||||||
transcriptText = transcriptText.trim();
|
transcriptText = transcriptText.trim();
|
||||||
|
|
||||||
return transcriptText;
|
return transcriptText;
|
||||||
|
@@ -178,7 +178,7 @@ public class StreamGobbler extends Thread {
|
|||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
|
|
||||||
if(currentLogLevel >= logLevelVerbose)
|
if (currentLogLevel >= logLevelVerbose)
|
||||||
Logger.logVerbose(LOG_TAG, String.format(Locale.ENGLISH, "[%s] %s", shell, line)); // This will get truncated by LOGGER_ENTRY_MAX_LEN, likely 4KB
|
Logger.logVerbose(LOG_TAG, String.format(Locale.ENGLISH, "[%s] %s", shell, line)); // This will get truncated by LOGGER_ENTRY_MAX_LEN, likely 4KB
|
||||||
|
|
||||||
if (stringWriter != null) stringWriter.append(line).append("\n");
|
if (stringWriter != null) stringWriter.append(line).append("\n");
|
||||||
|
@@ -170,7 +170,7 @@ public class TermuxSession {
|
|||||||
*/
|
*/
|
||||||
public void killIfExecuting(@NonNull final Context context, boolean processResult) {
|
public void killIfExecuting(@NonNull final Context context, boolean processResult) {
|
||||||
// If execution command has already finished executing, then no need to process results or send SIGKILL
|
// If execution command has already finished executing, then no need to process results or send SIGKILL
|
||||||
if(mExecutionCommand.hasExecuted()) {
|
if (mExecutionCommand.hasExecuted()) {
|
||||||
Logger.logDebug(LOG_TAG, "Ignoring sending SIGKILL to \"" + mExecutionCommand.getCommandIdAndLabelLogString() + "\" TermuxSession since it has already finished executing");
|
Logger.logDebug(LOG_TAG, "Ignoring sending SIGKILL to \"" + mExecutionCommand.getCommandIdAndLabelLogString() + "\" TermuxSession since it has already finished executing");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -149,7 +149,7 @@ public final class TermuxTask {
|
|||||||
STDIN.close();
|
STDIN.close();
|
||||||
//STDIN.write("exit\n".getBytes(StandardCharsets.UTF_8));
|
//STDIN.write("exit\n".getBytes(StandardCharsets.UTF_8));
|
||||||
//STDIN.flush();
|
//STDIN.flush();
|
||||||
} catch(IOException e){
|
} catch(IOException e) {
|
||||||
if (e.getMessage().contains("EPIPE") || e.getMessage().contains("Stream closed")) {
|
if (e.getMessage().contains("EPIPE") || e.getMessage().contains("Stream closed")) {
|
||||||
// Method most horrid to catch broken pipe, in which case we
|
// Method most horrid to catch broken pipe, in which case we
|
||||||
// do nothing. The command is not a shell, the shell closed
|
// do nothing. The command is not a shell, the shell closed
|
||||||
@@ -218,7 +218,7 @@ public final class TermuxTask {
|
|||||||
*/
|
*/
|
||||||
public void killIfExecuting(@NonNull final Context context, boolean processResult) {
|
public void killIfExecuting(@NonNull final Context context, boolean processResult) {
|
||||||
// If execution command has already finished executing, then no need to process results or send SIGKILL
|
// If execution command has already finished executing, then no need to process results or send SIGKILL
|
||||||
if(mExecutionCommand.hasExecuted()) {
|
if (mExecutionCommand.hasExecuted()) {
|
||||||
Logger.logDebug(LOG_TAG, "Ignoring sending SIGKILL to \"" + mExecutionCommand.getCommandIdAndLabelLogString() + "\" TermuxTask since it has already finished executing");
|
Logger.logDebug(LOG_TAG, "Ignoring sending SIGKILL to \"" + mExecutionCommand.getCommandIdAndLabelLogString() + "\" TermuxTask since it has already finished executing");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user