mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-10 04:24:05 +08:00
Added: Add TERMUX_IS_DEBUG_BUILD, TERMUX_APK_RELEASE and TERMUX_APP_PID to termux shell environment
The `TERMUX_IS_DEBUG_BUILD` env variable will be set to `1` if termux APK is a debuggable APK and `0` otherwise. Note that the `dev_keystore.jks` shipped with termux app and plugin source code can also be used to create a release APK even though its mainly used for Github Debug Builds, in which case value will be `0`. The `TERMUX_APK_RELEASE` will be set to `GITHUB_DEBUG_BUILD`, `F_DROID` or `GOOGLE_PLAY_STORE` depending on release type. It will be set to `UNKNOWN` if signed with a custom key. The `TERMUX_APP_PID` will be set to the process of the main app process of the termux app package (`com.termux`), assuming its running when shell is started, like for `termux-float`. This variable is included since `pidof com.termux` does not return anything for release builds. It does work for debug builds and over adb/root. However, you still won't be able to get additional process info with `ps`, like that of threads, even with the pid and will need to use adb/root. However, `kill $TERMUX_APP_PID` will work from `termux-app` and `termux-float`. These variables can be used by termux devs and users for custom logic in future depending on release type.
This commit is contained in:
@@ -20,6 +20,11 @@ import java.util.List;
|
||||
|
||||
public class TermuxShellUtils {
|
||||
|
||||
public static String TERMUX_VERSION_NAME;
|
||||
public static String TERMUX_IS_DEBUG_BUILD;
|
||||
public static String TERMUX_APK_RELEASE;
|
||||
public static String TERMUX_APP_PID;
|
||||
|
||||
public static String getDefaultWorkingDirectoryPath() {
|
||||
return TermuxConstants.TERMUX_HOME_DIR_PATH;
|
||||
}
|
||||
@@ -36,13 +41,16 @@ public class TermuxShellUtils {
|
||||
|
||||
List<String> environment = new ArrayList<>();
|
||||
|
||||
// This function may be called by a different package like a plugin, so we get version for Termux package via its context
|
||||
Context termuxPackageContext = TermuxUtils.getTermuxPackageContext(currentPackageContext);
|
||||
if (termuxPackageContext != null) {
|
||||
String termuxVersionName = PackageUtils.getVersionNameForPackage(termuxPackageContext);
|
||||
if (termuxVersionName != null)
|
||||
environment.add("TERMUX_VERSION=" + termuxVersionName);
|
||||
}
|
||||
loadTermuxEnvVariables(currentPackageContext);
|
||||
|
||||
if (TERMUX_VERSION_NAME != null)
|
||||
environment.add("TERMUX_VERSION=" + TERMUX_VERSION_NAME);
|
||||
if (TERMUX_IS_DEBUG_BUILD != null)
|
||||
environment.add("TERMUX_IS_DEBUG_BUILD=" + TERMUX_IS_DEBUG_BUILD);
|
||||
if (TERMUX_APK_RELEASE != null)
|
||||
environment.add("TERMUX_APK_RELEASE=" + TERMUX_APK_RELEASE);
|
||||
if (TERMUX_APP_PID != null)
|
||||
environment.add("TERMUX_APP_PID=" + TERMUX_APP_PID);
|
||||
|
||||
environment.add("TERM=xterm-256color");
|
||||
environment.add("COLORTERM=truecolor");
|
||||
@@ -147,4 +155,21 @@ public class TermuxShellUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadTermuxEnvVariables(Context currentPackageContext) {
|
||||
TERMUX_VERSION_NAME = TERMUX_IS_DEBUG_BUILD = TERMUX_APK_RELEASE = TERMUX_APP_PID = null;
|
||||
|
||||
// This function may be called by a different package like a plugin, so we get version for Termux package via its context
|
||||
Context termuxPackageContext = TermuxUtils.getTermuxPackageContext(currentPackageContext);
|
||||
if (termuxPackageContext != null) {
|
||||
TERMUX_VERSION_NAME = PackageUtils.getVersionNameForPackage(termuxPackageContext);
|
||||
TERMUX_IS_DEBUG_BUILD = PackageUtils.isAppForPackageADebugBuild(termuxPackageContext) ? "1" : "0";
|
||||
|
||||
String signingCertificateSHA256Digest = PackageUtils.getSigningCertificateSHA256DigestForPackage(termuxPackageContext);
|
||||
if (signingCertificateSHA256Digest != null)
|
||||
TERMUX_APK_RELEASE = TermuxUtils.getAPKRelease(signingCertificateSHA256Digest).replaceAll("[^a-zA-Z]", "_").toUpperCase();
|
||||
|
||||
TERMUX_APP_PID = TermuxUtils.getTermuxAppPID(currentPackageContext);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user