Power bugs
-
Upload
adityakulkarni -
Category
Technology
-
view
662 -
download
0
description
Transcript of Power bugs
![Page 1: Power bugs](https://reader036.fdocuments.net/reader036/viewer/2022062300/5584c75bd8b42ae5138b4932/html5/thumbnails/1.jpg)
Understanding, Debugging and Fixing
Power Bugs
Aditya & Satyam
![Page 2: Power bugs](https://reader036.fdocuments.net/reader036/viewer/2022062300/5584c75bd8b42ae5138b4932/html5/thumbnails/2.jpg)
Power Bugs
Apps are to blame the most for bad battery life
![Page 3: Power bugs](https://reader036.fdocuments.net/reader036/viewer/2022062300/5584c75bd8b42ae5138b4932/html5/thumbnails/3.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022062300/5584c75bd8b42ae5138b4932/html5/thumbnails/4.jpg)
Users Hate Power Bugs
![Page 5: Power bugs](https://reader036.fdocuments.net/reader036/viewer/2022062300/5584c75bd8b42ae5138b4932/html5/thumbnails/5.jpg)
Understanding Common Power Bugs
![Page 6: Power bugs](https://reader036.fdocuments.net/reader036/viewer/2022062300/5584c75bd8b42ae5138b4932/html5/thumbnails/6.jpg)
Common Power Bugs 1. Not Sleeping Properly
![Page 7: Power bugs](https://reader036.fdocuments.net/reader036/viewer/2022062300/5584c75bd8b42ae5138b4932/html5/thumbnails/7.jpg)
Common Power Bugs 2. Un-necessary Animations
![Page 8: Power bugs](https://reader036.fdocuments.net/reader036/viewer/2022062300/5584c75bd8b42ae5138b4932/html5/thumbnails/8.jpg)
Common Power Bugs 3. Updating the Screen
![Page 9: Power bugs](https://reader036.fdocuments.net/reader036/viewer/2022062300/5584c75bd8b42ae5138b4932/html5/thumbnails/9.jpg)
Common Power Bugs 4. Handling Display-Off
![Page 10: Power bugs](https://reader036.fdocuments.net/reader036/viewer/2022062300/5584c75bd8b42ae5138b4932/html5/thumbnails/10.jpg)
Common Power Bugs 5. Waking up to notifications
![Page 11: Power bugs](https://reader036.fdocuments.net/reader036/viewer/2022062300/5584c75bd8b42ae5138b4932/html5/thumbnails/11.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022062300/5584c75bd8b42ae5138b4932/html5/thumbnails/12.jpg)
Best Practices(or how to avoid the dreaded battery drain)
![Page 13: Power bugs](https://reader036.fdocuments.net/reader036/viewer/2022062300/5584c75bd8b42ae5138b4932/html5/thumbnails/13.jpg)
Power Consumption is Complex and Inter-dependent among components
Jeff Sharkey at Google IO
![Page 14: Power bugs](https://reader036.fdocuments.net/reader036/viewer/2022062300/5584c75bd8b42ae5138b4932/html5/thumbnails/14.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022062300/5584c75bd8b42ae5138b4932/html5/thumbnails/15.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022062300/5584c75bd8b42ae5138b4932/html5/thumbnails/16.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022062300/5584c75bd8b42ae5138b4932/html5/thumbnails/17.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022062300/5584c75bd8b42ae5138b4932/html5/thumbnails/18.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022062300/5584c75bd8b42ae5138b4932/html5/thumbnails/19.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022062300/5584c75bd8b42ae5138b4932/html5/thumbnails/20.jpg)
Identifying power bugs with little eye
Demo