• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "pasteboard_progress.h"
17 #include "iservice_registry.h"
18 #include "pasteboard_error.h"
19 #include "pasteboard_hilog.h"
20 #include "pasteboard_time.h"
21 #include "udmf_client.h"
22 
23 using namespace OHOS::UDMF;
24 namespace OHOS::MiscServices {
25 constexpr const int32_t PASTEBOARD_SA_ID = 3701;
26 
InsertValue(std::string & key,std::string & value)27 int32_t PasteBoardProgress::InsertValue(std::string &key, std::string &value)
28 {
29     CustomOption option = {.intention = Intention::UD_INTENTION_DATA_HUB};
30     UnifiedData data;
31     auto udsObject = std::make_shared<Object>();
32     if (udsObject == nullptr) {
33         PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "udsObject is nullptr");
34         return static_cast<int32_t>(PasteboardError::INVALID_PARAM_ERROR);
35     }
36     auto utdId = UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::PLAIN_TEXT);
37     udsObject->value_[UDMF::UNIFORM_DATA_TYPE] = utdId;
38     udsObject->value_[UDMF::CONTENT] = value;
39     udsObject->value_[UDMF::ABSTRACT] = std::to_string(PasteBoardTime::GetCurrentTimeMicros());
40     std::shared_ptr<UnifiedRecord> record = std::make_shared<UnifiedRecord>();
41     record->AddEntry(utdId, std::move(udsObject));
42     data.AddRecord(record);
43     UdmfClient::GetInstance().SetData(option, data, key);
44     return static_cast<int32_t>(PasteboardError::E_OK);
45 }
46 
UpdateValue(std::string & key,std::string value)47 int32_t PasteBoardProgress::UpdateValue(std::string &key, std::string value)
48 {
49     QueryOption queryOption = { .key = key };
50     UnifiedData data;
51     auto udsObject = std::make_shared<Object>();
52     if (udsObject == nullptr) {
53         PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "udsObject is nullptr");
54         return static_cast<int32_t>(PasteboardError::INVALID_PARAM_ERROR);
55     }
56     auto utdId = UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::PLAIN_TEXT);
57     udsObject->value_[UDMF::UNIFORM_DATA_TYPE] = utdId;
58     udsObject->value_[UDMF::CONTENT] = value;
59     udsObject->value_[UDMF::ABSTRACT] = std::to_string(PasteBoardTime::GetCurrentTimeMicros());
60     std::shared_ptr<UnifiedRecord> record = std::make_shared<UnifiedRecord>();
61     record->AddEntry(utdId, std::move(udsObject));
62     data.AddRecord(record);
63     UdmfClient::GetInstance().UpdateData(queryOption, data);
64     return static_cast<int32_t>(PasteboardError::E_OK);
65 }
66 } // namespace OHOS::MiscServices