This commit is contained in:
wwx1139321 2024-03-28 14:10:14 +08:00
commit 17479a91cf
22 changed files with 292 additions and 226 deletions

View File

@ -126,9 +126,10 @@ napi_value JsPanel::SetUiContent(napi_env env, napi_callback_info info)
auto exec = [ctxt](AsyncCall::Context *ctx) { ctxt->SetState(napi_ok); };
auto output = [ctxt](napi_env env, napi_value *result) -> napi_status {
CHECK_RETURN(ctxt->inputMethodPanel != nullptr, "inputMethodPanel is nullptr!", napi_generic_failure);
auto code = ctxt->inputMethodPanel->SetUiContent(
ctxt->path, env, ctxt->contentStorage);
CHECK_RETURN(code == ErrorCode::NO_ERROR, "SetUiContent failed!", napi_generic_failure);
auto code = ctxt->inputMethodPanel->SetUiContent(ctxt->path, env, ctxt->contentStorage);
if (code == ErrorCode::ERROR_PARAMETER_CHECK_FAILED) {
PARAM_CHECK_RETURN(env, code == ErrorCode::NO_ERROR, "path is invalid!", TYPE_NONE, napi_generic_failure);
}
return napi_ok;
};
ctxt->SetAction(std::move(input), std::move(output));

View File

@ -89,8 +89,8 @@ int32_t InputMethodAgentProxy::SendRequest(int code, ParcelHandler input, Parcel
}
auto remote = Remote();
if (remote == nullptr) {
IMSA_HILOGE("InputMethodAgentProxy::SendRequest remote is nullptr.");
return ERROR_EX_NULL_POINTER;
IMSA_HILOGE("InputMethodAgentProxy remote is nullptr");
return ErrorCode::ERROR_EX_NULL_POINTER;
}
auto ret = remote->SendRequest(code, data, reply, option);
if (ret != NO_ERROR) {

View File

@ -115,7 +115,12 @@ int32_t InputMethodCoreProxy::SendRequest(int code, ParcelHandler input, ParcelH
IMSA_HILOGE("InputMethodCoreProxy::write data failed");
return ErrorCode::ERROR_EX_PARCELABLE;
}
auto ret = Remote()->SendRequest(code, data, reply, option);
auto remote = Remote();
if (remote == nullptr) {
IMSA_HILOGE("InputMethodCoreProxy remote is nullptr");
return ErrorCode::ERROR_EX_NULL_POINTER;
}
auto ret = remote->SendRequest(code, data, reply, option);
if (ret != NO_ERROR) {
IMSA_HILOGE("InputMethodCoreProxy send request failed, code: %{public}d, ret %{public}d", code, ret);
return ret;

View File

@ -336,7 +336,7 @@ int32_t InputMethodPanel::SetUiContent(
WMError wmError = window_->SetTransparent(true);
IMSA_HILOGI("SetTransparent ret = %{public}u", wmError);
IMSA_HILOGI("NapiSetUIContent ret = %{public}d", ret);
return ret == WMError::WM_OK ? ErrorCode::NO_ERROR : ErrorCode::ERROR_OPERATE_PANEL;
return ret == WMError::WM_ERROR_INVALID_PARAM ? ErrorCode::ERROR_PARAMETER_CHECK_FAILED : ErrorCode::NO_ERROR;
}
void InputMethodPanel::SetPanelStatusListener(
@ -397,12 +397,12 @@ bool InputMethodPanel::IsSizeValid(uint32_t width, uint32_t height)
{
if (width > INT32_MAX || height > INT32_MAX) {
IMSA_HILOGE("width or height over maximum");
return ErrorCode::ERROR_BAD_PARAMETERS;
return false;
}
auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
if (defaultDisplay == nullptr) {
IMSA_HILOGE("GetDefaultDisplay failed.");
return ErrorCode::ERROR_NULL_POINTER;
return false;
}
float ratio = panelType_ == PanelType::SOFT_KEYBOARD && panelFlag_ == PanelFlag::FLG_FIXED
? FIXED_SOFT_KEYBOARD_PANEL_RATIO

View File

@ -69,7 +69,12 @@ int32_t InputClientProxy::SendRequest(int code, ParcelHandler input, ParcelHandl
IMSA_HILOGE("InputClientProxy::write data failed");
return ErrorCode::ERROR_EX_PARCELABLE;
}
auto ret = Remote()->SendRequest(code, data, reply, option);
auto remote = Remote();
if (remote == nullptr) {
IMSA_HILOGE("InputClientProxy remote is nullptr");
return ErrorCode::ERROR_EX_NULL_POINTER;
}
auto ret = remote->SendRequest(code, data, reply, option);
if (ret != NO_ERROR) {
IMSA_HILOGE("InputClientProxy send request failed, code: %{public}d, ret: %{public}d", code, ret);
return ret;

View File

@ -160,7 +160,12 @@ int32_t InputDataChannelProxy::SendRequest(int code, ParcelHandler input, Parcel
IMSA_HILOGE("write data failed");
return ErrorCode::ERROR_EX_PARCELABLE;
}
auto ret = Remote()->SendRequest(code, data, reply, option);
auto remote = Remote();
if (remote == nullptr) {
IMSA_HILOGE("InputDataChannelProxy remote is nullptr");
return ErrorCode::ERROR_EX_NULL_POINTER;
}
auto ret = remote->SendRequest(code, data, reply, option);
if (ret != NO_ERROR) {
IMSA_HILOGE("InputDataChannelProxy send request failed, code: %{public}d ret %{public}d", code, ret);
return ret;

View File

@ -272,7 +272,12 @@ int32_t InputMethodSystemAbilityProxy::SendRequest(int code, ParcelHandler input
IMSA_HILOGE("write data failed");
return ErrorCode::ERROR_EX_PARCELABLE;
}
auto ret = Remote()->SendRequest(code, data, reply, option);
auto remote = Remote();
if (remote == nullptr) {
IMSA_HILOGE("InputMethodSystemAbilityProxy remote is nullptr");
return ErrorCode::ERROR_EX_NULL_POINTER;
}
auto ret = remote->SendRequest(code, data, reply, option);
if (ret != NO_ERROR) {
IMSA_HILOGE("transport exceptions, code: %{public}d, ret %{public}d", code, ret);
return ret;

View File

@ -70,7 +70,12 @@ int32_t KeyEventConsumerProxy::SendRequest(int code, ParcelHandler input, Parcel
IMSA_HILOGE("write data failed");
return ErrorCode::ERROR_EX_PARCELABLE;
}
auto ret = Remote()->SendRequest(code, data, reply, option);
auto remote = Remote();
if (remote == nullptr) {
IMSA_HILOGE("KeyEventConsumerProxy remote is nullptr");
return ErrorCode::ERROR_EX_NULL_POINTER;
}
auto ret = remote->SendRequest(code, data, reply, option);
if (ret != NO_ERROR) {
IMSA_HILOGE("KeyEventConsumerProxy send request failed, code: %{public}d ret %{public}d", code, ret);
return ret;

View File

@ -38,7 +38,13 @@ int32_t KeyboardEvent::AddKeyEventMonitor(KeyHandle handle)
std::shared_ptr<InputEventCallback> callback = std::make_shared<InputEventCallback>();
callback->SetKeyHandle(handle);
int32_t monitorId =
InputManager::GetInstance()->AddMonitor(std::static_pointer_cast<MMI::IInputEventConsumer>(callback));
InputManager::GetInstance()->AddMonitor([callback](std::shared_ptr<MMI::KeyEvent> keyEvent) {
if (callback == nullptr) {
IMSA_HILOGE("callback is nullptr.");
return;
}
callback->OnInputEvent(keyEvent);
});
if (monitorId < 0) {
IMSA_HILOGE("add monitor failed, id: %{public}d", monitorId);
return ErrorCode::ERROR_SUBSCRIBE_KEYBOARD_EVENT;
@ -48,6 +54,7 @@ int32_t KeyboardEvent::AddKeyEventMonitor(KeyHandle handle)
CombinationKeyCallBack combinationKeyCallBack = [callback](std::shared_ptr<MMI::KeyEvent> keyEvent) {
if (callback == nullptr) {
IMSA_HILOGE("callback is nullptr.");
return;
}
callback->TriggerSwitch();
};

View File

@ -120,7 +120,10 @@ private:
int32_t SwitchInputType(const SwitchInfo &switchInfo);
ServiceRunningState state_;
void InitServiceHandler();
void SetCurrentUserId();
int32_t GetCurrentUserIdFromOsAccount();
void HandleUserChanged(int32_t userId);
int32_t StartImeWhenWmsReady();
void HandleWmsReady(int32_t userId);
int32_t InitAccountMonitor();
static std::shared_ptr<AppExecFwk::EventHandler> serviceHandler_;
int32_t userId_;
@ -148,6 +151,9 @@ private:
void DatashareCallback(const std::string &key);
bool enableImeOn_ = false;
bool enableSecurityMode_ = false;
bool isScbEnable_ = false;
std::atomic<bool> imeStarting_ = false;
};
} // namespace MiscServices
} // namespace OHOS

View File

@ -40,7 +40,7 @@ public:
static bool GetValue(cJSON *node, const std::string &name, bool &value);
static bool GetValue(cJSON *node, const std::string &name, Serializable &value);
template<typename T>
static bool GetValue(cJSON *node, const std::string &name, std::vector<T> &values, uint32_t maxNum = 0)
static bool GetValue(cJSON *node, const std::string &name, std::vector<T> &values, int32_t maxNum = 0)
{
auto subNode = GetSubNode(node, name);
if (!cJSON_IsArray(subNode)) {

View File

@ -46,7 +46,12 @@ int32_t InputControlChannelProxy::HideKeyboardSelf()
IMSA_HILOGE("InputControlChannelProxy descriptor is not match");
return ErrorCode::ERROR_EX_PARCELABLE;
}
auto ret = Remote()->SendRequest(HIDE_KEYBOARD_SELF, data, reply, option);
auto remote = Remote();
if (remote == nullptr) {
IMSA_HILOGE("InputControlChannelProxy remote is nullptr");
return ErrorCode::ERROR_EX_NULL_POINTER;
}
auto ret = remote->SendRequest(HIDE_KEYBOARD_SELF, data, reply, option);
if (ret != ErrorCode::NO_ERROR) {
IMSA_HILOGE("InputControlChannelProxy SendRequest failed");
return ErrorCode::ERROR_EX_PARCELABLE;

View File

@ -146,19 +146,56 @@ int32_t InputMethodSystemAbility::Init()
return ErrorCode::NO_ERROR;
}
void InputMethodSystemAbility::SetCurrentUserId()
int32_t InputMethodSystemAbility::GetCurrentUserIdFromOsAccount()
{
std::vector<int32_t> userIds;
if (!BlockRetry(RETRY_INTERVAL, BLOCK_RETRY_TIMES, [&userIds]() -> bool {
return OsAccountManager::QueryActiveOsAccountIds(userIds) == ERR_OK && !userIds.empty();
})) {
IMSA_HILOGE("get userId failed");
return;
return MAIN_USER_ID;
}
IMSA_HILOGD("get userId success :%{public}d", userIds[0]);
userId_ = userIds[0];
InputMethodSysEvent::GetInstance().SetUserId(userId_);
return userIds[0];
}
void InputMethodSystemAbility::HandleUserChanged(int32_t userId)
{
IMSA_HILOGI("%{public}d switch to %{public}d", userId_, userId);
userId_ = userId;
userSession_->UpdateCurrentUserId(userId_);
InputMethodSysEvent::GetInstance().SetUserId(userId_);
if (enableImeOn_) {
EnableImeDataParser::GetInstance()->OnUserChanged(userId_);
}
if (enableSecurityMode_) {
SecurityModeParser::GetInstance()->GetFullModeList(userId_);
}
ImeInfoInquirer::GetInstance().SetCurrentImeInfo(nullptr);
}
int32_t InputMethodSystemAbility::StartImeWhenWmsReady()
{
if (imeStarting_.exchange(true)) {
IMSA_HILOGD("do starting");
return ErrorCode::NO_ERROR;
}
IMSA_HILOGI("start ime, userId: %{public}d", userId_);
userSession_->StopCurrentIme();
auto ret = userSession_->StartCurrentIme(userId_, true);
if (!ret) {
IMSA_HILOGE("start ime failed");
}
imeStarting_.store(false);
return ret ? ErrorCode::NO_ERROR : ErrorCode::ERROR_IME_START_FAILED;
}
void InputMethodSystemAbility::HandleWmsReady(int32_t userId)
{
// wms ready scene: user switch(in scb enable), device boots, wms reboot
if (userId != userId_) {
HandleUserChanged(userId);
}
StartImeWhenWmsReady();
}
void InputMethodSystemAbility::OnStop()
@ -194,6 +231,7 @@ void InputMethodSystemAbility::Initialize()
userId_ = MAIN_USER_ID;
userSession_ = std::make_shared<PerUserSession>(userId_);
InputMethodSysEvent::GetInstance().SetUserId(userId_);
isScbEnable_ = Rosen::SceneBoardJudgement::IsSceneBoardEnabled();
}
void InputMethodSystemAbility::StartUserIdListener()
@ -517,6 +555,7 @@ int32_t InputMethodSystemAbility::OnSwitchInputMethod(const SwitchInfo &switchIn
if (!switchQueue_.IsReady(switchInfo)) {
IMSA_HILOGD("start wait");
switchQueue_.Wait(switchInfo);
usleep(SWITCH_BLOCK_TIME);
}
IMSA_HILOGI("start switch %{public}s|%{public}s", switchInfo.bundleName.c_str(), switchInfo.subName.c_str());
int32_t ret = CheckSwitchPermission(switchInfo, trigger);
@ -771,38 +810,24 @@ void InputMethodSystemAbility::WorkThread()
*/
int32_t InputMethodSystemAbility::OnUserStarted(const Message *msg)
{
// if scb enable, deal when receive wmsConnected.
if (isScbEnable_) {
return ErrorCode::NO_ERROR;
}
if (msg->msgContent_ == nullptr) {
IMSA_HILOGE("msgContent is nullptr.");
return ErrorCode::ERROR_NULL_POINTER;
}
int32_t oldUserId = userId_;
userId_ = msg->msgContent_->ReadInt32();
if (oldUserId == userId_) {
IMSA_HILOGI("device boot, userId: %{public}d", userId_);
auto newUserId = msg->msgContent_->ReadInt32();
if (newUserId == userId_) {
return ErrorCode::NO_ERROR;
}
IMSA_HILOGI("%{public}d switch to %{public}d.", oldUserId, userId_);
userSession_->UpdateCurrentUserId(userId_);
InputMethodSysEvent::GetInstance().SetUserId(userId_);
if (enableImeOn_) {
EnableImeDataParser::GetInstance()->OnUserChanged(userId_);
}
if (enableSecurityMode_) {
SecurityModeParser::GetInstance()->GetFullModeList(userId_);
}
userSession_->StopCurrentIme();
// user switch, reset currentImeInfo_ = nullptr
ImeInfoInquirer::GetInstance().SetCurrentImeInfo(nullptr);
HandleUserChanged(newUserId);
if (!userSession_->IsWmsReady()) {
IMSA_HILOGI("wms not ready, wait");
return ErrorCode::NO_ERROR;
}
if (!userSession_->StartCurrentIme(userId_, true)) {
IMSA_HILOGE("start input method failed");
return ErrorCode::ERROR_IME_START_FAILED;
}
return ErrorCode::NO_ERROR;
return StartImeWhenWmsReady();
}
int32_t InputMethodSystemAbility::OnUserRemoved(const Message *msg)
@ -838,7 +863,7 @@ int32_t InputMethodSystemAbility::OnPackageRemoved(const Message *msg)
IMSA_HILOGE("Failed to read message parcel");
return ErrorCode::ERROR_EX_PARCELABLE;
}
// 用户移除也会有该通知如果移除的app用户不是当前用户则不处理
// if the app that doesn't belong to current user is removed, ignore it
if (userId != userId_) {
IMSA_HILOGD("userId: %{public}d, currentUserId: %{public}d,", userId, userId_);
return ErrorCode::NO_ERROR;
@ -986,7 +1011,13 @@ void InputMethodSystemAbility::InitMonitors()
int32_t InputMethodSystemAbility::InitAccountMonitor()
{
IMSA_HILOGI("InputMethodSystemAbility::InitAccountMonitor");
return ImCommonEventManager::GetInstance()->SubscribeAccountManagerService([this]() { SetCurrentUserId(); });
return ImCommonEventManager::GetInstance()->SubscribeAccountManagerService([this]() {
auto userId = GetCurrentUserIdFromOsAccount();
if (userId_ == userId) {
return;
}
HandleUserChanged(userId);
});
}
int32_t InputMethodSystemAbility::InitKeyEventMonitor()
@ -1004,28 +1035,19 @@ bool InputMethodSystemAbility::InitWmsMonitor()
return isOnFocused ? userSession_->OnFocused(pid, uid) : userSession_->OnUnfocused(pid, uid);
},
[this]() {
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
if (isScbEnable_) {
IMSA_HILOGI("scb enable, register WMS connection listener");
InitWmsConnectionMonitor();
return;
}
IMSA_HILOGI("scb disable, start ime");
SetCurrentUserId();
userSession_->StartCurrentIme(userId_, true);
HandleWmsReady(GetCurrentUserIdFromOsAccount());
});
}
void InputMethodSystemAbility::InitWmsConnectionMonitor()
{
WmsConnectionMonitorManager::GetInstance().RegisterWMSConnectionChangedListener(
[this](int32_t userId, int32_t screenId) {
SetCurrentUserId();
IMSA_HILOGI("WMS connect, start ime, userId: %{public}d, currentUserId: %{public}d", userId, userId_);
if (userId != userId_) {
return;
}
userSession_->StartCurrentIme(userId_, true);
});
[this](int32_t userId, int32_t screenId) { HandleWmsReady(userId); });
}
void InputMethodSystemAbility::InitSystemLanguageMonitor()

View File

@ -17,6 +17,7 @@
namespace OHOS {
namespace MiscServices {
constexpr uint32_t KEYBOARD_STATUS_WAIT_TIME_OUT = 2;
std::mutex TextListener::textListenerCallbackLock_;
std::condition_variable TextListener::textListenerCv_;
int32_t TextListener::direction_ = -1;
@ -169,8 +170,8 @@ void TextListener::ResetParam()
bool TextListener::WaitSendKeyboardStatusCallback(const KeyboardStatus &keyboardStatus)
{
std::unique_lock<std::mutex> lock(textListenerCallbackLock_);
textListenerCv_.wait_for(
lock, std::chrono::seconds(1), [&keyboardStatus]() { return keyboardStatus == keyboardStatus_; });
textListenerCv_.wait_for(lock, std::chrono::seconds(KEYBOARD_STATUS_WAIT_TIME_OUT),
[&keyboardStatus]() { return keyboardStatus == keyboardStatus_; });
return keyboardStatus == keyboardStatus_;
}

View File

@ -25,22 +25,14 @@ namespace OHOS {
class KeyboardListenerImpl : public KeyboardListener {
bool OnKeyEvent(int32_t keyCode, int32_t keyStatus, sptr<KeyEventConsumerProxy> &consumer)
{
if (consumer != nullptr) {
consumer->OnKeyCodeConsumeResult(true);
}
return true;
}
bool OnKeyEvent(const std::shared_ptr<MMI::KeyEvent> &keyEvent, sptr<KeyEventConsumerProxy> &consumer)
{
if (consumer != nullptr) {
consumer->OnKeyEventConsumeResult(true);
}
return true;
}
bool OnDealKeyEvent(const std::shared_ptr<MMI::KeyEvent> &keyEvent, sptr<KeyEventConsumerProxy> &consumer)
{
OnKeyEvent(keyEvent->GetKeyCode(), keyEvent->GetKeyAction(), consumer);
OnKeyEvent(keyEvent, consumer);
return true;
}
void OnCursorUpdate(int32_t positionX, int32_t positionY, int32_t height)
@ -57,7 +49,7 @@ class KeyboardListenerImpl : public KeyboardListener {
}
};
void TestInsertText(std::string fuzzedString)
void TestInsertText(const std::string &fuzzedString)
{
sptr<InputMethodAbility> ability = InputMethodAbility::GetInstance();
ability->InsertText(std::move(fuzzedString));
@ -73,8 +65,7 @@ void TestSetImeListener()
void TestSetKdListener()
{
sptr<InputMethodAbility> ability = InputMethodAbility::GetInstance();
auto keyBoardListener = std::make_shared<KeyboardListenerImpl>();
ability->SetKdListener(keyBoardListener);
ability->SetKdListener(nullptr);
}
void TestDeleteForward(int32_t fuzzedInt32)

View File

@ -294,6 +294,7 @@ ohos_unittest("InputMethodPanelTest") {
"${inputmethod_path}/interfaces/inner_api/inputmethod_ability:inputmethod_ability",
"${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client_static",
"${inputmethod_path}/services:inputmethod_service",
"${inputmethod_path}/test/common:inputmethod_test_common",
"${inputmethod_path}/test/unittest/cpp_test/common:inputmethod_tdd_util",
"//third_party/googletest:gtest_main",
]

View File

@ -49,7 +49,7 @@ public:
static void RestoreSelfTokenID();
static bool ExecuteCmd(const std::string &cmd, std::string &result);
static pid_t GetImsaPid();
static void KillImsaProcess();
static bool KillImsaProcess();
static void PushEnableImeValue(const std::string &key, const std::string &value);
static void GrantNativePermission();
static int32_t GetEnableData(std::string &value);

View File

@ -46,9 +46,7 @@ using namespace Rosen;
constexpr int32_t INVALID_USER_ID = -1;
constexpr int32_t MAIN_USER_ID = 100;
constexpr const uint16_t EACH_LINE_LENGTH = 500;
constexpr int32_t BUFF_LENGTH = 10;
constexpr int32_t PERMISSION_NUM = 2;
constexpr const char *CMD_PIDOF_IMS = "pidof inputmethod_ser";
constexpr const char *SETTING_COLUMN_KEYWORD = "KEYWORD";
constexpr const char *SETTING_COLUMN_VALUE = "VALUE";
static constexpr int32_t MAX_TIMEOUT_WAIT_FOCUS = 2000;
@ -173,32 +171,33 @@ bool TddUtil::ExecuteCmd(const std::string &cmd, std::string &result)
pid_t TddUtil::GetImsaPid()
{
char buff[BUFF_LENGTH] = { 0 };
FILE *fp = popen(CMD_PIDOF_IMS, "r");
if (fp == nullptr) {
IMSA_HILOGI("get pid failed.");
auto currentToken = GetSelfTokenID();
GrantNativePermission();
auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
SystemProcessInfo info;
int32_t ret = saMgr->GetSystemProcessInfo(INPUT_METHOD_SYSTEM_ABILITY_ID, info);
if (ret != ErrorCode::NO_ERROR) {
IMSA_HILOGE("failed to get sa info, ret: %{public}d", ret);
return -1;
}
fgets(buff, sizeof(buff), fp);
pid_t pid = atoi(buff);
pclose(fp);
fp = nullptr;
return pid;
SetSelfTokenID(currentToken);
return info.pid;
}
void TddUtil::KillImsaProcess()
bool TddUtil::KillImsaProcess()
{
pid_t pid = GetImsaPid();
if (pid == -1) {
IMSA_HILOGE("Pid of Imsa is not exist.");
return;
IMSA_HILOGE("failed to get pid");
return false;
}
auto ret = kill(pid, SIGTERM);
if (ret != 0) {
IMSA_HILOGE("Kill failed, ret: %{public}d", ret);
return;
return false;
}
IMSA_HILOGI("Kill success.");
IMSA_HILOGI("Kill [%{public}d] success", pid);
return true;
}
sptr<OHOS::AppExecFwk::IBundleMgr> TddUtil::GetBundleMgr()

View File

@ -60,6 +60,7 @@ namespace MiscServices {
constexpr uint32_t RETRY_TIME = 200 * 1000;
constexpr uint32_t RETRY_TIMES = 5;
constexpr uint32_t WAIT_INTERVAL = 500;
constexpr uint32_t WAIT_SA_DIE_TIME_OUT = 3;
class SelectListenerMock : public ControllerListener {
public:
@ -331,8 +332,7 @@ bool InputMethodControllerTest::WaitRemoteDiedCallback()
{
IMSA_HILOGI("InputMethodControllerTest::WaitRemoteDiedCallback");
std::unique_lock<std::mutex> lock(onRemoteSaDiedMutex_);
// 2 means wait 2 seconds.
return onRemoteSaDiedCv_.wait_for(lock, std::chrono::seconds(2)) != std::cv_status::timeout;
return onRemoteSaDiedCv_.wait_for(lock, std::chrono::seconds(WAIT_SA_DIE_TIME_OUT)) != std::cv_status::timeout;
}
void InputMethodControllerTest::CheckProxyObject()
@ -1098,16 +1098,14 @@ HWTEST_F(InputMethodControllerTest, testOnRemoteDied, TestSize.Level0)
IMSA_HILOGI("IMC OnRemoteDied Test START");
int32_t ret = inputMethodController_->Attach(textListener_, true);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
pid_t pid = TddUtil::GetImsaPid();
EXPECT_TRUE(pid > 0);
TextListener::ResetParam();
ret = kill(pid, SIGTERM);
EXPECT_EQ(ret, 0);
bool result = TddUtil::KillImsaProcess();
EXPECT_TRUE(result);
EXPECT_TRUE(WaitRemoteDiedCallback());
CheckProxyObject();
inputMethodController_->OnRemoteSaDied(nullptr);
EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::SHOW));
bool result = inputMethodController_->WasAttached();
result = inputMethodController_->WasAttached();
EXPECT_TRUE(result);
inputMethodController_->Close();
}

View File

@ -29,6 +29,7 @@
#include "input_method_engine_listener_impl.h"
#include "panel_status_listener.h"
#include "tdd_util.h"
#include "text_listener.h"
using namespace testing::ext;
namespace OHOS {
@ -36,7 +37,6 @@ namespace MiscServices {
constexpr uint32_t IMC_WAIT_PANEL_STATUS_LISTEN_TIME = 200;
constexpr float FIXED_SOFT_KEYBOARD_PANEL_RATIO = 0.7;
constexpr float NON_FIXED_SOFT_KEYBOARD_PANEL_RATIO = 1;
constexpr int32_t IMC_WAIT_TIME = 2;
enum ListeningStatus : uint32_t { ON, OFF, NONE };
class InputMethodPanelTest : public testing::Test {
public:
@ -45,15 +45,15 @@ public:
void SetUp();
void TearDown();
static std::shared_ptr<InputMethodPanel> CreatePanel();
static void InitPanel();
static void ClearPanel();
static void TriggerShowCallback(std::shared_ptr<InputMethodPanel> &inputMethodPanel);
static void TriggerHideCallback(std::shared_ptr<InputMethodPanel> &inputMethodPanel);
static void ChangePanelListeningStatus(ListeningStatus status);
static void ImcPanelListeningTestRestore(InputWindowStatus status);
static void ImcPanelListeningTestCheck(InputWindowStatus realStatus, InputWindowStatus waitStatus);
static void ImcPanelListeningTestCheck(
InputWindowStatus realStatus, InputWindowStatus waitStatus, const InputWindowInfo &windowInfo);
static void ImcPanelListeningTestCheck(InputWindowStatus realStatus, InputWindowStatus waitStatus);
static void ImcPanelListeningTestPrepare(
const std::shared_ptr<InputMethodPanel> &inputMethodPanel, const PanelInfo &info, ListeningStatus status);
static void ImcPanelListeningTestRestore(InputWindowStatus status);
static void ImcPanelListeningTestClear(const std::shared_ptr<InputMethodPanel> &inputMethodPanel);
class PanelStatusListenerImpl : public PanelStatusListener {
public:
PanelStatusListenerImpl()
@ -85,9 +85,10 @@ public:
static constexpr uint32_t DELAY_TIME = 100;
static constexpr int32_t INTERVAL = 10;
static std::shared_ptr<AppExecFwk::EventHandler> panelHandler_;
static uint64_t tokenId_;
static std::string beforeValue;
static std::string allEnableIme;
static uint64_t testTokenId_;
static sptr<OnTextChangedListener> textListener_;
static std::shared_ptr<InputMethodEngineListener> imeListener_;
static std::shared_ptr<InputMethodPanel> inputMethodPanel_;
};
class ImeEventListenerImpl : public ImeEventListener {
public:
@ -126,41 +127,36 @@ std::condition_variable InputMethodPanelTest::imcPanelStatusListenerCv_;
std::mutex InputMethodPanelTest::imcPanelStatusListenerLock_;
InputWindowStatus InputMethodPanelTest::status_{ InputWindowStatus::HIDE };
std::vector<InputWindowInfo> InputMethodPanelTest::windowInfo_;
sptr<InputMethodController> InputMethodPanelTest::imc_;
sptr<InputMethodAbility> InputMethodPanelTest::ima_;
sptr<InputMethodController> InputMethodPanelTest::imc_{ nullptr };
sptr<InputMethodAbility> InputMethodPanelTest::ima_{ nullptr };
uint32_t InputMethodPanelTest::windowWidth_ = 0;
uint32_t InputMethodPanelTest::windowHeight_ = 0;
uint64_t InputMethodPanelTest::tokenId_ = 0;
std::string InputMethodPanelTest::beforeValue;
std::string InputMethodPanelTest::allEnableIme = "{\"enableImeList\" : {\"100\" : [ \"com.example.testIme\"]}}";
uint64_t InputMethodPanelTest::testTokenId_ = 0;
sptr<OnTextChangedListener> InputMethodPanelTest::textListener_{ nullptr };
std::shared_ptr<InputMethodEngineListener> InputMethodPanelTest::imeListener_{ nullptr };
std::shared_ptr<InputMethodPanel> InputMethodPanelTest::inputMethodPanel_{ nullptr };
void InputMethodPanelTest::SetUpTestCase(void)
{
IMSA_HILOGI("InputMethodPanelTest::SetUpTestCase");
// storage current token id
TddUtil::StorageSelfTokenID();
ima_ = InputMethodAbility::GetInstance();
auto listener = std::make_shared<ImeEventListenerImpl>();
imc_ = InputMethodController::GetInstance();
imc_->SetSettingListener(listener);
TddUtil::SetTestTokenID(TddUtil::AllocTestTokenID(true, "undefined", { "ohos.permission.CONNECT_IME_ABILITY" }));
TddUtil::GrantNativePermission();
TddUtil::GetEnableData(beforeValue);
TddUtil::PushEnableImeValue("settings.inputmethod.enable_ime", allEnableIme);
auto ret = imc_->SwitchInputMethod(SwitchTrigger::CURRENT_IME, "com.example.testIme");
if (ret != ErrorCode::NO_ERROR) {
IMSA_HILOGI("SwitchInputMethod failed, ret = %{public}d", ret);
return;
}
TddUtil::RestoreSelfTokenID();
textListener_ = new (std::nothrow) TextListener();
imeListener_ = std::make_shared<InputMethodEngineListenerImpl>();
// set token as current input method
std::shared_ptr<Property> property = InputMethodController::GetInstance()->GetCurrentInputMethod();
std::string bundleName = property != nullptr ? property->name : "default.inputmethod.unittest";
tokenId_ = TddUtil::AllocTestTokenID(true, bundleName, { "ohos.permission.CONNECT_IME_ABILITY" });
testTokenId_ = TddUtil::AllocTestTokenID(true, bundleName, {});
InitPanel();
}
void InputMethodPanelTest::TearDownTestCase(void)
{
IMSA_HILOGI("InputMethodPanelTest::TearDownTestCase");
TddUtil::GrantNativePermission();
TddUtil::PushEnableImeValue("settings.inputmethod.enable_ime", beforeValue);
ClearPanel();
}
void InputMethodPanelTest::SetUp(void)
@ -170,6 +166,7 @@ void InputMethodPanelTest::SetUp(void)
void InputMethodPanelTest::TearDown(void)
{
TddUtil::RestoreSelfTokenID();
IMSA_HILOGI("InputMethodPanelTest::TearDown");
}
@ -182,6 +179,31 @@ std::shared_ptr<InputMethodPanel> InputMethodPanelTest::CreatePanel()
return inputMethodPanel;
}
void InputMethodPanelTest::InitPanel()
{
TddUtil::SetTestTokenID(testTokenId_);
inputMethodPanel_ = std::make_shared<InputMethodPanel>();
PanelInfo info = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
auto ret = inputMethodPanel_->CreatePanel(nullptr, info);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
ASSERT_TRUE(defaultDisplay != nullptr);
windowWidth_ = defaultDisplay->GetWidth();
windowHeight_ = 1;
ret = inputMethodPanel_->Resize(windowWidth_, windowHeight_);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
TddUtil::RestoreSelfTokenID();
}
void InputMethodPanelTest::ClearPanel()
{
if (inputMethodPanel_ == nullptr) {
IMSA_HILOGD("nullptr");
return;
}
inputMethodPanel_->DestroyPanel();
}
void InputMethodPanelTest::TriggerShowCallback(std::shared_ptr<InputMethodPanel> &inputMethodPanel)
{
panelHandler_->PostTask([&inputMethodPanel]() { inputMethodPanel->ShowPanel(); }, InputMethodPanelTest::INTERVAL);
@ -228,17 +250,9 @@ void InputMethodPanelTest::ImcPanelListeningTestCheck(InputWindowStatus realStat
EXPECT_TRUE(windowInfo_.empty());
}
void InputMethodPanelTest::ImcPanelListeningTestPrepare(
const std::shared_ptr<InputMethodPanel> &inputMethodPanel, const PanelInfo &info, ListeningStatus status)
void InputMethodPanelTest::ChangePanelListeningStatus(ListeningStatus status)
{
auto ret = inputMethodPanel->CreatePanel(nullptr, info);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
ASSERT_TRUE(defaultDisplay != nullptr);
windowWidth_ = defaultDisplay->GetWidth();
windowHeight_ = 1;
ret = inputMethodPanel->Resize(windowWidth_, windowHeight_);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
IMSA_HILOGI("status: %{public}d", static_cast<uint32_t>(status));
switch (status) {
case ListeningStatus::NONE: {
break;
@ -264,11 +278,6 @@ void InputMethodPanelTest::ImcPanelListeningTestRestore(InputWindowStatus status
windowInfo_.clear();
}
void InputMethodPanelTest::ImcPanelListeningTestClear(const std::shared_ptr<InputMethodPanel> &inputMethodPanel)
{
inputMethodPanel->DestroyPanel();
}
/**
* @tc.name: testCreatePanel
* @tc.desc: Test CreatePanel.
@ -470,9 +479,13 @@ HWTEST_F(InputMethodPanelTest, testShowPanel, TestSize.Level0)
HWTEST_F(InputMethodPanelTest, testIsPanelShown_001, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testIsPanelShown_001 start.");
TddUtil::SetTestTokenID(tokenId_);
TddUtil::SetTestTokenID(InputMethodPanelTest::testTokenId_);
TddUtil::InitWindow(true);
InputMethodPanelTest::ima_->SetImeListener(InputMethodPanelTest::imeListener_);
int32_t ret = ima_->SetCoreAndAgent();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = InputMethodPanelTest::imc_->Attach(InputMethodPanelTest::textListener_, false);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
bool isShown = false;
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
@ -495,6 +508,8 @@ HWTEST_F(InputMethodPanelTest, testIsPanelShown_001, TestSize.Level0)
ret = ima_->DestroyPanel(inputMethodPanel);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
/**
@ -505,8 +520,13 @@ HWTEST_F(InputMethodPanelTest, testIsPanelShown_001, TestSize.Level0)
HWTEST_F(InputMethodPanelTest, testIsPanelShown_002, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testIsPanelShown_002 start.");
TddUtil::SetTestTokenID(tokenId_);
TddUtil::SetTestTokenID(InputMethodPanelTest::testTokenId_);
TddUtil::InitWindow(true);
InputMethodPanelTest::ima_->SetImeListener(InputMethodPanelTest::imeListener_);
int32_t ret = ima_->SetCoreAndAgent();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = InputMethodPanelTest::imc_->Attach(InputMethodPanelTest::textListener_, false);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
bool isShown = false;
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
@ -530,6 +550,8 @@ HWTEST_F(InputMethodPanelTest, testIsPanelShown_002, TestSize.Level0)
ret = ima_->DestroyPanel(inputMethodPanel);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
/**
@ -540,8 +562,13 @@ HWTEST_F(InputMethodPanelTest, testIsPanelShown_002, TestSize.Level0)
HWTEST_F(InputMethodPanelTest, testIsPanelShown_003, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testIsPanelShown_003 start.");
TddUtil::SetTestTokenID(tokenId_);
TddUtil::SetTestTokenID(InputMethodPanelTest::testTokenId_);
TddUtil::InitWindow(true);
InputMethodPanelTest::ima_->SetImeListener(InputMethodPanelTest::imeListener_);
int32_t ret = ima_->SetCoreAndAgent();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = InputMethodPanelTest::imc_->Attach(InputMethodPanelTest::textListener_, false);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
bool isShown = false;
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo = { .panelType = STATUS_BAR };
@ -564,6 +591,8 @@ HWTEST_F(InputMethodPanelTest, testIsPanelShown_003, TestSize.Level0)
ret = ima_->DestroyPanel(inputMethodPanel);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
/**
@ -756,22 +785,19 @@ HWTEST_F(InputMethodPanelTest, testRegisterListener, TestSize.Level0)
HWTEST_F(InputMethodPanelTest, testImcPanelListening_001, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_001 start.");
TddUtil::SetTestTokenID(tokenId_);
// set token as system app and current ime
TddUtil::SetTestTokenID(InputMethodPanelTest::testTokenId_);
InputMethodPanelTest::ImcPanelListeningTestRestore(InputWindowStatus::HIDE);
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
InputMethodPanelTest::ImcPanelListeningTestPrepare(inputMethodPanel, panelInfo, NONE);
InputMethodPanelTest::ChangePanelListeningStatus(NONE);
auto ret = inputMethodPanel->ShowPanel();
auto ret = InputMethodPanelTest::inputMethodPanel_->ShowPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImcPanelListeningTestCheck(InputWindowStatus::HIDE, InputWindowStatus::SHOW);
InputMethodPanelTest::ImcPanelListeningTestRestore(InputWindowStatus::SHOW);
ret = inputMethodPanel->HidePanel();
ret = InputMethodPanelTest::inputMethodPanel_->HidePanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImcPanelListeningTestCheck(InputWindowStatus::SHOW, InputWindowStatus::HIDE);
InputMethodPanelTest::ImcPanelListeningTestClear(inputMethodPanel);
TddUtil::RestoreSelfTokenID();
}
/**
@ -782,27 +808,21 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_001, TestSize.Level0)
HWTEST_F(InputMethodPanelTest, testImcPanelListening_002, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_002 start.");
TddUtil::SetTestTokenID(tokenId_);
// set token as system app and current ime
TddUtil::SetTestTokenID(InputMethodPanelTest::testTokenId_);
InputMethodPanelTest::ImcPanelListeningTestRestore(InputWindowStatus::HIDE);
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
InputMethodPanelTest::ImcPanelListeningTestPrepare(inputMethodPanel, panelInfo, ON);
// need to wait amoment to make sure can get the new window size.
sleep(IMC_WAIT_TIME);
auto ret = inputMethodPanel->ShowPanel();
InputMethodPanelTest::ChangePanelListeningStatus(ON);
auto ret = InputMethodPanelTest::inputMethodPanel_->ShowPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImcPanelListeningTestCheck(InputWindowStatus::SHOW, InputWindowStatus::SHOW,
{ "", 0, 0, InputMethodPanelTest::windowWidth_, InputMethodPanelTest::windowHeight_ });
InputMethodPanelTest::ImcPanelListeningTestRestore(InputWindowStatus::SHOW);
// need to wait amoment to make sure can get the new window size.
sleep(IMC_WAIT_TIME);
ret = inputMethodPanel->HidePanel();
ret = InputMethodPanelTest::inputMethodPanel_->HidePanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImcPanelListeningTestCheck(InputWindowStatus::HIDE, InputWindowStatus::HIDE,
{ "", 0, 0, InputMethodPanelTest::windowWidth_, InputMethodPanelTest::windowHeight_ });
InputMethodPanelTest::ImcPanelListeningTestClear(inputMethodPanel);
TddUtil::RestoreSelfTokenID();
}
/**
@ -813,22 +833,19 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_002, TestSize.Level0)
HWTEST_F(InputMethodPanelTest, testImcPanelListening_003, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_003 start.");
TddUtil::SetTestTokenID(tokenId_);
// set token as system app and current ime
TddUtil::SetTestTokenID(InputMethodPanelTest::testTokenId_);
InputMethodPanelTest::ImcPanelListeningTestRestore(InputWindowStatus::HIDE);
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
InputMethodPanelTest::ImcPanelListeningTestPrepare(inputMethodPanel, panelInfo, OFF);
InputMethodPanelTest::ChangePanelListeningStatus(OFF);
auto ret = inputMethodPanel->ShowPanel();
auto ret = InputMethodPanelTest::inputMethodPanel_->ShowPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImcPanelListeningTestCheck(InputWindowStatus::HIDE, InputWindowStatus::SHOW);
InputMethodPanelTest::ImcPanelListeningTestRestore(InputWindowStatus::SHOW);
ret = inputMethodPanel->HidePanel();
ret = InputMethodPanelTest::inputMethodPanel_->HidePanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImcPanelListeningTestCheck(InputWindowStatus::SHOW, InputWindowStatus::HIDE);
InputMethodPanelTest::ImcPanelListeningTestClear(inputMethodPanel);
TddUtil::RestoreSelfTokenID();
}
/**
@ -840,52 +857,19 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_004, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_004 start.");
InputMethodPanelTest::ImcPanelListeningTestRestore(InputWindowStatus::HIDE);
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
imc_->UpdateListenEventFlag("imeShow", true);
imc_->UpdateListenEventFlag("imeHide", true);
// register with non-systemApp token
InputMethodPanelTest::ChangePanelListeningStatus(ListeningStatus::ON);
TddUtil::SetTestTokenID(tokenId_);
auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->Resize(windowWidth_, windowHeight_);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->ShowPanel();
// set token as current ime
TddUtil::SetTestTokenID(InputMethodPanelTest::testTokenId_);
auto ret = InputMethodPanelTest::inputMethodPanel_->ShowPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImcPanelListeningTestCheck(InputWindowStatus::HIDE, InputWindowStatus::SHOW);
InputMethodPanelTest::ImcPanelListeningTestRestore(InputWindowStatus::SHOW);
ret = inputMethodPanel->HidePanel();
ret = InputMethodPanelTest::inputMethodPanel_->HidePanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImcPanelListeningTestCheck(InputWindowStatus::SHOW, InputWindowStatus::HIDE);
InputMethodPanelTest::ImcPanelListeningTestClear(inputMethodPanel);
TddUtil::RestoreSelfTokenID();
}
/**
* @tc.name: testImcPanelListening_005
* @tc.desc: SOFT_KEYBOARD FLG_FIXED Set up listening systemApp not currentIme
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testImcPanelListening_005, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_005 start.");
TddUtil::SetTestTokenID(tokenId_);
InputMethodPanelTest::ImcPanelListeningTestRestore(InputWindowStatus::HIDE);
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
TddUtil::RestoreSelfTokenID();
InputMethodPanelTest::ImcPanelListeningTestPrepare(inputMethodPanel, panelInfo, ON);
auto ret = inputMethodPanel->ShowPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImcPanelListeningTestCheck(InputWindowStatus::HIDE, InputWindowStatus::SHOW);
InputMethodPanelTest::ImcPanelListeningTestRestore(InputWindowStatus::SHOW);
ret = inputMethodPanel->HidePanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImcPanelListeningTestCheck(InputWindowStatus::SHOW, InputWindowStatus::HIDE);
InputMethodPanelTest::ImcPanelListeningTestClear(inputMethodPanel);
}
/**

View File

@ -169,31 +169,47 @@ HWTEST_F(InputMethodPrivateMemberTest, SA_TestOnPackageRemoved, TestSize.Level0)
*/
HWTEST_F(InputMethodPrivateMemberTest, SA_TestOnUserStarted, TestSize.Level0)
{
// isScbEnable_ is true
service_->isScbEnable_ = true;
MessageParcel *parcel = nullptr;
auto msg = std::make_shared<Message>(MessageID::MSG_ID_USER_START, parcel);
auto ret = service_->OnUserStarted(msg.get());
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
// msg is nullptr
auto *msg = new Message(MessageID::MSG_ID_USER_START, nullptr);
auto ret = service_->OnUserStarted(msg);
service_->isScbEnable_ = false;
ret = service_->OnUserStarted(msg.get());
EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
MessageHandler::Instance()->SendMessage(msg);
// userId is same
service_->userId_ = 50;
MessageParcel *parcel1 = new MessageParcel();
parcel1->WriteInt32(50);
auto msg1 = std::make_shared<Message>(MessageID::MSG_ID_USER_START, parcel1);
auto ret1 = service_->OnUserStarted(msg1.get());
EXPECT_EQ(ret1, ErrorCode::NO_ERROR);
ret = service_->OnUserStarted(msg1.get());
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
//start ime failed
service_->userId_ = 50;
auto currentUserId = TddUtil::GetCurrentUserId();
ImeCfgManager::GetInstance().imeConfigs_.push_back({ currentUserId, "testBundleName/testExtName", "testSubName" });
auto parcel2 = new MessageParcel();
parcel2->WriteInt32(currentUserId);
auto msg2 = std::make_shared<Message>(MessageID::MSG_ID_USER_START, parcel2);
// start ime
WmsConnectionObserver observer(nullptr);
observer.OnConnected(100, 0);
auto ret2 = service_->OnUserStarted(msg2.get());
EXPECT_EQ(ret2, ErrorCode::ERROR_IME_START_FAILED);
observer.OnConnected(60, 0);
// imeStarting_ is true
IMSA_HILOGI("InputMethodPrivateMemberTest::imeStarting_ is true");
service_->imeStarting_ = true;
service_->userId_ = 50;
MessageParcel *parcel2 = new MessageParcel();
parcel2->WriteInt32(60);
auto msg2 = std::make_shared<Message>(MessageID::MSG_ID_USER_START, parcel2);
ret = service_->OnUserStarted(msg2.get());
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
// imeStarting_ is false
IMSA_HILOGI("InputMethodPrivateMemberTest::imeStarting_ is false");
service_->imeStarting_ = false;
service_->userId_ = 50;
MessageParcel *parcel3 = new MessageParcel();
parcel3->WriteInt32(333);
auto msg3 = std::make_shared<Message>(MessageID::MSG_ID_USER_START, parcel3);
ret = service_->OnUserStarted(msg3.get());
EXPECT_EQ(ret, ErrorCode::ERROR_IME_START_FAILED);
}
/**
@ -701,6 +717,7 @@ HWTEST_F(InputMethodPrivateMemberTest, WMSConnectObserver_001, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPrivateMemberTest WMSConnectObserver_001 TEST START");
WmsConnectionObserver observer(nullptr);
WmsConnectionObserver::connectedUserId_.clear();
int32_t userId = 100;
int32_t screenId = 0;

View File

@ -39,14 +39,15 @@ public:
void TearDown();
static std::shared_ptr<DataShareHelper> helper_;
static std::shared_ptr<DataShareResultSet> resultSet_;
static std::shared_ptr<InputMethodSystemAbility> service_;
static sptr<InputMethodSystemAbility> service_;
static constexpr int32_t USER_ID = 100;
};
std::shared_ptr<DataShareHelper> SecurityModeParserTest::helper_;
std::shared_ptr<DataShareResultSet> SecurityModeParserTest::resultSet_;
std::shared_ptr<InputMethodSystemAbility> SecurityModeParserTest::service_;
sptr<InputMethodSystemAbility> SecurityModeParserTest::service_{ nullptr };
void SecurityModeParserTest::SetUpTestCase(void)
{
IMSA_HILOGI("SecurityModeParserTest::SetUpTestCase");
std::vector<std::string> columns = { "VALUE" };
helper_ = DataShare::DataShareHelper::Creator(nullptr, "tsetUri", "tsetUri");
DataSharePredicates predicates;
@ -54,17 +55,24 @@ void SecurityModeParserTest::SetUpTestCase(void)
resultSet_ = helper_->Query(uri, predicates, columns);
SecurityModeParser::GetInstance()->Initialize(USER_ID);
service_ = std::make_shared<InputMethodSystemAbility>();
service_ = new (std::nothrow) InputMethodSystemAbility();
if (service_ == nullptr) {
IMSA_HILOGE("failed to new service");
return;
}
service_->OnStart();
service_->userId_ = USER_ID;
}
void SecurityModeParserTest::TearDownTestCase(void)
{
service_->OnStop();
IMSA_HILOGI("SecurityModeParserTest::TearDownTestCase");
}
void SecurityModeParserTest::SetUp()
{
IMSA_HILOGI("SecurityModeParserTest::SetUp");
resultSet_->strValue_ = "{\"fullExperienceList\" : {\"100\" : [ \"xiaoyiIme\", \"baiduIme\", "
"\"sougouIme\"],\"101\" : [\"sougouIme\"]}}";
@ -73,6 +81,7 @@ void SecurityModeParserTest::SetUp()
void SecurityModeParserTest::TearDown()
{
IMSA_HILOGI("SecurityModeParserTest::TearDown");
}
/**
@ -196,7 +205,7 @@ HWTEST_F(SecurityModeParserTest, testIsSecurityChange_001, TestSize.Level0)
int32_t ret = SecurityModeParser::GetInstance()->GetFullModeList(SecurityModeParserTest::USER_ID);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
SecurityModeParserTest::resultSet_->strValue_ = "{\"fullExperienceList\" : {\"100\" : [ \"baiduIme\", "
"\"sougouIme\"],\"101\" : [\"sougouIme\"]}}";
"\"sougouIme\"],\"101\" : [\"sougouIme\"]}}";
bool isSecurityChange =
SecurityModeParser::GetInstance()->IsSecurityChange("xiaoyiIme", SecurityModeParserTest::USER_ID);
EXPECT_EQ(isSecurityChange, true);