1 /*
2 * Copyright (c) 2021 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 "pin_auth_ui.h"
17
18 #include "dm_ability_manager.h"
19 #include "dm_constants.h"
20 #include "dm_log.h"
21 #include "nlohmann/json.hpp"
22 #include "parameter.h"
23 #include "ui_service_mgr_client.h"
24
25 namespace OHOS {
26 namespace DistributedHardware {
27 constexpr const char* VERIFY_FAILED = "verifyFailed";
28
PinAuthUi()29 PinAuthUi::PinAuthUi()
30 {
31 LOGI("AuthUi constructor");
32 }
33
ShowPinDialog(int32_t code,std::shared_ptr<DmAuthManager> authManager)34 int32_t PinAuthUi::ShowPinDialog(int32_t code, std::shared_ptr<DmAuthManager> authManager)
35 {
36 LOGI("ShowPinDialog start");
37 if (authManager == nullptr) {
38 LOGE("authManager is null");
39 return DM_FAILED;
40 }
41 std::shared_ptr<DmAbilityManager> dmAbilityMgr = std::make_shared<DmAbilityManager>();
42 if (dmAbilityMgr == nullptr) {
43 LOGE("PinAuthUi::dmAbilityManager is null");
44 return DM_FAILED;
45 }
46 AAFwk::Want want;
47 want.SetParam("PinCode", std::to_string(code));
48 char localDeviceId[DEVICE_UUID_LENGTH] = {0};
49 GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH);
50 const std::string deviceId = localDeviceId;
51 const std::string bundleUiName = "com.ohos.devicemanagerui";
52 const std::string abilityUiName = "com.ohos.devicemanagerui.PinDialogAbility";
53 AppExecFwk::ElementName element(deviceId, bundleUiName, abilityUiName);
54 want.SetElement(element);
55 AbilityStatus status = dmAbilityMgr->StartAbility(want);
56 if (status != AbilityStatus::ABILITY_STATUS_SUCCESS) {
57 LOGE("ShowConfirm::start ui service success");
58 return DM_FAILED;
59 }
60 LOGI("ShowPinDialog end");
61 return DM_OK;
62 }
63
InputPinDialog(std::shared_ptr<DmAuthManager> authManager)64 int32_t PinAuthUi::InputPinDialog(std::shared_ptr<DmAuthManager> authManager)
65 {
66 LOGI("InputPinDialog start");
67 if (authManager == nullptr) {
68 LOGE("authManager is null");
69 return DM_FAILED;
70 }
71 std::shared_ptr<DmAbilityManager> dmAbilityMgr = std::make_shared<DmAbilityManager>();
72 if (dmAbilityMgr == nullptr) {
73 LOGE("PinAuthUi::dmAbilityManager is null");
74 return DM_FAILED;
75 }
76 AAFwk::Want want;
77 want.SetParam(VERIFY_FAILED, false);
78 char localDeviceId[DEVICE_UUID_LENGTH] = {0};
79 GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH);
80 const std::string deviceId = localDeviceId;
81 const std::string bundleUiName = "com.ohos.devicemanagerui";
82 const std::string abilityUiName = "com.ohos.devicemanagerui.InputPinDialogAbility";
83 AppExecFwk::ElementName element(deviceId, bundleUiName, abilityUiName);
84 want.SetElement(element);
85 AbilityStatus status = dmAbilityMgr->StartAbility(want);
86 if (status != AbilityStatus::ABILITY_STATUS_SUCCESS) {
87 LOGE("ShowConfirm::start ui service success");
88 return DM_FAILED;
89 }
90 LOGI("InputPinDialog end");
91 return DM_OK;
92 }
93
ClosePage(const int32_t & pageId,std::shared_ptr<DmAuthManager> authManager)94 int32_t PinAuthUi::ClosePage(const int32_t &pageId, std::shared_ptr<DmAuthManager> authManager)
95 {
96 LOGI("PinAuthUi start");
97 Ace::UIServiceMgrClient::GetInstance()->CancelDialog(pageId);
98 LOGI("PinAuthUi end");
99 return DM_OK;
100 }
101
102 } // namespace DistributedHardware
103 } // namespace OHOS