Skip to content

Commit

Permalink
fix: Improve Java interop for SecurityCheckState enum
Browse files Browse the repository at this point in the history
  • Loading branch information
rajiv-singaseni committed Dec 14, 2024
1 parent 0abb67a commit 8ed7362
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
);
}
Expand All @@ -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);
Expand Down
21 changes: 18 additions & 3 deletions protect/src/main/java/com/webileapps/safeguard/SecurityChecker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8ed7362

Please sign in to comment.