mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 12:43:16 -04:00
+4
@@ -23,6 +23,9 @@
|
||||
#include "ets_agent_extension_stub_impl.h"
|
||||
#include "ets_native_reference.h"
|
||||
|
||||
#include <mutex>
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
@@ -140,6 +143,7 @@ private:
|
||||
std::shared_ptr<AbilityHandler> handler_ = nullptr;
|
||||
sptr<EtsAgentExtensionStubImpl> extensionStub_;
|
||||
std::map<AgentRemoteObjectKey, ani_ref> hostProxyMap_;
|
||||
std::mutex hostProxyMapMutex_;
|
||||
ani_vm *etsVm_ = nullptr;
|
||||
};
|
||||
} // namespace AgentRuntime
|
||||
|
||||
+46
-17
@@ -76,6 +76,15 @@ EtsAgentExtension::~EtsAgentExtension()
|
||||
TAG_LOGE(AAFwkTag::SER_ROUTER, "null env");
|
||||
return;
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(hostProxyMapMutex_);
|
||||
for (auto& item : hostProxyMap_) {
|
||||
if (item.second != nullptr) {
|
||||
env->GlobalReference_Delete(item.second);
|
||||
}
|
||||
}
|
||||
hostProxyMap_.clear();
|
||||
}
|
||||
if (shellContextRef_ && shellContextRef_->aniRef) {
|
||||
env->GlobalReference_Delete(shellContextRef_->aniRef);
|
||||
}
|
||||
@@ -193,9 +202,12 @@ sptr<IRemoteObject> EtsAgentExtension::OnConnect(const AAFwk::Want &want,
|
||||
}
|
||||
|
||||
auto hostProxyKey = BuildAgentRemoteObjectKey(hostProxy);
|
||||
if (hostProxyMap_.find(hostProxyKey) != hostProxyMap_.end()) {
|
||||
TAG_LOGI(AAFwkTag::SER_ROUTER, "hostProxy exist");
|
||||
return stubObject;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(hostProxyMapMutex_);
|
||||
if (hostProxyMap_.find(hostProxyKey) != hostProxyMap_.end()) {
|
||||
TAG_LOGI(AAFwkTag::SER_ROUTER, "hostProxy exist");
|
||||
return stubObject;
|
||||
}
|
||||
}
|
||||
|
||||
// Create ETS connector proxy object using the created proxy class
|
||||
@@ -214,7 +226,10 @@ sptr<IRemoteObject> EtsAgentExtension::OnConnect(const AAFwk::Want &want,
|
||||
TAG_LOGE(AAFwkTag::SER_ROUTER, "GlobalReference_Create failed status: %{public}d", status);
|
||||
return nullptr;
|
||||
}
|
||||
hostProxyMap_[hostProxyKey] = connectorProxyRef;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(hostProxyMapMutex_);
|
||||
hostProxyMap_[hostProxyKey] = connectorProxyRef;
|
||||
}
|
||||
TAG_LOGD(AAFwkTag::SER_ROUTER, "end");
|
||||
return stubObject;
|
||||
}
|
||||
@@ -241,10 +256,14 @@ void EtsAgentExtension::OnDisconnect(const AAFwk::Want &want,
|
||||
return;
|
||||
}
|
||||
ani_ref etsHostProxy = nullptr;
|
||||
auto iter = hostProxyMap_.find(BuildAgentRemoteObjectKey(hostProxy));
|
||||
if (iter != hostProxyMap_.end()) {
|
||||
if (iter->second != nullptr) {
|
||||
etsHostProxy = iter->second;
|
||||
auto hostProxyKey = BuildAgentRemoteObjectKey(hostProxy);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(hostProxyMapMutex_);
|
||||
auto iter = hostProxyMap_.find(hostProxyKey);
|
||||
if (iter != hostProxyMap_.end()) {
|
||||
if (iter->second != nullptr) {
|
||||
etsHostProxy = iter->second;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (etsHostProxy == nullptr) {
|
||||
@@ -252,7 +271,11 @@ void EtsAgentExtension::OnDisconnect(const AAFwk::Want &want,
|
||||
return;
|
||||
}
|
||||
CallObjectMethod("onDisconnect", ON_DISCONNECT_SIGNATURE, aniWant, etsHostProxy);
|
||||
hostProxyMap_.erase(iter);
|
||||
env->GlobalReference_Delete(etsHostProxy);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(hostProxyMapMutex_);
|
||||
hostProxyMap_.erase(hostProxyKey);
|
||||
}
|
||||
TAG_LOGD(AAFwkTag::SER_ROUTER, "end");
|
||||
}
|
||||
|
||||
@@ -285,10 +308,13 @@ void EtsAgentExtension::HandleSendData(sptr<IRemoteObject> hostProxy, const std:
|
||||
return;
|
||||
}
|
||||
ani_ref etsHostProxy = nullptr;
|
||||
auto iter = hostProxyMap_.find(BuildAgentRemoteObjectKey(hostProxy));
|
||||
if (iter != hostProxyMap_.end()) {
|
||||
if (iter->second != nullptr) {
|
||||
etsHostProxy = iter->second;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(hostProxyMapMutex_);
|
||||
auto iter = hostProxyMap_.find(BuildAgentRemoteObjectKey(hostProxy));
|
||||
if (iter != hostProxyMap_.end()) {
|
||||
if (iter->second != nullptr) {
|
||||
etsHostProxy = iter->second;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (etsHostProxy == nullptr) {
|
||||
@@ -324,10 +350,13 @@ void EtsAgentExtension::HandleAuthorize(sptr<IRemoteObject> hostProxy, const std
|
||||
return;
|
||||
}
|
||||
ani_ref etsHostProxy = nullptr;
|
||||
auto iter = hostProxyMap_.find(BuildAgentRemoteObjectKey(hostProxy));
|
||||
if (iter != hostProxyMap_.end()) {
|
||||
if (iter->second != nullptr) {
|
||||
etsHostProxy = iter->second;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(hostProxyMapMutex_);
|
||||
auto iter = hostProxyMap_.find(BuildAgentRemoteObjectKey(hostProxy));
|
||||
if (iter != hostProxyMap_.end()) {
|
||||
if (iter->second != nullptr) {
|
||||
etsHostProxy = iter->second;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (etsHostProxy == nullptr) {
|
||||
|
||||
@@ -160,19 +160,13 @@ void ETSAppForegroundStateObserver::RemoveEtsObserverObject(const ani_object &ob
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "null observer");
|
||||
return;
|
||||
}
|
||||
wptr<ETSAppForegroundStateObserver> weakPtr = this;
|
||||
std::lock_guard<std::mutex> lock(etsObserverObjectSetLock_);
|
||||
auto it = find_if(etsObserverObjects_.begin(),
|
||||
etsObserverObjects_.end(),
|
||||
[weakPtr, &observerObj](ani_ref item) {
|
||||
auto appForegroundStateObserver = weakPtr.promote();
|
||||
if (appForegroundStateObserver == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "null appForegroundStateObserver");
|
||||
return false;
|
||||
}
|
||||
return appForegroundStateObserver->IsStrictEquals(item, observerObj);
|
||||
[this, &observerObj](ani_ref item) {
|
||||
return IsStrictEquals(item, observerObj);
|
||||
});
|
||||
if (it != etsObserverObjects_.end()) {
|
||||
std::lock_guard<std::mutex> lock(etsObserverObjectSetLock_);
|
||||
AppManagerEts::ReleaseObjectReference(etsVm_, *it);
|
||||
etsObserverObjects_.erase(it);
|
||||
}
|
||||
|
||||
@@ -163,6 +163,10 @@ sptr<AppExecFwk::IAppMgr> EtsAppManager::GetAppManagerInstance()
|
||||
{
|
||||
sptr<ISystemAbilityManager> systemAbilityManager =
|
||||
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (systemAbilityManager == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "systemAbilityManager is null");
|
||||
return nullptr;
|
||||
}
|
||||
sptr<IRemoteObject> appObject = systemAbilityManager->GetSystemAbility(APP_MGR_SERVICE_ID);
|
||||
return iface_cast<AppExecFwk::IAppMgr>(appObject);
|
||||
}
|
||||
@@ -171,6 +175,10 @@ sptr<AAFwk::IAbilityManager> EtsAppManager::GetAbilityManagerInstance()
|
||||
{
|
||||
sptr<ISystemAbilityManager> systemAbilityManager =
|
||||
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (systemAbilityManager == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "systemAbilityManager is null");
|
||||
return nullptr;
|
||||
}
|
||||
sptr<IRemoteObject> abilityObject =
|
||||
systemAbilityManager->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
|
||||
return iface_cast<AAFwk::IAbilityManager>(abilityObject);
|
||||
@@ -1039,6 +1047,10 @@ void EtsAppManager::NativeGetSupportedProcessCachePids(ani_env *env, ani_string
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "env null ptr");
|
||||
return;
|
||||
}
|
||||
if (callback == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "callback null ptr");
|
||||
return;
|
||||
}
|
||||
ani_object emptyArray = CreateEmptyAniArray(env);
|
||||
sptr<AppExecFwk::IAppMgr> appMgr = GetAppManagerInstance();
|
||||
if (appMgr == nullptr) {
|
||||
@@ -1351,7 +1363,7 @@ void EtsAppManager::OnOnAppForegroundState(ani_env *env, ani_string type, ani_ob
|
||||
}
|
||||
std::string strType;
|
||||
if (!OHOS::AppExecFwk::GetStdString(env, type, strType)
|
||||
&& strType != ON_OFF_TYPE_APP_FOREGROUND_STATE) {
|
||||
|| strType != ON_OFF_TYPE_APP_FOREGROUND_STATE) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "GetStdString failed");
|
||||
EtsErrorUtil::ThrowInvalidParamError(env,
|
||||
"Parse param observer failed, must be a AppForegroundStateObserver.");
|
||||
@@ -1448,7 +1460,7 @@ void EtsAppManager::OnOffAppForegroundState(ani_env *env, ani_string type, ani_o
|
||||
return;
|
||||
}
|
||||
std::string strType;
|
||||
if (!OHOS::AppExecFwk::GetStdString(env, type, strType) && strType != ON_OFF_TYPE_APP_FOREGROUND_STATE) {
|
||||
if (!OHOS::AppExecFwk::GetStdString(env, type, strType) || strType != ON_OFF_TYPE_APP_FOREGROUND_STATE) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "GetStdString failed");
|
||||
EtsErrorUtil::ThrowInvalidParamError(env,
|
||||
"Parse param observer failed, must be a AppForegroundStateObserver.");
|
||||
|
||||
+3
-3
@@ -37,13 +37,13 @@ public:
|
||||
const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int32_t resultCode) override;
|
||||
void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int32_t resultCode) override;
|
||||
void CallEtsFailed(int32_t errorCode);
|
||||
void SetConnectionId(int32_t id);
|
||||
int32_t GetConnectionId() { return connectionId_; }
|
||||
void SetConnectionId(int64_t id);
|
||||
int64_t GetConnectionId() { return connectionId_; }
|
||||
void SetConnectionRef(ani_object connectOptionsObj);
|
||||
void RemoveConnectionObject();
|
||||
protected:
|
||||
ani_vm *etsVm_ = nullptr;
|
||||
int32_t connectionId_ = -1;
|
||||
int64_t connectionId_ = -1;
|
||||
ani_ref stsConnectionRef_ = nullptr;
|
||||
};
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@ namespace {
|
||||
|
||||
std::recursive_mutex g_connectsLock;
|
||||
int64_t g_serialNumber = 0;
|
||||
static std::mutex g_connectsMutex;
|
||||
static std::map<EtsConnectionKey, sptr<ETSServiceExtensionConnection>, EtsKeyCompare> g_connects;
|
||||
const std::string APP_LINKING_ONLY = "appLinkingOnly";
|
||||
const std::string KEY_REQUEST_ID = "com.ohos.param.requestId";
|
||||
@@ -156,7 +155,7 @@ bool BindNativeMethods(ani_env *env, ani_class &cls)
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t InsertConnection(sptr<ETSServiceExtensionConnection> connection,
|
||||
int64_t InsertConnection(sptr<ETSServiceExtensionConnection> connection,
|
||||
const AAFwk::Want &want, int32_t accountId = -1)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(g_connectsLock);
|
||||
@@ -164,7 +163,7 @@ int32_t InsertConnection(sptr<ETSServiceExtensionConnection> connection,
|
||||
TAG_LOGE(AAFwkTag::SERVICE_EXT, "null connection");
|
||||
return -1;
|
||||
}
|
||||
int32_t connectId = static_cast<int32_t>(g_serialNumber);
|
||||
int64_t connectId = g_serialNumber;
|
||||
EtsConnectionKey key;
|
||||
key.id = g_serialNumber;
|
||||
key.want = want;
|
||||
@@ -175,7 +174,7 @@ int32_t InsertConnection(sptr<ETSServiceExtensionConnection> connection,
|
||||
return connectId;
|
||||
}
|
||||
|
||||
void RemoveConnection(int32_t connectId)
|
||||
void RemoveConnection(int64_t connectId)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(g_connectsLock);
|
||||
auto item = std::find_if(g_connects.begin(), g_connects.end(),
|
||||
@@ -201,6 +200,10 @@ void EtsServiceExtensionContext::Finalizer(ani_env *env, ani_object obj)
|
||||
TAG_LOGE(AAFwkTag::SERVICE_EXT, "null env");
|
||||
return;
|
||||
}
|
||||
if (obj == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::SERVICE_EXT, "null obj");
|
||||
return;
|
||||
}
|
||||
ani_long nativeEtsContextPtr;
|
||||
if (env->Object_GetFieldByName_Long(obj, "nativeEtsContext", &nativeEtsContextPtr) != ANI_OK) {
|
||||
TAG_LOGE(AAFwkTag::SERVICE_EXT, "Failed to get nativeEtsContext");
|
||||
@@ -218,6 +221,10 @@ void EtsServiceExtensionContext::TerminateSelf(ani_env *env, ani_object aniObj,
|
||||
TAG_LOGE(AAFwkTag::SERVICE_EXT, "null env");
|
||||
return;
|
||||
}
|
||||
if (aniObj == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::SERVICE_EXT, "null aniObj");
|
||||
return;
|
||||
}
|
||||
auto etsServiceExtensionContext = EtsServiceExtensionContext::GetEtsAbilityContext(env, aniObj);
|
||||
if (etsServiceExtensionContext == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::SERVICE_EXT, "null etsServiceExtensionContext");
|
||||
@@ -234,6 +241,14 @@ void EtsServiceExtensionContext::StartServiceExtensionAbility(
|
||||
TAG_LOGE(AAFwkTag::SERVICE_EXT, "null env");
|
||||
return;
|
||||
}
|
||||
if (wantObj == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::SERVICE_EXT, "null wantObj");
|
||||
return;
|
||||
}
|
||||
if (callbackobj == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::SERVICE_EXT, "null callbackobj");
|
||||
return;
|
||||
}
|
||||
auto etsServiceExtensionContext = EtsServiceExtensionContext::GetEtsAbilityContext(env, aniObj);
|
||||
if (etsServiceExtensionContext == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::SERVICE_EXT, "null etsServiceExtensionContext");
|
||||
@@ -925,12 +940,13 @@ ani_long EtsServiceExtensionContext::OnConnectServiceExtensionAbility(ani_env *e
|
||||
}
|
||||
sptr<ETSServiceExtensionConnection> connection = sptr<ETSServiceExtensionConnection>::MakeSptr(etsVm);
|
||||
connection->SetConnectionRef(connectOptionsObj);
|
||||
int32_t connectId = InsertConnection(connection, want);
|
||||
int64_t connectId = InsertConnection(connection, want);
|
||||
auto context = context_.lock();
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::SERVICE_EXT, "null context");
|
||||
RemoveConnection(connectId);
|
||||
EtsErrorUtil::ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT);
|
||||
return FAILED_CODE;
|
||||
}
|
||||
auto innerErrCode = context->ConnectAbility(want, connection);
|
||||
int32_t errcode = static_cast<int32_t>(GetJsErrorCodeByNativeError(innerErrCode));
|
||||
@@ -964,12 +980,13 @@ ani_long EtsServiceExtensionContext::OnConnectServiceExtensionAbilityWithAccount
|
||||
}
|
||||
sptr<ETSServiceExtensionConnection> connection = sptr<ETSServiceExtensionConnection>::MakeSptr(etsVm);
|
||||
connection->SetConnectionRef(connectOptionsObj);
|
||||
int32_t connectId = InsertConnection(connection, want, accountId);
|
||||
int64_t connectId = InsertConnection(connection, want, accountId);
|
||||
auto context = context_.lock();
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::SERVICE_EXT, "null context");
|
||||
RemoveConnection(connectId);
|
||||
EtsErrorUtil::ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT);
|
||||
return FAILED_CODE;
|
||||
}
|
||||
auto innerErrCode = context->ConnectAbilityWithAccount(want, accountId, connection);
|
||||
int32_t errcode = static_cast<int32_t>(GetJsErrorCodeByNativeError(innerErrCode));
|
||||
@@ -977,7 +994,7 @@ ani_long EtsServiceExtensionContext::OnConnectServiceExtensionAbilityWithAccount
|
||||
connection->CallEtsFailed(errcode);
|
||||
RemoveConnection(connectId);
|
||||
}
|
||||
return static_cast<ani_long>(connectId);
|
||||
return connectId;
|
||||
}
|
||||
|
||||
void EtsServiceExtensionContext::OnDisconnectServiceExtensionAbility(ani_env *env, ani_object aniObj,
|
||||
@@ -1001,7 +1018,7 @@ void EtsServiceExtensionContext::OnDisconnectServiceExtensionAbility(ani_env *en
|
||||
AAFwk::Want want;
|
||||
int32_t accountId = -1;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_connectsMutex);
|
||||
std::lock_guard<std::recursive_mutex> lock(g_connectsLock);
|
||||
auto iter = std::find_if(
|
||||
g_connects.begin(), g_connects.end(), [&connectId](const auto &obj) { return connectId == obj.first.id; });
|
||||
if (iter != g_connects.end()) {
|
||||
@@ -1217,7 +1234,7 @@ ETSServiceExtensionConnection::~ETSServiceExtensionConnection()
|
||||
RemoveConnectionObject();
|
||||
}
|
||||
|
||||
void ETSServiceExtensionConnection::SetConnectionId(int32_t id)
|
||||
void ETSServiceExtensionConnection::SetConnectionId(int64_t id)
|
||||
{
|
||||
connectionId_ = id;
|
||||
}
|
||||
|
||||
@@ -2722,6 +2722,10 @@ bool AppMgrServiceInner::GetBundleAndHapInfo(const AbilityInfo &abilityInfo,
|
||||
int32_t appIndex) const
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
if (appInfo == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "appInfo null");
|
||||
return false;
|
||||
}
|
||||
auto bundleMgrHelper = remoteClientManager_->GetBundleManagerHelper();
|
||||
if (bundleMgrHelper == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "bundleMgrHelper null");
|
||||
|
||||
+20
@@ -149,6 +149,26 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetBundleAndHapInfo_002, TestSize.Level1
|
||||
TAG_LOGI(AAFwkTag::TEST, "GetBundleAndHapInfo_002 end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetBundleAndHapInfo_003
|
||||
* @tc.desc: test GetBundleAndHapInfo when appInfo is nullptr
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppMgrServiceInnerSeventhTest, GetBundleAndHapInfo_003, TestSize.Level1)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::TEST, "GetBundleAndHapInfo_003 start");
|
||||
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
|
||||
AAFwk::MyStatus::GetInstance().getBundleManagerHelper_ = std::make_shared<BundleMgrHelper>();
|
||||
AbilityInfo abilityInfo;
|
||||
std::shared_ptr<ApplicationInfo> appInfo = nullptr;
|
||||
BundleInfo bundleInfo;
|
||||
HapModuleInfo hapModuleInfo;
|
||||
int32_t appIndex = 0;
|
||||
bool ret = appMgrServiceInner->GetBundleAndHapInfo(abilityInfo, appInfo, bundleInfo, hapModuleInfo, appIndex);
|
||||
EXPECT_EQ(ret, false);
|
||||
TAG_LOGI(AAFwkTag::TEST, "GetBundleAndHapInfo_003 end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UpdateApplicationInfoInstalled_001
|
||||
* @tc.desc: test UpdateApplicationInfoInstalled_001
|
||||
|
||||
Reference in New Issue
Block a user