OneSignal-Android-SDK icon indicating copy to clipboard operation
OneSignal-Android-SDK copied to clipboard

Fix IAM display rendering issues on foldable Android devices (Samsung Galaxy Fold/Flip)

Open abdulraqeeb33 opened this issue 8 months ago • 0 comments

Description

One Line Summary

Fix In-App Message (IAM) display rendering issues on foldable Android devices, gated behind a remote feature flag.

Details

Motivation

Foldable Android devices like Samsung Galaxy Fold and Flip experience IAM rendering issues when users fold/unfold their devices. The IAM content may appear cut-off, mispositioned, or incorrectly sized because:

  1. Screen size changes without orientation change: When a foldable device transitions between its cover screen and main screen (or vice versa), the screen dimensions change dramatically without triggering an orientation change event.

  2. Deprecated APIs: The SDK was using deprecated defaultDisplay.getSize() APIs that don't properly handle multi-window and foldable device scenarios on Android 11+.

  3. Missing configuration detection: The SDK only listened for CONFIG_ORIENTATION changes, missing the CONFIG_SCREEN_SIZE changes that foldable devices trigger.

Feature Flag Implementation

All changes are gated behind a remote feature flag: SDK_050800_FOLDABLE_IAM_FIX

  • When OFF (default): Legacy behavior is used - no changes to existing functionality
  • When ON: New foldable-aware behavior is activated:
    • Uses WindowMetrics API for accurate window dimensions on API 30+
    • Detects screen size changes from fold/unfold events
    • Recalculates IAM dimensions when screen size changes

This allows for safe rollout and easy rollback if issues are discovered.

Scope

What is affected:

  • In-App Message display on foldable devices (Samsung Galaxy Fold, Flip, and similar devices)
  • Window dimension calculations on Android 11+ (API 30+)

What is NOT affected:

  • IAM behavior when feature flag is disabled (default)
  • IAM behavior on non-foldable devices when flag is enabled (no functional change expected)
  • Other SDK features (notifications, outcomes, sessions, etc.)

Technical Changes

  1. FoldableIAMFeature.kt (NEW):

    • Global feature switch object similar to ThreadingMode
    • isEnabled property controlled by FeatureManager
    • Provides centralized access to feature state from static utilities
  2. FeatureFlag.kt:

    • Added SDK_050800_FOLDABLE_IAM_FIX feature flag
    • Uses IMMEDIATE activation mode for instant toggling
  3. FeatureManager.kt:

    • Added side effect handler for the new feature flag
    • Updates FoldableIAMFeature.isEnabled when flag changes
  4. ViewUtils.kt:

    • getWindowHeight(): Uses WindowMetrics API (API 30+) when FF enabled
    • getWindowWidth(): Uses WindowMetrics API (API 30+) when FF enabled
    • getFullbleedWindowWidth(): Uses WindowMetrics API (API 30+) when FF enabled
    • Falls back to legacy behavior when FF disabled
  5. ApplicationService.kt:

    • Screen size change detection only runs when FF enabled
    • Detects fold/unfold via screenWidthDp/screenHeightDp changes
    • Triggers IAM view recreation on screen size change
  6. WebViewManager.kt:

    • Updated comment to clarify fold/unfold handling alongside rotation

Testing

Unit testing

  • Existing ApplicationServiceTests pass
  • Existing FeatureManagerTests pass
  • The feature flag integration follows the same pattern as SDK_050800_BACKGROUND_THREADING

Manual testing

Recommended testing scenarios:

  1. With flag OFF: Verify no change in behavior on any device
  2. With flag ON on foldable device: Display an IAM, then fold/unfold - IAM should resize correctly
  3. With flag ON on non-foldable device: Verify no regression
  4. Test all IAM positions (TOP_BANNER, BOTTOM_BANNER, CENTER_MODAL, FULL_SCREEN) during fold/unfold

Affected code checklist

  • [ ] Notifications
    • [ ] Display
    • [ ] Open
    • [ ] Push Processing
    • [ ] Confirm Deliveries
  • [ ] Outcomes
  • [ ] Sessions
  • [x] In-App Messaging
  • [ ] REST API requests
  • [ ] Public API changes

Checklist

Overview

  • [x] I have filled out all REQUIRED sections above
  • [x] PR does one thing
  • [x] Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • [x] I have included test coverage for these changes, or explained why they are not needed
  • [x] All automated tests pass, or I explained why that is not possible
  • [ ] I have personally tested this on my device, or explained why that is not possible

Final pass

  • [x] Code is as readable as possible.
  • [x] I have reviewed this PR myself, ensuring it meets each checklist item
Open in Web Open in Cursor 

abdulraqeeb33 avatar Mar 26 '26 16:03 abdulraqeeb33