diff --git a/bundle.json b/bundle.json index 5d6b7849cf2043caa0836def99c7490f794760fe..fdde9d9554680684ced7b86f00a071b983df093e 100644 --- a/bundle.json +++ b/bundle.json @@ -77,9 +77,6 @@ "header_base": "//foundation/distributedhardware/device_manager/interfaces/inner_kits/native_cpp/include" } } - ], - "test": [ - "//foundation/distributedhardware/device_manager:device_manager_test" ] } } diff --git a/common/include/ipc/ipc_def.h b/common/include/ipc/ipc_def.h index 436eecc120369bf0f6a796e86e0fa7394855c917..88e418f91f8c24981ccc7f55a607cabc26d1b39d 100644 --- a/common/include/ipc/ipc_def.h +++ b/common/include/ipc/ipc_def.h @@ -66,6 +66,8 @@ enum IpcCmdID { REGISTER_CREDENTIAL_CALLBACK, UNREGISTER_CREDENTIAL_CALLBACK, NOTIFY_EVENT, + SET_AUTH_PINCODE, + GENERATE_PINCODE, // Add ipc msg here IPC_MSG_BUTT }; diff --git a/common/include/ipc/model/ipc_set_auth_pincode_req.h b/common/include/ipc/model/ipc_set_auth_pincode_req.h new file mode 100644 index 0000000000000000000000000000000000000000..69d0f6380608f1cc2102fa704842555a9acb434b --- /dev/null +++ b/common/include/ipc/model/ipc_set_auth_pincode_req.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DM_IPC_SET_AUTH_PINCODE_REQ_H +#define OHOS_DM_IPC_SET_AUTH_PINCODE_REQ_H + +#include "ipc_req.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcSetAuthPinCodeReq : public IpcReq { + DECLARE_IPC_MODEL(IpcSetAuthPinCodeReq); + +public: + const std::string &GetPinCode() const + { + return pinCode_; + } + + void SetPinCode(const std::string &pinCode) + { + pinCode_ = pinCode; + } + +private: + std::string pinCode_; +}; +} // namespace DistributedHardware +} // namespace OHOS + +#endif // OHOS_DM_IPC_SET_AUTH_PINCODE_REQ_H diff --git a/common/src/dfx/standard/dm_hisysevent.cpp b/common/src/dfx/standard/dm_hisysevent.cpp index 4e9b2970a8cce3d5c189740f35be94687bb81703..067677fa022c46726fef0ede65722a5afbdacbf1 100644 --- a/common/src/dfx/standard/dm_hisysevent.cpp +++ b/common/src/dfx/standard/dm_hisysevent.cpp @@ -17,23 +17,23 @@ #include "dm_constants.h" // for DM_OK #include "dm_log.h" // for LOGE -#include "hisysevent.h" // for HiSysEvent, HiSysEvent::Domain, HiSysEvent... +// #include "hisysevent.h" // for HiSysEvent, HiSysEvent::Domain, HiSysEvent... #include "unistd.h" // for getpid, getuid namespace OHOS { namespace DistributedHardware { void SysEventWrite(const std::string &status, int32_t eventType, const std::string &msg) { - int32_t res = OHOS::HiviewDFX::HiSysEvent::Write( - OHOS::HiviewDFX::HiSysEvent::Domain::DISTRIBUTED_DEVICE_MANAGER, - status.c_str(), - (OHOS::HiviewDFX::HiSysEvent::EventType)eventType, - "PID", getpid(), - "UID", getuid(), - "MSG", msg.c_str()); - if (res != DM_OK) { - LOGE("%s Write HiSysEvent error, res:%d", status.c_str(), res); - } + // int32_t res = OHOS::HiviewDFX::HiSysEvent::Write( + // OHOS::HiviewDFX::HiSysEvent::Domain::DISTRIBUTED_DEVICE_MANAGER, + // status.c_str(), + // (OHOS::HiviewDFX::HiSysEvent::EventType)eventType, + // "PID", getpid(), + // "UID", getuid(), + // "MSG", msg.c_str()); + // if (res != DM_OK) { + // LOGE("%s Write HiSysEvent error, res:%d", status.c_str(), res); + // } } } // namespace DistributedHardware } // namespace OHOS diff --git a/common/src/dfx/standard/dm_hitrace.cpp b/common/src/dfx/standard/dm_hitrace.cpp index 1bbe65fa39f0dad8fe13bc58445330674f542c6c..85a529ff3b8c0ee761216e5958219b29398fd53f 100644 --- a/common/src/dfx/standard/dm_hitrace.cpp +++ b/common/src/dfx/standard/dm_hitrace.cpp @@ -13,18 +13,18 @@ * limitations under the License. */ #include "dm_hitrace.h" -#include "hitrace_meter.h" +// #include "hitrace_meter.h" namespace OHOS { namespace DistributedHardware { void DmTraceStart(const std::string &msg) { - StartTrace(HITRACE_TAG_DEVICE_MANAGER, msg); + // StartTrace(HITRACE_TAG_DEVICE_MANAGER, msg); } void DmTraceEnd() { - FinishTrace(HITRACE_TAG_DEVICE_MANAGER); + // FinishTrace(HITRACE_TAG_DEVICE_MANAGER); } } // namespace DistributedHardware } // namespace OHOS diff --git a/ext/BUILD.gn b/ext/BUILD.gn index 03033ecc5a85e9d291714072803b03e16911f5df..5bc04e2abadb4c4dce13da25cf26b06b99c9ade2 100644 --- a/ext/BUILD.gn +++ b/ext/BUILD.gn @@ -16,11 +16,11 @@ import("//foundation/distributedhardware/device_manager/device_manager.gni") group("ext_modules") { deps = [] - if (support_jsapi) { + # if (support_jsapi) { if (device_manager_no_interaction_auth) { deps += [ "./no_interaction_auth:devicemanagerext_no_interaction_auth" ] } else { deps += [ "./pin_auth:devicemanagerext_pin_auth" ] } - } + # } } diff --git a/ext/no_interaction_auth/BUILD.gn b/ext/no_interaction_auth/BUILD.gn index 231e60e41c74eb56fe283634238a366b90602824..78cf071fbfd616516f51f6c70935d760db9e066e 100644 --- a/ext/no_interaction_auth/BUILD.gn +++ b/ext/no_interaction_auth/BUILD.gn @@ -21,80 +21,80 @@ import("//foundation/distributedhardware/device_manager/device_manager.gni") if (defined(ohos_lite)) { } else { - ohos_shared_library("devicemanagerext_no_interaction_auth") { - include_dirs = [ - "include", - "${common_path}/include", - "${ext_path}/pin_auth/include/ability", - "${servicesimpl_path}/include/dependency/timer", - "${servicesimpl_path}/include/config", - "${servicesimpl_path}/include/adapter", - "${servicesimpl_path}/include/authentication", - "${servicesimpl_path}/include/ability", - "${servicesimpl_path}/include/devicestate", - "${servicesimpl_path}/include/discovery", - "${servicesimpl_path}/include/dependency/commonevent", - "${servicesimpl_path}/include/dependency/hichain", - "${servicesimpl_path}/include/dependency/softbus", - "${servicesimpl_path}/include/dependency/timer", - "${services_path}/include/ipc", - "${services_path}/include/ipc/standard", - "${utils_path}/include", - "${utils_path}/include/ipc/standard", - "${servicesimpl_path}/include", - "${innerkits_path}/native_cpp/include", - "${common_path}/include/ipc", - "${common_path}/include/ipc/model", - "${innerkits_path}/native_cpp/include", - "${innerkits_path}/native_cpp/include/ipc", - "${innerkits_path}/native_cpp/include/ipc/standard", - "//third_party/json/include", - "//commonlibrary/c_utils/base/include", - "//utils/system/safwk/native/include", - "//base/notification/common_event_service/frameworks/core/include", - "//base/notification/common_event_service/interfaces/innerkits/native/include", - "//base/security/device_auth/interfaces/innerkits", - ] + # ohos_shared_library("devicemanagerext_no_interaction_auth") { + # include_dirs = [ + # "include", + # "${common_path}/include", + # "${ext_path}/pin_auth/include/ability", + # "${servicesimpl_path}/include/dependency/timer", + # "${servicesimpl_path}/include/config", + # "${servicesimpl_path}/include/adapter", + # "${servicesimpl_path}/include/authentication", + # "${servicesimpl_path}/include/ability", + # "${servicesimpl_path}/include/devicestate", + # "${servicesimpl_path}/include/discovery", + # "${servicesimpl_path}/include/dependency/commonevent", + # "${servicesimpl_path}/include/dependency/hichain", + # "${servicesimpl_path}/include/dependency/softbus", + # "${servicesimpl_path}/include/dependency/timer", + # "${services_path}/include/ipc", + # "${services_path}/include/ipc/standard", + # "${utils_path}/include", + # "${utils_path}/include/ipc/standard", + # "${servicesimpl_path}/include", + # "${innerkits_path}/native_cpp/include", + # "${common_path}/include/ipc", + # "${common_path}/include/ipc/model", + # "${innerkits_path}/native_cpp/include", + # "${innerkits_path}/native_cpp/include/ipc", + # "${innerkits_path}/native_cpp/include/ipc/standard", + # "//third_party/json/include", + # "//commonlibrary/c_utils/base/include", + # "//utils/system/safwk/native/include", + # "//base/notification/common_event_service/frameworks/core/include", + # "//base/notification/common_event_service/interfaces/innerkits/native/include", + # "//base/security/device_auth/interfaces/innerkits", + # ] - sources = [ - "src/ability/standard/dm_ability_manager.cpp", - "src/no_interaction_auth.cpp", - ] + # sources = [ + # "src/ability/standard/dm_ability_manager.cpp", + # "src/no_interaction_auth.cpp", + # ] - deps = [ - "${ability_runtime_innerkits_path}/ability_manager:ability_manager", - "${ability_runtime_services_path}/abilitymgr:abilityms", - "${innerkits_path}/native_cpp:devicemanagersdk", - "${utils_path}:devicemanagerutils", - "//base/security/device_auth/services:deviceauth_sdk", - "//foundation/distributedhardware/device_manager/services/implementation:devicemanagerserviceimpl", - "//foundation/distributedhardware/device_manager/services/service:devicemanagerservice", - ] + # deps = [ + # "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + # "${ability_runtime_services_path}/abilitymgr:abilityms", + # "${innerkits_path}/native_cpp:devicemanagersdk", + # "${utils_path}:devicemanagerutils", + # "//base/security/device_auth/services:deviceauth_sdk", + # "//foundation/distributedhardware/device_manager/services/implementation:devicemanagerserviceimpl", + # "//foundation/distributedhardware/device_manager/services/service:devicemanagerservice", + # ] - external_deps = [ - "ability_base:want", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "c_utils:utils", - "common_event_service:cesfwk_core", - "common_event_service:cesfwk_innerkits", - "dsoftbus:softbus_client", - "hiviewdfx_hilog_native:libhilog", - "init:libbeget_proxy", - "init:libbegetutil", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - ] + # external_deps = [ + # "ability_base:want", + # "bundle_framework:appexecfwk_base", + # "bundle_framework:appexecfwk_core", + # "c_utils:utils", + # "common_event_service:cesfwk_core", + # "common_event_service:cesfwk_innerkits", + # "dsoftbus:softbus_client", + # "hiviewdfx_hilog_native:libhilog", + # "init:libbeget_proxy", + # "init:libbegetutil", + # "ipc:ipc_core", + # "safwk:system_ability_fwk", + # "samgr:samgr_proxy", + # ] - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"devicemanagerext\"", - "LOG_DOMAIN=0xD004100", - ] + # defines = [ + # "HI_LOG_ENABLE", + # "DH_LOG_TAG=\"devicemanagerext\"", + # "LOG_DOMAIN=0xD004100", + # ] - subsystem_name = "distributedhardware" + # subsystem_name = "distributedhardware" - part_name = "device_manager" - } + # part_name = "device_manager" + # } } diff --git a/ext/pin_auth/BUILD.gn b/ext/pin_auth/BUILD.gn index d49e4f4acd3e21ca30ed1c19b46997065856f94b..042de4d9299a65b278087323176a2df094aef91c 100644 --- a/ext/pin_auth/BUILD.gn +++ b/ext/pin_auth/BUILD.gn @@ -128,19 +128,19 @@ if (defined(ohos_lite)) { ] sources = [ - "src/ability/standard/dm_ability_manager.cpp", + # "src/ability/standard/dm_ability_manager.cpp", "src/pin_auth.cpp", "src/standard/pin_auth_ui.cpp", ] deps = [ - "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + # "${ability_runtime_innerkits_path}/ability_manager:ability_manager", "${innerkits_path}/native_cpp:devicemanagersdk", "//foundation/distributedhardware/device_manager/services/implementation:devicemanagerserviceimpl", ] external_deps = [ - "ability_base:want", + # "ability_base:want", "init:libbegetutil", ] diff --git a/ext/pin_auth/include/ability/dm_ability_manager.h b/ext/pin_auth/include/ability/dm_ability_manager.h index 83a62f2c445948bc7567e3f9aa88970c9ffaebc4..318ad8f0dc0c6c138d508928ab6e0624c9c964ae 100644 --- a/ext/pin_auth/include/ability/dm_ability_manager.h +++ b/ext/pin_auth/include/ability/dm_ability_manager.h @@ -18,7 +18,7 @@ #include #include -#include "want.h" +// #include "want.h" namespace OHOS { namespace DistributedHardware { @@ -37,7 +37,7 @@ enum UiAction { class DmAbilityManager { public: - AbilityStatus StartAbility(AAFwk::Want &want); + // AbilityStatus StartAbility(AAFwk::Want &want); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/ext/pin_auth/include/pin_auth.h b/ext/pin_auth/include/pin_auth.h index b91517117a895a67f058f6bd478318f2ed76786a..4c1fd20b13cf14f9d23a2885f978d2e7c28dbc4e 100644 --- a/ext/pin_auth/include/pin_auth.h +++ b/ext/pin_auth/include/pin_auth.h @@ -19,9 +19,9 @@ #include #include -#include "authentication.h" +// #include "authentication.h" #include "dm_auth_manager.h" -#include "dm_ability_manager.h" +// #include "dm_ability_manager.h" #include "pin_auth_ui.h" namespace OHOS { diff --git a/ext/pin_auth/include/standard/pin_auth_ui.h b/ext/pin_auth/include/standard/pin_auth_ui.h index aa33b20fb236239111146a12047077a5f1ac7f9a..b87b000d010c8f4ec64dd7e4f24636e5cd75271b 100644 --- a/ext/pin_auth/include/standard/pin_auth_ui.h +++ b/ext/pin_auth/include/standard/pin_auth_ui.h @@ -19,8 +19,8 @@ #include #include "dm_auth_manager.h" -#include "dm_ability_manager.h" -#include "want.h" +// #include "dm_ability_manager.h" +// #include "want.h" namespace OHOS { namespace DistributedHardware { diff --git a/ext/pin_auth/src/pin_auth.cpp b/ext/pin_auth/src/pin_auth.cpp index 948d98e663c2165b4e9d185c582bf9147077404a..b141bb6a9a049015679d451c153685c7e6c1c183 100644 --- a/ext/pin_auth/src/pin_auth.cpp +++ b/ext/pin_auth/src/pin_auth.cpp @@ -38,59 +38,62 @@ PinAuth::~PinAuth() int32_t PinAuth::ShowAuthInfo(std::string &authToken, std::shared_ptr authManager) { - nlohmann::json jsonObject = nlohmann::json::parse(authToken, nullptr, false); - if (jsonObject.is_discarded()) { - LOGE("DecodeRequestAuth jsonStr error"); - return ERR_DM_FAILED; - } - if (!IsInt32(jsonObject, PIN_CODE_KEY)) { - LOGE("err json string, first time"); - return ERR_DM_FAILED; - } - return pinAuthUi_->ShowPinDialog(jsonObject[PIN_CODE_KEY].get(), authManager); + return DM_OK; + // nlohmann::json jsonObject = nlohmann::json::parse(authToken, nullptr, false); + // if (jsonObject.is_discarded()) { + // LOGE("DecodeRequestAuth jsonStr error"); + // return ERR_DM_FAILED; + // } + // if (!IsInt32(jsonObject, PIN_CODE_KEY)) { + // LOGE("err json string, first time"); + // return ERR_DM_FAILED; + // } + // return pinAuthUi_->ShowPinDialog(jsonObject[PIN_CODE_KEY].get(), authManager); } int32_t PinAuth::StartAuth(std::string &authToken, std::shared_ptr authManager) { - return pinAuthUi_->InputPinDialog(authManager); + // return pinAuthUi_->InputPinDialog(authManager); + return DM_OK; } int32_t PinAuth::VerifyAuthentication(std::string &authToken, const std::string &authParam) { - times_ += 1; - if (authParam.length() == 1) { - if (authParam == std::string(EVENT_CONFIRM_CODE)) { - return DM_OK; - } - LOGE("Peer rejection"); - return ERR_DM_FAILED; - } - nlohmann::json authParamJson = nlohmann::json::parse(authParam, nullptr, false); - if (authParamJson.is_discarded()) { - LOGE("DecodeRequestAuth jsonStr error"); - return ERR_DM_FAILED; - } - nlohmann::json authTokenJson = nlohmann::json::parse(authToken, nullptr, false); - if (authTokenJson.is_discarded()) { - LOGE("DecodeRequestAuth jsonStr error"); - return ERR_DM_FAILED; - } - if (!IsInt32(authTokenJson, PIN_CODE_KEY) || !IsString(authTokenJson, PIN_TOKEN) || - !IsInt32(authParamJson, PIN_CODE_KEY) || !IsString(authParamJson, PIN_TOKEN)) { - LOGE("PinAuth::VerifyAuthentication err json string."); - return ERR_DM_FAILED; - } - int32_t code = authTokenJson[PIN_CODE_KEY].get(); - std::string pinToken = authTokenJson[PIN_TOKEN].get(); - int32_t inputPinCode = authParamJson[PIN_CODE_KEY].get(); - std::string inputPinToken = authParamJson[PIN_TOKEN].get(); - if (code == inputPinCode && pinToken == inputPinToken) { - return DM_OK; - } else if (code != inputPinCode && times_ < MAX_VERIFY_TIMES) { - return ERR_DM_INPUT_PARA_INVALID; - } else { - return ERR_DM_FAILED; - } + return DM_OK; + // times_ += 1; + // if (authParam.length() == 1) { + // if (authParam == std::string(EVENT_CONFIRM_CODE)) { + // return DM_OK; + // } + // LOGE("Peer rejection"); + // return ERR_DM_FAILED; + // } + // nlohmann::json authParamJson = nlohmann::json::parse(authParam, nullptr, false); + // if (authParamJson.is_discarded()) { + // LOGE("DecodeRequestAuth jsonStr error"); + // return ERR_DM_FAILED; + // } + // nlohmann::json authTokenJson = nlohmann::json::parse(authToken, nullptr, false); + // if (authTokenJson.is_discarded()) { + // LOGE("DecodeRequestAuth jsonStr error"); + // return ERR_DM_FAILED; + // } + // if (!IsInt32(authTokenJson, PIN_CODE_KEY) || !IsString(authTokenJson, PIN_TOKEN) || + // !IsInt32(authParamJson, PIN_CODE_KEY) || !IsString(authParamJson, PIN_TOKEN)) { + // LOGE("PinAuth::VerifyAuthentication err json string."); + // return ERR_DM_FAILED; + // } + // int32_t code = authTokenJson[PIN_CODE_KEY].get(); + // std::string pinToken = authTokenJson[PIN_TOKEN].get(); + // int32_t inputPinCode = authParamJson[PIN_CODE_KEY].get(); + // std::string inputPinToken = authParamJson[PIN_TOKEN].get(); + // if (code == inputPinCode && pinToken == inputPinToken) { + // return DM_OK; + // } else if (code != inputPinCode && times_ < MAX_VERIFY_TIMES) { + // return ERR_DM_INPUT_PARA_INVALID; + // } else { + // return ERR_DM_FAILED; + // } } extern "C" IAuthentication *CreatePinAuthObject(void) diff --git a/ext/pin_auth/src/standard/pin_auth_ui.cpp b/ext/pin_auth/src/standard/pin_auth_ui.cpp index 65af67a6ebd2d8a49c304a755b5ab09dee16b3c2..be9647023a03e4249a0b526ed71a5df71055efd6 100644 --- a/ext/pin_auth/src/standard/pin_auth_ui.cpp +++ b/ext/pin_auth/src/standard/pin_auth_ui.cpp @@ -31,55 +31,57 @@ PinAuthUi::PinAuthUi() int32_t PinAuthUi::ShowPinDialog(int32_t code, std::shared_ptr authManager) { - LOGI("ShowPinDialog start"); - if (authManager == nullptr) { - LOGE("authManager is null"); - return ERR_DM_FAILED; - } - std::shared_ptr dmAbilityMgr = std::make_shared(); - AAFwk::Want want; - want.SetParam("PinCode", std::to_string(code)); - char localDeviceId[DEVICE_UUID_LENGTH] = {0}; - GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); - const std::string deviceId = localDeviceId; - const std::string bundleUiName = "com.ohos.devicemanagerui"; - const std::string abilityUiName = "com.ohos.devicemanagerui.PincodeServiceExtAbility"; - AppExecFwk::ElementName element(deviceId, bundleUiName, abilityUiName); - want.SetElement(element); - AbilityStatus status = dmAbilityMgr->StartAbility(want); - if (status != AbilityStatus::ABILITY_STATUS_SUCCESS) { - LOGE("ShowConfirm::start ui service fail"); - return ERR_DM_FAILED; - } - LOGI("ShowPinDialog end"); - return DM_OK; + return -1; + // LOGI("ShowPinDialog start"); + // if (authManager == nullptr) { + // LOGE("authManager is null"); + // return ERR_DM_FAILED; + // } + // std::shared_ptr dmAbilityMgr = std::make_shared(); + // AAFwk::Want want; + // want.SetParam("PinCode", std::to_string(code)); + // char localDeviceId[DEVICE_UUID_LENGTH] = {0}; + // GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); + // const std::string deviceId = localDeviceId; + // const std::string bundleUiName = "com.ohos.devicemanagerui"; + // const std::string abilityUiName = "com.ohos.devicemanagerui.PincodeServiceExtAbility"; + // AppExecFwk::ElementName element(deviceId, bundleUiName, abilityUiName); + // want.SetElement(element); + // AbilityStatus status = dmAbilityMgr->StartAbility(want); + // if (status != AbilityStatus::ABILITY_STATUS_SUCCESS) { + // LOGE("ShowConfirm::start ui service fail"); + // return ERR_DM_FAILED; + // } + // LOGI("ShowPinDialog end"); + // return DM_OK; } int32_t PinAuthUi::InputPinDialog(std::shared_ptr authManager) { - LOGI("InputPinDialog start"); - if (authManager == nullptr) { - LOGE("authManager is null"); - return ERR_DM_FAILED; - } - std::shared_ptr dmAbilityMgr = std::make_shared(); + return -1; + // LOGI("InputPinDialog start"); + // if (authManager == nullptr) { + // LOGE("authManager is null"); + // return ERR_DM_FAILED; + // } + // std::shared_ptr dmAbilityMgr = std::make_shared(); - AAFwk::Want want; - want.SetParam(VERIFY_FAILED, false); - char localDeviceId[DEVICE_UUID_LENGTH] = {0}; - GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); - const std::string deviceId = localDeviceId; - const std::string bundleUiName = "com.ohos.devicemanagerui"; - const std::string abilityUiName = "com.ohos.devicemanagerui.InputServiceExtAbility"; - AppExecFwk::ElementName element(deviceId, bundleUiName, abilityUiName); - want.SetElement(element); - AbilityStatus status = dmAbilityMgr->StartAbility(want); - if (status != AbilityStatus::ABILITY_STATUS_SUCCESS) { - LOGE("ShowConfirm::start ui service success"); - return ERR_DM_FAILED; - } - LOGI("InputPinDialog end"); - return DM_OK; + // AAFwk::Want want; + // want.SetParam(VERIFY_FAILED, false); + // char localDeviceId[DEVICE_UUID_LENGTH] = {0}; + // GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); + // const std::string deviceId = localDeviceId; + // const std::string bundleUiName = "com.ohos.devicemanagerui"; + // const std::string abilityUiName = "com.ohos.devicemanagerui.InputServiceExtAbility"; + // AppExecFwk::ElementName element(deviceId, bundleUiName, abilityUiName); + // want.SetElement(element); + // AbilityStatus status = dmAbilityMgr->StartAbility(want); + // if (status != AbilityStatus::ABILITY_STATUS_SUCCESS) { + // LOGE("ShowConfirm::start ui service success"); + // return ERR_DM_FAILED; + // } + // LOGI("InputPinDialog end"); + // return DM_OK; } } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/BUILD.gn b/interfaces/inner_kits/native_cpp/BUILD.gn index d572656747f535e7158f3a578bd371ba857a0a4b..24989e865707399646b9af72d035bd863e4de0dc 100644 --- a/interfaces/inner_kits/native_cpp/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/BUILD.gn @@ -147,10 +147,14 @@ if (defined(ohos_lite)) { "LOG_DOMAIN=0xD004100", ] + deps = [ + "//foundation/distributedhardware/device_manager/services/service:devicemanagerservice", + ] + external_deps = [ "c_utils:utils", - "hisysevent_native:libhisysevent", - "hitrace_native:hitrace_meter", + # "hisysevent_native:libhisysevent", + # "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "samgr:samgr_proxy", diff --git a/interfaces/inner_kits/native_cpp/include/device_manager.h b/interfaces/inner_kits/native_cpp/include/device_manager.h index d96fb50246aa289357df2569ff6cec0cf744d23e..b695a7616e9c44ddc43b7d7646cb9027c72167c1 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager.h @@ -27,6 +27,7 @@ namespace OHOS { namespace DistributedHardware { + class DeviceManager { public: static DeviceManager &GetInstance(); @@ -207,6 +208,12 @@ public: * @param event event info */ virtual int32_t NotifyEvent(const std::string &pkgName, const int32_t eventId, const std::string &event) = 0; + + virtual int32_t SetAuthPinCode(const std::string &pkgName, const std::string &pinCode) = 0; + + virtual int32_t RegNotifyPinCodeCallback(const std::string &pkgName, std::shared_ptr callback) = 0; + + virtual int32_t UnRegNotifyPinCodeCallback(const std::string &pkgName) = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/include/device_manager_callback.h b/interfaces/inner_kits/native_cpp/include/device_manager_callback.h index 8f63d023723cc6ec8236d3a381e168925177528d..2c27b90960c8037ec896d24fd626863047131c3a 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_callback.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_callback.h @@ -23,6 +23,7 @@ namespace OHOS { namespace DistributedHardware { + class DmInitCallback { public: virtual ~DmInitCallback() @@ -91,6 +92,14 @@ public: } virtual void OnCredentialResult(int32_t &action, const std::string &credentialResult) = 0; }; + +class NotifyPinCodeCallback { +public: + virtual ~NotifyPinCodeCallback() + { + } + virtual void OnSet(const std::string& pinCode) = 0; +}; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_CALLBACK_H diff --git a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h index cc3c85b24f14fecad1018273fc9e589a4ad53515..db83530aab545f19518201989788060f29abde0f 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h @@ -24,6 +24,7 @@ namespace OHOS { namespace DistributedHardware { + class DeviceManagerImpl : public DeviceManager { public: static DeviceManagerImpl &GetInstance(); @@ -207,7 +208,14 @@ public: */ virtual int32_t NotifyEvent(const std::string &pkgName, const int32_t eventId, const std::string &event) override; + virtual int32_t SetAuthPinCode(const std::string &pkgName, const std::string &pinCode) override; + + virtual int32_t RegNotifyPinCodeCallback(const std::string &pkgName, std::shared_ptr callback) override; + + virtual int32_t UnRegNotifyPinCodeCallback(const std::string &pkgName) override; + int32_t OnDmServiceDied(); + private: DeviceManagerImpl() = default; ~DeviceManagerImpl() = default; diff --git a/interfaces/inner_kits/native_cpp/include/dm_publish_info.h b/interfaces/inner_kits/native_cpp/include/dm_publish_info.h index ed35273704d76736acdf7143cc1652f2b6081dc1..f4a68982c5a31b29c1c65f3c057144beedb7bf80 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_publish_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_publish_info.h @@ -17,6 +17,7 @@ #define OHOS_DM_PUBLISH_INFO_H #include +#include #include "dm_subscribe_info.h" diff --git a/interfaces/inner_kits/native_cpp/include/dm_subscribe_info.h b/interfaces/inner_kits/native_cpp/include/dm_subscribe_info.h index 603e242109cc3c284491f8e0ee110c9f04cb62b9..2fb8dc37b6ee4d88d3300619e8edbf045a5eb776 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_subscribe_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_subscribe_info.h @@ -17,6 +17,7 @@ #define OHOS_DM_SUBSCRIBE_INFO_H #include +#include #define DM_MAX_DEVICE_CAPABILITY_LEN 65 diff --git a/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h b/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h index 1e59131fe8dad1853fd53a7e6aadd4e105a4ab07..fb6c9136bfbf94f165bfb29ca991ec64ac214739 100644 --- a/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h +++ b/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h @@ -52,9 +52,13 @@ public: void UnRegisterVerifyAuthenticationCallback(const std::string &pkgName); void RegisterDeviceManagerFaCallback(const std::string &pkgName, std::shared_ptr callback); void UnRegisterDeviceManagerFaCallback(const std::string &pkgName); + void RegisterCredentialCallback(const std::string &pkgName, std::shared_ptr callback); void UnRegisterCredentialCallback(const std::string &pkgName); + void RegisterNotifyPinCodeCallback(const std::string &pkgName, std::shared_ptr callback); + void UnRegisterNotifyPinCodeCallback(const std::string &pkgName); + public: void OnRemoteDied(); void OnDeviceOnline(const std::string &pkgName, const DmDeviceInfo &deviceInfo); @@ -69,7 +73,9 @@ public: uint32_t status, uint32_t reason); void OnVerifyAuthResult(const std::string &pkgName, const std::string &deviceId, int32_t resultCode, int32_t flag); void OnUiCall(std::string &pkgName, std::string ¶mJson); + void OnPinInput(std::string &pkgName, std::string &pinCode); void OnCredentialResult(const std::string &pkgName, int32_t &action, const std::string &credentialResult); + void OnGeneratePinCode(const std::string &pkgName, const std::string &pinCode); private: #if !defined(__LITEOS_M__) @@ -83,6 +89,7 @@ private: std::map> dmInitCallback_; std::map> dmUiCallback_; std::map> credentialCallback_; + std::map> pinCodeCallback_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp index cf063a9e1762e12b55de907fab539b486e48859f..a337c9f1f1a8f06ee36e1c2f3d0623c0177f5f85 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -42,6 +42,7 @@ #include "ipc_unpublish_req.h" #include "ipc_verify_authenticate_req.h" #include "ipc_register_dev_state_callback_req.h" +#include "ipc_set_auth_pincode_req.h" #include "securec.h" namespace OHOS { @@ -293,7 +294,6 @@ int32_t DeviceManagerImpl::PublishDeviceDiscovery(const std::string &pkgName, co LOGE("PublishDeviceDiscovery error: Failed with ret %d", ret); return ret; } - LOGI("PublishDeviceDiscovery completed, pkgName: %s", pkgName.c_str()); return DM_OK; } @@ -792,6 +792,58 @@ int32_t DeviceManagerImpl::NotifyEvent(const std::string &pkgName, const int32_t return DM_OK; } +int32_t DeviceManagerImpl::SetAuthPinCode(const std::string &pkgName, const std::string &pinCode) +{ + if (pkgName.empty() || pinCode.empty()) { + LOGE("SetAuthPinCode error: invalid value"); + return ERR_DM_INPUT_PARA_INVALID; + } + LOGI("DeviceManagerImpl::SetAuthPinCode start, pkgName: %s", pkgName.c_str()); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + req->SetPkgName(pkgName); + req->SetPinCode(pinCode); + int32_t ret = ipcClientProxy_->SendRequest(SET_AUTH_PINCODE, req, rsp); + if (ret != DM_OK) { + LOGE("SetAuthPinCode error: Send Request failed ret: %d", ret); + SysEventWrite(std::string(DM_SEND_REQUEST_FAILED), DM_HISYEVENT_BEHAVIOR, + std::string(DM_SEND_REQUEST_FAILED_MSG)); + return ERR_DM_IPC_SEND_REQUEST_FAILED; + } + SysEventWrite(std::string(DM_SEND_REQUEST_SUCCESS), DM_HISYEVENT_BEHAVIOR, + std::string(DM_SEND_REQUEST_SUCCESS_MSG)); + ret = rsp->GetErrCode(); + if (ret != DM_OK) { + LOGE("SetAuthPinCode error: Failed with ret %d", ret); + return ret; + } + DmTraceEnd(); + LOGI("SetAuthPinCode completed, pkgName: %s", pkgName.c_str()); + return DM_OK; +} + +int32_t DeviceManagerImpl::RegNotifyPinCodeCallback(const std::string &pkgName, std::shared_ptr callback) +{ + if (pkgName.empty() || callback == nullptr) { + LOGE("SetAuthPinCode error: invalid value"); + return ERR_DM_INPUT_PARA_INVALID; + } + LOGI("RegNotifyPinCodeCallback start, pkgName: %s", pkgName.c_str()); + DeviceManagerNotify::GetInstance().RegisterNotifyPinCodeCallback(pkgName, callback); + return DM_OK; +} + +int32_t DeviceManagerImpl::UnRegNotifyPinCodeCallback(const std::string &pkgName) +{ + if (pkgName.empty()) { + LOGE("UnRegNotifyPinCodeCallback Invalid parameter, pkgName is empty."); + return ERR_DM_INPUT_PARA_INVALID; + } + LOGI("UnRegNotifyPinCodeCallback start, pkgName: %s", pkgName.c_str()); + DeviceManagerNotify::GetInstance().UnRegisterNotifyPinCodeCallback(pkgName); + return DM_OK; +} + int32_t DeviceManagerImpl::OnDmServiceDied() { LOGI("OnDmServiceDied begin"); diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp index f51c1450a037ef430165ccbe591ad9730ef5a60c..32b5b3b610d12730cb224779521ca2b357dda913 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp @@ -40,6 +40,7 @@ #include "ipc_unpublish_req.h" #include "ipc_unauthenticate_device_req.h" #include "ipc_verify_authenticate_req.h" +#include "ipc_set_auth_pincode_req.h" #include "securec.h" namespace OHOS { class IRemoteObject; } @@ -739,5 +740,36 @@ ON_IPC_READ_RESPONSE(NOTIFY_EVENT, MessageParcel &reply, std::shared_ptr pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } + +ON_IPC_SET_REQUEST(SET_AUTH_PINCODE, std::shared_ptr pBaseReq, MessageParcel &data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + std::string pinCode = pReq->GetPinCode(); + if (!data.WriteString(pkgName)) { + LOGE("write pkgName failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + if (!data.WriteString(pinCode)) { + LOGE("write pinCode failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(SET_AUTH_PINCODE, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DM_OK; +} + +ON_IPC_CMD(GENERATE_PINCODE, MessageParcel &data, MessageParcel &reply) +{ + std::string pkgName = data.ReadString(); + std::string pinCode = data.ReadString(); + DeviceManagerNotify::GetInstance().OnGeneratePinCode(pkgName, pinCode); + reply.WriteInt32(DM_OK); + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp index def8d7cb58d764255ec6feb0fac0d6fe058bba9d..fad34b3affb6d04a401b8820714c0c86aae4e813 100644 --- a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp +++ b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp @@ -217,6 +217,18 @@ void DeviceManagerNotify::UnRegisterCredentialCallback(const std::string &pkgNam credentialCallback_.erase(pkgName); } +void DeviceManagerNotify::RegisterNotifyPinCodeCallback(const std::string &pkgName, std::shared_ptr callback) +{ + std::lock_guard autoLock(lock_); + pinCodeCallback_[pkgName] = callback; +} + +void DeviceManagerNotify::UnRegisterNotifyPinCodeCallback(const std::string &pkgName) +{ + std::lock_guard autoLock(lock_); + pinCodeCallback_.erase(pkgName); +} + void DeviceManagerNotify::OnRemoteDied() { LOGW("DeviceManagerNotify::OnRemoteDied"); @@ -557,5 +569,29 @@ void DeviceManagerNotify::OnCredentialResult(const std::string &pkgName, int32_t } tempCbk->OnCredentialResult(action, credentialResult); } + +void DeviceManagerNotify::OnGeneratePinCode(const std::string &pkgName, const std::string &pinCode) +{ + if (pkgName.empty() || pinCode.empty()) { + LOGE("DeviceManagerNotify::OnGeneratePinCode error: Invalid parameter"); + return; + } + LOGI("DeviceManagerNotify::OnGeneratePinCode in, pkgName:%s", pkgName.c_str()); + std::shared_ptr tempCbk; + { + std::lock_guard autoLock(lock_); + if (pinCodeCallback_.count(pkgName) == 0) { + LOGE("DeviceManagerNotify::OnGeneratePinCode error, pincode callback not register for pkgName %s.", + pkgName.c_str()); + return; + } + tempCbk = pinCodeCallback_[pkgName]; + } + if (tempCbk == nullptr) { + LOGE("OnGeneratePinCode error, registered pincode callback is nullptr."); + return; + } + tempCbk->OnSet(pinCode); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/kits/BUILD.gn b/interfaces/kits/BUILD.gn index 8aaf23fbd565bcf3858df83b390615aee71a567c..a454cad1725b6dec54f38d9ff02c8ea279d8a37f 100644 --- a/interfaces/kits/BUILD.gn +++ b/interfaces/kits/BUILD.gn @@ -15,7 +15,7 @@ import("//build/ohos.gni") group("devicemanager_native_js") { deps = [] - if (support_jsapi) { - deps += [ "./js:devicemanager" ] - } + # if (support_jsapi) { + # deps += [ "./js:devicemanager" ] + # } } diff --git a/services/implementation/BUILD.gn b/services/implementation/BUILD.gn index 126232e24e04a72bb07d1f3a59f125802c9960eb..c338e958c7b4b6d963b5c6e7d013991ea290fa28 100644 --- a/services/implementation/BUILD.gn +++ b/services/implementation/BUILD.gn @@ -127,11 +127,13 @@ if (defined(ohos_lite)) { ] } } -} else if (!support_jsapi) { - group("devicemanagerserviceimpl") { - deps = [] - } -} else { +} +# else if (!support_jsapi) { +# group("devicemanagerserviceimpl") { +# deps = [] +# } +# } +else { config("devicemanagerserviceimpl_config") { include_dirs = [ "include", @@ -183,7 +185,7 @@ if (defined(ohos_lite)) { "src/authentication/showconfirm/standard/show_confirm.cpp", "src/config/dm_config_manager.cpp", "src/credential/dm_credential_manager.cpp", - "src/dependency/commonevent/dm_common_event_manager.cpp", + # "src/dependency/commonevent/dm_common_event_manager.cpp", "src/dependency/hichain/hichain_connector.cpp", "src/dependency/multipleuser/multiple_user_connector.cpp", "src/dependency/softbus/softbus_connector.cpp", @@ -205,7 +207,7 @@ if (defined(ohos_lite)) { ] deps = [ - "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + # "${ability_runtime_innerkits_path}/ability_manager:ability_manager", "${innerkits_path}/native_cpp:devicemanagersdk", "${utils_path}:devicemanagerutils", "//base/security/device_auth/services:deviceauth_sdk", @@ -220,10 +222,10 @@ if (defined(ohos_lite)) { } external_deps = [ - "ability_base:want", + # "ability_base:want", "c_utils:utils", - "common_event_service:cesfwk_core", - "common_event_service:cesfwk_innerkits", + # "common_event_service:cesfwk_core", + # "common_event_service:cesfwk_innerkits", "dsoftbus:softbus_client", "init:libbegetutil", "ipc:ipc_core", diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 163361a3c7eef4477af3f7eed1c6813f0ff166b6..bf4372b3d4e85e3a4dadb6088b5e0383170eb6e0 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -345,6 +345,7 @@ public: */ void ShowStartAuthDialog(); + int32_t SetAuthPinCode(const std::string &pkgName, const std::string &pinCode); /** * @tc.name: DmAuthManager::GetAuthenticationParam * @tc.desc: Get Authentication Param of the DeviceManager Authenticate Manager diff --git a/services/implementation/include/device_manager_service_impl.h b/services/implementation/include/device_manager_service_impl.h index 0eec8291486767953c66a84a43b84c583ff4662e..a4bac4888ebc7946e0ad3a03a501245e04af5f4c 100644 --- a/services/implementation/include/device_manager_service_impl.h +++ b/services/implementation/include/device_manager_service_impl.h @@ -21,7 +21,7 @@ #include "dm_ability_manager.h" #include "dm_auth_manager.h" -#include "dm_common_event_manager.h" +// #include "dm_common_event_manager.h" #include "dm_credential_manager.h" #include "dm_device_info.h" #include "dm_device_state_manager.h" @@ -88,6 +88,8 @@ public: int32_t NotifyEvent(const std::string &pkgName, const int32_t eventId, const std::string &event); + int32_t SetAuthPinCode(const std::string &pkgName, const std::string &pinCode); + void LoadHardwareFwkService(); private: int32_t PraseNotifyEventJson(const std::string &event, nlohmann::json &jsonObject); @@ -100,7 +102,7 @@ private: std::shared_ptr abilityMgr_; std::shared_ptr hiChainConnector_; std::shared_ptr credentialMgr_; - std::shared_ptr commonEventManager_; + // std::shared_ptr commonEventManager_; }; using CreateDMServiceFuncPtr = IDeviceManagerServiceImpl *(*)(void); diff --git a/services/implementation/src/ability/standard/dm_ability_manager.cpp b/services/implementation/src/ability/standard/dm_ability_manager.cpp index f045fcaab84c662370f5f65fc2f473fd6bb2d925..110070b37cf71348a47e846c3e9a53c66afcfaaf 100644 --- a/services/implementation/src/ability/standard/dm_ability_manager.cpp +++ b/services/implementation/src/ability/standard/dm_ability_manager.cpp @@ -15,7 +15,7 @@ #include "dm_ability_manager.h" -#include "ability_manager_client.h" +// #include "ability_manager_client.h" #include "dm_constants.h" #include "dm_log.h" #include "parameter.h" @@ -30,18 +30,18 @@ const std::string abilityName = "com.ohos.devicemanagerui.ConfirmServiceExtAbili AbilityStatus DmAbilityManager::StartAbility() { - char localDeviceId[DEVICE_UUID_LENGTH] = {0}; - GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); - std::string deviceId = localDeviceId; - AAFwk::Want want; - AppExecFwk::ElementName element(deviceId, bundleName, abilityName); - want.SetElement(element); - AAFwk::AbilityManagerClient::GetInstance()->Connect(); - ErrCode result = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want); - if (result != 0) { - LOGE("Start Ability failed, error value = %d", (int32_t)result); - return AbilityStatus::ABILITY_STATUS_FAILED; - } + // char localDeviceId[DEVICE_UUID_LENGTH] = {0}; + // GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); + // std::string deviceId = localDeviceId; + // AAFwk::Want want; + // AppExecFwk::ElementName element(deviceId, bundleName, abilityName); + // want.SetElement(element); + // AAFwk::AbilityManagerClient::GetInstance()->Connect(); + // ErrCode result = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want); + // if (result != 0) { + // LOGE("Start Ability failed, error value = %d", (int32_t)result); + // return AbilityStatus::ABILITY_STATUS_FAILED; + // } return AbilityStatus::ABILITY_STATUS_SUCCESS; } } // namespace DistributedHardware diff --git a/services/implementation/src/authentication/auth_message_processor.cpp b/services/implementation/src/authentication/auth_message_processor.cpp index 80a2f586c4f3948bd091b96d9724e8c55298ff3d..d14c6f609f800c038b1a2aed3f7c06b5659bcf30 100644 --- a/services/implementation/src/authentication/auth_message_processor.cpp +++ b/services/implementation/src/authentication/auth_message_processor.cpp @@ -65,6 +65,7 @@ std::vector AuthMessageProcessor::CreateAuthRequestMessage() jsonObj[TAG_TARGET] = authRequestContext_->targetPkgName; jsonObj[TAG_HOST] = authRequestContext_->hostPkgName; } + jsonObj[TAG_HOST] = authRequestContext_->hostPkgName; jsonObj[TAG_APP_NAME] = authRequestContext_->appName; jsonObj[TAG_APP_DESCRIPTION] = authRequestContext_->appDesc; jsonObj[TAG_APP_ICON] = authRequestContext_->appIcon; @@ -235,6 +236,7 @@ int32_t AuthMessageProcessor::ParseAuthRequestMessage(nlohmann::json &json) authResponseContext_->targetPkgName = json[TAG_TARGET].get(); authResponseContext_->appName = json[TAG_APP_NAME].get(); authResponseContext_->appThumbnail = ""; + authResponseContext_->hostPkgName = json[TAG_HOST].get(); } if (idx < sliceNum && IsString(json, TAG_APP_THUMBNAIL)) { diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 4b0fbd912f1e89a738a2892da12d6573a7fe6d7e..0fb6c71d7d4fa13bbd421fae783435b3acbf135f 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -16,6 +16,7 @@ #include "dm_auth_manager.h" #include +#include #include "auth_message_processor.h" #include "dm_ability_manager.h" @@ -204,7 +205,7 @@ int32_t DmAuthManager::VerifyAuthentication(const std::string &authParam) return DM_OK; } -void DmAuthManager::OnSessionOpened(int32_t sessionId, int32_t sessionSide, int32_t result) +void DmAuthManager::OnSessionOpened(int32_t sessionId, int32_t sessionSide, int32_t result) // sessionSide = IS_SERVER ? 0 : 1 { LOGI("DmAuthManager::OnSessionOpened sessionId = %d result = %d", sessionId, result); if (sessionSide == AUTH_SESSION_SIDE_SERVER) { @@ -358,6 +359,9 @@ void DmAuthManager::OnGroupCreated(int64_t requestId, const std::string &groupId LOGI("DmAuthManager::OnGroupCreated start group id %s", GetAnonyString(groupId).c_str()); authResponseContext_->groupId = groupId; authResponseContext_->code = pinCode; + listener_->OnGeneratePinCode(authResponseContext_->hostPkgName.c_str(), std::to_string(pinCode)); + const char* prefix = "------------------------------------"; + LOGI("\n%s PINCODE %s\n\t\t\t\t\t%d\n%s PINCODE %s", prefix, prefix, pinCode, prefix, prefix); authMessageProcessor_->SetResponseContext(authResponseContext_); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_RESP_AUTH); softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); @@ -501,6 +505,7 @@ void DmAuthManager::RespNegotiate(const int32_t &sessionId) return; } } + jsonObject[TAG_CRYPTO_SUPPORT] = false; message = jsonObject.dump(); softbusConnector_->GetSoftbusSession()->SendData(sessionId, message); @@ -531,6 +536,7 @@ void DmAuthManager::SendAuthRequest(const int32_t &sessionId) return; } } + if (authResponseContext_->reply == ERR_DM_AUTH_PEER_REJECT) { if (hiChainConnector_->IsDevicesInGroup(authResponseContext_->localDeviceId, authRequestContext_->localDeviceId)) { @@ -555,6 +561,7 @@ int32_t DmAuthManager::StartAuthProcess(const int32_t &action) LOGE("failed to StartAuthProcess because authResponseContext_ is nullptr"); return ERR_DM_AUTH_NOT_START; } + LOGI("DmAuthManager::StartAuthProcess"); authResponseContext_->reply = action; if (authResponseContext_->reply == USER_OPERATION_TYPE_ALLOW_AUTH && @@ -787,20 +794,26 @@ int32_t DmAuthManager::GetPinCode() void DmAuthManager::ShowConfigDialog() { - if (authResponseContext_ == nullptr) { - LOGE("failed to ShowConfigDialog because authResponseContext_ is nullptr"); - return; - } + // if (authResponseContext_ == nullptr) { + // LOGE("failed to ShowConfigDialog because authResponseContext_ is nullptr"); + // return; + // } + // LOGI("ShowConfigDialog start"); + // dmAbilityMgr_ = std::make_shared(); + // nlohmann::json jsonObj; + // jsonObj[TAG_AUTH_TYPE] = AUTH_TYPE_PIN; + // jsonObj[TAG_TOKEN] = authResponseContext_->token; + // jsonObj[TARGET_PKG_NAME_KEY] = authResponseContext_->targetPkgName; + // jsonObj.dump(); + // const std::string params = jsonObj.dump(); + // std::shared_ptr showConfirm_ = std::make_shared(); + // showConfirm_->ShowConfirmDialog(params, shared_from_this(), dmAbilityMgr_); + // LOGI("ShowConfigDialog end"); LOGI("ShowConfigDialog start"); - dmAbilityMgr_ = std::make_shared(); - nlohmann::json jsonObj; - jsonObj[TAG_AUTH_TYPE] = AUTH_TYPE_PIN; - jsonObj[TAG_TOKEN] = authResponseContext_->token; - jsonObj[TARGET_PKG_NAME_KEY] = authResponseContext_->targetPkgName; - jsonObj.dump(); - const std::string params = jsonObj.dump(); - std::shared_ptr showConfirm_ = std::make_shared(); - showConfirm_->ShowConfirmDialog(params, shared_from_this(), dmAbilityMgr_); + int32_t ret = OnUserOperation(0, ""); + if (ret != 0) { + LOGI("ShowConfigDialog failed to set user operation"); + } LOGI("ShowConfigDialog end"); } @@ -817,14 +830,24 @@ void DmAuthManager::ShowAuthInfoDialog() authPtr_->ShowAuthInfo(authParam, shared_from_this()); } -void DmAuthManager::ShowStartAuthDialog() +int32_t DmAuthManager::SetAuthPinCode(const std::string &pkgName, const std::string &pinCode) { - if (authResponseContext_ == nullptr) { - LOGE("failed to ShowStartAuthDialog because authResponseContext_ is nullptr"); - return; + int32_t ret = OnUserOperation(5, pinCode); + if (ret != 0) { + LOGE("ShowStartAuthDialog OnUserOperation failed\n"); } - LOGI("DmAuthManager::ShowStartAuthDialog start"); - authPtr_->StartAuth(authResponseContext_->authToken, shared_from_this()); + return ret; +} + +void DmAuthManager::ShowStartAuthDialog() +{ + // if (authResponseContext_ == nullptr) { + // LOGE("failed to ShowStartAuthDialog because authResponseContext_ is nullptr"); + // return; + // } + // LOGI("DmAuthManager::ShowStartAuthDialog start"); + // authPtr_->StartAuth(authResponseContext_->authToken, shared_from_this()); + // LOGI("DmAuthManager::ShowStartAuthDialog end"); } int32_t DmAuthManager::GetAuthenticationParam(DmAuthParam &authParam) diff --git a/services/implementation/src/dependency/multipleuser/multiple_user_connector.cpp b/services/implementation/src/dependency/multipleuser/multiple_user_connector.cpp index dbd87e87aeeb20188a88a98b345ea4b56c202ae9..5b7b8f911be8a6a671a4e0369e49896b3d2f0cdc 100644 --- a/services/implementation/src/dependency/multipleuser/multiple_user_connector.cpp +++ b/services/implementation/src/dependency/multipleuser/multiple_user_connector.cpp @@ -14,6 +14,7 @@ */ #include "multiple_user_connector.h" +#include "parameter.h" #include "dm_log.h" #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) @@ -43,7 +44,10 @@ int32_t MultipleUserConnector::GetCurrentAccountUserID(void) } return ids[0]; #else // OS_ACCOUNT_PART_EXISTS - return DEFAULT_OS_ACCOUNT_ID; + int userId; + if (GetOsAccount(&userId) != 0) + userId = DEFAULT_OS_ACCOUNT_ID; + return userId; #endif // OS_ACCOUNT_PART_EXISTS #endif } diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index a78109c18a59c0c9660f98f4117e7799150a5b57..9742c52f5718a7dda8dc76f2bd20cd3b39e34073 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -23,11 +23,11 @@ #include "dm_log.h" #include "multiple_user_connector.h" #include "permission_manager.h" -#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) -#include "dm_common_event_manager.h" -#include "common_event_support.h" -using namespace OHOS::EventFwk; -#endif +// #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) +// #include "dm_common_event_manager.h" +// #include "common_event_support.h" +// using namespace OHOS::EventFwk; +// #endif namespace OHOS { namespace DistributedHardware { @@ -74,16 +74,16 @@ int32_t DeviceManagerServiceImpl::Initialize(const std::shared_ptr(); - } - CommomEventCallback callback = std::bind(&DmAuthManager::UserSwitchEventCallback, *authMgr_.get(), - std::placeholders::_1); - if (commonEventManager_->SubscribeServiceEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED, callback)) { - LOGI("subscribe service user switch common event success"); - } -#endif +// #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) +// if (commonEventManager_ == nullptr) { +// commonEventManager_ = std::make_shared(); +// } +// CommomEventCallback callback = std::bind(&DmAuthManager::UserSwitchEventCallback, *authMgr_.get(), +// std::placeholders::_1); +// if (commonEventManager_->SubscribeServiceEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED, callback)) { +// LOGI("subscribe service user switch common event success"); +// } +// #endif LOGI("Init success, singleton initialized"); return DM_OK; } @@ -91,9 +91,9 @@ int32_t DeviceManagerServiceImpl::Initialize(const std::shared_ptrGetSoftbusSession()->UnRegisterSessionCallback(); hiChainConnector_->UnRegisterHiChainCallback(); authMgr_ = nullptr; @@ -389,6 +389,20 @@ int32_t DeviceManagerServiceImpl::NotifyEvent(const std::string &pkgName, const return DM_OK; } +int32_t DeviceManagerServiceImpl::SetAuthPinCode(const std::string &pkgName, const std::string &pinCode) +{ + LOGI("SetAuthPinCode begin, pkgName : %s", pkgName.c_str()); + if (!PermissionManager::GetInstance().CheckPermission()) { + LOGI("The caller does not have permission to call"); + return ERR_DM_NO_PERMISSION; + } + if (pkgName.empty() || pinCode.empty()) { + LOGE("DeviceManagerServiceImpl::SetAuthPinCode failed, pkgName is %s", pkgName.c_str()); + return ERR_DM_INPUT_PARA_INVALID; + } + return authMgr_->SetAuthPinCode(pkgName, pinCode); +} + void DeviceManagerServiceImpl::LoadHardwareFwkService() { DmDistributedHardwareLoad::GetInstance().LoadDistributedHardwareFwk(); diff --git a/services/service/BUILD.gn b/services/service/BUILD.gn index bb353c126ecec1d19702773a433825abcd9a6594..0e301f97369126f1f1828d3258bd0f3c3b2ac001 100644 --- a/services/service/BUILD.gn +++ b/services/service/BUILD.gn @@ -180,11 +180,13 @@ if (defined(ohos_lite)) { ] } } -} else if (!support_jsapi) { - group("devicemanagerservice") { - deps = [] - } -} else { +} +# else if (!support_jsapi) { +# group("devicemanagerservice") { +# deps = [] +# } +# } +else { config("devicemanagerservice_config") { include_dirs = [ "include", @@ -241,3 +243,4 @@ if (defined(ohos_lite)) { part_name = "device_manager" } } + diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index d6038878df826f3168c295139032a0fd0a9c659d..25b5911e6e9242edce191a360fde0ccea2865c34 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -110,6 +110,8 @@ public: int32_t NotifyEvent(const std::string &pkgName, const int32_t eventId, const std::string &event); void LoadHardwareFwkService(); + + int32_t SetAuthPinCode(const std::string &pkgName, const std::string &pinCode); private: bool isImplsoLoaded_ = false; std::mutex isImplLoadLock_; diff --git a/services/service/include/device_manager_service_listener.h b/services/service/include/device_manager_service_listener.h index 43fa5668f990964a9ee5c95e0d963b8b76facfc8..9851b946d6b9934da2798662c20ced03a5213671 100644 --- a/services/service/include/device_manager_service_listener.h +++ b/services/service/include/device_manager_service_listener.h @@ -52,6 +52,8 @@ public: void OnUiCall(std::string &pkgName, std::string ¶mJson); void OnCredentialResult(const std::string &pkgName, int32_t action, const std::string &resultInfo); + + void OnGeneratePinCode(const std::string &pkgName, const std::string &pinCode); private: #if !defined(__LITEOS_M__) IpcServerListener ipcServerListener_; diff --git a/services/service/include/idevice_manager_service_impl.h b/services/service/include/idevice_manager_service_impl.h index b7f118b23ddb265d34f63c49eaf527cda1aadc6c..c4a2c09a05068f1ccd34782c9e03567c670911f3 100644 --- a/services/service/include/idevice_manager_service_impl.h +++ b/services/service/include/idevice_manager_service_impl.h @@ -196,6 +196,8 @@ public: */ virtual int32_t NotifyEvent(const std::string &pkgName, const int32_t eventId, const std::string &event); + virtual int32_t SetAuthPinCode(const std::string &pkgName, const std::string &pinCode); + /** * @tc.name: DeviceManagerService::LoadHardwareFwkService * @tc.desc: LoadHardwareFwkService diff --git a/services/service/include/idevice_manager_service_listener.h b/services/service/include/idevice_manager_service_listener.h index 13afa6e342e557f7fdcb269132e582e3ec614677..0a905c5f08c2d068628ac88e3d4c3ce898a25aac 100644 --- a/services/service/include/idevice_manager_service_listener.h +++ b/services/service/include/idevice_manager_service_listener.h @@ -91,6 +91,8 @@ public: * @tc.type: FUNC */ virtual void OnCredentialResult(const std::string &pkgName, int32_t action, const std::string &resultInfo); + + virtual void OnGeneratePinCode(const std::string &pkgName, const std::string &pinCode); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/include/ipc/standard/ipc_server_listener.h b/services/service/include/ipc/standard/ipc_server_listener.h index 0ff7bb806dacd003eab4eb93bfc54b8a01e242a0..02283724f301d81fd2b996eff2a33dd0325feec7 100644 --- a/services/service/include/ipc/standard/ipc_server_listener.h +++ b/services/service/include/ipc/standard/ipc_server_listener.h @@ -17,6 +17,7 @@ #define OHOS_DM_IPC_SERVER_LISTENER_H #include +#include #include "ipc_req.h" #include "ipc_rsp.h" diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 904bca7c1f7ebe92e4d895b2a24c88243c46d52d..77ba800e8392720806c57ba631372de1d77c6952 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -464,6 +464,19 @@ int32_t DeviceManagerService::NotifyEvent(const std::string &pkgName, const int3 return dmServiceImpl_->NotifyEvent(pkgName, eventId, event); } +int32_t DeviceManagerService::SetAuthPinCode(const std::string &pkgName, const std::string &pinCode) +{ + if (pkgName.empty() || pinCode.empty()) { + LOGE("DeviceManagerService::SetAuthPinCode error: Invalid parameter, pkgName: %s", pkgName.c_str()); + return ERR_DM_INPUT_PARA_INVALID; + } + if (!IsDMServiceImplReady()) { + LOGE("SetAuthPinCode failed, instance not init or init failed."); + return ERR_DM_NOT_INIT; + } + return dmServiceImpl_->SetAuthPinCode(pkgName, pinCode); +} + void DeviceManagerService::LoadHardwareFwkService() { std::string extra; diff --git a/services/service/src/device_manager_service_listener.cpp b/services/service/src/device_manager_service_listener.cpp index 567b427cf4428a454d3c6803e51b3bb8f7a13632..00eb18dcb2589ae57f146692da6be97d538eb58c 100644 --- a/services/service/src/device_manager_service_listener.cpp +++ b/services/service/src/device_manager_service_listener.cpp @@ -13,6 +13,9 @@ * limitations under the License. */ +#include +#include + #include "device_manager_service_listener.h" #include "dm_constants.h" @@ -24,6 +27,7 @@ #include "ipc_notify_discover_result_req.h" #include "ipc_notify_publish_result_req.h" #include "ipc_notify_verify_auth_result_req.h" +#include "ipc_set_auth_pincode_req.h" namespace OHOS { namespace DistributedHardware { @@ -107,6 +111,16 @@ void DeviceManagerServiceListener::OnAuthResult(const std::string &pkgName, cons ipcServerListener_.SendRequest(SERVER_AUTH_RESULT, pReq, pRsp); } +void DeviceManagerServiceListener::OnGeneratePinCode(const std::string &pkgName, const std::string &pinCode) +{ + std::shared_ptr pReq = std::make_shared(); + std::shared_ptr pRsp = std::make_shared(); + + pReq->SetPkgName(pkgName); + pReq->SetPinCode(pinCode); + ipcServerListener_.SendRequest(GENERATE_PINCODE, pReq, pRsp); +} + void DeviceManagerServiceListener::OnVerifyAuthResult(const std::string &pkgName, const std::string &deviceId, int32_t resultCode, const std::string &flag) { diff --git a/services/service/src/ipc/lite/ipc_server_listener.cpp b/services/service/src/ipc/lite/ipc_server_listener.cpp index 0f9b186b60d78d1807d274f86ab001aa3622bc90..efb467c594ff82409f514b01022e66459f6c11d8 100644 --- a/services/service/src/ipc/lite/ipc_server_listener.cpp +++ b/services/service/src/ipc/lite/ipc_server_listener.cpp @@ -1,95 +1,95 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// /* +// * Copyright (c) 2022 Huawei Device Co., Ltd. +// * Licensed under the Apache License, Version 2.0 (the "License"); +// * you may not use this file except in compliance with the License. +// * You may obtain a copy of the License at +// * +// * http://www.apache.org/licenses/LICENSE-2.0 +// * +// * Unless required by applicable law or agreed to in writing, software +// * distributed under the License is distributed on an "AS IS" BASIS, +// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// * See the License for the specific language governing permissions and +// * limitations under the License. +// */ -#include "ipc_server_listener.h" +// #include "ipc_server_listener.h" -#include "dm_constants.h" -#include "dm_log.h" -#include "ipc_cmd_register.h" -#include "ipc_def.h" -#include "ipc_server_listenermgr.h" +// #include "dm_constants.h" +// #include "dm_log.h" +// #include "ipc_cmd_register.h" +// #include "ipc_def.h" +// #include "ipc_server_listenermgr.h" -namespace OHOS { -namespace DistributedHardware { -void IpcServerListener::CommonSvcToIdentity(CommonSvcId *svcId, SvcIdentity *identity) -{ - identity->handle = svcId->handle; - identity->token = svcId->token; - identity->cookie = svcId->cookie; -} +// namespace OHOS { +// namespace DistributedHardware { +// void IpcServerListener::CommonSvcToIdentity(CommonSvcId *svcId, SvcIdentity *identity) +// { +// identity->handle = svcId->handle; +// identity->token = svcId->token; +// identity->cookie = svcId->cookie; +// } -int32_t IpcServerListener::GetIdentityByPkgName(std::string &name, SvcIdentity *svc) -{ - CommonSvcId svcId; - if (IpcServerListenermgr::GetInstance().GetListenerByPkgName(name, &svcId) != DM_OK) { - LOGE("get identity failed."); - return ERR_DM_FAILED; - } - CommonSvcToIdentity(&svcId, svc); - return DM_OK; -} +// int32_t IpcServerListener::GetIdentityByPkgName(std::string &name, SvcIdentity *svc) +// { +// CommonSvcId svcId; +// if (IpcServerListenermgr::GetInstance().GetListenerByPkgName(name, &svcId) != DM_OK) { +// LOGE("get identity failed."); +// return ERR_DM_FAILED; +// } +// CommonSvcToIdentity(&svcId, svc); +// return DM_OK; +// } -int32_t IpcServerListener::SendRequest(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) -{ - std::string pkgName = req->GetPkgName(); - SvcIdentity svc; - if (GetIdentityByPkgName(pkgName, &svc) != DM_OK) { - LOGE("OnDeviceFound callback get listener failed."); - return ERR_DM_FAILED; - } +// int32_t IpcServerListener::SendRequest(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) +// { +// std::string pkgName = req->GetPkgName(); +// SvcIdentity svc; +// if (GetIdentityByPkgName(pkgName, &svc) != DM_OK) { +// LOGE("OnDeviceFound callback get listener failed."); +// return ERR_DM_FAILED; +// } - IpcIo io; - uint8_t data[MAX_DM_IPC_LEN] = {0}; - if (IpcCmdRegister::GetInstance().SetRequest(cmdCode, req, io, data, MAX_DM_IPC_LEN) != DM_OK) { - LOGE("SetRequest failed cmdCode:%d", cmdCode); - return ERR_DM_FAILED; - } +// IpcIo io; +// uint8_t data[MAX_DM_IPC_LEN] = {0}; +// if (IpcCmdRegister::GetInstance().SetRequest(cmdCode, req, io, data, MAX_DM_IPC_LEN) != DM_OK) { +// LOGE("SetRequest failed cmdCode:%d", cmdCode); +// return ERR_DM_FAILED; +// } - MessageOption option; - MessageOptionInit(&option); - option.flags = TF_OP_ASYNC; - if (::SendRequest(svc, cmdCode, &io, nullptr, option, nullptr) != DM_OK) { - LOGI("SendRequest failed cmdCode:%d", cmdCode); - } - return DM_OK; -} +// MessageOption option; +// MessageOptionInit(&option); +// option.flags = TF_OP_ASYNC; +// if (::SendRequest(svc, cmdCode, &io, nullptr, option, nullptr) != DM_OK) { +// LOGI("SendRequest failed cmdCode:%d", cmdCode); +// } +// return DM_OK; +// } -int32_t IpcServerListener::SendAll(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) -{ - const std::map &listenerMap = IpcServerListenermgr::GetInstance().GetAllListeners(); - for (const auto &kv : listenerMap) { - SvcIdentity svc; - IpcIo io; - uint8_t data[MAX_DM_IPC_LEN] = {0}; - std::string pkgName = kv.first; +// int32_t IpcServerListener::SendAll(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) +// { +// const std::map &listenerMap = IpcServerListenermgr::GetInstance().GetAllListeners(); +// for (const auto &kv : listenerMap) { +// SvcIdentity svc; +// IpcIo io; +// uint8_t data[MAX_DM_IPC_LEN] = {0}; +// std::string pkgName = kv.first; - req->SetPkgName(pkgName); - if (IpcCmdRegister::GetInstance().SetRequest(cmdCode, req, io, data, MAX_DM_IPC_LEN) != DM_OK) { - LOGE("SetRequest failed cmdCode:%d", cmdCode); - continue; - } - CommonSvcId svcId = kv.second; - CommonSvcToIdentity(&svcId, &svc); - MessageOption option; - MessageOptionInit(&option); - option.flags = TF_OP_ASYNC; - if (::SendRequest(svc, cmdCode, &io, nullptr, option, nullptr) != DM_OK) { - LOGI("SendRequest failed cmdCode:%d", cmdCode); - } - } - return DM_OK; -} -} // namespace DistributedHardware -} // namespace OHOS +// req->SetPkgName(pkgName); +// if (IpcCmdRegister::GetInstance().SetRequest(cmdCode, req, io, data, MAX_DM_IPC_LEN) != DM_OK) { +// LOGE("SetRequest failed cmdCode:%d", cmdCode); +// continue; +// } +// CommonSvcId svcId = kv.second; +// CommonSvcToIdentity(&svcId, &svc); +// MessageOption option; +// MessageOptionInit(&option); +// option.flags = TF_OP_ASYNC; +// if (::SendRequest(svc, cmdCode, &io, nullptr, option, nullptr) != DM_OK) { +// LOGI("SendRequest failed cmdCode:%d", cmdCode); +// } +// } +// return DM_OK; +// } +// } // namespace DistributedHardware +// } // namespace OHOS diff --git a/services/service/src/ipc/standard/ipc_cmd_parser.cpp b/services/service/src/ipc/standard/ipc_cmd_parser.cpp index 66ccd01e872d0f331558c2abe298823233cbbee8..baf170ea3a7c1882a252ce22a0e3b17230f1326d 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -30,6 +30,7 @@ #include "ipc_notify_discover_result_req.h" #include "ipc_notify_publish_result_req.h" #include "ipc_notify_verify_auth_result_req.h" +#include "ipc_set_auth_pincode_req.h" #include "ipc_server_stub.h" namespace OHOS { @@ -642,6 +643,18 @@ ON_IPC_CMD(NOTIFY_EVENT, MessageParcel &data, MessageParcel &reply) return DM_OK; } +ON_IPC_CMD(SET_AUTH_PINCODE, MessageParcel &data, MessageParcel &reply) +{ + std::string pkgName = data.ReadString(); + std::string pinCode = data.ReadString(); + int32_t result = DeviceManagerService::GetInstance().SetAuthPinCode(pkgName, pinCode); + if (!reply.WriteInt32(result)) { + LOGE("write result failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + ON_IPC_SET_REQUEST(SERVER_CREDENTIAL_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) { if (pBaseReq == nullptr) { @@ -676,5 +689,27 @@ ON_IPC_READ_RESPONSE(SERVER_CREDENTIAL_RESULT, MessageParcel &reply, std::shared pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } + +ON_IPC_SET_REQUEST(GENERATE_PINCODE, std::shared_ptr pBaseReq, MessageParcel &data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + std::string pinCode = pReq->GetPinCode(); + if (!data.WriteString(pkgName)) { + LOGE("write pkgName failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + if (!data.WriteString(pinCode)) { + LOGE("write pinCode failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(GENERATE_PINCODE, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/test/BUILD.gn b/test/BUILD.gn index da8df87ea6e939e3405067cd439255e1eafc3858..69bdd8f1c963445f859581c718a52071c43d7d8f 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -15,11 +15,11 @@ group("test") { testonly = true deps = [] - if (support_jsapi) { + # if (support_jsapi) { deps += [ "benchmarktest:benchmarktest", "fuzztest:fuzztest", "unittest:unittest", ] - } + # } } diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 0d231c71b09de598093657cdd9e4220ba23a67a2..16b2058c326947c810e6f91637fecd9a6962e487 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -163,12 +163,12 @@ if (defined(ohos_lite)) { "${common_path}/src/ipc/standard/ipc_cmd_register.cpp", "src/dm_random.cpp", ] - if (support_jsapi) { + # if (support_jsapi) { sources += [ "src/fwkload/standard/dm_distributed_hardware_load.cpp", "src/permission/standard/permission_manager.cpp", ] - } + # } public_configs = [ ":devicemanagerutils_config" ] @@ -181,17 +181,17 @@ if (defined(ohos_lite)) { deps = [ "//third_party/mbedtls:mbedtls_shared" ] external_deps = [ - "access_token:libaccesstoken_sdk", + # "access_token:libaccesstoken_sdk", "c_utils:utils", - "hisysevent_native:libhisysevent", - "hitrace_native:hitrace_meter", + # "hisysevent_native:libhisysevent", + # "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "samgr:samgr_proxy", ] - if (support_jsapi) { - external_deps += [ "bundle_framework:appexecfwk_core" ] - } + # if (support_jsapi) { + # external_deps += [ "bundle_framework:appexecfwk_core" ] + # } subsystem_name = "distributedhardware" diff --git a/utils/src/permission/standard/permission_manager.cpp b/utils/src/permission/standard/permission_manager.cpp index 11db468c2f871b8a3e1e5f94f1216a07ed932036..2ee224aa4c37445b66fb8f6a13650918ee09d3a7 100644 --- a/utils/src/permission/standard/permission_manager.cpp +++ b/utils/src/permission/standard/permission_manager.cpp @@ -15,24 +15,24 @@ #include "permission_manager.h" -#include "bundle_constants.h" -#include "bundle_info.h" -#include "bundle_mgr_client.h" -#include "bundle_mgr_interface.h" -#include "bundle_mgr_proxy.h" +// #include "bundle_constants.h" +// #include "bundle_info.h" +// #include "bundle_mgr_client.h" +// #include "bundle_mgr_interface.h" +// #include "bundle_mgr_proxy.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" #include "system_ability_definition.h" #include "ipc_skeleton.h" -#include "access_token.h" -#include "hap_token_info.h" -#include "native_token_info.h" -#include "accesstoken_kit.h" +// #include "access_token.h" +// #include "hap_token_info.h" +// #include "native_token_info.h" +// #include "accesstoken_kit.h" #include "dm_log.h" -using namespace OHOS::AppExecFwk; -using namespace OHOS::AppExecFwk::Constants; -using namespace OHOS::Security::AccessToken; +// using namespace OHOS::AppExecFwk; +// using namespace OHOS::AppExecFwk::Constants; +// using namespace OHOS::Security::AccessToken; namespace OHOS { namespace DistributedHardware { @@ -40,49 +40,50 @@ IMPLEMENT_SINGLE_INSTANCE(PermissionManager); bool PermissionManager::CheckPermission(void) { - LOGI("Enter PermissionManager::CheckPermission"); - AccessTokenID tokenCaller = IPCSkeleton::GetCallingTokenID(); - if (tokenCaller == 0) { - LOGI("PermissionManager::tokenCaller == 0"); - return false; - } - LOGI("PermissionManager::tokenCaller ID == %d", tokenCaller); + // LOGI("Enter PermissionManager::CheckPermission"); + // AccessTokenID tokenCaller = IPCSkeleton::GetCallingTokenID(); + // if (tokenCaller == 0) { + // LOGI("PermissionManager::tokenCaller == 0"); + // return false; + // } + // LOGI("PermissionManager::tokenCaller ID == %d", tokenCaller); - ATokenTypeEnum tokenTypeFlag = AccessTokenKit::GetTokenTypeFlag(tokenCaller); - if (tokenTypeFlag == ATokenTypeEnum::TOKEN_HAP) { - int32_t uid = IPCSkeleton::GetCallingUid(); - if (uid < 0) { - LOGI("app caller uid is: %d,", uid); - return false; - } + // ATokenTypeEnum tokenTypeFlag = AccessTokenKit::GetTokenTypeFlag(tokenCaller); + // if (tokenTypeFlag == ATokenTypeEnum::TOKEN_HAP) { + // int32_t uid = IPCSkeleton::GetCallingUid(); + // if (uid < 0) { + // LOGI("app caller uid is: %d,", uid); + // return false; + // } - sptr systemAbilityManager = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (systemAbilityManager == nullptr) { - LOGE("failed to get system ability mgr."); - return false; - } - sptr remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); - if (remoteObject == nullptr) { - LOGE("failed to get bundle manager proxy."); - return false; - } + // sptr systemAbilityManager = + // SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + // if (systemAbilityManager == nullptr) { + // LOGE("failed to get system ability mgr."); + // return false; + // } + // sptr remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); + // if (remoteObject == nullptr) { + // LOGE("failed to get bundle manager proxy."); + // return false; + // } - LOGI("get bundle manager proxy success."); - sptr iBundleMgr = iface_cast(remoteObject); - if (iBundleMgr == nullptr) { - LOGI("iBundleMgr is nullptr, caller may be a process"); - return false; - } - LOGI("PermissionManager::tokenTypeFlag is hap process"); - return iBundleMgr->CheckIsSystemAppByUid(uid); - } else if (tokenTypeFlag == ATokenTypeEnum::TOKEN_NATIVE || tokenTypeFlag == ATokenTypeEnum::TOKEN_SHELL) { - LOGI("PermissionManager::tokenTypeFlag is native process"); - return true; - } else { - LOGI("PermissionManager::invalid tokenTypeFlag"); - return false; - } + // LOGI("get bundle manager proxy success."); + // sptr iBundleMgr = iface_cast(remoteObject); + // if (iBundleMgr == nullptr) { + // LOGI("iBundleMgr is nullptr, caller may be a process"); + // return false; + // } + // LOGI("PermissionManager::tokenTypeFlag is hap process"); + // return iBundleMgr->CheckIsSystemAppByUid(uid); + // } else if (tokenTypeFlag == ATokenTypeEnum::TOKEN_NATIVE || tokenTypeFlag == ATokenTypeEnum::TOKEN_SHELL) { + // LOGI("PermissionManager::tokenTypeFlag is native process"); + // return true; + // } else { + // LOGI("PermissionManager::invalid tokenTypeFlag"); + // return false; + // } + return true; } } // namespace DistributedHardware } // namespace OHOS