improves the documentation
[src/app-framework-main.git] / doc / quick-tutorial.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4   <meta charset="utf-8">
5   <meta name="generator" content="pandoc">
6   <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
7   <meta name="author" content="Stephane Desneux">
8   <title>AGL Application Framework: A Quick Tutorial</title>
9   <style type="text/css">code{white-space: pre;}</style>
10   <!--[if lt IE 9]>
11     <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
12   <![endif]-->
13   <link rel="stylesheet" href="doc.css">
14 </head>
15 <body>
16 <header>
17 <h1 class="title">AGL Application Framework: A Quick Tutorial</h1>
18 <h2 class="author">Stephane Desneux</h2>
19 <h3 class="date">09 juin 2016</h3>
20 </header>
21 <nav id="TOC">
22 <ul>
23 <li><a href="#agl-application-framework-a-quick-tutorial">AGL Application Framework: A Quick Tutorial</a><ul>
24 <li><a href="#introduction">Introduction</a></li>
25 <li><a href="#sample-applications">Sample applications</a></li>
26 <li><a href="#using-the-cli-tool">Using the CLI tool</a><ul>
27 <li><a href="#setup-environment">Setup Environment</a></li>
28 <li><a href="#install-an-application">Install an application</a></li>
29 <li><a href="#list-installed-applications">List installed applications</a></li>
30 <li><a href="#get-information-about-an-application">Get information about an application</a></li>
31 <li><a href="#start-application">Start application</a></li>
32 <li><a href="#security-context">Security Context</a></li>
33 <li><a href="#check-running-applications">Check running applications</a></li>
34 <li><a href="#stop-application">Stop application</a></li>
35 <li><a href="#uninstall-application">Uninstall application</a></li>
36 </ul></li>
37 <li><a href="#afm-client-a-sample-html5-homescreen">afm-client: a sample HTML5 'Homescreen'</a><ul>
38 <li><a href="#installing-an-application">Installing an application</a></li>
39 <li><a href="#running-an-application">Running an application</a></li>
40 <li><a href="#stopping-an-application">Stopping an application</a></li>
41 <li><a href="#uninstalling-an-application">Uninstalling an application</a></li>
42 </ul></li>
43 <li><a href="#afb-client-a-template-for-angular-applications">afb-client: a template for Angular Applications</a></li>
44 </ul></li>
45 </ul>
46 </nav>
47 <h1 id="agl-application-framework-a-quick-tutorial">AGL Application Framework: A Quick Tutorial</h1>
48 <p>[TOC]</p>
49 <h2 id="introduction">Introduction</h2>
50 <p>This document proposes a quick tutorial to demonstrate the major functionnalities of the AGL Application Framework. For more complete information, please refer to the inline documentation available in the main git repository: https://gerrit.automotivelinux.org/gerrit/#/admin/projects/src/app-framework-main https://gerrit.automotivelinux.org/gerrit/#/admin/projects/src/app-framework-binder</p>
51 <p>For more information on AGL, please visit: https://www.automotivelinux.org/</p>
52 <hr />
53 <h2 id="sample-applications">Sample applications</h2>
54 <p>4 sample applications (.wgt files) are prebuilt and available at the following address: https://github.com/iotbzh/afm-widget-examples</p>
55 <p>You can get them by cloning this git repository on your desktop (will be useful later in this tutorial):</p>
56 <pre><code>$ git clone https://github.com/iotbzh/afm-widget-examples</code></pre>
57 <h2 id="using-the-cli-tool">Using the CLI tool</h2>
58 <h3 id="setup-environment">Setup Environment</h3>
59 <p>Connect your AGL target board to the network and copy some sample widgets on it through SSH (set BOARDIP with your board IP address) :</p>
60 <pre><code>$ cd afm-widget-examples
61 $ BOARDIP=1.2.3.4
62 $ scp *.wgt root@$BOARDIP:~/</code></pre>
63 <p>Connect through SSH on the target board and check for Application Framework daemons:</p>
64 <pre><code>$ ssh root@$BOARDIP
65 root@porter:~# ps -ef|grep bin/afm
66 afm        409     1  0 13:00 ?        00:00:00 /usr/bin/afm-system-daemon
67 root       505   499  0 13:01 ?        00:00:00 /usr/bin/afm-user-daemon
68 root       596   550  0 13:22 pts/0    00:00:00 grep afm</code></pre>
69 <p>We can see that there are two daemons running: * <strong>afm-system-daemon</strong> runs with a system user 'afm' and is responsible for installing/uninstalling packages * <strong>afm-user-daemon</strong> runs as a user daemon (currently as root because it's the only real user on the target board) and is responsible for the whole lifecycle of the applications running inside the user session.</p>
70 <p>The application framework has a tool running on the Command Line Interface (CLI). Using the <strong>afm-util</strong> command, you can install, uninstall, list, run, stop ... applications.</p>
71 <p>To begin, run '<strong>afm-util help</strong>' to get a quick help on commands:</p>
72 <pre><code>root@porter:~# afm-util help
73 usage: afm-util command [arg]
74
75 The commands are:
76
77   list
78   runnables      list the runnable widgets installed
79
80   add wgt
81   install wgt    install the wgt file
82
83   remove id
84   uninstall id   remove the installed widget of id
85
86   info id
87   detail id      print detail about the installed widget of id
88
89   ps
90   runners        list the running instance
91
92   run id
93   start id       start an instance of the widget of id
94
95   kill rid
96   terminate rid       terminate the running instance rid
97
98   stop rid
99   pause rid      stop the running instance rid
100
101   resume rid
102   continue rid   continue the previously rid
103
104   status rid
105   state rid     get status of the running instance rid</code></pre>
106 <h3 id="install-an-application">Install an application</h3>
107 <p>You can then install your first application:</p>
108 <pre><code>root@porter:~# afm-util install /home/root/annex.wgt 
109 { &quot;added&quot;: &quot;webapps-annex@0.0&quot; }</code></pre>
110 <p>Let's install a second application:</p>
111 <pre><code>root@porter:~# afm-util install /home/root/memory-match.wgt 
112 { &quot;added&quot;: &quot;webapps-memory-match@1.1&quot; }</code></pre>
113 <p>Note that usually, <strong>afm-util</strong> will return a <strong>JSON result</strong>, which is the common format for messages returned by the Application Framework daemons.</p>
114 <h3 id="list-installed-applications">List installed applications</h3>
115 <p>You can then list all installed applications:</p>
116 <pre><code>root@porter:~# afm-util list
117 [ { &quot;id&quot;: &quot;webapps-annex@0.0&quot;, &quot;version&quot;: &quot;0.0.10&quot;, &quot;width&quot;: 0, &quot;height&quot;: 0, &quot;name&quot;: &quot;Annex&quot;, &quot;description&quot;: &quot;Reversi\/Othello&quot;, &quot;shortname&quot;: &quot;&quot;, &quot;author&quot;: &quot;Todd Brandt &lt;todd.e.brandt@intel.com&gt;&quot; },
118  { &quot;id&quot;: &quot;webapps-memory-match@1.1&quot;, &quot;version&quot;: &quot;1.1.7&quot;, &quot;width&quot;: 0, &quot;height&quot;: 0, &quot;name&quot;: &quot;MemoryMatch&quot;, &quot;description&quot;: &quot;Memory match&quot;, &quot;shortname&quot;: &quot;&quot;, &quot;author&quot;: &quot;Todd Brandt &lt;todd.e.brandt@intel.com&gt;&quot; } ]</code></pre>
119 <p>Here, we can see the two previously installed applications.</p>
120 <h3 id="get-information-about-an-application">Get information about an application</h3>
121 <p>Let's get some details about the first application:</p>
122 <pre><code>root@porter:~# afm-util info webapps-annex@0.0
123 { &quot;id&quot;: &quot;webapps-annex@0.0&quot;, &quot;version&quot;: &quot;0.0.10&quot;, &quot;width&quot;: 0, &quot;height&quot;: 0, &quot;name&quot;: &quot;Annex&quot;, &quot;description&quot;: &quot;Reversi\/Othello&quot;, &quot;shortname&quot;: &quot;&quot;, &quot;author&quot;: &quot;Todd Brandt &lt;todd.e.brandt@intel.com&gt;&quot; }</code></pre>
124 <p>Note that AGL applications are mostly handled by afm-util through their IDs. In our example, the application ID is 'webapps-annex@0.0'.</p>
125 <h3 id="start-application">Start application</h3>
126 <p>Let's start the first application Annex:</p>
127 <pre><code>root@porter:~# afm-util start webapps-annex@0.0
128 1</code></pre>
129 <p>As the application is a HTML5 game, you should then get a webview running with QML on the board display.</p>
130 <h3 id="security-context">Security Context</h3>
131 <p>The application has been started in the user session, with a dedicated security context, enforced by SMACK. To illustrate this, we can take a look at the running processes and their respective SMACK labels:</p>
132 <pre><code>root@porter:~# ps -efZ |grep webapps-annex | grep -v grep
133 User::App::webapps-annex        root       716   491  0 13:19 ?        00:00:00 /usr/bin/afb-daemon --mode=local --readyfd=8 --alias=/icons /usr/share/afm/icons --port=12348 --rootdir=/usr/share/afm/applications/webapps-annex/0.0 --token=7D6D2F16 --sessiondir=/home/root/app-data/webapps-annex/.afb-daemon
134 User::App::webapps-annex        root       717   491  0 13:19 ?        00:00:00 /usr/bin/qt5/qmlscene http://localhost:12348/index.html?token=7D6D2F16 /usr/bin/web-runtime-webkit.qml</code></pre>
135 <p>In the previous result, we see that the application is composed of two processes: * the application binder (afb-daemon) * the application UI (qmlscene ...)</p>
136 <p>While most system processes run with the label 'System', we see that the application runs with a specific SMACK label 'User::App::webapps-annex': this label is used to force the application to follow a Mandatory Access Control (MAC) scheme. This means that those processes run in their own security context, isolated from the rest of the system (and other applications). Global security rules can then be applied to restrict access to all other user or system resources.</p>
137 <h3 id="check-running-applications">Check running applications</h3>
138 <p>To check for running applications, just run:</p>
139 <pre><code>root@porter:~# afm-util ps
140 [ { &quot;runid&quot;: 1, &quot;state&quot;: &quot;running&quot;, &quot;id&quot;: &quot;webapps-annex@0.0&quot; } ]</code></pre>
141 <p>The 'runid' is the application instance ID and is used as an argument for the subcommands controlling the application runtime state (kill/stop/resume/status)</p>
142 <h3 id="stop-application">Stop application</h3>
143 <p>To stop the application that was just started (the one with RUNID 1), just run the stop command:</p>
144 <pre><code>root@porter:~# afm-util terminate 1
145 true</code></pre>
146 <p>The application is now stopped, as confirmed by a list of running apps:</p>
147 <pre><code>root@porter:~# afm-util ps
148 [ ]</code></pre>
149 <h3 id="uninstall-application">Uninstall application</h3>
150 <p>To uninstall an application, simply use its ID:</p>
151 <pre><code>root@porter:~# afm-util uninstall webapps-annex@0.0
152 true</code></pre>
153 <p>Then list the installed apps to confirm the removal:</p>
154 <pre><code>root@porter:~# afm-util list
155 [ { &quot;id&quot;: &quot;webapps-memory-match@1.1&quot;, &quot;version&quot;: &quot;1.1.7&quot;, &quot;width&quot;: 0, &quot;height&quot;: 0, &quot;name&quot;: &quot;MemoryMatch&quot;, &quot;description&quot;: &quot;Memory match&quot;, &quot;shortname&quot;: &quot;&quot;, &quot;author&quot;: &quot;Todd Brandt &lt;todd.e.brandt@intel.com&gt;&quot; } ]</code></pre>
156 <h2 id="afm-client-a-sample-html5-homescreen">afm-client: a sample HTML5 'Homescreen'</h2>
157 <p><strong>afm-client</strong> is a HTML5 UI that allows to install/uninstall applications as well as starting/stopping them as already demonstrated with afm-util.</p>
158 <p>The HTML5 UI is accessible remotely through this URL: http://[board_ip]:1234/opa?token=132456789</p>
159 <h3 id="installing-an-application">Installing an application</h3>
160 <p>By clicking on the '<strong>Upload</strong>' button on the right, you can send an application package (WGT file) and install it. Select for example the file '<strong>rabbit.wgt</strong>' that was cloned initially from the git repository afm-widget-examples.</p>
161 <p>Then a popup requester ask for a confirmation: 'Upload Application rabbit.wgt ?'. Click on the '<strong>Install</strong>' button.</p>
162 <p>You should then see some changes in the toolbar: a new icon appeared, representing the freshly installed application.</p>
163 <h3 id="running-an-application">Running an application</h3>
164 <p>In the toolbar, click on the button representing the Rabbit application. You'll get a popup asking to: * start the application * or get some info about it * or uninstall it</p>
165 <p>Click on the 'start' item: the application starts and should be visible as a webview on the target board display. Note that at this point, we could also run the application remotely, that is in the same browser as the Homescreen app. By default, the application framework is configured to run applications 'locally' on the board display.</p>
166 <h3 id="stopping-an-application">Stopping an application</h3>
167 <p>In the Homescreen application, click again on the Rabbit application button, then select 'stop': the application then stops.</p>
168 <h3 id="uninstalling-an-application">Uninstalling an application</h3>
169 <p>From the same popup menu, you can select 'uninstall' to remove the application from the system. As a consequence, the application icon should disappear from the toolbar.</p>
170 <h2 id="afb-client-a-template-for-angular-applications">afb-client: a template for Angular Applications</h2>
171 <p>Another package '<strong>afb-client</strong>' is also available for testing. This is a sample HTML5 application demonstrating various basic capabilities of the Binder daemon. It can be used by developers as a template to start writing real AGL Applications.</p>
172 <p>This application is not available as WGT file yet and it should be started manually without any specific security context:</p>
173 <pre><code>root@porter:~# /usr/bin/afb-daemon --mode=remote --port=1235 --token=&#39;&#39; --sessiondir=/home/root/.afm-daemon --rootdir=/usr/share/agl/afb-client --alias=/icons:/usr/share/afm/icons</code></pre>
174 <p>Then you can access it from a browser: http://[board_ip]:1235/opa/?token=132456789</p>
175 <p>afb-client is a simple application to demonstrate the built-in capabilities of the binder daemon (handling sessions and security tokens, testing POSTs uploads...) and was used during the application framework development to validate the proposed features.</p>
176 </body>
177 </html>