From 122601b733c71b2ac29dffa06d2aa72a6f80bada Mon Sep 17 00:00:00 2001 From: Pablo Matias Gomez Date: Thu, 5 Dec 2024 17:31:48 -0300 Subject: [PATCH 1/3] Change sdk enabled logic to mimic android and backend --- .../EmbraceConfigurable/RemoteConfig.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/EmbraceConfigInternal/EmbraceConfigurable/RemoteConfig.swift b/Sources/EmbraceConfigInternal/EmbraceConfigurable/RemoteConfig.swift index ba98244a..589e188c 100644 --- a/Sources/EmbraceConfigInternal/EmbraceConfigurable/RemoteConfig.swift +++ b/Sources/EmbraceConfigInternal/EmbraceConfigurable/RemoteConfig.swift @@ -97,17 +97,17 @@ extension RemoteConfig { /// Determine the max value for the probability `space` by using the number of `digits` (16 ^ `n`) /// If the `hexValue` is within the `threshold` /// ``` - /// space = 16^numDigits - /// result = (hexValue / space) * 100.0 < threshold + /// space = 16^numDigits - 1 + /// result = (hexValue / space) * 100.0 <= threshold /// ``` /// - Parameters: /// - hexValue: The value to test /// - digits: The number of digits used to calculate the total space. Must match the number of digits used to determine the hexValue /// - threshold: The percentage threshold to test against. Values between 0.0 and 100.0 static func isEnabled(hexValue: UInt64, digits: UInt, threshold: Float) -> Bool { - let space = powf(16, Float(digits)) + let space = powf(16, Float(digits)) - 1 let result = (Float(hexValue) / space) * 100 - return result < threshold + return result <= threshold } } From 70802453a243b130fb55a779c2ad6f98ca3ddd1f Mon Sep 17 00:00:00 2001 From: Pablo Matias Gomez Date: Thu, 5 Dec 2024 17:50:37 -0300 Subject: [PATCH 2/3] Change sdk enabled logic to mimic android and backend --- .../EmbraceConfigurable/RemoteConfig.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sources/EmbraceConfigInternal/EmbraceConfigurable/RemoteConfig.swift b/Sources/EmbraceConfigInternal/EmbraceConfigurable/RemoteConfig.swift index 589e188c..e42935c7 100644 --- a/Sources/EmbraceConfigInternal/EmbraceConfigurable/RemoteConfig.swift +++ b/Sources/EmbraceConfigInternal/EmbraceConfigurable/RemoteConfig.swift @@ -89,6 +89,9 @@ extension RemoteConfig: EmbraceConfigurable { extension RemoteConfig { func isEnabled(threshold: Float) -> Bool { + if (threshold <= 0 || threshold > 100) { + return false + } return Self.isEnabled(hexValue: deviceIdHexValue, digits: Self.deviceIdUsedDigits, threshold: threshold) } From 8de4f98e8de56df97138a4e9a0852801a5663d98 Mon Sep 17 00:00:00 2001 From: Pablo Matias Gomez Date: Fri, 6 Dec 2024 10:52:33 -0300 Subject: [PATCH 3/3] check logic in generic func --- .../EmbraceConfigurable/RemoteConfig.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Sources/EmbraceConfigInternal/EmbraceConfigurable/RemoteConfig.swift b/Sources/EmbraceConfigInternal/EmbraceConfigurable/RemoteConfig.swift index e42935c7..be74d59d 100644 --- a/Sources/EmbraceConfigInternal/EmbraceConfigurable/RemoteConfig.swift +++ b/Sources/EmbraceConfigInternal/EmbraceConfigurable/RemoteConfig.swift @@ -89,9 +89,6 @@ extension RemoteConfig: EmbraceConfigurable { extension RemoteConfig { func isEnabled(threshold: Float) -> Bool { - if (threshold <= 0 || threshold > 100) { - return false - } return Self.isEnabled(hexValue: deviceIdHexValue, digits: Self.deviceIdUsedDigits, threshold: threshold) } @@ -108,6 +105,10 @@ extension RemoteConfig { /// - digits: The number of digits used to calculate the total space. Must match the number of digits used to determine the hexValue /// - threshold: The percentage threshold to test against. Values between 0.0 and 100.0 static func isEnabled(hexValue: UInt64, digits: UInt, threshold: Float) -> Bool { + if threshold <= 0 || threshold > 100 { + return false + } + let space = powf(16, Float(digits)) - 1 let result = (Float(hexValue) / space) * 100