AAnnddrrooiidd EExxeeccuuttaabbllee MMooddeelliinngg:: 
BBeeyyoonndd AAnnddrrooiidd PPrrooggrraammmmiinngg 
Olivier Le Goaër 
olivier.legoaer@univ-pau.fr 
MobiApps # Session 1: Smart Systems 
Barcelona, 2014
AAggeennddaa 
 Context of Work 
 Moving Executable Models to Android 
 A software architecture powered by PauWare 
API 
 Conclusion & perspectives 
Olivier Le Goaer @ MobiApps 2014
CCoonntteexxtt ooff WWoorrkk
WWee eenntteerreedd tthhee mmooddeelliinngg eerraa 
 The power of software modeling 
 Mental effort that differs from that required for programming 
 A higher level of abstraction provides a better reasoning support 
 supposed to be more concise, more intelligible, more agile… 
 Model-driven engineering field (MDE) 
 Promotes the « model everywhere » vision 
 Models are considered first-class citizen during the software life-cycle 
 UML was just the tip of the iceberg; DSL are now at the forefront 
Olivier Le Goaer @ MobiApps 2014
SSttaattiicc vveerrssuuss ddyynnaammiicc mmooddeellss 
 Classical MDE use static model 
 A model = a blueprint for a software viewpoint that one can refer 
to do stuff 
 Testing, code generation, requirements elicitation, proofs, … 
 A recent MDE trend is about dynamic model 
 Extension that aims to breathe life into models 
 A dynamic model = an animated/actioned blueprint that plays a 
leading role 
 Simulation and validation, rapid prototyping, ... 
 There is no code generation; The model is sufficient in itself. 
Olivier Le Goaer @ MobiApps 2014
EExxeeccuuttaabbllee mmooddeellss 
 An execution engine is required 
 An interpreter manages each execution step of the model under 
execution 
 Specific to each kind of models (petri nets, statecharts, workflows, 
activity diagrams…) 
 Statechart is a prominent example of 
executable model 
 Describes the behavior of something in terms of states and 
transitions 
 Is a general-purpose modeling language 
 User navigation, Control flow... and generally speaking any object's life-cycle 
Olivier Le Goaer @ MobiApps 2014
EExxeeccuuttaabbllee ssttaatteecchhaarrttss ffoorr rreeaall...... 
From “Statecharts: A visual formalism for complex systems” by David HAREL 
Olivier Le Goaer @ MobiApps 2014
MMoovviinngg EExxeeccuuttaabbllee MMooddeellss ttoo 
AAnnddrrooiidd
IIlllluussttrraattiioonn wwiitthh aa ttooyy mmoobbAApppp 
 Create a tiny mobApp « Energy Assistant » 
 An avatar gives (not too serious) advices to the end-user based 
on both the battery level and the usage of his device 
 Statechart formalism to the rescue 
 This kind of mobApp can be easily modeled with a statechart 
 States will reflect the battery level 
 Events will be mapped to Android system events 
 Actions will be short notifications to the end-user (can be much more complex of 
course) 
 Accessible even to non-specialists of Android platform 
 Requires a basic knowledge of how any mobile device operates 
 This allows us to imagine that a customer can entirely model its needs in that way 
Olivier Le Goaer @ MobiApps 2014
SSttaatteecchhaarrtt mmooddeelliinngg gguuiiddeelliinnee 
 The control flow rises up to the model level 
 Much more easy to understand and to maintain that when buried 
in code 
 Hence be careful that no control flow resides into the action code 
A 
B 
[isOk] e1 / foo() 
Olivier Le Goaer @ MobiApps 2014 
public void foo() { 
//do something 
if (!isOk) { 
//do something else 
} 
} 
Interferes 
with the 
model !
EEnneerrggyy AAssssiissttaanntt''ss bbeehhaavviioorr 
Olivier Le Goaer @ MobiApps 2014 
 4 states 
 Including a composite 
 2 pseudos-states 
 2 initials 
 0 final 
 7 transitions 
 No guards 
 7 Android-related 
events 
 1 kind of action : 
« alert »
AAnnddrrooiidd mmooddeelliinngg?? RReeaallllyy?? 
 Classical code = 
programming effort 
 "I am writing the code of my 
Android app. My focus is at 
the program-level." 
 Complex, 
unmaintainable code 
 Nested if, switch 
statements, ... 
 Flag variables and 
« global » variables to 
record what happened 
previously... 
Olivier Le Goaer @ MobiApps 2014 
 Model-oriented code 
= modeling effort 
 "I am writing the code that 
describes a statechart 
model of my Android app. 
My focus is at the model-level." 
 Clear separation of 
concerns 
 Statechart description 
 Actions' implementation 
 Let an engine executes 
directly the model
A software AArrcchhiitteeccttuurree ppoowweerreedd bbyy 
PPaauuWWaarree AAPPII
PPaauuWWaarree EExxeeccuuttiioonn EEnnggiinnee 
 PauWare engine (www.pauware.com) 
 Lightweight execution engine for statechart models 
 Implements the complete UML2 execution semantics specification 
 API written in Java (hence ported effortlessly to Android) 
Engine that executes the model 
loaded (« run-to-completion ») 
Olivier Le Goaer @ MobiApps 2014 
JJaavvaa 
PPaauuWWaarree AAPPII 
Code/xml that describes the 
statechart model to be loaded 
Consumes an 
event for each 
execution step 
Free implementation of 
the actions 
(called by reflection from the engine)
AArrcchhiitteeccttuurree oovveerrvviieeww 
Java or xmi or scxml 
Olivier Le Goaer @ MobiApps 2014 
SERVICE 
BROADCAST 
RECEIVER 
AAnnddrrooiidd OOSS 
ANDROID 
CONNECTOR 
e1/foo 
e1 
public void foo() { 
//do something 
} 
public void bar() { 
//do other thing 
} 
A statechart model 
runs-to-completion 
PauWare 
Execution 
Engine 
starts invokes
AAnn eexxaammppllee 
Olivier Le Goaer @ MobiApps 2014 
Active state 
Triggered 
transition
EEnneerrggyy AAssssiissttaanntt''ss AArrcchhiitteeccttuurree 
Olivier Le Goaer @ MobiApps 2014 
SERVICE 
BROADCAST 
RECEIVER 
AAnnddrrooiidd OOSS 
ANDROID 
CONNECTOR 
PauWare 
Execution 
Engine 
ACTION_POWER_CONNECTED 
void alert(String msg) { 
Notification noti 
= new Notification.Builder 
... 
} 
runs-to-completion 
starts invokes
SSccrreeeennsshhoottss 
Assistant available 
from the Launcher 
Olivier Le Goaer @ MobiApps 2014 
Assistant notification 
POWER_CONNECTED
CCoonncclluussiioonn 
 Executable models 
 There is no code generation, the model is directly executed on a 
target platform through an engine (.i.e. an interpreter) 
 Android modeling rather than android 
programming 
 Shift the efforts on modeling activities (for those who are not 
allergic to modeling ;-) 
 Limited knowledge of the underlying platform is enough 
 Stateshart formalism and beyond 
 Widespread and well suited for aspects of apps (partly or entirely) 
 A lot of further modeling languages can be useful... 
Olivier Le Goaer @ MobiApps 2014
PPeerrssppeeccttiivvee:: uuppddaattee mmaaddee eeaassyy 
 Ability to load a new model on-the-fly 
 A model is just a (meta)data taken as input of the engine 
 Actions' implementation have to stay unchanged 
 Challenge: the execution continuum between old and new model 
Fresh (meta)data retrieval 
Olivier Le Goaer @ MobiApps 2014 
SERVICE 
BROADCAST 
RECEIVER 
AAnnddrrooiidd OOSS 
ANDROID 
CONNECTOR 
runs-to-completion 
PauWare 
Execution 
Engine 
ACTION_POWER_CONNECTED 
void alert(String msg) { 
Notification noti 
= new Notification.Builder 
... 
} 
starts invokes 
Model 
Server 
Google 
Cloud 
Messaging Push Notification
QQuueessttiioonnss??

Android executable modeling: beyond android programming

  • 1.
    AAnnddrrooiidd EExxeeccuuttaabbllee MMooddeelliinngg:: BBeeyyoonndd AAnnddrrooiidd PPrrooggrraammmmiinngg Olivier Le Goaër olivier.legoaer@univ-pau.fr MobiApps # Session 1: Smart Systems Barcelona, 2014
  • 2.
    AAggeennddaa  Contextof Work  Moving Executable Models to Android  A software architecture powered by PauWare API  Conclusion & perspectives Olivier Le Goaer @ MobiApps 2014
  • 3.
  • 4.
    WWee eenntteerreedd tthheemmooddeelliinngg eerraa  The power of software modeling  Mental effort that differs from that required for programming  A higher level of abstraction provides a better reasoning support  supposed to be more concise, more intelligible, more agile…  Model-driven engineering field (MDE)  Promotes the « model everywhere » vision  Models are considered first-class citizen during the software life-cycle  UML was just the tip of the iceberg; DSL are now at the forefront Olivier Le Goaer @ MobiApps 2014
  • 5.
    SSttaattiicc vveerrssuuss ddyynnaammiiccmmooddeellss  Classical MDE use static model  A model = a blueprint for a software viewpoint that one can refer to do stuff  Testing, code generation, requirements elicitation, proofs, …  A recent MDE trend is about dynamic model  Extension that aims to breathe life into models  A dynamic model = an animated/actioned blueprint that plays a leading role  Simulation and validation, rapid prototyping, ...  There is no code generation; The model is sufficient in itself. Olivier Le Goaer @ MobiApps 2014
  • 6.
    EExxeeccuuttaabbllee mmooddeellss An execution engine is required  An interpreter manages each execution step of the model under execution  Specific to each kind of models (petri nets, statecharts, workflows, activity diagrams…)  Statechart is a prominent example of executable model  Describes the behavior of something in terms of states and transitions  Is a general-purpose modeling language  User navigation, Control flow... and generally speaking any object's life-cycle Olivier Le Goaer @ MobiApps 2014
  • 7.
    EExxeeccuuttaabbllee ssttaatteecchhaarrttss ffoorrrreeaall...... From “Statecharts: A visual formalism for complex systems” by David HAREL Olivier Le Goaer @ MobiApps 2014
  • 8.
  • 9.
    IIlllluussttrraattiioonn wwiitthh aattooyy mmoobbAApppp  Create a tiny mobApp « Energy Assistant »  An avatar gives (not too serious) advices to the end-user based on both the battery level and the usage of his device  Statechart formalism to the rescue  This kind of mobApp can be easily modeled with a statechart  States will reflect the battery level  Events will be mapped to Android system events  Actions will be short notifications to the end-user (can be much more complex of course)  Accessible even to non-specialists of Android platform  Requires a basic knowledge of how any mobile device operates  This allows us to imagine that a customer can entirely model its needs in that way Olivier Le Goaer @ MobiApps 2014
  • 10.
    SSttaatteecchhaarrtt mmooddeelliinngg gguuiiddeelliinnee  The control flow rises up to the model level  Much more easy to understand and to maintain that when buried in code  Hence be careful that no control flow resides into the action code A B [isOk] e1 / foo() Olivier Le Goaer @ MobiApps 2014 public void foo() { //do something if (!isOk) { //do something else } } Interferes with the model !
  • 11.
    EEnneerrggyy AAssssiissttaanntt''ss bbeehhaavviioorr Olivier Le Goaer @ MobiApps 2014  4 states  Including a composite  2 pseudos-states  2 initials  0 final  7 transitions  No guards  7 Android-related events  1 kind of action : « alert »
  • 12.
    AAnnddrrooiidd mmooddeelliinngg?? RReeaallllyy??  Classical code = programming effort  "I am writing the code of my Android app. My focus is at the program-level."  Complex, unmaintainable code  Nested if, switch statements, ...  Flag variables and « global » variables to record what happened previously... Olivier Le Goaer @ MobiApps 2014  Model-oriented code = modeling effort  "I am writing the code that describes a statechart model of my Android app. My focus is at the model-level."  Clear separation of concerns  Statechart description  Actions' implementation  Let an engine executes directly the model
  • 13.
    A software AArrcchhiitteeccttuurreeppoowweerreedd bbyy PPaauuWWaarree AAPPII
  • 14.
    PPaauuWWaarree EExxeeccuuttiioonn EEnnggiinnee  PauWare engine (www.pauware.com)  Lightweight execution engine for statechart models  Implements the complete UML2 execution semantics specification  API written in Java (hence ported effortlessly to Android) Engine that executes the model loaded (« run-to-completion ») Olivier Le Goaer @ MobiApps 2014 JJaavvaa PPaauuWWaarree AAPPII Code/xml that describes the statechart model to be loaded Consumes an event for each execution step Free implementation of the actions (called by reflection from the engine)
  • 15.
    AArrcchhiitteeccttuurree oovveerrvviieeww Javaor xmi or scxml Olivier Le Goaer @ MobiApps 2014 SERVICE BROADCAST RECEIVER AAnnddrrooiidd OOSS ANDROID CONNECTOR e1/foo e1 public void foo() { //do something } public void bar() { //do other thing } A statechart model runs-to-completion PauWare Execution Engine starts invokes
  • 16.
    AAnn eexxaammppllee OlivierLe Goaer @ MobiApps 2014 Active state Triggered transition
  • 17.
    EEnneerrggyy AAssssiissttaanntt''ss AArrcchhiitteeccttuurree Olivier Le Goaer @ MobiApps 2014 SERVICE BROADCAST RECEIVER AAnnddrrooiidd OOSS ANDROID CONNECTOR PauWare Execution Engine ACTION_POWER_CONNECTED void alert(String msg) { Notification noti = new Notification.Builder ... } runs-to-completion starts invokes
  • 18.
    SSccrreeeennsshhoottss Assistant available from the Launcher Olivier Le Goaer @ MobiApps 2014 Assistant notification POWER_CONNECTED
  • 19.
    CCoonncclluussiioonn  Executablemodels  There is no code generation, the model is directly executed on a target platform through an engine (.i.e. an interpreter)  Android modeling rather than android programming  Shift the efforts on modeling activities (for those who are not allergic to modeling ;-)  Limited knowledge of the underlying platform is enough  Stateshart formalism and beyond  Widespread and well suited for aspects of apps (partly or entirely)  A lot of further modeling languages can be useful... Olivier Le Goaer @ MobiApps 2014
  • 20.
    PPeerrssppeeccttiivvee:: uuppddaattee mmaaddeeeeaassyy  Ability to load a new model on-the-fly  A model is just a (meta)data taken as input of the engine  Actions' implementation have to stay unchanged  Challenge: the execution continuum between old and new model Fresh (meta)data retrieval Olivier Le Goaer @ MobiApps 2014 SERVICE BROADCAST RECEIVER AAnnddrrooiidd OOSS ANDROID CONNECTOR runs-to-completion PauWare Execution Engine ACTION_POWER_CONNECTED void alert(String msg) { Notification noti = new Notification.Builder ... } starts invokes Model Server Google Cloud Messaging Push Notification
  • 21.

Editor's Notes

  • #5 Lifecycle : (design-time & run-time & maintenance) Some students are very skilled for programming and have difficulties with modeling. It is very surprising
  • #11 A basic principle is that In that case, one must add another transition wich explicit the guard and the action
  • #12 Notice that there is no final state. It is not mandatory These are build-in android events Nested states
  • #13 Described by this sentence Now imagine a very complex model: composite state, history state : power of statechart
  • #19 The mobApp have to be previously launched