SlideShare ist ein Scribd-Unternehmen logo
1 von 67
Downloaden Sie, um offline zu lesen
Android Lollipop Internals
and our inferiority complex
+AleksanderPiotrowski
@pelotasplus
About presentation
Inferiority complex
● mine but maybe yours as well?
● gets better with each PR or a talk
● … or look taken at others code
History
● originally as “What’s new in Lollipop”
● about new APIs
● how it works under the hood
● the devil is in the detail
What to look for
● technical information - a bit
● motivation - hopefully lot more
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
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
JobScheduler
Our App
Task
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);
}
}
BatteryController
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);
[...]
}
BatteryController
public void onReceiveInternal(Intent intent) {
final String action = intent.getAction();
if (Intent.ACTION_BATTERY_LOW.equals(action)) {
[...]
// If we get this action, the battery is discharging => it isn't plugged in so
// there's no work to cancel. We track this variable for the case where it is
// charging, but hasn't been for long enough to be healthy.
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
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();
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(Intent.ACTION_SCREEN_OFF)
|| action.equals(Intent.ACTION_DREAMING_STARTED)) {
// when the screen goes off or dreaming starts, we schedule the
// alarm that will tell us when we have decided the device is
// truly idle.
final long nowElapsed = SystemClock.elapsedRealtime();
final long when = nowElapsed + INACTIVITY_IDLE_THRESHOLD;
if (DEBUG) {
Slog.v(TAG, "Scheduling idle : " + action + " now:" + nowElapsed + " when="
+ when);
}
mAlarm.setWindow(AlarmManager.ELAPSED_REALTIME_WAKEUP,
when, IDLE_WINDOW_SLOP, mIdleTriggerIntent);
}
[...]
@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) {
if (DEBUG) {
Slog.v(TAG, "Idle trigger fired @ " + SystemClock.elapsedRealtime());
}
mIdle = true;
reportNewIdleState(mIdle);
}
}
}
The “idle” state algorithm
● time is not a factor
at night
● sensors not used
lying next to the bed
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 Zagreb
● YOU <3
for attending my talk
and others too ;-)

Weitere ähnliche Inhalte

Ähnlich wie Android Lollipop internals and inferiority complex droidcon.hr 2015

Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best Practices
Yekmer Simsek
 

Ähnlich wie Android Lollipop internals and inferiority complex droidcon.hr 2015 (20)

A gently introduction to AngularJS
A gently introduction to AngularJSA gently introduction to AngularJS
A gently introduction to AngularJS
 
Testing android apps with espresso
Testing android apps with espressoTesting android apps with espresso
Testing android apps with espresso
 
Using APEX to Create a Mobile User Interface for Enterprise Manager 12c
Using APEX to Create a Mobile User Interface for Enterprise Manager 12cUsing APEX to Create a Mobile User Interface for Enterprise Manager 12c
Using APEX to Create a Mobile User Interface for Enterprise Manager 12c
 
Blogging tizen devlab@seoul ppt - optimization
Blogging   tizen devlab@seoul ppt - optimizationBlogging   tizen devlab@seoul ppt - optimization
Blogging tizen devlab@seoul ppt - optimization
 
Hardware hackers - hacking appliances with netduino + xamarin
Hardware hackers - hacking appliances with netduino + xamarinHardware hackers - hacking appliances with netduino + xamarin
Hardware hackers - hacking appliances with netduino + xamarin
 
Android scheduling.pptx
Android scheduling.pptxAndroid scheduling.pptx
Android scheduling.pptx
 
nter-pod Revolutions: Connected Enterprise Solution in Oracle EPM Cloud
nter-pod Revolutions: Connected Enterprise Solution in Oracle EPM Cloud nter-pod Revolutions: Connected Enterprise Solution in Oracle EPM Cloud
nter-pod Revolutions: Connected Enterprise Solution in Oracle EPM Cloud
 
Easy job scheduling with android
Easy job scheduling with androidEasy job scheduling with android
Easy job scheduling with android
 
Kogito: cloud native business automation
Kogito: cloud native business automationKogito: cloud native business automation
Kogito: cloud native business automation
 
Teardown Conference: hacking appliances with netduino + xamarin
Teardown Conference: hacking appliances with netduino + xamarinTeardown Conference: hacking appliances with netduino + xamarin
Teardown Conference: hacking appliances with netduino + xamarin
 
[AngularJS] From Angular to Mobile in 30 minutes
[AngularJS] From Angular to Mobile in 30 minutes[AngularJS] From Angular to Mobile in 30 minutes
[AngularJS] From Angular to Mobile in 30 minutes
 
From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)
 
Hybrid Tips & Tricks
Hybrid Tips & TricksHybrid Tips & Tricks
Hybrid Tips & Tricks
 
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
 
Android, the life of your app
Android, the life of your appAndroid, the life of your app
Android, the life of your app
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)
 
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
 
Advanced Dagger talk from 360andev
Advanced Dagger talk from 360andevAdvanced Dagger talk from 360andev
Advanced Dagger talk from 360andev
 
Performance Instrumentation for PL/SQL: When, Why, How
Performance Instrumentation for PL/SQL: When, Why, HowPerformance Instrumentation for PL/SQL: When, Why, How
Performance Instrumentation for PL/SQL: When, Why, How
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best Practices
 

Kürzlich hochgeladen

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)
Cara Menggugurkan Kandungan 087776558899
 

Kürzlich hochgeladen (6)

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)
 
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
 
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
 
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
 
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRFULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
 
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPowerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
 

Android Lollipop internals and inferiority complex droidcon.hr 2015