• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #include "nlohmann/json.hpp"
20 
21 #include "ability_manager_interface.h"
22 #include "app_log_wrapper.h"
23 #include "bundle_installer_interface.h"
24 #include "bundle_mgr_proxy.h"
25 #include "bundle_mgr_interface.h"
26 #include "bundle_constants.h"
27 #include "common_tool.h"
28 #include "common_event_manager.h"
29 #include "common_event_support.h"
30 #include "iservice_registry.h"
31 #include "sa_mgr_client.h"
32 #include "system_ability_definition.h"
33 #include "status_receiver_host.h"
34 
35 using OHOS::AAFwk::Want;
36 using namespace OHOS::EventFwk;
37 using namespace testing::ext;
38 using namespace std::chrono_literals;
39 
40 namespace {
41 const std::string THIRD_BUNDLE_PATH = "/data/test/bms_bundle/";
42 const std::string SYSTEM_BUNDLE_PATH = "/system/app/";
43 const std::string BASE_BUNDLE_NAME = "com.third.hiworld.example";
44 const std::string SYSTEM_LAUNCHER_BUNDLE_NAME = "com.ohos.launcher";
45 const std::string SYSTEM_SETTINGS_BUNDLE_NAME = "com.ohos.settings";
46 const std::string SYSTEM_SYSTEMUI_BUNDLE_NAME = "com.ohos.systemui";
47 const std::string BUNDLE_DATA_ROOT_PATH = "/data/accounts/account_0/appdata/";
48 const std::string BUNDLE_CODE_ROOT_PATH = "/data/app/el1/bundle/public/";
49 const std::string ERROR_INSTALL_FAILED = "install failed!";
50 const std::string ERROR_UNINSTALL_FAILED = "uninstall failed!";
51 const std::string MSG_SUCCESS = "[SUCCESS]";
52 const std::string OPERATION_FAILURE = "Failure";
53 const std::string OPERATION_SUCCESS = "Success";
54 const std::string START_SUCCESS = "start ability success";
55 using CloneInfo = struct {
56     int uid;
57     bool isCloned;
58 };
59 const int64_t TIMEOUT = 10;
60 const size_t CLONEINFO_SIZE = 2;
61 const size_t NONECLONEINFO_SIZE = 1;
62 const size_t ONE_SIZE = 1;
63 constexpr int USERID = 0;
64 constexpr int CLONEUID = 20000000;
65 const std::string THIRED1_EVENT = "ACTS_Third1_Clone_Publish_CommonEvent";
66 const std::string KEY_BUNDLENAME = "bundleName";
67 const std::string KEY_ABILITYNAME = "abilityName";
68 const std::string START_BUNDLENAME = "com.example.bmsstartability";
69 const std::string START_ABILITYNAME = "com.example.bmsstartability.MainAbility";
70 const std::string START_BUNDLE_PATH = "/data/test/bms_bundle/bmsStartAbility.hap";
71 }  // namespace
72 
73 namespace OHOS {
74 namespace AppExecFwk {
75 class StatusReceiverImpl : public StatusReceiverHost {
76 public:
77     StatusReceiverImpl();
78     virtual ~StatusReceiverImpl();
79     virtual void OnStatusNotify(const int progress) override;
80     virtual void OnFinished(const int32_t resultCode, const std::string &resultMsg) override;
81     std::string GetResultMsg() const;
82 
83 private:
84     mutable std::promise<std::string> resultMsgSignal_;
85     int iProgress_ = 0;
86 
87     DISALLOW_COPY_AND_MOVE(StatusReceiverImpl);
88 };
89 
StatusReceiverImpl()90 StatusReceiverImpl::StatusReceiverImpl()
91 {
92     APP_LOGI("create status receiver instance");
93 }
94 
~StatusReceiverImpl()95 StatusReceiverImpl::~StatusReceiverImpl()
96 {
97     APP_LOGI("destroy status receiver instance");
98 }
99 
OnFinished(const int32_t resultCode,const std::string & resultMsg)100 void StatusReceiverImpl::OnFinished(const int32_t resultCode, const std::string &resultMsg)
101 {
102     APP_LOGI("on finished result is %{public}d, %{public}s", resultCode, resultMsg.c_str());
103     resultMsgSignal_.set_value(resultMsg);
104 }
OnStatusNotify(const int progress)105 void StatusReceiverImpl::OnStatusNotify(const int progress)
106 {
107     EXPECT_GT(progress, iProgress_);
108     iProgress_ = progress;
109     APP_LOGI("OnStatusNotify progress:%{public}d", progress);
110 }
111 
GetResultMsg() const112 std::string StatusReceiverImpl::GetResultMsg() const
113 {
114     auto future = resultMsgSignal_.get_future();
115     std::chrono::seconds timeout(TIMEOUT);
116     if (future.wait_for(timeout) == std::future_status::timeout) {
117         return OPERATION_FAILURE + " timeout";
118     }
119     std::string resultMsg = future.get();
120     if (resultMsg == MSG_SUCCESS) {
121         return OPERATION_SUCCESS;
122     }
123     return OPERATION_FAILURE + resultMsg;
124 }
125 
126 class BmsCloneSystemTest : public testing::Test {
127 public:
128     static void SetUpTestCase();
129     static void TearDownTestCase();
130     void SetUp();
131     void TearDown();
132     static void InstallBundle(
133         const std::string &bundleFilePath, const InstallFlag installFlag, std::string &installMsg);
134     static void UninstallBundle(const std::string &bundleName, std::string &uninstallMsg);
135     static void UninstallBundle(
136         const std::string &bundleName, const std::string &modulePackage, std::string &uninstallMsg);
137     static sptr<IBundleMgr> GetBundleMgrProxy();
138     static sptr<IBundleInstaller> GetInstallerProxy();
139     int CheckFileExist(const std::string &str) const;
140     static void Complete(const std::string message);
141     static bool Wait(const std::string message);
Clean()142     static void Clean()
143     {
144         message_ = "";
145         completeMessage_.clear();
146     }
147     static void CheckCloneInfo(std::vector<CloneInfo> &cloneInfo);
148     static void CheckAbilityInfo(AbilityInfo &originInfo, AbilityInfo &cloneInfo);
149     static void GetCloneInfo(
150         const std::vector<BundleInfo> &bundleInfos, const std::string &bundleName, std::vector<CloneInfo> &cloneInfos);
151 
152 private:
153     static std::mutex mutex_;
154     static std::condition_variable cv_;
155     static std::string message_;
156     static std::vector<std::string> completeMessage_;
157 };
158 
SetUpTestCase()159 void BmsCloneSystemTest::SetUpTestCase()
160 {}
161 
TearDownTestCase()162 void BmsCloneSystemTest::TearDownTestCase()
163 {}
164 
SetUp()165 void BmsCloneSystemTest::SetUp()
166 {}
167 
TearDown()168 void BmsCloneSystemTest::TearDown()
169 {}
170 
GetBundleMgrProxy()171 sptr<IBundleMgr> BmsCloneSystemTest::GetBundleMgrProxy()
172 {
173     sptr<ISystemAbilityManager> systemAbilityManager =
174         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
175     if (!systemAbilityManager) {
176         APP_LOGI("fail to get system ability mgr.");
177         return nullptr;
178     }
179     sptr<IRemoteObject> remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
180     if (!remoteObject) {
181         APP_LOGI("fail to get bundle manager proxy.");
182         return nullptr;
183     }
184 
185     APP_LOGI("get bundle manager proxy success.");
186     return iface_cast<IBundleMgr>(remoteObject);
187 }
188 
GetInstallerProxy()189 sptr<IBundleInstaller> BmsCloneSystemTest::GetInstallerProxy()
190 {
191     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
192     if (!bundleMgrProxy) {
193         APP_LOGI("bundle mgr proxy is nullptr.");
194         return nullptr;
195     }
196 
197     sptr<IBundleInstaller> installerProxy = bundleMgrProxy->GetBundleInstaller();
198     if (!installerProxy) {
199         APP_LOGI("fail to get bundle installer proxy.");
200         return nullptr;
201     }
202 
203     APP_LOGI("get bundle installer proxy success.");
204     return installerProxy;
205 }
InstallBundle(const std::string & bundleFilePath,const InstallFlag installFlag,std::string & installMsg)206 void BmsCloneSystemTest::InstallBundle(
207     const std::string &bundleFilePath, const InstallFlag installFlag, std::string &installMsg)
208 {
209     sptr<IBundleInstaller> installerProxy = GetInstallerProxy();
210     if (!installerProxy) {
211         APP_LOGI("get bundle installer Failure.");
212         installMsg = "Failure";
213         return;
214     }
215     InstallParam installParam;
216     installParam.installFlag = installFlag;
217     sptr<StatusReceiverImpl> statusReceiver(new (std::nothrow) StatusReceiverImpl());
218     EXPECT_NE(statusReceiver, nullptr);
219     bool installResult = installerProxy->Install(bundleFilePath, installParam, statusReceiver);
220     EXPECT_TRUE(installResult);
221     installMsg = statusReceiver->GetResultMsg();
222 }
223 
UninstallBundle(const std::string & bundleName,std::string & uninstallMsg)224 void BmsCloneSystemTest::UninstallBundle(const std::string &bundleName, std::string &uninstallMsg)
225 {
226     sptr<IBundleInstaller> installerProxy = GetInstallerProxy();
227     if (!installerProxy) {
228         APP_LOGI("get bundle installer Failure.");
229         uninstallMsg = "Failure";
230         return;
231     }
232 
233     if (bundleName.empty()) {
234         APP_LOGI("bundelname is null.");
235         uninstallMsg = "Failure";
236     } else {
237         sptr<StatusReceiverImpl> statusReceiver(new (std::nothrow) StatusReceiverImpl());
238         EXPECT_NE(statusReceiver, nullptr);
239         InstallParam installParam;
240         bool uninstallResult = installerProxy->Uninstall(bundleName, installParam, statusReceiver);
241         EXPECT_TRUE(uninstallResult);
242         uninstallMsg = statusReceiver->GetResultMsg();
243     }
244 }
245 
UninstallBundle(const std::string & bundleName,const std::string & modulePackage,std::string & uninstallMsg)246 void BmsCloneSystemTest::UninstallBundle(
247     const std::string &bundleName, const std::string &modulePackage, std::string &uninstallMsg)
248 {
249     sptr<IBundleInstaller> installerProxy = GetInstallerProxy();
250     if (!installerProxy) {
251         APP_LOGI("get bundle installer Failure.");
252         uninstallMsg = "Failure";
253         return;
254     }
255 
256     if (bundleName.empty() || modulePackage.empty()) {
257         APP_LOGI("bundelname is null.");
258         uninstallMsg = "Failure";
259     } else {
260         sptr<StatusReceiverImpl> statusReceiver(new (std::nothrow) StatusReceiverImpl());
261         EXPECT_NE(statusReceiver, nullptr);
262         InstallParam installParam;
263         bool uninstallResult = installerProxy->Uninstall(bundleName, modulePackage, installParam, statusReceiver);
264         EXPECT_TRUE(uninstallResult);
265         uninstallMsg = statusReceiver->GetResultMsg();
266     }
267 }
268 
CheckFileExist(const std::string & str) const269 int BmsCloneSystemTest::CheckFileExist(const std::string &str) const
270 {
271     int bundleDataExist = access((str).c_str(), F_OK);
272     return bundleDataExist;
273 }
274 std::string BmsCloneSystemTest::message_ = "";
275 std::vector<std::string> BmsCloneSystemTest::completeMessage_ {};
276 std::condition_variable BmsCloneSystemTest::cv_ = std::condition_variable();
277 std::mutex BmsCloneSystemTest::mutex_ = std::mutex();
Complete(const std::string message)278 void BmsCloneSystemTest::Complete(const std::string message)
279 {
280     std::this_thread::sleep_for(500ms);
281     std::unique_lock<std::mutex> lock(mutex_);
282     if (message_.compare(message) == 0) {
283         GTEST_LOG_(INFO) << "Complete.";
284         cv_.notify_all();
285         message_ = "";
286         return;
287     }
288     GTEST_LOG_(INFO) << "Can't Complete." << message_;
289     completeMessage_.emplace_back(message);
290     return;
291 }
292 
Wait(const std::string message)293 bool BmsCloneSystemTest::Wait(const std::string message)
294 {
295     GTEST_LOG_(INFO) << "Wait start.";
296     std::unique_lock<std::mutex> lock(mutex_);
297     message_ = message;
298     if (!message_.empty()) {
299         for (size_t i = 0; i < completeMessage_.size(); i++) {
300             if (message_.compare(completeMessage_.at(i)) == 0) {
301                 message_ = "";
302                 return true;
303             }
304         }
305     }
306     if (cv_.wait_for(lock, std::chrono::seconds(TIMEOUT)) == std::cv_status::timeout) {
307         GTEST_LOG_(INFO) << "Time out.";
308         message_ = "";
309         return false;
310     }
311     GTEST_LOG_(INFO) << "Wait done.";
312     return true;
313 }
314 
CheckCloneInfo(std::vector<CloneInfo> & cloneInfos)315 void BmsCloneSystemTest::CheckCloneInfo(std::vector<CloneInfo> &cloneInfos)
316 {
317     EXPECT_LT(cloneInfos[0].uid, CLONEUID);
318     EXPECT_GT(cloneInfos[1].uid, CLONEUID);
319     EXPECT_FALSE(cloneInfos[0].isCloned);
320     EXPECT_TRUE(cloneInfos[1].isCloned);
321 }
322 
CheckAbilityInfo(AbilityInfo & originInfo,AbilityInfo & cloneInfo)323 void BmsCloneSystemTest::CheckAbilityInfo(AbilityInfo &originInfo, AbilityInfo &cloneInfo)
324 {
325     GTEST_LOG_(INFO) << "================CheckAbilityInfo==============:";
326     EXPECT_EQ(originInfo.package, cloneInfo.package);
327     EXPECT_EQ(originInfo.name, cloneInfo.name);
328     EXPECT_EQ(originInfo.description, cloneInfo.description);
329     EXPECT_EQ(originInfo.iconPath, cloneInfo.iconPath);
330     EXPECT_EQ(originInfo.uri, cloneInfo.uri);
331     EXPECT_EQ(originInfo.moduleName, cloneInfo.moduleName);
332     EXPECT_EQ(originInfo.process, cloneInfo.process);
333     EXPECT_EQ(originInfo.targetAbility, cloneInfo.targetAbility);
334     EXPECT_EQ(originInfo.appName, cloneInfo.appName);
335     EXPECT_EQ(originInfo.privacyUrl, cloneInfo.privacyUrl);
336     EXPECT_EQ(originInfo.privacyName, cloneInfo.privacyName);
337     EXPECT_EQ(originInfo.downloadUrl, cloneInfo.downloadUrl);
338     EXPECT_EQ(originInfo.versionName, cloneInfo.versionName);
339     EXPECT_EQ(originInfo.backgroundModes, cloneInfo.backgroundModes);
340     EXPECT_EQ(originInfo.packageSize, cloneInfo.packageSize);
341     EXPECT_EQ(originInfo.visible, cloneInfo.visible);
342     EXPECT_EQ(originInfo.formEnabled, cloneInfo.formEnabled);
343     EXPECT_EQ(originInfo.multiUserShared, cloneInfo.multiUserShared);
344     EXPECT_EQ(originInfo.type, cloneInfo.type);
345     EXPECT_EQ(originInfo.launchMode, cloneInfo.launchMode);
346     EXPECT_EQ(originInfo.permissions, cloneInfo.permissions);
347     EXPECT_EQ(originInfo.deviceTypes, cloneInfo.deviceTypes);
348     EXPECT_EQ(originInfo.bundleName, cloneInfo.bundleName);
349     EXPECT_EQ(originInfo.className, cloneInfo.className);
350     EXPECT_EQ(originInfo.deviceId, cloneInfo.deviceId);
351     EXPECT_EQ(originInfo.iconId, cloneInfo.iconId);
352     EXPECT_EQ(originInfo.labelId, cloneInfo.labelId);
353 }
354 
GetCloneInfo(const std::vector<BundleInfo> & bundleInfos,const std::string & bundleName,std::vector<CloneInfo> & cloneInfos)355 void BmsCloneSystemTest::GetCloneInfo(
356     const std::vector<BundleInfo> &bundleInfos, const std::string &bundleName, std::vector<CloneInfo> &cloneInfos)
357 {
358     for (auto bundleInfo : bundleInfos) {
359         if (bundleInfo.name == bundleName) {
360             CloneInfo info;
361             info.uid = bundleInfo.uid;
362             info.isCloned = bundleInfo.applicationInfo.isCloned;
363             cloneInfos.emplace_back(info);
364         }
365     }
366 }
367 
368 /**
369  * @tc.number: BMS_BundleClone_0100
370  * @tc.name: test the BundleClone interface
371  * @tc.desc: 1. install a third-party app
372  *           2. clone this third-party app
373  *           3. check data dir and code dir of the cloned app
374  */
375 HWTEST_F(BmsCloneSystemTest, BMS_BundleClone_0100, Function | MediumTest | Level1)
376 {
377     GTEST_LOG_(INFO) << "START BMS_BundleClone_0100";
378     std::string installresvec;
379     std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap";
380     std::string bundleName = "com.example.third1";
381     InstallBundle(bundleFilePath, InstallFlag::NORMAL, installresvec);
382     EXPECT_EQ(installresvec, "Success") << "install fail!";
383     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
384     if (!bundleMgrProxy) {
385         GTEST_LOG_(INFO) << "bundle mgr proxy is nullptr.";
386         EXPECT_NE(bundleMgrProxy, nullptr);
387     }
388     bool cloneResult = bundleMgrProxy->BundleClone(bundleName);
389     EXPECT_TRUE(cloneResult);
390     std::vector<BundleInfo> bundleInfos;
391     std::vector<CloneInfo> cloneInfos;
392     EXPECT_TRUE(bundleMgrProxy->GetBundleInfos(BundleFlag::GET_BUNDLE_DEFAULT, bundleInfos));
393     GetCloneInfo(bundleInfos, bundleName, cloneInfos);
394     EXPECT_EQ(cloneInfos.size(), CLONEINFO_SIZE);
395     if (cloneInfos.size() == CLONEINFO_SIZE) {
396         CheckCloneInfo(cloneInfos);
397         std::string cloneDataPath = BUNDLE_DATA_ROOT_PATH + bundleName + "#" + std::to_string(cloneInfos[1].uid);
398         std::string cloneCodePath = BUNDLE_CODE_ROOT_PATH + bundleName + "#" + std::to_string(cloneInfos[1].uid);
399         EXPECT_EQ(CheckFileExist(cloneDataPath), 0);
400         EXPECT_NE(CheckFileExist(cloneCodePath), 0);
401     }
402     UninstallBundle(bundleName, installresvec);
403     EXPECT_EQ(installresvec, "Success") << "uninstall fail!";
404     GTEST_LOG_(INFO) << "END BMS_BundleClone_0100";
405 }
406 
407 /**
408  * @tc.number: BMS_BundleClone_0200
409  * @tc.name: test repeately call the BundleClone interface
410  * @tc.desc: 1. install a third-party app
411  *           2. repeately clone this third-party app
412  */
413 HWTEST_F(BmsCloneSystemTest, BMS_BundleClone_0200, Function | MediumTest | Level2)
414 {
415     GTEST_LOG_(INFO) << "START BMS_BundleClone_0200";
416     std::string installresvec;
417     std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap";
418     std::string bundleName = "com.example.third1";
419     InstallBundle(bundleFilePath, InstallFlag::NORMAL, installresvec);
420     EXPECT_EQ(installresvec, "Success") << "install fail!";
421     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
422     if (!bundleMgrProxy) {
423         GTEST_LOG_(INFO) << "bundle mgr proxy is nullptr.";
424         EXPECT_NE(bundleMgrProxy, nullptr);
425     }
426     EXPECT_TRUE(bundleMgrProxy->BundleClone(bundleName));
427     EXPECT_FALSE(bundleMgrProxy->BundleClone(bundleName));
428     EXPECT_FALSE(bundleMgrProxy->BundleClone(bundleName));
429     UninstallBundle(bundleName, installresvec);
430     EXPECT_EQ(installresvec, "Success") << "uninstall fail!";
431     GTEST_LOG_(INFO) << "END BMS_BundleClone_0200";
432 }
433 
434 /**
435  * @tc.number: BMS_BundleClone_0300
436  * @tc.name: test the BundleClone interface by empty bundleName
437  * @tc.desc: 1.install a third-party application
438  *           2.clone this application by empty bundleName
439  */
440 HWTEST_F(BmsCloneSystemTest, BMS_BundleClone_0300, Function | MediumTest | Level2)
441 {
442     GTEST_LOG_(INFO) << "START BMS_BundleClone_0300";
443     std::string bundleName = "";
444     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
445     if (!bundleMgrProxy) {
446         GTEST_LOG_(INFO) << "bundle mgr proxy is nullptr.";
447         EXPECT_NE(bundleMgrProxy, nullptr);
448     }
449     bool cloneResult = bundleMgrProxy->BundleClone(bundleName);
450     EXPECT_FALSE(cloneResult);
451     GTEST_LOG_(INFO) << "END BMS_BundleClone_0300";
452 }
453 
454 /**
455  * @tc.number: BMS_BundleClone_0400
456  * @tc.name: test the  BundleClone interface used bundleName that is not in trustlist
457  * @tc.desc: 1.install a third-party application that is not in trustlist
458  *           2.clone this third-party app
459  */
460 HWTEST_F(BmsCloneSystemTest, BMS_BundleClone_0400, Function | MediumTest | Level2)
461 {
462     GTEST_LOG_(INFO) << "START BMS_BundleClone_0400";
463     std::string installresvec;
464     std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle2.hap";
465     std::string bundleName = "com.example.third2";
466     InstallBundle(bundleFilePath, InstallFlag::NORMAL, installresvec);
467     EXPECT_EQ(installresvec, "Success") << "install fail!";
468     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
469     if (!bundleMgrProxy) {
470         GTEST_LOG_(INFO) << "bundle mgr proxy is nullptr.";
471         EXPECT_NE(bundleMgrProxy, nullptr);
472     }
473     bool cloneResult = bundleMgrProxy->BundleClone(bundleName);
474     EXPECT_FALSE(cloneResult);
475     UninstallBundle(bundleName, installresvec);
476     EXPECT_EQ(installresvec, "Success") << "uninstall fail!";
477     GTEST_LOG_(INFO) << "END BMS_BundleClone_0400";
478 }
479 
480 /**
481  * @tc.number: BMS_BundleClone_0500
482  * @tc.name: test the  BundleClone interface by invalid bundleName
483  * @tc.desc: 1.install a third-party application
484  *           2.clone this application with an invalid bundle name
485  */
486 HWTEST_F(BmsCloneSystemTest, BMS_BundleClone_0500, Function | MediumTest | Level2)
487 {
488     GTEST_LOG_(INFO) << "START BMS_BundleClone_0500";
489     std::string bundleName = "com.example.error";
490     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
491     if (!bundleMgrProxy) {
492         GTEST_LOG_(INFO) << "bundle mgr proxy is nullptr.";
493         EXPECT_NE(bundleMgrProxy, nullptr);
494     }
495     bool cloneResult = bundleMgrProxy->BundleClone(bundleName);
496     EXPECT_FALSE(cloneResult);
497     GTEST_LOG_(INFO) << "END BMS_BundleClone_0500";
498 }
499 
500 /**
501  * @tc.number: BMS_BundleClone_0600
502  * @tc.name: test the  BundleClone interface by update bundleName
503  * @tc.desc: 1.install a third-party app
504  *           2.clone this app
505  *           3.update this app
506  *           4.clone the updated app
507  */
508 HWTEST_F(BmsCloneSystemTest, BMS_BundleClone_0600, Function | MediumTest | Level2)
509 {
510     GTEST_LOG_(INFO) << "START BMS_BundleClone_0600";
511     std::string installresvec;
512     std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap";
513     std::string bundleUpFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle4.hap";
514     std::string bundleName = "com.example.third1";
515     InstallBundle(bundleFilePath, InstallFlag::NORMAL, installresvec);
516     EXPECT_EQ(installresvec, "Success") << "install fail!";
517     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
518     if (!bundleMgrProxy) {
519         GTEST_LOG_(INFO) << "bundle mgr proxy is nullptr.";
520         EXPECT_NE(bundleMgrProxy, nullptr);
521     }
522     EXPECT_TRUE(bundleMgrProxy->BundleClone(bundleName));
523     std::vector<BundleInfo> bundleInfos;
524     std::vector<CloneInfo> cloneInfos;
525     EXPECT_TRUE(bundleMgrProxy->GetBundleInfos(BundleFlag::GET_BUNDLE_DEFAULT, bundleInfos));
526     GetCloneInfo(bundleInfos, bundleName, cloneInfos);
527     EXPECT_EQ(cloneInfos.size(), CLONEINFO_SIZE);
528     if (cloneInfos.size() == CLONEINFO_SIZE) {
529         CheckCloneInfo(cloneInfos);
530     }
531     InstallBundle(bundleUpFilePath, InstallFlag::REPLACE_EXISTING, installresvec);
532     EXPECT_EQ(installresvec, "Success") << "install fail!";
533     EXPECT_FALSE(bundleMgrProxy->BundleClone(bundleName));
534     bundleInfos.clear();
535     EXPECT_TRUE(bundleMgrProxy->GetBundleInfos(BundleFlag::GET_BUNDLE_DEFAULT, bundleInfos));
536     std::vector<uint32_t> versionCodes;
537     for (auto bundleInfo : bundleInfos) {
538         if (bundleInfo.name == bundleName) {
539             versionCodes.emplace_back(bundleInfo.versionCode);
540         }
541     }
542     EXPECT_EQ(versionCodes.size(), CLONEINFO_SIZE);
543     if (!versionCodes.empty()) {
544         EXPECT_NE(*(versionCodes.begin()), *(versionCodes.end() - 1));
545     }
546     std::string uninstallResult;
547     UninstallBundle(bundleName, uninstallResult);
548     EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!";
549     GTEST_LOG_(INFO) << "END BMS_BundleClone_0600";
550 }
551 
552 /**
553  * @tc.number: BMS_BundleClone_0700
554  * @tc.name: clone a application includes two haps
555  * @tc.desc: 1.install a third-party application includes two haps
556  *           2.check cloned application's data directory doesn't have module directory, ontology application has module
557  *               directory
558  */
559 HWTEST_F(BmsCloneSystemTest, BMS_BundleClone_0700, Function | MediumTest | Level1)
560 {
561     GTEST_LOG_(INFO) << "START BMS_BundleClone_0700";
562     std::string installresvec;
563     std::string bundleFilePath1 = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap";
564     std::string bundleFilePath2 = THIRD_BUNDLE_PATH + "bmsThirdBundle3.hap";
565     std::string bundleName = "com.example.third1";
566     std::string entryModule = "com.example.third1";
567     std::string featureModule = "com.example.third3";
568     std::string abilityName = "com.example.third1.MainAbility";
569     InstallBundle(bundleFilePath1, InstallFlag::NORMAL, installresvec);
570     EXPECT_EQ(installresvec, "Success") << "install fail!";
571     InstallBundle(bundleFilePath2, InstallFlag::NORMAL, installresvec);
572     EXPECT_EQ(installresvec, "Success") << "install fail!";
573     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
574     if (!bundleMgrProxy) {
575         GTEST_LOG_(INFO) << "bundle mgr proxy is nullptr.";
576         EXPECT_NE(bundleMgrProxy, nullptr);
577     }
578     EXPECT_TRUE(bundleMgrProxy->BundleClone(bundleName));
579     EXPECT_EQ(CheckFileExist(BUNDLE_DATA_ROOT_PATH + bundleName + "/" + entryModule), 0);
580     EXPECT_EQ(CheckFileExist(BUNDLE_DATA_ROOT_PATH + bundleName + "/" + featureModule), 0);
581     std::vector<BundleInfo> bundleInfos;
582     std::vector<CloneInfo> cloneInfos;
583     EXPECT_TRUE(bundleMgrProxy->GetBundleInfos(BundleFlag::GET_BUNDLE_DEFAULT, bundleInfos));
584     GetCloneInfo(bundleInfos, bundleName, cloneInfos);
585     EXPECT_EQ(cloneInfos.size(), CLONEINFO_SIZE);
586     if (cloneInfos.size() == CLONEINFO_SIZE) {
587         CheckCloneInfo(cloneInfos);
588         EXPECT_EQ(CheckFileExist(BUNDLE_DATA_ROOT_PATH + bundleName + "#" + std::to_string(cloneInfos[1].uid)), 0);
589         int isExist = 0;
590         isExist = CheckFileExist(
591             BUNDLE_DATA_ROOT_PATH + bundleName + "#" + std::to_string(cloneInfos[1].uid) + "/" + entryModule);
592         EXPECT_NE(isExist, 0);
593         isExist = CheckFileExist(
594             BUNDLE_DATA_ROOT_PATH + bundleName + "#" + std::to_string(cloneInfos[1].uid) + "/" + featureModule);
595         EXPECT_NE(isExist, 0);
596     }
597     std::string uninstallResult;
598     UninstallBundle(bundleName, uninstallResult);
599     EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!";
600     GTEST_LOG_(INFO) << "END BMS_BundleClone_0700";
601 }
602 
603 /**
604  * @tc.number: BMS_RemoveClonedBundle_0100
605  * @tc.name: test the interface of RemoveClonedBundle
606  * @tc.desc: 1.install a third-party application
607  *           2.clone this application
608  *           3.remove the cloned application
609  */
610 HWTEST_F(BmsCloneSystemTest, BMS_RemoveClonedBundle_0100, Function | MediumTest | Level1)
611 {
612     GTEST_LOG_(INFO) << "START BMS_RemoveClonedBundle_0100";
613     std::string installresvec;
614     std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap";
615     std::string bundleName = "com.example.third1";
616     InstallBundle(bundleFilePath, InstallFlag::NORMAL, installresvec);
617     EXPECT_EQ(installresvec, "Success") << "install fail!";
618     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
619     if (!bundleMgrProxy) {
620         GTEST_LOG_(INFO) << "bundle mgr proxy is nullptr.";
621         EXPECT_NE(bundleMgrProxy, nullptr);
622     }
623     EXPECT_TRUE(bundleMgrProxy->BundleClone(bundleName));
624     std::vector<BundleInfo> bundleInfos;
625     std::vector<CloneInfo> cloneInfos;
626     EXPECT_TRUE(bundleMgrProxy->GetBundleInfos(BundleFlag::GET_BUNDLE_DEFAULT, bundleInfos));
627     GetCloneInfo(bundleInfos, bundleName, cloneInfos);
628     EXPECT_EQ(cloneInfos.size(), CLONEINFO_SIZE);
629     if (cloneInfos.size() == CLONEINFO_SIZE) {
630         CheckCloneInfo(cloneInfos);
631         std::string cloneDataPath = BUNDLE_DATA_ROOT_PATH + bundleName + "#" + std::to_string(cloneInfos[1].uid);
632         std::string cloneCodePath = BUNDLE_CODE_ROOT_PATH + bundleName + "#" + std::to_string(cloneInfos[1].uid);
633         EXPECT_EQ(CheckFileExist(cloneDataPath), 0);
634         EXPECT_NE(CheckFileExist(cloneCodePath), 0);
635         EXPECT_TRUE(bundleMgrProxy->RemoveClonedBundle(bundleName, cloneInfos[1].uid));
636         EXPECT_NE(CheckFileExist(cloneDataPath), 0);
637         EXPECT_NE(CheckFileExist(cloneCodePath), 0);
638     }
639     std::string uninstallResult;
640     UninstallBundle(bundleName, uninstallResult);
641     EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!";
642     GTEST_LOG_(INFO) << "END BMS_RemoveClonedBundle_0100";
643 }
644 
645 /**
646  * @tc.number: BMS_RemoveClonedBundle_0200
647  * @tc.name: uninstall app to remove the cloned app
648  * @tc.desc: 1.install a third-party application
649  *           2.clone this application
650  *           3.uninstall the application to remove the cloneed application
651  */
652 HWTEST_F(BmsCloneSystemTest, BMS_RemoveClonedBundle_0200, Function | MediumTest | Level1)
653 {
654     GTEST_LOG_(INFO) << "START BMS_RemoveClonedBundle_0200";
655     std::string installresvec;
656     std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap";
657     std::string bundleName = "com.example.third1";
658     InstallBundle(bundleFilePath, InstallFlag::NORMAL, installresvec);
659     EXPECT_EQ(installresvec, "Success") << "install fail!";
660     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
661     if (!bundleMgrProxy) {
662         GTEST_LOG_(INFO) << "bundle mgr proxy is nullptr.";
663         EXPECT_NE(bundleMgrProxy, nullptr);
664     }
665     EXPECT_TRUE(bundleMgrProxy->BundleClone(bundleName));
666     std::vector<BundleInfo> bundleInfos;
667     std::vector<CloneInfo> cloneInfos;
668     EXPECT_TRUE(bundleMgrProxy->GetBundleInfos(BundleFlag::GET_BUNDLE_DEFAULT, bundleInfos));
669     GetCloneInfo(bundleInfos, bundleName, cloneInfos);
670     std::string cloneDataPath = BUNDLE_DATA_ROOT_PATH + bundleName + "#";
671     std::string cloneCodePath = BUNDLE_CODE_ROOT_PATH + bundleName + "#";
672     EXPECT_EQ(cloneInfos.size(), CLONEINFO_SIZE);
673     if (cloneInfos.size() == CLONEINFO_SIZE) {
674         CheckCloneInfo(cloneInfos);
675         cloneDataPath += std::to_string(cloneInfos[1].uid);
676         cloneCodePath += std::to_string(cloneInfos[1].uid);
677     }
678     EXPECT_EQ(CheckFileExist(cloneDataPath), 0);
679     EXPECT_NE(CheckFileExist(cloneCodePath), 0);
680     std::string uninstallResult;
681     UninstallBundle(bundleName, uninstallResult);
682     EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!";
683     EXPECT_NE(CheckFileExist(cloneDataPath), 0);
684     EXPECT_NE(CheckFileExist(cloneCodePath), 0);
685     GTEST_LOG_(INFO) << "END BMS_RemoveClonedBundle_0200";
686 }
687 
688 /**
689  * @tc.number: BMS_RemoveClonedBundle_0300
690  * @tc.name: update the application doesn't change cloned application
691  * @tc.desc: 1.install a third-party application
692  *           2.clone this application
693  *           3.update the application
694  */
695 HWTEST_F(BmsCloneSystemTest, BMS_RemoveClonedBundle_0300, Function | MediumTest | Level1)
696 {
697     GTEST_LOG_(INFO) << "START BMS_RemoveClonedBundle_0300";
698     std::string installresvec;
699     std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap";
700     std::string bundleUpFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle4.hap";
701     std::string bundleName = "com.example.third1";
702     InstallBundle(bundleFilePath, InstallFlag::NORMAL, installresvec);
703     EXPECT_EQ(installresvec, "Success") << "install fail!";
704     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
705     if (!bundleMgrProxy) {
706         GTEST_LOG_(INFO) << "bundle mgr proxy is nullptr.";
707         EXPECT_NE(bundleMgrProxy, nullptr);
708     }
709     EXPECT_TRUE(bundleMgrProxy->BundleClone(bundleName));
710     std::vector<BundleInfo> bundleInfos;
711     std::vector<CloneInfo> cloneInfos;
712     EXPECT_TRUE(bundleMgrProxy->GetBundleInfos(BundleFlag::GET_BUNDLE_DEFAULT, bundleInfos));
713     GetCloneInfo(bundleInfos, bundleName, cloneInfos);
714     std::string cloneDataPath = BUNDLE_DATA_ROOT_PATH + bundleName + "#";
715     std::string cloneCodePath = BUNDLE_CODE_ROOT_PATH + bundleName + "#";
716     EXPECT_EQ(cloneInfos.size(), CLONEINFO_SIZE);
717     if (cloneInfos.size() == CLONEINFO_SIZE) {
718         CheckCloneInfo(cloneInfos);
719         cloneDataPath += std::to_string(cloneInfos[1].uid);
720         cloneCodePath += std::to_string(cloneInfos[1].uid);
721     }
722     EXPECT_EQ(CheckFileExist(cloneDataPath), 0);
723     EXPECT_NE(CheckFileExist(cloneCodePath), 0);
724     InstallBundle(bundleUpFilePath, InstallFlag::REPLACE_EXISTING, installresvec);
725     EXPECT_EQ(installresvec, "Success") << "install fail!";
726     EXPECT_EQ(CheckFileExist(cloneDataPath), 0);
727     EXPECT_NE(CheckFileExist(cloneCodePath), 0);
728     std::string uninstallResult;
729     UninstallBundle(bundleName, uninstallResult);
730     EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!";
731     EXPECT_NE(CheckFileExist(cloneDataPath), 0);
732     EXPECT_NE(CheckFileExist(cloneCodePath), 0);
733     GTEST_LOG_(INFO) << "END BMS_RemoveClonedBundle_0300";
734 }
735 
736 /**
737  * @tc.number: BMS_RemoveClonedBundle_0400
738  * @tc.name: remove cloned apps from uncloned apps
739  * @tc.desc: 1.install a third-party application
740  *           2.use the bundleName and use the uid of the ontology application to stop using the clone
741  */
742 HWTEST_F(BmsCloneSystemTest, BMS_RemoveClonedBundle_0400, Function | MediumTest | Level2)
743 {
744     GTEST_LOG_(INFO) << "START BMS_RemoveClonedBundle_0400";
745     std::string installresvec;
746     std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap";
747     std::string bundleName = "com.example.third1";
748     InstallBundle(bundleFilePath, InstallFlag::NORMAL, installresvec);
749     EXPECT_EQ(installresvec, "Success") << "install fail!";
750     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
751     if (!bundleMgrProxy) {
752         GTEST_LOG_(INFO) << "bundle mgr proxy is nullptr.";
753         EXPECT_NE(bundleMgrProxy, nullptr);
754     }
755     BundleInfo bundleInfo;
756     bundleMgrProxy->GetBundleInfo(bundleName, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo);
757     EXPECT_FALSE(bundleMgrProxy->RemoveClonedBundle(bundleName, bundleInfo.uid));
758     std::string uninstallResult;
759     UninstallBundle(bundleName, uninstallResult);
760     EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!";
761     GTEST_LOG_(INFO) << "END BMS_RemoveClonedBundle_0400";
762 }
763 
764 /**
765  * @tc.number: BMS_RemoveClonedBundle_0500
766  * @tc.name: test the RemoveClonedBundle interface by invalid param
767  * @tc.desc: 1.install a third-party application
768  *           2.clone this application
769  *           3.use invalid bundleName and uid to stop the application clone
770  */
771 HWTEST_F(BmsCloneSystemTest, BMS_RemoveClonedBundle_0500, Function | MediumTest | Level2)
772 {
773     GTEST_LOG_(INFO) << "START BMS_RemoveClonedBundle_0500";
774     std::string bundleName = "com.example.error";
775     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
776     if (!bundleMgrProxy) {
777         GTEST_LOG_(INFO) << "bundle mgr proxy is nullptr.";
778         EXPECT_NE(bundleMgrProxy, nullptr);
779     }
780     EXPECT_FALSE(bundleMgrProxy->RemoveClonedBundle(bundleName, Constants::INVALID_UID));
781     GTEST_LOG_(INFO) << "END BMS_RemoveClonedBundle_0500";
782 }
783 
784 /**
785  * @tc.number: BMS_RemoveClonedBundle_0600
786  * @tc.name: test the RemoveClonedBundle interface by ontology application uid
787  * @tc.desc: 1.install a third-party application
788  *           2.clone this application
789  *           3.use the uid of the ontology application to remove the cloned application
790  */
791 HWTEST_F(BmsCloneSystemTest, BMS_RemoveClonedBundle_0600, Function | MediumTest | Level2)
792 {
793     GTEST_LOG_(INFO) << "START BMS_RemoveClonedBundle_0600";
794     std::string installresvec;
795     std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap";
796     std::string bundleName = "com.example.third1";
797     InstallBundle(bundleFilePath, InstallFlag::NORMAL, installresvec);
798     EXPECT_EQ(installresvec, "Success") << "install fail!";
799     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
800     if (!bundleMgrProxy) {
801         GTEST_LOG_(INFO) << "bundle mgr proxy is nullptr.";
802         EXPECT_NE(bundleMgrProxy, nullptr);
803     }
804     EXPECT_TRUE(bundleMgrProxy->BundleClone(bundleName));
805     std::vector<BundleInfo> bundleInfos;
806     std::vector<CloneInfo> cloneInfos;
807     EXPECT_TRUE(bundleMgrProxy->GetBundleInfos(BundleFlag::GET_BUNDLE_DEFAULT, bundleInfos));
808     GetCloneInfo(bundleInfos, bundleName, cloneInfos);
809     EXPECT_EQ(cloneInfos.size(), CLONEINFO_SIZE);
810     if (cloneInfos.size() == CLONEINFO_SIZE) {
811         CheckCloneInfo(cloneInfos);
812         EXPECT_FALSE(bundleMgrProxy->RemoveClonedBundle(bundleName, cloneInfos[0].uid));
813     }
814     std::string uninstallResult;
815     UninstallBundle(bundleName, uninstallResult);
816     EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!";
817     GTEST_LOG_(INFO) << "END BMS_RemoveClonedBundle_0600";
818 }
819 
820 /**
821  * @tc.number: BMS_RemoveClonedBundle_0700
822  * @tc.name: test the RemoveClonedBundle interface by empty bundleName
823  * @tc.desc: 1.install a third-party application
824  *           2.clone this application
825  *           3.use an empty bundleName to remove the cloned application
826  */
827 HWTEST_F(BmsCloneSystemTest, BMS_RemoveClonedBundle_0700, Function | MediumTest | Level2)
828 {
829     GTEST_LOG_(INFO) << "START BMS_RemoveClonedBundle_0700";
830     std::string installresvec;
831     std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap";
832     std::string bundleName = "com.example.third1";
833     InstallBundle(bundleFilePath, InstallFlag::NORMAL, installresvec);
834     EXPECT_EQ(installresvec, "Success") << "install fail!";
835     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
836     if (!bundleMgrProxy) {
837         GTEST_LOG_(INFO) << "bundle mgr proxy is nullptr.";
838         EXPECT_NE(bundleMgrProxy, nullptr);
839     }
840     EXPECT_TRUE(bundleMgrProxy->BundleClone(bundleName));
841     std::vector<BundleInfo> bundleInfos;
842     std::vector<CloneInfo> cloneInfos;
843     EXPECT_TRUE(bundleMgrProxy->GetBundleInfos(BundleFlag::GET_BUNDLE_DEFAULT, bundleInfos));
844     GetCloneInfo(bundleInfos, bundleName, cloneInfos);
845     EXPECT_EQ(cloneInfos.size(), CLONEINFO_SIZE);
846     if (cloneInfos.size() == CLONEINFO_SIZE) {
847         CheckCloneInfo(cloneInfos);
848         EXPECT_FALSE(bundleMgrProxy->RemoveClonedBundle(bundleName, cloneInfos[0].uid));
849         EXPECT_FALSE(bundleMgrProxy->RemoveClonedBundle("", cloneInfos[1].uid));
850     }
851     std::string uninstallResult;
852     UninstallBundle(bundleName, uninstallResult);
853     EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!";
854     GTEST_LOG_(INFO) << "END BMS_RemoveClonedBundle_0700";
855 }
856 
857 /**
858  * @tc.number: BMS_RemoveClonedBundle_0800
859  * @tc.name: test repeately call the interface RemoveClonedBundle
860  * @tc.desc: 1.install a third-party application
861  *           2.clone this application
862  *           3.repeately remove the cloned application
863  */
864 HWTEST_F(BmsCloneSystemTest, BMS_RemoveClonedBundle_0800, Function | MediumTest | Level2)
865 {
866     GTEST_LOG_(INFO) << "START BMS_RemoveClonedBundle_0800";
867     std::string installresvec;
868     std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap";
869     std::string bundleName = "com.example.third1";
870     InstallBundle(bundleFilePath, InstallFlag::NORMAL, installresvec);
871     EXPECT_EQ(installresvec, "Success") << "install fail!";
872     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
873     if (!bundleMgrProxy) {
874         GTEST_LOG_(INFO) << "bundle mgr proxy is nullptr.";
875         EXPECT_NE(bundleMgrProxy, nullptr);
876     }
877     EXPECT_TRUE(bundleMgrProxy->BundleClone(bundleName));
878     std::vector<BundleInfo> bundleInfos;
879     std::vector<CloneInfo> cloneInfos;
880     EXPECT_TRUE(bundleMgrProxy->GetBundleInfos(BundleFlag::GET_BUNDLE_DEFAULT, bundleInfos));
881     GetCloneInfo(bundleInfos, bundleName, cloneInfos);
882     EXPECT_EQ(cloneInfos.size(), CLONEINFO_SIZE);
883     if (cloneInfos.size() == CLONEINFO_SIZE) {
884         EXPECT_TRUE(bundleMgrProxy->RemoveClonedBundle(bundleName, cloneInfos[1].uid));
885         EXPECT_FALSE(bundleMgrProxy->RemoveClonedBundle(bundleName, cloneInfos[1].uid));
886         EXPECT_FALSE(bundleMgrProxy->RemoveClonedBundle(bundleName, cloneInfos[1].uid));
887     }
888     std::string uninstallResult;
889     UninstallBundle(bundleName, uninstallResult);
890     EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!";
891     GTEST_LOG_(INFO) << "END BMS_RemoveClonedBundle_0800";
892 }
893 
894 /**
895  * @tc.number: BMS_RemoveClonedBundle_0900
896  * @tc.name: uninstall app to remove the cloned app
897  * @tc.desc: 1.install a third-party application
898  *           2.clone this application
899  *           3.uninstall the application's feature module
900  */
901 HWTEST_F(BmsCloneSystemTest, BMS_RemoveClonedBundle_0900, Function | MediumTest | Level1)
902 {
903     GTEST_LOG_(INFO) << "START BMS_RemoveClonedBundle_0900";
904     std::string installresvec;
905     std::string bundleFilePath1 = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap";
906     std::string bundleFilePath2 = THIRD_BUNDLE_PATH + "bmsThirdBundle3.hap";
907     std::string entryModule = "com.example.third1";
908     std::string featureModule = "com.example.third3";
909     std::string bundleName = "com.example.third1";
910     InstallBundle(bundleFilePath1, InstallFlag::NORMAL, installresvec);
911     EXPECT_EQ(installresvec, "Success") << "install fail!";
912     InstallBundle(bundleFilePath2, InstallFlag::NORMAL, installresvec);
913     EXPECT_EQ(installresvec, "Success") << "install fail!";
914     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
915     if (!bundleMgrProxy) {
916         GTEST_LOG_(INFO) << "bundle mgr proxy is nullptr.";
917         EXPECT_NE(bundleMgrProxy, nullptr);
918     }
919     EXPECT_TRUE(bundleMgrProxy->BundleClone(bundleName));
920     std::vector<BundleInfo> bundleInfos;
921     std::vector<CloneInfo> cloneInfos;
922     EXPECT_TRUE(bundleMgrProxy->GetBundleInfos(BundleFlag::GET_BUNDLE_DEFAULT, bundleInfos));
923     GetCloneInfo(bundleInfos, bundleName, cloneInfos);
924     std::string cloneUid;
925     EXPECT_EQ(cloneInfos.size(), CLONEINFO_SIZE);
926     if (cloneInfos.size() == CLONEINFO_SIZE) {
927         CheckCloneInfo(cloneInfos);
928         cloneUid = std::to_string(cloneInfos[1].uid);
929     }
930     std::string uninstallResult;
931     UninstallBundle(bundleName, featureModule, uninstallResult);
932     EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!";
933     EXPECT_EQ(CheckFileExist(BUNDLE_DATA_ROOT_PATH + bundleName + "#" + cloneUid), 0);
934     EXPECT_EQ(CheckFileExist(BUNDLE_DATA_ROOT_PATH + bundleName + "/" + entryModule), 0);
935     EXPECT_NE(CheckFileExist(BUNDLE_DATA_ROOT_PATH + bundleName + "/" + featureModule), 0);
936     EXPECT_EQ(CheckFileExist(BUNDLE_CODE_ROOT_PATH + bundleName + "/" + entryModule), 0);
937     EXPECT_NE(CheckFileExist(BUNDLE_CODE_ROOT_PATH + bundleName + "/" + featureModule), 0);
938     UninstallBundle(bundleName, entryModule, uninstallResult);
939     EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!";
940     EXPECT_NE(CheckFileExist(BUNDLE_CODE_ROOT_PATH + bundleName), 0);
941     GTEST_LOG_(INFO) << "END BMS_RemoveClonedBundle_0900";
942 }
943 
944 /**
945  * @tc.number: BMS_RemoveClonedBundle_1000
946  * @tc.name: clone system preset application, remove cloned application.
947  * @tc.desc: 1.clone this application
948  *           2.uninstall the application to remove the cloneed application failed
949  *           3.call RemoveClonedBundle interface to remove the cloneed application success
950  */
951 HWTEST_F(BmsCloneSystemTest, BMS_RemoveClonedBundle_1000, Function | MediumTest | Level1)
952 {
953     GTEST_LOG_(INFO) << "START BMS_RemoveClonedBundle_1000";
954     std::string bundleName = "com.ohos.settings";
955     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
956     if (!bundleMgrProxy) {
957         GTEST_LOG_(INFO) << "bundle mgr proxy is nullptr.";
958         EXPECT_NE(bundleMgrProxy, nullptr);
959     }
960     EXPECT_TRUE(bundleMgrProxy->BundleClone(bundleName));
961     std::vector<BundleInfo> bundleInfos;
962     std::vector<CloneInfo> cloneInfos;
963     EXPECT_TRUE(bundleMgrProxy->GetBundleInfos(BundleFlag::GET_BUNDLE_DEFAULT, bundleInfos));
964     GetCloneInfo(bundleInfos, bundleName, cloneInfos);
965     std::string cloneDataPath = BUNDLE_DATA_ROOT_PATH + bundleName + "#";
966     std::string cloneCodePath = BUNDLE_CODE_ROOT_PATH + bundleName + "#";
967     uint32_t cloneUid = 0;
968     EXPECT_EQ(cloneInfos.size(), CLONEINFO_SIZE);
969     if (cloneInfos.size() == CLONEINFO_SIZE) {
970         CheckCloneInfo(cloneInfos);
971         cloneUid = cloneInfos[1].uid;
972         cloneDataPath += std::to_string(cloneInfos[1].uid);
973         cloneCodePath += std::to_string(cloneInfos[1].uid);
974     }
975     std::string uninstallResult;
976     UninstallBundle(bundleName, uninstallResult);
977     EXPECT_EQ(uninstallResult, "Failure[MSG_ERR_UNINSTALL_SYSTEM_APP_ERROR]") << "uninstall success!";
978     EXPECT_EQ(CheckFileExist(cloneDataPath), 0);
979     EXPECT_NE(CheckFileExist(cloneCodePath), 0);
980     EXPECT_TRUE(bundleMgrProxy->RemoveClonedBundle(bundleName, cloneUid));
981     EXPECT_NE(CheckFileExist(cloneDataPath), 0);
982     EXPECT_NE(CheckFileExist(cloneCodePath), 0);
983     GTEST_LOG_(INFO) << "END BMS_RemoveClonedBundle_1000";
984 }
985 
986 /**
987  * @tc.number: BMS_CloneGetApplicationInfos_0100
988  * @tc.name: test the GetApplicationInfos interface to get cloned application's info
989  * @tc.desc: 1.install a third-party application
990  *           2.clone this application
991  *           3.get the application information of the cloned application
992  */
993 HWTEST_F(BmsCloneSystemTest, BMS_CloneGetApplicationInfos_0100, Function | MediumTest | Level1)
994 {
995     GTEST_LOG_(INFO) << "START BMS_CloneGetApplicationInfos_0100";
996     std::string installresvec;
997     std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap";
998     std::string bundleName = "com.example.third1";
999     InstallBundle(bundleFilePath, InstallFlag::NORMAL, installresvec);
1000     EXPECT_EQ(installresvec, "Success") << "install fail!";
1001     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
1002     if (!bundleMgrProxy) {
1003         GTEST_LOG_(INFO) << "bundle mgr proxy is nullptr.";
1004         EXPECT_NE(bundleMgrProxy, nullptr);
1005     }
1006     EXPECT_TRUE(bundleMgrProxy->BundleClone(bundleName));
1007     std::vector<ApplicationInfo> appInfos;
1008     std::vector<CloneInfo> cloneInfos;
1009     EXPECT_TRUE(bundleMgrProxy->GetApplicationInfos(ApplicationFlag::GET_BASIC_APPLICATION_INFO, USERID, appInfos));
1010     for (auto appInfo : appInfos) {
1011         if (appInfo.name == bundleName) {
1012             CloneInfo info;
1013             info.uid = appInfo.uid;
1014             info.isCloned = appInfo.isCloned;
1015             cloneInfos.emplace_back(info);
1016         }
1017     }
1018     EXPECT_EQ(cloneInfos.size(), CLONEINFO_SIZE);
1019     if (cloneInfos.size() == CLONEINFO_SIZE) {
1020         CheckCloneInfo(cloneInfos);
1021     }
1022     UninstallBundle(bundleName, installresvec);
1023     EXPECT_EQ(installresvec, "Success") << "uninstall fail!";
1024     GTEST_LOG_(INFO) << "END BMS_CloneGetApplicationInfos_0100";
1025 }
1026 
1027 /**
1028  * @tc.number: BMS_CloneGetApplicationInfos_0200
1029  * @tc.name: test the GetApplicationInfos interface
1030  * @tc.desc: 1.install a third-party application
1031  *           2.clone this application
1032  *           3.remove this cloned application, get the application information of the cloned application
1033  */
1034 HWTEST_F(BmsCloneSystemTest, BMS_CloneGetApplicationInfos_0200, Function | MediumTest | Level1)
1035 {
1036     GTEST_LOG_(INFO) << "START BMS_CloneGetApplicationInfos_0200";
1037     std::string installresvec;
1038     std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap";
1039     std::string bundleName = "com.example.third1";
1040     InstallBundle(bundleFilePath, InstallFlag::NORMAL, installresvec);
1041     EXPECT_EQ(installresvec, "Success") << "install fail!";
1042     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
1043     if (!bundleMgrProxy) {
1044         GTEST_LOG_(INFO) << "bundle mgr proxy is nullptr.";
1045         EXPECT_NE(bundleMgrProxy, nullptr);
1046     }
1047     std::vector<ApplicationInfo> appInfos;
1048     Want want;
1049     ElementName name;
1050     name.SetBundleName(bundleName);
1051     name.SetAbilityName("com.example.third1.MainAbility");
1052     want.SetElement(name);
1053     std::vector<AbilityInfo> abilityInfos;
1054     EXPECT_TRUE(bundleMgrProxy->BundleClone(bundleName));
1055     EXPECT_TRUE(bundleMgrProxy->QueryAbilityInfosForClone(want, abilityInfos));
1056     EXPECT_TRUE(bundleMgrProxy->RemoveClonedBundle(bundleName, abilityInfos[0].applicationInfo.uid));
1057     EXPECT_TRUE(bundleMgrProxy->GetApplicationInfos(ApplicationFlag::GET_BASIC_APPLICATION_INFO, USERID, appInfos));
1058     for (auto appInfo : appInfos) {
1059         if (appInfo.name == bundleName) {
1060             EXPECT_FALSE(appInfo.isCloned);
1061             EXPECT_LT(appInfo.uid, CLONEUID);
1062         }
1063     }
1064     UninstallBundle(bundleName, installresvec);
1065     EXPECT_EQ(installresvec, "Success") << "uninstall fail!";
1066     GTEST_LOG_(INFO) << "END BMS_CloneGetApplicationInfos_0200";
1067 }
1068 
1069 /**
1070  * @tc.number: BMS_QueryAbilityInfosForClone_0100
1071  * @tc.name: test the QueryAbilityInfosForClone interface to get ontology and cloned applications' info
1072  * @tc.name: test the QueryAbilityInfosForClone interface to get uncloned application's abilityInfo
1073  * @tc.desc: 1.install a third-party application
1074  *           2.call the QueryAbilityInfosForClone interface to get the ability information of
1075  *              the ontology and cloned applications
1076  */
1077 HWTEST_F(BmsCloneSystemTest, BMS_QueryAbilityInfosForClone_0100, Function | MediumTest | Level1)
1078 {
1079     GTEST_LOG_(INFO) << "START BMS_QueryAbilityInfosForClone_0100";
1080     std::string installresvec;
1081     std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap";
1082     std::string bundleName = "com.example.third1";
1083     std::string abilityName = "com.example.third1.MainAbility";
1084     InstallBundle(bundleFilePath, InstallFlag::NORMAL, installresvec);
1085     EXPECT_EQ(installresvec, "Success") << "install fail!";
1086     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
1087     if (!bundleMgrProxy) {
1088         GTEST_LOG_(INFO) << "bundle mgr proxy is nullptr.";
1089         EXPECT_NE(bundleMgrProxy, nullptr);
1090     }
1091     bool cloneResult = bundleMgrProxy->BundleClone(bundleName);
1092     EXPECT_TRUE(cloneResult);
1093     Want want;
1094     ElementName name;
1095     name.SetBundleName(bundleName);
1096     name.SetAbilityName(abilityName);
1097     want.SetElement(name);
1098     std::vector<AbilityInfo> abilityInfos;
1099     EXPECT_TRUE(bundleMgrProxy->QueryAbilityInfosForClone(want, abilityInfos));
1100     EXPECT_EQ(abilityInfos.size(), CLONEINFO_SIZE);
1101     if (abilityInfos.size() == CLONEINFO_SIZE) {
1102         CheckAbilityInfo(abilityInfos[0], abilityInfos[1]);
1103         EXPECT_TRUE(abilityInfos.at(0).applicationInfo.isCloned);
1104         EXPECT_FALSE(abilityInfos.at(1).applicationInfo.isCloned);
1105     }
1106     std::string uninstallResult;
1107     UninstallBundle(bundleName, uninstallResult);
1108     EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!";
1109     GTEST_LOG_(INFO) << "END BMS_BundleClone_0100";
1110 }
1111 
1112 /**
1113  * @tc.number: BMS_QueryAbilityInfosForClone_0200
1114  * @tc.name: test the QueryAbilityInfosForClone interface to get uncloned application's abilityInfo
1115  * @tc.desc: 1.install a third-party application
1116  *           2.call the QueryAbilityInfosForClone interface to get uncloned application's abilityInfo
1117  */
1118 HWTEST_F(BmsCloneSystemTest, BMS_QueryAbilityInfosForClone_0200, Function | MediumTest | Level1)
1119 {
1120     GTEST_LOG_(INFO) << "START BMS_QueryAbilityInfosForClone_0200";
1121     std::string installresvec;
1122     std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap";
1123     std::string bundleName = "com.example.third1";
1124     std::string abilityName = "com.example.third1.MainAbility";
1125     InstallBundle(bundleFilePath, InstallFlag::NORMAL, installresvec);
1126     EXPECT_EQ(installresvec, "Success") << "install fail!";
1127     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
1128     if (!bundleMgrProxy) {
1129         GTEST_LOG_(INFO) << "bundle mgr proxy is nullptr.";
1130         EXPECT_NE(bundleMgrProxy, nullptr);
1131     }
1132     Want want;
1133     ElementName name;
1134     name.SetBundleName(bundleName);
1135     name.SetAbilityName(abilityName);
1136     want.SetElement(name);
1137     std::vector<AbilityInfo> abilityInfos;
1138     EXPECT_TRUE(bundleMgrProxy->QueryAbilityInfosForClone(want, abilityInfos));
1139     EXPECT_EQ(abilityInfos.size(), NONECLONEINFO_SIZE);
1140     if (abilityInfos.size() == NONECLONEINFO_SIZE) {
1141         EXPECT_EQ(abilityInfos.at(0).name, abilityName);
1142         EXPECT_EQ(abilityInfos.at(0).bundleName, bundleName);
1143         EXPECT_FALSE(abilityInfos.at(0).applicationInfo.isCloned);
1144     }
1145     std::string uninstallResult;
1146     UninstallBundle(bundleName, uninstallResult);
1147     EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!";
1148     GTEST_LOG_(INFO) << "END BMS_QueryAbilityInfosForClone_0200";
1149 }
1150 
1151 /**
1152  * @tc.number: BMS_QueryAbilityInfosForClone_0300
1153  * @tc.name: test the QueryAbilityInfosForClone interface to get abilityInfo which has removed cloned application
1154  * @tc.desc: 1.install a third-party application
1155  *           2.clone this application
1156  *           3.remove this cloned application
1157  *           4.get the ability information of the cloned application
1158  */
1159 HWTEST_F(BmsCloneSystemTest, BMS_QueryAbilityInfosForClone_0300, Function | MediumTest | Level1)
1160 {
1161     GTEST_LOG_(INFO) << "START BMS_QueryAbilityInfosForClone_0300";
1162     std::string installresvec;
1163     std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap";
1164     std::string bundleName = "com.example.third1";
1165     std::string abilityName = "com.example.third1.MainAbility";
1166     InstallBundle(bundleFilePath, InstallFlag::NORMAL, installresvec);
1167     EXPECT_EQ(installresvec, "Success") << "install fail!";
1168     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
1169     if (!bundleMgrProxy) {
1170         GTEST_LOG_(INFO) << "bundle mgr proxy is nullptr.";
1171         EXPECT_NE(bundleMgrProxy, nullptr);
1172     }
1173     EXPECT_TRUE(bundleMgrProxy->BundleClone(bundleName));
1174     Want want;
1175     ElementName name;
1176     name.SetBundleName(bundleName);
1177     name.SetAbilityName(abilityName);
1178     want.SetElement(name);
1179     std::vector<AbilityInfo> abilityInfos;
1180     EXPECT_TRUE(bundleMgrProxy->QueryAbilityInfosForClone(want, abilityInfos));
1181     EXPECT_EQ(abilityInfos.size(), CLONEINFO_SIZE);
1182     EXPECT_TRUE(bundleMgrProxy->RemoveClonedBundle(bundleName, abilityInfos.at(0).applicationInfo.uid));
1183     abilityInfos.clear();
1184     EXPECT_TRUE(bundleMgrProxy->QueryAbilityInfosForClone(want, abilityInfos));
1185     EXPECT_EQ(abilityInfos.size(), NONECLONEINFO_SIZE);
1186     std::string uninstallResult;
1187     UninstallBundle(bundleName, uninstallResult);
1188     EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!";
1189     GTEST_LOG_(INFO) << "END BMS_QueryAbilityInfosForClone_0300";
1190 }
1191 
1192 /**
1193  * @tc.number: BMS_QueryAbilityInfosForClone_0400
1194  * @tc.name: test the QueryAbilityInfosForClone interface to get abilityInfo
1195  * @tc.desc: 1.install a third-party application
1196  *           2.clone this application
1197  *           3.uninstall this application
1198  *           4.get the ability information of the cloned application
1199  */
1200 HWTEST_F(BmsCloneSystemTest, BMS_QueryAbilityInfosForClone_0400, Function | MediumTest | Level2)
1201 {
1202     GTEST_LOG_(INFO) << "START BMS_QueryAbilityInfosForClone_0400";
1203     std::string installresvec;
1204     std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap";
1205     std::string bundleName = "com.example.third1";
1206     std::string abilityName = "com.example.third1.MainAbility";
1207     InstallBundle(bundleFilePath, InstallFlag::NORMAL, installresvec);
1208     EXPECT_EQ(installresvec, "Success") << "install fail!";
1209     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
1210     if (!bundleMgrProxy) {
1211         GTEST_LOG_(INFO) << "bundle mgr proxy is nullptr.";
1212         EXPECT_NE(bundleMgrProxy, nullptr);
1213     }
1214     EXPECT_TRUE(bundleMgrProxy->BundleClone(bundleName));
1215     Want want;
1216     ElementName name;
1217     name.SetBundleName(bundleName);
1218     name.SetAbilityName(abilityName);
1219     want.SetElement(name);
1220     std::vector<AbilityInfo> abilityInfos;
1221     EXPECT_TRUE(bundleMgrProxy->QueryAbilityInfosForClone(want, abilityInfos));
1222     EXPECT_EQ(abilityInfos.size(), CLONEINFO_SIZE);
1223     std::string uninstallResult;
1224     UninstallBundle(bundleName, uninstallResult);
1225     EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!";
1226     EXPECT_FALSE(bundleMgrProxy->QueryAbilityInfosForClone(want, abilityInfos));
1227     GTEST_LOG_(INFO) << "END BMS_QueryAbilityInfosForClone_0400";
1228 }
1229 
1230 /**
1231  * @tc.number: BMS_QueryAbilityInfosForClone_0500
1232  * @tc.name: test the QueryAbilityInfosForClone interface to get abilityInfo from an application includes two haps
1233  * @tc.desc: 1.install a third-party application
1234  *           2.clone this application
1235  *           3.get the ability information of the cloned application
1236  */
1237 HWTEST_F(BmsCloneSystemTest, BMS_QueryAbilityInfosForClone_0500, Function | MediumTest | Level1)
1238 {
1239     GTEST_LOG_(INFO) << "START BMS_QueryAbilityInfosForClone_0500";
1240     std::string installresvec;
1241     std::string bundleFilePath1 = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap";
1242     std::string bundleFilePath2 = THIRD_BUNDLE_PATH + "bmsThirdBundle3.hap";
1243     std::string bundleName = "com.example.third1";
1244     std::string entryModule = "com.example.third1";
1245     std::string featureModule = "com.example.third3";
1246     std::string abilityName = "com.example.third1.MainAbility";
1247     InstallBundle(bundleFilePath1, InstallFlag::NORMAL, installresvec);
1248     EXPECT_EQ(installresvec, "Success") << "install fail!";
1249     InstallBundle(bundleFilePath2, InstallFlag::NORMAL, installresvec);
1250     EXPECT_EQ(installresvec, "Success") << "install fail!";
1251     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
1252     if (!bundleMgrProxy) {
1253         GTEST_LOG_(INFO) << "bundle mgr proxy is nullptr.";
1254         EXPECT_NE(bundleMgrProxy, nullptr);
1255     }
1256     EXPECT_TRUE(bundleMgrProxy->BundleClone(bundleName));
1257     Want want;
1258     ElementName name;
1259     name.SetBundleName(bundleName);
1260     name.SetAbilityName(abilityName);
1261     want.SetElement(name);
1262     std::vector<AbilityInfo> abilityInfos;
1263     EXPECT_TRUE(bundleMgrProxy->QueryAbilityInfosForClone(want, abilityInfos));
1264     EXPECT_EQ(abilityInfos.size(), CLONEINFO_SIZE);
1265     EXPECT_EQ(abilityInfos.size(), CLONEINFO_SIZE);
1266     if (abilityInfos.size() == CLONEINFO_SIZE) {
1267         EXPECT_EQ(abilityInfos.at(0).name, abilityInfos.at(1).name);
1268         EXPECT_EQ(abilityInfos.at(0).name, abilityName);
1269         EXPECT_EQ(abilityInfos.at(0).bundleName, abilityInfos.at(1).bundleName);
1270         EXPECT_TRUE(abilityInfos.at(0).applicationInfo.isCloned);
1271         EXPECT_FALSE(abilityInfos.at(1).applicationInfo.isCloned);
1272     }
1273     abilityInfos.clear();
1274     std::string uninstallResult;
1275     UninstallBundle(bundleName, entryModule, uninstallResult);
1276     EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!";
1277     EXPECT_NE(CheckFileExist(BUNDLE_CODE_ROOT_PATH + bundleName + "/" + entryModule), 0);
1278     EXPECT_EQ(CheckFileExist(BUNDLE_CODE_ROOT_PATH + bundleName + "/" + featureModule), 0);
1279     EXPECT_TRUE(bundleMgrProxy->QueryAbilityInfosForClone(want, abilityInfos));
1280     EXPECT_EQ(abilityInfos.size(), NONECLONEINFO_SIZE);
1281     if (!abilityInfos.empty()) {
1282         EXPECT_TRUE(abilityInfos[0].applicationInfo.isCloned);
1283     }
1284     UninstallBundle(bundleName, uninstallResult);
1285     EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!";
1286     GTEST_LOG_(INFO) << "END BMS_QueryAbilityInfosForClone_0500";
1287 }
1288 
1289 /**
1290  * @tc.number: BMS_QueryAbilityInfosForClone_0600
1291  * @tc.name: test the QueryAbilityInfosForClone interface to get abilityInfo from an application includes two haps
1292  * @tc.desc: 1.install a third-party application
1293  *           2.call the QueryAbilityInfosForClone interface to get application's abilityInfo by invalid bundleName
1294  */
1295 HWTEST_F(BmsCloneSystemTest, BMS_QueryAbilityInfosForClone_0600, Function | MediumTest | Level2)
1296 {
1297     GTEST_LOG_(INFO) << "START BMS_QueryAbilityInfosForClone_0600";
1298     std::string installresvec;
1299     std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap";
1300     std::string bundleName = "com.example.third1";
1301     std::string abilityName = "com.example.third1.MainAbility";
1302     InstallBundle(bundleFilePath, InstallFlag::NORMAL, installresvec);
1303     EXPECT_EQ(installresvec, "Success") << "install fail!";
1304     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
1305     if (!bundleMgrProxy) {
1306         GTEST_LOG_(INFO) << "bundle mgr proxy is nullptr.";
1307         EXPECT_NE(bundleMgrProxy, nullptr);
1308     }
1309     Want want;
1310     ElementName name;
1311     name.SetBundleName("");
1312     name.SetAbilityName(abilityName);
1313     want.SetElement(name);
1314     std::vector<AbilityInfo> abilityInfos;
1315     EXPECT_FALSE(bundleMgrProxy->QueryAbilityInfosForClone(want, abilityInfos));
1316     EXPECT_TRUE(abilityInfos.size() == 0);
1317     std::string uninstallResult;
1318     UninstallBundle(bundleName, uninstallResult);
1319     EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!";
1320     GTEST_LOG_(INFO) << "END BMS_QueryAbilityInfosForClone_0600";
1321 }
1322 
1323 /**
1324  * @tc.number: BMS_QueryAbilityInfosForClone_0700
1325  * @tc.name: test the QueryAbilityInfosForClone interface to get abilityInfo from an application includes two haps
1326  * @tc.desc: 1.install a third-party application
1327  *           2.call the QueryAbilityInfosForClone interface to get application's abilityInfo by invalid abilityName
1328  */
1329 HWTEST_F(BmsCloneSystemTest, BMS_QueryAbilityInfosForClone_0700, Function | MediumTest | Level2)
1330 {
1331     GTEST_LOG_(INFO) << "START BMS_QueryAbilityInfosForClone_0700";
1332     std::string installresvec;
1333     std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap";
1334     std::string bundleName = "com.example.third1";
1335     std::string abilityName = "com.example.third3.MainAbility";
1336     InstallBundle(bundleFilePath, InstallFlag::NORMAL, installresvec);
1337     EXPECT_EQ(installresvec, "Success") << "install fail!";
1338     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
1339     if (!bundleMgrProxy) {
1340         GTEST_LOG_(INFO) << "bundle mgr proxy is nullptr.";
1341         EXPECT_NE(bundleMgrProxy, nullptr);
1342     }
1343     Want want;
1344     ElementName name;
1345     name.SetBundleName(bundleName);
1346     name.SetAbilityName("");
1347     want.SetElement(name);
1348     std::vector<AbilityInfo> abilityInfos;
1349     EXPECT_FALSE(bundleMgrProxy->QueryAbilityInfosForClone(want, abilityInfos));
1350     EXPECT_TRUE(abilityInfos.size() == 0);
1351     std::string uninstallResult;
1352     UninstallBundle(bundleName, uninstallResult);
1353     EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!";
1354     GTEST_LOG_(INFO) << "END BMS_QueryAbilityInfosForClone_0700";
1355 }
1356 
1357 /**
1358  * @tc.number: BMS_CloneTestGetBundleNameForUid_0100
1359  * @tc.name: test the GetBundleNameForUid interface to get bundleName by cloned application's uid
1360  * @tc.desc: 1.install a third-party application
1361  *           2.clone this application
1362  *           3.get the bundleName by cloned application's uid
1363  */
1364 HWTEST_F(BmsCloneSystemTest, BMS_CloneTestGetBundleNameForUid_0100, Function | MediumTest | Level1)
1365 {
1366     GTEST_LOG_(INFO) << "START BMS_CloneTestGetBundleNameForUid_0100";
1367     std::string installresvec;
1368     std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap";
1369     std::string bundleName = "com.example.third1";
1370     std::string abilityName = "com.example.third1.MainAbility";
1371     InstallBundle(bundleFilePath, InstallFlag::NORMAL, installresvec);
1372     EXPECT_EQ(installresvec, "Success") << "install fail!";
1373     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
1374     if (!bundleMgrProxy) {
1375         GTEST_LOG_(INFO) << "bundle mgr proxy is nullptr.";
1376         EXPECT_NE(bundleMgrProxy, nullptr);
1377     }
1378     bool cloneResult = bundleMgrProxy->BundleClone(bundleName);
1379     EXPECT_TRUE(cloneResult);
1380     Want want;
1381     ElementName name;
1382     name.SetBundleName(bundleName);
1383     name.SetAbilityName(abilityName);
1384     want.SetElement(name);
1385     std::vector<AbilityInfo> abilityInfos;
1386     bundleMgrProxy->QueryAbilityInfosForClone(want, abilityInfos);
1387     EXPECT_EQ(abilityInfos.size(), CLONEINFO_SIZE);
1388     if (abilityInfos.size() == CLONEINFO_SIZE) {
1389         std::string getBundleName1;
1390         std::string getBundleName2;
1391         EXPECT_TRUE(bundleMgrProxy->GetBundleNameForUid(abilityInfos.at(0).applicationInfo.uid, getBundleName1));
1392         EXPECT_TRUE(bundleMgrProxy->GetBundleNameForUid(abilityInfos.at(1).applicationInfo.uid, getBundleName2));
1393         EXPECT_EQ(getBundleName1, getBundleName2);
1394     }
1395     std::string uninstallResult;
1396     UninstallBundle(bundleName, uninstallResult);
1397     EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!";
1398     GTEST_LOG_(INFO) << "END BMS_CloneTestGetBundleNameForUid_0100";
1399 }
1400 
1401 /**
1402  * @tc.number: BMS_CloneTestGetBundlesForUid_0100
1403  * @tc.name: test the GetBundlesForUid interface to get bundleInfos by cloned application's uid
1404  * @tc.desc: 1.install a third-party application
1405  *           2.clone this application
1406  *           3.get the bundleInfos by cloned application's uid
1407  */
1408 HWTEST_F(BmsCloneSystemTest, BMS_CloneTestGetBundlesForUid_0100, Function | MediumTest | Level1)
1409 {
1410     GTEST_LOG_(INFO) << "START BMS_CloneTestGetBundlesForUid_0100";
1411     std::string installresvec;
1412     std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap";
1413     std::string bundleName = "com.example.third1";
1414     std::string abilityName = "com.example.third1.MainAbility";
1415     InstallBundle(bundleFilePath, InstallFlag::NORMAL, installresvec);
1416     EXPECT_EQ(installresvec, "Success") << "install fail!";
1417     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
1418     if (!bundleMgrProxy) {
1419         GTEST_LOG_(INFO) << "bundle mgr proxy is nullptr.";
1420         EXPECT_NE(bundleMgrProxy, nullptr);
1421     }
1422     bool cloneResult = bundleMgrProxy->BundleClone(bundleName);
1423     EXPECT_TRUE(cloneResult);
1424     Want want;
1425     ElementName name;
1426     name.SetBundleName(bundleName);
1427     name.SetAbilityName(abilityName);
1428     want.SetElement(name);
1429     std::vector<AbilityInfo> abilityInfos;
1430     bundleMgrProxy->QueryAbilityInfosForClone(want, abilityInfos);
1431     EXPECT_EQ(abilityInfos.size(), CLONEINFO_SIZE);
1432     if (abilityInfos.size() == CLONEINFO_SIZE) {
1433         std::vector<std::string> bundleNames1;
1434         std::vector<std::string> bundleNames2;
1435         EXPECT_TRUE(bundleMgrProxy->GetBundlesForUid(abilityInfos.at(0).applicationInfo.uid, bundleNames1));
1436         EXPECT_TRUE(bundleMgrProxy->GetBundlesForUid(abilityInfos.at(1).applicationInfo.uid, bundleNames2));
1437         EXPECT_EQ(bundleNames1.size(), ONE_SIZE);
1438         EXPECT_EQ(bundleNames2.size(), ONE_SIZE);
1439         EXPECT_EQ(bundleNames1.at(0), bundleNames2.at(0));
1440     }
1441     std::string uninstallResult;
1442     UninstallBundle(bundleName, uninstallResult);
1443     EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!";
1444     GTEST_LOG_(INFO) << "END BMS_CloneTestGetBundlesForUid_0100";
1445 }
1446 
1447 /**
1448  * @tc.number: BMS_CloneTestGetNameForUid_0100
1449  * @tc.name: test the BMS_CloneTestGetNameForUid_0100 interface to get name by cloned application's uid
1450  * @tc.desc: 1.install a third-party application
1451  *           2.clone this application
1452  *           3.get the name by cloned application's uid
1453  */
1454 HWTEST_F(BmsCloneSystemTest, BMS_CloneTestGetNameForUid_0100, Function | MediumTest | Level1)
1455 {
1456     GTEST_LOG_(INFO) << "START BMS_CloneTestGetNameForUid_0100";
1457     std::string installresvec;
1458     std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap";
1459     std::string bundleName = "com.example.third1";
1460     std::string abilityName = "com.example.third1.MainAbility";
1461     InstallBundle(bundleFilePath, InstallFlag::NORMAL, installresvec);
1462     EXPECT_EQ(installresvec, "Success") << "install fail!";
1463     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
1464     if (!bundleMgrProxy) {
1465         GTEST_LOG_(INFO) << "bundle mgr proxy is nullptr.";
1466         EXPECT_NE(bundleMgrProxy, nullptr);
1467     }
1468     bool cloneResult = bundleMgrProxy->BundleClone(bundleName);
1469     EXPECT_TRUE(cloneResult);
1470     Want want;
1471     ElementName name;
1472     name.SetBundleName(bundleName);
1473     name.SetAbilityName(abilityName);
1474     want.SetElement(name);
1475     std::vector<AbilityInfo> abilityInfos;
1476     bundleMgrProxy->QueryAbilityInfosForClone(want, abilityInfos);
1477     EXPECT_EQ(abilityInfos.size(), CLONEINFO_SIZE);
1478     if (abilityInfos.size() == CLONEINFO_SIZE) {
1479         std::string getName1;
1480         std::string getName2;
1481         EXPECT_TRUE(bundleMgrProxy->GetNameForUid(abilityInfos.at(0).applicationInfo.uid, getName1));
1482         EXPECT_TRUE(bundleMgrProxy->GetNameForUid(abilityInfos.at(1).applicationInfo.uid, getName2));
1483         EXPECT_EQ(getName1, getName2);
1484     }
1485     std::string uninstallResult;
1486     UninstallBundle(bundleName, uninstallResult);
1487     EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!";
1488     GTEST_LOG_(INFO) << "END BMS_CloneTestGetNameForUid_0100";
1489 }
1490 
1491 /**
1492  * @tc.number: BMS_CloneTestQueryAbilityInfosByUri_0100
1493  * @tc.name: test the BMS_CloneTestQueryAbilityInfosByUri_0100 interface to get cloned data ability's ablityInfos
1494  * @tc.desc: 1.install a third-party application include data ability
1495  *           2.clone this application
1496  *           3.get the ablityInfos by application's uri
1497  */
1498 HWTEST_F(BmsCloneSystemTest, BMS_CloneTestQueryAbilityInfosByUri_0100, Function | MediumTest | Level1)
1499 {
1500     GTEST_LOG_(INFO) << "START BMS_CloneTestQueryAbilityInfosByUri_0100";
1501     std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundleDataAbility.hap";
1502     std::string bundleName = "com.example.dataability";
1503     std::string abilityName = "com.example.dataability.MainAbility";
1504     std::string uri = "dataability://com.test.demo.dataability.UserADataAbility";
1505     std::string message;
1506     InstallBundle(bundleFilePath, InstallFlag::NORMAL, message);
1507     EXPECT_EQ(message, "Success") << "install fail!";
1508     std::string abilityUri = "dataability:///com.test.demo.dataability.UserADataAbility";
1509     std::vector<AbilityInfo> abilityInfos;
1510     sptr<IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
1511     if (!bundleMgrProxy) {
1512         APP_LOGE("bundle mgr proxy is nullptr.");
1513         EXPECT_TRUE(false);
1514     }
1515     EXPECT_TRUE(bundleMgrProxy->BundleClone(bundleName));
1516     EXPECT_TRUE(bundleMgrProxy->QueryAbilityInfosByUri(abilityUri, abilityInfos));
1517     EXPECT_EQ(abilityInfos.size(), CLONEINFO_SIZE);
1518     for (size_t i = 0, len = abilityInfos.size(); i < len; i++) {
1519         EXPECT_EQ(abilityInfos[i].name, abilityName);
1520         EXPECT_EQ(abilityInfos[i].bundleName, bundleName);
1521         EXPECT_EQ(abilityInfos[i].uri, uri);
1522     }
1523     UninstallBundle(bundleName, message);
1524     EXPECT_EQ(message, "Success") << "uninstall fail!";
1525     GTEST_LOG_(INFO) << "END BMS_CloneTestQueryAbilityInfosByUri_0100";
1526 }
1527 }  // namespace AppExecFwk
1528 }  // namespace OHOS