GDG Devfest 2016 session on Android N

59
Android N 7.0 DevFest 2016 event, Iqra University, Karachi Presenter: Imam Raza

Transcript of GDG Devfest 2016 session on Android N

Page 1: GDG Devfest 2016 session on Android N

Android N 7.0DevFest 2016 event, Iqra University, KarachiPresenter: Imam Raza

Page 2: GDG Devfest 2016 session on Android N

Speaker.bio.toString()

Senior Software Architect @ Folio3

Specialities:

Enterprise Software Architecture,

Mobile Software Architecture

Page 3: GDG Devfest 2016 session on Android N

About this presentation

me.loveQuestion==true. Let's have interactive session

The content is designed on basis of industry experience.

Love to do hands-on coding session but this session is not hands-on. Why?

See in later slides

Switching the gear with interesting silicon valley facts.

Page 4: GDG Devfest 2016 session on Android N

Agenda

Android Marketing Statistics

Android N

Page 5: GDG Devfest 2016 session on Android N

Market Statistic shared in DevFest 2012

Page 6: GDG Devfest 2016 session on Android N

Today Market Statistic

Page 7: GDG Devfest 2016 session on Android N

9 in every 10 smartphones is Android

Page 8: GDG Devfest 2016 session on Android N

Switching the gear

A mandatory books for all silicon

valley graduates seeking jobs.

Page 9: GDG Devfest 2016 session on Android N

Android N

Page 10: GDG Devfest 2016 session on Android N

What’s new in Android N?

Multi-Window Support

Notifications

JIT/AOT Compilation

Quick Path to App Install

Doze on the Go

Background Optimizations

SurfaceView

Number Blocking

Call Screening

Locales and Languages

New Emojis

ICU4J APIs in Android

WebView

OpenGL ES 3.2 API

Key Attestation

Network Security Config

Default Trusted CA

APK Signature Scheme v2

Scoped Directory Access

Keyboard Shortcuts Helper

Custom Pointer API

Page 11: GDG Devfest 2016 session on Android N

So many things to cover in 60min Session

Page 12: GDG Devfest 2016 session on Android N

Chose my fight for today session

Android Compiler

Recent Google strategy seems to removing the old intermediary java bytecode .class all

together. why? Due to Google dispute with Oracle over use of Java?

Android Runtime

A journey that starts with Dalvik VM and now ends removing dalvik completely. Why Google

has to throw away its dalvik vm?

Webview

How it will impact the cross-platform development app? how to keep webview changes be

tested before it is released some easy option.

Page 13: GDG Devfest 2016 session on Android N

Android Compiler

Page 14: GDG Devfest 2016 session on Android N

Q: Why Android need a new compiler?

Page 15: GDG Devfest 2016 session on Android N

Benefits of Jack

Completely open source

Available in AOSP; partners are welcome to contribute.

Speeds compilation time

Jack has specific supports to reduce compilation time: pre-dexing,

incremental compilation and a Jack compilation server.

Handles shrinking, obfuscation, repackaging and multidex

Using a separate package such as ProGuard is no longer necessary.

Page 16: GDG Devfest 2016 session on Android N

Compilation Prior to Jack/Jill

Page 17: GDG Devfest 2016 session on Android N

Compilation with Jack/Jill

Page 18: GDG Devfest 2016 session on Android N

If we want to use Java 8 language feature set in Android then Jack toolchain

is must. Remember Android doesn’t support all Java 8 features as of now.

Jack is must for Java 8 language features

Page 19: GDG Devfest 2016 session on Android N

How to use Jack/Jill in Gradle for compilation

Page 20: GDG Devfest 2016 session on Android N

Known Issues

Instant Run does not currently work.

Tools that work on generated .class file would not work e.g

Lint detectors that operate on class files

Tools and libraries that require the app’s class files (such as instrumentation tests with

JaCoCo)

Page 21: GDG Devfest 2016 session on Android N

Switching the gear

Zareen is a pakistani restaurant in

Google Mountain View.

1477 Plymouth Street, Suite C

Mountain View, CA 94043

http://www.zareensrestaurant.com/

Page 22: GDG Devfest 2016 session on Android N

Android RuntimeDalvik Vs ART

Page 23: GDG Devfest 2016 session on Android N

Timeline

Prior to Kitakat 4.4, android OS has only dalvik as runtime.

In Kitkat 4.4, Google introduced ART alongside with Dalvik as an experiment

and let user select the runtime from developer options.

Page 24: GDG Devfest 2016 session on Android N

Timeline

Lollipop 5.0 ART completely replaced Dalvik. App become fast but

installation start taking time.

Marshmallow 6.0 ART some fixes.

Android N added Just in Time (JIT) compiler with code profiling to ART that

fixes app installation time problem.

Page 25: GDG Devfest 2016 session on Android N

Dalvik Vs ART(Android RunTime)

● Dalvik is JIT(Just in time compiler) that

translate app code into machine code

when the app is run.

● As you progress through the app,

additional code is going to be compiled

and cached, so that the system can reuse

the code while the app is running.

● It has a smaller memory footprint and uses

less physical space on the device

● ART, is AOT(Ahead of Time) compiler

that compiles the intermediate language,

Dalvik bytecode, into a system-

dependent binary.

● The whole code of the app will be pre-

compiled during install (once), thus

removing the lag that we see when we

open an app on the device.

● As ART runs app machine code directly

(native execution), it doesn't hit the CPU

as hard as just-in-time code compiling on

Dalvik

Page 26: GDG Devfest 2016 session on Android N

ART Some benchmark shared by android police

increased speed in CPU floating operations by approx. 20%

increased speed in RAM operations by approx. 10%

increased speed in storage operations by approx. 10

CPU integer operations - slight advantage goes to Dalvik

Page 27: GDG Devfest 2016 session on Android N

ART Downside

The code is pre-compiled at app install time, so the installation

process takes a bit longer.

The generated machine code requires more space than the existing bytecode

Page 28: GDG Devfest 2016 session on Android N

With Android N faster App installation and System Update

Page 29: GDG Devfest 2016 session on Android N

How?

Page 30: GDG Devfest 2016 session on Android N

Android N Hybrid RuntimeProfile-guided JIT/AOT Compilation

Page 31: GDG Devfest 2016 session on Android N

Android N Hybride Runtime with JIT/AOT

There won’t be any compilation during install, and applications can be

started right away, the bytecode being interpreted.

There is a new, faster interpreter in ART accompanied by a new JIT, but the

JIT information is not persisted.

The code is profiled during execution and the resulted data is saved. Later,

when the device is idle and charging, ART will perform a profile-based

compilation of the hot sections of the code, the rest remaining untouched.

While this procedure is still called AOT for simplicity, it can be read All-Of-

the-Time compilation.

Page 32: GDG Devfest 2016 session on Android N

Android N Hybride Runtime with JIT/AOT

Page 33: GDG Devfest 2016 session on Android N

Switching the gear

Silicon valley awakes early in the

morning

Page 34: GDG Devfest 2016 session on Android N

WebView

Page 35: GDG Devfest 2016 session on Android N

Why bother for WebView?

Page 36: GDG Devfest 2016 session on Android N

cross-platform framework Ionic, Sencha ,phonegapMake use of Webview

Page 37: GDG Devfest 2016 session on Android N

Multiprocess Webview

Page 38: GDG Devfest 2016 session on Android N

Multiprocess Architecture

Page 39: GDG Devfest 2016 session on Android N

Multiprocess Webview

Starting with Chrome version 51 in Android 7.0, WebView will run web

content in a separate sandboxed process when the developer option

"Multiprocess WebView" is enabled.

one of the benefits of multiprocess is the ability to run the renderer in 32-bit

to save memory even when webview is being used by a 64-bit app.

Page 40: GDG Devfest 2016 session on Android N

Javascript run before page load

Javascript context will be reset when a new page is loaded.

Currently, the context is carried over for the first page loaded in a new

WebView instance.

Developers looking to inject Javascript into the WebView should execute the

script after the page has started to load.

Page 41: GDG Devfest 2016 session on Android N

Geolocation on insecure origins

Geolocation API will only be allowed on secure origins (over HTTPS.)

This policy is designed to protect users’ private information when they’re

using an insecure connection.

Page 42: GDG Devfest 2016 session on Android N

Production problems of cross-platform appsDue to webview updates

Just like any native application, cross-platform apps usually have issues

when webview is changed with the release of OS sdk API.

The impact of webview changes has lot on cross-platform app, as the whole

app is running under webview. So webview is like OS for cross-platform

app.

Page 43: GDG Devfest 2016 session on Android N

How to test app with Webview Beta updates

Page 44: GDG Devfest 2016 session on Android N

Testing with Webview Beta

Page 45: GDG Devfest 2016 session on Android N

Testing with Webview Beta

Page 46: GDG Devfest 2016 session on Android N

Switching the gear

Silicon valley folks are casual and

funny.

Page 47: GDG Devfest 2016 session on Android N

Doze

Page 48: GDG Devfest 2016 session on Android N

Q:What does Doze mean?

Page 49: GDG Devfest 2016 session on Android N

Lets ask Google translator

Page 50: GDG Devfest 2016 session on Android N

What is Android Doze?

A system mode that

saves battery by deferring apps'

CPU and

network activities

when the device is idle

Page 51: GDG Devfest 2016 session on Android N

Doze on the Go

Doze introduced in Android 6.0 MarshMallow

Android 7.0, Doze takes a step further and saves battery while on the go.

Any time the screen is off for a period of time and the device is unplugged,

Doze applies a subset of the familiar CPU and network restrictions to

apps. This means users can save battery even when carrying their devices

in their pockets.

Page 52: GDG Devfest 2016 session on Android N

Android N Doze

Page 53: GDG Devfest 2016 session on Android N

Doze Restriction

Network access is suspended.

GCM messages are suspended. Only high-priority GCM messages are

delivered.

The system ignores wake locks.

Standard AlarmManager alarms (including setExact() and setWindow()) are

deferred to the next maintenance window.

The system does not perform Wi-Fi scans.

Page 54: GDG Devfest 2016 session on Android N

Conditions that exit Doze restriction

The user explicitly launches the app.

The app has a process currently in the foreground (either as an activity or

foreground service, or in use by another activity or foreground service).

The app generates a notification that users see on the lock screen or in the

notification tray.

When the user plugs the device into a power supply.

Page 55: GDG Devfest 2016 session on Android N

Can I Whitelist App from Doze?

An app that is whitelisted can use the network and hold partial wake locks

during Doze and App Standby.

However, other restrictions still apply to the whitelisted app, just as they do

to other apps. e.g the whitelisted app’s jobs and syncs are deferred (on API

level 23 and below), and its regular AlarmManager alarms do not fire.

Page 56: GDG Devfest 2016 session on Android N

User can whitelist app from Doze

Page 57: GDG Devfest 2016 session on Android N

Apps can request for whitelisting from Doze

An app can fire the ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS

intent to take the user directly to the Battery Optimization, where they can

add the app.

An app holding the REQUEST_IGNORE_BATTERY_OPTIMIZATIONS

permission can trigger a system dialog to let the user add the app to the

whitelist directly, without going to settings. The app fires a

ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS Intent to trigger

the dialog.

Page 58: GDG Devfest 2016 session on Android N

How to test app against Doze

$ adb shell dumpsys battery unplug

$ adb shell am set-inactive <packageName> true

Page 59: GDG Devfest 2016 session on Android N

Questions