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 "call_ability_report_proxy.h"
17 #include "call_superprivacy_control_manager.h"
18 #include "call_number_utils.h"
19 #include "call_control_manager.h"
20 #include "syspara/parameters.h"
21 #include "super_privacy_manager_client.h"
22 #include "display_manager.h"
23 #include "display_info.h"
24
25 namespace OHOS {
26 namespace Telephony {
27 const std::string SUPER_PRIVACY_MODE_PARAM_KEY = "persist.super_privacy.mode";
28 const char SUPER_PRIVACY_MODE_PARAM_KEYS[] = "persist.super_privacy.mode";
29 const char SUPER_PRIVACY_MODE_PARAM_OPEN[] = "2";
30 const char SUPER_PRIVACY_MODE_PARAM_CLOSE[] = "0";
31 const int32_t SOURCE_CALL = 2;
32
RegisterSuperPrivacyMode()33 void CallSuperPrivacyControlManager::RegisterSuperPrivacyMode()
34 {
35 int32_t ret = WatchParameter(SUPER_PRIVACY_MODE_PARAM_KEYS, ParamChangeCallback, nullptr);
36 TELEPHONY_LOGE("RegisterSuperPrivacyMode ret:%{public}d", ret);
37 }
38
ParamChangeCallback(const char *key, const char *value, void *context)39 void CallSuperPrivacyControlManager::ParamChangeCallback(const char *key, const char *value, void *context)
40 {
41 SuperPrivacyModeChangeEvent();
42 if (key == nullptr ||value == nullptr) {
43 return;
44 }
45 if (strcmp(key, SUPER_PRIVACY_MODE_PARAM_KEYS)) {
46 return;
47 }
48 std::string keyStr(key);
49 std::string valueStr(value);
50 TELEPHONY_LOGE("ParamChangeCallback keyStr:%{public}s", keyStr.c_str());
51 TELEPHONY_LOGE("ParamChangeCallback valueStr:%{public}s", valueStr.c_str());
52 bool isSuperPrivacyModeOpen = strcmp(value, SUPER_PRIVACY_MODE_PARAM_OPEN) == 0 ? true : false;
53 bool isSuperPrivacyModeClose = strcmp(value, SUPER_PRIVACY_MODE_PARAM_CLOSE) == 0 ? true : false;
54 if (isSuperPrivacyModeOpen) {
55 DelayedSingleton<CallSuperPrivacyControlManager>::GetInstance()->SetIsChangeSuperPrivacyMode(false);
56 DelayedSingleton<CallSuperPrivacyControlManager>::GetInstance()->CloseAllCall();
57 } else if (isSuperPrivacyModeClose) {
58 bool isChangeSuperPrivacyMode = DelayedSingleton<CallSuperPrivacyControlManager>::GetInstance()->
59 GetIsChangeSuperPrivacyMode();
60 if (!isChangeSuperPrivacyMode) {
61 DelayedSingleton<CallSuperPrivacyControlManager>::GetInstance()->SetIsChangeSuperPrivacyMode(false);
62 }
63 }
64 }
65
SuperPrivacyModeChangeEvent()66 void CallSuperPrivacyControlManager::SuperPrivacyModeChangeEvent()
67 {
68 CallEventInfo eventInfo;
69 (void)memset_s(&eventInfo, sizeof(CallEventInfo), 0, sizeof(CallEventInfo));
70 bool isSuperPrivacyMode = DelayedSingleton<CallSuperPrivacyControlManager>::GetInstance()->
71 GetCurrentIsSuperPrivacyMode();
72 TELEPHONY_LOGI("SuperPrivacyMode:%{public}d", isSuperPrivacyMode);
73 if (isSuperPrivacyMode) {
74 eventInfo.eventId = CallAbilityEventId::EVENT_IS_SUPER_PRIVACY_MODE_ON;
75 } else {
76 eventInfo.eventId = CallAbilityEventId::EVENT_IS_SUPER_PRIVACY_MODE_OFF;
77 }
78 DelayedSingleton<CallAbilityReportProxy>::GetInstance()->CallEventUpdated(eventInfo);
79 }
80
CloseAllCall()81 void CallSuperPrivacyControlManager::CloseAllCall()
82 {
83 std::vector<CallAttributeInfo> infos = CallObjectManager::GetAllCallInfoList();
84 for (auto &info : infos) {
85 if (!info.isEcc && !info.isEccContact) {
86 TELEPHONY_LOGE("OnSuperPrivacyModeChanged callState:%{public}d", info.callState);
87 if (info.callState == TelCallState::CALL_STATUS_INCOMING ||
88 info.callState == TelCallState::CALL_STATUS_WAITING) {
89 DelayedSingleton<CallControlManager>::GetInstance()->RejectCall(info.callId, false,
90 u"superPrivacyModeOn");
91 } else {
92 DelayedSingleton<CallControlManager>::GetInstance()->HangUpCall(info.callId);
93 }
94 }
95 }
96 }
97
GetIsChangeSuperPrivacyMode()98 bool CallSuperPrivacyControlManager::GetIsChangeSuperPrivacyMode()
99 {
100 return isChangeSuperPrivacyMode;
101 }
102
SetIsChangeSuperPrivacyMode(bool isChangeSuperPrivacy)103 void CallSuperPrivacyControlManager::SetIsChangeSuperPrivacyMode(bool isChangeSuperPrivacy)
104 {
105 isChangeSuperPrivacyMode = isChangeSuperPrivacy;
106 }
107
SetOldSuperPrivacyMode()108 void CallSuperPrivacyControlManager::SetOldSuperPrivacyMode()
109 {
110 int32_t privpacyMode = system::GetIntParameter(SUPER_PRIVACY_MODE_PARAM_KEY.c_str(), -1);
111 TELEPHONY_LOGE("SetOldSuperPrivacyMode privpacyMode:%{public}d", privpacyMode);
112 oldSuperPrivacyMode = privpacyMode;
113 }
114
GetOldSuperPrivacyMode()115 int32_t CallSuperPrivacyControlManager::GetOldSuperPrivacyMode()
116 {
117 return oldSuperPrivacyMode;
118 }
119
CloseSuperPrivacyMode()120 int32_t CallSuperPrivacyControlManager::CloseSuperPrivacyMode()
121 {
122 int32_t privacy = SuperPrivacyManagerClient::GetInstance().
123 SetSuperPrivacyMode(static_cast<int32_t>(CallSuperPrivacyModeType::OFF), SOURCE_CALL);
124 TELEPHONY_LOGE("CloseSuperPrivacyMode privacy:%{public}d", privacy);
125 return privacy;
126 }
127
CloseCallSuperPrivacyMode(std::u16string &phoneNumber, int32_t &accountId, int32_t &videoState, int32_t &dialType, int32_t &dialScene, int32_t &callType)128 void CallSuperPrivacyControlManager::CloseCallSuperPrivacyMode(std::u16string &phoneNumber, int32_t &accountId,
129 int32_t &videoState, int32_t &dialType, int32_t &dialScene, int32_t &callType)
130 {
131 int32_t privacy = CloseSuperPrivacyMode();
132 TELEPHONY_LOGE("CloseCallSuperPrivacyMode privacy:%{public}d", privacy);
133 if (privacy == SUPER_PRIVACY_MODE_REQUEST_SUCCESS) {
134 AppExecFwk::PacMap dialInfo;
135 dialInfo.PutIntValue("accountId", accountId);
136 dialInfo.PutIntValue("videoState", videoState);
137 dialInfo.PutIntValue("dialType", dialType);
138 dialInfo.PutIntValue("dialScene", dialScene);
139 dialInfo.PutIntValue("callType", callType);
140 int32_t ret = DelayedSingleton<CallControlManager>::GetInstance()->DialCall(phoneNumber, dialInfo);
141 if (ret != TELEPHONY_SUCCESS) {
142 RestoreSuperPrivacyMode();
143 }
144 }
145 }
146
CloseAnswerSuperPrivacyMode(int32_t callId, int32_t videoState)147 void CallSuperPrivacyControlManager::CloseAnswerSuperPrivacyMode(int32_t callId, int32_t videoState)
148 {
149 int32_t privacy = CloseSuperPrivacyMode();
150 TELEPHONY_LOGE("CloseAnswerSuperPrivacyMode privacy:%{public}d", privacy);
151 if (privacy == SUPER_PRIVACY_MODE_REQUEST_SUCCESS) {
152 DelayedSingleton<CallControlManager>::GetInstance()->AnswerCall(callId, videoState);
153 SuperPrivacyModeChangeEvent();
154 }
155 }
156
RestoreSuperPrivacyMode()157 void CallSuperPrivacyControlManager::RestoreSuperPrivacyMode()
158 {
159 if (!GetIsChangeSuperPrivacyMode()) {
160 return;
161 }
162 int32_t privpacyMode = system::GetIntParameter(SUPER_PRIVACY_MODE_PARAM_KEY.c_str(), -1);
163 int32_t oldPrivpacy = GetOldSuperPrivacyMode();
164 TELEPHONY_LOGE("RestoreSuperPrivacyMode oldPrivpacy:%{public}d", oldPrivpacy);
165 if (privpacyMode != oldPrivpacy) {
166 SetIsChangeSuperPrivacyMode(false);
167 if (oldPrivpacy == static_cast<int32_t>(CallSuperPrivacyModeType::ALWAYS_ON)
168 || oldPrivpacy == static_cast<int32_t>(CallSuperPrivacyModeType::ON_WHEN_FOLDED)) {
169 int32_t privacy = SuperPrivacyManagerClient::GetInstance().SetSuperPrivacyMode(oldPrivpacy, SOURCE_CALL);
170 TELEPHONY_LOGE("RestoreSuperPrivacyMode ret privacy:%{public}d", privacy);
171 }
172 }
173 }
174
GetCurrentIsSuperPrivacyMode()175 bool CallSuperPrivacyControlManager::GetCurrentIsSuperPrivacyMode()
176 {
177 int32_t privpacyMode = system::GetIntParameter(SUPER_PRIVACY_MODE_PARAM_KEY.c_str(), -1);
178 TELEPHONY_LOGE("GetCurrentIsSuperPrivacyMode privpacyMode:%{public}d", privpacyMode);
179 if (privpacyMode == static_cast<int32_t>(CallSuperPrivacyModeType::ALWAYS_ON)) {
180 return true;
181 }
182 Rosen::FoldStatus foldStatus = Rosen::DisplayManager::GetInstance().GetFoldStatus();
183 if (privpacyMode == static_cast<int32_t>(CallSuperPrivacyModeType::ON_WHEN_FOLDED)
184 && foldStatus == Rosen::FoldStatus::FOLDED) {
185 TELEPHONY_LOGI("GetCurrentIsSuperPrivacyMode ON_WHEN_FOLDED");
186 return true;
187 }
188 return false;
189 }
190 } // namespace Telephony
191 } // namespace OHOS