未验证 提交 18080436 编写于 作者: O openharmony_ci 提交者: Gitee

!643 增加sa服务动态拉起 测试用例源码

Merge pull request !643 from Mupceet/init519_1
......@@ -69,12 +69,28 @@ ohos_executable("server") {
part_name = "init"
}
ohos_executable("ondemandTest") {
sources = [ "sa_service_ondemand_test.cpp" ]
external_deps = [
"ipc:ipc_core",
"safwk:system_ability_fwk",
"samgr_standard:samgr_proxy",
"utils_base:utils",
]
install_images = [ "system" ]
install_enable = true
part_name = "init"
}
group("exectest") {
if (control_test) {
deps = [
":client",
":fd_holder_test",
":fd_holder_test.cfg",
":ondemandTest",
":server",
]
}
......
/*
* 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.
*/
#include <cstdlib>
#include <iostream>
#include <string>
#include "iservice_registry.h"
#include "system_ability_definition.h"
#include "system_ability_load_callback_stub.h"
using namespace OHOS;
using namespace std;
class OnDemandLoadCallback : public SystemAbilityLoadCallbackStub {
public:
void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr<IRemoteObject>& remoteObject) override;
void OnLoadSystemAbilityFail(int32_t systemAbilityId) override;
};
void OnDemandLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId,
const sptr<IRemoteObject>& remoteObject)
{
cout << "OnLoadSystemAbilitySuccess systemAbilityId:" << systemAbilityId << " IRemoteObject result:" <<
((remoteObject != nullptr) ? "succeed" : "failed") << endl;
}
void OnDemandLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId)
{
cout << "OnLoadSystemAbilityFail systemAbilityId:" << systemAbilityId << endl;
}
int main(int argc, char *argv[])
{
std::map<string, int> saService = {
{"updater_sa", UPDATE_DISTRIBUTED_SERVICE_ID},
{"softbus_server", SOFTBUS_SERVER_SA_ID},
};
int parameterNum = 2;
if ((argc != parameterNum) || (argv[1] == nullptr)) {
cout << "Invaild parameter" << endl;
}
const string name = argv[1];
int abilityId = 0;
std::map<string, int>::iterator item = saService.find(name);
if (item != saService.end()) {
cout << "sa service name " << item->first << "ability id " << item->second << endl;
abilityId = item->second;
} else {
cout << "Invaild sa service name" << endl;
return 0;
}
sptr<OnDemandLoadCallback> loadCallback_ = new OnDemandLoadCallback();
sptr<ISystemAbilityManager> sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (sm == nullptr) {
cout << "GetSystemAbilityManager samgr object null!" << endl;
return 0;
}
int32_t result = sm->LoadSystemAbility(abilityId, loadCallback_);
if (result != ERR_OK) {
cout << "systemAbilityId:" << abilityId << " load failed, result code:" << result << endl;
return 0;
}
return 0;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册