21
21
public class TermuxShellUtils {
22
22
23
23
public static String TERMUX_VERSION_NAME ;
24
- public static String TERMUX_IS_DEBUG_BUILD ;
25
- public static String TERMUX_APK_RELEASE ;
24
+ public static String TERMUX_IS_DEBUGGABLE_BUILD ;
26
25
public static String TERMUX_APP_PID ;
26
+ public static String TERMUX_APK_RELEASE ;
27
27
28
28
public static String getDefaultWorkingDirectoryPath () {
29
29
return TermuxConstants .TERMUX_HOME_DIR_PATH ;
@@ -45,12 +45,12 @@ public static String[] buildEnvironment(Context currentPackageContext, boolean i
45
45
46
46
if (TERMUX_VERSION_NAME != null )
47
47
environment .add ("TERMUX_VERSION=" + TERMUX_VERSION_NAME );
48
- if (TERMUX_IS_DEBUG_BUILD != null )
49
- environment .add ("TERMUX_IS_DEBUG_BUILD=" + TERMUX_IS_DEBUG_BUILD );
50
- if (TERMUX_APK_RELEASE != null )
51
- environment .add ("TERMUX_APK_RELEASE=" + TERMUX_APK_RELEASE );
48
+ if (TERMUX_IS_DEBUGGABLE_BUILD != null )
49
+ environment .add ("TERMUX_IS_DEBUGGABLE_BUILD=" + TERMUX_IS_DEBUGGABLE_BUILD );
52
50
if (TERMUX_APP_PID != null )
53
51
environment .add ("TERMUX_APP_PID=" + TERMUX_APP_PID );
52
+ if (TERMUX_APK_RELEASE != null )
53
+ environment .add ("TERMUX_APK_RELEASE=" + TERMUX_APK_RELEASE );
54
54
55
55
environment .add ("TERM=xterm-256color" );
56
56
environment .add ("COLORTERM=truecolor" );
@@ -156,20 +156,30 @@ public static void clearTermuxTMPDIR(boolean onlyIfExists) {
156
156
}
157
157
158
158
public static void loadTermuxEnvVariables (Context currentPackageContext ) {
159
- TERMUX_VERSION_NAME = TERMUX_IS_DEBUG_BUILD = TERMUX_APK_RELEASE = TERMUX_APP_PID = null ;
160
-
161
- // This function may be called by a different package like a plugin, so we get version for Termux package via its context
162
- Context termuxPackageContext = TermuxUtils .getTermuxPackageContext (currentPackageContext );
163
- if (termuxPackageContext != null ) {
164
- TERMUX_VERSION_NAME = PackageUtils .getVersionNameForPackage (termuxPackageContext );
165
- TERMUX_IS_DEBUG_BUILD = PackageUtils .isAppForPackageADebugBuild (termuxPackageContext ) ? "1" : "0" ;
166
-
167
- String signingCertificateSHA256Digest = PackageUtils .getSigningCertificateSHA256DigestForPackage (termuxPackageContext );
168
- if (signingCertificateSHA256Digest != null )
169
- TERMUX_APK_RELEASE = TermuxUtils .getAPKRelease (signingCertificateSHA256Digest ).replaceAll ("[^a-zA-Z]" , "_" ).toUpperCase ();
170
-
171
- TERMUX_APP_PID = TermuxUtils .getTermuxAppPID (currentPackageContext );
159
+ String termuxAPKReleaseOld = TERMUX_APK_RELEASE ;
160
+ TERMUX_VERSION_NAME = TERMUX_IS_DEBUGGABLE_BUILD = TERMUX_APP_PID = TERMUX_APK_RELEASE = null ;
161
+
162
+ // Check if Termux app is installed and not disabled
163
+ if (TermuxUtils .isTermuxAppInstalled (currentPackageContext ) == null ) {
164
+ // This function may be called by a different package like a plugin, so we get version for Termux package via its context
165
+ Context termuxPackageContext = TermuxUtils .getTermuxPackageContext (currentPackageContext );
166
+ if (termuxPackageContext != null ) {
167
+ TERMUX_VERSION_NAME = PackageUtils .getVersionNameForPackage (termuxPackageContext );
168
+ TERMUX_IS_DEBUGGABLE_BUILD = PackageUtils .isAppForPackageADebuggableBuild (termuxPackageContext ) ? "1" : "0" ;
169
+
170
+ TERMUX_APP_PID = TermuxUtils .getTermuxAppPID (currentPackageContext );
171
+
172
+ // Getting APK signature is a slightly expensive operation, so do it only when needed
173
+ if (termuxAPKReleaseOld == null ) {
174
+ String signingCertificateSHA256Digest = PackageUtils .getSigningCertificateSHA256DigestForPackage (termuxPackageContext );
175
+ if (signingCertificateSHA256Digest != null )
176
+ TERMUX_APK_RELEASE = TermuxUtils .getAPKRelease (signingCertificateSHA256Digest ).replaceAll ("[^a-zA-Z]" , "_" ).toUpperCase ();
177
+ } else {
178
+ TERMUX_APK_RELEASE = termuxAPKReleaseOld ;
179
+ }
180
+ }
172
181
}
182
+
173
183
}
174
184
175
185
}
0 commit comments