LocalOverrideSettings.swift 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // Copyright 2022 Google LLC
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. import Foundation
  16. /// Class that manages the local overrides configs related to the library.
  17. class LocalOverrideSettings: SettingsProvider, SettingsProtocol {
  18. static let PlistKey_sessions_enabled = "FirebaseSessionsEnabled"
  19. static let PlistKey_sessions_timeout = "FirebaseSessionsTimeout"
  20. static let PlistKey_sessions_samplingRate = "FirebaseSessionsSampingRate"
  21. var sessionsEnabled: Bool? {
  22. let session_enabled = plistValueForConfig(configName: LocalOverrideSettings
  23. .PlistKey_sessions_enabled) as? Bool
  24. if session_enabled != nil {
  25. return Bool(session_enabled!)
  26. }
  27. return nil
  28. }
  29. var sessionTimeout: TimeInterval? {
  30. let timeout = plistValueForConfig(configName: LocalOverrideSettings
  31. .PlistKey_sessions_timeout) as? String
  32. if timeout != nil {
  33. return Double(timeout!)
  34. }
  35. return nil
  36. }
  37. var samplingRate: Double? {
  38. let rate = plistValueForConfig(configName: LocalOverrideSettings
  39. .PlistKey_sessions_samplingRate) as? String
  40. if rate != nil {
  41. return Double(rate!)
  42. }
  43. return nil
  44. }
  45. private func plistValueForConfig(configName: String) -> Any? {
  46. return Bundle.main.infoDictionary?[configName]
  47. }
  48. }
  49. typealias LocalOverrideSettingsProvider = LocalOverrideSettings
  50. extension LocalOverrideSettingsProvider {
  51. func updateSettings() {
  52. // Nothing to be done since there is nothing to be updated.
  53. }
  54. func isSettingsStale() -> Bool {
  55. // Settings are never stale since all of these are local settings from Plist
  56. return false
  57. }
  58. }