• 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 #ifndef SECURITY_COLLECTOR_SDK_FLAG_H
17 #define SECURITY_COLLECTOR_SDK_FLAG_H
18 
19 #include <string>
20 #include <vector>
21 #include "parcel.h"
22 #include "event_define.h"
23 
24 namespace OHOS::Security::SecurityCollector {
25 class SecuritySdkFlag : public Parcelable {
26 public:
27     SecuritySdkFlag() = default;
SecuritySdkFlag(const SdkFlags & flag)28     SecuritySdkFlag(const SdkFlags &flag) : flag_(flag) {};
29     ~SecuritySdkFlag() override = default;
30 
GetSdkFlag()31     SdkFlags GetSdkFlag() const { return flag_; };
Marshalling(Parcel & parcel)32     bool Marshalling(Parcel& parcel) const override
33     {
34         if (!parcel.WriteString(flag_.sdkFlag)) {
35             LOGE("failed to write sdkFlag");
36             return false;
37         }
38         if (!parcel.WriteUint32(flag_.instanceFalgs.size())) {
39             LOGE("failed to write instanceFalgs size");
40             return false;
41         }
42         for (auto iter : flag_.instanceFalgs) {
43             if (!parcel.WriteString(iter)) {
44                 LOGE("failed to write version");
45                 return false;
46             }
47         }
48         return true;
49     }
ReadFromParcel(Parcel & parcel)50     bool ReadFromParcel(Parcel &parcel)
51     {
52         if (!parcel.ReadString(flag_.sdkFlag)) {
53             LOGE("failed to read sdkFlag");
54             return false;
55         }
56         uint32_t size = parcel.ReadUint32();
57         if (size > MAX_API_INSTACNE_SIZE) {
58             LOGE("the subs size error");
59             return false;
60         }
61         for (uint32_t i = 0; i < size; i++) {
62             flag_.instanceFalgs.insert(parcel.ReadString());
63         }
64         return true;
65     }
Unmarshalling(Parcel & parcel)66     static SecuritySdkFlag* Unmarshalling(Parcel& parcel)
67     {
68         SecuritySdkFlag *flag = new (std::nothrow) SecuritySdkFlag();
69         if (flag != nullptr && !flag->ReadFromParcel(parcel)) {
70             delete flag;
71             flag = nullptr;
72         }
73         return flag;
74     }
75 
76 private:
77     SdkFlags flag_ {};
78 };
79 } // namespace OHOS::Security::SecurityCollector
80 
81 #endif // SECURITY_COLLECTOR_SDK_FLAG_H
82