LocalOverrideSettings.swift 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 {
  18. // This will disable Sessions SDK Events, but not Settings requests.
  19. // If any apps use this flag to disable the Firebase Sessions SDK,
  20. // keep in mind this may break metrics future features with products like
  21. // FirePerf and Crashlytics. As a result, we would recommend apps
  22. // use another way to disable data collection (like disabling it via
  23. // the product public data collection APIs themselves).
  24. // This flag is internal and may break in the future.
  25. static let PlistKey_sessions_enabled = "FirebaseSessionsEnabled"
  26. static let PlistKey_sessions_timeout = "FirebaseSessionsTimeout"
  27. static let PlistKey_sessions_samplingRate = "FirebaseSessionsSampingRate"
  28. var sessionsEnabled: Bool? {
  29. let session_enabled = plistValueForConfig(configName: LocalOverrideSettings
  30. .PlistKey_sessions_enabled) as? Bool
  31. if session_enabled != nil {
  32. return Bool(session_enabled!)
  33. }
  34. return nil
  35. }
  36. var sessionTimeout: TimeInterval? {
  37. let timeout = plistValueForConfig(configName: LocalOverrideSettings
  38. .PlistKey_sessions_timeout) as? Double
  39. if timeout != nil {
  40. return Double(timeout!)
  41. }
  42. return nil
  43. }
  44. var samplingRate: Double? {
  45. let rate = plistValueForConfig(configName: LocalOverrideSettings
  46. .PlistKey_sessions_samplingRate) as? Double
  47. if rate != nil {
  48. return Double(rate!)
  49. }
  50. return nil
  51. }
  52. private func plistValueForConfig(configName: String) -> Any? {
  53. return Bundle.main.infoDictionary?[configName]
  54. }
  55. }
  56. typealias LocalOverrideSettingsProvider = LocalOverrideSettings
  57. extension LocalOverrideSettingsProvider {
  58. func updateSettings() {
  59. // Nothing to be done since there is nothing to be updated.
  60. }
  61. func isSettingsStale() -> Bool {
  62. // Settings are never stale since all of these are local settings from Plist
  63. return false
  64. }
  65. }