13 This document describes what we intend to do. It may happen that our
14 current implementation and the content of this document differ.
16 In case of differences, it is assumed that this document is right
17 and the implementation is wrong.
23 The daemon **afm-user-daemon** is in charge of handling
24 applications for one user. Its main tasks are:
26 - enumerate the applications that the user can run
27 and keep the list avalable on demand
29 - start applications for the user, set their running
30 environment, set their security context
32 - list the current runner applications
34 - stop (aka pause), continue (aka resume), terminate
35 the running instance of application
37 - transfer requests for installation or uninstallation
38 of applications to the dedicated system daemon
41 The **afm-user-daemon** takes its orders from the session
44 The figure below summarizes the situation of the
45 **afm-user-daemon** in the system.
47 +------------------------------------------------------------+
49 | +---------------------+ |
50 | +---------------------+ | Smack isolated | |
51 | | D-Bus session + | APPLICATIONS | |
52 | +----------+----------+ +---------+-----------+ |
55 | +----------+--------------------------+-----------+ |
57 | | afm-user-daemon | |
59 | +----------+----------------------+----------+----+ |
62 :================|======================|==========:=========:
64 | +----------+----------+ +-----+-----+ : |
65 | | D-Bus system +-----+ CYNARA | : |
66 | +----------+----------+ +-----+-----+ : |
68 | +----------+---------+ +-------+----------+----+ |
69 | | afm-system-daemon +----+ SECURITY-MANAGER | |
70 | +--------------------+ +-----------------------+ |
73 +------------------------------------------------------------+
76 Tasks of **afm-user-daemon**
77 ----------------------------
79 ### Maintaining list of applications ###
81 At start **afm-user-daemon** scans the directories containing
82 the applications and load in memory the list applications
83 availables to the current user.
85 When **afm-system-daemon** installs or removes an application,
86 it sends the signal *org.AGL.afm.system.changed* on success.
87 If it receives that signal, **afm-user-daemon** rebuild its
90 **afm-user-daemon** provides the data that it collected about
91 application to its clients that either want to get that list
92 or to get information about one application.
94 ### Launching applications ###
96 **afm-user-daemon** launchs the applications. This means
97 that its builds a secure environment for the application
98 and then start it inside that secured environment.
100 Applications of different kind can be launched.
102 This is set using a configuration file that describes
103 how to launch an application of a given kind for a given
106 There is two launching modes: local or remote.
108 Launching an application locally means that
109 the application and its binder are launcher together.
111 Launching application remotely means that only the
112 binder is launched for the application.
114 Once launched, running instances of application receive
115 a runid that identify them.
117 ### Managing instances of running applications ###
119 **afm-user-daemon** manages the list of applications
122 With the good permissions, a client can get the list
123 of the running instances and details about a specific
124 running instance. It can also terminate, stop or
125 continue a given application.
127 ### Installing and uninstalling applications ###
129 If the client has the good permission,
130 **afm-user-daemon** delegates that task
131 to **afm-system-daemon**.
134 Starting **afm-user-daemon**
135 -----------------------------
137 **afm-user-daemon** is launched as a **systemd** service
138 attached to user sessions. Normally, the service file is
139 located at /usr/lib/systemd/user/afm-user-daemon.service.
141 The options for launching **afm-user-daemon** are:
144 --application directory
146 Includes the given application directory to
147 the database base of applications.
154 Includes the root application directory to
155 the database base of applications.
157 Note that the default root directory for
158 applications is always added. It is defined
159 to be /usr/share/afm/applications (may change).
164 --mode (local|remote)
166 Set the default launch mode.
167 The default value is 'local'
172 Daemonizes the process. It is not needed by sytemd.
177 Reduces the verbosity (can be repeated).
182 Increases the verbosity (can be repeated).
190 Configuration of the launcher
191 -----------------------------
193 It contains rules for launching applications.
194 When **afm-user-daemon** need to launch an application,
195 it looks to the mode of launch, local or remote, and the
196 type of the application as given by the file ***config.xml***
199 This couple mode and type allows to select the rule.
201 The configuration file is **/etc/afm/afm-launch.conf**.
203 It contains sections and rules. It can also contain comments
204 and empty lines to improve the readability.
206 The separators are space and tabulation, any other character
207 is meaning something.
209 The format is line oriented.
210 The new line character separate the lines.
212 Lines having only separators are blank lines and are skipped.
213 Line having the character # (sharp) as first not separator character
214 are comment lines and are ignored.
216 Lines starting with a not separator character are differents
217 of lines starting with a separator character.
219 The grammar of the configuration file is defined below:
221 CONF: *COMMENT *SECTION
225 RULE: +TYPE VECTOR ?VECTOR
227 MODE: 'mode' +SEP ('local' | 'remote') *SEP EOL
231 VECTOR: +SEP DATA *(+SEP NDATA) *SEP EOL
237 COMMENT: *SEP CMT *(SEP | NCHAR) NL
242 CHAR: '\x00'..'\x08' | '\x0b'..'\x1f' | '\x21' | '\x22' | '\x24'..'\xff'
245 Here is a sample of configuration file for defining how
246 to launch an application declared of types *application/x-executable*,
247 *text/x-shellscript* and *text/html* in mode local:
251 application/x-executable
256 /usr/bin/afb-daemon --mode=local --readyfd=%R --alias=/icons:%I --port=%P --rootdir=%r --token=%S --sessiondir=%D/.afb-daemon
257 /usr/bin/web-runtime http://localhost:%P/%c?token=%S
261 - within a section, several rules can be defined
262 - within a rule, several types can be defined
263 - within a rule, one or two vectors can be defined
264 - vectors are using %substitution
265 - launched binaries must be defined with their full path
269 Within this mode, the launchers have either one or two vectors
270 describing them. All of these vectors are treated as programs
271 and are executed with the system call 'execve'.
273 The first vector is the leader vector and it defines the process
274 group. The second vector (if any) is attached to the group
275 defined by this first vector.
279 Within this mode, the launchers have either one or two vectors
282 The first vector is treated as a program and is executed with
283 the system call 'execve'.
285 The second vector (if any) defines a text that is returned
286 to the caller. This mechanism can be used to return the uri
287 to connect to for executing the application remotely.
289 The daemon ***afm-user-daemon*** allocates a port for the
290 running the application remotely.
291 The current implmentation of the port allocation is just
293 A more reliable (cacheable and same-originable) allocation
298 Vectors can include sequences of 2 characters that have a special
299 meaning. These sequences are named *%substitution* because their
300 first character is the percent sign (%) and because each occurrence
301 of the sequence is replaced, at launch time, by the value associated
304 Here is the list of *%substitutions*:
308 This simply emits the percent sign %
312 This is the application Id of the launched application.
314 Defined by the attribute **id** of the element **<widget>**
319 The file within the widget directory that is the entry point.
321 For a HTML application, it is the relative path to the main
322 page (aka index.html).
324 Defined by the attribute **src** of the element **<content>**
329 Path of the directory where the application runs (cwd)
332 It is equal to %h/%a.
336 Requested height for the widget.
338 Defined by the attribute **height** of the element **<widget>**
343 Path of the home directory for all applications.
345 It is generally equal to $HOME/app-data
349 Path of the directory were the icons of the applications can be found.
351 - ***%m***: mime-type
353 Mime type of the launched application.
355 Defined by the attribute **type** of the element **<content>**
360 Name of the application as defined by the content of the
361 element **<name>** of **config.xml**.
367 Will be the colon separated list of plugins and plugins directory.
371 A port to use. It is currently a kind of random port. The precise
372 model is to be defined later.
376 Number of the file descriptor to use for signalling
377 readyness of the launched process.
381 Path of the directory containing the widget and its data.
385 An hexadecimal number that can be used to pair the client
386 with its server binder.
390 Requested width for the widget.
392 Defined by the attribute **width** of the element **<widget>**
399 ### Overview of the dbus interface
401 ***afm-user-daemon*** takes its orders from the session instance
402 of D-Bus. The use of D-Bus is great because it allows to implement
403 discovery and signaling.
405 The dbus of the session is by default adressed by the environment
406 variable ***DBUS_SESSION_BUS_ADDRESS***. Using **systemd**
407 the variable *DBUS_SESSION_BUS_ADDRESS* is automatically set for
410 The **afm-user-daemon** is listening with the destination name
411 ***org.AGL.afm.user*** at the object of path ***/org/AGL/afm/user***
412 on the interface ***org.AGL.afm.user*** for the below detailed
413 members ***runnables***, ***detail***, ***start***, ***terminate***,
414 ***stop***, ***continue***, ***runners***, ***state***,
415 ***install*** and ***uninstall***.
417 D-Bus is mainly used for signaling and discovery. Its optimized
418 typed protocol is not used except for transmitting only one string
421 The client and the service are using JSON serialisation to
424 The D-Bus interface is defined by:
426 * DESTINATION: **org.AGL.afm.user**
428 * PATH: **/org/AGL/afm/user**
430 * INTERFACE: **org.AGL.afm.user**
432 The signature of any member of the interface is ***string -> string***
433 for ***JSON -> JSON***.
435 This is the normal case. In case of error, the current implmentation
436 returns a dbus error that is a string.
438 Here is an example that use *dbus-send* to query data on
439 installed applications.
441 dbus-send --session --print-reply \
442 --dest=org.AGL.afm.user \
444 org.AGL.afm.user.runnables string:true
446 ### Using ***afm-util***
448 The command line tool ***afm-util*** uses dbus-send to send
449 orders to **afm-user-daemon**. This small scripts allows to
450 send command to ***afm-user-daemon*** either interactively
451 at shell prompt or scriptically.
453 The syntax is simple: it accept a command and if the command
454 requires it, the argument to the command.
456 Here is the summary of ***afm-util***:
458 - **afm-util runnables **:
460 list the runnable widgets installed
462 - **afm-util install wgt **:
466 - **afm-util uninstall id **:
468 remove the installed widget of id
470 - **afm-util detail id **:
472 print detail about the installed widget of id
474 - **afm-util runners **:
476 list the running instance
478 - **afm-util start id **:
480 start an instance of the widget of id
482 - **afm-util terminate rid **:
484 terminate the running instance rid
486 - **afm-util stop rid **:
488 stop the running instance rid
490 - **afm-util continue rid **:
492 continue the previously rid
494 - **afm-util state rid **:
496 get status of the running instance rid
499 Here is how to list applications using ***afm-util***:
505 ### The protocol over D-Bus
509 * **DESTINATION**: org.AGL.afm.user
511 * **PATH**: /org/AGL/afm/user
513 * **INTERFACE**: org.AGL.afm.user
517 #### Method org.AGL.afm.user.detail
519 **Description**: Get details about an application from its id.
521 **Input**: the id of the application as below.
523 Either just a string:
527 Or an object having the field "id" of type string:
531 **Output**: A JSON object describing the application containing
532 the fields described below.
535 "id": string, the application id (id@version)
536 "version": string, the version of the application
537 "width": integer, requested width of the application
538 "height": integer, resqueted height of the application
539 "name": string, the name of the application
540 "description": string, the description of the application
541 "shortname": string, the short name of the application
542 "author": string, the author of the application
547 #### Method org.AGL.afm.user.runnables
549 **Description**: Get the list of applications that can be run.
551 **Input**: any valid json entry, can be anything except null.
553 **output**: An array of description of the runnable applications.
554 Each item of the array contains an object containing the detail of
555 an application as described above for the method
556 *org.AGL.afm.user.detail*.
560 #### Method org.AGL.afm.user.install
562 **Description**: Install an application from its widget file.
564 If an application of the same *id* and *version* exists, it is not
565 reinstalled except if *force=true*.
567 Applications are installed in the subdirectories of the common directory
569 If *root* is specified, the application is installed under the
570 sub-directories of the *root* defined.
572 Note that this methods is a simple accessor to the method
573 ***org.AGL.afm.system.install*** of ***afm-system-daemon***.
575 After the installation and before returning to the sender,
576 ***afm-user-daemon*** sends the signal ***org.AGL.afm.user.changed***.
578 **Input**: The *path* of the widget file to install and, optionaly,
579 a flag to *force* reinstallation, and, optionaly, a *root* directory.
581 Either just a string being the absolute path of the widget file:
583 "/a/path/driving/to/the/widget"
588 "wgt": "/a/path/to/the/widget",
590 "root": "/a/path/to/the/root"
593 "wgt" and "root" must be absolute paths.
595 **output**: An object with the field "added" being the string for
596 the id of the added application.
598 {"added":"appli@x.y"}
602 #### Method org.AGL.afm.user.uninstall
604 **Description**: Uninstall an application from its id.
607 Note that this methods is a simple accessor to the method
608 ***org.AGL.afm.system.uninstall*** of ***afm-system-daemon***.
610 After the uninstallation and before returning to the sender,
611 ***afm-user-daemon*** sends the signal ***org.AGL.afm.user.changed***.
613 **Input**: the *id* of the application and, otpionaly, the path to
614 *root* of the application.
624 "root": "/a/path/to/the/root"
627 **output**: the value 'true'.
631 #### Method org.AGL.afm.user.start
635 **Input**: the *id* of the application and, optionaly, the
636 start *mode* as below.
638 Either just a string:
642 Or an object having the field "id" of type string and
643 optionaly a field mode:
645 {"id":"appli@x.y","mode":"local"}
647 The field "mode" as a string value being either "local" or "remote".
649 **output**: The *runid* of the application launched.
650 The runid is an integer.
654 #### Method org.AGL.afm.user.terminate
656 **Description**: Terminates the application of *runid*.
658 **Input**: The *runid* (an integer) of the running instance to terminate.
660 **output**: the value 'true'.
664 #### Method org.AGL.afm.user.stop
666 **Description**: Stops the application of *runid* until terminate or continue.
668 **Input**: The *runid* (an integer) of the running instance to stop.
670 **output**: the value 'true'.
674 #### Method org.AGL.afm.user.continue
676 **Description**: Continues the application of *runid* previously stopped.
678 **Input**: The *runid* (an integer) of the running instance to continue.
680 **output**: the value 'true'.
684 #### Method org.AGL.afm.user.state
686 **Description**: Get informations about a running instance of *runid*.
688 **Input**: The *runid* (an integer) of the running instance inspected.
690 **output**: An object describing the state of the instance. It contains:
691 the runid (an integer), the id of the running application (a string),
692 the state of the application (a string being either "starting", "running"
695 Example of returned state:
705 #### Method org.AGL.afm.user.runners
707 **Description**: Get the list of the currently running instances.
711 **output**: An array of states, one per running instance, as returned by
712 the methodd ***org.AGL.afm.user.state***.