fun loadAppSettingsAsync()

in facebook-core/src/main/java/com/facebook/internal/FetchedAppSettingsManager.kt [103:165]


  fun loadAppSettingsAsync() {
    val context = FacebookSdk.getApplicationContext()
    val applicationId = FacebookSdk.getApplicationId()
    if (Utility.isNullOrEmpty(applicationId)) {
      loadingState.set(FetchAppSettingState.ERROR)
      pollCallbacks()
      return
    } else if (fetchedAppSettings.containsKey(applicationId)) {
      loadingState.set(FetchAppSettingState.SUCCESS)
      pollCallbacks()
      return
    }
    val canStartLoading =
        loadingState.compareAndSet(FetchAppSettingState.NOT_LOADED, FetchAppSettingState.LOADING) ||
            loadingState.compareAndSet(FetchAppSettingState.ERROR, FetchAppSettingState.LOADING)
    if (!canStartLoading) {
      pollCallbacks()
      return
    }
    val settingsKey = String.format(APP_SETTINGS_PREFS_KEY_FORMAT, applicationId)
    FacebookSdk.getExecutor().execute { // See if we had a cached copy and use that immediately.
      val sharedPrefs = context.getSharedPreferences(APP_SETTINGS_PREFS_STORE, Context.MODE_PRIVATE)
      val settingsJSONString = sharedPrefs.getString(settingsKey, null)
      var appSettings: FetchedAppSettings? = null
      if (!Utility.isNullOrEmpty(settingsJSONString)) {
        checkNotNull(settingsJSONString)
        var settingsJSON: JSONObject? = null
        try {
          settingsJSON = JSONObject(settingsJSONString)
        } catch (je: JSONException) {
          Utility.logd(Utility.LOG_TAG, je)
        }
        if (settingsJSON != null) {
          appSettings = parseAppSettingsFromJSON(applicationId, settingsJSON)
        }
      }
      val resultJSON = getAppSettingsQueryResponse(applicationId)
      if (resultJSON != null) {
        parseAppSettingsFromJSON(applicationId, resultJSON)
        sharedPrefs.edit().putString(settingsKey, resultJSON.toString()).apply()
      }

      // Print log to notify developers to upgrade SDK when version is too old
      if (appSettings != null) {
        val updateMessage = appSettings.sdkUpdateMessage
        if (!printedSDKUpdatedMessage && updateMessage != null && updateMessage.length > 0) {
          printedSDKUpdatedMessage = true
          Log.w(TAG, updateMessage)
        }
      }

      // Fetch GateKeepers
      queryAppGateKeepers(applicationId, true)

      // Start log activate & deactivate app events, in case autoLogAppEvents flag is set
      AutomaticAnalyticsLogger.logActivateAppEvent()

      loadingState.set(
          if (fetchedAppSettings.containsKey(applicationId)) FetchAppSettingState.SUCCESS
          else FetchAppSettingState.ERROR)
      pollCallbacks()
    }
  }