1 /*
2 * Copyright (c) 2022-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 <gtest/gtest.h>
17 #define private public
18 #define protected public
19 #include "ability_manager_service.h"
20 #include "interceptor/screen_unlock_interceptor.h"
21 #undef private
22 #undef protected
23
24 #include "ability_util.h"
25 #include "event_report.h"
26 #include "parameters.h"
27 #include "scene_board_judgement.h"
28 #include "start_ability_utils.h"
29
30 using namespace testing;
31 using namespace testing::ext;
32 using namespace OHOS::AppExecFwk;
33
34 namespace OHOS {
35 namespace AAFwk {
36 class ScreenUnlockInterceptorTest : public testing::Test {
37 public:
38 static void SetUpTestCase();
39 static void TearDownTestCase();
40 void SetUp();
41 void TearDown();
42
43 public:
44 };
45
SetUpTestCase()46 void ScreenUnlockInterceptorTest::SetUpTestCase()
47 {}
48
TearDownTestCase()49 void ScreenUnlockInterceptorTest::TearDownTestCase()
50 {}
51
SetUp()52 void ScreenUnlockInterceptorTest::SetUp()
53 {}
54
TearDown()55 void ScreenUnlockInterceptorTest::TearDown()
56 {}
57
58 /**
59 * @tc.name: ScreenUnlockInterceptorTest_DoProcess_001
60 * @tc.desc: DoProcess
61 * @tc.type: FUNC
62 * @tc.require: issueI5I0DY
63 */
64 HWTEST_F(ScreenUnlockInterceptorTest, DoProcess_001, TestSize.Level1)
65 {
66 ScreenUnlockInterceptor screenUnlockInterceptor;
67 Want want;
68 int requestCode = 123;
69 int32_t userId = 1001;
70 bool isWithUI = true;
71 sptr<IRemoteObject> callerToken;
__anon279f2edc0102() 72 std::function<bool(void)> shouldBlockAllAppStartFunc = []() -> bool {
73 return false;
74 };
75 StartAbilityUtils::startAbilityInfo = std::make_shared<StartAbilityInfo>();
76 AbilityInterceptorParam param(want, requestCode, userId, isWithUI, callerToken, shouldBlockAllAppStartFunc);
77 auto ret = screenUnlockInterceptor.DoProcess(param);
78 if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
79 EXPECT_EQ(ret, ERR_OK);
80 }
81 }
82
83 /**
84 * @tc.name: ScreenUnlockInterceptorTest_DoProcess_002
85 * @tc.desc: DoProcess
86 * @tc.type: FUNC
87 * @tc.require: issueI5I0DY
88 */
89 HWTEST_F(ScreenUnlockInterceptorTest, DoProcess_002, TestSize.Level1)
90 {
91 ScreenUnlockInterceptor screenUnlockInterceptor;
92 Want want;
93 int requestCode = 123;
94 int32_t userId = 1001;
95 bool isWithUI = true;
96 sptr<IRemoteObject> callerToken;
__anon279f2edc0202() 97 std::function<bool(void)> shouldBlockAllAppStartFunc = []() -> bool {
98 return false;
99 };
100 StartAbilityUtils::startAbilityInfo ->abilityInfo.applicationInfo.allowAppRunWhenDeviceFirstLocked = true;
101 AbilityInterceptorParam param(want, requestCode, userId, isWithUI, callerToken, shouldBlockAllAppStartFunc);
102 auto ret = screenUnlockInterceptor.DoProcess(param);
103 EXPECT_EQ(ret, ERR_OK);
104 }
105
106 /**
107 * @tc.name: ScreenUnlockInterceptorTest_DoProcess_003
108 * @tc.desc: DoProcess
109 * @tc.type: FUNC
110 * @tc.require: issueI5I0DY
111 */
112 HWTEST_F(ScreenUnlockInterceptorTest, DoProcess_003, TestSize.Level1)
113 {
114 ScreenUnlockInterceptor screenUnlockInterceptor;
115 Want want;
116 int requestCode = 123;
117 int32_t userId = 1001;
118 bool isWithUI = true;
119 sptr<IRemoteObject> callerToken;
__anon279f2edc0302() 120 std::function<bool(void)> shouldBlockAllAppStartFunc = []() -> bool {
121 return false;
122 };
123 StartAbilityUtils::startAbilityInfo ->abilityInfo.applicationInfo.allowAppRunWhenDeviceFirstLocked = false;
124 StartAbilityUtils::startAbilityInfo ->abilityInfo.applicationInfo.isSystemApp = true;
125 AbilityInterceptorParam param(want, requestCode, userId, isWithUI, callerToken, shouldBlockAllAppStartFunc);
126 auto ret = screenUnlockInterceptor.DoProcess(param);
127 EXPECT_EQ(ret, ERR_OK);
128 }
129
130 /**
131 * @tc.name: ScreenUnlockInterceptorTest_DoProcess_004
132 * @tc.desc: DoProcess
133 * @tc.type: FUNC
134 * @tc.require: issueI5I0DY
135 */
136 HWTEST_F(ScreenUnlockInterceptorTest, DoProcess_004, TestSize.Level1)
137 {
138 ScreenUnlockInterceptor screenUnlockInterceptor;
139 Want want;
140 int requestCode = 123;
141 int32_t userId = 1001;
142 bool isWithUI = true;
143 sptr<IRemoteObject> callerToken;
__anon279f2edc0402() 144 std::function<bool(void)> shouldBlockAllAppStartFunc = []() -> bool {
145 return false;
146 };
147 StartAbilityUtils::startAbilityInfo = nullptr;
148 AbilityInterceptorParam param(want, requestCode, userId, isWithUI, callerToken, shouldBlockAllAppStartFunc);
149 auto ret = screenUnlockInterceptor.DoProcess(param);
150 EXPECT_EQ(ret, ERR_OK);
151 }
152
153 /**
154 * @tc.name: ScreenUnlockInterceptorTest_DoProcess_005
155 * @tc.desc: DoProcess
156 * @tc.type: FUNC
157 * @tc.require: issueI5I0DY
158 */
159 HWTEST_F(ScreenUnlockInterceptorTest, DoProcess_005, TestSize.Level1)
160 {
161 GTEST_LOG_(INFO) << "DoProcess_005 start";
162 ScreenUnlockInterceptor screenUnlockInterceptor;
163 Want want;
164 int requestCode = 123;
165 int32_t userId = 1001;
166 bool isWithUI = true;
167 sptr<IRemoteObject> callerToken;
__anon279f2edc0502() 168 std::function<bool(void)> shouldBlockAllAppStartFunc = []() -> bool {
169 return false;
170 };
171 StartAbilityUtils::startAbilityInfo = std::make_shared<StartAbilityInfo>();
172 AppExecFwk::AbilityInfo targetAbilityInfo;
173 targetAbilityInfo.type = AppExecFwk::AbilityType::EXTENSION;
174 StartAbilityUtils::startAbilityInfo->abilityInfo = targetAbilityInfo;
175 AbilityInterceptorParam param(want, requestCode, userId, isWithUI, callerToken, shouldBlockAllAppStartFunc);
176 auto ret = screenUnlockInterceptor.DoProcess(param);
177 EXPECT_EQ(ret, ERR_OK);
178 GTEST_LOG_(INFO) << "DoProcess_005 end";
179 }
180 } // namespace AAFwk
181 } // namespace OHOS
182