FIRIAMSDKModeManager.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright 2018 Google
  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. */
  16. #import <Foundation/Foundation.h>
  17. NS_ASSUME_NONNULL_BEGIN
  18. extern NSInteger const kFIRIAMMaxFetchInNewlyInstalledMode;
  19. /**
  20. * At runtime a FIAM SDK client can function in one of the following modes:
  21. * 1 Regular. This SDK client instance will conform to regular fetch minimal interval time policy.
  22. * 2 Newly installed. This is a mode a newly installed SDK stays in until the first
  23. * kFIRIAMMaxFetchInNewlyInstalledMode fetches have finished. In this mode, there is no
  24. * minimal time interval between fetches: a fetch would be triggered as long as the app goes
  25. * into foreground state.
  26. * 3 Testing Instance. This app instance is targeted for test on device feature for fiam. When
  27. * it's in this mode, no minimal time interval between fetches is applied. SDK turns itself
  28. * into this mode on seeing test-on-client messages are returned in fetch responses.
  29. */
  30. typedef NS_ENUM(NSInteger, FIRIAMSDKMode) {
  31. FIRIAMSDKModeRegular,
  32. FIRIAMSDKModeTesting,
  33. FIRIAMSDKModeNewlyInstalled
  34. };
  35. // turn the sdk mode enum integer value into a descriptive string
  36. NSString *FIRIAMDescriptonStringForSDKMode(FIRIAMSDKMode mode);
  37. extern NSString *const kFIRIAMUserDefaultKeyForSDKMode;
  38. extern NSString *const kFIRIAMUserDefaultKeyForServerFetchCount;
  39. extern NSInteger const kFIRIAMMaxFetchInNewlyInstalledMode;
  40. @protocol FIRIAMTestingModeListener <NSObject>
  41. // Triggered when the current app switches into testing mode from a using testing mode
  42. - (void)testingModeSwitchedOn;
  43. @end
  44. // A class for tracking and updating the SDK mode. The tracked mode related info is persisted
  45. // so that it can be restored beyond app restarts
  46. @interface FIRIAMSDKModeManager : NSObject
  47. - (instancetype)init NS_UNAVAILABLE;
  48. // having NSUserDefaults as passed-in to help with unit testing
  49. - (instancetype)initWithUserDefaults:(NSUserDefaults *)userDefaults
  50. testingModeListener:(id<FIRIAMTestingModeListener>)testingModeListener;
  51. // returns the current SDK mode
  52. - (FIRIAMSDKMode)currentMode;
  53. // turn the current SDK into 'Testing Instance' mode.
  54. - (void)becomeTestingInstance;
  55. // inform the manager that one more fetch is done. This is to allow
  56. // the manager to potentially graduate from the newly installed mode.
  57. - (void)registerOneMoreFetch;
  58. @end
  59. NS_ASSUME_NONNULL_END