1 /*
2  * Copyright (C) 2021 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 MAP_SERVICE_H
17 #define MAP_SERVICE_H
18 
19 #include <memory>
20 #include <vector>
21 
22 namespace stub {
23 static const std::string STUB_MAP_MSE_DB_FILE = "map_mse.s3db";
24 
25 enum AccountType { EMAIL, IM, OTHER };
26 
27 enum PhoneType { NONE, SMS_GSM, SMS_CDMA };
28 
29 enum class Presence : uint8_t { UNKNOWN, OFFLINE, ONLINE, AWAY, DO_NOT_DISTURB, BUSY, IN_A_MEETING };
30 
31 enum class ChatState : uint8_t { UNKNOWN, INACTIVE, ACTIVE, COMPOSING, PAUSED_COMPOSING, GONE };
32 
33 enum EventType {
34     NEW_MESSAGE,
35     MESSAGE_DELETED,
36     MESSAGE_REMOVED,
37     MESSAGE_SHIFT,
38     DELIVERY_SUCCESS,
39     SENDING_SUCCESS,
40     SENDING_FAILURE,
41     DELIVERY_FAILURE,
42     READ_STATUS_CHANGED,
43     CONVERSATION_CHANGED,
44     PARTICIPANT_PRESENCE_CHANGED,
45     PARTICIPANT_CHAT_STATE_CHANGED,
46     MESSAGE_EXTENDED_DATA_CHANGED,
47     MEMORY_FULL,
48     MEMORY_AVAILABLE
49 };
50 
51 enum class MsgType { NONE, EMAIL, SMS_GSM, SMS_CDMA, MMS, IM };
52 
53 class EmailImAccount {
54 public:
EmailImAccount(std::string & accountId,AccountType accountType,std::string & name,std::string & packageName,std::string & providerAuthority,std::string & uci,std::string & uciPrefix)55     explicit EmailImAccount(std::string &accountId, AccountType accountType, std::string &name,
56         std::string &packageName, std::string &providerAuthority, std::string &uci, std::string &uciPrefix)
57     {}
~EmailImAccount()58     virtual ~EmailImAccount()
59     {}
GetType(void)60     AccountType GetType(void)
61     {
62         return OTHER;
63     }
GetAccountId(void)64     std::string GetAccountId(void)
65     {
66         return "";
67     }
GetName(void)68     std::string GetName(void)
69     {
70         return "";
71     }
GetPackageName(void)72     std::string GetPackageName(void)
73     {
74         return "";
75     }
GetProviderAuthority(void)76     std::string GetProviderAuthority(void)
77     {
78         return "";
79     }
GetBaseUri(void)80     std::string GetBaseUri(void)
81     {
82         return "";
83     }
GetBaseUriNoAccount(void)84     std::string GetBaseUriNoAccount(void)
85     {
86         return "";
87     }
GetUci(void)88     std::string GetUci(void)
89     {
90         return "";
91     }
GetUciPrefix(void)92     std::string GetUciPrefix(void)
93     {
94         return "";
95     }
96 };
97 
98 struct FolderColumns {
99     std::string id = "";
100     std::string name = "";
101     std::string accountId = "";
102     std::string parentId = "";
103 };
104 
105 struct OwnerStatusParam {
106     std::string conversationId = "";
107     uint8_t presenceAvailability = 0;
108     std::string presenceText = "";
109     std::string lastActivity = "";
110     uint8_t chatState = 0;
111 };
112 struct TelContent {
113     bool isSmsCapable = false;
114     PhoneType phoneType = PhoneType::NONE;
115     std::string phoneNumber = "";
116 };
117 
118 struct MsgInfo {
119     uint8_t transparent = 0;
120     uint8_t retry = 0;
121     std::string phoneNumber = "";
122     std::string emailAddress = "";
123     int msgType = 0;
124 };
125 
126 struct EventInfo {
127     EventType eventType {};
128     std::string handle = "";
129     std::string folder = "";
130     std::string oldFolder = "";
131     MsgType msgType = MsgType::NONE;
132     std::string datetime = "";
133     std::string subject = "";
134     std::string senderName = "";
135     int priority = -1;
136     std::string conversationName = "";
137     std::string conversationID = "";
138     int presenceAvailability = -1;
139     std::string presenceText = "";
140     std::string lastActivity = "";
141     int chatState = 0;
142     int readStatus = -1;
143     std::string extendedData = "";
144     std::string participantUci = "";
145     std::string contactUid = "";
146 };
147 
148 class MapServiceObserver {
149 public:
150     virtual ~MapServiceObserver() = default;
OnNotifyingEvent(const std::string & addr,EventInfo & event)151     virtual void OnNotifyingEvent(const std::string &addr, EventInfo &event)
152     {}
OnUpdateDbIdCounter(void)153     virtual void OnUpdateDbIdCounter(void)
154     {}
OnUpdateVerIdCounter(void)155     virtual void OnUpdateVerIdCounter(void)
156     {}
OnUpdateConvoVerIdCounter(void)157     virtual void OnUpdateConvoVerIdCounter(void)
158     {}
159 };
160 
161 class StubMapObserver {
162 public:
163     virtual ~StubMapObserver() = default;
OnSetOwnerStatusComplete(const OwnerStatusParam & ownerStatus)164     virtual void OnSetOwnerStatusComplete(const OwnerStatusParam &ownerStatus)
165     {}
OnUpdateFolder(std::string & accountId,std::string & folderId)166     virtual void OnUpdateFolder(std::string &accountId, std::string &folderId)
167     {}
OnSendMessage(MsgInfo & msgInfo,std::string & msgBody)168     virtual void OnSendMessage(MsgInfo &msgInfo, std::string &msgBody)
169     {}
OnEventConnected(const std::string & addr)170     virtual void OnEventConnected(const std::string &addr)
171     {}
OnEventDisConnected(const std::string & addr)172     virtual void OnEventDisConnected(const std::string &addr)
173     {}
OnEventSendComplete(const std::string & addr)174     virtual void OnEventSendComplete(const std::string &addr)
175     {}
176 };
177 
178 class MapService {
179 public:
180     static MapService *GetInstance();
RegisterObserver(StubMapObserver & observer)181     void RegisterObserver(StubMapObserver &observer)
182     {}
DeregisterObserver(StubMapObserver & observer)183     void DeregisterObserver(StubMapObserver &observer)
184     {}
RegisterObserver(MapServiceObserver * observer,int masId)185     void RegisterObserver(MapServiceObserver *observer, int masId)
186     {}
DeregisterObserver(MapServiceObserver * observer,int masId)187     void DeregisterObserver(MapServiceObserver *observer, int masId)
188     {}
GetSystemTelephonyService(void)189     TelContent GetSystemTelephonyService(void)
190     {
191         TelContent tmp = {0};
192         return tmp;
193     }
GetEmailImAccounts(void)194     std::vector<std::unique_ptr<EmailImAccount>> &GetEmailImAccounts(void)
195     {
196         return accounts_;
197     }
198     void SetMseInstance(int id = 0)
199     {}
QueryFolderInfo(std::string & parentId)200     std::vector<FolderColumns> QueryFolderInfo(std::string &parentId)
201     {
202         std::vector<FolderColumns> tmp;
203         return tmp;
204     }
UpdateFolder(std::string & accountId,std::string folderId,int masId)205     bool UpdateFolder(std::string &accountId, std::string folderId, int masId)
206     {
207         return false;
208     }
SetOwnerStatus(OwnerStatusParam & ownerParam,int masId)209     bool SetOwnerStatus(OwnerStatusParam &ownerParam, int masId)
210     {
211         return false;
212     }
GetOwnerStatus(std::string & conversationId)213     const OwnerStatusParam &GetOwnerStatus(std::string &conversationId)
214     {
215         return ownerStatus_;
216     }
SendMessage(MsgInfo & msgInfo,std::string & msgBody,int masId)217     void SendMessage(MsgInfo &msgInfo, std::string &msgBody, int masId)
218     {}
219     void SendEvent(const std::string &addr, int type, int msgType = 2)
220     {}
221     int ReceiveMessage(int type, std::string id = "")
222     {
223         return 0;
224     }
UpdateMessageStatus()225     void UpdateMessageStatus()
226     {}
EventConnected(const std::string & addr)227     void EventConnected(const std::string &addr)
228     {}
EventDisConnected(const std::string & addr)229     void EventDisConnected(const std::string &addr)
230     {}
EventSendComplete(const std::string & addr)231     void EventSendComplete(const std::string &addr)
232     {}
233 
234 private:
235     MapService() = default;
236     ~MapService() = default;
237 
238     std::vector<std::unique_ptr<EmailImAccount>> accounts_ {};
239     OwnerStatusParam ownerStatus_ {};
240 
241     MapService(const MapService &) = delete;
242     MapService &operator=(const MapService &) = delete;
243 };
244 }  // namespace stub
245 #endif  // MAP_SERVICE_H