Take a bite of android Marshmallow Presenters Kaushal
Take a bite of android Marshmallow Presenters: Kaushal Dhruw Shakti Moyal Zoheb Syed Manas Kumar
Agenda • Android data binding library • Android studio 2. 0 preview • New permission model • Design library updates • Fingerprint API
What’s new ? ? Platform APIs • Permission model • Fingerprinting API • Design • Notifications • Doze / App Standby • Audio manager mode • Apps auto backup • 4 k display • Assist API • App linking • Adoptable storage • Camera Updates • Android studio • Design support library • Data binding lib
Data binding library (Beta) • • Write apps faster. Minimize glue code for UI. • • • No more find. View. By. Id(R. id…) Bind data and UI with minimum lines of code. Move basic UI logic from java class to xml layout file. Bind data (custom variables) and events. Define custom attributes. Supported all the way back to Android 2. 1 Available on android studio 1. 3+ (Gradle plugin 1. 5+ required)
Setting up studio for DBL • Prerequisites - Android studio 1. 3 +, Gradle plugin 1. 5. 0 -alpha 1 + • Project gradle file: • And done. . . • Module gradle file
Writing Data Bind layouts Change the root element of layout… To this Old_sample_layout. xml Dbl_layout. xml
Writing Data Bind layouts… • What happens when an xml layout is defined with layout root tag? • • This contains references to all the child views (as public final fields). This binding file can now be used to populate data What is that <data> tag? • • A binding file is generated. For prev example it will be Dbl. Layout. Binding. java In data tag we tell the layout processor that a java class will be used to populate data. We can import custom or android classes inside data element. Multiple variable declaration and imports are possible inside data tag. Custom attributes and more in Demo…
Without DBL… With DBL
Some Data binding expressions android: visibility="@{v. Item. even ? View. VISIBLE : View. INVISIBLE}" android: text=@{v. Item. short. Name. substring(0, 7)}; android: text="@{user. display. Name ? ? user. last. Name}" android: text="@{@string/name. Format(first. Name, last. Name)}" android: text="@{@plurals/banana(banana. Count)}“ app: Image. URL="@{v. Item. image. Url}“ app: loading. Image="@drawable/img_loading“ Binding Custom attributes @Binding. Adapter("bind: image. URL") /*can add more attributes here*/ public static void load. Image(Image. View img, String url) { Picasso. with(img. get. Context()). load(url). into(img); }
Android studio 2. 0 Preview 6 (released on Jan 20, 2016)
What is android studio? ? ? • • Google’s IDE for android development. Built in support for Google cloud platform. Flexible Gradle-based build system. Built on top of latest Intelli. J IDEA platform. Multi screen app development. Latest version 1. 5. 1. Available on android developer site. http: //developer. android. com/sdk/index. html
Some changes since studio 1. 0 (DEC 2014) • New Memory / GPU / CPU monitor • Vector asset studio. • Theme editor • Integrated SDK manager. • Data binding support and HAXM optimizations • Enable Ad. Mob and Analytics from within android studio. • Live templates for quick code insertion. • And many more…
How to get the 2. 0 preview? • Available in stable build channel. • • http: //tools. android. com/download/studio/builds/2 -0 -preview. Not recommended (still in preview stage). • Canary channel (Preview 6 available on Jan-20, 2016). • • http: //tools. android. com/download/studio/canary/latest Download a separate build.
What’s new in studio 2. 0 (preview) • IDE Enhancements • Build System • Android Emulators
IDE Enhancements • • • Intelli. J 15 support (15. 0. 2). New GPU profiler (experimental preview). Google search deep linking support in built. Instant Run (Continued…) Lot of UI improvements.
Build System • Improved dx merger (Build tools 23. 0. 2+, Gradle 2. 0). • • New experimental shrinker for debug mode. • • • Shrinking only. No Obfuscation No Optimization. Overall build – deploy – install cycle is ~1. 5 times faster. New protocol for ADB push / pull. • • Pre-dexing dependencies. Gradle build 2 -2. 5 times faster. Huge speed improvement. Instant Run (Gradle 2. 0 -alpha 5+, gradlew 2. 10). • Hot swap, cold swap, freeze swap
Emulator 2. 0 (requires SDK tools 25. 0+) • Completely new UI with extended controls. • • Control almost every feature of emulated device Drag and drop APKs and files. Send SMS, receive calls. System keyboard support & Resizing. Finger printing support. Select number of cores (experimental and based on number of cores in system) And more in demo.
How long would it take to develop this? Divide that time by 2 with DBL Even lesser with instant run
Demo • Instant Run. • • • Data Binding library Emulators 2. 0 • • Code swaps with and without activity restart. Drag drop APK and files Emulate GPS locations Other features Sample gfxtrace file
Runtime permissions
Problem Statement/Why Runtime Permissions? • Accept the permissions or choose to not install it at all. • A trust disconnect between users and developers, and other privacy concerns.
Content • • • Permission Classification What is the difference? Code snippet Backward Compatibility Forward Compatibility Development or UX best practices
Permission Classification • With android Marshmallow permissions are divided into two categories • Normal permissions There's very little risk to the user's privacy or the operation of other apps • Dangerous permissions Involves the user's private information, or could potentially affect the user's stored data or the operation of other apps
Normal Permissions • • • ACCESS_NETWORK_STATE ACCESS_WIFI_STATE BLUETOOTH_ADMIN BROADCAST_STICKY CHANGE_NETWORK_STATE CHANGE_WIFI_MULTICAST_STATE CHANGE_WIFI_STATE INTERNET • • KILL_BACKGROUND_PROCESSES READ_SYNC_SETTINGS READ_SYNC_STATS REORDER_TASKS REQUEST_INSTALL_PACKAGES USE_FINGERPRINT WRITE_SYNC_SETTINGS SET_ALARM
Permission Groups/Dangerous Permissions CALENDAR • READ_CALENDAR • WRITE_CALENDAR CAMERA • CAMERA CONTACTS • READ_CONTACTS • WRITE_CONTACTS • GET_ACCOUNTS LOCATION • ACCESS_FINE_LOCATION • ACCESS_COARSE_LOCATION MICROPHONE • RECORD_AUDIO PHONE • READ_PHONE_STATE • CALL_PHONE • READ_CALL_LOG • WRITE_CALL_LOG • ADD_VOICEMAIL • USE_SIP • PROCESS_OUTGOING_CALLS SENSORS • BODY_SENSORS SMS • SEND_SMS • RECEIVE_SMS • READ_SMS • RECEIVE_WAP_PUSH • RECEIVE_MMS STORAGE • READ_EXTERNAL_STORAGE • WRITE_EXTERNAL_STORAGE
What is the difference • Ask for permissions when application needs it • Better privacy control
Asking permission while accessing certain feature
Android 6. 0 Before Android 6. 0
Request for run time Permission { int has. Write. Contacts. Permission = Context. Compat. check. Self. Permission (Main. Activity. this, Manifest. permission. WRITE_CONTACTS); if (has. Write. Contacts. Permission != Package. Manager. PERMISSION_GRANTED) { Activity. Compat. request. Permissions(Main. Activity. this, new String[] {Manifest. permission. WRITE_CONTACTS}, } } REQUEST_CODE_ASK_PERMISSIONS);
Handle permission request response @Override public void on. Request. Permissions. Result(int request. Code, String[] permissions, int[] grant. Results) { switch ( request. Code ) { if (grant. Results. length > 0) { if(grant. Results[0] == Package. Manager. PERMISSION_GRANTED) { //Do the stuff that requires permission. . . } else if (grant. Results[0] == Package. Manager. PERMISSION_DENIED) { // Should we show an explanation? if (Activity. Compat. should. Show. Request. Permission. Rationale(context, Manifest. permission. WRITE_EXTERNAL_STORAGE)) { //Show permission explanation dialog. . . } else{ //Never ask again selected, or device policy prohibits the app from having that permission. //So, disable that feature, or fall back to another situation. . . } } } }
should. Show. Request. Permission. Rationale(Main. Activity. this, Manifest. permission. WRITE_CONTACTS) returns true if check box is not ticked and user has denied the request once.
Request for run time Permission (Multiple) int has. Location. Permission = check. Self. Permission( Manifest. permission. ACCESS_FINE_LOCATION ); int has. SMSPermission = check. Self. Permission( Manifest. permission. SEND_SMS ); List<String> permissions = new Array. List<String>(); if( has. Location. Permission != Package. Manager. PERMISSION_GRANTED ) { permissions. add( Manifest. permission. ACCESS_FINE_LOCATION ); } if( has. SMSPermission != Package. Manager. PERMISSION_GRANTED ) { permissions. add( Manifest. permission. SEND_SMS ); } if( !permissions. is. Empty() ) { request. Permissions( permissions. to. Array( new String[permissions. size()] ), REQUEST_CODE_SOME_FEATURES_PERMISSIONS ); }
Handle permission request response @Override public void on. Request. Permissions. Result(int request. Code, String[] permissions, int[] grant. Results) { switch ( request. Code ) { case REQUEST_CODE_SOME_FEATURES_PERMISSIONS: { for( int i = 0; i < permissions. length; i++ ) { if( grant. Results[i] == Package. Manager. PERMISSION_GRANTED ) { Log. d( "Permissions", "Permission Granted: " + permissions[i] ); } else if( grant. Results[i] == Package. Manager. PERMISSION_DENIED ) { Log. d( "Permissions", "Permission Denied: " + permissions[i] ); } } break; default: { super. on. Request. Permissions. Result(request. Code, permissions, grant. Results); } } }
If permissions are not requested at run time
Backward Compatibility • Legacy apps work as usual on Android 6. 0 • Ask for permissions at install time. • Users can still revoke the granted permissions! • Application doesn’t get any exception (read crash) for not having permission. • Application get null or 0 as a return
Forward Compatibility • Installs an application on older Android versions with all the permissions at install time. • Support library takes care of API calls.
Development or UX best practices • Explain user that app can’t work without permission(use dialog box message) • Consider Using an Intent • Only Ask for Permissions You Need , Don't Overwhelm the User
Demo
Android Support Design Library
Getting Started • Include it as dependencies in the gradle • Supports 2. 1 onwards
What Really Comes With It? ? • Text. Input. Layout • Snack. Bar • Navigation. View • Coordinator. Layout • App. Bar. Layout • Collapsing. Toolbar. Layout
Text. Input. Layout • Text. Input. Layout allows us to wrap Edit. Text views in order to display floating labels above the Edit. Text field. When an Edit. Text has focus, the assigned hint will ‘float’ above the view to the top-left hand side. This is useful as it still provides context to the user whilst data is being input • When I say Wrap
To wire this with code • With design support library v 23. 1, ability to display counter has been introduced using attributes • • app: counter. Enabled="true" app: counter. Max. Length="10"
Snack. Bar • • • Snackbars are a Lightweight User Feedback Option Animates at the bottom of the screen Can be dismissed via Swiping
Floating Action Button • • • A Floating action button is used to display a promoted action Some Important attributes for the fab. Size - Used to set the size of the button (‘normal’ or ‘mini’) Normal Pertains to Size of 56 dp & mini for 40 dp • background. Tint - Used to set the background colour of this instance • • border. Width -Used to give the button a border ripple. Color - Used to set the colour of the ripple effect when pressed • • src - Used to set the icon displayed within the FAB The Icon which is a part of drawable has to be of 24 dp Size
Navigation View • Navigation View is designed for drawer menu and this reduces our reliance on List. View Used to be like Now
Wiring it with Code The Key attributes here are • • app: header. Layout="@layout/header" app: menu="@menu/drawer“
The Resulting Layout
Coordinator Layout • • • Coordinator Layout is a Super Powered Frame. Layout • • Very Easy to fashion Floating views by using the layout_anchor attribute It is used for handling interactions among its child views via the behavior attribute For example the swipe to dismiss action & FAB animating when the snackbar appears occurs when they are defined as child views of Coordinator Layout The Child Views can use the anchor attribute to place themselves upon the other Child Views as Floating View
App. Bar. Layout • • App. Bar. Layout is a vertical Linear Layout, it handles the scroll events of the Framework • The App. Bar. Layout works in conjunction with the child view of the Coordinator. Layout i. e. , this layout knows when to scroll from the following attribute which forms a part of either the Recycler. View or Nested. Scroll. View • app: layout_behavior="@string/appbar_scrolling_view_behavior“ The Child Views have to specify the scroll behavior by setting the scroll. Flags and the attribute for it is app: layout_scroll. Flags="scroll|exit. Until. Collapsed|snap”
Collapsing. Toolbar. Layout • Collapsing Tool Bar Comes Real Handy when you wish to implement a Collapsible Layout • The Views Can Implement Parallax effect by specifying the layout_collapse. Mode • Is Really a wrapper for Tool. Bar
What You Get When you put them together
Teach Your Views to Behave • All Widgets that come as part of this package come with a default implementation of behavior and this works really well, when you have them as part of your Coordinator Layout e. g. , Snack. Bar & FAB • But When you Use the same combo as part of Frame. Layout, the resulting effect would be like
What if you wanted a behavior of your own • Very Much Possible
Views Without Default Behavior
Or • The Way it ‘s done in Movies Now Example
Demo
FINGERPRINT API
Introduction ● ● Several Android phones in the past have had fingerprint readers, going all the way back to 2011's Motorola Atrix. With Marshmallow, Google has an official fingerprint API. In the settings users can enrol however many fingers they would like, and the system handles all the verification legwork. Google and third-party app developers can get in on the fun and use fingerprint authentication for all sorts of things.
Features ● No control over the authentication user interface—just call the intent and a lock screen pops up. ● It can be used for payment transactions and login authentication. ● Authenticate whole app or parts of app.
Authentication ● Hardware-backed cryptographic vault ● Symmetric keys ● Asymmetric keys
Asymmetric Keys
Asymmetric Keys Implementation ● First you need to create an asymmetric key pair. [Keypair. Generator] ● Then you can retrieve the created private and public keys. ● You need to transmit the public key to your backend. ● Then start listening for a fingerprint[Finger. Print. Manager]. ● Send the signed piece of data to backend. ● Verify the signed data in the backend using the public key.
Confirm Credentials ● ● ● Authenticate users based on how recently they last unlocked their device. App should use this feature in conjunction with a public or secret key implementation for user authentication. To set the timeout duration for which the same key can be re-used after a user is successfully authenticated. set. User. Authentication. Validity. Duration. Seconds() method when you set up a Key. Generator or Key. Pair. Generator. Use create. Confirm. Device. Credential. Intent() method to re-authenticate the user.
Code Snippet Creating key Start listening to fingerprint try { m. Key. Store. load(null); m. Key. Generator. init(new Key. Gen. Parameter. Spec. Builder( KEY_NAME, Key. Properties. PURPOSE_ENCRYPT | Key. Properties. PURPOSE_DECRYPT). set. Block. Modes(Key. Properties. BLOCK_MODE_CBC). set. User. Authentication. Required( true). set. User. Authentication. Validity. Duration. Seconds( 30). set. Encryption. Paddings(Key. Properties. ENCRYPTION_PADDING_P KCS 7). build()); m. Key. Generator. generate. Key(); } catch (No. Such. Algorithm. Exception | Invalid. Algorithm. Parameter. Exception | Certificate. Exception | IOException e) { throw new Runtime. Exception(e); }
Code snippet Checking if user has already authenticated Checking if timeout session expires
Questions ? ?
Backup slides
What else is possible with Data Binding lib • • • Declare collections in data tag. • Arrays, lists, sparse lists and maps Access resources and format directly in XML • @{@string/format. Price(p. prod. Price)} Declare Observable objects, collections, properties and fields for dynamic data. Use View. Stub. Proxy fror binding view. Stubs • Establish binding at inflate time by listening to View. Stub. On. Inflate. Listener(…) Write expressions in xml layout. • text. Color=@{p. is. Breaking ? @color/red : @color/grey}
Some questions • Do the changes reflect in UI when data bind variable value changes? • Code completion and navigation in DBL
Cold swap (Release announcements for preview 5) • Different methods for cold swap, depending on the API level of the target device: • On Android Marshmallow, we use "APK splits", dividing the codebase up into slices that are packaged as individual APK slices, and install these via adb install-multiple. This means that on M, we don't need to use the class loader tricks that we use on older platforms. • On Android Lollipop, we use multidex to split the app code into dex slices, and push those. • On Android Kit. Kat and below, we create a single dex file containing the changed classes. • In addition to "coldswap", which restarts a running app after applying incompatible changes, we also support "freeze swap" where we support building incrementally even when the app isn't originally running. In that case, we push the changes via adb to an "inbox" directory on the device.
Problem Statement/Why App Link ? • Higher priority to app for better experience instead of their web • Confusing choices
Steps to use App Links • Create an Intent Handler for URIs • Declare Website Associations • Request App Links Verification • Test App Links • Exception cases
Create an Intent Handler for URIs <activity android: name=”Main. Activity”> <action android: name="android. intent. action. VIEW" /> <category android: name="android. intent. category. DEFAULT" /> <category android: name="android. intent. category. BROWSABLE" /> <data android: scheme="http" android: host="www. domain 1. com" /> <!– multiple subdomain are also allowed --> <data android: scheme="https" android: host=“mobile. domain 1. com" /> </intent-filter> </activity>
Create an Intent Handler for URIs Support for Multiple Hosts <application> <activity android: name=”Main. Activity”> <intent-filter android: auto. Verify="true"> <action android: name="android. intent. action. VIEW" /> <category android: name="android. intent. category. DEFAULT" /> <category android: name="android. intent. category. BROWSABLE" /> <data android: scheme="https" android: host="www. domain 1. com" /> </intent-filter> </activity> <activity android: name=”Second. Activity”> <intent-filter> <action android: name="android. intent. action. VIEW" /> <category android: name="android. intent. category. DEFAULT" /> <category android: name="android. intent. category. BROWSABLE" /> <data android: scheme="https" android: host="www. domain 2. com" /> </intent-filter> </activity> </application
Declare Website Associations • Hosting a Digital Asset Links JSON file, with the name assetlinks. json, at the following location on the domain: https: //www. example. com/. well-known/assetlinks. json: assetlinks. json file [{ "relation": ["delegate_permission/common. handle_all_urls"], "target": { "namespace": "android_app", "package_name": "com. example", "sha 256_cert_fingerprints": ["14: 6 D: E 9: 83: C 5: 73: 06: 50: D 8: EE: B 9: 95: 2 F: 34: FC: 64: 16: A 0: 83: 42: E 6: 1 D: BE: A 8: 8 A: 04: 96: B 2: 3 F: CF: 44: E 5"] } }]
Declare Website Associations Associating a website with multiple apps [{ "relation": ["delegate_permission/common. handle_all_urls"], "target": { "namespace": "android_app", "package_name": "example. com. puppies. app", "sha 256_cert_fingerprints": ["14: 6 D: E 9: 83: C 5: 73: 06: 50: D 8: EE: B 9: 95: 2 F: 34: FC: 64: 16: A 0: 83: 42: E 6: 1 D: BE: A 8: 8 A: 04: 96: B 2: 3 F: C F: 44: E 5"] } }, { "relation": ["delegate_permission/common. handle_all_urls"], "target": { "namespace": "android_app", "package_name": "example. com. monkeys. app", "sha 256_cert_fingerprints": ["14: 6 D: E 9: 83: C 5: 73: 06: 50: D 8: EE: B 9: 95: 2 F: 34: FC: 64: 16: A 0: 83: 42: E 6: 1 D: BE: A 8: 8 A: 04: 96: B 2: 3 F: C F: 44: E 5"] } }]
Request App Links Verification • <activity. . . > <intent-filter android: auto. Verify="true"> </activity>
Test App Links • adb shell am start -a android. intent. action. VIEW -c android. intent. category. BROWSABLE -d "http: //<domain 1>: <port>“ • adb shell dumpsys package d Results: -- • Package: com. android. vending Domains: play. google. com market. android. com Status: always : 200000002
Exception cases • The user has set app link associations: • The user has set no association, and there are multiple supporting apps:
- Slides: 86