• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "clipboard_utils.h"
17 
18 #include "edm_log.h"
19 #include "pasteboard_client.h"
20 namespace OHOS {
21 namespace EDM {
HandlePasteboardPolicy(std::map<int32_t,ClipboardInfo> & data)22 ErrCode ClipboardUtils::HandlePasteboardPolicy(std::map<int32_t, ClipboardInfo> &data)
23 {
24     EDMLOGI("ClipboardUtils handlePasteboardPolicy.");
25     auto pasteboardClient = MiscServices::PasteboardClient::GetInstance();
26     if (pasteboardClient == nullptr) {
27         EDMLOGE("ClipboardUtils::HandlePasteboardPolicy PasteboardClient null");
28         return EdmReturnErrCode::SYSTEM_ABNORMALLY;
29     }
30     std::map<uint32_t, MiscServices::ShareOption> setMap;
31     std::vector<uint32_t> removeVector;
32     for (const auto &item : data) {
33         switch (item.second.policy) {
34             case ClipboardPolicy::DEFAULT:
35                 removeVector.emplace_back(item.first);
36                 break;
37             case ClipboardPolicy::IN_APP:
38                 setMap.insert(std::make_pair(item.first, MiscServices::ShareOption::InApp));
39                 break;
40             case ClipboardPolicy::LOCAL_DEVICE:
41                 setMap.insert(std::make_pair(item.first, MiscServices::ShareOption::LocalDevice));
42                 break;
43             case ClipboardPolicy::CROSS_DEVICE:
44                 setMap.insert(std::make_pair(item.first, MiscServices::ShareOption::CrossDevice));
45                 break;
46             default:
47                 break;
48         }
49     }
50     ErrCode setRet = ERR_OK;
51     ErrCode rmRet = ERR_OK;
52     if (!setMap.empty()) {
53         setRet = pasteboardClient->SetGlobalShareOption(setMap);
54     }
55     if (!removeVector.empty()) {
56         rmRet = pasteboardClient->RemoveGlobalShareOption(removeVector);
57     }
58     if (setRet != ERR_OK || rmRet != ERR_OK) {
59         return EdmReturnErrCode::SYSTEM_ABNORMALLY;
60     }
61     return ERR_OK;
62 }
63 } // namespace EDM
64 } // namespace OHOS