• 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 #ifndef PASTE_BOARD_SERVICE_LOADER_H
17 #define PASTE_BOARD_SERVICE_LOADER_H
18 
19 #include "ipasteboard_service.h"
20 #include "paste_data_entry.h"
21 #include "refbase.h"
22 #include "api/visibility.h"
23 
24 namespace OHOS {
25 namespace MiscServices {
26 
27 class API_EXPORT PasteboardSaDeathRecipient : public IRemoteObject::DeathRecipient {
28 public:
29     explicit PasteboardSaDeathRecipient();
30     ~PasteboardSaDeathRecipient() = default;
31     void OnRemoteDied(const wptr<IRemoteObject> &object) override;
32 
33 private:
34     DISALLOW_COPY_AND_MOVE(PasteboardSaDeathRecipient);
35 };
36 
37 class API_EXPORT PasteboardServiceLoader {
38 public:
39     static PasteboardServiceLoader &GetInstance();
40     sptr<IPasteboardService> GetPasteboardService();
41     sptr<IPasteboardService> GetPasteboardServiceProxy();
42     void SetPasteboardServiceProxy(const sptr<IRemoteObject> &remoteObject);
43     void ReleaseDeathRecipient();
44     int32_t GetRecordValueByType(uint32_t dataId, uint32_t recordId, PasteDataEntry& value);
45     void OnRemoteSaDied(const wptr<IRemoteObject> &object);
46     void LoadSystemAbilityFail();
47     void LoadSystemAbilitySuccess(const sptr<IRemoteObject> &remoteObject);
48     void ClearPasteboardServiceProxy();
49     void CleanupResource();
50 
51 private:
52     PasteboardServiceLoader();
53     ~PasteboardServiceLoader();
54     int32_t ProcessPasteData(PasteDataEntry &data, int64_t rawDataSize, int fd,
55         const std::vector<uint8_t> &recvTLV);
56     static sptr<IPasteboardService> pasteboardServiceProxy_;
57     static std::condition_variable proxyConVar_;
58     static std::mutex instanceLock_;
59     bool constructing_ = false;
60     sptr<IRemoteObject::DeathRecipient> deathRecipient_{ nullptr };
61 
62     class StaticDestroyMonitor {
63     public:
StaticDestroyMonitor()64         StaticDestroyMonitor() : destroyed_(false) {}
~StaticDestroyMonitor()65         ~StaticDestroyMonitor()
66         {
67             destroyed_ = true;
68         }
69 
IsDestroyed()70         bool IsDestroyed() const
71         {
72             return destroyed_;
73         }
74 
75     private:
76         bool destroyed_ = false;
77     };
78     static StaticDestroyMonitor staticDestroyMonitor_;
79 };
80 } // namespace MiscServices
81 } // namespace OHOS
82 #endif // PASTE_BOARD_SERVICE_LOADER_H
83