First, WiFi RTT function-accurate navigation under complex terrain
WiFi RTT function is a new function introduced by Android P, which is consistent with the positioning principle of cellular network in principle, but it greatly makes up for the shortage of indoor positioning of cellular network, and WiFi RTT will be able to provide indoor high-precision positioning, which is difficult for cellular network to do.
WiFi rtt is a brand-new function. Add RTT package under android.net.wifi package to store WiFi RTT related classes and interfaces.
The API of WiFi RTT takes WifiRttManager as the core, and with the help of AP hotspot or WiFi, using RTT principle, the location of equipment can be accurately located through more than three ranging points.
WiFiRTTManager provides a ranging interface, which is an asynchronous ranging operation. According to the official document (/reference/Android/net/wifi/RTT/wifirtmanager.html), the ranging interface is as follows:
Void start ranging (ranging request request, RangingResultCallback, Handler);
Attention:? The interface definition of the SDK platform Android P preview 1 is different, but the interface in the actual official map is the same. Developers need to update the latest Android P preview version 2, in which Google has fixed this interface.
In the interface, RangingRequest is built by RangingRequest. Generator, and the parameters required for RangingRequest to be generated by RangingRequest. Builder can obtain related content through system services such as WiFiManager, such as? List & ltscanresult & gtscanresults = wifi manager. getscanresults ();
Here is a simple test demonstration for your reference:
Private WifiRttManager wifiRttManager
Private WifiManager wifiManager
@ Overlay
Protected void oncreate (bundle saved instancestate) (
// ......
if(getPackageManager()。 hasSystemFeature(package manager。 FEATURE_WIFI_RTT)) {
object service = this . getapplicationcontext()。 GetSystemService (context. WIFI _ RTT _ ranging _ service);
WifiRttManager's service instance) (
WifiRttManager= (WifiRttManager) service;
Log.i (tag, "Getting WifiRttManager succeeded." );
}
wifi manager =(wifi manager)this . getapplicationcontext()。 GetSystemService (context. WIFI _ service);
intent filter wifi filter = new intent filter();
wifi leter . addaction(wifi manager。 Network _ Status _ Changed _ Operation);
wifi leter . addaction(wifi manager。 WIFI _ status _ changed _ action);
wifi leter . addaction(wifi manager。 Scan _ Result _ Available _ Action);
RegisterReceiver (new WifiChangeReceiver (), wifi leter);
}
// ......
}
Private void startScanAPs() {
wifi manager . setwifienabled(true);
wifi manager . starts can();
}
WifiChangeReceiver class extends BroadcastReceiver {
@RequiresApi(api = 28)
@ Overlay
Public void onReceive (context, intention) (
if (intent.getAction()。 Equal to (WifiManager. Scan results available for operation) {
List & ltscanresult & gtscanresults = wifi manager. getscanresults ();
Log.i (label, "Wifi scan size:"+scanresults.size ());
For(ScanResult scan result:? Scan results) {
Log.i (tag, scanresult.tostring ());
RangingRequest。 builder builder = new ranging request。 builder();
builder . addaccess point(scan result);
wifirttmanager . start ranging(builder . build(),new RangingResultCallback() {
@SuppressLint("Override ")
@ Overlay
Public void (int i) on RangingFailure {
// TODO
}
@SuppressLint("Override ")
@ Overlay
public void on ranging results(List & lt; RangingResult & gt list) (
// TODO gets the results from the list.
For(RangingResult: list) (
Log.i (tag, result. tostring()););
}
}
},new Handler());
}
}
}
}
When using WiFi RTT, you need to add the following statement in AndroidManifest.xml:
& ltuses-feature Android:name = " Android . hardware . wifi . RTT "/& gt;
Through the simple code above, the function of WiFi RTT can be realized.
WiFi RTT function is suitable for large-scale indoor and outdoor places with complex terrain, such as shopping malls, entertainment places, large-scale leisure, playgrounds and so on. , and provide functions such as accurately navigating the local area in the location. I believe that in a short time, you can experience this convenient function in major map applications, which will be a great boon for road-crazy and map-blind partners.
Second, show clips-support Liu Haiping.
With the launch of iPhone X, "Liu Haiping" reached an unprecedented climax. Android P provides a UI adaptation and compatibility scheme for special-shaped screens. Through the relevant interfaces provided by the DisplayCutout class, you can get the information of the clipping area in the screen.
With the help of DisplayCutout, you can get the following information:
display cutout display cutout = view . getrootwindowinsets()。 getDisplayCutout();
if(displayCutout! = null) {
region bounds = display cutout . get bounds();
Log.d(TAG,String.format("Bounds:%s ",Bounds . tostring()));
int top = display cutout . getsafeinsettop();
int bottom = display cutout . getsafeinsetbottom();
int left = display cutout . getsafeinsteleft();
int right = display cutout . getsafeinsetright();
Log.d(TAG, string. format(" Cutout edge:[ left: %d, top: %d, right: %d, bottom: %d] ",left, top, right, bottom)););
}
The public area getBounds () can get all the information of the clipping area, and the area is the clipping area.
public int getSafeInsetTop()
public int getSafeInsetBottom()
public int getSafeInsetLeft()
public int getSafeInsetRight()
The above four interfaces can get the boundary value of the safe area after cutting the area.
Through the above data, developers can accurately control the drawing of UI, and avoid the UI display abnormality caused by drawing the UI content into the clipping area.
In Android, Liu Haiping is still extremely rare. In order to facilitate debugging by developers, Google specially provides clipping support in Android P preview. Please refer to the cut-out part of the function description document provided by Google for the specific opening method.
Cut section: /preview/features.html#cutout
As shown in the figure, the author experienced the matting settings of Android P with Pixel 2 XL at hand.
Third, notification optimization-more diverse operations and richer content.
Android P optimizes the richness and operability of notification content.
In the latest version, the notification management of Android system has been optimized and upgraded. Android O provides a finer-grained channel function. When pushing the notification bar, you need to specify the NotificationChannel. Users can select notification channels, and only the notifications pushed by interested channels are allowed to be displayed. Through channel setting and interference-free optimization, the message experience is greatly enhanced.
Enhance the message experience
Android P continues to improve enhanced message notification [v 1]? . As early as Android 7.0, it provided direct response and input in notifications, and Android P made more enhancements to this function.
The notification of Android P supports image content, and the image content of the message can be given through the setData () method and displayed to the user in the notification.
Android P also simplifies the configuration of notifications. Class notice. Person is added to Android P to distinguish the information of participants in the same conversation, such as their avatars and URIs. According to the official explanation, in Android P, other notification message APIs also use Person instead of the previous CharSequence.
Development of new API under simple experience;
notification channel channel = new notification channel(" WtTestChannel ",
“WtTestChannel”,NotificationManager。 Importance _ default);
channel . enable lights(true); //The point in the upper right corner of the luncher icon
Channel.setLightColor (color. Red); //read point
channel . setshowbadge(true); //Whether to display the channel notification on the long press icon?
Notice. Generator generator =
New notice. The builder (MainActivity.this,
“WtTestChannel”);
Notice. Person p = new notification. person();
p . set name(" we test ");
p.setUri("/" +
" ui/ 1 . 2 . 0/PC/static/image/new logo- 16042 . png ");
Notice. Messagestylemessagestyle = new notification. messaging style(p);
Notice. Message style. Message message =
New notice. Messagingstyle.message ("we test message", 2000, p);
//Display image
Uri image = Uri.parse(
"/ui/ 1 . 2 . 0/PC/static/image/new logo- 16042 . png ");
Message.setData("image/png ",image);
MessageStyle.addMessage (message);
builder . set style(message style);
builder . setsmallicon(r . MIP map . IC _ launcher);
Notify notification = builder.build ();
NotificationManager notification manager =
(notification manager)getSystemService(
main activity . this . getapplicationcontext()。 Notification _ service);
Notifymanager. createnotification channel (channel);
notifyManager.notify("WeTest ", 1,notification);
Channel setting, broadcasting and interference-free optimization
In Android P, we focus on enriching the content and simplifying the channel setting.
In the Android O version, NotificationChannel is introduced for the first time, and developers need to configure the corresponding channel to push notifications to users. Can users be more granular [v 1]? Choose a channel for the application, instead of blocking all the notification content of the application.
In Android P, the management of notifications is further optimized, including blocking channel groups, providing new broadcast types and new do not disturb priorities.
Shielded channel group:? Users can filter the entire channel group of the App in the notification settings. Developers can judge whether a channel group isBlocked by isblocked (), and according to the result, no notification will be sent to the blocked channel group. In addition, developers can use the new interface getNotificationChannelGroup () in the application to query the current channel group settings.
New broadcast type: The new broadcast type is "channel (group) shielding status change" broadcast, which increases the functions of channels and channel groups. In the developer application, you can receive the broadcast of the channel (group) you own and operate according to the specific broadcast content. Developers can view specific information related to broadcasting through NotificationManager. For broadcasting this action, you can check the specific methods and information through broadcasting.
Do not disturb priority:? Notification manager. The policy adds two new priority constants, PRIORITY_CATEGORY_ALARMS and priority _ category _ media _ system _ other? (Media, system and game sound are preferred).
Fourth, support multiple cameras and video cameras * * *
Recently, dual-camera and multi-camera models have appeared one after another. Dual cameras and multiple cameras provide functions that a single camera cannot achieve, such as seamless zoom, panoramic view and stereoscopic vision. Android P also provides system-level API support in this respect.
Android P provides a system API that supports two or more physical cameras to collect data streams at the same time. Most of the dual camera devices provided by OEMs were customized by the manufacturers themselves. At this time, Android P launched the API and formulated the API specification from the system level.
The new API provides the calling ability to switch logical data streams or mixed data streams between different cameras. In the aspect of capture delay, new session parameters are provided to reduce the initial capture delay. At the same time, it provides the camera with the ability to repeatedly stop and start the camera stream in various scenes using the camera. In terms of flash, Android P adds display-based flash support. In terms of optical image stabilization, Android P provides OIS timestamps to developers for image stability optimization and other special effects.
In addition, Android P also supports an external USB/UVC camera, which can use a more powerful external camera module.
Fifth, support the post-processing of image media.
Android P has launched a brand-new ImageDecoder, which not only supports decoding, scaling and cropping of various image formats, but also supports post-processing of decoded images. With this feature, you can add complex custom effects, such as rounded corners, or put pictures in a circular frame. Write a post-processing callback function, you can add any drawing instructions to achieve the desired effect.
In addition, Android P natively supports animations in GIF and WebP formats, and adds the class AnimatedImageDrawable, which is directly supported by the newly added decoder class ImageDecoder. The usage is similar to that of vector animation class AnimatedVectorDrawable, and the implementation is similar. By adding rendering thread and worker thread, you don't need to deal with animation update in UI thread, which can be said to be painless and very worry-free.
The following shows a gif image by writing code, and draws a green solid circle in the middle of the image by using post-processing mechanism.
final ImageView image =(ImageView)findViewById(r . id . image);
File gif File = new File("/data/local/tmp/test . gif ");
If (! gifFile.exists()) {
Log.d (tag, "gifFile doesn't exist!" );
Return;
}
Image decoder. source source = image decoder . createsource(gif file);
Try {
D = ImageDecoder.decodeDrawable (source, new ImageDecoder. onheaderdecodelistener(){
@ Overlay
public void on header decoded(image decoder image decoder,final ImageDecoder。 ImageInfo imageInfo,ImageDecoder。 Source source) {
ImageDecoder.setPostProcessor (new postprocessor () {
@ Overlay
public int onPostProcess(Canvas Canvas){
int w = imageInfo.getSize()。 getWidth();
int h = imageInfo.getSize()。 getHeight();
Paint paint = new paint ();
paint . setantialias(true);
Paint.setColor (color. Green);
Canvas.drawCircle(w/2, h/2, h/4, new Paint);
Returns 0;
}
});
}
});
Image.setVisibility (view. Visible);
image . setimagedrawable(d);
} catch (IOException e){
Log.d(TAG,e . tostring());
}
Button Button =(Button)findViewById(r . id . Button text);
Button.setOnClickListener (new view. OnClickListener() {
@ Overlay
Public void onClick (view view)
If (d! = null & d instance of Ampanimatedimagedrawable) (
AnimatedImageDrawable ad =(AnimatedImageDrawable)d;
if (ad.isRunning()) {
Log.d (label, "stop running");
ad . stop();
} Otherwise {
Log.d (label, "start running");
ad . start();
}
}
}
});
Sixth, support HDR VP9 and HEIF.
Android P has built-in support for HDR VP9 and HEIF(heic) image coding. HEIF is an efficient compression format introduced by Apple in iOS 1 1, which has been supported on iPhone, Iphone 8 and IPhone 8P. The compression rate of this format is higher, but the encoding of this format needs the support of hardware, and the decoding does not. HeifWriter in the latest support library supports converting from YUV byte buffer, surface or bitmap class to static images in HEIF format.
Android P has newly launched MediaPlayer2, which supports playlists created by DataSourceDesc.
Overview of Function Optimization and Upgrade
I. Neural Network API 1. 1
On the recently released Android 8.1(API level 27), Google launched the neural network API on the Android platform for the first time, which means that the intelligence level of our Android machine has been greatly improved. This time, Android P further enriched the support for neural networks, not only optimized the previous related APIs, but also provided nine new operations, which provided more in-depth support for specific data operations.
Second, improve the automatic filling of forms.
Android 8.0 (API level 26) introduces an automatic filling framework, which makes it easier to fill in forms in applications. Android P has introduced the auto-fill service and achieved many improvements, which can further enhance the user's experience when filling out forms.
Third, strengthen security.
Android P has introduced many new security functions, including a unified fingerprint verification dialog box and high-reliability user confirmation of sensitive transactions. The fingerprint authentication UI in the application will also be more consistent.
Unified fingerprint verification dialog box
If the third-party APP wants to use fingerprints, the Android system framework provides a fingerprint authentication dialog box for the application, which can provide a unified appearance and experience, and users can feel more at ease when using it. If your program is still using FingerprintManager, please use FingerprintDialog instead, and a dialog box will be provided. By the way, before using FingerprintDialog, don't forget to call hasSystemFeature () method to check whether the mobile phone device supports fingerprints.
User's high credibility confirmation of sensitive transactions
Android P system provides a protected validation API. With this new set of APIs, the application can use the ConfirmationDialog dialog box to prompt the user and ask the user to approve a short statement, which allows the application to remind the user that a sensitive transaction (such as payment) is about to be completed.
If the user accepts this statement, the application will receive a key-hash message authentication code (HMAC) generated by TEE to protect the display of the dialog box for input and verification. This signature indicates that you have read the statement and agree.
Hardware security module
Android P also provides a StrongBox Keymaster, which is stored in the hardware security module. The hardware security module has its own CPU, secure storage space, true random number generator and additional mechanisms to resist application tampering or malicious loading of unauthorized applications. When checking the key stored in the StrongBox Keymaster, the system confirms the integrity of the key through the trusted execution environment (TEE). To reduce energy consumption, StrongBox supports a set of algorithms and keys with different lengths:
●? RSA 2048
●? AES 128 and 256
●? ECDSA P-256
●? HMAC-SHA256 (supports any key length from 8 bytes to 64 bytes)
●? Triple DES 168
It should be noted that this mechanism needs hardware support.
Import security keys into keystore.
Using the new ASN. 1 encoding key format, the import key is added to the keystore, and Android P provides additional password decryption security functions. After that, the KeyMaster can decrypt the key stored in the KeyStore, which makes the key plaintext never appear in the device memory. This feature requires the device to support Keymaster 4.
Fourth, support client Android backup encryption.
Android P supports encrypting Android backups with client keys. This privacy measure requires the PIN, mode password or standard password of the device to recover the data from the data backed up by the user device.
Verb (abbreviation of verb) accessibility optimization
In order to make the App more convenient to use, Android provides usability optimization for developers in many aspects.
1, navigation semantics
Android P provides many optimization points for developers in the scene switching and operation of the App.
2. Accessibility pane title
Android P provides a new mechanism for Section, called accessibility pane title. The accessibility service can receive changes to these titles so that it can provide finer-grained information for some changes.
Specify the title of the section, which can be set through the new attribute of android: accessibilityPaneTitle, or through setAccessibilityPaneTitle () at runtime.
3. Navigation in the top bar
Android P provides a new navigation mechanism for the top bar, and displays the logical title by setting the android:accessibilityHeading property of the view instance to true. Using these titles, users can navigate from one title to the next.
4. Group navigation and output
For the screen reader, Android P provides a new attribute Android: screenreaderfocusable to view instead of the original android:focusable to mark it, which solves the operation of setting the view as the focus in order to make the screen reader work in some scenes. At this point, the screen reader needs to pay attention to the view that both android:screenReaderFocusable and android:focusable are set to true.
5, the operation is convenient
Tooltip interaction
In Android P, you can use getTooltipText () to read the text content of the tooltip. Use the new ACTION_SHOW_TOOLTIP and ACTION_HIDE_TOOLTIP to control the view to show or hide tooltips.
New global interaction
Android P provides two new operations in the AccessibilityService class. The developer's service can help users lock the screen through GLOBAL_ACTION_LOCK_SCREEN, and help users complete screenshots through GLOBAL _ ACTION _ TAKE _ SCREEN.
Some details of morphological changes
Android P optimizes the acquisition of updated content when the synchronization of various forms of App changes. When TYPE_WINDOWS_CHANGED appears, developers can get the changes of the form through the getWindowChanges()API.
When multiple forms change, each form will issue its own event, and developers can get the root view of the event form through getSource ().
If your application defines an accessibility pane title for the view, your service can recognize the corresponding changes when the UI is updated. When the TYPE_WINDOW_STATE_CHANGED event occurs, you can get the changes of the current form by using the type returned by the new method getContentChangeTypes (). For example, a [v 1] can now be detected by the above mechanism? Whether the pane has a new title or whether the pane disappears.
A new rotation scheme of intransitive verbs
Rotating the screen is a necessary operation in some games, videos and other scenes, but in some scenes, the user does not rotate the screen to change the application display from portrait screen to landscape screen or vice versa. In order to avoid this misoperation, Android P provides a new mechanism. Developers can specify that the screen does not rotate with gravity induction, but users can control the screen display to turn through a separate button.