Selectively Taming Background Android Applications
Total Page:16
File Type:pdf, Size:1020Kb
Selectively Taming Background Android Apps to Improve Battery Lifetime Marcelo Martins Justin Cappos Rodrigo Fonseca Brown University New York University Brown University 2 Your Battery and You Active device high battery drainage Matches our battery life expectation 3 Your Battery and You Idle device expect low battery drain (?) Background activities break low-power harmony Energy bugs keep the device awake 4 Hidden Energy Drain Pure AOSP + Google Mobile Services 5 100 100 Pure AOSP Pure AOSP w/ Google M. Services w/ Google M. Services 80 80 (%) (%) 60 60 40 40 Battery LevelBattery Battery LevelBattery 20 20 0 0 0 20 40 60 80 100 120 140 0 50 100 150 200 250 ~1.8 days ~8.3 days Hours Hours Samsung Galaxy Nexus ASUS MeMO Pad 7 6 ) W AlarmManager ( 2 1 Power Power Pure AOSP 0 0 50 100 150 200 250 300 350 Timeline (s) AlarmManager NetworkLocationService GCoreFlp GeofencerStateMachine NlpCollectorWakeLock ) NlpWakeLock W ( UlrDispatchingService PendingIntentCallbackService NlpLocationReceiverService Power Power 3 Hidden Energy Drain 2 1 + Google Mobile Services 0 0 50 100 150 200 250 300 350 7 Timeline (s) What Can We Do Today? Reconfigure apps Uninstall/Switch apps Kill apps Change system settings 8 What Can We Do Today? Reconfigure apps Uninstall/Switch apps Kill apps Change system settings 9 What Can We Do Today? Reconfigure apps Uninstall/Switch apps Kill apps Change system settings 10 What Can We Do Today? Reconfigure apps Uninstall/Switch apps Kill apps Change system settings 11 TAMER Runtime mechanism to rate-limit background events 12 Backgrounding Sources? Tomorrow’s Services temperature? Alarms Intent Receivers Wakelocks 25o C 13 Backgrounding Sources? Sync files Services every 15 min Alarms Intent Receivers Wakelocks 14 Backgrounding Sources? Wake me up Services on new msg Alarms Intent Receivers Wakelocks 15 Backgrounding Sources? Keep screen Services awake Alarms Intent Receivers Wakelocks 16 Backgrounding Sources? Services Alarms Asynchronous Intent Receivers Wakelocks Symmetric 17 Prelude to Blocking: Event Dispatching Tomorrow’s class fetchTemperature extends IntentService { temperature? @Override public void onHandleIntent(…) {…} }; 1. Event definition (what) 18 Prelude to Blocking: Event Dispatching Tomorrow’s class fetchTemperature extends IntentService {…} temperature? startService(new Intent(…, fetchTemperature.class)); 1. Event definition (what) 2. Event request 19 Prelude to Blocking: Event Dispatching Tomorrow’s class fetchTemperature extends IntentService {…} temperature? startService(new Intent(…, fetchTemperature.class)); startService(…) 1. Event definition (what) ⁞ acquireWakelock(…) 2. Event request ⁞ 3. Event callback (where) startServiceLocked(…) order Call ⁞ startRunningLocked(…) 20 Blocking the Event Dispatch Tomorrow’s class fetchTemperature extends IntentService {…} temperature? startService(new Intent(…, fetchTemperature.class)); startService(…) 1. Event definition (what) ⁞ acquireWakelock(…) 2. Event request ⁞ 3. Event callback (where) startServiceLocked(…) order Call ⁞ startRunningLocked(…) 21 Throttling Abstraction Observer Arbiter Actuator Controller 22 App TAMER Tomorrow’s temperature? App Name Type #Calls fetchTemp Service 1231+1 syncPhotos Service 342 scanSystem Service 3 Event Event rate Observer Arbiter Actuator Controller 23 only syncs once a hour User (Ideal case) Policy Event Event rate Decision Observer Arbiter Actuator Controller if (monitoredRate > policyThreshold) should block 24 only syncs once a hour Expert (Current state) Policy Event Event rate Decision Observer Arbiter Actuator Controller if (monitoredRate > policyThreshold) should block 25 App TAMER Tomorrow’s temperature? Policy Event Event rate Decision Action Observer Arbiter Actuator Controller 26 Wakelock Service Tamer Intent Alarm Services Application Framework Intent Receivers Alarms Libraries Android Runtime WakelocksObserver Arbiter Actuator Kernel 27 Tomorrow’s Implementation temperature? Java-based runtime code injection via Xposed startService(…) Interposes on event callbacks to ⁞ control their execution acquireWakelock(…) deny ⁞ (early return) startServiceLocked(…) order Call Policies in JSON format controller startRunningLocked(…) accept http://repo.xposed.info 28 Installation Installs like any other app (APK file) Runtime modifications . No need for app recompilation/reinstallation Android compatibility . Different vendors (Samsung, HTC, ASUS, CyanogenMod, etc.) . Different versions (Ice Cream to KitKat) . Requires rooting 29 Evaluation Four devices Android KitKat Galaxy Nexus Kindle Fire2 Galaxy S4 MeMOPad 7 Experiments (2011) (2012) (2013) (2014) General lifetime Energy Bugs GPS throttling 30 Evaluation Four devices Android KitKat Galaxy Nexus Kindle Fire2 Galaxy S4 MeMOPad 7 Experiments (2011) (2012) (2013) (2014) General lifetime Energy Bugs GPS throttling 31 General Lifetime Pure AOSP + Google Mobile Services 32 100 100 Pure AOSP Pure AOSP w/ Google M. Services w/ Google M. Services 80 80 (%) (%) 60 60 40 40 Battery LevelBattery Battery LevelBattery 20 20 0 0 0 20 40 60 80 100 120 140 0 50 100 150 200 250 Hours Hours Samsung Galaxy Nexus ASUS MeMO Pad 7 33 Exploring Taming Possibilities Monitoring time: 100 hours One call per min Event Observer Sys awake 11hs New Policies Tamer-15: Events allowed every 15 minutes Tamer-45: Events allowed every 45 minutes 34 100 100 Pure AOSP Pure AOSP w/ Google M. Services w/ Google M. Services 80 80 (%) (%) 60 60 40 40 Battery LevelBattery Battery LevelBattery 20 20 0 0 0 20 40 60 80 100 120 140 0 50 100 150 200 250 Hours Hours Samsung Galaxy Nexus ASUS MeMO Pad 7 35 100 100 Pure AOSP Pure AOSP w/ Google M. Services w/ Google M. Services 80 w/ GMS + Tamer-15 80 w/ GMS + Tamer-15 w/ GMS + Tamer-45 w/ GMS + Tamer-45 (%) (%) 60 60 40 40 Battery Battery Level Battery Battery Level 20 20 0 0 0 20 40 60 80 100 120 140 0 50 100 150 200 250 +23 hours +4.6 days Hours Hours +32 hours +5.8 days Samsung Galaxy Nexus ASUS MeMO Pad 7 36 Chasing Energy Bugs – Bejeweled Blitz 10M+ downloads on Play Store Top 20 on Puzzle Category 37 Chasing Energy Bugs – Bejeweled Blitz AudioIn AudioIn (!!) 38 Bejeweled Blitz – Effects on Battery Lifetime 100 100 Untamed 80 80 (%) (%) 60 60 40 40 CPU Residency BatteryLevel 20 20 Candy Crush Saga Bejeweled (Untamed) 0 0 0 2 4 6 8 10 12 Hours CPU Frequency Samsung Galaxy S4 39 Chasing Energy Bugs – Bejeweled Blitz { “AppName”: “com.ea.BejeweledBlitz_na” “EventList”: { “Entry”: { “Type”: “wakelock” “Name”: “AudioIn” “AllowEvery”: “0” “BackgroundOnly”: “true” } } } AudioIn 40 After Taming 100 100 Untamed 80 80 Tamed (%) (%) 60 60 40 40 CPU Residency BatteryLevel Candy Crush Saga 20 20 Bejeweled (Untamed) Bejeweled (Tamed) 0 0 0 2 4 6 8 10 12 Hours CPU Frequency Samsung Galaxy S4 41 Limitations and Extensions How to define good policies? .Avoid breaking functionality .Dynamic policies .Context awareness 42 Limitations and Extensions How to define good policies? How to engage users? 43 Limitations and Extensions How to define good policies? How to engage users? Event batching instead of blocking 44 Wrap Up Mobile apps can silently kill battery TAMER: OS-level mechanism to throttle background events Separation of control and policy Extends battery life / Selectively keeps functionality Effectively mitigates energy bugs 45.