Random Musings on the N Developer Preview 2

Each time Google releases a new developer preview, I try to talk about the changes that Google isn’t talking about.

N Developer Preview 2 is an incremental change over N Developer Preview 1. The announcement blog post does not mention all that much, spending the most screen space talking about emoji. However, despite that, there are things that you really should know about NDP2 compared to the previous NDP1, beyond what is mentioned there. And, yes, beyond emoji.

Regressions… Compared to Production Android

Google changed the “Behavior Changes” page without pointing out what the actual changes were in NDP2 compared to NDP1. Of note:

  • Google admitted that the file: Uri scheme is defunct, as we discovered the hard way in NDP1

  • In the same section of the docs, Google now points out that MODE_WORLD_READABLE and MODE_WORLD_WRITEABLE, beyond merely being deprecated, will crash with a SecurityException, and that attempts to access COLUMN_LOCAL_FILENAME from DownloadManager will also result in a SecurityException.

  • The StrictMode configuration for checking for network I/O on the main application thread must have been focused on HTTP APIs or something. Regardless, apparently you could open and write to a Socket directly without triggering the dreaded NetworkOnMainThreadException. This has been tightened up. Apps that had skated by with UI-thread network I/O due to this hole now need to be patched.

Regresssions… Compared to NDP1

Some symbols that you used in your NDP1 tests may have been revised in NDP2, so be compared for some compilation errors.

For example, a number of things related to multi-window support changed:

  • android:minimumSize now split into android:minimumWidth and android:minimumHeight

  • inMultiWindow() and inPictureInPicture() were renamed isInMultiWindowMode() and isInPictureInPictureMode()

  • Mode was also added in other related spots (e.g., onMultiWindowChanged() is now onMultiWindowModeChanged())

Minor Bits of Goodness

While I tend to focus on the problem areas, there are some less-known good things that arose in NDP2.

  • Apparently, onSaveInstanceState() and various other methods that involved IPC, if they resulted in a TransactionTooLargeException (e.g., the state Bundle exceeding 1MB), would fail fairly quietly. Now, such exceptions will be wrapped in some form of RuntimeException. This should not result in new problems, but it may result in new exceptions. While that may cause angst, the exception details will help you clean up your code, since it was not working correctly previously anyway.

  • Debug.startMethodTracing(), IIRC, used to write its output to the root of external storage. Now, it will write to getExternalFilesDir() or someplace around there. In a nutshell, you will not need WRITE_EXTERNAL_STORAGE just to capture method traces.

  • PowerManager now has a SUSTAINED_PERFORMANCE_WAKE_LOCK, described as “used by Gaming and VR applications to ensure the device provides will provide consistent performance over a large amount of time”. It is unclear exactly what the behavior of this will be.

  • Long-time Android developers will remember that Activity used to support onRetainNonConfigurationInstance() and getLastNonConfigurationInstance(). These were deprecated back in API Level 11, replaced by retained fragments. For some reason, they have been un-deprecated (de-deprecated? dis-deprecated? anti-deprecated?!?) in NDP2.

  • I reported in the NDP1 “random musings” post that Activity had a new onProvideKeyboardShortcuts() method, suggesting a greater emphasis on physical keyboards. That was removed in NDP2, with no obvious replacement. If it was removed because I pointed it out, I wish to apologize to onProvideKeyboardShortcuts() and its next of kin.

  • There is a whole new android.os.health package, described as:

Applications running in the background are responsible for a significant amount of battery usage on a typical android device. There are several things that applications can do in order to reduce their impact… This package provides more insight into what is going on behind the scenes when an application is running.

The API seems convoluted, at least on first glance, and it is largely undocumented at this point. But, it appears that we can access things like the number of times our _WAKEUP alarms were invoked, how many times our services were started, how many ANRs we generated, how much CPU time we have used, and so forth.

Bugs

Some of the bugs that I filed against NDP1 were fixed. Of note, it appears that the multi-window minimal-size stuff works better and the network security configuration is no longer sensitive to whitespace.

However, some bugs that I filed are still outstanding, such as this RemoteInput documentation gap. Plus, all three of my TileService bugs still seem to be outstanding:

One bug is partially fixed, and it’s an interesting one. For many years, the documentation has claimed that you can use a content: Uri to install an app. This does not work on production versions of Android and did not work on NDP1, as there was simply no activity that could handle installing with a content: Uri. On NDP2, the activity now exists. It doesn't work, at least in my tests, and so once I have a fresh up-to-date sample, I will be filing a fresh bug report to match. If you are implementing some sort of app installer, or a self-upgrading app, having content: support is very useful for security, which is why it was frustrating that Google ignored this for years.


I am sure that many more things changed in NDP2 than I caught in the past couple of hours. And most of what I pointed out in NDP1 stil holds true.


Nervous about how the newest version of Android affects your app? Consider subscribing, then asking questions in the office hours chats!