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