!1144 统一身份认证控件支持以模应用方式拉起 合入新特性分支

Merge pull request !1144 from liuhanxiong/OpenHarmony_feature_20241121
This commit is contained in:
openharmony_ci 2024-11-22 13:08:25 +00:00 committed by Gitee
commit 040e20dca4
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
64 changed files with 1893 additions and 192 deletions

View File

@ -31,6 +31,7 @@
"components": [
"ability_base",
"ability_runtime",
"ace_engine",
"bundle_framework",
"hilog",
"hicollie",

View File

@ -50,6 +50,13 @@ ohos_shared_library("userauth") {
external_deps = [
"ability_base:want",
"ability_runtime:ability_context_native",
"ability_runtime:ability_manager",
"ability_runtime:abilitykit_native",
"ability_runtime:app_context",
"ability_runtime:napi_base_context",
"ability_runtime:ui_extension",
"ace_engine:ace_uicontent",
"c_utils:utils",
"hilog:libhilog",
"ipc:ipc_single",

View File

@ -20,9 +20,12 @@
#include "nocopyable.h"
#include "ability.h"
#include "auth_common.h"
#include "auth_instance_v9.h"
#include "user_auth_callback_v10.h"
#include "user_auth_napi_client_impl.h"
namespace OHOS {
namespace UserIam {
@ -50,9 +53,11 @@ private:
UserAuthResultCode InitWidgetParam(napi_env env, napi_value value);
std::shared_ptr<JsRefHolder> GetCallback(napi_env env, napi_value value);
static napi_value DoGetEnrolledStateResult(napi_env env, EnrolledState enrolledState);
UserAuthResultCode ProcessContext(napi_env env, napi_value value);
bool CheckUIContext(const std::shared_ptr<OHOS::AbilityRuntime::Context> context);
WidgetAuthParam authParam_ = {};
WidgetParam widgetParam_ = {};
AuthParamInner authParam_ = {};
UserAuthNapiClientImpl::WidgetParamNapi widgetParam_ = {};
uint64_t contextId_ = 0;
bool isAuthStarted_ = false;

View File

@ -19,6 +19,11 @@
#include <cinttypes>
#include <string>
#include "napi_base_context.h"
#include "ui_content.h"
#include "ui_extension_context.h"
#include "ui_holder_extension_context.h"
#include "iam_logger.h"
#include "iam_ptr.h"
@ -39,6 +44,7 @@ const std::string AUTH_PARAM_REUSEUNLOCKRESULT = "reuseUnlockResult";
const std::string WIDGET_PARAM_TITLE = "title";
const std::string WIDGET_PARAM_NAVIBTNTEXT = "navigationButtonText";
const std::string WIDGET_PARAM_WINDOWMODE = "windowMode";
const std::string WIDGET_PARAM_CONTEXT = "uiContext";
const std::string NOTICETYPE = "noticeType";
const std::string REUSEMODE = "reuseMode";
const std::string REUSEDURATION = "reuseDuration";
@ -355,9 +361,72 @@ UserAuthResultCode UserAuthInstanceV10::InitWidgetParam(napi_env env, napi_value
if (errorCode != UserAuthResultCode::SUCCESS) {
return errorCode;
}
errorCode = ProcessContext(env, value);
if (errorCode != UserAuthResultCode::SUCCESS) {
return errorCode;
}
return UserAuthResultCode::SUCCESS;
}
UserAuthResultCode UserAuthInstanceV10::ProcessContext(napi_env env, napi_value value)
{
IAM_LOGI("process uiContext");
if (UserAuthNapiHelper::HasNamedProperty(env, value, WIDGET_PARAM_CONTEXT)) {
IAM_LOGI("widgetParam has uiContext");
napi_value napi_uiContext = UserAuthNapiHelper::GetNamedProperty(env, value, WIDGET_PARAM_CONTEXT);
napi_status ret = UserAuthNapiHelper::CheckNapiType(env, napi_uiContext, napi_object);
if (ret != napi_ok) {
IAM_LOGE("get uiContext fail: %{public}d", ret);
std::string msgStr = "Parameter error. The type of \"uiContext\" must be context.";
return UserAuthNapiHelper::ThrowErrorMsg(env, UserAuthResultCode::OHOS_INVALID_PARAM, msgStr);
}
bool stageMode = false;
ret = OHOS::AbilityRuntime::IsStageContext(env, napi_uiContext, stageMode);
if (ret != napi_ok) {
IAM_LOGE("uiContext must be stage mode: %{public}d", ret);
std::string msgStr = "Parameter error. The type of \"uiContext\" must be stage mode.";
return UserAuthNapiHelper::ThrowErrorMsg(env, UserAuthResultCode::OHOS_INVALID_PARAM, msgStr);
}
auto context = OHOS::AbilityRuntime::GetStageModeContext(env, napi_uiContext);
if (CheckUIContext(context)) {
widgetParam_.context = context;
IAM_LOGI("widgetParam has valid uiContext");
} else {
// Default as modal system
IAM_LOGI("widgetParam has invalid uiContext, not base on valid AbilityContext or UIExtensionContext.");
}
}
return UserAuthResultCode::SUCCESS;
}
bool UserAuthInstanceV10::CheckUIContext(const std::shared_ptr<AbilityRuntime::Context> context)
{
if (context == nullptr) {
IAM_LOGE("get context failed");
return false;
}
auto abilityContext = AbilityRuntime::Context::ConvertTo<AbilityRuntime::AbilityContext>(context);
if (abilityContext == nullptr) {
IAM_LOGE("abilityContext is null");
auto holderContext = AbilityRuntime::Context::ConvertTo<AbilityRuntime::UIHolderExtensionContext>(context);
if (holderContext == nullptr) {
IAM_LOGE("uiExtensionContext is null");
return false;
}
if (holderContext->GetUIContent() == nullptr) {
IAM_LOGE("uiContent is null");
return false;
}
} else {
if (abilityContext->GetUIContent() == nullptr) {
IAM_LOGE("uiContent is null");
return false;
}
}
return true;
}
UserAuthResultCode UserAuthInstanceV10::ProcessWindowMode(napi_env env, napi_value value)
{
if (UserAuthNapiHelper::HasNamedProperty(env, value, WIDGET_PARAM_WINDOWMODE)) {
@ -561,7 +630,7 @@ UserAuthResultCode UserAuthInstanceV10::Start(napi_env env, napi_callback_info i
IAM_LOGE("auth already started");
return UserAuthResultCode::GENERAL_ERROR;
}
contextId_ = UserAuthClientImpl::Instance().BeginWidgetAuth(API_VERSION_10,
contextId_ = UserAuthNapiClientImpl::Instance().BeginWidgetAuth(API_VERSION_10,
authParam_, widgetParam_, callback_);
isAuthStarted_ = true;
return UserAuthResultCode::SUCCESS;

View File

@ -44,8 +44,12 @@ ohos_shared_library("userauth_client") {
"src/executor_callback_service.cpp",
"src/executor_messenger_client.cpp",
"src/ipc_client_utils.cpp",
"src/modal_callback_service.cpp",
"src/modal_extension_callback.cpp",
"src/user_auth_callback_service.cpp",
"src/user_auth_client_impl.cpp",
"src/user_auth_modal_callback.cpp",
"src/user_auth_napi_client_impl.cpp",
"src/user_idm_callback_service.cpp",
"src/user_idm_client_impl.cpp",
"src/widget_callback_service.cpp",
@ -76,6 +80,14 @@ ohos_shared_library("userauth_client") {
}
external_deps = [
"ability_base:want",
"ability_runtime:ability_context_native",
"ability_runtime:ability_manager",
"ability_runtime:abilitykit_native",
"ability_runtime:app_context",
"ability_runtime:napi_base_context",
"ability_runtime:ui_extension",
"ace_engine:ace_uicontent",
"c_utils:utils",
"hilog:libhilog",
"ipc:ipc_single",

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 2024 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 MODAL_CALLBACK_SERVICE_H
#define MODAL_CALLBACK_SERVICE_H
#include "modal_callback_stub.h"
#include "iam_hitrace_helper.h"
#include "user_auth_modal_callback.h"
namespace OHOS {
namespace UserIam {
namespace UserAuth {
class ModalCallbackService : public ModalCallbackStub {
public:
explicit ModalCallbackService(const std::shared_ptr<UserAuthModalCallback> &impl);
~ModalCallbackService() override;
void SendCommand(uint64_t contextId, const std::string &cmdData) override;
private:
std::shared_ptr<UserAuthModalCallback> modalCallback_ {nullptr};
std::shared_ptr<UserIam::UserAuth::IamHitraceHelper> iamHitraceHelper_ {nullptr};
};
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS
#endif // MODAL_CALLBACK_SERVICE_H

View File

@ -0,0 +1,57 @@
/*
* Copyright (c) 2024 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 MODAL_EXTENSION_CALLBACK_H
#define MODAL_EXTENSION_CALLBACK_H
#include <string>
#include "ui_content.h"
#include "ui_extension_context.h"
namespace OHOS {
namespace UserIam {
namespace UserAuth {
class ModalExtensionCallback {
public:
ModalExtensionCallback();
~ModalExtensionCallback();
void OnRelease(int32_t code);
void OnResult(int32_t code, const OHOS::AAFwk::Want& result);
void OnReceive(const OHOS::AAFwk::WantParams& request);
void OnError(int32_t code, const std::string& name, const std::string &message);
void OnRemoteReady(const std::shared_ptr<OHOS::Ace::ModalUIExtensionProxy> &uiProxy);
void OnDestroy();
void SetSessionId(int32_t sessionId);
void SetContextId(uint64_t contextId);
void SetAbilityContext(std::shared_ptr<OHOS::AbilityRuntime::AbilityContext> abilityContext);
void SetHolderContext(std::shared_ptr<OHOS::AbilityRuntime::UIHolderExtensionContext> uiHolderContext);
void ReleaseOrErrorHandle(int32_t code);
bool IsModalDestroy();
private:
void CancelAuthentication();
int32_t sessionId_ = 0;
uint64_t contextId_ = 0;
std::shared_ptr<OHOS::AbilityRuntime::AbilityContext> abilityContext_;
std::shared_ptr<OHOS::AbilityRuntime::UIHolderExtensionContext> uiHolderContext_;
bool isDestroy_ {false};
std::recursive_mutex mutex_;
};
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS
#endif // MODAL_EXTENSION_CALLBACK_H

View File

@ -20,6 +20,7 @@
#include "iam_hitrace_helper.h"
#include "user_auth_client_callback.h"
#include "user_auth_modal_callback.h"
namespace OHOS {
namespace UserIam {
@ -27,6 +28,8 @@ namespace UserAuth {
class UserAuthCallbackService : public UserAuthCallbackStub {
public:
explicit UserAuthCallbackService(const std::shared_ptr<AuthenticationCallback> &impl);
explicit UserAuthCallbackService(const std::shared_ptr<AuthenticationCallback> &impl,
const std::shared_ptr<UserAuthModalCallback> &modalCallback);
explicit UserAuthCallbackService(const std::shared_ptr<IdentificationCallback> &impl);
explicit UserAuthCallbackService(const std::shared_ptr<PrepareRemoteAuthCallback> &impl);
~UserAuthCallbackService() override;
@ -35,6 +38,7 @@ public:
private:
std::shared_ptr<AuthenticationCallback> authCallback_ {nullptr};
std::shared_ptr<UserAuthModalCallback> modalCallback_ {nullptr};
std::shared_ptr<IdentificationCallback> identifyCallback_ {nullptr};
std::shared_ptr<PrepareRemoteAuthCallback> prepareRemoteAuthCallback_ {nullptr};
std::shared_ptr<UserIam::UserAuth::IamHitraceHelper> iamHitraceHelper_ {nullptr};

View File

@ -66,7 +66,7 @@ private:
ResultCode SetPropertyInner(int32_t userId, const SetPropertyRequest &request,
const std::shared_ptr<SetPropCallback> &callback);
uint64_t BeginWidgetAuthInner(int32_t apiVersion, const AuthParamInner &authParam,
const WidgetParam &widgetParam, const std::shared_ptr<AuthenticationCallback> &callback);
const WidgetParamInner &widgetParam, const std::shared_ptr<AuthenticationCallback> &callback);
friend class UserAuthClient;
UserAuthClientImpl() = default;

View File

@ -0,0 +1,50 @@
/*
* Copyright (c) 2024 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 USER_AUTH_MODAL_CALLBACK_H
#define USER_AUTH_MODAL_CALLBACK_H
#include <string>
#include "modal_extension_callback.h"
namespace OHOS {
namespace UserIam {
namespace UserAuth {
class UserAuthModalCallback {
public:
explicit UserAuthModalCallback(const std::shared_ptr<AbilityRuntime::Context> context);
~UserAuthModalCallback();
void SendCommand(uint64_t contextId, const std::string &cmdData);
bool IsModalInit();
bool IsModalDestroy();
private:
Ace::UIContent* InitAndGetUIContent(const std::shared_ptr<OHOS::AbilityRuntime::Context> context);
bool CreateUIExtension(const std::shared_ptr<OHOS::AbilityRuntime::Context> context, uint64_t contextId,
const std::string &cmdData);
void CancelAuthentication(uint64_t contextId);
std::shared_ptr<AbilityRuntime::Context> context_ {nullptr};
std::shared_ptr<ModalExtensionCallback> uiExtCallback_ {nullptr};
uint64_t contextId_ {0};
bool isInit_ {false};
bool isInitError_ {false};
std::recursive_mutex mutex_;
};
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS
#endif // USER_AUTH_MODAL_CALLBACK_H

View File

@ -0,0 +1,76 @@
/*
* Copyright (c) 2024 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 USER_AUTH_NAPI_CLIENT_IMPL_H
#define USER_AUTH_NAPI_CLIENT_IMPL_H
#include <mutex>
#include "nocopyable.h"
#include "ui_content.h"
#include "user_auth_client_callback.h"
#include "user_auth_client_defines.h"
#include "user_auth_interface.h"
namespace OHOS {
namespace UserIam {
namespace UserAuth {
class UserAuthNapiClientImpl final : public NoCopyable {
public:
/**
* @brief Auth widget parameter.
*/
struct WidgetParamNapi {
/** Title of widget. */
std::string title;
/** The description text of navigation button. */
std::string navigationButtonText;
/** Full screen or not. */
WindowModeType windowMode;
/** UI context of caller hap. */
std::shared_ptr<AbilityRuntime::Context> context;
};
static UserAuthNapiClientImpl& Instance();
uint64_t BeginWidgetAuth(int32_t apiVersion, const AuthParamInner &authParam, const WidgetParamNapi &widgetParam,
const std::shared_ptr<AuthenticationCallback> &callback);
int32_t CancelAuthentication(uint64_t contextId, int32_t cancelReason);
private:
uint64_t BeginWidgetAuthInner(int32_t apiVersion, const AuthParamInner &authParam,
const WidgetParamInner &widgetParam, const std::shared_ptr<AuthenticationCallback> &callback,
const std::shared_ptr<AbilityRuntime::Context> context);
UserAuthNapiClientImpl() = default;
~UserAuthNapiClientImpl() override = default;
class UserAuthImplDeathRecipient : public IRemoteObject::DeathRecipient, public NoCopyable {
public:
UserAuthImplDeathRecipient() = default;
~UserAuthImplDeathRecipient() override = default;
void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
};
void ResetProxy(const wptr<IRemoteObject> &remote);
sptr<UserAuthInterface> GetProxy();
sptr<UserAuthInterface> proxy_ {nullptr};
sptr<IRemoteObject::DeathRecipient> deathRecipient_ {nullptr};
constexpr static int32_t MINIMUM_VERSION {0};
std::mutex mutex_;
};
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS
#endif // USER_AUTH_NAPI_CLIENT_IMPL_H

View File

@ -0,0 +1,62 @@
/*
* Copyright (c) 2024 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 "modal_callback_service.h"
#include "callback_manager.h"
#include "iam_logger.h"
#include "iam_ptr.h"
#define LOG_TAG "USER_AUTH_SDK"
namespace OHOS {
namespace UserIam {
namespace UserAuth {
ModalCallbackService::ModalCallbackService(const std::shared_ptr<UserAuthModalCallback> &impl)
: modalCallback_(impl),
iamHitraceHelper_(Common::MakeShared<UserIam::UserAuth::IamHitraceHelper>("UserAuthWidget"))
{
IAM_LOGI("set modal callback");
CallbackManager::CallbackAction action = [impl]() {
if (impl != nullptr) {
IAM_LOGI("user auth service death, auth widget callback return default result to caller");
uint64_t contextId = 0;
std::string cmdData = "";
impl->SendCommand(contextId, cmdData);
}
};
CallbackManager::GetInstance().AddCallback(reinterpret_cast<uintptr_t>(this), action);
}
ModalCallbackService::~ModalCallbackService()
{
IAM_LOGI("~ModalCallbackService clean");
iamHitraceHelper_= nullptr;
CallbackManager::GetInstance().RemoveCallback(reinterpret_cast<uintptr_t>(this));
}
void ModalCallbackService::SendCommand(uint64_t contextId, const std::string &cmdData)
{
IAM_LOGI("SendCommand start");
if (modalCallback_ == nullptr) {
IAM_LOGE("modal callback is nullptr");
return;
}
modalCallback_->SendCommand(contextId, cmdData);
iamHitraceHelper_ = nullptr;
}
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS

View File

@ -0,0 +1,142 @@
/*
* Copyright (c) 2024 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 "modal_extension_callback.h"
#include "ability.h"
#include "system_ability_definition.h"
#include "ui_holder_extension_context.h"
#include "iam_logger.h"
#include "iam_ptr.h"
#include "user_auth_napi_client_impl.h"
#define LOG_TAG "USER_AUTH_SDK"
namespace OHOS {
namespace UserIam {
namespace UserAuth {
ModalExtensionCallback::ModalExtensionCallback()
{}
ModalExtensionCallback::~ModalExtensionCallback()
{}
void ModalExtensionCallback::OnResult(int32_t code, const AAFwk::Want& result)
{
IAM_LOGI("OnResult, code: %{public}d", code);
}
void ModalExtensionCallback::OnReceive(const AAFwk::WantParams& receive)
{
IAM_LOGI("OnReceive");
}
void ModalExtensionCallback::OnRelease(int32_t code)
{
IAM_LOGI("OnRelease, code: %{public}d", code);
std::lock_guard<std::recursive_mutex> lock(mutex_);
if (code != 0) {
CancelAuthentication();
}
ReleaseOrErrorHandle(code);
}
void ModalExtensionCallback::OnError(int32_t code, const std::string& name, const std::string& message)
{
IAM_LOGE("OnError, name: %{public}s, message: %{public}s", name.c_str(), message.c_str());
std::lock_guard<std::recursive_mutex> lock(mutex_);
CancelAuthentication();
ReleaseOrErrorHandle(code);
}
void ModalExtensionCallback::OnRemoteReady(const std::shared_ptr<Ace::ModalUIExtensionProxy>& uiProxy)
{
IAM_LOGI("OnRemoteReady");
}
void ModalExtensionCallback::OnDestroy()
{
IAM_LOGI("OnDestroy");
std::lock_guard<std::recursive_mutex> lock(mutex_);
isDestroy_ = true;
}
void ModalExtensionCallback::SetSessionId(int32_t sessionId)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
sessionId_ = sessionId;
}
void ModalExtensionCallback::SetContextId(uint64_t contextId)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
contextId_ = contextId;
}
void ModalExtensionCallback::SetAbilityContext(std::shared_ptr<OHOS::AbilityRuntime::AbilityContext> abilityContext)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
abilityContext_ = abilityContext;
}
void ModalExtensionCallback::SetHolderContext(
std::shared_ptr<OHOS::AbilityRuntime::UIHolderExtensionContext> uiHolderContext)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
uiHolderContext_ = uiHolderContext;
}
void ModalExtensionCallback::ReleaseOrErrorHandle(int32_t code)
{
IAM_LOGI("ReleaseOrErrorHandle start, code: %{public}d", code);
std::lock_guard<std::recursive_mutex> lock(mutex_);
if (abilityContext_ != nullptr) {
Ace::UIContent* uiContent = abilityContext_->GetUIContent();
if (uiContent == nullptr) {
IAM_LOGE("uiContent is null");
return;
}
uiContent->CloseModalUIExtension(sessionId_);
}
if (uiHolderContext_ != nullptr) {
Ace::UIContent* uiContent = uiHolderContext_->GetUIContent();
if (uiContent == nullptr) {
IAM_LOGE("uiContent is null");
return;
}
uiContent->CloseModalUIExtension(sessionId_);
}
IAM_LOGI("ReleaseOrErrorHandle end");
isDestroy_ = true;
return;
}
bool ModalExtensionCallback::IsModalDestroy()
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
return isDestroy_;
}
void ModalExtensionCallback::CancelAuthentication()
{
// cancel for failed
int32_t code = UserAuthNapiClientImpl::Instance().CancelAuthentication(contextId_, CancelReason::MODAL_RUN_ERROR);
IAM_LOGI("CancelAuthentication, code: %{public}d", code);
}
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 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
@ -38,6 +38,21 @@ UserAuthCallbackService::UserAuthCallbackService(const std::shared_ptr<Authentic
CallbackManager::GetInstance().AddCallback(reinterpret_cast<uintptr_t>(this), action);
}
UserAuthCallbackService::UserAuthCallbackService(const std::shared_ptr<AuthenticationCallback> &impl,
const std::shared_ptr<UserAuthModalCallback> &modalCallback)
: authCallback_(impl), modalCallback_(modalCallback),
iamHitraceHelper_(Common::MakeShared<UserIam::UserAuth::IamHitraceHelper>("UserAuth InnerKit"))
{
CallbackManager::CallbackAction action = [impl]() {
if (impl != nullptr) {
IAM_LOGI("user auth service death, auth callback return default result to caller");
Attributes extraInfo;
impl->OnResult(GENERAL_ERROR, extraInfo);
}
};
CallbackManager::GetInstance().AddCallback(reinterpret_cast<uintptr_t>(this), action);
}
UserAuthCallbackService::UserAuthCallbackService(const std::shared_ptr<IdentificationCallback> &impl)
: identifyCallback_(impl),
iamHitraceHelper_(Common::MakeShared<UserIam::UserAuth::IamHitraceHelper>("UserAuth InnerKit"))
@ -76,6 +91,15 @@ void UserAuthCallbackService::OnResult(int32_t result, const Attributes &extraIn
{
IAM_LOGI("start, result:%{public}d", result);
if (authCallback_ != nullptr) {
if (modalCallback_ != nullptr) {
IAM_LOGI("IsModalInit :%{public}d, IsModalDestroy :%{public}d", modalCallback_->IsModalInit(),
modalCallback_->IsModalDestroy());
if (modalCallback_->IsModalInit() && !modalCallback_->IsModalDestroy()) {
const uint32_t sleepTime = 100000;
usleep(sleepTime);
IAM_LOGI("process result continue");
}
}
authCallback_->OnResult(result, extraInfo);
} else if (identifyCallback_ != nullptr) {
identifyCallback_->OnResult(result, extraInfo);

View File

@ -25,6 +25,7 @@
#include "iam_para2str.h"
#include "iam_ptr.h"
#include "ipc_client_utils.h"
#include "modal_callback_service.h"
#include "user_auth_callback_service.h"
#include "widget_callback_service.h"
@ -282,7 +283,7 @@ int32_t UserAuthClientImpl::CancelAuthentication(uint64_t contextId)
return GENERAL_ERROR;
}
return proxy->CancelAuthOrIdentify(contextId);
return proxy->CancelAuthOrIdentify(contextId, CancelReason::ORIGINAL_CANCEL);
}
uint64_t UserAuthClientImpl::BeginIdentification(const std::vector<uint8_t> &challenge, AuthType authType,
@ -321,7 +322,7 @@ int32_t UserAuthClientImpl::CancelIdentification(uint64_t contextId)
return GENERAL_ERROR;
}
return proxy->CancelAuthOrIdentify(contextId);
return proxy->CancelAuthOrIdentify(contextId, CancelReason::ORIGINAL_CANCEL);
}
int32_t UserAuthClientImpl::GetVersion(int32_t &version)
@ -423,7 +424,13 @@ uint64_t UserAuthClientImpl::BeginWidgetAuth(const WidgetAuthParam &authParam, c
.authTrustLevel = authParam.authTrustLevel,
.reuseUnlockResult = authParam.reuseUnlockResult,
};
return BeginWidgetAuthInner(INNER_API_VERSION_20000, authParamInner, widgetParam, callback);
WidgetParamInner widgetParamInner = {
.title = widgetParam.title,
.navigationButtonText = widgetParam.navigationButtonText,
.windowMode = widgetParam.windowMode,
.hasContext = false,
};
return BeginWidgetAuthInner(INNER_API_VERSION_20000, authParamInner, widgetParamInner, callback);
}
uint64_t UserAuthClientImpl::BeginWidgetAuth(int32_t apiVersion, const WidgetAuthParam &authParam,
@ -439,11 +446,17 @@ uint64_t UserAuthClientImpl::BeginWidgetAuth(int32_t apiVersion, const WidgetAut
.authTrustLevel = authParam.authTrustLevel,
.reuseUnlockResult = authParam.reuseUnlockResult,
};
return BeginWidgetAuthInner(apiVersion, authParamInner, widgetParam, callback);
WidgetParamInner widgetParamInner = {
.title = widgetParam.title,
.navigationButtonText = widgetParam.navigationButtonText,
.windowMode = widgetParam.windowMode,
.hasContext = false,
};
return BeginWidgetAuthInner(apiVersion, authParamInner, widgetParamInner, callback);
}
uint64_t UserAuthClientImpl::BeginWidgetAuthInner(int32_t apiVersion, const AuthParamInner &authParam,
const WidgetParam &widgetParam, const std::shared_ptr<AuthenticationCallback> &callback)
const WidgetParamInner &widgetParam, const std::shared_ptr<AuthenticationCallback> &callback)
{
if (!callback) {
IAM_LOGE("auth callback is nullptr");
@ -464,7 +477,17 @@ uint64_t UserAuthClientImpl::BeginWidgetAuthInner(int32_t apiVersion, const Auth
callback->OnResult(static_cast<int32_t>(ResultCode::GENERAL_ERROR), extraInfo);
return BAD_CONTEXT_ID;
}
return proxy->AuthWidget(apiVersion, authParam, widgetParam, wrapper);
// modal
const std::shared_ptr<UserAuthModalCallback> &modalCallback = Common::MakeShared<UserAuthModalCallback>(nullptr);
sptr<ModalCallbackInterface> wrapperModal(new (std::nothrow) ModalCallbackService(modalCallback));
if (wrapperModal == nullptr) {
IAM_LOGE("failed to create wrapper for modal");
Attributes extraInfo;
callback->OnResult(static_cast<int32_t>(ResultCode::GENERAL_ERROR), extraInfo);
return BAD_CONTEXT_ID;
}
return proxy->AuthWidget(apiVersion, authParam, widgetParam, wrapper, wrapperModal);
}
int32_t UserAuthClientImpl::SetWidgetCallback(int32_t version, const std::shared_ptr<IUserAuthWidgetCallback> &callback)

View File

@ -0,0 +1,183 @@
/*
* Copyright (c) 2024 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 "user_auth_modal_callback.h"
#include "ability.h"
#include "system_ability_definition.h"
#include "ui_holder_extension_context.h"
#include "want.h"
#include "iam_logger.h"
#include "iam_ptr.h"
#include "user_auth_napi_client_impl.h"
#define LOG_TAG "USER_AUTH_SDK"
namespace OHOS {
namespace UserIam {
namespace UserAuth {
UserAuthModalCallback::UserAuthModalCallback(const std::shared_ptr<AbilityRuntime::Context> context)
: context_(context)
{}
UserAuthModalCallback::~UserAuthModalCallback()
{}
void UserAuthModalCallback::SendCommand(uint64_t contextId, const std::string &cmdData)
{
IAM_LOGI("SendCommand start");
std::lock_guard<std::recursive_mutex> lock(mutex_);
if (context_ != nullptr) {
IAM_LOGI("widgetParam context not null, process as modal application");
if (contextId == 0 && cmdData.empty()) {
IAM_LOGI("stop modal");
isInitError_ = true;
CancelAuthentication(contextId);
return;
}
contextId_ = contextId;
bool createModalRet = CreateUIExtension(context_, contextId, cmdData);
// Cancel for failed
if (!createModalRet) {
IAM_LOGE("create modal error, createModalRet: %{public}d", createModalRet);
isInitError_ = true;
CancelAuthentication(contextId);
return;
}
IAM_LOGI("create modal success");
isInit_ = true;
return;
}
IAM_LOGI("widgetParam.context is nullptr");
}
bool UserAuthModalCallback::IsModalInit()
{
IAM_LOGI("get is modal init");
std::lock_guard<std::recursive_mutex> lock(mutex_);
return isInit_;
}
bool UserAuthModalCallback::IsModalDestroy()
{
IAM_LOGI("get is modal on destroy");
std::lock_guard<std::recursive_mutex> lock(mutex_);
if (isInitError_ || (uiExtCallback_ != nullptr && uiExtCallback_->IsModalDestroy())) {
IAM_LOGI("modal on destroy");
return true;
}
return false;
}
Ace::UIContent* UserAuthModalCallback::InitAndGetUIContent(
const std::shared_ptr<OHOS::AbilityRuntime::Context> context)
{
if (context == nullptr) {
IAM_LOGE("context is nullptr");
return nullptr;
}
Ace::UIContent* uiContent = nullptr;
auto abilityContext = AbilityRuntime::Context::ConvertTo<AbilityRuntime::AbilityContext>(context);
std::shared_ptr<AbilityRuntime::UIHolderExtensionContext> holderContext;
if (abilityContext == nullptr) {
IAM_LOGE("abilityContext is nullptr");
holderContext = AbilityRuntime::Context::ConvertTo<AbilityRuntime::UIHolderExtensionContext>(context);
if (holderContext == nullptr) {
IAM_LOGE("uiExtensionContext is nullptr");
return nullptr;
}
uiContent = holderContext->GetUIContent();
if (uiContent == nullptr) {
IAM_LOGE("uiContent is nullptr");
return nullptr;
}
} else {
uiContent = abilityContext->GetUIContent();
if (uiContent == nullptr) {
IAM_LOGE("uiContent is nullptr");
return nullptr;
}
}
uiExtCallback_ = std::make_shared<ModalExtensionCallback>();
uiExtCallback_->SetAbilityContext(abilityContext);
uiExtCallback_->SetHolderContext(holderContext);
return uiContent;
}
bool UserAuthModalCallback::CreateUIExtension(const std::shared_ptr<OHOS::AbilityRuntime::Context> context,
uint64_t contextId, const std::string &cmdData)
{
Ace::UIContent* uiContent = InitAndGetUIContent(context);
if (uiContent == nullptr) {
IAM_LOGE("uiContent invalid");
return false;
}
AAFwk::Want want;
std::string targetBundleName = "com.ohos.useriam.authwidget";
std::string targetAbilityName = "UserAuthModalUIAbility";
want.SetElementName(targetBundleName, targetAbilityName);
std::string typeKey = "ability.want.params.uiExtensionType";
std::string typeValue = "sys/commonUI";
want.SetParam(typeKey, typeValue);
std::string commandKey = "parameters";
want.SetParam(commandKey, cmdData);
uiExtCallback_->SetContextId(contextId);
Ace::ModalUIExtensionCallbacks uiExtensionCallbacks = {
.onRelease = std::bind(&ModalExtensionCallback::OnRelease, uiExtCallback_, std::placeholders::_1),
.onResult = std::bind(&ModalExtensionCallback::OnResult, uiExtCallback_,
std::placeholders::_1, std::placeholders::_2),
.onReceive = std::bind(&ModalExtensionCallback::OnReceive, uiExtCallback_, std::placeholders::_1),
.onError = std::bind(&ModalExtensionCallback::OnError, uiExtCallback_,
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3),
.onRemoteReady = std::bind(&ModalExtensionCallback::OnRemoteReady, uiExtCallback_, std::placeholders::_1),
.onDestroy = std::bind(&ModalExtensionCallback::OnDestroy, uiExtCallback_),
};
Ace::ModalUIExtensionConfig config;
config.isProhibitBack = true;
int32_t sessionId = uiContent->CreateModalUIExtension(want, uiExtensionCallbacks, config);
IAM_LOGI("Create end, sessionId: %{public}d", sessionId);
if (sessionId == 0) {
IAM_LOGE("Create component failed, sessionId is 0");
return false;
}
uiExtCallback_->SetSessionId(sessionId);
return true;
}
void UserAuthModalCallback::CancelAuthentication(uint64_t contextId)
{
// cancel for failed
int32_t code = UserAuthNapiClientImpl::Instance().CancelAuthentication(contextId,
CancelReason::MODAL_CREATE_ERROR);
IAM_LOGI("CancelAuthentication, code: %{public}d, contextId: ****%{public}hx", code,
static_cast<uint16_t>(contextId));
if (uiExtCallback_ != nullptr) {
IAM_LOGI("release modal");
isInitError_ = true;
uiExtCallback_->ReleaseOrErrorHandle(0);
}
}
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS

View File

@ -0,0 +1,164 @@
/*
* Copyright (c) 2024 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 "user_auth_napi_client_impl.h"
#include "system_ability_definition.h"
#include "callback_manager.h"
#include "iam_logger.h"
#include "iam_ptr.h"
#include "ipc_client_utils.h"
#include "modal_callback_service.h"
#include "user_auth_callback_service.h"
#define LOG_TAG "USER_AUTH_SDK"
namespace OHOS {
namespace UserIam {
namespace UserAuth {
sptr<UserAuthInterface> UserAuthNapiClientImpl::GetProxy()
{
std::lock_guard<std::mutex> lock(mutex_);
if (proxy_ != nullptr) {
return proxy_;
}
sptr<IRemoteObject> obj = IpcClientUtils::GetRemoteObject(SUBSYS_USERIAM_SYS_ABILITY_USERAUTH);
if (obj == nullptr) {
IAM_LOGE("remote object is null");
return proxy_;
}
sptr<IRemoteObject::DeathRecipient> dr(new (std::nothrow) UserAuthImplDeathRecipient());
if ((dr == nullptr) || (obj->IsProxyObject() && !obj->AddDeathRecipient(dr))) {
IAM_LOGE("add death recipient fail");
return proxy_;
}
proxy_ = iface_cast<UserAuthInterface>(obj);
deathRecipient_ = dr;
return proxy_;
}
void UserAuthNapiClientImpl::ResetProxy(const wptr<IRemoteObject> &remote)
{
IAM_LOGI("start");
std::lock_guard<std::mutex> lock(mutex_);
if (proxy_ == nullptr) {
IAM_LOGE("proxy_ is null");
return;
}
auto serviceRemote = proxy_->AsObject();
if ((serviceRemote != nullptr) && (serviceRemote == remote.promote())) {
IAM_LOGI("need reset");
serviceRemote->RemoveDeathRecipient(deathRecipient_);
proxy_ = nullptr;
deathRecipient_ = nullptr;
}
IAM_LOGI("end reset proxy");
}
void UserAuthNapiClientImpl::UserAuthImplDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
{
IAM_LOGI("start");
if (remote == nullptr) {
IAM_LOGE("remote is nullptr");
return;
}
CallbackManager::GetInstance().OnServiceDeath();
UserAuthNapiClientImpl::Instance().ResetProxy(remote);
}
UserAuthNapiClientImpl &UserAuthNapiClientImpl::Instance()
{
static UserAuthNapiClientImpl impl;
return impl;
}
uint64_t UserAuthNapiClientImpl::BeginWidgetAuth(int32_t apiVersion, const AuthParamInner &authParam,
const WidgetParamNapi &widgetParam, const std::shared_ptr<AuthenticationCallback> &callback)
{
IAM_LOGI("start, apiVersion: %{public}d authTypeSize: %{public}zu authTrustLevel: %{public}u",
apiVersion, authParam.authTypes.size(), authParam.authTrustLevel);
AuthParamInner authParamInner = {
.challenge = authParam.challenge,
.authTypes = authParam.authTypes,
.authTrustLevel = authParam.authTrustLevel,
.reuseUnlockResult = authParam.reuseUnlockResult,
.isUserIdSpecified = false,
};
WidgetParamInner widgetParamInner = {
.title = widgetParam.title,
.navigationButtonText = widgetParam.navigationButtonText,
.windowMode = widgetParam.windowMode,
};
if (widgetParam.context != nullptr) {
widgetParamInner.hasContext = true;
}
IAM_LOGI("has context: %{public}d", widgetParamInner.hasContext);
return BeginWidgetAuthInner(apiVersion, authParamInner, widgetParamInner, callback, widgetParam.context);
}
uint64_t UserAuthNapiClientImpl::BeginWidgetAuthInner(int32_t apiVersion, const AuthParamInner &authParam,
const WidgetParamInner &widgetParam, const std::shared_ptr<AuthenticationCallback> &callback,
const std::shared_ptr<AbilityRuntime::Context> context)
{
if (!callback) {
IAM_LOGE("auth callback is nullptr");
return BAD_CONTEXT_ID;
}
auto proxy = GetProxy();
if (!proxy) {
IAM_LOGE("proxy is nullptr");
Attributes extraInfo;
callback->OnResult(static_cast<int32_t>(ResultCode::GENERAL_ERROR), extraInfo);
return BAD_CONTEXT_ID;
}
// modal
const std::shared_ptr<UserAuthModalCallback> &modalCallback = Common::MakeShared<UserAuthModalCallback>(context);
sptr<UserAuthCallbackInterface> wrapper(new (std::nothrow) UserAuthCallbackService(callback));
if (wrapper == nullptr) {
IAM_LOGE("failed to create wrapper");
Attributes extraInfo;
callback->OnResult(static_cast<int32_t>(ResultCode::GENERAL_ERROR), extraInfo);
return BAD_CONTEXT_ID;
}
// modal
sptr<ModalCallbackInterface> wrapperModal(new (std::nothrow) ModalCallbackService(modalCallback));
if (wrapperModal == nullptr) {
IAM_LOGE("failed to create wrapper for modal");
Attributes extraInfo;
callback->OnResult(static_cast<int32_t>(ResultCode::GENERAL_ERROR), extraInfo);
return BAD_CONTEXT_ID;
}
return proxy->AuthWidget(apiVersion, authParam, widgetParam, wrapper, wrapperModal);
}
int32_t UserAuthNapiClientImpl::CancelAuthentication(uint64_t contextId, int32_t cancelReason)
{
IAM_LOGI("start");
auto proxy = GetProxy();
if (!proxy) {
IAM_LOGE("proxy is nullptr");
return GENERAL_ERROR;
}
return proxy->CancelAuthOrIdentify(contextId, cancelReason);
}
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS

View File

@ -1,4 +1,4 @@
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Copyright (c) 2023-2024 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
@ -29,6 +29,9 @@
OHOS::UserIam::UserAuth::Attributes*;
OHOS::UserIam::UserAuth::UserAuthClientImpl::GetEnrolledState*;
OHOS::UserIam::UserAuth::AuthEventListenerStub::OnRemoteRequest*;
OHOS::UserIam::UserAuth::UserAuthNapiClientImpl::Instance*;
OHOS::UserIam::UserAuth::UserAuthNapiClientImpl::BeginWidgetAuth*;
OHOS::UserIam::UserAuth::UserAuthNapiClientImpl::CancelAuthentication*;
};
local:
*;

View File

@ -41,6 +41,7 @@ ohos_source_set("userauth_client_ipc") {
"src/co_auth_proxy.cpp",
"src/executor_callback_stub.cpp",
"src/executor_messenger_proxy.cpp",
"src/modal_callback_stub.cpp",
"src/user_auth_callback_stub.cpp",
"src/user_auth_event_listener_stub.cpp",
"src/user_auth_proxy.cpp",
@ -58,6 +59,14 @@ ohos_source_set("userauth_client_ipc") {
remove_configs = [ "//build/config/compiler:no_exceptions" ]
external_deps = [
"ability_base:want",
"ability_runtime:ability_context_native",
"ability_runtime:ability_manager",
"ability_runtime:abilitykit_native",
"ability_runtime:app_context",
"ability_runtime:napi_base_context",
"ability_runtime:ui_extension",
"ace_engine:ace_uicontent",
"c_utils:utils",
"hilog:libhilog",
"ipc:ipc_single",
@ -88,6 +97,7 @@ ohos_source_set("userauth_service_ipc") {
"src/co_auth_stub.cpp",
"src/executor_callback_proxy.cpp",
"src/executor_messenger_stub.cpp",
"src/modal_callback_proxy.cpp",
"src/user_auth_callback_proxy.cpp",
"src/user_auth_event_listener_proxy.cpp",
"src/user_auth_stub.cpp",
@ -105,6 +115,7 @@ ohos_source_set("userauth_service_ipc") {
remove_configs = [ "//build/config/compiler:no_exceptions" ]
external_deps = [
"ace_engine:ace_uicontent",
"c_utils:utils",
"hilog:libhilog",
"ipc:ipc_single",

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2024 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 MODAL_CALLBACK_INTERFACE_H
#define MODAL_CALLBACK_INTERFACE_H
#include <cstdint>
#include "iremote_broker.h"
#include "iam_common_defines.h"
#include "user_auth_common_defines.h"
namespace OHOS {
namespace UserIam {
namespace UserAuth {
class ModalCallbackInterface : public IRemoteBroker {
public:
virtual void SendCommand(uint64_t contextId, const std::string &cmdData) = 0;
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.UserIam.UserAuth.ModalCallback");
};
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS
#endif // MODAL_CALLBACK_INTERFACE_H

View File

@ -83,6 +83,31 @@ struct EnrolledState {
uint16_t credentialCount {0};
};
/**
* @brief Auth widget parameter.
*/
struct WidgetParamInner {
/** Title of widget. */
std::string title;
/** The description text of navigation button. */
std::string navigationButtonText;
/** Full screen or not. */
WindowModeType windowMode;
/** Default has't context. */
bool hasContext {false};
};
/**
* @brief Cancel reason for user authentication.
*/
enum CancelReason : int32_t {
/** notice from widget. */
ORIGINAL_CANCEL = 0,
/** notice from widget. */
MODAL_CREATE_ERROR = 1,
/** notice from widget. */
MODAL_RUN_ERROR = 2,
};
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS

View File

@ -23,6 +23,7 @@
#include "refbase.h"
#include "attributes.h"
#include "modal_callback_interface.h"
#include "user_auth_callback_interface.h"
#include "user_auth_client_callback.h"
#include "user_auth_interface_ipc_interface_code.h"
@ -51,12 +52,13 @@ public:
AuthTrustLevel authTrustLevel, sptr<UserAuthCallbackInterface> &callback) = 0;
virtual uint64_t AuthWidget(int32_t apiVersion, const AuthParamInner &authParam,
const WidgetParam &widgetParam, sptr<UserAuthCallbackInterface> &callback) = 0;
const WidgetParamInner &widgetParam, sptr<UserAuthCallbackInterface> &callback,
sptr<ModalCallbackInterface> &modalCallback) = 0;
virtual uint64_t Identify(const std::vector<uint8_t> &challenge, AuthType authType,
sptr<UserAuthCallbackInterface> &callback) = 0;
virtual int32_t CancelAuthOrIdentify(uint64_t contextId) = 0;
virtual int32_t CancelAuthOrIdentify(uint64_t contextId, int32_t cancelReason) = 0;
virtual int32_t GetVersion(int32_t &version) = 0;

View File

@ -45,6 +45,7 @@ enum UserAuthInterfaceCode : uint32_t {
USER_AUTH_EVENT_LISTENER_NOTIFY,
USER_AUTH_SET_CLOBAL_CONFIG_PARAM,
USER_AUTH_PREPARE_REMOTE_AUTH,
USER_AUTH_AUTH_MODAL_SEND_COMMAND,
};
} // namespace UserAuth
} // namespace UserIam

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2024 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 MODAL_CALLBACK_PROXY_H
#define MODAL_CALLBACK_PROXY_H
#include <iremote_proxy.h>
#include "modal_callback_interface.h"
namespace OHOS {
namespace UserIam {
namespace UserAuth {
class ModalCallbackProxy : public IRemoteProxy<ModalCallbackInterface>, public NoCopyable {
public:
explicit ModalCallbackProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<ModalCallbackInterface>(object)
{
}
~ModalCallbackProxy() override = default;
void SendCommand(uint64_t contextId, const std::string &cmdData) override;
private:
static inline BrokerDelegator<ModalCallbackProxy> delegator_;
bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply);
};
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS
#endif // MODAL_CALLBACK_PROXY_H

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2024 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 MODAL_CALLBACK_STUB_H
#define MODAL_CALLBACK_STUB_H
#include "iremote_stub.h"
#include "message_parcel.h"
#include "nocopyable.h"
#include "modal_callback_interface.h"
namespace OHOS {
namespace UserIam {
namespace UserAuth {
class ModalCallbackStub : public IRemoteStub<ModalCallbackInterface>, public NoCopyable {
public:
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
private:
int32_t OnSendCommandStub(MessageParcel &data, MessageParcel &reply);
};
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS
#endif // MODAL_CALLBACK_STUB_H

View File

@ -41,10 +41,11 @@ public:
uint64_t Auth(int32_t apiVersion, const std::vector<uint8_t> &challenge, AuthType authType,
AuthTrustLevel authTrustLevel, sptr<UserAuthCallbackInterface> &callback) override;
uint64_t AuthWidget(int32_t apiVersion, const AuthParamInner &authParam,
const WidgetParam &widgetParam, sptr<UserAuthCallbackInterface> &callback) override;
const WidgetParamInner &widgetParam, sptr<UserAuthCallbackInterface> &callback,
sptr<ModalCallbackInterface> &modalCallback) override;
uint64_t Identify(const std::vector<uint8_t> &challenge, AuthType authType,
sptr<UserAuthCallbackInterface> &callback) override;
int32_t CancelAuthOrIdentify(uint64_t contextId) override;
int32_t CancelAuthOrIdentify(uint64_t contextId, int32_t cancelReason) override;
int32_t GetVersion(int32_t &version) override;
int32_t Notice(NoticeType noticeType, const std::string &eventData) override;
int32_t RegisterWidgetCallback(int32_t version, sptr<WidgetCallbackInterface> &callback) override;
@ -64,7 +65,7 @@ private:
bool WriteOptionalUint32(MessageParcel &data, const std::optional<uint32_t> &val);
bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply);
bool WriteWidgetAuthParam(MessageParcel &data, const AuthParamInner &authParam);
bool WriteWidgetParam(MessageParcel &data, const WidgetParam &widgetParam);
bool WriteWidgetParam(MessageParcel &data, const WidgetParamInner &widgetParam);
ResultCode WriteGlobalConfigValue(MessageParcel &data, const GlobalConfigParam &param);
int32_t GetAvailableStatusInner(int32_t apiVersion, AuthType authType, AuthTrustLevel authTrustLevel,
MessageParcel &data);

View File

@ -42,7 +42,7 @@ private:
int32_t GetVersionStub(MessageParcel &data, MessageParcel &reply);
int32_t NoticeStub(MessageParcel &data, MessageParcel &reply);
bool ReadWidgetAuthParam(MessageParcel &data, AuthParamInner &authParam);
bool ReadWidgetParam(MessageParcel &data, WidgetParam &widgetParam);
bool ReadWidgetParam(MessageParcel &data, WidgetParamInner &widgetParam);
int32_t RegisterWidgetCallbackStub(MessageParcel &data, MessageParcel &reply);
int32_t GetEnrolledStateStub(MessageParcel &data, MessageParcel &reply);
int32_t RegistUserAuthSuccessEventListenerStub(MessageParcel &data, MessageParcel &reply);

View File

@ -0,0 +1,72 @@
/*
* Copyright (c) 2024 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 "modal_callback_proxy.h"
#include "iam_logger.h"
#include "iam_common_defines.h"
#include "user_auth_interface.h"
#define LOG_TAG "USER_AUTH_SA"
namespace OHOS {
namespace UserIam {
namespace UserAuth {
void ModalCallbackProxy::SendCommand(uint64_t contextId, const std::string &cmdData)
{
IAM_LOGI("start");
MessageParcel data;
MessageParcel reply;
if (!data.WriteInterfaceToken(ModalCallbackProxy::GetDescriptor())) {
IAM_LOGE("write descriptor failed");
return;
}
if (!data.WriteUint64(contextId)) {
IAM_LOGE("write context id failed");
return;
}
if (!data.WriteString(cmdData)) {
IAM_LOGE("write cmd data failed");
return;
}
bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_AUTH_MODAL_SEND_COMMAND, data, reply);
if (!ret) {
IAM_LOGE("send request failed");
}
}
bool ModalCallbackProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply)
{
IAM_LOGI("start code = %{public}u", code);
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
IAM_LOGE("get remote failed");
return false;
}
MessageOption option(MessageOption::TF_ASYNC);
int32_t result = remote->SendRequest(code, data, reply, option);
if (result != OHOS::NO_ERROR) {
IAM_LOGE("send request failed, result = %{public}d", result);
return false;
}
IAM_LOGI("end");
return true;
}
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS

View File

@ -0,0 +1,55 @@
/*
* Copyright (c) 2024 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 "modal_callback_stub.h"
#include <cinttypes>
#include "iam_logger.h"
#include "user_auth_interface.h"
#define LOG_TAG "USER_AUTH_SDK"
namespace OHOS {
namespace UserIam {
namespace UserAuth {
int32_t ModalCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
MessageOption &option)
{
IAM_LOGI("code = %{public}u, flags = %{public}d", code, option.GetFlags());
if (ModalCallbackStub::GetDescriptor() != data.ReadInterfaceToken()) {
IAM_LOGE("descriptor is not matched");
return GENERAL_ERROR;
}
switch (code) {
case UserAuthInterfaceCode::USER_AUTH_AUTH_MODAL_SEND_COMMAND:
return OnSendCommandStub(data, reply);
default:
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
}
int32_t ModalCallbackStub::OnSendCommandStub(MessageParcel &data, MessageParcel &reply)
{
IAM_LOGI("start");
uint64_t contextId = data.ReadUint64();
std::string cmdData = data.ReadString();
SendCommand(contextId, cmdData);
return SUCCESS;
}
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS

View File

@ -333,7 +333,8 @@ uint64_t UserAuthProxy::Auth(int32_t apiVersion, const std::vector<uint8_t> &cha
}
uint64_t UserAuthProxy::AuthWidget(int32_t apiVersion, const AuthParamInner &authParam,
const WidgetParam &widgetParam, sptr<UserAuthCallbackInterface> &callback)
const WidgetParamInner &widgetParam, sptr<UserAuthCallbackInterface> &callback,
sptr<ModalCallbackInterface> &modalCallback)
{
if (callback == nullptr) {
IAM_LOGE("callback is nullptr");
@ -362,6 +363,11 @@ uint64_t UserAuthProxy::AuthWidget(int32_t apiVersion, const AuthParamInner &aut
return BAD_CONTEXT_ID;
}
if (!data.WriteRemoteObject(modalCallback->AsObject())) {
IAM_LOGE("failed to write modal callback");
return BAD_CONTEXT_ID;
}
if (!data.WriteInt32(apiVersion)) {
IAM_LOGE("failed to write apiVersion");
return BAD_CONTEXT_ID;
@ -422,7 +428,7 @@ bool UserAuthProxy::WriteWidgetAuthParam(MessageParcel &data, const AuthParamInn
return true;
}
bool UserAuthProxy::WriteWidgetParam(MessageParcel &data, const WidgetParam &widgetParam)
bool UserAuthProxy::WriteWidgetParam(MessageParcel &data, const WidgetParamInner &widgetParam)
{
if (!data.WriteString(widgetParam.title)) {
IAM_LOGE("failed to write title");
@ -436,6 +442,10 @@ bool UserAuthProxy::WriteWidgetParam(MessageParcel &data, const WidgetParam &wid
IAM_LOGE("failed to write window mode");
return false;
}
if (!data.WriteBool(widgetParam.hasContext)) {
IAM_LOGE("failed to write hasContext");
return false;
}
return true;
}
@ -520,7 +530,7 @@ uint64_t UserAuthProxy::Identify(const std::vector<uint8_t> &challenge, AuthType
return result;
}
int32_t UserAuthProxy::CancelAuthOrIdentify(uint64_t contextId)
int32_t UserAuthProxy::CancelAuthOrIdentify(uint64_t contextId, int32_t cancelReason)
{
MessageParcel data;
MessageParcel reply;
@ -533,6 +543,10 @@ int32_t UserAuthProxy::CancelAuthOrIdentify(uint64_t contextId)
IAM_LOGE("failed to write contextId");
return GENERAL_ERROR;
}
if (!data.WriteInt32(cancelReason)) {
IAM_LOGE("failed to write cancelReason");
return GENERAL_ERROR;
}
bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_CANCEL_AUTH, data, reply);
if (!ret) {

View File

@ -21,6 +21,7 @@
#include "iam_logger.h"
#include "iam_scope_guard.h"
#include "iam_common_defines.h"
#include "modal_callback_proxy.h"
#include "user_auth_callback_proxy.h"
#include "user_auth_event_listener_proxy.h"
#include "widget_callback_proxy.h"
@ -263,7 +264,7 @@ int32_t UserAuthStub::AuthWidgetStub(MessageParcel &data, MessageParcel &reply)
ON_SCOPE_EXIT(IAM_LOGI("leave"));
AuthParamInner authParam;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
if (!ReadWidgetAuthParam(data, authParam)) {
IAM_LOGE("failed to read widget auth param");
return ResultCode::READ_PARCEL_ERROR;
@ -285,13 +286,20 @@ int32_t UserAuthStub::AuthWidgetStub(MessageParcel &data, MessageParcel &reply)
return ResultCode::GENERAL_ERROR;
}
sptr<IRemoteObject> objModal = data.ReadRemoteObject();
if (objModal == nullptr) {
IAM_LOGE("failed to read remote object for modal callback");
return ResultCode::READ_PARCEL_ERROR;
}
sptr<ModalCallbackInterface> modalCallback = iface_cast<ModalCallbackProxy>(objModal);
int32_t apiVersion;
if (!data.ReadInt32(apiVersion)) {
IAM_LOGE("failed to read apiVersion");
return ResultCode::READ_PARCEL_ERROR;
}
uint64_t contextId = AuthWidget(apiVersion, authParam, widgetParam, callback);
uint64_t contextId = AuthWidget(apiVersion, authParam, widgetParam, callback, modalCallback);
if (!reply.WriteUint64(contextId)) {
IAM_LOGE("failed to write contextId");
return ResultCode::WRITE_PARCEL_ERROR;
@ -349,7 +357,7 @@ bool UserAuthStub::ReadWidgetAuthParam(MessageParcel &data, AuthParamInner &auth
return true;
}
bool UserAuthStub::ReadWidgetParam(MessageParcel &data, WidgetParam &widgetParam)
bool UserAuthStub::ReadWidgetParam(MessageParcel &data, WidgetParamInner &widgetParam)
{
if (!data.ReadString(widgetParam.title)) {
IAM_LOGE("failed to read title");
@ -365,6 +373,10 @@ bool UserAuthStub::ReadWidgetParam(MessageParcel &data, WidgetParam &widgetParam
return false;
}
widgetParam.windowMode = static_cast<WindowModeType>(winMode);
if (!data.ReadBool(widgetParam.hasContext)) {
IAM_LOGE("failed to read hasContext");
return false;
}
return true;
}
@ -452,7 +464,14 @@ int32_t UserAuthStub::CancelAuthOrIdentifyStub(MessageParcel &data, MessageParce
return READ_PARCEL_ERROR;
}
int32_t result = CancelAuthOrIdentify(contextId);
int32_t cancelReason;
if (!data.ReadInt32(cancelReason)) {
IAM_LOGE("failed to read cancelReason");
return READ_PARCEL_ERROR;
}
int32_t result = CancelAuthOrIdentify(contextId, cancelReason);
if (!reply.WriteInt32(result)) {
IAM_LOGE("failed to write CancelAuthOrIdentify result");
return WRITE_PARCEL_ERROR;

View File

@ -26,7 +26,7 @@ namespace UserAuth {
class AuthWidgetHelper {
public:
static bool InitWidgetContextParam(const AuthParamInner &authParam, std::vector<AuthType> &validType,
const WidgetParam &widgetParam, ContextFactory::AuthWidgetContextPara &para);
const WidgetParamInner &widgetParam, ContextFactory::AuthWidgetContextPara &para);
static int32_t CheckValidSolution(int32_t userId,
const std::vector<AuthType> &authTypeList, const AuthTrustLevel &atl, std::vector<AuthType> &validTypeList);
static int32_t CheckReuseUnlockResult(const ContextFactory::AuthWidgetContextPara &para,

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 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
@ -50,7 +50,7 @@ public:
std::vector<uint8_t> challenge {};
std::vector<AuthType> authTypeList {};
AuthTrustLevel atl {ATL1};
WidgetParam widgetParam {};
WidgetParamInner widgetParam {};
std::map<AuthType, AuthProfile> authProfileMap {};
int32_t callerType {0};
std::string callingAppID {""};

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 2023-2024 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
@ -22,6 +22,7 @@
#include <vector>
#include "authentication_impl.h"
#include "modal_callback_interface.h"
#include "widget_callback_interface.h"
#include "widget_json.h"
#include "widget_schedule_node.h"
@ -36,7 +37,7 @@ public:
// sets
void SetWidgetSchedule(const std::shared_ptr<WidgetScheduleNode> &schedule);
void SetWidgetContextId(uint64_t contextId);
void SetWidgetParam(const WidgetParam &param);
void SetWidgetParam(const WidgetParamInner &param);
void SetAuthTypeList(const std::vector<AuthType> &authTypeList);
void SetWidgetCallback(const sptr<WidgetCallbackInterface> &callback);
void SetAuthTokenId(uint32_t tokenId);
@ -58,6 +59,9 @@ public:
void SetChallenge(const std::vector<uint8_t> &challenge);
void SetCallingBundleName(const std::string &callingBundleName);
void SetModalCallback(const sptr<ModalCallbackInterface> &callback);
void LaunchModal(const std::string &commandData);
private:
WidgetClient() = default;
void SendCommand(const WidgetCommand &command);
@ -68,7 +72,7 @@ private:
private:
std::shared_ptr<WidgetScheduleNode> schedule_ {nullptr};
uint64_t widgetContextId_ {0};
WidgetParam widgetParam_ {};
WidgetParamInner widgetParam_ {};
std::vector<AuthType> authTypeList_ {};
sptr<WidgetCallbackInterface> widgetCallback_ {nullptr};
std::string pinSubType_ {""};
@ -76,6 +80,7 @@ private:
uint32_t authTokenId_ {0};
std::vector<uint8_t> challenge_ {};
std::string callingBundleName_ {""};
sptr<ModalCallbackInterface> modalCallback_ {nullptr};
};
} // namespace UserAuth
} // namespace UserIam

View File

@ -106,8 +106,9 @@ private:
void StopAllRunTask(const ResultCode &resultCode);
std::string BuildStartCommand(const WidgetRotatePara &widgetRotatePara);
void ProcessRotatePara(WidgetCmdParameters &widgetCmdParameters, const WidgetRotatePara &widgetRotatePara);
bool isValidRotate(const WidgetRotatePara &widgetRotatePara);
bool IsValidRotate(const WidgetRotatePara &widgetRotatePara);
std::string GetCallingBundleName();
bool IsSupportFollowCallerUi();
private:
struct TaskInfo {

View File

@ -31,7 +31,7 @@ namespace UserIam {
namespace UserAuth {
bool AuthWidgetHelper::InitWidgetContextParam(const AuthParamInner &authParam, std::vector<AuthType> &validType,
const WidgetParam &widgetParam, ContextFactory::AuthWidgetContextPara &para)
const WidgetParamInner &widgetParam, ContextFactory::AuthWidgetContextPara &para)
{
for (auto &authType : validType) {
ContextFactory::AuthProfile profile;

View File

@ -185,7 +185,7 @@ void WidgetClient::SetWidgetContextId(uint64_t contextId)
widgetContextId_ = contextId;
}
void WidgetClient::SetWidgetParam(const WidgetParam &param)
void WidgetClient::SetWidgetParam(const WidgetParamInner &param)
{
widgetParam_ = param;
}
@ -321,6 +321,20 @@ void WidgetClient::SetCallingBundleName(const std::string &callingBundleName)
{
callingBundleName_ = callingBundleName;
}
void WidgetClient::SetModalCallback(const sptr<ModalCallbackInterface> &callback)
{
IAM_LOGI("set modal callback");
modalCallback_ = callback;
}
void WidgetClient::LaunchModal(const std::string &commandData)
{
IAM_LOGI("launch modal command: %{public}s", commandData.c_str());
if (modalCallback_ != nullptr) {
modalCallback_->SendCommand(widgetContextId_, commandData);
}
}
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS

View File

@ -41,6 +41,7 @@
#include "refbase.h"
#include "hisysevent_adapter.h"
#include "system_ability_definition.h"
#include "parameters.h"
#define LOG_TAG "USER_AUTH_SA"
@ -58,6 +59,7 @@ const std::string TO_PORTRAIT = "90";
const std::string TO_INVERTED = "180";
const std::string TO_PORTRAIT_INVERTED = "270";
const uint32_t NOT_SUPPORT_ORIENTATION_INVERTED = 2;
const std::string SUPPORT_FOLLOW_CALLER_UI = "const.useriam.authWidget.supportFollowCallerUi";
WidgetContext::WidgetContext(uint64_t contextId, const ContextFactory::AuthWidgetContextPara &para,
std::shared_ptr<ContextCallback> callback)
@ -373,7 +375,7 @@ bool WidgetContext::AuthWidgetReload(uint32_t orientation, uint32_t needRotate,
if (alreadyLoad) {
widgetAlreadyLoad_ = 1;
}
if (!isValidRotate(widgetRotatePara)) {
if (!IsValidRotate(widgetRotatePara)) {
IAM_LOGE("check rotate failed");
return false;
}
@ -384,7 +386,7 @@ bool WidgetContext::AuthWidgetReload(uint32_t orientation, uint32_t needRotate,
return true;
}
bool WidgetContext::isValidRotate(const WidgetRotatePara &widgetRotatePara)
bool WidgetContext::IsValidRotate(const WidgetRotatePara &widgetRotatePara)
{
IAM_LOGI("check rotate, needRotate: %{public}u, orientation: %{public}u, orientation_: %{public}u",
widgetRotatePara.needRotate, widgetRotatePara.orientation, widgetRotateOrientation_);
@ -455,8 +457,17 @@ int32_t WidgetContext::ConnectExtensionAbility(const AAFwk::Want &want, const st
return ret;
}
bool WidgetContext::IsSupportFollowCallerUi()
{
bool isSupportFollowCallerUi = OHOS::system::GetParameter(SUPPORT_FOLLOW_CALLER_UI, "false") == "true";
IAM_LOGI("is support follow caller UI: %{public}d", isSupportFollowCallerUi);
return isSupportFollowCallerUi;
}
bool WidgetContext::ConnectExtension(const WidgetRotatePara &widgetRotatePara)
{
IAM_LOGI("connect extension start");
std::lock_guard<std::recursive_mutex> lock(mutex_);
if (widgetRotatePara.isReload) {
for (auto &authType : para_.authTypeList) {
ContextFactory::AuthProfile profile;
@ -467,14 +478,22 @@ bool WidgetContext::ConnectExtension(const WidgetRotatePara &widgetRotatePara)
para_.authProfileMap[authType] = profile;
}
}
std::string tmp = BuildStartCommand(widgetRotatePara);
IAM_LOGI("start command: %{public}s", tmp.c_str());
std::string commandData = BuildStartCommand(widgetRotatePara);
IAM_LOGI("start command: %{public}s", commandData.c_str());
IAM_LOGI("has context: %{public}d", para_.widgetParam.hasContext);
if (para_.widgetParam.hasContext && IsSupportFollowCallerUi()) {
// As modal application
// No need do anything, caller death has process; only process timeout for widget.
WidgetClient::Instance().LaunchModal(commandData);
return true;
}
// Default as modal system
AAFwk::Want want;
std::string bundleName = "com.ohos.systemui";
std::string abilityName = "com.ohos.systemui.dialog";
want.SetElementName(bundleName, abilityName);
auto ret = ConnectExtensionAbility(want, tmp);
auto ret = ConnectExtensionAbility(want, commandData);
if (ret != ERR_OK) {
UserIam::UserAuth::ReportSystemFault(Common::GetNowTimeString(), "userauthservice");
IAM_LOGE("ConnectExtensionAbility failed.");
@ -485,6 +504,11 @@ bool WidgetContext::ConnectExtension(const WidgetRotatePara &widgetRotatePara)
bool WidgetContext::DisconnectExtension()
{
IAM_LOGI("has context: %{public}d", para_.widgetParam.hasContext);
if (para_.widgetParam.hasContext) {
// As modal application, need't release.
return true;
}
if (connection_ == nullptr) {
IAM_LOGE("invalid connection handle");
return false;

View File

@ -51,11 +51,11 @@ public:
sptr<UserAuthCallbackInterface> &callback) override;
uint64_t Auth(int32_t apiVersion, const std::vector<uint8_t> &challenge, AuthType authType,
AuthTrustLevel authTrustLevel, sptr<UserAuthCallbackInterface> &callback) override;
uint64_t AuthWidget(int32_t apiVersion, const AuthParamInner &authParam,
const WidgetParam &widgetParam, sptr<UserAuthCallbackInterface> &callback) override;
uint64_t AuthWidget(int32_t apiVersion, const AuthParamInner &authParam, const WidgetParamInner &widgetParam,
sptr<UserAuthCallbackInterface> &callback, sptr<ModalCallbackInterface> &modalCallback) override;
uint64_t Identify(const std::vector<uint8_t> &challenge, AuthType authType,
sptr<UserAuthCallbackInterface> &callback) override;
int32_t CancelAuthOrIdentify(uint64_t contextId) override;
int32_t CancelAuthOrIdentify(uint64_t contextId, int32_t cancelReason) override;
int32_t GetVersion(int32_t &version) override;
int32_t Notice(NoticeType noticeType, const std::string &eventData) override;
int32_t RegisterWidgetCallback(int32_t version, sptr<WidgetCallbackInterface> &callback) override;
@ -74,15 +74,15 @@ private:
std::shared_ptr<ContextCallback> GetAuthContextCallback(int32_t apiVersion,
const std::vector<uint8_t> &challenge, AuthType authType, AuthTrustLevel authTrustLevel,
sptr<UserAuthCallbackInterface> &callback);
std::shared_ptr<ContextCallback> GetAuthContextCallback(int32_t apiVersion,
const AuthParamInner &authParam, const WidgetParam &widgetParam, sptr<UserAuthCallbackInterface> &callback);
std::shared_ptr<ContextCallback> GetAuthContextCallback(int32_t apiVersion, const AuthParamInner &authParam,
const WidgetParamInner &widgetParam, sptr<UserAuthCallbackInterface> &callback);
bool CheckAuthTrustLevel(AuthTrustLevel authTrustLevel);
bool CheckSingeFaceOrFinger(const std::vector<AuthType> &authType);
int32_t CheckAuthWidgetType(const std::vector<AuthType> &authType);
int32_t CheckAuthPermissionAndParam(const AuthParamInner &authParam, const WidgetParam &widgetParam,
int32_t CheckAuthPermissionAndParam(const AuthParamInner &authParam, const WidgetParamInner &widgetParam,
bool isBackgroundApplication);
uint64_t StartWidgetContext(const std::shared_ptr<ContextCallback> &contextCallback,
const AuthParamInner &authParam, const WidgetParam &widgetParam, std::vector<AuthType> &validType,
const AuthParamInner &authParam, const WidgetParamInner &widgetParam, std::vector<AuthType> &validType,
ContextFactory::AuthWidgetContextPara &para);
uint64_t StartAuthContext(int32_t apiVersion, Authentication::AuthenticationPara para,
const std::shared_ptr<ContextCallback> &contextCallback);
@ -98,7 +98,7 @@ private:
bool CheckAuthPermissionAndParam(AuthType authType, AuthTrustLevel authTrustLevel,
const std::shared_ptr<ContextCallback> &contextCallback, Attributes &extraInfo);
bool CheckAuthTypeIsValid(std::vector<AuthType> authType);
int32_t CheckValidSolution(int32_t userId, const AuthParamInner &authParam, const WidgetParam &widgetParam,
int32_t CheckValidSolution(int32_t userId, const AuthParamInner &authParam, const WidgetParamInner &widgetParam,
std::vector<AuthType> &validType);
int32_t GetCallerInfo(bool isUserIdSpecified, int32_t userId, ContextFactory::AuthWidgetContextPara &para,
bool &isBackgroundApplication, std::shared_ptr<ContextCallback> &contextCallback);

View File

@ -750,7 +750,7 @@ uint64_t UserAuthService::Identify(const std::vector<uint8_t> &challenge, AuthTy
return context->GetContextId();
}
int32_t UserAuthService::CancelAuthOrIdentify(uint64_t contextId)
int32_t UserAuthService::CancelAuthOrIdentify(uint64_t contextId, int32_t cancelReason)
{
IAM_LOGI("start");
Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT);
@ -771,6 +771,11 @@ int32_t UserAuthService::CancelAuthOrIdentify(uint64_t contextId)
return INVALID_CONTEXT_ID;
}
if (cancelReason == CancelReason::MODAL_CREATE_ERROR || cancelReason == CancelReason::MODAL_RUN_ERROR) {
IAM_LOGE("widget modal fault");
UserIam::UserAuth::ReportSystemFault(Common::GetNowTimeString(), "AuthWidget");
}
if (!context->Stop()) {
IAM_LOGE("failed to cancel auth or identify");
return context->GetLatestError();
@ -829,8 +834,8 @@ bool UserAuthService::CheckSingeFaceOrFinger(const std::vector<AuthType> &authTy
return false;
}
int32_t UserAuthService::CheckAuthPermissionAndParam(const AuthParamInner &authParam, const WidgetParam &widgetParam,
bool isBackgroundApplication)
int32_t UserAuthService::CheckAuthPermissionAndParam(const AuthParamInner &authParam,
const WidgetParamInner &widgetParam, bool isBackgroundApplication)
{
if (!IpcCommon::CheckPermission(*this, IS_SYSTEM_APP) &&
(widgetParam.windowMode != WindowModeType::UNKNOWN_WINDOW_MODE)) {
@ -877,7 +882,7 @@ int32_t UserAuthService::CheckAuthPermissionAndParam(const AuthParamInner &authP
}
uint64_t UserAuthService::StartWidgetContext(const std::shared_ptr<ContextCallback> &contextCallback,
const AuthParamInner &authParam, const WidgetParam &widgetParam, std::vector<AuthType> &validType,
const AuthParamInner &authParam, const WidgetParamInner &widgetParam, std::vector<AuthType> &validType,
ContextFactory::AuthWidgetContextPara &para)
{
Attributes extraInfo;
@ -908,7 +913,7 @@ uint64_t UserAuthService::StartWidgetContext(const std::shared_ptr<ContextCallba
}
int32_t UserAuthService::CheckValidSolution(int32_t userId, const AuthParamInner &authParam,
const WidgetParam &widgetParam, std::vector<AuthType> &validType)
const WidgetParamInner &widgetParam, std::vector<AuthType> &validType)
{
int32_t ret = AuthWidgetHelper::CheckValidSolution(
userId, authParam.authTypes, authParam.authTrustLevel, validType);
@ -956,7 +961,8 @@ int32_t UserAuthService::GetCallerInfo(bool isUserIdSpecified, int32_t userId,
}
uint64_t UserAuthService::AuthWidget(int32_t apiVersion, const AuthParamInner &authParam,
const WidgetParam &widgetParam, sptr<UserAuthCallbackInterface> &callback)
const WidgetParamInner &widgetParam, sptr<UserAuthCallbackInterface> &callback,
sptr<ModalCallbackInterface> &modalCallback)
{
IAM_LOGI("start %{public}d authTrustLevel:%{public}u", apiVersion, authParam.authTrustLevel);
auto contextCallback = GetAuthContextCallback(apiVersion, authParam, widgetParam, callback);
@ -1001,6 +1007,9 @@ uint64_t UserAuthService::AuthWidget(int32_t apiVersion, const AuthParamInner &a
para.isPinExpired = true;
validType.emplace_back(AuthType::PIN);
}
if (modalCallback != nullptr && widgetParam.hasContext) {
WidgetClient::Instance().SetModalCallback(modalCallback);
}
return StartWidgetContext(contextCallback, authParam, widgetParam, validType, para);
}
@ -1019,7 +1028,7 @@ bool UserAuthService::Insert2ContextPool(const std::shared_ptr<Context> &context
}
std::shared_ptr<ContextCallback> UserAuthService::GetAuthContextCallback(int32_t apiVersion,
const AuthParamInner &authParam, const WidgetParam &widgetParam, sptr<UserAuthCallbackInterface> &callback)
const AuthParamInner &authParam, const WidgetParamInner &widgetParam, sptr<UserAuthCallbackInterface> &callback)
{
if (callback == nullptr) {
IAM_LOGE("callback is nullptr");

View File

@ -1,4 +1,4 @@
# Copyright (c) 2022-2023 Huawei Device Co., Ltd.
# Copyright (c) 2022-2024 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
@ -45,8 +45,11 @@ ohos_fuzztest("CoAuthClientFuzzTest") {
"../../../../frameworks/native/client/src/executor_callback_service.cpp",
"../../../../frameworks/native/client/src/executor_messenger_client.cpp",
"../../../../frameworks/native/client/src/ipc_client_utils.cpp",
"../../../../frameworks/native/client/src/modal_callback_service.cpp",
"../../../../frameworks/native/client/src/modal_extension_callback.cpp",
"../../../../frameworks/native/client/src/user_auth_callback_service.cpp",
"../../../../frameworks/native/client/src/user_auth_client_impl.cpp",
"../../../../frameworks/native/client/src/user_auth_modal_callback.cpp",
"../../../../frameworks/native/client/src/user_idm_callback_service.cpp",
"../../../../frameworks/native/client/src/user_idm_client_impl.cpp",
"co_auth_client_fuzzer.cpp",
@ -62,6 +65,13 @@ ohos_fuzztest("CoAuthClientFuzzTest") {
remove_configs = [ "//build/config/compiler:no_exceptions" ]
external_deps = [
"ability_runtime:ability_context_native",
"ability_runtime:ability_manager",
"ability_runtime:abilitykit_native",
"ability_runtime:app_context",
"ability_runtime:napi_base_context",
"ability_runtime:ui_extension",
"ace_engine:ace_uicontent",
"c_utils:utils",
"hilog:libhilog",
"ipc:ipc_single",

View File

@ -1,4 +1,4 @@
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Copyright (c) 2023-2024 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
@ -45,8 +45,11 @@ ohos_fuzztest("ExecutorCallbackStubFuzzTest") {
"../../../../frameworks/native/client/src/executor_callback_service.cpp",
"../../../../frameworks/native/client/src/executor_messenger_client.cpp",
"../../../../frameworks/native/client/src/ipc_client_utils.cpp",
"../../../../frameworks/native/client/src/modal_callback_service.cpp",
"../../../../frameworks/native/client/src/modal_extension_callback.cpp",
"../../../../frameworks/native/client/src/user_auth_callback_service.cpp",
"../../../../frameworks/native/client/src/user_auth_client_impl.cpp",
"../../../../frameworks/native/client/src/user_auth_modal_callback.cpp",
"../../../../frameworks/native/client/src/user_idm_callback_service.cpp",
"../../../../frameworks/native/client/src/user_idm_client_impl.cpp",
"../../../../frameworks/native/client/src/widget_callback_service.cpp",
@ -63,6 +66,13 @@ ohos_fuzztest("ExecutorCallbackStubFuzzTest") {
remove_configs = [ "//build/config/compiler:no_exceptions" ]
external_deps = [
"ability_runtime:ability_context_native",
"ability_runtime:ability_manager",
"ability_runtime:abilitykit_native",
"ability_runtime:app_context",
"ability_runtime:napi_base_context",
"ability_runtime:ui_extension",
"ace_engine:ace_uicontent",
"c_utils:utils",
"hilog:libhilog",
"ipc:ipc_single",

View File

@ -1,4 +1,4 @@
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Copyright (c) 2023-2024 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
@ -45,8 +45,11 @@ ohos_fuzztest("UserAuthCallbackStubFuzzTest") {
"../../../../frameworks/native/client/src/executor_callback_service.cpp",
"../../../../frameworks/native/client/src/executor_messenger_client.cpp",
"../../../../frameworks/native/client/src/ipc_client_utils.cpp",
"../../../../frameworks/native/client/src/modal_callback_service.cpp",
"../../../../frameworks/native/client/src/modal_extension_callback.cpp",
"../../../../frameworks/native/client/src/user_auth_callback_service.cpp",
"../../../../frameworks/native/client/src/user_auth_client_impl.cpp",
"../../../../frameworks/native/client/src/user_auth_modal_callback.cpp",
"../../../../frameworks/native/client/src/user_idm_callback_service.cpp",
"../../../../frameworks/native/client/src/user_idm_client_impl.cpp",
"../../../../frameworks/native/client/src/widget_callback_service.cpp",
@ -63,6 +66,13 @@ ohos_fuzztest("UserAuthCallbackStubFuzzTest") {
remove_configs = [ "//build/config/compiler:no_exceptions" ]
external_deps = [
"ability_runtime:ability_context_native",
"ability_runtime:ability_manager",
"ability_runtime:abilitykit_native",
"ability_runtime:app_context",
"ability_runtime:napi_base_context",
"ability_runtime:ui_extension",
"ace_engine:ace_uicontent",
"hilog:libhilog",
"ipc:ipc_single",
"napi:ace_napi",

View File

@ -1,4 +1,4 @@
# Copyright (c) 2022-2023 Huawei Device Co., Ltd.
# Copyright (c) 2022-2024 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
@ -44,8 +44,12 @@ ohos_fuzztest("UserAuthClientFuzzTest") {
"../../../../frameworks/native/client/src/executor_callback_service.cpp",
"../../../../frameworks/native/client/src/executor_messenger_client.cpp",
"../../../../frameworks/native/client/src/ipc_client_utils.cpp",
"../../../../frameworks/native/client/src/modal_callback_service.cpp",
"../../../../frameworks/native/client/src/modal_extension_callback.cpp",
"../../../../frameworks/native/client/src/user_auth_callback_service.cpp",
"../../../../frameworks/native/client/src/user_auth_client_impl.cpp",
"../../../../frameworks/native/client/src/user_auth_modal_callback.cpp",
"../../../../frameworks/native/client/src/user_auth_napi_client_impl.cpp",
"../../../../frameworks/native/client/src/user_idm_callback_service.cpp",
"../../../../frameworks/native/client/src/user_idm_client_impl.cpp",
"../../../../frameworks/native/client/src/widget_callback_service.cpp",
@ -62,6 +66,13 @@ ohos_fuzztest("UserAuthClientFuzzTest") {
remove_configs = [ "//build/config/compiler:no_exceptions" ]
external_deps = [
"ability_runtime:ability_context_native",
"ability_runtime:ability_manager",
"ability_runtime:abilitykit_native",
"ability_runtime:app_context",
"ability_runtime:napi_base_context",
"ability_runtime:ui_extension",
"ace_engine:ace_uicontent",
"hilog:libhilog",
"ipc:ipc_single",
"napi:ace_napi",

View File

@ -17,12 +17,15 @@
#include "parcel.h"
#include "user_auth_client_impl.h"
#include "user_auth_callback_service.h"
#include "iam_fuzz_test.h"
#include "iam_logger.h"
#include "iam_ptr.h"
#include "modal_callback_service.h"
#include "user_auth_client_impl.h"
#include "user_auth_callback_service.h"
#include "user_auth_napi_client_impl.h"
#define LOG_TAG "USER_AUTH_SDK"
namespace OHOS {
@ -277,6 +280,27 @@ void FuzzBeginWidgetAuth(Parcel &parcel)
IAM_LOGI("end");
}
void FuzzNapiBeginWidgetAuth(Parcel &parcel)
{
IAM_LOGI("start");
int32_t apiVersion = parcel.ReadInt32();
AuthParamInner authParam;
UserAuthNapiClientImpl::WidgetParamNapi widgetParam;
Common::FillFuzzUint8Vector(parcel, authParam.challenge);
std::vector<int32_t> atList;
parcel.ReadInt32Vector(&atList);
for (auto at : atList) {
authParam.authTypes.push_back(static_cast<AuthType>(at));
}
authParam.authTrustLevel = static_cast<AuthTrustLevel>(parcel.ReadInt32());
widgetParam.title = parcel.ReadString();
widgetParam.navigationButtonText = parcel.ReadString();
widgetParam.windowMode = static_cast<WindowModeType>(parcel.ReadInt32());
auto callback = Common::MakeShared<DummyAuthenticationCallback>();
UserAuthNapiClientImpl::Instance().BeginWidgetAuth(apiVersion, authParam, widgetParam, callback);
IAM_LOGI("end");
}
void FuzzSetWidgetCallback(Parcel &parcel)
{
IAM_LOGI("start");
@ -388,6 +412,7 @@ FuzzFunc *g_fuzzFuncs[] = {
FuzzGetPropCallbackServiceOnPropResult,
FuzzSetPropCallbackServiceOnPropResult,
FuzzSetGlobalConfigParam,
FuzzNapiBeginWidgetAuth,
};
void UserAuthClientFuzzTest(const uint8_t *data, size_t size)

View File

@ -1,4 +1,4 @@
# Copyright (c) 2022-2023 Huawei Device Co., Ltd.
# Copyright (c) 2022-2024 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
@ -45,8 +45,11 @@ ohos_fuzztest("UserIdmClientFuzzTest") {
"../../../../frameworks/native/client/src/executor_callback_service.cpp",
"../../../../frameworks/native/client/src/executor_messenger_client.cpp",
"../../../../frameworks/native/client/src/ipc_client_utils.cpp",
"../../../../frameworks/native/client/src/modal_callback_service.cpp",
"../../../../frameworks/native/client/src/modal_extension_callback.cpp",
"../../../../frameworks/native/client/src/user_auth_callback_service.cpp",
"../../../../frameworks/native/client/src/user_auth_client_impl.cpp",
"../../../../frameworks/native/client/src/user_auth_modal_callback.cpp",
"../../../../frameworks/native/client/src/user_idm_callback_service.cpp",
"../../../../frameworks/native/client/src/user_idm_client_impl.cpp",
"../../../../frameworks/native/client/src/widget_callback_service.cpp",
@ -63,6 +66,13 @@ ohos_fuzztest("UserIdmClientFuzzTest") {
remove_configs = [ "//build/config/compiler:no_exceptions" ]
external_deps = [
"ability_runtime:ability_context_native",
"ability_runtime:ability_manager",
"ability_runtime:abilitykit_native",
"ability_runtime:app_context",
"ability_runtime:napi_base_context",
"ability_runtime:ui_extension",
"ace_engine:ace_uicontent",
"c_utils:utils",
"hilog:libhilog",
"ipc:ipc_single",

View File

@ -1,4 +1,4 @@
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Copyright (c) 2023-2024 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
@ -45,8 +45,11 @@ ohos_fuzztest("UserIdmClientStubFuzzTest") {
"../../../../frameworks/native/client/src/executor_callback_service.cpp",
"../../../../frameworks/native/client/src/executor_messenger_client.cpp",
"../../../../frameworks/native/client/src/ipc_client_utils.cpp",
"../../../../frameworks/native/client/src/modal_callback_service.cpp",
"../../../../frameworks/native/client/src/modal_extension_callback.cpp",
"../../../../frameworks/native/client/src/user_auth_callback_service.cpp",
"../../../../frameworks/native/client/src/user_auth_client_impl.cpp",
"../../../../frameworks/native/client/src/user_auth_modal_callback.cpp",
"../../../../frameworks/native/client/src/user_idm_callback_service.cpp",
"../../../../frameworks/native/client/src/user_idm_client_impl.cpp",
"../../../../frameworks/native/client/src/widget_callback_service.cpp",
@ -63,6 +66,13 @@ ohos_fuzztest("UserIdmClientStubFuzzTest") {
remove_configs = [ "//build/config/compiler:no_exceptions" ]
external_deps = [
"ability_runtime:ability_context_native",
"ability_runtime:ability_manager",
"ability_runtime:abilitykit_native",
"ability_runtime:app_context",
"ability_runtime:napi_base_context",
"ability_runtime:ui_extension",
"ace_engine:ace_uicontent",
"c_utils:utils",
"hilog:libhilog",
"ipc:ipc_single",

View File

@ -81,6 +81,7 @@ ohos_source_set("userauth_client_ipc_fuzzer") {
"../../../frameworks/native/ipc/src/co_auth_proxy.cpp",
"../../../frameworks/native/ipc/src/executor_callback_stub.cpp",
"../../../frameworks/native/ipc/src/executor_messenger_proxy.cpp",
"../../../frameworks/native/ipc/src/modal_callback_stub.cpp",
"../../../frameworks/native/ipc/src/user_auth_callback_stub.cpp",
"../../../frameworks/native/ipc/src/user_auth_event_listener_stub.cpp",
"../../../frameworks/native/ipc/src/user_auth_proxy.cpp",
@ -318,6 +319,7 @@ ohos_source_set("userauth_service_ipc_fuzzer") {
"../../../frameworks/native/ipc/src/co_auth_stub.cpp",
"../../../frameworks/native/ipc/src/executor_callback_proxy.cpp",
"../../../frameworks/native/ipc/src/executor_messenger_stub.cpp",
"../../../frameworks/native/ipc/src/modal_callback_proxy.cpp",
"../../../frameworks/native/ipc/src/user_auth_callback_proxy.cpp",
"../../../frameworks/native/ipc/src/user_auth_event_listener_proxy.cpp",
"../../../frameworks/native/ipc/src/user_auth_stub.cpp",

View File

@ -202,7 +202,7 @@ void FuzzAuthWidgetHelper(Parcel &parcel)
authParam.authTypes.push_back(PIN);
authParam.authTypes.push_back(FINGERPRINT);
authParam.authTrustLevel = ATL2;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "确定";
ContextFactory::AuthWidgetContextPara para;

View File

@ -265,7 +265,8 @@ void FuzzCancelAuthOrIdentify(Parcel &parcel)
{
IAM_LOGI("begin");
uint64_t contextId = parcel.ReadUint64();
g_userAuthService.CancelAuthOrIdentify(contextId);
int32_t cancelReason = parcel.ReadInt32();
g_userAuthService.CancelAuthOrIdentify(contextId, cancelReason);
IAM_LOGI("end");
}
@ -282,7 +283,7 @@ void FuzzAuthWidget(Parcel &parcel)
IAM_LOGI("begin");
int32_t apiVersion = parcel.ReadInt32();
AuthParamInner authParam;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
FillFuzzUint8Vector(parcel, authParam.challenge);
std::vector<int32_t> atList;
parcel.ReadInt32Vector(&atList);
@ -297,7 +298,8 @@ void FuzzAuthWidget(Parcel &parcel)
if (parcel.ReadBool()) {
callback = sptr<UserAuthCallbackInterface>(new (std::nothrow) DummyUserAuthCallback());
}
g_userAuthService.AuthWidget(apiVersion, authParam, widgetParam, callback);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
g_userAuthService.AuthWidget(apiVersion, authParam, widgetParam, callback, testModalCallback);
IAM_LOGI("end");
}
@ -376,7 +378,7 @@ void FuzzCheckValidSolution(Parcel &parcel)
.authType = static_cast<AuthType>(parcel.ReadInt32()),
.authTrustLevel = static_cast<AuthTrustLevel>(parcel.ReadInt32()),
};
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = parcel.ReadString();
widgetParam.navigationButtonText = parcel.ReadString();
widgetParam.windowMode = static_cast<WindowModeType>(parcel.ReadInt32());
@ -411,7 +413,7 @@ void FuzzGetAuthContextCallback(Parcel &parcel)
IAM_LOGI("begin");
int32_t apiVersion = parcel.ReadInt32();
AuthParamInner authParam = {};
WidgetParam widgetParam = {};
WidgetParamInner widgetParam = {};
sptr<UserAuthCallbackInterface> callback = sptr<UserAuthCallbackInterface>(new (nothrow) DummyUserAuthCallback);
g_userAuthService.GetAuthContextCallback(apiVersion, authParam, widgetParam, callback);
authParam.authTypes = {PIN, FACE, FINGERPRINT};
@ -507,7 +509,7 @@ void FuzzStartWidgetContext(Parcel &parcel)
sptr<IamCallbackInterface> iamCallback = sptr<IamCallbackInterface>(new (nothrow) DummyIamCallbackInterface);
std::shared_ptr<ContextCallback> contextCallback = ContextCallback::NewInstance(iamCallback, TRACE_ADD_CREDENTIAL);
AuthParamInner authParam = {};
WidgetParam widgetParam = {};
WidgetParamInner widgetParam = {};
std::vector<AuthType> validType = {PIN};
ContextFactory::AuthWidgetContextPara para;
g_userAuthService.StartWidgetContext(contextCallback, authParam, widgetParam, validType, para);

View File

@ -40,8 +40,12 @@ ohos_unittest("iam_inner_api_test") {
"../../../frameworks/native/client/src/co_auth_client_impl.cpp",
"../../../frameworks/native/client/src/executor_callback_service.cpp",
"../../../frameworks/native/client/src/executor_messenger_client.cpp",
"../../../frameworks/native/client/src/modal_callback_service.cpp",
"../../../frameworks/native/client/src/modal_extension_callback.cpp",
"../../../frameworks/native/client/src/user_auth_callback_service.cpp",
"../../../frameworks/native/client/src/user_auth_client_impl.cpp",
"../../../frameworks/native/client/src/user_auth_modal_callback.cpp",
"../../../frameworks/native/client/src/user_auth_napi_client_impl.cpp",
"../../../frameworks/native/client/src/user_idm_callback_service.cpp",
"../../../frameworks/native/client/src/user_idm_client_impl.cpp",
"../../../frameworks/native/client/src/widget_callback_service.cpp",
@ -60,6 +64,7 @@ ohos_unittest("iam_inner_api_test") {
"src/user_auth_callback_stub_test.cpp",
"src/user_auth_client_test.cpp",
"src/user_auth_event_listener_stub_test.cpp",
"src/user_auth_napi_client_test.cpp",
"src/user_auth_proxy_test.cpp",
"src/user_idm_callback_proxy_test.cpp",
"src/user_idm_callback_service_test.cpp",
@ -86,6 +91,13 @@ ohos_unittest("iam_inner_api_test") {
]
external_deps = [
"ability_runtime:ability_context_native",
"ability_runtime:ability_manager",
"ability_runtime:abilitykit_native",
"ability_runtime:app_context",
"ability_runtime:napi_base_context",
"ability_runtime:ui_extension",
"ace_engine:ace_uicontent",
"c_utils:utils",
"googletest:gmock",
"hilog:libhilog",

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2024 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 USER_AUTH_NAPI_CLIENT_TEST_H
#define USER_AUTH_NAPI_CLIENT_TEST_H
#include <gtest/gtest.h>
#include "mock_ipc_client_utils.h"
#include "mock_remote_object.h"
#include "mock_user_auth_callback_service.h"
#include "mock_user_auth_service.h"
#include "mock_user_auth_client_callback.h"
#include "mock_user_auth_modal_callback.h"
namespace OHOS {
namespace UserIam {
namespace UserAuth {
class UserAuthNapiClientTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp() override;
void TearDown() override;
void CallRemoteObject(const std::shared_ptr<MockUserAuthService> service, const sptr<MockRemoteObject> &obj,
sptr<IRemoteObject::DeathRecipient> &dr);
};
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS
#endif // USER_AUTH_NAPI_CLIENT_TEST_H

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2024 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 MOCK_USER_AUTH_MODAL_CALLBACK_H
#define MOCK_USER_AUTH_MODAL_CALLBACK_H
#include <gmock/gmock.h>
#include "user_auth_modal_callback.h"
namespace OHOS {
namespace UserIam {
namespace UserAuth {
class MockUserAuthModalCallback final : public UserAuthModalCallback {
public:
MockUserAuthModalCallback(const std::shared_ptr<AbilityRuntime::Context> context);
virtual ~MockUserAuthModalCallback() = default;
MOCK_METHOD2(SendCommand, void(uint64_t contextId, const std::string &cmdData));
MOCK_METHOD0(IsModalInit, void());
MOCK_METHOD0(IsModalDestroy, void());
};
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS
#endif // MOCK_USER_AUTH_MODAL_CALLBACK_H

View File

@ -16,6 +16,7 @@
#include "user_auth_client_test.h"
#include "iam_ptr.h"
#include "modal_callback_service.h"
#include "user_auth_client.h"
#include "user_auth_client_impl.h"
@ -392,14 +393,16 @@ HWTEST_F(UserAuthClientTest, UserAuthClientCancelAuthentication001, TestSize.Lev
HWTEST_F(UserAuthClientTest, UserAuthClientCancelAuthentication002, TestSize.Level0)
{
uint64_t testContextId = 12345562;
int32_t testCancelReason = 0;
auto service = Common::MakeShared<MockUserAuthService>();
EXPECT_NE(service, nullptr);
EXPECT_CALL(*service, CancelAuthOrIdentify(_)).Times(1);
EXPECT_CALL(*service, CancelAuthOrIdentify(_, _)).Times(1);
ON_CALL(*service, CancelAuthOrIdentify)
.WillByDefault(
[&testContextId](uint64_t contextId) {
[&testContextId, &testCancelReason](uint64_t contextId, int32_t cancelReason) {
EXPECT_EQ(contextId, testContextId);
EXPECT_EQ(cancelReason, testCancelReason);
return SUCCESS;
}
);
@ -479,14 +482,16 @@ HWTEST_F(UserAuthClientTest, UserAuthClientCancelIdentification001, TestSize.Lev
HWTEST_F(UserAuthClientTest, UserAuthClientCancelIdentification002, TestSize.Level0)
{
uint64_t testContextId = 1221215;
int32_t testCancelReason = 0;
auto service = Common::MakeShared<MockUserAuthService>();
EXPECT_NE(service, nullptr);
EXPECT_CALL(*service, CancelAuthOrIdentify(_)).Times(1);
EXPECT_CALL(*service, CancelAuthOrIdentify(_, _)).Times(1);
ON_CALL(*service, CancelAuthOrIdentify)
.WillByDefault(
[&testContextId](uint64_t contextId) {
[&testContextId, &testCancelReason](uint64_t contextId, int32_t cancelReason) {
EXPECT_EQ(contextId, testContextId);
EXPECT_EQ(cancelReason, testCancelReason);
return SUCCESS;
}
);
@ -599,23 +604,23 @@ HWTEST_F(UserAuthClientTest, UserAuthClientBeginWidgetAuth003, TestSize.Level0)
AuthParamInner testParam = {};
testParam.challenge = {0};
testParam.authTypes = {ALL};
WidgetParam testWidgetParam = {};
testWidgetParam.title = "title";
WidgetParamInner testWidgetParamInner = {};
testWidgetParamInner.title = "title";
auto testCallback = Common::MakeShared<MockAuthenticationCallback>();
EXPECT_NE(testCallback, nullptr);
uint64_t testContextVersion = 1;
auto service = Common::MakeShared<MockUserAuthService>();
EXPECT_NE(service, nullptr);
EXPECT_CALL(*service, AuthWidget(_, _, _, _)).WillRepeatedly(Return(true));
EXPECT_CALL(*service, AuthWidget(_, _, _, _, _)).WillRepeatedly(Return(true));
ON_CALL(*service, AuthWidget)
.WillByDefault(
[&testVersion, &testParam, &testWidgetParam, &testContextVersion](int32_t apiVersion,
const AuthParamInner &authParam, const WidgetParam &widgetParam,
sptr<UserAuthCallbackInterface> &callback) {
[&testVersion, &testParam, &testWidgetParamInner, &testContextVersion](int32_t apiVersion,
const AuthParamInner &authParam, const WidgetParamInner &widgetParam,
sptr<UserAuthCallbackInterface> &callback, sptr<ModalCallbackInterface> &modalCallback) {
EXPECT_EQ(apiVersion, testVersion);
EXPECT_EQ(authParam.authTypes, testParam.authTypes);
EXPECT_EQ(widgetParam.title, testWidgetParam.title);
EXPECT_EQ(widgetParam.title, testWidgetParamInner.title);
if (callback != nullptr) {
Attributes extraInfo;
callback->OnResult(static_cast<int32_t>(ResultCode::GENERAL_ERROR), extraInfo);
@ -628,6 +633,8 @@ HWTEST_F(UserAuthClientTest, UserAuthClientBeginWidgetAuth003, TestSize.Level0)
sptr<IRemoteObject::DeathRecipient> dr(nullptr);
CallRemoteObject(service, obj, dr);
WidgetAuthParam testAuthParam = {};
WidgetParam testWidgetParam = {};
testWidgetParam.title = "title";
uint64_t widgetAuth = UserAuthClientImpl::Instance().BeginWidgetAuth(testVersion, testAuthParam,
testWidgetParam, testCallback);
EXPECT_EQ(widgetAuth, testContextVersion);
@ -635,7 +642,6 @@ HWTEST_F(UserAuthClientTest, UserAuthClientBeginWidgetAuth003, TestSize.Level0)
IpcClientUtils::ResetObj();
}
HWTEST_F(UserAuthClientTest, UserAuthClientSetWidgetCallback001, TestSize.Level0)
{
static const int32_t apiVersion = 0;

View File

@ -0,0 +1,122 @@
/*
* Copyright (C) 2024 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 "user_auth_napi_client_test.h"
#include "iam_ptr.h"
#include "modal_callback_service.h"
#include "user_auth_napi_client_impl.h"
namespace OHOS {
namespace UserIam {
namespace UserAuth {
using namespace testing;
using namespace testing::ext;
void UserAuthNapiClientTest::SetUpTestCase()
{
}
void UserAuthNapiClientTest::TearDownTestCase()
{
}
void UserAuthNapiClientTest::SetUp()
{
}
void UserAuthNapiClientTest::TearDown()
{
}
HWTEST_F(UserAuthNapiClientTest, UserAuthNapiClientBeginWidgetAuth001, TestSize.Level0)
{
static const int32_t apiVersion = 0;
AuthParamInner authParam;
UserAuthNapiClientImpl::WidgetParamNapi widgetParam;
std::shared_ptr<MockAuthenticationCallback> testCallback = nullptr;
testCallback = Common::MakeShared<MockAuthenticationCallback>();
uint64_t widgetAuth = UserAuthNapiClientImpl::Instance().BeginWidgetAuth(apiVersion, authParam,
widgetParam, testCallback);
EXPECT_EQ(widgetAuth, 0);
}
HWTEST_F(UserAuthNapiClientTest, UserAuthNapiClientBeginWidgetAuth002, TestSize.Level0)
{
int32_t testVersion = 0;
AuthParamInner testParam = {};
testParam.challenge = {0};
testParam.authTypes = {ALL};
WidgetParamInner testWidgetParamInner = {};
testWidgetParamInner.title = "title";
auto testCallback = Common::MakeShared<MockAuthenticationCallback>();
EXPECT_NE(testCallback, nullptr);
uint64_t testContextVersion = 1;
auto service = Common::MakeShared<MockUserAuthService>();
EXPECT_NE(service, nullptr);
EXPECT_CALL(*service, AuthWidget(_, _, _, _, _)).WillRepeatedly(Return(true));
ON_CALL(*service, AuthWidget)
.WillByDefault(
[&testVersion, &testParam, &testWidgetParamInner, &testContextVersion](int32_t apiVersion,
const AuthParamInner &authParam, const WidgetParamInner &widgetParam,
sptr<UserAuthCallbackInterface> &callback, sptr<ModalCallbackInterface> &modalCallback) {
EXPECT_EQ(apiVersion, testVersion);
EXPECT_EQ(authParam.authTypes, testParam.authTypes);
EXPECT_EQ(widgetParam.title, testWidgetParamInner.title);
if (callback != nullptr) {
Attributes extraInfo;
callback->OnResult(static_cast<int32_t>(ResultCode::GENERAL_ERROR), extraInfo);
}
return testContextVersion;
}
);
sptr<MockRemoteObject> obj = new MockRemoteObject();
sptr<IRemoteObject::DeathRecipient> dr(nullptr);
CallRemoteObject(service, obj, dr);
AuthParamInner testAuthParam = {};
UserAuthNapiClientImpl::WidgetParamNapi testWidgetParam = {};
testWidgetParam.title = "title";
uint64_t widgetAuth = UserAuthNapiClientImpl::Instance().BeginWidgetAuth(testVersion, testAuthParam,
testWidgetParam, testCallback);
EXPECT_EQ(widgetAuth, testContextVersion);
dr->OnRemoteDied(obj);
IpcClientUtils::ResetObj();
}
void UserAuthNapiClientTest::CallRemoteObject(const std::shared_ptr<MockUserAuthService> service,
const sptr<MockRemoteObject> &obj, sptr<IRemoteObject::DeathRecipient> &dr)
{
EXPECT_NE(obj, nullptr);
EXPECT_CALL(*obj, IsProxyObject()).WillRepeatedly(Return(true));
EXPECT_CALL(*obj, RemoveDeathRecipient(_)).WillRepeatedly(Return(true));
EXPECT_CALL(*obj, AddDeathRecipient(_))
.WillRepeatedly([&dr](const sptr<IRemoteObject::DeathRecipient> &recipient) {
dr = recipient;
return true;
});
IpcClientUtils::SetObj(obj);
EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
ON_CALL(*obj, SendRequest)
.WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
service->OnRemoteRequest(code, data, reply, option);
return OHOS::NO_ERROR;
});
}
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS

View File

@ -17,11 +17,13 @@
#include "iam_ptr.h"
#include "user_auth_proxy.h"
#include "mock_modal_callback.h"
#include "mock_remote_object.h"
#include "mock_user_auth_service.h"
#include "mock_user_auth_client_callback.h"
#include "mock_user_auth_callback_service.h"
#include "mock_iuser_auth_widget_callback.h"
#include "modal_callback_service.h"
#include "user_auth_callback_service.h"
#include "widget_callback_service.h"
@ -261,6 +263,7 @@ HWTEST_F(UserAuthProxyTest, UserAuthProxyAuthUser, TestSize.Level0)
HWTEST_F(UserAuthProxyTest, UserAuthProxyCancelAuthOrIdentify, TestSize.Level0)
{
static const uint64_t testContextId = 200;
static const int32_t testCancelReason = 0;
sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
EXPECT_NE(obj, nullptr);
@ -268,10 +271,11 @@ HWTEST_F(UserAuthProxyTest, UserAuthProxyCancelAuthOrIdentify, TestSize.Level0)
EXPECT_NE(proxy, nullptr);
auto service = Common::MakeShared<MockUserAuthService>();
EXPECT_NE(service, nullptr);
EXPECT_CALL(*service, CancelAuthOrIdentify(_))
EXPECT_CALL(*service, CancelAuthOrIdentify(_, _))
.Times(Exactly(1))
.WillOnce([](uint64_t contextId) {
.WillOnce([](uint64_t contextId, int32_t cancelReason) {
EXPECT_EQ(contextId, testContextId);
EXPECT_EQ(cancelReason, testCancelReason);
return SUCCESS;
});
EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
@ -280,7 +284,7 @@ HWTEST_F(UserAuthProxyTest, UserAuthProxyCancelAuthOrIdentify, TestSize.Level0)
service->OnRemoteRequest(code, data, reply, option);
return SUCCESS;
});
proxy->CancelAuthOrIdentify(testContextId);
proxy->CancelAuthOrIdentify(testContextId, testCancelReason);
}
HWTEST_F(UserAuthProxyTest, UserAuthProxyIdentify, TestSize.Level0)
@ -319,7 +323,7 @@ HWTEST_F(UserAuthProxyTest, UserAuthProxyAuthWidget001, TestSize.Level0)
{
static const int32_t testApiVersion = 0;
AuthParamInner authParam;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
EXPECT_NE(obj, nullptr);
@ -331,12 +335,19 @@ HWTEST_F(UserAuthProxyTest, UserAuthProxyAuthWidget001, TestSize.Level0)
new (std::nothrow) UserAuthCallbackService(identifyCallback);
auto service = Common::MakeShared<MockUserAuthService>();
EXPECT_NE(service, nullptr);
EXPECT_CALL(*service, AuthWidget(_, _, _, _))
sptr<ModalCallbackInterface> testModalCallback = new MockModalCallback();
EXPECT_NE(testModalCallback, nullptr);
auto *mockModalCallback = static_cast<MockModalCallback *>(testModalCallback.GetRefPtr());
EXPECT_NE(mockModalCallback, nullptr);
EXPECT_CALL(*mockModalCallback, SendCommand(_, _)).Times(0);
EXPECT_CALL(*service, AuthWidget(_, _, _, _, _))
.Times(Exactly(1))
.WillOnce([&testCallback](int32_t apiVersion, const AuthParamInner &authParam, const WidgetParam &widgetParam,
sptr<UserAuthCallbackInterface> &callback) {
.WillOnce([&testCallback, &testModalCallback](int32_t apiVersion, const AuthParamInner &authParam,
const WidgetParamInner &widgetParam, sptr<UserAuthCallbackInterface> &callback,
sptr<ModalCallbackInterface> &modalCallback) {
EXPECT_EQ(apiVersion, testApiVersion);
EXPECT_EQ(callback, testCallback);
EXPECT_EQ(modalCallback, testModalCallback);
return 0;
});
EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
@ -345,21 +356,22 @@ HWTEST_F(UserAuthProxyTest, UserAuthProxyAuthWidget001, TestSize.Level0)
service->OnRemoteRequest(code, data, reply, option);
return SUCCESS;
});
proxy->AuthWidget(testApiVersion, authParam, widgetParam, testCallback);
proxy->AuthWidget(testApiVersion, authParam, widgetParam, testCallback, testModalCallback);
}
HWTEST_F(UserAuthProxyTest, UserAuthProxyAuthWidget002, TestSize.Level0)
{
static const int32_t testApiVersion = 0;
AuthParamInner authParam;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
EXPECT_NE(obj, nullptr);
auto proxy = Common::MakeShared<UserAuthProxy>(obj);
EXPECT_NE(proxy, nullptr);
sptr<UserAuthCallbackInterface> testCallback(nullptr);
proxy->AuthWidget(testApiVersion, authParam, widgetParam, testCallback);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
proxy->AuthWidget(testApiVersion, authParam, widgetParam, testCallback, testModalCallback);
}
HWTEST_F(UserAuthProxyTest, UserAuthProxyNotice001, TestSize.Level0)

View File

@ -182,13 +182,18 @@ ohos_unittest("iam_services_test") {
"ability_base:want",
"ability_base:zuri",
"ability_runtime:ability_context_native",
"ability_runtime:ability_manager",
"ability_runtime:abilitykit_native",
"ability_runtime:app_context",
"ability_runtime:app_manager",
"ability_runtime:extension_manager",
"ability_runtime:napi_base_context",
"ability_runtime:ui_extension",
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"access_token:libtokenid_sdk",
"ace_engine:ace_uicontent",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"device_manager:devicemanagersdk",

View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2024 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 IAM_MOCK_MODAL_CALLBACK_H
#define IAM_MOCK_MODAL_CALLBACK_H
#include <gmock/gmock.h>
#include <iremote_stub.h>
#include "modal_callback_interface.h"
namespace OHOS {
namespace UserIam {
namespace UserAuth {
class MockModalCallback final : public IRemoteStub<ModalCallbackInterface> {
public:
MOCK_METHOD4(OnRemoteRequest,
int32_t(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option));
MOCK_METHOD2(SendCommand, void(uint64_t contextId, const std::string &cmdData));
};
} // namespace UserAuth
} // namespace UserIam
} // namespace OHOS
#endif // IAM_MOCK_MODAL_CALLBACK_H

View File

@ -18,6 +18,7 @@
#include <gmock/gmock.h>
#include "user_auth_stub.h"
#include "modal_callback_stub.h"
namespace OHOS {
namespace UserIam {
@ -48,13 +49,14 @@ public:
uint64_t(int32_t apiVersion, const std::vector<uint8_t> &challenge, AuthType authType,
AuthTrustLevel authTrustLevel, sptr<UserAuthCallbackInterface> &callback));
MOCK_METHOD4(AuthWidget, uint64_t(int32_t apiVersion, const AuthParamInner &authParam,
const WidgetParam &widgetParam, sptr<UserAuthCallbackInterface> &callback));
MOCK_METHOD5(AuthWidget, uint64_t(int32_t apiVersion, const AuthParamInner &authParam,
const WidgetParamInner &widgetParam, sptr<UserAuthCallbackInterface> &callback,
sptr<ModalCallbackInterface> &modalCallback));
MOCK_METHOD3(Identify,
uint64_t(const std::vector<uint8_t> &challenge, AuthType authType, sptr<UserAuthCallbackInterface> &callback));
MOCK_METHOD1(CancelAuthOrIdentify, int32_t(uint64_t contextId));
MOCK_METHOD2(CancelAuthOrIdentify, int32_t(uint64_t contextId, int32_t cancelReason));
MOCK_METHOD1(GetVersion, int32_t(int32_t &version));
MOCK_METHOD2(Notice, int32_t(NoticeType noticeType, const std::string &eventData));
MOCK_METHOD2(RegisterWidgetCallback, int32_t(int32_t version, sptr<WidgetCallbackInterface> &callback));

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Huawei Device Co., Ltd.
* Copyright (C) 2022-2024 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
@ -63,7 +63,7 @@ HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestInitWidgetContextParam001, Te
authParam.authTypes.push_back(PIN);
authParam.authTypes.push_back(FINGERPRINT);
authParam.authTrustLevel = ATL2;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "确定";
ContextFactory::AuthWidgetContextPara para;
@ -80,7 +80,7 @@ HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestInitWidgetContextParam002, Te
authParam.authTypes.push_back(PIN);
authParam.authTypes.push_back(FINGERPRINT);
authParam.authTrustLevel = ATL2;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "确定";
ContextFactory::AuthWidgetContextPara para;

View File

@ -1068,10 +1068,11 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceCancelAuthOrIdentify_001, TestSize.
{
UserAuthService service;
uint64_t testContextId = 12355236;
EXPECT_EQ(service.CancelAuthOrIdentify(testContextId), CHECK_PERMISSION_FAILED);
int32_t cancelReason = 0;
EXPECT_EQ(service.CancelAuthOrIdentify(testContextId, cancelReason), CHECK_PERMISSION_FAILED);
IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION);
EXPECT_EQ(service.CancelAuthOrIdentify(testContextId), GENERAL_ERROR);
EXPECT_EQ(service.CancelAuthOrIdentify(testContextId, cancelReason), GENERAL_ERROR);
IpcCommon::DeleteAllPermission();
}
@ -1080,6 +1081,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceCancelAuthOrIdentify_002, TestSize.
UserAuthService service;
uint64_t testContextId = 0x5678;
uint32_t tokenId = 0x1234;
int32_t cancelReason = 0;
IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION);
IpcCommon::SetAccessTokenId(0, true);
@ -1094,11 +1096,11 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceCancelAuthOrIdentify_002, TestSize.
EXPECT_TRUE(ContextPool::Instance().Insert(context));
EXPECT_EQ(service.CancelAuthOrIdentify(testContextId), INVALID_CONTEXT_ID);
EXPECT_EQ(service.CancelAuthOrIdentify(testContextId, cancelReason), INVALID_CONTEXT_ID);
IpcCommon::SetAccessTokenId(tokenId, true);
EXPECT_EQ(service.CancelAuthOrIdentify(testContextId), GENERAL_ERROR);
EXPECT_EQ(service.CancelAuthOrIdentify(testContextId), SUCCESS);
EXPECT_EQ(service.CancelAuthOrIdentify(testContextId, cancelReason), GENERAL_ERROR);
EXPECT_EQ(service.CancelAuthOrIdentify(testContextId, cancelReason), SUCCESS);
EXPECT_TRUE(ContextPool::Instance().Delete(testContextId));
IpcCommon::DeleteAllPermission();
}

View File

@ -25,6 +25,7 @@
#include "mock_context.h"
#include "mock_iuser_auth_interface.h"
#include "mock_ipc_common.h"
#include "mock_modal_callback.h"
#include "mock_user_auth_callback.h"
#include "mock_user_auth_service.h"
#include "mock_resource_node.h"
@ -49,12 +50,14 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_001, TestSize.Level0)
authParam.challenge.push_back(4);
authParam.authTypes.push_back(FACE);
authParam.authTrustLevel = ATL2;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "确定";
sptr<UserAuthCallbackInterface> testUserAuthCallback(nullptr);
EXPECT_EQ(service.AuthWidget(apiVersion, authParam, widgetParam, testUserAuthCallback), (uint64_t)0);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
EXPECT_EQ(service.AuthWidget(apiVersion, authParam, widgetParam, testUserAuthCallback, testModalCallback),
(uint64_t)0);
}
HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_002, TestSize.Level0)
@ -68,7 +71,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_002, TestSize.Level0)
authParam.challenge.push_back(4);
authParam.authTypes.push_back(FACE);
authParam.authTrustLevel = ATL2;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "";
widgetParam.windowMode = WindowModeType::FULLSCREEN;
@ -77,7 +80,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_002, TestSize.Level0)
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
IpcCommon::AddPermission(USE_USER_IDM_PERMISSION);
sptr<UserAuthCallbackInterface> callbackInterface = testCallback;
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback);
EXPECT_NE(conxtId, INVALID_CONTEXT_ID);
IpcCommon::DeleteAllPermission();
}
@ -93,7 +97,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_003, TestSize.Level0)
authParam.challenge.push_back(4);
authParam.authTypes.push_back(FACE);
authParam.authTrustLevel = ATL2;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "";
widgetParam.windowMode = WindowModeType::FULLSCREEN;
@ -102,7 +106,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_003, TestSize.Level0)
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
IpcCommon::AddPermission(IS_SYSTEM_APP);
sptr<UserAuthCallbackInterface> callbackInterface = testCallback;
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback);
EXPECT_NE(conxtId, INVALID_CONTEXT_ID);
IpcCommon::DeleteAllPermission();
}
@ -118,7 +123,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_004, TestSize.Level0)
authParam.challenge.push_back(4);
authParam.authTypes.push_back(FACE);
authParam.authTrustLevel = ATL2;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "";
widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE;
@ -127,7 +132,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_004, TestSize.Level0)
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
IpcCommon::AddPermission(USE_USER_IDM_PERMISSION);
sptr<UserAuthCallbackInterface> callbackInterface = testCallback;
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback);
EXPECT_NE(conxtId, INVALID_CONTEXT_ID);
IpcCommon::DeleteAllPermission();
}
@ -143,19 +149,20 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_005, TestSize.Level0)
authParam.challenge.push_back(4);
authParam.authTypes.push_back(FACE);
authParam.authTrustLevel = ATL2;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "";
widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE;
sptr<MockUserAuthCallback> testCallback(new (std::nothrow) MockUserAuthCallback);
EXPECT_NE(testCallback, nullptr);
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(2);
IpcCommon::AddPermission(IS_SYSTEM_APP);
IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION);
sptr<UserAuthCallbackInterface> callbackInterface = testCallback;
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback);
EXPECT_NE(conxtId, INVALID_CONTEXT_ID);
service.CancelAuthOrIdentify(conxtId);
service.CancelAuthOrIdentify(conxtId, 0);
IpcCommon::DeleteAllPermission();
}
@ -170,19 +177,20 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_006, TestSize.Level0)
authParam.challenge.push_back(4);
authParam.authTypes.push_back(FACE);
authParam.authTrustLevel = ATL2;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "";
widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE;
sptr<MockUserAuthCallback> testCallback(new (std::nothrow) MockUserAuthCallback);
EXPECT_NE(testCallback, nullptr);
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(2);
IpcCommon::AddPermission(IS_SYSTEM_APP);
IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION);
sptr<UserAuthCallbackInterface> callbackInterface = testCallback;
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback);
EXPECT_NE(conxtId, INVALID_CONTEXT_ID);
service.CancelAuthOrIdentify(conxtId);
service.CancelAuthOrIdentify(conxtId, 0);
IpcCommon::DeleteAllPermission();
}
@ -196,7 +204,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_007, TestSize.Level0)
authParam.challenge.push_back(3);
authParam.challenge.push_back(4);
authParam.authTrustLevel = ATL2;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "";
widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE;
@ -208,14 +216,15 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_007, TestSize.Level0)
IpcCommon::AddPermission(IS_SYSTEM_APP);
IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION);
sptr<UserAuthCallbackInterface> callbackInterface = testCallback;
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback);
EXPECT_NE(conxtId, INVALID_CONTEXT_ID);
authParam.authTypes.push_back(FACE);
authParam.authTypes.push_back(FACE);
authParam.authTypes.push_back(FACE);
authParam.authTypes.push_back(FACE);
conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface);
conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback);
EXPECT_NE(conxtId, INVALID_CONTEXT_ID);
IpcCommon::DeleteAllPermission();
}
@ -231,7 +240,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_008, TestSize.Level0)
authParam.challenge.push_back(4);
authParam.authTypes.push_back(static_cast<AuthType>(5));
authParam.authTrustLevel = ATL2;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "";
widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE;
@ -241,7 +250,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_008, TestSize.Level0)
IpcCommon::AddPermission(IS_SYSTEM_APP);
IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION);
sptr<UserAuthCallbackInterface> callbackInterface = testCallback;
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback);
EXPECT_NE(conxtId, INVALID_CONTEXT_ID);
IpcCommon::DeleteAllPermission();
}
@ -257,7 +267,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_009, TestSize.Level0)
authParam.challenge.push_back(4);
authParam.authTypes.push_back(AuthType::ALL);
authParam.authTrustLevel = ATL2;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "";
widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE;
@ -267,7 +277,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_009, TestSize.Level0)
IpcCommon::AddPermission(IS_SYSTEM_APP);
IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION);
sptr<UserAuthCallbackInterface> callbackInterface = testCallback;
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback);
EXPECT_NE(conxtId, INVALID_CONTEXT_ID);
IpcCommon::DeleteAllPermission();
}
@ -283,7 +294,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_010, TestSize.Level0)
authParam.challenge.push_back(4);
authParam.authTypes.push_back(AuthType::PIN);
authParam.authTrustLevel = (AuthTrustLevel)50000;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "";
widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE;
@ -293,7 +304,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_010, TestSize.Level0)
IpcCommon::AddPermission(IS_SYSTEM_APP);
IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION);
sptr<UserAuthCallbackInterface> callbackInterface = testCallback;
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback);
EXPECT_NE(conxtId, INVALID_CONTEXT_ID);
IpcCommon::DeleteAllPermission();
}
@ -309,7 +321,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_011, TestSize.Level0)
authParam.challenge.push_back(4);
authParam.authTypes.push_back(AuthType::PIN);
authParam.authTrustLevel = ATL1;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "";
widgetParam.navigationButtonText = "";
widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE;
@ -319,7 +331,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_011, TestSize.Level0)
IpcCommon::AddPermission(IS_SYSTEM_APP);
IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION);
sptr<UserAuthCallbackInterface> callbackInterface = testCallback;
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback);
EXPECT_NE(conxtId, INVALID_CONTEXT_ID);
IpcCommon::DeleteAllPermission();
}
@ -335,19 +348,20 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_012, TestSize.Level0)
authParam.challenge.push_back(4);
authParam.authTypes.push_back(AuthType::PIN);
authParam.authTrustLevel = ATL1;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "WidgetParamTitle";
widgetParam.navigationButtonText = "";
widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE;
sptr<MockUserAuthCallback> testCallback(new (std::nothrow) MockUserAuthCallback);
EXPECT_NE(testCallback, nullptr);
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(2);
IpcCommon::AddPermission(IS_SYSTEM_APP);
IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION);
sptr<UserAuthCallbackInterface> callbackInterface = testCallback;
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback);
EXPECT_NE(conxtId, INVALID_CONTEXT_ID);
service.CancelAuthOrIdentify(conxtId);
service.CancelAuthOrIdentify(conxtId, 0);
IpcCommon::DeleteAllPermission();
}
@ -362,7 +376,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_013, TestSize.Level0)
authParam.challenge.push_back(4);
authParam.authTypes.push_back(FACE);
authParam.authTrustLevel = ATL2;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "";
widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE;
@ -376,7 +390,12 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_013, TestSize.Level0)
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
EXPECT_NE(mockHdi, nullptr);
EXPECT_CALL(*mockHdi, GetValidSolution(_, _, _, _)).WillRepeatedly(Return(FAIL));
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback);
sptr<ModalCallbackInterface> modalCallback = new MockModalCallback();
EXPECT_NE(modalCallback, nullptr);
auto *testModalCallback = static_cast<MockModalCallback *>(modalCallback.GetRefPtr());
EXPECT_NE(testModalCallback, nullptr);
EXPECT_CALL(*testModalCallback, SendCommand(_, _)).Times(0);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, modalCallback);
EXPECT_NE(conxtId, INVALID_CONTEXT_ID);
IpcCommon::DeleteAllPermission();
}
@ -392,7 +411,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_014, TestSize.Level0)
authParam.challenge.push_back(4);
authParam.authTypes.push_back(FACE);
authParam.authTrustLevel = (AuthTrustLevel)50000;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "";
widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE;
@ -403,7 +422,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_014, TestSize.Level0)
EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(1);
IpcCommon::AddPermission(IS_SYSTEM_APP);
IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback);
EXPECT_NE(conxtId, INVALID_CONTEXT_ID);
IpcCommon::DeleteAllPermission();
}
@ -419,7 +439,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_015, TestSize.Level0)
authParam.challenge.push_back(4);
authParam.authTypes.push_back(AuthType::FINGERPRINT);
authParam.authTrustLevel = ATL2;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "";
widgetParam.windowMode = WindowModeType::FULLSCREEN;
@ -427,7 +447,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_015, TestSize.Level0)
EXPECT_NE(testCallback, nullptr);
auto *tempCallback = static_cast<MockUserAuthCallback *>(testCallback.GetRefPtr());
EXPECT_NE(tempCallback, nullptr);
EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(1);
EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(2);
IpcCommon::AddPermission(IS_SYSTEM_APP);
IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION);
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
@ -447,9 +467,10 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_015, TestSize.Level0)
}
);
ResourceNodePool::Instance().Insert(nullptr);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback);
EXPECT_NE(conxtId, INVALID_CONTEXT_ID);
service.CancelAuthOrIdentify(conxtId);
service.CancelAuthOrIdentify(conxtId, 0);
IpcCommon::DeleteAllPermission();
}
@ -461,7 +482,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_016, TestSize.Level0)
authParam.challenge.push_back(1);
authParam.authTypes.push_back(AuthType::PIN);
authParam.authTrustLevel = ATL2;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "";
widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE;
@ -469,7 +490,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_016, TestSize.Level0)
EXPECT_NE(testCallback, nullptr);
auto *tempCallback = static_cast<MockUserAuthCallback *>(testCallback.GetRefPtr());
EXPECT_NE(tempCallback, nullptr);
EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(1);
EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(2);
IpcCommon::AddPermission(IS_SYSTEM_APP);
IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION);
int32_t acquire = 20;
@ -497,10 +518,11 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_016, TestSize.Level0)
return SUCCESS;
}
);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback);
EXPECT_NE(conxtId, INVALID_CONTEXT_ID);
EXPECT_TRUE(ResourceNodePool::Instance().Delete(0));
service.CancelAuthOrIdentify(conxtId);
service.CancelAuthOrIdentify(conxtId, 0);
IpcCommon::DeleteAllPermission();
}
@ -512,15 +534,14 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0017, TestSize.Level0)
authParam.challenge.push_back(1);
authParam.authTypes.push_back(AuthType::FINGERPRINT);
authParam.authTrustLevel = ATL2;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "";
widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE;
sptr<UserAuthCallbackInterface> testCallback = new MockUserAuthCallback();
EXPECT_NE(testCallback, nullptr);
auto *tempCallback = static_cast<MockUserAuthCallback *>(testCallback.GetRefPtr());
EXPECT_NE(tempCallback, nullptr);
EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(1);
EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(2);
IpcCommon::AddPermission(IS_SYSTEM_APP);
IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION);
int32_t acquire = 20;
@ -549,10 +570,11 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0017, TestSize.Level0)
return SUCCESS;
}
);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback);
EXPECT_NE(conxtId, INVALID_CONTEXT_ID);
EXPECT_TRUE(ResourceNodePool::Instance().Delete(0));
service.CancelAuthOrIdentify(conxtId);
service.CancelAuthOrIdentify(conxtId, 0);
IpcCommon::DeleteAllPermission();
}
@ -564,7 +586,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0018, TestSize.Level0)
authParam.challenge.push_back(1);
authParam.authTypes.push_back(AuthType::FINGERPRINT);
authParam.authTrustLevel = ATL2;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "";
widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE;
@ -572,7 +594,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0018, TestSize.Level0)
EXPECT_NE(testCallback, nullptr);
auto *tempCallback = static_cast<MockUserAuthCallback *>(testCallback.GetRefPtr());
EXPECT_NE(tempCallback, nullptr);
EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(1);
EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(2);
IpcCommon::AddPermission(IS_SYSTEM_APP);
IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION);
int32_t acquire = 20;
@ -600,10 +622,11 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0018, TestSize.Level0)
return SUCCESS;
}
);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback);
EXPECT_NE(conxtId, INVALID_CONTEXT_ID);
EXPECT_TRUE(ResourceNodePool::Instance().Delete(0));
service.CancelAuthOrIdentify(conxtId);
service.CancelAuthOrIdentify(conxtId, 0);
IpcCommon::DeleteAllPermission();
}
@ -615,15 +638,13 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0019, TestSize.Level0)
authParam.challenge.push_back(1);
authParam.authTypes.push_back(AuthType::FINGERPRINT);
authParam.authTrustLevel = ATL2;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "";
widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE;
sptr<UserAuthCallbackInterface> testCallback = new MockUserAuthCallback();
EXPECT_NE(testCallback, nullptr);
auto *tempCallback = static_cast<MockUserAuthCallback *>(testCallback.GetRefPtr());
EXPECT_NE(tempCallback, nullptr);
EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(1);
EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(2);
IpcCommon::AddPermission(IS_SYSTEM_APP);
IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION);
int32_t acquire = 20;
@ -652,10 +673,11 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0019, TestSize.Level0)
return SUCCESS;
}
);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback);
EXPECT_NE(conxtId, INVALID_CONTEXT_ID);
EXPECT_TRUE(ResourceNodePool::Instance().Delete(0));
service.CancelAuthOrIdentify(conxtId);
service.CancelAuthOrIdentify(conxtId, 0);
IpcCommon::DeleteAllPermission();
}
@ -667,7 +689,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0020, TestSize.Level0)
authParam.challenge.push_back(1);
authParam.authTypes.push_back(AuthType::PIN);
authParam.authTrustLevel = ATL2;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "";
widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE;
@ -702,7 +724,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0020, TestSize.Level0)
return SUCCESS;
}
);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback);
EXPECT_NE(conxtId, INVALID_CONTEXT_ID);
EXPECT_TRUE(ResourceNodePool::Instance().Delete(0));
IpcCommon::DeleteAllPermission();
@ -716,7 +739,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0021, TestSize.Level0)
authParam.challenge.push_back(1);
authParam.authTypes.push_back(AuthType::ALL);
authParam.authTrustLevel = ATL2;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "";
widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE;
@ -751,7 +774,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0021, TestSize.Level0)
return SUCCESS;
}
);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback);
EXPECT_NE(conxtId, INVALID_CONTEXT_ID);
EXPECT_TRUE(ResourceNodePool::Instance().Delete(0));
IpcCommon::DeleteAllPermission();
@ -765,7 +789,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_022, TestSize.Level0)
authParam.challenge.push_back(1);
authParam.authTypes.push_back(AuthType::FINGERPRINT);
authParam.authTrustLevel = ATL2;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "";
widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE;
@ -800,7 +824,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_022, TestSize.Level0)
return SUCCESS;
}
);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback);
EXPECT_NE(conxtId, INVALID_CONTEXT_ID);
EXPECT_TRUE(ResourceNodePool::Instance().Delete(0));
IpcCommon::DeleteAllPermission();
@ -817,7 +842,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_023, TestSize.Level0)
authParam.reuseUnlockResult.isReuse = true;
authParam.reuseUnlockResult.reuseMode = AUTH_TYPE_IRRELEVANT;
authParam.reuseUnlockResult.reuseDuration = 5 * 60 *1000;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "";
widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE;
@ -838,7 +863,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_023, TestSize.Level0)
return HDF_SUCCESS;
}
);
uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback);
EXPECT_EQ(contextId, REUSE_AUTH_RESULT_CONTEXT_ID);
IpcCommon::DeleteAllPermission();
}
@ -851,7 +877,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_024, TestSize.Level0)
authParam.challenge.push_back(1);
authParam.authTypes.push_back(AuthType::FACE);
authParam.authTrustLevel = ATL2;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "确定";
widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE;
@ -863,7 +889,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_024, TestSize.Level0)
EXPECT_NE(mockHdi, nullptr);
EXPECT_CALL(*mockHdi, GetAvailableStatus(_, _, _, _)).Times(0);
EXPECT_CALL(*mockHdi, BeginAuthentication(_, _, _)).Times(0);
uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback);
EXPECT_EQ(contextId, BAD_CONTEXT_ID);
IpcCommon::DeleteAllPermission();
}
@ -876,7 +903,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_025, TestSize.Level0)
authParam.challenge.push_back(1);
authParam.authTypes.push_back(AuthType::FACE);
authParam.authTrustLevel = ATL2;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "确定";
widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE;
@ -895,7 +922,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_025, TestSize.Level0)
return PIN_EXPIRED;
}
);
uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback);
EXPECT_EQ(contextId, BAD_CONTEXT_ID);
IpcCommon::DeleteAllPermission();
}
@ -908,7 +936,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_026, TestSize.Level0)
authParam.challenge.push_back(1);
authParam.authTypes.push_back(AuthType::FACE);
authParam.authTrustLevel = ATL2;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "";
widgetParam.windowMode = WindowModeType::FULLSCREEN;
@ -929,7 +957,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_026, TestSize.Level0)
return HDF_SUCCESS;
}
);
uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback);
EXPECT_EQ(contextId, BAD_CONTEXT_ID);
IpcCommon::DeleteAllPermission();
}
@ -942,7 +971,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_027, TestSize.Level0)
authParam.challenge.push_back(1);
authParam.authTypes.push_back(AuthType::FINGERPRINT);
authParam.authTrustLevel = ATL2;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "";
widgetParam.windowMode = WindowModeType::FULLSCREEN;
@ -963,7 +992,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_027, TestSize.Level0)
return HDF_SUCCESS;
}
);
uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback);
EXPECT_EQ(contextId, BAD_CONTEXT_ID);
IpcCommon::DeleteAllPermission();
}
@ -976,7 +1006,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_028, TestSize.Level0)
authParam.challenge.push_back(1);
authParam.authTypes.push_back(AuthType::PIN);
authParam.authTrustLevel = ATL2;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "";
widgetParam.windowMode = WindowModeType::FULLSCREEN;
@ -997,7 +1027,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_028, TestSize.Level0)
return HDF_SUCCESS;
}
);
uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback);
EXPECT_EQ(contextId, BAD_CONTEXT_ID);
IpcCommon::DeleteAllPermission();
}
@ -1011,7 +1042,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_029, TestSize.Level0)
authParam.authTypes.push_back(AuthType::PIN);
authParam.authTrustLevel = ATL2;
authParam.isUserIdSpecified = true;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "";
widgetParam.windowMode = WindowModeType::FULLSCREEN;
@ -1032,7 +1063,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_029, TestSize.Level0)
return HDF_SUCCESS;
}
);
uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback);
EXPECT_EQ(contextId, BAD_CONTEXT_ID);
IpcCommon::DeleteAllPermission();
}
@ -1046,7 +1078,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_030, TestSize.Level0)
authParam.authTypes.push_back(AuthType::PIN);
authParam.authTrustLevel = ATL2;
authParam.isUserIdSpecified = true;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "";
widgetParam.windowMode = WindowModeType::FULLSCREEN;
@ -1067,7 +1099,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_030, TestSize.Level0)
return HDF_SUCCESS;
}
);
uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback);
EXPECT_EQ(contextId, BAD_CONTEXT_ID);
IpcCommon::DeleteAllPermission();
}
@ -1081,7 +1114,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_031, TestSize.Level0)
authParam.authTypes.push_back(AuthType::FACE);
authParam.authTypes.push_back(AuthType::FINGERPRINT);
authParam.authTrustLevel = ATL2;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "";
widgetParam.windowMode = WindowModeType::FULLSCREEN;
@ -1093,7 +1126,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_031, TestSize.Level0)
EXPECT_NE(mockHdi, nullptr);
EXPECT_CALL(*mockHdi, GetAvailableStatus(_, _, _, _)).Times(0);
EXPECT_CALL(*mockHdi, BeginAuthentication(_, _, _)).Times(0);
uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback);
EXPECT_EQ(contextId, BAD_CONTEXT_ID);
IpcCommon::DeleteAllPermission();
}
@ -1107,7 +1141,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_032, TestSize.Level0)
authParam.authTypes.push_back(AuthType::FINGERPRINT);
authParam.authTypes.push_back(AuthType::FACE);
authParam.authTrustLevel = ATL2;
WidgetParam widgetParam;
WidgetParamInner widgetParam;
widgetParam.title = "使用密码验证";
widgetParam.navigationButtonText = "";
widgetParam.windowMode = WindowModeType::FULLSCREEN;
@ -1119,7 +1153,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_032, TestSize.Level0)
EXPECT_NE(mockHdi, nullptr);
EXPECT_CALL(*mockHdi, GetAvailableStatus(_, _, _, _)).Times(0);
EXPECT_CALL(*mockHdi, BeginAuthentication(_, _, _)).Times(0);
uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback);
sptr<ModalCallbackInterface> testModalCallback(nullptr);
uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback);
EXPECT_EQ(contextId, BAD_CONTEXT_ID);
IpcCommon::DeleteAllPermission();
}

View File

@ -784,13 +784,15 @@ HWTEST_F(UserAuthStubTest, UserAuthStubCancelAuthOrIdentifyStub001, TestSize.Lev
HWTEST_F(UserAuthStubTest, UserAuthStubCancelAuthOrIdentifyStub002, TestSize.Level0)
{
uint64_t testContextId = 9346248;
int32_t testCancelReason = 0;
MockUserAuthService service;
EXPECT_CALL(service, CancelAuthOrIdentify(_)).Times(1);
EXPECT_CALL(service, CancelAuthOrIdentify(_, _)).Times(1);
ON_CALL(service, CancelAuthOrIdentify)
.WillByDefault(
[&testContextId](uint64_t contextId) {
[&testContextId, &testCancelReason](uint64_t contextId, int32_t cancelReason) {
EXPECT_EQ(contextId, testContextId);
EXPECT_EQ(cancelReason, testCancelReason);
return SUCCESS;
}
);
@ -802,6 +804,7 @@ HWTEST_F(UserAuthStubTest, UserAuthStubCancelAuthOrIdentifyStub002, TestSize.Lev
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
EXPECT_TRUE(data.WriteUint64(testContextId));
EXPECT_TRUE(data.WriteInt32(testCancelReason));
EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
int32_t result = FAIL;
@ -812,13 +815,15 @@ HWTEST_F(UserAuthStubTest, UserAuthStubCancelAuthOrIdentifyStub002, TestSize.Lev
HWTEST_F(UserAuthStubTest, UserAuthStubCancelAuthOrIdentifyStub003, TestSize.Level0)
{
uint64_t testContextId = 9346248;
int32_t testCancelReason = 0;
MockUserAuthService service;
EXPECT_CALL(service, CancelAuthOrIdentify(_)).Times(1);
EXPECT_CALL(service, CancelAuthOrIdentify(_, _)).Times(1);
ON_CALL(service, CancelAuthOrIdentify)
.WillByDefault(
[&testContextId](uint64_t contextId) {
[&testContextId, &testCancelReason](uint64_t contextId, int32_t cancelReason) {
EXPECT_EQ(contextId, testContextId);
EXPECT_EQ(cancelReason, testCancelReason);
return SUCCESS;
}
);
@ -830,6 +835,7 @@ HWTEST_F(UserAuthStubTest, UserAuthStubCancelAuthOrIdentifyStub003, TestSize.Lev
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
EXPECT_TRUE(data.WriteUint64(testContextId));
EXPECT_TRUE(data.WriteInt32(testCancelReason));
EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
int32_t result = FAIL;

View File

@ -98,7 +98,7 @@ HWTEST_F(WidgetClientTest, WidgetClientTestSetWidgetSchedule_0002, TestSize.Leve
HWTEST_F(WidgetClientTest, WidgetClientTestSetWidgetParam, TestSize.Level0)
{
WidgetParam widgetParam;
WidgetParamInner widgetParam;
WidgetClient::Instance().SetWidgetParam(widgetParam);
EXPECT_EQ(widgetParam.title, "");
}