diff --git a/common/include/message_handler.h b/common/include/message_handler.h index d4650cfe..f0a2fda0 100644 --- a/common/include/message_handler.h +++ b/common/include/message_handler.h @@ -32,6 +32,7 @@ enum { MSG_ID_USER_START = 0, // a user started MSG_ID_USER_REMOVED, // a user removed MSG_ID_PACKAGE_REMOVED, // a package is removed + MSG_ID_BUNDLE_SCAN_FINISHED, // bundle scan finished, ready to create data share helper MSG_ID_SELECT_BY_RANGE, MSG_ID_SELECT_BY_MOVEMENT, MSG_ID_HANDLE_EXTEND_ACTION, diff --git a/frameworks/native/inputmethod_controller/include/input_method_utils.h b/frameworks/native/inputmethod_controller/include/input_method_utils.h index eb6a0756..aab3d50d 100644 --- a/frameworks/native/inputmethod_controller/include/input_method_utils.h +++ b/frameworks/native/inputmethod_controller/include/input_method_utils.h @@ -68,7 +68,7 @@ enum class Direction { RIGHT, }; -enum class SecurityMode { +enum class SecurityMode : int32_t { BASIC = 0, FULL = 1, }; diff --git a/seccomp_policy/imf_ext_secure_mode.seccomp.policy b/seccomp_policy/imf_ext_secure_mode.seccomp.policy index 8a64c2fd..04dbab7f 100644 --- a/seccomp_policy/imf_ext_secure_mode.seccomp.policy +++ b/seccomp_policy/imf_ext_secure_mode.seccomp.policy @@ -90,11 +90,9 @@ pread64;all pwrite64;all preadv;all pwritev;all -sendfile;all pselect6;all ppoll;all signalfd4;all -vmsplice;all splice;all tee;all readlinkat;all @@ -178,19 +176,12 @@ getegid;arm64 gettid;all sysinfo;all socket;all -socketpair;all bind;all -listen;all -accept;all connect;all -getsockname;all -getpeername;all sendto;all recvfrom;all setsockopt;all getsockopt;all -shutdown;all -sendmsg;all recvmsg;all readahead;all brk;all @@ -209,8 +200,6 @@ mincore;all madvise;all rt_tgsigqueueinfo;all perf_event_open;all -accept4;all -recvmmsg;all wait4;all prlimit64;all syncfs;all @@ -277,7 +266,6 @@ getresuid32;arm getresgid32;arm chown32;arm fcntl64;arm -sendfile64;arm epoll_create;arm epoll_wait;arm remap_file_pages;arm @@ -300,7 +288,6 @@ timerfd_settime64;arm utimensat_time64;arm pselect6_time64;arm ppoll_time64;arm -recvmmsg_time64;arm semtimedop_time64;arm rt_sigtimedwait_time64;arm futex_time64;arm diff --git a/services/adapter/settings_data_provider/include/security_mode_parser.h b/services/adapter/settings_data_provider/include/security_mode_parser.h index 3a03a19d..bb4ba627 100644 --- a/services/adapter/settings_data_provider/include/security_mode_parser.h +++ b/services/adapter/settings_data_provider/include/security_mode_parser.h @@ -24,6 +24,7 @@ #include "datashare_helper.h" #include "global.h" +#include "input_method_utils.h" #include "serializable.h" #include "settings_data_observer.h" #include "settings_data_utils.h" @@ -42,9 +43,8 @@ class SecurityModeParser : public RefBase { public: static sptr GetInstance(); int32_t Initialize(const int32_t userId); - int32_t GetSecurityMode(const std::string bundleName, int32_t &security, const int32_t userId); - bool IsSecurityChange(const std::string bundleName, const int32_t userId); - int32_t GetFullModeList(const int32_t userId); + SecurityMode GetSecurityMode(const std::string &bundleName, int32_t userId); + int32_t UpdateFullModeList(int32_t userId); static constexpr const char *SECURITY_MODE = "settings.inputmethod.full_experience"; private: @@ -57,6 +57,8 @@ private: static sptr instance_; std::mutex listMutex_; std::vector fullModeList_; + std::mutex initLock_; + bool initialized_{ false }; }; } // namespace MiscServices } // namespace OHOS diff --git a/services/adapter/settings_data_provider/src/security_mode_parser.cpp b/services/adapter/settings_data_provider/src/security_mode_parser.cpp index 1b167bb4..a5fac553 100644 --- a/services/adapter/settings_data_provider/src/security_mode_parser.cpp +++ b/services/adapter/settings_data_provider/src/security_mode_parser.cpp @@ -48,10 +48,10 @@ sptr SecurityModeParser::GetInstance() int32_t SecurityModeParser::Initialize(const int32_t userId) { - return GetFullModeList(userId); + return UpdateFullModeList(userId); } -int32_t SecurityModeParser::GetFullModeList(const int32_t userId) +int32_t SecurityModeParser::UpdateFullModeList(int32_t userId) { IMSA_HILOGD("key: %{public}s.", SECURITY_MODE); std::string valueStr; @@ -68,20 +68,13 @@ int32_t SecurityModeParser::GetFullModeList(const int32_t userId) return ErrorCode::NO_ERROR; } -bool SecurityModeParser::IsSecurityChange(const std::string bundleName, const int32_t userId) -{ - bool oldExit = IsFullMode(bundleName); - GetFullModeList(userId); - bool onewExit = IsFullMode(bundleName); - return oldExit != onewExit; -} - bool SecurityModeParser::ParseSecurityMode(const std::string &valueStr, const int32_t userId) { SecModeCfg secModeCfg; secModeCfg.userImeCfg.userId = std::to_string(userId); auto ret = secModeCfg.Unmarshall(valueStr); if (!ret) { + IMSA_HILOGE("unmarshall failed"); return ret; } std::lock_guard autoLock(listMutex_); @@ -89,15 +82,25 @@ bool SecurityModeParser::ParseSecurityMode(const std::string &valueStr, const in return true; } -int32_t SecurityModeParser::GetSecurityMode(const std::string bundleName, int32_t &security, const int32_t userId) +SecurityMode SecurityModeParser::GetSecurityMode(const std::string &bundleName, int32_t userId) { - GetFullModeList(userId); - if (IsFullMode(bundleName)) { - security = static_cast(SecurityMode::FULL); - } else { - security = static_cast(SecurityMode::BASIC); + // always set default ime to full mode, remove this rule when default ime finishes adaptation. + auto defaultIme = ImeInfoInquirer::GetInstance().GetDefaultImeCfgProp(); + if (defaultIme != nullptr && bundleName == defaultIme->name) { + return SecurityMode::FULL; + } + if (!initialized_) { + std::lock_guard lock(initLock_); + if (!initialized_) { + UpdateFullModeList(userId); + initialized_ = true; + } + } + if (IsFullMode(bundleName)) { + return SecurityMode::FULL; + } else { + return SecurityMode::BASIC; } - return ErrorCode::NO_ERROR; } bool SecurityModeParser::IsFullMode(std::string bundleName) diff --git a/services/include/im_common_event_manager.h b/services/include/im_common_event_manager.h index 25eef573..72d8545c 100644 --- a/services/include/im_common_event_manager.h +++ b/services/include/im_common_event_manager.h @@ -54,6 +54,7 @@ public: void RemovePackage(const EventFwk::CommonEventData &data); void StartUser(const EventFwk::CommonEventData &data); void RemoveUser(const EventFwk::CommonEventData &data); + void OnBundleScanFinished(const EventFwk::CommonEventData &data); private: using EventListenerFunc = void (EventSubscriber::*)(const EventFwk::CommonEventData &data); diff --git a/services/include/input_method_system_ability.h b/services/include/input_method_system_ability.h index 2ca77dcc..8bfaf1e7 100644 --- a/services/include/input_method_system_ability.h +++ b/services/include/input_method_system_ability.h @@ -123,6 +123,7 @@ private: int32_t RestartCurrentIme(); void HandleWmsReady(int32_t userId); int32_t InitAccountMonitor(); + int32_t RegisterDataShareObserver(); static std::shared_ptr serviceHandler_; int32_t userId_; static constexpr const char *SELECT_DIALOG_ACTION = "action.system.inputmethodchoose"; @@ -147,6 +148,8 @@ private: void CheckInputTypeOption(InputClientInfo &inputClientInfo); int32_t IsDefaultImeFromTokenId(uint32_t tokenId); void DealSwitchRequest(); + void DealSecurityChange(); + void OnSecurityModeChange(); std::mutex checkMutex_; void DatashareCallback(const std::string &key); @@ -158,6 +161,10 @@ private: std::mutex switchImeMutex_; std::atomic switchTaskExecuting_ = false; std::atomic targetSwitchCount_ = 0; + + std::mutex modeChangeMutex_; + bool isChangeHandling_ = false; + bool hasPendingChanges_ = false; }; } // namespace MiscServices } // namespace OHOS diff --git a/services/src/im_common_event_manager.cpp b/services/src/im_common_event_manager.cpp index 78bb48fc..c9db8eca 100644 --- a/services/src/im_common_event_manager.cpp +++ b/services/src/im_common_event_manager.cpp @@ -60,6 +60,7 @@ bool ImCommonEventManager::SubscribeEvent(const std::string &event) matchingSkills.AddEvent(event); matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_REMOVED); matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_BUNDLE_SCAN_FINISHED); EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills); @@ -198,6 +199,7 @@ ImCommonEventManager::EventSubscriber::EventSubscriber(const EventFwk::CommonEve EventManagerFunc_[CommonEventSupport::COMMON_EVENT_USER_SWITCHED] = &EventSubscriber::StartUser; EventManagerFunc_[CommonEventSupport::COMMON_EVENT_USER_REMOVED] = &EventSubscriber::RemoveUser; EventManagerFunc_[CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED] = &EventSubscriber::RemovePackage; + EventManagerFunc_[CommonEventSupport::COMMON_EVENT_BUNDLE_SCAN_FINISHED] = &EventSubscriber::OnBundleScanFinished; } void ImCommonEventManager::EventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &data) @@ -225,6 +227,23 @@ void ImCommonEventManager::EventSubscriber::StartUser(const CommonEventData &dat MessageHandler::Instance()->SendMessage(msg); } +void ImCommonEventManager::EventSubscriber::OnBundleScanFinished(const EventFwk::CommonEventData &data) +{ + IMSA_HILOGI("ImCommonEventManager in"); + auto parcel = new (std::nothrow) MessageParcel(); + if (parcel == nullptr) { + IMSA_HILOGE("failed to create MessageParcel"); + return; + } + auto msg = new (std::nothrow) Message(MessageID::MSG_ID_BUNDLE_SCAN_FINISHED, parcel); + if (msg == nullptr) { + IMSA_HILOGE("failed to create Message"); + delete parcel; + return; + } + MessageHandler::Instance()->SendMessage(msg); +} + void ImCommonEventManager::EventSubscriber::RemoveUser(const CommonEventData &data) { auto userId = data.GetCode(); diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index d86fc291..e56683b6 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -173,7 +173,7 @@ void InputMethodSystemAbility::HandleUserChanged(int32_t userId) EnableImeDataParser::GetInstance()->OnUserChanged(userId_); } if (enableSecurityMode_) { - SecurityModeParser::GetInstance()->GetFullModeList(userId_); + SecurityModeParser::GetInstance()->UpdateFullModeList(userId_); } ImeInfoInquirer::GetInstance().SetCurrentImeInfo(nullptr); } @@ -842,6 +842,10 @@ void InputMethodSystemAbility::WorkThread() userSession_->OnHideSoftKeyBoardSelf(); break; } + case MSG_ID_BUNDLE_SCAN_FINISHED: { + RegisterDataShareObserver(); + break; + } default: { IMSA_HILOGD("the message is %{public}d.", msg->msgId_); break; @@ -970,6 +974,36 @@ int32_t InputMethodSystemAbility::SwitchByCombinationKey(uint32_t state) return ErrorCode::ERROR_EX_UNSUPPORTED_OPERATION; } +void InputMethodSystemAbility::DealSecurityChange() +{ + { + std::lock_guard lock(modeChangeMutex_); + if (isChangeHandling_) { + IMSA_HILOGI("already has mode change task."); + hasPendingChanges_ = true; + return; + } else { + isChangeHandling_ = true; + hasPendingChanges_ = true; + } + } + auto changeTask = [this]() { + pthread_setname_np(pthread_self(), "SecurityChange"); + auto checkChangeCount = [this]() { + std::lock_guard lock(modeChangeMutex_); + if (hasPendingChanges_) { + return true; + } + isChangeHandling_ = false; + return false; + }; + do { + OnSecurityModeChange(); + } while (checkChangeCount()); + }; + std::thread(changeTask).detach(); +} + void InputMethodSystemAbility::DealSwitchRequest() { { @@ -1088,13 +1122,24 @@ void InputMethodSystemAbility::InitMonitors() IMSA_HILOGW("Enter enable mode"); EnableImeDataParser::GetInstance()->Initialize(userId_); enableImeOn_ = true; - RegisterEnableImeObserver(); } if (ImeInfoInquirer::GetInstance().IsEnableSecurityMode()) { IMSA_HILOGW("Enter security mode"); enableSecurityMode_ = true; + } + RegisterDataShareObserver(); +} + +int32_t InputMethodSystemAbility::RegisterDataShareObserver() +{ + IMSA_HILOGD("in"); + if (enableImeOn_) { + RegisterEnableImeObserver(); + } + if (enableSecurityMode_) { RegisterSecurityModeObserver(); } + return ErrorCode::NO_ERROR; } int32_t InputMethodSystemAbility::InitAccountMonitor() @@ -1182,26 +1227,46 @@ void InputMethodSystemAbility::DatashareCallback(const std::string &key) OnSwitchInputMethod(switchInfo, SwitchTrigger::IMSA); } } - if (key == SecurityModeParser::SECURITY_MODE) { - auto currentBundleName = ImeCfgManager::GetInstance().GetCurrentImeCfg(userId_)->bundleName; - if (SecurityModeParser::GetInstance()->IsSecurityChange(currentBundleName, userId_)) { - int32_t security; - SecurityModeParser::GetInstance()->GetSecurityMode(currentBundleName, security, userId_); - userSession_->OnSecurityChange(security); - } + DealSecurityChange(); + } +} + +void InputMethodSystemAbility::OnSecurityModeChange() +{ + { + std::lock_guard lock(modeChangeMutex_); + hasPendingChanges_ = false; + } + auto currentIme = ImeCfgManager::GetInstance().GetCurrentImeCfg(userId_); + auto oldMode = SecurityModeParser::GetInstance()->GetSecurityMode(currentIme->bundleName, userId_); + SecurityModeParser::GetInstance()->UpdateFullModeList(userId_); + auto newMode = SecurityModeParser::GetInstance()->GetSecurityMode(currentIme->bundleName, userId_); + if (oldMode == newMode) { + IMSA_HILOGD("current ime mode not changed"); + return; + } + IMSA_HILOGI("ime: %{public}s securityMode change to: %{public}d", currentIme->bundleName.c_str(), + static_cast(newMode)); + userSession_->OnSecurityChange(static_cast(newMode)); + userSession_->StopCurrentIme(); + auto ret = userSession_->StartInputService(currentIme, true); + if (!ret) { + IMSA_HILOGE("ime start failed"); } } int32_t InputMethodSystemAbility::GetSecurityMode(int32_t &security) { - IMSA_HILOGD("GetSecurityMode"); + IMSA_HILOGD("InputMethodSystemAbility in"); if (!enableSecurityMode_) { security = static_cast(SecurityMode::FULL); return ErrorCode::NO_ERROR; } auto callBundleName = identityChecker_->GetBundleNameByToken(IPCSkeleton::GetCallingTokenID()); - return SecurityModeParser::GetInstance()->GetSecurityMode(callBundleName, security, userId_); + SecurityMode mode = SecurityModeParser::GetInstance()->GetSecurityMode(callBundleName, userId_); + security = static_cast(mode); + return ErrorCode::NO_ERROR; } int32_t InputMethodSystemAbility::UnRegisteredProxyIme(UnRegisteredType type, const sptr &core) diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index f660d408..6ad2607b 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -30,6 +30,7 @@ #include "message_parcel.h" #include "parcel.h" #include "scene_board_judgement.h" +#include "security_mode_parser.h" #include "sys/prctl.h" #include "system_ability_definition.h" #include "unistd.h" @@ -43,6 +44,7 @@ constexpr uint32_t IME_RESTART_TIMES = 5; constexpr uint32_t IME_RESTART_INTERVAL = 300; constexpr int64_t INVALID_PID = -1; constexpr uint32_t STOP_IME_TIME = 600; +constexpr const char *STRICT_MODE = "strictMode"; PerUserSession::PerUserSession(int32_t userId) : userId_(userId) { } @@ -972,9 +974,17 @@ void PerUserSession::StopCurrentIme() bool PerUserSession::StartInputService(const std::shared_ptr &ime, bool isRetry) { - IMSA_HILOGI("start %{public}s with isRetry: %{public}d", ime->imeId.c_str(), isRetry); + SecurityMode mode; + if (ImeInfoInquirer::GetInstance().IsEnableSecurityMode()) { + mode = SecurityModeParser::GetInstance()->GetSecurityMode(ime->bundleName, userId_); + } else { + mode = SecurityMode::FULL; + } + IMSA_HILOGI("ime: %{public}s, mode: %{public}d isRetry: %{public}d", ime->imeId.c_str(), + static_cast(mode), isRetry); AAFwk::Want want; want.SetElementName(ime->bundleName, ime->extName); + want.SetParam(STRICT_MODE, !(mode == SecurityMode::FULL)); isImeStarted_.Clear(false); sptr connection = new (std::nothrow) ImeConnection(); if (connection == nullptr) { diff --git a/test/unittest/cpp_test/src/input_method_ext_seccomp_test.cpp b/test/unittest/cpp_test/src/input_method_ext_seccomp_test.cpp index 20b4da3f..d8066665 100644 --- a/test/unittest/cpp_test/src/input_method_ext_seccomp_test.cpp +++ b/test/unittest/cpp_test/src/input_method_ext_seccomp_test.cpp @@ -13,23 +13,23 @@ * limitations under the License. */ -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include #include "seccomp_policy.h" @@ -44,10 +44,10 @@ namespace OHOS { namespace MiscServices { class SeccompUnitTest : public testing::Test { public: - SeccompUnitTest() {}; - virtual ~SeccompUnitTest() {}; - static void SetUpTestCase() {}; - static void TearDownTestCase() {}; + SeccompUnitTest(){}; + virtual ~SeccompUnitTest(){}; + static void SetUpTestCase(){}; + static void TearDownTestCase(){}; void SetUp() { @@ -59,8 +59,8 @@ public: sleep(SLEEP_TIME_1S); }; - void TearDown() {}; - void TestBody(void) {}; + void TearDown(){}; + void TestBody(void){}; static pid_t StartChild(SeccompFilterType type, const char *filterName, SyscallFunc func) { @@ -96,8 +96,8 @@ public: if (WIFSIGNALED(status)) { if (WTERMSIG(status) == SIGSYS) { - std::cout << "child process exit with SIGSYS" << std::endl; - return isAllow ? -1 : 0; + std::cout << "child process exit with SIGSYS" << std::endl; + return isAllow ? -1 : 0; } } else { std::cout << "child process finished normally" << std::endl; @@ -113,7 +113,7 @@ public: int status; pid_t pid; int flag = 0; - struct timespec waitTime = {5, 0}; + struct timespec waitTime = { 5, 0 }; sigemptyset(&set); sigaddset(&set, SIGCHLD); @@ -156,6 +156,115 @@ public: return CheckStatus(status, isAllow); } + static bool CheckSendfile() + { + int ret = syscall(__NR_sendfile, 0, 0, nullptr, 0); + if (ret == 0) { + return true; + } + + return false; + } + + static bool CheckVmsplice() + { + int ret = syscall(__NR_vmsplice, 0, nullptr, 0, 0); + if (ret == 0) { + return true; + } + + return false; + } + + static bool CheckSocketpair() + { + int ret = syscall(__NR_socketpair, 0, 0, 0, nullptr); + if (ret == 0) { + return true; + } + + return false; + } + + static bool CheckListen() + { + int ret = syscall(__NR_listen, 0, 0); + if (ret == 0) { + return true; + } + + return false; + } + + static bool CheckAccept() + { + int ret = syscall(__NR_accept, 0, nullptr, nullptr); + if (ret == 0) { + return true; + } + + return false; + } + + static bool CheckAccept4() + { + int ret = syscall(__NR_accept4, 0, nullptr, nullptr, 0); + if (ret == 0) { + return true; + } + + return false; + } + + static bool CheckGetsockname() + { + int ret = syscall(__NR_getsockname, 0, nullptr, nullptr); + if (ret == 0) { + return true; + } + + return false; + } + + static bool CheckGetpeername() + { + int ret = syscall(__NR_getpeername, 0, nullptr, nullptr); + if (ret == 0) { + return true; + } + + return false; + } + + static bool CheckShutdown() + { + int ret = syscall(__NR_shutdown, 0, 0); + if (ret == 0) { + return true; + } + + return false; + } + + static bool CheckSendmsg() + { + int ret = syscall(__NR_sendmsg, 0, nullptr, 0); + if (ret == 0) { + return true; + } + + return false; + } + + static bool CheckRecvmmsg() + { + int ret = syscall(__NR_recvmmsg, 0, nullptr, 0, 0, nullptr); + if (ret == 0) { + return true; + } + + return false; + } #if defined __aarch64__ static bool CheckSetuid() { @@ -166,12 +275,6 @@ public: return false; } - void TestInputMethodExtSycall() - { - // system blocklist - int ret = CheckSyscall(APP, IMF_EXTENTOIN_NAME, CheckSetuid, false); - EXPECT_EQ(ret, 0); - } #elif defined __arm__ static bool CheckSetuid32() @@ -183,13 +286,49 @@ public: return false; } - void TestInputMethodExtSycall() + static bool CheckSendfile64() { - // system blocklist - int ret = CheckSyscall(APP, IMF_EXTENTOIN_NAME, CheckSetuid32, false); - EXPECT_EQ(ret, 0); + int ret = syscall(__NR_sendfile64, 0, 0, nullptr, 0); + if (ret == 0) { + return true; + } + + return false; + } + static bool CheckRecvmmsgTime64() + { + int ret = syscall(__NR_recvmmsg_time64, 0, nullptr, 0, 0, nullptr); + if (ret == 0) { + return true; + } + + return false; } #endif + + void TestInputMethodExtSycall() + { + int ret = -1; + ret = CheckSyscall(APP, IMF_EXTENTOIN_NAME, CheckSendfile, false); + EXPECT_EQ(ret, 0); + + ret = CheckSyscall(APP, IMF_EXTENTOIN_NAME, CheckVmsplice, false); + EXPECT_EQ(ret, 0); + +#if defined __aarch64__ + // system blocklist + ret = CheckSyscall(APP, IMF_EXTENTOIN_NAME, CheckSetuid, false); + EXPECT_EQ(ret, 0); +#elif defined __arm__ + // system blocklist + ret = CheckSyscall(APP, IMF_EXTENTOIN_NAME, CheckSetuid32, false); + EXPECT_EQ(ret, 0); + ret = CheckSyscall(APP, IMF_EXTENTOIN_NAME, CheckSendfile64, false); + EXPECT_EQ(ret, 0); + ret = CheckSyscall(APP, IMF_EXTENTOIN_NAME, CheckRecvmmsgTime64, false); + EXPECT_EQ(ret, 0); +#endif + } }; /** @@ -203,6 +342,5 @@ HWTEST_F(SeccompUnitTest, TestInputMethodExtSycall, TestSize.Level1) SeccompUnitTest test; test.TestInputMethodExtSycall(); } -} -} - +} // namespace MiscServices +} // namespace OHOS diff --git a/test/unittest/cpp_test/src/security_mode_parser_test.cpp b/test/unittest/cpp_test/src/security_mode_parser_test.cpp index 304739a2..da0c0a7f 100644 --- a/test/unittest/cpp_test/src/security_mode_parser_test.cpp +++ b/test/unittest/cpp_test/src/security_mode_parser_test.cpp @@ -92,7 +92,7 @@ void SecurityModeParserTest::TearDown() HWTEST_F(SecurityModeParserTest, testGetFullModeList_001, TestSize.Level0) { IMSA_HILOGI("SecurityModeParserTest testGetFullModeList_001 START"); - int32_t ret = SecurityModeParser::GetInstance()->GetFullModeList(101); + int32_t ret = SecurityModeParser::GetInstance()->UpdateFullModeList(101); EXPECT_EQ(ret, ErrorCode::NO_ERROR); EXPECT_EQ(SecurityModeParser::GetInstance()->fullModeList_.size(), USER_101_TOTAL_COUNT); if (SecurityModeParser::GetInstance()->fullModeList_.size() == USER_101_TOTAL_COUNT) { @@ -110,7 +110,7 @@ HWTEST_F(SecurityModeParserTest, testGetFullModeList_001, TestSize.Level0) HWTEST_F(SecurityModeParserTest, testGetFullModeList_002, TestSize.Level0) { IMSA_HILOGI("SecurityModeParserTest testGetFullModeList_002 START"); - int32_t ret = SecurityModeParser::GetInstance()->GetFullModeList(SecurityModeParserTest::USER_ID); + int32_t ret = SecurityModeParser::GetInstance()->UpdateFullModeList(SecurityModeParserTest::USER_ID); EXPECT_EQ(ret, ErrorCode::NO_ERROR); EXPECT_EQ(SecurityModeParser::GetInstance()->fullModeList_.size(), USER_100_TOTAL_COUNT); if (SecurityModeParser::GetInstance()->fullModeList_.size() == USER_100_TOTAL_COUNT) { @@ -130,12 +130,11 @@ HWTEST_F(SecurityModeParserTest, testGetFullModeList_002, TestSize.Level0) HWTEST_F(SecurityModeParserTest, testGetSecurityMode_001, TestSize.Level0) { IMSA_HILOGI("SecurityModeParserTest testGetSecurityMode_001 START"); - int32_t ret = SecurityModeParser::GetInstance()->GetFullModeList(SecurityModeParserTest::USER_ID); + int32_t ret = SecurityModeParser::GetInstance()->UpdateFullModeList(SecurityModeParserTest::USER_ID); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - int32_t security; - ret = SecurityModeParser::GetInstance()->GetSecurityMode("xiaoyiIme", security, SecurityModeParserTest::USER_ID); - EXPECT_EQ(ret, ErrorCode::NO_ERROR); - EXPECT_EQ(security, 1); + SecurityMode security = + SecurityModeParser::GetInstance()->GetSecurityMode("xiaoyiIme", SecurityModeParserTest::USER_ID); + EXPECT_EQ(static_cast(security), 1); } /** @@ -148,12 +147,11 @@ HWTEST_F(SecurityModeParserTest, testGetSecurityMode_001, TestSize.Level0) HWTEST_F(SecurityModeParserTest, testGetSecurityMode_002, TestSize.Level0) { IMSA_HILOGI("SecurityModeParserTest testGetSecurityMode_002 START"); - int32_t ret = SecurityModeParser::GetInstance()->GetFullModeList(SecurityModeParserTest::USER_ID); + int32_t ret = SecurityModeParser::GetInstance()->UpdateFullModeList(SecurityModeParserTest::USER_ID); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - int32_t security; - ret = SecurityModeParser::GetInstance()->GetSecurityMode("test", security, SecurityModeParserTest::USER_ID); - EXPECT_EQ(ret, ErrorCode::NO_ERROR); - EXPECT_EQ(security, 0); + SecurityMode security = + SecurityModeParser::GetInstance()->GetSecurityMode("test", SecurityModeParserTest::USER_ID); + EXPECT_EQ(static_cast(security), 0); } /** @@ -189,24 +187,5 @@ HWTEST_F(SecurityModeParserTest, testGetSecurityMode_004, TestSize.Level0) EXPECT_EQ(ret, ErrorCode::NO_ERROR); EXPECT_EQ(securityMode, 0); } - -/** - * @tc.name: testIsSecurityChange_001 - * @tc.desc: is security change - * @tc.type: FUNC - * @tc.require: - * @tc.author: guojin - */ -HWTEST_F(SecurityModeParserTest, testIsSecurityChange_001, TestSize.Level0) -{ - IMSA_HILOGI("SecurityModeParserTest testIsSecurityChange_001 START"); - int32_t ret = SecurityModeParser::GetInstance()->GetFullModeList(SecurityModeParserTest::USER_ID); - EXPECT_EQ(ret, ErrorCode::NO_ERROR); - SecurityModeParserTest::resultSet_->strValue_ = "{\"fullExperienceList\" : {\"100\" : [ \"baiduIme\", " - "\"sougouIme\"],\"101\" : [\"sougouIme\"]}}"; - bool isSecurityChange = - SecurityModeParser::GetInstance()->IsSecurityChange("xiaoyiIme", SecurityModeParserTest::USER_ID); - EXPECT_EQ(isSecurityChange, true); -} } // namespace MiscServices } // namespace OHOS \ No newline at end of file