Ubuntu OS应用Runtime Enviroment
在这篇文章中。我们将介绍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
 
                    
                
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号