• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "set_auto_unlock_after_reboot_plugin_test.h"
17 
18 #include "edm_ipc_interface_code.h"
19 #include "iplugin_manager.h"
20 #include "parameters.h"
21 #include "plugin_singleton.h"
22 #include "set_auto_unlock_after_reboot_plugin.h"
23 #include "utils.h"
24 
25 using namespace testing::ext;
26 using namespace testing;
27 
28 namespace OHOS {
29 namespace EDM {
30 namespace TEST {
31 const std::string PERSIST_EDM_REMOTE_AUTO_UNLOCK_MODE = "persist.edm.auto_unlock_after_reboot";
SetUpTestSuite(void)32 void SetAutoUnlockAfterRebootPluginTest::SetUpTestSuite(void)
33 {
34     Utils::SetEdmInitialEnv();
35 }
36 
TearDownTestSuite(void)37 void SetAutoUnlockAfterRebootPluginTest::TearDownTestSuite(void)
38 {
39     Utils::ResetTokenTypeAndUid();
40     OHOS::system::SetParameter(PERSIST_EDM_REMOTE_AUTO_UNLOCK_MODE, "false");
41     ASSERT_TRUE(Utils::IsOriginalUTEnv());
42     std::cout << "now ut process is orignal ut env : " << Utils::IsOriginalUTEnv() << std::endl;
43 }
44 
45 /**
46  * @tc.name: TestSetAutoUnlockAfterRebootPluginTestSetTrue
47  * @tc.desc: Test SetAutoUnlockAfterRebootPluginTest OnSetPolicy function.
48  * @tc.type: FUNC
49  */
50 HWTEST_F(SetAutoUnlockAfterRebootPluginTest, TestSetAutoUnlockAfterRebootPluginTestSetTrue, TestSize.Level1)
51 {
52     MessageParcel data;
53     MessageParcel reply;
54     data.WriteBool(true);
55     std::shared_ptr<IPlugin> plugin = SetAutoUnlockAfterRebootPlugin::GetPlugin();
56     HandlePolicyData handlePolicyData{"false", "", false};
57     std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET,
58         EdmInterfaceCode::SET_AUTO_UNLOCK_AFTER_REBOOT);
59     ErrCode ret = plugin->OnHandlePolicy(funcCode, data, reply, handlePolicyData, DEFAULT_USER_ID);
60     ASSERT_TRUE(ret == ERR_OK);
61     ASSERT_TRUE(OHOS::system::GetBoolParameter(PERSIST_EDM_REMOTE_AUTO_UNLOCK_MODE, false));
62 }
63 
64 /**
65  * @tc.name: TestSetAutoUnlockAfterRebootPluginTestSetFalse
66  * @tc.desc: Test SetAutoUnlockAfterRebootPluginTest OnSetPolicy function.
67  * @tc.type: FUNC
68  */
69 HWTEST_F(SetAutoUnlockAfterRebootPluginTest, TestSetAutoUnlockAfterRebootPluginTestSetFalse, TestSize.Level1)
70 {
71     MessageParcel data;
72     MessageParcel reply;
73     data.WriteBool(false);
74     std::shared_ptr<IPlugin> plugin = SetAutoUnlockAfterRebootPlugin::GetPlugin();
75     HandlePolicyData handlePolicyData{"false", "", false};
76     std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET,
77         EdmInterfaceCode::SET_AUTO_UNLOCK_AFTER_REBOOT);
78     ErrCode ret = plugin->OnHandlePolicy(funcCode, data, reply, handlePolicyData, DEFAULT_USER_ID);
79     ASSERT_TRUE(ret == ERR_OK);
80     ASSERT_FALSE(OHOS::system::GetBoolParameter(PERSIST_EDM_REMOTE_AUTO_UNLOCK_MODE, true));
81 }
82 } // namespace TEST
83 } // namespace EDM
84 } // namespace OHOS
85