1 /*
2 * Copyright (c) 2025 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 "multiple_user_connector.h"
17 #include "os_account_manager.h"
18
19 #include "dm_constants.h"
20 #include "dm_error_type.h"
21 #include "dm_auth_manager_base.h"
22 #include "power_mgr_client.h"
23 #if defined(SUPPORT_SCREENLOCK)
24 #include "screenlock_manager.h"
25 #endif
26
27 #ifdef OS_ACCOUNT_PART_EXISTS
28 #include "os_account_manager.h"
29 using namespace OHOS::AccountSA;
30 #endif // OS_ACCOUNT_PART_EXISTS
31
32 namespace OHOS {
33 namespace DistributedHardware {
34 const char* TAG_DMVERSION = "dmVersion";
35 const char* TAG_DM_VERSION_V2 = "dmVersionV2";
36 const char* TAG_EDITION = "edition";
37 const char* TAG_DATA = "data";
38 const char* TAG_DATA_LEN = "dataLen";
39 const char* TAG_BUNDLE_NAME = "bundleName";
40 const char* TAG_BUNDLE_NAME_V2 = "bundleNameV2";
41 const char* TAG_PEER_BUNDLE_NAME = "PEER_BUNDLE_NAME";
42 const char* TAG_PEER_BUNDLE_NAME_V2 = "PEER_BUNDLE_NAME_V2";
43 const char* TAG_PEER_PKG_NAME = "PEER_PKG_NAME";
44 const char* TAG_BIND_LEVEL = "bindLevel";
45 const char* TAG_REPLY = "REPLY";
46 const char* TAG_APP_THUMBNAIL2 = "appThumbnail"; // Naming Add 2 to resolve conflicts with TAG_APP_THUMBNAIL
47 const char* TAG_AUTH_FINISH = "isFinish";
48 const char* TAG_LOCAL_USERID = "localUserId";
49 const char* TAG_LOCAL_DEVICE_ID = "LOCALDEVICEID";
50 const char* TAG_IDENTICAL_ACCOUNT = "IDENTICALACCOUNT";
51 const char* TAG_ACCOUNT_GROUPID = "ACCOUNTGROUPID";
52 const char* TAG_HAVE_CREDENTIAL = "haveCredential";
53 const char* TAG_ISONLINE = "isOnline";
54 const char* TAG_AUTHED = "authed";
55 const char* TAG_LOCAL_ACCOUNTID = "localAccountId";
56 const char* TAG_TOKENID = "tokenId";
57 const char* TAG_HOST_PKGLABEL = "hostPkgLabel";
58 const char* TAG_REMOTE_DEVICE_NAME = "REMOTE_DEVICE_NAME";
59 const char* TAG_HOST = "HOST";
60 const char* TAG_PROXY_CONTEXT_ID = "proxyContextId";
61
62 const char* APP_OPERATION_KEY = "appOperation";
63 const char* TARGET_PKG_NAME_KEY = "targetPkgName";
64 const char* CUSTOM_DESCRIPTION_KEY = "customDescription";
65 const char* CANCEL_DISPLAY_KEY = "cancelPinCodeDisplay";
66 const char* BUNDLE_NAME_KEY = "bundleName";
67
68 const char* AUTHENTICATE_TIMEOUT_TASK = "deviceManagerTimer:authenticate";
69 const char* NEGOTIATE_TIMEOUT_TASK = "deviceManagerTimer:negotiate";
70 const char* CONFIRM_TIMEOUT_TASK = "deviceManagerTimer:confirm";
71 const char* INPUT_TIMEOUT_TASK = "deviceManagerTimer:input";
72 const char* SESSION_HEARTBEAT_TIMEOUT_TASK = "deviceManagerTimer:sessionHeartbeat";
73 const char* WAIT_REQUEST_TIMEOUT_TASK = "deviceManagerTimer:waitRequest";
74 const char* AUTH_DEVICE_TIMEOUT_TASK = "deviceManagerTimer:authDevice_";
75 const char* WAIT_PIN_AUTH_TIMEOUT_TASK = "deviceManagerTimer:waitPinAuth";
76 const char* WAIT_NEGOTIATE_TIMEOUT_TASK = "deviceManagerTimer:waitNegotiate";
77 const char* GET_ULTRASONIC_PIN_TIMEOUT_TASK = "deviceManagerTimer:getUltrasonicPin";
78 const char* ADD_TIMEOUT_TASK = "deviceManagerTimer:add";
79 const char* WAIT_SESSION_CLOSE_TIMEOUT_TASK = "deviceManagerTimer:waitSessionClose";
80 const char* CLOSE_SESSION_TASK_SEPARATOR = "#";
81 const char* TAG_DM_CERT_CHAIN = "dmCertChain";
82 const char* TAG_CERT_COUNT = "certCount";
83 const char* TAG_CERT = "cert";
84 const char* TAG_IS_COMMON_FLAG = "isCommonFlag";
85 const char* TAG_CERT_RANDOM = "certRandom";
86
87 const int32_t AUTHENTICATE_TIMEOUT = 120;
88 const int32_t CONFIRM_TIMEOUT = 60;
89 const int32_t NEGOTIATE_TIMEOUT = 10;
90 const int32_t INPUT_TIMEOUT = 60;
91 const int32_t ADD_TIMEOUT = 10;
92 const int32_t WAIT_NEGOTIATE_TIMEOUT = 10;
93 const int32_t WAIT_REQUEST_TIMEOUT = 10;
94 const int32_t CLONE_AUTHENTICATE_TIMEOUT = 20;
95 const int32_t CLONE_CONFIRM_TIMEOUT = 10;
96 const int32_t CLONE_NEGOTIATE_TIMEOUT = 10;
97 const int32_t CLONE_ADD_TIMEOUT = 10;
98 const int32_t CLONE_WAIT_NEGOTIATE_TIMEOUT = 10;
99 const int32_t CLONE_WAIT_REQUEST_TIMEOUT = 10;
100 const int32_t CLONE_SESSION_HEARTBEAT_TIMEOUT = 20;
101 const int32_t CLONE_PIN_AUTH_TIMEOUT = 10;
102 const int32_t HML_SESSION_TIMEOUT = 10;
103 const int32_t SESSION_HEARTBEAT_TIMEOUT = 50;
104 const int32_t PIN_AUTH_TIMEOUT = 60;
105 const int32_t EVENT_TIMEOUT = 5000; // 5000 ms
106
107 constexpr int32_t OPEN_PROCESS_NAME_WHITE_LIST_NUM = 1;
108 constexpr int32_t CLOSE_PROCESS_NAME_WHITE_LIST_NUM = 4;
109 constexpr const static char* OPEN_PROCESS_NAME_WHITE_LIST[OPEN_PROCESS_NAME_WHITE_LIST_NUM] = {
110 "com.example.myapplication"
111 };
112 constexpr const static char* CLOSE_PROCESS_NAME_WHITE_LIST[CLOSE_PROCESS_NAME_WHITE_LIST_NUM] = {
113 "CollaborationFwk",
114 "gameservice_server",
115 "wear_link_service",
116 "watch_system_service"
117 };
118
119 constexpr const static char* PROCESS_NAME_PROXY_ADAPTATION_LIST[] = {
120 "gameservice_server"
121 };
122 constexpr uint32_t PROCESS_NAME_PROXY_ADAPTATION_LIST_NUM = std::size(PROCESS_NAME_PROXY_ADAPTATION_LIST);
123
AuthenticateDevice(const std::string & pkgName,int32_t authType,const std::string & deviceId,const std::string & extra)124 int32_t AuthManagerBase::AuthenticateDevice(const std::string &pkgName, int32_t authType,
125 const std::string &deviceId, const std::string &extra)
126 {
127 LOGE("AuthenticateDevice is not implemented in the current version");
128 return ERR_DM_FAILED;
129 }
130
UnAuthenticateDevice(const std::string & pkgName,const std::string & udid,int32_t bindLevel)131 int32_t AuthManagerBase::UnAuthenticateDevice(const std::string &pkgName, const std::string &udid, int32_t bindLevel)
132 {
133 LOGE("UnAuthenticateDevice is not implemented in the current version");
134 return ERR_DM_FAILED;
135 }
136
UnBindDevice(const std::string & pkgName,const std::string & udid,int32_t bindLevel,const std::string & extra)137 int32_t AuthManagerBase::UnBindDevice(const std::string &pkgName, const std::string &udid,
138 int32_t bindLevel, const std::string &extra)
139 {
140 LOGE("UnBindDevice is not implemented in the current version");
141 return ERR_DM_FAILED;
142 }
143
OnSessionOpened(int32_t sessionId,int32_t sessionSide,int32_t result)144 void AuthManagerBase::OnSessionOpened(int32_t sessionId, int32_t sessionSide, int32_t result)
145 {
146 LOGE("OnSessionOpened is not implemented in the current version");
147 }
148
OnSessionClosed(const int32_t sessionId)149 void AuthManagerBase::OnSessionClosed(const int32_t sessionId)
150 {
151 LOGE("OnSessionClosed is not implemented in the current version");
152 }
153
OnSessionDisable()154 void AuthManagerBase::OnSessionDisable()
155 {
156 LOGE("OnSessionDisable is not implemented in the current version");
157 }
158
OnDataReceived(const int32_t sessionId,const std::string message)159 void AuthManagerBase::OnDataReceived(const int32_t sessionId, const std::string message)
160 {
161 LOGE("OnDataReceived is not implemented in the current version");
162 }
163
OnSoftbusJoinLNNResult(const int32_t sessionId,const char * networkId,int32_t result)164 void AuthManagerBase::OnSoftbusJoinLNNResult(const int32_t sessionId, const char *networkId, int32_t result)
165 {
166 LOGE("OnSoftbusJoinLNNResult is not implemented in the current version");
167 }
168
OnGroupCreated(int64_t requestId,const std::string & groupId)169 void AuthManagerBase::OnGroupCreated(int64_t requestId, const std::string &groupId)
170 {
171 LOGE("OnGroupCreated is not implemented in the current version");
172 }
173
OnMemberJoin(int64_t requestId,int32_t status,int32_t operationCode)174 void AuthManagerBase::OnMemberJoin(int64_t requestId, int32_t status, int32_t operationCode)
175 {
176 LOGE("OnMemberJoin is not implemented in the current version");
177 }
178
EstablishAuthChannel(const std::string & deviceId)179 int32_t AuthManagerBase::EstablishAuthChannel(const std::string &deviceId)
180 {
181 LOGE("EstablishAuthChannel is not implemented in the current version");
182 return ERR_DM_FAILED;
183 }
184
StartNegotiate(const int32_t & sessionId)185 void AuthManagerBase::StartNegotiate(const int32_t &sessionId)
186 {
187 LOGE("StartNegotiate is not implemented in the current version");
188 }
189
RespNegotiate(const int32_t & sessionId)190 void AuthManagerBase::RespNegotiate(const int32_t &sessionId)
191 {
192 LOGE("RespNegotiate is not implemented in the current version");
193 }
194
SendAuthRequest(const int32_t & sessionId)195 void AuthManagerBase::SendAuthRequest(const int32_t &sessionId)
196 {
197 LOGE("SendAuthRequest is not implemented in the current version");
198 }
199
StartAuthProcess(const int32_t & action)200 int32_t AuthManagerBase::StartAuthProcess(const int32_t &action)
201 {
202 LOGE("StartAuthProcess is not implemented in the current version");
203 return ERR_DM_FAILED;
204 }
205
StartRespAuthProcess()206 void AuthManagerBase::StartRespAuthProcess()
207 {
208 LOGE("StartRespAuthProcess is not implemented in the current version");
209 }
210
CreateGroup()211 int32_t AuthManagerBase::CreateGroup()
212 {
213 LOGE("CreateGroup is not implemented in the current version");
214 return ERR_DM_FAILED;
215 }
216
ProcessPincode(const std::string & pinCode)217 int32_t AuthManagerBase::ProcessPincode(const std::string &pinCode)
218 {
219 LOGE("ProcessPincode is not implemented in the current version");
220 return ERR_DM_FAILED;
221 }
222
GetConnectAddr(std::string deviceId)223 std::string AuthManagerBase::GetConnectAddr(std::string deviceId)
224 {
225 LOGE("GetConnectAddr is not implemented in the current version");
226 return "";
227 }
228
JoinNetwork()229 int32_t AuthManagerBase::JoinNetwork()
230 {
231 LOGE("JoinNetwork is not implemented in the current version");
232 return ERR_DM_FAILED;
233 }
234
AuthenticateFinish()235 void AuthManagerBase::AuthenticateFinish()
236 {
237 LOGE("AuthenticateFinish is not implemented in the current version");
238 }
239
GetIsCryptoSupport()240 bool AuthManagerBase::GetIsCryptoSupport()
241 {
242 LOGE("GetIsCryptoSupport is not implemented in the current version");
243 return false;
244 }
245
SetAuthRequestState(std::shared_ptr<AuthRequestState> authRequestState)246 int32_t AuthManagerBase::SetAuthRequestState(std::shared_ptr<AuthRequestState> authRequestState)
247 {
248 LOGE("SetAuthRequestState is not implemented in the current version");
249 return ERR_DM_FAILED;
250 }
251
SetAuthResponseState(std::shared_ptr<AuthResponseState> authResponseState)252 int32_t AuthManagerBase::SetAuthResponseState(std::shared_ptr<AuthResponseState> authResponseState)
253 {
254 LOGE("SetAuthResponseState is not implemented in the current version");
255 return ERR_DM_FAILED;
256 }
257
GetPinCode(std::string & code)258 int32_t AuthManagerBase::GetPinCode(std::string &code)
259 {
260 LOGE("GetPinCode is not implemented in the current version");
261 return ERR_DM_FAILED;
262 }
263
GenerateGroupName()264 std::string AuthManagerBase::GenerateGroupName()
265 {
266 LOGE("GenerateGroupName is not implemented in the current version");
267 return "";
268 }
269
HandleAuthenticateTimeout(std::string name)270 void AuthManagerBase::HandleAuthenticateTimeout(std::string name)
271 {
272 LOGE("HandleAuthenticateTimeout is not implemented in the current version");
273 }
274
GeneratePincode()275 std::string AuthManagerBase::GeneratePincode()
276 {
277 LOGE("GeneratePincode is not implemented in the current version");
278 return "";
279 }
280
ShowConfigDialog()281 void AuthManagerBase::ShowConfigDialog()
282 {
283 LOGE("ShowConfigDialog is not implemented in the current version");
284 }
285
ShowAuthInfoDialog(bool authDeviceError)286 void AuthManagerBase::ShowAuthInfoDialog(bool authDeviceError)
287 {
288 LOGE("ShowAuthInfoDialog is not implemented in the current version");
289 }
290
ShowStartAuthDialog()291 void AuthManagerBase::ShowStartAuthDialog()
292 {
293 LOGE("ShowStartAuthDialog is not implemented in the current version");
294 }
295
OnUserOperation(int32_t action,const std::string & params)296 int32_t AuthManagerBase::OnUserOperation(int32_t action, const std::string ¶ms)
297 {
298 LOGE("OnUserOperation is not implemented in the current version");
299 return ERR_DM_FAILED;
300 }
301
SetPageId(int32_t pageId)302 int32_t AuthManagerBase::SetPageId(int32_t pageId)
303 {
304 LOGE("SetPageId is not implemented in the current version");
305 return ERR_DM_FAILED;
306 }
307
SetReasonAndFinish(int32_t reason,int32_t state)308 int32_t AuthManagerBase::SetReasonAndFinish(int32_t reason, int32_t state)
309 {
310 LOGE("SetReasonAndFinish is not implemented in the current version");
311 return ERR_DM_FAILED;
312 }
313
IsIdenticalAccount()314 bool AuthManagerBase::IsIdenticalAccount()
315 {
316 LOGE("IsIdenticalAccount is not implemented in the current version");
317 return false;
318 }
319
RegisterUiStateCallback(const std::string pkgName)320 int32_t AuthManagerBase::RegisterUiStateCallback(const std::string pkgName)
321 {
322 LOGE("RegisterUiStateCallback is not implemented in the current version");
323 return ERR_DM_FAILED;
324 }
325
UnRegisterUiStateCallback(const std::string pkgName)326 int32_t AuthManagerBase::UnRegisterUiStateCallback(const std::string pkgName)
327 {
328 LOGE("UnRegisterUiStateCallback is not implemented in the current version");
329 return ERR_DM_FAILED;
330 }
331
ImportAuthCode(const std::string & pkgName,const std::string & authCode)332 int32_t AuthManagerBase::ImportAuthCode(const std::string &pkgName, const std::string &authCode)
333 {
334 LOGE("ImportAuthCode is not implemented in the current version");
335 return ERR_DM_FAILED;
336 }
337
BindTarget(const std::string & pkgName,const PeerTargetId & targetId,const std::map<std::string,std::string> & bindParam,int sessionId,uint64_t logicalSessionId)338 int32_t AuthManagerBase::BindTarget(const std::string &pkgName, const PeerTargetId &targetId,
339 const std::map<std::string, std::string> &bindParam, int sessionId, uint64_t logicalSessionId)
340 {
341 LOGE("BindTarget is not implemented in the current version");
342 return ERR_DM_FAILED;
343 }
344
RegisterAuthenticationType(int32_t authenticationType)345 int32_t AuthManagerBase::RegisterAuthenticationType(int32_t authenticationType)
346 {
347 LOGE("RegisterAuthenticationType is not implemented in the current version");
348 return ERR_DM_FAILED;
349 }
350
StopAuthenticateDevice(const std::string & pkgName)351 int32_t AuthManagerBase::StopAuthenticateDevice(const std::string &pkgName)
352 {
353 LOGE("StopAuthenticateDevice is not implemented in the current version");
354 return ERR_DM_FAILED;
355 }
356
DeleteGroup(const std::string & pkgName,const std::string & deviceId)357 int32_t AuthManagerBase::DeleteGroup(const std::string &pkgName, const std::string &deviceId)
358 {
359 LOGE("DeleteGroup is not implemented in the current version");
360 return ERR_DM_FAILED;
361 }
362
GetReason()363 int32_t AuthManagerBase::GetReason()
364 {
365 LOGE("GetReason is not implemented in the current version");
366 return ERR_DM_FAILED;
367 }
368
GetBindTargetParams(std::string & pkgName,PeerTargetId & targetId,std::map<std::string,std::string> & bindParam)369 void AuthManagerBase::GetBindTargetParams(std::string &pkgName, PeerTargetId &targetId,
370 std::map<std::string, std::string> &bindParam)
371 {
372 LOGE("GetBindTargetParams is not implemented in the current version");
373 return;
374 }
375
GetAuthCodeAndPkgName(std::string & pkgName,std::string & authCode)376 void AuthManagerBase::GetAuthCodeAndPkgName(std::string &pkgName, std::string &authCode)
377 {
378 LOGE("GetAuthCodeAndPkgName is not implemented in the current version");
379 return;
380 }
381
SetBindTargetParams(const PeerTargetId & targetId)382 void AuthManagerBase::SetBindTargetParams(const PeerTargetId &targetId)
383 {
384 LOGE("SetBindTargetParams is not implemented in the current version");
385 return;
386 }
387
RegisterCleanNotifyCallback(CleanNotifyCallback cleanNotifyCallback)388 void AuthManagerBase::RegisterCleanNotifyCallback(CleanNotifyCallback cleanNotifyCallback)
389 {
390 LOGE("RegisterCleanNotifyCallback is not implemented in the current version");
391 return;
392 }
393
ConvertSrcVersion(const std::string & version,const std::string & edition)394 std::string AuthManagerBase::ConvertSrcVersion(const std::string &version, const std::string &edition)
395 {
396 std::string srcVersion = "";
397 if (version == "" && edition != "") {
398 srcVersion = edition;
399 } else if (version == "" && edition == "") {
400 srcVersion = DM_VERSION_5_1_0;
401 } else if (version != "" && edition == "") {
402 srcVersion = version;
403 }
404 LOGI("ConvertSrcVersion version %{public}s, edition %{public}s, srcVersion is %{public}s.",
405 version.c_str(), edition.c_str(), srcVersion.c_str());
406 return srcVersion;
407 }
408
409 // Scenario 1: The remote side specifies userId -> Verify if it is a front-end user
410 // Scenario 2: The remote side does not specify userId
411 // Scenario 2.1: Single user -> Use the current unique front-end user
412 // Scenario 2.2: Multiple users -> Use the current main screen user
DmGetUserId(int32_t displayId)413 int32_t AuthManagerBase::DmGetUserId(int32_t displayId)
414 {
415 int32_t ret;
416 int32_t userId = -1;
417
418 std::vector<int32_t> userIds;
419 ret = MultipleUserConnector::GetForegroundUserIds(userIds);
420 if (ret != DM_OK) {
421 LOGE("RespQueryTokenId: GetForegroundUserIds failed, ret: %{public}d", ret);
422 return -1;
423 }
424 // Scenario 1: The remote side specifies userId -> Verify if it is a front-end user
425 // Scenario 2: The remote side does not specify userId
426 // Scenario 2.1: Single user -> Use the current unique front-end user
427 // Scenario 2.2: Multiple users -> Use the current main screen user
428 if (userIds.size() == 0) {
429 LOGE("RespQueryTokenId: GetForegroundUserIds no foreground users");
430 return -1;
431 }
432
433 if (displayId != -1) {
434 ret = AccountSA::OsAccountManager::GetForegroundOsAccountLocalId(displayId, userId);
435 if (ret != DM_OK) {
436 LOGE("RespQueryTokenId: fail to get userId by displayId %{public}d", displayId);
437 return -1;
438 }
439 return userId;
440 }
441 if (userIds.size() == 1) {
442 return userIds[0];
443 } else {
444 // If userIds.size() > 1, we need to find the main screen user
445 #ifdef OS_ACCOUNT_PART_EXISTS
446 ret = AccountSA::OsAccountManager::GetForegroundOsAccountLocalId(userId);
447 if (ret != DM_OK) {
448 LOGE("AuthManagerBase::DmGetUserId: get foreground user failed in multi users with error %{public}d", ret);
449 return -1;
450 }
451 return userId;
452 #else
453 LOGE("AuthManagerBase::DmGetUserId: get foreground user failed because no OsAcccountManager");
454 return -1;
455 #endif
456 }
457 }
458
IsTransferReady()459 bool AuthManagerBase::IsTransferReady()
460 {
461 return isTransferReady_;
462 }
463
SetTransferReady(bool version)464 void AuthManagerBase::SetTransferReady(bool version)
465 {
466 isTransferReady_ = version;
467 }
468
ClearSoftbusSessionCallback()469 void AuthManagerBase::ClearSoftbusSessionCallback()
470 {}
471
PrepareSoftbusSessionCallback()472 void AuthManagerBase::PrepareSoftbusSessionCallback()
473 {}
474
EnableInsensibleSwitching()475 void AuthManagerBase::EnableInsensibleSwitching()
476 {
477 insensibleSwitching = true;
478 }
479
DisableInsensibleSwitching()480 void AuthManagerBase::DisableInsensibleSwitching()
481 {
482 insensibleSwitching = false;
483 }
484
NeedInsensibleSwitching()485 bool AuthManagerBase::NeedInsensibleSwitching()
486 {
487 return insensibleSwitching;
488 }
489
ParseAuthType(const std::map<std::string,std::string> & bindParam,int32_t & authType)490 int32_t AuthManagerBase::ParseAuthType(const std::map<std::string, std::string> &bindParam, int32_t &authType)
491 {
492 auto iter = bindParam.find(PARAM_KEY_AUTH_TYPE);
493 if (iter == bindParam.end()) {
494 LOGE("AuthManagerBase::ParseAuthType bind param key: %{public}s not exist.", PARAM_KEY_AUTH_TYPE);
495 return ERR_DM_INPUT_PARA_INVALID;
496 }
497 std::string authTypeStr = iter->second;
498 if (authTypeStr.empty()) {
499 LOGE("AuthManagerBase::ParseAuthType bind param %{public}s is empty.", PARAM_KEY_AUTH_TYPE);
500 return ERR_DM_INPUT_PARA_INVALID;
501 }
502 if (authTypeStr.length() > 1) {
503 LOGE("AuthManagerBase::ParseAuthType bind param %{public}s length is unsupported.", PARAM_KEY_AUTH_TYPE);
504 return ERR_DM_INPUT_PARA_INVALID;
505 }
506 if (!isdigit(authTypeStr[0])) {
507 LOGE("AuthManagerBase::ParseAuthType bind param %{public}s fromat is unsupported.", PARAM_KEY_AUTH_TYPE);
508 return ERR_DM_INPUT_PARA_INVALID;
509 }
510 authType = std::atoi(authTypeStr.c_str());
511 return DM_OK;
512 }
513
OnAuthDeviceDataReceived(int32_t sessionId,std::string message)514 void AuthManagerBase::OnAuthDeviceDataReceived(int32_t sessionId, std::string message)
515 {
516 LOGE("OnAuthDeviceDataReceived is not used in the new protocol");
517 }
518
EndDream()519 int32_t AuthManagerBase::EndDream()
520 {
521 auto &powerMgrClient = OHOS::PowerMgr::PowerMgrClient::GetInstance();
522 if (!powerMgrClient.IsScreenOn()) {
523 LOGW("screen not on");
524 return ERR_DM_FAILED;
525 }
526 #if defined(SUPPORT_SCREENLOCK)
527 if (!OHOS::ScreenLock::ScreenLockManager::GetInstance()->IsScreenLocked()) {
528 LOGI("screen not locked");
529 return DM_OK;
530 }
531 #endif
532 PowerMgr::PowerErrors ret =
533 powerMgrClient.WakeupDevice(PowerMgr::WakeupDeviceType::WAKEUP_DEVICE_END_DREAM, "end_dream");
534 if (ret != OHOS::PowerMgr::PowerErrors::ERR_OK) {
535 LOGE("fail to end dream, err:%{public}d", ret);
536 return ERR_DM_FAILED;
537 }
538 LOGI("end dream success");
539 return DM_OK;
540 }
541
CheckProcessNameInWhiteList(const std::string & processName)542 bool AuthManagerBase::CheckProcessNameInWhiteList(const std::string &processName)
543 {
544 LOGI("AuthManagerBase::CheckProcessNameInWhiteList start");
545 if (processName.empty()) {
546 LOGE("processName is empty");
547 return false;
548 }
549 uint16_t index = 0;
550 #ifdef DEVICE_MANAGER_COMMON_FLAG
551 for (; index < OPEN_PROCESS_NAME_WHITE_LIST_NUM; ++index) {
552 std::string whitePkgName(OPEN_PROCESS_NAME_WHITE_LIST[index]);
553 if (processName == whitePkgName) {
554 LOGI("processName = %{public}s in whiteList.", processName.c_str());
555 return true;
556 }
557 }
558 #else
559 for (; index < CLOSE_PROCESS_NAME_WHITE_LIST_NUM; ++index) {
560 std::string whitePkgName(CLOSE_PROCESS_NAME_WHITE_LIST[index]);
561 if (processName == whitePkgName) {
562 LOGI("processName = %{public}s in whiteList.", processName.c_str());
563 return true;
564 }
565 }
566 #endif
567 LOGI("CheckProcessNameInWhiteList: %{public}s invalid.", processName.c_str());
568 return false;
569 }
570
CheckProcessNameInProxyAdaptationList(const std::string & processName)571 bool AuthManagerBase::CheckProcessNameInProxyAdaptationList(const std::string &processName)
572 {
573 LOGI("start");
574 if (processName.empty()) {
575 LOGE("processName is empty");
576 return false;
577 }
578 uint16_t index = 0;
579 for (; index < PROCESS_NAME_PROXY_ADAPTATION_LIST_NUM; ++index) {
580 std::string whitePkgName(PROCESS_NAME_PROXY_ADAPTATION_LIST[index]);
581 if (processName == whitePkgName) {
582 LOGI("processName = %{public}s in adaptation List.", processName.c_str());
583 return true;
584 }
585 }
586 LOGI("processName = %{public}s not in adaptation List.", processName.c_str());
587 return false;
588 }
589
DeleteTimer()590 void AuthManagerBase::DeleteTimer()
591 {}
592 } // namespace DistributedHardware
593 } // namespace OHOS