Issue: #I8U4EQ
Description:Add TDD for appService Sig: SIG_ApplicaitonFramework Feature or Bugfix: Feature Binary Source: No Signed-off-by: zhaogan <zhaogan2@huawei.com>
@ -1173,11 +1173,157 @@ ohos_unittest("BmsBundleInstallDriverTest") {
|
||||
}
|
||||
}
|
||||
|
||||
ohos_unittest("BmsBundleAppServiceFwkInstallerTest") {
|
||||
use_exceptions = true
|
||||
module_out_path = module_output_path
|
||||
include_dirs = [ "//third_party/jsoncpp/include" ]
|
||||
sources = bundle_mgr_source
|
||||
sources -= [ "${services_path}/bundlemgr/src/bms_param.cpp" ]
|
||||
sources += [ "${services_path}/bundlemgr/test/mock/src/bms_param.cpp" ]
|
||||
sources -= [ "${services_path}/bundlemgr/src/system_ability_helper.cpp" ]
|
||||
sources += [
|
||||
"${services_path}/bundlemgr/src/aot/aot_executor.cpp",
|
||||
"${services_path}/bundlemgr/src/installd/installd_host_impl.cpp",
|
||||
"${services_path}/bundlemgr/src/installd/installd_operator.cpp",
|
||||
"${services_path}/bundlemgr/test/mock/src/installd_service.cpp",
|
||||
]
|
||||
|
||||
sources += [
|
||||
"${services_path}/bundlemgr/test/mock/src/accesstoken_kit.cpp",
|
||||
"${services_path}/bundlemgr/test/mock/src/installd_permission_mgr.cpp",
|
||||
"${services_path}/bundlemgr/test/mock/src/mock_status_receiver.cpp",
|
||||
"${services_path}/bundlemgr/test/mock/src/system_ability_helper.cpp",
|
||||
]
|
||||
|
||||
sources += bundle_install_sources
|
||||
sources -= [ "${services_path}/bundlemgr/src/installd_client.cpp" ]
|
||||
sources += [ "${services_path}/bundlemgr/test/mock/src/installd_client.cpp" ]
|
||||
|
||||
sources += [ "bms_bundle_app_service_fwk_installer.cpp" ]
|
||||
|
||||
configs = [ "${services_path}/bundlemgr/test:bundlemgr_test_config" ]
|
||||
cflags = []
|
||||
if (target_cpu == "arm") {
|
||||
cflags += [ "-DBINDER_IPC_32BIT" ]
|
||||
}
|
||||
deps = [
|
||||
"${bundle_framework_path}/test/sceneProject/unittest/bundle_app_service/app_service_version1_library1:appService_v1_library1",
|
||||
"${bundle_framework_path}/test/sceneProject/unittest/bundle_app_service/app_service_version1_library2:appService_v1_library2",
|
||||
"${bundle_framework_path}/test/sceneProject/unittest/bundle_app_service/app_service_version2_library1:appService_v2_library1",
|
||||
"${bundle_framework_path}/test/sceneProject/unittest/bundle_app_service/app_service_version2_library2:appService_v2_library2",
|
||||
"${bundle_framework_path}/test/sceneProject/unittest/test_bundle/rightTest:rightTest",
|
||||
"${core_path}:appexecfwk_core",
|
||||
]
|
||||
deps += bundle_install_deps
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"access_token:libprivacy_sdk",
|
||||
"access_token:libtokenid_sdk",
|
||||
"appverify:libhapverify",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"eventhandler:libeventhandler",
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"init:libbegetutil",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
external_deps += bundle_install_external_deps
|
||||
|
||||
defines = []
|
||||
if (configpolicy_enable) {
|
||||
external_deps += [ "config_policy:configpolicy_util" ]
|
||||
defines += [ "CONFIG_POLOCY_ENABLE" ]
|
||||
}
|
||||
|
||||
if (bundle_framework_app_control) {
|
||||
defines += [ "BUNDLE_FRAMEWORK_APP_CONTROL" ]
|
||||
sources += [
|
||||
"${services_path}/bundlemgr/src/app_control/app_control_manager.cpp",
|
||||
"${services_path}/bundlemgr/src/app_control/app_control_manager_host_impl.cpp",
|
||||
"${services_path}/bundlemgr/src/app_control/app_control_manager_rdb.cpp",
|
||||
"${services_path}/bundlemgr/src/app_control/app_jump_interceptor_event_subscriber.cpp",
|
||||
"${services_path}/bundlemgr/src/app_control/app_jump_interceptor_manager_rdb.cpp",
|
||||
]
|
||||
include_dirs += [ "${services_path}/bundlemgr/include/app_control" ]
|
||||
external_deps += [ "c_utils:utils" ]
|
||||
}
|
||||
if (current_cpu == "arm64") {
|
||||
defines += [ "USE_BUNDLE_EXTENSION" ]
|
||||
}
|
||||
|
||||
if (build_selinux) {
|
||||
external_deps += [ "selinux_adapter:libhap_restorecon" ]
|
||||
cflags += [ "-DWITH_SELINUX" ]
|
||||
}
|
||||
if (account_enable) {
|
||||
external_deps += [ "os_account:os_account_innerkits" ]
|
||||
defines += [ "ACCOUNT_ENABLE" ]
|
||||
}
|
||||
if (bundle_framework_free_install) {
|
||||
sources += aging
|
||||
sources += free_install
|
||||
sources += distributed_manager
|
||||
external_deps += [
|
||||
"ability_runtime:ability_manager",
|
||||
"ability_runtime:app_manager",
|
||||
"battery_manager:batterysrv_client",
|
||||
"device_info_manager:distributed_device_profile_client",
|
||||
"device_usage_statistics:usagestatsinner",
|
||||
"display_manager:displaymgr",
|
||||
"power_manager:powermgr_client",
|
||||
"syscap_codec:syscap_interface_shared",
|
||||
]
|
||||
defines += [ "BUNDLE_FRAMEWORK_FREE_INSTALL" ]
|
||||
}
|
||||
if (global_resmgr_enable) {
|
||||
defines += [ "GLOBAL_RESMGR_ENABLE" ]
|
||||
external_deps += [ "resource_management:global_resmgr" ]
|
||||
}
|
||||
if (hicollie_enable) {
|
||||
external_deps += [ "hicollie:libhicollie" ]
|
||||
defines += [ "HICOLLIE_ENABLE" ]
|
||||
}
|
||||
|
||||
if (hisysevent_enable) {
|
||||
sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ]
|
||||
external_deps += [ "hisysevent:libhisysevent" ]
|
||||
defines += [ "HISYSEVENT_ENABLE" ]
|
||||
}
|
||||
|
||||
if (bundle_framework_quick_fix) {
|
||||
include_dirs += [ "${services_path}/bundlemgr/src/include/quick_fix" ]
|
||||
sources += quick_fix
|
||||
defines += [ "BUNDLE_FRAMEWORK_QUICK_FIX" ]
|
||||
}
|
||||
|
||||
if (storage_service_enable) {
|
||||
external_deps += [ "storage_service:storage_manager_sa_proxy" ]
|
||||
defines += [ "STORAGE_SERVICE_ENABLE" ]
|
||||
}
|
||||
|
||||
external_deps += [ "kv_store:distributeddata_inner" ]
|
||||
configs += [ "../../../../../services/bundlemgr:rdb_config" ]
|
||||
external_deps += [ "relational_store:native_rdb" ]
|
||||
sources += [
|
||||
"${services_path}/bundlemgr/src/bundle_data_storage_rdb.cpp",
|
||||
"${services_path}/bundlemgr/src/preinstall_data_storage_rdb.cpp",
|
||||
"${services_path}/bundlemgr/src/rdb/bms_rdb_open_callback.cpp",
|
||||
"${services_path}/bundlemgr/src/rdb/rdb_data_manager.cpp",
|
||||
]
|
||||
if (udmf_enabled) {
|
||||
defines += [ "BUNDLE_FRAMEWORK_UDMF_ENABLED" ]
|
||||
external_deps += [ "udmf:udmf_client" ]
|
||||
}
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
|
||||
if (ability_runtime_enable) {
|
||||
deps = [
|
||||
":BmsBundleAppServiceFwkInstallerTest",
|
||||
":BmsBundleInstallCheckerTest",
|
||||
":BmsBundleInstallDeviceTypeTest",
|
||||
":BmsBundleInstallDriverTest",
|
||||
|
@ -0,0 +1,796 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define private public
|
||||
#define protected public
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <fstream>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "app_service_fwk/app_service_fwk_installer.h"
|
||||
#include "bundle_mgr_service.h"
|
||||
#include "directory_ex.h"
|
||||
#include "install_param.h"
|
||||
#include "installd/installd_service.h"
|
||||
#include "installd_client.h"
|
||||
#include "mock_status_receiver.h"
|
||||
#include "scope_guard.h"
|
||||
#include "shared/shared_bundle_installer.h"
|
||||
#include "system_bundle_installer.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace std::chrono_literals;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
using OHOS::DelayedSingleton;
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
const int32_t DEFAULT_USERID = 0;
|
||||
const int32_t USERID = 100;
|
||||
const int32_t VERSION_LOW = 0;
|
||||
const int32_t VERSION = 1000000;
|
||||
const int32_t WAIT_TIME = 5; // init mocked bms
|
||||
const int32_t VERSION_HIGH = INT32_MAX;
|
||||
const std::string BUNDLE_NAME = "com.example.appService";
|
||||
const std::string BUNDLE_NAME_WRONG = "com.example.appService.wrong";
|
||||
const std::string BUNDLE_NAME_TEST = "com.example.l3jsdemo";
|
||||
const std::string MODULE_NAME_TEST = "moduleName";
|
||||
const std::string MODULE_NAME_LIBRARY_ONE = "library_one";
|
||||
const std::string EMPTY_STRING = "";
|
||||
const std::string HAP_PATH_TEST = "/data/test/resource/bms/app_service_test/right.hap";
|
||||
const std::string VERSION_ONE_LIBRARY_ONE_PATH = "/data/test/resource/bms/app_service_test/appService_v1_library1.hsp";
|
||||
const std::string VERSION_ONE_LIBRARY_TWO_PATH = "/data/test/resource/bms/app_service_test/appService_v1_library2.hsp";
|
||||
const std::string BUNDLE_DATA_DIR = "/data/app/el2/100/base/com.example.l3jsdemo";
|
||||
const std::string BUNDLE_CODE_DIR = "/data/app/el1/bundle/public/com.example.l3jsdemo";
|
||||
const std::string BUNDLE_LIBRARY_PATH_DIR = "/data/app/el1/bundle/public/com.example.l3jsdemo/libs/arm";
|
||||
const std::string TEST_CREATE_FILE_PATH = "/data/test/resource/bms/app_service_test/test_create_dir/test.hap";
|
||||
const std::string BUILD_HASH = "8670157ae28ac2dc08075c4a9364e320898b4aaf4c1ab691df6afdb854a6811b";
|
||||
} // namespace
|
||||
|
||||
class BmsBundleAppServiceFwkInstallerTest : public testing::Test {
|
||||
public:
|
||||
BmsBundleAppServiceFwkInstallerTest();
|
||||
~BmsBundleAppServiceFwkInstallerTest();
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
ErrCode InstallSystemBundle(const std::string &filePath, int32_t userId) const;
|
||||
ErrCode UnInstallBundle(const std::string &bundleName, int32_t userId) const;
|
||||
ErrCode InstallSystemHsp(const std::string &filePath);
|
||||
bool DeletePreBundleInfo(const std::string &bundleName);
|
||||
const std::shared_ptr<BundleDataMgr> GetBundleDataMgr() const;
|
||||
const std::shared_ptr<BundleInstallerManager> GetBundleInstallerManager() const;
|
||||
void AddBundleInfo(const std::string &bundleName, const InnerBundleInfo& info);
|
||||
void DeleteBundleInfo(const std::string &bundleName);
|
||||
void StopInstalldService() const;
|
||||
void StopBundleService();
|
||||
void CreateInstallerManager();
|
||||
void ClearBundleInfo(const std::string &bundleName);
|
||||
void ClearDataMgr();
|
||||
void ResetDataMgr();
|
||||
void InitAppServiceFwkInstaller(AppServiceFwkInstaller &appServiceFwkInstaller);
|
||||
|
||||
private:
|
||||
std::shared_ptr<BundleInstallerManager> manager_ = nullptr;
|
||||
static std::shared_ptr<InstalldService> installdService_;
|
||||
static std::shared_ptr<BundleMgrService> bundleMgrService_;
|
||||
};
|
||||
|
||||
std::shared_ptr<BundleMgrService> BmsBundleAppServiceFwkInstallerTest::bundleMgrService_ =
|
||||
DelayedSingleton<BundleMgrService>::GetInstance();
|
||||
|
||||
std::shared_ptr<InstalldService> BmsBundleAppServiceFwkInstallerTest::installdService_ =
|
||||
std::make_shared<InstalldService>();
|
||||
|
||||
BmsBundleAppServiceFwkInstallerTest::BmsBundleAppServiceFwkInstallerTest()
|
||||
{}
|
||||
|
||||
BmsBundleAppServiceFwkInstallerTest::~BmsBundleAppServiceFwkInstallerTest()
|
||||
{}
|
||||
|
||||
ErrCode BmsBundleAppServiceFwkInstallerTest::InstallSystemHsp(const std::string &filePath)
|
||||
{
|
||||
AppServiceFwkInstaller appServiceFwkInstaller;
|
||||
InitAppServiceFwkInstaller(appServiceFwkInstaller);
|
||||
InstallParam installParam;
|
||||
installParam.isPreInstallApp = true;
|
||||
installParam.removable = false;
|
||||
std::vector<std::string> hspPaths{ filePath };
|
||||
return appServiceFwkInstaller.Install(hspPaths, installParam);
|
||||
}
|
||||
|
||||
ErrCode BmsBundleAppServiceFwkInstallerTest::InstallSystemBundle(const std::string &filePath, int32_t userId) const
|
||||
{
|
||||
bundleMgrService_->GetDataMgr()->AddUserId(USERID);
|
||||
auto installer = std::make_unique<SystemBundleInstaller>();
|
||||
InstallParam installParam;
|
||||
installParam.userId = userId;
|
||||
installParam.isPreInstallApp = true;
|
||||
installParam.noSkipsKill = false;
|
||||
installParam.needSendEvent = false;
|
||||
installParam.needSavePreInstallInfo = true;
|
||||
installParam.copyHapToInstallPath = false;
|
||||
return installer->InstallSystemBundle(
|
||||
filePath, installParam, Constants::AppType::SYSTEM_APP);
|
||||
}
|
||||
|
||||
ErrCode BmsBundleAppServiceFwkInstallerTest::UnInstallBundle(const std::string &bundleName, int32_t userId) const
|
||||
{
|
||||
auto installer = bundleMgrService_->GetBundleInstaller();
|
||||
if (!installer) {
|
||||
EXPECT_FALSE(true) << "the installer is nullptr";
|
||||
return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR;
|
||||
}
|
||||
sptr<MockStatusReceiver> receiver = new (std::nothrow) MockStatusReceiver();
|
||||
if (!receiver) {
|
||||
EXPECT_FALSE(true) << "the receiver is nullptr";
|
||||
return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR;
|
||||
}
|
||||
InstallParam installParam;
|
||||
installParam.userId = userId;
|
||||
installParam.installFlag = InstallFlag::NORMAL;
|
||||
bool result = installer->Uninstall(bundleName, installParam, receiver);
|
||||
EXPECT_TRUE(result);
|
||||
return receiver->GetResultCode();
|
||||
}
|
||||
|
||||
void BmsBundleAppServiceFwkInstallerTest::SetUpTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void BmsBundleAppServiceFwkInstallerTest::InitAppServiceFwkInstaller(AppServiceFwkInstaller &appServiceFwkInstaller)
|
||||
{
|
||||
std::vector<std::string> hspPaths;
|
||||
hspPaths.push_back(VERSION_ONE_LIBRARY_ONE_PATH);
|
||||
InstallParam installParam;
|
||||
installParam.isPreInstallApp = true;
|
||||
|
||||
appServiceFwkInstaller.BeforeInstall(hspPaths, installParam);
|
||||
appServiceFwkInstaller.versionUpgrade_ = false;
|
||||
appServiceFwkInstaller.moduleUpdate_ = false;
|
||||
}
|
||||
|
||||
void BmsBundleAppServiceFwkInstallerTest::TearDownTestCase()
|
||||
{
|
||||
bundleMgrService_->OnStop();
|
||||
}
|
||||
|
||||
void BmsBundleAppServiceFwkInstallerTest::SetUp()
|
||||
{
|
||||
if (!installdService_->IsServiceReady()) {
|
||||
installdService_->Start();
|
||||
}
|
||||
if (!bundleMgrService_->IsServiceReady()) {
|
||||
bundleMgrService_->OnStart();
|
||||
bundleMgrService_->GetDataMgr()->AddUserId(USERID);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME));
|
||||
}
|
||||
}
|
||||
|
||||
void BmsBundleAppServiceFwkInstallerTest::TearDown()
|
||||
{
|
||||
OHOS::ForceRemoveDirectory(BUNDLE_DATA_DIR);
|
||||
OHOS::ForceRemoveDirectory(BUNDLE_CODE_DIR);
|
||||
OHOS::ForceRemoveDirectory(BUNDLE_LIBRARY_PATH_DIR);
|
||||
}
|
||||
|
||||
const std::shared_ptr<BundleDataMgr> BmsBundleAppServiceFwkInstallerTest::GetBundleDataMgr() const
|
||||
{
|
||||
return bundleMgrService_->GetDataMgr();
|
||||
}
|
||||
|
||||
const std::shared_ptr<BundleInstallerManager> BmsBundleAppServiceFwkInstallerTest::GetBundleInstallerManager() const
|
||||
{
|
||||
return manager_;
|
||||
}
|
||||
|
||||
void BmsBundleAppServiceFwkInstallerTest::ClearDataMgr()
|
||||
{
|
||||
bundleMgrService_->dataMgr_ = nullptr;
|
||||
}
|
||||
|
||||
void BmsBundleAppServiceFwkInstallerTest::ResetDataMgr()
|
||||
{
|
||||
bundleMgrService_->dataMgr_ = std::make_shared<BundleDataMgr>();
|
||||
EXPECT_NE(bundleMgrService_->dataMgr_, nullptr);
|
||||
}
|
||||
|
||||
void BmsBundleAppServiceFwkInstallerTest::StopInstalldService() const
|
||||
{
|
||||
if (installdService_->IsServiceReady()) {
|
||||
installdService_->Stop();
|
||||
InstalldClient::GetInstance()->ResetInstalldProxy();
|
||||
}
|
||||
}
|
||||
|
||||
void BmsBundleAppServiceFwkInstallerTest::StopBundleService()
|
||||
{
|
||||
if (bundleMgrService_->IsServiceReady()) {
|
||||
bundleMgrService_->OnStop();
|
||||
bundleMgrService_.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void BmsBundleAppServiceFwkInstallerTest::CreateInstallerManager()
|
||||
{
|
||||
if (manager_ != nullptr) {
|
||||
return;
|
||||
}
|
||||
manager_ = std::make_shared<BundleInstallerManager>();
|
||||
EXPECT_NE(nullptr, manager_);
|
||||
}
|
||||
|
||||
void BmsBundleAppServiceFwkInstallerTest::ClearBundleInfo(const std::string &bundleName)
|
||||
{
|
||||
if (bundleMgrService_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
auto dataMgr = bundleMgrService_->GetDataMgr();
|
||||
if (dataMgr == nullptr) {
|
||||
return;
|
||||
}
|
||||
auto dataStorage = dataMgr->GetDataStorage();
|
||||
if (dataStorage == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
// clear innerBundleInfo from data manager
|
||||
dataMgr->UpdateBundleInstallState(bundleName, InstallState::UNINSTALL_START);
|
||||
dataMgr->UpdateBundleInstallState(bundleName, InstallState::UNINSTALL_SUCCESS);
|
||||
|
||||
InnerBundleInfo innerBundleInfo;
|
||||
ApplicationInfo applicationInfo;
|
||||
applicationInfo.bundleName = bundleName;
|
||||
innerBundleInfo.SetBaseApplicationInfo(applicationInfo);
|
||||
// clear innerBundleInfo from data storage
|
||||
bool result = dataStorage->DeleteStorageBundleInfo(innerBundleInfo);
|
||||
EXPECT_TRUE(result) << "the bundle info in db clear fail: " << bundleName;
|
||||
}
|
||||
|
||||
void BmsBundleAppServiceFwkInstallerTest::AddBundleInfo(const std::string &bundleName, const InnerBundleInfo& info)
|
||||
{
|
||||
if (bundleMgrService_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
auto dataMgr = bundleMgrService_->GetDataMgr();
|
||||
if (dataMgr == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
dataMgr->bundleInfos_[bundleName] = info;
|
||||
}
|
||||
|
||||
void BmsBundleAppServiceFwkInstallerTest::DeleteBundleInfo(const std::string &bundleName)
|
||||
{
|
||||
if (bundleMgrService_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
auto dataMgr = bundleMgrService_->GetDataMgr();
|
||||
if (dataMgr == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
dataMgr->bundleInfos_.erase(bundleName);
|
||||
}
|
||||
|
||||
bool BmsBundleAppServiceFwkInstallerTest::DeletePreBundleInfo(const std::string &bundleName)
|
||||
{
|
||||
auto dataMgr = bundleMgrService_->GetDataMgr();
|
||||
if (dataMgr == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PreInstallBundleInfo preInstallBundleInfo;
|
||||
bool getRes = dataMgr->GetPreInstallBundleInfo(bundleName, preInstallBundleInfo);
|
||||
if (!getRes) {
|
||||
return false;
|
||||
}
|
||||
return dataMgr->DeletePreInstallBundleInfo(bundleName, preInstallBundleInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: BeforeInstall_0100
|
||||
* @tc.name: test BeforeInstall
|
||||
* @tc.desc: 1.Test the BeforeInstall
|
||||
*/
|
||||
HWTEST_F(BmsBundleAppServiceFwkInstallerTest, BeforeInstall_0100, Function | SmallTest | Level0)
|
||||
{
|
||||
AppServiceFwkInstaller appServiceFwkInstaller;
|
||||
std::vector<std::string> hspPaths;
|
||||
hspPaths.push_back(TEST_CREATE_FILE_PATH);
|
||||
InstallParam installParam;
|
||||
installParam.isPreInstallApp = false;
|
||||
|
||||
auto res = appServiceFwkInstaller.BeforeInstall(hspPaths, installParam);
|
||||
EXPECT_EQ(res, ERR_APP_SERVICE_FWK_INSTALL_NOT_PREINSTALL);
|
||||
|
||||
installParam.isPreInstallApp = true;
|
||||
res = appServiceFwkInstaller.BeforeInstall(hspPaths, installParam);
|
||||
EXPECT_EQ(res, ERR_OK);
|
||||
|
||||
ClearDataMgr();
|
||||
res = appServiceFwkInstaller.BeforeInstall(hspPaths, installParam);
|
||||
EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_BUNDLE_MGR_SERVICE_ERROR);
|
||||
ResetDataMgr();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: CheckFileType_0100
|
||||
* @tc.name: test CheckFileType
|
||||
* @tc.desc: 1.Test the CheckFileType
|
||||
*/
|
||||
HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckFileType_0100, Function | SmallTest | Level0)
|
||||
{
|
||||
AppServiceFwkInstaller appServiceFwkInstaller;
|
||||
std::vector<std::string> hspPaths;
|
||||
auto res = appServiceFwkInstaller.CheckFileType(hspPaths);
|
||||
EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_PARAM_ERROR);
|
||||
|
||||
hspPaths.push_back(TEST_CREATE_FILE_PATH);
|
||||
res = appServiceFwkInstaller.CheckFileType(hspPaths);
|
||||
EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_INVALID_HAP_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: CheckAppLabelInfo_0100
|
||||
* @tc.name: test CheckAppLabelInfo
|
||||
* @tc.desc: 1.Test the CheckAppLabelInfo
|
||||
*/
|
||||
HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckAppLabelInfo_0100, Function | SmallTest | Level0)
|
||||
{
|
||||
AppServiceFwkInstaller appServiceFwkInstaller;
|
||||
InnerBundleInfo innerBundleInfo;
|
||||
innerBundleInfo.baseApplicationInfo_->bundleType = BundleType::APP;
|
||||
std::unordered_map<std::string, InnerBundleInfo> infos;
|
||||
infos.emplace(TEST_CREATE_FILE_PATH, innerBundleInfo);
|
||||
auto res = appServiceFwkInstaller.CheckAppLabelInfo(infos);
|
||||
EXPECT_EQ(res, ERR_APP_SERVICE_FWK_INSTALL_TYPE_FAILED);
|
||||
|
||||
innerBundleInfo.baseApplicationInfo_->bundleType = BundleType::APP_SERVICE_FWK;
|
||||
res = appServiceFwkInstaller.CheckAppLabelInfo(infos);
|
||||
EXPECT_EQ(res, ERR_OK);
|
||||
|
||||
innerBundleInfo.currentPackage_ = MODULE_NAME_TEST;
|
||||
InnerModuleInfo innerModuleInfo;
|
||||
innerModuleInfo.moduleName = MODULE_NAME_TEST;
|
||||
innerBundleInfo.innerModuleInfos_.emplace(MODULE_NAME_TEST, innerModuleInfo);
|
||||
res = appServiceFwkInstaller.CheckAppLabelInfo(infos);
|
||||
EXPECT_EQ(res, ERR_OK);
|
||||
|
||||
innerModuleInfo.bundleType = BundleType::SHARED;
|
||||
res = appServiceFwkInstaller.CheckAppLabelInfo(infos);
|
||||
EXPECT_EQ(res, ERR_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: CheckNeedInstall_0100
|
||||
* @tc.name: test CheckNeedInstall
|
||||
* @tc.desc: 1.Test the CheckNeedInstall
|
||||
*/
|
||||
HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckNeedInstall_0100, Function | SmallTest | Level0)
|
||||
{
|
||||
AppServiceFwkInstaller appServiceFwkInstaller;
|
||||
std::unordered_map<std::string, InnerBundleInfo> infos;
|
||||
InnerBundleInfo oldInfo;
|
||||
bool result = appServiceFwkInstaller.CheckNeedInstall(infos, oldInfo);
|
||||
EXPECT_FALSE(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: CheckNeedInstall_0200
|
||||
* @tc.name: test CheckNeedInstall
|
||||
* @tc.desc: 1.Test the CheckNeedInstall
|
||||
*/
|
||||
HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckNeedInstall_0200, Function | SmallTest | Level0)
|
||||
{
|
||||
AppServiceFwkInstaller appServiceFwkInstaller;
|
||||
InitAppServiceFwkInstaller(appServiceFwkInstaller);
|
||||
std::unordered_map<std::string, InnerBundleInfo> infos;
|
||||
InnerBundleInfo oldInfo;
|
||||
|
||||
appServiceFwkInstaller.bundleName_ = BUNDLE_NAME_WRONG;
|
||||
infos[VERSION_ONE_LIBRARY_ONE_PATH] = oldInfo;
|
||||
bool result = appServiceFwkInstaller.CheckNeedInstall(infos, oldInfo);
|
||||
EXPECT_TRUE(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: CheckNeedInstall_0300
|
||||
* @tc.name: test CheckNeedInstall
|
||||
* @tc.desc: 1.Test the CheckNeedInstall
|
||||
*/
|
||||
HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckNeedInstall_0300, Function | SmallTest | Level0)
|
||||
{
|
||||
AppServiceFwkInstaller appServiceFwkInstaller;
|
||||
InitAppServiceFwkInstaller(appServiceFwkInstaller);
|
||||
std::unordered_map<std::string, InnerBundleInfo> infos;
|
||||
auto result = InstallSystemBundle(HAP_PATH_TEST, USERID);
|
||||
ASSERT_EQ(result, ERR_OK);
|
||||
|
||||
appServiceFwkInstaller.bundleName_ = BUNDLE_NAME_TEST;
|
||||
|
||||
InnerBundleInfo oldInfo;
|
||||
infos[VERSION_ONE_LIBRARY_ONE_PATH] = oldInfo;
|
||||
bool result1 = appServiceFwkInstaller.CheckNeedInstall(infos, oldInfo);
|
||||
EXPECT_FALSE(result1);
|
||||
|
||||
ClearBundleInfo(BUNDLE_NAME_TEST);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: CheckNeedInstall_0400
|
||||
* @tc.name: test CheckNeedInstall
|
||||
* @tc.desc: 1.Test the CheckNeedInstall
|
||||
*/
|
||||
HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckNeedInstall_0400, Function | SmallTest | Level0)
|
||||
{
|
||||
AppServiceFwkInstaller appServiceFwkInstaller;
|
||||
InitAppServiceFwkInstaller(appServiceFwkInstaller);
|
||||
std::unordered_map<std::string, InnerBundleInfo> infos;
|
||||
InnerBundleInfo newInfo;
|
||||
ApplicationInfo applicationInfo;
|
||||
applicationInfo.bundleName = BUNDLE_NAME;
|
||||
newInfo.SetBaseApplicationInfo(applicationInfo);
|
||||
AddBundleInfo(BUNDLE_NAME, newInfo);
|
||||
|
||||
appServiceFwkInstaller.bundleName_ = BUNDLE_NAME;
|
||||
appServiceFwkInstaller.versionCode_ = VERSION_LOW;
|
||||
infos[VERSION_ONE_LIBRARY_ONE_PATH] = newInfo;
|
||||
|
||||
InnerBundleInfo oldInfo;
|
||||
bool result = appServiceFwkInstaller.CheckNeedInstall(infos, oldInfo);
|
||||
EXPECT_FALSE(result);
|
||||
|
||||
DeleteBundleInfo(BUNDLE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: CheckNeedInstall_0500
|
||||
* @tc.name: test CheckNeedInstall
|
||||
* @tc.desc: 1.Test the CheckNeedInstall
|
||||
*/
|
||||
HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckNeedInstall_0500, Function | SmallTest | Level0)
|
||||
{
|
||||
AppServiceFwkInstaller appServiceFwkInstaller;
|
||||
InitAppServiceFwkInstaller(appServiceFwkInstaller);
|
||||
std::unordered_map<std::string, InnerBundleInfo> infos;
|
||||
|
||||
InnerBundleInfo innerBundleInfo;
|
||||
ApplicationInfo applicationInfo;
|
||||
applicationInfo.bundleName = BUNDLE_NAME;
|
||||
innerBundleInfo.baseBundleInfo_->versionCode = VERSION;
|
||||
innerBundleInfo.SetBaseApplicationInfo(applicationInfo);
|
||||
AddBundleInfo(BUNDLE_NAME, innerBundleInfo);
|
||||
auto dataMgr = bundleMgrService_->GetDataMgr();
|
||||
ASSERT_NE(dataMgr, nullptr);
|
||||
|
||||
|
||||
InnerBundleInfo newInfo;
|
||||
bool getRes = dataMgr->FetchInnerBundleInfo(BUNDLE_NAME, newInfo);
|
||||
EXPECT_TRUE(getRes);
|
||||
|
||||
appServiceFwkInstaller.bundleName_ = BUNDLE_NAME;
|
||||
appServiceFwkInstaller.versionCode_ = newInfo.GetVersionCode();
|
||||
infos[VERSION_ONE_LIBRARY_ONE_PATH] = newInfo;
|
||||
|
||||
InnerBundleInfo oldInfo;
|
||||
bool result = appServiceFwkInstaller.CheckNeedInstall(infos, oldInfo);
|
||||
EXPECT_FALSE(result);
|
||||
|
||||
DeleteBundleInfo(BUNDLE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: CheckNeedUpdate_0100
|
||||
* @tc.name: test CheckNeedUpdate
|
||||
* @tc.desc: 1.Test the CheckNeedUpdate
|
||||
*/
|
||||
HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckNeedUpdate_0100, Function | SmallTest | Level0)
|
||||
{
|
||||
AppServiceFwkInstaller appServiceFwkInstaller;
|
||||
appServiceFwkInstaller.versionCode_ = VERSION;
|
||||
|
||||
InnerBundleInfo oldInfo;
|
||||
oldInfo.baseBundleInfo_->versionCode = VERSION_HIGH;
|
||||
InnerBundleInfo newInfo;
|
||||
|
||||
bool res = appServiceFwkInstaller.CheckNeedUpdate(newInfo, oldInfo);
|
||||
EXPECT_FALSE(res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: CheckNeedUpdate_0200
|
||||
* @tc.name: test CheckNeedUpdate
|
||||
* @tc.desc: 1.Test the CheckNeedUpdate
|
||||
*/
|
||||
HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckNeedUpdate_0200, Function | SmallTest | Level0)
|
||||
{
|
||||
AppServiceFwkInstaller appServiceFwkInstaller;
|
||||
appServiceFwkInstaller.versionCode_ = VERSION_HIGH;
|
||||
|
||||
InnerBundleInfo oldInfo;
|
||||
oldInfo.baseBundleInfo_->versionCode = VERSION;
|
||||
InnerBundleInfo newInfo;
|
||||
|
||||
bool res = appServiceFwkInstaller.CheckNeedUpdate(newInfo, oldInfo);
|
||||
EXPECT_TRUE(appServiceFwkInstaller.versionUpgrade_);
|
||||
EXPECT_TRUE(res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: CheckNeedUpdate_0300
|
||||
* @tc.name: test CheckNeedUpdate
|
||||
* @tc.desc: 1.Test the CheckNeedUpdate
|
||||
*/
|
||||
HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckNeedUpdate_0300, Function | SmallTest | Level0)
|
||||
{
|
||||
AppServiceFwkInstaller appServiceFwkInstaller;
|
||||
appServiceFwkInstaller.versionCode_ = VERSION;
|
||||
|
||||
InnerBundleInfo oldInfo;
|
||||
oldInfo.baseBundleInfo_->versionCode = VERSION;
|
||||
InnerBundleInfo newInfo;
|
||||
newInfo.currentPackage_ = MODULE_NAME_TEST;
|
||||
|
||||
bool res = appServiceFwkInstaller.CheckNeedUpdate(newInfo, oldInfo);
|
||||
EXPECT_TRUE(appServiceFwkInstaller.moduleUpdate_);
|
||||
EXPECT_TRUE(res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: CheckNeedUpdate_0400
|
||||
* @tc.name: test CheckNeedUpdate
|
||||
* @tc.desc: 1.Test the CheckNeedUpdate
|
||||
*/
|
||||
HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckNeedUpdate_0400, Function | SmallTest | Level0)
|
||||
{
|
||||
AppServiceFwkInstaller appServiceFwkInstaller;
|
||||
appServiceFwkInstaller.versionCode_ = VERSION;
|
||||
|
||||
InnerBundleInfo oldInfo;
|
||||
oldInfo.baseBundleInfo_->versionCode = VERSION;
|
||||
oldInfo.currentPackage_ = MODULE_NAME_TEST;
|
||||
|
||||
InnerModuleInfo innerModuleInfo;
|
||||
innerModuleInfo.moduleName = MODULE_NAME_TEST;
|
||||
oldInfo.innerModuleInfos_[MODULE_NAME_TEST] = innerModuleInfo;
|
||||
InnerBundleInfo newInfo;
|
||||
newInfo.currentPackage_ = MODULE_NAME_TEST;
|
||||
newInfo.innerModuleInfos_[MODULE_NAME_TEST] = innerModuleInfo;
|
||||
|
||||
bool res = appServiceFwkInstaller.CheckNeedUpdate(newInfo, oldInfo);
|
||||
EXPECT_FALSE(appServiceFwkInstaller.moduleUpdate_);
|
||||
EXPECT_FALSE(res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: CheckNeedUpdate_0500
|
||||
* @tc.name: test CheckNeedUpdate
|
||||
* @tc.desc: 1.Test the CheckNeedUpdate
|
||||
*/
|
||||
HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckNeedUpdate_0500, Function | SmallTest | Level0)
|
||||
{
|
||||
AppServiceFwkInstaller appServiceFwkInstaller;
|
||||
appServiceFwkInstaller.versionCode_ = VERSION;
|
||||
|
||||
InnerBundleInfo oldInfo;
|
||||
oldInfo.baseBundleInfo_->versionCode = VERSION;
|
||||
oldInfo.currentPackage_ = MODULE_NAME_TEST;
|
||||
|
||||
InnerModuleInfo innerModuleInfo;
|
||||
innerModuleInfo.moduleName = MODULE_NAME_TEST;
|
||||
oldInfo.innerModuleInfos_[MODULE_NAME_TEST] = innerModuleInfo;
|
||||
|
||||
InnerBundleInfo newInfo;
|
||||
newInfo.currentPackage_ = MODULE_NAME_TEST;
|
||||
innerModuleInfo.buildHash = BUILD_HASH;
|
||||
newInfo.innerModuleInfos_[MODULE_NAME_TEST] = innerModuleInfo;
|
||||
|
||||
bool res = appServiceFwkInstaller.CheckNeedUpdate(newInfo, oldInfo);
|
||||
EXPECT_TRUE(appServiceFwkInstaller.moduleUpdate_);
|
||||
EXPECT_TRUE(res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: RemoveBundleCodeDir_0010
|
||||
* @tc.name: test RemoveBundleCodeDir
|
||||
* @tc.desc: 1.Test the RemoveBundleCodeDir
|
||||
*/
|
||||
HWTEST_F(BmsBundleAppServiceFwkInstallerTest, RemoveBundleCodeDir_0010, Function | SmallTest | Level0)
|
||||
{
|
||||
AppServiceFwkInstaller appServiceFwkInstaller;
|
||||
|
||||
InnerBundleInfo info;
|
||||
auto res = appServiceFwkInstaller.RemoveBundleCodeDir(info);
|
||||
appServiceFwkInstaller.RemoveInfo(EMPTY_STRING);
|
||||
EXPECT_NE(res, ERR_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: GetInnerBundleInfo_0010
|
||||
* @tc.name: test GetInnerBundleInfo
|
||||
* @tc.desc: 1.Test the GetInnerBundleInfo
|
||||
*/
|
||||
HWTEST_F(BmsBundleAppServiceFwkInstallerTest, GetInnerBundleInfo_0010, Function | SmallTest | Level0)
|
||||
{
|
||||
AppServiceFwkInstaller appServiceFwkInstaller;
|
||||
appServiceFwkInstaller.bundleName_ = BUNDLE_NAME;
|
||||
|
||||
InnerBundleInfo info;
|
||||
bool isAppExist;
|
||||
auto res = appServiceFwkInstaller.GetInnerBundleInfo(info, isAppExist);
|
||||
EXPECT_FALSE(isAppExist);
|
||||
EXPECT_TRUE(res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: UninstallLowerVersion_0010
|
||||
* @tc.name: test UninstallLowerVersion
|
||||
* @tc.desc: 1.Test the UninstallLowerVersion
|
||||
*/
|
||||
HWTEST_F(BmsBundleAppServiceFwkInstallerTest, UninstallLowerVersion_0010, Function | SmallTest | Level0)
|
||||
{
|
||||
AppServiceFwkInstaller appServiceFwkInstaller;
|
||||
appServiceFwkInstaller.bundleName_ = BUNDLE_NAME;
|
||||
|
||||
std::vector<std::string> moduleNameList;
|
||||
auto res = appServiceFwkInstaller.UninstallLowerVersion(moduleNameList);
|
||||
EXPECT_EQ(res, ERR_APPEXECFWK_UNINSTALL_BUNDLE_MGR_SERVICE_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: UninstallLowerVersion_0020
|
||||
* @tc.name: test UninstallLowerVersion
|
||||
* @tc.desc: 1.Test the UninstallLowerVersion
|
||||
*/
|
||||
HWTEST_F(BmsBundleAppServiceFwkInstallerTest, UninstallLowerVersion_0020, Function | SmallTest | Level0)
|
||||
{
|
||||
auto installRes = InstallSystemHsp(VERSION_ONE_LIBRARY_ONE_PATH);
|
||||
ASSERT_EQ(installRes, ERR_OK);
|
||||
|
||||
AppServiceFwkInstaller appServiceFwkInstaller;
|
||||
InitAppServiceFwkInstaller(appServiceFwkInstaller);
|
||||
appServiceFwkInstaller.bundleName_ = BUNDLE_NAME;
|
||||
|
||||
std::vector<std::string> moduleNameList;
|
||||
auto res = appServiceFwkInstaller.UninstallLowerVersion(moduleNameList);
|
||||
EXPECT_EQ(res, ERR_APPEXECFWK_UNINSTALL_BUNDLE_MGR_SERVICE_ERROR);
|
||||
|
||||
DeleteBundleInfo(BUNDLE_NAME);
|
||||
DeletePreBundleInfo(BUNDLE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: UninstallLowerVersion_0030
|
||||
* @tc.name: test UninstallLowerVersion
|
||||
* @tc.desc: 1.Test the UninstallLowerVersion
|
||||
*/
|
||||
HWTEST_F(BmsBundleAppServiceFwkInstallerTest, UninstallLowerVersion_0030, Function | SmallTest | Level0)
|
||||
{
|
||||
auto installRes = InstallSystemHsp(VERSION_ONE_LIBRARY_ONE_PATH);
|
||||
ASSERT_EQ(installRes, ERR_OK);
|
||||
|
||||
AppServiceFwkInstaller appServiceFwkInstaller;
|
||||
InitAppServiceFwkInstaller(appServiceFwkInstaller);
|
||||
appServiceFwkInstaller.bundleName_ = BUNDLE_NAME;
|
||||
|
||||
auto dataMgr = GetBundleDataMgr();
|
||||
ASSERT_NE(dataMgr, nullptr);
|
||||
dataMgr->installStates_[BUNDLE_NAME] = InstallState::INSTALL_SUCCESS;
|
||||
|
||||
std::vector<std::string> moduleNameList;
|
||||
auto res = appServiceFwkInstaller.UninstallLowerVersion(moduleNameList);
|
||||
EXPECT_EQ(res, ERR_APPEXECFWK_UNINSTALL_BUNDLE_MGR_SERVICE_ERROR);
|
||||
|
||||
DeleteBundleInfo(BUNDLE_NAME);
|
||||
DeletePreBundleInfo(BUNDLE_NAME);
|
||||
dataMgr->installStates_.erase(BUNDLE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: UninstallLowerVersion_0040
|
||||
* @tc.name: test UninstallLowerVersion
|
||||
* @tc.desc: 1.Test the UninstallLowerVersion
|
||||
*/
|
||||
HWTEST_F(BmsBundleAppServiceFwkInstallerTest, UninstallLowerVersion_0040, Function | SmallTest | Level0)
|
||||
{
|
||||
auto installRes = InstallSystemHsp(VERSION_ONE_LIBRARY_ONE_PATH);
|
||||
ASSERT_EQ(installRes, ERR_OK);
|
||||
|
||||
AppServiceFwkInstaller appServiceFwkInstaller;
|
||||
InitAppServiceFwkInstaller(appServiceFwkInstaller);
|
||||
appServiceFwkInstaller.bundleName_ = BUNDLE_NAME;
|
||||
|
||||
auto dataMgr = GetBundleDataMgr();
|
||||
ASSERT_NE(dataMgr, nullptr);
|
||||
dataMgr->installStates_[BUNDLE_NAME] = InstallState::INSTALL_SUCCESS;
|
||||
|
||||
std::vector<std::string> moduleNameList { MODULE_NAME_TEST };
|
||||
auto res = appServiceFwkInstaller.UninstallLowerVersion(moduleNameList);
|
||||
EXPECT_EQ(res, ERR_APPEXECFWK_UNINSTALL_BUNDLE_MGR_SERVICE_ERROR);
|
||||
|
||||
DeleteBundleInfo(BUNDLE_NAME);
|
||||
DeletePreBundleInfo(BUNDLE_NAME);
|
||||
dataMgr->installStates_.erase(BUNDLE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: UninstallLowerVersion_0050
|
||||
* @tc.name: test UninstallLowerVersion
|
||||
* @tc.desc: 1.Test the UninstallLowerVersion
|
||||
*/
|
||||
HWTEST_F(BmsBundleAppServiceFwkInstallerTest, UninstallLowerVersion_0050, Function | SmallTest | Level0)
|
||||
{
|
||||
auto installRes = InstallSystemHsp(VERSION_ONE_LIBRARY_ONE_PATH);
|
||||
ASSERT_EQ(installRes, ERR_OK);
|
||||
|
||||
auto installRes2 = InstallSystemHsp(VERSION_ONE_LIBRARY_TWO_PATH);
|
||||
ASSERT_EQ(installRes2, ERR_OK);
|
||||
|
||||
AppServiceFwkInstaller appServiceFwkInstaller;
|
||||
InitAppServiceFwkInstaller(appServiceFwkInstaller);
|
||||
appServiceFwkInstaller.bundleName_ = BUNDLE_NAME;
|
||||
|
||||
auto dataMgr = GetBundleDataMgr();
|
||||
ASSERT_NE(dataMgr, nullptr);
|
||||
dataMgr->installStates_[BUNDLE_NAME] = InstallState::INSTALL_SUCCESS;
|
||||
|
||||
std::vector<std::string> moduleNameList { MODULE_NAME_LIBRARY_ONE };
|
||||
auto res = appServiceFwkInstaller.UninstallLowerVersion(moduleNameList);
|
||||
EXPECT_EQ(res, ERR_APPEXECFWK_UNINSTALL_BUNDLE_MGR_SERVICE_ERROR);
|
||||
|
||||
DeleteBundleInfo(BUNDLE_NAME);
|
||||
DeletePreBundleInfo(BUNDLE_NAME);
|
||||
dataMgr->installStates_.erase(BUNDLE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: ProcessNewModuleInstall_0010
|
||||
* @tc.name: test ProcessNewModuleInstall
|
||||
* @tc.desc: 1.Test the ProcessNewModuleInstall
|
||||
*/
|
||||
HWTEST_F(BmsBundleAppServiceFwkInstallerTest, ProcessNewModuleInstall_0010, Function | SmallTest | Level0)
|
||||
{
|
||||
auto installRes = InstallSystemHsp(VERSION_ONE_LIBRARY_ONE_PATH);
|
||||
ASSERT_EQ(installRes, ERR_OK);
|
||||
|
||||
auto installRes2 = InstallSystemHsp(VERSION_ONE_LIBRARY_TWO_PATH);
|
||||
ASSERT_EQ(installRes2, ERR_OK);
|
||||
|
||||
AppServiceFwkInstaller appServiceFwkInstaller;
|
||||
InitAppServiceFwkInstaller(appServiceFwkInstaller);
|
||||
appServiceFwkInstaller.bundleName_ = BUNDLE_NAME;
|
||||
|
||||
auto dataMgr = GetBundleDataMgr();
|
||||
ASSERT_NE(dataMgr, nullptr);
|
||||
dataMgr->installStates_[BUNDLE_NAME] = InstallState::INSTALL_SUCCESS;
|
||||
|
||||
std::vector<std::string> moduleNameList { MODULE_NAME_LIBRARY_ONE };
|
||||
auto res = appServiceFwkInstaller.UninstallLowerVersion(moduleNameList);
|
||||
EXPECT_EQ(res, ERR_APPEXECFWK_UNINSTALL_BUNDLE_MGR_SERVICE_ERROR);
|
||||
|
||||
DeleteBundleInfo(BUNDLE_NAME);
|
||||
DeletePreBundleInfo(BUNDLE_NAME);
|
||||
dataMgr->installStates_.erase(BUNDLE_NAME);
|
||||
}
|
||||
}
|
BIN
test/sceneProject/signature/com.example.appservice.p7b
Normal file
@ -17,6 +17,7 @@ group("unittest_hap") {
|
||||
|
||||
deps += [
|
||||
# deps file
|
||||
"bundle_app_service:bundle_app_service",
|
||||
"bundle_dependencies:bundle_dependencies",
|
||||
"bundle_kit:bundle_kit",
|
||||
"install_daemon:install_daemon",
|
||||
|
25
test/sceneProject/unittest/bundle_app_service/BUILD.gn
Normal file
@ -0,0 +1,25 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
group("bundle_app_service") {
|
||||
testonly = true
|
||||
deps = []
|
||||
|
||||
deps += [
|
||||
# deps file
|
||||
"app_service_version1_library1:appService_v1_library1",
|
||||
"app_service_version1_library2:appService_v1_library2",
|
||||
"app_service_version2_library1:appService_v2_library1",
|
||||
"app_service_version2_library2:appService_v2_library2",
|
||||
]
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
{
|
||||
"app": {
|
||||
"apiReleaseType": "Release",
|
||||
"bundleName": "com.example.appservice",
|
||||
"debug": true,
|
||||
"icon": "$media:app_icon",
|
||||
"iconId": 16777217,
|
||||
"label": "$string:app_name",
|
||||
"labelId": 16777216,
|
||||
"minAPIVersion": 11,
|
||||
"targetAPIVersion": 11,
|
||||
"vendor": "example",
|
||||
"versionCode": 1000000,
|
||||
"versionName": "1.0.0",
|
||||
"bundleType": "appService"
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"string":[
|
||||
{
|
||||
"name":"app_name",
|
||||
"value":"ohosProject"
|
||||
}
|
||||
]
|
||||
}
|
After Width: | Height: | Size: 6.6 KiB |
@ -0,0 +1,43 @@
|
||||
# Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("../../../../../appexecfwk.gni")
|
||||
|
||||
ohos_hap("appService_v1_library1") {
|
||||
hap_profile = "entry/src/main/module.json"
|
||||
hap_name = "appService_v1_library1"
|
||||
subsystem_name = "bundlemanager"
|
||||
final_hap_path = "$root_out_dir/tests/unittest/bundle_framework/bundlemgrservice/resource/bundle_app_service/${hap_name}.hsp"
|
||||
testonly = true
|
||||
deps = [
|
||||
":hjs_demo_js_assets",
|
||||
":hjs_demo_resources",
|
||||
]
|
||||
certificate_profile = "${bundle_framework_path}/test/sceneProject/signature/com.example.appservice.p7b"
|
||||
}
|
||||
|
||||
ohos_app_scope("bmsstagedemoone_app_profile") {
|
||||
app_profile = "AppScope/app.json"
|
||||
sources = [ "AppScope/resources" ]
|
||||
}
|
||||
|
||||
ohos_js_assets("hjs_demo_js_assets") {
|
||||
source_dir = "entry/src/main/ets"
|
||||
}
|
||||
|
||||
ohos_resources("hjs_demo_resources") {
|
||||
sources = [ "entry/src/main/resources" ]
|
||||
deps = [ ":bmsstagedemoone_app_profile" ]
|
||||
hap_profile = "entry/src/main/module.json"
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
cmake_minimum_required(VERSION 3.4.1)
|
||||
project(LibA)
|
||||
|
||||
set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
include_directories(${NATIVERENDER_ROOT_PATH}
|
||||
${NATIVERENDER_ROOT_PATH}/include)
|
||||
|
||||
add_library(entry SHARED hello.cpp)
|
||||
target_link_libraries(entry PUBLIC libace_napi.z.so)
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "napi/native_api.h"
|
||||
|
||||
static napi_value Add(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = 2;
|
||||
napi_value args[2] = {nullptr};
|
||||
|
||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
||||
|
||||
napi_valuetype valuetype0;
|
||||
napi_typeof(env, args[0], &valuetype0);
|
||||
|
||||
napi_valuetype valuetype1;
|
||||
napi_typeof(env, args[1], &valuetype1);
|
||||
|
||||
double value0;
|
||||
napi_get_value_double(env, args[0], &value0);
|
||||
|
||||
double value1;
|
||||
napi_get_value_double(env, args[1], &value1);
|
||||
|
||||
napi_value sum;
|
||||
napi_create_double(env, value0 + value1, &sum);
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
EXTERN_C_START
|
||||
static napi_value Init(napi_env env, napi_value exports)
|
||||
{
|
||||
napi_property_descriptor desc[] = {
|
||||
{ "add", nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr }
|
||||
};
|
||||
napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
|
||||
return exports;
|
||||
}
|
||||
EXTERN_C_END
|
||||
|
||||
static napi_module demoModule = {
|
||||
.nm_version =1,
|
||||
.nm_flags = 0,
|
||||
.nm_filename = nullptr,
|
||||
.nm_register_func = Init,
|
||||
.nm_modname = "entry",
|
||||
.nm_priv = ((void*)0),
|
||||
.reserved = { 0 },
|
||||
};
|
||||
|
||||
extern "C" __attribute__((constructor)) void RegisterEntryModule(void)
|
||||
{
|
||||
napi_module_register(&demoModule);
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export const add: (a: number, b: number) => number;
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
"name": "libentry.so",
|
||||
"types": "./index.d.ts"
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import UIAbility from '@ohos.app.ability.UIAbility';
|
||||
import hilog from '@ohos.hilog';
|
||||
import Window from '@ohos.window'
|
||||
|
||||
export default class EntryAbility extends UIAbility {
|
||||
onCreate(want, launchParam) {
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? '');
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
|
||||
}
|
||||
|
||||
onWindowStageCreate(windowStage: Window.WindowStage) {
|
||||
// Main window is created, set main page for this ability
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
|
||||
|
||||
windowStage.loadContent('pages/Index', (err, data) => {
|
||||
if (err.code) {
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR);
|
||||
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
|
||||
return;
|
||||
}
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
|
||||
});
|
||||
}
|
||||
|
||||
onWindowStageDestroy() {
|
||||
// Main window is destroyed, release UI related resources
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
|
||||
}
|
||||
|
||||
onForeground() {
|
||||
// Ability has brought to foreground
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
|
||||
}
|
||||
|
||||
onBackground() {
|
||||
// Ability has back to background
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
|
||||
}
|
||||
};
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import hilog from '@ohos.hilog';
|
||||
import testNapi from 'libentry.so'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct Index {
|
||||
@State message: string = 'Hello World'
|
||||
|
||||
build() {
|
||||
Row() {
|
||||
Column() {
|
||||
Text(this.message)
|
||||
.fontSize(50)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.onClick(() => {
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', 'Test NAPI 2 + 3 = %{public}d', testNapi.add(2, 3));
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
}
|
||||
.height('100%')
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
{
|
||||
"module": {
|
||||
"name": "library_one",
|
||||
"type": "shared",
|
||||
"description": "$string:module_desc",
|
||||
"deviceTypes": [
|
||||
"2in1",
|
||||
"default",
|
||||
"tablet"
|
||||
],
|
||||
"deliveryWithInstall": true,
|
||||
"installationFree": false,
|
||||
"pages": "$profile:main_pages"
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"color": [
|
||||
{
|
||||
"name": "start_window_background",
|
||||
"value": "#FFFFFF"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "module description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "label"
|
||||
}
|
||||
]
|
||||
}
|
After Width: | Height: | Size: 6.6 KiB |
@ -0,0 +1,5 @@
|
||||
{
|
||||
"src": [
|
||||
"pages/Index"
|
||||
]
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "module description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "label"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "description of module"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "label"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
{
|
||||
"app": {
|
||||
"apiReleaseType": "Release",
|
||||
"bundleName": "com.example.appservice",
|
||||
"debug": true,
|
||||
"icon": "$media:app_icon",
|
||||
"iconId": 16777217,
|
||||
"label": "$string:app_name",
|
||||
"labelId": 16777216,
|
||||
"minAPIVersion": 11,
|
||||
"targetAPIVersion": 11,
|
||||
"vendor": "example",
|
||||
"versionCode": 1000000,
|
||||
"versionName": "1.0.0",
|
||||
"bundleType": "appService"
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"string":[
|
||||
{
|
||||
"name":"app_name",
|
||||
"value":"ohosProject"
|
||||
}
|
||||
]
|
||||
}
|
After Width: | Height: | Size: 6.6 KiB |
@ -0,0 +1,43 @@
|
||||
# Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("../../../../../appexecfwk.gni")
|
||||
|
||||
ohos_hap("appService_v1_library2") {
|
||||
hap_profile = "entry/src/main/module.json"
|
||||
hap_name = "appService_v1_library2"
|
||||
subsystem_name = "bundlemanager"
|
||||
final_hap_path = "$root_out_dir/tests/unittest/bundle_framework/bundlemgrservice/resource/bundle_app_service/${hap_name}.hsp"
|
||||
testonly = true
|
||||
deps = [
|
||||
":hjs_demo_js_assets",
|
||||
":hjs_demo_resources",
|
||||
]
|
||||
certificate_profile = "${bundle_framework_path}/test/sceneProject/signature/com.example.appservice.p7b"
|
||||
}
|
||||
|
||||
ohos_app_scope("bmsstagedemoone_app_profile") {
|
||||
app_profile = "AppScope/app.json"
|
||||
sources = [ "AppScope/resources" ]
|
||||
}
|
||||
|
||||
ohos_js_assets("hjs_demo_js_assets") {
|
||||
source_dir = "entry/src/main/ets"
|
||||
}
|
||||
|
||||
ohos_resources("hjs_demo_resources") {
|
||||
sources = [ "entry/src/main/resources" ]
|
||||
deps = [ ":bmsstagedemoone_app_profile" ]
|
||||
hap_profile = "entry/src/main/module.json"
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
cmake_minimum_required(VERSION 3.4.1)
|
||||
project(LibA)
|
||||
|
||||
set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
include_directories(${NATIVERENDER_ROOT_PATH}
|
||||
${NATIVERENDER_ROOT_PATH}/include)
|
||||
|
||||
add_library(entry SHARED hello.cpp)
|
||||
target_link_libraries(entry PUBLIC libace_napi.z.so)
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "napi/native_api.h"
|
||||
|
||||
static napi_value Add(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = 2;
|
||||
napi_value args[2] = {nullptr};
|
||||
|
||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
||||
|
||||
napi_valuetype valuetype0;
|
||||
napi_typeof(env, args[0], &valuetype0);
|
||||
|
||||
napi_valuetype valuetype1;
|
||||
napi_typeof(env, args[1], &valuetype1);
|
||||
|
||||
double value0;
|
||||
napi_get_value_double(env, args[0], &value0);
|
||||
|
||||
double value1;
|
||||
napi_get_value_double(env, args[1], &value1);
|
||||
|
||||
napi_value sum;
|
||||
napi_create_double(env, value0 + value1, &sum);
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
EXTERN_C_START
|
||||
static napi_value Init(napi_env env, napi_value exports)
|
||||
{
|
||||
napi_property_descriptor desc[] = {
|
||||
{ "add", nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr }
|
||||
};
|
||||
napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
|
||||
return exports;
|
||||
}
|
||||
EXTERN_C_END
|
||||
|
||||
static napi_module demoModule = {
|
||||
.nm_version =1,
|
||||
.nm_flags = 0,
|
||||
.nm_filename = nullptr,
|
||||
.nm_register_func = Init,
|
||||
.nm_modname = "entry",
|
||||
.nm_priv = ((void*)0),
|
||||
.reserved = { 0 },
|
||||
};
|
||||
|
||||
extern "C" __attribute__((constructor)) void RegisterEntryModule(void)
|
||||
{
|
||||
napi_module_register(&demoModule);
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export const add: (a: number, b: number) => number;
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
"name": "libentry.so",
|
||||
"types": "./index.d.ts"
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import UIAbility from '@ohos.app.ability.UIAbility';
|
||||
import hilog from '@ohos.hilog';
|
||||
import Window from '@ohos.window'
|
||||
|
||||
export default class EntryAbility extends UIAbility {
|
||||
onCreate(want, launchParam) {
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? '');
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
|
||||
}
|
||||
|
||||
onWindowStageCreate(windowStage: Window.WindowStage) {
|
||||
// Main window is created, set main page for this ability
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
|
||||
|
||||
windowStage.loadContent('pages/Index', (err, data) => {
|
||||
if (err.code) {
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR);
|
||||
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
|
||||
return;
|
||||
}
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
|
||||
});
|
||||
}
|
||||
|
||||
onWindowStageDestroy() {
|
||||
// Main window is destroyed, release UI related resources
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
|
||||
}
|
||||
|
||||
onForeground() {
|
||||
// Ability has brought to foreground
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
|
||||
}
|
||||
|
||||
onBackground() {
|
||||
// Ability has back to background
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
|
||||
}
|
||||
};
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import hilog from '@ohos.hilog';
|
||||
import testNapi from 'libentry.so'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct Index {
|
||||
@State message: string = 'Hello World'
|
||||
|
||||
build() {
|
||||
Row() {
|
||||
Column() {
|
||||
Text(this.message)
|
||||
.fontSize(50)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.onClick(() => {
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', 'Test NAPI 2 + 3 = %{public}d', testNapi.add(2, 3));
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
}
|
||||
.height('100%')
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
{
|
||||
"module": {
|
||||
"name": "library_two",
|
||||
"type": "shared",
|
||||
"description": "$string:module_desc",
|
||||
"deviceTypes": [
|
||||
"2in1",
|
||||
"default",
|
||||
"tablet"
|
||||
],
|
||||
"deliveryWithInstall": true,
|
||||
"installationFree": false,
|
||||
"pages": "$profile:main_pages"
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"color": [
|
||||
{
|
||||
"name": "start_window_background",
|
||||
"value": "#FFFFFF"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "module description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "label"
|
||||
}
|
||||
]
|
||||
}
|
After Width: | Height: | Size: 6.6 KiB |
@ -0,0 +1,5 @@
|
||||
{
|
||||
"src": [
|
||||
"pages/Index"
|
||||
]
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "module description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "label"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "description of module"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "label"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
{
|
||||
"app": {
|
||||
"apiReleaseType": "Release",
|
||||
"bundleName": "com.example.appservice",
|
||||
"debug": true,
|
||||
"icon": "$media:app_icon",
|
||||
"iconId": 16777217,
|
||||
"label": "$string:app_name",
|
||||
"labelId": 16777216,
|
||||
"minAPIVersion": 11,
|
||||
"targetAPIVersion": 11,
|
||||
"vendor": "example",
|
||||
"versionCode": 1000002,
|
||||
"versionName": "1.0.02",
|
||||
"bundleType": "appService"
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"string":[
|
||||
{
|
||||
"name":"app_name",
|
||||
"value":"ohosProject"
|
||||
}
|
||||
]
|
||||
}
|
After Width: | Height: | Size: 6.6 KiB |
@ -0,0 +1,43 @@
|
||||
# Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("../../../../../appexecfwk.gni")
|
||||
|
||||
ohos_hap("appService_v2_library1") {
|
||||
hap_profile = "entry/src/main/module.json"
|
||||
hap_name = "appService_v2_library1"
|
||||
subsystem_name = "bundlemanager"
|
||||
final_hap_path = "$root_out_dir/tests/unittest/bundle_framework/bundlemgrservice/resource/bundle_app_service/${hap_name}.hsp"
|
||||
testonly = true
|
||||
deps = [
|
||||
":hjs_demo_js_assets",
|
||||
":hjs_demo_resources",
|
||||
]
|
||||
certificate_profile = "${bundle_framework_path}/test/sceneProject/signature/com.example.appservice.p7b"
|
||||
}
|
||||
|
||||
ohos_app_scope("bmsstagedemoone_app_profile") {
|
||||
app_profile = "AppScope/app.json"
|
||||
sources = [ "AppScope/resources" ]
|
||||
}
|
||||
|
||||
ohos_js_assets("hjs_demo_js_assets") {
|
||||
source_dir = "entry/src/main/ets"
|
||||
}
|
||||
|
||||
ohos_resources("hjs_demo_resources") {
|
||||
sources = [ "entry/src/main/resources" ]
|
||||
deps = [ ":bmsstagedemoone_app_profile" ]
|
||||
hap_profile = "entry/src/main/module.json"
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
cmake_minimum_required(VERSION 3.4.1)
|
||||
project(LibA)
|
||||
|
||||
set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
include_directories(${NATIVERENDER_ROOT_PATH}
|
||||
${NATIVERENDER_ROOT_PATH}/include)
|
||||
|
||||
add_library(entry SHARED hello.cpp)
|
||||
target_link_libraries(entry PUBLIC libace_napi.z.so)
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "napi/native_api.h"
|
||||
|
||||
static napi_value Add(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = 2;
|
||||
napi_value args[2] = {nullptr};
|
||||
|
||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
||||
|
||||
napi_valuetype valuetype0;
|
||||
napi_typeof(env, args[0], &valuetype0);
|
||||
|
||||
napi_valuetype valuetype1;
|
||||
napi_typeof(env, args[1], &valuetype1);
|
||||
|
||||
double value0;
|
||||
napi_get_value_double(env, args[0], &value0);
|
||||
|
||||
double value1;
|
||||
napi_get_value_double(env, args[1], &value1);
|
||||
|
||||
napi_value sum;
|
||||
napi_create_double(env, value0 + value1, &sum);
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
EXTERN_C_START
|
||||
static napi_value Init(napi_env env, napi_value exports)
|
||||
{
|
||||
napi_property_descriptor desc[] = {
|
||||
{ "add", nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr }
|
||||
};
|
||||
napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
|
||||
return exports;
|
||||
}
|
||||
EXTERN_C_END
|
||||
|
||||
static napi_module demoModule = {
|
||||
.nm_version =1,
|
||||
.nm_flags = 0,
|
||||
.nm_filename = nullptr,
|
||||
.nm_register_func = Init,
|
||||
.nm_modname = "entry",
|
||||
.nm_priv = ((void*)0),
|
||||
.reserved = { 0 },
|
||||
};
|
||||
|
||||
extern "C" __attribute__((constructor)) void RegisterEntryModule(void)
|
||||
{
|
||||
napi_module_register(&demoModule);
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export const add: (a: number, b: number) => number;
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
"name": "libentry.so",
|
||||
"types": "./index.d.ts"
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import UIAbility from '@ohos.app.ability.UIAbility';
|
||||
import hilog from '@ohos.hilog';
|
||||
import Window from '@ohos.window'
|
||||
|
||||
export default class EntryAbility extends UIAbility {
|
||||
onCreate(want, launchParam) {
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? '');
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
|
||||
}
|
||||
|
||||
onWindowStageCreate(windowStage: Window.WindowStage) {
|
||||
// Main window is created, set main page for this ability
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
|
||||
|
||||
windowStage.loadContent('pages/Index', (err, data) => {
|
||||
if (err.code) {
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR);
|
||||
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
|
||||
return;
|
||||
}
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
|
||||
});
|
||||
}
|
||||
|
||||
onWindowStageDestroy() {
|
||||
// Main window is destroyed, release UI related resources
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
|
||||
}
|
||||
|
||||
onForeground() {
|
||||
// Ability has brought to foreground
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
|
||||
}
|
||||
|
||||
onBackground() {
|
||||
// Ability has back to background
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
|
||||
}
|
||||
};
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import hilog from '@ohos.hilog';
|
||||
import testNapi from 'libentry.so'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct Index {
|
||||
@State message: string = 'Hello World'
|
||||
|
||||
build() {
|
||||
Row() {
|
||||
Column() {
|
||||
Text(this.message)
|
||||
.fontSize(50)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.onClick(() => {
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', 'Test NAPI 2 + 3 = %{public}d', testNapi.add(2, 3));
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
}
|
||||
.height('100%')
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
{
|
||||
"module": {
|
||||
"name": "library_one",
|
||||
"type": "shared",
|
||||
"description": "$string:module_desc",
|
||||
"deviceTypes": [
|
||||
"2in1",
|
||||
"default",
|
||||
"tablet"
|
||||
],
|
||||
"deliveryWithInstall": true,
|
||||
"installationFree": false,
|
||||
"pages": "$profile:main_pages"
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"color": [
|
||||
{
|
||||
"name": "start_window_background",
|
||||
"value": "#FFFFFF"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "module description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "label"
|
||||
}
|
||||
]
|
||||
}
|
After Width: | Height: | Size: 6.6 KiB |
@ -0,0 +1,5 @@
|
||||
{
|
||||
"src": [
|
||||
"pages/Index"
|
||||
]
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "module description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "label"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "description of module"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "label"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
{
|
||||
"app": {
|
||||
"apiReleaseType": "Release",
|
||||
"bundleName": "com.example.appservice",
|
||||
"debug": true,
|
||||
"icon": "$media:app_icon",
|
||||
"iconId": 16777217,
|
||||
"label": "$string:app_name",
|
||||
"labelId": 16777216,
|
||||
"minAPIVersion": 11,
|
||||
"targetAPIVersion": 11,
|
||||
"vendor": "example",
|
||||
"versionCode": 1000002,
|
||||
"versionName": "1.0.02",
|
||||
"bundleType": "appService"
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"string":[
|
||||
{
|
||||
"name":"app_name",
|
||||
"value":"ohosProject"
|
||||
}
|
||||
]
|
||||
}
|
After Width: | Height: | Size: 6.6 KiB |
@ -0,0 +1,43 @@
|
||||
# Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("../../../../../appexecfwk.gni")
|
||||
|
||||
ohos_hap("appService_v2_library2") {
|
||||
hap_profile = "entry/src/main/module.json"
|
||||
hap_name = "appService_v2_library2"
|
||||
subsystem_name = "bundlemanager"
|
||||
final_hap_path = "$root_out_dir/tests/unittest/bundle_framework/bundlemgrservice/resource/bundle_app_service/${hap_name}.hsp"
|
||||
testonly = true
|
||||
deps = [
|
||||
":hjs_demo_js_assets",
|
||||
":hjs_demo_resources",
|
||||
]
|
||||
certificate_profile = "${bundle_framework_path}/test/sceneProject/signature/com.example.appservice.p7b"
|
||||
}
|
||||
|
||||
ohos_app_scope("bmsstagedemoone_app_profile") {
|
||||
app_profile = "AppScope/app.json"
|
||||
sources = [ "AppScope/resources" ]
|
||||
}
|
||||
|
||||
ohos_js_assets("hjs_demo_js_assets") {
|
||||
source_dir = "entry/src/main/ets"
|
||||
}
|
||||
|
||||
ohos_resources("hjs_demo_resources") {
|
||||
sources = [ "entry/src/main/resources" ]
|
||||
deps = [ ":bmsstagedemoone_app_profile" ]
|
||||
hap_profile = "entry/src/main/module.json"
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
cmake_minimum_required(VERSION 3.4.1)
|
||||
project(LibA)
|
||||
|
||||
set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
include_directories(${NATIVERENDER_ROOT_PATH}
|
||||
${NATIVERENDER_ROOT_PATH}/include)
|
||||
|
||||
add_library(entry SHARED hello.cpp)
|
||||
target_link_libraries(entry PUBLIC libace_napi.z.so)
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "napi/native_api.h"
|
||||
|
||||
static napi_value Add(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = 2;
|
||||
napi_value args[2] = {nullptr};
|
||||
|
||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
||||
|
||||
napi_valuetype valuetype0;
|
||||
napi_typeof(env, args[0], &valuetype0);
|
||||
|
||||
napi_valuetype valuetype1;
|
||||
napi_typeof(env, args[1], &valuetype1);
|
||||
|
||||
double value0;
|
||||
napi_get_value_double(env, args[0], &value0);
|
||||
|
||||
double value1;
|
||||
napi_get_value_double(env, args[1], &value1);
|
||||
|
||||
napi_value sum;
|
||||
napi_create_double(env, value0 + value1, &sum);
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
EXTERN_C_START
|
||||
static napi_value Init(napi_env env, napi_value exports)
|
||||
{
|
||||
napi_property_descriptor desc[] = {
|
||||
{ "add", nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr }
|
||||
};
|
||||
napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
|
||||
return exports;
|
||||
}
|
||||
EXTERN_C_END
|
||||
|
||||
static napi_module demoModule = {
|
||||
.nm_version =1,
|
||||
.nm_flags = 0,
|
||||
.nm_filename = nullptr,
|
||||
.nm_register_func = Init,
|
||||
.nm_modname = "entry",
|
||||
.nm_priv = ((void*)0),
|
||||
.reserved = { 0 },
|
||||
};
|
||||
|
||||
extern "C" __attribute__((constructor)) void RegisterEntryModule(void)
|
||||
{
|
||||
napi_module_register(&demoModule);
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export const add: (a: number, b: number) => number;
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
"name": "libentry.so",
|
||||
"types": "./index.d.ts"
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import UIAbility from '@ohos.app.ability.UIAbility';
|
||||
import hilog from '@ohos.hilog';
|
||||
import Window from '@ohos.window'
|
||||
|
||||
export default class EntryAbility extends UIAbility {
|
||||
onCreate(want, launchParam) {
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? '');
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
|
||||
}
|
||||
|
||||
onWindowStageCreate(windowStage: Window.WindowStage) {
|
||||
// Main window is created, set main page for this ability
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
|
||||
|
||||
windowStage.loadContent('pages/Index', (err, data) => {
|
||||
if (err.code) {
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR);
|
||||
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
|
||||
return;
|
||||
}
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
|
||||
});
|
||||
}
|
||||
|
||||
onWindowStageDestroy() {
|
||||
// Main window is destroyed, release UI related resources
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
|
||||
}
|
||||
|
||||
onForeground() {
|
||||
// Ability has brought to foreground
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
|
||||
}
|
||||
|
||||
onBackground() {
|
||||
// Ability has back to background
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
|
||||
}
|
||||
};
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import hilog from '@ohos.hilog';
|
||||
import testNapi from 'libentry.so'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct Index {
|
||||
@State message: string = 'Hello World'
|
||||
|
||||
build() {
|
||||
Row() {
|
||||
Column() {
|
||||
Text(this.message)
|
||||
.fontSize(50)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.onClick(() => {
|
||||
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
|
||||
hilog.info(0x0000, 'testTag', 'Test NAPI 2 + 3 = %{public}d', testNapi.add(2, 3));
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
}
|
||||
.height('100%')
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
{
|
||||
"module": {
|
||||
"name": "library_two",
|
||||
"type": "shared",
|
||||
"description": "$string:module_desc",
|
||||
"deviceTypes": [
|
||||
"2in1",
|
||||
"default",
|
||||
"tablet"
|
||||
],
|
||||
"deliveryWithInstall": true,
|
||||
"installationFree": false,
|
||||
"pages": "$profile:main_pages"
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"color": [
|
||||
{
|
||||
"name": "start_window_background",
|
||||
"value": "#FFFFFF"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "module description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "label"
|
||||
}
|
||||
]
|
||||
}
|
After Width: | Height: | Size: 6.6 KiB |
@ -0,0 +1,5 @@
|
||||
{
|
||||
"src": [
|
||||
"pages/Index"
|
||||
]
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "module description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "label"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "description of module"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "label"
|
||||
}
|
||||
]
|
||||
}
|
@ -412,4 +412,13 @@
|
||||
src="res" />
|
||||
</preparer>
|
||||
</target>
|
||||
<target name="BmsBundleAppServiceFwkInstallerTest">
|
||||
<preparer>
|
||||
<option name="push" value="install_daemon/right.hap -> /data/test/resource/bms/app_service_test/" src="res" />
|
||||
<option name="push" value="bundle_app_service/appService_v1_library1.hsp -> /data/test/resource/bms/app_service_test/" src="res" />
|
||||
<option name="push" value="bundle_app_service/appService_v1_library2.hsp -> /data/test/resource/bms/app_service_test/" src="res" />
|
||||
<option name="push" value="bundle_app_service/appService_v2_library1.hsp -> /data/test/resource/bms/app_service_test/" src="res" />
|
||||
<option name="push" value="bundle_app_service/appService_v2_library2.hsp -> /data/test/resource/bms/app_service_test/" src="res" />
|
||||
</preparer>
|
||||
</target>
|
||||
</configuration>
|