• 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 "if_system_ability_manager.h"
21 
22 #include "refbase.h"
23 #include "singleton.h"
24 
25 #include "system_ability.h"
26 #include "system_ability_definition.h"
27 
28 #include "data_ability_helper.h"
29 #include "data_ability_predicates.h"
30 #include "values_bucket.h"
31 #include "abs_shared_result_set.h"
32 #include "data_ability_observer_stub.h"
33 
34 namespace OHOS {
35 namespace Telephony {
36 const std::string CALL_PHONE_NUMBER = "phone_number";
37 const std::string CALL_DISPLAY_NAME = "display_name";
38 const std::string CALL_DIRECTION = "call_direction";
39 const std::string CALL_VOICEMAIL_URI = "voicemail_uri";
40 const std::string CALL_SIM_TYPE = "sim_type";
41 const std::string CALL_IS_HD = "is_hd";
42 const std::string CALL_IS_READ = "is_read";
43 const std::string CALL_RING_DURATION = "ring_duration";
44 const std::string CALL_TALK_DURATION = "talk_duration";
45 const std::string CALL_FORMAT_NUMBER = "format_number";
46 const std::string CALL_QUICKSEARCH_KEY = "quicksearch_key";
47 const std::string CALL_NUMBER_TYPE = "number_type";
48 const std::string CALL_NUMBER_TYPE_NAME = "number_type_name";
49 const std::string CALL_BEGIN_TIME = "begin_time";
50 const std::string CALL_END_TIME = "end_time";
51 const std::string CALL_ANSWER_STATE = "answer_state";
52 const std::string CALL_CREATE_TIME = "create_time";
53 const std::string CALL_NUMBER_LOCATION = "number_location";
54 const std::string CALL_PHOTO_ID = "photo_id";
55 
56 class CallDataRdbObserver : public AAFwk::DataAbilityObserverStub {
57 public:
58     CallDataRdbObserver(std::vector<std::string> *phones);
59     ~CallDataRdbObserver();
60     void OnChange() override;
61 
62 private:
63     std::vector<std::string> *phones;
64 };
65 
66 class CallDataBaseHelper {
67     DECLARE_DELAYED_SINGLETON(CallDataBaseHelper)
68 public:
69     void RegisterObserver(std::vector<std::string> *phones);
70     void UnRegisterObserver();
71     bool Insert(NativeRdb::ValuesBucket &values);
72     bool Query(std::vector<std::string> *phones, NativeRdb::DataAbilityPredicates &predicates);
73     bool Delete(NativeRdb::DataAbilityPredicates &predicates);
74 
75 private:
76     sptr<CallDataRdbObserver> callDataRdbObserverPtr_;
77     std::shared_ptr<AppExecFwk::DataAbilityHelper> CreateDataAHelper();
78     void ResultSetConvertToIndexer(const std::shared_ptr<NativeRdb::AbsSharedResultSet> &resultSet);
79     const std::string CALL_SUBSECTION = "dataability:///com.ohos.calllogability/calls/calllog";
80     const std::string CALL_BLOCK = "dataability:///com.ohos.contactsdataability/contacts/contact_blocklist";
81 };
82 } // namespace Telephony
83 } // namespace OHOS
84 #endif