OpenHarmony开发者论坛

标题: dataobject分布式接口 出现SOFTBUS_PERMISSION_DENIED错误如何解决 [打印本页]

作者: hm17    时间: 2024-10-25 11:30
标题: dataobject分布式接口 出现SOFTBUS_PERMISSION_DENIED错误如何解决
[md]### 【问题描述】

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>();
   uint32_t 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>();
uint32_t ret = objectStore_->SetStatusNotifier(notifierPtr);
std::cout<<"objectStore->SetStatusNotifier ret:"[ret<std::endl;notifycachedstatus(sessionid);"<deviceid<<"<"<status<<std::endl;DeleteTable(TABLESESSIONID);
return true;
}](%3Cret%3C%3Cstd::endl;%0AobjectStore_-)

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_data_mgr.cpp(GetNameForUid):2241] get innerBundleInfo from bundleInfo_ by uid failed.
10-23 09:20:10.194   694   878 E C01120/BundleMgrService: [bundle_mgr_proxy.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 lzyistributedObjectStoreImpl::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
[/md]
作者: kuaile    时间: 2024-10-30 18:28
更新新版本, 打印uio是0,获取的权限失败




欢迎光临 OpenHarmony开发者论坛 (https://forums.openharmony.cn/) Powered by Discuz! X3.5