Ubuntu OS应用Runtime Enviroment

原创 2014年11月19日 14:52:03

在这篇文章中,我们将介绍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库来读取该应用的环境变量。运行我们的程序,显示如下:


 


在文章中,它提到如下的目录,该应具有读和写的权限:


  • 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

一个更加完整的例程在:https://github.com/liu-xiao-guo/runtimeenv

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



版权声明:本文为博主原创文章,未经博主允许不得转载。

Ubuntu OS上的QML应用框架

在我们编写QML应用的时候,我们有时事先需要来考虑我们怎么使用一个好的框架来完成我们的应用。我们的应用有多少个页面,页面之间的导航到底是怎么样子的。这个对于我们一开始来设计我们的应用来说非常中要。在这...
  • UbuntuTouch
  • UbuntuTouch
  • 2015年03月25日 10:20
  • 1625

使用Ubuntu OS上的URL dispatcher来启动其它的应用

URL dispatcher 是在Ubuntu OS上的一个服务。它可以让我们的应用(confined,i.e, click package应用)来启动其它的应用。这些应用通常是一个特别的URL来 识...
  • UbuntuTouch
  • UbuntuTouch
  • 2014年10月23日 23:06
  • 1047

在Ubuntu OS上怎么本地化一个QML应用

在这篇文章中,我们来介绍怎么在Ubuntu OS上本地化一个应用。本地化对很多的应用很重要。我们重点介绍怎么把应用本地化为中文。...
  • UbuntuTouch
  • UbuntuTouch
  • 2014年11月28日 15:05
  • 1004

/etc/profile与/etc /enviroment的比较 UBUNTU四种环境变量的简介

原文链接: http://blog.csdn.net/adparking/article/details/5701764 以下节选: /etc/environment 与 /et...
  • yypony
  • yypony
  • 2013年06月03日 20:26
  • 385

/etc/profile与/etc /enviroment的比较 UBUNTU四种环境变量的简介

先将export LANG=zh_CN加入/etc/profile ,退出系统重新登录,登录提示显示英文。将/etc/profile 中的export LANG=zh_CN删除,将LNAG=zh_CN...
  • liangjiu2009
  • liangjiu2009
  • 2011年08月21日 16:18
  • 439

Ubuntu linux解决:”修改profile/enviroment文件无法进入ubuntu“的方法

首先说一下出现问题的原因: 配置了错误的PATH造成系统无法加载系统默认的PATH路径。 错误如: 当然,就是红框的这句造成的。 要是无法用界面登陆模式进入,那该怎么办...
  • hudan2714
  • hudan2714
  • 2012年09月01日 09:33
  • 1001

Ubuntu OS上的QML应用框架

在我们编写QML应用的时候,我们有时事先需要来考虑我们怎么使用一个好的框架来完成我们的应用。我们的应用有多少个页面,页面之间的导航到底是怎么样子的。这个对于我们一开始来设计我们的应用来说非常中要。在这...
  • UbuntuTouch
  • UbuntuTouch
  • 2015年03月25日 10:20
  • 1625

vim-runtime_7.2.330-1ubuntu4_all.deb

  • 2014年10月19日 20:16
  • 5.44MB
  • 下载

(OS X) Loading Code at Runtime

To load dynamic libraries at runtime, apps should use a set of efficient and portable functions, cal...
  • chuanyituoku
  • chuanyituoku
  • 2013年12月26日 11:38
  • 649

OS高级开发~Runtime(四)

用C代替OC: #import #import #import extern int UIApplicationMain (int argc,char *argv[],void *pri...
  • super_man_ww
  • super_man_ww
  • 2016年05月12日 14:04
  • 323
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Ubuntu OS应用Runtime Enviroment
举报原因:
原因补充:

(最多只允许输入30个字)