Added: Add `TERMUX_APPS_DIR_PATH` and `TERMUX_APP.APPS_DIR_PATH` and create them at application startup.

The termux files directory will also be checked and created if required at startup and code related to it will only be run if it is accessible. This can later also be used for init execution commands.

The `TERMUX_APP.APPS_DIR_PATH` will act as app specific directory for `termux-app` app related files. Other plugin apps will have their own directories under `TERMUX_APPS_DIR_PATH` if required.
This commit is contained in:
agnostic-apollo 2022-04-17 06:38:42 +05:00
parent 6bda7c4fc4
commit bcd8f4c419
3 changed files with 52 additions and 3 deletions

View File

@ -4,16 +4,20 @@ import android.app.Application;
import android.content.Context;
import com.termux.am.Am;
import com.termux.shared.errors.Error;
import com.termux.shared.logger.Logger;
import com.termux.shared.shell.LocalSocketListener;
import com.termux.shared.termux.TermuxConstants;
import com.termux.shared.termux.crash.TermuxCrashUtils;
import com.termux.shared.termux.file.TermuxFileUtils;
import com.termux.shared.termux.settings.preferences.TermuxAppSharedPreferences;
import com.termux.shared.termux.settings.properties.TermuxAppSharedProperties;
import com.termux.shared.termux.theme.TermuxThemeUtils;
public class TermuxApplication extends Application {
private static final String LOG_TAG = "TermuxApplication";
public void onCreate() {
super.onCreate();
@ -33,6 +37,21 @@ public class TermuxApplication extends Application {
// Set NightMode.APP_NIGHT_MODE
TermuxThemeUtils.setAppNightMode(properties.getNightMode());
// Check and create termux files directory. If failed to access it like in case of secondary
// user or external sd card installation, then don't run files directory related code
Error error = TermuxFileUtils.isTermuxFilesDirectoryAccessible(this, true, true);
if (error != null) {
Logger.logErrorExtended(LOG_TAG, "Termux files directory is not accessible\n" + error);
} else {
Logger.logInfo(LOG_TAG, "Termux files directory is accessible");
error = TermuxFileUtils.isAppsTermuxAppDirectoryAccessible(true, true);
if (error != null) {
Logger.logErrorExtended(LOG_TAG, "Create apps/termux-app directory failed\n" + error);
return;
}
}
if (LocalSocketListener.tryEstablishLocalSocketListener(this, (args, out, err) -> {
try {
new Am(out, err, this).run(args);

View File

@ -11,7 +11,7 @@ import java.util.Formatter;
import java.util.List;
/*
* Version: v0.39.0
* Version: v0.40.0
* SPDX-License-Identifier: MIT
*
* Changelog
@ -216,10 +216,10 @@ import java.util.List;
* - Added `TERMUX_PROPERTIES_FILE_PATHS_LIST` and `TERMUX_FLOAT_PROPERTIES_FILE_PATHS_LIST`.
*
* - 0.34.0 (2021-10-26)
* - Move `RESULT_SENDER` to `com.termux.shared.shell.command.ShellCommandConstants`.
* - Move `RESULT_SENDER` to `com.termux.shared.shell.command.ShellCommandConstants`.
*
* - 0.35.0 (2022-01-28)
* - Add `TERMUX_APP.TERMUX_ACTIVITY.EXTRA_RECREATE_ACTIVITY`.
* - Add `TERMUX_APP.TERMUX_ACTIVITY.EXTRA_RECREATE_ACTIVITY`.
*
* - 0.36.0 (2022-03-10)
* - Added `TERMUX_APP.TERMUX_SERVICE.EXTRA_RUNNER` and `TERMUX_APP.RUN_COMMAND_SERVICE.EXTRA_RUNNER`
@ -233,6 +233,9 @@ import java.util.List;
* - 0.39.0 (2022-03-18)
* - Added `TERMUX_APP.TERMUX_SERVICE.EXTRA_SESSION_NAME`, `TERMUX_APP.RUN_COMMAND_SERVICE.EXTRA_SESSION_NAME`,
* `TERMUX_APP.TERMUX_SERVICE.EXTRA_SESSION_CREATE_MODE` and `TERMUX_APP.RUN_COMMAND_SERVICE.EXTRA_SESSION_CREATE_MODE`.
*
* - 0.40.0 (2022-04-17)
* - Added `TERMUX_APPS_DIR_PATH` and `TERMUX_APP.APPS_DIR_PATH`.
*/
/**
@ -657,6 +660,11 @@ public final class TermuxConstants {
/** Termux and plugin apps directory path */
public static final String TERMUX_APPS_DIR_PATH = TERMUX_FILES_DIR_PATH + "/apps"; // Default: "/data/data/com.termux/files/apps"
/** Termux and plugin apps directory */
public static final File TERMUX_APPS_DIR = new File(TERMUX_APPS_DIR_PATH);
/*
@ -872,6 +880,10 @@ public final class TermuxConstants {
*/
public static final class TERMUX_APP {
/** Termux apps directory path */
public static final String APPS_DIR_PATH = TERMUX_APPS_DIR_PATH + "/termux-app"; // Default: "/data/data/com.termux/files/apps/termux-app"
/** Termux app core activity name. */
public static final String TERMUX_ACTIVITY_NAME = TERMUX_PACKAGE_NAME + ".app.TermuxActivity"; // Default: "com.termux.app.TermuxActivity"

View File

@ -307,6 +307,24 @@ public class TermuxFileUtils {
false, false);
}
/**
* Validate if {@link TermuxConstants.TERMUX_APP#APPS_DIR_PATH} exists and has
* {@link FileUtils#APP_WORKING_DIRECTORY_PERMISSIONS} permissions.
*
* @param createDirectoryIfMissing The {@code boolean} that decides if directory file
* should be created if its missing.
* @param setMissingPermissions The {@code boolean} that decides if permissions are to be
* automatically set.
* @return Returns the {@code error} if path is not a directory file, failed to create it,
* or validating permissions failed, otherwise {@code null}.
*/
public static Error isAppsTermuxAppDirectoryAccessible(boolean createDirectoryIfMissing, boolean setMissingPermissions) {
return FileUtils.validateDirectoryFileExistenceAndPermissions("apps/termux-app directory", TermuxConstants.TERMUX_APP.APPS_DIR_PATH,
null, createDirectoryIfMissing,
FileUtils.APP_WORKING_DIRECTORY_PERMISSIONS, setMissingPermissions, true,
false, false);
}
/**
* Get a markdown {@link String} for stat output for various Termux app files paths.
*