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;
  }
    public boolean validateSignature(Context context, String packageName) {
      String brand = Build.BRAND;
      int applicationFlags = context.getApplicationInfo().flags;
      if (brand.startsWith("generic")
          && (applicationFlags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
        // We are debugging on an emulator, don't validate package signature.
        return true;
      }

      PackageInfo packageInfo = null;
      try {
        packageInfo =
            context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
      } catch (PackageManager.NameNotFoundException e) {
        return false;
      }

      for (Signature signature : packageInfo.signatures) {
        String hashedSignature = Utility.sha1hash(signature.toByteArray());
        if (validAppSignatureHashes.contains(hashedSignature)) {
          return true;
        }
      }

      return false;
    }
  public static Intent createPlatformActivityIntent(
      Context context,
      String callId,
      String action,
      int version,
      String applicationName,
      Bundle extras) {
    Intent intent = findActivityIntent(context, INTENT_ACTION_PLATFORM_ACTIVITY, action);
    if (intent == null) {
      return null;
    }

    String applicationId = Utility.getMetadataApplicationId(context);

    intent
        .putExtra(EXTRA_PROTOCOL_VERSION, version)
        .putExtra(EXTRA_PROTOCOL_ACTION, action)
        .putExtra(EXTRA_APPLICATION_ID, applicationId);

    if (isVersionCompatibleWithBucketedIntent(version)) {
      // This is a bucketed intent
      Bundle bridgeArguments = new Bundle();
      bridgeArguments.putString(BRIDGE_ARG_ACTION_ID_STRING, callId);
      bridgeArguments.putString(BRIDGE_ARG_APP_NAME_STRING, applicationName);
      intent.putExtra(EXTRA_PROTOCOL_BRIDGE_ARGS, bridgeArguments);

      Bundle methodArguments = (extras == null) ? new Bundle() : extras;
      intent.putExtra(EXTRA_PROTOCOL_METHOD_ARGS, methodArguments);
    } else {
      // This is the older flat intent
      intent.putExtra(EXTRA_PROTOCOL_CALL_ID, callId);
      intent.putExtra(EXTRA_APPLICATION_NAME, applicationName);
      intent.putExtras(extras);
    }

    return intent;
  }