Align BODY_SENSORS permission request with API 36 migration guidelines#344
Align BODY_SENSORS permission request with API 36 migration guidelines#344ithinkihaveacat wants to merge 1 commit intoandroid:mainfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refines the application's permission request mechanism to ensure compatibility with the latest Android API guidelines, specifically for Wear OS 6 (API 36). By adjusting when the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly aligns the BODY_SENSORS permission request with Android's API 36 migration guidelines by conditionally requesting it only on API levels 35 and below. The change is correct and addresses the issue described. I have one suggestion to improve code readability and maintainability.
| if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.VANILLA_ICE_CREAM) { | ||
| add(Manifest.permission.BODY_SENSORS) | ||
| } |
There was a problem hiding this comment.
For improved readability and to make the code more self-documenting, consider extracting Build.VERSION_CODES.VANILLA_ICE_CREAM into a named constant. This makes the reason for this specific API level check more explicit, as it relates to the maxSdkVersion for the BODY_SENSORS permission in your manifest.
For example, you could define a constant in the companion object and use it in the check:
private const val MAX_BODY_SENSORS_SDK = Build.VERSION_CODES.VANILLA_ICE_CREAM
// ... inside buildList
if (Build.VERSION.SDK_INT <= MAX_BODY_SENSORS_SDK) {
add(Manifest.permission.BODY_SENSORS)
}|
Hello @ithinkihaveacat, It looks like this PR covers the same ground as my earlier PR #342 from January. I’d love to learn if there's anything missing or incorrect in my implementation compared to this one. Could you please review my PR? |
Motivation
This PR updates the permission request logic to align with Wear OS 6 (API level 36) migration guidelines.
The
AndroidManifest.xmlcorrectly restricts the legacyBODY_SENSORSpermission tomaxSdkVersion="35". However, the runtime permission array inPreparingViewModel.ktwas requestingBODY_SENSORSon all API levels.While the Android system gracefully ignores invalid permission requests and still allows the exercise to proceed, requesting a permission that is explicitly restricted in the manifest is incorrect hygiene. It causes the
ActivityResultLauncherto return afalseresult for that specific permission on API 36+, which could break future logic that strictly validates the success of the permission request array.This PR updates
PreparingViewModel.ktto only requestManifest.permission.BODY_SENSORSon API levels 35 and below, ensuring the runtime request matches the manifest declaration.How to test
Verifying the fix
On API 36+ (Android 16+):
ExerciseSampleComposeapp on an Android 16 (API 36) emulator or device.READ_HEART_RATE) but no longer attempts to request the legacyBODY_SENSORSpermission.(Note: Ensure device-level Location is toggled ON in the system settings, otherwise the
DataType.LOCATIONrequest will fail).On API <= 35 (Android 15 and below):
BODY_SENSORSpermission is still requested as expected for backward compatibility.