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 int32_t ReportSecurityInfo(const struct EventInfoSt *info);
31 
32 int32_t SecurityGuardConfigUpdate(int32_t fd, const char *fileName);
33 #ifdef __cplusplus
34 }
35 #endif
36 
37 namespace OHOS::Security::SecurityGuard {
38 class NativeDataCollectKit {
39 public:
40     static int32_t ReportSecurityInfo(const std::shared_ptr<EventInfo> &info);
41     static int32_t SecurityGuardConfigUpdate(int32_t fd, const std::string &fileName);
42 };
43 
44 class SgCollectClient {
45 public:
46     static SgCollectClient &GetInstance();
47     sptr<IDataCollectManager> GetProxy();
48     void InitProxy();
49     void ReleaseProxy();
50 
51 private:
52     SgCollectClient() = default;
53     ~SgCollectClient() = default;
54     std::mutex proxyMutex_;
55     sptr<IDataCollectManager> proxy_ = nullptr;
56     sptr<IRemoteObject::DeathRecipient> deathRecipient_ = nullptr;
57 };
58 
59 class SgCollectClientDeathRecipient : public IRemoteObject::DeathRecipient {
60 public:
61     SgCollectClientDeathRecipient() = default;
62     ~SgCollectClientDeathRecipient() override = default;
63 
64     void OnRemoteDied(const wptr<IRemoteObject> &object) override;
65 };
66 } // namespace OHOS::Security::SecurityGuard
67 
68 #endif // SECURITY_GUARD_SG_COLLECT_CLIENT_H