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 OHOS_SIM_SMS_CONTROLLER_H
17 #define OHOS_SIM_SMS_CONTROLLER_H
18 
19 #include "icc_file_controller.h"
20 #include "sim_state_manager.h"
21 #include "sim_file_manager.h"
22 
23 namespace OHOS {
24 namespace Telephony {
25 enum {
26     SIM_SMS_STATE_DELETE = 0,
27     SIM_SMS_STATE_READ = 1,
28     SIM_SMS_STATE_UNREAD = 3,
29     SIM_SMS_STATE_SENT = 5,
30     SIM_SMS_STATE_UNSENT = 7,
31 };
32 
33 enum {
34     SIM_SMS_GET_COMPLETED = 1,
35     SIM_SMS_UPDATE_COMPLETED = 2,
36     SIM_SMS_WRITE_COMPLETED = 3,
37     SIM_SMS_DELETE_COMPLETED = 4
38 };
39 
40 class SimSmsController : public TelEventHandler {
41 public:
42     explicit SimSmsController(std::shared_ptr<SimStateManager> simStateManager);
43     ~SimSmsController();
44     void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event);
45     int32_t AddSmsToIcc(int status, std::string &pdu, std::string &smsc);
46     int32_t UpdateSmsIcc(int index, int status, std::string &pduData, std::string &smsc);
47     int32_t DelSmsIcc(int index);
48     std::vector<std::string> ObtainAllSmsOfIcc();
49     void SetRilAndFileManager(
50         std::shared_ptr<Telephony::ITelRilManager> ril, std::shared_ptr<SimFileManager> fileMgr);
51     void Init(int slotId);
52 
53 protected:
54     std::shared_ptr<SimFileManager> fileManager_ = nullptr;
55     std::shared_ptr<Telephony::ITelRilManager> telRilManager_ = nullptr;
56     std::shared_ptr<SimStateManager> stateManager_ = nullptr;
57     bool responseReady_ = false;
58     bool loadDone_ = false;
59     int slotId_ = 0;
60 
61 private:
62     bool IsCdmaCardType() const;
63     std::vector<std::string> smsList_;
64     static std::mutex mtx_;
65     std::condition_variable processWait_;
66     void ProcessLoadDone(const AppExecFwk::InnerEvent::Pointer &event);
67     void ProcessUpdateDone(const AppExecFwk::InnerEvent::Pointer &event);
68     void ProcessWriteDone(const AppExecFwk::InnerEvent::Pointer &event);
69     void ProcessDeleteDone(const AppExecFwk::InnerEvent::Pointer &event);
70     AppExecFwk::InnerEvent::Pointer BuildCallerInfo(int eventId);
71 };
72 } // namespace Telephony
73 } // namespace OHOS
74 #endif // OHOS_SIM_SMS_CONTROLLER_H