power bugs

21
Understanding, Debugging and Fixing Power Bugs Aditya & Satyam

Upload: adityakulkarni

Post on 20-Jun-2015

659 views

Category:

Technology


0 download

DESCRIPTION

Identifying and Fixing power bugs in Android Apps

TRANSCRIPT

Page 1: Power bugs

Understanding, Debugging and Fixing

Power Bugs

Aditya & Satyam

Page 2: Power bugs

Power Bugs

Apps are to blame the most for bad battery life

Page 3: Power bugs

Power Bugs

• Bad coding patterns cause power bugs

• Specific behaviors of the Android Platform

• App inter-dependencies!

• Special Attention must be paid to optimize for power!

Page 4: Power bugs

Users Hate Power Bugs

Page 5: Power bugs

Understanding Common Power Bugs

Page 6: Power bugs

Common Power Bugs 1. Not Sleeping Properly

Page 7: Power bugs

Common Power Bugs 2. Un-necessary Animations

Page 8: Power bugs

Common Power Bugs 3. Updating the Screen

Page 9: Power bugs

Common Power Bugs 4. Handling Display-Off

Page 10: Power bugs

Common Power Bugs 5. Waking up to notifications

Page 11: Power bugs

More Types Of Power Bugs

• Registering for un-necessary events

• Waking up the system causes everyone to be woken up

• Register for “active” notifications (instead of passive ones)

• Handset-specific problems

Page 12: Power bugs

Best Practices(or how to avoid the dreaded battery drain)

Page 13: Power bugs

Power Consumption is Complex and Inter-dependent among components

Jeff Sharkey at Google IO

Page 14: Power bugs

Best Practices - Network

• prefetch data

– to avoid switching states frequently, try and read as much data as possible

– trade-off between too much pre-fetch and battery drain

– google recommends pre-fetching data that you will initiate in the next 2 to 5 minutes, and in the order of 1-5 MB size

• batch data

– do data send/receive in batches rather than on-demand

– eg: batch analytics information, rather than sending them as they are collected

Page 15: Power bugs

Best Practices - Network

• using inexact timers

– AlarmManager.setInexactRepeating()

– use ELAPSED_REALTIME instead of ELAPSED_REALTIME_WAKEUP

• detect network connection

– avoid connection attempts if no network is active

• avoid polling and use GCM when possible

– avoids multiple connections

– reduces the number of device state changes

Page 16: Power bugs

Best Practices - Screen

• color matters!

– esp on OLED screens

– darker the color, lesser the consumption

• brightness levels have more impact

– refer to - http://stackoverflow.com/questions/5032588/cant-apply-system-screen-brightness-programmatically-in-android

Page 17: Power bugs

Best Practices - Screen

• programmatically reduce brightness if its suits your app/activity

• Use “night mode” for reading Apps

• Think about your color scheme

Page 18: Power bugs

Best Practices - CPU

• wakelocks are your friend, but your users worst nightmare!

• use them only if really needed and ensure they are removed as soon as possible

• Use ‘android:keepScreenOn’ property in your manifest instead of doing it programmatically

Page 19: Power bugs

Best Practices - CPU

• if possible, spread out your computationally intensive job

• gpu typically consumes more power than cpu

– avoid floating point math where possible

• use algorithms that consume less CPU cycle

– O(n log n) vs O(n 2) algorithms

Page 20: Power bugs

Identifying power bugs with little eye

Demo

Page 21: Power bugs

Optimized Apps = Better User Experience

Thank You

www.littleeye.co

[email protected]@littleeye.co