mirror of
https://gitee.com/openharmony/useriam_user_auth_framework
synced 2025-02-20 00:34:36 +00:00
add for only first support invented
Signed-off-by: liuhanxiong <liuhanxiong@huawei.com> Change-Id: Ib212a4e60a6f1b4f09c187afbd132a9470d14f48
This commit is contained in:
parent
8233965da3
commit
b188c6c089
@ -71,7 +71,8 @@ public:
|
||||
void EndAuthAsWidgetParaInvalid() override;
|
||||
void StopAuthList(const std::vector<AuthType> &authTypeList) override;
|
||||
void SuccessAuth(AuthType authType) override;
|
||||
bool AuthWidgetReload(uint32_t orientation, uint32_t needRotate, AuthType &rotateAuthType) override;
|
||||
bool AuthWidgetReload(uint32_t orientation, uint32_t needRotate, uint32_t alreadyLoad,
|
||||
AuthType &rotateAuthType) override;
|
||||
void AuthWidgetReloadInit() override;
|
||||
|
||||
void AuthResult(int32_t resultCode, int32_t authType, const Attributes &finalResult);
|
||||
@ -86,6 +87,7 @@ private:
|
||||
bool isReload {false};
|
||||
uint32_t orientation {0};
|
||||
uint32_t needRotate {0};
|
||||
uint32_t alreadyLoad {0};
|
||||
AuthType rotateAuthType {0};
|
||||
};
|
||||
void SetLatestError(int32_t error) override;
|
||||
@ -131,6 +133,7 @@ private:
|
||||
WidgetAuthResultInfo authResultInfo_ {};
|
||||
int32_t faceReload_ {0};
|
||||
uint32_t widgetRotateOrientation_ {0};
|
||||
uint32_t widgetAlreadyLoad_ {0};
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
|
@ -44,6 +44,7 @@ struct WidgetNotice {
|
||||
std::string event {""};
|
||||
uint32_t orientation {0};
|
||||
uint32_t needRotate {0};
|
||||
uint32_t alreadyLoad {0};
|
||||
std::string version {""};
|
||||
std::vector<std::string> typeList {};
|
||||
bool endAfterFirstFail {false};
|
||||
|
@ -110,7 +110,7 @@ void WidgetClient::ProcessNotice(const WidgetNotice ¬ice, std::vector<AuthTyp
|
||||
if ((authTypeList.size() == 1 && authTypeList[0] == AuthType::ALL) || authTypeList.size() != 1) {
|
||||
schedule_->WidgetParaInvalid();
|
||||
} else {
|
||||
schedule_->WidgetReload(notice.orientation, notice.needRotate, authTypeList[0]);
|
||||
schedule_->WidgetReload(notice.orientation, notice.needRotate, notice.alreadyLoad, authTypeList[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -335,7 +335,8 @@ void WidgetContext::AuthWidgetReloadInit()
|
||||
}
|
||||
}
|
||||
|
||||
bool WidgetContext::AuthWidgetReload(uint32_t orientation, uint32_t needRotate, AuthType &rotateAuthType)
|
||||
bool WidgetContext::AuthWidgetReload(uint32_t orientation, uint32_t needRotate, uint32_t alreadyLoad,
|
||||
AuthType &rotateAuthType)
|
||||
{
|
||||
IAM_LOGI("auth widget reload");
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
@ -343,7 +344,11 @@ bool WidgetContext::AuthWidgetReload(uint32_t orientation, uint32_t needRotate,
|
||||
widgetRotatePara.isReload = true;
|
||||
widgetRotatePara.orientation = orientation;
|
||||
widgetRotatePara.needRotate = needRotate;
|
||||
widgetRotatePara.alreadyLoad = alreadyLoad;
|
||||
widgetRotatePara.rotateAuthType = rotateAuthType;
|
||||
if (alreadyLoad) {
|
||||
widgetAlreadyLoad_ = 1;
|
||||
}
|
||||
if (!isValidRotate(widgetRotatePara)) {
|
||||
IAM_LOGE("check rotate failed");
|
||||
return false;
|
||||
@ -360,9 +365,10 @@ bool WidgetContext::isValidRotate(const WidgetRotatePara &widgetRotatePara)
|
||||
IAM_LOGI("check rotate, needRotate: %{public}u, orientation: %{public}u, orientation_: %{public}u",
|
||||
widgetRotatePara.needRotate, widgetRotatePara.orientation, widgetRotateOrientation_);
|
||||
if (widgetRotatePara.needRotate) {
|
||||
if (widgetRotatePara.orientation == ORIENTATION_PORTRAIT_INVERTED) {
|
||||
IAM_LOGI("not support");
|
||||
return false;
|
||||
IAM_LOGI("check rotate, widgetAlreadyLoad_: %{public}u", widgetAlreadyLoad_);
|
||||
if (widgetRotatePara.orientation == ORIENTATION_PORTRAIT_INVERTED && !widgetAlreadyLoad_) {
|
||||
IAM_LOGI("only support first");
|
||||
return true;
|
||||
}
|
||||
if (widgetRotatePara.orientation > widgetRotateOrientation_ &&
|
||||
widgetRotatePara.orientation - widgetRotateOrientation_ == NOT_SUPPORT_ORIENTATION_INVERTED) {
|
||||
|
@ -45,6 +45,7 @@ const std::string JSON_AUTH_PAYLOAD = "payload";
|
||||
const std::string JSON_AUTH_END_AFTER_FIRST_FAIL = "endAfterFirstFail";
|
||||
const std::string JSON_ORIENTATION = "orientation";
|
||||
const std::string JSON_NEED_ROTATE = "needRotate";
|
||||
const std::string JSON_ALREADY_LOAD = "alreadyLoad";
|
||||
const std::string JSON_LOCKOUT_DURATION = "lockoutDuration";
|
||||
const std::string JSON_REMAIN_ATTEMPTS = "remainAttempts";
|
||||
const std::string JSON_AUTH_RESULT = "result";
|
||||
@ -201,6 +202,7 @@ void to_json(nlohmann::json &jsonNotice, const WidgetNotice ¬ice)
|
||||
{JSON_AUTH_EVENT, notice.event},
|
||||
{JSON_ORIENTATION, notice.orientation},
|
||||
{JSON_NEED_ROTATE, notice.needRotate},
|
||||
{JSON_ALREADY_LOAD, notice.alreadyLoad},
|
||||
{JSON_AUTH_VERSION, notice.version},
|
||||
{JSON_AUTH_PAYLOAD, type}});
|
||||
}
|
||||
@ -219,6 +221,9 @@ void from_json(const nlohmann::json &jsonNotice, WidgetNotice ¬ice)
|
||||
if (jsonNotice.find(JSON_NEED_ROTATE) != jsonNotice.end() && jsonNotice[JSON_NEED_ROTATE].is_number()) {
|
||||
jsonNotice.at(JSON_NEED_ROTATE).get_to(notice.needRotate);
|
||||
}
|
||||
if (jsonNotice.find(JSON_ALREADY_LOAD) != jsonNotice.end() && jsonNotice[JSON_ALREADY_LOAD].is_number()) {
|
||||
jsonNotice.at(JSON_ALREADY_LOAD).get_to(notice.alreadyLoad);
|
||||
}
|
||||
if (jsonNotice.find(JSON_AUTH_VERSION) != jsonNotice.end() && jsonNotice[JSON_AUTH_VERSION].is_string()) {
|
||||
jsonNotice.at(JSON_AUTH_VERSION).get_to(notice.version);
|
||||
}
|
||||
|
@ -60,7 +60,8 @@ public:
|
||||
virtual bool SuccessAuth(AuthType authType) = 0;
|
||||
virtual bool NaviPinAuth() = 0;
|
||||
virtual bool WidgetParaInvalid() = 0;
|
||||
virtual bool WidgetReload(uint32_t orientation, uint32_t needRotate, AuthType &rotateAuthType) = 0;
|
||||
virtual bool WidgetReload(uint32_t orientation, uint32_t needRotate, uint32_t alreadyLoad,
|
||||
AuthType &rotateAuthType) = 0;
|
||||
virtual void SetCallback(std::shared_ptr<WidgetScheduleNodeCallback> callback) = 0;
|
||||
};
|
||||
} // namespace UserAuth
|
||||
|
@ -38,7 +38,8 @@ public:
|
||||
virtual void EndAuthAsWidgetParaInvalid() = 0;
|
||||
virtual void StopAuthList(const std::vector<AuthType> &authTypeList) = 0;
|
||||
virtual void SuccessAuth(AuthType authType) = 0;
|
||||
virtual bool AuthWidgetReload(uint32_t orientation, uint32_t needRotate, AuthType &rotateAuthType) = 0;
|
||||
virtual bool AuthWidgetReload(uint32_t orientation, uint32_t needRotate, uint32_t alreadyLoad,
|
||||
AuthType &rotateAuthType) = 0;
|
||||
virtual void AuthWidgetReloadInit() = 0;
|
||||
};
|
||||
} // namespace UserAuth
|
||||
|
@ -148,11 +148,13 @@ bool WidgetScheduleNodeImpl::WidgetParaInvalid()
|
||||
return TryKickMachine(E_WIDGET_PARA_INVALID);
|
||||
}
|
||||
|
||||
bool WidgetScheduleNodeImpl::WidgetReload(uint32_t orientation, uint32_t needRotate, AuthType &rotateAuthType)
|
||||
bool WidgetScheduleNodeImpl::WidgetReload(uint32_t orientation, uint32_t needRotate, uint32_t alreadyLoad,
|
||||
AuthType &rotateAuthType)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
orientation_ = orientation;
|
||||
needRotate_ = needRotate;
|
||||
alreadyLoad_ = alreadyLoad;
|
||||
rotateAuthType_ = rotateAuthType;
|
||||
return TryKickMachine(E_WIDGET_RELOAD);
|
||||
}
|
||||
@ -241,7 +243,7 @@ void WidgetScheduleNodeImpl::OnWidgetReload(FiniteStateMachine &machine, uint32_
|
||||
const uint32_t reloadInitMs = 100;
|
||||
auto sleepTime = std::chrono::milliseconds(reloadInitMs);
|
||||
std::this_thread::sleep_for(sleepTime);
|
||||
if (!callback->AuthWidgetReload(orientation_, needRotate_, rotateAuthType_)) {
|
||||
if (!callback->AuthWidgetReload(orientation_, needRotate_, alreadyLoad_, rotateAuthType_)) {
|
||||
IAM_LOGE("Failed to reload widget, cancel Auth");
|
||||
StopSchedule();
|
||||
}
|
||||
|
@ -44,7 +44,8 @@ public:
|
||||
bool SuccessAuth(AuthType authType) override;
|
||||
bool NaviPinAuth() override;
|
||||
bool WidgetParaInvalid() override;
|
||||
bool WidgetReload(uint32_t orientation, uint32_t needRotate, AuthType &rotateAuthType) override;
|
||||
bool WidgetReload(uint32_t orientation, uint32_t needRotate, uint32_t alreadyLoad,
|
||||
AuthType &rotateAuthType) override;
|
||||
void SetCallback(std::shared_ptr<WidgetScheduleNodeCallback> callback) override;
|
||||
|
||||
protected:
|
||||
@ -75,6 +76,7 @@ private:
|
||||
std::set<AuthType> runningAuthTypeSet_;
|
||||
uint32_t orientation_ {0};
|
||||
uint32_t needRotate_ {0};
|
||||
uint32_t alreadyLoad_ {0};
|
||||
AuthType rotateAuthType_ {0};
|
||||
};
|
||||
} // namespace UserAuth
|
||||
|
@ -32,7 +32,8 @@ public:
|
||||
MOCK_METHOD0(NaviPinAuth, bool());
|
||||
MOCK_METHOD0(WidgetParaInvalid, bool());
|
||||
MOCK_METHOD1(SetCallback, void(std::shared_ptr<WidgetScheduleNodeCallback>));
|
||||
MOCK_METHOD3(WidgetReload, bool(uint32_t orientation, uint32_t needRotate, AuthType &rotateAuthType));
|
||||
MOCK_METHOD4(WidgetReload, bool(uint32_t orientation, uint32_t needRotate, uint32_t alreadyLoad,
|
||||
AuthType &rotateAuthType));
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
|
@ -34,7 +34,8 @@ public:
|
||||
MOCK_METHOD0(EndAuthAsWidgetParaInvalid, void());
|
||||
MOCK_METHOD1(StopAuthList, void(const std::vector<AuthType> &authTypeList));
|
||||
MOCK_METHOD1(SuccessAuth, void(AuthType authType));
|
||||
MOCK_METHOD3(AuthWidgetReload, bool(uint32_t orientation, uint32_t needRotate, AuthType &rotateAuthType));
|
||||
MOCK_METHOD4(AuthWidgetReload, bool(uint32_t orientation, uint32_t needRotate, uint32_t alreadyLoad,
|
||||
AuthType &rotateAuthType));
|
||||
MOCK_METHOD0(AuthWidgetReloadInit, void());
|
||||
};
|
||||
} // namespace UserAuth
|
||||
|
@ -407,8 +407,9 @@ HWTEST_F(WidgetContextTest, WidgetContextTestAuthWidgetReload_0001, TestSize.Lev
|
||||
auto widgetContext = CreateWidgetContext(contextId, para);
|
||||
uint32_t orientation = 1;
|
||||
uint32_t needRotate = 1;
|
||||
uint32_t alreadyLoad = 1;
|
||||
AuthType rotateAuthType = PIN;
|
||||
widgetContext->AuthWidgetReload(orientation, needRotate, rotateAuthType);
|
||||
widgetContext->AuthWidgetReload(orientation, needRotate, alreadyLoad, rotateAuthType);
|
||||
EXPECT_NE(widgetContext, nullptr);
|
||||
auto handler = ThreadHandler::GetSingleThreadInstance();
|
||||
handler->EnsureTask(nullptr);
|
||||
@ -421,8 +422,9 @@ HWTEST_F(WidgetContextTest, WidgetContextTestAuthWidgetReload_0002, TestSize.Lev
|
||||
auto widgetContext = CreateWidgetContext(contextId, para);
|
||||
uint32_t orientation = 2;
|
||||
uint32_t needRotate = 1;
|
||||
uint32_t alreadyLoad = 1;
|
||||
AuthType rotateAuthType = FINGERPRINT;
|
||||
widgetContext->AuthWidgetReload(orientation, needRotate, rotateAuthType);
|
||||
widgetContext->AuthWidgetReload(orientation, needRotate, alreadyLoad, rotateAuthType);
|
||||
EXPECT_NE(widgetContext, nullptr);
|
||||
auto handler = ThreadHandler::GetSingleThreadInstance();
|
||||
handler->EnsureTask(nullptr);
|
||||
@ -435,8 +437,9 @@ HWTEST_F(WidgetContextTest, WidgetContextTestAuthWidgetReload_0003, TestSize.Lev
|
||||
auto widgetContext = CreateWidgetContext(contextId, para);
|
||||
uint32_t orientation = 3;
|
||||
uint32_t needRotate = 1;
|
||||
uint32_t alreadyLoad = 1;
|
||||
AuthType rotateAuthType = FACE;
|
||||
widgetContext->AuthWidgetReload(orientation, needRotate, rotateAuthType);
|
||||
widgetContext->AuthWidgetReload(orientation, needRotate, alreadyLoad, rotateAuthType);
|
||||
EXPECT_NE(widgetContext, nullptr);
|
||||
auto handler = ThreadHandler::GetSingleThreadInstance();
|
||||
handler->EnsureTask(nullptr);
|
||||
|
@ -159,8 +159,9 @@ HWTEST_F(WidgetScheduleNodeImplTest, WidgetScheduleNodeImplWidgetReload_0001, Te
|
||||
schedule->StartSchedule();
|
||||
uint32_t orientation = 1;
|
||||
uint32_t needRotate = 1;
|
||||
uint32_t alreadyLoad = 1;
|
||||
AuthType rotateAuthType = PIN;
|
||||
EXPECT_TRUE(schedule->WidgetReload(orientation, needRotate, rotateAuthType));
|
||||
EXPECT_TRUE(schedule->WidgetReload(orientation, needRotate, alreadyLoad, rotateAuthType));
|
||||
widgetContext->LaunchWidget();
|
||||
auto handler = ThreadHandler::GetSingleThreadInstance();
|
||||
handler->EnsureTask(nullptr);
|
||||
@ -174,8 +175,9 @@ HWTEST_F(WidgetScheduleNodeImplTest, WidgetScheduleNodeImplWidgetReload_0002, Te
|
||||
schedule->StartSchedule();
|
||||
uint32_t orientation = 2;
|
||||
uint32_t needRotate = 1;
|
||||
uint32_t alreadyLoad = 1;
|
||||
AuthType rotateAuthType = FINGERPRINT;
|
||||
EXPECT_TRUE(schedule->WidgetReload(orientation, needRotate, rotateAuthType));
|
||||
EXPECT_TRUE(schedule->WidgetReload(orientation, needRotate, alreadyLoad, rotateAuthType));
|
||||
widgetContext->LaunchWidget();
|
||||
auto handler = ThreadHandler::GetSingleThreadInstance();
|
||||
handler->EnsureTask(nullptr);
|
||||
@ -189,8 +191,9 @@ HWTEST_F(WidgetScheduleNodeImplTest, WidgetScheduleNodeImplWidgetReload_0003, Te
|
||||
schedule->StartSchedule();
|
||||
uint32_t orientation = 3;
|
||||
uint32_t needRotate = 1;
|
||||
uint32_t alreadyLoad = 1;
|
||||
AuthType rotateAuthType = FACE;
|
||||
EXPECT_TRUE(schedule->WidgetReload(orientation, needRotate, rotateAuthType));
|
||||
EXPECT_TRUE(schedule->WidgetReload(orientation, needRotate, alreadyLoad, rotateAuthType));
|
||||
widgetContext->LaunchWidget();
|
||||
auto handler = ThreadHandler::GetSingleThreadInstance();
|
||||
handler->EnsureTask(nullptr);
|
||||
|
Loading…
x
Reference in New Issue
Block a user