Random Musings on the R Developer Preview 3

Each time Google releases a new developer preview, I read what I can to see if there are things that warrant more attention from developers. I try to emphasize mainstream features that any developer might reasonably use, along with things that may not get quite as much attention, because they are buried in the JavaDocs.

The deeper we get into the release series for a new Android version, the fewer “big ticket” changes appear. Android R is no exception. Many of the changes are tweaks to things that debuted earlier, such as new class and method names around data access auditing.

So, What’s New?

Besides stuff like the improved wireless ADB access that Google pointed out in the DP3 release blog post, I see a few other new items of interest:

  • We now have isExternalStorageManager() methods on Environment. This is how we can find out if the user has granted us MANAGE_EXTERNAL_STORAGE. The zero-parameter version tells us if we have such rights for external storage; the one-parameter version tells us if we have such rights on whatever storage volume contains the supplied File. This was a clear gap in the earlier developer previews, so I am glad that this was added!

  • There is a new option with the keystore to require authentication per use on designated keys, with developer-controlled authenticators (e.g., strong biometrics or a device credential).

  • ContentResolver now has a notifyChange() method that takes a collection of Uri values, presumably as an optimization.

  • ParcelFileDescriptor now has a wrap() method. You also supply an OnCloseListener, which is notified when the underlying ParcelFileDescriptor is closed. This could be useful for tracking file descriptor leaks — keep a roster of those that you create and remove them from the list when they are closed.

Also, Android Police pointed out that there is a new Settings option to “auto-revoke permissions”. Basically, if the user does not use your app for a while (“a few months”), Android will automatically revoke certain permissions that the user has granted. Well-written apps should not be harmed by this, but it is yet another wrinkle with runtime permissions added by Android R, on top of the one-time permission option that debuted with DP1.

What Significantly Changed?

Besides the name changes in data access auditing, we have:

  • android.view.inline moved to android.widget.inline and got a bit more in the way of documentation. InlineContentView feels like something layered atop of the SurfaceControlViewHost that I profiled here and here. Still, it is unclear how this is going to get used in practice.

  • ApplicationExitInfo got three new reasons of why your process died. Also, we can now register a “process state summary” via ActivityManager and get that back in ApplicationExitInfo, to provide a bit more context about what the app was doing at the time its process died. And, if we crashed (particularly with an ANR), we can get details of what the threads were doing at the time.

What’s Gone?

Whatever FEATURE_CONTEXT_HUB was, it no longer exists.

Also, as part of revamping the “resource loader” system, they got rid of DirectoryAssetLoader… despite still referring to it in the preview documentation.

While technically not “gone”, a couple of WebView methods were deprecated:

  • setAllowFileAccessFromFileURLs()
  • setAllowUniversalAccessFromFileURLs()

What Now?

I will work on releasing an updated version of Elements of Android R in the coming weeks, covering some of this and other things that are part of earlier developer previews.

Interested in Jetpack Compose? jetc.dev has a weekly newsletter of the latest articles, samples, and other details of Compose development!