Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Becoming a Better Battery Citizen

Becoming a Better Battery Citizen

From DroidCon Boston 2017 - In the 8 years since the release of the first commercial Android device, we’ve seen screen resolutions go from thousands of pixels to millions, cameras from 3MP to 13MP, and cores from 1 to 8 – but battery life is staying the same or even getting worse! This makes it even more important to be a good battery citizen and leave some juice for your users’ other apps (they do use apps other than yours, right?) In this session, we will explore the different battery tools and resources available for profiling – like Trepn Power Profiler and Battery Historian – and use them to identify common battery pain points in your app. We’ll also cover best practices for power-sensitive development so you can prevent battery drain problems from the beginning.

Avatar for Eric Brynsvold

Eric Brynsvold

April 10, 2017
Tweet

Other Decks in Programming

Transcript

  1. Other App Background Processes Disk Storage Network Requests Push Notifications

    Other App Background Processes Disk Storage Network Requests Push Notifications Other App Background Processes Disk Storage Network Requests Push Notifications Other App Background Processes Disk Storage Network Requests Push Notifications Other App Background Processes Disk Storage Network Requests Push Notifications Other App Background Processes Disk Storage Network Requests Push Notifications Your App Background Processes Disk Storage Network Requests Push Notifications Other App Background Processes Disk Storage Network Requests Push Notifications Other App Background Processes Disk Storage Network Requests Push Notifications Other App Background Processes Disk Storage Network Requests Push Notifications Other App Background Processes Disk Storage Network Requests Push Notifications Other App Background Processes Disk Storage Network Requests Push Notifications
  2. VS

  3. How To Use 5.0 - 6.0 adb bugreport > mybugreport.txt

    7.0+ adb bugreport mybugreport.zip
  4. Worst Practices • Scheduling frequent periodic alarms when not absolutely

    necessary • Syncing data too often • Not caching data • Abusing wakelocks
  5. Worst Practices • Scheduling frequent periodic alarms when not absolutely

    necessary • Syncing data too often • Not caching data • Abusing wakelocks
  6. Worst Practices • Scheduling frequent periodic alarms when not absolutely

    necessary • Syncing data too often • Not caching data • Abusing wakelocks
  7. Worst Practices • Scheduling frequent periodic alarms when not absolutely

    necessary • Syncing data too often • Not caching data • Abusing wakelocks
  8. JobScheduler Other App Background Processes Disk Storage Network Requests Push

    Notifications Your App Background Processes Disk Storage Network Requests Push Notifications Other App Background Processes Disk Storage Network Requests Push Notifications
  9. JobScheduler Other App Background Processes Disk Storage Network Requests Push

    Notifications Your App Background Processes Disk Storage Network Requests Push Notifications Other App Background Processes Disk Storage Network Requests Push Notifications
  10. Scheduling Photo Backup JobScheduler scheduler = (JobScheduler) getSystemService(JOB_SCHEDULER_SERVICE);
 ComponentName componentName

    = new ComponentName(this, PhotoBackupService.class); PersistableBundle extrasBundle = new PersistableBundle(); extrasBundle.putString(“photoToBackup”, “SOME_STRING_ID”);
 
 JobInfo jobInfo = new JobInfo.Builder(1234, componentName)
 .setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED)
 .setRequiresCharging(true) .setPersisted(true) .setExtras(extrasBundle);
 .build();
 
 scheduler.schedule(jobInfo);
  11. Job Service public class PhotoBackupService extends JobService {
 
 @Override


    public boolean onStartJob(JobParameters jobParameters) { switch (jobParameters.getJobId()) {
 case 1234: String photoId = jobParameters.getExtras().getString(“photoToBackup”);
 // start new thread to do work, // call jobFinished(jobParameters, false); when done return true;
 } 
 return false;
 }
 
 @Override
 public boolean onStopJob(JobParameters jobParameters) {
 return false;
 }
 }
  12. Working with Doze • Test with Doze: adb shell dumpsys

    deviceidle force-idle • AlarmManager • GCM • Whitelist
  13. Recap • Be Aware • Use Trepn and Battery Historian

    • No Worst Practices • Use Job Scheduler • Test with Doze
  14. Recap • Be Aware • Use Trepn and Battery Historian

    • No Worst Practices • Use Job Scheduler • Test with Doze
  15. Recap • Be Aware • Use Trepn and Battery Historian

    • No Worst Practices • Use Job Scheduler • Test with Doze
  16. Recap • Be Aware • Use Trepn and Battery Historian

    • No Worst Practices • Use Job Scheduler • Test with Doze
  17. Recap • Be Aware • Use Trepn and Battery Historian

    • No Worst Practices • Use Job Scheduler • Test with Doze