Mobile Computing
COMP5216
Week 07 Semester 2, 2020
Dr. Kanchana Thilakarathna School of Computer Science
The University of Sydney
Page 1
Outline
– Computation
– Managing Computation tasks
– Monitoring the load
– Cloud computing support
– Energy Management
– Energy consumption
– Best practices for energy management
– Platform supported energy management
– Towards battery less devices The University of Sydney
Page 2
Computing Challenge
– Hardware updates screen every 16 milliseconds – UI thread has 16ms to do all its work
– If it takes too long, app stutters or hangs
The University of Sydney Page 3
Computing Challenge
– What are long running tasks ? – Downloading/Uploading files
– Image processing, e.g. object detection – Loading data
– Complex calculations
– How to check whether your app does well ?
The University of Sydney
Page 4
Checking your frame rate
– What are long running tasks ? – Downloading/Uploading files
– Image processing, e.g. object detection – Loading data
– Complex calculations
– How to check whether your app does well ?
– Settings > Developer options > Monitoring section > Profile GPU
rendering > On screen as bars
– How to find Developer options ?
The University of Sydney
Page 5
Checking your frame rate
– Settings > Developer options > Monitoring section > Profile GPU rendering > On screen as bars
– How to find Developer options ? – Hidden by default.
16ms bar
– One bar represents one frame of rendering
– Taller the bar, the longer it takes to render
– The horizontal green line represents 16 milliseconds.
– Each frame needs to stay below this lineà60 frames/s
The University of Sydney
Page 6
Visualize GPU overdraw
– Settings > Developer options > Hardware accelerated rendering> Debug GPU Overdraw > overdraw areas
– How to reduce overdraw ?
– Removing unwanted backgrounds in layouts. – Flattening the view hierarchy.
– Reducing transparency.
– https://developer.android.com/topic/performance/rendering/overdraw
The University of Sydney
Page 7
Best Practice Computing
1. Complete tasks in less than 16ms
2. Move non-UI tasks to background thread
Main Thread
Update UI
Worker Thread
– In Android
– AsyncTask, The Loader Framework, Services The University of Sydney
Page 8
Long running task
Best Practice Computing
1. Complete tasks in less than 16ms
2. Move non-UI tasks to background thread
3. Offload to a location with enough resources
– Mobile Computing + Cloud Computing
– Provides mobile application developers a way to connect their
application to backend cloud storage and processing
The University of Sydney
Page 9
What is Mobile Cloud Computing ?
– Mobile Computing + Cloud Computing
– Provides mobile application developers a way to connect their
application to backend cloud storage and processing
– “Anything-as-a-Service” – Software-as-a-Service
– Platform-as-a-Service
– Infrastructure-as-a-Service
– Mobile Backend as-a-Service
– Multiple monetization models – Pay per use
– Subscriptions
– Private vs Public cloud resources
https://www.back4app.com
The University of Sydney
Page 10
Mobile Cloud Computing
– Why?
– Limitedresourcesonmobiledevices
• Battery, Computation, Network, etc.
– Abstractawaycomplexitiesofappdevelopment
• E.g. Google Play Services
– Minimizelaunchingandmanagingowninfrastructure
• Enable enterprises to treat IT as a utility than a capital expenditure – Focusmoreonfront-enddevelopmentinsteadofbackendfunctions
– Integrationofmultipledevelopers,apps,services
– Toenabledatasharing
– Forpermanentstorage,backup
– Easyappanalytics
– Security
– Examplesfromcurrentpopularapps? The University of Sydney
Page 11
Examples
– AppleSiri
– Speech recognitionàToo complex for a mobile device
– Dropbox,GoogleDrive,AppleiCloud
– Unlimited storageàNot enough storage on mobile devices
– GooglePlayLocationAPI
– Hidecomplexityfromtheappdeveloper
– SingleSign-onAuthentication
– Focusmoreonthefront-enddevelopment
– SocialNetworking
– Datastorageandsharing,Pushnotifications
The University of Sydney
Page 12
MBaaS Providers
– Not a comprehensive list
– Literary every company has a MBaaS Cloud Service
The University of Sydney Page 13
Firebase
– Google MBaaS Solution – Not only for Android
– Most Features supports
– Offer a number of features – Build better apps
– Improve app quality
– Grow your business
– Click Tools >Firebase to open the Assistant window
– Tutorial 4
The University of Sydney
Page 14
Firebase
– FirebaseML-https://firebase.google.com/docs/ml
– Stillabetaversion
– APIsthatworkeitherintheinthecloudoronthedevice – ConvenientAPIstousedeeplearningcapabilities
– ForbothiOSandAndroid
– Textrecognition
– Facedetection
– Barcodereading
– Labelimages
– Landmarkrecognition
– FirebaseCloudMessaging-https://firebase.google.com/docs/cloud-messaging/ – FCMprovidesasingle,persistentconnectiontothecloud
– Allappsneedingreal-timemessagingcansharethisconnection
The University of Sydney Page 15
ML Tool kit
– ML Tool Kit – https://developers.google.com/ml-kit – Released on Jun 2020
The University of Sydney Page 16
ML Tool kit
– ML Tool Kit – https://developers.google.com/ml-kit – Released on Jun 2020
– Samples: https://github.com/googlesamples/mlkit/tree/master/android /vision-quickstart
The University of Sydney Page 17
The University of Sydney
Page 18
Energy Management
Battery consumption
The University of Sydney Page 19
Battery consumption
– Screen & CPU
– Foreground vs Background – Activity vs Services
– Sleep vs Active
– Input modalities
– Type, Talk or Swype
– Sensing
– Location (GPS vs Network)
– Activity monitoring sensors – Accelerometer, Gyroscope, Magnetometer, etc.
– Camera
– Network interface
– Cellular>WiFi>Bluetooth in general
– Communication protocol, e.g. HTTPS vs HTTP, content refresh rate
The University of Sydney
Page 20
Screen & CPU
– Move the app to background, if the user interaction is not required.
– Activity vs Services in Android
– Good programming practices
– Efficient algorithms
– Reduce disk access frequency
– Figure Reference: Chen, Xiaomeng, et al. ”Smartphone Background Activities in the Wild: Origin, Energy Drain, and
Optimization.” Proceedings of the 21st Annual International Conference on Mobile Computing and Networking. ACM,
2015.
The University of Sydney Page 21
Input Modalities
– Talk (Speech to Text), Type (Soft Key) and Swipe
Reference: Jiang, Fangzhou, et al. ”When to type, talk, or Swype: Characterizing energy consumption of mobile input modalities.” Pervasive Computing and Communications (PerCom), 2015 IEEE International Conference on. IEEE, 2015.
The University of Sydney Page 22
Sensing
– Sensor API are primarily used;
– Identifying sensors and sensor capabilities – Monitor sensor events
– Identify Sensor features
– getResolution() for sensor resolution
– getMaximumRange() for maximum range of measurement
– getPower() for sensor’s power requirements
– getVendor() and getVersion() to optimize for different sensors or different versions of sensor
– getMinDelay() to determine maximum rate at which sensor can acquire data
The University of Sydney
Page 23
Sensor Delays
– Rely on the lowest possible sampling rate
– Higher the sampling rate, higher the energy consumption
Kolamunna, H. D., Thilakarathna, K., Perino, D., Makaroff, D.,&Seneviratne, A. (2018). Seamless Resources Sharing in Wearable Networks by Application Function Virtualization. IEEE Transactions on Mobile Computing.
The University of Sydney Page 24
Networking Radio/Chipset on mobile devices
– Not always ON
– Becomes ACTIVE, only when it is required to transfer data – After a transfer, stays ON for some time
– Eventually, goes back to SLEEP
3G State machine. LTE State machine.
[1]. Qian, Feng, et al. ”Profiling resource usage for mobile applications: a cross-layer approach”. Proceedings of
the 9th international conference on Mobile systems, applications, and services. ACM, 2011.
The University of Sydney [2]. Huang, Junxian, et al. ”A close examination of performance and power characteristics of 4G LTE networks”. Page 25
Proceedings of the 10th international conference on Mobile systems, applications, and services. ACM, 2012.
LTE Network Power Usage
– Power consumption of LTE data communication
1. HighPower
2. MediumPower 3. LowPower
The University of Sydney
Page 26
Network Power Usage
LTE vs 3G vs WiFi
– In general, LTE>3G>WiFi.
– Dependent on the network conditions, e.g. available bandwidth, signal
strength, interference, etc.
Balasubramanian, Niranjan, Aruna Balasubramanian, and Arun Venkataramani. ”Energy consumption in mobile phones: a measurement study and implications for network applications.” Proceedings of the 9th ACM SIGCOMM conference on Internet measurement conference. ACM, 2009.
The University of Sydney Page 27
Privacy and Security
– Energy cost of secure protocols is not negligible.
– More data due to adding noise, encryption, channel coding, etc. – Extra communication due to key exchanges
– Security is important in today’s mobile world. – It is worth the cost of energy
H. Kolamunna, J. Chauhan, K. Thilakarathna, D. Perino, D. Makaroff and A. Seneviratne, “Are Wearables Ready for Secure and Direct Internet Communication?”, ACM GetMobile: Mobile Computing and Communications, vol. 21, no. 3, pp. 5-10, Sep 2017.
The University of Sydney Page 28
Best Practices for Energy Management
– “Lazy First” design strategy 1. Reduce
– Can we cache data with out re- downloading?
2. Defer
– Can we wait until the device is charging ?
3. Batch
– Can we batch downloads together?
The University of Sydney
Page 29
Best Practices for Energy Management
– Reduce
– Upload/Download only necessary data [Week 5]
– Reduce – Caching [Week 5] – Compressing [Week 5]
– Defer
– Offloading (reactive/predictive) to energy efficient networks [Week 5]
– Batch
– Reduce the frequency of communication
– Use an exponential back-off pattern when you sync or poll to extend the time between subsequent polls
The University of Sydney Page 30
Best Practices for Energy Management
– Batch transfers and connections
– E.g. analytics information should batched together and queued to be
bundled with another download or upload
– In Android, JobScheduler API or Firebase JobDispatcher
The University of Sydney
Page 31
Example Question
You have decided to develop your own ads library to reduce device energy consumption. To properly configure the relevant parameters, you first conducted an experiment to measure the energy consumption of an Android phone when downloading an image of 100KB using the 3G (UMTS) Cellular network. The obtained average energy profile is in the Figure. Note that it takes 4 seconds to download a 100KB file and the idle energy consumption is 10 mJ per seconds as shown in the Figure.
Q1. Consider a scenario where there is 5 ads to be displayed during a 2.5 minutes time frame and the ad library refresh ads at every 30 seconds. Calculate the energy consumption of the app (in mJ). Note: assume each ad is of size 100KB.
Q2. Calculate the amount of energy that can be saved, if your ad library fetch all 5 ads at the same time.
The University of Sydney
Page 32
Best Practices for Energy Management
– Avoid polling server to see whether there is an update
– Let the server push data to the app only when there is an update
– Firebase Cloud Messaging (FCM) implements lightweight mechanism to transmit data.
– Measure the performance of your app using Network Profiler – Best programming practices
– https://developer.att.com/video-optimizer/docs/best-practices
The University of Sydney Page 33
Best Practices for Energy Management
Android Platform Battery Management
1. Doze
– Deferring background CPU and network activity for apps when the device is unused for long periods of time
– If the device is unplugged and stationary for a period of time, with the screen off, the device enters Doze mode.
– After that, system provides periodic maintenance windows
https://developer.android.com/training/monitoring-device-state/doze-standby
The University of Sydney Page 34
Best Practices for Energy Management
Android Platform Battery Management
– Doze restrictions
– Network access is suspended, including WiFi scans – Does not allow JobScheduler, SyncAdapters
– Ignores wake locks.
– Standard Alarms will not go off.
2. App Standby
– If the user does not touch the app for a certain period of time
– No current foreground processes
– No notifications
– Not a an admin app, Android move the app to Standby mode
– For list of all restrictions of Doze and App Standby
– https://developer.android.com/topic/performance/power/power-
details
The University of Sydney
Page 35
Best Practices for Energy Management
Android Platform Battery Management
3. App Standby Buckets
The system dynamically assigns each app to a priority bucket
– Active: App is currently being used or was very recently used
– Working set: App is in regular use
– Frequent: App is often used, but not every day – Rare: App is not frequently used
The University of Sydney
Page 36
Best Practices for Energy Management
Android Platform Battery Management
– Restrictions
– https://developer.android.com/topic/performance/power/power-details
The University of Sydney Page 37
Best Practices for Energy Management
Android Platform Battery Management
– Make sure your app functions well under Doze & App Standby modes
– If you need to set alarms that fire while in Doze,
use setAndAllowWhileIdle() or setExactAndAllowWhileIdle().
– Use Firebase Cloud Messaging (FCM)
– FCM is optimized to work with Doze and App Standby idle modes by
means of high-priority FCM messages
• Gives the app temporary access to network services and partial
wake locks, then returns the device or app to the idle state. – Partial exemption from restrictions
– Users can manually configure the list of exempted apps in Settings > Battery > Battery Optimization
– REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission can trigger a system dialog without user setting it manually
The University of Sydney Page 38
Best Practices for Energy Management
Android Platform Battery Management
Best practices to mange App Standby Bucket
– Donottrytomanipulatethesystemintoputtingyourappintoone bucket or another.
– Ifanappdoesnothavealauncheractivity,itmightneverbe promoted to the active bucket.
– Iftheapp’snotifications(includinghigh-priorityFCMmessage)aren’t actionable, users won’t be able to trigger the app’s promotion to the active bucket by interacting with the notifications.
– Youshouldbesuretotestsuchappswiththepackagesassignedto various buckets to make sure the app behaves properly.
– YoushouldtestyourappfullyinDozeandAppStandby
– ForcingthesystemintoDozemodebyrunningthefollowingcommand:
– $adbshelldumpsysdeviceidleforce-idle
– ForcingtheappintoAppStandbymodebyrunningthefollowing commands:
– $adbshelldumpsysbatteryunplug
– $adbshellamset-inactive
Page 39
Profile battery usage in Android
– Batterystats – a tool in Android framework
– Battery Historian – visualize data collected from Batterystats
1. Install Battery Historian
– https://github.com/google/battery-historian
– Using Docker
– Install Docker.
– Choose a port number and replace
9999
– For Linux and Mac OS X:
• Historian will be available at http://localhost:
– For Windows:
• You may have to enable Virtualization in your BIOS.
• FindtheIPaddressofdocket.
• Historian will be available at http://
The University of Sydney
Page 40
Profile battery usage in Android
– CollectdatawithBatteryStats
– UsingAndroidDebugBridge(ADB)
– https://developer.android.com/studio/command-line/adb – Followthiswalkthrough-
https://developer.android.com/studio/profile/battery-historian
• Connect the device
• Restart battery stats collection
– adb shell dumpsys batterystats –reset • Disconnect the device
• Play with your app
• Reconncet the devoce
• Dump battery stats
– adb shell dumpsys batterystats>[path/]batterystats.txt – adb bugreport>[path/]bugreport.txt
• Run Battery Historian and open bugreport file The University of Sydney
Page 41
Profile battery usage in Android
1 2
3
Add more metrics
Moreinfoincluding the color legend
Moreinfoofthe metric at that particular time
The University of Sydney
Page 42
Towards battery less devices
– Ambient energy harvesting
– Radiant – Light, Radio frequencies – Kinetic – Vibrations, human motion – Thermal – Temperature
– Chemical – Metabolic reactions
– Using body heat to power wearables
– PowerWatch
– https://www.powerwatch.com
– Kinetic energy harvesting shoes – https://newatlas.com/energy-
harvesting-shoes/41796/
– Kumara Kahatapitiya, Chamod Weerasinghe, Jinal Jayawardhana, Hiranya Kuruppu, Kanchana Thilakarathna, and Dileeka Días. 2018. Low-power step counting paired with electromagnetic energy harvesting for wearables. In Proceedings of the 2018 ACM International Symposium on Wearable Computers (ISWC ’18)
The University of Sydney Page 43
What’s Next ?
– Next week
– Mobile computing beyond smartphones
– Homework 2 is due next week !
– Guest/Industry Lecture – 26th October 2020 – Cross-Platform App Development
– Glenn Stephens from Microsoft
– Project proposal marks will be made available soon !
– If you want feedback about your proposal, please talk to me !
The University of Sydney
Page 44