AGL – Application framework
1. 介绍
1.1 概述
下图通过应用程序安装场景描述了framework的主要组件以及其交互(
图片转载自:
下面对图片中描述的时序进行解释:
- APPLICATION 调用其binder安装另外一个应用程序
- binder调用的afm-main-binding通过D-Bus system和afm-system-daemon安装程序
- D-Bus system通过调用SYNARA检查APPLICATION是否有权限安装程序
- D-Bus system将安装命令传送到afm-system-daemon,afm-system-daemon检查被安装的应用程序的签名和权限,然后进行安装
- afm-system-daemon调用SECURITY-MANAGER完成安装程序的security上下文
- SECURITY-MANAGER通过调用SYNARA为应用程序安装初始化权限
- APPLICATION通过其binder启动刚安装的应用程序
- binder调用的afm-main-binding通过D-Bus session和afm-user-daemon启动应用程序。
- D-Bus session通过调用SYNARA检查APPLICATION是否有权限启动其他进程
- D-Bus session将请求转送至afm-user-daemon
- afm-user-daemon通过SYNARA检查APPLICATION是否有权限启动其他程序
- afm-user-daemon通过SECURITY-MANAGER特性为应用程序设置security上下文
- afm-user-daemon启动应用程序
上图中部分组件的功能介绍:
- SECURITY-MANAGER:设置 Smack 上下文和规则、设置组、为应用程序创建 CYNARA 规则的初始内容。
- CYNARA:负责处理用户和应用程序的API访问权限。
- D-Bus:负责检查消息的安全性。 CYNARA 检查规则增强了通常的 D-Bus 安全规则。
- afm-system-daemon:负责安装和卸载应用程序
- afm-user-daemon:负责列出应用程序、查询应用程序详细信息、启动、终止、暂停、恢复给定用户上下文的应用程序及其实例。
- afb-binder:负责通过 HTTP 接口提供资源和功能。
- afm-main-binding:允许应用程序使用 AGL 框架的 API。
1.2 Security framework和Application framework的连接
- Security Framework是指用于确保安全的安全模型以及为实现该模型而提供的工具。
- Security Model是指系统如何使用 DAC(自主访问控制)、MAC(强制访问控制)和Capabilities来确保安全和隐私。 它还包括使用审计功能和管理日志和警报的报告功能。
- Application Framework使用安全模型/框架来确保其管理的应用程序的安全性和隐私性。
- Application Framework必须符合底层安全模型/框架。 但它应该将其隐藏到应用程序中。
1.3 Security Framework
包含三部分:
- Security-Manager
- Cynara
- 符合Cynara的D-Bus.
理论上,Security Framework/Model是不应该影响Application Framework之上的层的实现细节。
1.4 Application Framework
Security Framework之上的Application Framework提供了安装和卸载应用程序以及在安全环境中运行应用程序的组件。
目标是管理应用程序并向应用程序隐藏安全框架的细节。
2. afb daemons
2.1 介绍
afm-user-daemon和afm-system-daemon管理应用程序的生命周期,管理方式:installation,uninstallation,running,suspend,inventory…
afm-user-daemon和afm-system-daemon能够确保在需要的时候使用security framework,并且能够保证应用程序能在安全的上下文环境中运行.
D-Bus 负责根据 D-Bus 目的地将命令传输到适当的守护进程。
图片转载自https://docs.automotivelinux.org/en/lamprey/#3_Developer_Guides/1_Application_Framework/1_afm-daemons/
2.2 D-Bus接口
2.2.1 D-Bus接口概述
afm daemons从D-Bus session实例中获取命令
D-Bus session 默认由环境变量 DBUS_SESSION_BUS_ADDRESS 寻址。
afm daemons监听org.AGL.afm.[user|system]接口中路径为/org/AGL/afm/[user|system]的对象并且以org.AGL.afm.[user|system] 作为目的名称的成员
- afm-system-daemon:监听的接口:
- install
- uninstall
- afm-user-daemon监听的接口:
- runnables
- detail
- start
- once
- terminate
- pause
- resume
- runners
- state
- install
- uninstall
D-Bus主要用于signaling和discovery,client和server主要通过JSON交换数据
2.2.2 D-Bus协议
- DESTINATION: org.AGL.afm.[user|system]
- PATH: /org/AGL/afm/[user|system]
- INTERFACE: org.AGL.afm.[user|system]
Method org.AGL.afm.system.install
- 描述:通过widget安装应用程序,如果存在相同id,相同版本的程序,只有设置force=true才会重新安装,应用程序安装在应用程序公共目录的子目录中,如果指定了根目录,则应用程序安装在指定根目录的子目录中.
- 输入:要安装的widget路径, 可选项force=true, 可选项root
表示widget绝对路径的字符串
"/a/path/driving/to/the/widget"
或者一个对象
{
"wgt": "/a/path/to/the/widget",
"force": false,
"root": "/a/path/to/the/root"
}
"wgt"和"root"必须是绝对路径
- 输出:包含"added"字段的对象
{
"added":"appli@x.y"}
Method org.AGL.afm.system.uninstall
- 描述:卸载指定id的应用程序
- 输入:要卸载的应用程序id, 可选项应用程序根目录
一个字符串
"appli@x.y"
或一个对象
{
"id": "appli@x.y",
"root": "/a/path/to/the/root"
}
- 输出:“true”
Method org.AGL.afm.user.detail
- 描述:获取指定应用程序的详细信息
- 输入:应用程序id
一个字符串:
"appli@x.y"
或者一个对象
{
"id":"appli@x.y"}
- 输出:一个JSON对象,描述应用程序所包含的字段
{
"id": string, the application id (id@version)
"version": string, the version of the application
"width": integer, requested width of the application
"height": integer, requested height of the application
"name": string, the name of the application
"description": string, the description of the application
"shortname": string, the short name of the application
"author": string, the author of the application
}
Method org.AGL.afm.user.runnables
- 描述: 获取能够运行的应用程序列表.
- 输入: 任何有效的json对象, 可以是除null外的任何东西
- 输出: 描述可以运行的应用程序数组.
数组中每一项都包含一个对象描述应用程序的详细信息,详细参考 org.AGL.afm.user.detail.
Method org.AGL.afm.user.install
- 描述: 通过widget安装应用程序,如果存在相同id,相同版本的程序,只有设置force=true才会重新安装,应用程序安装在应用程序公共目录的子目录中,如果指定了根目录,则应用程序安装在指定根目录的子目录中.
- 输入: 要安装的widget路径,可选项force=true, 可选项root
包含widget绝对路径的字符串:
"/a/path/driving/to/the/widget"
或者一个对象
{
"wgt": "/a/path/to/the/widget",
"force": false,
"root": "/a/path/to/the/root"
}
wgt and root 必须是绝对路径.
- 输出: 一个包含"added"字段的对象
{
"added":"appli@x.y"}
Method org.AGL.afm.user.uninstall
- 描述: 卸载指定id的应用程序.
- 输入: 应用程序的id,可选项应用程序根目录
一个字符串
"appli@x.y"
或者一个对象:
{
"id": "appli@x.y",
"root": "/a/path/to/the/root"
}
- 输出:“true”
Method org.AGL.afm.user.start
-
描述:启动指定id的应用程序
-
输入: 应用程序id,可选项启动模式
一个字符串:
"appli@x.y"
或者是一个包含id字段和可选mode字段的对象
{
"id":"appli@x.y","mode":"local"}
mode字段的值只能是"local" 或者 “remote”.
- 输出: 启动程序的runid,是一个整型
Method org.AGL.afm.user.once
-
描述:
-
输入: 应用程序的id
一个字符串
"appli@x.y"
或者一个包含id字段的对象
{
"id":"appli@x.y"}
- 输出: 应用程序的状态. 详细信息参考 org.AGL.afm.user.state
Method org.AGL.afm.user.terminate
-
描述: 终止指定runid的应用程序
-
输入: 要终止的应用程序的runid.
-
输出: “true”
Method org.AGL.afm.user.stop
使用 org.AGL.afm.user.pause 替代.
Method org.AGL.afm.user.continue
使用 org.AGL.afm.user.resume 替代.
Method org.AGL.afm.user.pause
[当前在systemd版本不存在]
- 描述: 暂定指定runid的应用程序.
- 输入: 要暂定的应用程序runid.
- 输出: “true”
Method org.AGL.afm.user.resume
[当前在systemd版本不存在]
- 描述: 恢复指定runid的应用程序.
- 输入: 要恢复的应用程序runid.
- 输出: “true”
Method org.AGL.afm.user.state
- 描述: 或者指定runid的运行实例.
- 输入: 运行实例的runid.
- 输出: 描述运行实例状态的对象,包含如下内容:
- the runid (整型)
- 进程pid数组
- with the group leader
- 运行应用程序的id (string)
- 应用程序状态 (string: “starting”, “running”, “paused”).
返回的状态举例:
{
"runid": 2,
"pids": [