• 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_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 AccountSystemAbilityListener : public SystemAbilityStatusChangeStub {
44 public:
45     AccountSystemAbilityListener() = default;
46     ~AccountSystemAbilityListener() = default;
47     void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
48     void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
49 
50 private:
51     std::shared_ptr<UserSwitchEventSubscriber> userSwitchSubscriber_ = nullptr;
52 };
53 
54 /**
55  * @class CallRecordsManager
56  * Responsible for recording calls. Logging operations will be performed in a background thread
57  * to avoid blocking the main thread.
58  */
59 class CallRecordsManager : public CallStateListenerBase {
60     DECLARE_DELAYED_SINGLETON(CallRecordsManager)
61 public:
62     void Init();
63     void CallStateUpdated(sptr<CallBase> &callObjectPtr, TelCallState priorState, TelCallState nextState) override;
64     void AddOneCallRecord(CallAttributeInfo &info);
65     void CopyCallInfoToRecord(CallAttributeInfo &info, CallRecordInfo &data);
66     void AddOneCallRecord(sptr<CallBase> call, CallAnswerType answerType);
67     int32_t RemoveMissedIncomingCallNotification();
68     int32_t GetCallFeatures(int32_t videoState);
69     bool IsVideoCall(int32_t videoState);
70 
71 private:
72     std::shared_ptr<CallRecordsHandlerService> callRecordsHandlerServerPtr_;
73     std::mutex mutex_;
74     sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr;
75 };
76 } // namespace Telephony
77 } // namespace OHOS
78 #endif // TELEPHONY_CALL_RECORDS_MANAGER_H