• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_DATA_BASE_HELPER_H
17 #define TELEPHONY_CALL_DATA_BASE_HELPER_H
18 
19 #include "ability_manager_interface.h"
20 #include "common_type.h"
21 #include "data_ability_observer_stub.h"
22 #include "datashare_helper.h"
23 #include "datashare_predicates.h"
24 #include "if_system_ability_manager.h"
25 #include "refbase.h"
26 #include "singleton.h"
27 #include "system_ability.h"
28 #include "system_ability_definition.h"
29 
30 namespace OHOS {
31 namespace Telephony {
32 constexpr const char *CALL_PHONE_NUMBER = "phone_number";
33 constexpr const char *CALL_DISPLAY_NAME = "display_name";
34 constexpr const char *CALL_DIRECTION = "call_direction";
35 constexpr const char *CALL_VOICEMAIL_URI = "voicemail_uri";
36 constexpr const char *CALL_SIM_TYPE = "sim_type";
37 constexpr const char *CALL_IS_HD = "is_hd";
38 constexpr const char *CALL_IS_READ = "is_read";
39 constexpr const char *CALL_RING_DURATION = "ring_duration";
40 constexpr const char *CALL_TALK_DURATION = "talk_duration";
41 constexpr const char *CALL_FORMAT_NUMBER = "format_number";
42 constexpr const char *CALL_QUICKSEARCH_KEY = "quicksearch_key";
43 constexpr const char *CALL_NUMBER_TYPE = "number_type";
44 constexpr const char *CALL_NUMBER_TYPE_NAME = "number_type_name";
45 constexpr const char *CALL_BEGIN_TIME = "begin_time";
46 constexpr const char *CALL_END_TIME = "end_time";
47 constexpr const char *CALL_ANSWER_STATE = "answer_state";
48 constexpr const char *CALL_CREATE_TIME = "create_time";
49 constexpr const char *CALL_NUMBER_LOCATION = "number_location";
50 constexpr const char *CALL_PHOTO_ID = "photo_id";
51 constexpr const char *CALL_DETAIL_INFO = "detail_info";
52 constexpr const char *CALL_CONTENT_TYPE = "content_type";
53 constexpr const char *CALL_PHONE = "phone";
54 constexpr const char *CALL_SLOT_ID = "slot_id";
55 constexpr const char *CALL_FEATURES = "features";
56 
57 enum class CallLogReadState {
58     CALL_IS_UNREAD,
59     CALL_IS_READ,
60 };
61 
62 class CallDataRdbObserver : public AAFwk::DataAbilityObserverStub {
63 public:
64     CallDataRdbObserver(std::vector<std::string> *phones);
65     ~CallDataRdbObserver();
66     void OnChange() override;
67 
68 private:
69     std::vector<std::string> *phones;
70 };
71 
72 class CallDataBaseHelper {
73     DECLARE_DELAYED_SINGLETON(CallDataBaseHelper)
74 public:
75     void RegisterObserver(std::vector<std::string> *phones);
76     void UnRegisterObserver();
77     bool Insert(DataShare::DataShareValuesBucket &values);
78     bool Query(std::vector<std::string> *phones, DataShare::DataSharePredicates &predicates);
79     bool Query(ContactInfo &contactInfo, DataShare::DataSharePredicates &predicates);
80     bool Update(DataShare::DataSharePredicates &predicates, DataShare::DataShareValuesBucket &values);
81     bool Delete(DataShare::DataSharePredicates &predicates);
82     bool QueryCallLog(
83         std::map<std::string, int32_t> &phonesAndUnreadCountMap, DataShare::DataSharePredicates &predicates);
84     int32_t QueryIsBlockPhoneNumber(const std::string &phoneNum, bool &result);
85 
86 public:
87     const int16_t CALL_LOG_DEFAULT_COUNT = 1;
88 
89 private:
90     sptr<CallDataRdbObserver> callDataRdbObserverPtr_;
91     std::shared_ptr<DataShare::DataShareHelper> CreateDataShareHelper(std::string uri);
92 };
93 } // namespace Telephony
94 } // namespace OHOS
95 #endif
96