1 /*
2 * Copyright (C) 2021-2022 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 #include "missed_call_notification.h"
17
18 #include "call_manager_errors.h"
19 #include "common_event.h"
20 #include "common_event_manager.h"
21 #include "common_event_support.h"
22 #include "notification_content.h"
23 #include "notification_helper.h"
24 #include "notification_normal_content.h"
25 #include "notification_request.h"
26 #include "telephony_log_wrapper.h"
27 #include "telephony_permission.h"
28 #include "want.h"
29 #include "os_account_manager.h"
30
31 namespace OHOS {
32 namespace Telephony {
33 using namespace OHOS::EventFwk;
MissedCallNotification()34 MissedCallNotification::MissedCallNotification() {}
35
NewCallCreated(sptr<CallBase> & callObjectPtr)36 void MissedCallNotification::NewCallCreated(sptr<CallBase> &callObjectPtr) {}
37
CallStateUpdated(sptr<CallBase> & callObjectPtr,TelCallState priorState,TelCallState nextState)38 void MissedCallNotification::CallStateUpdated(
39 sptr<CallBase> &callObjectPtr, TelCallState priorState, TelCallState nextState)
40 {
41 if (callObjectPtr != nullptr && callObjectPtr->GetCallType() == CallType::TYPE_VOIP) {
42 TELEPHONY_LOGI("Voip call should not save missed notification");
43 return;
44 }
45 if (callObjectPtr != nullptr && nextState == TelCallState::CALL_STATUS_DISCONNECTED &&
46 callObjectPtr->GetCallDirection() == CallDirection::CALL_DIRECTION_IN &&
47 callObjectPtr->GetAnswerType() == CallAnswerType::CALL_ANSWER_MISSED) {
48 int32_t userId = 0;
49 bool isUserUnlocked = false;
50 AccountSA::OsAccountManager::GetForegroundOsAccountLocalId(userId);
51 AccountSA::OsAccountManager::IsOsAccountVerified(userId, isUserUnlocked);
52 TELEPHONY_LOGI("isUserUnlocked: %{public}d", isUserUnlocked);
53 if (isUserUnlocked) {
54 PublishMissedCallEvent(callObjectPtr);
55 }
56 }
57 }
58
PublishMissedCallEvent(sptr<CallBase> & callObjectPtr)59 void MissedCallNotification::PublishMissedCallEvent(sptr<CallBase> &callObjectPtr)
60 {
61 AAFwk::Want want;
62 want.SetParam("callId", callObjectPtr->GetCallID());
63 want.SetParam("notificationId", INCOMING_CALL_MISSED_ID);
64 want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_INCOMING_CALL_MISSED);
65 EventFwk::CommonEventData data;
66 data.SetWant(want);
67 data.SetCode(INCOMING_CALL_MISSED_CODE);
68 EventFwk::CommonEventPublishInfo publishInfo;
69 publishInfo.SetOrdered(true);
70 bool result = EventFwk::CommonEventManager::PublishCommonEvent(data, publishInfo, nullptr);
71 TELEPHONY_LOGW("publish missed call event result : %{public}d", result);
72
73 AAFwk::Want wantWithNumber = want;
74 wantWithNumber.SetParam("phoneNumber", callObjectPtr->GetAccountNumber());
75 EventFwk::CommonEventData dataWithNumber;
76 dataWithNumber.SetWant(wantWithNumber);
77 dataWithNumber.SetCode(INCOMING_CALL_MISSED_CODE);
78 dataWithNumber.SetData(callObjectPtr->GetAccountNumber());
79 std::vector<std::string> callPermissions;
80 callPermissions.emplace_back(Permission::GET_TELEPHONY_STATE);
81 publishInfo.SetSubscriberPermissions(callPermissions);
82 bool resultWithNumber = EventFwk::CommonEventManager::PublishCommonEvent(dataWithNumber, publishInfo, nullptr);
83 TELEPHONY_LOGW("publish missed call event with number result : %{public}d", resultWithNumber);
84 }
85
PublishBlockedCallEvent(sptr<CallBase> & callObjectPtr)86 void MissedCallNotification::PublishBlockedCallEvent(sptr<CallBase> &callObjectPtr)
87 {
88 AAFwk::Want want;
89 want.SetParam("callId", callObjectPtr->GetCallID());
90 want.SetParam("notificationId", INCOMING_CALL_MISSED_ID);
91 want.SetParam("phoneNumber", callObjectPtr->GetAccountNumber());
92 want.SetParam("isBlocked", true);
93 std::string detectDetails = callObjectPtr->GetDetectDetails();
94 want.SetParam("detectDetails", detectDetails);
95 want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_INCOMING_CALL_MISSED);
96 EventFwk::CommonEventData data;
97 data.SetWant(want);
98 data.SetCode(INCOMING_CALL_MISSED_CODE);
99 EventFwk::CommonEventPublishInfo publishInfo;
100 publishInfo.SetOrdered(true);
101 std::vector<std::string> callPermissions;
102 callPermissions.emplace_back(Permission::GET_TELEPHONY_STATE);
103 publishInfo.SetSubscriberPermissions(callPermissions);
104 bool result = EventFwk::CommonEventManager::PublishCommonEvent(data, publishInfo, nullptr);
105 TELEPHONY_LOGW("publish blocked call event result: %{public}d, detectDetails length: %{public}zu",
106 result, detectDetails.length());
107 }
108
NotifyUnReadMissedCall(std::map<std::string,int32_t> & phoneNumAndUnreadCountMap)109 int32_t MissedCallNotification::NotifyUnReadMissedCall(std::map<std::string, int32_t> &phoneNumAndUnreadCountMap)
110 {
111 AAFwk::Want want;
112 want.SetParam("notificationId", INCOMING_CALL_MISSED_ID);
113 std::vector<std::string> phoneNumberList;
114 std::vector<int32_t> countList;
115 for (auto it = phoneNumAndUnreadCountMap.begin(); it != phoneNumAndUnreadCountMap.end(); it++) {
116 phoneNumberList.push_back(it->first);
117 countList.push_back(it->second);
118 }
119 want.SetParam("phoneNumberList", phoneNumberList);
120 want.SetParam("countList", countList);
121 want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_INCOMING_CALL_MISSED);
122 EventFwk::CommonEventData data;
123 data.SetWant(want);
124 EventFwk::CommonEventPublishInfo publishInfo;
125 std::vector<std::string> callPermissions;
126 callPermissions.emplace_back(Permission::GET_TELEPHONY_STATE);
127 publishInfo.SetSubscriberPermissions(callPermissions);
128 bool resultWithNumber = EventFwk::CommonEventManager::PublishCommonEvent(data, publishInfo, nullptr);
129 TELEPHONY_LOGI("publish unread missed call event with number result : %{public}d", resultWithNumber);
130 if (!resultWithNumber) {
131 TELEPHONY_LOGE("publish unread missed call event with number error");
132 return TELEPHONY_ERR_PUBLISH_BROADCAST_FAIL;
133 }
134 return TELEPHONY_ERR_SUCCESS;
135 }
136
IncomingCallActivated(sptr<CallBase> & callObjectPtr)137 void MissedCallNotification::IncomingCallActivated(sptr<CallBase> &callObjectPtr) {}
138
IncomingCallHungUp(sptr<CallBase> & callObjectPtr,bool isSendSms,std::string content)139 void MissedCallNotification::IncomingCallHungUp(sptr<CallBase> &callObjectPtr,
140 bool isSendSms, std::string content) {}
141
CallDestroyed(const DisconnectedDetails & details)142 void MissedCallNotification::CallDestroyed(const DisconnectedDetails &details) {}
143 } // namespace Telephony
144 } // namespace OHOS
145