• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #include "first_use_dialog_test.h"
16 
17 #include <cstdio>
18 #include "accesstoken_kit.h"
19 #include "location_button.h"
20 #include "save_button.h"
21 #include "sec_comp_log.h"
22 #include "sec_comp_err.h"
23 #include "sec_event_handler.h"
24 
25 using namespace testing::ext;
26 using namespace OHOS;
27 using namespace OHOS::Security::SecurityComponent;
28 using namespace OHOS::Security::AccessToken;
29 
30 namespace {
31 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {
32     LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "FirstUseDialogTest"};
33 static const std::string SEC_COMP_SRV_CFG_PATH = "/data/service/el1/public/security_component_service";
34 static const std::string SEC_COMP_SRV_CFG_FILE = SEC_COMP_SRV_CFG_PATH + "/" + "first_use_record.json";
35 static const std::string SEC_COMP_SRV_CFG_BACK_FILE = SEC_COMP_SRV_CFG_PATH + "/" + "first_use_record.json.bak";
36 static const std::string INVALID_PATH = "/invalid_path";
37 static const std::string DATA_FOLDER = "/data";
38 constexpr uint64_t LOCATION_BUTTON_FIRST_USE = 1 << 0;
39 constexpr uint64_t SAVE_BUTTON_FIRST_USE = 1 << 1;
40 }
41 
SetUpTestCase()42 void FirstUseDialogTest::SetUpTestCase()
43 {
44 }
45 
TearDownTestCase()46 void FirstUseDialogTest::TearDownTestCase()
47 {
48     struct stat fstatJson = {};
49     if (stat(SEC_COMP_SRV_CFG_FILE.c_str(), &fstatJson) != 0) {
50         return;
51     }
52     // if json file is created by root, delete it
53     if (fstatJson.st_uid == 0) {
54         std::string cmdline = "rm -f " + SEC_COMP_SRV_CFG_FILE;
55         system(cmdline.c_str());
56     }
57     struct stat fstatDir = {};
58     if (stat(SEC_COMP_SRV_CFG_PATH.c_str(), &fstatDir) != 0) {
59         return;
60     }
61     if (fstatDir.st_uid == 0) {
62         std::string cmdline = "chown security_component:security_component " + SEC_COMP_SRV_CFG_PATH;
63         system(cmdline.c_str());
64     }
65 }
66 
SetUp()67 void FirstUseDialogTest::SetUp()
68 {
69     SC_LOG_INFO(LABEL, "setup");
70     struct stat fstat = {};
71     if (stat(SEC_COMP_SRV_CFG_FILE.c_str(), &fstat) != 0) {
72         return;
73     }
74     std::string cmdline = "mv " + SEC_COMP_SRV_CFG_FILE + " " + SEC_COMP_SRV_CFG_BACK_FILE;
75     system(cmdline.c_str());
76 }
77 
TearDown()78 void FirstUseDialogTest::TearDown()
79 {
80     struct stat fstat = {};
81     if (stat(SEC_COMP_SRV_CFG_BACK_FILE.c_str(), &fstat) != 0) {
82         return;
83     }
84     std::string cmdline = "mv " + SEC_COMP_SRV_CFG_BACK_FILE + " " + SEC_COMP_SRV_CFG_FILE;
85     system(cmdline.c_str());
86 }
87 
88 /**
89  * @tc.name: LoadFirstUseRecord001
90  * @tc.desc: Test cfg file not exist
91  * @tc.type: FUNC
92  * @tc.require:
93  */
94 HWTEST_F(FirstUseDialogTest, ReportUserData001, TestSize.Level0)
95 {
96     FirstUseDialog diag;
97     diag.firstUseMap_[1] = 1;
98     diag.SaveFirstUseRecord();
99     ASSERT_EQ(true, ReportUserData(SEC_COMP_SRV_CFG_FILE, DATA_FOLDER));
100     ASSERT_EQ(false, ReportUserData(INVALID_PATH, DATA_FOLDER));
101     ASSERT_EQ(false, ReportUserData(SEC_COMP_SRV_CFG_FILE, INVALID_PATH));
102 }
103 
104 /**
105  * @tc.name: LoadFirstUseRecord001
106  * @tc.desc: Test cfg file not exist
107  * @tc.type: FUNC
108  * @tc.require:
109  */
110 HWTEST_F(FirstUseDialogTest, LoadFirstUseRecord001, TestSize.Level0)
111 {
112     FirstUseDialog diag;
113     diag.LoadFirstUseRecord();
114     ASSERT_EQ(0, static_cast<int32_t>(diag.firstUseMap_.size()));
115 }
116 
117 /**
118  * @tc.name: LoadFirstUseRecord002
119  * @tc.desc: Test cfg file too large
120  * @tc.type: FUNC
121  * @tc.require:
122  */
123 HWTEST_F(FirstUseDialogTest, LoadFirstUseRecord002, TestSize.Level0)
124 {
125     std::string cmdline = "dd if=/dev/random of=" + SEC_COMP_SRV_CFG_FILE + " bs=101k count=1";
126     system(cmdline.c_str());
127     FirstUseDialog diag;
128     diag.LoadFirstUseRecord();
129     ASSERT_EQ(0, static_cast<int32_t>(diag.firstUseMap_.size()));
130 }
131 
132 /**
133  * @tc.name: LoadFirstUseRecord003
134  * @tc.desc: Test cfg file is not json
135  * @tc.type: FUNC
136  * @tc.require:
137  */
138 HWTEST_F(FirstUseDialogTest, LoadFirstUseRecord003, TestSize.Level0)
139 {
140     std::string cmdline = "echo {x=\\\' > " + SEC_COMP_SRV_CFG_FILE;
141     system(cmdline.c_str());
142     FirstUseDialog diag;
143     diag.LoadFirstUseRecord();
144     ASSERT_EQ(0, static_cast<int32_t>(diag.firstUseMap_.size()));
145 }
146 
147 /**
148  * @tc.name: LoadFirstUseRecord004
149  * @tc.desc: Test cfg file has no tag named FIRST_USE_RECORD_TAG
150  * @tc.type: FUNC
151  * @tc.require:
152  */
153 HWTEST_F(FirstUseDialogTest, LoadFirstUseRecord004, TestSize.Level0)
154 {
155     std::string cmdline = "echo {\\\"x\\\":1} > " + SEC_COMP_SRV_CFG_FILE;
156     system(cmdline.c_str());
157     FirstUseDialog diag;
158     diag.LoadFirstUseRecord();
159     ASSERT_EQ(0, static_cast<int32_t>(diag.firstUseMap_.size()));
160 }
161 
162 /**
163  * @tc.name: LoadFirstUseRecord005
164  * @tc.desc: Test cfg file has no tag named TOKEN_ID_TAG
165  * @tc.type: FUNC
166  * @tc.require:
167  */
168 HWTEST_F(FirstUseDialogTest, LoadFirstUseRecord005, TestSize.Level0)
169 {
170     std::string cmdline = "echo {\\\"FirstUseRecord\\\":[{\\\"CompType\\\":1}]} > "
171          + SEC_COMP_SRV_CFG_FILE;
172     system(cmdline.c_str());
173     FirstUseDialog diag;
174     diag.LoadFirstUseRecord();
175     ASSERT_EQ(0, static_cast<int32_t>(diag.firstUseMap_.size()));
176 }
177 
178 /**
179  * @tc.name: LoadFirstUseRecord006
180  * @tc.desc: Test cfg file TOKEN_ID_TAG is not number
181  * @tc.type: FUNC
182  * @tc.require:
183  */
184 HWTEST_F(FirstUseDialogTest, LoadFirstUseRecord006, TestSize.Level0)
185 {
186     std::string cmdline = "echo {\\\"FirstUseRecord\\\":[{\\\"CompType\\\":1,\\\"TokenId\\\":\\\"kk\\\"}]} > "
187          + SEC_COMP_SRV_CFG_FILE;
188     system(cmdline.c_str());
189     FirstUseDialog diag;
190     diag.LoadFirstUseRecord();
191     ASSERT_EQ(0, static_cast<int32_t>(diag.firstUseMap_.size()));
192 }
193 
194 /**
195  * @tc.name: LoadFirstUseRecord007
196  * @tc.desc: Test cfg file TOKEN_ID_TAG value is 0
197  * @tc.type: FUNC
198  * @tc.require:
199  */
200 HWTEST_F(FirstUseDialogTest, LoadFirstUseRecord007, TestSize.Level0)
201 {
202     std::string cmdline = "echo {\\\"FirstUseRecord\\\":[{\\\"CompType\\\":1,\\\"TokenId\\\":0}]} > "
203          + SEC_COMP_SRV_CFG_FILE;
204     system(cmdline.c_str());
205     FirstUseDialog diag;
206     diag.LoadFirstUseRecord();
207     ASSERT_EQ(0, static_cast<int32_t>(diag.firstUseMap_.size()));
208 }
209 
210 /**
211  * @tc.name: LoadFirstUseRecord008
212  * @tc.desc: Test cfg file COMP_TYPE_TAG is not exist
213  * @tc.type: FUNC
214  * @tc.require:
215  */
216 HWTEST_F(FirstUseDialogTest, LoadFirstUseRecord008, TestSize.Level0)
217 {
218     std::string cmdline = "echo {\\\"FirstUseRecord\\\":[{\\\"TokenId\\\":1}]} > "
219          + SEC_COMP_SRV_CFG_FILE;
220     system(cmdline.c_str());
221     FirstUseDialog diag;
222     diag.LoadFirstUseRecord();
223     ASSERT_EQ(0, static_cast<int32_t>(diag.firstUseMap_.size()));
224 }
225 
226 /**
227  * @tc.name: LoadFirstUseRecord009
228  * @tc.desc: Test cfg file COMP_TYPE_TAG is number
229  * @tc.type: FUNC
230  * @tc.require:
231  */
232 HWTEST_F(FirstUseDialogTest, LoadFirstUseRecord009, TestSize.Level0)
233 {
234     std::string cmdline = "echo {\\\"FirstUseRecord\\\":[{\\\"CompType\\\":\\\"k\\\",\\\"TokenId\\\":1}]} > "
235          + SEC_COMP_SRV_CFG_FILE;
236     system(cmdline.c_str());
237     FirstUseDialog diag;
238     diag.LoadFirstUseRecord();
239     ASSERT_EQ(0, static_cast<int32_t>(diag.firstUseMap_.size()));
240 }
241 
242 /**
243  * @tc.name: LoadFirstUseRecord010
244  * @tc.desc: Test cfg file is success
245  * @tc.type: FUNC
246  * @tc.require:
247  */
248 HWTEST_F(FirstUseDialogTest, LoadFirstUseRecord010, TestSize.Level0)
249 {
250     std::string cmdline = "echo {\\\"FirstUseRecord\\\":[{\\\"CompType\\\":1,\\\"TokenId\\\":1}]} > "
251          + SEC_COMP_SRV_CFG_FILE;
252     system(cmdline.c_str());
253     FirstUseDialog diag;
254     diag.LoadFirstUseRecord();
255     ASSERT_EQ(1, static_cast<int32_t>(diag.firstUseMap_.size()));
256     ASSERT_EQ(1, static_cast<int32_t>(diag.firstUseMap_[1]));
257 }
258 
259 /**
260  * @tc.name: SaveFirstUseRecord001
261  * @tc.desc: Test cfg dir is not exist
262  * @tc.type: FUNC
263  * @tc.require:
264  */
265 HWTEST_F(FirstUseDialogTest, SaveFirstUseRecord001, TestSize.Level0)
266 {
267     std::string cmdline = "rm " + SEC_COMP_SRV_CFG_PATH + " -rf";
268     system(cmdline.c_str());
269     FirstUseDialog diag;
270     diag.firstUseMap_[1] = 1;
271     diag.SaveFirstUseRecord();
272     diag.firstUseMap_.clear();
273     diag.LoadFirstUseRecord();
274     EXPECT_EQ(0, static_cast<int32_t>(diag.firstUseMap_.size()));
275     std::string cmdline1 = "mkdir " + SEC_COMP_SRV_CFG_PATH + " 0750 security_component security_component";
276     system(cmdline1.c_str());
277 }
278 
279 /**
280  * @tc.name: SaveFirstUseRecord002
281  * @tc.desc: Test cfg dir is not dir
282  * @tc.type: FUNC
283  * @tc.require:
284  */
285 HWTEST_F(FirstUseDialogTest, SaveFirstUseRecord002, TestSize.Level0)
286 {
287     std::string cmdline = "rm " + SEC_COMP_SRV_CFG_PATH + " -rf && touch " + SEC_COMP_SRV_CFG_PATH;
288     system(cmdline.c_str());
289     FirstUseDialog diag;
290     diag.firstUseMap_[1] = 1;
291     diag.SaveFirstUseRecord();
292     diag.firstUseMap_.clear();
293     diag.LoadFirstUseRecord();
294     EXPECT_EQ(0, static_cast<int32_t>(diag.firstUseMap_.size()));
295     std::string cmdline1 = "rm " + SEC_COMP_SRV_CFG_PATH +  " && mkdir " +
296         SEC_COMP_SRV_CFG_PATH + " 0750 security_component security_component";
297     system(cmdline1.c_str());
298 }
299 
300 /**
301  * @tc.name: SaveFirstUseRecord003
302  * @tc.desc: Test cfg file is not exist, tokenid is invalid.
303  * @tc.type: FUNC
304  * @tc.require:
305  */
306 HWTEST_F(FirstUseDialogTest, SaveFirstUseRecord003, TestSize.Level0)
307 {
308     FirstUseDialog diag;
309     OHOS::Security::AccessToken::AccessTokenKit::getHapTokenInfoRes = -1;
310     diag.firstUseMap_[1] = 1;
311     diag.SaveFirstUseRecord();
312     diag.firstUseMap_.clear();
313     diag.LoadFirstUseRecord();
314     EXPECT_EQ(0, static_cast<int32_t>(diag.firstUseMap_.size()));
315     OHOS::Security::AccessToken::AccessTokenKit::getHapTokenInfoRes = 0;
316 }
317 
318 /**
319  * @tc.name: SaveFirstUseRecord004
320  * @tc.desc: Test cfg file is exist, save ok
321  * @tc.type: FUNC
322  * @tc.require:
323  */
324 HWTEST_F(FirstUseDialogTest, SaveFirstUseRecord004, TestSize.Level0)
325 {
326     FirstUseDialog diag;
327     diag.firstUseMap_[1] = 1;
328     diag.SaveFirstUseRecord();
329     diag.firstUseMap_.clear();
330     diag.LoadFirstUseRecord();
331     EXPECT_EQ(1, static_cast<int32_t>(diag.firstUseMap_.size()));
332     EXPECT_EQ(1, static_cast<int32_t>(diag.firstUseMap_[1]));
333 }
334 
335 class TestRemoteObject : public IRemoteObject {
336 public:
TestRemoteObject(std::u16string descriptor)337     explicit TestRemoteObject(std::u16string descriptor) : IRemoteObject(descriptor)
338     {
339     };
340 
341     ~TestRemoteObject() = default;
342 
IsProxyObject() const343     bool IsProxyObject() const override
344     {
345         return false;
346     };
347 
GetObjectRefCount()348     int32_t GetObjectRefCount() override
349     {
350         return 0;
351     };
352 
Dump(int fd,const std::vector<std::u16string> & args)353     int Dump(int fd, const std::vector<std::u16string>& args) override
354     {
355         return 0;
356     };
357 
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)358     int SendRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override
359     {
360         return -1;
361     };
362 
AddDeathRecipient(const sptr<DeathRecipient> & recipient)363     bool AddDeathRecipient(const sptr<DeathRecipient>& recipient) override
364     {
365         return false;
366     };
367 
RemoveDeathRecipient(const sptr<DeathRecipient> & recipient)368     bool RemoveDeathRecipient(const sptr<DeathRecipient>& recipient) override
369     {
370         return false;
371     };
372 };
373 
374 /*
375  * @tc.name: SetFirstUseMap001
376  * @tc.desc: Test SetFirstUseMap
377  * @tc.type: FUNC
378  * @tc.require:
379  */
380 HWTEST_F(FirstUseDialogTest, SetFirstUseMap001, TestSize.Level0)
381 {
382     FirstUseDialog diag;
383     std::shared_ptr<SecCompEntity> entity = std::make_shared<SecCompEntity>(nullptr, 0, 0, 0, 0);
384 
385     std::shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create(true);
386     ASSERT_NE(nullptr, runner);
387     std::shared_ptr<SecEventHandler> handler = std::make_shared<SecEventHandler>(runner);
388     diag.secHandler_ = handler;
389 
390     // no entity
391     EXPECT_EQ(diag.SetFirstUseMap(nullptr), false);
392 
393     // type invalid
394     EXPECT_EQ(diag.SetFirstUseMap(entity), false);
395 
396     // first use location button
397     entity->componentInfo_ = std::make_shared<LocationButton>();
398     entity->componentInfo_->type_ = LOCATION_COMPONENT;
399     entity->tokenId_ = 0;
400     EXPECT_EQ(diag.SetFirstUseMap(entity), true);
401     EXPECT_NE(LOCATION_BUTTON_FIRST_USE, static_cast<uint64_t>(diag.firstUseMap_[0]));
402 
403     // first use save button
404     entity->componentInfo_->type_ = SAVE_COMPONENT;
405     EXPECT_EQ(diag.SetFirstUseMap(entity), true);
406     EXPECT_EQ(SAVE_BUTTON_FIRST_USE, static_cast<uint64_t>(diag.firstUseMap_[0]));
407 
408     // second use save button
409     EXPECT_EQ(diag.SetFirstUseMap(entity), true);
410     EXPECT_EQ(SAVE_BUTTON_FIRST_USE, static_cast<uint64_t>(diag.firstUseMap_[0]));
411 
412     // wait for event handler done
413     sleep(3);
414 }
415 
416 /*
417  * @tc.name: NotifyFirstUseDialog001
418  * @tc.desc: Test NotifyFirstUseDialog
419  * @tc.type: FUNC
420  * @tc.require:
421  */
422 HWTEST_F(FirstUseDialogTest, NotifyFirstUseDialog001, TestSize.Level0)
423 {
424     FirstUseDialog diag;
425     diag.secHandler_ = nullptr;
426 
427     const FirstUseDialog::DisplayInfo displayInfo = {0, CrossAxisState::STATE_INVALID, 0};
428 
429     // no entity
430     EXPECT_EQ(diag.NotifyFirstUseDialog(nullptr, nullptr, nullptr, displayInfo),
431         SC_SERVICE_ERROR_VALUE_INVALID);
432 
433     std::shared_ptr<SecCompEntity> entity = std::make_shared<SecCompEntity>(nullptr, 0, 0, 0, 0);
434     // no handler
435     EXPECT_EQ(diag.NotifyFirstUseDialog(entity, nullptr, nullptr, displayInfo),
436         SC_SERVICE_ERROR_VALUE_INVALID);
437 
438     // no calltoken
439     std::shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create(true);
440     ASSERT_NE(nullptr, runner);
441     std::shared_ptr<SecEventHandler> handler = std::make_shared<SecEventHandler>(runner);
442     diag.secHandler_ = handler;
443     EXPECT_EQ(diag.NotifyFirstUseDialog(entity, nullptr, nullptr, displayInfo),
444         SC_SERVICE_ERROR_VALUE_INVALID);
445 
446     // no dialogCallback
447     sptr<TestRemoteObject> testRemoteObject = new TestRemoteObject(std::u16string());
448     EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, nullptr, displayInfo),
449         SC_SERVICE_ERROR_VALUE_INVALID);
450 
451     // type invalid
452     EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject, displayInfo),
453         SC_OK);
454 
455     // first use location button
456     entity->componentInfo_ = std::make_shared<LocationButton>();
457     entity->componentInfo_->type_ = LOCATION_COMPONENT;
458     entity->tokenId_ = 0;
459     EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject, displayInfo),
460         SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE);
461     EXPECT_EQ(0, static_cast<uint64_t>(diag.firstUseMap_[0]));
462 
463     diag.firstUseMap_[0] = LOCATION_BUTTON_FIRST_USE;
464     EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject, displayInfo),
465         SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE);
466 
467     diag.firstUseMap_[0] = SAVE_BUTTON_FIRST_USE;
468     EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject, displayInfo),
469         SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE);
470 
471     // first use save button
472     diag.firstUseMap_[0] = 0;
473     entity->componentInfo_ = std::make_shared<SaveButton>();
474     entity->componentInfo_->type_ = SAVE_COMPONENT;
475     EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject, displayInfo),
476         SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE);
477     EXPECT_EQ(0, static_cast<uint64_t>(diag.firstUseMap_[0]));
478 
479     // second use save button
480     EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject, displayInfo),
481         SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE);
482     EXPECT_EQ(0, static_cast<uint64_t>(diag.firstUseMap_[0]));
483 
484     diag.firstUseMap_[0] = SAVE_BUTTON_FIRST_USE;
485     EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject, displayInfo), SC_OK);
486 
487     diag.firstUseMap_[0] = LOCATION_BUTTON_FIRST_USE;
488     EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject, displayInfo),
489         SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE);
490 
491     diag.StartDialogAbility(entity, testRemoteObject, testRemoteObject, displayInfo);
492 
493     // wait for event handler done
494     sleep(3);
495 }
496 
497 /*
498  * @tc.name: NotifyFirstUseDialog002
499  * @tc.desc: Test NotifyFirstUseDialog
500  * @tc.type: FUNC
501  * @tc.require:
502  */
503 HWTEST_F(FirstUseDialogTest, NotifyFirstUseDialog002, TestSize.Level0)
504 {
505     FirstUseDialog diag;
506     diag.secHandler_ = nullptr;
507 
508     const FirstUseDialog::DisplayInfo displayInfo = {0, CrossAxisState::STATE_INVALID, 0};
509 
510     // entity
511     std::shared_ptr<SecCompEntity> entity = std::make_shared<SecCompEntity>(nullptr, 0, 0, 0, 0);
512     std::shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create(true);
513     ASSERT_NE(nullptr, runner);
514     // handler
515     std::shared_ptr<SecEventHandler> handler = std::make_shared<SecEventHandler>(runner);
516     diag.secHandler_ = handler;
517 
518     sptr<TestRemoteObject> testRemoteObject = new TestRemoteObject(std::u16string());
519     // first use save button
520     entity->componentInfo_ = std::make_shared<SaveButton>();
521     entity->componentInfo_->type_ = SAVE_COMPONENT;
522     entity->tokenId_ = 0;
523     EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject, displayInfo),
524         SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE);
525     EXPECT_EQ(0, static_cast<uint64_t>(diag.firstUseMap_[0]));
526 
527     // second use save button
528     EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject, displayInfo),
529         SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE);
530     EXPECT_EQ(0, static_cast<uint64_t>(diag.firstUseMap_[0]));
531 
532     entity->isCustomAuthorized_ = true;
533     std::string message = "message";
534     EXPECT_EQ(true, entity->AllowToBypassSecurityCheck(message));
535     diag.StartToastAbility(entity, testRemoteObject, displayInfo);
536 
537     // wait for event handler done
538     sleep(3);
539 }
540 
541 /*
542  * @tc.name: GrantDialogWaitEntity001
543  * @tc.desc: Test GrantDialogWaitEntity
544  * @tc.type: FUNC
545  * @tc.require:
546  */
547 HWTEST_F(FirstUseDialogTest, GrantDialogWaitEntity001, TestSize.Level0)
548 {
549     FirstUseDialog diag;
550     EXPECT_EQ(diag.GrantDialogWaitEntity(0), SC_SERVICE_ERROR_COMPONENT_NOT_EXIST);
551 
552     diag.dialogWaitMap_[0] = nullptr;
553     EXPECT_EQ(diag.GrantDialogWaitEntity(0), SC_SERVICE_ERROR_COMPONENT_NOT_EXIST);
554 
555     std::shared_ptr<SecCompEntity> entity = std::make_shared<SecCompEntity>(nullptr, 1, 0, 0, 0);
556     diag.dialogWaitMap_[0] = entity;
557     EXPECT_EQ(diag.GrantDialogWaitEntity(0), SC_SERVICE_ERROR_PERMISSION_OPER_FAIL);
558 
559     std::shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create(true);
560     ASSERT_NE(runner, nullptr);
561 
562     std::shared_ptr<SecEventHandler> handler = std::make_shared<SecEventHandler>(runner);
563     SecCompPermManager::GetInstance().InitEventHandler(handler);
564     entity->componentInfo_ = std::make_shared<SaveButton>();
565     entity->componentInfo_->type_ = SAVE_COMPONENT;
566     diag.dialogWaitMap_[1] = entity;
567     EXPECT_EQ(diag.GrantDialogWaitEntity(1), SC_OK);
568 }
569 
570 /*
571  * @tc.name: RemoveDialogWaitEntitys001
572  * @tc.desc: Test RemoveDialogWaitEntitys
573  * @tc.type: FUNC
574  * @tc.require:
575  */
576 HWTEST_F(FirstUseDialogTest, RemoveDialogWaitEntitys001, TestSize.Level0)
577 {
578     FirstUseDialog diag;
579     std::shared_ptr<SecCompEntity> entity = std::make_shared<SecCompEntity>(nullptr, 0, 0, 0, 0);
580     std::shared_ptr<SecCompEntity> entity1 = std::make_shared<SecCompEntity>(nullptr, 0, 0, 1, 0);
581     diag.dialogWaitMap_[0] = entity;
582     diag.dialogWaitMap_[1] = entity1;
583     diag.RemoveDialogWaitEntitys(1);
584     EXPECT_EQ(diag.dialogWaitMap_.count(1), 0);
585 }
586 
587 /*
588  * @tc.name: SecCompDialogSrvCallback001
589  * @tc.desc: Test SecCompDialogSrvCallback
590  * @tc.type: FUNC
591  * @tc.require:
592  */
593 HWTEST_F(FirstUseDialogTest, SecCompDialogSrvCallback001, TestSize.Level0)
594 {
595     SecCompDialogSrvCallback *call = new (std::nothrow)SecCompDialogSrvCallback(0, nullptr, nullptr);
596     sptr<SecCompDialogSrvCallback> srvCallback = call;
597 
598     MessageParcel data;
599     MessageParcel reply;
600     MessageOption option;
601     EXPECT_EQ(srvCallback->OnRemoteRequest(ISecCompDialogCallback::ON_DIALOG_CLOSED, data, reply, option),
602         SC_SERVICE_ERROR_IPC_REQUEST_FAIL);
603 
604     data.WriteInterfaceToken(ISecCompDialogCallback::GetDescriptor());
605     EXPECT_EQ(srvCallback->OnRemoteRequest(ISecCompDialogCallback::ON_DIALOG_CLOSED, data, reply, option),
606         SC_SERVICE_ERROR_IPC_REQUEST_FAIL);
607 
608     MessageParcel data1;
609     data1.WriteInterfaceToken(ISecCompDialogCallback::GetDescriptor());
610     data1.WriteInt32(0);
611     EXPECT_EQ(srvCallback->OnRemoteRequest(ISecCompDialogCallback::ON_DIALOG_CLOSED, data1, reply, option),
612         0);
613 
614     MessageParcel data2;
615     data2.WriteInterfaceToken(ISecCompDialogCallback::GetDescriptor());
616     EXPECT_NE(srvCallback->OnRemoteRequest(-1, data2, reply, option), 0);
617 }
618