Android N Preview behavior changes

Source: Internet
Author: User

Behavioral changes

In addition to providing many new features and functionality, Android N also makes various changes to system and API behavior. This article highlights some of the important changes you should be aware of and consider when developing your application.

If you've previously published an Android app, be aware that your app may be affected by these platform changes.

Performance improvements

To extend the battery life of the device, reduce memory usage, and improve application performance, Android N has made some changes to the system behavior. These changes may affect the availability of system resources and system notifications to the app. You should review these changes carefully and assess what adjustments your app may need to make to accommodate these changes.

Nap

The Android 6.0 (API level 23) introduces snooze mode, which delays CPU and network activity and prolongs battery life when the user device is unplugged, at rest, and the screen is turned off. Android N further enhances snooze mode by applying part of the CPU and network restrictions when the device is unplugged and the screen is off, but not necessarily at rest (for example, when a user is out of the hand-held device in his pocket).


Figure 1. NAP mode how to apply the first-level system activity limit to extend the battery life diagram.

When the device is charging and the screen is off for a certain amount of time, the device goes into NAP mode and applies the first part of the limit: Turn off app network access, postpone jobs, and sync. If the device is stationary for a certain amount of time after entering snooze mode, the system will PowerManager.WakeLock AlarmManager apply the rest of the snooze restrictions to the alarm, GPS, and Wi-Fi scan. The system wakes up the device to provide a short maintenance window, whether the app part or the full snooze limit, during which the application can access the network and perform any deferred jobs/synchronizations.


Figure 2. How nap mode applies a diagram of the second-level system activity limit after the device has reached a standstill for a certain amount of time.

Note that when you activate the screen or plug-in the device, the system exits NAP mode and cancels these processing restrictions. This new behavior does not affect the recommendations and best practices for making your app adapt to the older version of NAP mode introduced in Android 6.0 (API level 23), as discussed in NAP and app standby optimization. You should still follow these recommendations, such as using Google Cloud Messaging (GCM) to send and receive messages, and start scheduling update plans to accommodate the new snooze behavior.

Project Svelte: Background optimization

Android N removed three implicit broadcasts to help optimize memory usage and power consumption. This change is necessary because implicit broadcasts frequently start applications that are registered to listen for these broadcasts in the background. Removing these broadcasts can significantly improve device performance and user experience.

Mobile devices experience frequent connection changes, such as when switching between Wi-Fi and mobile data. Currently, you can listen to implicit broadcasts by registering a receiver in the app manifest file CONNECTIVITY_ACTION , allowing the app to monitor these changes. Because many applications register to receive this broadcast, a single network switchover can cause all apps to wake up and process the broadcast at the same time.

Similarly, an app can register to receive implicit and broadcast from other apps, such as a camera ACTION_NEW_PICTURE ACTION_NEW_VIDEO . When a user takes a photo using the camera app, the apps are awakened to process the broadcast.

To mitigate these problems, Android N applies the following optimizations:

    • Apps that are developed for Android N will not receive CONNECTIVITY_ACTION broadcasts, even if they already have a manifest entry to request notification of these events. Apps that run in the foreground BroadcastReceiver can still listen in the main thread if they are receiving notifications using a request CONNECTIVITY_CHANGE .
    • Apps cannot be sent or received ACTION_NEW_PICTURE or ACTION_NEW_VIDEO broadcast. This optimization affects all applications, not just Android N.

Future versions of Android may also discard other implicit broadcasts and unbound back-end services. In view of this, you should avoid relying on sinks declared in the manifest file to listen for implicit broadcasts or to delete this dependency, and to avoid or remove dependencies on background services.

The Android framework offers a variety of solutions to reduce the need for these implicit broadcast or back-office services. For example, the JobScheduler API provides a robust mechanism to schedule network operations that meet specified conditions, such as connecting to a non-metered network. You can even use it JobScheduler to respond to changes that occur in the content provider.

For more information about this behavior change and how to overwrite the app, see Background optimization.

Permission changes

Android N has made some permissions changes, including user account permissions and new permissions to write information to external storage devices, which may affect your app. The following outlines the permissions that have changed in the preview version.

    • GET_ACCOUNTS(deprecated)

      Get_accounts permissions are now deprecated. For Android N-oriented apps, this permission is ignored by the system.

Assistive tool Improvements

Android N made some changes to improve the usability of the platform for poor eyesight or visually impaired users. These changes generally do not require changes to your app code, but you should carefully review and test these features with your app to assess their potential impact on the user experience.

Screen Zoom

Android N enables the user to set the display size to enlarge or reduce all elements on the screen, thereby enhancing the accessibility of the device to visually impaired users. The user cannot scale the screen below the minimum screen width of SW320DP, which is the width of the Nexus 4 and the width of the regular medium-sized phone.

Figure 3. The right-hand screen shows the effect of a device running an Android N system image that increases the size of the display.

When device density changes, the system notifies the running app as follows:

    • If the application is for an API level 23 or earlier system, all of its background processes are automatically terminated. This means that if a user switches away from such an app, turns on the Settings screen and changes the display size setting, the system terminates the app as if it were running out of memory. If the app has any foreground processes, the system notifies them of the configuration changes as described in processing a run-time change, as if the device's screen orientation changes.
    • If the app is for Android N, all of its processes (foreground and background) will receive notifications about configuration changes, as described in handling runtime changes.

Most apps do not need to make any changes to support this feature, but only if these apps follow Android best practices. Specific items to check for:

    • sw320dpTest your app on a screen-wide device and make sure it runs well.
    • Updates any density-related cache information, such as cached bitmaps or resources loaded from the network, when the device configuration changes. Check for configuration changes when the app resumes running from a paused state.

      Note: If you want to cache configuration-related data, it is also best to include related metadata, such as the screen size or pixel density for that data. Saving these metadata makes it easier for you to decide whether you need to refresh the cached data after you configure the changes.

    • Avoid specifying dimensions in pixel units, because pixels do not scale with screen density. Instead, specify the dimensions using the density-independent pixel ( dp ) units.
Setting visual settings in the wizard

Android N adds "Vision Settings" to the "Welcome" screen, which allows the user to set the following accessibility settings on the new device:magnification gesture,Font size, Display size and TalkBack. This change enhances the visibility of errors related to different screen settings. To evaluate the impact of this feature, you should test the app in a state where these settings are enabled. You can find these settings in Settings > Accessibility .

NDK app link to platform library

Android N has made some namespace changes to prevent the non-public API from loading. If you use the NDK, you can only use the exposed APIs provided by the Android platform. Using the non-public API on the next officially released Android version will cause the app to crash.

To remind you that a non-public API is used, an app running on an Android N device generates an error in the log message output when an app calls a non-public API. This error also appears as a message on the device screen to help enhance your awareness of this situation. You should check your app's code to remove the use of NonPublic platform APIs and test your app thoroughly using a preview device or simulator.

If your app relies on a platform library, see the NDK documentation for a typical fix that replaces the generic private API with exposing API equivalents. You can also link to the platform library without implementing the app, especially if the library used by the app is part of the platform (for example libpng ), but it's not part of the NDK. In this case, make sure that your APK contains all the. So files that you intend to link to.

Note: Some third-party libraries may be linked to non-public APIs. If your app uses these libraries, a crash may occur when your app runs on the next officially released version of Android.

Apps should not rely on or use native libraries that are not part of the NDK, as these libraries may change or migrate from one Android version to another. For example, switching from OpenSSL to Boringssl is a change of this kind. In addition, different devices may offer different levels of compatibility because there is no compatibility requirement for platform libraries that are not part of the NDK. If you must access a non-NDK library on an older device, load it according to the Android API level.

To help you diagnose such problems, here are some Java and NDK errors you might encounter when you try to develop your app using Android N:

Java Error Example:

Java.lang.UnsatisfiedLinkError:dlopen failed:library "/system/lib/libcutils.so" is not accessible for the    Namespace "Classloader-namespace"

NDK Error Example:

Dlopen failed:cannot Locate symbol "__system_property_get" referenced by ...

Here are some typical fixes for applications that encounter this type of error:

  • You can use standard JNI functions instead of GETJAVAVM and getjnienv in libandroid_runtime.so:
    ANDROIDRUNTIME::GETJAVAVM, GETJAVAVM from <jni.h>androidruntime::getjnienv, javavm::getenv OrJavaVM:: Attachcurrentthread from <jni.h>.
  • You can use the public alternates __system_property_get to replace the libcutils.so symbols in use property_get . If you want to do this, use __system_property_get the following include function:
    <span class= "com" > #include </span><span class= "PLN" style= "Color:rgb (0, 0, 0);" > </span><span class= "str" style= "COLOR:RGB (136, 0, 0);" ><sys/system_properties.h></span>
  • You should use the local version of the app to replace libcrypto.so the symbols in use SSL_ctrl . For example, you should .so statically link in a file libcyrpto.a , or include your own dynamic from Boringssl or OpenSSL in your app libcrypto.so .
Android for work

Android N contains changes to apps that target Android for work, including changes to certificate installation, password reset, level two user management, and device identifier access. If you are developing an app for the Android for work environment, you should review these changes carefully and modify your app accordingly.

  • You must install the Licensing certificate installer before DPC can set it up. For profile and device owner apps that target the N SDK, you should DevicePolicyManager.setCertInstallerPackage() install the authorization Certificate installer before the device policy controller (DPC) call. If you have not already installed this installer, the system is raised IllegalArgumentException .
  • The Reset password limit for device Administrators now also applies to the profile owner. Device administrators can no longer use DevicePolicyManager.resetPassword() to purge or change passwords that have been set. However, the device administrator can still set the password, but only when the device does not have a password, PIN, or pattern.
  • The device owner and the profile owner can still manage the account, even if the limit is set. And, even with DISALLOW_MODIFY_ACCOUNTS user restrictions, the device owner and the profile owner can still invoke the account Management API.
  • Device owners make it easier to manage level two users. When the device is running in device owner mode, the system automatically sets the DISALLOW_ADD_USER limit. This prevents users from creating unmanaged level two users. In addition, CreateUser() and createAndInitial() methods have been deprecated and replaced by DevicePolicyManager.createAndManageUser() methods.
  • The device owner can access the device identifier. The device owner can use DevicePolicyManagewr.getWifiMacAddress() the Wi-Fi MAC address to access the device. If Wi-Fi is never enabled on the device, this method returns a null value.

For more information about the changes that you make to Android for work in Android N, see Android for job update.

Other important notes
    • If an app is running on Android N, but is developed for a lower API level, the system terminates the app process when the user changes the display size. Therefore, the app must be able to handle this scenario properly. Otherwise, the app crashes when the user resumes running the app from a recent usage record.

      You should test your app to make sure that this behavior does not occur. To perform this test, you can manually terminate the app with DDMS to cause the same crash.

      Applications that target N and later are not automatically terminated when density changes, but these applications may still respond negatively to configuration changes.

    • Apps on Android N should be able to handle configuration changes normally and not crash on subsequent startup. You can verify the app behavior by changing the font size (Setting > Display > font size) and then resuming the app from the most recently used record.

Android N Preview behavior changes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.