Remove function that reads the "termux.properties" files from RunCommandService

The `RunCommandService` will now call the `TermuxSharedProperties` for getting current value of `allow-external-apps`, instead of using its own duplicated function to read "termux.properties" files.
This commit is contained in:
agnostic-apollo
2021-03-11 20:30:16 +05:00
parent ef9e406300
commit 36be41d0de

View File

@@ -15,6 +15,8 @@ import android.util.Log;
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.settings.properties.TermuxPropertyConstants;
import com.termux.app.settings.properties.TermuxSharedProperties;
import java.io.File;
import java.io.FileInputStream;
@@ -109,9 +111,9 @@ public class RunCommandService extends Service {
return Service.START_NOT_STICKY;
}
// If allow-external-apps property to not set to "true"
if (!allowExternalApps()) {
Log.e("termux", "RunCommandService requires allow-external-apps property to be set to \"true\" in ~/.termux/termux.properties file.");
// If allow-external-apps property is not set to "true"
if (!TermuxSharedProperties.isPropertyValueTrue(this, TermuxPropertyConstants.getTermuxPropertiesFile(), TermuxConstants.PROP_ALLOW_EXTERNAL_APPS)) {
Log.e("termux", "RunCommandService requires allow-external-apps property to be set to \"true\" in \"" + TermuxConstants.TERMUX_PROPERTIES_PRIMARY_FILE_PATH + "\" file");
return Service.START_NOT_STICKY;
}
@@ -183,25 +185,6 @@ public class RunCommandService extends Service {
manager.createNotificationChannel(channel);
}
private boolean allowExternalApps() {
File propsFile = new File(TermuxConstants.TERMUX_PROPERTIES_PRIMARY_FILE_PATH);
if (!propsFile.exists())
propsFile = new File(TermuxConstants.TERMUX_PROPERTIES_SECONDARY_FILE_PATH);
Properties props = new Properties();
try {
if (propsFile.isFile() && propsFile.canRead()) {
try (FileInputStream in = new FileInputStream(propsFile)) {
props.load(new InputStreamReader(in, StandardCharsets.UTF_8));
}
}
} catch (Exception e) {
Log.e("termux", "Error loading props", e);
}
return props.getProperty("allow-external-apps", "false").equals("true");
}
/** Replace "$PREFIX/" or "~/" prefix with termux absolute paths */
public static String getExpandedTermuxPath(String path) {
if(path != null && !path.isEmpty()) {