From f278dab83eba9891ae1017e8bcd0ae4fddd44912 Mon Sep 17 00:00:00 2001
From: Joe Fernandez
-This page is under construction. For now,
-this
-doc contains information on upcoming behavior changes.
-
+ If you have previously published an app for Android, be aware that your app + might be affected by these changes in the platform. +
+ + ++ The Preview contains system behavior changes aimed at improving the battery + life of devices. These changes can impact the availability of system + resources and system notifications to your app. You should review these + changes and evaluate how your app may need to adjust to them. +
+ ++ Introduced in Android 6.0 (API level 23), Doze improves battery life by + deferring CPU and network activities when a user leaves a device unplugged, + stationary, and with the screen turned off. This Preview brings further + enhancements to Doze by applying a subset of CPU and network restrictions + while the device is unplugged with the screen turned off, but not necessarily + stationary, for example, when a handset is traveling in a user’s pocket. +
+ ++ Figure 1. Illustration of how Doze applies a first level of + system activity restrictions to improve battery life. +
+ ++ When a device is on battery power, and the screen has been off for a certain + time, the device enters Doze and applies the first subset of restrictions: It + shuts off app network access, and defers jobs and syncs. After some more time + elapses, the system applies the rest of the Doze restrictions to {@link + android.os.PowerManager.WakeLock}, {@link android.app.AlarmManager} alarms, + GPS, and Wi-Fi scans.. Regardless of whether some or all Doze restrictions + are being applied, the system wakes the device for brief maintenance windows, + during which applications are allowed network access and can execute any + deferred jobs/syncs. +
+ + ++ Figure 1. Illustration of how Doze applies a second level of + system activity restrictions to further improve battery life. +
+ ++ Note that activating the screen on or plugging in the device exits Doze and + removes these processing restrictions. The additional behavior does not + affect recommendations and best practices in adapting your app to the prior + version of Doze introduced in Android 6.0 (API level 23). You should still + follow those recommendations, such as using Google Cloud Messaging (GCM) to + send and receive messages, and start planning updates for the additional Doze + behavior. +
+ + ++ The Preview removes three implicit broadcasts in order to help optimize both + memory use and power consumption. This change is necessary because implicit + broadcasts frequently start apps that have registered to listen for them in + the background. Removing these broadcasts can substantially benefit device + performance and user experience. +
+ ++ Mobile devices experience frequent connectivity changes, such as when moving + between Wi-Fi and mobile data. Currently, apps can monitor for changes in + connectivity by registering a receiver for the implicit {@link + android.net.ConnectivityManager#CONNECTIVITY_ACTION} broadcast in their + manifest. Since many apps register to receive this broadcast, a single + network switch can cause them all to wake up and process the broadcast at + once. +
+ ++ Similarly, apps can register to receive implicit {@code NEW_PICTURE} and + {@code NEW_VIDEO} broadcasts from other apps, such as Camera. When a user + takes a picture with the Camera app, these apps wake up to process the + broadcast. +
+ ++ To alleviate these issues, the Preview applies the following + optimizations: +
+ ++ Future releases of Android may deprecate additional implicit broadcasts, as + well as unbound background services. For this reason, you should avoid or + remove dependencies on manifest-declared receivers for implicit broadcasts, + as well as on background services. +
+ ++ The Android framework provides several solutions to mitigate the need for + these implicit broadcasts or background services. For example, the {@link + android.app.job.JobScheduler} API provides a robust mechanism to schedule + network operations when specified conditions, such as connection to an + unmetered network, are met. You can even use {@link + android.app.job.JobScheduler} to react to changes to content providers. +
+ ++ For more information about this behavior change and how to adapt your app, + see Background + Optimizations. +
+ + ++ The Preview includes changes to permissions that may affect your app, + including user accounts permissions and a new permission for writing to + external storage. Here is a summary of the permissions that have changed in + the preview: +
+ ++ The GET_ACCOUNTS permission is now deprecated. The system ignores this + permission for apps that target the N Developer Preview. +
++ This permission is for a new storage option. Apps can now use the intent + {@code ACTION_OPEN_EXTERNAL_DIRECTORY} to request that the system create a + directory for the app's use. The system prompts the user to grant + approval. If the user approves, the app can read and write files and + directories in that one directory (and its descendants). The app does not + need {@link android.Manifest.permission_group#STORAGE STORAGE} + permissions to access this external directory +
+ ++ For more information about this intent, see the updated + {@code Intent} reference documentation in the + N Preview SDK Reference. +
++ This Preview includes changes intended to improve the usability of the + platform for users with low or impaired vision. These changes should + generally not require code changes in your app, however you should review + these feature and test them with your app to assess potential impacts to user + experience. +
+ + ++ The Preview enables users to set Display sizewhich magnifies + or shrinks all elements on the screen, thereby improving device accessibility + for users with low vision. Users cannot zoom the screen past a minimum screen + width of + sw320dp, which is the width of a Nexus 4, a common medium-sized phone. +
+ + +
++ Figure 1. The screen on the right shows the effect of + increasing the Display size of a device running an N Preview system image. +
+ ++ When the device density changes, the system notifies running apps in the + following ways: +
+ ++ Most apps do not need to make any changes to support this feature, provided + the apps follow Android best practices. You should verify that your app + behaves properly under Screen Zoom. +
+ + ++ The Preview includes Vision Settings on the Welcome screen, where users can + set up the following accessibility settings on a new device: + Magnification gesture, Font size, + Display size and TalkBack. This change + increases the visibility of bugs related to different screen settings. To + assess the impact of this feature, you should test your apps with these + settings enabled. You can find the settings under Settings > + Accessibility. +
+ + ++ The Preview moves Android’s Java language libraries to an OpenJDK-based + approach, creating a common code base for developers to build apps and + services. If your app depends on a private implementation of Java or + unspecified behavior, you should be aware of these known issues: +
+ ++ If your app, or a library it used, was dependent on a private field of + the ArrayList class, you may encounter an exception such as: +
++java.lang.NoSuchFieldException: No field array in class Ljava/util/ArrayList; ++
+ You can now call implementations of Comparator to compare an element to + itself. However, doing so may cause problems if the Comparator expects to + be called only with unique arguments. +
++ You should only call to the Java Cryptography Extension (JCE) APIs with a + provider listed if the provider is included in the code of the APK. + Otherwise, your app needs to be able to handle the provider’s absence. +
+ ++ The reason apps use this provider is to take advantage of its + SecureRandom implementation. If your app was relying on setSeed() to + derive keys from strings, you must either switch to using SecretKeySpec + to load raw key bytes directly, or use a real key derivation function + (KDF). +
++ The Preview contains changes for apps that target Android for Work, including + changes to certificate installation, password resetting, secondary user + management, and access to device identifiers. If you are building apps for + Android for Work environments, you should review these changes and modify + your app accordingly. +
+ +DevicePolicyManager.setCertInstallerPackage(). If the installer
+ is not already installed, the system throws an
+ IllegalArgumentException.
+ DevicePolicyManager.resetPassword()to clear passwords or change
+ ones that are already set. Device admins can still set a password, but only
+ when the device has no password, PIN, or pattern.
+ DISALLOW_MODIFY_ACCOUNTS user restrictions are in place.
+ DISALLOW_ADD_USER restriction
+ is automatically set. This prevents users from creating unmanaged secondary
+ users. In addition, the CreateUser() and
+ createAndInitial() methods are deprecated; the new
+ DevicePolicyManager.createAndManageUser() method replaces them.
+ DevicePolicyManagewr.getWifiMacAddress() . If Wi-Fi has never
+ been enabled on the device, this method returns a value of {@code null}.
+ + In the Preview, an application built with the NDK and targeting the N Preview + API cannot link against the platform libraries shipped with the NDK. This + change affects both the dlopen(3) and DT_NEEDED entries in your {@code .so} + files. +
+ +
+ If your app depends on platform libraries, see the NDK documentation for
+ typical fixes for replacing common private APIs with public API equivalents.
+ You may also be linking to platform libraries without realizing it,
+ especially if your app uses a library that is part of the platform (such as
+ libpng), but is not part of the NDK. In that case, ensure that
+ your APK contains all the .so files you intended to link against.
+
+ Apps should not depend on or use native libraries that are not included in + the NDK, because they may change, or be removed from one Android release to + another. The switch from OpenSSL to BoringSSL is an example of such a change. + Also, different devices may offer different levels of compatibility, because + there are no compatibility requirements for platform libraries not included + in the NDK. If you must access non-NDK libraries on older devices, make the + loading dependent on the Android API level. +
+ ++ To help you diagnose these types problems here are some example Java and NDK + errors you might encounter when attempting to build your app with the N + Developer Preview: +
+ +Example Java error:
++java.lang.UnsatisfiedLinkError: dlopen failed: library "/system/lib/libcutils.so" + is not accessible for the namespace "classloader-namespace" ++ +
Example NDK error:
++dlopen failed: cannot locate symbol "__system_property_get" referenced by ... ++ + +
+ Here are some typical fixes for apps encountering these types of errors: +
+ ++AndroidRuntime::getJavaVM -> GetJavaVM from <jni.h> +AndroidRuntime::getJNIEnv -> JavaVM::GetEnv or +JavaVM::AttachCurrentThread from <jni.h>. ++
+#include <sys/system_properties.h> and use __system_property_get ++