• Lv0
    粉丝0

积分0 / 贡献0

提问2答案被采纳0文章0

dataobject分布式接口 出现SOFTBUS_PERMISSION_DENIED错误如何解决

hm17 显示全部楼层 发表于 2024-10-25 11:30:33

【问题描述】

  1. 调用出现 createsession函数 出现 SOFTBUS_PERMISSION_DENIED,也就是-268369911错误

  2. 相关代码 //申请权限 const char *perms = new const char [3]; perms[0] = "ohos.permission.DISTRIBUTED_DATASYNC"; perms[1] = "ohos.permission.DISTRIBUTED_SOFTBUS_CENTER"; perms[2] = "ohos.permission.ACCESS_SERVICE_DM"; TokenInfoParams infoInstance = { .dcapsNum = 0, .permsNum = 3, .aclsNum = 0, .dcaps = nullptr, .perms = perms, .acls = nullptr, .processName = "dataObject", .aplStr = "system_core", }; uint64_t tokenId = GetAccessTokenId(&infoInstance); SetSelfTokenID(tokenId); OHOS::Security::AccessToken::AccessTokenKit::AccessTokenKit::ReloadNativeTokenInfo(); //检查权限 int res; res = OHOS::Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenId, "ohos.permission.DISTRIBUTED_DATASYNC"); std::cout<<"res:"<<res<<std::endl; res = OHOS::Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenId, "ohos.permission.DISTRIBUTED_SOFTBUS_CENTER"); std::cout<<"res:"<<res<<std::endl; res = OHOS::Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenId, "ohos.permission.ACCESS_SERVICE_DM"); std::cout<<"res:"<<res<<std::endl;

    //数据变化 bool RegisterObserver() { bool result = true; std::shared_ptr<MockObjectWatcher> watcher = std::make_shared<MockObjectWatcher>(); uint32t status = objectStore->Watch(object_, watcher); std::cout<<"objectStore->Watch status:"<<status<<std::endl; return result; }

//监听设备上下线

bool NotifyStatusAndNotifyChange() { // std::shared_ptr<FlatObjectStorageEngine> storageEngine = std::make_shared<FlatObjectStorageEngine>(); // storageEngine->Open("com.example.myapplication"); // uint32_t ret = storageEngine->CreateTable(TABLESESSIONID); // if (ret != SUCCESS) { // return false; // } // std::map<std::string, std::vector<uint8_t>> filteredData; // storageEngine->NotifyChange(sessionId, filteredData); // storageEngine->NotifyStatus(sessionId, deviceId, status); auto notifierPtr = std::shared_ptr<StatusNotifier>(); uint32t ret = objectStore->SetStatusNotifier(notifierPtr); std::cout<<"objectStore->SetStatusNotifier ret:"ret<std::endl;notifycachedstatus(sessionid);"<deviceid<<"<"<status<<std::endl;DeleteTable(TABLESESSIONID); return true; }

2.日志文件如下

10-23 09:20:10.192 2758 2758 I C015c0/dsoftbus: [COMM][ClientRegisterService:165]ohos.objectstore softbus server register service success! 10-23 09:20:10.193 2758 2758 I C015c0/dsoftbus: [COMM][InitSoftBus:260]softbus sdk frame init success. 10-23 09:20:10.193 2758 2758 I C015c0/dsoftbus: [TRAN][ClientAddSessionServer:332]session name [objectstoreDB-com.example.myapplication], pkg name [ohos.objectstore] 10-23 09:20:10.193 694 878 I C015c0/dsoftbus: [COMM][OnRemoteRequest:204]SoftBusServerStub::OnReceived, code = 130 10-23 09:20:10.193 694 878 I C015c0/dsoftbus: [COMM][CreateSessionServerInner:456]lzy: OHOS::IPCSkeleton::GetCallingUid(),callingUid:0! 10-23 09:20:10.193 694 878 I C015c0/dsoftbus: [COMM][CreateSessionServerInner:458]lzy: OHOS::IPCSkeleton::GetCallingPid(),callingPid:2758! 10-23 09:20:10.193 694 878 I C015c0/dsoftbus: [COMM][CompareString:267]src:objectstoreDB-* dest:objectstoreDB-com.example.myapplication 10-23 09:20:10.193 694 878 I C015c0/dsoftbus: [COMM][CompareString:274]src:ohos.objectstore dest:ohos.objectstore 10-23 09:20:10.193 694 878 I C015c0/dsoftbus: [COMM][CheckSessionName:421]lzy:CheckSessionName sessionName:objectstoreDB-com.example.myapplication,callingUid:0! 10-23 09:20:10.193 694 878 I C01510/IPCObjectProxy: 58: handle = 21 create, descriptor: IPCObjectProxy21 10-23 09:20:10.194 589 589 W C01120/BundleMgrService: [bundle_datamgr.cpp(GetNameForUid):2241] get innerBundleInfo from bundleInfo by uid failed. 10-23 09:20:10.194 694 878 E C01120/BundleMgrService: [bundle_mgrproxy.cpp(GetNameForUid):738] host reply errCode : 8521233 10-23 09:20:10.194 694 878 E C015c0/dsoftbus: [TRAN][GetBundleName:410]get bundleName failed 10-23 09:20:10.194 694 878 W C01510/IPCObjectProxy: 63: handle = 21 destroyed, descriptor: IPCObjectProxy21 10-23 09:20:10.194 694 878 E C015c0/dsoftbus: [TRAN][CheckSessionName:425]get bundle name failed 10-23 09:20:10.194 2758 2758 E C015c0/dsoftbus: [TRAN][CreateSessionServer:134]Server createSessionServer failed 10-23 09:20:10.194 2758 2758 I C015c0/dsoftbus: [TRAN][DestroyClientSessionServer:222]destroy session server [objectstoreDB-com.example.myapplication] 10-23 09:20:10.194 2758 2758 E C015c0/dsoftbus: [TRAN][ClientDestroySession:181]destroyList is empty fail. 10-23 09:20:10.194 2758 2758 I C015c0/dsoftbus: [TRAN][CreateSessionServer:137]CreateSessionServer ok: ret=-268369911 10-23 09:20:10.194 2758 2758 W C01652/ObjectStore-x: 100: Start Start pipeInfo:objectstoreDB-com.example.myapplication, failed ret:-268369911. 10-23 09:20:10.194 2758 2758 I C01652/ObjectStore-x: 28: ~AppPipeHandler destructor pipeId: objectstoreDB-com.example.myapplication 10-23 09:20:10.194 2758 2758 E C01652/ObjectStore-x: 39: Start commProvider Start Fail. 10-23 09:20:10.194 2758 2758 E C01630/DistributedDB: [NAdapt][Start] Start Fail, errCode=-1. 10-23 09:20:10.194 2758 2758 E C01630/DistributedDB: [CommAggr][Init] Start Adapter Fail, errCode=-1032. 10-23 09:20:10.194 2758 2758 E C01630/DistributedDB: CommunicatorAggregator init failed, err = -1032! 10-23 09:20:10.194 2758 2758 I C01630/DistributedDB: [AutoLaunch] SetCommunicatorAggregator 10-23 09:20:10.194 2758 2758 I C01630/DistributedDB: [AutoLaunch] SetCommunicatorAggregator aggregator is nullptr 10-23 09:20:10.194 2758 2758 I C01652/ObjectStore-x: 62: Open FlatObjectDatabase::Open Succeed 10-23 09:20:10.194 2758 2758 I C01652/ObjectStore-x: 187: SetStatusNotifier lzy:DistributedObjectStoreImpl::SetStatusNotifier: start!!! 10-23 09:20:10.194 2758 2758 I C01630/DistributedDB: lzy:SetStoreStatusNotifier ok!!! 10-23 09:20:10.194 2758 2758 I C01630/DistributedDB: SetStoreStatusNotifier ok 10-23 09:20:10.194 2758 2758 I C01652/ObjectStore-x: 369: SetStatusNotifier FlatObjectStorageEngine::SetStatusNotifier success

3、总结

目测无问题,相关接口返回值也正常,本地可以进行正常的增删改查 ,但分布式无法使用,无法获取对端设备数据变动,请问这个问题是权限问题还是什么?我觉得是callinguid()获取失败导致,但是不知道是什么原因

【运行环境】

硬件:rk3588 ROM版本:OpenHarmony4.0

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

精彩评论1

kuaile

沙发 发表于 6 天前
更新新版本, 打印uio是0,获取的权限失败

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

返回顶部