Openharmony 应用获取系统签名和权限

1.配置SDK签名

deveco studio Tools->SDK Manager->SDK 选择OpenHarmonyOS,复制Location里面的路径,在文件管理器中打开。打开{SDK目录}\10\toolchains\lib\UnsgnedReleasedProfileTemplate.json,修改里面的下面内容

"apl":"system_core ",
"app-feature":"ohos_system_app"

如果之前编译过应用,需要把clean一下然后把原来的签名删掉重新生成一次,如果没有编译过,则不需要

2.在Dev eco studio中点击build->build haps->build haps,生成HAP安装包

3.在项目entry\build\default\outputs\default目录下找到生成的两个hap包,一个是未签名的,一个是签名的。使用签名的那个

4. 安装HAP

    hdc install -r D:\OpenHarmonyProjects\MyApplication2\entry\build\default\outputs\default\entry-default-signed.hap
    [Info]App install path:D:\OpenHarmonyProjects\MyApplication2\entry\build\default\outputs\default\entry-default-signed.hap, queuesize:0, msg:install bundle successfully.
    AppMod finish

    5.获取应用的fingerprint

    包名是entry\build\default\outputs\default\pack.info文字中bundleName对应的值

    # bm dump -n com.xunglong.myapplication | grep fingerprint
            "fingerprint": "6D19990C1CF83FC441971E7997E245EAED3C7C7E72D28FA399E68CE79DD29888",

    6. 配置系统文件

    system/etc/app目录下有install_list_capability.json和install_list_permissions.json两个文件,将他们拉到本地。修改install_list_capability.json在结尾处添加自己的应用信息。

    {
        "bundleName": "com.xunglong.myapplication",
         "singleton": true,   //设置为true后无法使用dev studio 调试安装
         "keepAlive": true,   
         "runningResourcesApply": false,
         "app_signature" : ["6D19990C1CF83FC441971E7997E245EAED3C7C7E72D28FA399E68CE79DD29888"],
         "allowAppDesktopIconHide": false,   //设置为true后桌面不显示图标
         "allowAppUsePrivilegeExtension": true
    }
    在install_list_permissions.json尾部添加
    {
       "bundleName": "com.xunglong.myapplication",
       "app_signature" : ["6D19990C1CF83FC441971E7997E245EAED3C7C7E72D28FA399E68CE79DD29888"],
       "permissions" : [
                {
                    "name" : "xxxxx", //你想添加的权限
                    "userCancellable" : false
                }
            ]
        }
    
    singleton配置为true如果需要重新安装应用 需要先将hap推到板子上,然后使用bm install -p {hap路径} -u 0

    7. 然后将install_list_capability.json和install_list_permissions.json替换板子上的文件,重启系统。

    8.验证

    重启后查看应用信息; “appPrivilegeLevel”: “system_core “,说明当前已是系统应用。

    bm dump -n com.xunglong.myapplication
    com.xunglong.myapplication:
    {
        "appId": "com.xunglong.myapplication_BC6Ueb3SF3y2yJG31+b/jPhB97Bkb6YUuo3+PkN/9MaX9p+0cMyKH0dOuSsJrAVOk1AriD/MKsMRjrCwgAPmkMo=",
        "appIndex": 0,
        "applicationInfo": {
            "accessTokenId": 537722394,
            "accessTokenIdEx": 537722394,
            "accessible": false,
            "allowCommonEvent": [],
            "apiCompatibleVersion": 10,
            "apiReleaseType": "Release",
            "apiTargetVersion": 10,
            "appDetailAbilityLibraryPath": "",
            "appDistributionType": "os_integration",
            "appPrivilegeLevel": "system_core ",
            "appProvisionType": "release",
    发表回复 0

    Your email address will not be published. Required fields are marked *