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