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 
41     AAFwk::Want want;
42     want.SetParam("PinCode", std::to_string(code));
43     char localDeviceId[DEVICE_UUID_LENGTH] = {0};
44     GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH);
45     const std::string deviceId = localDeviceId;
46     const std::string bundleUiName = "com.ohos.devicemanagerui";
47     const std::string abilityUiName = "com.ohos.devicemanagerui.PincodeServiceExtAbility";
48     AppExecFwk::ElementName element(deviceId, bundleUiName, abilityUiName);
49     want.SetElement(element);
50     AbilityStatus status = dmAbilityMgr->StartAbility(want);
51     if (status != AbilityStatus::ABILITY_STATUS_SUCCESS) {
52         LOGE("ShowPinDialog::start ui service fail");
53         return ERR_DM_FAILED;
54     }
55     LOGI("ShowPinDialog end");
56     return DM_OK;
57 }
58 
InputPinDialog(std::shared_ptr<DmAuthManager> authManager)59 int32_t PinAuthUi::InputPinDialog(std::shared_ptr<DmAuthManager> authManager)
60 {
61     LOGI("InputPinDialog start");
62     if (authManager == nullptr) {
63         LOGE("authManager is null");
64         return ERR_DM_FAILED;
65     }
66     std::shared_ptr<DmAbilityManager> dmAbilityMgr = std::make_shared<DmAbilityManager>();
67 
68     AAFwk::Want want;
69     want.SetParam(VERIFY_FAILED, false);
70     char localDeviceId[DEVICE_UUID_LENGTH] = {0};
71     GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH);
72     const std::string deviceId = localDeviceId;
73     const std::string bundleUiName = "com.ohos.devicemanagerui";
74     const std::string abilityUiName = "com.ohos.devicemanagerui.InputServiceExtAbility";
75     AppExecFwk::ElementName element(deviceId, bundleUiName, abilityUiName);
76     want.SetElement(element);
77     AbilityStatus status = dmAbilityMgr->StartAbility(want);
78     if (status != AbilityStatus::ABILITY_STATUS_SUCCESS) {
79         LOGE("InputPinDialog::start ui service fail");
80         return ERR_DM_FAILED;
81     }
82     LOGI("InputPinDialog end");
83     return DM_OK;
84 }
85 } // namespace DistributedHardware
86 } // namespace OHOS
87