Skip to content

Backport request orientation cache #757

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

Open
wants to merge 1 commit into
base: androidx-main
Choose a base branch
from

Conversation

pyricau
Copy link

@pyricau pyricau commented Feb 26, 2025

API 35 / Android 15 added a field cache to Activity.setRequestedOrientation() because every call would lead to an IPC call, which can be expensive and hammer the system.

https://cs.android.com/android/_/android/platform/frameworks/base/+/14b59e53b82dbeb93ca1c8ac612c13d62c8672e9

Proposed Changes

This change backports the API 35 behavior.

Note: I made the change in androidx.core.app.ComponentActivity as that's the top level base activity class. Let me know if you'd like me to move it somewhere else instead (or feel free to just edit).

Testing

Test: we tested this change in our own base activity class in the Square Point of Sale app.

Issues Fixed

Fixes: 265021810 (not public, I couldn't read it, but it's referenced in the Android 15 change)

@pyricau pyricau requested a review from alanv as a code owner February 26, 2025 20:01
Copy link

google-cla bot commented Feb 26, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link

Important

The terms of service for this installation has not been accepted. Please ask the Organization owners to visit the Gemini Code Assist Admin Console to sign it.

@dlam
Copy link
Member

dlam commented Feb 26, 2025

Our GH build is not in a good state, so I would ignore failures in the checks here, but just enabling it so copybara can mirror the change to Gerrit once we review

Copy link
Member

@ianhanniballake ianhanniballake left a comment

Choose a reason for hiding this comment

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

The original change also returned the lastRequestedOrientation from getRequestedOrientation. Was there a reason you didn't override that method also to returned the cached value (as that also seems to do the same binder transaction every time it is called)?

@pyricau
Copy link
Author

pyricau commented Feb 27, 2025

The original change also returned the lastRequestedOrientation from getRequestedOrientation. Was there a reason you didn't override that method also to returned the cached value (as that also seems to do the same binder transaction every time it is called)?

... I totally missed it. cs.android.com changed its diff rendering at some point, idk why but some lines aren't fully covered in color

image

@pyricau pyricau force-pushed the patch-1 branch 2 times, most recently from 3b19f16 to 704ac92 Compare February 27, 2025 23:17
@ianhanniballake ianhanniballake requested review from jbw0033 and removed request for alanv February 28, 2025 04:36
@@ -50,6 +50,8 @@ public open class ComponentActivity : Activity(), LifecycleOwner, KeyEventDispat
*/
@Suppress("LeakingThis") private val lifecycleRegistry = LifecycleRegistry(this)

private var lastRequestedOrientation: Int = ActivityInfo.SCREEN_ORIENTATION_UNSET
Copy link
Author

Choose a reason for hiding this comment

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

I need to actually backport that constant as it's hidden.

API 35 / Android 15 added a field cache to `Activity.setRequestedOrientation()` because every call would lead to an IPC call, which can be expensive and hammer the system.

This change backports the API 35 behavior.

https://cs.android.com/android/_/android/platform/frameworks/base/+/14b59e53b82dbeb93ca1c8ac612c13d62c8672e9
Copy link
Member

@ianhanniballake ianhanniballake left a comment

Choose a reason for hiding this comment

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

Looks like the formatting needs to be corrected before this can be submitted:

Execution failed for task ':core:core:ktCheck'.
> Failed check for the following files:
  $SUPPORT/core/core/src/main/java/androidx/core/app/ComponentActivity.kt

  ********************************************************************************
  You can automatically fix these issues with:
  ./gradlew :core:core:ktFormat
  ********************************************************************************

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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy