1 /*
2  * Copyright (c) 2022 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 SECURITY_GUARD_SG_COLLECT_CLIENT_H
17 #define SECURITY_GUARD_SG_COLLECT_CLIENT_H
18 
19 #include <mutex>
20 
21 #include "iremote_object.h"
22 
23 #include "event_info.h"
24 #include "i_data_collect_manager.h"
25 #include "security_guard_api.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 int32_t ReportSecurityInfo(const struct EventInfoSt *info);
32 int32_t ReportSecurityInfoAsync(const struct EventInfoSt *info);
33 
34 #ifdef __cplusplus
35 }
36 #endif
37 
38 namespace OHOS::Security::SecurityGuard {
39 class NativeDataCollectKit {
40 public:
41     static int32_t ReportSecurityInfo(const std::shared_ptr<EventInfo> &info);
42     static int32_t ReportSecurityInfoAsync(const std::shared_ptr<EventInfo> &info);
43     static int32_t SecurityGuardConfigUpdate(int32_t fd, const std::string &fileName);
44 };
45 
46 class SgCollectClient {
47 public:
48     static SgCollectClient &GetInstance();
49     sptr<IDataCollectManager> GetProxy();
50     void InitProxy();
51     void ReleaseProxy();
52 
53 private:
54     SgCollectClient() = default;
55     ~SgCollectClient() = default;
56     std::mutex proxyMutex_;
57     sptr<IDataCollectManager> proxy_ = nullptr;
58     sptr<IRemoteObject::DeathRecipient> deathRecipient_ = nullptr;
59 };
60 
61 class SgCollectClientDeathRecipient : public IRemoteObject::DeathRecipient {
62 public:
63     SgCollectClientDeathRecipient() = default;
64     ~SgCollectClientDeathRecipient() override = default;
65 
66     void OnRemoteDied(const wptr<IRemoteObject> &object) override;
67 };
68 } // namespace OHOS::Security::SecurityGuard
69 
70 #endif // SECURITY_GUARD_SG_COLLECT_CLIENT_H