Changed: Load termux.properties into a single static app wide TermuxAppSharedProperties class

The `TermuxAppSharedProperties.properties` will exist in `termux-shared` library and only the single static instance will be reloaded whenever needed, instead of different activities and services maintaining their own instances. The classes in `termux-shared` library will also get access to the properties for their own needs.

The night mode set in `TermuxApplication` and terminal rows set in `TermuxService` will no longer require loading props from disk.

Updating `allow-external-apps` value will now require restarting termux or running `termux-reload-settings` since value will no longer be loaded from disk every time.
This commit is contained in:
agnostic-apollo
2022-03-10 02:26:59 +05:00
parent 6d944b5f7f
commit 05283bd774
12 changed files with 200 additions and 162 deletions

View File

@@ -0,0 +1,42 @@
package com.termux.shared.termux.settings.properties;
import android.content.Context;
import androidx.annotation.NonNull;
import com.termux.shared.termux.TermuxConstants;
public class TermuxAppSharedProperties extends TermuxSharedProperties {
private static TermuxAppSharedProperties properties;
private TermuxAppSharedProperties(@NonNull Context context) {
super(context, TermuxConstants.TERMUX_APP_NAME,
TermuxPropertyConstants.getTermuxPropertiesFile(), TermuxPropertyConstants.TERMUX_APP_PROPERTIES_LIST,
new TermuxSharedProperties.SharedPropertiesParserClient());
}
/**
* Initialize the {@link #properties} and load properties from disk.
*
* @param context The {@link Context} for operations.
* @return Returns the {@link TermuxAppSharedProperties}.
*/
public static TermuxAppSharedProperties init(@NonNull Context context) {
if (properties == null)
properties = new TermuxAppSharedProperties(context);
return properties;
}
/**
* Get the {@link #properties}.
*
* @return Returns the {@link TermuxAppSharedProperties}.
*/
public static TermuxAppSharedProperties getProperties() {
return properties;
}
}

View File

@@ -355,7 +355,7 @@ public final class TermuxPropertyConstants {
/** Defines the set for keys loaded by termux
* Setting this to {@code null} will make {@link SharedProperties} throw an exception.
* */
public static final Set<String> TERMUX_PROPERTIES_LIST = new HashSet<>(Arrays.asList(
public static final Set<String> TERMUX_APP_PROPERTIES_LIST = new HashSet<>(Arrays.asList(
/* boolean */
KEY_DISABLE_HARDWARE_KEYBOARD_SHORTCUTS,
KEY_DISABLE_TERMINAL_SESSION_CHANGE_TOAST,

View File

@@ -8,6 +8,7 @@ import com.termux.shared.logger.Logger;
import com.termux.shared.data.DataUtils;
import com.termux.shared.settings.properties.SharedProperties;
import com.termux.shared.settings.properties.SharedPropertiesParser;
import com.termux.shared.termux.TermuxConstants;
import java.io.File;
import java.util.HashMap;
@@ -539,6 +540,9 @@ public abstract class TermuxSharedProperties {
public boolean shouldAllowExternalApps() {
return (boolean) getInternalPropertyValue(TermuxConstants.PROP_ALLOW_EXTERNAL_APPS, true);
}
public boolean areHardwareKeyboardShortcutsDisabled() {
return (boolean) getInternalPropertyValue(TermuxPropertyConstants.KEY_DISABLE_HARDWARE_KEYBOARD_SHORTCUTS, true);
}