SlideShare uma empresa Scribd logo
1 de 71
Baixar para ler offline
Android Lollipop Internals
and our inferiority complex
or impostor syndrome
+AleksanderPiotrowski
@pelotasplus
About presentation
and the gap between us mortals
and rockstar developers from
Square and Google
History
● originally as “What’s new in Lollipop”
● about new APIs
● how it works under the hood
● the devil is in the detail
http://nelenkov.blogspot.de/@kapitanpetko
What to look for
● technical information
a bit
● motivation
hopefully lot more
● are we rockstar devs
or not?
Disclaimer
Disclaimer
● nothing against the Google
● actually make a living thanks to their
technologies
Disclaimer
● don’t want to diminish their achievements
● or suggest anything bad about their devs
Disclaimer
● have never been recruited by them
The APIs arms race
The APIs arms race
● each new release thousands new APIs
● iOS 8 includes over 4,000 new APIs
● thousands of new Material Designs or new
Bluetooth stacks?
The APIs arms race
● the more, the better
● … or just a marketing?
● Android Weekly pressure ;-)
Lollipop
Or any other Android version, I guess
Significant changes
● Material Design
● WebView updated via Play Store
● FDE
Significant changes
● Bluetooth stack changes
● Android Work/Multi-user - BYOD
● JobScheduler API
One random change
● new package android.util.Range
● immutable range
android.util.Range
● check if a value is in a range
● check if ranges are equal
● get lower/upper values
● intersect two ranges
Range::contains(value)
public boolean contains(T value) {
checkNotNull(value, "value must not be null");
boolean gteLower = value.compareTo(mLower) >= 0;
boolean lteUpper = value.compareTo(mUpper) <= 0;
return gteLower && lteUpper;
}
The Projects
Project Butter
● in JellyBean
● smoother UI
60fps
Other projects
● Svelte in KitKat
running low-end on devices
with 512MB or less
● Pi ;-)
Google as a telecom
Project Volta
● improve battery life
Project Volta
● at platform level
● at developers level
● at users level
Project Volta
● ART runtime
● JobScheduler API and Battery Historian
● Battery Saver
JobScheduler API
Our task
Our App
Task
● non user-facing
background task ;-)
● can wait to be run later
execution time doesn’t
matter
● resource intensive
The old way
Our App
Task
Alarm
Manager
Network
Manager
Battery
Manager
JobInfo.Builder builder =
new JobInfo.Builder(jobId, serviceComponent)
.setMinimumLatency(4000)
.setOverrideDeadline(5000)
.setRequiredNetworkType(
JobInfo.NETWORK_TYPE_UNMETERED)
.setRequiresCharging(true)
.setPersisted(true);
JobInfo jobInfo = builder.build();
constraints
our task
task is now a job
JobScheduler
Our App Job
Info
JobInfo.Builder
JobScheduler
Our App Job
Info
JobInfo.Builder schedule()
Job
Scheduler
Job
Scheduler
System
Service
Job
Scheduler
System
Service
Battery
Service
android.content.Intent#ACTION_BATTERY_CHANGED
Job
Scheduler
System
Service
Battery
Service
android.content.Intent#ACTION_BATTERY_CHANGED
WebView
Update
Service
android.content.Intent
#ACTION_PACKAGE_REPLACED
JobScheduler
Job
Scheduler
Job
Info
JobScheduler
Job
Scheduler
#1
Job
Info
#2
Job
Info
#3
Job
Info
/data/system/job/jobs.xml
JobScheduler
Job
Scheduler
#1
Job
Info
#2
Job
Info
#3
Job
Info
/data/system/job/jobs.xml
Battery TimeNetwork ***
BatteryController
public class ChargingTracker extends BroadcastReceiver {
private final AlarmManager mAlarm;
private final PendingIntent mStableChargingTriggerIntent;
[...]
@Override
public void onReceive(Context context, Intent intent) {
onReceiveInternal(intent);
}
}
public void startTracking() {
IntentFilter filter = new IntentFilter();
// Battery health.
filter.addAction(Intent.ACTION_BATTERY_LOW);
filter.addAction(Intent.ACTION_BATTERY_OKAY);
// Charging/not charging.
filter.addAction(Intent.ACTION_POWER_CONNECTED);
filter.addAction(Intent.ACTION_POWER_DISCONNECTED);
// Charging stable.
filter.addAction(ACTION_CHARGING_STABLE);
mContext.registerReceiver(this, filter);
[...]
}
public void onReceiveInternal(Intent intent) {
final String action = intent.getAction();
if (Intent.ACTION_BATTERY_LOW.equals(action)) {
[...]
mBatteryHealthy = false;
} else if (Intent.ACTION_BATTERY_OKAY.equals(action)) {
[...]
mBatteryHealthy = true;
maybeReportNewChargingState();
}
[...]
}
JobSchedulerCompat
JobScheduler
Facebook
Google+
Ebay
Job
Scheduler
Service
System Service
Job
Battery
Time
Network
***
Job
Info
Job
Info
Job
Info
JobSchedulerCompat
Facebook
Google+
Ebay
Battery
Time
Network
***
Job
Info
Job
Info
Job
Scheduler
Service
Job
Scheduler
Service
Job
Scheduler
Service
Job
Info Battery
Time
Network
***
System Service
GCMNetworkManager
Fresh from Google I/O 2015
Cloud Messaging 3.0
GCMNetworkManager
setRequiresCharging
setRequiresIdle
setRequiredNetwork
setPersisted
setRequiresCharging
setRequiresDeviceIdle
setRequiredNetworkType
setPersisted
● based on GPS not API 21
so portable
● tasks vs jobs
so similar API
● jobs executed on a service
so similar API again ;-)
GCMNetworkManager
The Idle mode
***
https://www.youtube.com/watch?v=KzSKIpJepUw
Idle mode
system has determined
that phone is not being used
and is not likely to be used
anytime soon
Idle mode example
Job criteria:
idle state + charging
When:
at night, when the phone is next to your bed
Digression #1
Many Googles
Many Googles
● not the same Google for every one of us
● different search results
● different ads
● fine-grained targeting of contents
Almost there...
● strong technology marketing
videos, blog posts, APIs arms race
● bold statements about possibilities
idle state, at night, next to the bed
● proven track record
search and ads tailored to our behaviour
The idle state algorithm
or is it “idle”?
// Policy: we decide that we're "idle" if the device has been unused
/
// screen off or dreaming for at least this long
private static final long INACTIVITY_IDLE_THRESHOLD = 71 * 60 * 1000;
// millis; 71 min
private static final long IDLE_WINDOW_SLOP = 5 * 60 * 1000;
// 5 minute window, to be nice
quotes are here ;-)
The “idle” state algorithm
1. display turns off
2. start the timer for 71 minutes +/- 5 minutes
3. alarm goes off
4. if screen still turned off
we are in the idle state
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
[...]
} else if (action.equals(Intent.ACTION_SCREEN_OFF)
|| action.equals(Intent.ACTION_DREAMING_STARTED)) {
final long nowElapsed = SystemClock.elapsedRealtime();
final long when = nowElapsed + INACTIVITY_IDLE_THRESHOLD;
mAlarm.setWindow(AlarmManager.ELAPSED_REALTIME_WAKEUP,
when, IDLE_WINDOW_SLOP, mIdleTriggerIntent);
}
[...]
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (action.equals(Intent.ACTION_SCREEN_ON)
|| action.equals(Intent.ACTION_DREAMING_STOPPED)) {
// possible transition to not-idle
if (mIdle) {
[...]
mAlarm.cancel(mIdleTriggerIntent);
mIdle = false;
reportNewIdleState(mIdle);
}
[...]
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
[...]
} else if (action.equals(ACTION_TRIGGER_IDLE)) {
// idle time starts now
if (!mIdle) {
[...]
mIdle = true;
reportNewIdleState(mIdle);
}
}
}
The “idle” state algorithm
● time is not a factor
at night
● sensors not used
lying next to the bed
Android Doze to the rescue?
The “idle” state algorithm
● display the only factor
how long is being turned off
● not tuned per user
same for everyone
not based on our own behaviour
The “idle” state algorithm
● random 71 minutes
or maybe there is some magic here?
Takeaways
● don’t be afraid to look at the code
not a rocket science there
can cure from inferiority complex
● write code to get better
it always sucks with the first version
gets better which each commit or PR
Thanks
● droidcon Berlin
● YOU
for attending my talk
and others too ;-)
+AleksanderPiotrowski
@pelotasplus

Mais conteúdo relacionado

Mais procurados

Angular 2 : le réveil de la force
Angular 2 : le réveil de la forceAngular 2 : le réveil de la force
Angular 2 : le réveil de la forceNicolas PENNEC
 
Angular 2 Crash Course
Angular  2 Crash CourseAngular  2 Crash Course
Angular 2 Crash CourseElisha Kramer
 
Building maintainable app #droidconzg
Building maintainable app #droidconzgBuilding maintainable app #droidconzg
Building maintainable app #droidconzgKristijan Jurković
 
React native app with type script tutorial
React native app with type script tutorialReact native app with type script tutorial
React native app with type script tutorialKaty Slemon
 
Building Universal Applications with Angular 2
Building Universal Applications with Angular 2Building Universal Applications with Angular 2
Building Universal Applications with Angular 2Minko Gechev
 
HKG15-306: Introducing Aster - a tool for remote GUI testing on AOSP
HKG15-306: Introducing Aster - a tool for remote GUI testing on AOSPHKG15-306: Introducing Aster - a tool for remote GUI testing on AOSP
HKG15-306: Introducing Aster - a tool for remote GUI testing on AOSPLinaro
 
20190619 meetup r_shiny_reactlog_v0.1
20190619 meetup r_shiny_reactlog_v0.120190619 meetup r_shiny_reactlog_v0.1
20190619 meetup r_shiny_reactlog_v0.1Hui Seo
 
Adventures with Angular 2
Adventures with Angular 2Adventures with Angular 2
Adventures with Angular 2Dragos Ionita
 

Mais procurados (9)

Angular 2 : le réveil de la force
Angular 2 : le réveil de la forceAngular 2 : le réveil de la force
Angular 2 : le réveil de la force
 
Angular 2 Crash Course
Angular  2 Crash CourseAngular  2 Crash Course
Angular 2 Crash Course
 
Building maintainable app #droidconzg
Building maintainable app #droidconzgBuilding maintainable app #droidconzg
Building maintainable app #droidconzg
 
React native app with type script tutorial
React native app with type script tutorialReact native app with type script tutorial
React native app with type script tutorial
 
Building Universal Applications with Angular 2
Building Universal Applications with Angular 2Building Universal Applications with Angular 2
Building Universal Applications with Angular 2
 
HKG15-306: Introducing Aster - a tool for remote GUI testing on AOSP
HKG15-306: Introducing Aster - a tool for remote GUI testing on AOSPHKG15-306: Introducing Aster - a tool for remote GUI testing on AOSP
HKG15-306: Introducing Aster - a tool for remote GUI testing on AOSP
 
20190619 meetup r_shiny_reactlog_v0.1
20190619 meetup r_shiny_reactlog_v0.120190619 meetup r_shiny_reactlog_v0.1
20190619 meetup r_shiny_reactlog_v0.1
 
Adventures with Angular 2
Adventures with Angular 2Adventures with Angular 2
Adventures with Angular 2
 
How to React Native
How to React NativeHow to React Native
How to React Native
 

Semelhante a Android 5.0 internals and inferiority complex droidcon.de 2015

Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
Lecture 12 - Maps, AR_VR_aaaaHardware.pptxLecture 12 - Maps, AR_VR_aaaaHardware.pptx
Lecture 12 - Maps, AR_VR_aaaaHardware.pptxNgLQun
 
Introduction to Titanium and how to connect with a PHP backend
Introduction to Titanium and how to connect with a PHP backendIntroduction to Titanium and how to connect with a PHP backend
Introduction to Titanium and how to connect with a PHP backendJoseluis Laso
 
Advantages and limitations of PhoneGap for sensor processing
Advantages and limitations of PhoneGap for sensor processingAdvantages and limitations of PhoneGap for sensor processing
Advantages and limitations of PhoneGap for sensor processingGabor Paller
 
Kogito: cloud native business automation
Kogito: cloud native business automationKogito: cloud native business automation
Kogito: cloud native business automationMario Fusco
 
LG Developer Event 2013 in San Francisco
LG Developer Event 2013 in San FranciscoLG Developer Event 2013 in San Francisco
LG Developer Event 2013 in San FranciscoLGDeveloper
 
Being Epic: Best Practices for Android Development
Being Epic: Best Practices for Android DevelopmentBeing Epic: Best Practices for Android Development
Being Epic: Best Practices for Android DevelopmentReto Meier
 
Testing android apps with espresso
Testing android apps with espressoTesting android apps with espresso
Testing android apps with espressoÉdipo Souza
 
How to feature flag and run experiments in iOS and Android
How to feature flag and run experiments in iOS and AndroidHow to feature flag and run experiments in iOS and Android
How to feature flag and run experiments in iOS and AndroidOptimizely
 
Workshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte IIWorkshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte IIVisual Engineering
 
Android, the life of your app
Android, the life of your appAndroid, the life of your app
Android, the life of your appEyal Lezmy
 
Testing of javacript
Testing of javacriptTesting of javacript
Testing of javacriptLei Kang
 
A gently introduction to AngularJS
A gently introduction to AngularJSA gently introduction to AngularJS
A gently introduction to AngularJSGregor Woiwode
 
jRecruiter - The AJUG Job Posting Service
jRecruiter - The AJUG Job Posting ServicejRecruiter - The AJUG Job Posting Service
jRecruiter - The AJUG Job Posting ServiceGunnar Hillert
 
a friend in need-a js indeed / Yonatan levin
a friend in need-a js indeed / Yonatan levina friend in need-a js indeed / Yonatan levin
a friend in need-a js indeed / Yonatan levingeektimecoil
 
Android Best Practices - Thoughts from the Trenches
Android Best Practices - Thoughts from the TrenchesAndroid Best Practices - Thoughts from the Trenches
Android Best Practices - Thoughts from the TrenchesAnuradha Weeraman
 
Google I/O 2019 - what's new in Android Q and Jetpack
Google I/O 2019 - what's new in Android Q and JetpackGoogle I/O 2019 - what's new in Android Q and Jetpack
Google I/O 2019 - what's new in Android Q and JetpackSunita Singh
 
Naive application development
Naive application developmentNaive application development
Naive application developmentShaka Huang
 
Raising ux bar with offline first design
Raising ux bar with offline first designRaising ux bar with offline first design
Raising ux bar with offline first designKyrylo Reznykov
 

Semelhante a Android 5.0 internals and inferiority complex droidcon.de 2015 (20)

Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
Lecture 12 - Maps, AR_VR_aaaaHardware.pptxLecture 12 - Maps, AR_VR_aaaaHardware.pptx
Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
 
Introduction to Titanium and how to connect with a PHP backend
Introduction to Titanium and how to connect with a PHP backendIntroduction to Titanium and how to connect with a PHP backend
Introduction to Titanium and how to connect with a PHP backend
 
Advantages and limitations of PhoneGap for sensor processing
Advantages and limitations of PhoneGap for sensor processingAdvantages and limitations of PhoneGap for sensor processing
Advantages and limitations of PhoneGap for sensor processing
 
Kogito: cloud native business automation
Kogito: cloud native business automationKogito: cloud native business automation
Kogito: cloud native business automation
 
LG Developer Event 2013 in San Francisco
LG Developer Event 2013 in San FranciscoLG Developer Event 2013 in San Francisco
LG Developer Event 2013 in San Francisco
 
Being Epic: Best Practices for Android Development
Being Epic: Best Practices for Android DevelopmentBeing Epic: Best Practices for Android Development
Being Epic: Best Practices for Android Development
 
Testing android apps with espresso
Testing android apps with espressoTesting android apps with espresso
Testing android apps with espresso
 
How to feature flag and run experiments in iOS and Android
How to feature flag and run experiments in iOS and AndroidHow to feature flag and run experiments in iOS and Android
How to feature flag and run experiments in iOS and Android
 
Workshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte IIWorkshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte II
 
Android, the life of your app
Android, the life of your appAndroid, the life of your app
Android, the life of your app
 
Testing of javacript
Testing of javacriptTesting of javacript
Testing of javacript
 
A gently introduction to AngularJS
A gently introduction to AngularJSA gently introduction to AngularJS
A gently introduction to AngularJS
 
jRecruiter - The AJUG Job Posting Service
jRecruiter - The AJUG Job Posting ServicejRecruiter - The AJUG Job Posting Service
jRecruiter - The AJUG Job Posting Service
 
Advanced android app development
Advanced android app developmentAdvanced android app development
Advanced android app development
 
a friend in need-a js indeed / Yonatan levin
a friend in need-a js indeed / Yonatan levina friend in need-a js indeed / Yonatan levin
a friend in need-a js indeed / Yonatan levin
 
Android Best Practices - Thoughts from the Trenches
Android Best Practices - Thoughts from the TrenchesAndroid Best Practices - Thoughts from the Trenches
Android Best Practices - Thoughts from the Trenches
 
Google I/O 2019 - what's new in Android Q and Jetpack
Google I/O 2019 - what's new in Android Q and JetpackGoogle I/O 2019 - what's new in Android Q and Jetpack
Google I/O 2019 - what's new in Android Q and Jetpack
 
Naive application development
Naive application developmentNaive application development
Naive application development
 
Raising ux bar with offline first design
Raising ux bar with offline first designRaising ux bar with offline first design
Raising ux bar with offline first design
 
Sst hackathon express
Sst hackathon expressSst hackathon express
Sst hackathon express
 

Último

Android Application Components with Implementation & Examples
Android Application Components with Implementation & ExamplesAndroid Application Components with Implementation & Examples
Android Application Components with Implementation & ExamplesChandrakantDivate1
 
Mobile Application Development-Android and It’s Tools
Mobile Application Development-Android and It’s ToolsMobile Application Development-Android and It’s Tools
Mobile Application Development-Android and It’s ToolsChandrakantDivate1
 
Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...
Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...
Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...nishasame66
 
Leading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdfLeading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdfCWS Technology
 
Mobile Application Development-Components and Layouts
Mobile Application Development-Components and LayoutsMobile Application Development-Components and Layouts
Mobile Application Development-Components and LayoutsChandrakantDivate1
 

Último (6)

Android Application Components with Implementation & Examples
Android Application Components with Implementation & ExamplesAndroid Application Components with Implementation & Examples
Android Application Components with Implementation & Examples
 
Mobile Application Development-Android and It’s Tools
Mobile Application Development-Android and It’s ToolsMobile Application Development-Android and It’s Tools
Mobile Application Development-Android and It’s Tools
 
Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...
Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...
Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...
 
Leading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdfLeading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdf
 
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
 
Mobile Application Development-Components and Layouts
Mobile Application Development-Components and LayoutsMobile Application Development-Components and Layouts
Mobile Application Development-Components and Layouts
 

Android 5.0 internals and inferiority complex droidcon.de 2015