• Lv0
    粉丝5

积分196 / 贡献0

提问31答案被采纳6文章2

rk3568下SoftBusDumpDeviceInfo执行错误

shixiaocheng 显示全部楼层 发表于 2023-12-21 10:33:55

【问题描述】

  1. 介绍问题现象和发生的背景 命令行运行SoftBusDumpDeviceInfo,测试分布式能力。

  2. 相关的代码(请勿使用截图)

  3. 运行结果、错误截图

    SoftBusDumpDeviceInfo

    ------Local Device Info------ 4 nStackXLog: SetLogCallback:[76] :log callback changed LnnGetLocalNodeInfo Fail!

  4. 我尝试过的解决方法和结果 hilog中看到部分信息 12-21 09:38:28.903 605 989 I C015c0/dsoftbus: [COMM]SoftBusServerStub::OnReceived, code = 148 12-21 09:38:28.903 605 989 I C015c0/dsoftbus: [COMM]access token permission ohos.permission.DI STRIBUTED_DATASYNC denied! 12-21 09:38:28.903 1841 1841 E C015c0/dsoftbus: [LNN]GetLocalDeviceInfo send request failed! 12-21 09:38:28.903 1841 1841 E C015c0/dsoftbus: [LNN]ServerIpcGetLocalDeviceInfo get local devic e info failed! 12-21 09:38:28.904 1841 1841 E C015c0/dsoftbus: [LNN]Server GetLocalNodeDeviceInfo failed, ret = -268369889

  5. 我想要达到的结果

    请问如何解决这个问题,如果是权限问题,那该怎么添加权限呢

【运行环境】

硬件:rk3568 ROM版本: DevEvoStudio版本: SDK版本:3.2.11.9

您尚未登录,无法参与评论,登录后可以:
参与开源共建问题交流
认同或收藏高质量问答
获取积分成为开源共建先驱

精彩评论4

深开鸿_王石

沙发 发表于 2023-12-21 14:22:35
这个就是softbus service要求调用他的进程需要具备权限,而这个应用没有(估计是年久失修了)
那么现在就是两种改法:
1,你自己研究用,那就知道check权限的那行,屏蔽掉,重编镜像,试试这个功能;
2,为softbusdumpinfo这个程序添加权限,参考了benchmarktest,如下:
void AddPermission()
{
    if (g_flag) {
        uint64_t tokenId;
        const char *perms[2];
        perms[0] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
        perms[1] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
        NativeTokenInfoParams infoInstance = {
            .dcapsNum = 0,
            .permsNum = 2,
            .aclsNum = 0,
            .dcaps = NULL,
            .perms = perms,
            .acls = NULL,
            .processName = "Softbus_Kits",
            .aplStr = "normal",
        };
        tokenId = GetAccessTokenId(&infoInstance);
        SetSelfTokenID(tokenId);
        OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
        g_flag = false;
    }
}

shixiaocheng

发表于 2023-12-22 10:05  IP属地: - 中国福建省厦门市 中国电信IDC

回复 深开鸿_王石: 万分感谢,我试试看

shixiaocheng

发表于 2023-12-22 16:49  IP属地: - 中国福建省厦门市 中国电信IDC

回复 深开鸿_王石: 依旧不行,这是我修改后的代码

/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include<stdio.h>

#include "softbus_adapter_mem.h"
#include "softbus_bus_center.h"
#include "softbus_common.h"
#include "token_setproc.h"

#include "nativetoken_kit.h"


static char const *g_pkgName = "com.huawei.dmsdp";
static bool flag = true;

static void AddPermission()
{
    if (flag) {
        uint64_t tokenId;
        const char *perms[2];
        perms[0] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
        perms[1] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
        NativeTokenInfoParams infoInstance = {
            .dcapsNum = 0,
            .permsNum = 2,
            .aclsNum = 0,
            .dcaps = NULL,
            .perms = perms,
            .acls = NULL,
            .processName = "com.huawei.dmsdp.sxc",
            .aplStr = "system_core",
        };
        tokenId = GetAccessTokenId(&infoInstance);
        printf("[47]GetAccessTokenId : %llu\n",tokenId);
        SetSelfTokenID(tokenId);
        flag = false;
    }
}
static void PrintNodeProperty(const NodeBasicInfo *nodeInfo)
{
    printf("DeviceName = %s\n", nodeInfo->deviceName);
    printf("NetworkId = %s\n", nodeInfo->networkId);
    NodeDeviceInfoKey key;
    key = NODE_KEY_UDID;
    unsigned char udid[UDID_BUF_LEN] = {0};
    if (GetNodeKeyInfo(g_pkgName, nodeInfo->networkId, key,
        udid, UDID_BUF_LEN) != 0) {
        printf("GetNodeKeyInfo Fail!\n");
    } else {
        printf("Udid = %s\n", udid);
    }
    key = NODE_KEY_UUID;
    unsigned char uuid[UUID_BUF_LEN] = {0};
    if (GetNodeKeyInfo(g_pkgName, nodeInfo->networkId, key,
        uuid, UUID_BUF_LEN) != 0) {
        printf("GetNodeKeyInfo Fail!\n");
    } else {
        printf("Uuid = %s\n", uuid);
    }
    key = NODE_KEY_BR_MAC;
    unsigned char brMac[BT_MAC_LEN] = {0};
    if (GetNodeKeyInfo(g_pkgName, nodeInfo->networkId, key,
        brMac, BT_MAC_LEN) != 0) {
        printf("GetNodeKeyInfo Fail!\n");
    } else {
        printf("BrMac = %s\n", brMac);
    }
    key = NODE_KEY_IP_ADDRESS;
    unsigned char ipAddr[IP_STR_MAX_LEN] = {0};
    if (GetNodeKeyInfo(g_pkgName, nodeInfo->networkId, key,
        ipAddr, IP_STR_MAX_LEN) != 0) {
        printf("GetNodeKeyInfo Fail!\n");
    } else {
        printf("ipAddr = %s\n", ipAddr);
    }
    key = NODE_KEY_DEV_NAME;
    unsigned char deviceName[DEVICE_NAME_BUF_LEN] = {0};
    if (GetNodeKeyInfo(g_pkgName, nodeInfo->networkId, key,
        deviceName, DEVICE_NAME_BUF_LEN) != 0) {
        printf("GetNodeKeyInfo Fail!\n");
    } else {
        printf("deviceName = %s\n", deviceName);
    }
}

static void PrintNodePropertyNum(const NodeBasicInfo *nodeInfo)
{
    NodeDeviceInfoKey key;
    key = NODE_KEY_NETWORK_CAPABILITY;
    int32_t netCapacity = 0;
    if (GetNodeKeyInfo(g_pkgName, nodeInfo->networkId, key,
    (uint8_t *)&netCapacity, LNN_COMMON_LEN) != 0) {
        printf("GetNodeKeyInfo Fail!\n");
    } else {
        printf("netCapacity = %d\n", netCapacity);
    }
    key = NODE_KEY_NETWORK_TYPE;
    int32_t netType = 0;
    if (GetNodeKeyInfo(g_pkgName, nodeInfo->networkId, key,
    (uint8_t *)&netType, LNN_COMMON_LEN) != 0) {
        printf("GetNodeKeyInfo Fail!\n");
    } else {
        printf("netType = %d\n", netType);
    }
}

int main(void)
{
    AddPermission();
    NodeBasicInfo localNodeinfo;
    NodeBasicInfo *remoteNodeInfo = NULL;
    int32_t infoNum = 0;
    printf("------Local Device Info------\n");
    if (GetLocalNodeDeviceInfo(g_pkgName, &localNodeinfo) != 0) {
        printf("LnnGetLocalNodeInfo Fail!\n");
        return -1;
    }
    PrintNodeProperty(&localNodeinfo);
    PrintNodePropertyNum(&localNodeinfo);
    printf("------Remote Device Info------\n");
    if (GetAllNodeDeviceInfo(g_pkgName, &remoteNodeInfo, &infoNum) != 0) {
        printf("GetAllNodeDeviceInfo Fail!\n");
        return -1;
    }
    printf("Device Num = %d\n", infoNum);
    for (int i = 0; i < infoNum; i++) {
        printf("\n[No.%d]\n", i + 1);
        PrintNodeProperty(remoteNodeInfo + i);
        PrintNodePropertyNum(remoteNodeInfo + i);
    }
    FreeNodeInfo(remoteNodeInfo);
    printf("SoftBusDumpDeviceInfo complete!\n");
    return 0;
}

深开鸿_王石

发表于 2023-12-26 14:19  IP属地: - 中国江苏省 中国移动IDC

回复 shixiaocheng: native进程
在native进程拉起前,需要调用GetAccessTokenId函数,获取该native进程的TokenID;再调用SetSelfTokenID将进程TokenID设置到内核中。
在native进程运行过程中,可以通过调用GetNativeTokenInfo、CheckNativeDCap来查验对应进程所具备的token信息,包括分布式能力、APL等级等信息。

【3 条回复】
共4 条回复,点击查看

Copyright   ©2023  OpenHarmony开发者论坛  京ICP备2020036654号-3 |技术支持 Discuz!

返回顶部