add in projected permissions and hardware access snippets#821
add in projected permissions and hardware access snippets#821trambui09 wants to merge 2 commits intoandroid:mainfrom
Conversation
|
Here is the summary of changes. You are about to add 7 region tags.
This comment is generated by snippet-bot.
|
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 enhances the XR projected samples by incorporating robust permission handling for projected devices and showcasing advanced hardware access capabilities. It enables applications running on projected devices, such as AI glasses, to request and manage camera permissions, and demonstrates how to capture high-fidelity images using CameraX with fine-grained control over resolution and frame rates, bridging the gap between projected and host device interactions. 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 adds code snippets for handling projected permissions and accessing hardware like the camera in an XR context. The changes include updating dependencies, modifying GlassesMainActivity to handle camera permissions, and adding a new ProjectedHardware.kt file with example functions. My review focuses on improving the robustness and maintainability of the new code. I've suggested consolidating dependency versions, adding better error handling for context creation and permission requests, and cleaning up some minor code style issues.
| // Permission granted, initialize the session/features. | ||
| initializeGlassesFeatures() | ||
| } else { | ||
| // Handle permission denial. |
There was a problem hiding this comment.
gradle/libs.versions.toml
Outdated
| androidx-camera-lifecycle = { group = "androidx.camera", name = "camera-lifecycle", version.ref = "cameraLifecycle" } | ||
| androidx-camera-camera2 = { group = "androidx.camera", name = "camera-camera2", version.ref = "cameraCamera2" } |
There was a problem hiding this comment.
To align with the practice of using a consolidated version for the CameraX library group, please update these library definitions to reference the cameraX version variable.
| androidx-camera-lifecycle = { group = "androidx.camera", name = "camera-lifecycle", version.ref = "cameraLifecycle" } | |
| androidx-camera-camera2 = { group = "androidx.camera", name = "camera-camera2", version.ref = "cameraCamera2" } | |
| androidx-camera-lifecycle = { group = "androidx.camera", name = "camera-lifecycle", version.ref = "cameraX" } | |
| androidx-camera-camera2 = { group = "androidx.camera", name = "camera-camera2", version.ref = "cameraX" } |
| val cameraCharacteristics = camera2CameraInfo.getCameraCharacteristic( | ||
| CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP | ||
| ) |
| // [START androidxr_projected_permissions_launcher] | ||
| // Register the permissions launcher using the ProjectedPermissionsResultContract. | ||
| private val requestPermissionLauncher: ActivityResultLauncher<List<ProjectedPermissionsRequestParams>> = | ||
| registerForActivityResult(ProjectedPermissionsResultContract()) { results -> |
There was a problem hiding this comment.
Should we use rememberLauncherForActivityResult() instead?
https://developer.android.com/develop/ui/compose/libraries#requesting-runtime-permissions
There was a problem hiding this comment.
I think rememberLauncherForActivityResult cannot be used in onCreate; it can only be used inside a @composable function. The registerForActivityResult ensures the launcher is registered before the Activity starts.
| // 1. Get the CameraProvider using the projected context. | ||
| // When using the projected context, DEFAULT_BACK_CAMERA maps to the AI glasses' camera. | ||
| val projectedContext = ProjectedContext.createProjectedDeviceContext(activity) | ||
| val cameraProviderFuture = ProcessCameraProvider.getInstance(projectedContext) |
There was a problem hiding this comment.
Just wanted to make sure we're handling the null case in the code here.
If projectedContext is null, will this always return a non-null object? could cameraProviderFuture be null?
There was a problem hiding this comment.
createProjectedDeviceContext() throws an IllegalStateException if the projected device isn't found. I'll edit the snippets to catch this. I don't think cameraProviderFuture can be null.
Projected Snippets:
Created ProjectedHardware.kt covering: