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 TELEPHONY_CALL_RECORDS_HANDLER_H
17 #define TELEPHONY_CALL_RECORDS_HANDLER_H
18 
19 #include <memory>
20 #include <mutex>
21 
22 #include "call_data_base_helper.h"
23 #include "call_status_manager.h"
24 #include "event_handler.h"
25 #include "event_runner.h"
26 #include "missed_call_notification.h"
27 #include "singleton.h"
28 
29 namespace OHOS {
30 namespace Telephony {
31 class CallRecordsHandler {
32 public:
33     CallRecordsHandler();
34     virtual ~CallRecordsHandler() = default;
35     int32_t QueryAndNotifyUnReadMissedCall();
36     int32_t AddCallLogInfo(const CallRecordInfo &info);
37 
38 private:
39     void QueryCallerInfo(ContactInfo &contactInfo, std::string phoneNumber);
40     std::string CheckNumberLocationInfo(const CallRecordInfo &info);
41     void MakeCallLogInsertBucket(DataShare::DataShareValuesBucket &bucket,
42         const CallRecordInfo &info, std::string displayName, std::string numberLocation);
43     void DeleteCallLogForLimit(const CallRecordInfo &info);
44 
45 private:
46     std::shared_ptr<CallDataBaseHelper> callDataPtr_;
47     std::shared_ptr<MissedCallNotification> missedCallNotification_;
48 };
49 
50 class CallRecordsHandlerService : public std::enable_shared_from_this<CallRecordsHandlerService> {
51     DECLARE_DELAYED_SINGLETON(CallRecordsHandlerService)
52 public:
53     void Start();
54     int32_t StoreCallRecord(const CallRecordInfo &info);
55     int32_t RemoveMissedIncomingCallNotification();
56     int32_t QueryUnReadMissedCallLog();
57 
58 private:
59     std::shared_ptr<CallRecordsHandler> handler_;
60 };
61 } // namespace Telephony
62 } // namespace OHOS
63 #endif // TELEPHONY_CALL_RECORDS_HANDLER_H