From e14c4e1eb8b5afe2664be669403ea5e2f27837a0 Mon Sep 17 00:00:00 2001 From: Jamil Date: Fri, 16 May 2025 16:21:08 -0700 Subject: [PATCH] refactor(apple): Only apply MDM config when changed (#9173) In #9169 we applied MDM configuration from MDM upon _any_ change to UserDefaults. This is unnecessary. Instead, we can compare new vs old and only apply the new dict if there's changes. In this PR we also log the old and new dicts for debugging reasons. --- .../ConfigurationManager.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/swift/apple/FirezoneNetworkExtension/ConfigurationManager.swift b/swift/apple/FirezoneNetworkExtension/ConfigurationManager.swift index b0319382c..2e5f28fc6 100644 --- a/swift/apple/FirezoneNetworkExtension/ConfigurationManager.swift +++ b/swift/apple/FirezoneNetworkExtension/ConfigurationManager.swift @@ -81,7 +81,15 @@ class ConfigurationManager { } @objc private func handleUserDefaultsChanged(_ notification: Notification) { - self.managedDict = userDefaults.dictionary(forKey: managedDictKey) ?? [:] + let newManagedDict = (userDefaults.dictionary(forKey: managedDictKey) ?? [:]) as [String: Any?] + + // NSDictionary conforms to Equatable + if (managedDict as NSDictionary) == (newManagedDict as NSDictionary) { + return + } + + Log.log("Applying MDM configuration. Old: \(managedDict) New: \(newManagedDict)") + self.managedDict = newManagedDict } private func saveUserDict() {