diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp index 7c628c8d4f6f6d3363074ee4b8c47570bf3ef183..4aa437cbcca79c75abd356630f8a1c23ac6a1746 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp @@ -245,6 +245,12 @@ void KVDBServiceImpl::OnAsyncComplete(uint32_t tokenId, uint64_t seqNum, Progres Status KVDBServiceImpl::Sync(const AppId &appId, const StoreId &storeId, int32_t subUser, SyncInfo &syncInfo) { + auto instanceId = GetInstIndex(IPCSkeleton::GetCallingTokenID(), appId); + if (instanceId != 0) { + ZLOGE("twin application not allow sync, instanceId:%{public}d, appId:%{public}s, storeId:%{public}s", + instanceId, appId.appId.c_str(), Anonymous::Change(storeId.storeId).c_str()); + return Status::NOT_SUPPORT; + } StoreMetaData metaData = GetStoreMetaData(appId, storeId, subUser); MetaDataManager::GetInstance().LoadMeta(metaData.GetKeyWithoutPath(), metaData); auto delay = GetSyncDelayTime(syncInfo.delay, storeId, metaData.user); diff --git a/services/distributeddataservice/service/test/kvdb_service_impl_test.cpp b/services/distributeddataservice/service/test/kvdb_service_impl_test.cpp index bc4c17a967256e8a69e7d1f1202ef438ca003f4e..039577976be7a8734d7a87fad25c39288a4dbbfc 100644 --- a/services/distributeddataservice/service/test/kvdb_service_impl_test.cpp +++ b/services/distributeddataservice/service/test/kvdb_service_impl_test.cpp @@ -1507,6 +1507,24 @@ HWTEST_F(KvdbServiceImplTest, syncTest003, TestSize.Level0) EXPECT_EQ(localMeta.HasPolicy(DistributedKv::IMMEDIATE_SYNC_ON_ONLINE), true); } +/** +* @tc.name: SyncTest004 +* @tc.desc: twin application sync test +* @tc.type: FUNC +*/ +HWTEST_F(KvdbServiceImplTest, SyncTest004, TestSize.Level0) +{ + EXPECT_CALL(*accTokenMock, GetTokenTypeFlag(testing::_)) + .WillOnce(testing::Return(ATokenTypeEnum::TOKEN_HAP)) + .WillRepeatedly(testing::Return(ATokenTypeEnum::TOKEN_HAP)); + EXPECT_CALL(*accTokenMock, GetHapTokenInfo(testing::_, testing::_)) + .WillOnce(testing::Return(0)) + .WillRepeatedly(testing::Return(0)); + SyncInfo syncInfo; + auto status = kvdbServiceImpl_->Sync(appId, storeId, 0, syncInfo); + ASSERT_EQ(status, Status::NOT_SUPPORT); +} + /** * @tc.name: GetSyncParamTest001 * @tc.desc: GetStoreIds