-
Notifications
You must be signed in to change notification settings - Fork 1
fix(#98): initial device computation breaking sensor usages #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(#98): initial device computation breaking sensor usages #100
Conversation
|
Warning Rate limit exceeded@gladiuscode has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 25 minutes and 39 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
WalkthroughEnables orientation sensors earlier and refines lifecycle handling in OrientationDirectorModuleImpl: conditional sensor re-enable on resume, guarded sensor disable on pause/destroy during initial-orientation computation, unconditional AutoRotationObserver toggles on resume/pause/destroy, and broadcast receiver registration/unregistration adjusted; init notes added. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Host
participant OrientationSensors
participant AutoRotationObserver
participant BroadcastReceiver
Host->>OrientationSensors: enable early during init (NOTE(1.init))
Host->>AutoRotationObserver: (init) configure (not necessarily enabled)
Host->>BroadcastReceiver: register on resume
alt hostResume
Host->>OrientationSensors: if (sensorsEnabled || !initialComputed) enable
Host->>AutoRotationObserver: enable (unconditional)
Host->>BroadcastReceiver: register
end
alt hostPause or hostDestroy
Host->>OrientationSensors: if (sensorsEnabled || !initialComputed) disable (guard: not in-use && initialComputed)
Host->>AutoRotationObserver: disable (unconditional)
Host->>BroadcastReceiver: unregister
end
note over OrientationSensors: onOrientationAnglesChanged applies initial-computation guard\nand avoids disabling while "in use"
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
♻️ Duplicate comments (1)
android/src/main/java/com/orientationdirector/implementation/OrientationDirectorModuleImpl.kt (1)
51-54: Same observer lifecycle issue as noted in the resume callback.See previous comment regarding decoupling
AutoRotationObserverfrom theareOrientationSensorsEnabledflag.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
android/src/main/java/com/orientationdirector/implementation/OrientationDirectorModuleImpl.kt(2 hunks)
🔇 Additional comments (2)
android/src/main/java/com/orientationdirector/implementation/OrientationDirectorModuleImpl.kt (2)
39-40: LGTM! Enables sensors for initial device orientation computation.This correctly enables orientation sensors during initialization to ensure the initial device orientation is computed before the first user interaction. The guard at lines 171-173 will automatically disable these sensors after the first orientation reading if the user hasn't explicitly called
enableOrientationSensors().
169-174: LGTM! Guard correctly prevents premature sensor disabling.The condition
!didComputeInitialDeviceOrientation && !areOrientationSensorsEnabledcorrectly ensures sensors are only disabled after initial computation if the user hasn't explicitly enabled them viaenableOrientationSensors(). This prevents disabling sensors that should remain active.
android/src/main/java/com/orientationdirector/implementation/OrientationDirectorModuleImpl.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
android/src/main/java/com/orientationdirector/implementation/OrientationDirectorModuleImpl.kt(2 hunks)
🔇 Additional comments (2)
android/src/main/java/com/orientationdirector/implementation/OrientationDirectorModuleImpl.kt (2)
47-47: Partial fix for AutoRotationObserver lifecycle management.The PR partially addresses the past review comment by making
AutoRotationObserverlifecycle unconditional (always enabled on resume at line 47, always disabled on pause at line 54 and destroy at line 61). This prevents the resource leak whenenableOrientationSensors()is never called.However, the lifecycle management is still complex due to the three-state system (init pending, user-enabled, user-disabled). The critical race condition flagged in my previous comment must be addressed to fully resolve the initialization issues.
Based on past review comments, this change addresses the AutoRotationObserver resource leak concern.
Also applies to: 54-54, 61-61
169-174: Guard logic is correct but depends on race condition fix.The guard to disable sensors after initial computation (when
areOrientationSensorsEnabledis false) is a good optimization. The dual condition check is correct:
!didComputeInitialDeviceOrientation: ensures this only runs on the first orientation change!areOrientationSensorsEnabled: ensures sensors stay enabled if user explicitly enabled themHowever, this code may never execute if the race condition (flagged in my earlier comment) occurs. Once the race condition is fixed, this logic will work as intended.
This PR fixes #98
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.