diff --git a/app/build.gradle b/app/build.gradle index 17691e8a..47a4d6ec 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,8 +2,6 @@ plugins { id "com.android.application" } -ext.markwon_version='4.6.2' - android { compileSdkVersion project.properties.compileSdkVersion.toInteger() ndkVersion project.properties.ndkVersion @@ -15,16 +13,13 @@ android { implementation "androidx.preference:preference:1.1.1" implementation "androidx.viewpager:viewpager:1.0.0" implementation "com.google.guava:guava:24.1-jre" - implementation "io.noties.markwon:core:$markwon_version" - implementation "io.noties.markwon:ext-strikethrough:$markwon_version" - implementation "io.noties.markwon:linkify:$markwon_version" - implementation "io.noties.markwon:recycler:$markwon_version" - implementation project(":terminal-view") + implementation "io.noties.markwon:core:$markwonVersion" + implementation "io.noties.markwon:ext-strikethrough:$markwonVersion" + implementation "io.noties.markwon:linkify:$markwonVersion" + implementation "io.noties.markwon:recycler:$markwonVersion" - // Do not increment version higher than 2.5 or there - // will be runtime exceptions on android < 8 - // due to missing classes like java.nio.file.Path. - implementation "commons-io:commons-io:2.5" + implementation project(":terminal-view") + implementation project(":termux-shared") } defaultConfig { @@ -99,7 +94,7 @@ android { } dependencies { - testImplementation "junit:junit:4.13.1" + testImplementation "junit:junit:4.13.2" testImplementation "org.robolectric:robolectric:4.4" } diff --git a/app/src/main/java/com/termux/app/RunCommandService.java b/app/src/main/java/com/termux/app/RunCommandService.java index 800889bb..338b037c 100644 --- a/app/src/main/java/com/termux/app/RunCommandService.java +++ b/app/src/main/java/com/termux/app/RunCommandService.java @@ -12,13 +12,14 @@ import android.os.Build; import android.os.IBinder; import com.termux.R; -import com.termux.app.TermuxConstants.TERMUX_APP.RUN_COMMAND_SERVICE; -import com.termux.app.TermuxConstants.TERMUX_APP.TERMUX_SERVICE; -import com.termux.app.file.FileUtils; -import com.termux.app.utils.Logger; -import com.termux.app.utils.NotificationUtils; +import com.termux.shared.termux.TermuxConstants; +import com.termux.shared.termux.TermuxConstants.TERMUX_APP.RUN_COMMAND_SERVICE; +import com.termux.shared.termux.TermuxConstants.TERMUX_APP.TERMUX_SERVICE; +import com.termux.shared.file.FileUtils; +import com.termux.shared.logger.Logger; +import com.termux.shared.notification.NotificationUtils; import com.termux.app.utils.PluginUtils; -import com.termux.app.utils.DataUtils; +import com.termux.shared.data.DataUtils; import com.termux.app.models.ExecutionCommand; /** @@ -269,10 +270,6 @@ import com.termux.app.models.ExecutionCommand; */ public class RunCommandService extends Service { - private static final String NOTIFICATION_CHANNEL_ID = "termux_run_command_notification_channel"; - private static final String NOTIFICATION_CHANNEL_NAME = TermuxConstants.TERMUX_APP_NAME + " RunCommandService"; - public static final int NOTIFICATION_ID = 1338; - private static final String LOG_TAG = "RunCommandService"; class LocalBinder extends Binder { @@ -296,7 +293,7 @@ public class RunCommandService extends Service { public int onStartCommand(Intent intent, int flags, int startId) { 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 runStartForeground(); @@ -421,7 +418,7 @@ public class RunCommandService extends Service { private void runStartForeground() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { setupNotificationChannel(); - startForeground(NOTIFICATION_ID, buildNotification()); + startForeground(TermuxConstants.TERMUX_RUN_COMMAND_NOTIFICATION_ID, buildNotification()); } } @@ -434,8 +431,8 @@ public class RunCommandService extends Service { private Notification buildNotification() { // Build the notification Notification.Builder builder = NotificationUtils.geNotificationBuilder(this, - NOTIFICATION_CHANNEL_ID, Notification.PRIORITY_LOW, - NOTIFICATION_CHANNEL_NAME, null, null, + TermuxConstants.TERMUX_RUN_COMMAND_NOTIFICATION_CHANNEL_ID, Notification.PRIORITY_LOW, + TermuxConstants.TERMUX_RUN_COMMAND_NOTIFICATION_CHANNEL_NAME, null, null, null, NotificationUtils.NOTIFICATION_MODE_SILENT); if(builder == null) return null; @@ -454,8 +451,8 @@ public class RunCommandService extends Service { private void setupNotificationChannel() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return; - NotificationUtils.setupNotificationChannel(this, NOTIFICATION_CHANNEL_ID, - NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW); + NotificationUtils.setupNotificationChannel(this, TermuxConstants.TERMUX_RUN_COMMAND_NOTIFICATION_CHANNEL_ID, + TermuxConstants.TERMUX_RUN_COMMAND_NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW); } } diff --git a/app/src/main/java/com/termux/app/TermuxActivity.java b/app/src/main/java/com/termux/app/TermuxActivity.java index 750bee55..6ec5e9b3 100644 --- a/app/src/main/java/com/termux/app/TermuxActivity.java +++ b/app/src/main/java/com/termux/app/TermuxActivity.java @@ -31,22 +31,23 @@ import android.widget.ListView; import android.widget.Toast; import com.termux.R; -import com.termux.app.TermuxConstants.TERMUX_APP.TERMUX_ACTIVITY; +import com.termux.shared.termux.TermuxConstants; +import com.termux.shared.termux.TermuxConstants.TERMUX_APP.TERMUX_ACTIVITY; import com.termux.app.activities.HelpActivity; import com.termux.app.activities.SettingsActivity; -import com.termux.app.crash.CrashUtils; -import com.termux.app.settings.preferences.TermuxAppSharedPreferences; +import com.termux.shared.settings.preferences.TermuxAppSharedPreferences; import com.termux.app.terminal.TermuxSessionsListViewController; import com.termux.app.terminal.io.TerminalToolbarViewPager; import com.termux.app.terminal.TermuxSessionClient; import com.termux.app.terminal.TermuxViewClient; import com.termux.app.terminal.io.extrakeys.ExtraKeysView; -import com.termux.app.settings.properties.TermuxSharedProperties; -import com.termux.app.utils.DialogUtils; -import com.termux.app.utils.Logger; -import com.termux.app.utils.TermuxUtils; +import com.termux.app.settings.properties.TermuxAppSharedProperties; +import com.termux.shared.interact.DialogUtils; +import com.termux.shared.logger.Logger; +import com.termux.shared.termux.TermuxUtils; import com.termux.terminal.TerminalSession; import com.termux.terminal.TerminalSessionClient; +import com.termux.app.utils.CrashUtils; import com.termux.view.TerminalView; import com.termux.view.TerminalViewClient; @@ -101,7 +102,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection /** * Termux app shared properties manager, loaded from termux.properties */ - private TermuxSharedProperties mProperties; + private TermuxAppSharedProperties mProperties; /** * The terminal extra keys view. @@ -116,7 +117,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection /** * The {@link TermuxActivity} broadcast receiver for various things like terminal style configuration changes. */ - private final BroadcastReceiver mTermuxActivityBroadcastReceiever = new TermuxActivityBroadcastReceiever(); + private final BroadcastReceiver mTermuxActivityBroadcastReceiever = new TermuxActivityBroadcastReceiver(); /** * The last toast shown, used cancel current toast before showing new in {@link #showToast(String, boolean)}. @@ -161,7 +162,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection // Load termux shared preferences and properties mPreferences = new TermuxAppSharedPreferences(this); - mProperties = new TermuxSharedProperties(this); + mProperties = new TermuxAppSharedProperties(this); setActivityTheme(); @@ -327,7 +328,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection } @Override - public void onSaveInstanceState(Bundle savedInstanceState) { + public void onSaveInstanceState(@NonNull Bundle savedInstanceState) { super.onSaveInstanceState(savedInstanceState); saveTerminalToolbarTextInput(savedInstanceState); } @@ -383,6 +384,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection if(terminalToolbarViewPager == null) return; final boolean showNow = mPreferences.toogleShowTerminalToolbar(); + Logger.showToast(this, (showNow ? getString(R.string.msg_enabling_terminal_toolbar) : getString(R.string.msg_disabling_terminal_toolbar)), true); terminalToolbarViewPager.setVisibility(showNow ? View.VISIBLE : View.GONE); if (showNow && terminalToolbarViewPager.getCurrentItem() == 1) { // Focus the text input view if just revealed. @@ -704,7 +706,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection return mPreferences; } - public TermuxSharedProperties getProperties() { + public TermuxAppSharedProperties getProperties() { return mProperties; } @@ -718,7 +720,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection context.sendBroadcast(stylingIntent); } - class TermuxActivityBroadcastReceiever extends BroadcastReceiver { + class TermuxActivityBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (mIsVisible) { @@ -755,7 +757,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection // TermuxActivity.this.recreate(); } } - }; + } diff --git a/app/src/main/java/com/termux/app/TermuxApplication.java b/app/src/main/java/com/termux/app/TermuxApplication.java index 62713ac2..3bc6689c 100644 --- a/app/src/main/java/com/termux/app/TermuxApplication.java +++ b/app/src/main/java/com/termux/app/TermuxApplication.java @@ -2,9 +2,9 @@ package com.termux.app; import android.app.Application; -import com.termux.app.crash.CrashHandler; -import com.termux.app.settings.preferences.TermuxAppSharedPreferences; -import com.termux.app.utils.Logger; +import com.termux.shared.crash.CrashHandler; +import com.termux.shared.settings.preferences.TermuxAppSharedPreferences; +import com.termux.shared.logger.Logger; public class TermuxApplication extends Application { @@ -19,7 +19,7 @@ public class TermuxApplication extends Application { } private void setLogLevel() { - // Load the log level from shared preferences and set it to the {@link Loggger.CURRENT_LOG_LEVEL} + // Load the log level from shared preferences and set it to the {@link Logger.CURRENT_LOG_LEVEL} TermuxAppSharedPreferences preferences = new TermuxAppSharedPreferences(getApplicationContext()); preferences.setLogLevel(null, preferences.getLogLevel()); Logger.logDebug("Starting Application"); diff --git a/app/src/main/java/com/termux/app/TermuxInstaller.java b/app/src/main/java/com/termux/app/TermuxInstaller.java index 6c355bbf..bc258380 100644 --- a/app/src/main/java/com/termux/app/TermuxInstaller.java +++ b/app/src/main/java/com/termux/app/TermuxInstaller.java @@ -11,8 +11,9 @@ import android.util.Pair; import android.view.WindowManager; import com.termux.R; -import com.termux.app.file.FileUtils; -import com.termux.app.utils.Logger; +import com.termux.shared.file.FileUtils; +import com.termux.shared.logger.Logger; +import com.termux.shared.termux.TermuxConstants; import java.io.BufferedReader; import java.io.ByteArrayInputStream; diff --git a/app/src/main/java/com/termux/app/TermuxOpenReceiver.java b/app/src/main/java/com/termux/app/TermuxOpenReceiver.java index 455c2211..c3609dbc 100644 --- a/app/src/main/java/com/termux/app/TermuxOpenReceiver.java +++ b/app/src/main/java/com/termux/app/TermuxOpenReceiver.java @@ -13,7 +13,8 @@ import android.os.ParcelFileDescriptor; import android.provider.MediaStore; import android.webkit.MimeTypeMap; -import com.termux.app.utils.Logger; +import com.termux.shared.logger.Logger; +import com.termux.shared.termux.TermuxConstants; import java.io.File; import java.io.FileNotFoundException; diff --git a/app/src/main/java/com/termux/app/TermuxService.java b/app/src/main/java/com/termux/app/TermuxService.java index 77779b6c..e9d47799 100644 --- a/app/src/main/java/com/termux/app/TermuxService.java +++ b/app/src/main/java/com/termux/app/TermuxService.java @@ -20,17 +20,18 @@ import android.provider.Settings; import android.widget.ArrayAdapter; import com.termux.R; -import com.termux.app.TermuxConstants.TERMUX_APP.TERMUX_ACTIVITY; -import com.termux.app.TermuxConstants.TERMUX_APP.TERMUX_SERVICE; -import com.termux.app.settings.preferences.TermuxAppSharedPreferences; +import com.termux.shared.termux.TermuxConstants; +import com.termux.shared.termux.TermuxConstants.TERMUX_APP.TERMUX_ACTIVITY; +import com.termux.shared.termux.TermuxConstants.TERMUX_APP.TERMUX_SERVICE; +import com.termux.shared.settings.preferences.TermuxAppSharedPreferences; import com.termux.app.terminal.TermuxSession; import com.termux.app.terminal.TermuxSessionClient; import com.termux.app.terminal.TermuxSessionClientBase; -import com.termux.app.utils.Logger; -import com.termux.app.utils.NotificationUtils; -import com.termux.app.utils.PermissionUtils; -import com.termux.app.shell.ShellUtils; -import com.termux.app.utils.DataUtils; +import com.termux.shared.logger.Logger; +import com.termux.shared.notification.NotificationUtils; +import com.termux.shared.packages.PermissionUtils; +import com.termux.shared.shell.ShellUtils; +import com.termux.shared.data.DataUtils; import com.termux.app.models.ExecutionCommand; import com.termux.app.models.ExecutionCommand.ExecutionState; import com.termux.app.terminal.TermuxTask; @@ -38,7 +39,6 @@ import com.termux.terminal.TerminalEmulator; import com.termux.terminal.TerminalSession; import com.termux.terminal.TerminalSessionClient; -import java.io.File; import java.util.ArrayList; import java.util.List; @@ -58,10 +58,6 @@ import javax.annotation.Nullable; */ public final class TermuxService extends Service { - private static final String NOTIFICATION_CHANNEL_ID = "termux_notification_channel"; - private static final String NOTIFICATION_CHANNEL_NAME = TermuxConstants.TERMUX_APP_NAME + " App"; - public static final int NOTIFICATION_ID = 1337; - private static int EXECUTION_ID = 1000; /** This service is only bound from inside the same process and never uses IPC. */ @@ -95,7 +91,7 @@ public final class TermuxService extends Service { /** The basic implementation of the {@link TerminalSessionClient} interface to be used by {@link TerminalSession} * that does not hold activity references. */ - final TermuxSessionClientBase mTermuxSessionClientBase = new TermuxSessionClientBase();; + final TermuxSessionClientBase mTermuxSessionClientBase = new TermuxSessionClientBase(); /** The wake lock and wifi lock are always acquired and released together. */ private PowerManager.WakeLock mWakeLock; @@ -183,7 +179,7 @@ public final class TermuxService extends Service { /** Make service run in foreground mode. */ private void runStartForeground() { setupNotificationChannel(); - startForeground(NOTIFICATION_ID, buildNotification()); + startForeground(TermuxConstants.TERMUX_APP_NOTIFICATION_ID, buildNotification()); } /** Make service leave foreground mode. */ @@ -366,7 +362,7 @@ public final class TermuxService extends Service { if (newTermuxTask == null) { Logger.logError(LOG_TAG, "Failed to execute new termux task command for:\n" + executionCommand.getCommandIdAndLabelLogString()); return null; - }; + } mTermuxTasks.add(newTermuxTask); @@ -436,7 +432,7 @@ public final class TermuxService extends Service { if (newTermuxSession == null) { Logger.logError(LOG_TAG, "Failed to execute new termux session command for:\n" + executionCommand.getCommandIdAndLabelLogString()); return null; - }; + } mTermuxSessions.add(newTermuxSession); @@ -593,13 +589,13 @@ public final class TermuxService extends Service { // Set notification text int sessionCount = getTermuxSessionsSize(); int taskCount = mTermuxTasks.size(); - String notifiationText = sessionCount + " session" + (sessionCount == 1 ? "" : "s"); + String notificationText = sessionCount + " session" + (sessionCount == 1 ? "" : "s"); if (taskCount > 0) { - notifiationText += ", " + taskCount + " task" + (taskCount == 1 ? "" : "s"); + notificationText += ", " + taskCount + " task" + (taskCount == 1 ? "" : "s"); } final boolean wakeLockHeld = mWakeLock != null; - if (wakeLockHeld) notifiationText += " (wake lock held)"; + if (wakeLockHeld) notificationText += " (wake lock held)"; // Set notification priority @@ -610,8 +606,8 @@ public final class TermuxService extends Service { // Build the notification Notification.Builder builder = NotificationUtils.geNotificationBuilder(this, - NOTIFICATION_CHANNEL_ID, priority, - getText(R.string.application_name), notifiationText, null, + TermuxConstants.TERMUX_APP_NOTIFICATION_CHANNEL_ID, priority, + getText(R.string.application_name), notificationText, null, pendingIntent, NotificationUtils.NOTIFICATION_MODE_SILENT); if(builder == null) return null; @@ -647,8 +643,8 @@ public final class TermuxService extends Service { private void setupNotificationChannel() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return; - NotificationUtils.setupNotificationChannel(this, NOTIFICATION_CHANNEL_ID, - NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW); + NotificationUtils.setupNotificationChannel(this, TermuxConstants.TERMUX_APP_NOTIFICATION_CHANNEL_ID, + TermuxConstants.TERMUX_APP_NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW); } /** Update the shown foreground service notification after making any changes that affect it. */ @@ -657,7 +653,7 @@ public final class TermuxService extends Service { // Exit if we are updating after the user disabled all locks with no sessions or tasks running. requestStopService(); } else { - ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFICATION_ID, buildNotification()); + ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(TermuxConstants.TERMUX_APP_NOTIFICATION_ID, buildNotification()); } } diff --git a/app/src/main/java/com/termux/app/activities/ReportActivity.java b/app/src/main/java/com/termux/app/activities/ReportActivity.java index 3bf5bdce..2491005a 100644 --- a/app/src/main/java/com/termux/app/activities/ReportActivity.java +++ b/app/src/main/java/com/termux/app/activities/ReportActivity.java @@ -15,9 +15,9 @@ import android.view.MenuInflater; import android.view.MenuItem; import com.termux.R; -import com.termux.app.TermuxConstants; -import com.termux.app.utils.MarkdownUtils; -import com.termux.app.utils.ShareUtils; +import com.termux.shared.termux.TermuxConstants; +import com.termux.shared.markdown.MarkdownUtils; +import com.termux.shared.interact.ShareUtils; import com.termux.app.models.ReportInfo; import org.commonmark.node.FencedCodeBlock; diff --git a/app/src/main/java/com/termux/app/crash/CrashHandler.java b/app/src/main/java/com/termux/app/crash/CrashHandler.java deleted file mode 100644 index a1f18f07..00000000 --- a/app/src/main/java/com/termux/app/crash/CrashHandler.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.termux.app.crash; - -import android.content.Context; - -import androidx.annotation.NonNull; - -/** - * Catches uncaught exceptions and logs them. - */ -public class CrashHandler implements Thread.UncaughtExceptionHandler { - - private final Context context; - private final Thread.UncaughtExceptionHandler defaultUEH; - - private CrashHandler(final Context context) { - this.context = context; - this.defaultUEH = Thread.getDefaultUncaughtExceptionHandler(); - } - - public void uncaughtException(@NonNull Thread thread, @NonNull Throwable throwable) { - CrashUtils.logCrash(context,thread, throwable); - defaultUEH.uncaughtException(thread, throwable); - } - - /** - * Set default uncaught crash handler of current thread to {@link CrashHandler}. - */ - public static void setCrashHandler(final Context context) { - if (!(Thread.getDefaultUncaughtExceptionHandler() instanceof CrashHandler)) { - Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(context)); - } - } - -} diff --git a/app/src/main/java/com/termux/app/fragments/settings/DebuggingPreferencesFragment.java b/app/src/main/java/com/termux/app/fragments/settings/DebuggingPreferencesFragment.java index 61f99156..c34d70e2 100644 --- a/app/src/main/java/com/termux/app/fragments/settings/DebuggingPreferencesFragment.java +++ b/app/src/main/java/com/termux/app/fragments/settings/DebuggingPreferencesFragment.java @@ -11,8 +11,8 @@ import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceManager; import com.termux.R; -import com.termux.app.settings.preferences.TermuxAppSharedPreferences; -import com.termux.app.utils.Logger; +import com.termux.shared.settings.preferences.TermuxAppSharedPreferences; +import com.termux.shared.logger.Logger; public class DebuggingPreferencesFragment extends PreferenceFragmentCompat { diff --git a/app/src/main/java/com/termux/app/fragments/settings/TerminalIOPreferencesFragment.java b/app/src/main/java/com/termux/app/fragments/settings/TerminalIOPreferencesFragment.java index 874a87b4..0280b897 100644 --- a/app/src/main/java/com/termux/app/fragments/settings/TerminalIOPreferencesFragment.java +++ b/app/src/main/java/com/termux/app/fragments/settings/TerminalIOPreferencesFragment.java @@ -3,14 +3,12 @@ package com.termux.app.fragments.settings; import android.content.Context; import android.os.Bundle; -import androidx.annotation.Nullable; - import androidx.preference.PreferenceDataStore; import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceManager; import com.termux.R; -import com.termux.app.settings.preferences.TermuxAppSharedPreferences; +import com.termux.shared.settings.preferences.TermuxAppSharedPreferences; public class TerminalIOPreferencesFragment extends PreferenceFragmentCompat { diff --git a/app/src/main/java/com/termux/app/models/ExecutionCommand.java b/app/src/main/java/com/termux/app/models/ExecutionCommand.java index ec43b7e6..240af229 100644 --- a/app/src/main/java/com/termux/app/models/ExecutionCommand.java +++ b/app/src/main/java/com/termux/app/models/ExecutionCommand.java @@ -6,10 +6,10 @@ import android.net.Uri; import androidx.annotation.NonNull; -import com.termux.app.TermuxConstants.TERMUX_APP.TERMUX_SERVICE; -import com.termux.app.utils.Logger; -import com.termux.app.utils.MarkdownUtils; -import com.termux.app.utils.DataUtils; +import com.termux.shared.termux.TermuxConstants.TERMUX_APP.TERMUX_SERVICE; +import com.termux.shared.logger.Logger; +import com.termux.shared.markdown.MarkdownUtils; +import com.termux.shared.data.DataUtils; import java.util.ArrayList; import java.util.List; @@ -112,7 +112,7 @@ public class ExecutionCommand { /** The stdout of shell command. */ public String stdout; - /** The sterr of shell command. */ + /** The stderr of shell command. */ public String stderr; /** The exit code of shell command. */ public Integer exitCode; diff --git a/app/src/main/java/com/termux/app/models/ReportInfo.java b/app/src/main/java/com/termux/app/models/ReportInfo.java index a4d62f15..05c8853d 100644 --- a/app/src/main/java/com/termux/app/models/ReportInfo.java +++ b/app/src/main/java/com/termux/app/models/ReportInfo.java @@ -1,30 +1,30 @@ package com.termux.app.models; -import com.termux.app.utils.MarkdownUtils; -import com.termux.app.utils.TermuxUtils; +import com.termux.shared.markdown.MarkdownUtils; +import com.termux.shared.termux.TermuxUtils; import java.io.Serializable; public class ReportInfo implements Serializable { /** The user action that was being processed for which the report was generated. */ - public UserAction userAction; + public final UserAction userAction; /** The internal app component that sent the report. */ - public String sender; + public final String sender; /** The report title. */ - public String reportTitle; + public final String reportTitle; /** The markdown report text prefix. Will not be part of copy and share operations, etc. */ - public String reportStringPrefix; + public final String reportStringPrefix; /** The markdown report text. */ - public String reportString; + public final String reportString; /** The markdown report text suffix. Will not be part of copy and share operations, etc. */ - public String reportStringSuffix; + public final String reportStringSuffix; /** If set to {@code true}, then report, app and device info will be added to the report when * markdown is generated. */ - public boolean addReportInfoToMarkdown; + public final boolean addReportInfoToMarkdown; /** The timestamp for the report. */ - public String reportTimestammp; + public final String reportTimestamp; public ReportInfo(UserAction userAction, String sender, String reportTitle, String reportStringPrefix, String reportString, String reportStringSuffix, boolean addReportInfoToMarkdown) { this.userAction = userAction; @@ -34,7 +34,7 @@ public class ReportInfo implements Serializable { this.reportString = reportString; this.reportStringSuffix = reportStringSuffix; this.addReportInfoToMarkdown = addReportInfoToMarkdown; - this.reportTimestammp = TermuxUtils.getCurrentTimeStamp(); + this.reportTimestamp = TermuxUtils.getCurrentTimeStamp(); } /** @@ -52,7 +52,7 @@ public class ReportInfo implements Serializable { markdownString.append("## Report Info\n\n"); markdownString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("User Action", reportInfo.userAction, "-")); markdownString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("Sender", reportInfo.sender, "-")); - markdownString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("Report Timestamp", reportInfo.reportTimestammp, "-")); + markdownString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("Report Timestamp", reportInfo.reportTimestamp, "-")); markdownString.append("\n##\n\n"); } diff --git a/app/src/main/java/com/termux/app/settings/properties/TermuxAppSharedProperties.java b/app/src/main/java/com/termux/app/settings/properties/TermuxAppSharedProperties.java new file mode 100644 index 00000000..4153a426 --- /dev/null +++ b/app/src/main/java/com/termux/app/settings/properties/TermuxAppSharedProperties.java @@ -0,0 +1,99 @@ +package com.termux.app.settings.properties; + +import android.content.Context; + +import com.termux.app.terminal.io.KeyboardShortcut; +import com.termux.app.terminal.io.extrakeys.ExtraKeysInfo; +import com.termux.shared.logger.Logger; +import com.termux.shared.settings.properties.SharedPropertiesParser; +import com.termux.shared.settings.properties.TermuxPropertyConstants; +import com.termux.shared.settings.properties.TermuxSharedProperties; + +import org.json.JSONException; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.annotation.Nonnull; + +public class TermuxAppSharedProperties extends TermuxSharedProperties implements SharedPropertiesParser { + + private ExtraKeysInfo mExtraKeysInfo; + private List mSessionShortcuts = new ArrayList<>(); + + private static final String LOG_TAG = "TermuxAppSharedProperties"; + + public TermuxAppSharedProperties(@Nonnull Context context) { + super(context); + } + + /** + * Reload the termux properties from disk into an in-memory cache. + */ + @Override + public void loadTermuxPropertiesFromDisk() { + super.loadTermuxPropertiesFromDisk(); + + setExtraKeys(); + setSessionShortcuts(); + } + + /** + * Set the terminal extra keys and style. + */ + private void setExtraKeys() { + mExtraKeysInfo = null; + + try { + // The mMap stores the extra key and style string values while loading properties + // Check {@link #getExtraKeysInternalPropertyValueFromValue(String)} and + // {@link #getExtraKeysStyleInternalPropertyValueFromValue(String)} + String extrakeys = (String) getInternalPropertyValue(TermuxPropertyConstants.KEY_EXTRA_KEYS, true); + String extraKeysStyle = (String) getInternalPropertyValue(TermuxPropertyConstants.KEY_EXTRA_KEYS_STYLE, true); + mExtraKeysInfo = new ExtraKeysInfo(extrakeys, extraKeysStyle); + } catch (JSONException e) { + Logger.showToast(mContext, "Could not load and set the \"" + TermuxPropertyConstants.KEY_EXTRA_KEYS + "\" property from the properties file: " + e.toString(), true); + Logger.logStackTraceWithMessage(LOG_TAG, "Could not load and set the \"" + TermuxPropertyConstants.KEY_EXTRA_KEYS + "\" property from the properties file: ", e); + + try { + mExtraKeysInfo = new ExtraKeysInfo(TermuxPropertyConstants.DEFAULT_IVALUE_EXTRA_KEYS, TermuxPropertyConstants.DEFAULT_IVALUE_EXTRA_KEYS_STYLE); + } catch (JSONException e2) { + Logger.showToast(mContext, "Can't create default extra keys",true); + Logger.logStackTraceWithMessage(LOG_TAG, "Could create default extra keys: ", e); + mExtraKeysInfo = null; + } + } + } + + /** + * Set the terminal sessions shortcuts. + */ + private void setSessionShortcuts() { + if(mSessionShortcuts == null) + mSessionShortcuts = new ArrayList<>(); + else + mSessionShortcuts.clear(); + + // The {@link TermuxPropertyConstants#MAP_SESSION_SHORTCUTS} stores the session shortcut key and action pair + for (Map.Entry entry : TermuxPropertyConstants.MAP_SESSION_SHORTCUTS.entrySet()) { + // The mMap stores the code points for the session shortcuts while loading properties + Integer codePoint = (Integer) getInternalPropertyValue(entry.getKey(), true); + // If codePoint is null, then session shortcut did not exist in properties or was invalid + // as parsed by {@link #getCodePointForSessionShortcuts(String,String)} + // If codePoint is not null, then get the action for the MAP_SESSION_SHORTCUTS key and + // add the code point to sessionShortcuts + if (codePoint != null) + mSessionShortcuts.add(new KeyboardShortcut(codePoint, entry.getValue())); + } + } + + public List getSessionShortcuts() { + return mSessionShortcuts; + } + + public ExtraKeysInfo getExtraKeysInfo() { + return mExtraKeysInfo; + } + +} diff --git a/app/src/main/java/com/termux/app/terminal/TermuxSession.java b/app/src/main/java/com/termux/app/terminal/TermuxSession.java index b282b1f0..7b8381e3 100644 --- a/app/src/main/java/com/termux/app/terminal/TermuxSession.java +++ b/app/src/main/java/com/termux/app/terminal/TermuxSession.java @@ -3,11 +3,11 @@ package com.termux.app.terminal; import androidx.annotation.NonNull; import com.termux.R; -import com.termux.app.TermuxConstants; +import com.termux.shared.termux.TermuxConstants; import com.termux.app.TermuxService; -import com.termux.app.utils.Logger; +import com.termux.shared.logger.Logger; import com.termux.app.utils.PluginUtils; -import com.termux.app.shell.ShellUtils; +import com.termux.shared.shell.ShellUtils; import com.termux.app.models.ExecutionCommand; import com.termux.terminal.TerminalSession; diff --git a/app/src/main/java/com/termux/app/terminal/TermuxSessionClient.java b/app/src/main/java/com/termux/app/terminal/TermuxSessionClient.java index 96fc3849..2dbc5552 100644 --- a/app/src/main/java/com/termux/app/terminal/TermuxSessionClient.java +++ b/app/src/main/java/com/termux/app/terminal/TermuxSessionClient.java @@ -13,13 +13,13 @@ import android.text.TextUtils; import android.widget.ListView; import com.termux.R; -import com.termux.app.utils.DialogUtils; +import com.termux.shared.interact.DialogUtils; import com.termux.app.TermuxActivity; -import com.termux.app.TermuxConstants; +import com.termux.shared.termux.TermuxConstants; import com.termux.app.TermuxService; -import com.termux.app.settings.properties.TermuxPropertyConstants; +import com.termux.shared.settings.properties.TermuxPropertyConstants; import com.termux.app.terminal.io.BellHandler; -import com.termux.app.utils.Logger; +import com.termux.shared.logger.Logger; import com.termux.terminal.TerminalColors; import com.termux.terminal.TerminalSession; import com.termux.terminal.TextStyle; @@ -31,15 +31,15 @@ import java.util.Properties; public class TermuxSessionClient extends TermuxSessionClientBase { - final TermuxActivity mActivity; + private final TermuxActivity mActivity; private static final int MAX_SESSIONS = 8; - final SoundPool mBellSoundPool = new SoundPool.Builder().setMaxStreams(1).setAudioAttributes( + private final SoundPool mBellSoundPool = new SoundPool.Builder().setMaxStreams(1).setAudioAttributes( new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION).build()).build(); - int mBellSoundId; + private final int mBellSoundId; private static final String LOG_TAG = "TermuxSessionClient"; diff --git a/app/src/main/java/com/termux/app/terminal/TermuxSessionClientBase.java b/app/src/main/java/com/termux/app/terminal/TermuxSessionClientBase.java index 7404ed00..cb0dec8f 100644 --- a/app/src/main/java/com/termux/app/terminal/TermuxSessionClientBase.java +++ b/app/src/main/java/com/termux/app/terminal/TermuxSessionClientBase.java @@ -1,6 +1,6 @@ package com.termux.app.terminal; -import com.termux.app.utils.Logger; +import com.termux.shared.logger.Logger; import com.termux.terminal.TerminalSession; import com.termux.terminal.TerminalSessionClient; diff --git a/app/src/main/java/com/termux/app/terminal/TermuxTask.java b/app/src/main/java/com/termux/app/terminal/TermuxTask.java index 0c0143ee..f70ee9e5 100644 --- a/app/src/main/java/com/termux/app/terminal/TermuxTask.java +++ b/app/src/main/java/com/termux/app/terminal/TermuxTask.java @@ -3,12 +3,12 @@ package com.termux.app.terminal; import androidx.annotation.NonNull; import com.termux.R; -import com.termux.app.TermuxConstants; +import com.termux.shared.termux.TermuxConstants; import com.termux.app.TermuxService; -import com.termux.app.shell.StreamGobbler; -import com.termux.app.utils.Logger; +import com.termux.shared.shell.StreamGobbler; +import com.termux.shared.logger.Logger; import com.termux.app.utils.PluginUtils; -import com.termux.app.shell.ShellUtils; +import com.termux.shared.shell.ShellUtils; import com.termux.app.models.ExecutionCommand; import com.termux.app.models.ExecutionCommand.ExecutionState; diff --git a/app/src/main/java/com/termux/app/terminal/TermuxViewClient.java b/app/src/main/java/com/termux/app/terminal/TermuxViewClient.java index 329e8f41..08586fe5 100644 --- a/app/src/main/java/com/termux/app/terminal/TermuxViewClient.java +++ b/app/src/main/java/com/termux/app/terminal/TermuxViewClient.java @@ -20,17 +20,17 @@ import android.widget.Toast; import com.termux.R; import com.termux.app.TermuxActivity; -import com.termux.app.TermuxConstants; +import com.termux.shared.termux.TermuxConstants; import com.termux.app.activities.ReportActivity; import com.termux.app.models.ReportInfo; import com.termux.app.models.UserAction; import com.termux.app.terminal.io.KeyboardShortcut; import com.termux.app.terminal.io.extrakeys.ExtraKeysView; -import com.termux.app.settings.properties.TermuxPropertyConstants; -import com.termux.app.utils.DataUtils; -import com.termux.app.utils.Logger; -import com.termux.app.utils.MarkdownUtils; -import com.termux.app.utils.TermuxUtils; +import com.termux.shared.settings.properties.TermuxPropertyConstants; +import com.termux.shared.data.DataUtils; +import com.termux.shared.logger.Logger; +import com.termux.shared.markdown.MarkdownUtils; +import com.termux.shared.termux.TermuxUtils; import com.termux.terminal.KeyHandler; import com.termux.terminal.TerminalEmulator; import com.termux.terminal.TerminalSession; @@ -81,7 +81,7 @@ public class TermuxViewClient implements TerminalViewClient { } @Override - public boolean shouldEnforeCharBasedInput() { + public boolean shouldEnforceCharBasedInput() { return mActivity.getProperties().isEnforcingCharBasedInput(); } @@ -301,7 +301,7 @@ public class TermuxViewClient implements TerminalViewClient { } List shortcuts = mActivity.getProperties().getSessionShortcuts(); - if (!shortcuts.isEmpty()) { + if (shortcuts != null && !shortcuts.isEmpty()) { int codePointLowerCase = Character.toLowerCase(codePoint); for (int i = shortcuts.size() - 1; i >= 0; i--) { KeyboardShortcut shortcut = shortcuts.get(i); diff --git a/app/src/main/java/com/termux/app/terminal/io/BellHandler.java b/app/src/main/java/com/termux/app/terminal/io/BellHandler.java index 490bd2fd..728e12e6 100644 --- a/app/src/main/java/com/termux/app/terminal/io/BellHandler.java +++ b/app/src/main/java/com/termux/app/terminal/io/BellHandler.java @@ -47,7 +47,7 @@ public class BellHandler { if (timeSinceLastBell < 0) { // there is a next bell pending; don't schedule another one } else if (timeSinceLastBell < MIN_PAUSE) { - // there was a bell recently, scheudle the next one + // there was a bell recently, schedule the next one handler.postDelayed(bellRunnable, MIN_PAUSE - timeSinceLastBell); lastBell = lastBell + MIN_PAUSE; } else { diff --git a/app/src/main/java/com/termux/app/terminal/io/extrakeys/ExtraKeyButton.java b/app/src/main/java/com/termux/app/terminal/io/extrakeys/ExtraKeyButton.java index 2701a9ec..94540819 100644 --- a/app/src/main/java/com/termux/app/terminal/io/extrakeys/ExtraKeyButton.java +++ b/app/src/main/java/com/termux/app/terminal/io/extrakeys/ExtraKeyButton.java @@ -33,7 +33,7 @@ public class ExtraKeyButton { * The information of the popup (triggered by swipe up). */ @Nullable - private ExtraKeyButton popup = null; + private ExtraKeyButton popup; public ExtraKeyButton(ExtraKeysInfo.CharDisplayMap charDisplayMap, JSONObject config) throws JSONException { this(charDisplayMap, config, null); diff --git a/app/src/main/java/com/termux/app/terminal/io/extrakeys/ExtraKeysInfo.java b/app/src/main/java/com/termux/app/terminal/io/extrakeys/ExtraKeysInfo.java index 12fe30a9..d71f3926 100644 --- a/app/src/main/java/com/termux/app/terminal/io/extrakeys/ExtraKeysInfo.java +++ b/app/src/main/java/com/termux/app/terminal/io/extrakeys/ExtraKeysInfo.java @@ -16,7 +16,7 @@ public class ExtraKeysInfo { /** * This corresponds to one of the CharMapDisplay below */ - private String style = "default"; + private String style; public ExtraKeysInfo(String propertiesInfo, String style) throws JSONException { this.style = style; diff --git a/app/src/main/java/com/termux/app/crash/CrashUtils.java b/app/src/main/java/com/termux/app/utils/CrashUtils.java similarity index 62% rename from app/src/main/java/com/termux/app/crash/CrashUtils.java rename to app/src/main/java/com/termux/app/utils/CrashUtils.java index e1af3dd0..a192e5ab 100644 --- a/app/src/main/java/com/termux/app/crash/CrashUtils.java +++ b/app/src/main/java/com/termux/app/utils/CrashUtils.java @@ -1,4 +1,4 @@ -package com.termux.app.crash; +package com.termux.app.utils; import android.app.Notification; import android.app.NotificationManager; @@ -10,66 +10,33 @@ import androidx.annotation.Nullable; import com.termux.R; import com.termux.app.activities.ReportActivity; -import com.termux.app.file.FileUtils; +import com.termux.shared.notification.NotificationUtils; +import com.termux.shared.file.FileUtils; import com.termux.app.models.ReportInfo; import com.termux.app.models.UserAction; -import com.termux.app.settings.preferences.TermuxAppSharedPreferences; -import com.termux.app.settings.preferences.TermuxPreferenceConstants; -import com.termux.app.utils.DataUtils; -import com.termux.app.utils.Logger; -import com.termux.app.utils.MarkdownUtils; -import com.termux.app.utils.NotificationUtils; -import com.termux.app.utils.TermuxUtils; +import com.termux.shared.settings.preferences.TermuxAppSharedPreferences; +import com.termux.shared.settings.preferences.TermuxPreferenceConstants; +import com.termux.shared.data.DataUtils; +import com.termux.shared.logger.Logger; +import com.termux.shared.termux.TermuxUtils; -import com.termux.app.TermuxConstants; +import com.termux.shared.termux.TermuxConstants; import java.nio.charset.Charset; public class CrashUtils { - private static final String NOTIFICATION_CHANNEL_ID_CRASH_REPORT_ERRORS = "termux_crash_reports_notification_channel"; - private static final String NOTIFICATION_CHANNEL_NAME_CRASH_REPORT_ERRORS = TermuxConstants.TERMUX_APP_NAME + " Crash Reports"; - private static final String LOG_TAG = "CrashUtils"; - /** - * Log a crash in the crash log file at - * {@link TermuxConstants#TERMUX_CRASH_LOG_FILE_PATH}. - * - * @param context The {@link Context} for operations. - * @param thread The {@link Thread} in which the crash happened. - * @param thread The {@link Throwable} thrown for the crash. - */ - public static void logCrash(final Context context, final Thread thread, final Throwable throwable) { - - StringBuilder reportString = new StringBuilder(); - - reportString.append("## Crash Details\n"); - reportString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("Crash Thread", thread.toString(), "-")); - reportString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("Crash Timestamp", TermuxUtils.getCurrentTimeStamp(), "-")); - - reportString.append("\n\n").append(Logger.getStackTracesMarkdownString("Stacktrace", Logger.getStackTraceStringArray(throwable))); - reportString.append("\n\n").append(TermuxUtils.getAppInfoMarkdownString(context, true)); - reportString.append("\n\n").append(TermuxUtils.getDeviceInfoMarkdownString(context)); - - // Log report string to logcat - Logger.logError(reportString.toString()); - - // Write report string to crash log file - String errmsg = FileUtils.writeStringToFile(context, "crash log", TermuxConstants.TERMUX_CRASH_LOG_FILE_PATH, Charset.defaultCharset(), reportString.toString(), false); - if (errmsg != null) { - Logger.logError(LOG_TAG, errmsg); - } - } - /** * Notify the user of a previous app crash by reading the crash info from the crash log file at - * {@link TermuxConstants#TERMUX_CRASH_LOG_FILE_PATH}. + * {@link TermuxConstants#TERMUX_CRASH_LOG_FILE_PATH}. The crash log file would have been + * created by {@link com.termux.shared.crash.CrashHandler}. * * If the crash log file exists and is not empty and * {@link TermuxPreferenceConstants.TERMUX_APP#KEY_CRASH_REPORT_NOTIFICATIONS_ENABLED} is * enabled, then a notification will be shown for the crash on the - * {@link #NOTIFICATION_CHANNEL_NAME_CRASH_REPORT_ERRORS} channel, otherwise nothing will be done. + * {@link TermuxConstants#TERMUX_CRASH_REPORTS_NOTIFICATION_CHANNEL_NAME} channel, otherwise nothing will be done. * * After reading from the crash log file, it will be moved to {@link TermuxConstants#TERMUX_CRASH_LOG_BACKUP_FILE_PATH}. * @@ -140,23 +107,23 @@ public class CrashUtils { } /** - * Get {@link Notification.Builder} for {@link #NOTIFICATION_CHANNEL_ID_CRASH_REPORT_ERRORS} - * and {@link #NOTIFICATION_CHANNEL_NAME_CRASH_REPORT_ERRORS}. + * Get {@link Notification.Builder} for {@link TermuxConstants#TERMUX_CRASH_REPORTS_NOTIFICATION_CHANNEL_ID} + * and {@link TermuxConstants#TERMUX_CRASH_REPORTS_NOTIFICATION_CHANNEL_NAME}. * * @param context The {@link Context} for operations. * @param title The title for the notification. - * @param notifiationText The second line text of the notification. + * @param notificationText The second line text of the notification. * @param notificationBigText The full text of the notification that may optionally be styled. * @param pendingIntent The {@link PendingIntent} which should be sent when notification is clicked. * @param notificationMode The notification mode. It must be one of {@code NotificationUtils.NOTIFICATION_MODE_*}. * @return Returns the {@link Notification.Builder}. */ @Nullable - public static Notification.Builder getCrashReportsNotificationBuilder(final Context context, final CharSequence title, final CharSequence notifiationText, final CharSequence notificationBigText, final PendingIntent pendingIntent, final int notificationMode) { + public static Notification.Builder getCrashReportsNotificationBuilder(final Context context, final CharSequence title, final CharSequence notificationText, final CharSequence notificationBigText, final PendingIntent pendingIntent, final int notificationMode) { Notification.Builder builder = NotificationUtils.geNotificationBuilder(context, - NOTIFICATION_CHANNEL_ID_CRASH_REPORT_ERRORS, Notification.PRIORITY_HIGH, - title, notifiationText, notificationBigText, pendingIntent, notificationMode); + TermuxConstants.TERMUX_CRASH_REPORTS_NOTIFICATION_CHANNEL_ID, Notification.PRIORITY_HIGH, + title, notificationText, notificationBigText, pendingIntent, notificationMode); if (builder == null) return null; @@ -176,14 +143,14 @@ public class CrashUtils { } /** - * Setup the notification channel for {@link #NOTIFICATION_CHANNEL_ID_CRASH_REPORT_ERRORS} and - * {@link #NOTIFICATION_CHANNEL_NAME_CRASH_REPORT_ERRORS}. + * Setup the notification channel for {@link TermuxConstants#TERMUX_CRASH_REPORTS_NOTIFICATION_CHANNEL_ID} and + * {@link TermuxConstants#TERMUX_CRASH_REPORTS_NOTIFICATION_CHANNEL_NAME}. * * @param context The {@link Context} for operations. */ public static void setupCrashReportsNotificationChannel(final Context context) { - NotificationUtils.setupNotificationChannel(context, NOTIFICATION_CHANNEL_ID_CRASH_REPORT_ERRORS, - NOTIFICATION_CHANNEL_NAME_CRASH_REPORT_ERRORS, NotificationManager.IMPORTANCE_HIGH); + NotificationUtils.setupNotificationChannel(context, TermuxConstants.TERMUX_CRASH_REPORTS_NOTIFICATION_CHANNEL_ID, + TermuxConstants.TERMUX_CRASH_REPORTS_NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH); } } diff --git a/app/src/main/java/com/termux/app/utils/PluginUtils.java b/app/src/main/java/com/termux/app/utils/PluginUtils.java index f95dd35a..a174c0d5 100644 --- a/app/src/main/java/com/termux/app/utils/PluginUtils.java +++ b/app/src/main/java/com/termux/app/utils/PluginUtils.java @@ -11,22 +11,24 @@ import android.os.Bundle; import androidx.annotation.Nullable; import com.termux.R; -import com.termux.app.TermuxConstants; -import com.termux.app.TermuxConstants.TERMUX_APP.TERMUX_SERVICE; +import com.termux.shared.notification.NotificationUtils; +import com.termux.shared.termux.TermuxConstants; +import com.termux.shared.termux.TermuxConstants.TERMUX_APP.TERMUX_SERVICE; import com.termux.app.activities.ReportActivity; -import com.termux.app.settings.preferences.TermuxAppSharedPreferences; -import com.termux.app.settings.preferences.TermuxPreferenceConstants.TERMUX_APP; -import com.termux.app.settings.properties.SharedProperties; -import com.termux.app.settings.properties.TermuxPropertyConstants; +import com.termux.shared.logger.Logger; +import com.termux.shared.settings.preferences.TermuxAppSharedPreferences; +import com.termux.shared.settings.preferences.TermuxPreferenceConstants.TERMUX_APP; +import com.termux.shared.settings.properties.SharedProperties; +import com.termux.shared.settings.properties.TermuxPropertyConstants; import com.termux.app.models.ReportInfo; import com.termux.app.models.ExecutionCommand; import com.termux.app.models.UserAction; +import com.termux.shared.data.DataUtils; +import com.termux.shared.markdown.MarkdownUtils; +import com.termux.shared.termux.TermuxUtils; public class PluginUtils { - private static final String NOTIFICATION_CHANNEL_ID_PLUGIN_COMMAND_ERRORS = "termux_plugin_command_errors_notification_channel"; - private static final String NOTIFICATION_CHANNEL_NAME_PLUGIN_COMMAND_ERRORS = TermuxConstants.TERMUX_APP_NAME + " Plugin Commands Errors"; - /** Required file permissions for the executable file of execute intent. Executable file must have read and execute permissions */ public static final String PLUGIN_EXECUTABLE_FILE_PERMISSIONS = "r-x"; // Default: "r-x" /** Required file permissions for the working directory of execute intent. Working directory must have read and write permissions. @@ -95,7 +97,7 @@ public class PluginUtils { * * Otherwise if the {@link TERMUX_APP#KEY_PLUGIN_ERROR_NOTIFICATIONS_ENABLED} is * enabled, then a flash and a notification will be shown for the error as well - * on the {@link #NOTIFICATION_CHANNEL_NAME_PLUGIN_COMMAND_ERRORS} channel instead of just logging + * on the {@link TermuxConstants#TERMUX_PLUGIN_COMMAND_ERRORS_NOTIFICATION_CHANNEL_NAME} channel instead of just logging * the error. * * @param context The {@link Context} for operations. @@ -162,11 +164,11 @@ public class PluginUtils { setupPluginCommandErrorsNotificationChannel(context); // Use markdown in notification - CharSequence notifiationText = MarkdownUtils.getSpannedMarkdownText(context, executionCommand.errmsg); - //CharSequence notifiationText = executionCommand.errmsg; + CharSequence notificationText = MarkdownUtils.getSpannedMarkdownText(context, executionCommand.errmsg); + //CharSequence notificationText = executionCommand.errmsg; // Build the notification - Notification.Builder builder = getPluginCommandErrorsNotificationBuilder(context, title, notifiationText, notifiationText, pendingIntent, NotificationUtils.NOTIFICATION_MODE_VIBRATE); + Notification.Builder builder = getPluginCommandErrorsNotificationBuilder(context, title, notificationText, notificationText, pendingIntent, NotificationUtils.NOTIFICATION_MODE_VIBRATE); if(builder == null) return; // Send the notification @@ -202,7 +204,6 @@ public class PluginUtils { String truncatedStdout = null; String truncatedStderr = null; - String truncatedErrmsg = null; String stdoutOriginalLength = (stdout == null) ? null: String.valueOf(stdout.length()); String stderrOriginalLength = (stderr == null) ? null: String.valueOf(stderr.length()); @@ -231,7 +232,7 @@ public class PluginUtils { // Truncate errmsg to max TRANSACTION_SIZE_LIMIT_IN_BYTES / 4 // trim from end to preserve start of stacktraces - 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()){ Logger.logWarn(logTag, "Execution Result for Execution Command \"" + label + "\" errmsg length truncated from " + errmsgOriginalLength + " to " + truncatedErrmsg.length()); errmsg = truncatedErrmsg; @@ -262,23 +263,23 @@ public class PluginUtils { /** - * Get {@link Notification.Builder} for {@link #NOTIFICATION_CHANNEL_ID_PLUGIN_COMMAND_ERRORS} - * and {@link #NOTIFICATION_CHANNEL_NAME_PLUGIN_COMMAND_ERRORS}. + * Get {@link Notification.Builder} for {@link TermuxConstants#TERMUX_PLUGIN_COMMAND_ERRORS_NOTIFICATION_CHANNEL_ID} + * and {@link TermuxConstants#TERMUX_PLUGIN_COMMAND_ERRORS_NOTIFICATION_CHANNEL_NAME}. * * @param context The {@link Context} for operations. * @param title The title for the notification. - * @param notifiationText The second line text of the notification. + * @param notificationText The second line text of the notification. * @param notificationBigText The full text of the notification that may optionally be styled. * @param pendingIntent The {@link PendingIntent} which should be sent when notification is clicked. * @param notificationMode The notification mode. It must be one of {@code NotificationUtils.NOTIFICATION_MODE_*}. * @return Returns the {@link Notification.Builder}. */ @Nullable - public static Notification.Builder getPluginCommandErrorsNotificationBuilder(final Context context, final CharSequence title, final CharSequence notifiationText, final CharSequence notificationBigText, final PendingIntent pendingIntent, final int notificationMode) { + public static Notification.Builder getPluginCommandErrorsNotificationBuilder(final Context context, final CharSequence title, final CharSequence notificationText, final CharSequence notificationBigText, final PendingIntent pendingIntent, final int notificationMode) { Notification.Builder builder = NotificationUtils.geNotificationBuilder(context, - NOTIFICATION_CHANNEL_ID_PLUGIN_COMMAND_ERRORS, Notification.PRIORITY_HIGH, - title, notifiationText, notificationBigText, pendingIntent, notificationMode); + TermuxConstants.TERMUX_PLUGIN_COMMAND_ERRORS_NOTIFICATION_CHANNEL_ID, Notification.PRIORITY_HIGH, + title, notificationText, notificationBigText, pendingIntent, notificationMode); if(builder == null) return null; @@ -298,14 +299,14 @@ public class PluginUtils { } /** - * Setup the notification channel for {@link #NOTIFICATION_CHANNEL_ID_PLUGIN_COMMAND_ERRORS} and - * {@link #NOTIFICATION_CHANNEL_NAME_PLUGIN_COMMAND_ERRORS}. + * Setup the notification channel for {@link TermuxConstants#TERMUX_PLUGIN_COMMAND_ERRORS_NOTIFICATION_CHANNEL_ID} and + * {@link TermuxConstants#TERMUX_PLUGIN_COMMAND_ERRORS_NOTIFICATION_CHANNEL_NAME}. * * @param context The {@link Context} for operations. */ public static void setupPluginCommandErrorsNotificationChannel(final Context context) { - NotificationUtils.setupNotificationChannel(context, NOTIFICATION_CHANNEL_ID_PLUGIN_COMMAND_ERRORS, - NOTIFICATION_CHANNEL_NAME_PLUGIN_COMMAND_ERRORS, NotificationManager.IMPORTANCE_HIGH); + NotificationUtils.setupNotificationChannel(context, TermuxConstants.TERMUX_PLUGIN_COMMAND_ERRORS_NOTIFICATION_CHANNEL_ID, + TermuxConstants.TERMUX_PLUGIN_COMMAND_ERRORS_NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH); } diff --git a/app/src/main/java/com/termux/filepicker/TermuxDocumentsProvider.java b/app/src/main/java/com/termux/filepicker/TermuxDocumentsProvider.java index 0a4de74f..7974d6db 100644 --- a/app/src/main/java/com/termux/filepicker/TermuxDocumentsProvider.java +++ b/app/src/main/java/com/termux/filepicker/TermuxDocumentsProvider.java @@ -12,7 +12,7 @@ import android.provider.DocumentsProvider; import android.webkit.MimeTypeMap; import com.termux.R; -import com.termux.app.TermuxConstants; +import com.termux.shared.termux.TermuxConstants; import java.io.File; import java.io.FileNotFoundException; @@ -63,9 +63,9 @@ public class TermuxDocumentsProvider extends DocumentsProvider { }; @Override - public Cursor queryRoots(String[] projection) throws FileNotFoundException { + public Cursor queryRoots(String[] projection) { final MatrixCursor result = new MatrixCursor(projection != null ? projection : DEFAULT_ROOT_PROJECTION); - @SuppressWarnings("ConstantConditions") final String applicationName = getContext().getString(R.string.application_name); + final String applicationName = getContext().getString(R.string.application_name); final MatrixCursor.RowBuilder row = result.newRow(); row.add(Root.COLUMN_ROOT_ID, getDocIdForFile(BASE_DIR)); diff --git a/app/src/main/java/com/termux/filepicker/TermuxFileReceiverActivity.java b/app/src/main/java/com/termux/filepicker/TermuxFileReceiverActivity.java index 8a279fca..ccee5765 100644 --- a/app/src/main/java/com/termux/filepicker/TermuxFileReceiverActivity.java +++ b/app/src/main/java/com/termux/filepicker/TermuxFileReceiverActivity.java @@ -9,11 +9,11 @@ import android.provider.OpenableColumns; import android.util.Patterns; import com.termux.R; -import com.termux.app.utils.DialogUtils; -import com.termux.app.TermuxConstants; -import com.termux.app.TermuxConstants.TERMUX_APP.TERMUX_SERVICE; +import com.termux.shared.interact.DialogUtils; +import com.termux.shared.termux.TermuxConstants; +import com.termux.shared.termux.TermuxConstants.TERMUX_APP.TERMUX_SERVICE; import com.termux.app.TermuxService; -import com.termux.app.utils.Logger; +import com.termux.shared.logger.Logger; import java.io.ByteArrayInputStream; import java.io.File; diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index cc83b56d..045e125f 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -1,5 +1,3 @@ - #1F000000 - #0F000000 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 11b39d2c..741e8498 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -48,6 +48,9 @@ Keyboard + Enabling Terminal Toolbar + Disabling Terminal Toolbar + @@ -103,55 +106,6 @@ - - Executable required. - The %1$s is to \"%2$s\" null or empty. - The regular file path is null or empty. - The regular file is null or empty. - The executable file path is null or empty. - The executable file is null or empty. - The directory file path is null or empty. - The directory file is null or empty. - - The %1$s is not found at path \"%2$s\". - Regular file not found at %1$s path. - The %1$s at path \"%2$s\" is not a regular file. - Non-regular file found at %1$s path. - Non-directory file found at %1$s path. - Non-symlink file found at %1$s path. - The %1$s found at path \"%2$s\" is not one of allowed file types \"%3$s\". - - Validating file existence and permissions of %1$s at path \"%2$s\" failed.\nException: %3$s - Validating directory existence and permissions of %1$s at path \"%2$s\" failed.\nException: %3$s - - Creating %1$s at path \"%2$s\" failed. - Creating %1$s at path \"%2$s\" failed.\nException: %3$s - - Cannot overwrite %1$s while creating symlink at \"%2$s\" to \"%3$s\" since destination file type \"%4$s\" is not a symlink. - Creating %1$s at path \"%2$s\" to \"%3$s\" failed.\nException: %4$s - - %1$s from \"%2$s\" to \"%3$s\" failed.\nException: %4$s - %1$s from \"%2$s\" to \"%3$s\" cannot be done since they point to the same path. - Cannot overwrite %1$s while %2$s it from \"%3$s\" to \"%4$s\" since destination file type \"%5$s\" is different from source file type \"%6$s\". - Cannot move %1$s from \"%2$s\" to \"%3$s\" since destination is a subdirectory of the source. - - The %1$s still exists after deleting it from \"%2$s\". - Deleting %1$s at path \"%2$s\" failed. - Deleting %1$s at path \"%2$s\" failed.\nException: %3$s - Clearing %1$s at path \"%2$s\" failed.\nException: %3$s - - Reading string from %1$s at path \"%2$s\" failed.\nException: %3$s - Writing string to %1$s at path \"%2$s\" failed.\nException: %3$s - Unsupported charset \"%1$s\" - Checking if charset \"%1$s\" is suppoted failed.\nException: %2$s - - The file permission string to check is invalid. - The %1$s at path is not readable. Permission Denied. - The %1$s at path is not writable. Permission Denied. - The %1$s at path is not executable. Permission Denied. - - - Copy Share @@ -159,14 +113,6 @@ Share With Report Text - If you think this report should be reported, then copy its text from the options menu (3-dots on top right) and post an issue on one of the following links at which the report belongs at. - - - - - Please grant permissions on next screen - &TERMUX_APP_NAME; requires \"Display over other apps\" permission to start terminal sessions from background on Android >= 10. Grants it from Settings -> Apps -> &TERMUX_APP_NAME; -> Advanced - @@ -185,15 +131,6 @@ Logging - - Log Level - "Off" - "Normal" - "Debug" - "Verbose" - "*Unknown*" - Logcat log level set to \"%1$s\" - Terminal View Key Logging Logs will not have entries for terminal view keys. (Default) @@ -221,5 +158,4 @@ Soft keyboard will be disabled. Soft keyboard will be enabled. (Default) - diff --git a/app/src/test/java/com/termux/app/TermuxActivityTest.java b/app/src/test/java/com/termux/app/TermuxActivityTest.java index 66be65fe..090d5cce 100644 --- a/app/src/test/java/com/termux/app/TermuxActivityTest.java +++ b/app/src/test/java/com/termux/app/TermuxActivityTest.java @@ -1,6 +1,6 @@ package com.termux.app; -import com.termux.app.utils.DataUtils; +import com.termux.shared.data.DataUtils; import org.junit.Assert; import org.junit.Test; diff --git a/gradle.properties b/gradle.properties index 663d8313..b0b9199f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,3 +19,6 @@ minSdkVersion=24 targetSdkVersion=28 ndkVersion=22.0.7026061 compileSdkVersion=29 + +markwonVersion=4.6.2 + diff --git a/settings.gradle b/settings.gradle index 2cfc6232..b8045c24 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':app', ':terminal-emulator', ':terminal-view' +include ':app', ':termux-shared', ':terminal-emulator', ':terminal-view' diff --git a/terminal-emulator/build.gradle b/terminal-emulator/build.gradle index e92d24ae..d899a96f 100644 --- a/terminal-emulator/build.gradle +++ b/terminal-emulator/build.gradle @@ -50,7 +50,7 @@ tasks.withType(Test) { } dependencies { - testImplementation 'junit:junit:4.13.1' + testImplementation 'junit:junit:4.13.2' } diff --git a/terminal-view/src/main/java/com/termux/view/TerminalView.java b/terminal-view/src/main/java/com/termux/view/TerminalView.java index 0eea85d4..3a0f0052 100644 --- a/terminal-view/src/main/java/com/termux/view/TerminalView.java +++ b/terminal-view/src/main/java/com/termux/view/TerminalView.java @@ -249,7 +249,7 @@ public final class TerminalView extends View { @Override public InputConnection onCreateInputConnection(EditorInfo outAttrs) { - if (mClient.shouldEnforeCharBasedInput()) { + if (mClient.shouldEnforceCharBasedInput()) { // Some keyboards seems do not reset the internal state on TYPE_NULL. // Affects mostly Samsung stock keyboards. // https://github.com/termux/termux-app/issues/686 diff --git a/terminal-view/src/main/java/com/termux/view/TerminalViewClient.java b/terminal-view/src/main/java/com/termux/view/TerminalViewClient.java index a1ed550b..3e454f9a 100644 --- a/terminal-view/src/main/java/com/termux/view/TerminalViewClient.java +++ b/terminal-view/src/main/java/com/termux/view/TerminalViewClient.java @@ -30,7 +30,7 @@ public interface TerminalViewClient { boolean shouldBackButtonBeMappedToEscape(); - boolean shouldEnforeCharBasedInput(); + boolean shouldEnforceCharBasedInput(); boolean shouldUseCtrlSpaceWorkaround(); diff --git a/termux-shared/.gitignore b/termux-shared/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/termux-shared/.gitignore @@ -0,0 +1 @@ +/build diff --git a/termux-shared/build.gradle b/termux-shared/build.gradle new file mode 100644 index 00000000..f4199365 --- /dev/null +++ b/termux-shared/build.gradle @@ -0,0 +1,67 @@ +apply plugin: 'com.android.library' +apply plugin: 'maven-publish' + +android { + compileSdkVersion project.properties.compileSdkVersion.toInteger() + + dependencies { + implementation "androidx.annotation:annotation:1.2.0" + implementation "com.google.guava:guava:24.1-jre" + implementation "io.noties.markwon:core:$markwonVersion" + implementation "io.noties.markwon:ext-strikethrough:$markwonVersion" + implementation "io.noties.markwon:linkify:$markwonVersion" + implementation "io.noties.markwon:recycler:$markwonVersion" + + // Do not increment version higher than 2.5 or there + // will be runtime exceptions on android < 8 + // due to missing classes like java.nio.file.Path. + implementation "commons-io:commons-io:2.5" + } + + defaultConfig { + minSdkVersion project.properties.minSdkVersion.toInteger() + targetSdkVersion project.properties.targetSdkVersion.toInteger() + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + testImplementation "junit:junit:4.13.2" + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' +} + +publishing { + publications { + bar(MavenPublication) { + groupId 'com.termux' + artifactId 'termux-shared' + version '0.108' + artifact("$buildDir/outputs/aar/termux-shared-release.aar") + } + } + + repositories { + maven { + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/termux/termux-app") + + credentials { + username = System.getenv("GH_USERNAME") + password = System.getenv("GH_TOKEN") + } + } + } +} diff --git a/termux-shared/proguard-rules.pro b/termux-shared/proguard-rules.pro new file mode 100644 index 00000000..ab2e21a7 --- /dev/null +++ b/termux-shared/proguard-rules.pro @@ -0,0 +1,10 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +-dontobfuscate +#-renamesourcefileattribute SourceFile +#-keepattributes SourceFile,LineNumberTable diff --git a/termux-shared/src/androidTest/java/com/termux/shared/ExampleInstrumentedTest.java b/termux-shared/src/androidTest/java/com/termux/shared/ExampleInstrumentedTest.java new file mode 100644 index 00000000..ff184472 --- /dev/null +++ b/termux-shared/src/androidTest/java/com/termux/shared/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.termux.shared; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.termux.shared.test", appContext.getPackageName()); + } +} diff --git a/termux-shared/src/main/AndroidManifest.xml b/termux-shared/src/main/AndroidManifest.xml new file mode 100644 index 00000000..5759b367 --- /dev/null +++ b/termux-shared/src/main/AndroidManifest.xml @@ -0,0 +1,3 @@ + + + diff --git a/termux-shared/src/main/java/com/termux/shared/crash/CrashHandler.java b/termux-shared/src/main/java/com/termux/shared/crash/CrashHandler.java new file mode 100644 index 00000000..8cdbdf24 --- /dev/null +++ b/termux-shared/src/main/java/com/termux/shared/crash/CrashHandler.java @@ -0,0 +1,74 @@ +package com.termux.shared.crash; + +import android.content.Context; + +import androidx.annotation.NonNull; + +import com.termux.shared.file.FileUtils; +import com.termux.shared.logger.Logger; +import com.termux.shared.markdown.MarkdownUtils; +import com.termux.shared.termux.TermuxConstants; +import com.termux.shared.termux.TermuxUtils; + +import java.nio.charset.Charset; + +/** + * Catches uncaught exceptions and logs them. + */ +public class CrashHandler implements Thread.UncaughtExceptionHandler { + + private final Context context; + private final Thread.UncaughtExceptionHandler defaultUEH; + + private static final String LOG_TAG = "CrashUtils"; + + private CrashHandler(final Context context) { + this.context = context; + this.defaultUEH = Thread.getDefaultUncaughtExceptionHandler(); + } + + public void uncaughtException(@NonNull Thread thread, @NonNull Throwable throwable) { + logCrash(context,thread, throwable); + defaultUEH.uncaughtException(thread, throwable); + } + + /** + * Set default uncaught crash handler of current thread to {@link CrashHandler}. + */ + public static void setCrashHandler(final Context context) { + if (!(Thread.getDefaultUncaughtExceptionHandler() instanceof CrashHandler)) { + Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(context)); + } + } + + /** + * Log a crash in the crash log file at + * {@link TermuxConstants#TERMUX_CRASH_LOG_FILE_PATH}. + * + * @param context The {@link Context} for operations. + * @param thread The {@link Thread} in which the crash happened. + * @param throwable The {@link Throwable} thrown for the crash. + */ + public static void logCrash(final Context context, final Thread thread, final Throwable throwable) { + + StringBuilder reportString = new StringBuilder(); + + reportString.append("## Crash Details\n"); + reportString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("Crash Thread", thread.toString(), "-")); + reportString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("Crash Timestamp", TermuxUtils.getCurrentTimeStamp(), "-")); + + reportString.append("\n\n").append(Logger.getStackTracesMarkdownString("Stacktrace", Logger.getStackTraceStringArray(throwable))); + reportString.append("\n\n").append(TermuxUtils.getAppInfoMarkdownString(context, true)); + reportString.append("\n\n").append(TermuxUtils.getDeviceInfoMarkdownString(context)); + + // Log report string to logcat + Logger.logError(reportString.toString()); + + // Write report string to crash log file + String errmsg = FileUtils.writeStringToFile(context, "crash log", TermuxConstants.TERMUX_CRASH_LOG_FILE_PATH, Charset.defaultCharset(), reportString.toString(), false); + if (errmsg != null) { + Logger.logError(LOG_TAG, errmsg); + } + } + +} diff --git a/app/src/main/java/com/termux/app/utils/DataUtils.java b/termux-shared/src/main/java/com/termux/shared/data/DataUtils.java similarity index 99% rename from app/src/main/java/com/termux/app/utils/DataUtils.java rename to termux-shared/src/main/java/com/termux/shared/data/DataUtils.java index c1799713..61b7fff2 100644 --- a/app/src/main/java/com/termux/app/utils/DataUtils.java +++ b/termux-shared/src/main/java/com/termux/shared/data/DataUtils.java @@ -1,4 +1,4 @@ -package com.termux.app.utils; +package com.termux.shared.data; import android.os.Bundle; diff --git a/app/src/main/java/com/termux/app/file/FileUtils.java b/termux-shared/src/main/java/com/termux/shared/file/FileUtils.java similarity index 99% rename from app/src/main/java/com/termux/app/file/FileUtils.java rename to termux-shared/src/main/java/com/termux/shared/file/FileUtils.java index b91cd2e4..71b1ae15 100644 --- a/app/src/main/java/com/termux/app/file/FileUtils.java +++ b/termux-shared/src/main/java/com/termux/shared/file/FileUtils.java @@ -1,4 +1,4 @@ -package com.termux.app.file; +package com.termux.shared.file; import android.content.Context; import android.os.Build; @@ -7,12 +7,12 @@ import android.system.Os; import androidx.annotation.NonNull; import com.google.common.io.RecursiveDeleteOption; -import com.termux.R; -import com.termux.app.TermuxConstants; -import com.termux.app.file.filesystem.FileType; -import com.termux.app.file.filesystem.FileTypes; -import com.termux.app.utils.DataUtils; -import com.termux.app.utils.Logger; +import com.termux.shared.R; +import com.termux.shared.termux.TermuxConstants; +import com.termux.shared.file.filesystem.FileType; +import com.termux.shared.file.filesystem.FileTypes; +import com.termux.shared.data.DataUtils; +import com.termux.shared.logger.Logger; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -1460,7 +1460,7 @@ public class FileUtils { label = (label == null ? "" : label + " "); if (filePath == null || filePath.isEmpty()) return; - if (!isValidPermissingString(permissionsToSet)) { + if (!isValidPermissionString(permissionsToSet)) { Logger.logError(LOG_TAG, "Invalid permissionsToSet passed to setFilePermissions: \"" + permissionsToSet + "\""); return; } @@ -1531,7 +1531,7 @@ public class FileUtils { label = (label == null ? "" : label + " "); if (filePath == null || filePath.isEmpty()) return; - if (!isValidPermissingString(permissionsToSet)) { + if (!isValidPermissionString(permissionsToSet)) { Logger.logError(LOG_TAG, "Invalid permissionsToSet passed to setMissingFilePermissions: \"" + permissionsToSet + "\""); return; } @@ -1585,7 +1585,7 @@ public class FileUtils { label = (label == null ? "" : label + " "); if (filePath == null || filePath.isEmpty()) return context.getString(R.string.error_null_or_empty_parameter, label + "file path", "checkMissingFilePermissions"); - if (!isValidPermissingString(permissionsToCheck)) { + if (!isValidPermissionString(permissionsToCheck)) { Logger.logError(LOG_TAG, "Invalid permissionsToCheck passed to checkMissingFilePermissions: \"" + permissionsToCheck + "\""); return context.getString(R.string.error_invalid_file_permissions_string_to_check); } @@ -1619,7 +1619,7 @@ public class FileUtils { * @param string The {@link String} to check. * @return Returns {@code true} if string exactly matches a permission string, otherwise {@code false}. */ - public static boolean isValidPermissingString(final String string) { + public static boolean isValidPermissionString(final String string) { if (string == null || string.isEmpty()) return false; return Pattern.compile("^([r-])[w-][x-]$", 0).matcher(string).matches(); } diff --git a/app/src/main/java/com/termux/app/file/filesystem/FileAttributes.java b/termux-shared/src/main/java/com/termux/shared/file/filesystem/FileAttributes.java similarity index 99% rename from app/src/main/java/com/termux/app/file/filesystem/FileAttributes.java rename to termux-shared/src/main/java/com/termux/shared/file/filesystem/FileAttributes.java index 03482136..a9986c1a 100644 --- a/app/src/main/java/com/termux/app/file/filesystem/FileAttributes.java +++ b/termux-shared/src/main/java/com/termux/shared/file/filesystem/FileAttributes.java @@ -23,15 +23,13 @@ * questions. */ -package com.termux.app.file.filesystem; +package com.termux.shared.file.filesystem; import android.os.Build; import android.system.StructStat; import androidx.annotation.NonNull; -import com.termux.app.utils.Logger; - import java.io.File; import java.io.FileDescriptor; import java.io.IOException; diff --git a/app/src/main/java/com/termux/app/file/filesystem/FileKey.java b/termux-shared/src/main/java/com/termux/shared/file/filesystem/FileKey.java similarity index 98% rename from app/src/main/java/com/termux/app/file/filesystem/FileKey.java rename to termux-shared/src/main/java/com/termux/shared/file/filesystem/FileKey.java index 87908a26..bc65cf16 100644 --- a/app/src/main/java/com/termux/app/file/filesystem/FileKey.java +++ b/termux-shared/src/main/java/com/termux/shared/file/filesystem/FileKey.java @@ -23,7 +23,7 @@ * questions. */ -package com.termux.app.file.filesystem; +package com.termux.shared.file.filesystem; /** * Container for device/inode to uniquely identify file. diff --git a/app/src/main/java/com/termux/app/file/filesystem/FilePermission.java b/termux-shared/src/main/java/com/termux/shared/file/filesystem/FilePermission.java similarity index 97% rename from app/src/main/java/com/termux/app/file/filesystem/FilePermission.java rename to termux-shared/src/main/java/com/termux/shared/file/filesystem/FilePermission.java index 6cb4dd19..b9b1ed0e 100644 --- a/app/src/main/java/com/termux/app/file/filesystem/FilePermission.java +++ b/termux-shared/src/main/java/com/termux/shared/file/filesystem/FilePermission.java @@ -24,7 +24,7 @@ * questions. */ -package com.termux.app.file.filesystem; +package com.termux.shared.file.filesystem; /** * Defines the bits for use with the {@link FileAttributes#permissions() @@ -83,5 +83,6 @@ public enum FilePermission { /** * Execute/search permission, others. */ - OTHERS_EXECUTE; + OTHERS_EXECUTE + } diff --git a/app/src/main/java/com/termux/app/file/filesystem/FilePermissions.java b/termux-shared/src/main/java/com/termux/shared/file/filesystem/FilePermissions.java similarity index 98% rename from app/src/main/java/com/termux/app/file/filesystem/FilePermissions.java rename to termux-shared/src/main/java/com/termux/shared/file/filesystem/FilePermissions.java index eb48579c..e0691609 100644 --- a/app/src/main/java/com/termux/app/file/filesystem/FilePermissions.java +++ b/termux-shared/src/main/java/com/termux/shared/file/filesystem/FilePermissions.java @@ -23,9 +23,9 @@ * questions. */ -package com.termux.app.file.filesystem; +package com.termux.shared.file.filesystem; -import static com.termux.app.file.filesystem.FilePermission.*; +import static com.termux.shared.file.filesystem.FilePermission.*; import java.util.*; diff --git a/app/src/main/java/com/termux/app/file/filesystem/FileTime.java b/termux-shared/src/main/java/com/termux/shared/file/filesystem/FileTime.java similarity index 99% rename from app/src/main/java/com/termux/app/file/filesystem/FileTime.java rename to termux-shared/src/main/java/com/termux/shared/file/filesystem/FileTime.java index cf0f30fd..14c1d8b5 100644 --- a/app/src/main/java/com/termux/app/file/filesystem/FileTime.java +++ b/termux-shared/src/main/java/com/termux/shared/file/filesystem/FileTime.java @@ -23,7 +23,7 @@ * questions. */ -package com.termux.app.file.filesystem; +package com.termux.shared.file.filesystem; import androidx.annotation.NonNull; diff --git a/app/src/main/java/com/termux/app/file/filesystem/FileType.java b/termux-shared/src/main/java/com/termux/shared/file/filesystem/FileType.java similarity index 94% rename from app/src/main/java/com/termux/app/file/filesystem/FileType.java rename to termux-shared/src/main/java/com/termux/shared/file/filesystem/FileType.java index 2378456b..00ed06d6 100644 --- a/app/src/main/java/com/termux/app/file/filesystem/FileType.java +++ b/termux-shared/src/main/java/com/termux/shared/file/filesystem/FileType.java @@ -1,4 +1,4 @@ -package com.termux.app.file.filesystem; +package com.termux.shared.file.filesystem; /** The {@link Enum} that defines file types. */ public enum FileType { diff --git a/app/src/main/java/com/termux/app/file/filesystem/FileTypes.java b/termux-shared/src/main/java/com/termux/shared/file/filesystem/FileTypes.java similarity index 98% rename from app/src/main/java/com/termux/app/file/filesystem/FileTypes.java rename to termux-shared/src/main/java/com/termux/shared/file/filesystem/FileTypes.java index 447f11f5..c6a78d7a 100644 --- a/app/src/main/java/com/termux/app/file/filesystem/FileTypes.java +++ b/termux-shared/src/main/java/com/termux/shared/file/filesystem/FileTypes.java @@ -1,10 +1,10 @@ -package com.termux.app.file.filesystem; +package com.termux.shared.file.filesystem; import android.system.Os; import androidx.annotation.NonNull; -import com.termux.app.utils.Logger; +import com.termux.shared.logger.Logger; import java.io.File; diff --git a/app/src/main/java/com/termux/app/file/filesystem/NativeDispatcher.java b/termux-shared/src/main/java/com/termux/shared/file/filesystem/NativeDispatcher.java similarity index 97% rename from app/src/main/java/com/termux/app/file/filesystem/NativeDispatcher.java rename to termux-shared/src/main/java/com/termux/shared/file/filesystem/NativeDispatcher.java index 2eb6bfad..08ba8088 100644 --- a/app/src/main/java/com/termux/app/file/filesystem/NativeDispatcher.java +++ b/termux-shared/src/main/java/com/termux/shared/file/filesystem/NativeDispatcher.java @@ -1,4 +1,4 @@ -package com.termux.app.file.filesystem; +package com.termux.shared.file.filesystem; import android.system.ErrnoException; import android.system.Os; diff --git a/app/src/main/java/com/termux/app/file/filesystem/UnixConstants.java b/termux-shared/src/main/java/com/termux/shared/file/filesystem/UnixConstants.java similarity index 99% rename from app/src/main/java/com/termux/app/file/filesystem/UnixConstants.java rename to termux-shared/src/main/java/com/termux/shared/file/filesystem/UnixConstants.java index 0cc7a79d..39e84eb6 100644 --- a/app/src/main/java/com/termux/app/file/filesystem/UnixConstants.java +++ b/termux-shared/src/main/java/com/termux/shared/file/filesystem/UnixConstants.java @@ -26,7 +26,7 @@ * */ // AUTOMATICALLY GENERATED FILE - DO NOT EDIT -package com.termux.app.file.filesystem; +package com.termux.shared.file.filesystem; // BEGIN Android-changed: Use constants from android.system.OsConstants. http://b/32203242 // Those constants are initialized by native code to ensure correctness on different architectures. diff --git a/app/src/main/java/com/termux/app/file/tests/FileUtilsTests.java b/termux-shared/src/main/java/com/termux/shared/file/tests/FileUtilsTests.java similarity index 98% rename from app/src/main/java/com/termux/app/file/tests/FileUtilsTests.java rename to termux-shared/src/main/java/com/termux/shared/file/tests/FileUtilsTests.java index 21db1d57..52f876f5 100644 --- a/app/src/main/java/com/termux/app/file/tests/FileUtilsTests.java +++ b/termux-shared/src/main/java/com/termux/shared/file/tests/FileUtilsTests.java @@ -1,12 +1,11 @@ -package com.termux.app.file.tests; +package com.termux.shared.file.tests; import android.content.Context; import androidx.annotation.NonNull; -import com.termux.app.TermuxConstants; -import com.termux.app.file.FileUtils; -import com.termux.app.utils.Logger; +import com.termux.shared.file.FileUtils; +import com.termux.shared.logger.Logger; import java.io.File; import java.nio.charset.Charset; diff --git a/app/src/main/java/com/termux/app/utils/DialogUtils.java b/termux-shared/src/main/java/com/termux/shared/interact/DialogUtils.java similarity index 98% rename from app/src/main/java/com/termux/app/utils/DialogUtils.java rename to termux-shared/src/main/java/com/termux/shared/interact/DialogUtils.java index 5970850f..1a5fa834 100644 --- a/app/src/main/java/com/termux/app/utils/DialogUtils.java +++ b/termux-shared/src/main/java/com/termux/shared/interact/DialogUtils.java @@ -1,4 +1,4 @@ -package com.termux.app.utils; +package com.termux.shared.interact; import android.app.Activity; import android.app.AlertDialog; diff --git a/app/src/main/java/com/termux/app/utils/ShareUtils.java b/termux-shared/src/main/java/com/termux/shared/interact/ShareUtils.java similarity index 94% rename from app/src/main/java/com/termux/app/utils/ShareUtils.java rename to termux-shared/src/main/java/com/termux/shared/interact/ShareUtils.java index 3530ad00..eb239703 100644 --- a/app/src/main/java/com/termux/app/utils/ShareUtils.java +++ b/termux-shared/src/main/java/com/termux/shared/interact/ShareUtils.java @@ -1,4 +1,4 @@ -package com.termux.app.utils; +package com.termux.shared.interact; import android.content.ClipData; import android.content.ClipboardManager; @@ -7,7 +7,9 @@ import android.content.Intent; import androidx.core.content.ContextCompat; -import com.termux.R; +import com.termux.shared.R; +import com.termux.shared.data.DataUtils; +import com.termux.shared.logger.Logger; public class ShareUtils { diff --git a/app/src/main/java/com/termux/app/utils/Logger.java b/termux-shared/src/main/java/com/termux/shared/logger/Logger.java similarity index 93% rename from app/src/main/java/com/termux/app/utils/Logger.java rename to termux-shared/src/main/java/com/termux/shared/logger/Logger.java index e296fc7a..b8fc151a 100644 --- a/app/src/main/java/com/termux/app/utils/Logger.java +++ b/termux-shared/src/main/java/com/termux/shared/logger/Logger.java @@ -1,4 +1,4 @@ -package com.termux.app.utils; +package com.termux.shared.logger; import android.content.Context; import android.os.Handler; @@ -6,8 +6,8 @@ import android.os.Looper; import android.util.Log; import android.widget.Toast; -import com.termux.R; -import com.termux.app.TermuxConstants; +import com.termux.shared.R; +import com.termux.shared.termux.TermuxConstants; import java.io.IOException; import java.io.PrintWriter; @@ -31,7 +31,7 @@ public class Logger { - public static void logMesssage(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) Log.e(getFullTag(tag), message); else if(logLevel == Log.WARN && CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL) @@ -47,51 +47,51 @@ public class Logger { public static void logError(String tag, String message) { - logMesssage(Log.ERROR, tag, message); + logMessage(Log.ERROR, tag, message); } public static void logError(String message) { - logMesssage(Log.ERROR, DEFAULT_LOG_TAG, message); + logMessage(Log.ERROR, DEFAULT_LOG_TAG, message); } public static void logWarn(String tag, String message) { - logMesssage(Log.WARN, tag, message); + logMessage(Log.WARN, tag, message); } public static void logWarn(String message) { - logMesssage(Log.WARN, DEFAULT_LOG_TAG, message); + logMessage(Log.WARN, DEFAULT_LOG_TAG, message); } public static void logInfo(String tag, String message) { - logMesssage(Log.INFO, tag, message); + logMessage(Log.INFO, tag, message); } public static void logInfo(String message) { - logMesssage(Log.INFO, DEFAULT_LOG_TAG, message); + logMessage(Log.INFO, DEFAULT_LOG_TAG, message); } public static void logDebug(String tag, String message) { - logMesssage(Log.DEBUG, tag, message); + logMessage(Log.DEBUG, tag, message); } public static void logDebug(String message) { - logMesssage(Log.DEBUG, DEFAULT_LOG_TAG, message); + logMessage(Log.DEBUG, DEFAULT_LOG_TAG, message); } public static void logVerbose(String tag, String message) { - logMesssage(Log.VERBOSE, tag, message); + logMessage(Log.VERBOSE, tag, message); } public static void logVerbose(String message) { - logMesssage(Log.VERBOSE, DEFAULT_LOG_TAG, message); + logMessage(Log.VERBOSE, DEFAULT_LOG_TAG, message); } diff --git a/app/src/main/java/com/termux/app/utils/MarkdownUtils.java b/termux-shared/src/main/java/com/termux/shared/markdown/MarkdownUtils.java similarity index 97% rename from app/src/main/java/com/termux/app/utils/MarkdownUtils.java rename to termux-shared/src/main/java/com/termux/shared/markdown/MarkdownUtils.java index 5d40a203..9c3bdaeb 100644 --- a/app/src/main/java/com/termux/app/utils/MarkdownUtils.java +++ b/termux-shared/src/main/java/com/termux/shared/markdown/MarkdownUtils.java @@ -1,4 +1,4 @@ -package com.termux.app.utils; +package com.termux.shared.markdown; import android.content.Context; import android.graphics.Typeface; @@ -16,7 +16,7 @@ import androidx.annotation.NonNull; import androidx.core.content.ContextCompat; import com.google.common.base.Strings; -import com.termux.R; +import com.termux.shared.R; import org.commonmark.ext.gfm.strikethrough.Strikethrough; import org.commonmark.node.BlockQuote; @@ -38,8 +38,8 @@ import io.noties.markwon.linkify.LinkifyPlugin; public class MarkdownUtils { - public static String backtick = "`"; - public static Pattern backticksPattern = Pattern.compile("(" + backtick + "+)"); + public static final String backtick = "`"; + public static final Pattern backticksPattern = Pattern.compile("(" + backtick + "+)"); /** * Get the markdown code {@link String} for a {@link String}. This ensures all backticks "`" are diff --git a/app/src/main/java/com/termux/app/utils/NotificationUtils.java b/termux-shared/src/main/java/com/termux/shared/notification/NotificationUtils.java similarity index 91% rename from app/src/main/java/com/termux/app/utils/NotificationUtils.java rename to termux-shared/src/main/java/com/termux/shared/notification/NotificationUtils.java index 9c83132e..64933cfe 100644 --- a/app/src/main/java/com/termux/app/utils/NotificationUtils.java +++ b/termux-shared/src/main/java/com/termux/shared/notification/NotificationUtils.java @@ -1,4 +1,4 @@ -package com.termux.app.utils; +package com.termux.shared.notification; import android.app.Notification; import android.app.NotificationChannel; @@ -9,10 +9,10 @@ import android.os.Build; import androidx.annotation.Nullable; -import com.termux.app.RunCommandService; -import com.termux.app.TermuxService; -import com.termux.app.settings.preferences.TermuxAppSharedPreferences; -import com.termux.app.settings.preferences.TermuxPreferenceConstants; +import com.termux.shared.logger.Logger; +import com.termux.shared.settings.preferences.TermuxAppSharedPreferences; +import com.termux.shared.settings.preferences.TermuxPreferenceConstants; +import com.termux.shared.termux.TermuxConstants; public class NotificationUtils { @@ -52,6 +52,9 @@ public class NotificationUtils { /** * Try to get the next unique notification id that isn't already being used by the app. * + * Termux app and its plugin must use unique notification ids from the same pool due to usage of android:sharedUserId. + * https://commonsware.com/blog/2017/06/07/jobscheduler-job-ids-libraries.html + * * @param context The {@link Context} for operations. * @return Returns the notification id that should be safe to use. */ @@ -62,7 +65,7 @@ public class NotificationUtils { int lastNotificationId = preferences.getLastNotificationId(); int nextNotificationId = lastNotificationId + 1; - while(nextNotificationId == TermuxService.NOTIFICATION_ID || nextNotificationId == RunCommandService.NOTIFICATION_ID) { + while(nextNotificationId == TermuxConstants.TERMUX_APP_NOTIFICATION_ID || nextNotificationId == TermuxConstants.TERMUX_RUN_COMMAND_NOTIFICATION_ID) { nextNotificationId++; } diff --git a/app/src/main/java/com/termux/app/utils/PackageUtils.java b/termux-shared/src/main/java/com/termux/shared/packages/PackageUtils.java similarity index 98% rename from app/src/main/java/com/termux/app/utils/PackageUtils.java rename to termux-shared/src/main/java/com/termux/shared/packages/PackageUtils.java index 96e96099..75b8b8c4 100644 --- a/app/src/main/java/com/termux/app/utils/PackageUtils.java +++ b/termux-shared/src/main/java/com/termux/shared/packages/PackageUtils.java @@ -1,4 +1,4 @@ -package com.termux.app.utils; +package com.termux.shared.packages; import android.content.Context; import android.content.pm.ApplicationInfo; @@ -6,6 +6,8 @@ import android.content.pm.PackageInfo; import androidx.annotation.NonNull; +import com.termux.shared.logger.Logger; + public class PackageUtils { /** diff --git a/app/src/main/java/com/termux/app/utils/PermissionUtils.java b/termux-shared/src/main/java/com/termux/shared/packages/PermissionUtils.java similarity index 93% rename from app/src/main/java/com/termux/app/utils/PermissionUtils.java rename to termux-shared/src/main/java/com/termux/shared/packages/PermissionUtils.java index 2b8614c9..d97895a0 100644 --- a/app/src/main/java/com/termux/app/utils/PermissionUtils.java +++ b/termux-shared/src/main/java/com/termux/shared/packages/PermissionUtils.java @@ -1,4 +1,4 @@ -package com.termux.app.utils; +package com.termux.shared.packages; import android.app.Activity; import android.content.Context; @@ -10,9 +10,10 @@ import android.provider.Settings; import androidx.core.content.ContextCompat; -import com.termux.R; -import com.termux.app.TermuxConstants; -import com.termux.app.settings.preferences.TermuxAppSharedPreferences; +import com.termux.shared.R; +import com.termux.shared.termux.TermuxConstants; +import com.termux.shared.logger.Logger; +import com.termux.shared.settings.preferences.TermuxAppSharedPreferences; import java.util.Arrays; diff --git a/app/src/main/java/com/termux/app/settings/preferences/SharedPreferenceUtils.java b/termux-shared/src/main/java/com/termux/shared/settings/preferences/SharedPreferenceUtils.java similarity index 99% rename from app/src/main/java/com/termux/app/settings/preferences/SharedPreferenceUtils.java rename to termux-shared/src/main/java/com/termux/shared/settings/preferences/SharedPreferenceUtils.java index 389ba9ba..21ccd1bf 100644 --- a/app/src/main/java/com/termux/app/settings/preferences/SharedPreferenceUtils.java +++ b/termux-shared/src/main/java/com/termux/shared/settings/preferences/SharedPreferenceUtils.java @@ -1,10 +1,10 @@ -package com.termux.app.settings.preferences; +package com.termux.shared.settings.preferences; import android.annotation.SuppressLint; import android.content.Context; import android.content.SharedPreferences; -import com.termux.app.utils.Logger; +import com.termux.shared.logger.Logger; import java.util.Set; diff --git a/app/src/main/java/com/termux/app/settings/preferences/TermuxAppSharedPreferences.java b/termux-shared/src/main/java/com/termux/shared/settings/preferences/TermuxAppSharedPreferences.java similarity index 95% rename from app/src/main/java/com/termux/app/settings/preferences/TermuxAppSharedPreferences.java rename to termux-shared/src/main/java/com/termux/shared/settings/preferences/TermuxAppSharedPreferences.java index ba2b37a2..086e50d7 100644 --- a/app/src/main/java/com/termux/app/settings/preferences/TermuxAppSharedPreferences.java +++ b/termux-shared/src/main/java/com/termux/shared/settings/preferences/TermuxAppSharedPreferences.java @@ -1,14 +1,14 @@ -package com.termux.app.settings.preferences; +package com.termux.shared.settings.preferences; import android.content.Context; import android.content.SharedPreferences; import android.util.TypedValue; -import com.termux.app.TermuxConstants; -import com.termux.app.utils.Logger; -import com.termux.app.utils.TermuxUtils; -import com.termux.app.utils.DataUtils; -import com.termux.app.settings.preferences.TermuxPreferenceConstants.TERMUX_APP; +import com.termux.shared.termux.TermuxConstants; +import com.termux.shared.logger.Logger; +import com.termux.shared.termux.TermuxUtils; +import com.termux.shared.data.DataUtils; +import com.termux.shared.settings.preferences.TermuxPreferenceConstants.TERMUX_APP; import javax.annotation.Nonnull; diff --git a/app/src/main/java/com/termux/app/settings/preferences/TermuxPreferenceConstants.java b/termux-shared/src/main/java/com/termux/shared/settings/preferences/TermuxPreferenceConstants.java similarity index 89% rename from app/src/main/java/com/termux/app/settings/preferences/TermuxPreferenceConstants.java rename to termux-shared/src/main/java/com/termux/shared/settings/preferences/TermuxPreferenceConstants.java index 2d3afd6e..633b7c34 100644 --- a/app/src/main/java/com/termux/app/settings/preferences/TermuxPreferenceConstants.java +++ b/termux-shared/src/main/java/com/termux/shared/settings/preferences/TermuxPreferenceConstants.java @@ -1,7 +1,7 @@ -package com.termux.app.settings.preferences; +package com.termux.shared.settings.preferences; /* - * Version: v0.8.0 + * Version: v0.9.0 * * Changelog * @@ -37,13 +37,16 @@ package com.termux.app.settings.preferences; * - 0.8.0 (2021-04-06) * - Added following to `TERMUX_APP`: * `KEY_CRASH_REPORT_NOTIFICATIONS_ENABLED` and `DEFAULT_VALUE_CRASH_REPORT_NOTIFICATIONS_ENABLED`. + * + * - 0.9.0 (2021-04-07) + * - Updated javadocs. */ /** - * A class that defines shared constants of the Shared preferences used by Termux app and its plugins. - * This class will be hosted by termux-app and should be imported by other termux plugin apps as is - * instead of copying constants to random classes. The 3rd party apps can also import it for - * interacting with termux apps. If changes are made to this file, increment the version number + * A class that defines shared constants of the SharedPreferences used by Termux app and its plugins. + * This class will be hosted by termux-shared lib and should be imported by other termux plugin + * apps as is instead of copying constants to random classes. The 3rd party apps can also import + * it for interacting with termux apps. If changes are made to this file, increment the version number * and add an entry in the Changelog section above. */ public final class TermuxPreferenceConstants { diff --git a/app/src/main/java/com/termux/app/settings/preferences/TermuxTaskerAppSharedPreferences.java b/termux-shared/src/main/java/com/termux/shared/settings/preferences/TermuxTaskerAppSharedPreferences.java similarity index 86% rename from app/src/main/java/com/termux/app/settings/preferences/TermuxTaskerAppSharedPreferences.java rename to termux-shared/src/main/java/com/termux/shared/settings/preferences/TermuxTaskerAppSharedPreferences.java index a0e1aed1..52730cdf 100644 --- a/app/src/main/java/com/termux/app/settings/preferences/TermuxTaskerAppSharedPreferences.java +++ b/termux-shared/src/main/java/com/termux/shared/settings/preferences/TermuxTaskerAppSharedPreferences.java @@ -1,13 +1,13 @@ -package com.termux.app.settings.preferences; +package com.termux.shared.settings.preferences; import android.content.Context; import android.content.SharedPreferences; -import com.termux.app.TermuxConstants; -import com.termux.app.settings.preferences.TermuxPreferenceConstants.TERMUX_TASKER_APP; -import com.termux.app.utils.DataUtils; -import com.termux.app.utils.Logger; -import com.termux.app.utils.TermuxUtils; +import com.termux.shared.termux.TermuxConstants; +import com.termux.shared.settings.preferences.TermuxPreferenceConstants.TERMUX_TASKER_APP; +import com.termux.shared.data.DataUtils; +import com.termux.shared.logger.Logger; +import com.termux.shared.termux.TermuxUtils; import javax.annotation.Nonnull; diff --git a/app/src/main/java/com/termux/app/settings/properties/SharedProperties.java b/termux-shared/src/main/java/com/termux/shared/settings/properties/SharedProperties.java similarity index 98% rename from app/src/main/java/com/termux/app/settings/properties/SharedProperties.java rename to termux-shared/src/main/java/com/termux/shared/settings/properties/SharedProperties.java index c1797d6e..72cf0dad 100644 --- a/app/src/main/java/com/termux/app/settings/properties/SharedProperties.java +++ b/termux-shared/src/main/java/com/termux/shared/settings/properties/SharedProperties.java @@ -1,11 +1,11 @@ -package com.termux.app.settings.properties; +package com.termux.shared.settings.properties; import android.content.Context; import android.widget.Toast; import com.google.common.collect.ImmutableBiMap; import com.google.common.primitives.Primitives; -import com.termux.app.utils.Logger; +import com.termux.shared.logger.Logger; import java.io.File; import java.io.FileInputStream; @@ -96,7 +96,7 @@ public class SharedProperties { mSharedPropertiesParser = sharedPropertiesParser; mProperties = new Properties(); - mMap = new HashMap(); + mMap = new HashMap<>(); } /** @@ -115,7 +115,7 @@ public class SharedProperties { if (properties == null) properties = new Properties(); - HashMap map = new HashMap(); + HashMap map = new HashMap<>(); Properties newProperties = new Properties(); Set propertiesList = mPropertiesList; @@ -187,7 +187,7 @@ public class SharedProperties { */ public Map getInternalProperties() { synchronized (mLock) { - if (mMap == null) mMap = new HashMap(); + if (mMap == null) mMap = new HashMap<>(); return getMapCopy(mMap); } } @@ -406,7 +406,7 @@ public class SharedProperties { public static Map getMapCopy(Map map) { if (map == null) return null; - return new HashMap(map); + return new HashMap<>(map); } diff --git a/app/src/main/java/com/termux/app/settings/properties/SharedPropertiesParser.java b/termux-shared/src/main/java/com/termux/shared/settings/properties/SharedPropertiesParser.java similarity index 83% rename from app/src/main/java/com/termux/app/settings/properties/SharedPropertiesParser.java rename to termux-shared/src/main/java/com/termux/shared/settings/properties/SharedPropertiesParser.java index a82141bf..8fd09eea 100644 --- a/app/src/main/java/com/termux/app/settings/properties/SharedPropertiesParser.java +++ b/termux-shared/src/main/java/com/termux/shared/settings/properties/SharedPropertiesParser.java @@ -1,4 +1,4 @@ -package com.termux.app.settings.properties; +package com.termux.shared.settings.properties; import android.content.Context; @@ -18,6 +18,6 @@ public interface SharedPropertiesParser { * @param value The literal value for the property found is the properties file. * @return Returns the {@link Object} object to store in the {@link HashMap <>} in-memory cache. */ - public Object getInternalPropertyValueFromValue(Context context, String key, String value); + Object getInternalPropertyValueFromValue(Context context, String key, String value); } diff --git a/app/src/main/java/com/termux/app/settings/properties/TermuxPropertyConstants.java b/termux-shared/src/main/java/com/termux/shared/settings/properties/TermuxPropertyConstants.java similarity index 94% rename from app/src/main/java/com/termux/app/settings/properties/TermuxPropertyConstants.java rename to termux-shared/src/main/java/com/termux/shared/settings/properties/TermuxPropertyConstants.java index fefe4246..588db5d2 100644 --- a/app/src/main/java/com/termux/app/settings/properties/TermuxPropertyConstants.java +++ b/termux-shared/src/main/java/com/termux/shared/settings/properties/TermuxPropertyConstants.java @@ -1,8 +1,8 @@ -package com.termux.app.settings.properties; +package com.termux.shared.settings.properties; import com.google.common.collect.ImmutableBiMap; -import com.termux.app.TermuxConstants; -import com.termux.app.utils.Logger; +import com.termux.shared.termux.TermuxConstants; +import com.termux.shared.logger.Logger; import java.io.File; import java.util.Arrays; @@ -10,7 +10,7 @@ import java.util.HashSet; import java.util.Set; /* - * Version: v0.5.0 + * Version: v0.6.0 * * Changelog * @@ -30,13 +30,16 @@ import java.util.Set; * * - 0.5.0 (2021-03-25) * - Add `KEY_HIDE_SOFT_KEYBOARD_ON_STARTUP`. + * + * - 0.6.0 (2021-04-07) + * - Updated javadocs. */ /** - * A class that defines shared constants of the properties used by Termux app and its plugins. - * This class will be hosted by termux-app and should be imported by other termux plugin apps as is - * instead of copying constants to random classes. The 3rd party apps can also import it for - * interacting with termux apps. If changes are made to this file, increment the version number + * A class that defines shared constants of the SharedProperties used by Termux app and its plugins. + * This class will be hosted by termux-shared lib and should be imported by other termux plugin + * apps as is instead of copying constants to random classes. The 3rd party apps can also import + * it for interacting with termux apps. If changes are made to this file, increment the version number * and add an entry in the Changelog section above. * * The properties are loaded from the first file found at diff --git a/app/src/main/java/com/termux/app/settings/properties/TermuxSharedProperties.java b/termux-shared/src/main/java/com/termux/shared/settings/properties/TermuxSharedProperties.java similarity index 86% rename from app/src/main/java/com/termux/app/settings/properties/TermuxSharedProperties.java rename to termux-shared/src/main/java/com/termux/shared/settings/properties/TermuxSharedProperties.java index 79c6ffae..124fe6ae 100644 --- a/app/src/main/java/com/termux/app/settings/properties/TermuxSharedProperties.java +++ b/termux-shared/src/main/java/com/termux/shared/settings/properties/TermuxSharedProperties.java @@ -1,19 +1,13 @@ -package com.termux.app.settings.properties; +package com.termux.shared.settings.properties; import android.content.Context; import android.content.res.Configuration; -import com.termux.app.terminal.io.extrakeys.ExtraKeysInfo; -import com.termux.app.terminal.io.KeyboardShortcut; -import com.termux.app.utils.Logger; -import com.termux.app.utils.DataUtils; - -import org.json.JSONException; +import com.termux.shared.logger.Logger; +import com.termux.shared.data.DataUtils; import java.io.File; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Properties; @@ -21,12 +15,9 @@ import javax.annotation.Nonnull; public class TermuxSharedProperties implements SharedPropertiesParser { - private final Context mContext; - private final SharedProperties mSharedProperties; - private final File mPropertiesFile; - - private ExtraKeysInfo mExtraKeysInfo; - private final List mSessionShortcuts = new ArrayList<>(); + protected final Context mContext; + protected final SharedProperties mSharedProperties; + protected final File mPropertiesFile; private static final String LOG_TAG = "TermuxSharedProperties"; @@ -44,53 +35,6 @@ public class TermuxSharedProperties implements SharedPropertiesParser { mSharedProperties.loadPropertiesFromDisk(); dumpPropertiesToLog(); dumpInternalPropertiesToLog(); - setExtraKeys(); - setSessionShortcuts(); - } - - /** - * Set the terminal extra keys and style. - */ - private void setExtraKeys() { - mExtraKeysInfo = null; - - try { - // The mMap stores the extra key and style string values while loading properties - // Check {@link #getExtraKeysInternalPropertyValueFromValue(String)} and - // {@link #getExtraKeysStyleInternalPropertyValueFromValue(String)} - String extrakeys = (String) getInternalPropertyValue(TermuxPropertyConstants.KEY_EXTRA_KEYS, true); - String extraKeysStyle = (String) getInternalPropertyValue(TermuxPropertyConstants.KEY_EXTRA_KEYS_STYLE, true); - mExtraKeysInfo = new ExtraKeysInfo(extrakeys, extraKeysStyle); - } catch (JSONException e) { - Logger.showToast(mContext, "Could not load and set the \"" + TermuxPropertyConstants.KEY_EXTRA_KEYS + "\" property from the properties file: " + e.toString(), true); - Logger.logStackTraceWithMessage(LOG_TAG, "Could not load and set the \"" + TermuxPropertyConstants.KEY_EXTRA_KEYS + "\" property from the properties file: ", e); - - try { - mExtraKeysInfo = new ExtraKeysInfo(TermuxPropertyConstants.DEFAULT_IVALUE_EXTRA_KEYS, TermuxPropertyConstants.DEFAULT_IVALUE_EXTRA_KEYS_STYLE); - } catch (JSONException e2) { - Logger.showToast(mContext, "Can't create default extra keys",true); - Logger.logStackTraceWithMessage(LOG_TAG, "Could create default extra keys: ", e); - mExtraKeysInfo = null; - } - } - } - - /** - * Set the terminal sessions shortcuts. - */ - private void setSessionShortcuts() { - mSessionShortcuts.clear(); - // The {@link TermuxPropertyConstants#MAP_SESSION_SHORTCUTS} stores the session shortcut key and action pair - for (Map.Entry entry : TermuxPropertyConstants.MAP_SESSION_SHORTCUTS.entrySet()) { - // The mMap stores the code points for the session shortcuts while loading properties - Integer codePoint = (Integer) getInternalPropertyValue(entry.getKey(), true); - // If codePoint is null, then session shortcut did not exist in properties or was invalid - // as parsed by {@link #getCodePointForSessionShortcuts(String,String)} - // If codePoint is not null, then get the action for the MAP_SESSION_SHORTCUTS key and - // add the code point to sessionShortcuts - if (codePoint != null) - mSessionShortcuts.add(new KeyboardShortcut(codePoint, entry.getValue())); - } } @@ -473,18 +417,10 @@ public class TermuxSharedProperties implements SharedPropertiesParser { return rangeTerminalToolbarHeightScaleFactorValue((float) getInternalPropertyValue(TermuxPropertyConstants.KEY_TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR, true)); } - public List getSessionShortcuts() { - return mSessionShortcuts; - } - public String getDefaultWorkingDirectory() { return (String) getInternalPropertyValue(TermuxPropertyConstants.KEY_DEFAULT_WORKING_DIRECTORY, true); } - public ExtraKeysInfo getExtraKeysInfo() { - return mExtraKeysInfo; - } - diff --git a/app/src/main/java/com/termux/app/shell/ShellUtils.java b/termux-shared/src/main/java/com/termux/shared/shell/ShellUtils.java similarity index 96% rename from app/src/main/java/com/termux/app/shell/ShellUtils.java rename to termux-shared/src/main/java/com/termux/shared/shell/ShellUtils.java index a6fbefe3..d30a01fa 100644 --- a/app/src/main/java/com/termux/app/shell/ShellUtils.java +++ b/termux-shared/src/main/java/com/termux/shared/shell/ShellUtils.java @@ -1,12 +1,12 @@ -package com.termux.app.shell; +package com.termux.shared.shell; import android.content.Context; -import com.termux.app.TermuxConstants; -import com.termux.app.file.FileUtils; -import com.termux.app.utils.Logger; -import com.termux.app.utils.PackageUtils; -import com.termux.app.utils.TermuxUtils; +import com.termux.shared.termux.TermuxConstants; +import com.termux.shared.file.FileUtils; +import com.termux.shared.logger.Logger; +import com.termux.shared.packages.PackageUtils; +import com.termux.shared.termux.TermuxUtils; import java.io.File; import java.io.FileInputStream; diff --git a/app/src/main/java/com/termux/app/shell/StreamGobbler.java b/termux-shared/src/main/java/com/termux/shared/shell/StreamGobbler.java similarity index 99% rename from app/src/main/java/com/termux/app/shell/StreamGobbler.java rename to termux-shared/src/main/java/com/termux/shared/shell/StreamGobbler.java index daad1176..bfb247a7 100644 --- a/app/src/main/java/com/termux/app/shell/StreamGobbler.java +++ b/termux-shared/src/main/java/com/termux/shared/shell/StreamGobbler.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.termux.app.shell; +package com.termux.shared.shell; import java.io.BufferedReader; import java.io.IOException; @@ -28,7 +28,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.WorkerThread; -import com.termux.app.utils.Logger; +import com.termux.shared.logger.Logger; /** * Thread utility class continuously reading from an InputStream diff --git a/app/src/main/java/com/termux/app/TermuxConstants.java b/termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java similarity index 91% rename from app/src/main/java/com/termux/app/TermuxConstants.java rename to termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java index 798e48a8..4f772cb6 100644 --- a/app/src/main/java/com/termux/app/TermuxConstants.java +++ b/termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java @@ -1,11 +1,11 @@ -package com.termux.app; +package com.termux.shared.termux; import android.annotation.SuppressLint; import java.io.File; /* - * Version: v0.16.0 + * Version: v0.17.0 * * Changelog * @@ -118,13 +118,20 @@ import java.io.File; * - Added `TERMUX_SUPPORT_EMAIL`, `TERMUX_SUPPORT_EMAIL_URL`, `TERMUX_SUPPORT_EMAIL_MAILTO_URL`, * `TERMUX_REDDIT_SUBREDDIT`, `TERMUX_REDDIT_SUBREDDIT_URL`. * - The `TERMUX_SUPPORT_EMAIL_URL` value must be fixed later when email has been set up. + * + * - 0.17.0 (2021-04-07) + * - Added `TERMUX_APP_NOTIFICATION_CHANNEL_ID`, `TERMUX_APP_NOTIFICATION_CHANNEL_NAME`, `TERMUX_APP_NOTIFICATION_ID`, + * `TERMUX_RUN_COMMAND_NOTIFICATION_CHANNEL_ID`, `TERMUX_RUN_COMMAND_NOTIFICATION_CHANNEL_NAME`, `TERMUX_RUN_COMMAND_NOTIFICATION_ID`, + * `TERMUX_PLUGIN_COMMAND_ERRORS_NOTIFICATION_CHANNEL_ID`, `TERMUX_PLUGIN_COMMAND_ERRORS_NOTIFICATION_CHANNEL_NAME`, + * `TERMUX_CRASH_REPORTS_NOTIFICATION_CHANNEL_ID`, `TERMUX_CRASH_REPORTS_NOTIFICATION_CHANNEL_NAME`. + * - Updated javadocs. */ /** * A class that defines shared constants of the Termux app and its plugins. - * This class will be hosted by termux-app and should be imported by other termux plugin apps as is - * instead of copying constants to random classes. The 3rd party apps can also import it for - * interacting with termux apps. If changes are made to this file, increment the version number + * This class will be hosted by termux-shared lib and should be imported by other termux plugin + * apps as is instead of copying constants to random classes. The 3rd party apps can also import + * it for interacting with termux apps. If changes are made to this file, increment the version number * and add an entry in the Changelog section above. * * Termux app default package name is "com.termux" and is used in {@link #TERMUX_PREFIX_DIR_PATH}. @@ -139,22 +146,25 @@ import java.io.File; * * Ideally the only places where changes should be required if changing package name are the following: * - The {@link #TERMUX_PACKAGE_NAME} in {@link TermuxConstants}. - * - The "applicationId" in "build.gradle". This is package name that android and app stores will - * use and is also the final package name stored in "AndroidManifest.xml". - * - The "manifestPlaceholders" values for {@link #TERMUX_PACKAGE_NAME} and *_APP_NAME in "build.gradle". - * - The "ENTITY" values for {@link #TERMUX_PACKAGE_NAME} and *_APP_NAME in "strings.xml". - * - The "shortcut.xml" and "*_preferences.xml" files like in termux-app since dynamic variables don't + * - The "applicationId" in "build.gradle" of termux-app. This is package name that android and app + * stores will use and is also the final package name stored in "AndroidManifest.xml". + * - The "manifestPlaceholders" values for {@link #TERMUX_PACKAGE_NAME} and *_APP_NAME in + * "build.gradle" of termux-app. + * - The "ENTITY" values for {@link #TERMUX_PACKAGE_NAME} and *_APP_NAME in "strings.xml" of + * termux-app and of termux-shared. + * - The "shortcut.xml" and "*_preferences.xml" files of termux-app since dynamic variables don't * work in it. - * - Optionally the "package" in "AndroidManifest.xml" if modifying project structure. This is - * package name for java classes project structure and is prefixed if activity and service - * names use dot (.) notation. + * - Optionally the "package" in "AndroidManifest.xml" if modifying project structure of termux-app. + * This is package name for java classes project structure and is prefixed if activity and service + * names use dot (.) notation. This is currently not advisable since this will break lot of + * stuff, including termux-* packages. * - Optionally the *_PATH variables in {@link TermuxConstants} containing the string "termux". * * Check https://developer.android.com/studio/build/application-id for info on "package" in * "AndroidManifest.xml" and "applicationId" in "build.gradle". * - * {@link #TERMUX_PACKAGE_NAME} must be used in source code of Termux app and its plugins instead of - * hardcoded "com.termux" paths. + * The {@link #TERMUX_PACKAGE_NAME} must be used in source code of Termux app and its plugins instead + * of hardcoded "com.termux" paths. */ public final class TermuxConstants { @@ -551,6 +561,38 @@ public final class TermuxConstants { + /* + * Termux app and plugins notification variables. + */ + + /** Termux app notification channel id used by {@link TERMUX_APP.TERMUX_SERVICE} */ + public static final String TERMUX_APP_NOTIFICATION_CHANNEL_ID = "termux_notification_channel"; + /** Termux app notification channel name used by {@link TERMUX_APP.TERMUX_SERVICE} */ + public static final String TERMUX_APP_NOTIFICATION_CHANNEL_NAME = TermuxConstants.TERMUX_APP_NAME + " App"; + /** Termux app unique notification id used by {@link TERMUX_APP.TERMUX_SERVICE} */ + public static final int TERMUX_APP_NOTIFICATION_ID = 1337; + + /** Termux app notification channel id used by {@link TERMUX_APP.RUN_COMMAND_SERVICE} */ + public static final String TERMUX_RUN_COMMAND_NOTIFICATION_CHANNEL_ID = "termux_run_command_notification_channel"; + /** Termux app notification channel name used by {@link TERMUX_APP.RUN_COMMAND_SERVICE} */ + public static final String TERMUX_RUN_COMMAND_NOTIFICATION_CHANNEL_NAME = TermuxConstants.TERMUX_APP_NAME + " RunCommandService"; + /** Termux app unique notification id used by {@link TERMUX_APP.RUN_COMMAND_SERVICE} */ + public static final int TERMUX_RUN_COMMAND_NOTIFICATION_ID = 1338; + + /** Termux app notification channel id used for plugin command errors */ + public static final String TERMUX_PLUGIN_COMMAND_ERRORS_NOTIFICATION_CHANNEL_ID = "termux_plugin_command_errors_notification_channel"; + /** Termux app notification channel name used for plugin command errors */ + public static final String TERMUX_PLUGIN_COMMAND_ERRORS_NOTIFICATION_CHANNEL_NAME = TermuxConstants.TERMUX_APP_NAME + " Plugin Commands Errors"; + + /** Termux app notification channel id used for crash reports */ + public static final String TERMUX_CRASH_REPORTS_NOTIFICATION_CHANNEL_ID = "termux_crash_reports_notification_channel"; + /** Termux app notification channel name used for crash reports */ + public static final String TERMUX_CRASH_REPORTS_NOTIFICATION_CHANNEL_NAME = TermuxConstants.TERMUX_APP_NAME + " Crash Reports"; + + + + + /* * Termux app and plugins miscellaneous variables. */ @@ -647,30 +689,30 @@ public final class TermuxConstants { /** The value for {@link #EXTRA_SESSION_ACTION} extra that will set the new session as - * the current session and will start {@link TermuxActivity} if its not running to bring + * the current session and will start {@link TERMUX_ACTIVITY} if its not running to bring * the new session to foreground. */ public static final int VALUE_EXTRA_SESSION_ACTION_SWITCH_TO_NEW_SESSION_AND_OPEN_ACTIVITY = 0; /** The value for {@link #EXTRA_SESSION_ACTION} extra that will keep any existing session - * as the current session and will start {@link TermuxActivity} if its not running to + * as the current session and will start {@link TERMUX_ACTIVITY} if its not running to * bring the existing session to foreground. The new session will be added to the left * sidebar in the sessions list. */ public static final int VALUE_EXTRA_SESSION_ACTION_KEEP_CURRENT_SESSION_AND_OPEN_ACTIVITY = 1; /** The value for {@link #EXTRA_SESSION_ACTION} extra that will set the new session as - * the current session but will not start {@link TermuxActivity} if its not running + * the current session but will not start {@link TERMUX_ACTIVITY} if its not running * and session(s) will be seen in Termux notification and can be clicked to bring new - * session to foreground. If the {@link TermuxActivity} is already running, then this + * session to foreground. If the {@link TERMUX_ACTIVITY} is already running, then this * will behave like {@link #VALUE_EXTRA_SESSION_ACTION_KEEP_CURRENT_SESSION_AND_OPEN_ACTIVITY}. */ public static final int VALUE_EXTRA_SESSION_ACTION_SWITCH_TO_NEW_SESSION_AND_DONT_OPEN_ACTIVITY = 2; /** The value for {@link #EXTRA_SESSION_ACTION} extra that will keep any existing session - * as the current session but will not start {@link TermuxActivity} if its not running + * as the current session but will not start {@link TERMUX_ACTIVITY} if its not running * and session(s) will be seen in Termux notification and can be clicked to bring - * existing session to foreground. If the {@link TermuxActivity} is already running, + * existing session to foreground. If the {@link TERMUX_ACTIVITY} is already running, * then this will behave like {@link #VALUE_EXTRA_SESSION_ACTION_KEEP_CURRENT_SESSION_AND_OPEN_ACTIVITY}. */ public static final int VALUE_EXTRA_SESSION_ACTION_KEEP_CURRENT_SESSION_AND_DONT_OPEN_ACTIVITY = 3; diff --git a/app/src/main/java/com/termux/app/utils/TermuxUtils.java b/termux-shared/src/main/java/com/termux/shared/termux/TermuxUtils.java similarity index 98% rename from app/src/main/java/com/termux/app/utils/TermuxUtils.java rename to termux-shared/src/main/java/com/termux/shared/termux/TermuxUtils.java index acff15cb..07a80cd7 100644 --- a/app/src/main/java/com/termux/app/utils/TermuxUtils.java +++ b/termux-shared/src/main/java/com/termux/shared/termux/TermuxUtils.java @@ -1,4 +1,4 @@ -package com.termux.app.utils; +package com.termux.shared.termux; import android.annotation.SuppressLint; import android.content.ComponentName; @@ -11,8 +11,10 @@ import androidx.annotation.NonNull; import com.google.common.base.Joiner; -import com.termux.R; -import com.termux.app.TermuxConstants; +import com.termux.shared.R; +import com.termux.shared.logger.Logger; +import com.termux.shared.markdown.MarkdownUtils; +import com.termux.shared.packages.PackageUtils; import java.io.BufferedReader; import java.io.IOException; diff --git a/termux-shared/src/main/res/values/colors.xml b/termux-shared/src/main/res/values/colors.xml new file mode 100644 index 00000000..cc83b56d --- /dev/null +++ b/termux-shared/src/main/res/values/colors.xml @@ -0,0 +1,5 @@ + + + #1F000000 + #0F000000 + diff --git a/termux-shared/src/main/res/values/strings.xml b/termux-shared/src/main/res/values/strings.xml new file mode 100644 index 00000000..888eece9 --- /dev/null +++ b/termux-shared/src/main/res/values/strings.xml @@ -0,0 +1,88 @@ + + + + + + + + + + + ]> + + + + + Executable required. + The %1$s is to \"%2$s\" null or empty. + The regular file path is null or empty. + The regular file is null or empty. + The executable file path is null or empty. + The executable file is null or empty. + The directory file path is null or empty. + The directory file is null or empty. + + The %1$s is not found at path \"%2$s\". + Regular file not found at %1$s path. + The %1$s at path \"%2$s\" is not a regular file. + Non-regular file found at %1$s path. + Non-directory file found at %1$s path. + Non-symlink file found at %1$s path. + The %1$s found at path \"%2$s\" is not one of allowed file types \"%3$s\". + + Validating file existence and permissions of %1$s at path \"%2$s\" failed.\nException: %3$s + Validating directory existence and permissions of %1$s at path \"%2$s\" failed.\nException: %3$s + + Creating %1$s at path \"%2$s\" failed. + Creating %1$s at path \"%2$s\" failed.\nException: %3$s + + Cannot overwrite %1$s while creating symlink at \"%2$s\" to \"%3$s\" since destination file type \"%4$s\" is not a symlink. + Creating %1$s at path \"%2$s\" to \"%3$s\" failed.\nException: %4$s + + %1$s from \"%2$s\" to \"%3$s\" failed.\nException: %4$s + %1$s from \"%2$s\" to \"%3$s\" cannot be done since they point to the same path. + Cannot overwrite %1$s while %2$s it from \"%3$s\" to \"%4$s\" since destination file type \"%5$s\" is different from source file type \"%6$s\". + Cannot move %1$s from \"%2$s\" to \"%3$s\" since destination is a subdirectory of the source. + + The %1$s still exists after deleting it from \"%2$s\". + Deleting %1$s at path \"%2$s\" failed. + Deleting %1$s at path \"%2$s\" failed.\nException: %3$s + Clearing %1$s at path \"%2$s\" failed.\nException: %3$s + + Reading string from %1$s at path \"%2$s\" failed.\nException: %3$s + Writing string to %1$s at path \"%2$s\" failed.\nException: %3$s + Unsupported charset \"%1$s\" + Checking if charset \"%1$s\" is suppoted failed.\nException: %2$s + + The file permission string to check is invalid. + The %1$s at path is not readable. Permission Denied. + The %1$s at path is not writable. Permission Denied. + The %1$s at path is not executable. Permission Denied. + + + + Please grant permissions on next screen + &TERMUX_APP_NAME; requires \"Display over other apps\" permission to start terminal sessions from background on Android >= 10. Grants it from Settings -> Apps -> &TERMUX_APP_NAME; -> Advanced + + + + + Share With + + + + + If you think this report should be reported, then copy its text from the options menu (3-dots on top right) and post an issue on one of the following links at which the report belongs at. + + + + Log Level + "Off" + "Normal" + "Debug" + "Verbose" + "*Unknown*" + Logcat log level set to \"%1$s\" + +