Commit Graph

914 Commits

Author SHA1 Message Date
agnostic-apollo 7aa957c684 Fix typos 2021-03-24 06:30:26 +05:00
agnostic-apollo eeb8554535 Fix string resources naming convention 2021-03-24 06:15:45 +05:00
agnostic-apollo 4eced52c5f Fix xml files naming convention 2021-03-24 05:28:38 +05:00
agnostic-apollo b856e16998 Move activities and fragments to respective packages
Move com.termux.TermuxSettingsActivity to com.termux.app.activities.SettingsActivity
Move com.termux.TermuxHepActivity to com.termux.app.activities.HelpActivity
Move com.termux.settings.DebuggingPreferencesFragment to com.termux.app.fragments.settings.DebuggingPreferencesFragment
2021-03-24 05:13:00 +05:00
agnostic-apollo 1bdf9bf2e3 Change log level to warn from error when termux.properties file is missing 2021-03-24 04:57:35 +05:00
agnostic-apollo 92b804dc9c Add logging for termux bootstrap package installation and setup of storage symlinks 2021-03-24 04:55:10 +05:00
agnostic-apollo 1b5e5b56cb Partially integrate ExectionCommand into TermuxService and BackgroundJob
The TERMUX_SERVICE.ACTION_SERVICE_EXECUTE intent received will be managed by the ExectionCommand now.
The cwd and failsafe have been renamed to workingDirectory and isFailsafe.
2021-03-24 03:59:18 +05:00
agnostic-apollo 31371b5e3d Fully integrate ExectionCommand into RunCommandService
Users will now also be shown flashes and notifications in addition to log entries for missing allow-external-apps permission or for invalid extras passed like the executable. The flashes and notifications can be controlled with the Termux Settings -> Debugging -> Plugin Error Notifications toggle
2021-03-24 03:56:25 +05:00
agnostic-apollo ef1ab197b6 Update TermuxConstants
The `TermuxConstants` classes has been updated to `v0.11.0`. Check its Changelog sections for info on changes.
2021-03-24 03:51:57 +05:00
agnostic-apollo bccc35bc3f Added ExectionCommand
ExectionCommand is a class that stores all data related to an execution command like:

- Input parameters like executable and arguments to be used to run the shell command, etc
- Output parameters like stdout, stderr and exitCode.
- Error info generated internally by termux outside the shell in errCode and errmsg.
- Command info like, id, label, description, help info, etc.
- Other config info like for how termux should handle the command.
- The pending intent if any that should be sent after execution to command requester.
- The help for the plugin API that was used to send the intent.
- Current and previous state of the command.

This allow easier management and passing of execution command data between classes and management of it. This will later allow each ExectionCommand command to be linked to a Terminal Session, to handle post processing and failure management.
The ExectionCommand also provides functions to get its data in markdown format, which can be used by failure or success reports generated for the command that are shown to the user. The commandHelp and pluginAPIHelp can also be specially useful to provide info to users on how to manage failures that are generated.
2021-03-24 03:48:24 +05:00
agnostic-apollo 20d20f42c0 Added NotificationUtils to build and manage notifications
The `TermuxPreferenceConstants` classes has been updated to `v0.5.0`. Check its Changelog sections for info on changes.
2021-03-24 03:25:25 +05:00
agnostic-apollo 9d36e9adde Add ReportActivity and ReportInfo
This implements the framework to report info to users. This may include reporting failure or result of commands or any exceptions that are raised.

The ReportInfo provides 5 fields:
- userAction: The user action that was being processed for which the report was generated.
- sender: The internal app component that sent the report.
- title: The report title.
- reportString: The markdown text for the report.
- addReportAndDeviceDetails: If set to true, then report and device details will be added to the report.

This should provide the basics parameters for showing a report to the user. The ReportActivity also allows user to copy and share the report.

In future this can also be used to allow users to easily email or post crash reports to github for Termux app crashes instead of going through logcat.
2021-03-24 03:22:12 +05:00
agnostic-apollo 3491956385 Update TermuxUtils to add support for getting device and termux info as markdown 2021-03-24 02:38:37 +05:00
agnostic-apollo 134e21765c Update Logger
- Add support to log Throwables instead of just Exception class objects.
- Adds utility functions to get Throwables as Strings and Markdown Strings.
2021-03-24 02:34:53 +05:00
agnostic-apollo c28990a176 Add ShareUtils 2021-03-24 02:31:22 +05:00
agnostic-apollo 131f481750 Add commonmark-spec markdown support with markwon library
Also adds MarkdownUtitls to provide various utils for markdown processing.
2021-03-24 02:30:20 +05:00
agnostic-apollo f393e9b2cf Allow mPropertiesList to be null for SharedProperties
This will allow all keys that are read from file to be stored in mMap without knowing their names beforehand.
2021-03-24 02:27:28 +05:00
agnostic-apollo 8612a1d0f8 Added plugin_error_notifications_enabled preference
This will allow user to control whether flashes and notifications for plugin errors are enabled or not.

The `TermuxPreferenceConstants` classes has been updated to `v0.4.0`. Check its Changelog sections for info on changes.
2021-03-19 22:49:06 +05:00
agnostic-apollo 7d53a147d8 Reordered TermuxService.actionAcquireWakeLock() 2021-03-19 21:18:39 +05:00
agnostic-apollo 5d6a98452a Added TERMUX_SERVICE#ACTION_SERVICE_EXECUTE Intent Logging 2021-03-19 21:18:37 +05:00
agnostic-apollo b4995ef9a7 Refactor RunCommandService
- The `FileUtils` and `PluginUtils` have been added to provide utility functions.
- The executable and working directory validation has been added to check for existence and missing permissions.
- The `expandPath()` function is removed from `RunCommandService`.
- Working directory will automatically be created if under `TermuxConstants.TERMUX_FILES_DIR_PATH` if missing.
- Better logging has been added. This will later be used to notify the user in foreground.
- Javadocs have been updated.
2021-03-19 21:18:35 +05:00
agnostic-apollo ec7568d28e Add support for session actions for foreground session commands
The `TERMUX_SERVICE.EXTRA_SESSION_ACTION` extra can be passed to define what should happen when a foreground session
command is received for the `TERMUX_SERVICE.ACTION_SERVICE_EXECUTE` intent to `TermuxService`, like from `RunCommandService` or `Termux:Tasker`. The user can define whether the new session should be automatically switched to or if existing session should remain as the current session. The user can also define if foreground session commands should open the `TermuxActivity` or if they should run in the "background" in the Termux notification. The user can click the notification to open the sessions. Check `TERMUX_SERVICE.VALUE_EXTRA_SESSION_ACTION*` values to see various behaviors.

This also solves the old "issue" that if a foreground command was received while an existing session was already in the foreground, the new session won't be switched to automatically. It only brought the new session to the foreground if the activity was not already in foreground, since a call to `mTermuxSessionClient.setCurrentSession(newSession)` wasn't being made.
2021-03-19 21:18:33 +05:00
agnostic-apollo 607ba3ee56 Update TermuxConstants
The `TermuxConstants` classes has been updated to `v0.10.0`. Check its Changelog sections for info on changes.
2021-03-19 21:18:31 +05:00
agnostic-apollo ae260fad9c Fix old bug where termux app would crash if sessions list ListView was not notified of new sessions
To reproduce:
1. Create 2 sessions.
2. From either session, run a random `RUN_COMMAND` intent command with `am` command and shift to the other session.

Termux app would crash and throw the `The content of the adapter has changed but ListView did not receive a notification.` exception. TermuxService was previously not notifying the ListView of the sessions list that a new session has been added, if the activity was in foreground.
2021-03-19 21:18:27 +05:00
agnostic-apollo d9b5344b24 Refactor TermuxService
- Dedicated functions have been created for various actions and commands.
- The `startForeground()` call will be made both on `onCreate()` and `onStartCommand().
- The `stopForeground()` call will be made before every `onSelf()` call.
- The references to `TermuxActivity` will now be removed in `onUnbind()` as well if activity `onDestroy()` failed to do so.
- Appropriate log entries are added to help debug issues.
2021-03-19 21:18:25 +05:00
agnostic-apollo bc02508102 Fix dependencies ordering 2021-03-19 21:18:24 +05:00
agnostic-apollo f969c01f7e Update TermuxConstants
The `TermuxConstants` classes has been updated to `v0.9.0`. Check its Changelog sections for info on changes.
2021-03-19 21:18:21 +05:00
agnostic-apollo fb6e9b69ab Update TermuxConstants
The `TermuxConstants` classes has been updated to `v0.8.0`. Check its Changelog sections for info on changes.
2021-03-19 21:18:13 +05:00
agnostic-apollo c1a377d15d Update SharedPreferenceUtils
This SharedPreferenceUtils now supports:
- Getting `Context.MODE_PRIVATE` and/or `Context.MODE_MULTI_PROCESS` `SharedPreference` instances.
- Setting values to shared preferences in-memory cache and the file synchronously.
- Getting and setting `float`, `long` and `Set<Sting>` values in shared preferences.
2021-03-17 03:16:37 +05:00
agnostic-apollo 8c1c7ce727 Update TermuxConstants
The `TermuxConstants` classes has been updated to `v0.7.0`. Check its Changelog sections for info on changes.
2021-03-17 01:13:44 +05:00
agnostic-apollo 2a940dfca6 Move general static functions from TermuxSharedProperties to SharedProperties class
This will allow `SharedProperties` class to be used directly to get property values and their internal values via static functions instead of using `TermuxSharedProperties` where the functions don't belong in.

The `TermuxPropertyConstants` classes has been updated to `v0.4.0`. Check its Changelog sections for info on changes.
2021-03-16 22:52:20 +05:00
agnostic-apollo 2e7fd480f4 Update TermuxConstants
The `TermuxConstants` classes has been updated to `v0.6.0`. Check its Changelog sections for info on changes.
2021-03-16 21:29:25 +05:00
agnostic-apollo 9e82561804 Added SharedPreferenceUtils
The `SharedPreferenceUtils` class has been added to provide static util functions for shared preferences like get and set while safely handling exceptions. The `TermuxSharedPreferences` class has been renamed to `TermuxAppSharedPreferences` since its to be used to handle only Termux App related shared preferences and not of other plugin apps. For plugin apps, separate classes can be created. However, Termux app and its plugins will share the same `TermuxPreferenceConstants` class that now has per app scoping since `v0.3.0`.
2021-03-16 20:51:41 +05:00
agnostic-apollo 4427c1675d Update TermuxConstants
The `TermuxConstants` classes has been updated to `v0.5.0`. Check its Changelog sections for info on changes.
2021-03-16 19:07:54 +05:00
agnostic-apollo 6f6d11fbb8 Updated TermuxPreferenceConstants
The `TermuxPreferenceConstants` classes has been updated to `v0.3.0`. Check its Changelog sections for info on changes.
2021-03-16 19:06:17 +05:00
agnostic-apollo ff0440d7d2 Allow users to adjust termux toolbar height with termux.properties
This `terminal-toolbar-height` key can be used to adjust the toolbar height. The user can set a float value between `0.4` and `3.0` which will be used as the scaling factor for the default height. The default scaling factor is `1`. So adding an entry like `terminal-toolbar-height=2.0` to `termux.properties` file will make the toolbar height twice its original height. Running `termux-reload-settings` command will also update the height instantaneously if changed.

Fixes #1857
2021-03-16 07:04:55 +05:00
agnostic-apollo c9e18e5b93 Refactor TermuxActivity
This commit majorly refactors `TermuxActivity` and moves its view components and functions into dedicated classes.

- The view layouts and ids have been given meaningful names, like `termux_activity.xml`.
- The `TerminalToolbarViewPager` class has been created to handle the now called toolbar that shows on the bottom of the terminal view. It currently contains extra keys view defined by `terminal_toolbar_extra_keys_view.xml` file and a text input view defined by `terminal_toolbar_text_input_view.xml` file when user can switch to by swiping left. The input text will now be preserved if android destroys the activity or its recreated.
- The `TermuxSessionsListViewController` class has been created to handle view related functionality of the termux sessions list shown in the left drawer, namely view creation, `onItemClick()`, `onItemLongClick()`, etc. Its list view is defined by `termux_activity.xml` file and each item's layout is defined by the `terminal_sessions_list_item.xml` file.
- The `TextDataUtils` class has been added to the `com.termux.app.utils` package for text utils.
- The design for the `SessionChangedCallback` interface for `TerminalSession` has been majorly changed. Firstly, it has been renamed and moved from `TerminalSession` to the dedicated `TerminalSessionClient` class file. The interface now also supports the termux app centralized logging framework so that `TerminalSession` and `TerminalEmulator` can use them. Previously, `TermuxService` was implementing a wrapper interface, which would then call the real interface defined by the `TermuxActivity` if it was currently bound to the service. This cluttered and partially duplicated the code. Now, the implementation is defined by the `TermuxSessionClientBase` and `TermuxSessionClient` classes. The `TermuxSessionClientBase` implements the `TerminalSessionClient` interface but the definition of the activity related functions do not do anything, only the background ones like the logging functions are fully implemented. The `TermuxSessionClient` class inherits from the `TermuxSessionClientBase` class and provides the implementation for the activity related functions. The design for how this works is that if the `TermuxService` is not bound to `TermuxActivity`, it just passes the `TermuxSessionClientBase` implementation to `TerminalSession`. If the activity is bound at some point, then in `onServiceConnected()` it replaces/updates the client objects stored in `TerminalSession` and `TerminalEmulator` with `TermuxSessionClient`, and then replaces them back with `TermuxSessionClientBase` in `onDestroy()`. This seems to be working for now without an issue.
2021-03-16 05:01:09 +05:00
agnostic-apollo 5e0b29bb6d Move DialogUtils to com.termux.app.utils package 2021-03-16 04:07:01 +05:00
agnostic-apollo 73af5c2326 Move terminal io related classed to com.termux.app.terminal.io package 2021-03-16 04:05:15 +05:00
agnostic-apollo 7da847a485 Update TermuxConstants
The `TermuxConstants` classes has been updated to `v0.4.0`. Check its Changelog sections for info on changes.
2021-03-16 03:59:54 +05:00
agnostic-apollo 11a236a172 Update TerminalView and TerminalViewClient javadocs 2021-03-16 03:46:34 +05:00
agnostic-apollo 3b5d3114a6 Prefix DEFAULT_LOG_TAG even when a tag is passed while logging 2021-03-16 03:44:45 +05:00
agnostic-apollo 66f15d2a08 Remove moved files 2021-03-16 03:44:27 +05:00
agnostic-apollo 0225a8b1fc Fix hardcoded value in strings.xml 2021-03-16 03:41:17 +05:00
agnostic-apollo d39972b3bf Implement GUI based Termux settings manager and a centralized logging framework
The settings activity can be accessed by long pressing on terminal view and selecting "Settings" from the popup shown. It uses the Android's Preference framework. Currently only debugging preferences to set log level and enabling terminal view key logging are provided. The Preference framework by default uses the keys set in `app:key` attribute in the respective preferences XML file to store the values in the default `SharedPreferences` file of the app. However, since we rely on `TermuxPreferenceConstants` and `TermuxPropertyConstants` classes to define key names so that they can be easily shared between termux and its plugin apps, we provide our own `PreferenceDataStore` for storing key/value pairs. The key name in the XML file can optionally be the same. Check `DebuggingPreferencesFragment` class for a sample. Each new preference category fragment should be added to `app/settings/` with its data store.

This commit may allow support to be added for modifying `termux.properties` file directly from the UI but that requires more work, since writing to property files with comments require in-place modification.

The `Logger` class provides various static functions for logging that should be used from now on instead of directly calling android `Log.*` functions. The log level is automatically loaded from shared preferences at application startup via `TermuxApplication` and set in the static `Logger.CURRENT_LOG_LEVEL` variable. Changing the log level through the settings activity also changes the log level immediately.

The 4 supported log levels are:
- LOG_LEVEL_OFF which will log nothing.
- LOG_LEVEL_NORMAL which will start logging error, warn and info messages and stacktraces.
- LOG_LEVEL_DEBUG which will start logging debug messages.
- LOG_LEVEL_VERBOSE which will start logging verbose messages.

The default log level is `LOG_LEVEL_NORMAL` which will not log debug or verbose messages. Contributors can add useful log entries at those levels where ever they feel is appropriate so that it allows users and devs to more easily help solve issues or find bugs, specially without having to recompile termux after having to manually add general log entries to the source. DO NOT log data that may have private info of users like command arguments at log levels below debug, like `BackgroundJob` was doing previously.

Logging to file support may be added later, will require log file rotation support and storage permissions.
2021-03-13 16:49:29 +05:00
agnostic-apollo 93b506a001 Move Termux Preferences to com.termux.app.settings.preferences package
The termux preferences handling was mixed in with termux properties before an earlier commit. They are now moved out of into a separate sub package, the following classes are added:

- `TermuxPreferenceConstants` class that defines shared constants of the preferences used by Termux app and its plugins. This class should be imported by other termux plugin apps instead of copying and defining their own constants.
- `TermuxSharedPreferences` class that acts as manager for handling termux preferences.
2021-03-12 06:01:31 +05:00
agnostic-apollo ebf2e472b3 Fix typo in TermuxPropertyConstants 2021-03-12 05:54:12 +05:00
agnostic-apollo e72841ba27 Update TermuxConstants
The `TermuxConstants` classes has been updated to `v0.3.0`. Check its Changelog sections for info on changes.
2021-03-12 05:53:10 +05:00
agnostic-apollo 5fd91b4f92 Rename com.termux.app.input package to com.termux.app.terminal
Also moves `TermuxViewClient` into com.termux.app.terminal package
2021-03-12 00:07:35 +05:00
agnostic-apollo 10d6eaa5d1 Make TerminalView agnostic of "termux.properties" files.
`TerminalView` will use the `TerminalViewClient` interface implemented by `TermuxViewClient` in termux-app to get "enforce-char-based-input" and "ctrl-space-workaround" property values. It will also not read the file every time it needs to get the property value and will get it from the in-memory cache of `TermuxSharedProperties`.
2021-03-11 21:06:42 +05:00