SlideShare a Scribd company logo
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
Android 5.0 internals and inferiority complex droidcon.de 2015
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
Android 5.0 internals and inferiority complex droidcon.de 2015
Android 5.0 internals and inferiority complex droidcon.de 2015
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
***
Android 5.0 internals and inferiority complex droidcon.de 2015
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
Android 5.0 internals and inferiority complex droidcon.de 2015
Android 5.0 internals and inferiority complex droidcon.de 2015
Android 5.0 internals and inferiority complex droidcon.de 2015
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

More Related Content

What's hot (9)

PDF
Angular 2 : le réveil de la force
Nicolas PENNEC
 
PDF
Angular 2 Crash Course
Elisha Kramer
 
PDF
Building maintainable app #droidconzg
Kristijan Jurković
 
PDF
React native app with type script tutorial
Katy Slemon
 
PDF
Building Universal Applications with Angular 2
Minko Gechev
 
PDF
HKG15-306: Introducing Aster - a tool for remote GUI testing on AOSP
Linaro
 
PDF
20190619 meetup r_shiny_reactlog_v0.1
Hui Seo
 
PDF
Adventures with Angular 2
Dragos Ionita
 
PDF
How to React Native
Dmitry Ulyanov
 
Angular 2 : le réveil de la force
Nicolas PENNEC
 
Angular 2 Crash Course
Elisha Kramer
 
Building maintainable app #droidconzg
Kristijan Jurković
 
React native app with type script tutorial
Katy Slemon
 
Building Universal Applications with Angular 2
Minko Gechev
 
HKG15-306: Introducing Aster - a tool for remote GUI testing on AOSP
Linaro
 
20190619 meetup r_shiny_reactlog_v0.1
Hui Seo
 
Adventures with Angular 2
Dragos Ionita
 
How to React Native
Dmitry Ulyanov
 

Similar to Android 5.0 internals and inferiority complex droidcon.de 2015 (20)

PPTX
Easy job scheduling with android
kirubhakarans2
 
PDF
Dicoding Developer Coaching #18: Android | Membuat Aplikasi Pengingat dengan ...
DicodingEvent
 
PDF
Android Best Practices - Thoughts from the Trenches
Anuradha Weeraman
 
PDF
W 0300 codingfor_life-batterylifethatis
jicheng687
 
PPTX
A journey through android development
raditya gumay
 
PDF
Mobile Fest 2018. Yonatan Levin. WTF with Android Background Restrictions
MobileFest2018
 
PDF
Analysing in depth work manager
bhatnagar.gaurav83
 
PDF
Advanced android app development
Rachmat Wahyu Pramono
 
PPTX
What's new in android M(6.0)
Yonatan Levin
 
PDF
HH QUALCOMM how to minimize the power consumption of your app
Satya Harish
 
PDF
How to Minimize Your App’s Power Consumption
Qualcomm Developer Network
 
PDF
Analysing in depth work manager
lpu
 
PPT
Gaad01 job scheduler
Md Farhad Hussain mun
 
PPTX
gcce-uapm-slide-20131001-1900
Samsung Electronics
 
PDF
GREEN PAUWARE - For a power-thrifty mobile app marketplace
Olivier Le Goaër
 
PPTX
Understanding, debugging and fixing power bugs
littleeye
 
PPTX
Power bugs
aditya_kulkarni
 
PDF
Migrating From Foreground Services To WorkManager
Aayush Gupta
 
PPTX
Android M, N preview
Fady Emad
 
PDF
Being Epic: Best Practices for Android Development
Reto Meier
 
Easy job scheduling with android
kirubhakarans2
 
Dicoding Developer Coaching #18: Android | Membuat Aplikasi Pengingat dengan ...
DicodingEvent
 
Android Best Practices - Thoughts from the Trenches
Anuradha Weeraman
 
W 0300 codingfor_life-batterylifethatis
jicheng687
 
A journey through android development
raditya gumay
 
Mobile Fest 2018. Yonatan Levin. WTF with Android Background Restrictions
MobileFest2018
 
Analysing in depth work manager
bhatnagar.gaurav83
 
Advanced android app development
Rachmat Wahyu Pramono
 
What's new in android M(6.0)
Yonatan Levin
 
HH QUALCOMM how to minimize the power consumption of your app
Satya Harish
 
How to Minimize Your App’s Power Consumption
Qualcomm Developer Network
 
Analysing in depth work manager
lpu
 
Gaad01 job scheduler
Md Farhad Hussain mun
 
gcce-uapm-slide-20131001-1900
Samsung Electronics
 
GREEN PAUWARE - For a power-thrifty mobile app marketplace
Olivier Le Goaër
 
Understanding, debugging and fixing power bugs
littleeye
 
Power bugs
aditya_kulkarni
 
Migrating From Foreground Services To WorkManager
Aayush Gupta
 
Android M, N preview
Fady Emad
 
Being Epic: Best Practices for Android Development
Reto Meier
 
Ad

Recently uploaded (8)

PDF
Building Smart, Scalable Solutions with Android App Development
Brancosoft Private Limited
 
PPTX
Mobile Apps Helping Business Grow in 2025
Infylo Techsolutions
 
PPT
lect 1 Introduction.ppt11112222333344455
212231
 
PDF
Call For Papers - International Journal on Natural Language Computing (IJNLC)
kevig
 
PDF
INTERLINGUAL SYNTACTIC PARSING: AN OPTIMIZED HEAD-DRIVEN PARSING FOR ENGLISH ...
kevig
 
PDF
💡 Digital Marketing Decoded: Mastering Online Growth Strategies for 2025 🚀
marketingaura24
 
PPT
lec2 wireless transmission exlaining.ppt
212231
 
PPTX
The Intersection of Emoji and NFT. What can be the Consequences?
Refit Global
 
Building Smart, Scalable Solutions with Android App Development
Brancosoft Private Limited
 
Mobile Apps Helping Business Grow in 2025
Infylo Techsolutions
 
lect 1 Introduction.ppt11112222333344455
212231
 
Call For Papers - International Journal on Natural Language Computing (IJNLC)
kevig
 
INTERLINGUAL SYNTACTIC PARSING: AN OPTIMIZED HEAD-DRIVEN PARSING FOR ENGLISH ...
kevig
 
💡 Digital Marketing Decoded: Mastering Online Growth Strategies for 2025 🚀
marketingaura24
 
lec2 wireless transmission exlaining.ppt
212231
 
The Intersection of Emoji and NFT. What can be the Consequences?
Refit Global
 
Ad

Android 5.0 internals and inferiority complex droidcon.de 2015