feat: support opening KIA files

Signed-off-by: yangxuguang-huawei <yangxuguang3@huawei.com>
This commit is contained in:
yangxuguang-huawei
2024-07-27 17:46:08 +08:00
parent fd760ea820
commit b755abe4da
24 changed files with 541 additions and 6 deletions
@@ -90,6 +90,8 @@ ohos_shared_library("app_manager") {
"src/appmgr/configuration_observer_proxy.cpp",
"src/appmgr/configuration_observer_stub.cpp",
"src/appmgr/fault_data.cpp",
"src/appmgr/kia_interceptor_proxy.cpp",
"src/appmgr/kia_interceptor_stub.cpp",
"src/appmgr/memory_level_info.cpp",
"src/appmgr/native_child_notify_proxy.cpp",
"src/appmgr/native_child_notify_stub.cpp",
@@ -28,6 +28,7 @@
#include "child_process_info.h"
#include "child_process_request.h"
#include "fault_data.h"
#include "kia_interceptor_interface.h"
#include "iapp_state_callback.h"
#include "iapplication_state_observer.h"
#include "iconfiguration_observer.h"
@@ -639,6 +640,20 @@ public:
*/
virtual int32_t UnregisterRenderStateObserver(const sptr<IRenderStateObserver> &observer) = 0;
/**
* Register KIA interceptor.
* @param interceptor KIA interceptor.
* @return Returns ERR_OK on success, others on failure.
*/
virtual int32_t RegisterKiaInterceptor(const sptr<IKiaInterceptor> &interceptor) = 0;
/**
* Check if the given pid is a KIA process.
* @param pid process id.
* @return Returns true if it is a KIA process, false otherwise.
*/
virtual int32_t CheckIsKiaProcess(pid_t pid, bool &isKia) = 0;
/**
* Update render state.
* @param renderPid Render pid.
@@ -113,6 +113,8 @@ enum class AppMgrInterfaceCode {
GET_SUPPORTED_PROCESS_CACHE_PIDS = 87,
GET_ALL_CHILDREN_PROCESSES = 88,
SET_SUPPORTED_PROCESS_CACHE = 89,
REGISTER_KIA_INTERCEPTOR = 90,
CHECK_IS_KIA_PROCESS = 91,
};
} // AppExecFwk
} // OHOS
@@ -570,6 +570,20 @@ public:
*/
virtual int32_t UnregisterRenderStateObserver(const sptr<IRenderStateObserver> &observer) override;
/**
* Register KIA interceptor.
* @param interceptor KIA interceptor.
* @return Returns ERR_OK on success, others on failure.
*/
virtual int32_t RegisterKiaInterceptor(const sptr<IKiaInterceptor> &interceptor) override;
/**
* Check if the given pid is a KIA process.
* @param pid process id.
* @return Returns true if it is a KIA process, false otherwise.
*/
virtual int32_t CheckIsKiaProcess(pid_t pid, bool &isKia) override;
/**
* Update render state.
* @param renderPid Render pid.
@@ -138,6 +138,8 @@ private:
int32_t HandleClearUpApplicationDataBySelf(MessageParcel &data, MessageParcel& reply);
int32_t HandleIsFinalAppProcess(MessageParcel &data, MessageParcel &reply);
int32_t HandleRegisterRenderStateObserver(MessageParcel &data, MessageParcel &reply);
int32_t HandleRegisterKiaInterceptor(MessageParcel &data, MessageParcel &reply);
int32_t HandleCheckIsKiaProcess(MessageParcel &data, MessageParcel &reply);
int32_t HandleUnregisterRenderStateObserver(MessageParcel &data, MessageParcel &reply);
int32_t HandleUpdateRenderState(MessageParcel &data, MessageParcel &reply);
int32_t HandleSignRestartAppFlag(MessageParcel &data, MessageParcel &reply);
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2024 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_KIA_INTERCEPTOR_INTERFACE_H
#define OHOS_ABILITY_RUNTIME_KIA_INTERCEPTOR_INTERFACE_H
#include <iremote_broker.h>
#include "want.h"
namespace OHOS {
namespace AppExecFwk {
class IKiaInterceptor : public OHOS::IRemoteBroker {
public:
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.IKiaInterceptor");
virtual int OnIntercept(AAFwk::Want &want) = 0;
enum {
KIA_INTERCEPTOR_ON_INTERCEPT = 0,
};
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_KIA_INTERCEPTOR_INTERFACE_H
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2024 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_KIA_INTERCEPTOR_PROXY_H
#define OHOS_ABILITY_RUNTIME_KIA_INTERCEPTOR_PROXY_H
#include "kia_interceptor_interface.h"
#include <iremote_proxy.h>
namespace OHOS {
namespace AppExecFwk {
class KiaInterceptorProxy : public IRemoteProxy<IKiaInterceptor> {
public:
explicit KiaInterceptorProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IKiaInterceptor>(impl)
{}
virtual ~KiaInterceptorProxy()
{}
virtual int OnIntercept(AAFwk::Want &want) override;
private:
bool WriteInterfaceToken(MessageParcel &data);
static inline BrokerDelegator<KiaInterceptorProxy> delegator_;
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_KIA_INTERCEPTOR_PROXY_H
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2024 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_KIA_INTERCEPTOR_STUB_H
#define OHOS_ABILITY_RUNTIME_KIA_INTERCEPTOR_STUB_H
#include "kia_interceptor_interface.h"
#include <iremote_object.h>
#include <iremote_stub.h>
namespace OHOS {
namespace AppExecFwk {
class KiaInterceptorStub : public IRemoteStub<IKiaInterceptor> {
public:
KiaInterceptorStub();
virtual ~KiaInterceptorStub();
virtual int OnRemoteRequest(
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
private:
int OnInterceptInner(MessageParcel &data, MessageParcel &reply);
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_KIA_INTERCEPTOR_STUB_H
@@ -1987,5 +1987,53 @@ int32_t AppMgrProxy::GetSupportedProcessCachePids(const std::string &bundleName,
}
return reply.ReadInt32();
}
int32_t AppMgrProxy::RegisterKiaInterceptor(const sptr<IKiaInterceptor> &interceptor)
{
if (interceptor == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "interceptor is nullptr.");
return ERR_INVALID_VALUE;
}
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!WriteInterfaceToken(data)) {
TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
return ERR_INVALID_VALUE;
}
if (!data.WriteRemoteObject(interceptor->AsObject())) {
TAG_LOGE(AAFwkTag::APPMGR, "write interceptor failed.");
return ERR_INVALID_VALUE;
}
PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::REGISTER_KIA_INTERCEPTOR, data, reply, option);
return reply.ReadInt32();
}
int32_t AppMgrProxy::CheckIsKiaProcess(pid_t pid, bool &isKia)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!WriteInterfaceToken(data)) {
TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
return ERR_INVALID_VALUE;
}
if (!data.WriteInt32(pid)) {
TAG_LOGE(AAFwkTag::APPMGR, "write pid failed.");
return ERR_INVALID_VALUE;
}
PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::CHECK_IS_KIA_PROCESS, data, reply, option);
int32_t ret = reply.ReadInt32();
if (ret != ERR_OK) {
TAG_LOGE(AAFwkTag::APPMGR, "failed,ret=%{public}d.", ret);
return ret;
}
isKia = reply.ReadBool();
return ERR_OK;
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -353,6 +353,10 @@ int32_t AppMgrStub::OnRemoteRequestInnerSeventh(uint32_t code, MessageParcel &da
return HandleGetSupportedProcessCachePids(data, reply);
case static_cast<uint32_t>(AppMgrInterfaceCode::GET_ALL_CHILDREN_PROCESSES):
return HandleGetAllChildrenProcesses(data, reply);
case static_cast<uint32_t>(AppMgrInterfaceCode::REGISTER_KIA_INTERCEPTOR):
return HandleRegisterKiaInterceptor(data, reply);
case static_cast<uint32_t>(AppMgrInterfaceCode::CHECK_IS_KIA_PROCESS):
return HandleCheckIsKiaProcess(data, reply);
}
return INVALID_FD;
}
@@ -1642,5 +1646,33 @@ int32_t AppMgrStub::GetSupportedProcessCachePids(const std::string &bundleName,
{
return NO_ERROR;
}
int32_t AppMgrStub::HandleRegisterKiaInterceptor(MessageParcel &data, MessageParcel &reply)
{
TAG_LOGD(AAFwkTag::APPMGR, "call");
sptr<IKiaInterceptor> interceptor = iface_cast<IKiaInterceptor>(data.ReadRemoteObject());
if (interceptor == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "interceptor is nullptr.");
return ERR_INVALID_VALUE;
}
reply.WriteInt32(RegisterKiaInterceptor(interceptor));
return NO_ERROR;
}
int32_t AppMgrStub::HandleCheckIsKiaProcess(MessageParcel &data, MessageParcel &reply)
{
TAG_LOGD(AAFwkTag::APPMGR, "call");
int pid = data.ReadInt32();
bool isKia = false;
int result = CheckIsKiaProcess(pid, isKia);
reply.WriteInt32(result);
if (result != ERR_OK) {
TAG_LOGE(AAFwkTag::APPMGR, "failed,result=%{public}d.", result);
return result;
}
reply.WriteBool(isKia);
return NO_ERROR;
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2024 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 "kia_interceptor_proxy.h"
#include "hilog_tag_wrapper.h"
namespace OHOS {
namespace AppExecFwk {
bool KiaInterceptorProxy::WriteInterfaceToken(MessageParcel &data)
{
if (!data.WriteInterfaceToken(KiaInterceptorProxy::GetDescriptor())) {
TAG_LOGE(AAFwkTag::APPMGR, "write interface token failed");
return false;
}
return true;
}
int KiaInterceptorProxy::OnIntercept(AAFwk::Want &want)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!WriteInterfaceToken(data)) {
return ERR_INVALID_VALUE;
}
data.WriteParcelable(&want);
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "Remote() is NULL");
return ERR_INVALID_VALUE;
}
int32_t ret = remote->SendRequest(static_cast<uint32_t>(IKiaInterceptor::KIA_INTERCEPTOR_ON_INTERCEPT),
data, reply, option);
if (ret != NO_ERROR) {
TAG_LOGE(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d.", ret);
return ret;
}
int resultCode = reply.ReadInt32();
if (resultCode != ERR_OK) {
TAG_LOGE(AAFwkTag::APPMGR, "OnIntercept failed, resultCode=%{public}d.", resultCode);
return resultCode;
}
sptr<AAFwk::Want> resultWant = reply.ReadParcelable<AAFwk::Want>();
if (resultWant == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "resultWant is nullptr.");
return ERR_INVALID_VALUE;
}
want = *resultWant;
return resultCode;
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2024 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 "kia_interceptor_stub.h"
#include "hilog_tag_wrapper.h"
namespace OHOS {
namespace AppExecFwk {
KiaInterceptorStub::KiaInterceptorStub() {}
KiaInterceptorStub::~KiaInterceptorStub() {}
int KiaInterceptorStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
{
TAG_LOGD(AAFwkTag::APPMGR, "cmd=%d,flags=%d", code, option.GetFlags());
std::u16string descriptor = KiaInterceptorStub::GetDescriptor();
std::u16string remoteDescriptor = data.ReadInterfaceToken();
if (descriptor != remoteDescriptor) {
TAG_LOGI(AAFwkTag::APPMGR, "local descriptor is not equal to remote");
return ERR_INVALID_STATE;
}
if (code == KIA_INTERCEPTOR_ON_INTERCEPT) {
return OnInterceptInner(data, reply);
}
TAG_LOGW(AAFwkTag::APPMGR, "KiaInterceptorStub::OnRemoteRequest, default case, need check.");
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
int KiaInterceptorStub::OnInterceptInner(MessageParcel &data, MessageParcel &reply)
{
sptr<AAFwk::Want> want = data.ReadParcelable<AAFwk::Want>();
int resultCode = OnIntercept(*want);
if (!reply.WriteInt32(resultCode)) {
TAG_LOGE(AAFwkTag::APPMGR, "write resultCode failed.");
return ERR_INVALID_VALUE;
}
if (!reply.WriteParcelable(want)) {
TAG_LOGE(AAFwkTag::APPMGR, "write want failed.");
return ERR_INVALID_VALUE;
}
return NO_ERROR;
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -83,7 +83,7 @@ enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING };
constexpr int32_t BASE_USER_RANGE = 200000;
constexpr int32_t U0_USER_ID = 0;
constexpr int32_t INVALID_USER_ID = -1;
constexpr const char* KEY_SESSION_ID = "com.ohohs.param.sessionId";
constexpr const char* KEY_SESSION_ID = "com.ohos.param.sessionId";
using OHOS::AppExecFwk::IAbilityController;
class PendingWantManager;
struct StartAbilityInfo;
+2
View File
@@ -77,6 +77,7 @@ ohos_shared_library("libappms") {
defines = [ "AMS_LOG_TAG = \"AppMgrService\"" ]
defines += [ "AMS_LOG_DOMAIN = 0xD001303" ]
defines += [ "OHOS_ACCOUNT_ENABLED" ]
defines += [ "INCLUDE_ZURI" ]
if (product_name != "ohcore") {
defines += [ "APP_MGR_SERVICE_APPMS" ]
@@ -114,6 +115,7 @@ ohos_shared_library("libappms") {
"ability_base:base",
"ability_base:configuration",
"ability_base:want",
"ability_base:zuri",
"access_token:libaccesstoken_sdk",
"appspawn:appspawn_client",
"bundle_framework:appexecfwk_base",
+14
View File
@@ -347,6 +347,20 @@ public:
virtual int32_t UnregisterConfigurationObserver(const sptr<IConfigurationObserver> &observer) override;
/**
* Register KIA interceptor.
* @param interceptor KIA interceptor.
* @return Returns ERR_OK on success, others on failure.
*/
virtual int32_t RegisterKiaInterceptor(const sptr<IKiaInterceptor> &interceptor) override;
/**
* Check if the given pid is a KIA process.
* @param pid process id.
* @return Returns true if it is a KIA process, false otherwise.
*/
virtual int32_t CheckIsKiaProcess(pid_t pid, bool &isKia) override;
bool GetAppRunningStateByBundleName(const std::string &bundleName) override;
int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback) override;
@@ -58,6 +58,7 @@
#include "iremote_object.h"
#include "irender_state_observer.h"
#include "istart_specified_ability_response.h"
#include "kia_interceptor_interface.h"
#include "record_query_result.h"
#include "refbase.h"
#include "remote_client_manager.h"
@@ -472,7 +473,8 @@ public:
const BundleInfo &bundleInfo,
const HapModuleInfo &hapModuleInfo,
std::shared_ptr<AAFwk::Want> want,
int32_t abilityRecordId);
int32_t abilityRecordId,
bool isKia = false);
/**
* OnStop, Application management service stopped.
@@ -1195,6 +1197,10 @@ public:
*/
virtual int32_t GetSupportedProcessCachePids(const std::string &bundleName, std::vector<int32_t> &pidList);
int32_t RegisterKiaInterceptor(const sptr<IKiaInterceptor> &interceptor);
int32_t CheckIsKiaProcess(pid_t pid, bool &isKia);
private:
int32_t ForceKillApplicationInner(const std::string &bundleName, const int userId = -1,
const int appIndex = 0);
@@ -1556,6 +1562,10 @@ private:
const HapModuleInfo &hapModuleInfo, std::string &processName) const;
void DealMultiUserConfig(const Configuration &config, const int32_t userId);
bool CheckIsDebugApp(const std::string &bundleName);
void MakeKiaProcess(std::shared_ptr<AAFwk::Want> want, bool &isKia, std::string &watermarkBusinessName,
bool &isWatermarkEnabled, bool &isFileUri, std::string &processName);
void ProcessKia(bool isKia, std::shared_ptr<AppRunningRecord> appRecord,
const std::string& watermarkBusinessName, bool isWatermarkEnabled);
const std::string TASK_ON_CALLBACK_DIED = "OnCallbackDiedTask";
std::vector<AppStateCallbackWithUserId> appStateCallbacks_;
std::shared_ptr<RemoteClientManager> remoteClientManager_;
@@ -1602,7 +1612,7 @@ private:
std::mutex loadTaskListMutex_;
std::vector<LoadAbilityTaskFunc> loadAbilityTaskFuncList_;
sptr<IKiaInterceptor> kiaInterceptor_;
std::shared_ptr<MultiUserConfigurationMgr> multiUserConfigurationMgr_;
};
} // namespace AppExecFwk
@@ -350,7 +350,9 @@ public:
void SetMultiUserConfigurationMgr(const std::shared_ptr<MultiUserConfigurationMgr>& multiUserConfigurationMgr);
private:
int32_t CheckIsKiaProcess(pid_t pid, bool &isKia);
private:
std::shared_ptr<AbilityRunningRecord> GetAbilityRunningRecord(const int64_t eventId);
int32_t AssignRunningProcessInfoByAppRecord(
std::shared_ptr<AppRunningRecord> appRecord, AppExecFwk::RunningProcessInfo &info) const;
@@ -850,6 +850,16 @@ public:
void SetUIAbilityLaunched(bool hasLaunched);
bool HasUIAbilityLaunched();
inline void SetIsKia(bool isKia)
{
isKia_ = isKia;
}
inline bool GetIsKia() const
{
return isKia_;
}
private:
/**
* SearchTheModuleInfoNeedToUpdated, Get an uninitialized abilityStage data.
@@ -1005,6 +1015,7 @@ private:
bool isDependedOnArkWeb_ = false;
bool isUserRequestCleaning_ = false;
bool hasUIAbilityLaunched_ = false;
bool isKia_ = false;
};
} // namespace AppExecFwk
+20
View File
@@ -1622,5 +1622,25 @@ int32_t AppMgrService::GetSupportedProcessCachePids(const std::string &bundleNam
}
return appMgrServiceInner_->GetSupportedProcessCachePids(bundleName, pidList);
}
int32_t AppMgrService::RegisterKiaInterceptor(const sptr<IKiaInterceptor> &interceptor)
{
TAG_LOGD(AAFwkTag::APPMGR, "Called");
if (!appMgrServiceInner_) {
TAG_LOGE(AAFwkTag::APPMGR, "appMgrServiceInner_ is nullptr");
return ERR_INVALID_VALUE;
}
return appMgrServiceInner_->RegisterKiaInterceptor(interceptor);
}
int32_t AppMgrService::CheckIsKiaProcess(pid_t pid, bool &isKia)
{
TAG_LOGD(AAFwkTag::APPMGR, "Called");
if (!appMgrServiceInner_) {
TAG_LOGE(AAFwkTag::APPMGR, "appMgrServiceInner_ is nullptr");
return ERR_INVALID_VALUE;
}
return appMgrServiceInner_->CheckIsKiaProcess(pid, isKia);
}
} // namespace AppExecFwk
} // namespace OHOS
+97 -2
View File
@@ -236,6 +236,9 @@ constexpr const char* ABILITY_OWNER_USERID = "AbilityMS_Owner_UserId";
constexpr const char* PROCESS_EXIT_EVENT_TASK = "Send Process Exit Event Task";
constexpr const char* KILL_PROCESS_REASON_PREFIX = "Kill Reason:";
constexpr const char* PRELOAD_APPLIATION_TASK = "PreloadApplicactionTask";
constexpr int32_t FILE_GUARD_UID = 6266;
constexpr const char* KEY_WATERMARK_BUSINESS_NAME = "com.ohos.param.watermarkBusinessName";
constexpr const char* KEY_IS_WATERMARK_ENABLED = "com.ohos.param.isWatermarkEnabled";
constexpr const char* PROC_SELF_TASK_PATH = "/proc/self/task/";
@@ -481,6 +484,61 @@ void AppMgrServiceInner::HandlePreloadApplication(const PreloadRequest &request)
}
}
void AppMgrServiceInner::MakeKiaProcess(std::shared_ptr<AAFwk::Want> want, bool &isKia,
std::string &watermarkBusinessName, bool &isWatermarkEnabled,
bool &isFileUri, std::string &processName)
{
if (want == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "want is nullptr");
return;
}
#ifdef INCLUDE_ZURI
isFileUri = !want->GetUriString().empty() && want->GetUri().GetScheme() == "file";
#endif
if (isFileUri && kiaInterceptor_ != nullptr) {
auto resultCode = kiaInterceptor_->OnIntercept(*want);
watermarkBusinessName = want->GetStringParam(KEY_WATERMARK_BUSINESS_NAME);
isWatermarkEnabled = want->GetBoolParam(KEY_IS_WATERMARK_ENABLED, false);
TAG_LOGI(AAFwkTag::APPMGR, "After calling kiaInterceptor_->OnIntercept,"
"resultCode=%{public}d,watermarkBusinessName=%{private}s,isWatermarkEnabled=%{private}d",
resultCode, watermarkBusinessName.c_str(),
static_cast<int>(isWatermarkEnabled));
isKia = (resultCode == ERR_OK && !watermarkBusinessName.empty() && isWatermarkEnabled);
if (isKia) {
processName += "_KIA";
}
}
}
void AppMgrServiceInner::ProcessKia(bool isKia, std::shared_ptr<AppRunningRecord> appRecord,
const std::string& watermarkBusinessName, bool isWatermarkEnabled)
{
if (appRecord == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "appRecord is nullptr");
return;
}
if (!isKia) {
return;
}
#ifdef SUPPORT_SCREEN
TAG_LOGI(AAFwkTag::APPMGR, "Openning KIA file, start setting watermark");
int32_t resultCode = static_cast<int32_t>(WindowManager::GetInstance().SetProcessWatermark(
appRecord->GetPriorityObject()->GetPid(), watermarkBusinessName, isWatermarkEnabled));
if (resultCode != ERR_OK) {
TAG_LOGE(AAFwkTag::APPMGR, "setting watermark fails with result code:%{public}d", resultCode);
return;
}
TAG_LOGI(AAFwkTag::APPMGR, "setting watermark succeeds, start setting snapshot skip");
resultCode = static_cast<int32_t>(WindowManager::GetInstance().SkipSnapshotForAppProcess(
appRecord->GetPriorityObject()->GetPid(), isWatermarkEnabled));
if (resultCode != ERR_OK) {
TAG_LOGE(AAFwkTag::APPMGR, "setting snapshot skip fails with result code:%{public}d", resultCode);
return;
}
TAG_LOGI(AAFwkTag::APPMGR, "setting snapshot skip succeeds");
#endif // SUPPORT_SCREEN
}
void AppMgrServiceInner::LoadAbility(std::shared_ptr<AbilityInfo> abilityInfo, std::shared_ptr<ApplicationInfo> appInfo,
std::shared_ptr<AAFwk::Want> want, std::shared_ptr<AbilityRuntime::LoadParam> loadParam)
{
@@ -527,6 +585,12 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr<AbilityInfo> abilityInfo, s
MakeProcessName(abilityInfo, appInfo, hapModuleInfo, appIndex, specifiedProcessFlag, processName);
TAG_LOGI(AAFwkTag::APPMGR, "%{public}s name:%{public}s-%{public}s processName = %{public}s",
__func__, abilityInfo->bundleName.c_str(), abilityInfo->name.c_str(), processName.c_str());
bool isKia = false;
std::string watermarkBusinessName;
bool isWatermarkEnabled = false;
bool isFileUri = false;
MakeKiaProcess(want, isKia, watermarkBusinessName, isWatermarkEnabled, isFileUri, processName);
std::shared_ptr<AppRunningRecord> appRecord;
bool isProcCache = false;
@@ -545,9 +609,10 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr<AbilityInfo> abilityInfo, s
bundleInfo.name, appInfo->uid, AbilityRuntime::RunningStatus::APP_RUNNING_START);
}
appRecord = CreateAppRunningRecord(loadParam->token, loadParam->preToken, appInfo, abilityInfo,
processName, bundleInfo, hapModuleInfo, want, loadParam->abilityRecordId);
processName, bundleInfo, hapModuleInfo, want, loadParam->abilityRecordId, isKia);
LoadAbilityNoAppRecord(appRecord, loadParam->isShellCall, appInfo, abilityInfo, processName,
specifiedProcessFlag, bundleInfo, hapModuleInfo, want, appExistFlag, false, loadParam->token);
ProcessKia(isKia, appRecord, watermarkBusinessName, isWatermarkEnabled);
} else {
TAG_LOGI(AAFwkTag::APPMGR, "have apprecord");
if (!isProcCache) {
@@ -2155,7 +2220,7 @@ std::shared_ptr<AppRunningRecord> AppMgrServiceInner::GetAppRunningRecordByPid(c
std::shared_ptr<AppRunningRecord> AppMgrServiceInner::CreateAppRunningRecord(sptr<IRemoteObject> token,
sptr<IRemoteObject> preToken, std::shared_ptr<ApplicationInfo> appInfo,
std::shared_ptr<AbilityInfo> abilityInfo, const std::string &processName, const BundleInfo &bundleInfo,
const HapModuleInfo &hapModuleInfo, std::shared_ptr<AAFwk::Want> want, int32_t abilityRecordId)
const HapModuleInfo &hapModuleInfo, std::shared_ptr<AAFwk::Want> want, int32_t abilityRecordId, bool isKia)
{
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
if (want != nullptr && (want->GetBoolParam(DEBUG_APP, false) || want->GetBoolParam(NATIVE_DEBUG, false))) {
@@ -2180,6 +2245,7 @@ std::shared_ptr<AppRunningRecord> AppMgrServiceInner::CreateAppRunningRecord(spt
appRecord->SetTaskHandler(taskHandler_);
appRecord->SetEventHandler(eventHandler_);
appRecord->AddModule(appInfo, abilityInfo, token, hapModuleInfo, want, abilityRecordId);
appRecord->SetIsKia(isKia);
if (want) {
appRecord->SetDebugApp(want->GetBoolParam(DEBUG_APP, false));
appRecord->SetNativeDebug(want->GetBoolParam("nativeDebug", false));
@@ -7842,5 +7908,34 @@ int32_t AppMgrServiceInner::GetSupportedProcessCachePids(const std::string &bund
}
return ERR_OK;
}
int AppMgrServiceInner::RegisterKiaInterceptor(const sptr<IKiaInterceptor> &interceptor)
{
TAG_LOGI(AAFwkTag::APPMGR, "call");
if (IPCSkeleton::GetCallingUid() != FILE_GUARD_UID) {
TAG_LOGE(AAFwkTag::APPMGR, "only open to file guard.");
return ERR_PERMISSION_DENIED;
}
if (interceptor == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "interceptor is nullptr.");
return ERR_INVALID_VALUE;
}
kiaInterceptor_ = interceptor;
return ERR_OK;
}
int32_t AppMgrServiceInner::CheckIsKiaProcess(pid_t pid, bool &isKia)
{
TAG_LOGI(AAFwkTag::APPMGR, "call");
if (IPCSkeleton::GetCallingUid() != FILE_GUARD_UID) {
TAG_LOGE(AAFwkTag::APPMGR, "only open to file guard.");
return ERR_PERMISSION_DENIED;
}
if (!appRunningManager_) {
TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ is nullptr");
return ERR_INVALID_VALUE;
}
return appRunningManager_->CheckIsKiaProcess(pid, isKia);
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -1658,5 +1658,16 @@ void AppRunningManager::SetMultiUserConfigurationMgr(
{
multiUserConfigurationMgr_ = multiUserConfigurationMgr;
}
int32_t AppRunningManager::CheckIsKiaProcess(pid_t pid, bool &isKia)
{
auto appRunningRecord = GetAppRunningRecordByPid(pid);
if (appRunningRecord == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "appRunningRecord is nullptr");
return ERR_INVALID_VALUE;
}
isKia = appRunningRecord->GetIsKia();
return ERR_OK;
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -88,6 +88,8 @@ public:
const sptr<IRemoteObject> &callback));
MOCK_METHOD2(GetSupportedProcessCachePids, int32_t(const std::string &bundleName,
std::vector<int32_t> &pidList));
MOCK_METHOD1(RegisterKiaInterceptor, int32_t(const sptr<IKiaInterceptor> &interceptor));
MOCK_METHOD2(CheckIsKiaProcess, int32_t(pid_t pid, bool &isKia));
void AttachApplication(const sptr<IRemoteObject>& app)
{
@@ -112,6 +112,8 @@ public:
MOCK_METHOD2(GetSupportedProcessCachePids, int32_t(const std::string &bundleName,
std::vector<int32_t> &pidList));
MOCK_METHOD1(RegisterKiaInterceptor, int32_t(const sptr<IKiaInterceptor> &interceptor));
MOCK_METHOD2(CheckIsKiaProcess, int32_t(pid_t pid, bool &isKia));
virtual int StartUserTestProcess(
const AAFwk::Want &want, const sptr<IRemoteObject> &observer, const BundleInfo &bundleInfo, int32_t userId)
{
@@ -257,6 +257,16 @@ class MockAppMgrStub : public AppMgrStub {
{
return true;
}
int32_t RegisterKiaInterceptor(const sptr<IKiaInterceptor> &interceptor) override
{
return 0;
}
int32_t CheckIsKiaProcess(pid_t pid, bool &isKia) override
{
return 0;
}
};
/*