在这篇文章中。我们将介绍Ubuntu OS的Runtime Environment。在文章“App confinement: Security policy for click packages”中,我们看见它里面有介绍一个应用的runtime环境。这里,我们通过一个样例来显示一个应用的runtime环境究竟是如何的。

在这里我们能够參阅我曾经的文章“在Ubuntu上的C++及QML混合编程”,我们下载文章中的例程:

bzr branch lp:~liu-xiao-guo/debiantrial/readenv

在一个Terminal中打入上述的句子,就能够下载例程中的软件。

同一时候,我们对我们的主程序文件“ReadEnv.qml”做例如以下的改动:

import QtQuick 2.0
import Ubuntu.Components 0.1
import Ubuntu.Components.ListItems 0.1 as ListItem
import ReadEnv 1.0
import "ui" /*!
\brief MainView with Tabs element.
First Tab has a single Label and
second Tab has a single ToolbarAction.
*/ MainView {
id: root // objectName for functional testing purposes (autopilot-qt5)
objectName: "mainView" // Note! applicationName needs to match the "name" field of the click manifest
applicationName: "com.ubuntu.developer.liu-xiao-guo.ReadEnv" anchorToKeyboard: true /*
This property enables the application to change orientation
when the device is rotated. The default is false.
*/
//automaticOrientation: true width: units.gu(50)
height: units.gu(75) property string app_pkgname ReadEnv {
id: readEnv
} Flickable {
id: scrollWidget
anchors.fill: parent
contentHeight: contentItem.childrenRect.height
boundsBehavior: (contentHeight > root.height) ? Flickable.DragAndOvershootBounds : Flickable.StopAtBounds
/* Set the direction to workaround https://bugreports.qt-project.org/browse/QTBUG-31905
otherwise the UI might end up in a situation where scrolling doesn't work */
flickableDirection: Flickable.VerticalFlick Column {
anchors.left: parent.left
anchors.right: parent.right ListItem.Base {
height: ubuntuLabel.height + runtime.height + units.gu(6) Column {
anchors.left: parent.left
anchors.right: parent.right
anchors.centerIn: parent
spacing: units.gu(2)
Label {
id: ubuntuLabel
anchors.horizontalCenter: parent.horizontalCenter
text: ""
fontSize: "x-large"
}
Label {
id: runtime
anchors.horizontalCenter: parent.horizontalCenter
text: "Runtime Environment"
}
}
} ListItem.Subtitled {
text: i18n.tr("UBUNTU_APPLICATION_ISOLATION")
subText: readEnv.getenv("UBUNTU_APPLICATION_ISOLATION")
} ListItem.Subtitled {
text: i18n.tr("APP_ID")
subText: readEnv.getenv("APP_ID")
} ListItem.Subtitled {
text: i18n.tr("XDG_CACHE_HOME")
subText: readEnv.getenv("XDG_CACHE_HOME")
} ListItem.Subtitled {
text: i18n.tr("XDG_CONFIG_HOME")
subText: readEnv.getenv("XDG_CONFIG_HOME")
} ListItem.Subtitled {
text: i18n.tr("XDG_DATA_HOME")
subText: readEnv.getenv("XDG_DATA_HOME")
} ListItem.Subtitled {
text: i18n.tr("XDG_RUNTIME_DIR")
subText: readEnv.getenv("XDG_RUNTIME_DIR")
} ListItem.Subtitled {
text: i18n.tr("TMPDIR")
subText: readEnv.getenv("TMPDIR")
} ListItem.Subtitled {
text: i18n.tr("PWD")
subText: readEnv.getenv("PWD")
} ListItem.Subtitled {
text: i18n.tr("APP_PKGNAME")
subText: app_pkgname
} ListItem.Subtitled {
text: i18n.tr("PATH")
subText: readEnv.getenv("PATH")
} ListItem.Subtitled {
text: i18n.tr("LD_LIBRARY_PATH")
subText: readEnv.getenv("LD_LIBRARY_PATH")
} ListItem.Subtitled {
text: i18n.tr("QML2_IMPORT_PATH")
subText: readEnv.getenv("QML2_IMPORT_PATH")
}
}
} Component.onCompleted: {
var APP_ID = readEnv.getenv("APP_ID"); console.log("APP_ID: " + APP_ID );
app_pkgname = APP_ID.split('_')[0]
console.log("APP_PKGNAME: " + app_pkgname);
}
}

我们能够通过我们设计的ReadEnv库来读取该应用的环境变量。

执行我们的程序。显演示样例如以下:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvVWJ1bnR1VG91Y2g=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" width="200" height="300" alt=""> 

在文章中,它提到例如以下的文件夹,该应具有读和写的权限:

  • XDG_CACHE_HOME/<APP_PKGNAME>
  • XDG_CONFIG_HOME/<APP_PKGNAME>
  • XDG_DATA_HOME/<APP_PKGNAME>
  • XDG_RUNTIME_DIR/<APP_PKGNAME>
  • XDG_RUNTIME_DIR/confined/<APP_PKGNAME> (for TMPDIR)

针对我们的应用来说。也即例如以下的文件夹具有读写的权限:

  • /home/phablet/.cache/com.ubuntu.developer.liu-xiao-guo.readenv
  • /home/phablet/.config/com.ubuntu.developer.liu-xiao-guo.readenv
  • /home/phablet/.local/share/com.ubuntu.developer.liu-xiao-guo.readenv
  • /run/user/32011/confined/com.ubuntu.developer.liu-xiao-guo.readenv

整个程序的源代码在例如以下的地址能够找到:


bzr branch lp:~liu-xiao-guo/debiantrial/runtimeevn

一个更加完整的例程在:git clone https://gitcafe.com/ubuntu/runtimeenv.git

请注意,在新的例程中。我们能够同一时候使用 readEnv.getenv 或 readEnv.getenv1两种方法来得到环境变量的值。

Ubuntu OS应用Runtime Enviroment的更多相关文章

  1. Windows 7 bug: nonexistent Java Runtime Enviroment

    When I tried installing atunes and TED, I got the message “The registry refers to a nonexistent Java ...

  2. compile openjdk7 in ubuntu OS

    success: openjdk version "1.7.0-internal"OpenJDK Runtime Environment (build 1.7.0-internal ...

  3. Packages on Ubuntu OS

    openSSH https://help.ubuntu.com/lts/serverguide/openssh-server.html

  4. 多个 git ssh key 配置 Ubuntu os

    1.生成ssh key: ssh-keygen -t rsa -C “email@sss.com” 此时,在~/.ssh/文件夹下会有两个文件, id_rsa 和 id_rsa.pub.分别保存ssh ...

  5. eduroam WIFI on Ubuntu OS

  6. extract a page from a multiple pages pdf on Ubuntu OS

    extract a page from a multiple pages pdf 1 extract a page from a multiple pages pdf use pdftk packag ...

  7. Ubuntu OS 打开端口命令

    直接执行命令:ufw allow 80 再去修改对应功能配置文件的端口号

  8. 怎样在Ubuntu手机应用中得到全部的环境变量值

    我们在先前的例程中已经通过一些方法得到我们应用的一些环境变量值.这些值有的很实用.比方我们能够得到我们应用所仅仅能訪问的文件夹.在今天的例程中,我们来展示一种方法能够得到应用全部的环境变量.在我们的实 ...

  9. VMWare 虚拟化 Ubuntu 64 (16.04)-- docker 无法链接 pull 镜像 ?(solved)

    背景 根据项目的需要,虚拟化一个Ubuntu OS 来玩 docker,虚拟机选择的是WMWare (VMware-player-14.0.0-6661328); Ubuntu的镜像来自于官网(ubu ...

随机推荐

  1. 洛谷P1008三连击 题解

    题目传送门 使用dfs搜索,搜索9个数字,注意回溯...最后判断是否符合条件,输出. #include<bits/stdc++.h> using namespace std; ],a[]; ...

  2. RabbitMQ指南之二:工作队列(Work Queues)

    在上一章的指南中,我们写了一个命名队列:生产者往该命名队列发送消息.消费从从该命名队列中消费消息.在本章中,我们将创建一个工作队列,用于在多个工作者之间分配耗时的任务.工作队列(即任务队列)的主要思想 ...

  3. list 移除值

    1. 移除基本类型值时,传入int 会以下标为依据移除 , 但传入Integer 对象时,则是移除对象为依据移除(即不受此对象代表的值相等的下标的影响) 都是只能移除一个值,(list 中有多个1时, ...

  4. MySQL几个特别语法示例

    简单介绍MySQL中几种特殊语法的用法: 1.创建示例用表和数据: 创建employees表[注:与SQL Server示例数据库Northwind中的表employees相同的表结构]: CREAT ...

  5. BZOJ4653 [NOI2016]区间 [线段树,离散化]

    题目传送门 区间 Description 在数轴上有 n个闭区间 [l1,r1],[l2,r2],...,[ln,rn].现在要从中选出 m 个区间,使得这 m个区间共同包含至少一个位置.换句话说,就 ...

  6. 【记录】mysql 无法启动 : NET HELPMSG 3523

    mysql 无法启动 : NET HELPMSG 3523后来注意到mysql 配置文件的格式是 utf-8 还是有bom的utf-8 bom格式前面会多出一些看不见的字符,所以mysql读取配置文件 ...

  7. js基本数据类型 BigInt 和 Number 的区别

    今天在做LeetCode的一到 “加一” 的题,题目如下 给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储一个数字. 你可以假设除 ...

  8. wc 统计行数 字数

    Linux统计文件行数 2011-07-17 17:32 by 依水间, 168255 阅读, 4 评论, 收藏, 编辑 语法:wc [选项] 文件… 说明:该命令统计给定文件中的字节数.字数.行数. ...

  9. iOS 9音频应用播放音频之第一个ios9音频实例

    iOS 9音频应用播放音频之第一个ios9音频实例 第一个ios9音频实例 为了让开发者可以对上面的内容有更加深入的了解,本节将实现播放音频的第一个实例.在此实例中会涉及到项目的创建.界面设计.关联以 ...

  10. Codeforces 30 E. Tricky and Cleve Password

    \(>Codeforces \space 30\ E. Tricky\ and\ Cleve\ Password<\) 题目大意 : 给出一个串 \(S\),让你找出 \(A, B, C\ ...