mirror of
https://github.com/openharmony/aafwk_standard.git
synced 2026-07-01 20:04:39 -04:00
@@ -128,6 +128,8 @@ ohos_shared_library("abilitykit_native") {
|
||||
# "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.cpp",
|
||||
# "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_util.cpp",
|
||||
# "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_want.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/continuation/distributed/ability_distributed_connect_callback_stub.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/continuation/distributed/ability_distributed_connection.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/continuation/distributed/continuation_handler.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/continuation/distributed/continuation_manager.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/continuation/distributed/continuation_scheduler.cpp",
|
||||
|
||||
@@ -696,16 +696,6 @@ public:
|
||||
*/
|
||||
virtual void SetMainRoute(const std::string &entry) final;
|
||||
|
||||
/**
|
||||
* @brief Migrates this ability to another device on the same distributed network in a reversible way that allows
|
||||
* this ability to be migrated back to the local device through reverseContinueAbility(). If there are multiple
|
||||
* candidate devices, a pop-up will be displayed for users to choose the desired one. The ability to migrate and its
|
||||
* ability slices must implement the IAbilityContinuation interface. Otherwise, an exception is thrown, indicating
|
||||
* that the ability does not support migration.
|
||||
*
|
||||
*/
|
||||
virtual void ContinueAbilityReversibly() final;
|
||||
|
||||
/**
|
||||
* @brief Migrates this ability to the given device on the same distributed network in a reversible way that allows
|
||||
* this ability to be migrated back to the local device through reverseContinueAbility(). The ability to migrate and
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
#ifndef FOUNDATION_APPEXECFWK_OHOS_ABILITY_CONTEXT_H
|
||||
#define FOUNDATION_APPEXECFWK_OHOS_ABILITY_CONTEXT_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "context_container.h"
|
||||
#include "data_ability_helper.h"
|
||||
#include "distributed_sched_interface.h"
|
||||
@@ -722,6 +724,7 @@ protected:
|
||||
std::string callingDeviceId_;
|
||||
std::string callingBundleName_;
|
||||
std::string callingAbilityName_;
|
||||
std::map<sptr<AAFwk::IAbilityConnection>, sptr<IRemoteObject>> abilityConnectionMap_;
|
||||
};
|
||||
|
||||
} // namespace AppExecFwk
|
||||
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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_AAFWK_ABILITY_DISTRIBUTE_CONNECT_CALLBACK_STUB_H
|
||||
#define OHOS_AAFWK_ABILITY_DISTRIBUTE_CONNECT_CALLBACK_STUB_H
|
||||
|
||||
#include <iremote_object.h>
|
||||
#include <iremote_stub.h>
|
||||
|
||||
#include "ability_distributed_connection_interface.h"
|
||||
#include "nocopyable.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
/**
|
||||
* @class AbilityDistributedConnectionStub
|
||||
* AbilityDistributeConnect Stub.
|
||||
*/
|
||||
class AbilityDistributedConnectionStub : public IRemoteStub<IAbilityDistributedConnection> {
|
||||
public:
|
||||
AbilityDistributedConnectionStub();
|
||||
virtual ~AbilityDistributedConnectionStub();
|
||||
|
||||
virtual int OnRemoteRequest(
|
||||
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_MOVE(AbilityDistributedConnectionStub);
|
||||
};
|
||||
|
||||
/**
|
||||
* @class AbilityDistriubuteConnectCallbackRecipient
|
||||
* AbilityDistriubuteConnectCallbackRecipient notices IRemoteBroker died.
|
||||
*/
|
||||
class AbilityDistriubuteConnectCallbackRecipient : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
using RemoteDiedHandler = std::function<void(const wptr<IRemoteObject> &)>;
|
||||
AbilityDistriubuteConnectCallbackRecipient(RemoteDiedHandler handler);
|
||||
virtual ~AbilityDistriubuteConnectCallbackRecipient();
|
||||
virtual void OnRemoteDied(const wptr<IRemoteObject> &remote);
|
||||
|
||||
private:
|
||||
RemoteDiedHandler handler_;
|
||||
};
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_AAFWK_ABILITY_DISTRIBUTE_CONNECT_CALLBACK_STUB_H
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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_AAFWK_ABILITY_DISTRIBUTE_CONNECT_CALLBACK_H
|
||||
#define OHOS_AAFWK_ABILITY_DISTRIBUTE_CONNECT_CALLBACK_H
|
||||
|
||||
#include "ability_connect_callback_interface.h"
|
||||
#include "ability_distributed_connect_callback_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
/**
|
||||
* @class AbilityDistributedConnection
|
||||
* AbilityDistributeConnect.
|
||||
*/
|
||||
class AbilityDistributedConnection : public AbilityDistributedConnectionStub {
|
||||
public:
|
||||
AbilityDistributedConnection(const sptr<AAFwk::IAbilityConnection> &conn);
|
||||
~AbilityDistributedConnection() = default;
|
||||
|
||||
/**
|
||||
* OnAbilityDistributeConnectDone, AbilityMs notify caller ability the result of connect.
|
||||
*
|
||||
* @param element, service ability's ElementName.
|
||||
* @param remoteObject,.the session proxy of service ability.
|
||||
* @param resultCode, ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual void OnAbilityConnectDone(
|
||||
const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode) override;
|
||||
|
||||
/**
|
||||
* OnAbilityDistributeDisconnectDone, AbilityMs notify caller ability the result of disconnect.
|
||||
*
|
||||
* @param element, service ability's ElementName.
|
||||
* @param resultCode, ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override;
|
||||
|
||||
private:
|
||||
sptr<AAFwk::IAbilityConnection> conn_;
|
||||
};
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_AAFWK_ABILITY_DISTRIBUTE_CONNECT_CALLBACK_H
|
||||
@@ -42,6 +42,9 @@ public:
|
||||
ErrCode StartRemoteAbility(const Want &want, const AppExecFwk::AbilityInfo &abilityInfo, int32_t requestCode);
|
||||
ErrCode StartContinuation(
|
||||
const Want &want, const AppExecFwk::AbilityInfo &abilityInfo, const sptr<IRemoteObject> &abilityToken);
|
||||
ErrCode ConnectRemoteAbility(
|
||||
const Want &want, const AppExecFwk::AbilityInfo &abilityInfo, const sptr<IRemoteObject> &connect);
|
||||
ErrCode DisconnectRemoteAbility(const sptr<IRemoteObject> &connect);
|
||||
ErrCode NotifyCompleteContinuation(
|
||||
const std::u16string &devId, int32_t sessionId, bool isSuccess, const sptr<IRemoteObject> &reverseScheduler);
|
||||
ErrCode RegisterAbilityToken(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &appThread);
|
||||
|
||||
@@ -171,19 +171,6 @@ void Ability::OnStart(const Want &want)
|
||||
abilityInfo_->bundleName.c_str(),
|
||||
abilityInfo_->name.c_str(),
|
||||
winType);
|
||||
|
||||
if (setting_ != nullptr) {
|
||||
auto windowMode = static_cast<AbilityWindowConfiguration>(
|
||||
std::atoi(setting_->GetProperty(AbilityStartSetting::WINDOW_MODE_KEY).c_str()));
|
||||
APP_LOGI("%{public}s windowMode : %{public}d", __func__, windowMode);
|
||||
if (windowMode == AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_FLOATING) {
|
||||
APP_LOGI("%{public}s begin SetWindowMode : WINDOW_MODE_FREE.", __func__);
|
||||
config->SetWindowType(WINDOW_TYPE_FLOAT);
|
||||
APP_LOGI("%{public}s end SetWindowMode : WINDOW_MODE_FREE.", __func__);
|
||||
}
|
||||
} else {
|
||||
APP_LOGI("Ability::OnStart setting_ == nullptr.");
|
||||
}
|
||||
SetUIContent(config);
|
||||
|
||||
if (abilityWindow_ != nullptr) {
|
||||
@@ -1169,23 +1156,6 @@ void Ability::ContinueAbilityReversibly(const std::string &deviceId)
|
||||
continuationManager_->ContinueAbility(true, deviceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Migrates this ability to another device on the same distributed network in a reversible way that allows this
|
||||
* ability to be migrated back to the local device through reverseContinueAbility(). If there are multiple candidate
|
||||
* devices, a pop-up will be displayed for users to choose the desired one. The ability to migrate and its ability
|
||||
* slices must implement the IAbilityContinuation interface. Otherwise, an exception is thrown, indicating that the
|
||||
* ability does not support migration.
|
||||
*
|
||||
*/
|
||||
void Ability::ContinueAbilityReversibly()
|
||||
{
|
||||
if (!VerifySupportForContinuation()) {
|
||||
APP_LOGE("Ability::ContinueAbilityReversibly failed. VerifySupportForContinuation faled");
|
||||
return;
|
||||
}
|
||||
continuationManager_->ContinueAbility(true, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief public final String getOriginalDeviceId() throws UnsupportedOperationException
|
||||
* Obtains the ID of the source device from which this ability is migrated.
|
||||
@@ -2097,7 +2067,7 @@ void Ability::CleanFormResource(const int64_t formId)
|
||||
{
|
||||
APP_LOGI("%{public}s called.", __func__);
|
||||
// compatible with int form id
|
||||
int64_t cleanId {-1L};
|
||||
int64_t cleanId{-1L};
|
||||
for (auto param : userReqParams_) {
|
||||
uint64_t unsignedFormId = static_cast<uint64_t>(formId);
|
||||
uint64_t unsignedParamFirst = static_cast<uint64_t>(param.first);
|
||||
@@ -2382,9 +2352,8 @@ void Ability::OnDeathReceived()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(formLock);
|
||||
want = userReqRaram.second;
|
||||
if (want.GetBoolParam(Constants::PARAM_FORM_TEMPORARY_KEY, false)
|
||||
&& std::find(lostedTempForms.begin(), lostedTempForms.end(),
|
||||
formId) == lostedTempForms.end()) {
|
||||
if (want.GetBoolParam(Constants::PARAM_FORM_TEMPORARY_KEY, false) &&
|
||||
std::find(lostedTempForms.begin(), lostedTempForms.end(), formId) == lostedTempForms.end()) {
|
||||
lostedTempForms.emplace_back(formId);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
*/
|
||||
|
||||
#include "ability_context.h"
|
||||
#include "ability_distributed_connection.h"
|
||||
#include "ability_manager_client.h"
|
||||
#include "distributed_client.h"
|
||||
#include "app_log_wrapper.h"
|
||||
#include "resource_manager.h"
|
||||
#include "bundle_constants.h"
|
||||
@@ -236,14 +238,37 @@ bool AbilityContext::ConnectAbility(const Want &want, const sptr<AAFwk::IAbility
|
||||
APP_LOGI("%{public}s begin.", __func__);
|
||||
|
||||
AppExecFwk::AbilityType type = GetAbilityInfoType();
|
||||
|
||||
std::shared_ptr<AbilityInfo> abilityInfo = GetAbilityInfo();
|
||||
if (abilityInfo == nullptr) {
|
||||
APP_LOGE("AbilityContext::ConnectAbility info == nullptr");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (AppExecFwk::AbilityType::PAGE != type && AppExecFwk::AbilityType::SERVICE != type) {
|
||||
APP_LOGE("AbilityContext::ConnectAbility AbilityType = %{public}d", type);
|
||||
return false;
|
||||
}
|
||||
|
||||
APP_LOGI("%{public}s begin ams->ConnectAbility", __func__);
|
||||
ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want, conn, token_);
|
||||
APP_LOGI("%{public}s end ams->ConnectAbility, ret=%{public}d", __func__, ret);
|
||||
ErrCode ret = ERR_OK;
|
||||
if (want.GetOperation().GetDeviceId() == "") {
|
||||
APP_LOGI("%{public}s begin ams->ConnectAbilityLocal", __func__);
|
||||
ret = AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want, conn, token_);
|
||||
} else {
|
||||
APP_LOGI("%{public}s begin ams->ConnectAbilityRemote", __func__);
|
||||
auto pos = abilityConnectionMap_.find(conn);
|
||||
if (pos != abilityConnectionMap_.end()) {
|
||||
APP_LOGI("%{public}s begin ams->ConnectAbilityHasDistributedConnection", __func__);
|
||||
return false;
|
||||
} else {
|
||||
APP_LOGI("%{public}s begin ams->ConnectAbilitySetDistributedConnection", __func__);
|
||||
sptr<AbilityDistributedConnection> distributedConnection = new AbilityDistributedConnection(conn);
|
||||
abilityConnectionMap_.emplace(conn, distributedConnection);
|
||||
ret = DistributedClient::GetInstance()->ConnectRemoteAbility(want, *abilityInfo, distributedConnection);
|
||||
}
|
||||
}
|
||||
|
||||
APP_LOGI("%{public}s end ConnectAbility, ret=%{public}d", __func__, ret);
|
||||
bool value = ((ret == ERR_OK) ? true : false);
|
||||
if (!value) {
|
||||
APP_LOGE("AbilityContext::ConnectAbility ErrorCode = %{public}d", ret);
|
||||
@@ -254,12 +279,12 @@ bool AbilityContext::ConnectAbility(const Want &want, const sptr<AAFwk::IAbility
|
||||
|
||||
/**
|
||||
*
|
||||
* @param conn Indicates the IAbilityConnection callback object passed by connectAbility after the connection
|
||||
* is set up. The IAbilityConnection object uniquely identifies a connection between two abilities.
|
||||
* @param conn Indicates the IAbilityDisConnection callback object passed by disconnectAbility after the disconnection
|
||||
* is set up. The IAbilityDisConnection object uniquely identifies a disconnection between two abilities.
|
||||
*/
|
||||
void AbilityContext::DisconnectAbility(const sptr<AAFwk::IAbilityConnection> &conn)
|
||||
{
|
||||
APP_LOGD("AbilityContext::DisconnectAbility begin");
|
||||
APP_LOGI("%{public}s begin.", __func__);
|
||||
|
||||
AppExecFwk::AbilityType type = GetAbilityInfoType();
|
||||
if (AppExecFwk::AbilityType::PAGE != type && AppExecFwk::AbilityType::SERVICE != type) {
|
||||
@@ -267,9 +292,18 @@ void AbilityContext::DisconnectAbility(const sptr<AAFwk::IAbilityConnection> &co
|
||||
return;
|
||||
}
|
||||
|
||||
APP_LOGI("%{public}s begin ams->DisconnectAbility", __func__);
|
||||
ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(conn);
|
||||
APP_LOGI("%{public}s end ams->ConnectAbility, ret=%{public}d", __func__, ret);
|
||||
ErrCode ret = ERR_OK;
|
||||
auto pos = abilityConnectionMap_.find(conn);
|
||||
if (pos != abilityConnectionMap_.end()) {
|
||||
APP_LOGI("%{public}s begin ams->DisconnectAbilityRemote", __func__);
|
||||
ret = DistributedClient::GetInstance()->DisconnectRemoteAbility(pos->second);
|
||||
abilityConnectionMap_.erase(conn);
|
||||
} else {
|
||||
APP_LOGI("%{public}s begin ams->DisconnectAbilityLocal", __func__);
|
||||
ret = AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(conn);
|
||||
}
|
||||
|
||||
APP_LOGI("%{public}s end ams->DisconnectAbility, ret=%{public}d", __func__, ret);
|
||||
if (ret != ERR_OK) {
|
||||
APP_LOGE("AbilityContext::DisconnectAbility error");
|
||||
}
|
||||
@@ -833,7 +867,7 @@ void AbilityContext::AttachBaseContext(const std::shared_ptr<Context> &base)
|
||||
ContextContainer::AttachBaseContext(base);
|
||||
APP_LOGI("AbilityContext::AttachBaseContext. End.");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Obtains the absolute path to the application-specific cache directory
|
||||
* on the primary external or shared storage device.
|
||||
|
||||
@@ -869,22 +869,6 @@ void AbilityThread::NotifyMultiWinModeChanged(int32_t winModeKey, bool flag)
|
||||
return;
|
||||
}
|
||||
|
||||
if (flag) {
|
||||
// true: normal windowMode -> free windowMode
|
||||
if (winModeKey == MULTI_WINDOW_DISPLAY_FLOATING) {
|
||||
APP_LOGI("NotifyMultiWinModeChanged.SetWindowMode:WINDOW_MODE_FREE begin.");
|
||||
window->SetWindowType(WINDOW_TYPE_FLOAT);
|
||||
APP_LOGI("NotifyMultiWinModeChanged.SetWindowMode:WINDOW_MODE_FREE end.");
|
||||
} else {
|
||||
APP_LOGI("NotifyMultiWinModeChanged.key:%{public}d", winModeKey);
|
||||
}
|
||||
} else {
|
||||
// false: free windowMode -> normal windowMode
|
||||
APP_LOGI("NotifyMultiWinModeChanged.SetWindowMode:WINDOW_MODE_TOP begin.");
|
||||
window->SetWindowType(WINDOW_TYPE_NORMAL);
|
||||
APP_LOGI("NotifyMultiWinModeChanged.SetWindowMode:WINDOW_MODE_TOP end.");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "ability_distributed_connect_callback_stub.h"
|
||||
|
||||
#include "hilog_wrapper.h"
|
||||
#include "ipc_types.h"
|
||||
#include "message_parcel.h"
|
||||
#include "want.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
AbilityDistributedConnectionStub::AbilityDistributedConnectionStub()
|
||||
{}
|
||||
|
||||
AbilityDistributedConnectionStub::~AbilityDistributedConnectionStub()
|
||||
{}
|
||||
|
||||
int AbilityDistributedConnectionStub::OnRemoteRequest(
|
||||
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
std::u16string descriptor = AbilityDistributedConnectionStub::GetDescriptor();
|
||||
std::u16string remoteDescriptor = data.ReadInterfaceToken();
|
||||
if (descriptor != remoteDescriptor) {
|
||||
HILOG_INFO("Local descriptor is not equal to remote");
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
auto element = data.ReadParcelable<AppExecFwk::ElementName>();
|
||||
switch (code) {
|
||||
case IAbilityDistributedConnection::ON_ABILITY_DISTRIBUTE_CONNECT_DONE: {
|
||||
if (element == nullptr) {
|
||||
HILOG_ERROR("callback stub receive element is nullptr");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
auto remoteObject = data.ReadRemoteObject();
|
||||
auto resultCode = data.ReadInt32();
|
||||
OnAbilityConnectDone(*element, remoteObject, resultCode);
|
||||
delete element;
|
||||
return NO_ERROR;
|
||||
}
|
||||
case IAbilityDistributedConnection::ON_ABILITY_DISTRIBUTE_DISCONNECT_DONE: {
|
||||
if (element == nullptr) {
|
||||
HILOG_ERROR("callback stub receive element is nullptr");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
auto resultCode = data.ReadInt32();
|
||||
OnAbilityDisconnectDone(*element, resultCode);
|
||||
delete element;
|
||||
return NO_ERROR;
|
||||
}
|
||||
default: {
|
||||
if (element != nullptr) {
|
||||
delete element;
|
||||
}
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AbilityDistriubuteConnectCallbackRecipient::OnRemoteDied(const wptr<IRemoteObject> &__attribute__((unused)) remote)
|
||||
{
|
||||
HILOG_ERROR("On remote died.");
|
||||
if (handler_) {
|
||||
handler_(remote);
|
||||
}
|
||||
}
|
||||
|
||||
AbilityDistriubuteConnectCallbackRecipient::AbilityDistriubuteConnectCallbackRecipient(RemoteDiedHandler handler)
|
||||
: handler_(handler)
|
||||
{}
|
||||
|
||||
AbilityDistriubuteConnectCallbackRecipient::~AbilityDistriubuteConnectCallbackRecipient()
|
||||
{}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "ability_distributed_connection.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
AbilityDistributedConnection::AbilityDistributedConnection(const sptr<AAFwk::IAbilityConnection> &conn)
|
||||
{
|
||||
HILOG_INFO("%{public}s called.", __func__);
|
||||
conn_ = conn;
|
||||
}
|
||||
|
||||
void AbilityDistributedConnection::OnAbilityConnectDone(
|
||||
const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode)
|
||||
{
|
||||
HILOG_INFO("%{public}s called.", __func__);
|
||||
if (conn_ == nullptr) {
|
||||
HILOG_INFO("%{public}s conn_ == nullptr.", __func__);
|
||||
return;
|
||||
}
|
||||
conn_->OnAbilityConnectDone(element, remoteObject, resultCode);
|
||||
}
|
||||
|
||||
void AbilityDistributedConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode)
|
||||
{
|
||||
HILOG_INFO("%{public}s called.", __func__);
|
||||
if (conn_ == nullptr) {
|
||||
HILOG_INFO("%{public}s conn_ == nullptr.", __func__);
|
||||
return;
|
||||
}
|
||||
conn_->OnAbilityDisconnectDone(element, resultCode);
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
@@ -99,6 +99,39 @@ ErrCode DistributedClient::StartContinuation(
|
||||
return dmsProxy_->StartContinuation(want, abilityInfo, abilityToken);
|
||||
}
|
||||
|
||||
ErrCode DistributedClient::ConnectRemoteAbility(
|
||||
const Want &want, const AppExecFwk::AbilityInfo &abilityInfo, const sptr<IRemoteObject> &connect)
|
||||
{
|
||||
APP_LOGI("%{public}s called", __func__);
|
||||
if (remoteObject_ == nullptr) {
|
||||
ErrCode err = Connect();
|
||||
if (err != ERR_OK) {
|
||||
return DISTRIBUTED_ABILITY_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
}
|
||||
if (connect == nullptr) {
|
||||
return INCOMING_PARAMETER_POINTER_IS_NULL;
|
||||
}
|
||||
|
||||
return dmsProxy_->ConnectRemoteAbility(want, abilityInfo, connect);
|
||||
}
|
||||
|
||||
ErrCode DistributedClient::DisconnectRemoteAbility(const sptr<IRemoteObject> &connect)
|
||||
{
|
||||
APP_LOGI("%{public}s called", __func__);
|
||||
if (remoteObject_ == nullptr) {
|
||||
ErrCode err = Connect();
|
||||
if (err != ERR_OK) {
|
||||
return DISTRIBUTED_ABILITY_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
}
|
||||
if (connect == nullptr) {
|
||||
return INCOMING_PARAMETER_POINTER_IS_NULL;
|
||||
}
|
||||
|
||||
return dmsProxy_->DisconnectRemoteAbility(connect);
|
||||
}
|
||||
|
||||
ErrCode DistributedClient::NotifyCompleteContinuation(
|
||||
const std::u16string &devId, int32_t sessionId, bool isSuccess, const sptr<IRemoteObject> &reverseScheduler)
|
||||
{
|
||||
|
||||
+32
-28
@@ -240,23 +240,25 @@ HWTEST_F(DataAbilityHelperTest, AaFwk_DataAbilityHelper_OpenFile_Test_0100, Func
|
||||
int fd = dataAbilityHelper->OpenFile(urivalue, mode);
|
||||
EXPECT_NE(fd, -1);
|
||||
|
||||
std::string result = "123456";
|
||||
FILE *file = nullptr;
|
||||
file = fdopen(fd, "r");
|
||||
EXPECT_NE(file, nullptr);
|
||||
if (fd > 0) {
|
||||
std::string result = "123456";
|
||||
FILE *file = nullptr;
|
||||
file = fdopen(fd, "r");
|
||||
EXPECT_NE(file, nullptr);
|
||||
|
||||
if (file != nullptr) {
|
||||
int strSize = 7;
|
||||
std::string str("");
|
||||
str.resize(strSize);
|
||||
if (!feof(file)) {
|
||||
fgets(&str[0], strSize, file);
|
||||
if (file != nullptr) {
|
||||
int strSize = 7;
|
||||
std::string str("");
|
||||
str.resize(strSize);
|
||||
if (!feof(file)) {
|
||||
fgets(&str[0], strSize, file);
|
||||
}
|
||||
string stringstr(str);
|
||||
EXPECT_STREQ(stringstr.c_str(), result.c_str());
|
||||
fclose(file);
|
||||
system("rm /dataability_openfile_test.txt");
|
||||
}
|
||||
string stringstr(str);
|
||||
EXPECT_STREQ(stringstr.c_str(), result.c_str());
|
||||
}
|
||||
fclose(file);
|
||||
system("rm /dataability_openfile_test.txt");
|
||||
|
||||
GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_OpenFile_Test_0100 end";
|
||||
}
|
||||
@@ -280,23 +282,25 @@ HWTEST_F(DataAbilityHelperTest, AaFwk_DataAbilityHelper_OpenFile_Test_0200, Func
|
||||
int fd = dataAbilityHelper->OpenFile(urivalue, mode);
|
||||
EXPECT_NE(fd, -1);
|
||||
|
||||
std::string result = "123456";
|
||||
FILE *file = nullptr;
|
||||
file = fdopen(fd, "r");
|
||||
EXPECT_NE(file, nullptr);
|
||||
if (fd > 0) {
|
||||
std::string result = "123456";
|
||||
FILE *file = nullptr;
|
||||
file = fdopen(fd, "r");
|
||||
EXPECT_NE(file, nullptr);
|
||||
|
||||
if (file != nullptr) {
|
||||
int strSize = 7;
|
||||
std::string str("");
|
||||
str.resize(strSize);
|
||||
if (!feof(file)) {
|
||||
fgets(&str[0], strSize, file);
|
||||
if (file != nullptr) {
|
||||
int strSize = 7;
|
||||
std::string str("");
|
||||
str.resize(strSize);
|
||||
if (!feof(file)) {
|
||||
fgets(&str[0], strSize, file);
|
||||
}
|
||||
string stringstr(str);
|
||||
EXPECT_STREQ(stringstr.c_str(), result.c_str());
|
||||
fclose(file);
|
||||
system("rm /dataability_openfile_test.txt");
|
||||
}
|
||||
string stringstr(str);
|
||||
EXPECT_STREQ(stringstr.c_str(), result.c_str());
|
||||
}
|
||||
fclose(file);
|
||||
system("rm /dataability_openfile_test.txt");
|
||||
|
||||
GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_OpenFile_Test_0200 end";
|
||||
}
|
||||
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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_AAFWK_ABILITY_DISTRIBUTE_CONNECT_CALLBACK_INTERFACE_H
|
||||
#define OHOS_AAFWK_ABILITY_DISTRIBUTE_CONNECT_CALLBACK_INTERFACE_H
|
||||
|
||||
#include "want.h"
|
||||
#include "element_name.h"
|
||||
|
||||
#include "iremote_broker.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
/**
|
||||
* @class IAbilityDistributedConnection
|
||||
* IAbilityDistributedConnection is used to notify caller ability that connect or disconnect is complete.
|
||||
*/
|
||||
class IAbilityDistributedConnection : public OHOS::IRemoteBroker {
|
||||
public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.abilityshell.DistributedConnection");
|
||||
|
||||
/**
|
||||
* OnAbilityDistributeConnectDone, AbilityMs notify caller ability the result of connect.
|
||||
*
|
||||
* @param element, service ability's ElementName.
|
||||
* @param remoteObject,.the session proxy of service ability.
|
||||
* @param resultCode, ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual void OnAbilityConnectDone(
|
||||
const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode) = 0;
|
||||
|
||||
/**
|
||||
* OnAbilityDistributeDisconnectDone, AbilityMs notify caller ability the result of disconnect.
|
||||
*
|
||||
* @param element, service ability's ElementName.
|
||||
* @param resultCode, ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) = 0;
|
||||
|
||||
enum {
|
||||
// ipc id for OnAbilityDistributeConnectDone
|
||||
ON_ABILITY_DISTRIBUTE_CONNECT_DONE = 0,
|
||||
|
||||
// ipc id for OnAbilityDistributeDisConnectDone
|
||||
ON_ABILITY_DISTRIBUTE_DISCONNECT_DONE
|
||||
};
|
||||
};
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_AAFWK_ABILITY_CONNECT_CALLBACK_INTERFACE_H
|
||||
@@ -450,6 +450,7 @@ napi_value NAPI_NotifyChange(napi_env env, napi_callback_info info)
|
||||
}
|
||||
ret = WrapVoidToJS(env);
|
||||
}
|
||||
HILOG_INFO("%{public}s,end", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -722,6 +723,11 @@ napi_value RegisterAsync(
|
||||
RegisterExecuteCB,
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
HILOG_INFO("NAPI_Register, main event thread complete.");
|
||||
DAHelperOnOffCB *onCB = static_cast<DAHelperOnOffCB *>(data);
|
||||
if (onCB != nullptr) {
|
||||
delete onCB;
|
||||
onCB = nullptr;
|
||||
}
|
||||
},
|
||||
(void *)onCB,
|
||||
&onCB->cbBase.asyncWork));
|
||||
@@ -886,6 +892,10 @@ void UnRegisterCompleteCB(napi_env env, napi_status status, void *data)
|
||||
DAHelperOnOffCB *offCB = static_cast<DAHelperOnOffCB *>(data);
|
||||
if (offCB == nullptr || offCB->dataAbilityHelper == nullptr) {
|
||||
HILOG_ERROR("NAPI_UnRegister, param is null.");
|
||||
if (offCB != nullptr) {
|
||||
delete offCB;
|
||||
offCB = nullptr;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (offCB->cbBase.cbInfo.callback != nullptr) {
|
||||
@@ -950,6 +960,10 @@ void UnRegisterCompleteCB(napi_env env, napi_status status, void *data)
|
||||
HILOG_ERROR("NAPI_UnRegister, error: uri is null.");
|
||||
}
|
||||
}
|
||||
if (offCB != nullptr) {
|
||||
delete offCB;
|
||||
offCB = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void NAPIDataAbilityObserver::SetEnv(const napi_env &env)
|
||||
@@ -999,22 +1013,28 @@ void NAPIDataAbilityObserver::OnChange()
|
||||
[](uv_work_t *work, int status) {
|
||||
HILOG_INFO("OnChange, uv_queue_work");
|
||||
// JS Thread
|
||||
DAHelperOnOffCB *event = (DAHelperOnOffCB *)work->data;
|
||||
DAHelperOnOffCB *onCB = (DAHelperOnOffCB *)work->data;
|
||||
napi_value result[ARGS_TWO] = {0};
|
||||
result[PARAM0] = GetCallbackErrorValue(event->cbBase.cbInfo.env, NO_ERROR);
|
||||
result[PARAM0] = GetCallbackErrorValue(onCB->cbBase.cbInfo.env, NO_ERROR);
|
||||
|
||||
napi_value callback = 0;
|
||||
napi_value undefined = 0;
|
||||
napi_get_undefined(event->cbBase.cbInfo.env, &undefined);
|
||||
napi_get_undefined(onCB->cbBase.cbInfo.env, &undefined);
|
||||
napi_value callResult = 0;
|
||||
napi_get_reference_value(event->cbBase.cbInfo.env, event->cbBase.cbInfo.callback, &callback);
|
||||
napi_get_reference_value(onCB->cbBase.cbInfo.env, onCB->cbBase.cbInfo.callback, &callback);
|
||||
|
||||
napi_call_function(event->cbBase.cbInfo.env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult);
|
||||
if (event->cbBase.cbInfo.callback != nullptr) {
|
||||
napi_delete_reference(event->cbBase.cbInfo.env, event->cbBase.cbInfo.callback);
|
||||
napi_call_function(onCB->cbBase.cbInfo.env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult);
|
||||
if (onCB->cbBase.cbInfo.callback != nullptr) {
|
||||
napi_delete_reference(onCB->cbBase.cbInfo.env, onCB->cbBase.cbInfo.callback);
|
||||
}
|
||||
if (onCB != nullptr) {
|
||||
delete onCB;
|
||||
onCB = nullptr;
|
||||
}
|
||||
if (work != nullptr) {
|
||||
delete work;
|
||||
work = nullptr;
|
||||
}
|
||||
delete event;
|
||||
delete work;
|
||||
});
|
||||
if (rev != 0) {
|
||||
if (onCB != nullptr) {
|
||||
|
||||
@@ -3148,8 +3148,16 @@ void NAPIAbilityConnection::SetDisconnectCBRef(const napi_ref &ref)
|
||||
void UvWorkOnAbilityConnectDone(uv_work_t *work, int status)
|
||||
{
|
||||
HILOG_INFO("UvWorkOnAbilityConnectDone, uv_queue_work");
|
||||
if (work == nullptr) {
|
||||
HILOG_ERROR("UvWorkOnAbilityConnectDone, work is null");
|
||||
return;
|
||||
}
|
||||
// JS Thread
|
||||
ConnectAbilityCB *connectAbilityCB = static_cast<ConnectAbilityCB *>(work->data);
|
||||
if (connectAbilityCB == nullptr) {
|
||||
HILOG_ERROR("UvWorkOnAbilityConnectDone, connectAbilityCB is null");
|
||||
return;
|
||||
}
|
||||
napi_value result[ARGS_TWO] = {0};
|
||||
result[PARAM0] =
|
||||
WrapElementName(connectAbilityCB->cbBase.cbInfo.env, connectAbilityCB->abilityConnectionCB.elementName);
|
||||
@@ -3235,8 +3243,16 @@ void NAPIAbilityConnection::OnAbilityConnectDone(
|
||||
void UvWorkOnAbilityDisconnectDone(uv_work_t *work, int status)
|
||||
{
|
||||
HILOG_INFO("UvWorkOnAbilityDisconnectDone, uv_queue_work");
|
||||
if (work == nullptr) {
|
||||
HILOG_ERROR("UvWorkOnAbilityDisconnectDone, work is null");
|
||||
return;
|
||||
}
|
||||
// JS Thread
|
||||
ConnectAbilityCB *connectAbilityCB = static_cast<ConnectAbilityCB *>(work->data);
|
||||
if (connectAbilityCB == nullptr) {
|
||||
HILOG_ERROR("UvWorkOnAbilityDisconnectDone, connectAbilityCB is null");
|
||||
return;
|
||||
}
|
||||
napi_value result = nullptr;
|
||||
result = WrapElementName(connectAbilityCB->cbBase.cbInfo.env, connectAbilityCB->abilityConnectionCB.elementName);
|
||||
|
||||
@@ -3347,13 +3363,17 @@ napi_value NAPI_AcquireDataAbilityHelperCommon(napi_env env, napi_callback_info
|
||||
}
|
||||
|
||||
napi_value global = nullptr;
|
||||
NAPI_CALL(env, napi_get_global(env, &global));
|
||||
napi_get_global(env, &global);
|
||||
napi_value abilityObj = nullptr;
|
||||
NAPI_CALL(env, napi_get_named_property(env, global, "ability", &abilityObj));
|
||||
napi_get_named_property(env, global, "ability", &abilityObj);
|
||||
Ability *ability = nullptr;
|
||||
NAPI_CALL(env, napi_get_value_external(env, abilityObj, (void **)&ability));
|
||||
napi_get_value_external(env, abilityObj, (void **)&ability);
|
||||
if (ability == nullptr) {
|
||||
HILOG_ERROR("%{public}s, ability == nullptr", __func__);
|
||||
if (dataAbilityHelperCB != nullptr) {
|
||||
delete dataAbilityHelperCB;
|
||||
dataAbilityHelperCB = nullptr;
|
||||
}
|
||||
return WrapVoidToJS(env);
|
||||
}
|
||||
|
||||
|
||||
@@ -1088,28 +1088,6 @@ void CompletePromiseCallbackWork(napi_env env, napi_status status, void *data)
|
||||
asyncCallbackInfo = nullptr;
|
||||
}
|
||||
|
||||
std::vector<std::string> ConvertStrVector(napi_env env, napi_value value, size_t strMax)
|
||||
{
|
||||
uint32_t arrLen = 0;
|
||||
napi_get_array_length(env, value, &arrLen);
|
||||
if (arrLen == 0) {
|
||||
return {};
|
||||
}
|
||||
std::vector<std::string> result;
|
||||
char *buf = new char[strMax + 1];
|
||||
size_t len = 0;
|
||||
for (size_t i = 0; i < arrLen; ++i) {
|
||||
napi_value element = nullptr;
|
||||
napi_get_element(env, value, i, &element);
|
||||
len = 0;
|
||||
napi_get_value_string_utf8(env, element, buf, strMax, &len);
|
||||
buf[len] = 0;
|
||||
result.push_back(buf);
|
||||
}
|
||||
delete[] buf;
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> ConvertU8Vector(napi_env env, napi_value jsValue)
|
||||
{
|
||||
bool isTypedArray = false;
|
||||
@@ -1134,76 +1112,5 @@ std::vector<uint8_t> ConvertU8Vector(napi_env env, napi_value jsValue)
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value ConvertJSValue(napi_env env, std::vector<std::string> &value)
|
||||
{
|
||||
napi_value jsValue;
|
||||
napi_status status = napi_create_array_with_length(env, value.size(), &jsValue);
|
||||
if (status != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < value.size(); ++i) {
|
||||
napi_set_element(env, jsValue, i, ConvertJSValue(env, value[i]));
|
||||
}
|
||||
return jsValue;
|
||||
}
|
||||
|
||||
napi_value ConvertJSValue(napi_env env, std::string &value)
|
||||
{
|
||||
napi_value jsValue;
|
||||
napi_status status = napi_create_string_utf8(env, value.c_str(), value.size(), &jsValue);
|
||||
if (status != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
return jsValue;
|
||||
}
|
||||
|
||||
napi_value ConvertJSValue(napi_env env, std::vector<uint8_t> &value)
|
||||
{
|
||||
napi_value jsValue = nullptr;
|
||||
void *native = nullptr;
|
||||
napi_value buffer = nullptr;
|
||||
napi_status status = napi_create_arraybuffer(env, value.size(), &native, &buffer);
|
||||
if (status != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
(void)memcpy_s(native, value.size(), value.data(), value.size());
|
||||
status = napi_create_typedarray(env, napi_uint8_array, value.size(), buffer, 0, &jsValue);
|
||||
if (status != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
return jsValue;
|
||||
}
|
||||
|
||||
napi_value ConvertJSValue(napi_env env, int32_t value)
|
||||
{
|
||||
napi_value jsValue;
|
||||
napi_status status = napi_create_int32(env, value, &jsValue);
|
||||
if (status != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
return jsValue;
|
||||
}
|
||||
|
||||
napi_value ConvertJSValue(napi_env env, int64_t value)
|
||||
{
|
||||
napi_value jsValue;
|
||||
napi_status status = napi_create_int64(env, value, &jsValue);
|
||||
if (status != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
return jsValue;
|
||||
}
|
||||
|
||||
napi_value ConvertJSValue(napi_env env, double value)
|
||||
{
|
||||
napi_value jsValue;
|
||||
napi_status status = napi_create_double(env, value, &jsValue);
|
||||
if (status != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
return jsValue;
|
||||
}
|
||||
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -235,16 +235,8 @@ void CompleteAsyncCallbackWork(napi_env env, napi_status status, void *data);
|
||||
*/
|
||||
void CompletePromiseCallbackWork(napi_env env, napi_status status, void *data);
|
||||
|
||||
std::vector<std::string> ConvertStrVector(napi_env env, napi_value value, size_t strMax);
|
||||
std::vector<uint8_t> ConvertU8Vector(napi_env env, napi_value jsValue);
|
||||
|
||||
napi_value ConvertJSValue(napi_env env, std::vector<std::string> &value);
|
||||
napi_value ConvertJSValue(napi_env env, std::string &value);
|
||||
napi_value ConvertJSValue(napi_env env, std::vector<uint8_t> &value);
|
||||
napi_value ConvertJSValue(napi_env env, int32_t value);
|
||||
napi_value ConvertJSValue(napi_env env, int64_t value);
|
||||
napi_value ConvertJSValue(napi_env env, double value);
|
||||
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_APPEXECFWK_NAPI_COMMON_UTIL_H
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
* 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.
|
||||
-->
|
||||
<info>
|
||||
<process>foundation</process>
|
||||
<systemability>
|
||||
<name>182</name>
|
||||
<libpath>/system/lib64/libdataobsms.z.so</libpath>
|
||||
<!--<depend></depend> --> <!-- Declare the name of system abilities which the system ability depends on. Note that one dependency uses 1 line. If there are dependencies, it needs to check if all those dependencies are available in service manager before starting the system ability. -->
|
||||
<!--<depend-time-out></depend-time-out> --> <!-- Check all dependencies are available before the timeout period ended. The MAX_DEPENDENCY_TIMEOUT is 60s. -->
|
||||
<run-on-create>true</run-on-create>
|
||||
<distributed>false</distributed>
|
||||
<dump-level>1</dump-level>
|
||||
</systemability>
|
||||
</info>
|
||||
+4
-1
@@ -14,7 +14,10 @@
|
||||
import("//build/ohos/sa_profile/sa_profile.gni")
|
||||
|
||||
ohos_sa_profile("aafwk_sa_profile") {
|
||||
sources = [ "180.xml" ]
|
||||
sources = [
|
||||
"180.xml",
|
||||
"182.xml",
|
||||
]
|
||||
|
||||
part_name = "aafwk_standard"
|
||||
}
|
||||
|
||||
+1
-3
@@ -104,13 +104,11 @@ bool BundleMgrService::QueryAbilityInfo(const AAFwk::Want &want, AbilityInfo &ab
|
||||
if (CheckWantEntity(want, abilityInfo)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ElementName elementTemp = want.GetElement();
|
||||
std::string abilityNameTemp = elementTemp.GetAbilityName();
|
||||
std::string bundleNameTemp = elementTemp.GetBundleName();
|
||||
abilityInfo.deviceId = elementTemp.GetDeviceID();
|
||||
abilityInfo.visible = true;
|
||||
|
||||
if (bundleNameTemp.empty() || abilityNameTemp.empty()) {
|
||||
return false;
|
||||
}
|
||||
@@ -132,7 +130,7 @@ bool BundleMgrService::QueryAbilityInfo(const AAFwk::Want &want, AbilityInfo &ab
|
||||
abilityInfo.deviceId = elementTemp.GetDeviceID();
|
||||
abilityInfo.applicationInfo.bundleName = elementTemp.GetBundleName();
|
||||
abilityInfo.applicationInfo.name = "hello";
|
||||
if (want.HasEntity(Want::ENTITY_HOME) && want.GetAction() == Want::ACTION_HOME) {
|
||||
if (elementTemp.GetAbilityName().find("com.ohos.launcher.MainAbility") != std::string::npos) {
|
||||
abilityInfo.applicationInfo.isLauncherApp = true;
|
||||
} else {
|
||||
abilityInfo.applicationInfo.isLauncherApp = false;
|
||||
|
||||
@@ -141,6 +141,10 @@ void AbilityDumpTest::TearDown()
|
||||
|
||||
void AbilityDumpTest::StartAbilityes()
|
||||
{
|
||||
EXPECT_TRUE(g_abilityMs->currentStackManager_);
|
||||
auto currentTopAbilityRecord = g_abilityMs->currentStackManager_->GetCurrentTopAbility();
|
||||
EXPECT_TRUE(currentTopAbilityRecord);
|
||||
currentTopAbilityRecord->SetAbilityState(AbilityState::ACTIVE);
|
||||
startAbility6();
|
||||
startAbility1();
|
||||
startAbility2();
|
||||
|
||||
+3
-3
@@ -274,7 +274,7 @@ HWTEST_F(AbilityWithApplicationsTest, Teminate_Ability_With_Applications_001, Te
|
||||
}
|
||||
|
||||
if (topAbility) {
|
||||
EXPECT_EQ("com.ix.hiworld", topAbility->GetAbilityInfo().applicationName);
|
||||
EXPECT_EQ("com.ohos.launcher", topAbility->GetAbilityInfo().applicationName);
|
||||
EXPECT_EQ(INACTIVATING, topAbility->GetAbilityState());
|
||||
}
|
||||
|
||||
@@ -350,10 +350,10 @@ HWTEST_F(AbilityWithApplicationsTest, Teminate_Ability_With_Applications_002, Te
|
||||
EXPECT_EQ(0, result);
|
||||
|
||||
auto missionstack = stackmgr->GetCurrentMissionStack();
|
||||
EXPECT_EQ(1, missionstack->GetMissionStackId());
|
||||
EXPECT_EQ(0, missionstack->GetMissionStackId());
|
||||
topAbility = missionstack->GetTopAbilityRecord();
|
||||
EXPECT_TRUE(topAbility != nullptr);
|
||||
EXPECT_EQ("com.ix.test1", topAbility->GetAbilityInfo().applicationName);
|
||||
EXPECT_EQ("com.ohos.launcher", topAbility->GetAbilityInfo().applicationName);
|
||||
AbilityRequest request;
|
||||
abilityMs_->GetStackManager()->GetTargetMissionStack(request)->RemoveAll();
|
||||
GTEST_LOG_(INFO) << "Teminate_Ability_With_Applications_002 end";
|
||||
|
||||
@@ -105,6 +105,7 @@ void AbilityMsAppmsTest::SetUp(void)
|
||||
|
||||
DelayedSingleton<AppScheduler>::GetInstance()->Init(callback_);
|
||||
DelayedSingleton<AbilityManagerService>::GetInstance()->OnStart();
|
||||
WaitUntilTaskFinished();
|
||||
startAbility();
|
||||
GTEST_LOG_(INFO) << "SetUp";
|
||||
}
|
||||
@@ -143,6 +144,10 @@ void AbilityMsAppmsTest::startAbility()
|
||||
ApplicationInfo applicationInfo;
|
||||
|
||||
auto abilityMs_ = DelayedSingleton<AbilityManagerService>::GetInstance();
|
||||
EXPECT_TRUE(abilityMs_->currentStackManager_);
|
||||
auto currentTopAbilityRecord = abilityMs_->currentStackManager_->GetCurrentTopAbility();
|
||||
EXPECT_TRUE(currentTopAbilityRecord);
|
||||
currentTopAbilityRecord->SetAbilityState(AbilityState::ACTIVE);
|
||||
ElementName element("device", "com.ix.hiworld", "luncherAbility");
|
||||
want.SetElement(element);
|
||||
abilityMs_->StartAbility(want);
|
||||
|
||||
@@ -126,6 +126,12 @@ void LifecycleTest::TearDown(void)
|
||||
|
||||
bool LifecycleTest::StartLauncherAbility()
|
||||
{
|
||||
auto stackManager = aams_->GetStackManager();
|
||||
EXPECT_TRUE(stackManager);
|
||||
auto topAbility = stackManager->GetCurrentTopAbility();
|
||||
EXPECT_TRUE(topAbility);
|
||||
topAbility->SetAbilityState(OHOS::AAFwk::AbilityState::ACTIVE);
|
||||
|
||||
ElementName element("device", "com.ix.hiWord", "LauncherAbility");
|
||||
Want want;
|
||||
want.AddEntity(Want::FLAG_HOME_INTENT_FROM_SYSTEM);
|
||||
@@ -137,8 +143,7 @@ bool LifecycleTest::StartLauncherAbility()
|
||||
GTEST_LOG_(ERROR) << "fail to start Launcher ability";
|
||||
return false;
|
||||
}
|
||||
auto stackManager = aams_->GetStackManager();
|
||||
EXPECT_TRUE(stackManager);
|
||||
|
||||
launcherAbilityRecord_ = (stackManager->GetCurrentTopAbility());
|
||||
EXPECT_TRUE(launcherAbilityRecord_);
|
||||
if (launcherAbilityRecord_) {
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <exception>
|
||||
#include <typeinfo>
|
||||
#include <cassert>
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace hidden {
|
||||
// workaroud for T& equally matching f(T&) and f(T const&)
|
||||
@@ -88,10 +89,10 @@ struct checked_cast_impl<T, X, true> {
|
||||
{
|
||||
#ifdef CHECKED_CAST_SAFE_CONVERSATION
|
||||
T t = dynamic_cast<T>(x);
|
||||
|
||||
// check cross cast
|
||||
if (t != static_cast<T>(x))
|
||||
if (t != static_cast<T>(x)) {
|
||||
BAD_CHECKED_CAST(x, T);
|
||||
}
|
||||
return t;
|
||||
#else
|
||||
return static_cast<T>(x);
|
||||
@@ -104,8 +105,9 @@ struct checked_cast_impl<T, X, true> {
|
||||
T t = dynamic_cast<T>(x);
|
||||
|
||||
// check cross cast
|
||||
if (t != static_cast<T>(x))
|
||||
if (t != static_cast<T>(x)) {
|
||||
BAD_CHECKED_CAST(x, T);
|
||||
}
|
||||
return t;
|
||||
#else
|
||||
return static_cast<T>(x);
|
||||
@@ -118,12 +120,12 @@ struct checked_cast_impl<T, X, false> {
|
||||
static T cast(X &x, hidden::LookUpHelper2 const &)
|
||||
{
|
||||
#ifdef CHECKED_CAST_SAFE_CONVERSATION
|
||||
T t = dynamic_cast<T>(x);
|
||||
// check cross cast
|
||||
if (&t != &static_cast<T>(x)) {
|
||||
throw std::bad_cast();
|
||||
}
|
||||
return t;
|
||||
T t = dynamic_cast<T>(x);
|
||||
// check cross cast
|
||||
if (&t != &static_cast<T>(x)) {
|
||||
HILOG_ERROR("!!!bad cast!!!");
|
||||
}
|
||||
return t;
|
||||
#else
|
||||
return static_cast<T>(x);
|
||||
#endif
|
||||
@@ -132,16 +134,12 @@ struct checked_cast_impl<T, X, false> {
|
||||
static T cast(X const &x, hidden::LookUpHelper const &)
|
||||
{
|
||||
#ifdef CHECKED_CAST_SAFE_CONVERSATION
|
||||
try {
|
||||
T t = dynamic_cast<T>(x);
|
||||
|
||||
// check cross cast
|
||||
if (&t != &static_cast<T>(x))
|
||||
std::bad_cast();
|
||||
return t;
|
||||
} catch (...) {
|
||||
BAD_CHECKED_CAST(x, T);
|
||||
T t = dynamic_cast<T>(x);
|
||||
// check cross cast
|
||||
if (&t != &static_cast<T>(x)) {
|
||||
std::bad_cast();
|
||||
}
|
||||
return t;
|
||||
#else
|
||||
return static_cast<T>(x);
|
||||
#endif
|
||||
|
||||
@@ -53,7 +53,6 @@ public:
|
||||
class ZipReader {
|
||||
public:
|
||||
// A callback that is called when the operation is successful.
|
||||
// using SuccessCallback = base::OnceClosure;
|
||||
using SuccessCallback = std::function<void()>;
|
||||
// A callback that is called when the operation fails.
|
||||
using FailureCallback = std::function<void()>;
|
||||
@@ -112,7 +111,14 @@ public:
|
||||
private:
|
||||
FilePath filePath_;
|
||||
int64_t originalSize_ = 0;
|
||||
struct tm lastModified_;
|
||||
struct tm lastModified_ {
|
||||
.tm_year = 0,
|
||||
.tm_mon = 0,
|
||||
.tm_mday = 0,
|
||||
.tm_hour = 0,
|
||||
.tm_min = 0,
|
||||
.tm_sec = 0
|
||||
};
|
||||
bool isDirectory_ = false;
|
||||
bool isUnsafe_ = false;
|
||||
bool isEncrypted_ = false;
|
||||
|
||||
Vendored
+15
-15
@@ -16,7 +16,7 @@
|
||||
import { AsyncCallback } from './basic';
|
||||
|
||||
declare namespace zlib {
|
||||
//Zlib library constant definition
|
||||
// Zlib library constant definition
|
||||
export enum FlushType {
|
||||
FLUSH_TYPE_NO_FLUSH = 0,
|
||||
FLUSH_TYPE_PARTIAL_FLUSH = 1,
|
||||
@@ -42,7 +42,7 @@ declare namespace zlib {
|
||||
ERROR_CODE_VERSION_ERROR = -6
|
||||
}
|
||||
|
||||
//enum CompressLevel
|
||||
// enum CompressLevel
|
||||
export enum CompressLevel {
|
||||
COMPRESS_LEVEL_NO_COMPRESSION = 0,
|
||||
COMPRESS_LEVEL_BEST_SPEED = 1,
|
||||
@@ -50,7 +50,7 @@ declare namespace zlib {
|
||||
COMPRESS_LEVEL_DEFAULT_COMPRESSION = -1
|
||||
}
|
||||
|
||||
//enum CompressStrategy
|
||||
// enum CompressStrategy
|
||||
export enum CompressStrategy {
|
||||
COMPRESS_STRATEGY_DEFAULT_STRATEGY = 0,
|
||||
COMPRESS_STRATEGY_FILTERED = 1,
|
||||
@@ -59,34 +59,34 @@ declare namespace zlib {
|
||||
COMPRESS_STRATEGY_FIXED = 4
|
||||
}
|
||||
|
||||
//enum MemLevel
|
||||
// enum MemLevel
|
||||
export enum MemLevel {
|
||||
MEM_LEVEL_MIN_MEMLEVEL = 1,
|
||||
MEM_LEVEL_DEFAULT_MEMLEVEL = 8,
|
||||
MEM_LEVEL_MAX_MEMLEVEL = 9
|
||||
}
|
||||
|
||||
//zip options
|
||||
// zip options
|
||||
interface Options {
|
||||
flush?: FlushType; //corresponding zlib library macro
|
||||
finishFlush?: FlushType; //corresponding zlib library macro #define Z_FINISH 4
|
||||
chunkSize?: number; //Buffer size,>64
|
||||
level?: CompressLevel; //Compression level. The compression level is a number from 0 to 9.
|
||||
//0 has the fastest compression speed (compression process), 9 has the slowest compression speed,
|
||||
flush?: FlushType; // corresponding zlib library macro
|
||||
finishFlush?: FlushType; // corresponding zlib library macro #define Z_FINISH 4
|
||||
chunkSize?: number; // Buffer size,>64
|
||||
level?: CompressLevel; // Compression level. The compression level is a number from 0 to 9.
|
||||
// 0 has the fastest compression speed (compression process), 9 has the slowest compression speed,
|
||||
// the largest compression rate, and 0 does not compress.
|
||||
|
||||
memLevel?: MemLevel; //How much memory should be allocated for the specified internal compression state.
|
||||
memLevel?: MemLevel; // How much memory should be allocated for the specified internal compression state.
|
||||
// Memlevel = 1 uses the minimum memory, but it is very slow, reducing the compression ratio; Memlevel = 9 uses the maximum memory to get the best speed. The default value is 8.
|
||||
strategy?: CompressStrategy; //CompressStrategy
|
||||
dictionary?: ArrayBuffer; //deflate/inflate only, empty dictionary by default
|
||||
strategy?: CompressStrategy; // CompressStrategy
|
||||
dictionary?: ArrayBuffer; // deflate/inflate only, empty dictionary by default
|
||||
}
|
||||
|
||||
|
||||
//The interface for compressing the specified file. There is only one callback callback interface
|
||||
// The interface for compressing the specified file. There is only one callback callback interface
|
||||
function zipFile(inFile:string, outFile:string, options: Options, callback: AsyncCallback<void>): void;
|
||||
function zipFile(inFile:string, outFile:string, options: Options): Promise<number>;
|
||||
|
||||
//The interface for decompressing the specified file. There is only one callback callback interface
|
||||
// The interface for decompressing the specified file. There is only one callback callback interface
|
||||
function unzipFile(inFile:string, outFile:string, options: Options, callback: AsyncCallback<void>): void;
|
||||
function unzipFile(inFile:string, outFile:string, options: Options): Promise<number>;
|
||||
}
|
||||
|
||||
@@ -26,9 +26,6 @@
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
namespace LIBZIP {
|
||||
namespace {
|
||||
const int E_OK = 0;
|
||||
}
|
||||
#define NO_ERROR 0
|
||||
|
||||
#define COMPRESS_LEVE_CHECK(level, ret) \
|
||||
@@ -491,10 +488,10 @@ napi_value NAPI_UnzipFile(napi_env env, napi_callback_info info)
|
||||
g_unzipAceCallbackInfo = nullptr;
|
||||
}
|
||||
if (asyncZipCallbackInfo != nullptr) {
|
||||
napi_delete_async_work(env, asyncZipCallbackInfo->asyncWork);
|
||||
delete asyncZipCallbackInfo;
|
||||
asyncZipCallbackInfo = nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
HILOG_INFO("%{public}s,end", __func__);
|
||||
return ret;
|
||||
@@ -684,7 +681,7 @@ void ZipAndUnzipFileAsyncCallBack(std::shared_ptr<ZlibCallbackInfo> &zipAceCallb
|
||||
zipAceCallbackInfo.reset();
|
||||
zipAceCallbackInfo = nullptr;
|
||||
work->data = (void *)asyncCallbackInfo;
|
||||
int rev = uv_queue_work(
|
||||
uv_queue_work(
|
||||
loop,
|
||||
work,
|
||||
[](uv_work_t *work) {},
|
||||
@@ -693,22 +690,19 @@ void ZipAndUnzipFileAsyncCallBack(std::shared_ptr<ZlibCallbackInfo> &zipAceCallb
|
||||
ZipAndUnzipFileAsyncCallBackInnerJsThread(work);
|
||||
HILOG_INFO("ZipAndUnzipFileAsyncCallBack, uv_queue_work end.");
|
||||
});
|
||||
if (rev != E_OK) {
|
||||
if (asyncCallbackInfo->isCallBack) {
|
||||
if (asyncCallbackInfo->callback != nullptr) {
|
||||
napi_delete_reference(asyncCallbackInfo->env, asyncCallbackInfo->callback);
|
||||
}
|
||||
}
|
||||
if (asyncCallbackInfo != nullptr) {
|
||||
delete asyncCallbackInfo;
|
||||
asyncCallbackInfo = nullptr;
|
||||
}
|
||||
if (work != nullptr) {
|
||||
delete work;
|
||||
work = nullptr;
|
||||
if (asyncCallbackInfo->isCallBack) {
|
||||
if (asyncCallbackInfo->callback != nullptr) {
|
||||
napi_delete_reference(asyncCallbackInfo->env, asyncCallbackInfo->callback);
|
||||
}
|
||||
}
|
||||
return;
|
||||
if (asyncCallbackInfo != nullptr) {
|
||||
delete asyncCallbackInfo;
|
||||
asyncCallbackInfo = nullptr;
|
||||
}
|
||||
if (work != nullptr) {
|
||||
delete work;
|
||||
work = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace LIBZIP
|
||||
|
||||
@@ -27,7 +27,14 @@ namespace LIBZIP {
|
||||
struct tm GetTmDataFromTickts(int64_t sec)
|
||||
{
|
||||
time_t second = (time_t)sec;
|
||||
struct tm now;
|
||||
struct tm now {
|
||||
.tm_year = 0,
|
||||
.tm_mon = 0,
|
||||
.tm_mday = 0,
|
||||
.tm_hour = 0,
|
||||
.tm_min = 0,
|
||||
.tm_sec = 0,
|
||||
};
|
||||
struct tm *tmNow = localtime(&second);
|
||||
if (tmNow == nullptr) {
|
||||
return now;
|
||||
@@ -143,9 +150,9 @@ uLong ReadZipBuffer(void *opaque, void *, void *buf, uLong size)
|
||||
|
||||
// Writes compressed data to the stream. This function always returns zero
|
||||
// because this implementation is only for reading compressed data.
|
||||
uLong WriteZipBuffer(void *, void *, const void *, uLong)
|
||||
uLong WriteZipBuffer(void *opaque, void *stream, const void *buf, uLong)
|
||||
{
|
||||
HILOG_INFO("%{public}s called.", __func__);
|
||||
HILOG_INFO("%{public}s called. opaque=%p, stream=%p, buf=%p", __func__, opaque, stream, buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -236,8 +243,9 @@ unzFile PrepareMemoryForUnzipping(const std::string &data)
|
||||
return NULL;
|
||||
}
|
||||
ZipBuffer *buffer = static_cast<ZipBuffer *>(malloc(sizeof(ZipBuffer)));
|
||||
if (!buffer)
|
||||
if (!buffer) {
|
||||
return NULL;
|
||||
}
|
||||
buffer->data = data.data();
|
||||
buffer->length = data.length();
|
||||
buffer->offset = 0;
|
||||
|
||||
@@ -197,9 +197,6 @@ bool ZipWriter::FlushEntriesIfNeeded(bool force, const OPTIONS &options, CALLBAC
|
||||
for (auto iter = pendingEntries_.begin(); iter != pendingEntries_.begin() + entry_count; ++iter) {
|
||||
// The FileAccessor requires absolute paths.
|
||||
absolutePaths.push_back(FilePath(rootDir_.Value() + iter->Value()));
|
||||
|
||||
printf("--zip-33--relativePaths=%s--\n", relativePaths[0].Value().c_str());
|
||||
printf("--zip-55--absolutePaths=%s--\n", (rootDir_.Value() + iter->Value()).c_str());
|
||||
}
|
||||
pendingEntries_.erase(pendingEntries_.begin(), pendingEntries_.begin() + entry_count);
|
||||
|
||||
@@ -211,15 +208,12 @@ bool ZipWriter::FlushEntriesIfNeeded(bool force, const OPTIONS &options, CALLBAC
|
||||
FilePath &relativePath = relativePaths[i];
|
||||
FilePath &absolutePath = absolutePaths[i];
|
||||
if (FilePath::PathIsValid(absolutePath)) {
|
||||
printf("--zip-88--relativePath=%s--\n", relativePath.Value().c_str());
|
||||
printf("--zip-99--absolutePath=%s--\n", absolutePath.Value().c_str());
|
||||
if (!AddFileEntryToZip(zipFile_, relativePath, absolutePath, options)) {
|
||||
CALLING_CALL_BACK(callback, ERROR_CODE_ERRNO)
|
||||
HILOG_INFO("%{public}s called, Failed to write file", __func__);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
printf("--zip-66--\n");
|
||||
// Missing file or directory case.
|
||||
struct tm *last_modified = GetCurrentSystemTime();
|
||||
if (!AddDirectoryEntryToZip(zipFile_, relativePath, last_modified, options)) {
|
||||
|
||||
Reference in New Issue
Block a user