From 8ed7362910d830b6cb4849687556604b1a9546b6 Mon Sep 17 00:00:00 2001 From: Rajiv Singaseni Date: Sun, 15 Dec 2024 00:37:42 +0530 Subject: [PATCH] fix: Improve Java interop for SecurityCheckState enum --- .../src/android/SecurityCheckerPlugin.java | 18 ++++++++-------- .../webileapps/safeguard/SecurityChecker.kt | 21 ++++++++++++++++--- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/cordova-plugin-security-checker/src/android/SecurityCheckerPlugin.java b/cordova-plugin-security-checker/src/android/SecurityCheckerPlugin.java index 29997b6..99752ea 100644 --- a/cordova-plugin-security-checker/src/android/SecurityCheckerPlugin.java +++ b/cordova-plugin-security-checker/src/android/SecurityCheckerPlugin.java @@ -35,14 +35,14 @@ public void initialize(CordovaInterface cordova, CordovaWebView webView) { SecurityConfigManager.INSTANCE.initialize( cordova.getActivity().getApplicationContext(), new SecurityChecker.SecurityConfig( - SecurityChecker.SecurityCheckState.valueOf(rootCheckState), - SecurityChecker.SecurityCheckState.valueOf(devOptionsCheckState), - SecurityChecker.SecurityCheckState.valueOf(malwareCheckState), - SecurityChecker.SecurityCheckState.valueOf(tamperingCheckState), - SecurityChecker.SecurityCheckState.valueOf(networkSecurityCheckState), - SecurityChecker.SecurityCheckState.valueOf(screenSharingCheckState), - SecurityChecker.SecurityCheckState.valueOf(appSpoofingCheckState), - SecurityChecker.SecurityCheckState.valueOf(keyloggerCheckState) + SecurityChecker.SecurityCheckState.fromString(rootCheckState), + SecurityChecker.SecurityCheckState.fromString(devOptionsCheckState), + SecurityChecker.SecurityCheckState.fromString(malwareCheckState), + SecurityChecker.SecurityCheckState.fromString(tamperingCheckState), + SecurityChecker.SecurityCheckState.fromString(networkSecurityCheckState), + SecurityChecker.SecurityCheckState.fromString(screenSharingCheckState), + SecurityChecker.SecurityCheckState.fromString(appSpoofingCheckState), + SecurityChecker.SecurityCheckState.fromString(keyloggerCheckState) ) ); } @@ -51,7 +51,7 @@ private String getSecurityCheckState(String preferenceName, String defaultValue) String value = preferences.getString(preferenceName, defaultValue); // Validate that the value is a valid SecurityCheckState try { - SecurityChecker.SecurityCheckState.valueOf(value); + SecurityChecker.SecurityCheckState.fromString(value); return value; } catch (IllegalArgumentException e) { Log.w(TAG, "Invalid security check state for " + preferenceName + ": " + value + ". Using default: " + defaultValue); diff --git a/protect/src/main/java/com/webileapps/safeguard/SecurityChecker.kt b/protect/src/main/java/com/webileapps/safeguard/SecurityChecker.kt index 476e2d3..45c0d38 100644 --- a/protect/src/main/java/com/webileapps/safeguard/SecurityChecker.kt +++ b/protect/src/main/java/com/webileapps/safeguard/SecurityChecker.kt @@ -37,12 +37,27 @@ class SecurityChecker(private val context: Context, private val config: Security val networkSecurityCheck: SecurityCheckState = SecurityCheckState.WARNING, val screenSharingCheck: SecurityCheckState = SecurityCheckState.WARNING, val appSpoofingCheck: SecurityCheckState = SecurityCheckState.WARNING, - val keyloggerCheck: SecurityCheckState = SecurityCheckState.WARNING, - val appSpoofingAsWarning: Boolean = false + val keyloggerCheck: SecurityCheckState = SecurityCheckState.WARNING ) + @JvmField + val DISABLED = SecurityCheckState.DISABLED + + @JvmField + val WARNING = SecurityCheckState.WARNING + + @JvmField + val ERROR = SecurityCheckState.ERROR + enum class SecurityCheckState { - DISABLED, WARNING, ERROR + DISABLED, WARNING, ERROR; + + companion object { + @JvmStatic + fun fromString(value: String): SecurityCheckState { + return valueOf(value.uppercase()) + } + } } // Check for rooted device