About the Environment Undeprecations

A week and a half ago, in my random musings on Android 12L, I wrote:

getExternalStorageDirectory() and getExternalStoragePublicDirectory() on Environment are now undeprecated. DATA in MediaStore.MediaColumns is also undeprecated.

I don’t know what to make of this.

A Google engineer reached out to clarify what is going on.

Good news! These changes were not an accident! getExternalStorageDirectory() and getExternalStoragePublicDirectory() on Environment are safe for use on all supported API levels. 🎉

The fact that they are undeprecated means that you can rely on them to return the same sorts of directories that they always have. However, this does not change your access rights. Scoped storage is still a thing, and what you can read from and write to is still governed by the scoped storage rules.

(someday, I will sit down and try to write the definitive guide for what those rules are)

So, for example, just because you can now access DIRECTORY_DOWNLOADS via getExternalStoragePublicDirectory() does not change the rules for that directory:

  • You can write content there

  • You can read back the content that you wrote there

  • You cannot read or write content created by other apps there, which includes prior installations of your own app (after the user uninstalled and reinstalled your app)

So, this undeprecation does not have a security impact. It just means that you will stop getting compiler Lint complaints about using a deprecated API, as soon as you start using compileSdkVersion 32, perhaps in 2022.

I am grateful for this change. Once Android 11 restored read access to much of external storage, the deprecations were an annoyance. This will help to simplify the discussion around how to work with external storage on modern versions of Android, because that is a major pain point for newer Android app developers.

To the Google engineers who decided to make this change: thanks!