Support apps sharing file:// URIs with the camera API
The camera API, MediaStore.ACTION_IMAGE_CAPTURE requires apps to pass a content:// URI with write permissions to the camera. Unfortunately, apps haven't been doing this and we only started hitting problems in R for two reasons: 1. The FileUriExposedException that should crash apps when they try to share file:// URIs acroos binder is skipped. This is because, the image_capture intent is passed across binder as a field in a ChooserActivity Intent and the child intents are not checked for file URI exposed 2. Prior to R, when camera gets a file:// URI, camera issues a file open(2) in its process. This open(2) succeeds because the camera had write_external_storage permission which gave it write access to all files on external storage Now, camera targets R and (2) fails because camera does not have write access to files owned by other apps. To workaround, we do the following in the apps process when it targets < R: a. When we detect a file:// URI for the camera in an Intent, we create the file on disk if it is not already created. b. Scan the file to insert it in the database and retrieve a content:// URI c. Replace the file:// URI with the content URI in the image_capture intent This works because, the system will ensure the camera is granted write access to the content URI. Test: Manual Bug: 156336269 Change-Id: I4849ff5e806a8207650ff7534846c36ecdc6d3c0
Loading
Please register or sign in to comment