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 
16 #include <fstream>
17 #include <future>
18 #include <gtest/gtest.h>
19 
20 #include "account_info.h"
21 #include "app_log_wrapper.h"
22 #include "bundle_constants.h"
23 #include "bundle_installer_interface.h"
24 #include "bundle_mgr_interface.h"
25 #include "common_event_manager.h"
26 #include "common_event_support.h"
27 #include "common_tool.h"
28 #include "iservice_registry.h"
29 #include "os_account_manager.h"
30 #include "system_ability_definition.h"
31 #include "status_receiver_host.h"
32 
33 using namespace testing::ext;
34 using namespace std::chrono_literals;
35 namespace {
36 const std::string THIRD_BUNDLE_PATH = "/data/test/bms_bundle/";
37 const std::string BUNDLE_NAME = "com.example.internalOverlayTest1";
38 const std::string TEST_BUNDLE_HAPA = "entry_hap.hap";
39 const std::string TEST_BUNDLE_HAPB = "entry_hapB.hap";
40 const std::string HIGHER_VERSION_CODE_TEST_BUNDLE_HAPA = "higher_version_entry_hap.hap";
41 const std::string HIGHER_VERSION_CODE_TEST_BUNDLE_HAPB = "higher_version_entry_hapB.hap";
42 const std::string LOWER_VERSION_CODE_TEST_BUNDLE_HAPA = "lower_versionCode_entry_hap.hap";
43 const std::string LOWER_VERSION_CODE_TEST_BUNDLE_HAPB = "lower_versionCode_entry_hapB.hap";
44 const int TIMEOUT = 10;
45 const int32_t WAIT_TIME = 3; // for creating or removing new user
46 const int32_t USERID = 100;
47 const std::string STRING_TEST_NAME = "test_account_name";
48 }  // namespace
49 
50 namespace OHOS {
51 namespace AppExecFwk {
52 using namespace OHOS::EventFwk;
53 using namespace AccountSA;
54 class StatusReceiverImpl : public StatusReceiverHost {
55 public:
56     StatusReceiverImpl();
57     virtual ~StatusReceiverImpl() override;
58     virtual void OnStatusNotify(const int progress) override;
59     virtual void OnFinished(const int32_t resultCode, const std::string &resultMsg) override;
60     int32_t GetResultCode() const;
61 
62 private:
63     mutable std::promise<int32_t> resultCodeSignal_;
64 
65     DISALLOW_COPY_AND_MOVE(StatusReceiverImpl);
66 };
67 
StatusReceiverImpl()68 StatusReceiverImpl::StatusReceiverImpl()
69 {
70     APP_LOGI("create status receiver instance");
71 }
72 
~StatusReceiverImpl()73 StatusReceiverImpl::~StatusReceiverImpl()
74 {
75     APP_LOGI("destroy status receiver instance");
76 }
77 
OnStatusNotify(const int progress)78 void StatusReceiverImpl::OnStatusNotify(const int progress)
79 {}
80 
OnFinished(const int32_t resultCode,const std::string & resultMsg)81 void StatusReceiverImpl::OnFinished(const int32_t resultCode, const std::string &resultMsg)
82 {
83     APP_LOGD("on finished result is %{public}d, %{public}s", resultCode, resultMsg.c_str());
84     resultCodeSignal_.set_value(resultCode);
85 }
86 
GetResultCode() const87 int32_t StatusReceiverImpl::GetResultCode() const
88 {
89     auto future = resultCodeSignal_.get_future();
90     std::chrono::seconds timeout(TIMEOUT);
91     if (future.wait_for(timeout) == std::future_status::timeout) {
92         return ERR_APPEXECFWK_OPERATION_TIME_OUT;
93     }
94 
95     return future.get();
96 }
97 
98 class BmsInstallMultiUserTest : public testing::Test {
99 public:
100     static void SetUpTestCase();
101     static void TearDownTestCase();
102     void SetUp();
103     void TearDown();
104     static ErrCode InstallBundle(const std::vector<std::string> &bundleFilePaths, int32_t userId);
105     static void UninstallBundle(const std::string &bundleName, int32_t userId);
106     bool CheckFilePath(const std::string &checkFilePath) const;
107     void CheckFileNonExist(const std::string &bundleName) const;
108     static sptr<IBundleMgr> GetBundleMgrProxy();
109     static sptr<IBundleInstaller> GetInstallerProxy();
110     static int32_t CreateNewUser();
111     static void RemoveUser(int32_t userId);
112 
113     static int32_t newUserId_;
114 };
115 
SetUpTestCase()116 void BmsInstallMultiUserTest::SetUpTestCase()
117 {
118     newUserId_ = CreateNewUser();
119     EXPECT_NE(newUserId_, 0);
120 }
121 
TearDownTestCase()122 void BmsInstallMultiUserTest::TearDownTestCase()
123 {
124     RemoveUser(newUserId_);
125 }
126 
SetUp()127 void BmsInstallMultiUserTest::SetUp()
128 {}
129 
TearDown()130 void BmsInstallMultiUserTest::TearDown()
131 {}
132 
GetBundleMgrProxy()133 sptr<IBundleMgr> BmsInstallMultiUserTest::GetBundleMgrProxy()
134 {
135     sptr<ISystemAbilityManager> systemAbilityManager =
136         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
137     if (!systemAbilityManager) {
138         APP_LOGE("fail to get system ability mgr.");
139         return nullptr;
140     }
141 
142     sptr<IRemoteObject> remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
143     if (!remoteObject) {
144         APP_LOGE("fail to get bundle manager proxy.");
145         return nullptr;
146     }
147 
148     APP_LOGI("get bundle manager proxy success.");
149     return iface_cast<IBundleMgr>(remoteObject);
150 }
151 
GetInstallerProxy()152 sptr<IBundleInstaller> BmsInstallMultiUserTest::GetInstallerProxy()
153 {
154     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
155     if (!bundleMgrProxy) {
156         APP_LOGE("bundle mgr proxy is nullptr.");
157         return nullptr;
158     }
159 
160     sptr<IBundleInstaller> installerProxy = bundleMgrProxy->GetBundleInstaller();
161     if (!installerProxy) {
162         APP_LOGE("fail to get bundle installer proxy");
163         return nullptr;
164     }
165 
166     APP_LOGI("get bundle installer proxy success.");
167     return installerProxy;
168 }
169 
InstallBundle(const std::vector<std::string> & bundleFilePaths,int32_t userId)170 ErrCode BmsInstallMultiUserTest::InstallBundle(const std::vector<std::string> &bundleFilePaths, int32_t userId)
171 {
172     sptr<IBundleInstaller> installerProxy = GetInstallerProxy();
173     if (!installerProxy) {
174         APP_LOGE("get bundle installer Failure.");
175         return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR;
176     }
177 
178     InstallParam installParam;
179     installParam.userId = userId;
180     installParam.installFlag = InstallFlag::REPLACE_EXISTING;
181     sptr<StatusReceiverImpl> statusReceiver(new (std::nothrow) StatusReceiverImpl());
182     EXPECT_NE(statusReceiver, nullptr);
183     auto ret = installerProxy->StreamInstall(bundleFilePaths, installParam, statusReceiver);
184     if (ret == ERR_OK) {
185         ret = statusReceiver->GetResultCode();
186     }
187     return ret;
188 }
189 
UninstallBundle(const std::string & bundleName,int32_t userId)190 void BmsInstallMultiUserTest::UninstallBundle(const std::string &bundleName, int32_t userId)
191 {
192     sptr<IBundleInstaller> installerProxy = GetInstallerProxy();
193     if (!installerProxy) {
194         APP_LOGE("get bundle installer Failure.");
195         return;
196     }
197 
198     sptr<StatusReceiverImpl> statusReceiver(new (std::nothrow) StatusReceiverImpl());
199     EXPECT_NE(statusReceiver, nullptr);
200     InstallParam installParam;
201     installParam.userId = userId;
202 
203     bool uninstallResult = installerProxy->Uninstall(bundleName, installParam, statusReceiver);
204     EXPECT_TRUE(uninstallResult);
205     auto res = statusReceiver->GetResultCode();
206     EXPECT_EQ(res, ERR_OK);
207 }
208 
CreateNewUser()209 int32_t BmsInstallMultiUserTest::CreateNewUser()
210 {
211     if (newUserId_ != 0) {
212         return newUserId_;
213     }
214     OsAccountInfo osAccountInfo;
215     auto res = OsAccountManager::CreateOsAccount(STRING_TEST_NAME, OsAccountType::NORMAL, osAccountInfo);
216     std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME));
217     EXPECT_EQ(res, ERR_OK);
218     return osAccountInfo.GetLocalId();
219 }
220 
RemoveUser(int32_t userId)221 void BmsInstallMultiUserTest::RemoveUser(int32_t userId)
222 {
223     ErrCode ret = OsAccountManager::RemoveOsAccount(userId);
224     std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME));
225     EXPECT_EQ(ret, ERR_OK);
226 }
227 
228 int32_t BmsInstallMultiUserTest::newUserId_ = 0;
229 
230 /**
231  * @tc.number: BMS_Install_multi_user_0100
232  * @tc.name:  test the installation of a third-party bundle for multi users
233  * @tc.desc: 1.install hapA under user 100 successfully
234  *           2.create user 101 successfully
235  *           3.install the higher version-code hapA under the user 101 successfully
236  *           4.query bundleInfo under user 100 and 101 successfully
237  */
238 HWTEST_F(BmsInstallMultiUserTest, BMS_Install_multi_user_0100, Function | MediumTest | Level1)
239 {
240     std::cout << "START BMS_Install_multi_user_0100" << std::endl;
241     std::vector<std::string> bundleFilePaths = { THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPA };
242     auto res = InstallBundle(bundleFilePaths, USERID);
243     EXPECT_EQ(res, ERR_OK);
244 
245     int32_t userId = CreateNewUser();
246     EXPECT_NE(userId, 0);
247 
248     bundleFilePaths.clear();
249     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + HIGHER_VERSION_CODE_TEST_BUNDLE_HAPA);
250     res = InstallBundle(bundleFilePaths, newUserId_);
251     EXPECT_EQ(res, ERR_OK);
252 
253     auto bmsProxy = GetBundleMgrProxy();
254     EXPECT_NE(bmsProxy, nullptr);
255 
256     // query bundleInfo under two users respectively
257     BundleInfo bundleInfo1;
258     bool ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo1, USERID);
259     EXPECT_TRUE(ret);
260 
261     BundleInfo bundleInfo2;
262     ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo2, userId);
263     EXPECT_TRUE(ret);
264 
265     UninstallBundle(BUNDLE_NAME, Constants::ALL_USERID);
266     std::cout << "END BMS_Install_multi_user_0100" << std::endl;
267 }
268 
269 /**
270  * @tc.number: BMS_Install_multi_user_0200
271  * @tc.name:  test the installation of a third-party bundle for multi users
272  * @tc.desc: 1.install hapA under user 100 successfully
273  *           2.create user 101 successfully
274  *           3.install the lower version-code hapA under the user 101 failed
275  *           4.query bundleInfo under user 100 and 101 successfully
276  */
277 HWTEST_F(BmsInstallMultiUserTest, BMS_Install_multi_user_0200, Function | MediumTest | Level1)
278 {
279     std::cout << "START BMS_Install_multi_user_0200" << std::endl;
280     std::vector<std::string> bundleFilePaths = { THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPA };
281     auto res = InstallBundle(bundleFilePaths, USERID);
282     EXPECT_EQ(res, ERR_OK);
283 
284     int32_t userId = CreateNewUser();
285     EXPECT_NE(userId, 0);
286 
287     bundleFilePaths.clear();
288     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + LOWER_VERSION_CODE_TEST_BUNDLE_HAPA);
289     res = InstallBundle(bundleFilePaths, userId);
290     EXPECT_EQ(res, IStatusReceiver::ERR_INSTALL_VERSION_DOWNGRADE);
291 
292     auto bmsProxy = GetBundleMgrProxy();
293     EXPECT_NE(bmsProxy, nullptr);
294 
295     // query bundleInfo under two users respectively
296     BundleInfo bundleInfo1;
297     bool ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo1, USERID);
298     EXPECT_TRUE(ret);
299 
300     BundleInfo bundleInfo2;
301     ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo2, userId);
302     EXPECT_FALSE(ret);
303 
304     UninstallBundle(BUNDLE_NAME, Constants::ALL_USERID);
305     std::cout << "END BMS_Install_multi_user_0200" << std::endl;
306 }
307 
308 /**
309  * @tc.number: BMS_Install_multi_user_0300
310  * @tc.name:  test the installation of a third-party bundle for multi users
311  * @tc.desc: 1.install hapA under user 100 successfully
312  *           2.create user 101 successfully
313  *           3.install the same version-code hapA under the user 101 successfully
314  *           4.query bundleInfo under user 100 and 101 successfully
315  */
316 HWTEST_F(BmsInstallMultiUserTest, BMS_Install_multi_user_0300, Function | MediumTest | Level1)
317 {
318     std::cout << "START BMS_Install_multi_user_0300" << std::endl;
319     std::vector<std::string> bundleFilePaths = { THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPA };
320     auto res = InstallBundle(bundleFilePaths, USERID);
321     EXPECT_EQ(res, ERR_OK);
322 
323     int32_t userId = CreateNewUser();
324     EXPECT_NE(userId, 0);
325 
326     bundleFilePaths.clear();
327     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPA);
328     res = InstallBundle(bundleFilePaths, userId);
329     EXPECT_EQ(res, ERR_OK);
330 
331     auto bmsProxy = GetBundleMgrProxy();
332     EXPECT_NE(bmsProxy, nullptr);
333 
334     // query bundleInfo under two users respectively
335     BundleInfo bundleInfo1;
336     bool ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo1, USERID);
337     EXPECT_TRUE(ret);
338 
339     BundleInfo bundleInfo2;
340     ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo2, userId);
341     EXPECT_TRUE(ret);
342 
343     UninstallBundle(BUNDLE_NAME, Constants::ALL_USERID);
344     std::cout << "END BMS_Install_multi_user_0300" << std::endl;
345 }
346 
347 /**
348  * @tc.number: BMS_Install_multi_user_0400
349  * @tc.name:  test the installation of a third-party bundle for multi users
350  * @tc.desc: 1.install hapA under user 100 successfully
351  *           2.create user 101 successfully
352  *           3.install the higher version-code hapB under the user 101 successfully
353  *           4.query bundleInfo under user 100 and 101 successfully
354  */
355 HWTEST_F(BmsInstallMultiUserTest, BMS_Install_multi_user_0400, Function | MediumTest | Level1)
356 {
357     std::cout << "START BMS_Install_multi_user_0400" << std::endl;
358     std::vector<std::string> bundleFilePaths = { THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPA };
359     auto res = InstallBundle(bundleFilePaths, USERID);
360     EXPECT_EQ(res, ERR_OK);
361 
362     int32_t userId = CreateNewUser();
363     EXPECT_NE(userId, 0);
364 
365     bundleFilePaths.clear();
366     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + HIGHER_VERSION_CODE_TEST_BUNDLE_HAPB);
367     res = InstallBundle(bundleFilePaths, userId);
368     EXPECT_EQ(res, IStatusReceiver::ERR_INSTALL_VERSION_NOT_COMPATIBLE);
369 
370     auto bmsProxy = GetBundleMgrProxy();
371     EXPECT_NE(bmsProxy, nullptr);
372 
373     // query bundleInfo under two users respectively
374     BundleInfo bundleInfo1;
375     bool ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo1, USERID);
376     EXPECT_TRUE(ret);
377 
378     BundleInfo bundleInfo2;
379     ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo2, userId);
380     EXPECT_FALSE(ret);
381 
382     UninstallBundle(BUNDLE_NAME, Constants::ALL_USERID);
383     std::cout << "END BMS_Install_multi_user_0400" << std::endl;
384 }
385 
386 /**
387  * @tc.number: BMS_Install_multi_user_0500
388  * @tc.name:  test the installation of a third-party bundle for multi users
389  * @tc.desc: 1.install hapA under user 100 successfully
390  *           2.create user 101 successfully
391  *           3.install the lower version-code hapB under the user 101 failed
392  *           4.query bundleInfo under user 100 and 101 successfully
393  */
394 HWTEST_F(BmsInstallMultiUserTest, BMS_Install_multi_user_0500, Function | MediumTest | Level1)
395 {
396     std::cout << "START BMS_Install_multi_user_0500" << std::endl;
397     std::vector<std::string> bundleFilePaths = { THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPA };
398     auto res = InstallBundle(bundleFilePaths, USERID);
399     EXPECT_EQ(res, ERR_OK);
400 
401     int32_t userId = CreateNewUser();
402     EXPECT_NE(userId, 0);
403 
404     bundleFilePaths.clear();
405     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + LOWER_VERSION_CODE_TEST_BUNDLE_HAPB);
406     res = InstallBundle(bundleFilePaths, userId);
407     EXPECT_EQ(res, IStatusReceiver::ERR_INSTALL_VERSION_DOWNGRADE);
408 
409     auto bmsProxy = GetBundleMgrProxy();
410     EXPECT_NE(bmsProxy, nullptr);
411 
412     // query bundleInfo under two users respectively
413     BundleInfo bundleInfo1;
414     bool ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo1, USERID);
415     EXPECT_TRUE(ret);
416 
417     BundleInfo bundleInfo2;
418     ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo2, userId);
419     EXPECT_FALSE(ret);
420 
421     UninstallBundle(BUNDLE_NAME, Constants::ALL_USERID);
422     std::cout << "END BMS_Install_multi_user_0500" << std::endl;
423 }
424 
425 /**
426  * @tc.number: BMS_Install_multi_user_0600
427  * @tc.name:  test the installation of a third-party bundle for multi users
428  * @tc.desc: 1.install hapA under user 100 successfully
429  *           2.create user 101 successfully
430  *           3.install the same version-code hapB under the user 101 successfully
431  *           4.query bundleInfo under user 100 and 101 successfully
432  */
433 HWTEST_F(BmsInstallMultiUserTest, BMS_Install_multi_user_0600, Function | MediumTest | Level1)
434 {
435     std::cout << "START BMS_Install_multi_user_0600" << std::endl;
436     std::vector<std::string> bundleFilePaths = { THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPA };
437     auto res = InstallBundle(bundleFilePaths, USERID);
438     EXPECT_EQ(res, ERR_OK);
439 
440     int32_t userId = CreateNewUser();
441     EXPECT_NE(userId, 0);
442 
443     bundleFilePaths.clear();
444     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPB);
445     res = InstallBundle(bundleFilePaths, userId);
446     EXPECT_EQ(res, ERR_OK);
447 
448     auto bmsProxy = GetBundleMgrProxy();
449     EXPECT_NE(bmsProxy, nullptr);
450 
451     // query bundleInfo under two users respectively
452     BundleInfo bundleInfo1;
453     bool ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo1, USERID);
454     EXPECT_TRUE(ret);
455 
456     BundleInfo bundleInfo2;
457     ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo2, userId);
458     EXPECT_TRUE(ret);
459 
460     UninstallBundle(BUNDLE_NAME, Constants::ALL_USERID);
461     std::cout << "END BMS_Install_multi_user_0600" << std::endl;
462 }
463 
464 /**
465  * @tc.number: BMS_Install_multi_user_0700
466  * @tc.name:  test the installation of a third-party bundle for multi users
467  * @tc.desc: 1.install hapA under user 100 successfully
468  *           2.create user 101 successfully
469  *           3.install the higher version-code hapA and hapB under the user 101 successfully
470  *           4.query bundleInfo under user 100 and 101 successfully
471  */
472 HWTEST_F(BmsInstallMultiUserTest, BMS_Install_multi_user_0700, Function | MediumTest | Level1)
473 {
474     std::cout << "START BMS_Install_multi_user_0700" << std::endl;
475     std::vector<std::string> bundleFilePaths = { THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPA };
476     auto res = InstallBundle(bundleFilePaths, USERID);
477     EXPECT_EQ(res, ERR_OK);
478 
479     int32_t userId = CreateNewUser();
480     EXPECT_NE(userId, 0);
481 
482     bundleFilePaths.clear();
483     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + HIGHER_VERSION_CODE_TEST_BUNDLE_HAPA);
484     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + HIGHER_VERSION_CODE_TEST_BUNDLE_HAPB);
485     res = InstallBundle(bundleFilePaths, newUserId_);
486     EXPECT_EQ(res, ERR_OK);
487 
488     auto bmsProxy = GetBundleMgrProxy();
489     EXPECT_NE(bmsProxy, nullptr);
490 
491     // query bundleInfo under two users respectively
492     BundleInfo bundleInfo1;
493     bool ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo1, USERID);
494     EXPECT_TRUE(ret);
495 
496     BundleInfo bundleInfo2;
497     ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo2, userId);
498     EXPECT_TRUE(ret);
499 
500     UninstallBundle(BUNDLE_NAME, Constants::ALL_USERID);
501     std::cout << "END BMS_Install_multi_user_0700" << std::endl;
502 }
503 
504 /**
505  * @tc.number: BMS_Install_multi_user_0800
506  * @tc.name:  test the installation of a third-party bundle for multi users
507  * @tc.desc: 1.install hapA under user 100 successfully
508  *           2.create user 101 successfully
509  *           3.install the lower version-code hapA and hapB under the user 101 failed
510  *           4.query bundleInfo under user 100 and 101 successfully
511  */
512 HWTEST_F(BmsInstallMultiUserTest, BMS_Install_multi_user_0800, Function | MediumTest | Level1)
513 {
514     std::cout << "START BMS_Install_multi_user_0800" << std::endl;
515     std::vector<std::string> bundleFilePaths = { THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPA };
516     auto res = InstallBundle(bundleFilePaths, USERID);
517     EXPECT_EQ(res, ERR_OK);
518 
519     int32_t userId = CreateNewUser();
520     EXPECT_NE(userId, 0);
521 
522     bundleFilePaths.clear();
523     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + LOWER_VERSION_CODE_TEST_BUNDLE_HAPA);
524     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + LOWER_VERSION_CODE_TEST_BUNDLE_HAPB);
525     res = InstallBundle(bundleFilePaths, userId);
526     EXPECT_EQ(res, IStatusReceiver::ERR_INSTALL_VERSION_DOWNGRADE);
527 
528     auto bmsProxy = GetBundleMgrProxy();
529     EXPECT_NE(bmsProxy, nullptr);
530 
531     // query bundleInfo under two users respectively
532     BundleInfo bundleInfo1;
533     bool ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo1, USERID);
534     EXPECT_TRUE(ret);
535 
536     BundleInfo bundleInfo2;
537     ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo2, userId);
538     EXPECT_FALSE(ret);
539 
540     UninstallBundle(BUNDLE_NAME, Constants::ALL_USERID);
541     std::cout << "END BMS_Install_multi_user_0800" << std::endl;
542 }
543 
544 /**
545  * @tc.number: BMS_Install_multi_user_0900
546  * @tc.name:  test the installation of a third-party bundle for multi users
547  * @tc.desc: 1.install hapA under user 100 successfully
548  *           2.create user 101 successfully
549  *           3.install the same version-code hapA and hapB under the user 101 successfully
550  *           4.query bundleInfo under user 100 and 101 successfully
551  */
552 HWTEST_F(BmsInstallMultiUserTest, BMS_Install_multi_user_0900, Function | MediumTest | Level1)
553 {
554     std::cout << "START BMS_Install_multi_user_0900" << std::endl;
555     std::vector<std::string> bundleFilePaths = { THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPA };
556     auto res = InstallBundle(bundleFilePaths, USERID);
557     EXPECT_EQ(res, ERR_OK);
558 
559     int32_t userId = CreateNewUser();
560     EXPECT_NE(userId, 0);
561 
562     bundleFilePaths.clear();
563     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPA);
564     res = InstallBundle(bundleFilePaths, userId);
565     EXPECT_EQ(res, ERR_OK);
566 
567     auto bmsProxy = GetBundleMgrProxy();
568     EXPECT_NE(bmsProxy, nullptr);
569 
570     // query bundleInfo under two users respectively
571     BundleInfo bundleInfo1;
572     bool ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo1, USERID);
573     EXPECT_TRUE(ret);
574 
575     BundleInfo bundleInfo2;
576     ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo2, userId);
577     EXPECT_TRUE(ret);
578 
579     UninstallBundle(BUNDLE_NAME, Constants::ALL_USERID);
580     std::cout << "END BMS_Install_multi_user_0900" << std::endl;
581 }
582 
583 /**
584  * @tc.number: BMS_Install_multi_user_1000
585  * @tc.name:  test the installation of a third-party bundle for multi users
586  * @tc.desc: 1.not install hapA under user 100
587  *           2.create user 101 successfully
588  *           3.install the same version-code hapA under the user 101 successfully
589  *           4.query bundleInfo under user 101 successfully
590  */
591 HWTEST_F(BmsInstallMultiUserTest, BMS_Install_multi_user_1000, Function | MediumTest | Level1)
592 {
593     std::cout << "START BMS_Install_multi_user_1000" << std::endl;
594     int32_t userId = CreateNewUser();
595     EXPECT_NE(userId, 0);
596 
597     std::vector<std::string> bundleFilePaths = { THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPA };
598     auto res = InstallBundle(bundleFilePaths, userId);
599     EXPECT_EQ(res, ERR_OK);
600 
601     auto bmsProxy = GetBundleMgrProxy();
602     EXPECT_NE(bmsProxy, nullptr);
603 
604     // query bundleInfo under two users respectively
605     BundleInfo bundleInfo1;
606     bool ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo1, USERID);
607     EXPECT_FALSE(ret);
608 
609     BundleInfo bundleInfo2;
610     ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo2, userId);
611     EXPECT_TRUE(ret);
612 
613     UninstallBundle(BUNDLE_NAME, Constants::ALL_USERID);
614     std::cout << "END BMS_Install_multi_user_1000" << std::endl;
615 }
616 
617 /**
618  * @tc.number: BMS_Install_multi_user_1100
619  * @tc.name:  test the installation of a third-party bundle for multi users
620  * @tc.desc: 1.not install hapA under user 100
621  *           2.create user 101 successfully
622  *           3.install the same version-code hapA and hapB under the user 101 successfully
623  *           4.query bundleInfo under user 100 and 101 successfully
624  */
625 HWTEST_F(BmsInstallMultiUserTest, BMS_Install_multi_user_1100, Function | MediumTest | Level1)
626 {
627     std::cout << "START BMS_Install_multi_user_1100" << std::endl;
628     int32_t userId = CreateNewUser();
629     EXPECT_NE(userId, 0);
630 
631     std::vector<std::string> bundleFilePaths = { THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPA };
632     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPB);
633     auto res = InstallBundle(bundleFilePaths, userId);
634     EXPECT_EQ(res, ERR_OK);
635 
636     auto bmsProxy = GetBundleMgrProxy();
637     EXPECT_NE(bmsProxy, nullptr);
638 
639     // query bundleInfo under two users respectively
640     BundleInfo bundleInfo1;
641     bool ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo1, USERID);
642     EXPECT_FALSE(ret);
643 
644     BundleInfo bundleInfo2;
645     ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo2, userId);
646     EXPECT_TRUE(ret);
647 
648     UninstallBundle(BUNDLE_NAME, Constants::ALL_USERID);
649     std::cout << "END BMS_Install_multi_user_1100" << std::endl;
650 }
651 
652 /**
653  * @tc.number: BMS_Install_multi_user_1500
654  * @tc.name:  test the installation of a third-party bundle for multi users
655  * @tc.desc: 1.install hapA under user 100 successfully
656  *           2.create user 101 successfully
657  *           3.updata install the lower version-code hapA under the user ALL_USERID failed
658  *           4.query bundleInfo under user 100 and 101 successfully
659  */
660 HWTEST_F(BmsInstallMultiUserTest, BMS_Install_multi_user_1500, Function | MediumTest | Level1)
661 {
662     std::cout << "START BMS_Install_multi_user_1500" << std::endl;
663     std::vector<std::string> bundleFilePaths = { THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPA };
664     auto res = InstallBundle(bundleFilePaths, USERID);
665     EXPECT_EQ(res, ERR_OK);
666 
667     int32_t userId = CreateNewUser();
668     EXPECT_NE(userId, 0);
669 
670     bundleFilePaths.clear();
671     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + LOWER_VERSION_CODE_TEST_BUNDLE_HAPA);
672     res = InstallBundle(bundleFilePaths, Constants::ALL_USERID);
673     EXPECT_EQ(res, IStatusReceiver::ERR_INSTALL_VERSION_DOWNGRADE);
674 
675     auto bmsProxy = GetBundleMgrProxy();
676     EXPECT_NE(bmsProxy, nullptr);
677 
678     // query bundleInfo under two users respectively
679     BundleInfo bundleInfo1;
680     bool ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo1, USERID);
681     EXPECT_TRUE(ret);
682 
683     BundleInfo bundleInfo2;
684     ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo2, userId);
685     EXPECT_FALSE(ret);
686 
687     UninstallBundle(BUNDLE_NAME, Constants::ALL_USERID);
688     std::cout << "END BMS_Install_multi_user_1500" << std::endl;
689 }
690 
691 /**
692  * @tc.number: BMS_Install_multi_user_1700
693  * @tc.name:  test the installation of a third-party bundle for multi users
694  * @tc.desc: 1.install hapA under user 100 successfully
695  *           2.create user 101 successfully
696  *           3.updata install the higher version-code hapB under the user ALL_USERID successfully
697  *           4.query bundleInfo under user 100 and 101 successfully
698  */
699 HWTEST_F(BmsInstallMultiUserTest, BMS_Install_multi_user_1700, Function | MediumTest | Level1)
700 {
701     std::cout << "START BMS_Install_multi_user_1700" << std::endl;
702     std::vector<std::string> bundleFilePaths = { THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPA };
703     auto res = InstallBundle(bundleFilePaths, USERID);
704     EXPECT_EQ(res, ERR_OK);
705 
706     int32_t userId = CreateNewUser();
707     EXPECT_NE(userId, 0);
708 
709     bundleFilePaths.clear();
710     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + HIGHER_VERSION_CODE_TEST_BUNDLE_HAPB);
711     res = InstallBundle(bundleFilePaths, Constants::ALL_USERID);
712     EXPECT_EQ(res, IStatusReceiver::ERR_INSTALL_VERSION_NOT_COMPATIBLE);
713 
714     auto bmsProxy = GetBundleMgrProxy();
715     EXPECT_NE(bmsProxy, nullptr);
716 
717     // query bundleInfo under two users respectively
718     BundleInfo bundleInfo1;
719     bool ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo1, USERID);
720     EXPECT_TRUE(ret);
721 
722     BundleInfo bundleInfo2;
723     ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo2, userId);
724     EXPECT_FALSE(ret);
725 
726     UninstallBundle(BUNDLE_NAME, Constants::ALL_USERID);
727     std::cout << "END BMS_Install_multi_user_1700" << std::endl;
728 }
729 
730 /**
731  * @tc.number: BMS_Install_multi_user_1800
732  * @tc.name:  test the installation of a third-party bundle for multi users
733  * @tc.desc: 1.install hapA under user 100 successfully
734  *           2.create user 101 successfully
735  *           3.updata install the lower version-code hapB under the user ALL_USERID failed
736  *           4.query bundleInfo under user 100 and 101 successfully
737  */
738 HWTEST_F(BmsInstallMultiUserTest, BMS_Install_multi_user_1800, Function | MediumTest | Level1)
739 {
740     std::cout << "START BMS_Install_multi_user_1800" << std::endl;
741     std::vector<std::string> bundleFilePaths = { THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPA };
742     auto res = InstallBundle(bundleFilePaths, USERID);
743     EXPECT_EQ(res, ERR_OK);
744 
745     int32_t userId = CreateNewUser();
746     EXPECT_NE(userId, 0);
747 
748     bundleFilePaths.clear();
749     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + LOWER_VERSION_CODE_TEST_BUNDLE_HAPB);
750     res = InstallBundle(bundleFilePaths, Constants::ALL_USERID);
751     EXPECT_EQ(res, IStatusReceiver::ERR_INSTALL_VERSION_DOWNGRADE);
752 
753     auto bmsProxy = GetBundleMgrProxy();
754     EXPECT_NE(bmsProxy, nullptr);
755 
756     // query bundleInfo under two users respectively
757     BundleInfo bundleInfo1;
758     bool ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo1, USERID);
759     EXPECT_TRUE(ret);
760 
761     BundleInfo bundleInfo2;
762     ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo2, userId);
763     EXPECT_FALSE(ret);
764 
765     UninstallBundle(BUNDLE_NAME, Constants::ALL_USERID);
766     std::cout << "END BMS_Install_multi_user_1800" << std::endl;
767 }
768 
769 /**
770  * @tc.number: BMS_Install_multi_user_2000
771  * @tc.name:  test the installation of a third-party bundle for multi users
772  * @tc.desc: 1.install hapA and hapB under user 100 successfully
773  *           2.create user 101 successfully
774  *           3.updata install the higher version-code hapA under the user ALL_USERID successfully
775  *           4.query bundleInfo under user 100 and 101 successfully
776  */
777 HWTEST_F(BmsInstallMultiUserTest, BMS_Install_multi_user_2000, Function | MediumTest | Level1)
778 {
779     std::cout << "START BMS_Install_multi_user_2000" << std::endl;
780     std::vector<std::string> bundleFilePaths = { THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPA };
781     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPB);
782     auto res = InstallBundle(bundleFilePaths, USERID);
783     EXPECT_EQ(res, ERR_OK);
784 
785     int32_t userId = CreateNewUser();
786     EXPECT_NE(userId, 0);
787 
788     bundleFilePaths.clear();
789     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + HIGHER_VERSION_CODE_TEST_BUNDLE_HAPA);
790     res = InstallBundle(bundleFilePaths, newUserId_);
791     EXPECT_EQ(res, ERR_OK);
792 
793     auto bmsProxy = GetBundleMgrProxy();
794     EXPECT_NE(bmsProxy, nullptr);
795 
796     // query bundleInfo under two users respectively
797     BundleInfo bundleInfo1;
798     bool ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo1, USERID);
799     EXPECT_TRUE(ret);
800 
801     BundleInfo bundleInfo2;
802     ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo2, userId);
803     EXPECT_TRUE(ret);
804 
805     UninstallBundle(BUNDLE_NAME, Constants::ALL_USERID);
806     std::cout << "END BMS_Install_multi_user_2000" << std::endl;
807 }
808 
809 /**
810  * @tc.number: BMS_Install_multi_user_2100
811  * @tc.name:  test the installation of a third-party bundle for multi users
812  * @tc.desc: 1.install hapA and hapB under user 100 successfully
813  *           2.create user 101 successfully
814  *           3.updata install the lower version-code hapA under the user ALL_USERID failed
815  *           4.query bundleInfo under user 100 and 101 successfully
816  */
817 HWTEST_F(BmsInstallMultiUserTest, BMS_Install_multi_user_2100, Function | MediumTest | Level1)
818 {
819     std::cout << "START BMS_Install_multi_user_2100" << std::endl;
820     std::vector<std::string> bundleFilePaths = { THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPA };
821     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPB);
822     auto res = InstallBundle(bundleFilePaths, USERID);
823     EXPECT_EQ(res, ERR_OK);
824 
825     int32_t userId = CreateNewUser();
826     EXPECT_NE(userId, 0);
827 
828     bundleFilePaths.clear();
829     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + LOWER_VERSION_CODE_TEST_BUNDLE_HAPA);
830     res = InstallBundle(bundleFilePaths, userId);
831     EXPECT_EQ(res, IStatusReceiver::ERR_INSTALL_VERSION_DOWNGRADE);
832 
833     auto bmsProxy = GetBundleMgrProxy();
834     EXPECT_NE(bmsProxy, nullptr);
835 
836     // query bundleInfo under two users respectively
837     BundleInfo bundleInfo1;
838     bool ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo1, USERID);
839     EXPECT_TRUE(ret);
840 
841     BundleInfo bundleInfo2;
842     ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo2, userId);
843     EXPECT_FALSE(ret);
844 
845     UninstallBundle(BUNDLE_NAME, Constants::ALL_USERID);
846     std::cout << "END BMS_Install_multi_user_2100" << std::endl;
847 }
848 
849 /**
850  * @tc.number: BMS_Install_multi_user_2200
851  * @tc.name:  test the installation of a third-party bundle for multi users
852  * @tc.desc: 1.install hapA and hapB under user 100 successfully
853  *           2.create user 101 successfully
854  *           3.updata install the same version-code hapA under the user ALL_USERID successfully
855  *           4.query bundleInfo under user 100 and 101 successfully
856  */
857 HWTEST_F(BmsInstallMultiUserTest, BMS_Install_multi_user_2200, Function | MediumTest | Level1)
858 {
859     std::cout << "START BMS_Install_multi_user_2200" << std::endl;
860     std::vector<std::string> bundleFilePaths = { THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPA };
861     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPB);
862     auto res = InstallBundle(bundleFilePaths, USERID);
863     EXPECT_EQ(res, ERR_OK);
864 
865     int32_t userId = CreateNewUser();
866     EXPECT_NE(userId, 0);
867 
868     bundleFilePaths.clear();
869     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPA);
870     res = InstallBundle(bundleFilePaths, userId);
871     EXPECT_EQ(res, ERR_OK);
872 
873     auto bmsProxy = GetBundleMgrProxy();
874     EXPECT_NE(bmsProxy, nullptr);
875 
876     // query bundleInfo under two users respectively
877     BundleInfo bundleInfo1;
878     bool ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo1, USERID);
879     EXPECT_TRUE(ret);
880 
881     BundleInfo bundleInfo2;
882     ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo2, userId);
883     EXPECT_TRUE(ret);
884 
885     UninstallBundle(BUNDLE_NAME, Constants::ALL_USERID);
886     std::cout << "END BMS_Install_multi_user_2200" << std::endl;
887 }
888 
889 /**
890  * @tc.number: BMS_Install_multi_user_2300
891  * @tc.name:  test the installation of a third-party bundle for multi users
892  * @tc.desc: 1.install hapA and hapB under user 100 successfully
893  *           2.create user 101 successfully
894  *           3.updata install the higher version-code hapB under the user ALL_USERID successfully
895  *           4.query bundleInfo under user 100 and 101 successfully
896  */
897 HWTEST_F(BmsInstallMultiUserTest, BMS_Install_multi_user_2300, Function | MediumTest | Level1)
898 {
899     std::cout << "START BMS_Install_multi_user_2300" << std::endl;
900     std::vector<std::string> bundleFilePaths = { THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPA };
901     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPB);
902     auto res = InstallBundle(bundleFilePaths, USERID);
903     EXPECT_EQ(res, ERR_OK);
904 
905     int32_t userId = CreateNewUser();
906     EXPECT_NE(userId, 0);
907 
908     bundleFilePaths.clear();
909     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + HIGHER_VERSION_CODE_TEST_BUNDLE_HAPB);
910     res = InstallBundle(bundleFilePaths, newUserId_);
911     EXPECT_EQ(res, IStatusReceiver::ERR_INSTALL_VERSION_NOT_COMPATIBLE);
912 
913     auto bmsProxy = GetBundleMgrProxy();
914     EXPECT_NE(bmsProxy, nullptr);
915 
916     // query bundleInfo under two users respectively
917     BundleInfo bundleInfo1;
918     bool ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo1, USERID);
919     EXPECT_TRUE(ret);
920 
921     BundleInfo bundleInfo2;
922     ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo2, userId);
923     EXPECT_FALSE(ret);
924 
925     UninstallBundle(BUNDLE_NAME, Constants::ALL_USERID);
926     std::cout << "END BMS_Install_multi_user_2300" << std::endl;
927 }
928 
929 /**
930  * @tc.number: BMS_Install_multi_user_2400
931  * @tc.name:  test the installation of a third-party bundle for multi users
932  * @tc.desc: 1.install hapA and hapB under user 100 successfully
933  *           2.create user 101 successfully
934  *           3.updata install the lower version-code hapB under the user ALL_USERID failed
935  *           4.query bundleInfo under user 100 and 101 successfully
936  */
937 HWTEST_F(BmsInstallMultiUserTest, BMS_Install_multi_user_2400, Function | MediumTest | Level1)
938 {
939     std::cout << "START BMS_Install_multi_user_2400" << std::endl;
940     std::vector<std::string> bundleFilePaths = { THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPA };
941     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPB);
942     auto res = InstallBundle(bundleFilePaths, USERID);
943     EXPECT_EQ(res, ERR_OK);
944 
945     int32_t userId = CreateNewUser();
946     EXPECT_NE(userId, 0);
947 
948     bundleFilePaths.clear();
949     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + LOWER_VERSION_CODE_TEST_BUNDLE_HAPB);
950     res = InstallBundle(bundleFilePaths, userId);
951     EXPECT_EQ(res, IStatusReceiver::ERR_INSTALL_VERSION_DOWNGRADE);
952 
953     auto bmsProxy = GetBundleMgrProxy();
954     EXPECT_NE(bmsProxy, nullptr);
955 
956     // query bundleInfo under two users respectively
957     BundleInfo bundleInfo1;
958     bool ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo1, USERID);
959     EXPECT_TRUE(ret);
960 
961     BundleInfo bundleInfo2;
962     ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo2, userId);
963     EXPECT_FALSE(ret);
964 
965     UninstallBundle(BUNDLE_NAME, Constants::ALL_USERID);
966     std::cout << "END BMS_Install_multi_user_2400" << std::endl;
967 }
968 
969 /**
970  * @tc.number: BMS_Install_multi_user_2500
971  * @tc.name:  test the installation of a third-party bundle for multi users
972  * @tc.desc: 1.install hapA and hapB under user 100 successfully
973  *           2.create user 101 successfully
974  *           3.updata install the same version-code hapB under the user ALL_USERID successfully
975  *           4.query bundleInfo under user 100 and 101 successfully
976  */
977 HWTEST_F(BmsInstallMultiUserTest, BMS_Install_multi_user_2500, Function | MediumTest | Level1)
978 {
979     std::cout << "START BMS_Install_multi_user_2500" << std::endl;
980     std::vector<std::string> bundleFilePaths = { THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPA };
981     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPB);
982     auto res = InstallBundle(bundleFilePaths, USERID);
983     EXPECT_EQ(res, ERR_OK);
984 
985     int32_t userId = CreateNewUser();
986     EXPECT_NE(userId, 0);
987 
988     bundleFilePaths.clear();
989     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPB);
990     res = InstallBundle(bundleFilePaths, userId);
991     EXPECT_EQ(res, ERR_OK);
992 
993     auto bmsProxy = GetBundleMgrProxy();
994     EXPECT_NE(bmsProxy, nullptr);
995 
996     // query bundleInfo under two users respectively
997     BundleInfo bundleInfo1;
998     bool ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo1, USERID);
999     EXPECT_TRUE(ret);
1000 
1001     BundleInfo bundleInfo2;
1002     ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo2, userId);
1003     EXPECT_TRUE(ret);
1004 
1005     UninstallBundle(BUNDLE_NAME, Constants::ALL_USERID);
1006     std::cout << "END BMS_Install_multi_user_2500" << std::endl;
1007 }
1008 
1009 /**
1010  * @tc.number: BMS_Install_multi_user_2600
1011  * @tc.name:  test the installation of a third-party bundle for multi users
1012  * @tc.desc: 1.install hapA and hapB under user 100 successfully
1013  *           2.create user 101 successfully
1014  *           3.updata install the higher version-code hapA and hapB under the user ALL_USERID successfully
1015  *           4.query bundleInfo under user 100 and 101 successfully
1016  */
1017 HWTEST_F(BmsInstallMultiUserTest, BMS_Install_multi_user_2600, Function | MediumTest | Level1)
1018 {
1019     std::cout << "START BMS_Install_multi_user_2600" << std::endl;
1020     std::vector<std::string> bundleFilePaths = { THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPA };
1021     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPB);
1022     auto res = InstallBundle(bundleFilePaths, USERID);
1023     EXPECT_EQ(res, ERR_OK);
1024 
1025     int32_t userId = CreateNewUser();
1026     EXPECT_NE(userId, 0);
1027 
1028     bundleFilePaths.clear();
1029     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + HIGHER_VERSION_CODE_TEST_BUNDLE_HAPA);
1030     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + HIGHER_VERSION_CODE_TEST_BUNDLE_HAPB);
1031     res = InstallBundle(bundleFilePaths, newUserId_);
1032     EXPECT_EQ(res, ERR_OK);
1033 
1034     auto bmsProxy = GetBundleMgrProxy();
1035     EXPECT_NE(bmsProxy, nullptr);
1036 
1037     // query bundleInfo under two users respectively
1038     BundleInfo bundleInfo1;
1039     bool ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo1, USERID);
1040     EXPECT_TRUE(ret);
1041 
1042     BundleInfo bundleInfo2;
1043     ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo2, userId);
1044     EXPECT_TRUE(ret);
1045 
1046     UninstallBundle(BUNDLE_NAME, Constants::ALL_USERID);
1047     std::cout << "END BMS_Install_multi_user_2600" << std::endl;
1048 }
1049 
1050 /**
1051  * @tc.number: BMS_Install_multi_user_2700
1052  * @tc.name:  test the installation of a third-party bundle for multi users
1053  * @tc.desc: 1.install hapA and hapB under user 100 successfully
1054  *           2.create user 101 successfully
1055  *           3.updata install the lower version-code hapA and hapB under the user ALL_USERID failed
1056  *           4.query bundleInfo under user 100 and 101 successfully
1057  */
1058 HWTEST_F(BmsInstallMultiUserTest, BMS_Install_multi_user_2700, Function | MediumTest | Level1)
1059 {
1060     std::cout << "START BMS_Install_multi_user_2700" << std::endl;
1061     std::vector<std::string> bundleFilePaths = { THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPA };
1062     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPB);
1063     auto res = InstallBundle(bundleFilePaths, USERID);
1064     EXPECT_EQ(res, ERR_OK);
1065 
1066     int32_t userId = CreateNewUser();
1067     EXPECT_NE(userId, 0);
1068 
1069     bundleFilePaths.clear();
1070     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + LOWER_VERSION_CODE_TEST_BUNDLE_HAPA);
1071     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + LOWER_VERSION_CODE_TEST_BUNDLE_HAPB);
1072     res = InstallBundle(bundleFilePaths, userId);
1073     EXPECT_EQ(res, IStatusReceiver::ERR_INSTALL_VERSION_DOWNGRADE);
1074 
1075     auto bmsProxy = GetBundleMgrProxy();
1076     EXPECT_NE(bmsProxy, nullptr);
1077 
1078     // query bundleInfo under two users respectively
1079     BundleInfo bundleInfo1;
1080     bool ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo1, USERID);
1081     EXPECT_TRUE(ret);
1082 
1083     BundleInfo bundleInfo2;
1084     ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo2, userId);
1085     EXPECT_FALSE(ret);
1086 
1087     UninstallBundle(BUNDLE_NAME, Constants::ALL_USERID);
1088     std::cout << "END BMS_Install_multi_user_2700" << std::endl;
1089 }
1090 
1091 /**
1092  * @tc.number: BMS_Install_multi_user_2800
1093  * @tc.name:  test the installation of a third-party bundle for multi users
1094  * @tc.desc: 1.install hapA and hapB under user 100 successfully
1095  *           2.create user 101 successfully
1096  *           3.updata install the same version-code hapA and hapB under the user ALL_USERID successfully
1097  *           4.query bundleInfo under user 100 and 101 successfully
1098  */
1099 HWTEST_F(BmsInstallMultiUserTest, BMS_Install_multi_user_2800, Function | MediumTest | Level1)
1100 {
1101     std::cout << "START BMS_Install_multi_user_2800" << std::endl;
1102     std::vector<std::string> bundleFilePaths = { THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPA };
1103     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPB);
1104     auto res = InstallBundle(bundleFilePaths, USERID);
1105     EXPECT_EQ(res, ERR_OK);
1106 
1107     int32_t userId = CreateNewUser();
1108     EXPECT_NE(userId, 0);
1109 
1110     bundleFilePaths.clear();
1111     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPA);
1112     bundleFilePaths.emplace_back(THIRD_BUNDLE_PATH + TEST_BUNDLE_HAPB);
1113     res = InstallBundle(bundleFilePaths, userId);
1114     EXPECT_EQ(res, ERR_OK);
1115 
1116     auto bmsProxy = GetBundleMgrProxy();
1117     EXPECT_NE(bmsProxy, nullptr);
1118 
1119     // query bundleInfo under two users respectively
1120     BundleInfo bundleInfo1;
1121     bool ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo1, USERID);
1122     EXPECT_TRUE(ret);
1123 
1124     BundleInfo bundleInfo2;
1125     ret = bmsProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo2, userId);
1126     EXPECT_TRUE(ret);
1127 
1128     UninstallBundle(BUNDLE_NAME, Constants::ALL_USERID);
1129     std::cout << "END BMS_Install_multi_user_2800" << std::endl;
1130 }
1131 
1132 /**
1133  * @tc.number: BMS_Install_multi_user_2900
1134  * @tc.name:  test the installation of a third-party bundle for multi users
1135  * @tc.desc: 1.install hap user 101 successfully
1136  *           2.create user 101 successfully
1137  *           3.updata install the same version-code hapA and hapB under the user ALL_USERID successfully
1138  *           4.query shortcutInfo under user 101 successfully
1139  */
1140 HWTEST_F(BmsInstallMultiUserTest, BMS_Install_multi_user_2900, Function | MediumTest | Level1)
1141 {
1142     std::cout << "START BMS_Install_multi_user_2900" << std::endl;
1143     int32_t userId = CreateNewUser();
1144     EXPECT_NE(userId, 0);
1145 
1146     std::vector<std::string> bundleFilePaths = { THIRD_BUNDLE_PATH + "bundleClient1.hap" };
1147     auto res1 = InstallBundle(bundleFilePaths, userId);
1148     EXPECT_EQ(res1, ERR_OK);
1149 
1150     auto bmsProxy = GetBundleMgrProxy();
1151     EXPECT_NE(bmsProxy, nullptr);
1152 
1153     std::vector<ShortcutInfo> shortcutInfos;
1154     auto res = bmsProxy->GetShortcutInfoV9("com.example.ohosproject.hmservice", shortcutInfos, userId);
1155     EXPECT_EQ(res, ERR_OK);
1156     EXPECT_FALSE(shortcutInfos.empty());
1157 
1158     UninstallBundle("com.example.ohosproject.hmservice", Constants::ALL_USERID);
1159     std::cout << "END BMS_Install_multi_user_2900" << std::endl;
1160 }
1161 
1162 /**
1163  * @tc.number: BMS_Install_multi_user_3000
1164  * @tc.name:  test the installation of a third-party bundle for multi users
1165  * @tc.desc: 1.install hap user 101 successfully
1166  *           2.create user 101 successfully
1167  *           3.updata install the same version-code hapA and hapB under the user ALL_USERID successfully
1168  *           4.query shortcutInfo under user 100 failed
1169  */
1170 HWTEST_F(BmsInstallMultiUserTest, BMS_Install_multi_user_3000, Function | MediumTest | Level1)
1171 {
1172     std::cout << "START BMS_Install_multi_user_3000" << std::endl;
1173     int32_t userId = CreateNewUser();
1174     EXPECT_NE(userId, 0);
1175 
1176     std::vector<std::string> bundleFilePaths = { THIRD_BUNDLE_PATH + "bundleClient1.hap" };
1177     auto res1 = InstallBundle(bundleFilePaths, userId);
1178     EXPECT_EQ(res1, ERR_OK);
1179 
1180     auto bmsProxy = GetBundleMgrProxy();
1181     EXPECT_NE(bmsProxy, nullptr);
1182 
1183     std::vector<ShortcutInfo> shortcutInfos;
1184     auto res = bmsProxy->GetShortcutInfoV9("com.example.ohosproject.hmservice", shortcutInfos, 100);
1185     EXPECT_NE(res, ERR_OK);
1186     EXPECT_TRUE(shortcutInfos.empty());
1187 
1188     UninstallBundle("com.example.ohosproject.hmservice", Constants::ALL_USERID);
1189     std::cout << "END BMS_Install_multi_user_3000" << std::endl;
1190 }
1191 } // AppExecFwk
1192 } // OHOS
1193