Skip to content

feat(braze): add support for platform-specific app keys#45

Closed
1abhishekpandey wants to merge 11 commits intomasterfrom
feature/sdk-4141-android-add-support-for-the-braze-multi-app-key-support
Closed

feat(braze): add support for platform-specific app keys#45
1abhishekpandey wants to merge 11 commits intomasterfrom
feature/sdk-4141-android-add-support-for-the-braze-multi-app-key-support

Conversation

@1abhishekpandey
Copy link
Contributor

@1abhishekpandey 1abhishekpandey commented Nov 3, 2025

Description

This PR adds support for platform-specific app key configuration in the Braze integration, enabling multi-platform app key management. When usePlatformSpecificApiKeys is enabled, the integration will prioritise the new androidAppKey configuration field over the legacy appKey field. The implementation maintains full backward compatibility by falling back to the existing appKey when the feature is not enabled or platform-specific keys are not configured.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Approach

The implementation introduces two new configuration fields:

  • androidAppKey: Platform-specific app key for Android
  • usePlatformSpecificApiKeys: UI toggle to enable platform-specific key resolution

When the UI toggle is enabled and androidAppKey is present, the integration will prioritize it over the legacy appKey field. If the feature is disabled or the platform-specific key is not configured, the integration falls back to the existing appKey field, ensuring full backward compatibility.

The legacy appKey field has been marked as deprecated with proper documentation to guide future migrations. (Note: This is an internal field used in the SDK).

Impact

  • Backward Compatibility: Fully maintained - existing configurations using appKey continue to work without changes
  • Breaking Changes: None
  • New Dependencies: None
  • Configuration Changes: Two new optional fields in destination configuration

Add support for androidAppKey configuration option to enable
multi-platform app key management. When usePlatformSpecificKeys
is enabled, the SDK will prioritize androidAppKey over the
deprecated appKey field for Android-specific configurations.

This change maintains backward compatibility by falling back to
the existing appKey field when platform-specific keys are not
configured or the feature flag is disabled.

🔒 Scanned for secrets using gitleaks 8.28.0
@1abhishekpandey 1abhishekpandey self-assigned this Nov 3, 2025
@1abhishekpandey 1abhishekpandey marked this pull request as draft November 3, 2025 13:04
Update API_KEY deprecation annotation to include required
metadata for Java 9+ compatibility. Set forRemoval to false
to explicitly indicate the field will be maintained for
backward compatibility indefinitely.

Resolves SonarQube issue java:S6355 requiring deprecation
metadata for proper API evolution tracking.

🔒 Scanned for secrets using gitleaks 8.28.0
…droid-add-support-for-the-braze-multi-app-key-support

🔒 Scanned for secrets using gitleaks 8.28.0
🔒 Scanned for secrets using gitleaks 8.28.0
@1abhishekpandey 1abhishekpandey marked this pull request as ready for review November 3, 2025 14:02
…y is empty

🔒 Scanned for secrets using gitleaks 8.28.0
Comment on lines +112 to +114
/**
* @deprecated Use {@link #ANDROID_APP_KEY} instead. This field is kept for backward compatibility.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this deprecation notice? It's not for public consumption.

Moreover, not all destinations must have opted for the new API keys. So, this is still a valid field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My main motive was to highlight which key should be preferred by the future maintainers. By marking it as deprecated, we ensure the new platform-specific key would be highlighted. I've also clearly highlighted that this is not going to be removed by setting forRemoval to false (in @Deprecated(since = "2.1.0", forRemoval = false) annotation).

Moreover, not all destinations must have opted for the new API keys. So, this is still a valid field.

I fully agree with this. We ensure full backward compatibility.

Need your final confirmation to understand if it would be better to remove this deprecation annotation!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not mark it as deprecated. You can add comments in the code to clarify the intention.

*/
@Deprecated(since = "2.1.0", forRemoval = false)
private static final String API_KEY = "appKey";
private static final String USE_PLATFORM_SPECIFIC_KEYS = "usePlatformSpecificKeys";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's fix this in the config too.

Suggested change
private static final String USE_PLATFORM_SPECIFIC_KEYS = "usePlatformSpecificKeys";
private static final String USE_PLATFORM_SPECIFIC_API_KEYS = "usePlatformSpecificApiKeys";

🔒 Scanned for secrets using gitleaks 8.28.0
🔒 Scanned for secrets using gitleaks 8.28.0
🔒 Scanned for secrets using gitleaks 8.28.0
🔒 Scanned for secrets using gitleaks 8.28.0
// Fallback to default app key if either platform-specific key is not present or is set to false
if (TextUtils.isEmpty(apiKey) && destinationConfig.containsKey(API_KEY)) {
if (getBoolean(destinationConfig.get(USE_PLATFORM_SPECIFIC_API_KEYS))) {
RudderLogger.logWarn("BrazeIntegration: usePlatformSpecificApiKeys is enabled but androidApiKey is not configured. Falling back to legacy apiKey.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also include the Android API key in the message.

Suggested change
RudderLogger.logWarn("BrazeIntegration: usePlatformSpecificApiKeys is enabled but androidApiKey is not configured. Falling back to legacy apiKey.");
RudderLogger.logWarn("BrazeIntegration: Configured to use platform-specific API keys but Android API key is not valid. Falling back to the default API key.");

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
RudderLogger.logError("Invalid API key. Aborting Braze initialization.");

Comment on lines 172 to 183
// Prefer platform-specific key if present and not empty
if (getBoolean(destinationConfig.get(USE_PLATFORM_SPECIFIC_API_KEYS))
&& destinationConfig.containsKey(ANDROID_API_KEY)) {
apiKey = (String) destinationConfig.get(ANDROID_API_KEY);
}
// Fallback to default app key if either platform-specific key is not present or is set to false
if (TextUtils.isEmpty(apiKey) && destinationConfig.containsKey(API_KEY)) {
if (getBoolean(destinationConfig.get(USE_PLATFORM_SPECIFIC_API_KEYS))) {
RudderLogger.logWarn("BrazeIntegration: usePlatformSpecificApiKeys is enabled but androidApiKey is not configured. Falling back to legacy apiKey.");
}
apiKey = (String) destinationConfig.get(API_KEY);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@1abhishekpandey can we make it simple?

Suggested change
// Prefer platform-specific key if present and not empty
if (getBoolean(destinationConfig.get(USE_PLATFORM_SPECIFIC_API_KEYS))
&& destinationConfig.containsKey(ANDROID_API_KEY)) {
apiKey = (String) destinationConfig.get(ANDROID_API_KEY);
}
// Fallback to default app key if either platform-specific key is not present or is set to false
if (TextUtils.isEmpty(apiKey) && destinationConfig.containsKey(API_KEY)) {
if (getBoolean(destinationConfig.get(USE_PLATFORM_SPECIFIC_API_KEYS))) {
RudderLogger.logWarn("BrazeIntegration: usePlatformSpecificApiKeys is enabled but androidApiKey is not configured. Falling back to legacy apiKey.");
}
apiKey = (String) destinationConfig.get(API_KEY);
}
apiKey = defaultApiKey
if (usePlatformSpecificApiKeys) {
if (android api key is valid) {
apiKey = androidApiKey
} else {
log a warning and use default
}
}
if (apiKey is invalid) {
log an eeror
}

🔒 Scanned for secrets using gitleaks 8.28.0
🔒 Scanned for secrets using gitleaks 8.28.0
@sonarqubecloud
Copy link

@1abhishekpandey 1abhishekpandey deleted the feature/sdk-4141-android-add-support-for-the-braze-multi-app-key-support branch December 8, 2025 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants