Signed-off-by: ma-shaoyin <mashaoyin1@huawei.com>

Changes to be committed:
This commit is contained in:
ma-shaoyin 2024-04-23 17:07:12 +08:00
parent d46c1096fc
commit 453abb25a4
3 changed files with 37 additions and 3 deletions

View File

@ -20,7 +20,7 @@
namespace OHOS {
namespace MiscServices {
enum class RequestType : int32_t { NORMAL = 0, START_INPUT, STOP_INPUT, REQUEST_HIDE };
enum class RequestType : int32_t { NORMAL = 0, START_INPUT, STOP_INPUT, REQUEST_SHOW, REQUEST_HIDE };
class FreezeManager {
public:
explicit FreezeManager(pid_t pid) : pid_(pid)

View File

@ -34,7 +34,7 @@ void FreezeManager::BeforeIpc(RequestType type)
{
{
std::lock_guard<std::mutex> lock(mutex_);
if (type == RequestType::START_INPUT) {
if (type == RequestType::START_INPUT || type == RequestType::REQUEST_SHOW) {
isImeInUse_ = true;
}
if (!isFrozen_) {
@ -51,7 +51,7 @@ void FreezeManager::AfterIpc(RequestType type, bool isSuccess)
bool shouldFreeze = false;
{
std::lock_guard<std::mutex> lock(mutex_);
if (type == RequestType::START_INPUT) {
if (type == RequestType::START_INPUT || type == RequestType::REQUEST_SHOW) {
isImeInUse_ = isSuccess;
}
if (type == RequestType::REQUEST_HIDE && isImeInUse_) {

View File

@ -76,6 +76,27 @@ public:
CheckAllState(false, true);
}
}
static void TestRequestShowInput(bool isSuccess)
{
IMSA_HILOGI("run in, isSuccess: %{public}d", isSuccess);
{
std::lock_guard<std::mutex> lock(mtx_);
bool ret = freezeManager_->IsIpcNeeded(RequestType::REQUEST_SHOW);
if (!ret) {
return;
}
freezeManager_->BeforeIpc(RequestType::REQUEST_SHOW);
CheckFreezable(false);
}
usleep(IPC_COST_TIME);
{
std::lock_guard<std::mutex> lock(mtx_);
freezeManager_->AfterIpc(RequestType::REQUEST_SHOW, isSuccess);
if (isSuccess) {
CheckAllState(true, false);
}
}
}
static void TestRequestHideInput(bool isSuccess)
{
IMSA_HILOGI("run in, isSuccess: %{public}d", isSuccess);
@ -249,5 +270,18 @@ HWTEST_F(ImeFreezeManagerTest, MultiThread_FullTest_001, TestSize.Level0)
SET_THREAD_NUM(5);
GTEST_RUN_TASK(FullTestTask);
}
/**
* @tc.name: SingleThread_RequestShow_001
* @tc.desc: test freeze manager
* @tc.type: FUNC
*/
HWTEST_F(ImeFreezeManagerTest, SingleThread_RequestShow_001, TestSize.Level0)
{
IMSA_HILOGI("ImeFreezeManagerTest::SingleThread_RequestShow_001");
EXPECT_NE(ImeFreezeManagerTest::freezeManager_, nullptr);
ClearState();
TestRequestShowInput(true);
}
} // namespace MiscServices
} // namespace OHOS