CAreDroid: Adaptation Framework for Android Context-Aware Applications
Salma Elmalaki Lucas Wanner Mani Srivastava
Networked & Embedded Systems Laboratory
1
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 2015
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 20152
Photo Courtesy: Student Portal
Isolated Disconnected Unaware
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 2015
Computing … From Isolation to Awareness
3Photo Courtesy: Mobile innovation lab
4
Sense
5
Sense
Understand
6
Sense
Understand
Emergency
Adapt
7
Sense
Understand
Eme
Adapt
CAreDroid
8
Understand
Adapt
Challenges 1. Automatically adapt to the
environmental change at runtime. 2. Adaptation should be burden-free
for the user. 3. Overhead of reading the
environmental context should be small.
CAreDroid
Sense
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 2015
ACE: Exploiting Correlation for Energy-
Efficient and Continuous Context
Sensing (MobiSys’12)
What is Context-awareness?
9
adapt
sense
understand
Fusing mobile, sensor, and social data to fully enable context-aware computing
([HotMobile '10])A System Context-Aware Approach for Battery Lifetime Prediction in Smart Phones
([SAC’11])
ErdOS: Achieving Energy
Savings in Mobile
([MobiArch’11])
ContextOS: A Context Aware
Operating System for
Mobile Devices ([GreenCom’13])
The Latency Accuracy and Battery LAB Abstraction:
Programmer Productivity and Energy Efficiency for Continuous
Mobile Context Sensing ([OOPSLA’13]) Balancing Energy,
Latency and Accuracy for
Mobile Sensor Data Classification
(SenSys’11)SymPhoney: A
Coordinated Sensing Flow Execution
Engine for Concurrent Mobile
Sensing Applications (SenSys’12)
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 2015
Adaptation Realization
10
Program
f()f1()
Context-Aware System
Connectivity Battery Status
Activity
Location Temperature
Function Adaptation
Location
Activity
Battery Status
Connectivity
Temperature
f2()Location
f3()
fn()Battery Status
Activity
Location
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 2015
Adaptation Realization
11
Program
f()f1()
Context-Aware System
Connectivity Battery Status
Activity
Location Temperature
Function Adaptation
Location
Activity
Battery Status
Connectivity
Temperature
f2()Location
f3()
fn()Battery Status
Activity
Location
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 2015
Adaptation Realization
12
Program
f()f1()
Context-Aware System
Connectivity Battery Status
Activity
Location Temperature
Function Adaptation
Location
Activity
f2()Location
f3()
fn()
Activity
Location
CAreDroid Architecture
13
Usability Performance
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 2015
CAreDroid Architecture
14
app
f f1 f2 f3
g1 g2 g3
Application Layer
SensitivityConfig
File
System Layer
Sensitive function registration & config parsing
ContextMonitoring
Context Sensors
AdaptationEngine
Temperature Energy Connectivity …
g
Application Layer
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 2015
CAreDroid Architecture
15
app
f f1 f2 f3
g1 g2 g3
Application Layer
SensitivityConfig
File
System Layer
Sensitive function registration & config parsing
ContextMonitoring
Context Sensors
AdaptationEngine
Temperature Energy Connectivity …
g
Application Layer
System Layer
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 2015
CAreDroid Architecture
16
app
f f1 f2 f3
g1 g2 g3
Application Layer
SensitivityConfig
File
System Layer
Sensitive function registration & config parsing
ContextMonitoring
Context Sensors
AdaptationEngine
Temperature Energy Connectivity …
g
Context Sensors
Application Layer
System Layer
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 2015
Sensitivity Configuration File
17
app
f f1 f2 f3
g1 g2 g3
Application Layer
SensitivityConfig
File
System Layer
Sensitive function registration & config parsing
ContextMonitoring
Context Sensors
AdaptationEngine
Temperature Energy Connectivity …
g
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 2015
Function Registration
18
app
f f1 f2 f3
g1 g2 g3
Application Layer
SensitivityConfig
File
System Layer
Sensitive function registration & config parsing
ContextMonitoring
Context Sensors
AdaptationEngine
Temperature Energy Connectivity …
g
• The sensitive function registration part is responsible for: • understanding the
ranges of operations of each method
• integrate it in the Android run-time system
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 2015
Function Registration & Config. Parsing
19
extended .odex
Development time
SensitivityConfigFile
Installation time
Sensitive Method Discovery
CAr
eDrio
d Fl
ow
Sensitivity Config File
SensitivityConfigFile .java
SensitivityConfigFile
SensitivityConfigFile .class
Compilation and packaging time
.dex
Sensitivity Config File
Nor
mal
And
roid
Fl
ow
.odex
Replacement MapTable of Range Identifiers
intercept
Table of Range IdentifiersTable of Range Identifiers
.apk
app
f f1 f2 f3
g1 g2 g3
Application Layer
SensitivityConfig
File
System Layer
Sensitive function registration & config parsing
ContextMonitoring
Context Sensors
AdaptationEngine
Temperature Energy Connectivity …
g
Normal Android
flow
CAreDroid flow
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 2015
Function Registration & Config. Parsing
20
extended .odex
Development time
SensitivityConfigFile
Installation time
Sensitive Method Discovery
CAr
eDrio
d Fl
ow
Sensitivity Config File
SensitivityConfigFile .java
SensitivityConfigFile
SensitivityConfigFile .class
Compilation and packaging time
.dex
Sensitivity Config File
Nor
mal
And
roid
Fl
ow
.odex
Replacement MapTable of Range Identifiers
intercept
Table of Range IdentifiersTable of Range Identifiers
.apk
app
f f1 f2 f3
g1 g2 g3
Application Layer
SensitivityConfig
File
System Layer
Sensitive function registration & config parsing
ContextMonitoring
Context Sensors
AdaptationEngine
Temperature Energy Connectivity …
g
Normal Android
flow
CAreDroid flow
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 2015
Function Registration & Config. Parsing
21
extended .odex
Development time
SensitivityConfigFile
Installation time
Sensitive Method Discovery
CAr
eDrio
d Fl
ow
Sensitivity Config File
SensitivityConfigFile .java
SensitivityConfigFile
SensitivityConfigFile .class
Compilation and packaging time
.dex
Sensitivity Config File
Nor
mal
And
roid
Fl
ow
.odex
Replacement MapTable of Range Identifiers
intercept
Table of Range IdentifiersTable of Range Identifiers
.apk
app
f f1 f2 f3
g1 g2 g3
Application Layer
SensitivityConfig
File
System Layer
Sensitive function registration & config parsing
ContextMonitoring
Context Sensors
AdaptationEngine
Temperature Energy Connectivity …
g
Normal Android
flow
CAreDroid flow
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 2015
Function Registration & Config. Parsing
22
extended .odex
Development time
SensitivityConfigFile
Installation time
Sensitive Method Discovery
CAr
eDrio
d Fl
ow
Sensitivity Config File
SensitivityConfigFile .java
SensitivityConfigFile
SensitivityConfigFile .class
Compilation and packaging time
.dex
Sensitivity Config File
Nor
mal
And
roid
Fl
ow
.odex
Replacement MapTable of Range Identifiers
intercept
Table of Range IdentifiersTable of Range Identifiers
.apk
app
f f1 f2 f3
g1 g2 g3
Application Layer
SensitivityConfig
File
System Layer
Sensitive function registration & config parsing
ContextMonitoring
Context Sensors
AdaptationEngine
Temperature Energy Connectivity …
g
Normal Android
flow
CAreDroid flow
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 2015
Context Monitoring
23
1. Battery state: capacity, temperature, voltage
2. Connectivity state: WiFi connection status, WiFi link quality, RSSI received signal strength indication
3. Location: GPS location 4. Mobility: run, walk, still
• Bypassing the HAL layer and the associated sensor managers.
• Snooping on the interface between the HAL and the low-level device drivers through the sysfs virtual file system.
app
f f1 f2 f3
g1 g2 g3
Application Layer
SensitivityConfig
File
System Layer
Sensitive function registration & config parsing
ContextMonitoring
Context Sensors
AdaptationEngine
Temperature Energy Connectivity …
g
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 2015
Adaptation Engine
24
app
f f1 f2 f3
g1 g2 g3
Application Layer
SensitivityConfig
File
System Layer
Sensitive function registration & config parsing
ContextMonitoring
Context Sensors
AdaptationEngine
Temperature Energy Connectivity …
g
It is where the method replacement happens at runtime.
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 2015
Adaptation Engine
2525
invoke-virtual-quick
CAr
eDrio
d Fl
owN
orm
al A
ndro
id
Flow
Replacement Map
intercept Dalvik Interpreter Method ID Class Virtual
Table
Class ID,Pointer to method byte code
Execute method
CAreDroid Dalvik Interpreter Extension
Class ID
Table of Range IdentifiersTable of Range IdentifiersTable of Range Identifiers
Operation Range Identifiers CAreDroid
Decision Graph
Current Context
Replaced Method ID
Class ID,Resolution Cache update cache
Replaced Method ID
Class ID,
cache miss cache hit Method ID
Class ID,
app
f f1 f2 f3
g1 g2 g3
Application Layer
SensitivityConfig
File
System Layer
Sensitive function registration & config parsing
ContextMonitoring
Context Sensors
AdaptationEngine
Temperature Energy Connectivity …
g
Normal Android
flow
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 2015
Adaptation Engine
2626
invoke-virtual-quick
CAr
eDrio
d Fl
owN
orm
al A
ndro
id
Flow
Replacement Map
intercept Dalvik Interpreter Method ID Class Virtual
Table
Class ID,Pointer to method byte code
Execute method
CAreDroid Dalvik Interpreter Extension
Class ID
Table of Range IdentifiersTable of Range IdentifiersTable of Range Identifiers
Operation Range Identifiers CAreDroid
Decision Graph
Current Context
Replaced Method ID
Class ID,Resolution Cache update cache
Replaced Method ID
Class ID,
cache miss cache hit Method ID
Class ID,
app
f f1 f2 f3
g1 g2 g3
Application Layer
SensitivityConfig
File
System Layer
Sensitive function registration & config parsing
ContextMonitoring
Context Sensors
AdaptationEngine
Temperature Energy Connectivity …
g
Normal Android
flow
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 201527
Adaptation Engine
27
invoke-virtual-quick
CAr
eDrio
d Fl
owN
orm
al A
ndro
id
Flow
Replacement Map
intercept Dalvik Interpreter Method ID Class Virtual
Table
Class ID,Pointer to method byte code
Execute method
CAreDroid Dalvik Interpreter Extension
Class ID
Table of Range IdentifiersTable of Range IdentifiersTable of Range Identifiers
Operation Range Identifiers CAreDroid
Decision Graph
Current Context
Replaced Method ID
Class ID,Resolution Cache update cache
Replaced Method ID
Class ID,
cache miss cache hit Method ID
Class ID,
app
f f1 f2 f3
g1 g2 g3
Application Layer
SensitivityConfig
File
System Layer
Sensitive function registration & config parsing
ContextMonitoring
Context Sensors
AdaptationEngine
Temperature Energy Connectivity …
g
CAreDroid flow
Normal Android
flow
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 201528
Adaptation Engine
28
invoke-virtual-quick
CAr
eDrio
d Fl
owN
orm
al A
ndro
id
Flow
Replacement Map
intercept Dalvik Interpreter Method ID Class Virtual
Table
Class ID,Pointer to method byte code
Execute method
CAreDroid Dalvik Interpreter Extension
Class ID
Table of Range IdentifiersTable of Range IdentifiersTable of Range Identifiers
Operation Range Identifiers CAreDroid
Decision Graph
Current Context
Replaced Method ID
Class ID,Resolution Cache update cache
Replaced Method ID
Class ID,
cache miss cache hit Method ID
Class ID,
app
f f1 f2 f3
g1 g2 g3
Application Layer
SensitivityConfig
File
System Layer
Sensitive function registration & config parsing
ContextMonitoring
Context Sensors
AdaptationEngine
Temperature Energy Connectivity …
g
CAreDroid flow
Normal Android
flow
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 201529
Adaptation Engine
29
invoke-virtual-quick
CAr
eDrio
d Fl
owN
orm
al A
ndro
id
Flow
Replacement Map
intercept Dalvik Interpreter Method ID Class Virtual
Table
Class ID,Pointer to method byte code
Execute method
CAreDroid Dalvik Interpreter Extension
Class ID
Table of Range IdentifiersTable of Range IdentifiersTable of Range Identifiers
Operation Range Identifiers CAreDroid
Decision Graph
Current Context
Replaced Method ID
Class ID,Resolution Cache update cache
Replaced Method ID
Class ID,
cache miss cache hit Method ID
Class ID,
app
f f1 f2 f3
g1 g2 g3
Application Layer
SensitivityConfig
File
System Layer
Sensitive function registration & config parsing
ContextMonitoring
Context Sensors
AdaptationEngine
Temperature Energy Connectivity …
g
CAreDroid flow
Normal Android
flow
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 201530
Adaptation Engine
30
invoke-virtual-quick
CAr
eDrio
d Fl
owN
orm
al A
ndro
id
Flow
Replacement Map
intercept Dalvik Interpreter Method ID Class Virtual
Table
Class ID,Pointer to method byte code
Execute method
CAreDroid Dalvik Interpreter Extension
Class ID
Table of Range IdentifiersTable of Range IdentifiersTable of Range Identifiers
Operation Range Identifiers CAreDroid
Decision Graph
Current Context
Replaced Method ID
Class ID,Resolution Cache update cache
Replaced Method ID
Class ID,
cache miss cache hit Method ID
Class ID,
app
f f1 f2 f3
g1 g2 g3
Application Layer
SensitivityConfig
File
System Layer
Sensitive function registration & config parsing
ContextMonitoring
Context Sensors
AdaptationEngine
Temperature Energy Connectivity …
g
CAreDroid flow
Normal Android
flow
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 201531
Adaptation Engine
31
invoke-virtual-quick
CAr
eDrio
d Fl
owN
orm
al A
ndro
id
Flow
Replacement Map
intercept Dalvik Interpreter Method ID Class Virtual
Table
Class ID,Pointer to method byte code
Execute method
CAreDroid Dalvik Interpreter Extension
Class ID
Table of Range IdentifiersTable of Range IdentifiersTable of Range Identifiers
Operation Range Identifiers CAreDroid
Decision Graph
Current Context
Replaced Method ID
Class ID,Resolution Cache update cache
Replaced Method ID
Class ID,
cache miss cache hit Method ID
Class ID,
app
f f1 f2 f3
g1 g2 g3
Application Layer
SensitivityConfig
File
System Layer
Sensitive function registration & config parsing
ContextMonitoring
Context Sensors
AdaptationEngine
Temperature Energy Connectivity …
g
Best Fit policy Must Fit policy
CAreDroid flow
Normal Android
flow
B
T
V
S
W
Q
M
L
M1 M2 M3 M4 M5
1 2 3 4 5
2 3 4 1 2
1 4 2 3 4
1 2 3 4 5
2 2 1 3 3
4 3 2 1 2
2 3 3 1 2
1 4 3 2 3
1 2 3 4 5
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3
1 2 3 4
1 2 3
1 2 3 4
5
B
T
V
S
W
Q
M
L
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 201532
Adaptation Engine
32
invoke-virtual-quick
CAr
eDrio
d Fl
owN
orm
al A
ndro
id
Flow
Replacement Map
intercept Dalvik Interpreter Method ID Class Virtual
Table
Class ID,Pointer to method byte code
Execute method
CAreDroid Dalvik Interpreter Extension
Class ID
Table of Range IdentifiersTable of Range IdentifiersTable of Range Identifiers
Operation Range Identifiers CAreDroid
Decision Graph
Current Context
Replaced Method ID
Class ID,Resolution Cache update cache
Replaced Method ID
Class ID,
cache miss cache hit Method ID
Class ID,
app
f f1 f2 f3
g1 g2 g3
Application Layer
SensitivityConfig
File
System Layer
Sensitive function registration & config parsing
ContextMonitoring
Context Sensors
AdaptationEngine
Temperature Energy Connectivity …
g
CAreDroid flow
Normal Android
flow
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 2015
Adaptation Engine
3333
invoke-virtual-quick
CAr
eDrio
d Fl
owN
orm
al A
ndro
id
Flow
Replacement Map
intercept Dalvik Interpreter Method ID Class Virtual
Table
Class ID,Pointer to method byte code
Execute method
CAreDroid Dalvik Interpreter Extension
Class ID
Table of Range IdentifiersTable of Range IdentifiersTable of Range Identifiers
Operation Range Identifiers CAreDroid
Decision Graph
Current Context
Replaced Method ID
Class ID,Resolution Cache update cache
Replaced Method ID
Class ID,
cache miss cache hit Method ID
Class ID,
app
f f1 f2 f3
g1 g2 g3
Application Layer
SensitivityConfig
File
System Layer
Sensitive function registration & config parsing
ContextMonitoring
Context Sensors
AdaptationEngine
Temperature Energy Connectivity …
g
CAreDroid flow
Normal Android
flow
Evaluation
34
1. Push context monitoring and adaptation to runtime system
2. At least 2x fewer lines of code 3. At least 10× more efficient in execution time
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 2015
Context-aware Camera
3535
Still position Walking !(non context aware)
Walking !(with CAreDroid)
Still position
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 2015
Context-aware Camera
3636
Still position Walking !(non context aware)
Walking !(with CAreDroid)
Walking (non-context aware)
Still position
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 20153737
Still position Walking !(non context aware)
Walking !(with CAreDroid)
Context-aware Camera
37
Still position Walking !(non context aware)
Walking !(with CAreDroid)
Walking (With CAreDroid)
Walking (non-context aware)
Still position
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 2015
Analysis - Significant Line of Code (SLOC)
38
Platform SLOC %Increase
Analysis of CAreDroid
39
1. Analyze the effect of cache in the adaptation engine 2. Examine the overhead of context-monitoring
module 3. The difference in energy and execution time
between pure Java implementation using Android APIs and CAreDroid
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 2015
Testbed and testing environment
•Nexus 4
•Android 4.2 - API 17
•Overhead of system image is 4.6%
40
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 2015
Analysis—Execution time
41
f1 f2 f3
Platform OverheadWithout cache With cache
CPU time (ms)
14.213
f1 f2 f3
f1 f2 f3
f1 f2 f3
Average of 10 executions with variance 0.5% ~ 1%
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 2015
Analysis — Energy
42
0 0.5 1 1.5 2 2.5
0
1,000
2,000
3,000
4,000
5,000
Time [hr]
En
erg
y[J]
Pure Java
Must fit
Best fit
Non-context aware
1. CAreDroid consumes only 6.73% more energy compared with the non-context aware implementation and
2. CAreDroid gives 69.33% energy saving compared to the pure Java implementation.
3. Measurements are taken every 5 seconds. Average is shown with variance < 1%
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 2015
Future Work
1. Migrate to new versions of Android that are based on ART instead of Dalvik (Kitkat and Lollipop).
2. Add support for more abstract contexts, for example, stress, smoking, fitness, … etc
3. The adaptation can be privacy-aware.
4. Time of the day is another axis that can be used to enhancing the adaptation support
43
Thank you!
44
http://www.seas.ucla.edu/~salma/
NESLNetworked & EmbeddedSystems Laboratory
Copyright (c) 2015
Keeping the developer/user in the loop
• Make the user not fully obfuscated
• Why this adaptation takes place?
• Special CAreDroid API - “read_operating_point()”
45