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