FIRIAMSDKModeManager.h 2.8 KB

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