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_MANAGER_H 17 #define TELEPHONY_CALL_RECORDS_MANAGER_H 18 19 #include <mutex> 20 #include <set> 21 22 #include "call_records_handler.h" 23 #include "call_state_listener_base.h" 24 #include "common_event_subscriber.h" 25 #include "iservice_registry.h" 26 #include "singleton.h" 27 #include "system_ability_definition.h" 28 #include "system_ability_status_change_stub.h" 29 30 namespace OHOS { 31 namespace Telephony { 32 using namespace OHOS::EventFwk; 33 using CommonEventSubscribeInfo = OHOS::EventFwk::CommonEventSubscribeInfo; 34 using CommonEventSubscriber = OHOS::EventFwk::CommonEventSubscriber; 35 36 class UserSwitchEventSubscriber : public CommonEventSubscriber { 37 public: UserSwitchEventSubscriber(const CommonEventSubscribeInfo & info)38 explicit UserSwitchEventSubscriber(const CommonEventSubscribeInfo &info) : CommonEventSubscriber(info) {} 39 ~UserSwitchEventSubscriber() = default; 40 void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &data) override; 41 }; 42 43 class DataShareReadyEventSubscriber : public CommonEventSubscriber { 44 public: DataShareReadyEventSubscriber(const CommonEventSubscribeInfo & info)45 explicit DataShareReadyEventSubscriber(const CommonEventSubscribeInfo &info) : CommonEventSubscriber(info) {} 46 ~DataShareReadyEventSubscriber() = default; 47 void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &data) override; 48 }; 49 50 class AccountSystemAbilityListener : public SystemAbilityStatusChangeStub { 51 public: 52 AccountSystemAbilityListener() = default; 53 ~AccountSystemAbilityListener() = default; 54 void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 55 void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 56 57 private: 58 std::shared_ptr<UserSwitchEventSubscriber> userSwitchSubscriber_ = nullptr; 59 }; 60 61 /** 62 * @class CallRecordsManager 63 * Responsible for recording calls. Logging operations will be performed in a background thread 64 * to avoid blocking the main thread. 65 */ 66 class CallRecordsManager : public CallStateListenerBase { 67 DECLARE_DELAYED_SINGLETON(CallRecordsManager) 68 public: 69 void Init(); 70 void CallStateUpdated(sptr<CallBase> &callObjectPtr, TelCallState priorState, TelCallState nextState) override; 71 void AddOneCallRecord(CallAttributeInfo &info); 72 void CopyCallInfoToRecord(CallAttributeInfo &info, CallRecordInfo &data); 73 void AddOneCallRecord(sptr<CallBase> call, CallAnswerType answerType); 74 int32_t RemoveMissedIncomingCallNotification(); 75 int32_t GetCallFeatures(int32_t videoState); 76 bool IsVideoCall(int32_t videoState); 77 void SetDataShareReady(bool isDataShareReady); 78 void SetSystemAbilityAdd(bool isSystemAbilityAdd); 79 void QueryUnReadMissedCallLog(int32_t userId); 80 81 private: 82 std::string GetCountryIso(); 83 int32_t CopyFormatNumberToRecord(std::string &countryIso, CallRecordInfo &data); 84 int32_t CopyFormatNumberToE164ToRecord(std::string &countryIso, CallRecordInfo &data); 85 void RegisterDataShareReadySubscriber(); 86 std::shared_ptr<CallRecordsHandlerService> callRecordsHandlerServerPtr_; 87 std::mutex mutex_; 88 sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr; 89 std::shared_ptr<DataShareReadyEventSubscriber> dataShareReadySubscriber_ = nullptr; 90 bool isDataShareReady_ = false; 91 bool isSystemAbilityAdd_ = false; 92 bool isUnReadMissedCallLogQuery_ = false; 93 }; 94 } // namespace Telephony 95 } // namespace OHOS 96 #endif // TELEPHONY_CALL_RECORDS_MANAGER_H