Obsolete
Status Update
Comments
ad...@google.com <ad...@google.com>
ad...@google.com <ad...@google.com> #2
Thank you for reporting this issue. For us to further investigate this issue, please provide the following additional information:
Please provide sample project to reproduce the issue. Also mention the steps to be followed for reproducing the issue with the given sample project.
NOTE : To avoid leaking private information, please share screenshots and bugreports only in Google Drive. Share files with android-bugreport@google.com and include only Google drive links in your bug. Bug report attachments should not be included directly in issue reports.
Please provide sample project to reproduce the issue. Also mention the steps to be followed for reproducing the issue with the given sample project.
NOTE : To avoid leaking private information, please share screenshots and bugreports only in Google Drive. Share files with android-bugreport@google.com and include only Google drive links in your bug. Bug report attachments should not be included directly in issue reports.
he...@gmail.com <he...@gmail.com> #3
I changed the test case code, it is all information you need:
@Test
fun onlyFailedOnAndroidQ() {
val app = ApplicationProvider.getApplicationContext<Application>()
val file = File(app.filesDir, "test.txt")
val uri = Uri.fromFile(file)
file.writeText("alpha beta")
assertEquals("alpha beta", file.readText())
app.contentResolver.openFileDescriptor(uri, "w").use { pfd ->
if (pfd == null) throw IOException("Unable to access file")
FileOutputStream(pfd.fileDescriptor).use { stream ->
stream.write("hello".toByteArray())
}
}
assertEquals("hello", file.readText())
}
@Test
fun onlyFailedOnAndroidQ() {
val app = ApplicationProvider.getApplicationContext<Application>()
val file = File(app.filesDir, "test.txt")
val uri = Uri.fromFile(file)
file.writeText("alpha beta")
assertEquals("alpha beta", file.readText())
app.contentResolver.openFileDescriptor(uri, "w").use { pfd ->
if (pfd == null) throw IOException("Unable to access file")
FileOutputStream(pfd.fileDescriptor).use { stream ->
stream.write("hello".toByteArray())
}
}
assertEquals("hello", file.readText())
}
ad...@google.com <ad...@google.com> #4
We have passed this to the development team and will update this issue with more information as it becomes available.
ad...@google.com <ad...@google.com> #5
If you want to truncate the file, you need to pass the "t" open mode, so something like "rwt".
he...@gmail.com <he...@gmail.com> #6
Thanks for the tip, use "rwt" mode is working as I expected.
But still, this behavior is different from previous Android system. this can cause compatibility issues.
At least for targetSdkVersion < 29 apps should maintain the previous behavior.
But still, this behavior is different from previous Android system. this can cause compatibility issues.
At least for targetSdkVersion < 29 apps should maintain the previous behavior.
he...@gmail.com <he...@gmail.com> #7
Should also mention this in the Android Q behavior change documentation.
ar...@google.com <ar...@google.com> #8
We've deferred this issue for consideration in a future release. Thank you for your time to make Android better. In case you want to provide more information with respect to this bug, please file a bug in AOSP via "https://goo.gl/TbMiIO
ad...@google.com <ad...@google.com> #9
Thank you for your feedback. We assure you we are doing our best to address the issues reported, however our product team has shifted work to higher priority bugs and may not be able to handle this bug. As for now, we will be closing the bug as won’t fix obsolete.
If you are still facing the issue recently, we request that you log a new bug along with the bug report herehttps://goo.gl/TbMiIO
If you are still facing the issue recently, we request that you log a new bug along with the bug report here
Description
for example there has a text file content is "alpha beta", by use context.contentResolver.openFileDescriptor to save text "hello" to this file, the file content has become "hello beta", but it should be "hello".
test case:
@Test
fun failedOnQ() {
val app = ApplicationProvider.getApplicationContext<Application>()
val file = File(app.filesDir, "test.txt")
val uri = Uri.fromFile(file)
TextFileHelp.save(file, "alpha beta")
assertEquals("alpha beta", TextFileHelp.open(file))
app.contentResolver.openFileDescriptor(uri, "rw").use { pfd ->
FileOutputStream(pfd!!.fileDescriptor).use { stream ->
TextFileHelp.save(stream, "hello")
}
}
assertEquals("hello", TextFileHelp.open(file)) // actual is "hello beta"
}