• 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 BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_TLV_BOX_H
17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_TLV_BOX_H
18 
19 #include <vector>
20 #include <string>
21 #include <map>
22 
23 namespace OHOS {
24 namespace Notification {
25 
26 enum NotificationEventType : int32_t {
27     PUBLISH_NOTIFICATION = 0,
28     UPDATE_NOTIFICATION = 1,
29     REMOVE_NOTIFICATION = 2,
30     CLICK_TO_JUMP = 3,
31     NOTIFICATION_QUICK_REPLY = 4,
32     NOTIFICATION_STATE_SYNC = 5,
33     NOTIFICATION_MATCH_SYNC = 6,
34     BUNDLE_ICON_SYNC = 7,
35     REMOVE_ALL_NOTIFICATIONS = 8,
36     NOTIFICATION_RESPONSE_SYNC = 9,
37     SYNC_NOTIFICATION = 10,
38     NOTIFICATION_RESPONSE_REPLY_SYNC = 11,
39     INSTALLED_BUNDLE_SYNC = 12,
40     REMOVE_ALL_DISTRIBUTED_NOTIFICATIONS = 13,
41 };
42 
43 enum TlvType : int32_t {
44     MESSAGE_TYPE_ID = 0,
45     NOTIFICATION_HASHCODE,
46     NOTIFICATION_SLOT_TYPE,
47     NOTIFICATION_REMINDERFLAG,
48     BUNDLE_NAME,
49     NOTIFICATION_TITLE,
50     NOTIFICATION_CONTENT,
51     BUNDLE_ICON,
52     NOTIFICATION_BIG_ICON = 8,
53     NOTIFICATION_OVERLAY_ICON = 9,
54     NOTIFICATION_CONTENT_TYPE = 10,
55     NOTIFICATION_COMMON_LIVEVIEW = 11,
56     BATCH_REMOVE_SLOT_TYPE = 14,
57     AUTO_DELETE_TIME = 15,
58     FINISH_DEADLINE_TIME = 16,
59     ACTION_BUTTON_NAME = 17,
60     ACTION_USER_INPUT = 18,
61     NOTIFICATION_ADDITIONAL_TEXT = 19,
62     NOTIFICATION_BRIEF_TEXT = 20,
63     NOTIFICATION_EXPANDED_TITLE = 21,
64     NOTIFICATION_LONG_TITLE = 22,
65     ALL_LINES_LENGTH = 23,
66     NOTIFICATION_APP_MESSAGE_ID = 24,
67     NOTIFICATION_EXTENDINFO = 25,
68     NOTIFICATION_RECEIVE_USERID = 26,
69     NOTIFICATION_BASIC_INFO = 985,
70     LOCAL_DEVICE_USERID = 986,
71     LIVEVIEW_SYNC_ENABLE = 987,
72     NOTIFICATION_SYNC_ENABLE = 988,
73     RESULT_CODE = 989,
74     OPERATION_TYPE = 990,
75     OPERATION_EVENT_ID = 991,
76     BUNDLE_ICON_SYNC_TYPE = 992,
77     MATCH_TYPE = 993,
78     PEER_DEVICE_ID = 994,
79     PEER_DEVICE_TYPE = 995,
80     LOCAL_DEVICE_STATUS = 996,
81     LOCAL_DEVICE_ID = 997,
82     LOCAL_DEVICE_TYPE = 998,
83     LOCAL_VERSION = 999,
84     CHECK_SUM = 1000,
85     OPERATION_BTN_INDEX = 1001,
86     ACTION_BUTTONS_TITILE_INDEX = 1002,
87     ACTION_BUTTONS_LENGTH = 1005,
88     OPERATION_JUMP_TYPE = 1006,
89     NOTIFICATION_ALL_LINES_START_INDEX = 2000,
90 };
91 
92 class TlvItem {
93 public:
94     TlvItem(int32_t type, bool value);
95     TlvItem(int32_t type, int32_t value);
96     TlvItem(int32_t type, int64_t value);
97     TlvItem(int32_t type, std::string value);
98     TlvItem(int32_t type, const unsigned char* value, uint32_t length);
99     TlvItem(int32_t type, const TlvItem& value);
100     ~TlvItem();
101 
102     int32_t GetType() const;
103     uint32_t GetLength() const;
104     unsigned char* GetValue() const;
105 
106 private:
107     void Initialize(const void* value, uint32_t length);
108 
109     int32_t type_;
110     uint32_t length_ = 0;
111     unsigned char* value_ = nullptr;
112 };
113 
114 class TlvBox {
115 public:
116     ~TlvBox();
117     bool Serialize(bool addCheck = true);
118     bool Parse(const unsigned char* buffer, uint32_t buffersize);
119     bool PutValue(std::shared_ptr<TlvItem> value);
120     bool SetMessageType(int32_t messageType);
121     void AddMessageCRC(std::string& content);
122     static bool CheckMessageCRC(const unsigned char* data, uint32_t dataLen);
123 
124     bool GetMessageType(int32_t& messageType);
125     bool GetBoolValue(int32_t type, bool& value);
126     bool GetBytes(int32_t type, std::vector<uint8_t>& value);
127     bool GetStringValue(int32_t type, std::string& value);
128     bool GetInt32Value(int32_t type, int32_t& value);
129     bool GetInt64Value(int32_t type, int64_t& value);
130     bool GetObjectValue(int32_t type, TlvBox& value);
131 
132     uint32_t bytesLength_ = 0;
133     unsigned char* byteBuffer_ = nullptr;
134     std::map<int32_t, std::shared_ptr<TlvItem>> TlvMap_;
135 };
136 }  // namespace Notification
137 }  // namespace OHOS
138 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_TLV_BOX_H
139 
140