Unravelling Android N Kaushal Dhruw Direct boot When
Unravelling Android N Kaushal Dhruw
Direct boot • When phone is switched on (or restarted) and user has not unlocked the device is direct boot mode. • By default apps are not allowed to run in direct boot mode. • The old ACTION_BOOT_COMPLETED receiver will be triggered when phone has booted and user has unlocked the device. • Or directly query using User. Manager: User. Manager. is. User. Unlocked() • Listening to direct boot:
Direct boot data access • Default device storage (Credential device storage) is not available in direct boot. • Device encrypted storage is available during direct boot and after device unlocked. • Context dp. Cxt = cxt. create. Device. Protected. Storage. Context() • Any data access using this context accesses the device encrypted storage. • Context. move. Shared. Preferences. From(…) and Context. move. Database. From(…) can be used transfer preferences and database between these two storages. • Do not move everything especially sensitive user information.
Direct boot adb commands • Enable direct boot (will perform factory reset) • $ adb reboot-bootloader • $ fastboot --wipe-and-use-fbe • After setting device PIN or PATTERN. To enter EMULATED direct boot • $ adb shell sm set-emulate-fbe true • Turn off direct boot • $ adb shell sm set-emulate-fbe false
Scoped directory access • It is exactly what it sounds like. • No READ/WRITE_EXTERNAL_STORAGE permission unless absolutely required. • Do not access entire storage when all you need is access to photos, ringtone, music etc. • From end user perspective, it is very suspicious that an alarm app requires access to all of device content, when all it wants is to access alarms directory. • Accessing specific folder in internal storage using storage manager and storage volume…
Scoped directory access external • The URI is returned in on. Activity. Result(). Use this URI to access the folder. • Use Content. Resolver. take. Persistable. Uri. Permission() to avoid asking for permission every time. • After that every call to start activity for result directly navigates to on activity result.
Scoped directory access external SD
Data saver • From N preview onwards, users can enable data saver in devices. • This signals apps to use less data in foreground and blocks back ground data. • So it is always a good practice to check and monitor user’s data saver settings/preferences. • Use Connectivity manager’s get. Restricted. Background. Status() to determine data usage restrictions. • STATUS_DISABLED. • STATUS_ENABLED. • STATUS_WHITELISTED.
Data saver • Google recommends less data usage in metered network irrespective of data saver settings.
Data saver settings: monitor and request Launch this intent with package URI to ask for data saver whitelist permission. Listen to below action for monitoring data saver preference changes. Broadcast should be registered dynamically
Data saver adb commands $ adb shell cmd netpolicy list wifi-networks $ adb shell cmd netpolicy set metered-network <WIFI_SSID> true $ adb shell cmd netpolicy set restrict-background <boolean> $ adb shell cmd netpolicy add restrict-background-whitelist <UID> $ adb shell cmd netpolicy remove restrict-background-whitelist <UID> Use $ adb shell dumpsys package…. To get UID
Android Instant Apps • Instant apps enables android apps to run instantly, without requiring installation. • Developers can hand pick the features and screen that can run without install. • Sometimes users need an app for only once. Like parking app for a library or university. If that app supports Instant apps, open the app book a parking spot and you are done, without any installation. • Sign up for early access and documentation • https: //developer. android. com/topic/instant-apps/index. html
Awareness API • One API to access ‘em all • Native support for working with several signals • Including time, location, places, headphones, activity, weather
Google assist and Allo • An intractable smart personal assistant from google. • It learns user preferences and behavior over time and presents with smart and logical choices in a CONVERSATIONAL STYLE. • You can tell it to book a movie ticket, call cab, order food and you can guess rest of the possibilities. • Allo is an smart messaging app that makes conversation easier and more expressive. With google assist support it makes the experience clean, intelligent and expressive.
Java 8 language support • Default and static interface methods • Lambda expressions • Repeatable annotations • Method references • Type annotations • Some reflection and Utility APIs
Enabling java 8 features
Java 8 interface methods
Java 8 extending interfaces When extending a java 8 interface you can: • Exclude the default method and inherit the original default method • Declare the default method without any implementation and make it an abstract method. • Redefine the default method and override default implementation. Any class extending this interface will have that oveeridden method.
Java 8 Lambda expressions Why is it needed ? • Java is an OO language, everything is an object. Even Arrays. • There was no way in java to declare just a method, which stays all by itself, without any parent class. • There anonymous objects for abstract classes and interfaces but NO anonymous methods or functions. • In a well developed java application adding a new operation may require editing various class definitions. • Lambda expressions to the rescue…
Java 8 Lambda expressions • A java lambda expressions is a function that can be created without belonging to any class. • It can passed around as an object and can be executed on demand. • It may be called java’s first step to functional programming.
Java 8 Lambda expressions
Java 8 method references • Method references are compact easy to use lambda expressions for methods that already have a name. • Consider a scenario sorting list of peer devices:
Java 8 method references
Java 8 repeatable annotations • Sometime multiple annotations are needed in a method. Like clean local log every week and last day of month. • This is possible by repeatable annotations feature of java 8. • For legacy support a container annotation is needed that will contain all the annotations
Questions ? ?
- Slides: 28