appspawn rebuild

Signed-off-by: hanchenZz <wanghanchen1@huawei.com>
This commit is contained in:
hanchenZz 2024-03-30 14:15:37 +08:00
parent a496d3bd88
commit ab9a04d1f5
69 changed files with 597 additions and 1110 deletions

View File

@ -21,7 +21,6 @@ config("appmgr_config") {
"//third_party/json/include",
"${ability_runtime_innerkits_path}/ability_manager/include",
"${ability_runtime_services_path}/common/include",
"${appspawn_path}/interfaces/innerkits/include",
"${ability_runtime_path}/tools/aa/include",
"${ability_runtime_path}/utils/global/time/include",
"${distributeddatamgr_path}/kv_store/interfaces/innerkits/distributeddatamgr/include",
@ -52,8 +51,6 @@ ohos_shared_library("libappms") {
"src/app_running_record.cpp",
"src/app_running_status_module.cpp",
"src/app_spawn_client.cpp",
"src/app_spawn_msg_wrapper.cpp",
"src/app_spawn_socket.cpp",
"src/app_state_observer_manager.cpp",
"src/child_process_record.cpp",
"src/module_running_record.cpp",
@ -101,9 +98,10 @@ ohos_shared_library("libappms") {
"ability_base:configuration",
"ability_base:want",
"access_token:libaccesstoken_sdk",
"appspawn:appspawn_socket_client",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"ffrt:libffrt",
"hicollie:libhicollie",

View File

@ -41,7 +41,7 @@
#include "priority_object.h"
#include "app_lifecycle_deal.h"
#include "module_running_record.h"
#include "app_spawn_msg_wrapper.h"
#include "app_spawn_client.h"
#include "app_malloc_info.h"
#include "window_visibility_changed_listener.h"
#include "app_jsheap_mem_info.h"

View File

@ -16,15 +16,78 @@
#ifndef OHOS_ABILITY_RUNTIME_APP_SPAWN_CLIENT_H
#define OHOS_ABILITY_RUNTIME_APP_SPAWN_CLIENT_H
#include <mutex>
#include <array>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <unistd.h>
#include <vector>
#include "appexecfwk_errors.h"
#include "appspawn.h"
#include "data_group_info.h"
#include "nocopyable.h"
#include "app_spawn_msg_wrapper.h"
#include "app_spawn_socket.h"
#include "shared/base_shared_bundle_info.h"
namespace OHOS {
namespace AppExecFwk {
enum class SpawnConnectionState { STATE_NOT_CONNECT, STATE_CONNECTED, STATE_CONNECT_FAILED };
using HspList = std::vector<BaseSharedBundleInfo>;
using DataGroupInfoList = std::vector<DataGroupInfo>;
const int32_t MAX_FLAG_INDEX = 32;
const int32_t MAX_PROC_NAME_LEN = 256;
const int32_t START_FLAG_BASE = 1;
struct AppSpawnStartMsg {
int32_t uid;
int32_t gid;
std::vector<int32_t> gids;
std::string procName;
std::string soPath;
uint32_t accessTokenId;
std::string apl;
std::string bundleName;
std::string renderParam; // only nweb spawn need this param.
int32_t pid;
int32_t code = 0; // 0: default, MSG_APP_SPAWN; 1: MSG_SPAWN_NATIVE_PROCESS; 2: MSG_GET_RENDER_TERMINATION_STATUS
uint32_t flags;
int32_t bundleIndex; // when dlp launch another app used, default is 0
uint8_t setAllowInternet;
uint8_t allowInternet; // hap socket allowed
uint8_t reserved1;
uint8_t reserved2;
uint64_t accessTokenIdEx;
uint32_t hapFlags = 0; // whether is pre installed hap
HspList hspList; // list of harmony shared package
std::string overlayInfo; // overlay hap resource path list
DataGroupInfoList dataGroupInfoList; // list of harmony shared package
uint32_t mountPermissionFlags;
std::set<std::string> permissions;
std::map<std::string, std::string> appEnv; // environment variable to be set to the process
std::string ownerId;
};
constexpr auto LEN_PID = sizeof(pid_t);
struct StartFlags {
static const int COLD_START = 0;
static const int BACKUP_EXTENSION = 1;
static const int DLP_MANAGER = 2;
static const int DEBUGGABLE = 3;
static const int ASANENABLED = 4;
static const int ACCESS_BUNDLE_DIR = 5;
static const int NATIVEDEBUG = 6;
static const int NO_SANDBOX = 7;
static const int OVERLAY = 8;
static const int BUNDLE_RESOURCES = 9;
static const int GWP_ENABLED_FORCE = 10;
static const int GWP_ENABLED_NORMAL = 11;
static const int TSANENABLED = 12;
};
union AppSpawnPidMsg {
pid_t pid = 0;
char pidBuf[LEN_PID];
};
class AppSpawnClient {
public:
@ -36,7 +99,7 @@ public:
/**
* Destructor
*/
virtual ~AppSpawnClient() = default;
virtual ~AppSpawnClient();
/**
* Disable copy.
@ -49,15 +112,66 @@ public:
ErrCode OpenConnection();
/**
* Close the connect of appSpawn.
* Close the connect of appspawn.
*/
void CloseConnection();
/**
* Return the connect state.
*/
SpawnConnectionState QueryConnectionState() const;
/**
* Set dac info.
*
* @param startMsg, request message.
* @param reqHandle, handle for request message
*/
int32_t SetDacInfo(const AppSpawnStartMsg &startMsg, AppSpawnReqMsgHandle reqHandle);
/**
* Set mount permission.
*
* @param startMsg, request message.
* @param reqHandle, handle for request message
*/
int32_t SetMountPermission(const AppSpawnStartMsg &startMsg, AppSpawnReqMsgHandle reqHandle);
/**
* Set start flags.
*
* @param startMsg, request message.
* @param reqHandle, handle for request message
*/
int32_t SetStartFlags(const AppSpawnStartMsg &startMsg, AppSpawnReqMsgHandle reqHandle);
/**
* Set extra info: render-cmd, HspList, Overlay, DataGroup, AppEnv.
*
* @param startMsg, request message.
* @param reqHandle, handle for request message
*/
int32_t AppspawnSetExtMsg(const AppSpawnStartMsg &startMsg, AppSpawnReqMsgHandle reqHandle);
/**
* Create default appspawn msg.
*
* @param startMsg, request message.
* @param reqHandle, handle for request message
*/
int32_t AppspawnCreateDefaultMsg(const AppSpawnStartMsg &startMsg, AppSpawnReqMsgHandle reqHandle);
/**
* Verify startMsg.
*
* @param startMsg, request message.
*/
bool VerifyMsg(const AppSpawnStartMsg &startMsg);
/**
* Start request to nwebspawn process.
*
*/
virtual ErrCode PreStartNWebSpawnProcess();
virtual int32_t PreStartNWebSpawnProcess();
/**
* AppSpawnClient core function, Start request to appSpawn.
@ -65,7 +179,7 @@ public:
* @param startMsg, request message.
* @param pid, pid of app process, get from appSpawn.
*/
virtual ErrCode StartProcess(const AppSpawnStartMsg &startMsg, pid_t &pid);
virtual int32_t StartProcess(const AppSpawnStartMsg &startMsg, pid_t &pid);
/**
* Get render process termination status.
@ -73,51 +187,12 @@ public:
* @param startMsg, request message.
* @param status, termination status of render process, get from appSpawn.
*/
virtual ErrCode GetRenderProcessTerminationStatus(const AppSpawnStartMsg &startMsg, int &status);
/**
* Return the connect state.
*/
SpawnConnectionState QueryConnectionState() const;
/**
* Set function, unit test also use it.
*/
void SetSocket(const std::shared_ptr<AppSpawnSocket> socket);
virtual int32_t GetRenderProcessTerminationStatus(const AppSpawnStartMsg &startMsg, int &status);
private:
/**
* AppSpawnClient core function,
*
* @param startMsg, request message.
* @param pid, pid of app process, get it from appSpawn.
*/
ErrCode StartProcessImpl(const AppSpawnStartMsg &startMsg, pid_t &pid);
/**
* Start request to nwebspawn process.
*
*/
ErrCode PreStartNWebSpawnProcessImpl();
/**
* write string info to appSpawn.
*
* @param strInfo, request message wrapper.
*/
ErrCode WriteStrInfoMessage(const std::string &strInfo);
/**
* @brief write message to appSpawn.
*
* @param startMsg, request message.
*/
ErrCode StartProcessForWriteMsg(const AppSpawnMsgWrapper &msgWrapper);
private:
std::shared_ptr<AppSpawnSocket> socket_;
std::string serviceName_ = APPSPAWN_SERVER_NAME;
AppSpawnClientHandle handle_ = nullptr;
SpawnConnectionState state_ = SpawnConnectionState::STATE_NOT_CONNECT;
std::mutex socketLock_;
};
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -1,168 +0,0 @@
/*
* 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.
*/
#ifndef OHOS_ABILITY_RUNTIME_APP_SPAWN_MSG_WRAPPER_H
#define OHOS_ABILITY_RUNTIME_APP_SPAWN_MSG_WRAPPER_H
#include <map>
#include <string>
#include <vector>
#include <unistd.h>
#include "nocopyable.h"
#include "client_socket.h"
#include "data_group_info.h"
#include "shared/base_shared_bundle_info.h"
namespace OHOS {
namespace AppExecFwk {
using AppSpawnMsg = AppSpawn::ClientSocket::AppProperty;
using HspList = std::vector<BaseSharedBundleInfo>;
using DataGroupInfoList = std::vector<DataGroupInfo>;
struct AppSpawnStartMsg {
int32_t uid;
int32_t gid;
std::vector<int32_t> gids;
std::string procName;
std::string soPath;
uint32_t accessTokenId;
std::string apl;
std::string bundleName;
std::string renderParam; // only nweb spawn need this param.
int32_t pid;
int32_t code = 0; // 0: DEFAULT; 1: GET_RENDER_TERMINATION_STATUS; 2: SPAWN_NATIVE_PROCESS
uint32_t flags;
int32_t bundleIndex; // when dlp launch another app used, default is 0
uint8_t setAllowInternet;
uint8_t allowInternet; // hap socket allowed
uint8_t reserved1;
uint8_t reserved2;
uint64_t accessTokenIdEx;
uint32_t hapFlags = 0; // whether is pre installed hap
HspList hspList; // list of harmony shared package
std::string overlayInfo; // overlay hap resource path list
DataGroupInfoList dataGroupInfoList; // list of harmony shared package
uint32_t mountPermissionFlags;
std::map<std::string, std::string> appEnv; // environment variable to be set to the process
std::string ownerId;
};
constexpr auto LEN_PID = sizeof(pid_t);
struct StartFlags {
static const int COLD_START = 0;
static const int BACKUP_EXTENSION = 1;
static const int DLP_MANAGER = 2;
static const int DEBUGGABLE = 3;
static const int ASANENABLED = 4;
static const int NATIVEDEBUG = 6;
static const int NO_SANDBOX = 7;
static const int GWP_ENABLED_FORCE = 10;
static const int GWP_ENABLED_NORMAL = 11;
static const int TSANENABLED = 12;
};
union AppSpawnPidMsg {
pid_t pid = 0;
char pidBuf[LEN_PID];
};
class AppSpawnMsgWrapper {
public:
/**
* Constructor.
*/
AppSpawnMsgWrapper() = default;
/**
* Destructor
*/
~AppSpawnMsgWrapper();
/**
* Disable copy.
*/
DISALLOW_COPY_AND_MOVE(AppSpawnMsgWrapper);
/**
* Verify message and assign to member variable.
*
* @param startMsg, request message.
*/
bool AssembleMsg(const AppSpawnStartMsg &startMsg);
/**
* Get function, return isValid_.
*/
bool IsValid() const
{
return isValid_;
}
/**
* Get function, return member variable message.
*/
const void *GetMsgBuf() const
{
return reinterpret_cast<void *>(msg_);
}
/**
* Get function, return message length.
*/
int32_t GetMsgLength() const
{
return isValid_ ? sizeof(AppSpawnMsg) : 0;
}
/**
* Get function, return hsp list string
*/
const std::string& GetExtraInfoStr() const
{
return extraInfoStr_;
}
private:
/**
* Verify message.
*
* @param startMsg, request message.
*/
bool VerifyMsg(const AppSpawnStartMsg &startMsg) const;
/**
* Print message.
*
* @param startMsg, request message.
*/
void DumpMsg() const;
/**
* Release message.
*/
void FreeMsg();
void BuildExtraInfo(const AppSpawnStartMsg &startMsg);
private:
bool isValid_ = false;
// because AppSpawnMsg's size is uncertain, so should use raw pointer.
AppSpawnMsg *msg_ = nullptr;
std::string extraInfoStr_;
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_APP_SPAWN_MSG_WRAPPER_H

View File

@ -1,82 +0,0 @@
/*
* Copyright (c) 2021 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.
*/
#ifndef OHOS_ABILITY_RUNTIME_APP_SPAWN_SOCKET_H
#define OHOS_ABILITY_RUNTIME_APP_SPAWN_SOCKET_H
#include <string>
#include "nocopyable.h"
#include "client_socket.h"
#include "appexecfwk_errors.h"
namespace OHOS {
namespace AppExecFwk {
class AppSpawnSocket {
public:
/**
* Constructor.
*/
explicit AppSpawnSocket(bool isNWebSpawn = false);
/**
* Destructor
*/
virtual ~AppSpawnSocket();
/**
* Disable copy.
*/
DISALLOW_COPY_AND_MOVE(AppSpawnSocket);
/**
* Create client socket and connect the socket.
*/
virtual ErrCode OpenAppSpawnConnection();
/**
* Close the client socket.
*/
virtual void CloseAppSpawnConnection();
/**
* Write message to the socket.
*
* @param buf, message pointer.
* @param len, message size.
*/
virtual ErrCode WriteMessage(const void *buf, const int32_t len);
/**
* Read message from the socket.
*
* @param buf, message pointer.
* @param len, message size.
*/
virtual ErrCode ReadMessage(void *buf, const int32_t len);
/**
* Set function, unit test also use it.
*
* @param clientSocket, client socket.
*/
void SetClientSocket(const std::shared_ptr<OHOS::AppSpawn::ClientSocket> clientSocket);
private:
std::shared_ptr<AppSpawn::ClientSocket> clientSocket_;
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_APP_SPAWN_SOCKET_H

View File

@ -17,7 +17,7 @@
#define OHOS_ABILITY_RUNTIME_APPSPAWN_UTIL_H
#include "ability_info.h"
#include "app_spawn_msg_wrapper.h"
#include "app_spawn_client.h"
#include "want.h"
namespace OHOS {
@ -29,30 +29,30 @@ static uint32_t BuildStartFlags(const AAFwk::Want &want, const ApplicationInfo &
{
uint32_t startFlags = 0x0;
if (want.GetBoolParam("coldStart", false)) {
startFlags = startFlags | (AppSpawn::ClientSocket::APPSPAWN_COLD_BOOT << StartFlags::COLD_START);
startFlags = startFlags | (START_FLAG_BASE << StartFlags::COLD_START);
}
if (want.GetIntParam(DLP_PARAMS_INDEX, 0) != 0) {
startFlags = startFlags | (AppSpawn::ClientSocket::APPSPAWN_COLD_BOOT << StartFlags::DLP_MANAGER);
startFlags = startFlags | (START_FLAG_BASE << StartFlags::DLP_MANAGER);
}
if (applicationInfo.debug) {
startFlags = startFlags | (AppSpawn::ClientSocket::APPSPAWN_COLD_BOOT << StartFlags::DEBUGGABLE);
startFlags = startFlags | (START_FLAG_BASE << StartFlags::DEBUGGABLE);
}
if (applicationInfo.asanEnabled) {
startFlags = startFlags | (AppSpawn::ClientSocket::APPSPAWN_COLD_BOOT << StartFlags::ASANENABLED);
startFlags = startFlags | (START_FLAG_BASE << StartFlags::ASANENABLED);
}
if (want.GetBoolParam("nativeDebug", false)) {
startFlags = startFlags | (AppSpawn::ClientSocket::APPSPAWN_COLD_BOOT << StartFlags::NATIVEDEBUG);
startFlags = startFlags | (START_FLAG_BASE << StartFlags::NATIVEDEBUG);
}
if (applicationInfo.gwpAsanEnabled) {
startFlags = startFlags | (AppSpawn::ClientSocket::APPSPAWN_COLD_BOOT << StartFlags::GWP_ENABLED_FORCE);
startFlags = startFlags | (START_FLAG_BASE << StartFlags::GWP_ENABLED_FORCE);
}
if (applicationInfo.isSystemApp) {
startFlags = startFlags | (AppSpawn::ClientSocket::APPSPAWN_COLD_BOOT << StartFlags::GWP_ENABLED_NORMAL);
startFlags = startFlags | (START_FLAG_BASE << StartFlags::GWP_ENABLED_NORMAL);
}
if (applicationInfo.tsanEnabled) {
startFlags = startFlags | (AppSpawn::ClientSocket::APPSPAWN_COLD_BOOT << StartFlags::TSANENABLED);
startFlags = startFlags | (START_FLAG_BASE << StartFlags::TSANENABLED);
}
return startFlags;
@ -63,7 +63,7 @@ static uint32_t BuildStartFlags(const AAFwk::Want &want, const AbilityInfo &abil
uint32_t startFlags = BuildStartFlags(want, abilityInfo.applicationInfo);
if (abilityInfo.extensionAbilityType == ExtensionAbilityType::BACKUP) {
startFlags = startFlags | (AppSpawn::ClientSocket::APPSPAWN_COLD_BOOT << StartFlags::BACKUP_EXTENSION);
startFlags = startFlags | (START_FLAG_BASE << StartFlags::BACKUP_EXTENSION);
}
return startFlags;

View File

@ -23,8 +23,6 @@
*AppRunningManager*;
*AppRunningRecord*;
*AppSpawnClient*;
*AppSpawnMsgWrapper*;
*AppSpawnSocket*;
*AppStateObserverManager*;
*ModuleRunningRecord*;
*QuickFixCallbackWithRecord*;

View File

@ -34,7 +34,6 @@
#include "app_utils.h"
#include "appfreeze_manager.h"
#include "application_state_observer_stub.h"
#include "appspawn_mount_permission.h"
#include "appspawn_util.h"
#include "bundle_constants.h"
#include "common_event.h"
@ -2087,10 +2086,10 @@ int32_t AppMgrServiceInner::StartPerfProcess(const std::shared_ptr<AppRunningRec
}
auto&& startMsg = appRecord->GetStartMsg();
startMsg.code = static_cast<int32_t>(AppSpawn::ClientSocket::AppOperateCode::SPAWN_NATIVE_PROCESS);
startMsg.code = static_cast<int32_t>(MSG_SPAWN_NATIVE_PROCESS);
if (!isSandboxApp) {
TAG_LOGD(AAFwkTag::APPMGR, "debuggablePipe sandbox: false.");
startMsg.flags |= (AppSpawn::ClientSocket::APPSPAWN_COLD_BOOT << StartFlags::NO_SANDBOX);
startMsg.flags |= (START_FLAG_BASE << StartFlags::NO_SANDBOX);
} else {
TAG_LOGI(AAFwkTag::APPMGR, "debuggablePipe sandbox: true");
}
@ -2202,8 +2201,9 @@ void AppMgrServiceInner::StartProcessVerifyPermission(const BundleInfo &bundleIn
}
}
std::set<std::string> mountPermissionList = AppSpawn::AppspawnMountPermission::GetMountPermissionList();
for (std::string permission : mountPermissionList) {
int32_t maxPermissionIndex = GetMaxPermissionIndex();
for (int i = 0; i < maxPermissionIndex; i++) {
std::string permission = std::string(GetPermissionByIndex(i));
if (Security::AccessToken::AccessTokenKit::VerifyAccessToken(token, permission, false) ==
Security::AccessToken::PERMISSION_GRANTED) {
permissions.insert(permission);
@ -2254,11 +2254,10 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str
uint8_t setAllowInternet = 0;
uint8_t allowInternet = 1;
std::vector<int32_t> gids;
std::set<std::string> permissions;
StartProcessVerifyPermission(bundleInfo, hasAccessBundleDirReq, setAllowInternet, allowInternet, gids,
permissions);
AppSpawnStartMsg startMsg;
StartProcessVerifyPermission(bundleInfo, hasAccessBundleDirReq, setAllowInternet, allowInternet,
gids, startMsg.permissions);
startMsg.uid = bundleInfo.uid;
startMsg.gid = bundleInfo.gid;
startMsg.gids = gids;
@ -2274,14 +2273,13 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str
startMsg.dataGroupInfoList = dataGroupInfoList;
startMsg.hapFlags = bundleInfo.isPreInstallApp ? 1 : 0;
startMsg.mountPermissionFlags = AppSpawn::AppspawnMountPermission::GenPermissionCode(permissions);
startMsg.ownerId = bundleInfo.signatureInfo.appIdentifier;
if (hasAccessBundleDirReq) {
startMsg.flags = startMsg.flags | APP_ACCESS_BUNDLE_DIR;
startMsg.flags = startMsg.flags | StartFlags::ACCESS_BUNDLE_DIR;
}
if (VerifyPermission(bundleInfo, PERMISSION_GET_BUNDLE_RESOURCES)) {
startMsg.flags = startMsg.flags | GET_BUNDLE_RESOURCES_FLAG;
startMsg.flags = startMsg.flags | StartFlags::BUNDLE_RESOURCES;
}
SetOverlayInfo(bundleName, userId, startMsg);
@ -4123,7 +4121,7 @@ int AppMgrServiceInner::GetRenderProcessTerminationStatus(pid_t renderPid, int &
AppSpawnStartMsg startMsg;
startMsg.pid = renderPid;
startMsg.code = 1; // 1: GET_RENDER_TERMINATION_STATUS
startMsg.code = MSG_GET_RENDER_TERMINATION_STATUS;
ErrCode errCode = nwebSpawnClient->GetRenderProcessTerminationStatus(startMsg, status);
if (FAILED(errCode)) {
TAG_LOGE(AAFwkTag::APPMGR, "failed to get render process termination status, errCode %{public}08x", errCode);

View File

@ -12,227 +12,74 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "app_spawn_client.h"
#include <unordered_set>
#include "hitrace_meter.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "nlohmann/json.hpp"
#include "securec.h"
namespace OHOS {
namespace AppExecFwk {
namespace {
const int32_t CONNECT_RETRY_DELAY = 200 * 1000; // 200ms
const int32_t CONNECT_RETRY_MAX_TIMES = 2;
const size_t SOCK_MAX_SEND_BUFFER = 5 * 1024; // 5KB
} // namespace
const std::string HSPLIST_BUNDLES = "bundles";
const std::string HSPLIST_MODULES = "modules";
const std::string HSPLIST_VERSIONS = "versions";
const std::string DATAGROUPINFOLIST_DATAGROUPID = "dataGroupId";
const std::string DATAGROUPINFOLIST_GID = "gid";
const std::string DATAGROUPINFOLIST_DIR = "dir";
const std::string JSON_DATA_APP = "/data/app/el2/";
const std::string JSON_GROUP = "/group/";
const std::string VERSION_PREFIX = "v";
const std::string APPSPAWN_CLIENT_USER_NAME = "APP_MANAGER_SERVICE";
constexpr int32_t RIGHT_SHIFT_STEP = 1;
constexpr int32_t START_FLAG_TEST_NUM = 1;
}
AppSpawnClient::AppSpawnClient(bool isNWebSpawn)
{
socket_ = std::make_shared<AppSpawnSocket>(isNWebSpawn);
HILOG_INFO("AppspawnCreateClient");
if (isNWebSpawn) {
serviceName_ = NWEBSPAWN_SERVER_NAME;
}
state_ = SpawnConnectionState::STATE_NOT_CONNECT;
}
AppSpawnClient::~AppSpawnClient()
{
CloseConnection();
}
ErrCode AppSpawnClient::OpenConnection()
{
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
if (state_ == SpawnConnectionState::STATE_CONNECTED) {
return ERR_OK;
return 0;
}
if (!socket_) {
TAG_LOGE(AAFwkTag::APPMGR, "failed to open connection without socket!");
return ERR_APPEXECFWK_BAD_APPSPAWN_SOCKET;
}
int32_t retryCount = 1;
ErrCode errCode = socket_->OpenAppSpawnConnection();
while (FAILED(errCode) && retryCount <= CONNECT_RETRY_MAX_TIMES) {
TAG_LOGW(AAFwkTag::APPMGR, "failed to OpenConnection, retry times %{public}d ...", retryCount);
usleep(CONNECT_RETRY_DELAY);
errCode = socket_->OpenAppSpawnConnection();
retryCount++;
}
if (SUCCEEDED(errCode)) {
state_ = SpawnConnectionState::STATE_CONNECTED;
} else {
TAG_LOGE(AAFwkTag::APPMGR, "failed to openConnection, errorCode is %{public}08x", errCode);
HILOG_INFO("OpenConnection");
AppSpawnClientHandle handle = nullptr;
ErrCode ret = 0;
ret = AppSpawnClientInit(serviceName_.c_str(), &handle);
if (FAILED(ret)) {
HILOG_ERROR("create appspawn client faild.");
state_ = SpawnConnectionState::STATE_CONNECT_FAILED;
return ret;
}
return errCode;
handle_ = handle;
state_ = SpawnConnectionState::STATE_CONNECTED;
return ret;
}
ErrCode AppSpawnClient::PreStartNWebSpawnProcess()
void AppSpawnClient::CloseConnection()
{
TAG_LOGI(AAFwkTag::APPMGR, "PreStartNWebSpawnProcess");
int32_t retryCount = 1;
ErrCode errCode = PreStartNWebSpawnProcessImpl();
while (FAILED(errCode) && retryCount <= CONNECT_RETRY_MAX_TIMES) {
TAG_LOGE(AAFwkTag::APPMGR, "failed to Start NWebSpawn Process, retry times %{public}d ...", retryCount);
usleep(CONNECT_RETRY_DELAY);
errCode = PreStartNWebSpawnProcessImpl();
retryCount++;
HILOG_INFO("AppspawnDestroyClient");
if (state_ == SpawnConnectionState::STATE_CONNECTED) {
AppSpawnClientDestroy(handle_);
}
return errCode;
}
ErrCode AppSpawnClient::PreStartNWebSpawnProcessImpl()
{
TAG_LOGI(AAFwkTag::APPMGR, "PreStartNWebSpawnProcessImpl");
if (!socket_) {
TAG_LOGE(AAFwkTag::APPMGR, "failed to Pre Start NWebSpawn Process without socket!");
return ERR_APPEXECFWK_BAD_APPSPAWN_SOCKET;
}
// openconnection failed, return fail
std::lock_guard<std::mutex> lock(socketLock_);
ErrCode result = OpenConnection();
if (FAILED(result)) {
TAG_LOGE(AAFwkTag::APPMGR, "connect to nwebspawn failed!");
return result;
}
std::unique_ptr<AppSpawnClient, void (*)(AppSpawnClient *)> autoCloseConnection(
this, [](AppSpawnClient *client) { client->CloseConnection(); });
return result;
}
ErrCode AppSpawnClient::StartProcess(const AppSpawnStartMsg &startMsg, pid_t &pid)
{
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
if (!socket_) {
TAG_LOGE(AAFwkTag::APPMGR, "failed to startProcess without socket!");
return ERR_APPEXECFWK_BAD_APPSPAWN_SOCKET;
}
int32_t retryCount = 1;
ErrCode errCode = StartProcessImpl(startMsg, pid);
while (FAILED(errCode) && retryCount <= CONNECT_RETRY_MAX_TIMES) {
TAG_LOGW(AAFwkTag::APPMGR, "failed to StartProcess, retry times %{public}d ...", retryCount);
usleep(CONNECT_RETRY_DELAY);
errCode = StartProcessImpl(startMsg, pid);
retryCount++;
}
return errCode;
}
ErrCode AppSpawnClient::StartProcessImpl(const AppSpawnStartMsg &startMsg, pid_t &pid)
{
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
std::lock_guard<std::mutex> lock(socketLock_);
ErrCode result = OpenConnection();
// open connection failed, return fail
if (FAILED(result)) {
TAG_LOGE(AAFwkTag::APPMGR, "connect to appSpawn failed!");
return result;
}
std::unique_ptr<AppSpawnClient, void (*)(AppSpawnClient *)> autoCloseConnection(
this, [](AppSpawnClient *client) { client->CloseConnection(); });
AppSpawnMsgWrapper msgWrapper;
if (!msgWrapper.AssembleMsg(startMsg)) {
TAG_LOGE(AAFwkTag::APPMGR, "AssembleMsg failed!");
return ERR_APPEXECFWK_ASSEMBLE_START_MSG_FAILED;
}
AppSpawnPidMsg pidMsg;
if (msgWrapper.IsValid()) {
result = socket_->WriteMessage(msgWrapper.GetMsgBuf(), msgWrapper.GetMsgLength());
if (FAILED(result)) {
TAG_LOGE(AAFwkTag::APPMGR, "WriteMessage failed!");
return result;
}
result = StartProcessForWriteMsg(msgWrapper);
if (FAILED(result)) {
TAG_LOGE(AAFwkTag::APPMGR, "StartProcessForWriteMsg failed!");
return result;
}
result = socket_->ReadMessage(reinterpret_cast<void *>(pidMsg.pidBuf), LEN_PID);
if (FAILED(result)) {
TAG_LOGE(AAFwkTag::APPMGR, "ReadMessage failed!");
return result;
}
}
if (pidMsg.pid <= 0) {
TAG_LOGE(AAFwkTag::APPMGR, "invalid pid!");
result = ERR_APPEXECFWK_INVALID_PID;
} else {
pid = pidMsg.pid;
}
return result;
}
ErrCode AppSpawnClient::StartProcessForWriteMsg(const AppSpawnMsgWrapper &msgWrapper)
{
ErrCode result = ERR_OK;
result = WriteStrInfoMessage(msgWrapper.GetExtraInfoStr());
if (FAILED(result)) {
TAG_LOGE(AAFwkTag::APPMGR, "Write extra info failed!");
return result;
}
return result;
}
ErrCode AppSpawnClient::WriteStrInfoMessage(const std::string &strInfo)
{
ErrCode result = ERR_OK;
if (strInfo.empty()) {
return result;
}
// split msg
const char *buff = strInfo.c_str();
size_t leftLen = strInfo.size() + 1;
TAG_LOGD(AAFwkTag::APPMGR, "strInfo length is %zu", leftLen);
while (leftLen >= SOCK_MAX_SEND_BUFFER) {
result = socket_->WriteMessage(buff, SOCK_MAX_SEND_BUFFER);
if (FAILED(result)) {
return result;
}
buff += SOCK_MAX_SEND_BUFFER;
leftLen -= SOCK_MAX_SEND_BUFFER;
}
TAG_LOGD(AAFwkTag::APPMGR, "strInfo: leftLen = %zu", leftLen);
if (leftLen > 0) {
result = socket_->WriteMessage(buff, leftLen);
}
return result;
}
ErrCode AppSpawnClient::GetRenderProcessTerminationStatus(const AppSpawnStartMsg &startMsg, int &status)
{
if (!socket_) {
TAG_LOGE(AAFwkTag::APPMGR, "socket_ is null!");
return ERR_APPEXECFWK_BAD_APPSPAWN_SOCKET;
}
std::lock_guard<std::mutex> lock(socketLock_);
ErrCode result = OpenConnection();
// open connection failed, return fail
if (FAILED(result)) {
TAG_LOGE(AAFwkTag::APPMGR, "connect to appSpawn failed!");
return result;
}
std::unique_ptr<AppSpawnClient, void (*)(AppSpawnClient *)> autoCloseConnection(
this, [](AppSpawnClient *client) { client->CloseConnection(); });
AppSpawnMsgWrapper msgWrapper;
if (!msgWrapper.AssembleMsg(startMsg)) {
TAG_LOGE(AAFwkTag::APPMGR, "AssembleMsg failed!");
return ERR_APPEXECFWK_ASSEMBLE_START_MSG_FAILED;
}
if (msgWrapper.IsValid()) {
result = socket_->WriteMessage(msgWrapper.GetMsgBuf(), msgWrapper.GetMsgLength());
if (FAILED(result)) {
TAG_LOGE(AAFwkTag::APPMGR, "WriteMessage failed!");
return result;
}
result = socket_->ReadMessage(reinterpret_cast<void *>(&status), sizeof(int));
if (FAILED(result)) {
TAG_LOGE(AAFwkTag::APPMGR, "ReadMessage failed!");
return result;
}
}
return result;
state_ = SpawnConnectionState::STATE_NOT_CONNECT;
}
SpawnConnectionState AppSpawnClient::QueryConnectionState() const
@ -240,17 +87,313 @@ SpawnConnectionState AppSpawnClient::QueryConnectionState() const
return state_;
}
void AppSpawnClient::CloseConnection()
static std::string DumpDataGroupInfoListToJson(const DataGroupInfoList &dataGroupInfoList)
{
if (socket_ && state_ == SpawnConnectionState::STATE_CONNECTED) {
socket_->CloseAppSpawnConnection();
nlohmann::json dataGroupInfoListJson;
for (auto& dataGroupInfo : dataGroupInfoList) {
dataGroupInfoListJson[DATAGROUPINFOLIST_DATAGROUPID].emplace_back(dataGroupInfo.dataGroupId);
dataGroupInfoListJson[DATAGROUPINFOLIST_GID].emplace_back(std::to_string(dataGroupInfo.gid));
std::string dir = JSON_DATA_APP + std::to_string(dataGroupInfo.userId)
+ JSON_GROUP + dataGroupInfo.uuid;
dataGroupInfoListJson[DATAGROUPINFOLIST_DIR].emplace_back(dir);
}
state_ = SpawnConnectionState::STATE_NOT_CONNECT;
return dataGroupInfoListJson.dump();
}
void AppSpawnClient::SetSocket(const std::shared_ptr<AppSpawnSocket> socket)
static std::string DumpHspListToJson(const HspList &hspList)
{
socket_ = socket;
nlohmann::json hspListJson;
for (auto& hsp : hspList) {
hspListJson[HSPLIST_BUNDLES].emplace_back(hsp.bundleName);
hspListJson[HSPLIST_MODULES].emplace_back(hsp.moduleName);
hspListJson[HSPLIST_VERSIONS].emplace_back(VERSION_PREFIX + std::to_string(hsp.versionCode));
}
return hspListJson.dump();
}
static std::string DumpAppEnvToJson(const std::map<std::string, std::string> &appEnv)
{
nlohmann::json appEnvJson;
for (const auto &[envName, envValue] : appEnv) {
appEnvJson[envName] = envValue;
}
return appEnvJson.dump();
}
int32_t AppSpawnClient::SetDacInfo(const AppSpawnStartMsg &startMsg, AppSpawnReqMsgHandle reqHandle)
{
int32_t ret = 0;
AppDacInfo appDacInfo = {0};
appDacInfo.uid = startMsg.uid;
appDacInfo.gid = startMsg.gid;
appDacInfo.gidCount = startMsg.gids.size() + startMsg.dataGroupInfoList.size();
for (uint32_t i = 0; i < startMsg.gids.size(); i++) {
appDacInfo.gidTable[i] = startMsg.gids[i];
}
for (uint32_t i = startMsg.gids.size(); i < appDacInfo.gidCount; i++) {
appDacInfo.gidTable[i] = startMsg.dataGroupInfoList[i - startMsg.gids.size()].gid;
}
ret = strcpy_s(appDacInfo.userName, sizeof(appDacInfo.userName), APPSPAWN_CLIENT_USER_NAME.c_str());
if (ret) {
HILOG_ERROR("failed to set dac userName!");
return ret;
}
return AppSpawnReqMsgSetAppDacInfo(reqHandle, &appDacInfo);
}
int32_t AppSpawnClient::SetMountPermission(const AppSpawnStartMsg &startMsg, AppSpawnReqMsgHandle reqHandle)
{
int32_t ret = 0;
std::set<std::string> mountPermissionList = startMsg.permissions;
for (std::string permission : mountPermissionList) {
ret = AppSpawnReqMsgAddPermission(reqHandle, permission.c_str());
if (ret != 0) {
HILOG_ERROR("AppSpawnReqMsgAddPermission %{public}s failed", permission.c_str());
return ret;
}
}
return ret;
}
int32_t AppSpawnClient::SetStartFlags(const AppSpawnStartMsg &startMsg, AppSpawnReqMsgHandle reqHandle)
{
int32_t ret = 0;
uint32_t startFlagTmp = startMsg.flags;
int flagIndex = 0;
while (startFlagTmp > 0) {
if (startFlagTmp & START_FLAG_TEST_NUM) {
ret = AppSpawnReqMsgSetAppFlag(reqHandle, static_cast<AppFlagsIndex>(flagIndex));
if (ret != 0) {
HILOG_ERROR("SetFlagIdx %{public}d failed, ret: %{public}d", flagIndex, ret);
return ret;
}
}
startFlagTmp = startFlagTmp >> RIGHT_SHIFT_STEP;
flagIndex++;
}
return ret;
}
int32_t AppSpawnClient::AppspawnSetExtMsg(const AppSpawnStartMsg &startMsg, AppSpawnReqMsgHandle reqHandle)
{
int32_t ret = 0;
if ((ret = AppSpawnReqMsgAddStringInfo(reqHandle, MSG_EXT_NAME_RENDER_CMD, startMsg.renderParam.c_str()))) {
HILOG_ERROR("SetRenderCmd failed, ret: %{public}d", ret);
return ret;
}
if (!startMsg.hspList.empty() &&
(ret = AppSpawnReqMsgAddStringInfo(reqHandle, MSG_EXT_NAME_HSP_LIST,
DumpHspListToJson(startMsg.hspList).c_str()))) {
HILOG_ERROR("SetExtraHspList failed, ret: %{public}d", ret);
return ret;
}
if (!startMsg.dataGroupInfoList.empty() &&
(ret = AppSpawnReqMsgAddStringInfo(reqHandle, MSG_EXT_NAME_DATA_GROUP,
DumpDataGroupInfoListToJson(startMsg.dataGroupInfoList).c_str()))) {
HILOG_ERROR("SetExtraDataGroupInfo failed, ret: %{public}d", ret);
return ret;
}
if (!startMsg.overlayInfo.empty() &&
(ret = AppSpawnReqMsgAddStringInfo(reqHandle, MSG_EXT_NAME_OVERLAY, startMsg.overlayInfo.c_str()))) {
HILOG_ERROR("SetExtraOverlayInfo failed, ret: %{public}d", ret);
return ret;
}
if (!startMsg.appEnv.empty() &&
(ret = AppSpawnReqMsgAddStringInfo(reqHandle, MSG_EXT_NAME_APP_ENV,
DumpAppEnvToJson(startMsg.appEnv).c_str()))) {
HILOG_ERROR("SetExtraEnv failed, ret: %{public}d", ret);
return ret;
}
return ret;
}
int32_t AppSpawnClient::AppspawnCreateDefaultMsg(const AppSpawnStartMsg &startMsg, AppSpawnReqMsgHandle reqHandle)
{
HILOG_INFO("AppspawnCreateDefaultMsg");
int32_t ret = 0;
do {
if ((ret = SetDacInfo(startMsg, reqHandle))) {
HILOG_ERROR("SetDacInfo failed, ret: %{public}d", ret);
break;
}
if ((ret = AppSpawnReqMsgSetBundleInfo(reqHandle, startMsg.bundleIndex, startMsg.bundleName.c_str()))) {
HILOG_ERROR("SetBundleInfo failed, ret: %{public}d", ret);
break;
}
if ((ret = AppSpawnReqMsgSetAppInternetPermissionInfo(reqHandle, startMsg.allowInternet,
startMsg.setAllowInternet))) {
HILOG_ERROR("SetInternetPermissionInfo failed, ret: %{public}d", ret);
break;
}
if (startMsg.ownerId.size() &&
(ret = AppSpawnReqMsgSetAppOwnerId(reqHandle, startMsg.ownerId.c_str()))) {
HILOG_ERROR("SetOwnerId %{public}s failed, ret: %{public}d",
startMsg.ownerId.c_str(), ret);
break;
}
if ((ret = AppSpawnReqMsgSetAppAccessToken(reqHandle, startMsg.accessTokenIdEx))) {
HILOG_ERROR("SetAccessTokenInfo %{public}llu failed, ret: %{public}d",
startMsg.accessTokenIdEx, ret);
break;
}
if ((ret = AppSpawnReqMsgSetAppDomainInfo(reqHandle, startMsg.hapFlags, startMsg.apl.c_str()))) {
HILOG_ERROR("SetDomainInfo failed, hapFlags is %{public}d, apl is %{public}s, ret: %{public}d",
startMsg.hapFlags, startMsg.apl.c_str(), ret);
break;
}
if ((ret = SetStartFlags(startMsg, reqHandle))) {
HILOG_ERROR("SetStartFlags failed, ret: %{public}d", ret);
break;
}
if ((ret = SetMountPermission(startMsg, reqHandle))) {
HILOG_ERROR("SetMountPermission failed, ret: %{public}d", ret);
break;
}
if (AppspawnSetExtMsg(startMsg, reqHandle)) {
break;
}
return ret;
} while (0);
HILOG_INFO("AppSpawnReqMsgFree");
AppSpawnReqMsgFree(reqHandle);
return ret;
}
bool AppSpawnClient::VerifyMsg(const AppSpawnStartMsg &startMsg)
{
HILOG_INFO("VerifyMsg");
if (startMsg.code == MSG_APP_SPAWN ||
startMsg.code == MSG_SPAWN_NATIVE_PROCESS) {
if (startMsg.uid < 0) {
HILOG_ERROR("invalid uid! [%{public}d]", startMsg.uid);
return false;
}
if (startMsg.gid < 0) {
HILOG_ERROR("invalid gid! [%{public}d]", startMsg.gid);
return false;
}
if (startMsg.gids.size() > APP_MAX_GIDS) {
HILOG_ERROR("too many app gids!");
return false;
}
for (uint32_t i = 0; i < startMsg.gids.size(); ++i) {
if (startMsg.gids[i] < 0) {
HILOG_ERROR("invalid gids array! [%{public}d]", startMsg.gids[i]);
return false;
}
}
if (startMsg.procName.empty() || startMsg.procName.size() >= MAX_PROC_NAME_LEN) {
HILOG_ERROR("invalid procName!");
return false;
}
} else if (startMsg.code == MSG_GET_RENDER_TERMINATION_STATUS) {
if (startMsg.pid < 0) {
HILOG_ERROR("invalid pid!");
return false;
}
} else {
HILOG_ERROR("invalid code!");
return false;
}
return true;
}
// 预启动
int32_t AppSpawnClient::PreStartNWebSpawnProcess()
{
HILOG_INFO("PreStartNWebSpawnProcess");
return OpenConnection();
}
int32_t AppSpawnClient::StartProcess(const AppSpawnStartMsg &startMsg, pid_t &pid)
{
HILOG_INFO("StartProcess");
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
if (!VerifyMsg(startMsg)) {
return ERR_INVALID_VALUE; // 入参非法
}
int32_t ret = 0;
AppSpawnReqMsgHandle reqHandle = nullptr;
ret = OpenConnection();
if (ret != 0) {
return ret;
}
ret = AppSpawnReqMsgCreate(static_cast<AppSpawnMsgType>(startMsg.code), startMsg.procName.c_str(), &reqHandle);
if (ret != 0) {
HILOG_ERROR("AppSpawnReqMsgCreate faild.");
return ret;
}
ret = AppspawnCreateDefaultMsg(startMsg, reqHandle);
if (ret != 0) {
return ret; // create msg failed
}
HILOG_INFO("AppspawnSendMsg");
AppSpawnResult result = {0};
ret = AppSpawnClientSendMsg(handle_, reqHandle, &result);
if (ret != 0) {
HILOG_ERROR("appspawn send msg faild!");
return ret;
}
if (result.pid <= 0) {
HILOG_ERROR("pid invalid!");
return ERR_APPEXECFWK_INVALID_PID;
} else {
pid = result.pid;
}
HILOG_INFO("pid = [%{public}d]", pid);
return ret;
}
int32_t AppSpawnClient::GetRenderProcessTerminationStatus(const AppSpawnStartMsg &startMsg, int &status)
{
HILOG_INFO("GetRenderProcessTerminationStatus");
int32_t ret = 0;
AppSpawnReqMsgHandle reqHandle = nullptr;
// 入参校验
if (!VerifyMsg(startMsg)) {
return ERR_INVALID_VALUE; // 入参非法
}
ret = OpenConnection();
if (ret != 0) {
return ret;
}
ret = AppSpawnTerminateMsgCreate(startMsg.pid, &reqHandle);
if (ret != 0) {
HILOG_ERROR("AppSpawnTerminateMsgCreate faild.");
return ret;
}
HILOG_INFO("AppspawnSendMsg");
AppSpawnResult result = {0};
ret = AppSpawnClientSendMsg(handle_, reqHandle, &result);
status = result.result;
if (ret != 0) {
HILOG_ERROR("appspawn send msg faild!");
return ret;
}
HILOG_INFO("status = [%{public}d]", status);
return ret;
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -48,13 +48,14 @@ ohos_fuzztest("AbilityMgrRestFuzzTest") {
"ability_base:want",
"ability_base:zuri",
"ability_runtime:ability_deps_wrapper",
"appspawn:appspawn_socket_client",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"ffrt:libffrt",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_core",
"napi:ace_napi",
"safwk:system_ability_fwk",

View File

@ -42,6 +42,7 @@ ohos_fuzztest("AmsManagerFuzzTest") {
external_deps = [
"ability_base:want",
"ability_base:zuri",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",

View File

@ -47,12 +47,13 @@ ohos_fuzztest("AmsMgrSchedulerFuzzTest") {
"ability_base:session_info",
"ability_base:want",
"ability_base:zuri",
"appspawn:appspawn_socket_client",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"ffrt:libffrt",
"init:libbegetutil",
"ipc:ipc_core",
"napi:ace_napi",
"safwk:system_ability_fwk",

View File

@ -48,10 +48,12 @@ ohos_fuzztest("AppManagerFuzzTest") {
external_deps = [
"ability_base:want",
"ability_base:zuri",
"appspawn:appspawn_socket_client",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"ffrt:libffrt",
"init:libbegetutil",
"ipc:ipc_core",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",

View File

@ -45,12 +45,13 @@ ohos_fuzztest("AppMgrRestFuzzTest") {
"ability_base:session_info",
"ability_base:want",
"ability_base:zuri",
"appspawn:appspawn_socket_client",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"ffrt:libffrt",
"init:libbegetutil",
"ipc:ipc_core",
"napi:ace_napi",
"safwk:system_ability_fwk",

View File

@ -23,9 +23,7 @@
#include "app_process_manager.h"
#define private public
#include "app_spawn_client.h"
#include "app_spawn_msg_wrapper.h"
#undef private
#include "app_spawn_socket.h"
#include "remote_client_manager.h"
#include "window_focus_changed_listener.h"
#include "ability_record.h"
@ -96,29 +94,12 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
appProcessManager.ClearRecentAppList();
AppSpawnClient appSpawnClient;
appSpawnClient.OpenConnection();
std::shared_ptr<AppSpawnSocket> socket;
appSpawnClient.SetSocket(socket);
appSpawnClient.PreStartNWebSpawnProcess();
appSpawnClient.PreStartNWebSpawnProcessImpl();
AppSpawnStartMsg startMsg;
appSpawnClient.StartProcess(startMsg, pid);
int status = static_cast<int>(GetU32Data(data));
appSpawnClient.GetRenderProcessTerminationStatus(startMsg, status);
appSpawnClient.QueryConnectionState();
appSpawnClient.CloseConnection();
AppSpawnMsgWrapper appSpawnMsgWrapper;
appSpawnMsgWrapper.AssembleMsg(startMsg);
appSpawnMsgWrapper.VerifyMsg(startMsg);
appSpawnMsgWrapper.DumpMsg();
appSpawnMsgWrapper.FreeMsg();
AppSpawnSocket appSpawnSocket;
std::shared_ptr<OHOS::AppSpawn::ClientSocket> clientSocket;
appSpawnSocket.SetClientSocket(clientSocket);
appSpawnSocket.OpenAppSpawnConnection();
int32_t len = appSpawnMsgWrapper.GetMsgLength();
appSpawnSocket.WriteMessage(appSpawnMsgWrapper.GetMsgBuf(), len);
appSpawnSocket.ReadMessage(reinterpret_cast<void*>(*data), len);
appSpawnSocket.CloseAppSpawnConnection();
RemoteClientManager remoteClientManager;
std::shared_ptr<BundleMgrHelper> bundleManagerHelper = nullptr;
remoteClientManager.SetBundleManagerHelper(bundleManagerHelper);
@ -132,7 +113,7 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
sptr<Rosen::FocusChangeInfo> focusChangeInfo = nullptr;
windowFocusChangedListener.OnFocused(focusChangeInfo);
windowFocusChangedListener.OnUnfocused(focusChangeInfo);
return (appSpawnClient.StartProcessImpl(startMsg, pid) != 0);
return (appSpawnClient.StartProcess(startMsg, pid) != 0);
}
}

View File

@ -24,10 +24,7 @@ ohos_fuzztest("AppMgrServiceFirstFuzzTest") {
fuzz_config_file =
"${ability_runtime_test_path}/fuzztest/appmgrservicefirst_fuzzer"
include_dirs = [
"${ability_runtime_services_path}/appmgr/include",
"${appspawn_path}/interfaces/innerkits/include",
]
include_dirs = [ "${ability_runtime_services_path}/appmgr/include" ]
cflags = [
"-g",
"-O0",
@ -50,12 +47,13 @@ ohos_fuzztest("AppMgrServiceFirstFuzzTest") {
"ability_base:configuration",
"ability_base:want",
"ability_base:zuri",
"appspawn:appspawn_socket_client",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"ffrt:libffrt",
"init:libbegetutil",
"ipc:ipc_core",
"napi:ace_napi",
"safwk:system_ability_fwk",

View File

@ -22,10 +22,12 @@ namespace OHOS {
namespace AppExecFwk {
class MockAppSpawnClient : public AppSpawnClient {
public:
MockAppSpawnClient()
MockAppSpawnClient(): AppSpawnClient(false)
{}
virtual ~MockAppSpawnClient()
{}
MOCK_METHOD0(OpenConnection, ErrCode());
MOCK_METHOD0(CloseConnection, void());
MOCK_METHOD2(StartProcess, ErrCode(const AppSpawnStartMsg& startMsg, pid_t& pid));
};
} // namespace AppExecFwk

View File

@ -1,59 +0,0 @@
/*
* Copyright (c) 2021 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.
*/
#ifndef MOCK_OHOS_ABILITY_RUNTIME_MOCK_APP_SPAWN_SOCKET_H
#define MOCK_OHOS_ABILITY_RUNTIME_MOCK_APP_SPAWN_SOCKET_H
#include "gmock/gmock.h"
#include "app_spawn_socket.h"
#include "app_spawn_msg_wrapper.h"
#include "hilog_wrapper.h"
#include "securec.h"
namespace OHOS {
namespace AppExecFwk {
class MockAppSpawnSocket : public AppSpawnSocket {
public:
MockAppSpawnSocket() : AppSpawnSocket(false) {}
virtual ~MockAppSpawnSocket() = default;
MOCK_METHOD0(OpenAppSpawnConnection, ErrCode());
MOCK_METHOD0(CloseAppSpawnConnection, void());
MOCK_METHOD2(WriteMessage, ErrCode(const void* buf, const int32_t len));
MOCK_METHOD2(ReadMessage, ErrCode(void* buf, int32_t len));
ErrCode ReadImpl(void* buf, [[maybe_unused]] int32_t len)
{
if (buf == nullptr) {
return ERR_NO_MEMORY;
}
AppSpawnPidMsg msg;
msg.pid = expectPid_;
if (memcpy_s(buf, sizeof(msg), msg.pidBuf, sizeof(msg)) != 0) {
return ERR_APPEXECFWK_ASSEMBLE_START_MSG_FAILED;
}
return ERR_OK;
}
void SetExpectPid(int32_t expectPid)
{
expectPid_ = expectPid;
}
private:
int32_t expectPid_ = 0;
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // MOCK_OHOS_ABILITY_RUNTIME_MOCK_APP_SPAWN_SOCKET_H

View File

@ -52,7 +52,6 @@ ohos_source_set("appmgr_mst_source") {
"${ability_runtime_innerkits_path}/app_manager:app_manager",
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
"${ability_runtime_services_path}/common:perm_verification",
"${appspawn_path}/interfaces/innerkits:appspawn_socket_client",
"${bundlefwk_inner_api_path}/appexecfwk_base:appexecfwk_base",
"${bundlefwk_inner_api_path}/appexecfwk_core:appexecfwk_core",
"${c_utils_base_path}:utils",
@ -67,8 +66,10 @@ ohos_source_set("appmgr_mst_source") {
"ability_base:want",
"ability_runtime:ability_deps_wrapper",
"access_token:libaccesstoken_sdk",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_core",
"common_event_service:cesfwk_innerkits",
"ffrt:libffrt",
@ -77,6 +78,7 @@ ohos_source_set("appmgr_mst_source") {
"hisysevent:libhisysevent",
"hitrace:hitrace_meter",
"init:libbeget_proxy",
"init:libbegetutil",
"ipc:ipc_core",
]
@ -106,8 +108,6 @@ group("moduletest") {
"ipc_ams_mgr_test:moduletest",
"ipc_app_mgr_test:moduletest",
"ipc_app_scheduler_test:moduletest",
"service_app_spawn_client_test:moduletest",
"service_event_drive_test:moduletest",
"service_start_process_test:moduletest",
"specified_ability_service_test:moduletest",
]

View File

@ -31,6 +31,7 @@ ohos_moduletest("AmsAbilityRunningRecordModuleTest") {
]
external_deps = [
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"ffrt:libffrt",
"hicollie:libhicollie",

View File

@ -30,7 +30,6 @@
#include "mock_ability_token.h"
#include "mock_app_scheduler.h"
#include "mock_app_spawn_client.h"
#include "mock_app_spawn_socket.h"
#include "mock_iapp_state_callback.h"
#include "mock_native_token.h"
#include "system_ability_definition.h"
@ -929,20 +928,12 @@ HWTEST_F(AmsAppLifeCycleModuleTest, StateChange_013, TestSize.Level3)
EXPECT_TRUE(serviceInner_->remoteClientManager_);
EXPECT_TRUE(serviceInner_->remoteClientManager_->GetSpawnClient());
auto mockAppSpawnSocket = std::make_shared<MockAppSpawnSocket>();
EXPECT_TRUE(mockAppSpawnSocket);
serviceInner_->remoteClientManager_->GetSpawnClient()->SetSocket(mockAppSpawnSocket);
EXPECT_EQ(serviceInner_->QueryAppSpawnConnectionState(), SpawnConnectionState::STATE_NOT_CONNECT);
EXPECT_CALL(*mockAppSpawnSocket, OpenAppSpawnConnection()).Times(1).WillOnce(Return(0));
int ret = serviceInner_->OpenAppSpawnConnection();
EXPECT_EQ(ret, 0);
EXPECT_EQ(serviceInner_->QueryAppSpawnConnectionState(), SpawnConnectionState::STATE_CONNECTED);
EXPECT_CALL(*mockAppSpawnSocket, CloseAppSpawnConnection()).Times(1);
serviceInner_->OnStop();
usleep(50000);
EXPECT_EQ(serviceInner_->QueryAppSpawnConnectionState(), SpawnConnectionState::STATE_NOT_CONNECT);

View File

@ -38,6 +38,7 @@ ohos_moduletest("AmsAppMgrServiceModuleTest") {
external_deps = [
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"ffrt:libffrt",
"hicollie:libhicollie",

View File

@ -24,7 +24,6 @@
#include "app_scheduler_host.h"
#include "app_scheduler_proxy.h"
#include "mock_app_mgr_service_inner.h"
#include "mock_app_spawn_socket.h"
#include "mock_native_token.h"
#include "semaphore_ex.h"

View File

@ -33,6 +33,7 @@ ohos_moduletest("AmsAppRecentListModuleTest") {
]
external_deps = [
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"ffrt:libffrt",
"hicollie:libhicollie",

View File

@ -40,6 +40,7 @@ ohos_moduletest("AppRunningProcessesInfoModuleTest") {
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"ffrt:libffrt",
"hilog:libhilog",

View File

@ -35,6 +35,7 @@ ohos_moduletest("AmsAppServiceFlowModuleTest") {
]
external_deps = [
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"ffrt:libffrt",
"hicollie:libhicollie",

View File

@ -41,6 +41,7 @@ ohos_moduletest("AmsIpcAmsmgrModuleTest") {
external_deps = [
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"ffrt:libffrt",
"hicollie:libhicollie",

View File

@ -1,62 +0,0 @@
# Copyright (c) 2021-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.
import("//build/test.gni")
import("//foundation/ability/ability_runtime/ability_runtime.gni")
module_output_path = "ability_runtime/mstappmgrservice"
ohos_moduletest("AmsServiceAppSpawnClientModuleTest") {
module_out_path = module_output_path
include_dirs = [
"${ability_runtime_test_path}/mock/services_appmgr_test/include",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper",
]
defines = [ "usleep(time) = MockSleep(time)" ]
sources = [ "ams_service_app_spawn_client_module_test.cpp" ]
deps = [
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source",
]
external_deps = [
"bundle_framework:appexecfwk_base",
"ffrt:libffrt",
"hicollie:libhicollie",
"hilog:libhilog",
"ipc:ipc_core",
"safwk:system_ability_fwk",
]
if (ability_runtime_graphics) {
deps += [
"${ability_runtime_native_path}/appkit:appkit_manager_helper",
"${global_path}/i18n/frameworks/intl:intl_util",
]
external_deps += [ "window_manager:libwm" ]
}
if (background_task_mgr_continuous_task_enable) {
external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ]
}
}
group("moduletest") {
testonly = true
deps = [ ":AmsServiceAppSpawnClientModuleTest" ]
}

View File

@ -33,6 +33,7 @@ ohos_moduletest("AmsServiceStartModuleTest") {
]
external_deps = [
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"ffrt:libffrt",
"hicollie:libhicollie",

View File

@ -365,9 +365,6 @@ group("unittest") {
"ams_mgr_scheduler_test:unittest",
"ams_mgr_stub_test:unittest",
"ams_recent_app_list_test:unittest",
"ams_service_app_spawn_client_test:unittest",
"ams_service_app_spawn_msg_wrapper_test:unittest",
"ams_service_app_spawn_socket_test:unittest",
"ams_service_load_ability_process_test:unittest",
"ams_service_startup_test:unittest",
"app_debug_info_test:unittest",
@ -395,7 +392,6 @@ group("unittest") {
"app_scheduler_proxy_test:unittest",
"app_scheduler_test:unittest",
"app_spawn_client_test:unittest",
"app_spawn_socket_test:unittest",
"app_state_observer_manager_test:unittest",
"app_utils_test:unittest",
"appkit:unittest",

View File

@ -36,8 +36,6 @@ ohos_unittest("AmsAbilityRunningRecordTest") {
"${ability_runtime_services_path}/appmgr/src/app_running_record.cpp",
"${ability_runtime_services_path}/appmgr/src/app_running_status_module.cpp",
"${ability_runtime_services_path}/appmgr/src/app_spawn_client.cpp",
"${ability_runtime_services_path}/appmgr/src/app_spawn_msg_wrapper.cpp",
"${ability_runtime_services_path}/appmgr/src/app_spawn_socket.cpp",
"${ability_runtime_services_path}/appmgr/src/app_state_observer_manager.cpp",
"${ability_runtime_services_path}/appmgr/src/child_process_record.cpp",
"${ability_runtime_services_path}/appmgr/src/render_state_observer_manager.cpp",
@ -67,14 +65,16 @@ ohos_unittest("AmsAbilityRunningRecordTest") {
external_deps = [
"access_token:libaccesstoken_sdk",
"appspawn:appspawn_socket_client",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"ffrt:libffrt",
"hilog:libhilog",
"hisysevent:libhisysevent",
"hitrace:hitrace_meter",
"init:libbeget_proxy",
"init:libbegetutil",
"ipc:ipc_core",
"kv_store:distributeddata_inner",
"memmgr:memmgrclient",

View File

@ -55,15 +55,17 @@ ohos_unittest("AppDeathRecipientTest") {
"ability_base:want",
"ability_runtime:ability_deps_wrapper",
"access_token:libaccesstoken_sdk",
"appspawn:appspawn_socket_client",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"ffrt:libffrt",
"hilog:libhilog",
"hisysevent:libhisysevent",
"hitrace:hitrace_meter",
"init:libbeget_proxy",
"init:libbegetutil",
"ipc:ipc_core",
]

View File

@ -36,8 +36,6 @@ ohos_unittest("AmsAppLifeCycleTest") {
"${ability_runtime_services_path}/appmgr/src/app_running_manager.cpp",
"${ability_runtime_services_path}/appmgr/src/app_running_record.cpp",
"${ability_runtime_services_path}/appmgr/src/app_spawn_client.cpp",
"${ability_runtime_services_path}/appmgr/src/app_spawn_msg_wrapper.cpp",
"${ability_runtime_services_path}/appmgr/src/app_spawn_socket.cpp",
"${ability_runtime_services_path}/appmgr/src/app_state_observer_manager.cpp",
"${ability_runtime_services_path}/appmgr/src/module_running_record.cpp",
"${ability_runtime_services_path}/appmgr/src/remote_client_manager.cpp",
@ -64,14 +62,16 @@ ohos_unittest("AmsAppLifeCycleTest") {
"ability_base:want",
"ability_runtime:ability_deps_wrapper",
"access_token:libaccesstoken_sdk",
"appspawn:appspawn_socket_client",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"ffrt:libffrt",
"hilog:libhilog",
"hisysevent:libhisysevent",
"hitrace:hitrace_meter",
"init:libbeget_proxy",
"init:libbegetutil",
"ipc:ipc_core",
"kv_store:distributeddata_inner",
"memmgr:memmgrclient",

View File

@ -26,7 +26,6 @@
#include "mock_ability_token.h"
#include "mock_app_scheduler.h"
#include "mock_app_spawn_client.h"
#include "mock_app_spawn_socket.h"
#include "mock_iapp_state_callback.h"
#include "mock_bundle_manager.h"
@ -1326,8 +1325,7 @@ HWTEST_F(AmsAppLifeCycleTest, Stop_001, TestSize.Level1)
HWTEST_F(AmsAppLifeCycleTest, Stop_002, TestSize.Level1)
{
std::shared_ptr<AppSpawnClient> appSpawnClient = std::make_shared<AppSpawnClient>();
std::shared_ptr<MockAppSpawnSocket> socketMock = std::make_shared<MockAppSpawnSocket>();
appSpawnClient->SetSocket(socketMock);
std::shared_ptr<MockAppSpawnClient> socketMock = std::make_shared<MockAppSpawnClient>();
EXPECT_EQ(SpawnConnectionState::STATE_NOT_CONNECT, appSpawnClient->QueryConnectionState());
EXPECT_CALL(*socketMock, OpenAppSpawnConnection()).WillOnce(Return(ERR_OK));
serviceInner_->SetAppSpawnClient(appSpawnClient);
@ -1367,8 +1365,6 @@ HWTEST_F(AmsAppLifeCycleTest, Stop_003, TestSize.Level1)
EXPECT_EQ(appState, appRecord->GetState());
std::shared_ptr<AppSpawnClient> appSpawnClient = std::make_shared<AppSpawnClient>();
std::shared_ptr<MockAppSpawnSocket> socketMock = std::make_shared<MockAppSpawnSocket>();
appSpawnClient->SetSocket(socketMock);
EXPECT_EQ(SpawnConnectionState::STATE_NOT_CONNECT, appSpawnClient->QueryConnectionState());
EXPECT_CALL(*socketMock, OpenAppSpawnConnection()).WillOnce(Return(ERR_OK));
serviceInner_->SetAppSpawnClient(appSpawnClient);

View File

@ -52,6 +52,7 @@ ohos_unittest("AmsAppMgrClientTest") {
"ability_base:want",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",

View File

@ -53,11 +53,13 @@ ohos_unittest("AmsAppRunningRecordTest") {
external_deps = [
"ability_base:configuration",
"ability_base:want",
"appspawn:appspawn_socket_client",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"ffrt:libffrt",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_core",
]

View File

@ -37,8 +37,6 @@ ohos_unittest("AmsWorkFlowTest") {
"${ability_runtime_services_path}/appmgr/src/app_running_manager.cpp",
"${ability_runtime_services_path}/appmgr/src/app_running_record.cpp",
"${ability_runtime_services_path}/appmgr/src/app_spawn_client.cpp",
"${ability_runtime_services_path}/appmgr/src/app_spawn_msg_wrapper.cpp",
"${ability_runtime_services_path}/appmgr/src/app_spawn_socket.cpp",
"${ability_runtime_services_path}/appmgr/src/app_state_observer_manager.cpp",
"${ability_runtime_services_path}/appmgr/src/module_running_record.cpp",
"${ability_runtime_services_path}/appmgr/src/remote_client_manager.cpp",
@ -63,14 +61,16 @@ ohos_unittest("AmsWorkFlowTest") {
"ability_base:want",
"ability_runtime:ability_deps_wrapper",
"access_token:libaccesstoken_sdk",
"appspawn:appspawn_socket_client",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"ffrt:libffrt",
"hilog:libhilog",
"hisysevent:libhisysevent",
"hitrace:hitrace_meter",
"init:libbeget_proxy",
"init:libbegetutil",
"ipc:ipc_core",
"kv_store:distributeddata_inner",
"memmgr:memmgrclient",

View File

@ -60,6 +60,7 @@ ohos_unittest("AmsMgrKillProcessTest") {
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",

View File

@ -43,11 +43,13 @@ ohos_unittest("AmsMgrProxyTest") {
"ability_base:configuration",
"ability_base:want",
"ability_runtime:app_manager",
"appspawn:appspawn_socket_client",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"ffrt:libffrt",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_core",
"samgr:samgr_proxy",
]

View File

@ -34,6 +34,7 @@ ohos_unittest("ams_mgr_scheduler_dump_test") {
"ability_base:configuration",
"ability_base:want",
"ability_runtime:app_manager",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",

View File

@ -52,6 +52,7 @@ ohos_unittest("ams_mgr_scheduler_test") {
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_core",
"ffrt:libffrt",
"hilog:libhilog",

View File

@ -41,11 +41,13 @@ ohos_unittest("AmsMgrStubTest") {
external_deps = [
"ability_base:want",
"ability_runtime:app_manager",
"appspawn:appspawn_socket_client",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"ffrt:libffrt",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_core",
"samgr:samgr_proxy",
]

View File

@ -38,8 +38,6 @@ ohos_unittest("AmsRecentAppListTest") {
"${ability_runtime_services_path}/appmgr/src/app_running_record.cpp",
"${ability_runtime_services_path}/appmgr/src/app_running_status_module.cpp",
"${ability_runtime_services_path}/appmgr/src/app_spawn_client.cpp",
"${ability_runtime_services_path}/appmgr/src/app_spawn_msg_wrapper.cpp",
"${ability_runtime_services_path}/appmgr/src/app_spawn_socket.cpp",
"${ability_runtime_services_path}/appmgr/src/app_state_observer_manager.cpp",
"${ability_runtime_services_path}/appmgr/src/child_process_record.cpp",
"${ability_runtime_services_path}/appmgr/src/module_running_record.cpp",
@ -76,15 +74,17 @@ ohos_unittest("AmsRecentAppListTest") {
"ability_base:want",
"ability_runtime:ability_deps_wrapper",
"access_token:libaccesstoken_sdk",
"appspawn:appspawn_socket_client",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"ffrt:libffrt",
"hilog:libhilog",
"hisysevent:libhisysevent",
"hitrace:hitrace_meter",
"init:libbeget_proxy",
"init:libbegetutil",
"ipc:ipc_core",
"kv_store:distributeddata_inner",
"memmgr:memmgrclient",

View File

@ -72,7 +72,7 @@ ohos_unittest("AmsServiceAppSpawnClientTest") {
external_deps = [
"ability_base:want",
"access_token:libaccesstoken_sdk",
"appspawn:appspawn_socket_client",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_core",
"common_event_service:cesfwk_innerkits",
"ffrt:libffrt",
@ -81,6 +81,7 @@ ohos_unittest("AmsServiceAppSpawnClientTest") {
"hisysevent:libhisysevent",
"hitrace:hitrace_meter",
"init:libbeget_proxy",
"init:libbegetutil",
"ipc:ipc_core",
"kv_store:distributeddata_inner",
"memmgr:memmgrclient",

View File

@ -1,50 +0,0 @@
# Copyright (c) 2021 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/test.gni")
import("//foundation/ability/ability_runtime/ability_runtime.gni")
module_output_path = "ability_runtime/appmgrservice"
ohos_unittest("AmsServiceAppSpawnMsgWrapperTest") {
module_out_path = module_output_path
cflags_cc = []
include_dirs = []
defines = [ "usleep(time) = MockSleep(time)" ]
sources = [
"${ability_runtime_services_path}/appmgr/src/app_spawn_msg_wrapper.cpp",
"${ability_runtime_services_path}/appmgr/src/app_spawn_socket.cpp",
]
sources += [ "ams_service_app_spawn_msg_wrapper_test.cpp" ]
cflags = []
if (target_cpu == "arm") {
cflags += [ "-DBINDER_IPC_32BIT" ]
}
configs = []
deps = [ "${ability_runtime_test_path}/unittest:appmgr_test_source" ]
external_deps = [
"hilog:libhilog",
"ipc:ipc_core",
]
}
group("unittest") {
testonly = true
deps = [ ":AmsServiceAppSpawnMsgWrapperTest" ]
}

View File

@ -1,48 +0,0 @@
# Copyright (c) 2021 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/test.gni")
import("//foundation/ability/ability_runtime/ability_runtime.gni")
module_output_path = "ability_runtime/appmgrservice"
ohos_unittest("AmsServiceAppSpawnSocketTest") {
module_out_path = module_output_path
cflags_cc = []
include_dirs = [ "${appspawn_path}/test/mock/include" ]
defines = [ "usleep(time) = MockSleep(time)" ]
sources =
[ "${ability_runtime_services_path}/appmgr/src/app_spawn_socket.cpp" ]
sources += [ "ams_service_app_spawn_socket_test.cpp" ]
cflags = []
if (target_cpu == "arm") {
cflags += [ "-DBINDER_IPC_32BIT" ]
}
deps = [ "${ability_runtime_test_path}/unittest:appmgr_test_source" ]
external_deps = [
"appspawn:appspawn_socket_client",
"hilog:libhilog",
"ipc:ipc_core",
]
}
group("unittest") {
testonly = true
deps = [ ":AmsServiceAppSpawnSocketTest" ]
}

View File

@ -42,8 +42,6 @@ ohos_unittest("AmsServiceEventDriveTest") {
"${ability_runtime_services_path}/appmgr/src/app_running_record.cpp",
"${ability_runtime_services_path}/appmgr/src/app_running_status_module.cpp",
"${ability_runtime_services_path}/appmgr/src/app_spawn_client.cpp",
"${ability_runtime_services_path}/appmgr/src/app_spawn_msg_wrapper.cpp",
"${ability_runtime_services_path}/appmgr/src/app_spawn_socket.cpp",
"${ability_runtime_services_path}/appmgr/src/app_state_observer_manager.cpp",
"${ability_runtime_services_path}/appmgr/src/child_process_record.cpp",
"${ability_runtime_services_path}/appmgr/src/render_state_observer_manager.cpp",
@ -76,9 +74,10 @@ ohos_unittest("AmsServiceEventDriveTest") {
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"appspawn:appspawn_socket_client",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"ffrt:libffrt",
"hicollie:libhicollie",
@ -86,6 +85,7 @@ ohos_unittest("AmsServiceEventDriveTest") {
"hisysevent:libhisysevent",
"hitrace:hitrace_meter",
"init:libbeget_proxy",
"init:libbegetutil",
"ipc:ipc_core",
"kv_store:distributeddata_inner",
"memmgr:memmgrclient",

View File

@ -38,8 +38,6 @@ ohos_unittest("AmsServiceLoadAbilityProcessTest") {
"${ability_runtime_services_path}/appmgr/src/app_running_record.cpp",
"${ability_runtime_services_path}/appmgr/src/app_running_status_module.cpp",
"${ability_runtime_services_path}/appmgr/src/app_spawn_client.cpp",
"${ability_runtime_services_path}/appmgr/src/app_spawn_msg_wrapper.cpp",
"${ability_runtime_services_path}/appmgr/src/app_spawn_socket.cpp",
"${ability_runtime_services_path}/appmgr/src/app_state_observer_manager.cpp",
"${ability_runtime_services_path}/appmgr/src/child_process_record.cpp",
"${ability_runtime_services_path}/appmgr/src/module_running_record.cpp",
@ -78,15 +76,17 @@ ohos_unittest("AmsServiceLoadAbilityProcessTest") {
"ability_base:want",
"ability_runtime:ability_deps_wrapper",
"access_token:libaccesstoken_sdk",
"appspawn:appspawn_socket_client",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"ffrt:libffrt",
"hilog:libhilog",
"hisysevent:libhisysevent",
"hitrace:hitrace_meter",
"init:libbeget_proxy",
"init:libbegetutil",
"ipc:ipc_core",
"kv_store:distributeddata_inner",
"memmgr:memmgrclient",

View File

@ -39,8 +39,6 @@ ohos_unittest("AmsServiceStartupTest") {
"${ability_runtime_services_path}/appmgr/src/app_running_record.cpp",
"${ability_runtime_services_path}/appmgr/src/app_running_status_module.cpp",
"${ability_runtime_services_path}/appmgr/src/app_spawn_client.cpp",
"${ability_runtime_services_path}/appmgr/src/app_spawn_msg_wrapper.cpp",
"${ability_runtime_services_path}/appmgr/src/app_spawn_socket.cpp",
"${ability_runtime_services_path}/appmgr/src/app_state_observer_manager.cpp",
"${ability_runtime_services_path}/appmgr/src/child_process_record.cpp",
"${ability_runtime_services_path}/appmgr/src/render_state_observer_manager.cpp",
@ -71,7 +69,7 @@ ohos_unittest("AmsServiceStartupTest") {
external_deps = [
"ability_base:want",
"access_token:libaccesstoken_sdk",
"appspawn:appspawn_socket_client",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
@ -81,6 +79,7 @@ ohos_unittest("AmsServiceStartupTest") {
"hisysevent:libhisysevent",
"hitrace:hitrace_meter",
"init:libbeget_proxy",
"init:libbegetutil",
"ipc:ipc_core",
"kv_store:distributeddata_inner",
"memmgr:memmgrclient",

View File

@ -36,11 +36,13 @@ ohos_unittest("AppDebugInfoTest") {
external_deps = [
"ability_base:want",
"appspawn:appspawn_socket_client",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"ffrt:libffrt",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_core",
"samgr:samgr_proxy",
"window_manager:libwm",

View File

@ -35,10 +35,12 @@ ohos_unittest("AppDebugListenerProxyTest") {
]
external_deps = [
"appspawn:appspawn_socket_client",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_core",
]
}

View File

@ -33,11 +33,13 @@ ohos_unittest("AppDebugListenerStubTest") {
external_deps = [
"ability_base:want",
"appspawn:appspawn_socket_client",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"ffrt:libffrt",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_core",
"samgr:samgr_proxy",
]

View File

@ -39,10 +39,12 @@ ohos_unittest("app_debug_manager_test") {
]
external_deps = [
"appspawn:appspawn_socket_client",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_core",
]
}

View File

@ -33,9 +33,12 @@ ohos_unittest("app_launch_data_test") {
]
external_deps = [
"appspawn:appspawn_socket_client",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_core",
]
}

View File

@ -44,6 +44,7 @@ ohos_unittest("app_mgr_service_dump_test") {
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",

View File

@ -35,8 +35,6 @@ ohos_unittest("AMSEventHandlerTest") {
"${ability_runtime_services_path}/appmgr/src/app_running_record.cpp",
"${ability_runtime_services_path}/appmgr/src/app_running_status_module.cpp",
"${ability_runtime_services_path}/appmgr/src/app_spawn_client.cpp",
"${ability_runtime_services_path}/appmgr/src/app_spawn_msg_wrapper.cpp",
"${ability_runtime_services_path}/appmgr/src/app_spawn_socket.cpp",
"${ability_runtime_services_path}/appmgr/src/app_state_observer_manager.cpp",
"${ability_runtime_services_path}/appmgr/src/child_process_record.cpp",
"${ability_runtime_services_path}/appmgr/src/module_running_record.cpp",
@ -72,9 +70,10 @@ ohos_unittest("AMSEventHandlerTest") {
"ability_base:want",
"ability_runtime:ability_deps_wrapper",
"access_token:libaccesstoken_sdk",
"appspawn:appspawn_socket_client",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"ffrt:libffrt",
"hicollie:libhicollie",
@ -82,6 +81,7 @@ ohos_unittest("AMSEventHandlerTest") {
"hisysevent:libhisysevent",
"hitrace:hitrace_meter",
"init:libbeget_proxy",
"init:libbegetutil",
"ipc:ipc_core",
"kv_store:distributeddata_inner",
"memmgr:memmgrclient",

View File

@ -47,6 +47,7 @@ ohos_unittest("app_mgr_service_inner_tdd_test") {
"ability_runtime:app_manager",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",

View File

@ -50,6 +50,7 @@ ohos_unittest("AppMgrServiceInnerTest") {
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",

View File

@ -48,6 +48,7 @@ ohos_unittest("app_mgr_service_test") {
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",

View File

@ -44,9 +44,10 @@ ohos_unittest("app_running_manager_test") {
"ability_base:configuration",
"ability_base:want",
"access_token:libaccesstoken_sdk",
"appspawn:appspawn_socket_client",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"ffrt:libffrt",
"hicollie:libhicollie",

View File

@ -35,8 +35,6 @@ ohos_unittest("AppRunningProcessesInfoTest") {
"${ability_runtime_services_path}/appmgr/src/app_running_record.cpp",
"${ability_runtime_services_path}/appmgr/src/app_running_status_module.cpp",
"${ability_runtime_services_path}/appmgr/src/app_spawn_client.cpp",
"${ability_runtime_services_path}/appmgr/src/app_spawn_msg_wrapper.cpp",
"${ability_runtime_services_path}/appmgr/src/app_spawn_socket.cpp",
"${ability_runtime_services_path}/appmgr/src/app_state_observer_manager.cpp",
"${ability_runtime_services_path}/appmgr/src/child_process_record.cpp",
"${ability_runtime_services_path}/appmgr/src/render_state_observer_manager.cpp",
@ -70,14 +68,16 @@ ohos_unittest("AppRunningProcessesInfoTest") {
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"appspawn:appspawn_socket_client",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"ffrt:libffrt",
"hilog:libhilog",
"hisysevent:libhisysevent",
"hitrace:hitrace_meter",
"init:libbeget_proxy",
"init:libbegetutil",
"ipc:ipc_core",
"kv_store:distributeddata_inner",
"memmgr:memmgrclient",

View File

@ -48,9 +48,10 @@ ohos_unittest("app_running_record_test") {
"ability_base:configuration",
"ability_base:want",
"access_token:libaccesstoken_sdk",
"appspawn:appspawn_socket_client",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"ffrt:libffrt",
"hicollie:libhicollie",

View File

@ -36,6 +36,7 @@ ohos_unittest("AppSpawnClientTest") {
"ability_runtime:app_manager",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",

View File

@ -57,19 +57,6 @@ HWTEST_F(AppSpawnClientTest, PreStartNWebSpawnProcess_001, TestSize.Level0)
EXPECT_EQ(ret, ERR_OK);
}
/**
* @tc.name: PreStartNWebSpawnProcessImpl_001
* @tc.desc: prestart nwebspawn process.
* @tc.type: FUNC
* @tc.require: issueI5W4S7
*/
HWTEST_F(AppSpawnClientTest, PreStartNWebSpawnProcessImpl_001, TestSize.Level0)
{
auto asc = std::make_shared<AppSpawnClient>(true);
int ret = asc->PreStartNWebSpawnProcessImpl();
EXPECT_EQ(ret, ERR_OK);
}
/**
* @tc.name: PreStartNWebSpawnProcessImpl_002
* @tc.desc: prestart nwebspawn process.
@ -80,7 +67,7 @@ HWTEST_F(AppSpawnClientTest, PreStartNWebSpawnProcessImpl_002, TestSize.Level0)
{
auto asc = std::make_shared<AppSpawnClient>(true);
asc->OpenConnection();
int ret = asc->PreStartNWebSpawnProcessImpl();
int ret = asc->PreStartNWebSpawnProcess();
EXPECT_EQ(ret, ERR_OK);
}
} // namespace AppExecFwk

View File

@ -1,72 +0,0 @@
# Copyright (c) 2021-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.
import("//build/test.gni")
import("//foundation/ability/ability_runtime/ability_runtime.gni")
module_output_path = "ability_runtime/appmgr"
ohos_unittest("app_spawn_socket_test") {
module_out_path = module_output_path
cflags_cc = []
include_dirs = [
"${ability_runtime_services_path}/appmgr/include",
"${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include",
]
sources =
[ "${ability_runtime_services_path}/appmgr/src/ams_mgr_scheduler.cpp" ]
sources += [ "app_spawn_socket_test.cpp" ]
configs = [ "${ability_runtime_test_path}/unittest:appmgr_test_config" ]
cflags = []
if (target_cpu == "arm") {
cflags += [ "-DBINDER_IPC_32BIT" ]
}
deps = [
"${ability_runtime_innerkits_path}/app_manager:app_manager",
"${ability_runtime_services_path}/appmgr:libappms",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_services_path}/common:task_handler_wrap",
"${ability_runtime_test_path}/unittest:appmgr_test_source",
]
external_deps = [
"access_token:libaccesstoken_sdk",
"bundle_framework:appexecfwk_core",
"ffrt:libffrt",
"hilog:libhilog",
"ipc:ipc_core",
]
defines = [ "AMS_LOG_TAG = \"AppMgrService\"" ]
if (ability_command_for_test) {
defines += [ "ABILITY_COMMAND_FOR_TEST" ]
}
if (ability_runtime_graphics) {
defines += [ "SUPPORT_GRAPHICS" ]
deps += []
external_deps += [
"i18n:intl_util",
"window_manager:libwm",
]
}
}
group("unittest") {
testonly = true
deps = [ ":app_spawn_socket_test" ]
}

View File

@ -1,180 +0,0 @@
/*
* Copyright (c) 2021-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 <gtest/gtest.h>
#define private public
#include "app_spawn_socket.h"
#undef private
using namespace testing;
using namespace testing::ext;
using namespace OHOS::AppSpawn;
namespace OHOS {
namespace AppExecFwk {
class AppSpawnSocketTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void AppSpawnSocketTest::SetUpTestCase()
{}
void AppSpawnSocketTest::TearDownTestCase()
{}
void AppSpawnSocketTest::SetUp()
{}
void AppSpawnSocketTest::TearDown()
{}
/*
* Feature: AppSpawnSocket
* Function: OpenAppSpawnConnection
* SubFunction: NA
* FunctionPoints: AppSpawnSocket OpenAppSpawnConnection
* EnvConditions: NA
* CaseDescription: Verify OpenAppSpawnConnection
*/
HWTEST_F(AppSpawnSocketTest, OpenAppSpawnConnection_001, TestSize.Level0)
{
auto appSpawnSocket = std::make_shared<AppSpawnSocket>(true);
ErrCode res1 = appSpawnSocket->OpenAppSpawnConnection();
EXPECT_EQ(res1, ERR_OK);
appSpawnSocket->clientSocket_ = nullptr;
ErrCode res2 = appSpawnSocket->OpenAppSpawnConnection();
EXPECT_EQ(res2, ERR_APPEXECFWK_BAD_APPSPAWN_SOCKET);
appSpawnSocket->CloseAppSpawnConnection();
appSpawnSocket->clientSocket_ = nullptr;
appSpawnSocket->CloseAppSpawnConnection();
}
/*
* Feature: AppSpawnSocket
* Function: WriteMessage
* SubFunction: NA
* FunctionPoints: AppSpawnSocket WriteMessage
* EnvConditions: NA
* CaseDescription: Verify WriteMessage
*/
HWTEST_F(AppSpawnSocketTest, WriteMessage_001, TestSize.Level0)
{
auto appSpawnSocket = std::make_shared<AppSpawnSocket>(true);
const void *buf = nullptr;
int32_t len = 0;
ErrCode res = appSpawnSocket->WriteMessage(buf, len);
EXPECT_EQ(res, ERR_INVALID_VALUE);
}
/*
* Feature: AppSpawnSocket
* Function: WriteMessage
* SubFunction: NA
* FunctionPoints: AppSpawnSocket WriteMessage
* EnvConditions: NA
* CaseDescription: Verify WriteMessage
*/
HWTEST_F(AppSpawnSocketTest, WriteMessage_002, TestSize.Level0)
{
auto appSpawnSocket = std::make_shared<AppSpawnSocket>(true);
const void *buf = nullptr;
int32_t len = 1;
ErrCode res = appSpawnSocket->WriteMessage(buf, len);
EXPECT_EQ(res, ERR_INVALID_VALUE);
}
/*
* Feature: AppSpawnSocket
* Function: WriteMessage
* SubFunction: NA
* FunctionPoints: AppSpawnSocket WriteMessage
* EnvConditions: NA
* CaseDescription: Verify WriteMessage
*/
HWTEST_F(AppSpawnSocketTest, WriteMessage_003, TestSize.Level0)
{
auto appSpawnSocket = std::make_shared<AppSpawnSocket>(true);
char data = 'a';
const void *buf = &data;
int32_t len = 1;
ErrCode res1 = appSpawnSocket->WriteMessage(buf, len);
EXPECT_EQ(res1, ERR_APPEXECFWK_SOCKET_WRITE_FAILED);
appSpawnSocket->clientSocket_ = nullptr;
ErrCode res2 = appSpawnSocket->WriteMessage(buf, len);
EXPECT_EQ(res2, ERR_APPEXECFWK_BAD_APPSPAWN_SOCKET);
}
/*
* Feature: AppSpawnSocket
* Function: ReadMessage
* SubFunction: NA
* FunctionPoints: AppSpawnSocket ReadMessage
* EnvConditions: NA
* CaseDescription: Verify ReadMessage
*/
HWTEST_F(AppSpawnSocketTest, ReadMessage_001, TestSize.Level0)
{
auto appSpawnSocket = std::make_shared<AppSpawnSocket>(true);
void *buf = nullptr;
int32_t len = 0;
ErrCode res = appSpawnSocket->ReadMessage(buf, len);
EXPECT_EQ(res, ERR_INVALID_VALUE);
}
/*
* Feature: AppSpawnSocket
* Function: ReadMessage
* SubFunction: NA
* FunctionPoints: AppSpawnSocket ReadMessage
* EnvConditions: NA
* CaseDescription: Verify ReadMessage
*/
HWTEST_F(AppSpawnSocketTest, ReadMessage_002, TestSize.Level0)
{
auto appSpawnSocket = std::make_shared<AppSpawnSocket>(true);
void *buf = nullptr;
int32_t len = 1;
ErrCode res = appSpawnSocket->ReadMessage(buf, len);
EXPECT_EQ(res, ERR_INVALID_VALUE);
}
/*
* Feature: AppSpawnSocket
* Function: ReadMessage
* SubFunction: NA
* FunctionPoints: AppSpawnSocket ReadMessage
* EnvConditions: NA
* CaseDescription: Verify ReadMessage
*/
HWTEST_F(AppSpawnSocketTest, ReadMessage_003, TestSize.Level0)
{
auto appSpawnSocket = std::make_shared<AppSpawnSocket>(true);
char data = 'a';
void *buf = &data;
int32_t len = 1;
ErrCode res1 = appSpawnSocket->ReadMessage(buf, len);
EXPECT_EQ(res1, ERR_APPEXECFWK_SOCKET_READ_FAILED);
appSpawnSocket->clientSocket_ = nullptr;
ErrCode res2 = appSpawnSocket->ReadMessage(buf, len);
EXPECT_EQ(res2, ERR_APPEXECFWK_BAD_APPSPAWN_CLIENT);
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -53,6 +53,7 @@ ohos_unittest("app_state_observer_manager_test") {
external_deps = [
"ability_runtime:ability_manager",
"access_token:libaccesstoken_sdk",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_core",
"ffrt:libffrt",
"hilog:libhilog",

View File

@ -41,6 +41,7 @@ ohos_unittest("dataobs_mgr_service_dump_test") {
"ability_runtime:app_manager",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",

View File

@ -39,10 +39,11 @@ ohos_unittest("render_state_observer_manager_test") {
]
external_deps = [
"appspawn:appspawn_socket_client",
"appspawn:appspawn_client",
"c_utils:utils",
"ffrt:libffrt",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_core",
"window_manager:libwm",
"window_manager:libwsutils",