Exemple #1
0
    private static DialogFeatureConfig parseDialogConfig(JSONObject dialogConfigJSON) {
      String dialogNameWithFeature = dialogConfigJSON.optString(DIALOG_CONFIG_NAME_KEY);
      if (Utility.isNullOrEmpty(dialogNameWithFeature)) {
        return null;
      }

      String[] components =
          dialogNameWithFeature.split(DIALOG_CONFIG_DIALOG_NAME_FEATURE_NAME_SEPARATOR);
      if (components.length != 2) {
        // We expect the format to be dialogName|FeatureName, where both components are
        // non-empty.
        return null;
      }

      String dialogName = components[0];
      String featureName = components[1];
      if (isNullOrEmpty(dialogName) || isNullOrEmpty(featureName)) {
        return null;
      }

      String urlString = dialogConfigJSON.optString(DIALOG_CONFIG_URL_KEY);
      Uri fallbackUri = null;
      if (!Utility.isNullOrEmpty(urlString)) {
        fallbackUri = Uri.parse(urlString);
      }

      JSONArray versionsJSON = dialogConfigJSON.optJSONArray(DIALOG_CONFIG_VERSIONS_KEY);

      int[] featureVersionSpec = parseVersionSpec(versionsJSON);

      return new DialogFeatureConfig(dialogName, featureName, fallbackUri, featureVersionSpec);
    }
  public static Intent createProxyAuthIntent(
      Context context,
      String applicationId,
      List<String> permissions,
      String e2e,
      boolean isRerequest,
      SessionDefaultAudience defaultAudience) {
    for (NativeAppInfo appInfo : facebookAppInfoList) {
      Intent intent =
          new Intent()
              .setClassName(appInfo.getPackage(), FACEBOOK_PROXY_AUTH_ACTIVITY)
              .putExtra(FACEBOOK_PROXY_AUTH_APP_ID_KEY, applicationId);

      if (!Utility.isNullOrEmpty(permissions)) {
        intent.putExtra(FACEBOOK_PROXY_AUTH_PERMISSIONS_KEY, TextUtils.join(",", permissions));
      }
      if (!Utility.isNullOrEmpty(e2e)) {
        intent.putExtra(FACEBOOK_PROXY_AUTH_E2E_KEY, e2e);
      }

      intent.putExtra(
          ServerProtocol.DIALOG_PARAM_RESPONSE_TYPE, ServerProtocol.DIALOG_RESPONSE_TYPE_TOKEN);
      intent.putExtra(
          ServerProtocol.DIALOG_PARAM_RETURN_SCOPES, ServerProtocol.DIALOG_RETURN_SCOPES_TRUE);
      intent.putExtra(
          ServerProtocol.DIALOG_PARAM_DEFAULT_AUDIENCE,
          defaultAudience.getNativeProtocolAudience());

      if (!Settings.getPlatformCompatibilityEnabled()) {
        // Override the API Version for Auth
        intent.putExtra(
            ServerProtocol.DIALOG_PARAM_LEGACY_OVERRIDE, ServerProtocol.GRAPH_API_VERSION);

        // Only set the rerequest auth type for non legacy requests
        if (isRerequest) {
          intent.putExtra(
              ServerProtocol.DIALOG_PARAM_AUTH_TYPE, ServerProtocol.DIALOG_REREQUEST_AUTH_TYPE);
        }
      }

      intent = validateActivityIntent(context, intent, appInfo);

      if (intent != null) {
        return intent;
      }
    }
    return null;
  }
Exemple #3
0
  public static DialogFeatureConfig getDialogFeatureConfig(
      String applicationId, String actionName, String featureName) {
    if (Utility.isNullOrEmpty(actionName) || Utility.isNullOrEmpty(featureName)) {
      return null;
    }

    FetchedAppSettings settings = fetchedAppSettings.get(applicationId);
    if (settings != null) {
      Map<String, DialogFeatureConfig> featureMap =
          settings.getDialogConfigurations().get(actionName);
      if (featureMap != null) {
        return featureMap.get(featureName);
      }
    }
    return null;
  }
Exemple #4
0
  public static void loadAppSettingsAsync(final Context context, final String applicationId) {
    boolean canStartLoading = loadingSettings.compareAndSet(false, true);
    if (Utility.isNullOrEmpty(applicationId)
        || fetchedAppSettings.containsKey(applicationId)
        || !canStartLoading) {
      return;
    }

    final String settingsKey = String.format(APP_SETTINGS_PREFS_KEY_FORMAT, applicationId);

    FacebookSdk.getExecutor()
        .execute(
            new Runnable() {
              @Override
              public void run() {
                JSONObject resultJSON = getAppSettingsQueryResponse(applicationId);
                if (resultJSON != null) {
                  parseAppSettingsFromJSON(applicationId, resultJSON);

                  SharedPreferences sharedPrefs =
                      context.getSharedPreferences(APP_SETTINGS_PREFS_STORE, Context.MODE_PRIVATE);
                  sharedPrefs.edit().putString(settingsKey, resultJSON.toString()).apply();
                }

                loadingSettings.set(false);
              }
            });

    // Also see if we had a cached copy and use that immediately.
    SharedPreferences sharedPrefs =
        context.getSharedPreferences(APP_SETTINGS_PREFS_STORE, Context.MODE_PRIVATE);
    String settingsJSONString = sharedPrefs.getString(settingsKey, null);
    if (!isNullOrEmpty(settingsJSONString)) {
      JSONObject settingsJSON = null;
      try {
        settingsJSON = new JSONObject(settingsJSONString);
      } catch (JSONException je) {
        logd(LOG_TAG, je);
      }
      if (settingsJSON != null) {
        parseAppSettingsFromJSON(applicationId, settingsJSON);
      }
    }
  }
Exemple #5
0
 public static void putNonEmptyString(Bundle b, String key, String value) {
   if (!Utility.isNullOrEmpty(value)) {
     b.putString(key, value);
   }
 }