mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-11-27 09:21:28 +00:00
sync aafwk code
Signed-off-by: jiangdayuan <jiangdayuan@huawei.com> Change-Id: Ic81a319b8dca78d10353f6c72ee1f3714636dd50
This commit is contained in:
parent
98c0ac3c37
commit
29666ca7bd
21
README_zh.md
21
README_zh.md
@ -296,13 +296,13 @@ featureAbility.terminateSelf().then((void) => { console.info("=============
|
||||
|
||||
**aa start**
|
||||
|
||||
| 命令 | 描述 |
|
||||
| --------------------------------------------------------- | ------------------------ |
|
||||
| aa start [-d <device>] -a <ability-name> -b <bundle-name> | 启动ability,设备ID 可空 |
|
||||
| 命令 | 描述 |
|
||||
| -------------------------------------------------------------- | ------------------------ |
|
||||
| aa start [-d <device>] -a <ability-name> -b <bundle-name> [-D] | 启动ability,设备ID 可空 |
|
||||
|
||||
```
|
||||
示例:
|
||||
aa start -d 12345 -a com.ohos.app.MainAbility -b com.ohos.app
|
||||
aa start -d 12345 -a com.ohos.app.MainAbility -b com.ohos.app -D
|
||||
```
|
||||
|
||||
**aa dump**
|
||||
@ -311,10 +311,21 @@ aa start -d 12345 -a com.ohos.app.MainAbility -b com.ohos.app
|
||||
| ---------- | --------------------- |
|
||||
| aa dump -a | 打印栈中的Ability信息 |
|
||||
|
||||
**aa force-stop**
|
||||
|
||||
| 命令 | 描述 |
|
||||
| -------------------------------------------------------------- | ------------------------ |
|
||||
| aa force-stop <bundle-name> | 强制停止application |
|
||||
|
||||
```
|
||||
示例:
|
||||
aa force-stop com.ohos.app
|
||||
```
|
||||
|
||||
## 相关仓
|
||||
元能力子系统
|
||||
|
||||
appexecfwk_standard
|
||||
appexecfwk_standard
|
||||
|
||||
**aafwk_standard**
|
||||
|
||||
|
57
frameworks/kits/ability/ability_runtime/BUILD.gn
Executable file
57
frameworks/kits/ability/ability_runtime/BUILD.gn
Executable file
@ -0,0 +1,57 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
SO_DIR = "//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime"
|
||||
INNERKITS_DIR = "//foundation/aafwk/standard/interfaces/innerkits"
|
||||
APPKIT_DIR = "//foundation/appexecfwk/standard/kits"
|
||||
|
||||
config("ability_context_public_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [
|
||||
"${SO_DIR}/include",
|
||||
"${APPKIT_DIR}/appkit/native/ability_runtime",
|
||||
"${APPKIT_DIR}/appkit/native/ability_runtime/context",
|
||||
]
|
||||
|
||||
cflags = []
|
||||
if (target_cpu == "arm") {
|
||||
cflags += [ "-DBINDER_IPC_32BIT" ]
|
||||
}
|
||||
}
|
||||
|
||||
ohos_shared_library("ability_context_native") {
|
||||
public_configs = [ ":ability_context_public_config" ]
|
||||
|
||||
sources = [
|
||||
"${SO_DIR}/src/ability_context_impl.cpp",
|
||||
"${SO_DIR}/src/js_extension_context.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${APPKIT_DIR}:app_context",
|
||||
"${INNERKITS_DIR}/ability_manager:ability_manager",
|
||||
"${INNERKITS_DIR}/want:want",
|
||||
"//foundation/ace/napi:ace_napi",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"aafwk_standard:runtime",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"utils_base:utils",
|
||||
]
|
||||
|
||||
subsystem_name = "aafwk"
|
||||
part_name = "aafwk_standard"
|
||||
}
|
93
frameworks/kits/ability/ability_runtime/include/ability_context.h
Executable file
93
frameworks/kits/ability/ability_runtime/include/ability_context.h
Executable file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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 ABILITY_RUNTIME_ABILITY_CONTEXT_H
|
||||
#define ABILITY_RUNTIME_ABILITY_CONTEXT_H
|
||||
|
||||
#include "foundation/appexecfwk/standard/kits/appkit/native/ability_runtime/context/context.h"
|
||||
|
||||
#include "ability_connect_callback_interface.h"
|
||||
#include "ability_info.h"
|
||||
#include "want.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
using RuntimeTask = std::function<void(int, const AAFwk::Want&)>;
|
||||
class AbilityContext : public Context {
|
||||
public:
|
||||
virtual ~AbilityContext() = default;
|
||||
|
||||
/**
|
||||
* @brief Starts a new ability.
|
||||
* An ability using the AbilityInfo.AbilityType.SERVICE or AbilityInfo.AbilityType.PAGE template uses this method
|
||||
* to start a specific ability. The system locates the target ability from installed abilities based on the value
|
||||
* of the want parameter and then starts it. You can specify the ability to start using the want parameter.
|
||||
*
|
||||
* @param want Indicates the Want containing information about the target ability to start.
|
||||
* @param requestCode Indicates the request code returned after the ability using the AbilityInfo.AbilityType.PAGE
|
||||
* template is started. You can define the request code to identify the results returned by abilities. The value
|
||||
* ranges from 0 to 65535. This parameter takes effect only on abilities using the AbilityInfo.AbilityType.PAGE
|
||||
* template.
|
||||
*/
|
||||
virtual ErrCode StartAbility(const AAFwk::Want &want, int requestCode) = 0;
|
||||
|
||||
virtual ErrCode StartAbilityForResult(const AAFwk::Want &Want, int requestCode, RuntimeTask &&task) = 0;
|
||||
|
||||
virtual ErrCode TerminateAbilityWithResult(const AAFwk::Want &want, int resultCode) = 0;
|
||||
|
||||
virtual void OnAbilityResult(int requestCode, int resultCode, const AAFwk::Want &resultData) = 0;
|
||||
|
||||
/**
|
||||
* @brief Connects the current ability to an ability using the AbilityInfo.AbilityType.SERVICE template.
|
||||
*
|
||||
* @param want Indicates the want containing information about the ability to connect
|
||||
* @param conn Indicates the callback object when the target ability is connected.
|
||||
* @return True means success and false means failure
|
||||
*/
|
||||
virtual bool ConnectAbility(const AAFwk::Want &want, const sptr<AAFwk::IAbilityConnection> &conn) = 0;
|
||||
|
||||
/**
|
||||
* @brief Disconnects the current ability from an ability
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
virtual void DisconnectAbility(const sptr<AAFwk::IAbilityConnection> &conn) = 0;
|
||||
|
||||
/**
|
||||
* @brief get ability info of the current ability
|
||||
*
|
||||
* @return the ability info of the current ability
|
||||
*/
|
||||
virtual std::shared_ptr<AppExecFwk::AbilityInfo> GetAbilityInfo() const = 0;
|
||||
|
||||
/**
|
||||
* @brief Minimize the current ability.
|
||||
*
|
||||
*/
|
||||
virtual void MinimizeAbility() = 0;
|
||||
|
||||
virtual ErrCode TerminateSelf() = 0;
|
||||
|
||||
/**
|
||||
* @brief Obtains token.
|
||||
*
|
||||
* @return Returns the token.
|
||||
*/
|
||||
virtual sptr<IRemoteObject> GetAbilityToken() = 0;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // ABILITY_RUNTIME_ABILITY_CONTEXT_H
|
83
frameworks/kits/ability/ability_runtime/include/ability_context_impl.h
Executable file
83
frameworks/kits/ability/ability_runtime/include/ability_context_impl.h
Executable file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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 ABILITY_RUNTIME_ABILITY_CONTEXT_IMPL_H
|
||||
#define ABILITY_RUNTIME_ABILITY_CONTEXT_IMPL_H
|
||||
|
||||
#include "ability_context.h"
|
||||
|
||||
#include "context_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
class AbilityContextImpl : public AbilityContext {
|
||||
public:
|
||||
AbilityContextImpl() = default;
|
||||
virtual ~AbilityContextImpl() = default;
|
||||
|
||||
std::string GetBundleCodeDir() override;
|
||||
std::string GetCacheDir() override;
|
||||
std::string GetTempDir() override;
|
||||
std::string GetFilesDir() override;
|
||||
std::string GetDatabaseDir() override;
|
||||
std::string GetStorageDir() override;
|
||||
std::string GetDistributedFilesDir() override;
|
||||
std::string GetBundleName() const override;
|
||||
std::shared_ptr<AppExecFwk::ApplicationInfo> GetApplicationInfo() const override;
|
||||
std::shared_ptr<Global::Resource::ResourceManager> GetResourceManager() const override;
|
||||
std::shared_ptr<Context> CreateBundleContext(const std::string &bundleName) override;
|
||||
|
||||
std::string GetBundleCodePath() const override;
|
||||
ErrCode StartAbility(const AAFwk::Want &want, int requestCode) override;
|
||||
ErrCode StartAbilityForResult(const AAFwk::Want &want, int requestCode, RuntimeTask &&task) override;
|
||||
ErrCode TerminateAbilityWithResult(const AAFwk::Want &want, int resultCode) override;
|
||||
void OnAbilityResult(int requestCode, int resultCode, const AAFwk::Want &resultData) override;
|
||||
bool ConnectAbility(const AAFwk::Want &want, const sptr<AAFwk::IAbilityConnection> &conn) override;
|
||||
void DisconnectAbility(const sptr<AAFwk::IAbilityConnection> &conn) override;
|
||||
std::shared_ptr<AppExecFwk::HapModuleInfo> GetHapModuleInfo() const override;
|
||||
std::shared_ptr<AppExecFwk::AbilityInfo> GetAbilityInfo() const override;
|
||||
void MinimizeAbility() override;
|
||||
|
||||
ErrCode TerminateSelf() override;
|
||||
sptr<IRemoteObject> GetAbilityToken() override;
|
||||
|
||||
void SetStageContext(const std::shared_ptr<AbilityRuntime::Context> &stageContext);
|
||||
|
||||
/**
|
||||
* @brief Set the Ability Info object
|
||||
*
|
||||
* set ability info to ability context
|
||||
*/
|
||||
void SetAbilityInfo(const std::shared_ptr<AppExecFwk::AbilityInfo> &abilityInfo);
|
||||
|
||||
/**
|
||||
* @brief Attachs ability's token.
|
||||
*
|
||||
* @param token The token represents ability.
|
||||
*/
|
||||
inline void SetToken(const sptr<IRemoteObject> &token)
|
||||
{
|
||||
token_ = token;
|
||||
}
|
||||
|
||||
private:
|
||||
sptr<IRemoteObject> token_;
|
||||
std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo_ = nullptr;
|
||||
std::shared_ptr<AbilityRuntime::Context> stageContext_ = nullptr;
|
||||
std::map<int, RuntimeTask> resultCallbacks_;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // ABILITY_RUNTIME_ABILITY_CONTEXT_IMPL_H
|
31
frameworks/kits/ability/ability_runtime/include/js_extension_context.h
Executable file
31
frameworks/kits/ability/ability_runtime/include/js_extension_context.h
Executable file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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 ABILITY_RUNTIME_JS_EXTENSION_CONTEXT_H
|
||||
#define ABILITY_RUNTIME_JS_EXTENSION_CONTEXT_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "extension_context.h"
|
||||
|
||||
class NativeEngine;
|
||||
class NativeValue;
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
NativeValue* CreateJsExtensionContext(NativeEngine& engine, std::shared_ptr<ExtensionContext> context);
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // ABILITY_RUNTIME_JS_EXTENSION_CONTEXT_H
|
179
frameworks/kits/ability/ability_runtime/src/ability_context_impl.cpp
Executable file
179
frameworks/kits/ability/ability_runtime/src/ability_context_impl.cpp
Executable file
@ -0,0 +1,179 @@
|
||||
/*
|
||||
* 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_context_impl.h"
|
||||
|
||||
#include "ability_manager_client.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
std::string AbilityContextImpl::GetBundleCodeDir()
|
||||
{
|
||||
return stageContext_ ? stageContext_->GetBundleCodeDir() : "";
|
||||
}
|
||||
|
||||
std::string AbilityContextImpl::GetCacheDir()
|
||||
{
|
||||
return stageContext_ ? stageContext_->GetCacheDir() : "";
|
||||
}
|
||||
|
||||
std::string AbilityContextImpl::GetDatabaseDir()
|
||||
{
|
||||
return stageContext_ ? stageContext_->GetDatabaseDir() : "";
|
||||
}
|
||||
|
||||
std::string AbilityContextImpl::GetStorageDir()
|
||||
{
|
||||
return stageContext_ ? stageContext_->GetStorageDir() : "";
|
||||
}
|
||||
|
||||
std::string AbilityContextImpl::GetTempDir()
|
||||
{
|
||||
return stageContext_ ? stageContext_->GetTempDir() : "";
|
||||
}
|
||||
|
||||
std::string AbilityContextImpl::GetFilesDir()
|
||||
{
|
||||
return stageContext_ ? stageContext_->GetFilesDir() : "";
|
||||
}
|
||||
|
||||
std::string AbilityContextImpl::GetDistributedFilesDir()
|
||||
{
|
||||
return stageContext_ ? stageContext_->GetDistributedFilesDir() : "";
|
||||
}
|
||||
|
||||
ErrCode AbilityContextImpl::StartAbility(const AAFwk::Want &want, int requestCode)
|
||||
{
|
||||
HILOG_DEBUG("AbilityContextImpl::StartAbility. Start calling ams->StartAbility.");
|
||||
ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, token_, requestCode);
|
||||
HILOG_INFO("AbilityContextImpl::StartAbility. End calling ams->StartAbility. ret=%{public}d", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
ErrCode AbilityContextImpl::StartAbilityForResult(const AAFwk::Want &want, int requestCode, RuntimeTask &&task)
|
||||
{
|
||||
HILOG_DEBUG("%{public}s. Start calling ams->StartAbilityForResult.", __func__);
|
||||
resultCallbacks_.insert(make_pair(requestCode, std::move(task)));
|
||||
ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, token_, requestCode);
|
||||
HILOG_INFO("%{public}s. End calling ams->StartAbilityForResult. ret=%{public}d", __func__, err);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
ErrCode AbilityContextImpl::TerminateAbilityWithResult(const AAFwk::Want &want, int resultCode)
|
||||
{
|
||||
HILOG_DEBUG("%{public}s. Start calling ams->TerminateAbilityWithResult.", __func__);
|
||||
ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->TerminateAbility(token_, resultCode, &want);
|
||||
HILOG_INFO("%{public}s. End calling ams->TerminateAbilityWithResult. ret=%{public}d", __func__, err);
|
||||
return err;
|
||||
}
|
||||
|
||||
void AbilityContextImpl::OnAbilityResult(int requestCode, int resultCode, const AAFwk::Want &resultData)
|
||||
{
|
||||
HILOG_DEBUG("%{public}s. Start calling ams->OnAbilityResult.", __func__);
|
||||
resultCallbacks_[requestCode](resultCode, resultData);
|
||||
resultCallbacks_.erase(requestCode);
|
||||
HILOG_INFO("%{public}s. End calling ams->OnAbilityResult.", __func__);
|
||||
}
|
||||
|
||||
bool AbilityContextImpl::ConnectAbility(const AAFwk::Want &want, const sptr<AAFwk::IAbilityConnection> &conn)
|
||||
{
|
||||
HILOG_DEBUG("%{public}s begin.", __func__);
|
||||
ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want, conn, token_);
|
||||
HILOG_INFO("AbilityContextImpl::ConnectAbility ErrorCode = %{public}d", ret);
|
||||
return ret == ERR_OK;
|
||||
}
|
||||
|
||||
void AbilityContextImpl::DisconnectAbility(const sptr<AAFwk::IAbilityConnection> &conn)
|
||||
{
|
||||
HILOG_DEBUG("%{public}s begin.", __func__);
|
||||
ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(conn);
|
||||
HILOG_INFO("%{public}s end ams->DisconnectAbility, ret=%{public}d", __func__, ret);
|
||||
}
|
||||
|
||||
std::string AbilityContextImpl::GetBundleName() const
|
||||
{
|
||||
return stageContext_ ? stageContext_->GetBundleName() : "";
|
||||
}
|
||||
|
||||
std::shared_ptr<AppExecFwk::ApplicationInfo> AbilityContextImpl::GetApplicationInfo() const
|
||||
{
|
||||
return stageContext_ ? stageContext_->GetApplicationInfo() : nullptr;
|
||||
}
|
||||
|
||||
std::string AbilityContextImpl::GetBundleCodePath() const
|
||||
{
|
||||
return stageContext_ ? stageContext_->GetBundleCodePath() : "";
|
||||
}
|
||||
|
||||
std::shared_ptr<AppExecFwk::HapModuleInfo> AbilityContextImpl::GetHapModuleInfo() const
|
||||
{
|
||||
return stageContext_ ? stageContext_->GetHapModuleInfo() : nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<Global::Resource::ResourceManager> AbilityContextImpl::GetResourceManager() const
|
||||
{
|
||||
return stageContext_ ? stageContext_->GetResourceManager() : nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<Context> AbilityContextImpl::CreateBundleContext(const std::string &bundleName)
|
||||
{
|
||||
return stageContext_ ? stageContext_->CreateBundleContext(bundleName) : nullptr;
|
||||
}
|
||||
|
||||
void AbilityContextImpl::SetAbilityInfo(const std::shared_ptr<AppExecFwk::AbilityInfo> &abilityInfo)
|
||||
{
|
||||
abilityInfo_ = abilityInfo;
|
||||
}
|
||||
|
||||
std::shared_ptr<AppExecFwk::AbilityInfo> AbilityContextImpl::GetAbilityInfo() const
|
||||
{
|
||||
return abilityInfo_;
|
||||
}
|
||||
|
||||
void AbilityContextImpl::SetStageContext(const std::shared_ptr<AbilityRuntime::Context> &stageContext)
|
||||
{
|
||||
stageContext_ = stageContext;
|
||||
}
|
||||
|
||||
void AbilityContextImpl::MinimizeAbility()
|
||||
{
|
||||
HILOG_DEBUG("%{public}s begin.", __func__);
|
||||
ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->MinimizeAbility(token_);
|
||||
if (err != ERR_OK) {
|
||||
HILOG_ERROR("AbilityContext::MinimizeAbility is failed %{public}d", err);
|
||||
}
|
||||
HILOG_INFO("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
ErrCode AbilityContextImpl::TerminateSelf()
|
||||
{
|
||||
HILOG_DEBUG("%{public}s begin.", __func__);
|
||||
AAFwk::Want resultWant;
|
||||
ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->TerminateAbility(token_, -1, &resultWant);
|
||||
if (err != ERR_OK) {
|
||||
HILOG_ERROR("AbilityContextImpl::TerminateSelf is failed %{public}d", err);
|
||||
}
|
||||
HILOG_INFO("%{public}s end.", __func__);
|
||||
return err;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> AbilityContextImpl::GetAbilityToken()
|
||||
{
|
||||
return token_;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
34
frameworks/kits/ability/ability_runtime/src/js_extension_context.cpp
Executable file
34
frameworks/kits/ability/ability_runtime/src/js_extension_context.cpp
Executable file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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 "js_extension_context.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_context_utils.h"
|
||||
#include "js_runtime.h"
|
||||
#include "js_runtime_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
NativeValue* CreateJsExtensionContext(NativeEngine& engine, std::shared_ptr<ExtensionContext> context)
|
||||
{
|
||||
HILOG_INFO("CreateJsExtensionContext begin");
|
||||
NativeValue* objValue = CreateJsBaseContext(engine, context);
|
||||
return objValue;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
@ -31,6 +31,7 @@ config("ability_config") {
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include/bundlemgr",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include/",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include/formmgr",
|
||||
"//foundation/appexecfwk/standard/kits/appkit/native/ability_runtime/app",
|
||||
"//foundation/appexecfwk/standard/kits/appkit/native/app/include",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/fmskit/native/include",
|
||||
"//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include",
|
||||
@ -65,9 +66,13 @@ config("ability_public_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [
|
||||
"${INNERKITS_PATH}/base/include",
|
||||
"//foundation/appexecfwk/standard/kits/appkit/native",
|
||||
"//foundation/appexecfwk/standard/kits/appkit/native/ability_runtime/app",
|
||||
"//foundation/appexecfwk/standard/kits/appkit/native/app/include",
|
||||
"//foundation/appexecfwk/standard/kits/appkit/native/ability_runtime",
|
||||
"${SUBSYSTEM_DIR}/include",
|
||||
"//third_party/libuv/include",
|
||||
"//foundation/appexecfwk/standard/kits/appkit/native/ability_runtime/context",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/base/include/ohos/aafwk/base",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native/include/continuation/remote_register_service",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native/include/continuation/distributed",
|
||||
@ -75,6 +80,7 @@ config("ability_public_config") {
|
||||
"//base/global/resmgr_standard/interfaces/innerkits/include",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native/include/continuation/kits",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/fmskit/native/include",
|
||||
"//foundation/windowmanager/interfaces/innerkits/wm",
|
||||
]
|
||||
}
|
||||
|
||||
@ -83,7 +89,9 @@ ohos_shared_library("abilitykit_native") {
|
||||
"//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/native_rdb",
|
||||
"//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/common",
|
||||
"//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/native_dataability",
|
||||
"//base/global/i18n_standard/frameworks/intl/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"${SUBSYSTEM_APPEXEXFWK_DIR}/interfaces/innerkits/appexecfwk_core/src/appmgr/process_info.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/ability.cpp",
|
||||
@ -91,7 +99,6 @@ ohos_shared_library("abilitykit_native") {
|
||||
"${SUBSYSTEM_DIR}/src/ability_handler.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/ability_impl.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/ability_impl_factory.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/ability_keyevent.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/ability_lifecycle.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/ability_lifecycle_executor.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/ability_loader.cpp",
|
||||
@ -99,7 +106,6 @@ ohos_shared_library("abilitykit_native") {
|
||||
"${SUBSYSTEM_DIR}/src/ability_post_event_timeout.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/ability_process.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/ability_thread.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/ability_touchevent.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/ability_window.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/data_ability_helper.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/data_ability_impl.cpp",
|
||||
@ -107,6 +113,12 @@ ohos_shared_library("abilitykit_native") {
|
||||
"${SUBSYSTEM_DIR}/src/data_ability_operation_builder.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/data_ability_result.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/data_uri_utils.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/extension.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/extension_base.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/extension_impl.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/js_service_extension.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/js_service_extension_context.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/service_extension.cpp",
|
||||
|
||||
#"${SUBSYSTEM_DIR}/src/dummy_data_ability_predicates.cpp",
|
||||
#"${SUBSYSTEM_DIR}/src/dummy_result_set.cpp",
|
||||
@ -114,22 +126,17 @@ ohos_shared_library("abilitykit_native") {
|
||||
"${SUBSYSTEM_DIR}/src/form_js_event_handler.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/form_provider_client.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/mission_information.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/new_ability_impl.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/page_ability_impl.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/service_ability_impl.cpp",
|
||||
"//foundation/aafwk/standard/services/abilitymgr/src/ability_start_setting.cpp",
|
||||
"//foundation/aafwk/standard/services/abilitymgr/src/launch_param.cpp",
|
||||
|
||||
# "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/featureAbility/feature_ability.cpp",
|
||||
# "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/featureAbility/napi_context.cpp",
|
||||
# "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.cpp",
|
||||
# "//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",
|
||||
"${SUBSYSTEM_DIR}/src/continuation/distributed/continuation_scheduler_stub.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/continuation/distributed/distributed_client.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/continuation/distributed/reverse_continuation_scheduler_primary.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/continuation/distributed/reverse_continuation_scheduler_primary_proxy.cpp",
|
||||
@ -146,6 +153,12 @@ ohos_shared_library("abilitykit_native") {
|
||||
"${SUBSYSTEM_DIR}/src/continuation/remote_register_service/continuation_register_manager_proxy.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/continuation/remote_register_service/remote_register_service_proxy.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/continuation/remote_register_service/remote_register_service_stub.cpp",
|
||||
"//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",
|
||||
"//foundation/appexecfwk/standard/kits/appkit/native/ability_runtime/context/context_impl.cpp",
|
||||
"//foundation/appexecfwk/standard/kits/appkit/native/ability_runtime/extension_context.cpp",
|
||||
"//foundation/appexecfwk/standard/kits/appkit/native/ability_runtime/service_extension_context.cpp",
|
||||
"//foundation/appexecfwk/standard/kits/appkit/native/app/src/application_context.cpp",
|
||||
"//foundation/appexecfwk/standard/kits/appkit/native/app/src/context_container.cpp",
|
||||
"//foundation/appexecfwk/standard/kits/appkit/native/app/src/context_deal.cpp",
|
||||
@ -153,16 +166,22 @@ ohos_shared_library("abilitykit_native") {
|
||||
"//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/common/js_utils.cpp",
|
||||
|
||||
#"//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/native_rdb/napi_rdb_predicates.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/ability_runtime/js_ability.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/ability_runtime/js_ability_context.cpp",
|
||||
"//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/native_dataability/napi_data_ability_predicates.cpp",
|
||||
"//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/native_rdb/napi_result_set.cpp",
|
||||
]
|
||||
configs = [ ":ability_config" ]
|
||||
public_configs = [ ":ability_public_config" ]
|
||||
public_configs = [
|
||||
":ability_public_config",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime:ability_context_public_config",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${INNERKITS_PATH}/base:base",
|
||||
"${INNERKITS_PATH}/want:want",
|
||||
"//base/security/permission/interfaces/innerkits/permission_standard/permissionsdk:libpermissionsdk_standard",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime:ability_context_native",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/dataobs_manager:dataobs_manager",
|
||||
"//foundation/ace/napi:ace_napi",
|
||||
@ -171,25 +190,35 @@ ohos_shared_library("abilitykit_native") {
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/task_dispatcher:appkit_dispatcher_td",
|
||||
"//foundation/appexecfwk/standard/kits:app_context",
|
||||
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
"//utils/native/base:utils",
|
||||
"//foundation/multimodalinput/input/frameworks/proxy:libmmi-common",
|
||||
"//foundation/windowmanager/wm:libwmutil",
|
||||
"//third_party/icu/icu4c:shared_icuuc",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"aafwk_standard:ability_context_native",
|
||||
"aafwk_standard:runtime",
|
||||
"appexecfwk_standard:fmskit_native",
|
||||
"bytrace_standard:bytrace_core",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"ipc_js:rpc",
|
||||
"multimodalinput_base:libmmi-client",
|
||||
"native_appdatamgr:native_appdatafwk",
|
||||
"native_appdatamgr:native_dataability",
|
||||
"native_appdatamgr:native_rdb",
|
||||
"utils_base:utils",
|
||||
]
|
||||
|
||||
public_deps = [
|
||||
"//base/global/i18n_standard/frameworks/intl:intl_util",
|
||||
"//base/global/resmgr_standard/frameworks/resmgr:global_resmgr",
|
||||
"//foundation/distributedschedule/dmsfwk/services/dtbschedmgr:distributedschedsvr",
|
||||
"//foundation/graphic/standard:libwmclient",
|
||||
"//foundation/windowmanager/wm:libwm",
|
||||
]
|
||||
|
||||
subsystem_name = "aafwk"
|
||||
|
@ -19,28 +19,32 @@
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
#include "iremote_object.h"
|
||||
|
||||
#include "ability_context.h"
|
||||
#include "ability_continuation_interface.h"
|
||||
#include "ability_event_interface.h"
|
||||
#include "ability_lifecycle_executor.h"
|
||||
#include "ability_lifecycle_interface.h"
|
||||
#include "ability_window.h"
|
||||
#include "configuration.h"
|
||||
#include "context.h"
|
||||
#include "want.h"
|
||||
#include "dummy_component_container.h"
|
||||
#include "pac_map.h"
|
||||
#include "dummy_notification_request.h"
|
||||
#include "continuation_handler.h"
|
||||
#include "continuation_state.h"
|
||||
#include "dummy_ability_package.h"
|
||||
#include "configuration.h"
|
||||
#include "continuation_handler.h"
|
||||
#include "ability_window.h"
|
||||
#include "ability_lifecycle_interface.h"
|
||||
#include "ability_lifecycle_executor.h"
|
||||
#include "ability_continuation_interface.h"
|
||||
|
||||
#include "dummy_component_container.h"
|
||||
#include "dummy_notification_request.h"
|
||||
#include "form_callback_interface.h"
|
||||
#include "form_constants.h"
|
||||
#include "form_death_callback.h"
|
||||
#include "form_provider_info.h"
|
||||
#include "form_info.h"
|
||||
#include "form_provider_info.h"
|
||||
#include "foundation/multimodalinput/input/interfaces/native/innerkits/event/include/key_event.h"
|
||||
#include "foundation/multimodalinput/input/interfaces/native/innerkits/event/include/pointer_event.h"
|
||||
#include "iremote_object.h"
|
||||
#include "pac_map.h"
|
||||
#include "want.h"
|
||||
#include "window_scene.h"
|
||||
#include "../../ability_runtime/include/ability_context.h"
|
||||
|
||||
using Uri = OHOS::Uri;
|
||||
|
||||
@ -50,8 +54,10 @@ class AbsSharedResultSet;
|
||||
class DataAbilityPredicates;
|
||||
class ValuesBucket;
|
||||
} // namespace NativeRdb
|
||||
namespace AbilityRuntime {
|
||||
class Runtime;
|
||||
}
|
||||
class KeyEvent;
|
||||
class TouchEvent;
|
||||
namespace AppExecFwk {
|
||||
class DataAbilityResult;
|
||||
class DataAbilityOperation;
|
||||
@ -71,10 +77,23 @@ class Ability : public IAbilityEvent,
|
||||
public std::enable_shared_from_this<Ability> {
|
||||
public:
|
||||
friend class PageAbilityImpl;
|
||||
friend class NewAbilityImpl;
|
||||
|
||||
static Ability* Create(const std::unique_ptr<AbilityRuntime::Runtime>& runtime);
|
||||
|
||||
Ability() = default;
|
||||
virtual ~Ability() = default;
|
||||
|
||||
/**
|
||||
* @brief Obtains the AbilityContext object of the ability.
|
||||
*
|
||||
* @return Returns the AbilityContext object of the ability.
|
||||
*/
|
||||
inline std::shared_ptr<AbilityRuntime::AbilityContext> GetAbilityContext()
|
||||
{
|
||||
return abilityContext_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Destroys ability.
|
||||
*
|
||||
@ -185,6 +204,8 @@ public:
|
||||
const std::shared_ptr<OHOSApplication> &application, std::shared_ptr<AbilityHandler> &handler,
|
||||
const sptr<IRemoteObject> &token);
|
||||
|
||||
void AttachAbilityContext(const std::shared_ptr<AbilityRuntime::AbilityContext> &abilityContext);
|
||||
|
||||
/**
|
||||
* @brief Called when this ability is started. You must override this function if you want to perform some
|
||||
* initialization operations during ability startup.
|
||||
@ -220,6 +241,22 @@ public:
|
||||
*/
|
||||
virtual void OnInactive();
|
||||
|
||||
/**
|
||||
* @brief Called after instantiating WindowScene.
|
||||
*
|
||||
*
|
||||
* You can override this function to implement your own processing logic.
|
||||
*/
|
||||
virtual void OnSceneCreated();
|
||||
|
||||
/**
|
||||
* @brief Called after ability stoped.
|
||||
*
|
||||
*
|
||||
* You can override this function to implement your own processing logic.
|
||||
*/
|
||||
virtual void onSceneDestroyed();
|
||||
|
||||
/**
|
||||
* @brief Called when this ability enters the <b>STATE_FOREGROUND</b> state.
|
||||
*
|
||||
@ -244,13 +281,12 @@ public:
|
||||
* key-down event of the component returns true. The default implementation of this callback does nothing
|
||||
* and returns false.
|
||||
*
|
||||
* @param keyCode Indicates the code of the key pressed.
|
||||
* @param keyEvent Indicates the key-down event.
|
||||
*
|
||||
* @return Returns true if this event is handled and will not be passed further; returns false if this event
|
||||
* is not handled and should be passed to other handlers.
|
||||
*/
|
||||
virtual bool OnKeyDown(int keyCode, const KeyEvent &keyEvent);
|
||||
virtual void OnKeyDown(const std::shared_ptr<MMI::KeyEvent>& keyEvent);
|
||||
|
||||
/**
|
||||
* @brief Called when a key is released. When any component in the Ability gains focus, the key-up event for
|
||||
@ -258,13 +294,12 @@ public:
|
||||
* key-up event of the component returns true. The default implementation of this callback does nothing and
|
||||
* returns false.
|
||||
*
|
||||
* @param keyCode Indicates the code of the key released.
|
||||
* @param keyEvent Indicates the key-up event.
|
||||
*
|
||||
* @return Returns true if this event is handled and will not be passed further; returns false if this event
|
||||
* is not handled and should be passed to other handlers.
|
||||
*/
|
||||
virtual bool OnKeyUp(int keyCode, const KeyEvent &keyEvent);
|
||||
virtual void OnKeyUp(const std::shared_ptr<MMI::KeyEvent>& keyEvent);
|
||||
|
||||
/**
|
||||
* @brief Called when a touch event is dispatched to this ability. The default implementation of this callback
|
||||
@ -274,7 +309,7 @@ public:
|
||||
*
|
||||
* @return Returns true if the event is handled; returns false otherwise.
|
||||
*/
|
||||
virtual bool OnTouchEvent(const TouchEvent &touchEvent);
|
||||
virtual void OnPointerEvent(std::shared_ptr<MMI::PointerEvent>& pointerEvent);
|
||||
|
||||
/**
|
||||
* @brief Called when this Service ability is connected for the first time.
|
||||
@ -330,18 +365,25 @@ public:
|
||||
virtual void OnTopActiveAbilityChanged(bool topActive);
|
||||
|
||||
/**
|
||||
* @brief Inflates UI controls by using WindowConfig.
|
||||
* @brief Inflates UI controls by using windowOption.
|
||||
*
|
||||
* @param config Indicates the window config defined by the user.
|
||||
* @param windowOption Indicates the window option defined by the user.
|
||||
*/
|
||||
virtual void SetUIContent(const sptr<WindowOption> &config);
|
||||
virtual void SetWindowType(Rosen::WindowType winType);
|
||||
|
||||
/**
|
||||
* @brief Get the window belong to the ability.
|
||||
*
|
||||
* @return Returns a Window object pointer.
|
||||
*/
|
||||
virtual const sptr<Window> GetWindow();
|
||||
virtual const sptr<Rosen::Window> GetWindow();
|
||||
|
||||
/**
|
||||
* @brief get the scene belong to the ability.
|
||||
*
|
||||
* @return Returns a WindowScene object pointer.
|
||||
*/
|
||||
std::shared_ptr<Rosen::WindowScene> GetScene();
|
||||
|
||||
/**
|
||||
* @brief Checks whether the main window of this ability has window focus.
|
||||
@ -350,6 +392,19 @@ public:
|
||||
*/
|
||||
bool HasWindowFocus();
|
||||
|
||||
/**
|
||||
* @description: Obtains api version based on ability.
|
||||
* @return api version.
|
||||
*/
|
||||
int GetTargetVersion();
|
||||
|
||||
/**
|
||||
* @description: Set api version in an ability.
|
||||
* @param targetVersion api version
|
||||
* @return None.
|
||||
*/
|
||||
void SetTargetVersion(int targetVersion);
|
||||
|
||||
/**
|
||||
* @brief Called when a key is lone pressed.
|
||||
*
|
||||
@ -1237,7 +1292,7 @@ public:
|
||||
*/
|
||||
void ExecuteOperation(std::shared_ptr<DataAbilityOperation> &operation,
|
||||
std::vector<std::shared_ptr<DataAbilityResult>> &results, int index);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Save user data of local Ability generated at runtime.
|
||||
*
|
||||
@ -1269,6 +1324,14 @@ public:
|
||||
*/
|
||||
virtual void OnRemoteTerminated() override;
|
||||
|
||||
/**
|
||||
* @brief Set WindowScene listener
|
||||
*
|
||||
* @param listener WindowScene listener
|
||||
* @return None.
|
||||
*/
|
||||
void SetSceneListener(sptr<Rosen::IWindowLifeCycle> listener);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Acquire a form provider remote object.
|
||||
@ -1276,6 +1339,8 @@ protected:
|
||||
*/
|
||||
sptr<IRemoteObject> GetFormRemoteObject();
|
||||
|
||||
const AAFwk::LaunchParam& GetLaunchParam() const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<NativeRdb::DataAbilityPredicates> ParsePredictionArgsReference(
|
||||
std::vector<std::shared_ptr<DataAbilityResult>> &results, std::shared_ptr<DataAbilityOperation> &operation,
|
||||
@ -1290,6 +1355,8 @@ private:
|
||||
bool CheckAssertQueryResult(std::shared_ptr<NativeRdb::AbsSharedResultSet> &queryResult,
|
||||
std::shared_ptr<NativeRdb::ValuesBucket> &&valuesBucket);
|
||||
|
||||
void DispatchLifecycleOnForeground(const Want &want);
|
||||
|
||||
friend class AbilityImpl;
|
||||
bool VerifySupportForContinuation();
|
||||
void HandleCreateAsContinuation(const Want &want);
|
||||
@ -1300,12 +1367,19 @@ private:
|
||||
*/
|
||||
void SetStartAbilitySetting(std::shared_ptr<AbilityStartSetting> setting);
|
||||
|
||||
/**
|
||||
* @brief Set the launch param.
|
||||
*
|
||||
* @param launchParam the launch param.
|
||||
*/
|
||||
void SetLaunchParam(const AAFwk::LaunchParam &launchParam);
|
||||
|
||||
private:
|
||||
std::shared_ptr<ContinuationHandler> continuationHandler_ = nullptr;
|
||||
std::shared_ptr<ContinuationManager> continuationManager_ = nullptr;
|
||||
std::shared_ptr<ContinuationRegisterManager> continuationRegisterManager_ = nullptr;
|
||||
std::shared_ptr<AbilityInfo> abilityInfo_ = nullptr;
|
||||
std::shared_ptr<Context> context_ = nullptr;
|
||||
std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext_ = nullptr;
|
||||
std::shared_ptr<AbilityHandler> handler_ = nullptr;
|
||||
std::shared_ptr<LifeCycle> lifecycle_ = nullptr;
|
||||
std::shared_ptr<AbilityLifecycleExecutor> abilityLifecycleExecutor_ = nullptr;
|
||||
@ -1315,11 +1389,16 @@ private:
|
||||
std::shared_ptr<AAFwk::Want> setWant_ = nullptr;
|
||||
sptr<IRemoteObject> reverseContinuationSchedulerReplica_ = nullptr;
|
||||
std::shared_ptr<AbilityStartSetting> setting_ = nullptr;
|
||||
sptr<Rosen::IWindowLifeCycle> sceneListener_ = nullptr;
|
||||
std::shared_ptr<Rosen::WindowScene> scene_ = nullptr;
|
||||
LaunchParam launchParam_;
|
||||
bool bWindowFocus_ = false;
|
||||
int targetVersion_ = 0;
|
||||
|
||||
static const std::string SYSTEM_UI;
|
||||
static const std::string STATUS_BAR;
|
||||
static const std::string NAVIGATION_BAR;
|
||||
static const std::string KEYGUARD;
|
||||
sptr<IRemoteObject> providerRemoteObject_ = nullptr;
|
||||
// Keep consistent with DMS defines. Used to callback to DMS.
|
||||
static const std::string DMS_SESSION_ID;
|
||||
|
@ -699,16 +699,6 @@ public:
|
||||
public:
|
||||
static int ABILITY_CONTEXT_DEFAULT_REQUEST_CODE;
|
||||
|
||||
protected:
|
||||
sptr<IRemoteObject> GetToken() override;
|
||||
sptr<IRemoteObject> token_;
|
||||
AAFwk::Want resultWant_;
|
||||
int resultCode_ = -1;
|
||||
std::string callingDeviceId_;
|
||||
std::string callingBundleName_;
|
||||
std::string callingAbilityName_;
|
||||
std::map<sptr<AAFwk::IAbilityConnection>, sptr<IRemoteObject>> abilityConnectionMap_;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Get Current Ability Type
|
||||
@ -718,21 +708,15 @@ private:
|
||||
AppExecFwk::AbilityType GetAbilityInfoType();
|
||||
void GetPermissionDes(const std::string &permissionName, std::string &des);
|
||||
|
||||
/**
|
||||
* @brief Check whether it wants to operate a remote ability
|
||||
*
|
||||
* @param want Indicates the Want containing information about the ability to start.
|
||||
*
|
||||
* @return return true if it wamts to operate a remote ability, ohterwise return false.
|
||||
*/
|
||||
bool CheckIfOperateRemote(const Want &want);
|
||||
|
||||
/**
|
||||
* @brief Obtains a distributedSchedService.
|
||||
*
|
||||
* @return Returns an IDistributedSched proxy.
|
||||
*/
|
||||
std::shared_ptr<OHOS::DistributedSchedule::DistributedSchedProxy> GetDistributedSchedServiceProxy();
|
||||
protected:
|
||||
sptr<IRemoteObject> GetToken() override;
|
||||
sptr<IRemoteObject> token_;
|
||||
AAFwk::Want resultWant_;
|
||||
int resultCode_ = -1;
|
||||
std::string callingDeviceId_;
|
||||
std::string callingBundleName_;
|
||||
std::string callingAbilityName_;
|
||||
std::map<sptr<AAFwk::IAbilityConnection>, sptr<IRemoteObject>> abilityConnectionMap_;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
56
frameworks/kits/ability/native/include/ability_impl.h
Normal file → Executable file
56
frameworks/kits/ability/native/include/ability_impl.h
Normal file → Executable file
@ -29,11 +29,7 @@
|
||||
#include "dummy_values_bucket.h"
|
||||
#include "dummy_data_ability_predicates.h"
|
||||
#include "dummy_result_set.h"
|
||||
#include "key_event.h"
|
||||
#include "touch_event.h"
|
||||
#include "ability_keyevent.h"
|
||||
#include "ability_touchevent.h"
|
||||
|
||||
#include "foundation/multimodalinput/input/interfaces/native/innerkits/event/include/i_input_event_consumer.h"
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class Ability;
|
||||
@ -105,25 +101,23 @@ public:
|
||||
|
||||
/**
|
||||
* @brief Execution the KeyDown callback of the ability
|
||||
* @param keyCode Indicates the code of the key pressed.
|
||||
* @param keyEvent Indicates the key-down event.
|
||||
*
|
||||
* @return Returns true if this event is handled and will not be passed further; returns false if this event is
|
||||
* not handled and should be passed to other handlers.
|
||||
*
|
||||
*/
|
||||
virtual bool DoKeyDown(int keyCode, const KeyEvent &keyEvent);
|
||||
virtual void DoKeyDown(const std::shared_ptr<MMI::KeyEvent>& keyEvent);
|
||||
|
||||
/**
|
||||
* @brief Execution the KeyUp callback of the ability
|
||||
* @param keyCode Indicates the code of the key released.
|
||||
* @param keyEvent Indicates the key-up event.
|
||||
*
|
||||
* @return Returns true if this event is handled and will not be passed further; returns false if this event is
|
||||
* not handled and should be passed to other handlers.
|
||||
*
|
||||
*/
|
||||
virtual bool DoKeyUp(int keyCode, const KeyEvent &keyEvent);
|
||||
virtual void DoKeyUp(const std::shared_ptr<MMI::KeyEvent>& keyEvent);
|
||||
|
||||
/**
|
||||
* @brief Called when a touch event is dispatched to this ability. The default implementation of this callback
|
||||
@ -133,7 +127,7 @@ public:
|
||||
* @return Returns true if the event is handled; returns false otherwise.
|
||||
*
|
||||
*/
|
||||
virtual bool DoTouchEvent(const TouchEvent &touchEvent);
|
||||
virtual void DoPointerEvent(std::shared_ptr<MMI::PointerEvent>& pointerEvent);
|
||||
|
||||
/**
|
||||
* @brief Send the result code and data to be returned by this Page ability to the caller.
|
||||
@ -214,8 +208,7 @@ public:
|
||||
*
|
||||
* @return Returns the number of data records updated.
|
||||
*/
|
||||
virtual int Update(const Uri &uri, const NativeRdb::ValuesBucket &value,
|
||||
const NativeRdb::DataAbilityPredicates &predicates);
|
||||
virtual int Update(const Uri &uri, const NativeRdb::ValuesBucket &value, const NativeRdb::DataAbilityPredicates &predicates);
|
||||
|
||||
/**
|
||||
* @brief Deletes one or more data records from the database.
|
||||
@ -327,6 +320,15 @@ public:
|
||||
virtual std::vector<std::shared_ptr<DataAbilityResult>> ExecuteBatch(
|
||||
const std::vector<std::shared_ptr<DataAbilityOperation>> &operations);
|
||||
|
||||
/**
|
||||
* @brief Notify continuation result to ability.
|
||||
*
|
||||
* @param result Continuaton result.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
virtual void NotifyContinuationResult(const int32_t result);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Toggles the lifecycle status of Ability to AAFwk::ABILITY_STATE_INACTIVE. And notifies the application
|
||||
@ -405,6 +407,27 @@ protected:
|
||||
std::shared_ptr<Ability> ability_;
|
||||
|
||||
private:
|
||||
class WindowLifeCycleImpl : public Rosen::IWindowLifeCycle {
|
||||
public:
|
||||
WindowLifeCycleImpl(const sptr<IRemoteObject>& token) : token_(token) {}
|
||||
virtual ~WindowLifeCycleImpl() {}
|
||||
void AfterForeground() override;
|
||||
void AfterBackground() override;
|
||||
void AfterFocused() override;
|
||||
void AfterUnFocused() override;
|
||||
private:
|
||||
sptr<IRemoteObject> token_ = nullptr;
|
||||
};
|
||||
|
||||
class InputEventConsumerImpl : public MMI::IInputEventConsumer {
|
||||
public:
|
||||
explicit InputEventConsumerImpl(const std::shared_ptr<AbilityImpl>& abilityImpl) : abilityImpl_(abilityImpl) {}
|
||||
void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override;
|
||||
void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override;
|
||||
void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override {}
|
||||
private:
|
||||
std::shared_ptr<AbilityImpl> abilityImpl_;
|
||||
};
|
||||
typedef enum {
|
||||
START,
|
||||
INACTIVE,
|
||||
@ -423,15 +446,8 @@ private:
|
||||
/**
|
||||
* @brief Multimodal Events Register.
|
||||
*/
|
||||
void MMIRegister();
|
||||
void WindowEventRegister();
|
||||
|
||||
/**
|
||||
* @brief Multimodal Events UnRegister.
|
||||
*/
|
||||
void MMIUnRegister();
|
||||
|
||||
sptr<AbilityKeyEventHandle> abilityKeyEventHandle_ = nullptr;
|
||||
sptr<AbilityTouchEventHandle> abilityTouchEventHandle_ = nullptr;
|
||||
bool hasSaveData_ = false;
|
||||
bool needSaveDate_ = false;
|
||||
PacMap restoreData_;
|
||||
|
4
frameworks/kits/ability/native/include/ability_impl_factory.h
Normal file → Executable file
4
frameworks/kits/ability/native/include/ability_impl_factory.h
Normal file → Executable file
@ -28,10 +28,12 @@ public:
|
||||
* @brief Create impl object based on abilitytype
|
||||
*
|
||||
* @param type AbilityType:PAGE/SERVICE/PROVIDER
|
||||
* @param targetVersion api version
|
||||
*
|
||||
* @return AbilityImpl object
|
||||
*/
|
||||
std::shared_ptr<AbilityImpl> MakeAbilityImplObject(const std::shared_ptr<AbilityInfo> &info);
|
||||
std::shared_ptr<AbilityImpl> MakeAbilityImplObject(const std::shared_ptr<AbilityInfo> &info,
|
||||
int targetVersion);
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
4
frameworks/kits/ability/native/include/ability_lifecycle_executor.h
Normal file → Executable file
4
frameworks/kits/ability/native/include/ability_lifecycle_executor.h
Normal file → Executable file
@ -28,6 +28,10 @@ public:
|
||||
INACTIVE,
|
||||
INITIAL,
|
||||
UNINITIALIZED,
|
||||
STARTED_NEW,
|
||||
FOREGROUND_NEW,
|
||||
BACKGROUND_NEW,
|
||||
STOPED_NEW
|
||||
};
|
||||
|
||||
/**
|
||||
|
40
frameworks/kits/ability/native/include/ability_loader.h
Normal file → Executable file
40
frameworks/kits/ability/native/include/ability_loader.h
Normal file → Executable file
@ -16,14 +16,17 @@
|
||||
#ifndef FOUNDATION_APPEXECFWK_OHOS_ABILITY_LOADER_H
|
||||
#define FOUNDATION_APPEXECFWK_OHOS_ABILITY_LOADER_H
|
||||
|
||||
#include "ability.h"
|
||||
#include "context.h"
|
||||
#include "extension.h"
|
||||
#include "ohos_application.h"
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include "ability.h"
|
||||
#include "ohos_application.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
using CreateExtension = std::function<AbilityRuntime::Extension *(void)>;
|
||||
using CreateAblity = std::function<Ability *(void)>;
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
using CreateSlice = std::function<AbilitySlice *(void)>;
|
||||
@ -53,6 +56,14 @@ public:
|
||||
*/
|
||||
void RegisterAbility(const std::string &abilityName, const CreateAblity &createFunc);
|
||||
|
||||
/**
|
||||
* @brief Register Extension Info
|
||||
*
|
||||
* @param abilityName Extension classname
|
||||
* @param createFunc Constructor address
|
||||
*/
|
||||
void RegisterExtension(const std::string &abilityName, const CreateExtension &createFunc);
|
||||
|
||||
/**
|
||||
* @brief Get Ability address
|
||||
*
|
||||
@ -62,6 +73,15 @@ public:
|
||||
*/
|
||||
Ability *GetAbilityByName(const std::string &abilityName);
|
||||
|
||||
/**
|
||||
* @brief Get Extension address
|
||||
*
|
||||
* @param abilityName Extension classname
|
||||
*
|
||||
* @return return Ability address
|
||||
*/
|
||||
AbilityRuntime::Extension *GetExtensionByName(const std::string &abilityName);
|
||||
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
void RegisterAbilitySlice(const std::string &sliceName, const CreateSlice &createFunc);
|
||||
AbilitySlice *GetAbilitySliceByName(const std::string &sliceName);
|
||||
@ -75,6 +95,7 @@ private:
|
||||
AbilityLoader &operator=(AbilityLoader &&) = delete;
|
||||
|
||||
std::unordered_map<std::string, CreateAblity> abilities_;
|
||||
std::unordered_map<std::string, CreateExtension> extensions_;
|
||||
};
|
||||
/**
|
||||
* @brief Registers the class name of an {@link Ability} child class.
|
||||
@ -91,6 +112,21 @@ private:
|
||||
#className, []()->Ability * { return new (std::nothrow) className; }); \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Registers the class name of an {@link Extension} child class.
|
||||
*
|
||||
* After implementing your own {@link Extension} class, you should call this function so that the extension management
|
||||
* framework can create <b>Extension</b> instances when loading your <b>Extension</b> class.
|
||||
*
|
||||
* @param className Indicates the {@link Extension} class name to register.
|
||||
*/
|
||||
#define REGISTER_EX(className) \
|
||||
__attribute__((constructor)) void RegisterEX##className() \
|
||||
{ \
|
||||
AbilityLoader::GetInstance().RegisterExtension( \
|
||||
#className, []()->AbilityRuntime::Extension * { return new (std::nothrow) className; }); \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Registers the class name of an {@link AbilitySlice} child class.
|
||||
*
|
||||
|
22
frameworks/kits/ability/native/include/ability_local_record.h
Normal file → Executable file
22
frameworks/kits/ability/native/include/ability_local_record.h
Normal file → Executable file
@ -111,13 +111,27 @@ public:
|
||||
*/
|
||||
void SetAbilityThread(const sptr<AbilityThread> &abilityThread);
|
||||
|
||||
/**
|
||||
* @description: Obtains api version based on ability record.
|
||||
* @return api version.
|
||||
*/
|
||||
int GetTargetVersion();
|
||||
|
||||
/**
|
||||
* @description: Set api version in an ability record.
|
||||
* @param targetVersion api version
|
||||
* @return None.
|
||||
*/
|
||||
void SetTargetVersion(int targetVersion);
|
||||
|
||||
private:
|
||||
std::shared_ptr<AbilityInfo> abilityInfo_;
|
||||
std::shared_ptr<AbilityInfo> abilityInfo_ = nullptr;
|
||||
sptr<IRemoteObject> token_;
|
||||
std::shared_ptr<EventRunner> runner_;
|
||||
std::shared_ptr<EventHandler> handler_;
|
||||
std::shared_ptr<AbilityImpl> abilityImpl_; // store abilityImpl
|
||||
std::shared_ptr<EventRunner> runner_ = nullptr;
|
||||
std::shared_ptr<EventHandler> handler_ = nullptr;
|
||||
std::shared_ptr<AbilityImpl> abilityImpl_ = nullptr; // store abilityImpl
|
||||
sptr<AbilityThread> abilityThread_;
|
||||
int targetVersion_ = 0;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
63
frameworks/kits/ability/native/include/ability_runtime/js_ability.h
Executable file
63
frameworks/kits/ability/native/include/ability_runtime/js_ability.h
Executable file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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 ABILITY_RUNTIME_JS_ABILITY_H
|
||||
#define ABILITY_RUNTIME_JS_ABILITY_H
|
||||
|
||||
#include "ability.h"
|
||||
|
||||
class NativeReference;
|
||||
class NativeValue;
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
class JsRuntime;
|
||||
|
||||
using Ability = AppExecFwk::Ability;
|
||||
using AbilityHandler = AppExecFwk::AbilityHandler;
|
||||
using AbilityInfo = AppExecFwk::AbilityInfo;
|
||||
using OHOSApplication = AppExecFwk::OHOSApplication;
|
||||
using Want = AppExecFwk::Want;
|
||||
|
||||
class JsAbility : public Ability {
|
||||
public:
|
||||
static Ability* Create(const std::unique_ptr<Runtime>& runtime);
|
||||
|
||||
JsAbility(JsRuntime& jsRuntime);
|
||||
~JsAbility() override;
|
||||
|
||||
void Init(const std::shared_ptr<AbilityInfo> &abilityInfo, const std::shared_ptr<OHOSApplication> &application,
|
||||
std::shared_ptr<AbilityHandler> &handler, const sptr<IRemoteObject> &token) override;
|
||||
|
||||
void OnStart(const Want &want) override;
|
||||
void OnStop() override;
|
||||
|
||||
void OnSceneCreated() override;
|
||||
void onSceneDestroyed() override;
|
||||
|
||||
void OnForeground(const Want &want) override;
|
||||
void OnBackground() override;
|
||||
|
||||
void OnAbilityResult(int requestCode, int resultCode, const Want &resultData) override;
|
||||
|
||||
private:
|
||||
void CallObjectMethod(const char* name, NativeValue* const* argv = nullptr, size_t argc = 0);
|
||||
|
||||
JsRuntime& jsRuntime_;
|
||||
std::unique_ptr<NativeReference> jsAbilityObj_;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // ABILITY_RUNTIME_JS_ABILITY_H
|
69
frameworks/kits/ability/native/include/ability_runtime/js_ability_context.h
Executable file
69
frameworks/kits/ability/native/include/ability_runtime/js_ability_context.h
Executable file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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 ABILITY_RUNTIME_JS_ABILITY_CONTEXT_H
|
||||
#define ABILITY_RUNTIME_JS_ABILITY_CONTEXT_H
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
|
||||
#include "foundation/aafwk/standard/frameworks/kits/ability/ability_runtime/include/ability_context.h"
|
||||
|
||||
#include "ability_connect_callback_stub.h"
|
||||
|
||||
class NativeEngine;
|
||||
class NativeObject;
|
||||
class NativeReference;
|
||||
class NativeValue;
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
NativeValue* CreateJsAbilityContext(NativeEngine& engine, std::shared_ptr<AbilityContext> context);
|
||||
|
||||
class JSAbilityConnection : public AAFwk::AbilityConnectionStub {
|
||||
public:
|
||||
explicit JSAbilityConnection(NativeEngine* engine);
|
||||
~JSAbilityConnection();
|
||||
void OnAbilityConnectDone(
|
||||
const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode) override;
|
||||
void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override;
|
||||
void SetJsConnectionObject(NativeValue* jsConnectionObject);
|
||||
void CallJsFailed();
|
||||
private:
|
||||
NativeValue* ConvertElement(const AppExecFwk::ElementName &element);
|
||||
std::unique_ptr<NativeEngine> engine_;
|
||||
std::unique_ptr<NativeReference> jsConnectionObject_ = nullptr;
|
||||
};
|
||||
|
||||
struct ConnectionKey {
|
||||
AAFwk::Want want;
|
||||
int64_t id;
|
||||
};
|
||||
|
||||
struct KeyCompare {
|
||||
bool operator()(const ConnectionKey &key1, const ConnectionKey &key2) const
|
||||
{
|
||||
if (key1.id < key2.id) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
static std::map<ConnectionKey, sptr<JSAbilityConnection>, KeyCompare> abilityConnects_;
|
||||
static int64_t g_serialNumber = 0;
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // ABILITY_RUNTIME_JS_ABILITY_CONTEXT_H
|
8
frameworks/kits/ability/native/include/ability_state.h
Normal file → Executable file
8
frameworks/kits/ability/native/include/ability_state.h
Normal file → Executable file
@ -79,6 +79,14 @@ typedef enum {
|
||||
STATE_ACTIVATING,
|
||||
STATE_MOVING_BACKGROUND,
|
||||
STATE_TERMINATING,
|
||||
|
||||
/**
|
||||
* State for ability (api > 7).
|
||||
*/
|
||||
STATE_FOREGROUND_NEW,
|
||||
STATE_BACKGROUND_NEW,
|
||||
STATE_FOREGROUNDING_NEW,
|
||||
STATE_BACKGROUNDING_NEW,
|
||||
} State;
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
79
frameworks/kits/ability/native/include/ability_thread.h
Normal file → Executable file
79
frameworks/kits/ability/native/include/ability_thread.h
Normal file → Executable file
@ -23,6 +23,7 @@
|
||||
#include "ability.h"
|
||||
#include "ability_local_record.h"
|
||||
#include "context.h"
|
||||
#include "extension_impl.h"
|
||||
#include "ohos_application.h"
|
||||
#include "ability_scheduler_stub.h"
|
||||
#include "pac_map.h"
|
||||
@ -55,17 +56,21 @@ public:
|
||||
* @param application Indicates the main process.
|
||||
* @param abilityRecord Indicates the abilityRecord.
|
||||
* @param mainRunner The runner which main_thread holds.
|
||||
* @param appContext the AbilityRuntime context
|
||||
*/
|
||||
static void AbilityThreadMain(std::shared_ptr<OHOSApplication> &application,
|
||||
const std::shared_ptr<AbilityLocalRecord> &abilityRecord, const std::shared_ptr<EventRunner> &mainRunner);
|
||||
const std::shared_ptr<AbilityLocalRecord> &abilityRecord, const std::shared_ptr<EventRunner> &mainRunner,
|
||||
const std::shared_ptr<AbilityRuntime::Context> &appContext);
|
||||
|
||||
/**
|
||||
* @description: Attach The ability thread to the main process.
|
||||
* @param application Indicates the main process.
|
||||
* @param abilityRecord Indicates the abilityRecord.
|
||||
* @param appContext the AbilityRuntime context
|
||||
*/
|
||||
static void AbilityThreadMain(
|
||||
std::shared_ptr<OHOSApplication> &application, const std::shared_ptr<AbilityLocalRecord> &abilityRecord);
|
||||
std::shared_ptr<OHOSApplication> &application, const std::shared_ptr<AbilityLocalRecord> &abilityRecord,
|
||||
const std::shared_ptr<AbilityRuntime::Context> &appContext);
|
||||
|
||||
/**
|
||||
* @description: Attach The ability thread to the main process.
|
||||
@ -74,15 +79,37 @@ public:
|
||||
* @param mainRunner The runner which main_thread holds.
|
||||
*/
|
||||
void Attach(std::shared_ptr<OHOSApplication> &application, const std::shared_ptr<AbilityLocalRecord> &abilityRecord,
|
||||
const std::shared_ptr<EventRunner> &mainRunner, const std::shared_ptr<AbilityRuntime::Context> &appContext);
|
||||
|
||||
/**
|
||||
* @description: Attach The ability thread to the main process.
|
||||
* @param application Indicates the main process.
|
||||
* @param abilityRecord Indicates the abilityRecord.
|
||||
* @param mainRunner The runner which main_thread holds.
|
||||
*/
|
||||
void AttachExtension(std::shared_ptr<OHOSApplication> &application,
|
||||
const std::shared_ptr<AbilityLocalRecord> &abilityRecord,
|
||||
const std::shared_ptr<EventRunner> &mainRunner);
|
||||
|
||||
/**
|
||||
* @description: Attach The ability thread to the main process.
|
||||
* @param application Indicates the main process.
|
||||
* @param abilityRecord Indicates the abilityRecord.
|
||||
* @param mainRunner The runner which main_thread holds.
|
||||
*/
|
||||
void AttachExtension(std::shared_ptr<OHOSApplication> &application,
|
||||
const std::shared_ptr<AbilityLocalRecord> &abilityRecord);
|
||||
|
||||
void InitExtensionFlag(const std::shared_ptr<AbilityLocalRecord> &abilityRecord);
|
||||
|
||||
/**
|
||||
* @description: Attach The ability thread to the main process.
|
||||
* @param application Indicates the main process.
|
||||
* @param abilityRecord Indicates the abilityRecord.
|
||||
*/
|
||||
void Attach(
|
||||
std::shared_ptr<OHOSApplication> &application, const std::shared_ptr<AbilityLocalRecord> &abilityRecord);
|
||||
std::shared_ptr<OHOSApplication> &application, const std::shared_ptr<AbilityLocalRecord> &abilityRecord,
|
||||
const std::shared_ptr<AbilityRuntime::Context> &appContext);
|
||||
|
||||
/**
|
||||
* @description: Provide operating system AbilityTransaction information to the observer
|
||||
@ -275,6 +302,13 @@ public:
|
||||
*/
|
||||
void NotifyTopActiveAbilityChanged(bool flag);
|
||||
|
||||
/**
|
||||
* @brief notify this ability continuation result.
|
||||
*
|
||||
* @param result: Continuation result
|
||||
*/
|
||||
void NotifyContinuationResult(const int32_t result);
|
||||
|
||||
/**
|
||||
* @brief Converts the given uri that refer to the Data ability into a normalized URI. A normalized URI can be used
|
||||
* across devices, persisted, backed up, and restored. It can refer to the same item in the Data ability even if the
|
||||
@ -388,6 +422,13 @@ private:
|
||||
*/
|
||||
void HandleAbilityTransaction(const Want &want, const LifeCycleStateInfo &lifeCycleStateInfo);
|
||||
|
||||
/**
|
||||
* @description: Handle the life cycle of Extension.
|
||||
* @param want Indicates the structure containing lifecycle information about the extension.
|
||||
* @param lifeCycleStateInfo Indicates the lifeCycleStateInfo.
|
||||
*/
|
||||
void HandleExtensionTransaction(const Want &want, const LifeCycleStateInfo &lifeCycleStateInfo);
|
||||
|
||||
/**
|
||||
* @description: Handle the current connection of Ability.
|
||||
* @param want Indicates the structure containing connection information about the ability.
|
||||
@ -413,6 +454,31 @@ private:
|
||||
*/
|
||||
void HandleCommandAbility(const Want &want, bool restart, int startId);
|
||||
|
||||
/**
|
||||
* @description: Handle the current connection of Extension.
|
||||
* @param want Indicates the structure containing connection information about the extension.
|
||||
*/
|
||||
void HandleConnectExtension(const Want &want);
|
||||
|
||||
/**
|
||||
* @description: Handle the current disconnection of Extension.
|
||||
*/
|
||||
void HandleDisconnectExtension(const Want &want);
|
||||
|
||||
/**
|
||||
* @brief Handle the current commadn of Extension.
|
||||
*
|
||||
* @param want The Want object to command to.
|
||||
*
|
||||
* * @param restart Indicates the startup mode. The value true indicates that Service is restarted after being
|
||||
* destroyed, and the value false indicates a normal startup.
|
||||
*
|
||||
* @param startId Indicates the number of times the Service extension has been started. The startId is incremented
|
||||
* by 1 every time the extension is started. For example, if the extension has been started for six times, the
|
||||
* value of startId is 6.
|
||||
*/
|
||||
void HandleCommandExtension(const Want &want, bool restart, int startId);
|
||||
|
||||
/**
|
||||
* @description: Handle the restoreAbility state.
|
||||
* @param state Indicates save ability state used to dispatchRestoreAbilityState.
|
||||
@ -424,11 +490,18 @@ private:
|
||||
*/
|
||||
void HandleUpdateConfiguration(const Configuration &config);
|
||||
|
||||
std::shared_ptr<AbilityRuntime::AbilityContext> BuildAbilityContext(
|
||||
const std::shared_ptr<AbilityInfo> &abilityInfo, const std::shared_ptr<OHOSApplication> &application,
|
||||
const sptr<IRemoteObject> &token, const std::shared_ptr<AbilityRuntime::Context> &stageContext);
|
||||
|
||||
std::shared_ptr<AbilityImpl> abilityImpl_ = nullptr;
|
||||
sptr<IRemoteObject> token_;
|
||||
std::shared_ptr<Ability> currentAbility_ = nullptr;
|
||||
std::shared_ptr<AbilityRuntime::ExtensionImpl> extensionImpl_ = nullptr;
|
||||
std::shared_ptr<AbilityRuntime::Extension> currentExtension_ = nullptr;
|
||||
std::shared_ptr<AbilityHandler> abilityHandler_ = nullptr;
|
||||
std::shared_ptr<EventRunner> runner_ = nullptr;
|
||||
bool isExtension_ = false;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
32
frameworks/kits/ability/native/include/ability_window.h
Normal file → Executable file
32
frameworks/kits/ability/native/include/ability_window.h
Normal file → Executable file
@ -16,10 +16,12 @@
|
||||
#ifndef OHOS_ABILITY_WINDOW_H
|
||||
#define OHOS_ABILITY_WINDOW_H
|
||||
|
||||
#include "window_manager.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "nocopyable.h"
|
||||
#include "window.h"
|
||||
#include "window_option.h"
|
||||
#include "window_scene.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
@ -43,27 +45,7 @@ public:
|
||||
*
|
||||
* @param config Indicates window config.
|
||||
*/
|
||||
bool SetWindowConfig(const sptr<WindowOption> &config);
|
||||
|
||||
/**
|
||||
* @brief Called when the KeyEvent sent.
|
||||
*
|
||||
* @param KeyEvent the key event.
|
||||
*
|
||||
* @return Returns true if the listener has processed the event; returns false otherwise.
|
||||
*
|
||||
*/
|
||||
bool OnKeyEvent(KeyEvent event);
|
||||
|
||||
/**
|
||||
* @brief Called back when the Back key is pressed.
|
||||
*
|
||||
* @param ability The ability receive the event.
|
||||
*
|
||||
* @return Returns true if the listener has processed the event; returns false otherwise.
|
||||
*
|
||||
*/
|
||||
bool OnBackPressed(std::shared_ptr<IAbilityEvent> &ability);
|
||||
bool SetWindowType(Rosen::WindowType winType);
|
||||
|
||||
/**
|
||||
* @brief Called when this ability is started.
|
||||
@ -106,12 +88,12 @@ public:
|
||||
*
|
||||
* @return Returns a Window object pointer.
|
||||
*/
|
||||
const sptr<Window> GetWindow();
|
||||
const sptr<Rosen::Window> GetWindow();
|
||||
|
||||
private:
|
||||
std::shared_ptr<AbilityHandler> handler_ = nullptr;
|
||||
std::weak_ptr<IAbilityEvent> ability_;
|
||||
sptr<Window> windowNew_;
|
||||
std::shared_ptr<Rosen::WindowScene> windowScene_;
|
||||
bool isWindowAttached = false;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef 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
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_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
|
1
frameworks/kits/ability/native/include/continuation/distributed/continuation_handler.h
Normal file → Executable file
1
frameworks/kits/ability/native/include/continuation/distributed/continuation_handler.h
Normal file → Executable file
@ -20,7 +20,6 @@
|
||||
|
||||
#include "distribute_schedule_handler_interface.h"
|
||||
#include "continuation_manager.h"
|
||||
#include "distributed_client.h"
|
||||
#include "reverse_continuation_scheduler_primary_proxy.h"
|
||||
#include "reverse_continuation_scheduler_replica_proxy.h"
|
||||
#include "reverse_continuation_scheduler_primary_stub.h"
|
||||
|
14
frameworks/kits/ability/native/include/continuation/distributed/continuation_manager.h
Normal file → Executable file
14
frameworks/kits/ability/native/include/continuation/distributed/continuation_manager.h
Normal file → Executable file
@ -19,7 +19,6 @@
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include "continuation_state.h"
|
||||
#include "continuation_scheduler.h"
|
||||
#include "ability_info.h"
|
||||
#include "event_handler.h"
|
||||
#include "iremote_object.h"
|
||||
@ -63,7 +62,7 @@ public:
|
||||
|
||||
bool NotifyRemoteTerminated();
|
||||
|
||||
bool UnregisterAbilityTokenIfNeed();
|
||||
void ChangeProcessStateToInit();
|
||||
|
||||
private:
|
||||
enum ProgressState { INITIAL, WAITING_SCHEDULE, IN_PROGRESS };
|
||||
@ -82,14 +81,6 @@ private:
|
||||
|
||||
bool CheckAbilityToken();
|
||||
|
||||
bool UnregisterAbilityToken(const sptr<IRemoteObject> &token);
|
||||
|
||||
bool RegisterAbilityTokenIfNeed(const sptr<IRemoteObject> &token);
|
||||
|
||||
bool RegisterAbilityToken(const sptr<IRemoteObject> &token);
|
||||
|
||||
void InitDistSchedulerHost();
|
||||
|
||||
void CheckDmsInterfaceResult(int result, const std::string &interfaceName);
|
||||
|
||||
bool DoScheduleStartContinuation();
|
||||
@ -100,19 +91,16 @@ private:
|
||||
|
||||
bool DoRestoreFromRemote(const WantParams &restoreData);
|
||||
|
||||
sptr<ContinuationScheduler> distSchedulerHost_ = nullptr;
|
||||
sptr<IRemoteObject> continueToken_ = nullptr;
|
||||
std::weak_ptr<Ability> ability_;
|
||||
std::weak_ptr<AbilityInfo> abilityInfo_;
|
||||
ProgressState progressState_ = ProgressState::INITIAL;
|
||||
bool reversible_ = false;
|
||||
bool tokenRegistered_ = false;
|
||||
ContinuationState continuationState_ = ContinuationState::LOCAL_RUNNING;
|
||||
std::string originalDeviceId_;
|
||||
std::weak_ptr<ContinuationHandler> continuationHandler_;
|
||||
std::shared_ptr<EventHandler> mainHandler_ = nullptr;
|
||||
std::mutex lock_;
|
||||
std::mutex lockForRegist_;
|
||||
|
||||
static const int TIMEOUT_MS_WAIT_DMS_SCHEDULE_START_CONTINUATION;
|
||||
static const int TIMEOUT_MS_WAIT_DMS_NOTIFY_CONTINUATION_COMPLETE;
|
||||
|
@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_AAFWK_STANDARD_FRAMEWORKS_ABILITY_INCLUDE_DISTRIBUTED_CONTINUATION_SCHEDULE_FOR_DMS_H
|
||||
#define FOUNDATION_AAFWK_STANDARD_FRAMEWORKS_ABILITY_INCLUDE_DISTRIBUTED_CONTINUATION_SCHEDULE_FOR_DMS_H
|
||||
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
#include <memory>
|
||||
|
||||
#include "distribute_schedule_handler_interface.h"
|
||||
#include "continuation_scheduler_stub.h"
|
||||
#include "event_handler.h"
|
||||
#include "iremote_object.h"
|
||||
#include "iremote_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class ContinuationScheduler : public ContinuationSchedulerStub {
|
||||
public:
|
||||
ContinuationScheduler(
|
||||
std::weak_ptr<IDistributeScheduleHandler> &callback, std::shared_ptr<EventHandler> &mainHandler);
|
||||
~ContinuationScheduler() = default;
|
||||
void ReceiveReplicaScheduler(const sptr<IRemoteObject> &remoteReplica);
|
||||
void ScheduleCompleteContinuation(int result);
|
||||
|
||||
private:
|
||||
void HandleReceiveReplicaScheduler(const sptr<IRemoteObject> &remoteReplica);
|
||||
void HandleCompleteContinuation(int result);
|
||||
bool GetCallback(std::shared_ptr<IDistributeScheduleHandler> &callback);
|
||||
|
||||
static std::mutex mutex_;
|
||||
std::shared_ptr<EventHandler> mainHandler_;
|
||||
std::weak_ptr<IDistributeScheduleHandler> callback_;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
#endif // FOUNDATION_AAFWK_STANDARD_FRAMEWORKS_ABILITY_INCLUDE_DISTRIBUTED_CONTINUATION_SCHEDULE_FOR_DMS_H
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_AAFWK_STANDARD_FRAMEWORKS_ABILITY_INCLUDE_DISTRIBUTED_CONTINUATION_SCHEDULE_FOR_DMS_INTERFACE_H
|
||||
#define FOUNDATION_AAFWK_STANDARD_FRAMEWORKS_ABILITY_INCLUDE_DISTRIBUTED_CONTINUATION_SCHEDULE_FOR_DMS_INTERFACE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "iremote_broker.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class IContinuationScheduler : public OHOS::IRemoteBroker {
|
||||
public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.abilityshell.ContinuationScheduler");
|
||||
/**
|
||||
* @brief Receive a scheduler which could handle reverse continuation.
|
||||
* Remote side will pass an scheduler before continuation completed if this continuation is
|
||||
* reversible. This method will not be called if this continuation is not reversible.
|
||||
* @param remoteReplica A scheduler to handle reverse continuation request.
|
||||
*/
|
||||
virtual void ReceiveReplicaScheduler(const sptr<IRemoteObject> &remoteReplica) = 0;
|
||||
|
||||
/**
|
||||
* @brief Called by DMS when the continuing device finished.
|
||||
* @param result Zero indicate the continuation is success, otherwise integer less than zero.
|
||||
*/
|
||||
virtual void ScheduleCompleteContinuation(int result) = 0;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
#endif // FOUNDATION_AAFWK_STANDARD_FRAMEWORKS_ABILITY_INCLUDE_DISTRIBUTED_CONTINUATION_SCHEDULE_FOR_DMS_INTERFACE_H
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_AAFWK_STANDARD_FRAMEWORKS_ABILITY_INCLUDE_DISTRIBUTED_CONTINUATION_SCHEDULE_FOR_DMS_STUB_H
|
||||
#define FOUNDATION_AAFWK_STANDARD_FRAMEWORKS_ABILITY_INCLUDE_DISTRIBUTED_CONTINUATION_SCHEDULE_FOR_DMS_STUB_H
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "continuation_scheduler_interface.h"
|
||||
#include "iremote_stub.h"
|
||||
#include "iremote_object.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class ContinuationSchedulerStub : public IRemoteStub<IContinuationScheduler> {
|
||||
public:
|
||||
ContinuationSchedulerStub();
|
||||
~ContinuationSchedulerStub();
|
||||
virtual int OnRemoteRequest(
|
||||
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
|
||||
private:
|
||||
int ReceiveReplicaSchedulerInner(MessageParcel &data, MessageParcel &reply);
|
||||
int ScheduleCompleteContinuationInner(MessageParcel &data, MessageParcel &reply);
|
||||
using RequestFuncType = int (ContinuationSchedulerStub::*)(MessageParcel &data, MessageParcel &reply);
|
||||
std::map<uint32_t, RequestFuncType> requestFuncMap_;
|
||||
|
||||
enum {
|
||||
SCHEDULE_COMPLETE_CONTINUATION = 1,
|
||||
RECEIVE_REPLICA_SCHEDULER = 2,
|
||||
};
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
#endif // FOUNDATION_AAFWK_STANDARD_FRAMEWORKS_ABILITY_INCLUDE_DISTRIBUTED_CONTINUATION_SCHEDULE_FOR_DMS_STUB_H
|
8
frameworks/kits/ability/native/include/continuation/distributed/distributed_client.h
Normal file → Executable file
8
frameworks/kits/ability/native/include/continuation/distributed/distributed_client.h
Normal file → Executable file
@ -39,16 +39,8 @@ public:
|
||||
virtual ~DistributedClient();
|
||||
static std::shared_ptr<DistributedClient> GetInstance();
|
||||
ErrCode Connect();
|
||||
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);
|
||||
ErrCode UnregisterAbilityToken(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &appThread);
|
||||
|
||||
private:
|
||||
static std::mutex mutex_;
|
||||
|
127
frameworks/kits/ability/native/include/extension.h
Executable file
127
frameworks/kits/ability/native/include/extension.h
Executable file
@ -0,0 +1,127 @@
|
||||
/*
|
||||
* 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 FOUNDATION_ABILITYRUNTIME_OHOS_EXTENSION_H
|
||||
#define FOUNDATION_ABILITYRUNTIME_OHOS_EXTENSION_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "iremote_object.h"
|
||||
#include "want.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
struct AbilityInfo;
|
||||
class OHOSApplication;
|
||||
class AbilityHandler;
|
||||
class AbilityLocalRecord;
|
||||
}
|
||||
namespace AbilityRuntime {
|
||||
using Want = OHOS::AAFwk::Want;
|
||||
/**
|
||||
* @brief The Extension component to schedule task with no pages.
|
||||
*/
|
||||
class Extension : public std::enable_shared_from_this<Extension> {
|
||||
public:
|
||||
Extension() = default;
|
||||
virtual ~Extension() = default;
|
||||
|
||||
/**
|
||||
* @brief Init the extension.
|
||||
*
|
||||
* @param record the extension record.
|
||||
* @param application the application info.
|
||||
* @param handler the extension handler.
|
||||
* @param token the remote token.
|
||||
*/
|
||||
virtual void Init(const std::shared_ptr<AppExecFwk::AbilityLocalRecord> &record,
|
||||
const std::shared_ptr<AppExecFwk::OHOSApplication> &application,
|
||||
std::shared_ptr<AppExecFwk::AbilityHandler> &handler,
|
||||
const sptr<IRemoteObject> &token);
|
||||
|
||||
/**
|
||||
* @brief Sets the first want object.
|
||||
*
|
||||
* @param Want information of other ability or extension.
|
||||
*/
|
||||
void SetLaunchWant(const AAFwk::Want &want);
|
||||
|
||||
/**
|
||||
* @brief Sets the last want object.
|
||||
*
|
||||
* @param Want information of other ability or extension.
|
||||
*/
|
||||
void SetLastRequestWant(const AAFwk::Want &want);
|
||||
|
||||
/**
|
||||
* @brief Called when this extension is started. You must override this function if you want to perform some
|
||||
* initialization operations during extension startup.
|
||||
*
|
||||
* This function can be called only once in the entire lifecycle of an extension.
|
||||
* @param Want Indicates the {@link Want} structure containing startup information about the extension.
|
||||
*/
|
||||
virtual void OnStart(const AAFwk::Want &want);
|
||||
|
||||
/**
|
||||
* @brief Called when this Service extension is connected for the first time.
|
||||
*
|
||||
* You can override this function to implement your own processing logic.
|
||||
*
|
||||
* @param want Indicates the {@link Want} structure containing connection information about the Service extension.
|
||||
* @return Returns a pointer to the <b>sid</b> of the connected Service extension.
|
||||
*/
|
||||
virtual sptr<IRemoteObject> OnConnect(const AAFwk::Want &want);
|
||||
|
||||
/**
|
||||
* @brief Called when all abilities connected to this Service extension are disconnected.
|
||||
*
|
||||
* You can override this function to implement your own processing logic.
|
||||
*
|
||||
*/
|
||||
virtual void OnDisconnect(const AAFwk::Want &want);
|
||||
|
||||
/**
|
||||
* @brief Called back when Service is started.
|
||||
* This method can be called only by Service. You can use the StartAbility(ohos.aafwk.content.Want) method to start
|
||||
* Service. Then the system calls back the current method to use the transferred want parameter to execute its own
|
||||
* logic.
|
||||
*
|
||||
* @param want Indicates the want of Service to start.
|
||||
* @param restart Indicates the startup mode. The value true indicates that Service is restarted after being
|
||||
* destroyed, and the value false indicates a normal startup.
|
||||
* @param startId Indicates the number of times the Service extension has been started. The startId is
|
||||
* incremented by 1 every time the extension is started. For example, if the extension has been started
|
||||
* for six times, the value of startId is 6.
|
||||
*/
|
||||
virtual void OnCommand(const AAFwk::Want &want, bool restart, int startId);
|
||||
|
||||
/**
|
||||
* @brief Called when this extension enters the <b>STATE_STOP</b> state.
|
||||
*
|
||||
* The extension in the <b>STATE_STOP</b> is being destroyed.
|
||||
* You can override this function to implement your own processing logic.
|
||||
*/
|
||||
virtual void OnStop();
|
||||
|
||||
std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo_ = nullptr;
|
||||
private:
|
||||
std::shared_ptr<AppExecFwk::AbilityHandler> handler_ = nullptr;
|
||||
std::shared_ptr<AppExecFwk::OHOSApplication> application_ = nullptr;
|
||||
std::shared_ptr<AAFwk::Want> launchWant_ = nullptr;
|
||||
std::shared_ptr<AAFwk::Want> lastRequestWant_ = nullptr;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // FOUNDATION_ABILITYRUNTIME_OHOS_EXTENSION_H
|
81
frameworks/kits/ability/native/include/extension_base.h
Executable file
81
frameworks/kits/ability/native/include/extension_base.h
Executable file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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 FOUNDATION_ABILITYRUNTIME_OHOS_EXTENSION_BASE_H
|
||||
#define FOUNDATION_ABILITYRUNTIME_OHOS_EXTENSION_BASE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "extension.h"
|
||||
#include "iremote_object.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class OHOSApplication;
|
||||
class AbilityHandler;
|
||||
class AbilityLocalRecord;
|
||||
}
|
||||
namespace AbilityRuntime {
|
||||
using namespace OHOS::AppExecFwk;
|
||||
class ExtensionContext;
|
||||
/**
|
||||
* @brief The ExtensionBase class for all extensions.
|
||||
*/
|
||||
template<class C = ExtensionContext>
|
||||
class ExtensionBase : public Extension,
|
||||
public std::enable_shared_from_this<ExtensionBase<C>> {
|
||||
public:
|
||||
ExtensionBase() = default;
|
||||
virtual ~ExtensionBase() = default;
|
||||
|
||||
/**
|
||||
* @brief Init the extension.
|
||||
*
|
||||
* @param record the extension record.
|
||||
* @param application the application info.
|
||||
* @param handler the extension handler.
|
||||
* @param token the remote token.
|
||||
*/
|
||||
virtual void Init(const std::shared_ptr<AbilityLocalRecord> &record,
|
||||
const std::shared_ptr<OHOSApplication> &application,
|
||||
std::shared_ptr<AbilityHandler> &handler,
|
||||
const sptr<IRemoteObject> &token) override;
|
||||
|
||||
/**
|
||||
* @brief Create and init context.
|
||||
*
|
||||
* @param record the extension record.
|
||||
* @param application the application info.
|
||||
* @param handler the extension handler.
|
||||
* @param token the remote token.
|
||||
* @return The created context.
|
||||
*/
|
||||
virtual std::shared_ptr<C> CreateAndInitContext(const std::shared_ptr<AbilityLocalRecord> &record,
|
||||
const std::shared_ptr<OHOSApplication> &application,
|
||||
std::shared_ptr<AbilityHandler> &handler,
|
||||
const sptr<IRemoteObject> &token);
|
||||
|
||||
/**
|
||||
* @brief Get context.
|
||||
*
|
||||
* @return The context object.
|
||||
*/
|
||||
virtual std::shared_ptr<C> GetContext();
|
||||
private:
|
||||
std::shared_ptr<C> context_ = nullptr;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // FOUNDATION_ABILITYRUNTIME_OHOS_EXTENSION_BASE_H
|
114
frameworks/kits/ability/native/include/extension_impl.h
Executable file
114
frameworks/kits/ability/native/include/extension_impl.h
Executable file
@ -0,0 +1,114 @@
|
||||
/*
|
||||
* 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 FOUNDATION_ABILITYRUNTIME_OHOS_EXTENSION_IMPL_H
|
||||
#define FOUNDATION_ABILITYRUNTIME_OHOS_EXTENSION_IMPL_H
|
||||
|
||||
#include "extension.h"
|
||||
|
||||
namespace OHOS {
|
||||
class IRemoteObject;
|
||||
namespace AAFwk {
|
||||
class Want;
|
||||
}
|
||||
namespace AppExecFwk {
|
||||
struct AbilityInfo;
|
||||
class OHOSApplication;
|
||||
class AbilityHandler;
|
||||
class AbilityLocalRecord;
|
||||
}
|
||||
namespace AbilityRuntime {
|
||||
/**
|
||||
* @brief Responsible for managing and scheduling the life cycle of extension.
|
||||
*/
|
||||
class ExtensionImpl : public std::enable_shared_from_this<ExtensionImpl> {
|
||||
public:
|
||||
ExtensionImpl() = default;
|
||||
virtual ~ExtensionImpl() = default;
|
||||
|
||||
/**
|
||||
* @brief Init the object.
|
||||
*
|
||||
* @param application the application info.
|
||||
* @param record the extension record.
|
||||
* @param extension the extension object.
|
||||
* @param handler the extension handler.
|
||||
* @param token the remote token.
|
||||
*/
|
||||
void Init(std::shared_ptr<AppExecFwk::OHOSApplication> &application,
|
||||
const std::shared_ptr<AppExecFwk::AbilityLocalRecord> &record,
|
||||
std::shared_ptr<Extension> &extension,
|
||||
std::shared_ptr<AppExecFwk::AbilityHandler> &handler, const sptr<IRemoteObject> &token);
|
||||
|
||||
/**
|
||||
* @brief Connect the Extension. and Calling information back to Extension.
|
||||
*
|
||||
* @param want The Want object to connect to.
|
||||
* @param targetState The terget state.
|
||||
*
|
||||
*/
|
||||
virtual void HandleExtensionTransaction(const Want &want, const AAFwk::LifeCycleStateInfo &targetState);
|
||||
|
||||
/**
|
||||
* @brief Connect the Extension. and Calling information back to Extension.
|
||||
*
|
||||
* @param want The Want object to connect to.
|
||||
*
|
||||
*/
|
||||
sptr<IRemoteObject> ConnectExtension(const Want &want);
|
||||
|
||||
/**
|
||||
* @brief Disconnects the connected object.
|
||||
*
|
||||
* @param want The Want object to disconnect to.
|
||||
*/
|
||||
void DisconnectExtension(const Want &want);
|
||||
|
||||
/**
|
||||
* @brief Command the Extension. and Calling information back to Extension.
|
||||
*
|
||||
* @param want The Want object to command to.
|
||||
*
|
||||
* * @param restart Indicates the startup mode. The value true indicates that Service is restarted after being
|
||||
* destroyed, and the value false indicates a normal startup.
|
||||
*
|
||||
* @param startId Indicates the number of times the Service Extension has been started. The startId is incremented
|
||||
* by 1 every time the Extension is started. For example, if the Extension has been started for six times, the value
|
||||
* of startId is 6.
|
||||
*/
|
||||
void CommandExtension(const Want &want, bool restart, int startId);
|
||||
protected:
|
||||
/**
|
||||
* @brief Toggles the lifecycle status of Extension to AAFwk::ABILITY_STATE_INACTIVE. And notifies the application
|
||||
* that it belongs to of the lifecycle status.
|
||||
*
|
||||
* @param want The Want object to switch the life cycle.
|
||||
*/
|
||||
void Start(const Want &want);
|
||||
|
||||
/**
|
||||
* @brief Toggles the lifecycle status of Extension to AAFwk::ABILITY_STATE_INITIAL. And notifies the application
|
||||
* that it belongs to of the lifecycle status.
|
||||
*
|
||||
*/
|
||||
void Stop();
|
||||
|
||||
int lifecycleState_ = AAFwk::ABILITY_STATE_INITIAL;
|
||||
sptr<IRemoteObject> token_;
|
||||
std::shared_ptr<Extension> extension_;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // FOUNDATION_ABILITYRUNTIME_OHOS_EXTENSION_IMPL_H
|
115
frameworks/kits/ability/native/include/js_service_extension.h
Executable file
115
frameworks/kits/ability/native/include/js_service_extension.h
Executable file
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* 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 FOUNDATION_ABILITYRUNTIME_OHOS_JS_SERVICE_EXTENSION_H
|
||||
#define FOUNDATION_ABILITYRUNTIME_OHOS_JS_SERVICE_EXTENSION_H
|
||||
|
||||
#include "service_extension.h"
|
||||
|
||||
class NativeReference;
|
||||
class NativeValue;
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
class ServiceExtension;
|
||||
class JsRuntime;
|
||||
/**
|
||||
* @brief Basic service components.
|
||||
*/
|
||||
class JsServiceExtension : public ServiceExtension,
|
||||
public std::enable_shared_from_this<JsServiceExtension> {
|
||||
public:
|
||||
JsServiceExtension(JsRuntime& jsRuntime);
|
||||
virtual ~JsServiceExtension() override;
|
||||
|
||||
/**
|
||||
* @brief Create JsServiceExtension.
|
||||
*
|
||||
* @param runtime The runtime.
|
||||
* @return The JsServiceExtension instance.
|
||||
*/
|
||||
static JsServiceExtension* Create(const std::unique_ptr<Runtime>& runtime);
|
||||
|
||||
/**
|
||||
* @brief Init the extension.
|
||||
*
|
||||
* @param record the extension record.
|
||||
* @param application the application info.
|
||||
* @param handler the extension handler.
|
||||
* @param token the remote token.
|
||||
*/
|
||||
virtual void Init(const std::shared_ptr<AppExecFwk::AbilityLocalRecord> &record,
|
||||
const std::shared_ptr<AppExecFwk::OHOSApplication> &application,
|
||||
std::shared_ptr<AppExecFwk::AbilityHandler> &handler,
|
||||
const sptr<IRemoteObject> &token) override;
|
||||
|
||||
/**
|
||||
* @brief Called when this extension is started. You must override this function if you want to perform some
|
||||
* initialization operations during extension startup.
|
||||
*
|
||||
* This function can be called only once in the entire lifecycle of an extension.
|
||||
* @param Want Indicates the {@link Want} structure containing startup information about the extension.
|
||||
*/
|
||||
virtual void OnStart(const AAFwk::Want &want) override;
|
||||
|
||||
/**
|
||||
* @brief Called when this Service extension is connected for the first time.
|
||||
*
|
||||
* You can override this function to implement your own processing logic.
|
||||
*
|
||||
* @param want Indicates the {@link Want} structure containing connection information about the Service extension.
|
||||
* @return Returns a pointer to the <b>sid</b> of the connected Service extension.
|
||||
*/
|
||||
virtual sptr<IRemoteObject> OnConnect(const AAFwk::Want &want) override;
|
||||
|
||||
/**
|
||||
* @brief Called when all abilities connected to this Service extension are disconnected.
|
||||
*
|
||||
* You can override this function to implement your own processing logic.
|
||||
*
|
||||
*/
|
||||
virtual void OnDisconnect(const AAFwk::Want &want) override;
|
||||
|
||||
/**
|
||||
* @brief Called back when Service is started.
|
||||
* This method can be called only by Service. You can use the StartAbility(ohos.aafwk.content.Want) method to start
|
||||
* Service. Then the system calls back the current method to use the transferred want parameter to execute its own
|
||||
* logic.
|
||||
*
|
||||
* @param want Indicates the want of Service to start.
|
||||
* @param restart Indicates the startup mode. The value true indicates that Service is restarted after being
|
||||
* destroyed, and the value false indicates a normal startup.
|
||||
* @param startId Indicates the number of times the Service extension has been started. The startId is incremented
|
||||
* by 1 every time the extension is started. For example, if the extension has been started for six times, the
|
||||
* value of startId is 6.
|
||||
*/
|
||||
virtual void OnCommand(const AAFwk::Want &want, bool restart, int startId) override;
|
||||
|
||||
/**
|
||||
* @brief Called when this extension enters the <b>STATE_STOP</b> state.
|
||||
*
|
||||
* The extension in the <b>STATE_STOP</b> is being destroyed.
|
||||
* You can override this function to implement your own processing logic.
|
||||
*/
|
||||
virtual void OnStop() override;
|
||||
private:
|
||||
NativeValue* CallObjectMethod(const char* name, NativeValue* const* argv = nullptr, size_t argc = 0);
|
||||
|
||||
JsRuntime& jsRuntime_;
|
||||
std::unique_ptr<NativeReference> jsObj_;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // FOUNDATION_ABILITYRUNTIME_OHOS_JS_SERVICE_EXTENSION_H
|
64
frameworks/kits/ability/native/include/js_service_extension_context.h
Executable file
64
frameworks/kits/ability/native/include/js_service_extension_context.h
Executable file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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 ABILITY_RUNTIME_JS_SERVICE_EXTENSION_CONTEXT_H
|
||||
#define ABILITY_RUNTIME_JS_SERVICE_EXTENSION_CONTEXT_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "service_extension_context.h"
|
||||
#include "ability_connect_callback_stub.h"
|
||||
|
||||
class NativeEngine;
|
||||
class NativeValue;
|
||||
class NativeReference;
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
NativeValue* CreateJsServiceExtensionContext(NativeEngine& engine, std::shared_ptr<ServiceExtensionContext> context);
|
||||
|
||||
class JSServiceExtensionConnection : public AAFwk::AbilityConnectionStub {
|
||||
public:
|
||||
void OnAbilityConnectDone(
|
||||
const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode) override;
|
||||
void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override;
|
||||
void SetNativeEngine(NativeEngine* engine);
|
||||
void SetJsConnectionObject(NativeValue* jsConnectionObject);
|
||||
void CallJsFailed();
|
||||
private:
|
||||
NativeEngine* engine_ = nullptr;
|
||||
std::unique_ptr<NativeReference> jsConnectionObject_ = nullptr;
|
||||
};
|
||||
|
||||
struct ConnecttionKey {
|
||||
AAFwk::Want want;
|
||||
int64_t id;
|
||||
};
|
||||
|
||||
struct key_compare {
|
||||
bool operator()(const ConnecttionKey &key1, const ConnecttionKey &key2) const
|
||||
{
|
||||
if (key1.id < key2.id) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
static std::map<ConnecttionKey, sptr<JSServiceExtensionConnection>, key_compare> connects_;
|
||||
static int64_t serialNumber_ = 0;
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // ABILITY_RUNTIME_JS_SERVICE_EXTENSION_CONTEXT_H
|
63
frameworks/kits/ability/native/include/new_ability_impl.h
Executable file
63
frameworks/kits/ability/native/include/new_ability_impl.h
Executable file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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 FOUNDATION_APPEXECFWK_OHOS_NEW_ABILITY_IMPL_H
|
||||
#define FOUNDATION_APPEXECFWK_OHOS_NEW_ABILITY_IMPL_H
|
||||
|
||||
#include "ability_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class Ability;
|
||||
class AbilityHandler;
|
||||
class AbilityLocalRecord;
|
||||
class AbilityImpl;
|
||||
class NewAbilityImpl final : public AbilityImpl {
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor.
|
||||
*
|
||||
*/
|
||||
NewAbilityImpl() = default;
|
||||
|
||||
/**
|
||||
* @brief Destructor.
|
||||
*
|
||||
*/
|
||||
~NewAbilityImpl() = default;
|
||||
|
||||
/**
|
||||
* @brief Handling the life cycle switching of NewAbility.
|
||||
*
|
||||
* @param want Indicates the structure containing information about the ability.
|
||||
* @param targetState The life cycle state to switch to.
|
||||
*
|
||||
*/
|
||||
void HandleAbilityTransaction(const Want &want, const AAFwk::LifeCycleStateInfo &targetState);
|
||||
|
||||
/**
|
||||
* @brief Handling the life cycle switching of NewAbility in switch.
|
||||
*
|
||||
* @param want Indicates the structure containing information about the ability.
|
||||
* @param targetState The life cycle state to switch to.
|
||||
*
|
||||
* @return return true if the lifecycle transaction successfully, otherwise return false.
|
||||
*
|
||||
*/
|
||||
bool AbilityTransaction(const Want &want, const AAFwk::LifeCycleStateInfo &targetState);
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
#endif // FOUNDATION_APPEXECFWK_OHOS_NEW_ABILITY_IMPL_H
|
10
frameworks/kits/ability/native/include/page_ability_impl.h
Normal file → Executable file
10
frameworks/kits/ability/native/include/page_ability_impl.h
Normal file → Executable file
@ -45,7 +45,7 @@ public:
|
||||
* @param targetState The life cycle state to switch to.
|
||||
*
|
||||
*/
|
||||
void HandleAbilityTransaction(const Want &want, const AAFwk::LifeCycleStateInfo &targetState);
|
||||
void HandleAbilityTransaction(const Want &want, const AAFwk::LifeCycleStateInfo &targetState) override;
|
||||
|
||||
/**
|
||||
* @brief Handling the life cycle switching of PageAbility in switch.
|
||||
@ -60,25 +60,23 @@ public:
|
||||
|
||||
/**
|
||||
* @brief Execution the KeyDown callback of the ability
|
||||
* @param keyCode Indicates the code of the key pressed.
|
||||
* @param keyEvent Indicates the key-down event.
|
||||
*
|
||||
* @return Returns true if this event is handled and will not be passed further; returns false if this event is
|
||||
* not handled and should be passed to other handlers.
|
||||
*
|
||||
*/
|
||||
bool DoKeyDown(int keyCode, const KeyEvent &keyEvent);
|
||||
void DoKeyDown(const std::shared_ptr<MMI::KeyEvent>& keyEvent) override;
|
||||
|
||||
/**
|
||||
* @brief Execution the KeyUp callback of the ability
|
||||
* @param keyCode Indicates the code of the key released.
|
||||
* @param keyEvent Indicates the key-up event.
|
||||
*
|
||||
* @return Returns true if this event is handled and will not be passed further; returns false if this event is
|
||||
* not handled and should be passed to other handlers.
|
||||
*
|
||||
*/
|
||||
bool DoKeyUp(int keyCode, const KeyEvent &keyEvent);
|
||||
void DoKeyUp(const std::shared_ptr<MMI::KeyEvent>& keyEvent) override;
|
||||
|
||||
/**
|
||||
* @brief Called when a touch event is dispatched to this ability. The default implementation of this callback
|
||||
@ -88,7 +86,7 @@ public:
|
||||
* @return Returns true if the event is handled; returns false otherwise.
|
||||
*
|
||||
*/
|
||||
bool DoTouchEvent(const TouchEvent &touchEvent);
|
||||
void DoPointerEvent(std::shared_ptr<MMI::PointerEvent>& pointerEvent) override;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
72
frameworks/kits/ability/native/include/service_extension.h
Executable file
72
frameworks/kits/ability/native/include/service_extension.h
Executable file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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 FOUNDATION_ABILITYRUNTIME_OHOS_SERVICE_EXTENSION_H
|
||||
#define FOUNDATION_ABILITYRUNTIME_OHOS_SERVICE_EXTENSION_H
|
||||
|
||||
#include "extension_base.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
class ServiceExtensionContext;
|
||||
class Runtime;
|
||||
/**
|
||||
* @brief Basic service components.
|
||||
*/
|
||||
class ServiceExtension : public ExtensionBase<ServiceExtensionContext>,
|
||||
public std::enable_shared_from_this<ServiceExtension> {
|
||||
public:
|
||||
ServiceExtension() = default;
|
||||
virtual ~ServiceExtension() = default;
|
||||
|
||||
/**
|
||||
* @brief Create and init context.
|
||||
*
|
||||
* @param record the extension record.
|
||||
* @param application the application info.
|
||||
* @param handler the extension handler.
|
||||
* @param token the remote token.
|
||||
* @return The created context.
|
||||
*/
|
||||
virtual std::shared_ptr<ServiceExtensionContext> CreateAndInitContext(
|
||||
const std::shared_ptr<AbilityLocalRecord> &record,
|
||||
const std::shared_ptr<OHOSApplication> &application,
|
||||
std::shared_ptr<AbilityHandler> &handler,
|
||||
const sptr<IRemoteObject> &token) override;
|
||||
|
||||
/**
|
||||
* @brief Init the extension.
|
||||
*
|
||||
* @param record the extension record.
|
||||
* @param application the application info.
|
||||
* @param handler the extension handler.
|
||||
* @param token the remote token.
|
||||
*/
|
||||
virtual void Init(const std::shared_ptr<AbilityLocalRecord> &record,
|
||||
const std::shared_ptr<OHOSApplication> &application,
|
||||
std::shared_ptr<AbilityHandler> &handler,
|
||||
const sptr<IRemoteObject> &token) override;
|
||||
|
||||
/**
|
||||
* @brief Create Extension.
|
||||
*
|
||||
* @param runtime The runtime.
|
||||
* @return The ServiceExtension instance.
|
||||
*/
|
||||
static ServiceExtension* Create(const std::unique_ptr<Runtime>& runtime);
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // FOUNDATION_ABILITYRUNTIME_OHOS_SERVICE_EXTENSION_H
|
@ -19,57 +19,78 @@
|
||||
#include <thread>
|
||||
|
||||
#include "ability_loader.h"
|
||||
#include "ability_post_event_timeout.h"
|
||||
#include "ability_runtime/js_ability.h"
|
||||
#include "abs_shared_result_set.h"
|
||||
#include "app_log_wrapper.h"
|
||||
#include "display_type.h"
|
||||
#include "form_provider_client.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "system_ability_definition.h"
|
||||
#include "task_handler_client.h"
|
||||
#include "ohos_application.h"
|
||||
#include "bytrace.h"
|
||||
#include "context_impl.h"
|
||||
#include "continuation_manager.h"
|
||||
#include "continuation_register_manager.h"
|
||||
#include "continuation_register_manager_proxy.h"
|
||||
#include "data_ability_operation.h"
|
||||
#include "data_ability_predicates.h"
|
||||
#include "data_ability_result.h"
|
||||
#include "data_uri_utils.h"
|
||||
#include "display_type.h"
|
||||
#include "form_host_client.h"
|
||||
#include "form_mgr.h"
|
||||
#include "form_provider_client.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "key_event.h"
|
||||
#include "ohos_application.h"
|
||||
#include "permission/permission.h"
|
||||
#include "permission/permission_kit.h"
|
||||
#include "reverse_continuation_scheduler_primary.h"
|
||||
#include "reverse_continuation_scheduler_replica.h"
|
||||
#include "reverse_continuation_scheduler_replica_handler_interface.h"
|
||||
#include "runtime.h"
|
||||
#include "string_wrapper.h"
|
||||
#include "permission/permission.h"
|
||||
#include "permission/permission_kit.h"
|
||||
#include "abs_shared_result_set.h"
|
||||
#include "data_ability_predicates.h"
|
||||
#include "values_bucket.h"
|
||||
#include "ability_post_event_timeout.h"
|
||||
#include "data_ability_result.h"
|
||||
#include "data_ability_operation.h"
|
||||
#include "data_uri_utils.h"
|
||||
#include "key_event.h"
|
||||
#include "system_ability_definition.h"
|
||||
#include "task_handler_client.h"
|
||||
#include "touch_event.h"
|
||||
#include "form_host_client.h"
|
||||
#include "form_mgr.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "values_bucket.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
using PermissionKit = OHOS::Security::Permission::PermissionKit;
|
||||
using PermissionState = OHOS::Security::Permission::PermissionState;
|
||||
|
||||
REGISTER_AA(Ability)
|
||||
// REGISTER_AA(Ability)
|
||||
const std::string Ability::SYSTEM_UI("com.ohos.systemui");
|
||||
const std::string Ability::STATUS_BAR("com.ohos.systemui.statusbar.MainAbility");
|
||||
const std::string Ability::NAVIGATION_BAR("com.ohos.systemui.navigationbar.MainAbility");
|
||||
const std::string Ability::KEYGUARD("com.ohos.screenlock");
|
||||
const std::string DEVICE_MANAGER_BUNDLE_NAME = "com.ohos.devicemanagerui";
|
||||
const std::string DEVICE_MANAGER_NAME = "com.ohos.devicemanagerui.MainAbility";
|
||||
const std::string Ability::DMS_SESSION_ID("sessionId");
|
||||
const std::string Ability::DMS_ORIGIN_DEVICE_ID("deviceId");
|
||||
const int Ability::DEFAULT_DMS_SESSION_ID(0);
|
||||
const std::string PERMISSION_REQUIRE_FORM = "ohos.permission.REQUIRE_FORM";
|
||||
const int TARGET_VERSION_THRESHOLDS = 8;
|
||||
|
||||
static std::mutex formLock;
|
||||
|
||||
constexpr int64_t SEC_TO_MILLISEC = 1000;
|
||||
constexpr int64_t MILLISEC_TO_NANOSEC = 1000000;
|
||||
|
||||
Ability* Ability::Create(const std::unique_ptr<AbilityRuntime::Runtime>& runtime)
|
||||
{
|
||||
if (!runtime) {
|
||||
return new Ability;
|
||||
}
|
||||
|
||||
switch (runtime->GetLanguage()) {
|
||||
case AbilityRuntime::Runtime::Language::JS:
|
||||
return AbilityRuntime::JsAbility::Create(runtime);
|
||||
|
||||
default:
|
||||
return new Ability();
|
||||
}
|
||||
}
|
||||
|
||||
void Ability::Init(const std::shared_ptr<AbilityInfo> &abilityInfo, const std::shared_ptr<OHOSApplication> &application,
|
||||
std::shared_ptr<AbilityHandler> &handler, const sptr<IRemoteObject> &token)
|
||||
{
|
||||
@ -80,11 +101,14 @@ void Ability::Init(const std::shared_ptr<AbilityInfo> &abilityInfo, const std::s
|
||||
|
||||
// page ability only.
|
||||
if (abilityInfo_->type == AbilityType::PAGE) {
|
||||
abilityWindow_ = std::make_shared<AbilityWindow>();
|
||||
if (abilityWindow_ != nullptr) {
|
||||
APP_LOGI("%{public}s begin abilityWindow_->Init", __func__);
|
||||
abilityWindow_->Init(handler_, shared_from_this());
|
||||
APP_LOGI("%{public}s end abilityWindow_->Init", __func__);
|
||||
if (targetVersion_ < TARGET_VERSION_THRESHOLDS) {
|
||||
abilityWindow_ = std::make_shared<AbilityWindow>();
|
||||
|
||||
if (abilityWindow_ != nullptr) {
|
||||
APP_LOGI("%{public}s begin abilityWindow_->Init", __func__);
|
||||
abilityWindow_->Init(handler_, shared_from_this());
|
||||
APP_LOGI("%{public}s end abilityWindow_->Init", __func__);
|
||||
}
|
||||
}
|
||||
continuationManager_ = std::make_shared<ContinuationManager>();
|
||||
std::weak_ptr<Ability> ability = shared_from_this();
|
||||
@ -116,6 +140,11 @@ void Ability::Init(const std::shared_ptr<AbilityInfo> &abilityInfo, const std::s
|
||||
APP_LOGI("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
void Ability::AttachAbilityContext(const std::shared_ptr<AbilityRuntime::AbilityContext> &abilityContext)
|
||||
{
|
||||
abilityContext_ = abilityContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains a resource manager.
|
||||
*
|
||||
@ -133,6 +162,7 @@ std::shared_ptr<Global::Resource::ResourceManager> Ability::GetResourceManager()
|
||||
*/
|
||||
void Ability::OnStart(const Want &want)
|
||||
{
|
||||
BYTRACE(BYTRACE_TAG_ABILITY_MANAGER);
|
||||
APP_LOGI("%{public}s begin.", __func__);
|
||||
if (abilityInfo_ == nullptr) {
|
||||
APP_LOGE("Ability::OnStart falied abilityInfo_ is nullptr.");
|
||||
@ -140,53 +170,43 @@ void Ability::OnStart(const Want &want)
|
||||
}
|
||||
|
||||
if (abilityInfo_->type == AppExecFwk::AbilityType::PAGE) {
|
||||
sptr<WindowOption> config = WindowOption::Get();
|
||||
|
||||
OHOS::WindowType winType = OHOS::WindowType::WINDOW_TYPE_NORMAL;
|
||||
Rosen::WindowType winType = Rosen::WindowType::WINDOW_TYPE_APP_MAIN_WINDOW;
|
||||
if (abilityInfo_->bundleName == SYSTEM_UI) {
|
||||
if (abilityInfo_->name == STATUS_BAR) {
|
||||
winType = OHOS::WindowType::WINDOW_TYPE_STATUS_BAR;
|
||||
winType = Rosen::WindowType::WINDOW_TYPE_STATUS_BAR;
|
||||
}
|
||||
if (abilityInfo_->name == NAVIGATION_BAR) {
|
||||
winType = OHOS::WindowType::WINDOW_TYPE_NAVI_BAR;
|
||||
winType = Rosen::WindowType::WINDOW_TYPE_NAVIGATION_BAR;
|
||||
}
|
||||
}
|
||||
if (abilityInfo_->bundleName == OHOS_REQUEST_PERMISSION_BUNDLENAME &&
|
||||
abilityInfo_->name == OHOS_REQUEST_PERMISSION_ABILITY_NAME) {
|
||||
winType = OHOS::WindowType::WINDOW_TYPE_ALARM_SCREEN;
|
||||
winType = Rosen::WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW;
|
||||
}
|
||||
|
||||
if (abilityInfo_->bundleName == KEYGUARD) {
|
||||
winType = Rosen::WindowType::WINDOW_TYPE_DRAGGING_EFFECT;
|
||||
}
|
||||
|
||||
if (abilityInfo_->bundleName == DEVICE_MANAGER_BUNDLE_NAME && abilityInfo_->name == DEVICE_MANAGER_NAME) {
|
||||
winType = OHOS::WindowType::WINDOW_TYPE_ALARM_SCREEN;
|
||||
winType = Rosen::WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW;
|
||||
}
|
||||
|
||||
config->SetWindowType(winType);
|
||||
APP_LOGI("Ability::OnStart bundleName:%{public}s abilityName:%{public}s: set config.type = %{public}d",
|
||||
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);
|
||||
SetWindowType(winType);
|
||||
|
||||
if (abilityWindow_ != nullptr) {
|
||||
APP_LOGI("%{public}s begin abilityWindow_->OnPostAbilityStart.", __func__);
|
||||
abilityWindow_->OnPostAbilityStart();
|
||||
if (abilityWindow_->GetWindow()) {
|
||||
auto windowId = abilityWindow_->GetWindow()->GetID();
|
||||
APP_LOGI("Ability::OnStart: add window info = %{public}d", windowId);
|
||||
OHOS::AAFwk::AbilityManagerClient::GetInstance()->AddWindowInfo(AbilityContext::GetToken(), windowId);
|
||||
}
|
||||
// TODO::GetID is not exist
|
||||
// if (abilityWindow_->GetWindow()) {
|
||||
// auto windowId = abilityWindow_->GetWindow()->GetID();
|
||||
// APP_LOGI("Ability::OnStart: add window info = %{public}d", windowId);
|
||||
// OHOS::AAFwk::AbilityManagerClient::GetInstance()->AddWindowInfo(AbilityContext::GetToken(), windowId);
|
||||
// }
|
||||
APP_LOGI("%{public}s end abilityWindow_->OnPostAbilityStart.", __func__);
|
||||
}
|
||||
}
|
||||
@ -196,7 +216,11 @@ void Ability::OnStart(const Want &want)
|
||||
APP_LOGE("Ability::OnStart error. abilityLifecycleExecutor_ == nullptr.");
|
||||
return;
|
||||
}
|
||||
abilityLifecycleExecutor_->DispatchLifecycleState(AbilityLifecycleExecutor::LifecycleState::INACTIVE);
|
||||
if (targetVersion_ < TARGET_VERSION_THRESHOLDS) {
|
||||
abilityLifecycleExecutor_->DispatchLifecycleState(AbilityLifecycleExecutor::LifecycleState::INACTIVE);
|
||||
} else {
|
||||
abilityLifecycleExecutor_->DispatchLifecycleState(AbilityLifecycleExecutor::LifecycleState::STARTED_NEW);
|
||||
}
|
||||
|
||||
if (lifecycle_ == nullptr) {
|
||||
APP_LOGE("Ability::OnStart error. lifecycle_ == nullptr.");
|
||||
@ -214,13 +238,12 @@ void Ability::OnStart(const Want &want)
|
||||
*/
|
||||
void Ability::OnStop()
|
||||
{
|
||||
BYTRACE(BYTRACE_TAG_ABILITY_MANAGER);
|
||||
APP_LOGI("%{public}s begin.", __func__);
|
||||
if (continuationManager_ != nullptr) {
|
||||
continuationManager_->UnregisterAbilityTokenIfNeed();
|
||||
} else {
|
||||
APP_LOGE("%{public}s continuationManager_ is nullptr.", __func__);
|
||||
if (scene_ != nullptr) {
|
||||
scene_ = nullptr;
|
||||
onSceneDestroyed();
|
||||
}
|
||||
|
||||
if (abilityWindow_ != nullptr && abilityInfo_->type == AppExecFwk::AbilityType::PAGE) {
|
||||
APP_LOGI("%{public}s begin abilityWindow_->OnPostAbilityStop.", __func__);
|
||||
abilityWindow_->OnPostAbilityStop();
|
||||
@ -250,6 +273,7 @@ void Ability::OnStop()
|
||||
*/
|
||||
void Ability::OnActive()
|
||||
{
|
||||
BYTRACE(BYTRACE_TAG_ABILITY_MANAGER);
|
||||
APP_LOGI("%{public}s begin.", __func__);
|
||||
if (abilityWindow_ != nullptr) {
|
||||
APP_LOGI("%{public}s begin abilityWindow_->OnPostAbilityActive.", __func__);
|
||||
@ -279,6 +303,7 @@ void Ability::OnActive()
|
||||
*/
|
||||
void Ability::OnInactive()
|
||||
{
|
||||
BYTRACE(BYTRACE_TAG_ABILITY_MANAGER);
|
||||
APP_LOGI("%{public}s begin.", __func__);
|
||||
if (abilityWindow_ != nullptr && abilityInfo_->type == AppExecFwk::AbilityType::PAGE) {
|
||||
APP_LOGI("%{public}s begin abilityWindow_->OnPostAbilityInactive.", __func__);
|
||||
@ -300,6 +325,28 @@ void Ability::OnInactive()
|
||||
APP_LOGI("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called after instantiating WindowScene.
|
||||
*
|
||||
*
|
||||
* You can override this function to implement your own processing logic.
|
||||
*/
|
||||
void Ability::OnSceneCreated()
|
||||
{
|
||||
APP_LOGI("%{public}s called.", __func__);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called after ability stoped.
|
||||
*
|
||||
*
|
||||
* You can override this function to implement your own processing logic.
|
||||
*/
|
||||
void Ability::onSceneDestroyed()
|
||||
{
|
||||
APP_LOGI("%{public}s called.", __func__);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called when this ability enters the <b>STATE_FOREGROUND</b> state.
|
||||
*
|
||||
@ -309,24 +356,37 @@ void Ability::OnInactive()
|
||||
*/
|
||||
void Ability::OnForeground(const Want &want)
|
||||
{
|
||||
BYTRACE(BYTRACE_TAG_ABILITY_MANAGER);
|
||||
APP_LOGI("%{public}s begin.", __func__);
|
||||
if (abilityWindow_ != nullptr) {
|
||||
APP_LOGI("%{public}s begin abilityWindow_->OnPostAbilityForeground.", __func__);
|
||||
abilityWindow_->OnPostAbilityForeground();
|
||||
APP_LOGI("%{public}s end abilityWindow_->OnPostAbilityForeground.", __func__);
|
||||
if (targetVersion_ >= TARGET_VERSION_THRESHOLDS) {
|
||||
if (scene_ == nullptr) {
|
||||
if ((abilityContext_ == nullptr) || (sceneListener_ == nullptr)) {
|
||||
APP_LOGE("Ability::OnForeground error. abilityContext_ or sceneListener_ is nullptr!");
|
||||
return;
|
||||
}
|
||||
scene_ = std::make_shared<Rosen::WindowScene>();
|
||||
if (scene_ == nullptr) {
|
||||
APP_LOGE("%{public}s error. failed to create WindowScene instance!", __func__);
|
||||
return;
|
||||
}
|
||||
Rosen::WMError ret = scene_->Init(Rosen::WindowScene::DEFAULT_DISPLAY_ID, abilityContext_, sceneListener_);
|
||||
if (ret != Rosen::WMError::WM_OK) {
|
||||
APP_LOGE("%{public}s error. failed to init window scene!", __func__);
|
||||
return;
|
||||
}
|
||||
OnSceneCreated();
|
||||
}
|
||||
APP_LOGI("%{public}s begin scene_->GoForeground.", __func__);
|
||||
scene_->GoForeground();
|
||||
APP_LOGI("%{public}s end scene_->GoForeground.", __func__);
|
||||
} else {
|
||||
if (abilityWindow_ != nullptr) {
|
||||
APP_LOGI("%{public}s begin abilityWindow_->OnPostAbilityForeground.", __func__);
|
||||
abilityWindow_->OnPostAbilityForeground();
|
||||
APP_LOGI("%{public}s end abilityWindow_->OnPostAbilityForeground.", __func__);
|
||||
}
|
||||
}
|
||||
|
||||
if (abilityLifecycleExecutor_ == nullptr) {
|
||||
APP_LOGE("Ability::OnForeground error. abilityLifecycleExecutor_ == nullptr.");
|
||||
return;
|
||||
}
|
||||
abilityLifecycleExecutor_->DispatchLifecycleState(AbilityLifecycleExecutor::LifecycleState::INACTIVE);
|
||||
|
||||
if (lifecycle_ == nullptr) {
|
||||
APP_LOGE("Ability::OnForeground error. lifecycle_ == nullptr.");
|
||||
return;
|
||||
}
|
||||
lifecycle_->DispatchLifecycle(LifeCycle::Event::ON_FOREGROUND, want);
|
||||
DispatchLifecycleOnForeground(want);
|
||||
APP_LOGI("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
@ -339,18 +399,36 @@ void Ability::OnForeground(const Want &want)
|
||||
*/
|
||||
void Ability::OnBackground()
|
||||
{
|
||||
BYTRACE(BYTRACE_TAG_ABILITY_MANAGER);
|
||||
APP_LOGI("%{public}s begin.", __func__);
|
||||
if (abilityWindow_ != nullptr && abilityInfo_->type == AppExecFwk::AbilityType::PAGE) {
|
||||
APP_LOGI("%{public}s begin abilityWindow_->OnPostAbilityBackground.", __func__);
|
||||
abilityWindow_->OnPostAbilityBackground();
|
||||
APP_LOGI("%{public}s end abilityWindow_->OnPostAbilityBackground.", __func__);
|
||||
if (abilityInfo_->type == AppExecFwk::AbilityType::PAGE) {
|
||||
APP_LOGI("%{public}s begin OnPostAbilityBackground.", __func__);
|
||||
if (targetVersion_ >= TARGET_VERSION_THRESHOLDS) {
|
||||
if (scene_ == nullptr) {
|
||||
APP_LOGE("Ability::OnBackground error. scene_ == nullptr.");
|
||||
return;
|
||||
}
|
||||
scene_->GoBackground();
|
||||
} else {
|
||||
if (abilityWindow_ == nullptr) {
|
||||
APP_LOGE("Ability::OnBackground error. abilityWindow_ == nullptr.");
|
||||
return;
|
||||
}
|
||||
abilityWindow_->OnPostAbilityBackground();
|
||||
}
|
||||
APP_LOGI("%{public}s end OnPostAbilityBackground.", __func__);
|
||||
}
|
||||
|
||||
if (abilityLifecycleExecutor_ == nullptr) {
|
||||
APP_LOGE("Ability::OnBackground error. abilityLifecycleExecutor_ == nullptr.");
|
||||
return;
|
||||
}
|
||||
abilityLifecycleExecutor_->DispatchLifecycleState(AbilityLifecycleExecutor::LifecycleState::BACKGROUND);
|
||||
|
||||
if (targetVersion_ >= TARGET_VERSION_THRESHOLDS) {
|
||||
abilityLifecycleExecutor_->DispatchLifecycleState(AbilityLifecycleExecutor::LifecycleState::BACKGROUND_NEW);
|
||||
} else {
|
||||
abilityLifecycleExecutor_->DispatchLifecycleState(AbilityLifecycleExecutor::LifecycleState::BACKGROUND);
|
||||
}
|
||||
|
||||
if (lifecycle_ == nullptr) {
|
||||
APP_LOGE("Ability::OnBackground error. lifecycle_ == nullptr.");
|
||||
@ -370,6 +448,7 @@ void Ability::OnBackground()
|
||||
*/
|
||||
sptr<IRemoteObject> Ability::OnConnect(const Want &want)
|
||||
{
|
||||
BYTRACE(BYTRACE_TAG_ABILITY_MANAGER);
|
||||
APP_LOGI("%{public}s begin.", __func__);
|
||||
if (abilityLifecycleExecutor_ == nullptr) {
|
||||
APP_LOGE("Ability::OnConnect error. abilityLifecycleExecutor_ == nullptr.");
|
||||
@ -393,7 +472,9 @@ sptr<IRemoteObject> Ability::OnConnect(const Want &want)
|
||||
*
|
||||
*/
|
||||
void Ability::OnDisconnect(const Want &want)
|
||||
{}
|
||||
{
|
||||
BYTRACE(BYTRACE_TAG_ABILITY_MANAGER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start other ability for result.
|
||||
@ -470,17 +551,14 @@ void Ability::StartAbility(const Want &want, AbilityStartSetting abilityStartSet
|
||||
* key-down event of the component returns true. The default implementation of this callback does nothing
|
||||
* and returns false.
|
||||
*
|
||||
* @param keyCode Indicates the code of the key pressed.
|
||||
* @param keyEvent Indicates the key-down event.
|
||||
*
|
||||
* @return Returns true if this event is handled and will not be passed further; returns false if this event
|
||||
* is not handled and should be passed to other handlers.
|
||||
*/
|
||||
bool Ability::OnKeyDown(int keyCode, const KeyEvent &keyEvent)
|
||||
void Ability::OnKeyDown(const std::shared_ptr<MMI::KeyEvent>& keyEvent)
|
||||
{
|
||||
APP_LOGI("Ability::OnKeyDown called");
|
||||
APP_LOGI("Ability::OnKeyDown keyCode: %{public}d.", keyCode);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -489,25 +567,19 @@ bool Ability::OnKeyDown(int keyCode, const KeyEvent &keyEvent)
|
||||
* key-up event of the component returns true. The default implementation of this callback does nothing and
|
||||
* returns false.
|
||||
*
|
||||
* @param keyCode Indicates the code of the key released.
|
||||
* @param keyEvent Indicates the key-up event.
|
||||
*
|
||||
* @return Returns true if this event is handled and will not be passed further; returns false if this event
|
||||
* is not handled and should be passed to other handlers.
|
||||
*/
|
||||
bool Ability::OnKeyUp(int keyCode, const KeyEvent &keyEvent)
|
||||
void Ability::OnKeyUp(const std::shared_ptr<MMI::KeyEvent>& keyEvent)
|
||||
{
|
||||
APP_LOGI("Ability::OnKeyUp called");
|
||||
APP_LOGI("Ability::OnKeyUp keyCode: %{public}d.", keyCode);
|
||||
switch (keyCode) {
|
||||
case OHOS::KeyEventEnum::KEY_BACK:
|
||||
APP_LOGI("Ability::OnKey Back key pressed.");
|
||||
OnBackPressed();
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
auto code = keyEvent->GetKeyCode();
|
||||
if (code == MMI::KeyEvent::KEYCODE_BACK) {
|
||||
APP_LOGI("Ability::OnKey Back key pressed.");
|
||||
OnBackPressed();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -518,13 +590,9 @@ bool Ability::OnKeyUp(int keyCode, const KeyEvent &keyEvent)
|
||||
*
|
||||
* @return Returns true if the event is handled; returns false otherwise.
|
||||
*/
|
||||
bool Ability::OnTouchEvent(const TouchEvent &touchEvent)
|
||||
void Ability::OnPointerEvent(std::shared_ptr<MMI::PointerEvent>& pointerEvent)
|
||||
{
|
||||
APP_LOGI("Ability::OnTouchEvent called");
|
||||
APP_LOGI("Ability::OnTouchEvent action: %{public}d phase: %{public}d",
|
||||
const_cast<TouchEvent &>(touchEvent).GetAction(),
|
||||
const_cast<TouchEvent &>(touchEvent).GetPhase());
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -567,19 +635,19 @@ void Ability::SetUIContent(int layoutRes, std::shared_ptr<Context> &context, int
|
||||
{}
|
||||
|
||||
/**
|
||||
* @brief Inflates UI controls by using WindowConfig.
|
||||
* @brief Inflates UI controls by using WindowOption.
|
||||
*
|
||||
* @param config Indicates the window config defined by the user.
|
||||
* @param windowOption Indicates the window option defined by the user.
|
||||
*/
|
||||
void Ability::SetUIContent(const sptr<WindowOption> &config)
|
||||
void Ability::SetWindowType(Rosen::WindowType winType)
|
||||
{
|
||||
if (abilityWindow_ == nullptr) {
|
||||
APP_LOGE("Ability::SetUIContent abilityWindow_ is nullptr");
|
||||
APP_LOGE("Ability::SetWindowType abilityWindow_ is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
APP_LOGI("%{public}s beign abilityWindow_->SetWindowConfig.", __func__);
|
||||
abilityWindow_->SetWindowConfig(config);
|
||||
abilityWindow_->SetWindowType(winType);
|
||||
APP_LOGI("%{public}s end abilityWindow_->SetWindowConfig.", __func__);
|
||||
}
|
||||
|
||||
@ -588,7 +656,7 @@ void Ability::SetUIContent(const sptr<WindowOption> &config)
|
||||
*
|
||||
* @return Returns a IWindowsManager object pointer.
|
||||
*/
|
||||
const sptr<Window> Ability::GetWindow()
|
||||
const sptr<Rosen::Window> Ability::GetWindow()
|
||||
{
|
||||
if (abilityWindow_ != nullptr) {
|
||||
return abilityWindow_->GetWindow();
|
||||
@ -598,6 +666,16 @@ const sptr<Window> Ability::GetWindow()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the scene belong to the ability.
|
||||
*
|
||||
* @return Returns a WindowScene object pointer.
|
||||
*/
|
||||
std::shared_ptr<Rosen::WindowScene> Ability::GetScene()
|
||||
{
|
||||
return scene_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the type of audio whose volume is adjusted by the volume button.
|
||||
*
|
||||
@ -627,6 +705,25 @@ bool Ability::HasWindowFocus()
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Obtains api version based on ability.
|
||||
* @return api version.
|
||||
*/
|
||||
int Ability::GetTargetVersion()
|
||||
{
|
||||
return targetVersion_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Set api version in an ability.
|
||||
* @param targetVersion api version
|
||||
* @return None.
|
||||
*/
|
||||
void Ability::SetTargetVersion(int32_t targetVersion)
|
||||
{
|
||||
targetVersion_ = targetVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called when a key is lone pressed.
|
||||
*
|
||||
@ -941,6 +1038,7 @@ void Ability::SetVolumeTypeAdjustedByKey(int volumeType)
|
||||
*/
|
||||
void Ability::OnCommand(const AAFwk::Want &want, bool restart, int startId)
|
||||
{
|
||||
BYTRACE(BYTRACE_TAG_ABILITY_MANAGER);
|
||||
APP_LOGI("%{public}s begin restart=%{public}s,startId=%{public}d.", __func__, restart ? "true" : "false", startId);
|
||||
if (abilityLifecycleExecutor_ == nullptr) {
|
||||
APP_LOGE("Ability::OnCommand error. abilityLifecycleExecutor_ == nullptr.");
|
||||
@ -1473,7 +1571,10 @@ bool Ability::OnRestoreData(WantParams &restoreData)
|
||||
* @return None.
|
||||
*/
|
||||
void Ability::OnCompleteContinuation(int result)
|
||||
{}
|
||||
{
|
||||
APP_LOGI("Ability::OnCompleteContinuation change continuation state to initial");
|
||||
continuationManager_->ChangeProcessStateToInit();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Used to notify the local Ability that the remote Ability has been destroyed.
|
||||
@ -1482,6 +1583,25 @@ void Ability::OnCompleteContinuation(int result)
|
||||
*/
|
||||
void Ability::OnRemoteTerminated()
|
||||
{}
|
||||
|
||||
void Ability::DispatchLifecycleOnForeground(const Want &want)
|
||||
{
|
||||
if (abilityLifecycleExecutor_ == nullptr) {
|
||||
APP_LOGE("Ability::OnForeground error. abilityLifecycleExecutor_ == nullptr.");
|
||||
return;
|
||||
}
|
||||
if (targetVersion_ >= TARGET_VERSION_THRESHOLDS) {
|
||||
abilityLifecycleExecutor_->DispatchLifecycleState(AbilityLifecycleExecutor::LifecycleState::FOREGROUND_NEW);
|
||||
} else {
|
||||
abilityLifecycleExecutor_->DispatchLifecycleState(AbilityLifecycleExecutor::LifecycleState::INACTIVE);
|
||||
}
|
||||
if (lifecycle_ == nullptr) {
|
||||
APP_LOGE("Ability::OnForeground error. lifecycle_ == nullptr.");
|
||||
return;
|
||||
}
|
||||
lifecycle_->DispatchLifecycle(LifeCycle::Event::ON_FOREGROUND, want);
|
||||
}
|
||||
|
||||
bool Ability::VerifySupportForContinuation()
|
||||
{
|
||||
if (continuationManager_ == nullptr) {
|
||||
@ -2593,6 +2713,27 @@ void Ability::SetStartAbilitySetting(std::shared_ptr<AbilityStartSetting> settin
|
||||
setting_ = setting;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the launch param.
|
||||
*
|
||||
* @param launchParam the launch param.
|
||||
*/
|
||||
void Ability::SetLaunchParam(const AAFwk::LaunchParam &launchParam)
|
||||
{
|
||||
APP_LOGI("%{public}s called.", __func__);
|
||||
launchParam_ = launchParam;
|
||||
}
|
||||
|
||||
const AAFwk::LaunchParam& Ability::GetLaunchParam() const
|
||||
{
|
||||
return launchParam_;
|
||||
}
|
||||
|
||||
void Ability::SetSceneListener(sptr<Rosen::IWindowLifeCycle> listener)
|
||||
{
|
||||
sceneListener_ = listener;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<DataAbilityResult>> Ability::ExecuteBatch(
|
||||
const std::vector<std::shared_ptr<DataAbilityOperation>> &operations)
|
||||
{
|
||||
|
@ -14,15 +14,14 @@
|
||||
*/
|
||||
|
||||
#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"
|
||||
#include "iservice_registry.h"
|
||||
#include "system_ability_definition.h"
|
||||
#include "resource_manager.h"
|
||||
#include "sys_mgr_client.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
@ -53,29 +52,11 @@ void AbilityContext::StartAbility(const AAFwk::Want &want, int requestCode)
|
||||
return;
|
||||
}
|
||||
|
||||
if (CheckIfOperateRemote(want)) {
|
||||
APP_LOGI("%{public}s. Start calling GetDistributedSchedServiceProxy.", __func__);
|
||||
std::shared_ptr<OHOS::DistributedSchedule::DistributedSchedProxy> dms = GetDistributedSchedServiceProxy();
|
||||
APP_LOGI("%{public}s. End calling GetDistributedSchedServiceProxy.", __func__);
|
||||
if (dms != nullptr) {
|
||||
AppExecFwk::AbilityInfo abilityInfo;
|
||||
APP_LOGI("AbilityContext::StartAbility. try to StartRemoteAbility");
|
||||
want.DumpInfo(0);
|
||||
int result = 0;
|
||||
if (result != ERR_NONE) {
|
||||
APP_LOGE("AbilityContext::StartAbility start remote ability failed, the result is %{public}d", result);
|
||||
}
|
||||
} else {
|
||||
APP_LOGE("AbilityContext::StartAbility failed. It wants to start a remote ability, but failed to get dms.");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
APP_LOGI("%{public}s. Start calling ams->StartAbility.", __func__);
|
||||
ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, token_, requestCode);
|
||||
APP_LOGI("%{public}s. End calling ams->StartAbility. ret=%{public}d", __func__, err);
|
||||
if (err != ERR_OK) {
|
||||
APP_LOGE("AbilityContext::StartAbility is failed %{public}d", err);
|
||||
}
|
||||
APP_LOGI("%{public}s. Start calling ams->StartAbility.", __func__);
|
||||
ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, token_, requestCode);
|
||||
APP_LOGI("%{public}s. End calling ams->StartAbility. ret=%{public}d", __func__, err);
|
||||
if (err != ERR_OK) {
|
||||
APP_LOGE("AbilityContext::StartAbility is failed %{public}d", err);
|
||||
}
|
||||
APP_LOGI("%{public}s end.", __func__);
|
||||
}
|
||||
@ -249,24 +230,7 @@ bool AbilityContext::ConnectAbility(const Want &want, const sptr<AAFwk::IAbility
|
||||
return false;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want, conn, token_);
|
||||
APP_LOGI("%{public}s end ConnectAbility, ret=%{public}d", __func__, ret);
|
||||
bool value = ((ret == ERR_OK) ? true : false);
|
||||
if (!value) {
|
||||
@ -291,17 +255,7 @@ void AbilityContext::DisconnectAbility(const sptr<AAFwk::IAbilityConnection> &co
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
ErrCode 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");
|
||||
@ -1201,42 +1155,6 @@ bool AbilityContext::IsFirstInMission()
|
||||
return (errval == ERR_OK) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check whether it wants to operate a remote ability
|
||||
*
|
||||
* @param want Indicates the Want containing information about the ability to start.
|
||||
*
|
||||
* @return return true if it wamts to operate a remote ability, ohterwise return false.
|
||||
*/
|
||||
bool AbilityContext::CheckIfOperateRemote(const Want &want)
|
||||
{
|
||||
if (want.GetElement().GetDeviceID() != "") {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains a distributedSchedService.
|
||||
*
|
||||
* @return Returns an IDistributedSched proxy.
|
||||
*/
|
||||
std::shared_ptr<OHOS::DistributedSchedule::DistributedSchedProxy> AbilityContext::GetDistributedSchedServiceProxy()
|
||||
{
|
||||
APP_LOGI("%{public}s begin.", __func__);
|
||||
auto remoteObject = OHOS::DelayedSingleton<SysMrgClient>::GetInstance()->GetSystemAbility(DISTRIBUTED_SCHED_SA_ID);
|
||||
if (remoteObject == nullptr) {
|
||||
APP_LOGE("failed to get dms service");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
APP_LOGI("get dms proxy success.");
|
||||
std::shared_ptr<OHOS::DistributedSchedule::DistributedSchedProxy> proxy = nullptr;
|
||||
proxy = std::make_shared<OHOS::DistributedSchedule::DistributedSchedProxy>(remoteObject);
|
||||
APP_LOGI("%{public}s end.", __func__);
|
||||
return proxy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains a task dispatcher that is bound to the UI thread.
|
||||
*
|
||||
|
160
frameworks/kits/ability/native/src/ability_impl.cpp
Normal file → Executable file
160
frameworks/kits/ability/native/src/ability_impl.cpp
Normal file → Executable file
@ -14,20 +14,22 @@
|
||||
*/
|
||||
|
||||
#include "ability_impl.h"
|
||||
|
||||
#include "app_log_wrapper.h"
|
||||
#include "bytrace.h"
|
||||
#include "data_ability_predicates.h"
|
||||
#include "values_bucket.h"
|
||||
#include "ability_keyevent.h"
|
||||
#include "ability_touchevent.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
const int TARGET_VERSION_THRESHOLDS = 8;
|
||||
|
||||
void AbilityImpl::Init(std::shared_ptr<OHOSApplication> &application, const std::shared_ptr<AbilityLocalRecord> &record,
|
||||
std::shared_ptr<Ability> &ability, std::shared_ptr<AbilityHandler> &handler, const sptr<IRemoteObject> &token,
|
||||
std::shared_ptr<ContextDeal> &contextDeal)
|
||||
{
|
||||
BYTRACE(BYTRACE_TAG_ABILITY_MANAGER);
|
||||
APP_LOGI("AbilityImpl::init begin");
|
||||
|
||||
if ((token == nullptr) || (application == nullptr) || (handler == nullptr) || (record == nullptr) ||
|
||||
ability == nullptr || contextDeal == nullptr) {
|
||||
APP_LOGE("AbilityImpl::init failed, token is nullptr, application is nullptr, handler is nullptr, record is "
|
||||
@ -39,15 +41,10 @@ void AbilityImpl::Init(std::shared_ptr<OHOSApplication> &application, const std:
|
||||
record->SetAbilityImpl(shared_from_this());
|
||||
ability_ = ability;
|
||||
ability_->Init(record->GetAbilityInfo(), application, handler, token);
|
||||
ability_->SetSceneListener(sptr<WindowLifeCycleImpl>(new (std::nothrow) WindowLifeCycleImpl(token_)));
|
||||
lifecycleState_ = AAFwk::ABILITY_STATE_INITIAL;
|
||||
abilityLifecycleCallbacks_ = application;
|
||||
contextDeal_ = contextDeal;
|
||||
|
||||
// Multimodal Events
|
||||
abilityKeyEventHandle_ = sptr<AbilityKeyEventHandle>(new (std::nothrow) AbilityKeyEventHandle(shared_from_this()));
|
||||
abilityTouchEventHandle_ =
|
||||
sptr<AbilityTouchEventHandle>(new (std::nothrow) AbilityTouchEventHandle(shared_from_this()));
|
||||
|
||||
APP_LOGI("AbilityImpl::init end");
|
||||
}
|
||||
|
||||
@ -71,16 +68,24 @@ void AbilityImpl::Start(const Want &want)
|
||||
|
||||
APP_LOGI("AbilityImpl::Start");
|
||||
ability_->OnStart(want);
|
||||
if (ability_->GetAbilityInfo()->type == AbilityType::DATA) {
|
||||
lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE;
|
||||
if ((ability_->GetAbilityInfo()->type == AppExecFwk::AbilityType::PAGE) &&
|
||||
(ability_->GetTargetVersion() >= TARGET_VERSION_THRESHOLDS)) {
|
||||
lifecycleState_ = AAFwk::ABILITY_STATE_STARTED_NEW;
|
||||
} else {
|
||||
lifecycleState_ = AAFwk::ABILITY_STATE_INACTIVE;
|
||||
if (ability_->GetAbilityInfo()->type == AbilityType::DATA) {
|
||||
lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE;
|
||||
} else {
|
||||
lifecycleState_ = AAFwk::ABILITY_STATE_INACTIVE;
|
||||
}
|
||||
}
|
||||
|
||||
abilityLifecycleCallbacks_->OnAbilityStart(ability_);
|
||||
|
||||
// Multimodal Events Register
|
||||
MMIRegister();
|
||||
if ((ability_->GetAbilityInfo()->type == AppExecFwk::AbilityType::PAGE) &&
|
||||
(ability_->GetTargetVersion() < TARGET_VERSION_THRESHOLDS)) {
|
||||
WindowEventRegister();
|
||||
}
|
||||
APP_LOGI("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
@ -99,11 +104,14 @@ void AbilityImpl::Stop()
|
||||
|
||||
APP_LOGI("AbilityImpl::Stop");
|
||||
ability_->OnStop();
|
||||
lifecycleState_ = AAFwk::ABILITY_STATE_INITIAL;
|
||||
if ((ability_->GetAbilityInfo()->type == AppExecFwk::AbilityType::PAGE) &&
|
||||
(ability_->GetTargetVersion() >= TARGET_VERSION_THRESHOLDS)) {
|
||||
lifecycleState_ = AAFwk::ABILITY_STATE_STOPED_NEW;
|
||||
} else {
|
||||
lifecycleState_ = AAFwk::ABILITY_STATE_INITIAL;
|
||||
}
|
||||
abilityLifecycleCallbacks_->OnAbilityStop(ability_);
|
||||
|
||||
// Multimodal Events UnRegister
|
||||
MMIUnRegister();
|
||||
APP_LOGI("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
@ -159,6 +167,28 @@ void AbilityImpl::Inactive()
|
||||
APP_LOGI("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
void AbilityImpl::WindowLifeCycleImpl::AfterForeground()
|
||||
{
|
||||
PacMap restoreData;
|
||||
AbilityManagerClient::GetInstance()->AbilityTransitionDone(token_,
|
||||
AbilityLifeCycleState::ABILITY_STATE_FOREGROUND_NEW, restoreData);
|
||||
}
|
||||
|
||||
void AbilityImpl::WindowLifeCycleImpl::AfterBackground()
|
||||
{
|
||||
PacMap restoreData;
|
||||
AbilityManagerClient::GetInstance()->AbilityTransitionDone(token_,
|
||||
AbilityLifeCycleState::ABILITY_STATE_BACKGROUND_NEW, restoreData);
|
||||
}
|
||||
|
||||
void AbilityImpl::WindowLifeCycleImpl::AfterFocused()
|
||||
{
|
||||
}
|
||||
|
||||
void AbilityImpl::WindowLifeCycleImpl::AfterUnFocused()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Toggles the lifecycle status of Ability to AAFwk::ABILITY_STATE_INACTIVE. And notifies the application
|
||||
* that it belongs to of the lifecycle status.
|
||||
@ -175,7 +205,12 @@ void AbilityImpl::Foreground(const Want &want)
|
||||
|
||||
APP_LOGI("AbilityImpl::Foreground");
|
||||
ability_->OnForeground(want);
|
||||
lifecycleState_ = AAFwk::ABILITY_STATE_INACTIVE;
|
||||
if ((ability_->GetAbilityInfo()->type == AppExecFwk::AbilityType::PAGE) &&
|
||||
(ability_->GetTargetVersion() >= TARGET_VERSION_THRESHOLDS)) {
|
||||
lifecycleState_ = AAFwk::ABILITY_STATE_FOREGROUND_NEW;
|
||||
} else {
|
||||
lifecycleState_ = AAFwk::ABILITY_STATE_INACTIVE;
|
||||
}
|
||||
abilityLifecycleCallbacks_->OnAbilityForeground(ability_);
|
||||
APP_LOGI("%{public}s end.", __func__);
|
||||
}
|
||||
@ -196,7 +231,12 @@ void AbilityImpl::Background()
|
||||
APP_LOGI("AbilityImpl::Background");
|
||||
ability_->OnLeaveForeground();
|
||||
ability_->OnBackground();
|
||||
lifecycleState_ = AAFwk::ABILITY_STATE_BACKGROUND;
|
||||
if ((ability_->GetAbilityInfo()->type == AppExecFwk::AbilityType::PAGE) &&
|
||||
(ability_->GetTargetVersion() >= TARGET_VERSION_THRESHOLDS)) {
|
||||
lifecycleState_ = AAFwk::ABILITY_STATE_BACKGROUND_NEW;
|
||||
} else {
|
||||
lifecycleState_ = AAFwk::ABILITY_STATE_BACKGROUND;
|
||||
}
|
||||
abilityLifecycleCallbacks_->OnAbilityBackground(ability_);
|
||||
APP_LOGI("%{public}s end.", __func__);
|
||||
}
|
||||
@ -319,32 +359,28 @@ int AbilityImpl::GetCurrentState()
|
||||
|
||||
/**
|
||||
* @brief Execution the KeyDown callback of the ability
|
||||
* @param keyCode Indicates the code of the key pressed.
|
||||
* @param keyEvent Indicates the key-down event.
|
||||
*
|
||||
* @return Returns true if this event is handled and will not be passed further; returns false if this event is
|
||||
* not handled and should be passed to other handlers.
|
||||
*
|
||||
*/
|
||||
bool AbilityImpl::DoKeyDown(int keyCode, const KeyEvent &keyEvent)
|
||||
void AbilityImpl::DoKeyDown(const std::shared_ptr<MMI::KeyEvent>& keyEvent)
|
||||
{
|
||||
APP_LOGI("AbilityImpl::DoKeyDown called");
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Execution the KeyUp callback of the ability
|
||||
* @param keyCode Indicates the code of the key released.
|
||||
* @param keyEvent Indicates the key-up event.
|
||||
*
|
||||
* @return Returns true if this event is handled and will not be passed further; returns false if this event is
|
||||
* not handled and should be passed to other handlers.
|
||||
*
|
||||
*/
|
||||
bool AbilityImpl::DoKeyUp(int keyCode, const KeyEvent &keyEvent)
|
||||
void AbilityImpl::DoKeyUp(const std::shared_ptr<MMI::KeyEvent>& keyEvent)
|
||||
{
|
||||
APP_LOGI("AbilityImpl::DoKeyUp called");
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -355,10 +391,9 @@ bool AbilityImpl::DoKeyUp(int keyCode, const KeyEvent &keyEvent)
|
||||
* @return Returns true if the event is handled; returns false otherwise.
|
||||
*
|
||||
*/
|
||||
bool AbilityImpl::DoTouchEvent(const TouchEvent &touchEvent)
|
||||
void AbilityImpl::DoPointerEvent(std::shared_ptr<MMI::PointerEvent>& pointerEvent)
|
||||
{
|
||||
APP_LOGI("AbilityImpl::DoTouchEvent called");
|
||||
return false;
|
||||
APP_LOGI("AbilityImpl::DoPointerEvent called");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -382,6 +417,7 @@ void AbilityImpl::SendResult(int requestCode, int resultCode, const Want &result
|
||||
|
||||
if (resultData.HasParameter(OHOS_RESULT_PERMISSION_KEY) && resultData.HasParameter(OHOS_RESULT_PERMISSIONS_LIST) &&
|
||||
resultData.HasParameter(OHOS_RESULT_CALLER_BUNDLERNAME)) {
|
||||
|
||||
if (resultCode > 0) {
|
||||
std::vector<std::string> permissions = resultData.GetStringArrayParam(OHOS_RESULT_PERMISSIONS_LIST);
|
||||
std::vector<std::string> grantYes = resultData.GetStringArrayParam(OHOS_RESULT_PERMISSIONS_LIST_YES);
|
||||
@ -740,57 +776,38 @@ void AbilityImpl::ScheduleUpdateConfiguration(const Configuration &config)
|
||||
ability_->OnConfigurationUpdated(config);
|
||||
APP_LOGI("%{public}s end.", __func__);
|
||||
}
|
||||
/**
|
||||
* @brief Multimodal Events Register.
|
||||
*/
|
||||
void AbilityImpl::MMIRegister()
|
||||
void AbilityImpl::InputEventConsumerImpl::OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const
|
||||
{
|
||||
APP_LOGI("%{public}s called.", __func__);
|
||||
int32_t ret = 0;
|
||||
int32_t windowID = 0;
|
||||
if (ability_->GetAbilityInfo()->type == AppExecFwk::AbilityType::PAGE) {
|
||||
if (ability_->GetWindow() != nullptr) {
|
||||
windowID = ability_->GetWindow()->GetID();
|
||||
}
|
||||
int32_t code = keyEvent->GetKeyAction();
|
||||
if (code == MMI::KeyEvent::KEY_ACTION_DOWN) {
|
||||
abilityImpl_->DoKeyDown(keyEvent);
|
||||
APP_LOGI("AbilityImpl::OnKeyDown keyAction: %{public}d.", code);
|
||||
} else if (code == MMI::KeyEvent::KEY_ACTION_UP) {
|
||||
abilityImpl_->DoKeyUp(keyEvent);
|
||||
APP_LOGI("AbilityImpl::DoKeyUp keyAction: %{public}d.", code);
|
||||
}
|
||||
}
|
||||
|
||||
// register keyEvent
|
||||
ret = MMIEventHdl.RegisterStandardizedEventHandle(token_, windowID, abilityKeyEventHandle_);
|
||||
APP_LOGI("MMIRegister :token:%{public}p windowID:%{public}d", token_.GetRefPtr(), windowID);
|
||||
APP_LOGI("MMIRegister :keyEventHandler:%{public}p", abilityKeyEventHandle_.GetRefPtr());
|
||||
APP_LOGI("MMIRegister :RegisterkeyEventHandler ret:%{public}d", ret);
|
||||
|
||||
// register touchEvent
|
||||
ret = MMIEventHdl.RegisterStandardizedEventHandle(token_, windowID, abilityTouchEventHandle_);
|
||||
APP_LOGI("MMIRegister :token:%{public}p windowID:%{public}d", token_.GetRefPtr(), windowID);
|
||||
APP_LOGI("MMIRegister :touchEventHandler:%{public}p", abilityTouchEventHandle_.GetRefPtr());
|
||||
APP_LOGI("MMIRegister :RegistertouchEventHandler ret:%{public}d", ret);
|
||||
void AbilityImpl::InputEventConsumerImpl::OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const
|
||||
{
|
||||
APP_LOGI("AbilityImpl::DoPointerEvent called.");
|
||||
abilityImpl_->DoPointerEvent(pointerEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Multimodal Events UnRegister.
|
||||
* @brief Multimodal Events Register.
|
||||
*/
|
||||
void AbilityImpl::MMIUnRegister()
|
||||
void AbilityImpl::WindowEventRegister()
|
||||
{
|
||||
APP_LOGI("%{public}s called.", __func__);
|
||||
int32_t ret = 0;
|
||||
int32_t windowID = 0;
|
||||
if (ability_->GetAbilityInfo()->type == AppExecFwk::AbilityType::PAGE) {
|
||||
if (ability_->GetWindow() != nullptr) {
|
||||
windowID = ability_->GetWindow()->GetID();
|
||||
if (ability_->GetTargetVersion() < TARGET_VERSION_THRESHOLDS) {
|
||||
auto window = ability_->GetWindow();
|
||||
if (window) {
|
||||
std::shared_ptr<MMI::IInputEventConsumer> inputEventListener =
|
||||
std::make_shared<AbilityImpl::InputEventConsumerImpl>(shared_from_this());
|
||||
window->AddInputEventListener(inputEventListener);
|
||||
}
|
||||
}
|
||||
// unregister keyEvent
|
||||
ret = MMIEventHdl.UnregisterStandardizedEventHandle(token_, windowID, abilityKeyEventHandle_);
|
||||
APP_LOGI("MMIUnRegister :token:%{public}p windowID:%{public}d", token_.GetRefPtr(), windowID);
|
||||
APP_LOGI("MMIUnRegister :keyEventHandler:%{public}p", abilityKeyEventHandle_.GetRefPtr());
|
||||
APP_LOGI("MMIUnRegister :UnRegisterkeyEventHandler ret:%{public}d", ret);
|
||||
|
||||
// unregister touchEvent
|
||||
ret = MMIEventHdl.UnregisterStandardizedEventHandle(token_, windowID, abilityTouchEventHandle_);
|
||||
APP_LOGI("MMIUnRegister :token:%{public}p windowID:%{public}d", token_.GetRefPtr(), windowID);
|
||||
APP_LOGI("MMIUnRegister :touchEventHandler:%{public}p", abilityTouchEventHandle_.GetRefPtr());
|
||||
APP_LOGI("MMIUnRegister :UnRegistertouchEventHandler ret:%{public}d", ret);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -815,5 +832,14 @@ std::vector<std::shared_ptr<DataAbilityResult>> AbilityImpl::ExecuteBatch(
|
||||
std::vector<std::shared_ptr<DataAbilityResult>> results;
|
||||
return results;
|
||||
}
|
||||
|
||||
void AbilityImpl::NotifyContinuationResult(const int32_t result)
|
||||
{
|
||||
if (ability_ == nullptr) {
|
||||
APP_LOGE("AbilityImpl::NotifyContinuationResult ability_ is nullptr");
|
||||
return;
|
||||
}
|
||||
ability_->OnCompleteContinuation(result);
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
15
frameworks/kits/ability/native/src/ability_impl_factory.cpp
Normal file → Executable file
15
frameworks/kits/ability/native/src/ability_impl_factory.cpp
Normal file → Executable file
@ -16,11 +16,13 @@
|
||||
#include "ability_impl_factory.h"
|
||||
#include "app_log_wrapper.h"
|
||||
#include "data_ability_impl.h"
|
||||
#include "new_ability_impl.h"
|
||||
#include "page_ability_impl.h"
|
||||
#include "service_ability_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
const int TARGET_VERSION_THRESHOLDS = 8;
|
||||
/**
|
||||
*
|
||||
* default constructor
|
||||
@ -44,7 +46,8 @@ AbilityImplFactory::~AbilityImplFactory()
|
||||
*
|
||||
* @return AbilityImpl object
|
||||
*/
|
||||
std::shared_ptr<AbilityImpl> AbilityImplFactory::MakeAbilityImplObject(const std::shared_ptr<AbilityInfo> &info)
|
||||
std::shared_ptr<AbilityImpl> AbilityImplFactory::MakeAbilityImplObject(const std::shared_ptr<AbilityInfo> &info,
|
||||
int targetVersion)
|
||||
{
|
||||
if (info == nullptr) {
|
||||
APP_LOGE("AbilityImplFactory::MakeAbilityImplObject is error nullptr == info ");
|
||||
@ -52,11 +55,15 @@ std::shared_ptr<AbilityImpl> AbilityImplFactory::MakeAbilityImplObject(const std
|
||||
}
|
||||
|
||||
std::shared_ptr<AbilityImpl> abilityImpl = nullptr;
|
||||
APP_LOGI("AbilityImplFactory::MakeAbilityImplObject type:%{public}d", info->type);
|
||||
|
||||
APP_LOGI("AbilityImplFactory::MakeAbilityImplObject type:%{public}d, targetVersion:%{public}d", info->type,
|
||||
targetVersion);
|
||||
switch (info->type) {
|
||||
case AppExecFwk::AbilityType::PAGE:
|
||||
abilityImpl = std::make_shared<PageAbilityImpl>();
|
||||
if (targetVersion >= TARGET_VERSION_THRESHOLDS) {
|
||||
abilityImpl = std::make_shared<NewAbilityImpl>();
|
||||
} else {
|
||||
abilityImpl = std::make_shared<PageAbilityImpl>();
|
||||
}
|
||||
break;
|
||||
case AppExecFwk::AbilityType::SERVICE:
|
||||
abilityImpl = std::make_shared<ServiceAbilityImpl>();
|
||||
|
@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ability_keyevent.h"
|
||||
#include "ability_impl.h"
|
||||
#include "app_log_wrapper.h"
|
||||
#include "ability_post_event_timeout.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
AbilityKeyEventHandle::AbilityKeyEventHandle(const std::shared_ptr<AbilityImpl> &abilityImpl)
|
||||
: abilityImpl_(abilityImpl)
|
||||
{
|
||||
APP_LOGI("AbilityKeyEventHandle is created");
|
||||
}
|
||||
|
||||
AbilityKeyEventHandle::~AbilityKeyEventHandle()
|
||||
{
|
||||
APP_LOGI("AbilityKeyEventHandle is destroyed");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called back when on key.
|
||||
*/
|
||||
bool AbilityKeyEventHandle::OnKey(const KeyEvent &keyEvent)
|
||||
{
|
||||
APP_LOGI("AbilityKeyEventHandle::OnKey called.");
|
||||
bool ret = false;
|
||||
if (abilityImpl_ == nullptr) {
|
||||
APP_LOGE("AbilityImpl::OnKey abilityImpl_ is nullptr. KeyCode %{public}d.", keyEvent.GetKeyCode());
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (keyEvent.IsKeyDown()) {
|
||||
std::string taskHead("OnKey");
|
||||
std::string taskCode = std::to_string(keyEvent.GetKeyCode());
|
||||
std::string taskTail("Down");
|
||||
auto timeOut = abilityImpl_->CreatePostEventTimeouter(taskHead + taskCode + taskTail);
|
||||
if (timeOut == nullptr) {
|
||||
APP_LOGW("AbilityKeyEventHandle::OnKeyDown timeouter Create return nullptr");
|
||||
ret = abilityImpl_->DoKeyDown(keyEvent.GetKeyCode(), keyEvent);
|
||||
} else {
|
||||
timeOut->TimingBegin();
|
||||
ret = abilityImpl_->DoKeyDown(keyEvent.GetKeyCode(), keyEvent);
|
||||
timeOut->TimeEnd();
|
||||
}
|
||||
APP_LOGI("AbilityImpl::OnKeyDown keyCode: %{public}d.", keyEvent.GetKeyCode());
|
||||
} else {
|
||||
std::string taskHead("OnKey");
|
||||
std::string taskCode = std::to_string(keyEvent.GetKeyCode());
|
||||
std::string taskTail("Up");
|
||||
auto timeOut = abilityImpl_->CreatePostEventTimeouter(taskHead + taskCode + taskTail);
|
||||
if (timeOut == nullptr) {
|
||||
APP_LOGW("AbilityKeyEventHandle::OnKeyUp timeouter Create return nullptr");
|
||||
ret = abilityImpl_->DoKeyUp(keyEvent.GetKeyCode(), keyEvent);
|
||||
} else {
|
||||
timeOut->TimingBegin();
|
||||
ret = abilityImpl_->DoKeyUp(keyEvent.GetKeyCode(), keyEvent);
|
||||
timeOut->TimeEnd();
|
||||
}
|
||||
APP_LOGI("AbilityImpl::DoKeyUp keyCode: %{public}d.", keyEvent.GetKeyCode());
|
||||
}
|
||||
|
||||
APP_LOGI("AbilityKeyEventHandle::OnKey called end. return %{public}s", ret ? "true" : "false");
|
||||
return ret;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
30
frameworks/kits/ability/native/src/ability_loader.cpp
Normal file → Executable file
30
frameworks/kits/ability/native/src/ability_loader.cpp
Normal file → Executable file
@ -36,6 +36,18 @@ void AbilityLoader::RegisterAbility(const std::string &abilityName, const Create
|
||||
APP_LOGD("AbilityLoader::RegisterAbility:%{public}s", abilityName.c_str());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Register Extension Info
|
||||
*
|
||||
* @param abilityName Extension classname
|
||||
* @param createFunc Constructor address
|
||||
*/
|
||||
void AbilityLoader::RegisterExtension(const std::string &abilityName, const CreateExtension &createFunc)
|
||||
{
|
||||
extensions_.emplace(abilityName, createFunc);
|
||||
APP_LOGD("AbilityLoader::RegisterExtension:%{public}s", abilityName.c_str());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get Ability address
|
||||
*
|
||||
@ -54,6 +66,24 @@ Ability *AbilityLoader::GetAbilityByName(const std::string &abilityName)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get Extension address
|
||||
*
|
||||
* @param abilityName Extension classname
|
||||
*
|
||||
* @return return Extension address
|
||||
*/
|
||||
AbilityRuntime::Extension *AbilityLoader::GetExtensionByName(const std::string &abilityName)
|
||||
{
|
||||
auto it = extensions_.find(abilityName);
|
||||
if (it != extensions_.end()) {
|
||||
return it->second();
|
||||
} else {
|
||||
APP_LOGE("AbilityLoader::GetExtensionByName failed:%{public}s", abilityName.c_str());
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
void AbilityLoader::RegisterAbilitySlice(const std::string &sliceName, const CreateSlice &createFunc)
|
||||
{
|
||||
|
19
frameworks/kits/ability/native/src/ability_local_record.cpp
Normal file → Executable file
19
frameworks/kits/ability/native/src/ability_local_record.cpp
Normal file → Executable file
@ -132,5 +132,24 @@ void AbilityLocalRecord::SetAbilityThread(const sptr<AbilityThread> &abilityThre
|
||||
{
|
||||
abilityThread_ = abilityThread;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Obtains api version based on ability record.
|
||||
* @return api version.
|
||||
*/
|
||||
int AbilityLocalRecord::GetTargetVersion()
|
||||
{
|
||||
return targetVersion_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Set api version in an ability record.
|
||||
* @param targetVersion api version
|
||||
* @return None.
|
||||
*/
|
||||
void AbilityLocalRecord::SetTargetVersion(int32_t targetVersion)
|
||||
{
|
||||
targetVersion_ = targetVersion;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
@ -14,9 +14,10 @@
|
||||
*/
|
||||
|
||||
#include "ability_process.h"
|
||||
#include <dlfcn.h>
|
||||
#include "app_log_wrapper.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include "app_log_wrapper.h"
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
static void *g_handle = nullptr;
|
||||
|
193
frameworks/kits/ability/native/src/ability_runtime/js_ability.cpp
Executable file
193
frameworks/kits/ability/native/src/ability_runtime/js_ability.cpp
Executable file
@ -0,0 +1,193 @@
|
||||
/*
|
||||
* 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_runtime/js_ability.h"
|
||||
|
||||
#include "ability_runtime/js_ability_context.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_data_struct_converter.h"
|
||||
#include "js_runtime.h"
|
||||
#include "js_runtime_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
Ability* JsAbility::Create(const std::unique_ptr<Runtime>& runtime)
|
||||
{
|
||||
return new JsAbility(static_cast<JsRuntime&>(*runtime));
|
||||
}
|
||||
|
||||
JsAbility::JsAbility(JsRuntime& jsRuntime) : jsRuntime_(jsRuntime) {}
|
||||
JsAbility::~JsAbility() = default;
|
||||
|
||||
void JsAbility::Init(const std::shared_ptr<AbilityInfo> &abilityInfo,
|
||||
const std::shared_ptr<OHOSApplication> &application, std::shared_ptr<AbilityHandler> &handler,
|
||||
const sptr<IRemoteObject> &token)
|
||||
{
|
||||
Ability::Init(abilityInfo, application, handler, token);
|
||||
|
||||
if (!abilityInfo) {
|
||||
HILOG_ERROR("abilityInfo is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string srcPath(abilityInfo->package);
|
||||
srcPath.append("/assets/js/");
|
||||
if (!abilityInfo->srcPath.empty()) {
|
||||
srcPath.append(abilityInfo->srcPath);
|
||||
}
|
||||
srcPath.append("/").append(abilityInfo->name).append(".abc");
|
||||
|
||||
std::string moduleName(abilityInfo->moduleName);
|
||||
moduleName.append("::").append(abilityInfo->name);
|
||||
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
auto& engine = jsRuntime_.GetNativeEngine();
|
||||
|
||||
jsAbilityObj_ = jsRuntime_.LoadModule(moduleName, srcPath);
|
||||
|
||||
NativeObject* obj = ConvertNativeValueTo<NativeObject>(jsAbilityObj_->Get());
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("Failed to get AbilityStage object");
|
||||
return;
|
||||
}
|
||||
|
||||
auto context = GetAbilityContext();
|
||||
NativeValue* contextObj = CreateJsAbilityContext(engine, context);
|
||||
auto shellContextRef = jsRuntime_.LoadSystemModule("application.AbilityContext", &contextObj, 1);
|
||||
contextObj = shellContextRef->Get();
|
||||
|
||||
context->Bind(jsRuntime_, shellContextRef.release());
|
||||
obj->SetProperty("context", contextObj);
|
||||
}
|
||||
|
||||
void JsAbility::OnStart(const Want &want)
|
||||
{
|
||||
Ability::OnStart(want);
|
||||
|
||||
if (!jsAbilityObj_) {
|
||||
HILOG_WARN("Not found Ability.js");
|
||||
return;
|
||||
}
|
||||
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
auto& nativeEngine = jsRuntime_.GetNativeEngine();
|
||||
|
||||
NativeValue* value = jsAbilityObj_->Get();
|
||||
NativeObject* obj = ConvertNativeValueTo<NativeObject>(value);
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("Failed to get Ability object");
|
||||
return;
|
||||
}
|
||||
|
||||
auto jsWant = CreateJsWantObject(nativeEngine, want);
|
||||
obj->SetProperty("launchWant", jsWant);
|
||||
obj->SetProperty("lastRequestWant", jsWant);
|
||||
|
||||
NativeValue* argv[] = {
|
||||
jsWant,
|
||||
CreateJsLaunchParam(nativeEngine, GetLaunchParam()),
|
||||
};
|
||||
CallObjectMethod("onCreate", argv, ArraySize(argv));
|
||||
}
|
||||
|
||||
void JsAbility::OnStop()
|
||||
{
|
||||
Ability::OnStop();
|
||||
|
||||
CallObjectMethod("onDestroy");
|
||||
}
|
||||
|
||||
void JsAbility::OnSceneCreated()
|
||||
{
|
||||
Ability::OnSceneCreated();
|
||||
|
||||
CallObjectMethod("onWindowStageCreate");
|
||||
}
|
||||
|
||||
void JsAbility::onSceneDestroyed()
|
||||
{
|
||||
Ability::onSceneDestroyed();
|
||||
|
||||
CallObjectMethod("onWindowStageDestroy");
|
||||
}
|
||||
|
||||
void JsAbility::OnForeground(const Want &want)
|
||||
{
|
||||
Ability::OnForeground(want);
|
||||
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
auto& nativeEngine = jsRuntime_.GetNativeEngine();
|
||||
|
||||
NativeValue* value = jsAbilityObj_->Get();
|
||||
NativeObject* obj = ConvertNativeValueTo<NativeObject>(value);
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("Failed to get Ability object");
|
||||
return;
|
||||
}
|
||||
|
||||
auto jsWant = CreateJsWantObject(nativeEngine, want);
|
||||
obj->SetProperty("lastRequestWant", jsWant);
|
||||
|
||||
CallObjectMethod("onForeground", &jsWant, 1);
|
||||
}
|
||||
|
||||
void JsAbility::OnBackground()
|
||||
{
|
||||
Ability::OnBackground();
|
||||
|
||||
CallObjectMethod("onBackground");
|
||||
}
|
||||
|
||||
void JsAbility::OnAbilityResult(int requestCode, int resultCode, const Want &resultData)
|
||||
{
|
||||
HILOG_INFO("%{public}s begin.", __func__);
|
||||
Ability::OnAbilityResult(requestCode, resultCode, resultData);
|
||||
std::shared_ptr<AbilityRuntime::AbilityContext> context = GetAbilityContext();
|
||||
if (context == nullptr) {
|
||||
HILOG_WARN("JsAbility not attached to any runtime context!");
|
||||
return;
|
||||
}
|
||||
context->OnAbilityResult(requestCode, resultCode, resultData);
|
||||
HILOG_INFO("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
void JsAbility::CallObjectMethod(const char* name, NativeValue* const* argv, size_t argc)
|
||||
{
|
||||
HILOG_INFO("JsAbility::CallObjectMethod(%{public}s", name);
|
||||
|
||||
if (!jsAbilityObj_) {
|
||||
HILOG_WARN("Not found Ability.js");
|
||||
return;
|
||||
}
|
||||
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
auto& nativeEngine = jsRuntime_.GetNativeEngine();
|
||||
|
||||
NativeValue* value = jsAbilityObj_->Get();
|
||||
NativeObject* obj = ConvertNativeValueTo<NativeObject>(value);
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("Failed to get Ability object");
|
||||
return;
|
||||
}
|
||||
|
||||
NativeValue* methodOnCreate = obj->GetProperty(name);
|
||||
if (methodOnCreate == nullptr) {
|
||||
HILOG_ERROR("Failed to get '%{public}s' from Ability object", name);
|
||||
return;
|
||||
}
|
||||
nativeEngine.CallFunction(value, methodOnCreate, argv, argc);
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
550
frameworks/kits/ability/native/src/ability_runtime/js_ability_context.cpp
Executable file
550
frameworks/kits/ability/native/src/ability_runtime/js_ability_context.cpp
Executable file
@ -0,0 +1,550 @@
|
||||
/*
|
||||
* 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_runtime/js_ability_context.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_context_utils.h"
|
||||
#include "js_data_struct_converter.h"
|
||||
#include "js_runtime.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "napi_common_want.h"
|
||||
#include "napi_remote_object.h"
|
||||
#include "want.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
namespace {
|
||||
constexpr size_t ARGC_ZERO = 0;
|
||||
constexpr size_t ARGC_ONE = 1;
|
||||
constexpr size_t ARGC_TWO = 2;
|
||||
|
||||
class JsAbilityContext final {
|
||||
public:
|
||||
JsAbilityContext(const std::shared_ptr<AbilityContext>& context) : context_(context) {}
|
||||
~JsAbilityContext() = default;
|
||||
|
||||
static void Finalizer(NativeEngine* engine, void* data, void* hint)
|
||||
{
|
||||
HILOG_INFO("JsAbilityContext::Finalizer is called");
|
||||
std::unique_ptr<JsAbilityContext>(static_cast<JsAbilityContext*>(data));
|
||||
}
|
||||
|
||||
static NativeValue* StartAbility(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsAbilityContext* me = CheckParamsAndGetThis<JsAbilityContext>(engine, info);
|
||||
return (me != nullptr) ? me->OnStartAbility(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
static NativeValue* StartAbilityForResult(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsAbilityContext* me = CheckParamsAndGetThis<JsAbilityContext>(engine, info);
|
||||
return (me != nullptr) ? me->OnStartAbilityForResult(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
static NativeValue* ConnectAbility(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsAbilityContext* me = CheckParamsAndGetThis<JsAbilityContext>(engine, info);
|
||||
return (me != nullptr) ? me->OnConnectAbility(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
static NativeValue* DisconnectAbility(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsAbilityContext* me = CheckParamsAndGetThis<JsAbilityContext>(engine, info);
|
||||
return (me != nullptr) ? me->OnDisconnectAbility(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
static NativeValue* TerminateSelf(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsAbilityContext* me = CheckParamsAndGetThis<JsAbilityContext>(engine, info);
|
||||
return (me != nullptr) ? me->OnTerminateSelf(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
static NativeValue* TerminateSelfWithResult(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsAbilityContext* me = CheckParamsAndGetThis<JsAbilityContext>(engine, info);
|
||||
return (me != nullptr) ? me->OnTerminateSelfWithResult(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
NativeValue* OnStartAbility(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
HILOG_INFO("OnStartAbility is called");
|
||||
|
||||
if (info.argc == ARGC_ZERO) {
|
||||
HILOG_ERROR("Not enough params");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
AAFwk::Want want;
|
||||
OHOS::AppExecFwk::UnwrapWant(reinterpret_cast<napi_env>(&engine),
|
||||
reinterpret_cast<napi_value>(info.argv[0]), want);
|
||||
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[weak = context_, want](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
auto context = weak.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is released");
|
||||
task.Reject(engine, CreateJsError(engine, 1, "Context is released"));
|
||||
return;
|
||||
}
|
||||
|
||||
auto errcode = context->StartAbility(want, -1);
|
||||
if (errcode == 0) {
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
} else {
|
||||
task.Reject(engine, CreateJsError(engine, errcode, "Start Ability failed."));
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc == ARGC_ONE) ? nullptr : info.argv[1];
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue* OnStartAbilityForResult(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
HILOG_INFO("OnStartAbilityForResult is called");
|
||||
|
||||
if (info.argc == ARGC_ZERO) {
|
||||
HILOG_ERROR("Not enough params");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
AAFwk::Want want;
|
||||
if (!JsAbilityContext::UnWrapWant(engine, info.argv[0], want)) {
|
||||
HILOG_ERROR("%s Failed to parse want!", __func__);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
NativeValue* lastParam = info.argc == 1 ? nullptr : info.argv[1];
|
||||
NativeValue* result = nullptr;
|
||||
std::unique_ptr<AsyncTask> uasyncTask =
|
||||
CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, nullptr, &result);
|
||||
std::shared_ptr<AsyncTask> asyncTask = std::move(uasyncTask);
|
||||
RuntimeTask task = [&engine, asyncTask](int resultCode, const AAFwk::Want& want) {
|
||||
HILOG_INFO("OnStartAbilityForResult async callback is called");
|
||||
NativeValue* abilityResult = JsAbilityContext::WrapAbilityResult(engine, resultCode, want);
|
||||
if (abilityResult == nullptr) {
|
||||
HILOG_WARN("wrap abilityResult failed");
|
||||
asyncTask->Reject(engine, CreateJsError(engine, 1, "failed to get result data!"));
|
||||
} else {
|
||||
asyncTask->Resolve(engine, abilityResult);
|
||||
}
|
||||
HILOG_INFO("OnStartAbilityForResult async callback is called end");
|
||||
};
|
||||
auto context = context_.lock();
|
||||
if (context == nullptr) {
|
||||
HILOG_WARN("context is released");
|
||||
asyncTask->Reject(engine, CreateJsError(engine, 1, "context is released!"));
|
||||
} else {
|
||||
curRequestCode_ = (curRequestCode_ == INT_MAX) ? 0 : (curRequestCode_ + 1);
|
||||
context->StartAbilityForResult(want, curRequestCode_, std::move(task));
|
||||
}
|
||||
HILOG_INFO("OnStartAbilityForResult is called end");
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue* OnTerminateSelfWithResult(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
HILOG_INFO("OnTerminateSelfWithResult is called");
|
||||
|
||||
if (info.argc == 0) {
|
||||
HILOG_ERROR("Not enough params");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
int resultCode = 0;
|
||||
AAFwk::Want want;
|
||||
if (!JsAbilityContext::UnWrapAbilityResult(engine, info.argv[0], resultCode, want)) {
|
||||
HILOG_ERROR("%s Failed to parse ability result!", __func__);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[weak = context_, want, resultCode](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
auto context = weak.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is released");
|
||||
task.Reject(engine, CreateJsError(engine, 1, "Context is released"));
|
||||
return;
|
||||
}
|
||||
|
||||
context->TerminateAbilityWithResult(want, resultCode);
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc == ARGC_ONE) ? nullptr : info.argv[1];
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
HILOG_INFO("OnTerminateSelfWithResult is called end");
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue* OnConnectAbility(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
HILOG_INFO("OnConnectAbility is called");
|
||||
// only support two params
|
||||
if (info.argc != ARGC_TWO) {
|
||||
HILOG_ERROR("Not enough params");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
// unwrap want
|
||||
AAFwk::Want want;
|
||||
OHOS::AppExecFwk::UnwrapWant(reinterpret_cast<napi_env>(&engine),
|
||||
reinterpret_cast<napi_value>(info.argv[0]), want);
|
||||
HILOG_INFO("%{public}s bundlename:%{public}s abilityname:%{public}s",
|
||||
__func__,
|
||||
want.GetBundle().c_str(),
|
||||
want.GetElement().GetAbilityName().c_str());
|
||||
|
||||
// unwarp connection
|
||||
sptr<JSAbilityConnection> connection = new JSAbilityConnection(&engine);
|
||||
connection->SetJsConnectionObject(info.argv[1]);
|
||||
int64_t connectId = g_serialNumber;
|
||||
ConnectionKey key;
|
||||
key.id = g_serialNumber;
|
||||
key.want = want;
|
||||
abilityConnects_.emplace(key, connection);
|
||||
if (g_serialNumber < INT64_MAX) {
|
||||
g_serialNumber++;
|
||||
} else {
|
||||
g_serialNumber = 0;
|
||||
}
|
||||
HILOG_INFO("%{public}s not find connection, make new one:%{public}p.", __func__, connection.GetRefPtr());
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[weak = context_, want, connection, connectId](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
HILOG_INFO("OnConnectAbility begin");
|
||||
auto context = weak.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is released");
|
||||
task.Reject(engine, CreateJsError(engine, 1, "Context is released"));
|
||||
return;
|
||||
}
|
||||
HILOG_INFO("context->ConnectAbility connection:%{public}d", (int32_t)connectId);
|
||||
if (!context->ConnectAbility(want, connection)) {
|
||||
connection->CallJsFailed();
|
||||
}
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
};
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, nullptr, nullptr, std::move(complete), &result));
|
||||
return engine.CreateNumber(connectId);
|
||||
}
|
||||
|
||||
NativeValue* OnDisconnectAbility(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
HILOG_INFO("OnDisconnectAbility is called");
|
||||
// only support one or two params
|
||||
if (info.argc != ARGC_ONE && info.argc != ARGC_TWO) {
|
||||
HILOG_ERROR("Not enough params");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
// unwrap connectId
|
||||
int64_t connectId = -1;
|
||||
sptr<JSAbilityConnection> connection = nullptr;
|
||||
napi_get_value_int64(reinterpret_cast<napi_env>(&engine),
|
||||
reinterpret_cast<napi_value>(info.argv[0]), &connectId);
|
||||
HILOG_INFO("OnDisconnectAbility connection:%{public}d", (int32_t)connectId);
|
||||
auto item = std::find_if(abilityConnects_.begin(),
|
||||
abilityConnects_.end(),
|
||||
[&connectId](const std::map<ConnectionKey, sptr<JSAbilityConnection>>::value_type &obj) {
|
||||
return connectId == obj.first.id;
|
||||
});
|
||||
if (item != abilityConnects_.end()) {
|
||||
// match id
|
||||
connection = item->second;
|
||||
HILOG_INFO("%{public}s find conn ability:%{public}p exist", __func__, item->second.GetRefPtr());
|
||||
} else {
|
||||
HILOG_INFO("%{public}s not find conn exist.", __func__);
|
||||
}
|
||||
// begin disconnect
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[weak = context_, connection](
|
||||
NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
HILOG_INFO("OnDisconnectAbility begin");
|
||||
auto context = weak.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is released");
|
||||
task.Reject(engine, CreateJsError(engine, 1, "Context is released"));
|
||||
return;
|
||||
}
|
||||
if (connection == nullptr) {
|
||||
HILOG_WARN("connection nullptr");
|
||||
task.Reject(engine, CreateJsError(engine, 2, "not found connection"));
|
||||
return;
|
||||
}
|
||||
HILOG_INFO("context->DisconnectAbility");
|
||||
context->DisconnectAbility(connection);
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc == ARGC_ONE) ? nullptr : info.argv[1];
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue* OnTerminateSelf(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
HILOG_INFO("OnTerminateSelf is called");
|
||||
|
||||
if (info.argc != ARGC_ZERO && info.argc != ARGC_ONE) {
|
||||
HILOG_ERROR("Not enough params");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[weak = context_](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
auto context = weak.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is released");
|
||||
task.Reject(engine, CreateJsError(engine, 1, "Context is released"));
|
||||
return;
|
||||
}
|
||||
|
||||
auto errcode = context->TerminateSelf();
|
||||
if (errcode == 0) {
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
} else {
|
||||
task.Reject(engine, CreateJsError(engine, errcode, "Terminate Ability failed."));
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc == ARGC_ONE) ? nullptr : info.argv[1];
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool UnWrapWant(NativeEngine& engine, NativeValue* argv, AAFwk::Want& want)
|
||||
{
|
||||
if (argv == nullptr) {
|
||||
HILOG_WARN("%s argv == nullptr!", __func__);
|
||||
return false;
|
||||
}
|
||||
return AppExecFwk::UnwrapWant(reinterpret_cast<napi_env>(&engine), reinterpret_cast<napi_value>(argv), want);
|
||||
}
|
||||
|
||||
static NativeValue* WrapWant(NativeEngine& engine, const AAFwk::Want& want)
|
||||
{
|
||||
return reinterpret_cast<NativeValue*>(AppExecFwk::WrapWant(reinterpret_cast<napi_env>(&engine), want));
|
||||
}
|
||||
|
||||
static bool UnWrapAbilityResult(NativeEngine& engine, NativeValue* argv, int& resultCode, AAFwk::Want& want)
|
||||
{
|
||||
if (argv == nullptr) {
|
||||
HILOG_WARN("%s argv == nullptr!", __func__);
|
||||
return false;
|
||||
}
|
||||
if (argv->TypeOf() != NativeValueType::NATIVE_OBJECT) {
|
||||
HILOG_WARN("%s invalid type of abilityResult!", __func__);
|
||||
return false;
|
||||
}
|
||||
NativeObject* jObj = ConvertNativeValueTo<NativeObject>(argv);
|
||||
NativeValue* jResultCode = jObj->GetProperty("resultCode");
|
||||
if (jResultCode == nullptr) {
|
||||
HILOG_WARN("%s jResultCode == nullptr!", __func__);
|
||||
return false;
|
||||
}
|
||||
if (jResultCode->TypeOf() != NativeValueType::NATIVE_NUMBER) {
|
||||
HILOG_WARN("%s invalid type of resultCode!", __func__);
|
||||
return false;
|
||||
}
|
||||
resultCode = int64_t(*ConvertNativeValueTo<NativeNumber>(jObj->GetProperty("resultCode")));
|
||||
NativeValue* jWant = jObj->GetProperty("want");
|
||||
if (jWant == nullptr) {
|
||||
HILOG_WARN("%s jWant == nullptr!", __func__);
|
||||
return false;
|
||||
}
|
||||
if (jWant->TypeOf() != NativeValueType::NATIVE_OBJECT) {
|
||||
HILOG_WARN("%s invalid type of want!", __func__);
|
||||
return false;
|
||||
}
|
||||
return JsAbilityContext::UnWrapWant(engine, jWant, want);
|
||||
}
|
||||
|
||||
static NativeValue* WrapAbilityResult(NativeEngine& engine, const int& resultCode, const AAFwk::Want& want)
|
||||
{
|
||||
NativeValue* jAbilityResult = engine.CreateObject();
|
||||
NativeObject* abilityResult = ConvertNativeValueTo<NativeObject>(jAbilityResult);
|
||||
abilityResult->SetProperty("resultCode", engine.CreateNumber(resultCode));
|
||||
abilityResult->SetProperty("want", JsAbilityContext::WrapWant(engine, want));
|
||||
return jAbilityResult;
|
||||
}
|
||||
|
||||
std::weak_ptr<AbilityContext> context_;
|
||||
int curRequestCode_ = 0;
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
NativeValue* CreateJsAbilityContext(NativeEngine& engine, std::shared_ptr<AbilityContext> context)
|
||||
{
|
||||
NativeValue* objValue = CreateJsBaseContext(engine, context);
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
|
||||
std::unique_ptr<JsAbilityContext> jsContext = std::make_unique<JsAbilityContext>(context);
|
||||
object->SetNativePointer(jsContext.release(), JsAbilityContext::Finalizer, nullptr);
|
||||
|
||||
auto abilityInfo = context->GetAbilityInfo();
|
||||
if (abilityInfo != nullptr) {
|
||||
object->SetProperty("abilityInfo", CreateJsAbilityInfo(engine, *abilityInfo));
|
||||
}
|
||||
|
||||
BindNativeFunction(engine, *object, "startAbility", JsAbilityContext::StartAbility);
|
||||
BindNativeFunction(engine, *object, "startAbilityForResult", JsAbilityContext::StartAbilityForResult);
|
||||
BindNativeFunction(engine, *object, "connectAbility", JsAbilityContext::ConnectAbility);
|
||||
BindNativeFunction(engine, *object, "disconnectAbility", JsAbilityContext::DisconnectAbility);
|
||||
BindNativeFunction(engine, *object, "terminateSelf", JsAbilityContext::TerminateSelf);
|
||||
BindNativeFunction(engine, *object, "terminateSelfWithResult", JsAbilityContext::TerminateSelfWithResult);
|
||||
return objValue;
|
||||
}
|
||||
|
||||
JSAbilityConnection::JSAbilityConnection(NativeEngine* engine) : engine_(engine) {}
|
||||
|
||||
JSAbilityConnection::~JSAbilityConnection() = default;
|
||||
|
||||
void JSAbilityConnection::OnAbilityConnectDone(const AppExecFwk::ElementName &element,
|
||||
const sptr<IRemoteObject> &remoteObject, int resultCode)
|
||||
{
|
||||
HILOG_INFO("OnAbilityConnectDone begin, resultCode:%{public}d", resultCode);
|
||||
if (jsConnectionObject_ == nullptr) {
|
||||
HILOG_ERROR("jsConnectionObject_ nullptr");
|
||||
return;
|
||||
}
|
||||
NativeValue* value = jsConnectionObject_->Get();
|
||||
NativeObject* obj = ConvertNativeValueTo<NativeObject>(value);
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("Failed to get object");
|
||||
return;
|
||||
}
|
||||
NativeValue* methodOnConnect = obj->GetProperty("onConnect");
|
||||
if (methodOnConnect == nullptr) {
|
||||
HILOG_ERROR("Failed to get onConnect from object");
|
||||
return;
|
||||
}
|
||||
HILOG_INFO("JSAbilityConnection::CallFunction onConnect, success");
|
||||
// two params
|
||||
if (engine_ == nullptr) {
|
||||
HILOG_ERROR("engine_ nullptr");
|
||||
return;
|
||||
}
|
||||
// wrap RemoteObject
|
||||
HILOG_INFO("OnAbilityConnectDone begin NAPI_ohos_rpc_CreateJsRemoteObject");
|
||||
napi_value napiRemoteObject = NAPI_ohos_rpc_CreateJsRemoteObject(
|
||||
reinterpret_cast<napi_env>(engine_.get()), remoteObject);
|
||||
NativeValue* nativeRemoteObject = reinterpret_cast<NativeValue*>(napiRemoteObject);
|
||||
NativeValue* argv[] = { ConvertElement(element), nativeRemoteObject };
|
||||
engine_->CallFunction(value, methodOnConnect, argv, ARGC_TWO);
|
||||
HILOG_INFO("OnAbilityConnectDone end");
|
||||
}
|
||||
|
||||
void JSAbilityConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode)
|
||||
{
|
||||
HILOG_INFO("OnAbilityDisconnectDone begin, resultCode:%{public}d", resultCode);
|
||||
if (jsConnectionObject_ == nullptr) {
|
||||
HILOG_ERROR("jsConnectionObject_ nullptr");
|
||||
return;
|
||||
}
|
||||
NativeValue* value = jsConnectionObject_->Get();
|
||||
NativeObject* obj = ConvertNativeValueTo<NativeObject>(value);
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("Failed to get object");
|
||||
return;
|
||||
}
|
||||
|
||||
NativeValue* method = obj->GetProperty("onDisconnect");
|
||||
if (method == nullptr) {
|
||||
HILOG_ERROR("Failed to get onDisconnect from object");
|
||||
return;
|
||||
}
|
||||
|
||||
// release connect
|
||||
HILOG_INFO("OnAbilityDisconnectDone abilityConnects_.size:%{public}zu", abilityConnects_.size());
|
||||
std::string bundleName = element.GetBundleName();
|
||||
std::string abilityName = element.GetAbilityName();
|
||||
auto item = std::find_if(abilityConnects_.begin(), abilityConnects_.end(),
|
||||
[bundleName, abilityName] (const std::map<ConnectionKey, sptr<JSAbilityConnection>>::value_type &obj) {
|
||||
return (bundleName == obj.first.want.GetBundle()) &&
|
||||
(abilityName == obj.first.want.GetElement().GetAbilityName());
|
||||
});
|
||||
if (item != abilityConnects_.end()) {
|
||||
// match bundlename && abilityname
|
||||
abilityConnects_.erase(item);
|
||||
HILOG_INFO("OnAbilityDisconnectDone erase abilityConnects_.size:%{public}zu", abilityConnects_.size());
|
||||
}
|
||||
// one params
|
||||
if (engine_ == nullptr) {
|
||||
HILOG_ERROR("engine_ nullptr");
|
||||
return;
|
||||
}
|
||||
NativeValue* argv[] = { ConvertElement(element) };
|
||||
HILOG_INFO("OnAbilityDisconnectDone CallFunction success");
|
||||
engine_->CallFunction(value, method, argv, ARGC_ONE);
|
||||
}
|
||||
|
||||
void JSAbilityConnection::CallJsFailed()
|
||||
{
|
||||
HILOG_INFO("CallJsFailed begin");
|
||||
if (jsConnectionObject_ == nullptr) {
|
||||
HILOG_ERROR("jsConnectionObject_ nullptr");
|
||||
return;
|
||||
}
|
||||
NativeValue* value = jsConnectionObject_->Get();
|
||||
NativeObject* obj = ConvertNativeValueTo<NativeObject>(value);
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("Failed to get object");
|
||||
return;
|
||||
}
|
||||
|
||||
NativeValue* method = obj->GetProperty("onFailed");
|
||||
if (method == nullptr) {
|
||||
HILOG_ERROR("Failed to get onFailed from object");
|
||||
return;
|
||||
}
|
||||
if (engine_ == nullptr) {
|
||||
HILOG_ERROR("engine_ nullptr");
|
||||
return;
|
||||
}
|
||||
HILOG_INFO("CallJsFailed CallFunction success");
|
||||
// no params
|
||||
engine_->CallFunction(value, method, nullptr, ARGC_ZERO);
|
||||
HILOG_INFO("CallJsFailed end");
|
||||
}
|
||||
|
||||
NativeValue* JSAbilityConnection::ConvertElement(const AppExecFwk::ElementName &element)
|
||||
{
|
||||
napi_value napiElementName = OHOS::AppExecFwk::WrapElementName(reinterpret_cast<napi_env>(engine_.get()), element);
|
||||
return reinterpret_cast<NativeValue*>(napiElementName);
|
||||
}
|
||||
|
||||
void JSAbilityConnection::SetJsConnectionObject(NativeValue* jsConnectionObject)
|
||||
{
|
||||
jsConnectionObject_ = std::unique_ptr<NativeReference>(engine_->CreateReference(jsConnectionObject, 1));
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
392
frameworks/kits/ability/native/src/ability_thread.cpp
Normal file → Executable file
392
frameworks/kits/ability/native/src/ability_thread.cpp
Normal file → Executable file
@ -14,27 +14,35 @@
|
||||
*/
|
||||
|
||||
#include "ability_thread.h"
|
||||
#include "ohos_application.h"
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "ability_context_impl.h"
|
||||
#include "ability_impl_factory.h"
|
||||
#include "ability_loader.h"
|
||||
#include "ability_state.h"
|
||||
#include "ability_impl_factory.h"
|
||||
#include "page_ability_impl.h"
|
||||
#include "application_impl.h"
|
||||
#include "app_log_wrapper.h"
|
||||
#include "context_deal.h"
|
||||
#include "abs_shared_result_set.h"
|
||||
#include "app_log_wrapper.h"
|
||||
#include "application_impl.h"
|
||||
#include "bytrace.h"
|
||||
#include "context_deal.h"
|
||||
#include "data_ability_predicates.h"
|
||||
#include "values_bucket.h"
|
||||
#include "dataobs_mgr_client.h"
|
||||
#include "ohos_application.h"
|
||||
#include "page_ability_impl.h"
|
||||
#include "values_bucket.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
using AbilityManagerClient = OHOS::AAFwk::AbilityManagerClient;
|
||||
using DataObsMgrClient = OHOS::AAFwk::DataObsMgrClient;
|
||||
constexpr static char ABILITY_NAME[] = "Ability";
|
||||
constexpr static char ACE_ABILITY_NAME[] = "AceAbility";
|
||||
constexpr static char ACE_SERVICE_ABILITY_NAME[] = "AceServiceAbility";
|
||||
constexpr static char ACE_DATA_ABILITY_NAME[] = "AceDataAbility";
|
||||
constexpr static char ACE_FORM_ABILITY_NAME[] = "AceFormAbility";
|
||||
constexpr static char BASE_SERVICE_EXTENSION[] = "ServiceExtension";
|
||||
constexpr int TARGET_VERSION_THRESHOLDS = 8;
|
||||
|
||||
/**
|
||||
* @brief Default constructor used to create a AbilityThread instance.
|
||||
@ -76,7 +84,11 @@ std::string AbilityThread::CreateAbilityName(const std::shared_ptr<AbilityLocalR
|
||||
|
||||
if (abilityInfo->isNativeAbility == false) {
|
||||
if (abilityInfo->type == AbilityType::PAGE) {
|
||||
abilityName = ACE_ABILITY_NAME;
|
||||
if (abilityRecord->GetTargetVersion() >= TARGET_VERSION_THRESHOLDS) {
|
||||
abilityName = ABILITY_NAME;
|
||||
} else {
|
||||
abilityName = ACE_ABILITY_NAME;
|
||||
}
|
||||
} else if (abilityInfo->type == AbilityType::SERVICE) {
|
||||
if (abilityInfo->formEnabled == true) {
|
||||
abilityName = ACE_FORM_ABILITY_NAME;
|
||||
@ -85,6 +97,9 @@ std::string AbilityThread::CreateAbilityName(const std::shared_ptr<AbilityLocalR
|
||||
}
|
||||
} else if (abilityInfo->type == AbilityType::DATA) {
|
||||
abilityName = ACE_DATA_ABILITY_NAME;
|
||||
} else if (abilityInfo->type == AbilityType::EXTENSION) {
|
||||
abilityName = BASE_SERVICE_EXTENSION;
|
||||
APP_LOGI("CreateAbilityName extension type, abilityName:%{public}s", abilityName.c_str());
|
||||
} else {
|
||||
abilityName = abilityInfo->name;
|
||||
}
|
||||
@ -144,8 +159,10 @@ std::shared_ptr<ContextDeal> AbilityThread::CreateAndInitContextDeal(std::shared
|
||||
* @param mainRunner The runner which main_thread holds.
|
||||
*/
|
||||
void AbilityThread::Attach(std::shared_ptr<OHOSApplication> &application,
|
||||
const std::shared_ptr<AbilityLocalRecord> &abilityRecord, const std::shared_ptr<EventRunner> &mainRunner)
|
||||
const std::shared_ptr<AbilityLocalRecord> &abilityRecord, const std::shared_ptr<EventRunner> &mainRunner,
|
||||
const std::shared_ptr<AbilityRuntime::Context> &stageContext)
|
||||
{
|
||||
BYTRACE(BYTRACE_TAG_ABILITY_MANAGER);
|
||||
APP_LOGI("AbilityThread::Attach begin");
|
||||
if ((application == nullptr) || (abilityRecord == nullptr) || (mainRunner == nullptr)) {
|
||||
APP_LOGE("AbilityThread::ability attach failed,context or record is nullptr");
|
||||
@ -166,6 +183,7 @@ void AbilityThread::Attach(std::shared_ptr<OHOSApplication> &application,
|
||||
APP_LOGE("AbilityThread::ability attach failed,load ability failed");
|
||||
return;
|
||||
}
|
||||
ability->SetTargetVersion(abilityRecord->GetTargetVersion());
|
||||
|
||||
APP_LOGI("AbilityThread::new ability success.");
|
||||
currentAbility_.reset(ability);
|
||||
@ -177,9 +195,14 @@ void AbilityThread::Attach(std::shared_ptr<OHOSApplication> &application,
|
||||
std::shared_ptr<ContextDeal> contextDeal = CreateAndInitContextDeal(application, abilityRecord, abilityObject);
|
||||
ability->AttachBaseContext(contextDeal);
|
||||
|
||||
// new hap requires
|
||||
ability->AttachAbilityContext(BuildAbilityContext(abilityRecord->GetAbilityInfo(), application, token_,
|
||||
stageContext));
|
||||
|
||||
// 3.new abilityImpl
|
||||
abilityImpl_ =
|
||||
DelayedSingleton<AbilityImplFactory>::GetInstance()->MakeAbilityImplObject(abilityRecord->GetAbilityInfo());
|
||||
DelayedSingleton<AbilityImplFactory>::GetInstance()->MakeAbilityImplObject(abilityRecord->GetAbilityInfo(),
|
||||
abilityRecord->GetTargetVersion());
|
||||
if (abilityImpl_ == nullptr) {
|
||||
APP_LOGE("AbilityThread::ability abilityImpl_ == nullptr");
|
||||
return;
|
||||
@ -199,14 +222,130 @@ void AbilityThread::Attach(std::shared_ptr<OHOSApplication> &application,
|
||||
APP_LOGI("AbilityThread::Attach end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Attach The ability thread to the main process.
|
||||
* @param application Indicates the main process.
|
||||
* @param abilityRecord Indicates the abilityRecord.
|
||||
* @param mainRunner The runner which main_thread holds.
|
||||
*/
|
||||
void AbilityThread::AttachExtension(std::shared_ptr<OHOSApplication> &application,
|
||||
const std::shared_ptr<AbilityLocalRecord> &abilityRecord, const std::shared_ptr<EventRunner> &mainRunner)
|
||||
{
|
||||
BYTRACE(BYTRACE_TAG_ABILITY_MANAGER);
|
||||
APP_LOGI("AbilityThread::AttachExtension begin");
|
||||
if ((application == nullptr) || (abilityRecord == nullptr) || (mainRunner == nullptr)) {
|
||||
APP_LOGE("AbilityThread::AttachExtension attach failed,context or record is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
// 1.new AbilityHandler
|
||||
std::string abilityName = CreateAbilityName(abilityRecord);
|
||||
abilityHandler_ = std::make_shared<AbilityHandler>(mainRunner, this);
|
||||
if (abilityHandler_ == nullptr) {
|
||||
APP_LOGE("AbilityThread::AttachExtension attach failed,abilityHandler_ is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
// 2.new ability
|
||||
auto extension = AbilityLoader::GetInstance().GetExtensionByName(abilityName);
|
||||
if (extension == nullptr) {
|
||||
APP_LOGE("AbilityThread::AttachExtension attach failed,load ability failed");
|
||||
return;
|
||||
}
|
||||
|
||||
APP_LOGI("AbilityThread::new extension success.");
|
||||
currentExtension_.reset(extension);
|
||||
token_ = abilityRecord->GetToken();
|
||||
abilityRecord->SetEventHandler(abilityHandler_);
|
||||
abilityRecord->SetEventRunner(mainRunner);
|
||||
abilityRecord->SetAbilityThread(this);
|
||||
extensionImpl_ = std::make_shared<AbilityRuntime::ExtensionImpl>();
|
||||
if (extensionImpl_ == nullptr) {
|
||||
APP_LOGE("AbilityThread::extension extensionImpl_ == nullptr");
|
||||
return;
|
||||
}
|
||||
// 3.new init
|
||||
APP_LOGI("AbilityThread::extensionImpl_ init.");
|
||||
extensionImpl_->Init(application, abilityRecord, currentExtension_, abilityHandler_, token_);
|
||||
// 4.ipc attach init
|
||||
ErrCode err = AbilityManagerClient::GetInstance()->AttachAbilityThread(this, token_);
|
||||
APP_LOGI("AbilityThread::AttachExtension after AttachAbilityThread");
|
||||
if (err != ERR_OK) {
|
||||
APP_LOGE("AbilityThread:: attach extension success faile err = %{public}d", err);
|
||||
return;
|
||||
}
|
||||
APP_LOGI("AbilityThread::AttachExtension end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Attach The ability thread to the main process.
|
||||
* @param application Indicates the main process.
|
||||
* @param abilityRecord Indicates the abilityRecord.
|
||||
* @param mainRunner The runner which main_thread holds.
|
||||
*/
|
||||
void AbilityThread::AttachExtension(std::shared_ptr<OHOSApplication> &application,
|
||||
const std::shared_ptr<AbilityLocalRecord> &abilityRecord)
|
||||
{
|
||||
BYTRACE(BYTRACE_TAG_ABILITY_MANAGER);
|
||||
APP_LOGI("AbilityThread::AttachExtension begin");
|
||||
if ((application == nullptr) || (abilityRecord == nullptr)) {
|
||||
APP_LOGE("AbilityThread::AttachExtension failed,context or record is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
// 1.new AbilityHandler
|
||||
std::string abilityName = CreateAbilityName(abilityRecord);
|
||||
runner_ = EventRunner::Create(abilityName);
|
||||
if (runner_ == nullptr) {
|
||||
APP_LOGE("AbilityThread::AttachExtension failed,create runner failed");
|
||||
return;
|
||||
}
|
||||
abilityHandler_ = std::make_shared<AbilityHandler>(runner_, this);
|
||||
if (abilityHandler_ == nullptr) {
|
||||
APP_LOGE("AbilityThread::AttachExtension failed,abilityHandler_ is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
// 2.new ability
|
||||
auto extension = AbilityLoader::GetInstance().GetExtensionByName(abilityName);
|
||||
if (extension == nullptr) {
|
||||
APP_LOGE("AbilityThread::AttachExtension failed,load extension failed");
|
||||
return;
|
||||
}
|
||||
|
||||
APP_LOGI("AbilityThread::new extension success.");
|
||||
currentExtension_.reset(extension);
|
||||
token_ = abilityRecord->GetToken();
|
||||
abilityRecord->SetEventHandler(abilityHandler_);
|
||||
abilityRecord->SetEventRunner(runner_);
|
||||
abilityRecord->SetAbilityThread(this);
|
||||
extensionImpl_ = std::make_shared<AbilityRuntime::ExtensionImpl>();
|
||||
if (extensionImpl_ == nullptr) {
|
||||
APP_LOGE("AbilityThread::extension extensionImpl_ == nullptr");
|
||||
return;
|
||||
}
|
||||
// 3.new init
|
||||
extensionImpl_->Init(application, abilityRecord, currentExtension_, abilityHandler_, token_);
|
||||
// 4.ipc attach init
|
||||
ErrCode err = AbilityManagerClient::GetInstance()->AttachAbilityThread(this, token_);
|
||||
APP_LOGI("AbilityThread::Attach after AttachAbilityThread");
|
||||
if (err != ERR_OK) {
|
||||
APP_LOGE("AbilityThread:: AttachExtension failed err = %{public}d", err);
|
||||
return;
|
||||
}
|
||||
APP_LOGI("AbilityThread::AttachExtension end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Attach The ability thread to the main process.
|
||||
* @param application Indicates the main process.
|
||||
* @param abilityRecord Indicates the abilityRecord.
|
||||
*/
|
||||
void AbilityThread::Attach(
|
||||
std::shared_ptr<OHOSApplication> &application, const std::shared_ptr<AbilityLocalRecord> &abilityRecord)
|
||||
std::shared_ptr<OHOSApplication> &application, const std::shared_ptr<AbilityLocalRecord> &abilityRecord,
|
||||
const std::shared_ptr<AbilityRuntime::Context> &stageContext)
|
||||
{
|
||||
BYTRACE(BYTRACE_TAG_ABILITY_MANAGER);
|
||||
APP_LOGI("AbilityThread::Attach begin");
|
||||
if ((application == nullptr) || (abilityRecord == nullptr)) {
|
||||
APP_LOGE("AbilityThread::ability attach failed,context or record is nullptr");
|
||||
@ -231,6 +370,7 @@ void AbilityThread::Attach(
|
||||
APP_LOGE("AbilityThread::ability attach failed,load ability failed");
|
||||
return;
|
||||
}
|
||||
ability->SetTargetVersion(abilityRecord->GetTargetVersion());
|
||||
|
||||
APP_LOGI("AbilityThread::new ability success.");
|
||||
currentAbility_.reset(ability);
|
||||
@ -242,9 +382,14 @@ void AbilityThread::Attach(
|
||||
std::shared_ptr<ContextDeal> contextDeal = CreateAndInitContextDeal(application, abilityRecord, abilityObject);
|
||||
ability->AttachBaseContext(contextDeal);
|
||||
|
||||
// new hap requires
|
||||
ability->AttachAbilityContext(BuildAbilityContext(abilityRecord->GetAbilityInfo(), application, token_,
|
||||
stageContext));
|
||||
|
||||
// 3.new abilityImpl
|
||||
abilityImpl_ =
|
||||
DelayedSingleton<AbilityImplFactory>::GetInstance()->MakeAbilityImplObject(abilityRecord->GetAbilityInfo());
|
||||
DelayedSingleton<AbilityImplFactory>::GetInstance()->MakeAbilityImplObject(abilityRecord->GetAbilityInfo(),
|
||||
abilityRecord->GetTargetVersion());
|
||||
if (abilityImpl_ == nullptr) {
|
||||
APP_LOGE("AbilityThread::ability abilityImpl_ == nullptr");
|
||||
return;
|
||||
@ -271,6 +416,7 @@ void AbilityThread::Attach(
|
||||
*/
|
||||
void AbilityThread::HandleAbilityTransaction(const Want &want, const LifeCycleStateInfo &lifeCycleStateInfo)
|
||||
{
|
||||
BYTRACE(BYTRACE_TAG_ABILITY_MANAGER);
|
||||
APP_LOGI("AbilityThread::HandleAbilityTransaction begin");
|
||||
if (abilityImpl_ == nullptr) {
|
||||
APP_LOGE("AbilityThread::HandleAbilityTransaction abilityImpl_ == nullptr");
|
||||
@ -288,12 +434,31 @@ void AbilityThread::HandleAbilityTransaction(const Want &want, const LifeCycleSt
|
||||
APP_LOGI("AbilityThread::HandleAbilityTransaction end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Handle the life cycle of Extension.
|
||||
*
|
||||
* @param want Indicates the structure containing lifecycle information about the extension.
|
||||
* @param lifeCycleStateInfo Indicates the lifeCycleStateInfo.
|
||||
*/
|
||||
void AbilityThread::HandleExtensionTransaction(const Want &want, const LifeCycleStateInfo &lifeCycleStateInfo)
|
||||
{
|
||||
BYTRACE(BYTRACE_TAG_ABILITY_MANAGER);
|
||||
APP_LOGI("AbilityThread::HandleExtensionTransaction begin");
|
||||
if (extensionImpl_ == nullptr) {
|
||||
APP_LOGE("AbilityThread::HandleExtensionTransaction extensionImpl_ == nullptr");
|
||||
return;
|
||||
}
|
||||
extensionImpl_->HandleExtensionTransaction(want, lifeCycleStateInfo);
|
||||
APP_LOGI("AbilityThread::HandleAbilityTransaction end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Handle the current connection of Ability.
|
||||
* @param want Indicates the structure containing connection information about the ability.
|
||||
*/
|
||||
void AbilityThread::HandleConnectAbility(const Want &want)
|
||||
{
|
||||
BYTRACE(BYTRACE_TAG_ABILITY_MANAGER);
|
||||
APP_LOGI("AbilityThread::HandleConnectAbility begin");
|
||||
if (abilityImpl_ == nullptr) {
|
||||
APP_LOGE("AbilityThread::HandleConnectAbility abilityImpl_ == nullptr");
|
||||
@ -317,6 +482,7 @@ void AbilityThread::HandleConnectAbility(const Want &want)
|
||||
*/
|
||||
void AbilityThread::HandleDisconnectAbility(const Want &want)
|
||||
{
|
||||
BYTRACE(BYTRACE_TAG_ABILITY_MANAGER);
|
||||
APP_LOGI("AbilityThread::HandleDisconnectAbility begin");
|
||||
if (abilityImpl_ == nullptr) {
|
||||
APP_LOGE("AbilityThread::HandleDisconnectAbility abilityImpl_ == nullptr");
|
||||
@ -349,6 +515,7 @@ void AbilityThread::HandleDisconnectAbility(const Want &want)
|
||||
*/
|
||||
void AbilityThread::HandleCommandAbility(const Want &want, bool restart, int startId)
|
||||
{
|
||||
BYTRACE(BYTRACE_TAG_ABILITY_MANAGER);
|
||||
APP_LOGI("AbilityThread::HandleCommandAbility begin");
|
||||
APP_LOGI("AbilityThread::HandleCommandAbility before abilityImpl_->CommandAbility");
|
||||
abilityImpl_->CommandAbility(want, restart, startId);
|
||||
@ -362,6 +529,72 @@ void AbilityThread::HandleCommandAbility(const Want &want, bool restart, int sta
|
||||
APP_LOGI("AbilityThread::HandleCommandAbility end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Handle the current connection of Extension.
|
||||
*
|
||||
* @param want Indicates the structure containing connection information about the extension.
|
||||
*/
|
||||
void AbilityThread::HandleConnectExtension(const Want &want)
|
||||
{
|
||||
BYTRACE(BYTRACE_TAG_ABILITY_MANAGER);
|
||||
APP_LOGI("AbilityThread::HandleConnectExtension begin");
|
||||
if (extensionImpl_ == nullptr) {
|
||||
APP_LOGE("AbilityThread::HandleConnectExtension extensionImpl_ == nullptr");
|
||||
return;
|
||||
}
|
||||
sptr<IRemoteObject> service = extensionImpl_->ConnectExtension(want);
|
||||
ErrCode err = AbilityManagerClient::GetInstance()->ScheduleConnectAbilityDone(token_, service);
|
||||
if (err != ERR_OK) {
|
||||
APP_LOGE("AbilityThread::HandleConnectExtension failed err = %{public}d", err);
|
||||
}
|
||||
APP_LOGI("AbilityThread::HandleConnectExtension end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Handle the current disconnection of Extension.
|
||||
*/
|
||||
void AbilityThread::HandleDisconnectExtension(const Want &want)
|
||||
{
|
||||
BYTRACE(BYTRACE_TAG_ABILITY_MANAGER);
|
||||
APP_LOGI("AbilityThread::HandleDisconnectExtension begin");
|
||||
if (extensionImpl_ == nullptr) {
|
||||
APP_LOGE("AbilityThread::HandleDisconnectExtension extensionImpl_ == nullptr");
|
||||
return;
|
||||
}
|
||||
extensionImpl_->DisconnectExtension(want);
|
||||
ErrCode err = AbilityManagerClient::GetInstance()->ScheduleDisconnectAbilityDone(token_);
|
||||
if (err != ERR_OK) {
|
||||
APP_LOGE("AbilityThread:: HandleDisconnectExtension failed err = %{public}d", err);
|
||||
}
|
||||
APP_LOGI("AbilityThread::HandleDisconnectExtension end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Handle the current command of Extension.
|
||||
*
|
||||
* @param want The Want object to command to.
|
||||
* @param restart Indicates the startup mode. The value true indicates that Service is restarted after being
|
||||
* destroyed, and the value false indicates a normal startup.
|
||||
* @param startId Indicates the number of times the Service Extension has been started. The startId is incremented by 1
|
||||
* every time the Extension is started. For example, if the Extension has been started for six times,
|
||||
* the value of startId is 6.
|
||||
*/
|
||||
void AbilityThread::HandleCommandExtension(const Want &want, bool restart, int startId)
|
||||
{
|
||||
BYTRACE(BYTRACE_TAG_ABILITY_MANAGER);
|
||||
APP_LOGI("AbilityThread::HandleCommandExtension begin");
|
||||
if (extensionImpl_ == nullptr) {
|
||||
APP_LOGE("AbilityThread::HandleCommandExtension extensionImpl_ == nullptr");
|
||||
return;
|
||||
}
|
||||
extensionImpl_->CommandExtension(want, restart, startId);
|
||||
ErrCode err = AbilityManagerClient::GetInstance()->ScheduleCommandAbilityDone(token_);
|
||||
if (err != ERR_OK) {
|
||||
APP_LOGE("AbilityThread::HandleCommandExtension failed err = %{public}d", err);
|
||||
}
|
||||
APP_LOGI("AbilityThread::HandleCommandExtension end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Handle the restoreAbility state.
|
||||
* @param state Indicates save ability state used to dispatchRestoreAbilityState.
|
||||
@ -471,13 +704,17 @@ void AbilityThread::ScheduleAbilityTransaction(const Want &want, const LifeCycle
|
||||
|
||||
want.DumpInfo(0);
|
||||
|
||||
if ((token_ == nullptr) || abilityImpl_ == nullptr) {
|
||||
APP_LOGE("ScheduleAbilityTransaction::failed");
|
||||
if (token_ == nullptr) {
|
||||
APP_LOGE("ScheduleAbilityTransaction::failed, token_ nullptr");
|
||||
return;
|
||||
}
|
||||
auto task = [abilityThread = this, want, lifeCycleStateInfo]() {
|
||||
abilityThread->HandleAbilityTransaction(want, lifeCycleStateInfo);
|
||||
};
|
||||
if (abilityThread->isExtension_) {
|
||||
abilityThread->HandleExtensionTransaction(want, lifeCycleStateInfo);
|
||||
} else {
|
||||
abilityThread->HandleAbilityTransaction(want, lifeCycleStateInfo);
|
||||
}
|
||||
};
|
||||
|
||||
if (abilityHandler_ == nullptr) {
|
||||
APP_LOGE("AbilityThread::ScheduleAbilityTransaction abilityHandler_ == nullptr");
|
||||
@ -497,8 +734,14 @@ void AbilityThread::ScheduleAbilityTransaction(const Want &want, const LifeCycle
|
||||
*/
|
||||
void AbilityThread::ScheduleConnectAbility(const Want &want)
|
||||
{
|
||||
APP_LOGI("AbilityThread::ScheduleConnectAbility begin");
|
||||
auto task = [abilityThread = this, want]() { abilityThread->HandleConnectAbility(want); };
|
||||
APP_LOGI("AbilityThread::ScheduleConnectAbility begin, isExtension_:%{public}d", isExtension_);
|
||||
auto task = [abilityThread = this, want]() {
|
||||
if (abilityThread->isExtension_) {
|
||||
abilityThread->HandleConnectExtension(want);
|
||||
} else {
|
||||
abilityThread->HandleConnectAbility(want);
|
||||
}
|
||||
};
|
||||
|
||||
if (abilityHandler_ == nullptr) {
|
||||
APP_LOGE("AbilityThread::ScheduleConnectAbility abilityHandler_ == nullptr");
|
||||
@ -518,8 +761,14 @@ void AbilityThread::ScheduleConnectAbility(const Want &want)
|
||||
*/
|
||||
void AbilityThread::ScheduleDisconnectAbility(const Want &want)
|
||||
{
|
||||
APP_LOGI("AbilityThread::ScheduleDisconnectAbility begin");
|
||||
auto task = [abilityThread = this, want]() { abilityThread->HandleDisconnectAbility(want); };
|
||||
APP_LOGI("AbilityThread::ScheduleDisconnectAbility begin, isExtension_:%{public}d", isExtension_);
|
||||
auto task = [abilityThread = this, want]() {
|
||||
if (abilityThread->isExtension_) {
|
||||
abilityThread->HandleDisconnectExtension(want);
|
||||
} else {
|
||||
abilityThread->HandleDisconnectAbility(want);
|
||||
}
|
||||
};
|
||||
|
||||
if (abilityHandler_ == nullptr) {
|
||||
APP_LOGE("AbilityThread::ScheduleDisconnectAbility abilityHandler_ == nullptr");
|
||||
@ -547,10 +796,14 @@ void AbilityThread::ScheduleDisconnectAbility(const Want &want)
|
||||
*/
|
||||
void AbilityThread::ScheduleCommandAbility(const Want &want, bool restart, int startId)
|
||||
{
|
||||
APP_LOGI("AbilityThread::ScheduleCommandAbility begin");
|
||||
APP_LOGI("AbilityThread::ScheduleCommandAbility begin. startId:%{public}d", startId);
|
||||
auto task = [abilityThread = this, want, restart, startId]() {
|
||||
abilityThread->HandleCommandAbility(want, restart, startId);
|
||||
};
|
||||
if (abilityThread->isExtension_) {
|
||||
abilityThread->HandleCommandExtension(want, restart, startId);
|
||||
} else {
|
||||
abilityThread->HandleCommandAbility(want, restart, startId);
|
||||
}
|
||||
};
|
||||
|
||||
if (abilityHandler_ == nullptr) {
|
||||
APP_LOGE("AbilityThread::ScheduleCommandAbility abilityHandler_ == nullptr");
|
||||
@ -583,10 +836,22 @@ void AbilityThread::SendResult(int requestCode, int resultCode, const Want &want
|
||||
return;
|
||||
}
|
||||
|
||||
if (requestCode != -1) {
|
||||
APP_LOGI("AbilityThread::SendResult before abilityImpl_->SendResult");
|
||||
abilityImpl_->SendResult(requestCode, resultCode, want);
|
||||
APP_LOGI("AbilityThread::SendResult after abilityImpl_->SendResult");
|
||||
auto task = [this, requestCode, resultCode, want]() {
|
||||
if (requestCode != -1) {
|
||||
APP_LOGI("AbilityThread::SendResult before abilityImpl_->SendResult");
|
||||
abilityImpl_->SendResult(requestCode, resultCode, want);
|
||||
APP_LOGI("AbilityThread::SendResult after abilityImpl_->SendResult");
|
||||
}
|
||||
};
|
||||
|
||||
if (abilityHandler_ == nullptr) {
|
||||
APP_LOGE("AbilityThread::SendResult abilityHandler_ == nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
bool ret = abilityHandler_->PostTask(task);
|
||||
if (!ret) {
|
||||
APP_LOGE("AbilityThread::SendResult PostTask error");
|
||||
}
|
||||
APP_LOGI("AbilityThread::SendResult end");
|
||||
}
|
||||
@ -845,7 +1110,7 @@ int AbilityThread::BatchInsert(const Uri &uri, const std::vector<NativeRdb::Valu
|
||||
void AbilityThread::NotifyMultiWinModeChanged(int32_t winModeKey, bool flag)
|
||||
{
|
||||
APP_LOGI("NotifyMultiWinModeChanged.key:%{public}d,flag:%{public}d", winModeKey, flag);
|
||||
sptr<Window> window = currentAbility_->GetWindow();
|
||||
auto window = currentAbility_->GetWindow();
|
||||
if (window == nullptr) {
|
||||
APP_LOGE("NotifyMultiWinModeChanged window == nullptr");
|
||||
return;
|
||||
@ -855,7 +1120,7 @@ void AbilityThread::NotifyMultiWinModeChanged(int32_t winModeKey, bool 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);
|
||||
window->SetWindowType(Rosen::WindowType::WINDOW_TYPE_FLOAT);
|
||||
APP_LOGI("NotifyMultiWinModeChanged.SetWindowMode:WINDOW_MODE_FREE end.");
|
||||
} else {
|
||||
APP_LOGI("NotifyMultiWinModeChanged.key:%{public}d", winModeKey);
|
||||
@ -863,7 +1128,7 @@ void AbilityThread::NotifyMultiWinModeChanged(int32_t winModeKey, bool flag)
|
||||
} else {
|
||||
// false: free windowMode -> normal windowMode
|
||||
APP_LOGI("NotifyMultiWinModeChanged.SetWindowMode:WINDOW_MODE_TOP begin.");
|
||||
window->SetWindowType(WINDOW_TYPE_NORMAL);
|
||||
window->SetWindowType(Rosen::WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
|
||||
APP_LOGI("NotifyMultiWinModeChanged.SetWindowMode:WINDOW_MODE_TOP end.");
|
||||
}
|
||||
|
||||
@ -873,25 +1138,37 @@ void AbilityThread::NotifyMultiWinModeChanged(int32_t winModeKey, bool flag)
|
||||
void AbilityThread::NotifyTopActiveAbilityChanged(bool flag)
|
||||
{
|
||||
APP_LOGI("NotifyTopActiveAbilityChanged,flag:%{public}d", flag);
|
||||
sptr<Window> window = currentAbility_->GetWindow();
|
||||
auto window = currentAbility_->GetWindow();
|
||||
if (window == nullptr) {
|
||||
APP_LOGE("NotifyMultiWinModeChanged window == nullptr");
|
||||
return;
|
||||
}
|
||||
if (flag) {
|
||||
window->SwitchTop();
|
||||
window->RequestFocus();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void AbilityThread::NotifyContinuationResult(const int32_t result)
|
||||
{
|
||||
APP_LOGI("NotifyContinuationResult, result:%{public}d", result);
|
||||
if (abilityImpl_ == nullptr) {
|
||||
APP_LOGE("AbilityThread::NotifyContinuationResult abilityImpl_ is nullptr");
|
||||
return;
|
||||
}
|
||||
abilityImpl_->NotifyContinuationResult(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Attach The ability thread to the main process.
|
||||
* @param application Indicates the main process.
|
||||
* @param abilityRecord Indicates the abilityRecord.
|
||||
* @param mainRunner The runner which main_thread holds.
|
||||
* @param stageContext the AbilityStage context
|
||||
*/
|
||||
void AbilityThread::AbilityThreadMain(std::shared_ptr<OHOSApplication> &application,
|
||||
const std::shared_ptr<AbilityLocalRecord> &abilityRecord, const std::shared_ptr<EventRunner> &mainRunner)
|
||||
const std::shared_ptr<AbilityLocalRecord> &abilityRecord, const std::shared_ptr<EventRunner> &mainRunner,
|
||||
const std::shared_ptr<AbilityRuntime::Context> &stageContext)
|
||||
{
|
||||
APP_LOGI("AbilityThread::AbilityThreadMain begin");
|
||||
sptr<AbilityThread> thread = sptr<AbilityThread>(new (std::nothrow) AbilityThread());
|
||||
@ -899,7 +1176,12 @@ void AbilityThread::AbilityThreadMain(std::shared_ptr<OHOSApplication> &applicat
|
||||
APP_LOGE("AbilityThread::AbilityThreadMain failed,thread is nullptr");
|
||||
return;
|
||||
}
|
||||
thread->Attach(application, abilityRecord, mainRunner);
|
||||
thread->InitExtensionFlag(abilityRecord);
|
||||
if (thread->isExtension_) {
|
||||
thread->AttachExtension(application, abilityRecord, mainRunner);
|
||||
} else {
|
||||
thread->Attach(application, abilityRecord, mainRunner, stageContext);
|
||||
}
|
||||
APP_LOGI("AbilityThread::AbilityThreadMain end");
|
||||
}
|
||||
|
||||
@ -907,9 +1189,11 @@ void AbilityThread::AbilityThreadMain(std::shared_ptr<OHOSApplication> &applicat
|
||||
* @description: Attach The ability thread to the main process.
|
||||
* @param application Indicates the main process.
|
||||
* @param abilityRecord Indicates the abilityRecord.
|
||||
* @param stageContext the AbilityStage context
|
||||
*/
|
||||
void AbilityThread::AbilityThreadMain(
|
||||
std::shared_ptr<OHOSApplication> &application, const std::shared_ptr<AbilityLocalRecord> &abilityRecord)
|
||||
std::shared_ptr<OHOSApplication> &application, const std::shared_ptr<AbilityLocalRecord> &abilityRecord,
|
||||
const std::shared_ptr<AbilityRuntime::Context> &stageContext)
|
||||
{
|
||||
APP_LOGI("AbilityThread::AbilityThreadMain begin");
|
||||
sptr<AbilityThread> thread = sptr<AbilityThread>(new (std::nothrow) AbilityThread());
|
||||
@ -917,9 +1201,34 @@ void AbilityThread::AbilityThreadMain(
|
||||
APP_LOGE("AbilityThread::AbilityThreadMain failed,thread is nullptr");
|
||||
return;
|
||||
}
|
||||
thread->Attach(application, abilityRecord);
|
||||
thread->InitExtensionFlag(abilityRecord);
|
||||
if (thread->isExtension_) {
|
||||
thread->AttachExtension(application, abilityRecord);
|
||||
} else {
|
||||
thread->Attach(application, abilityRecord, stageContext);
|
||||
}
|
||||
APP_LOGI("AbilityThread::AbilityThreadMain end");
|
||||
}
|
||||
|
||||
void AbilityThread::InitExtensionFlag(const std::shared_ptr<AbilityLocalRecord> &abilityRecord)
|
||||
{
|
||||
APP_LOGI("AbilityThread::InitExtensionFlag start");
|
||||
if (abilityRecord == nullptr) {
|
||||
APP_LOGE("AbilityThread::InitExtensionFlag abilityRecord null");
|
||||
}
|
||||
std::shared_ptr<AbilityInfo> abilityInfo = abilityRecord->GetAbilityInfo();
|
||||
if (abilityInfo == nullptr) {
|
||||
APP_LOGE("AbilityThread::InitExtensionFlag abilityInfo null");
|
||||
}
|
||||
APP_LOGI("AbilityThread::InitExtensionFlag:%{public}d", abilityInfo->type);
|
||||
if (abilityInfo->type == AppExecFwk::AbilityType::EXTENSION) {
|
||||
APP_LOGI("AbilityThread::InitExtensionFlag true");
|
||||
isExtension_ = true;
|
||||
} else {
|
||||
isExtension_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Converts the given uri that refer to the Data ability into a normalized URI. A normalized URI can be used
|
||||
* across devices, persisted, backed up, and restored. It can refer to the same item in the Data ability even if the
|
||||
@ -1156,5 +1465,16 @@ std::vector<std::shared_ptr<DataAbilityResult>> AbilityThread::ExecuteBatch(
|
||||
APP_LOGI("AbilityThread::ExecuteBatch end");
|
||||
return results;
|
||||
}
|
||||
|
||||
std::shared_ptr<AbilityRuntime::AbilityContext> AbilityThread::BuildAbilityContext(
|
||||
const std::shared_ptr<AbilityInfo> &abilityInfo, const std::shared_ptr<OHOSApplication> &application,
|
||||
const sptr<IRemoteObject> &token, const std::shared_ptr<AbilityRuntime::Context> &stageContext)
|
||||
{
|
||||
auto abilityContextImpl = std::make_shared<AbilityRuntime::AbilityContextImpl>();
|
||||
abilityContextImpl->SetStageContext(stageContext);
|
||||
abilityContextImpl->SetToken(token);
|
||||
abilityContextImpl->SetAbilityInfo(abilityInfo);
|
||||
return abilityContextImpl;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ability_touchevent.h"
|
||||
#include "ability_impl.h"
|
||||
#include "app_log_wrapper.h"
|
||||
#include "ability_post_event_timeout.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
AbilityTouchEventHandle::AbilityTouchEventHandle(std::shared_ptr<AbilityImpl> abilityImpl) : abilityImpl_(abilityImpl)
|
||||
{
|
||||
APP_LOGI("AbilityTouchEventHandle is created");
|
||||
}
|
||||
|
||||
AbilityTouchEventHandle::~AbilityTouchEventHandle()
|
||||
{
|
||||
APP_LOGI("AbilityTouchEventHandle is destroyed");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called back when on touch.
|
||||
*/
|
||||
bool AbilityTouchEventHandle::OnTouch(const TouchEvent &touchEvent)
|
||||
{
|
||||
APP_LOGI("AbilityTouchEventHandle::OnTouch called.");
|
||||
bool ret = false;
|
||||
if (abilityImpl_ == nullptr) {
|
||||
APP_LOGE("AbilityTouchEventHandle::OnTouch abilityImpl_ is nullptr");
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string taskHead("OnTouch");
|
||||
std::string taskCodeAction = std::to_string(touchEvent.GetAction());
|
||||
std::string taskCodePhase = std::to_string(touchEvent.GetPhase());
|
||||
std::string taskSplit("-");
|
||||
auto timeOut =
|
||||
abilityImpl_->CreatePostEventTimeouter(taskHead + taskCodeAction + taskSplit + taskCodePhase + taskSplit);
|
||||
if (timeOut == nullptr) {
|
||||
APP_LOGW("AbilityTouchEventHandle::OnTouch timeouter Create return nullptr");
|
||||
ret = abilityImpl_->DoTouchEvent(touchEvent);
|
||||
} else {
|
||||
timeOut->TimingBegin();
|
||||
ret = abilityImpl_->DoTouchEvent(touchEvent);
|
||||
timeOut->TimeEnd();
|
||||
}
|
||||
|
||||
APP_LOGI("AbilityImpl::DoTouchEvent action: %{public}d phase: %{public}d.",
|
||||
touchEvent.GetAction(),
|
||||
touchEvent.GetPhase());
|
||||
return ret;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
@ -31,127 +31,35 @@ AbilityWindow::~AbilityWindow()
|
||||
*
|
||||
* @param handler The EventHandler of the Ability the AbilityWindow belong.
|
||||
*/
|
||||
void AbilityWindow::Init(std::shared_ptr<AbilityHandler> &handler, std::shared_ptr<Ability> ability)
|
||||
void AbilityWindow::Init(std::shared_ptr<AbilityHandler>& handler, std::shared_ptr<Ability> ability)
|
||||
{
|
||||
APP_LOGI("%{public}s begin.", __func__);
|
||||
handler_ = handler;
|
||||
ability_ = std::weak_ptr<IAbilityEvent>(ability);
|
||||
|
||||
auto wmi = WindowManager::GetInstance();
|
||||
if (wmi == nullptr) {
|
||||
APP_LOGE("AbilityWindow::Init WindowManager::GetInstance() is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
auto wret = wmi->Init();
|
||||
if (wret != WM_OK) {
|
||||
APP_LOGE("AbilityWindow::Init WindowManager::Init() return %d", wret);
|
||||
return;
|
||||
}
|
||||
windowScene_ = std::make_shared<Rosen::WindowScene>();
|
||||
APP_LOGI("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the window config for the host ability to create window.
|
||||
* @brief Sets the window option for the host ability to create window.
|
||||
*
|
||||
* @param config Indicates window config.
|
||||
* @param windowOption Indicates window option.
|
||||
*/
|
||||
bool AbilityWindow::SetWindowConfig(const sptr<WindowOption> &config)
|
||||
bool AbilityWindow::SetWindowType(Rosen::WindowType winType)
|
||||
{
|
||||
APP_LOGI("%{public}s begin.", __func__);
|
||||
|
||||
APP_LOGI("config width = %{public}d, height = %{public}d.", config->GetWidth(), config->GetHeight());
|
||||
APP_LOGI("config pos_x = %{public}d, pos_y = %{public}d, type = %{public}d.",
|
||||
config->GetX(),
|
||||
config->GetY(),
|
||||
config->GetWindowType());
|
||||
|
||||
auto wmi = WindowManager::GetInstance();
|
||||
if (wmi == nullptr) {
|
||||
APP_LOGE("AbilityWindow::Init WindowManager::GetInstance() is nullptr.");
|
||||
return false;
|
||||
}
|
||||
|
||||
APP_LOGI("%{public}s begin wms->CreateWindow.", __func__);
|
||||
auto retvalCreate = wmi->CreateWindow(windowNew_, config);
|
||||
APP_LOGI("%{public}s end wms->CreateWindow.", __func__);
|
||||
if (retvalCreate != WM_OK) {
|
||||
APP_LOGE("AbilityWindow::SetWindowConfig WindowManager::CreateWindow() return %d", retvalCreate);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (windowNew_ == nullptr) {
|
||||
APP_LOGE("AbilityWindow::SetWindowConfig the window is nullptr.");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto callback = [abilityWindow = this](KeyEvent event) -> bool { return abilityWindow->OnKeyEvent(event); };
|
||||
APP_LOGI("%{public}s begin windowNew_->RegistOnKeyCb.", __func__);
|
||||
auto retvalKeyboardKey = windowNew_->OnKey(callback);
|
||||
APP_LOGI("%{public}s end windowNew_->RegistOnKeyCb.", __func__);
|
||||
if (retvalKeyboardKey != WM_OK) {
|
||||
APP_LOGE("AbilityWindow::SetWindowConfig WindowManager::OnKey() return %d", retvalKeyboardKey);
|
||||
sptr<Rosen::IWindowLifeCycle> windowLifecycle = nullptr;
|
||||
std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = nullptr;
|
||||
windowScene_->Init(Rosen::WindowScene::DEFAULT_DISPLAY_ID, abilityContext, windowLifecycle);
|
||||
auto window = windowScene_->GetMainWindow();
|
||||
auto ret = window->SetWindowType(winType);
|
||||
if (ret != OHOS::Rosen::WMError::WM_OK) {
|
||||
APP_LOGE("Set window type error, errcode = %{public}d", ret);
|
||||
return false;
|
||||
}
|
||||
|
||||
isWindowAttached = true;
|
||||
APP_LOGI("%{public}s end.", __func__);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called when the KeyEvent sent.
|
||||
*
|
||||
* @param KeyEvent the key event.
|
||||
*
|
||||
* @return Returns true if the listener has processed the event; returns false otherwise.
|
||||
*
|
||||
*/
|
||||
bool AbilityWindow::OnKeyEvent(KeyEvent event)
|
||||
{
|
||||
APP_LOGI("%{public}s begin.", __func__);
|
||||
|
||||
bool ret = false;
|
||||
std::shared_ptr<IAbilityEvent> ability = nullptr;
|
||||
ability = ability_.lock();
|
||||
if (ability == nullptr) {
|
||||
APP_LOGE("AbilityWindow::OnKeyEvent ability is nullptr.");
|
||||
return ret;
|
||||
}
|
||||
switch (event.GetKeyCode()) {
|
||||
case OHOS::KeyEventEnum::KEY_BACK:
|
||||
APP_LOGI("AbilityWindow::OnKeyEvent Back key pressed.");
|
||||
if (!event.IsKeyDown()) {
|
||||
ret = OnBackPressed(ability);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
APP_LOGI("AbilityWindow::OnKeyEvent the key event is %{public}d.", event.GetKeyCode());
|
||||
break;
|
||||
}
|
||||
APP_LOGI("%{public}s end.", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called back when the Back key is pressed.
|
||||
*
|
||||
* @param ability The ability receive the event.
|
||||
*
|
||||
* @return Returns true if the listener has processed the event; returns false otherwise.
|
||||
*
|
||||
*/
|
||||
bool AbilityWindow::OnBackPressed(std::shared_ptr<IAbilityEvent> &ability)
|
||||
{
|
||||
APP_LOGI("%{public}s begin.", __func__);
|
||||
if (handler_ == nullptr) {
|
||||
APP_LOGE("AbilityWindow::OnBackPressed handler_ is nullptr.");
|
||||
return false;
|
||||
}
|
||||
auto task = [abilityRun = ability]() { abilityRun->OnBackPressed(); };
|
||||
handler_->PostTask(task);
|
||||
APP_LOGI("%{public}s end.", __func__);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -167,10 +75,10 @@ void AbilityWindow::OnPostAbilityStart()
|
||||
return;
|
||||
}
|
||||
|
||||
if (windowNew_ != nullptr) {
|
||||
APP_LOGI("%{public}s begin windowNew_->Hide.", __func__);
|
||||
windowNew_->Hide();
|
||||
APP_LOGI("%{public}s end windowNew_->Hide.", __func__);
|
||||
if (windowScene_) {
|
||||
APP_LOGI("%{public}s begin windowScene_->GoBackground.", __func__);
|
||||
windowScene_->GoBackground();
|
||||
APP_LOGI("%{public}s end windowScene_->GoBackground.", __func__);
|
||||
}
|
||||
|
||||
APP_LOGI("%{public}s end.", __func__);
|
||||
@ -188,14 +96,14 @@ void AbilityWindow::OnPostAbilityActive()
|
||||
return;
|
||||
}
|
||||
|
||||
if (windowNew_ != nullptr) {
|
||||
APP_LOGI("%{public}s begin windowNew_->SwitchTop.", __func__);
|
||||
windowNew_->SwitchTop();
|
||||
APP_LOGI("%{public}s end windowNew_->SwitchTop.", __func__);
|
||||
if (windowScene_) {
|
||||
APP_LOGI("%{public}s begin windowScene_->RequestFocus.", __func__);
|
||||
windowScene_->RequestFocus();
|
||||
APP_LOGI("%{public}s end windowScene_->RequestFocus.", __func__);
|
||||
|
||||
APP_LOGI("%{public}s begin windowNew_->Show.", __func__);
|
||||
windowNew_->Show();
|
||||
APP_LOGI("%{public}s end windowNew_->Show.", __func__);
|
||||
APP_LOGI("%{public}s begin windowScene_->GoForeground.", __func__);
|
||||
windowScene_->GoForeground();
|
||||
APP_LOGI("%{public}s end windowScene_->GoForeground.", __func__);
|
||||
}
|
||||
|
||||
APP_LOGI("AbilityWindow::OnPostAbilityActive end.");
|
||||
@ -213,10 +121,10 @@ void AbilityWindow::OnPostAbilityInactive()
|
||||
return;
|
||||
}
|
||||
|
||||
if (windowNew_ != nullptr) {
|
||||
APP_LOGI("%{public}s begin windowNew_->Hide.", __func__);
|
||||
windowNew_->Hide();
|
||||
APP_LOGI("%{public}s end windowNew_->Hide.", __func__);
|
||||
if (windowScene_) {
|
||||
APP_LOGI("%{public}s begin windowScene_->GoBackground.", __func__);
|
||||
windowScene_->GoBackground();
|
||||
APP_LOGI("%{public}s end windowScene_->GoBackground.", __func__);
|
||||
}
|
||||
|
||||
APP_LOGI("AbilityWindow::OnPostAbilityInactive end.");
|
||||
@ -234,10 +142,10 @@ void AbilityWindow::OnPostAbilityBackground()
|
||||
return;
|
||||
}
|
||||
|
||||
if (windowNew_ != nullptr) {
|
||||
APP_LOGI("%{public}s begin windowNew_->Hide.", __func__);
|
||||
windowNew_->Hide();
|
||||
APP_LOGI("%{public}s end windowNew_->Hide.", __func__);
|
||||
if (windowScene_) {
|
||||
APP_LOGI("%{public}s begin windowScene_->GoBackground.", __func__);
|
||||
windowScene_->GoBackground();
|
||||
APP_LOGI("%{public}s end windowScene_->GoBackground.", __func__);
|
||||
}
|
||||
|
||||
APP_LOGI("AbilityWindow::OnPostAbilityBackground end.");
|
||||
@ -255,10 +163,10 @@ void AbilityWindow::OnPostAbilityForeground()
|
||||
return;
|
||||
}
|
||||
|
||||
if (windowNew_ != nullptr) {
|
||||
APP_LOGI("%{public}s begin windowNew_->Show.", __func__);
|
||||
windowNew_->Show();
|
||||
APP_LOGI("%{public}s end windowNew_->Show.", __func__);
|
||||
if (windowScene_) {
|
||||
APP_LOGI("%{public}s begin windowScene_->GoForeground.", __func__);
|
||||
windowScene_->GoForeground();
|
||||
APP_LOGI("%{public}s end windowScene_->GoForeground.", __func__);
|
||||
}
|
||||
|
||||
APP_LOGI("AbilityWindow::OnPostAbilityForeground end.");
|
||||
@ -276,13 +184,10 @@ void AbilityWindow::OnPostAbilityStop()
|
||||
return;
|
||||
}
|
||||
|
||||
if (windowNew_ != nullptr) {
|
||||
int32_t windowID = windowNew_->GetID();
|
||||
APP_LOGI("AbilityWindow::widow::DestroyWindow called windowID=%{public}d begin.", windowID);
|
||||
windowNew_->Destroy();
|
||||
APP_LOGI("AbilityWindow::widow::DestroyWindow called windowID=%{public}d end.", windowID);
|
||||
windowNew_ = nullptr;
|
||||
APP_LOGI("AbilityWindow::widow:: windowNew_ release end.");
|
||||
if (windowScene_) {
|
||||
windowScene_->~WindowScene();
|
||||
windowScene_ = nullptr;
|
||||
APP_LOGI("AbilityWindow::widow:: windowScene_ release end.");
|
||||
}
|
||||
|
||||
isWindowAttached = false;
|
||||
@ -294,16 +199,12 @@ void AbilityWindow::OnPostAbilityStop()
|
||||
*
|
||||
* @return Returns a Window object pointer.
|
||||
*/
|
||||
const sptr<Window> AbilityWindow::GetWindow()
|
||||
const sptr<Rosen::Window> AbilityWindow::GetWindow()
|
||||
{
|
||||
if (!isWindowAttached) {
|
||||
APP_LOGE("AbilityWindow::GetWindow window not attached.");
|
||||
}
|
||||
|
||||
if (windowNew_ == nullptr) {
|
||||
APP_LOGE("AbilityWindow::GetWindow the window is nullptr.");
|
||||
}
|
||||
return windowNew_;
|
||||
return windowScene_ ? windowScene_->GetMainWindow() : nullptr;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
@ -1,89 +0,0 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#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
|
@ -1,49 +0,0 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#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
|
@ -13,9 +13,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "continuation_handler.h"
|
||||
#include "element_name.h"
|
||||
#include "distributed_client.h"
|
||||
|
||||
#include "ability_manager_client.h"
|
||||
#include "app_log_wrapper.h"
|
||||
#include "distributed_client.h"
|
||||
#include "element_name.h"
|
||||
|
||||
using OHOS::AAFwk::WantParams;
|
||||
namespace OHOS {
|
||||
@ -70,7 +72,7 @@ bool ContinuationHandler::HandleStartContinuation(const sptr<IRemoteObject> &tok
|
||||
Want want = SetWantParams(wantParams);
|
||||
want.SetElementName(deviceId, abilityInfo_->bundleName, abilityInfo_->name);
|
||||
|
||||
int result = DistributedClient::GetInstance()->StartContinuation(want, *abilityInfo_, token);
|
||||
int result = AAFwk::AbilityManagerClient::GetInstance()->StartContinuation(want, token);
|
||||
if (result != 0) {
|
||||
APP_LOGE("distClient_.startContinuation failed.");
|
||||
return false;
|
||||
|
125
frameworks/kits/ability/native/src/continuation/distributed/continuation_manager.cpp
Normal file → Executable file
125
frameworks/kits/ability/native/src/continuation/distributed/continuation_manager.cpp
Normal file → Executable file
@ -14,15 +14,15 @@
|
||||
*/
|
||||
|
||||
#include "continuation_manager.h"
|
||||
|
||||
#include "ability.h"
|
||||
#include "ability_continuation_interface.h"
|
||||
#include "continuation_handler.h"
|
||||
#include "app_log_wrapper.h"
|
||||
#include "want.h"
|
||||
#include "continuation_scheduler.h"
|
||||
#include "continuation_handler.h"
|
||||
#include "distributed_client.h"
|
||||
#include "string_ex.h"
|
||||
#include "operation_builder.h"
|
||||
#include "string_ex.h"
|
||||
#include "want.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
@ -181,7 +181,6 @@ void ContinuationManager::NotifyCompleteContinuation(
|
||||
const std::string &originDeviceId, int sessionId, bool success, const sptr<IRemoteObject> &reverseScheduler)
|
||||
{
|
||||
APP_LOGI("%{public}s called begin", __func__);
|
||||
InitDistSchedulerHost();
|
||||
DistributedClient::GetInstance()->NotifyCompleteContinuation(
|
||||
Str8ToStr16(originDeviceId), sessionId, success, reverseScheduler);
|
||||
APP_LOGI("%{public}s called end", __func__);
|
||||
@ -278,11 +277,6 @@ bool ContinuationManager::HandleContinueAbility(bool reversible, const std::stri
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!RegisterAbilityTokenIfNeed(continueToken_)) {
|
||||
APP_LOGE("ContinuationManager::HandleContinueAbility failed. RegisterAbilityTokenIfNeed failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> continueToken = continueToken_;
|
||||
std::shared_ptr<ContinuationHandler> continuationHandler = continuationHandler_.lock();
|
||||
if (continuationHandler == nullptr) {
|
||||
@ -291,9 +285,11 @@ bool ContinuationManager::HandleContinueAbility(bool reversible, const std::stri
|
||||
}
|
||||
continuationHandler->SetReversible(reversible);
|
||||
|
||||
InitMainHandlerIfNeed();
|
||||
auto task = [continuationHandler, continueToken, deviceId]() {
|
||||
continuationHandler->HandleStartContinuation(continueToken, deviceId);
|
||||
};
|
||||
|
||||
if (!mainHandler_->PostTask(task)) {
|
||||
APP_LOGE("ContinuationManager::HandleContinueAbility failed.PostTask failed");
|
||||
return false;
|
||||
@ -318,6 +314,12 @@ void ContinuationManager::ChangeProcessState(const ProgressState &newState)
|
||||
progressState_ = newState;
|
||||
}
|
||||
|
||||
|
||||
void ContinuationManager::ChangeProcessStateToInit()
|
||||
{
|
||||
ChangeProcessState(ProgressState::INITIAL);
|
||||
}
|
||||
|
||||
void ContinuationManager::RestoreStateWhenTimeout(long timeoutInMs, const ProgressState &preState)
|
||||
{
|
||||
APP_LOGI("%{public}s called begin", __func__);
|
||||
@ -360,109 +362,6 @@ bool ContinuationManager::CheckAbilityToken()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ContinuationManager::UnregisterAbilityTokenIfNeed()
|
||||
{
|
||||
APP_LOGI("%{public}s called begin", __func__);
|
||||
|
||||
if (continueToken_ == nullptr) {
|
||||
APP_LOGE("%{public}s called failed continueToken_ is nullptr", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!tokenRegistered_) {
|
||||
APP_LOGI("%{public}s called no need to :Unregister", __func__);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock_l(lockForRegist_);
|
||||
|
||||
if (!tokenRegistered_) {
|
||||
APP_LOGI("%{public}s called no need to :Unregister", __func__);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool unregisterSuccess = UnregisterAbilityToken(continueToken_);
|
||||
if (unregisterSuccess) {
|
||||
tokenRegistered_ = false;
|
||||
}
|
||||
|
||||
APP_LOGI("%{public}s called end", __func__);
|
||||
return unregisterSuccess;
|
||||
}
|
||||
|
||||
bool ContinuationManager::UnregisterAbilityToken(const sptr<IRemoteObject> &token)
|
||||
{
|
||||
APP_LOGI("%{public}s called begin", __func__);
|
||||
int result = -1;
|
||||
|
||||
if (distSchedulerHost_ == nullptr) {
|
||||
APP_LOGE("%{public}s called failed. distSchedulerHost_ is nullptr", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
result = DistributedClient::GetInstance()->UnregisterAbilityToken(token, distSchedulerHost_);
|
||||
if (result != -1) {
|
||||
std::string interfaceName = "unregisterAbilityToken";
|
||||
CheckDmsInterfaceResult(result, interfaceName);
|
||||
}
|
||||
|
||||
APP_LOGI("%{public}s called end", __func__);
|
||||
return (result == NO_ERROR);
|
||||
}
|
||||
|
||||
bool ContinuationManager::RegisterAbilityTokenIfNeed(const sptr<IRemoteObject> &token)
|
||||
{
|
||||
APP_LOGI("%{public}s called begin", __func__);
|
||||
if (tokenRegistered_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock_l(lockForRegist_);
|
||||
|
||||
if (tokenRegistered_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool registerSuccess = RegisterAbilityToken(token);
|
||||
if (registerSuccess) {
|
||||
tokenRegistered_ = true;
|
||||
}
|
||||
APP_LOGI("%{public}s called end", __func__);
|
||||
return registerSuccess;
|
||||
}
|
||||
|
||||
bool ContinuationManager::RegisterAbilityToken(const sptr<IRemoteObject> &token)
|
||||
{
|
||||
APP_LOGI("%{public}s called begin", __func__);
|
||||
int result = -1;
|
||||
|
||||
InitDistSchedulerHost();
|
||||
|
||||
result = DistributedClient::GetInstance()->RegisterAbilityToken(token, distSchedulerHost_);
|
||||
if (result != -1) {
|
||||
std::string interfaceName = "registerAbilityToken";
|
||||
CheckDmsInterfaceResult(result, interfaceName);
|
||||
}
|
||||
APP_LOGI("%{public}s called end", __func__);
|
||||
return (result == NO_ERROR);
|
||||
}
|
||||
|
||||
void ContinuationManager::InitDistSchedulerHost()
|
||||
{
|
||||
APP_LOGI("%{public}s called begin", __func__);
|
||||
if (distSchedulerHost_ == nullptr) {
|
||||
InitMainHandlerIfNeed();
|
||||
std::weak_ptr<IDistributeScheduleHandler> continuationHandler = continuationHandler_;
|
||||
distSchedulerHost_ =
|
||||
sptr<ContinuationScheduler>(new (std::nothrow) ContinuationScheduler(continuationHandler, mainHandler_));
|
||||
if (distSchedulerHost_ == nullptr) {
|
||||
APP_LOGE("AbilityThread::AbilityThreadMain failed,thread is nullptr");
|
||||
return;
|
||||
}
|
||||
}
|
||||
APP_LOGI("%{public}s called end", __func__);
|
||||
}
|
||||
|
||||
void ContinuationManager::CheckDmsInterfaceResult(int result, const std::string &interfaceName)
|
||||
{
|
||||
APP_LOGI("ContinuationManager::CheckDmsInterfaceResult called. interfaceName: %{public}s, result: %{public}d.",
|
||||
|
@ -1,118 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "continuation_scheduler.h"
|
||||
#include "app_log_wrapper.h"
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
std::mutex ContinuationScheduler::mutex_;
|
||||
ContinuationScheduler::ContinuationScheduler(
|
||||
std::weak_ptr<IDistributeScheduleHandler> &callback, std::shared_ptr<EventHandler> &mainHandler)
|
||||
{
|
||||
if (mainHandler == nullptr) {
|
||||
APP_LOGE("Handler can not be nullptr.");
|
||||
}
|
||||
callback_ = callback;
|
||||
mainHandler_ = mainHandler;
|
||||
}
|
||||
|
||||
void ContinuationScheduler::ScheduleCompleteContinuation(int result)
|
||||
{
|
||||
APP_LOGI("%{public}s called begin", __func__);
|
||||
auto task = [continuationScheduler = this, result]() {
|
||||
continuationScheduler->HandleCompleteContinuation(result);
|
||||
};
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
if (mainHandler_ == nullptr) {
|
||||
APP_LOGE("ContinuationScheduler::ScheduleCompleteContinuation mainHandler_ == nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
bool ret = mainHandler_->PostTask(task);
|
||||
if (!ret) {
|
||||
APP_LOGE("ContinuationScheduler::ScheduleCompleteContinuation PostTask error");
|
||||
return;
|
||||
}
|
||||
APP_LOGI("%{public}s called end", __func__);
|
||||
}
|
||||
|
||||
void ContinuationScheduler::ReceiveReplicaScheduler(const sptr<IRemoteObject> &remoteReplica)
|
||||
{
|
||||
APP_LOGI("%{public}s called begin", __func__);
|
||||
if (remoteReplica == nullptr) {
|
||||
APP_LOGE("ContinuationScheduler::ReceiveReplicaScheduler remoteReplica is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
auto task = [continuationScheduler = this, remoteReplica]() {
|
||||
continuationScheduler->HandleReceiveReplicaScheduler(remoteReplica);
|
||||
};
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
if (mainHandler_ == nullptr) {
|
||||
APP_LOGE("ContinuationScheduler::ReceiveReplicaScheduler mainHandler_ == nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
bool ret = mainHandler_->PostTask(task);
|
||||
if (!ret) {
|
||||
APP_LOGE("ContinuationScheduler::ReceiveReplicaScheduler PostTask error");
|
||||
return;
|
||||
}
|
||||
APP_LOGI("%{public}s called end", __func__);
|
||||
}
|
||||
|
||||
void ContinuationScheduler::HandleReceiveReplicaScheduler(const sptr<IRemoteObject> &remoteReplica)
|
||||
{
|
||||
APP_LOGI("%{public}s called begin", __func__);
|
||||
std::shared_ptr<IDistributeScheduleHandler> callback = nullptr;
|
||||
if (GetCallback(callback)) {
|
||||
callback->HandleReceiveRemoteScheduler(remoteReplica);
|
||||
return;
|
||||
}
|
||||
APP_LOGI("%{public}s called end", __func__);
|
||||
}
|
||||
|
||||
void ContinuationScheduler::HandleCompleteContinuation(int result)
|
||||
{
|
||||
APP_LOGI("%{public}s called begin", __func__);
|
||||
std::shared_ptr<IDistributeScheduleHandler> callback = nullptr;
|
||||
if (GetCallback(callback)) {
|
||||
callback->HandleCompleteContinuation(result);
|
||||
return;
|
||||
}
|
||||
APP_LOGI("%{public}s called end", __func__);
|
||||
}
|
||||
|
||||
bool ContinuationScheduler::GetCallback(std::shared_ptr<IDistributeScheduleHandler> &callback)
|
||||
{
|
||||
APP_LOGI("%{public}s called begin", __func__);
|
||||
if (callback != nullptr) {
|
||||
APP_LOGE("ContinuationScheduler::GetCallback callback is not inited");
|
||||
return false;
|
||||
}
|
||||
|
||||
callback = callback_.lock();
|
||||
if (callback == nullptr) {
|
||||
APP_LOGE("ContinuationScheduler::GetCallback callback get failed");
|
||||
return false;
|
||||
}
|
||||
APP_LOGI("%{public}s called end", __func__);
|
||||
return true;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "continuation_scheduler_stub.h"
|
||||
#include "ipc_types.h"
|
||||
#include "string_ex.h"
|
||||
#include "app_log_wrapper.h"
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
ContinuationSchedulerStub::ContinuationSchedulerStub()
|
||||
{
|
||||
requestFuncMap_[SCHEDULE_COMPLETE_CONTINUATION] =
|
||||
&ContinuationSchedulerStub::ScheduleCompleteContinuationInner;
|
||||
requestFuncMap_[RECEIVE_REPLICA_SCHEDULER] = &ContinuationSchedulerStub::ReceiveReplicaSchedulerInner;
|
||||
}
|
||||
|
||||
ContinuationSchedulerStub::~ContinuationSchedulerStub()
|
||||
{
|
||||
requestFuncMap_.clear();
|
||||
}
|
||||
|
||||
int ContinuationSchedulerStub::ReceiveReplicaSchedulerInner(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
APP_LOGI("%{public}s called begin", __func__);
|
||||
auto remoteReplica = data.ReadParcelable<IRemoteObject>();
|
||||
ReceiveReplicaScheduler(remoteReplica);
|
||||
APP_LOGI("%{public}s called end", __func__);
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int ContinuationSchedulerStub::ScheduleCompleteContinuationInner(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
APP_LOGI("%{public}s called begin", __func__);
|
||||
int result = data.ReadInt32();
|
||||
ScheduleCompleteContinuation(result);
|
||||
APP_LOGI("%{public}s called end", __func__);
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int ContinuationSchedulerStub::OnRemoteRequest(
|
||||
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
APP_LOGI("%{public}s called begin", __func__);
|
||||
std::u16string descriptor = ContinuationSchedulerStub::GetDescriptor();
|
||||
std::u16string remoteDescriptor = data.ReadInterfaceToken();
|
||||
if (descriptor != remoteDescriptor) {
|
||||
APP_LOGI("local descriptor is not equal to remote");
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
auto itFunc = requestFuncMap_.find(code);
|
||||
if (itFunc != requestFuncMap_.end()) {
|
||||
auto requestFunc = itFunc->second;
|
||||
if (requestFunc != nullptr) {
|
||||
return (this->*requestFunc)(data, reply);
|
||||
}
|
||||
}
|
||||
APP_LOGI("ContinuationSchedulerStub::OnRemoteRequest, default case, need check.");
|
||||
APP_LOGI("%{public}s called end", __func__);
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
@ -68,69 +68,6 @@ ErrCode DistributedClient::Connect()
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode DistributedClient::StartRemoteAbility(
|
||||
const Want &want, const AppExecFwk::AbilityInfo &abilityInfo, int32_t requestCode)
|
||||
{
|
||||
APP_LOGI("%{public}s called", __func__);
|
||||
if (remoteObject_ == nullptr) {
|
||||
ErrCode err = Connect();
|
||||
if (err != ERR_OK) {
|
||||
return DISTRIBUTED_ABILITY_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
ErrCode DistributedClient::StartContinuation(
|
||||
const Want &want, const AppExecFwk::AbilityInfo &abilityInfo, const sptr<IRemoteObject> &abilityToken)
|
||||
{
|
||||
APP_LOGI("%{public}s called", __func__);
|
||||
if (remoteObject_ == nullptr) {
|
||||
ErrCode err = Connect();
|
||||
if (err != ERR_OK) {
|
||||
return DISTRIBUTED_ABILITY_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
}
|
||||
if (abilityToken == nullptr) {
|
||||
return INCOMING_PARAMETER_POINTER_IS_NULL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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 0;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@ -143,39 +80,7 @@ ErrCode DistributedClient::NotifyCompleteContinuation(
|
||||
}
|
||||
|
||||
// there need a params for reverseScheduler
|
||||
return 0;
|
||||
}
|
||||
|
||||
ErrCode DistributedClient::RegisterAbilityToken(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &appThread)
|
||||
{
|
||||
APP_LOGI("%{public}s called", __func__);
|
||||
if (remoteObject_ == nullptr) {
|
||||
ErrCode err = Connect();
|
||||
if (err != ERR_OK) {
|
||||
return DISTRIBUTED_ABILITY_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
}
|
||||
if (token == nullptr || appThread == nullptr) {
|
||||
return INCOMING_PARAMETER_POINTER_IS_NULL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
ErrCode DistributedClient::UnregisterAbilityToken(
|
||||
const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &appThread)
|
||||
{
|
||||
APP_LOGI("%{public}s called", __func__);
|
||||
if (remoteObject_ == nullptr) {
|
||||
ErrCode err = Connect();
|
||||
if (err != ERR_OK) {
|
||||
return DISTRIBUTED_ABILITY_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
}
|
||||
if (token == nullptr || appThread == nullptr) {
|
||||
return INCOMING_PARAMETER_POINTER_IS_NULL;
|
||||
}
|
||||
|
||||
dmsProxy_->NotifyCompleteContinuation(devId, sessionId, isSuccess);
|
||||
return 0;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
|
5
frameworks/kits/ability/native/src/continuation/remote_register_service/connect_callback_proxy.cpp
Normal file → Executable file
5
frameworks/kits/ability/native/src/continuation/remote_register_service/connect_callback_proxy.cpp
Normal file → Executable file
@ -13,11 +13,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "connect_callback_proxy.h"
|
||||
|
||||
#include "app_log_wrapper.h"
|
||||
#include "extra_params.h"
|
||||
#include "string_ex.h"
|
||||
#include "app_log_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
|
||||
/**
|
||||
* @brief Remote device sends connection request.
|
||||
* @param deviceId indicators id of connection device.
|
||||
|
3
frameworks/kits/ability/native/src/continuation/remote_register_service/connect_callback_stub.cpp
Normal file → Executable file
3
frameworks/kits/ability/native/src/continuation/remote_register_service/connect_callback_stub.cpp
Normal file → Executable file
@ -13,9 +13,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "connect_callback_stub.h"
|
||||
|
||||
#include "app_log_wrapper.h"
|
||||
#include "ipc_types.h"
|
||||
#include "string_ex.h"
|
||||
#include "app_log_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
|
3
frameworks/kits/ability/native/src/continuation/remote_register_service/continuation_connector.cpp
Normal file → Executable file
3
frameworks/kits/ability/native/src/continuation/remote_register_service/continuation_connector.cpp
Normal file → Executable file
@ -14,9 +14,10 @@
|
||||
*/
|
||||
|
||||
#include "continuation_connector.h"
|
||||
|
||||
#include "app_log_wrapper.h"
|
||||
#include "remote_register_service_proxy.h"
|
||||
#include "continuation_device_callback_proxy.h"
|
||||
#include "remote_register_service_proxy.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
|
3
frameworks/kits/ability/native/src/continuation/remote_register_service/continuation_register_manager.cpp
Normal file → Executable file
3
frameworks/kits/ability/native/src/continuation/remote_register_service/continuation_register_manager.cpp
Normal file → Executable file
@ -13,9 +13,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "continuation_register_manager.h"
|
||||
|
||||
#include "app_log_wrapper.h"
|
||||
#include "continuation_register_manager_proxy.h"
|
||||
#include "continuation_device_callback_interface.h"
|
||||
#include "continuation_register_manager_proxy.h"
|
||||
#include "extra_params.h"
|
||||
#include "request_callback.h"
|
||||
|
||||
|
7
frameworks/kits/ability/native/src/continuation/remote_register_service/continuation_register_manager_proxy.cpp
Normal file → Executable file
7
frameworks/kits/ability/native/src/continuation/remote_register_service/continuation_register_manager_proxy.cpp
Normal file → Executable file
@ -13,12 +13,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "continuation_register_manager_proxy.h"
|
||||
|
||||
#include "app_log_wrapper.h"
|
||||
#include "continuation_device_callback_interface.h"
|
||||
#include "request_callback.h"
|
||||
#include "continuation_request.h"
|
||||
#include "context.h"
|
||||
#include "continuation_connector.h"
|
||||
#include "continuation_device_callback_interface.h"
|
||||
#include "continuation_request.h"
|
||||
#include "request_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
|
15
frameworks/kits/ability/native/src/data_ability_helper.cpp
Normal file → Executable file
15
frameworks/kits/ability/native/src/data_ability_helper.cpp
Normal file → Executable file
@ -14,15 +14,16 @@
|
||||
*/
|
||||
|
||||
#include "data_ability_helper.h"
|
||||
#include "ability_thread.h"
|
||||
|
||||
#include "ability_scheduler_interface.h"
|
||||
#include "app_log_wrapper.h"
|
||||
#include "ability_thread.h"
|
||||
#include "abs_shared_result_set.h"
|
||||
#include "data_ability_predicates.h"
|
||||
#include "values_bucket.h"
|
||||
#include "data_ability_result.h"
|
||||
#include "data_ability_operation.h"
|
||||
#include "app_log_wrapper.h"
|
||||
#include "data_ability_observer_interface.h"
|
||||
#include "data_ability_operation.h"
|
||||
#include "data_ability_predicates.h"
|
||||
#include "data_ability_result.h"
|
||||
#include "values_bucket.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
@ -601,7 +602,7 @@ std::shared_ptr<NativeRdb::AbsSharedResultSet> DataAbilityHelper::Query(
|
||||
APP_LOGI("DataAbilityHelper::Query start.");
|
||||
std::lock_guard<std::mutex> guard(lock_);
|
||||
std::shared_ptr<NativeRdb::AbsSharedResultSet> resultset = nullptr;
|
||||
|
||||
|
||||
if (!CheckUriParam(uri)) {
|
||||
APP_LOGE("%{public}s called. CheckUriParam uri failed", __func__);
|
||||
return resultset;
|
||||
|
3
frameworks/kits/ability/native/src/data_ability_impl.cpp
Normal file → Executable file
3
frameworks/kits/ability/native/src/data_ability_impl.cpp
Normal file → Executable file
@ -14,8 +14,9 @@
|
||||
*/
|
||||
|
||||
#include "data_ability_impl.h"
|
||||
#include "app_log_wrapper.h"
|
||||
|
||||
#include "abs_shared_result_set.h"
|
||||
#include "app_log_wrapper.h"
|
||||
#include "data_ability_predicates.h"
|
||||
#include "values_bucket.h"
|
||||
|
||||
|
5
frameworks/kits/ability/native/src/data_ability_operation.cpp
Normal file → Executable file
5
frameworks/kits/ability/native/src/data_ability_operation.cpp
Normal file → Executable file
@ -14,9 +14,10 @@
|
||||
*/
|
||||
|
||||
#include "data_ability_operation.h"
|
||||
|
||||
#include "app_log_wrapper.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "data_ability_predicates.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "values_bucket.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -436,7 +437,7 @@ bool DataAbilityOperation::ReadFromParcel(Parcel &in)
|
||||
return false;
|
||||
}
|
||||
APP_LOGD("DataAbilityOperation::ReadFromParcel empty is %{public}s",
|
||||
empty == VALUE_OBJECT ? "VALUE_OBJECT" : "VALUE_NULL");
|
||||
(empty == VALUE_OBJECT) ? "VALUE_OBJECT" : "VALUE_NULL");
|
||||
if (empty == VALUE_OBJECT) {
|
||||
valuesBucketReferences_.reset(in.ReadParcelable<NativeRdb::ValuesBucket>());
|
||||
} else {
|
||||
|
123
frameworks/kits/ability/native/src/extension.cpp
Executable file
123
frameworks/kits/ability/native/src/extension.cpp
Executable file
@ -0,0 +1,123 @@
|
||||
/*
|
||||
* 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_local_record.h"
|
||||
#include "extension.h"
|
||||
#include "extension_context.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
void Extension::Init(const std::shared_ptr<AppExecFwk::AbilityLocalRecord> &record,
|
||||
const std::shared_ptr<AppExecFwk::OHOSApplication> &application,
|
||||
std::shared_ptr<AppExecFwk::AbilityHandler> &handler,
|
||||
const sptr<IRemoteObject> &token)
|
||||
{
|
||||
HILOG_INFO("Init begin.");
|
||||
if ((record == nullptr) || (application == nullptr) || (handler == nullptr) || (token == nullptr)) {
|
||||
HILOG_ERROR("Extension::init failed, some object is nullptr");
|
||||
return;
|
||||
}
|
||||
abilityInfo_ = record->GetAbilityInfo();
|
||||
handler_ = handler;
|
||||
application_ = application;
|
||||
HILOG_INFO("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will be called when extension start. You should override this function
|
||||
*
|
||||
* @param want start information
|
||||
*/
|
||||
void Extension::OnStart(const AAFwk::Want &want)
|
||||
{
|
||||
HILOG_INFO("OnStart begin.");
|
||||
SetLaunchWant(want);
|
||||
SetLastRequestWant(want);
|
||||
HILOG_INFO("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will be called when extension stop. You should override this function
|
||||
*
|
||||
* @param want start information
|
||||
*/
|
||||
void Extension::OnStop()
|
||||
{
|
||||
HILOG_INFO("OnStop begin.");
|
||||
HILOG_INFO("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called when this Service extension is connected for the first time.
|
||||
*
|
||||
* You can override this function to implement your own processing logic.
|
||||
*
|
||||
* @param want Indicates the {@link Want} structure containing connection information about the Service extension.
|
||||
* @return Returns a pointer to the <b>sid</b> of the connected Service extension.
|
||||
*/
|
||||
sptr<IRemoteObject> Extension::OnConnect(const AAFwk::Want &want)
|
||||
{
|
||||
HILOG_INFO("%{public}s begin.", __func__);
|
||||
HILOG_INFO("%{public}s end.", __func__);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called when all abilities connected to this Service ability are disconnected.
|
||||
*
|
||||
* You can override this function to implement your own processing logic.
|
||||
*
|
||||
*/
|
||||
void Extension::OnDisconnect(const AAFwk::Want &want)
|
||||
{
|
||||
HILOG_INFO("%{public}s begin.", __func__);
|
||||
HILOG_INFO("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called back when Service is started.
|
||||
* This method can be called only by Service. You can use the StartAbility(ohos.aafwk.content.Want) method to start
|
||||
* Service. Then the system calls back the current method to use the transferred want parameter to execute its own
|
||||
* logic.
|
||||
*
|
||||
* @param want Indicates the want of Service to start.
|
||||
* @param restart Indicates the startup mode. The value true indicates that Service is restarted after being destroyed,
|
||||
* and the value false indicates a normal startup.
|
||||
* @param startId Indicates the number of times the Service extension has been started. The startId is incremented by 1
|
||||
* every time the extension is started. For example, if the extension has been started for six times,
|
||||
* the value of startId is 6.
|
||||
*/
|
||||
void Extension::OnCommand(const AAFwk::Want &want, bool restart, int startId)
|
||||
{
|
||||
HILOG_INFO("%{public}s begin restart=%{public}s,startId=%{public}d.",
|
||||
__func__,
|
||||
restart ? "true" : "false",
|
||||
startId);
|
||||
SetLastRequestWant(want);
|
||||
HILOG_INFO("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
void Extension::SetLaunchWant(const AAFwk::Want &want)
|
||||
{
|
||||
launchWant_ = std::make_shared<AAFwk::Want>(want);
|
||||
}
|
||||
|
||||
void Extension::SetLastRequestWant(const AAFwk::Want &want)
|
||||
{
|
||||
lastRequestWant_ = std::make_shared<AAFwk::Want>(want);
|
||||
}
|
||||
}
|
||||
}
|
52
frameworks/kits/ability/native/src/extension_base.cpp
Executable file
52
frameworks/kits/ability/native/src/extension_base.cpp
Executable file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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 "extension_base.h"
|
||||
|
||||
#include "ability_local_record.h"
|
||||
#include "extension_context.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
template<class C>
|
||||
void ExtensionBase<C>::Init(const std::shared_ptr<AbilityLocalRecord> &record,
|
||||
const std::shared_ptr<OHOSApplication> &application,
|
||||
std::shared_ptr<AbilityHandler> &handler,
|
||||
const sptr<IRemoteObject> &token)
|
||||
{
|
||||
Extension::Init(record, application, handler, token);
|
||||
HILOG_INFO("begin init context");
|
||||
context_ = CreateAndInitContext(record, application, handler, token);
|
||||
}
|
||||
|
||||
template<class C>
|
||||
std::shared_ptr<C> ExtensionBase<C>::CreateAndInitContext(const std::shared_ptr<AbilityLocalRecord> &record,
|
||||
const std::shared_ptr<OHOSApplication> &application,
|
||||
std::shared_ptr<AbilityHandler> &handler,
|
||||
const sptr<IRemoteObject> &token)
|
||||
{
|
||||
std::shared_ptr<C> context = std::make_shared<C>();
|
||||
context->SetToken(token);
|
||||
return context;
|
||||
}
|
||||
|
||||
template<class C>
|
||||
std::shared_ptr<C> ExtensionBase<C>::GetContext()
|
||||
{
|
||||
return context_;
|
||||
}
|
||||
}
|
||||
}
|
201
frameworks/kits/ability/native/src/extension_impl.cpp
Executable file
201
frameworks/kits/ability/native/src/extension_impl.cpp
Executable file
@ -0,0 +1,201 @@
|
||||
/*
|
||||
* 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_manager_client.h"
|
||||
#include "ability_local_record.h"
|
||||
#include "bytrace.h"
|
||||
#include "extension_context.h"
|
||||
#include "extension_impl.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
void ExtensionImpl::Init(std::shared_ptr<AppExecFwk::OHOSApplication> &application,
|
||||
const std::shared_ptr<AppExecFwk::AbilityLocalRecord> &record,
|
||||
std::shared_ptr<Extension> &extension,
|
||||
std::shared_ptr<AppExecFwk::AbilityHandler> &handler,
|
||||
const sptr<IRemoteObject> &token)
|
||||
{
|
||||
BYTRACE(BYTRACE_TAG_ABILITY_MANAGER);
|
||||
HILOG_INFO("ExtensionImpl Init begin.");
|
||||
if ((token == nullptr) || (application == nullptr) || (handler == nullptr) || (record == nullptr) ||
|
||||
extension == nullptr) {
|
||||
HILOG_ERROR("ExtensionImpl::init failed, some object is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
token_ = record->GetToken();
|
||||
extension_ = extension;
|
||||
extension_->Init(record, application, handler, token);
|
||||
lifecycleState_ = AAFwk::ABILITY_STATE_INITIAL;
|
||||
HILOG_INFO("ExtensionImpl Init end.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Handling the life cycle switching of Extension.
|
||||
*
|
||||
* @param want Indicates the structure containing information about the extension.
|
||||
* @param targetState The life cycle state to switch to.
|
||||
*
|
||||
*/
|
||||
void ExtensionImpl::HandleExtensionTransaction(const Want &want,
|
||||
const AAFwk::LifeCycleStateInfo &targetState)
|
||||
{
|
||||
HILOG_INFO("ExtensionImpl::HandleExtensionTransaction begin sourceState:%{public}d; targetState: %{public}d; "
|
||||
"isNewWant: %{public}d",
|
||||
lifecycleState_,
|
||||
targetState.state,
|
||||
targetState.isNewWant);
|
||||
if (lifecycleState_ == targetState.state) {
|
||||
HILOG_ERROR("Org lifeCycleState equals to Dst lifeCycleState.");
|
||||
return;
|
||||
}
|
||||
|
||||
bool ret = true;
|
||||
|
||||
switch (targetState.state) {
|
||||
case AAFwk::ABILITY_STATE_INITIAL: {
|
||||
if (lifecycleState_ == AAFwk::ABILITY_STATE_ACTIVE) {
|
||||
Stop();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case AAFwk::ABILITY_STATE_INACTIVE: {
|
||||
if (lifecycleState_ == AAFwk::ABILITY_STATE_INITIAL) {
|
||||
Start(want);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
ret = false;
|
||||
HILOG_ERROR("ExtensionImpl::HandleAbilityTransaction state is error");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret) {
|
||||
HILOG_INFO("ExtensionImpl::HandleAbilityTransaction before AbilityManagerClient->AbilityTransitionDone");
|
||||
AAFwk::PacMap restoreData;
|
||||
AAFwk::AbilityManagerClient::GetInstance()->AbilityTransitionDone(token_, targetState.state, restoreData);
|
||||
HILOG_INFO("ExtensionImpl::HandleAbilityTransaction after AbilityManagerClient->AbilityTransitionDone");
|
||||
}
|
||||
HILOG_INFO("ExtensionImpl::HandleAbilityTransaction end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Toggles the lifecycle status of Extension to AAFwk::ABILITY_STATE_INACTIVE. And notifies the application
|
||||
* that it belongs to of the lifecycle status.
|
||||
*
|
||||
* @param want The Want object to switch the life cycle.
|
||||
*/
|
||||
void ExtensionImpl::Start(const Want &want)
|
||||
{
|
||||
HILOG_INFO("%{public}s begin.", __func__);
|
||||
if (extension_ == nullptr) {
|
||||
HILOG_ERROR("ExtensionImpl::Start extension_ is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
HILOG_INFO("ExtensionImpl::Start");
|
||||
extension_->OnStart(want);
|
||||
lifecycleState_ = AAFwk::ABILITY_STATE_INACTIVE;
|
||||
HILOG_INFO("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Toggles the lifecycle status of Extension to AAFwk::ABILITY_STATE_INITIAL. And notifies the application
|
||||
* that it belongs to of the lifecycle status.
|
||||
*
|
||||
*/
|
||||
void ExtensionImpl::Stop()
|
||||
{
|
||||
HILOG_INFO("%{public}s begin.", __func__);
|
||||
if (extension_ == nullptr) {
|
||||
HILOG_ERROR("ExtensionImpl::Stop extension_ is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
HILOG_INFO("ExtensionImpl::Stop");
|
||||
extension_->OnStop();
|
||||
lifecycleState_ = AAFwk::ABILITY_STATE_INITIAL;
|
||||
HILOG_INFO("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Connect the extension. and Calling information back to Extension.
|
||||
*
|
||||
* @param want The Want object to connect to.
|
||||
*
|
||||
*/
|
||||
sptr<IRemoteObject> ExtensionImpl::ConnectExtension(const Want &want)
|
||||
{
|
||||
HILOG_INFO("%{public}s begin.", __func__);
|
||||
if (extension_ == nullptr) {
|
||||
HILOG_ERROR("ExtensionImpl::ConnectAbility extension_ is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
HILOG_INFO("ExtensionImpl:: ConnectAbility");
|
||||
sptr<IRemoteObject> object = extension_->OnConnect(want);
|
||||
lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE;
|
||||
HILOG_INFO("%{public}s end.", __func__);
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disconnects the connected object.
|
||||
*
|
||||
* @param want The Want object to disconnect to.
|
||||
*/
|
||||
void ExtensionImpl::DisconnectExtension(const Want &want)
|
||||
{
|
||||
HILOG_INFO("%{public}s begin.", __func__);
|
||||
if (extension_ == nullptr) {
|
||||
HILOG_ERROR("ExtensionImpl::DisconnectAbility extension_ is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
extension_->OnDisconnect(want);
|
||||
HILOG_INFO("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Command the Extension. and Calling information back to Extension.
|
||||
*
|
||||
* @param want The Want object to command to.
|
||||
*
|
||||
* * @param restart Indicates the startup mode. The value true indicates that Service is restarted after being
|
||||
* destroyed, and the value false indicates a normal startup.
|
||||
*
|
||||
* @param startId Indicates the number of times the Service Extension has been started. The startId is incremented by 1
|
||||
* every time the Extension is started. For example, if the Extension has been started for six times,
|
||||
* the value of startId is 6.
|
||||
*/
|
||||
void ExtensionImpl::CommandExtension(const Want &want, bool restart, int startId)
|
||||
{
|
||||
HILOG_INFO("%{public}s begin.", __func__);
|
||||
if (extension_ == nullptr) {
|
||||
HILOG_ERROR("ExtensionImpl::CommandAbility extension_ is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
HILOG_INFO("ExtensionImpl:: CommandAbility");
|
||||
extension_->OnCommand(want, restart, startId);
|
||||
lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE;
|
||||
HILOG_INFO("%{public}s end.", __func__);
|
||||
}
|
||||
}
|
||||
}
|
2
frameworks/kits/ability/native/src/form_js_event_handler.cpp
Normal file → Executable file
2
frameworks/kits/ability/native/src/form_js_event_handler.cpp
Normal file → Executable file
@ -16,9 +16,9 @@
|
||||
#include "app_log_wrapper.h"
|
||||
#include "form_constants.h"
|
||||
#include "form_host_client.h"
|
||||
#include "form_js_event_handler.h"
|
||||
#include "form_mgr.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "form_js_event_handler.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
|
@ -13,16 +13,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "form_provider_client.h"
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
#include "appexecfwk_errors.h"
|
||||
#include "app_log_wrapper.h"
|
||||
#include "appexecfwk_errors.h"
|
||||
#include "form_supply_proxy.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "permission/permission.h"
|
||||
#include "permission/permission_kit.h"
|
||||
#include "string_ex.h"
|
||||
#include "form_provider_client.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
|
228
frameworks/kits/ability/native/src/js_service_extension.cpp
Executable file
228
frameworks/kits/ability/native/src/js_service_extension.cpp
Executable file
@ -0,0 +1,228 @@
|
||||
/*
|
||||
* 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 "js_service_extension.h"
|
||||
|
||||
#include "ability_info.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_runtime.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "js_service_extension_context.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_node_api.h"
|
||||
#include "napi_common_want.h"
|
||||
#include "napi_remote_object.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
namespace {
|
||||
constexpr size_t ARGC_ONE = 1;
|
||||
constexpr size_t ARGC_TWO = 2;
|
||||
}
|
||||
|
||||
using namespace OHOS::AppExecFwk;
|
||||
JsServiceExtension* JsServiceExtension::Create(const std::unique_ptr<Runtime>& runtime)
|
||||
{
|
||||
return new JsServiceExtension(static_cast<JsRuntime&>(*runtime));
|
||||
}
|
||||
|
||||
JsServiceExtension::JsServiceExtension(JsRuntime& jsRuntime) : jsRuntime_(jsRuntime) {}
|
||||
JsServiceExtension::~JsServiceExtension() = default;
|
||||
|
||||
void JsServiceExtension::Init(const std::shared_ptr<AbilityLocalRecord> &record,
|
||||
const std::shared_ptr<OHOSApplication> &application,
|
||||
std::shared_ptr<AbilityHandler> &handler,
|
||||
const sptr<IRemoteObject> &token)
|
||||
{
|
||||
ServiceExtension::Init(record, application, handler, token);
|
||||
std::string srcPath(Extension::abilityInfo_->package);
|
||||
srcPath.append("/assets/js/");
|
||||
if (!Extension::abilityInfo_->srcPath.empty()) {
|
||||
srcPath.append(Extension::abilityInfo_->srcPath);
|
||||
}
|
||||
srcPath.append("/").append(Extension::abilityInfo_->name).append(".abc");
|
||||
|
||||
std::string moduleName(Extension::abilityInfo_->moduleName);
|
||||
moduleName.append("::").append(abilityInfo_->name);
|
||||
HILOG_INFO("JsServiceExtension::Init moduleName:%{public}s,srcPath:%{public}s.",
|
||||
moduleName.c_str(), srcPath.c_str());
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
auto& engine = jsRuntime_.GetNativeEngine();
|
||||
|
||||
jsObj_ = jsRuntime_.LoadModule(moduleName, srcPath);
|
||||
if (jsObj_ == nullptr) {
|
||||
HILOG_ERROR("Failed to get jsObj_");
|
||||
return;
|
||||
}
|
||||
HILOG_INFO("JsServiceExtension::Init ConvertNativeValueTo.");
|
||||
NativeObject* obj = ConvertNativeValueTo<NativeObject>(jsObj_->Get());
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("Failed to get JsServiceExtension object");
|
||||
return;
|
||||
}
|
||||
|
||||
auto context = GetContext();
|
||||
if (context == nullptr) {
|
||||
HILOG_ERROR("Failed to get context");
|
||||
return;
|
||||
}
|
||||
HILOG_INFO("JsServiceExtension::Init CreateJsServiceExtensionContext.");
|
||||
NativeValue* contextObj = CreateJsServiceExtensionContext(engine, context);
|
||||
auto shellContextRef = jsRuntime_.LoadSystemModule("application.ServiceExtensionContext", &contextObj, ARGC_ONE);
|
||||
contextObj = shellContextRef->Get();
|
||||
HILOG_INFO("JsServiceExtension::Init Bind.");
|
||||
context->Bind(jsRuntime_, shellContextRef.release());
|
||||
HILOG_INFO("JsServiceExtension::SetProperty.");
|
||||
obj->SetProperty("context", contextObj);
|
||||
HILOG_INFO("JsServiceExtension::Init end.");
|
||||
}
|
||||
|
||||
void JsServiceExtension::OnStart(const AAFwk::Want &want)
|
||||
{
|
||||
Extension::OnStart(want);
|
||||
HILOG_INFO("JsServiceExtension OnStart begin..");
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
NativeEngine* nativeEngine = &jsRuntime_.GetNativeEngine();
|
||||
napi_value napiWant = OHOS::AppExecFwk::WrapWant(reinterpret_cast<napi_env>(nativeEngine), want);
|
||||
NativeValue* nativeWant = reinterpret_cast<NativeValue*>(napiWant);
|
||||
NativeValue* argv[] = {nativeWant};
|
||||
CallObjectMethod("onCreate", argv, ARGC_ONE);
|
||||
HILOG_INFO("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
void JsServiceExtension::OnStop()
|
||||
{
|
||||
Extension::OnStop();
|
||||
HILOG_INFO("JsServiceExtension OnStop begin.");
|
||||
CallObjectMethod("onDestroy");
|
||||
HILOG_INFO("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> JsServiceExtension::OnConnect(const AAFwk::Want &want)
|
||||
{
|
||||
Extension::OnConnect(want);
|
||||
HILOG_INFO("%{public}s begin.", __func__);
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
NativeEngine* nativeEngine = &jsRuntime_.GetNativeEngine();
|
||||
napi_value napiWant = OHOS::AppExecFwk::WrapWant(reinterpret_cast<napi_env>(nativeEngine), want);
|
||||
NativeValue* nativeWant = reinterpret_cast<NativeValue*>(napiWant);
|
||||
NativeValue* argv[] = {nativeWant};
|
||||
if (!jsObj_) {
|
||||
HILOG_WARN("Not found ServiceExtension.js");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue* value = jsObj_->Get();
|
||||
NativeObject* obj = ConvertNativeValueTo<NativeObject>(value);
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("Failed to get ServiceExtension object");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue* method = obj->GetProperty("onConnect");
|
||||
if (method == nullptr) {
|
||||
HILOG_ERROR("Failed to get onConnect from ServiceExtension object");
|
||||
return nullptr;
|
||||
}
|
||||
HILOG_INFO("JsServiceExtension::CallFunction onConnect, success");
|
||||
NativeValue* remoteNative = nativeEngine->CallFunction(value, method, argv, ARGC_ONE);
|
||||
auto remoteObj = NAPI_ohos_rpc_getNativeRemoteObject(
|
||||
reinterpret_cast<napi_env>(nativeEngine), reinterpret_cast<napi_value>(remoteNative));
|
||||
if (remoteObj == nullptr) {
|
||||
HILOG_ERROR("remoteObj nullptr.");
|
||||
}
|
||||
return remoteObj;
|
||||
}
|
||||
|
||||
void JsServiceExtension::OnDisconnect(const AAFwk::Want &want)
|
||||
{
|
||||
Extension::OnDisconnect(want);
|
||||
HILOG_INFO("%{public}s begin.", __func__);
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
NativeEngine* nativeEngine = &jsRuntime_.GetNativeEngine();
|
||||
napi_value napiWant = OHOS::AppExecFwk::WrapWant(reinterpret_cast<napi_env>(nativeEngine), want);
|
||||
NativeValue* nativeWant = reinterpret_cast<NativeValue*>(napiWant);
|
||||
NativeValue* argv[] = {nativeWant};
|
||||
if (!jsObj_) {
|
||||
HILOG_WARN("Not found ServiceExtension.js");
|
||||
return;
|
||||
}
|
||||
|
||||
NativeValue* value = jsObj_->Get();
|
||||
NativeObject* obj = ConvertNativeValueTo<NativeObject>(value);
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("Failed to get ServiceExtension object");
|
||||
return;
|
||||
}
|
||||
|
||||
NativeValue* method = obj->GetProperty("onDisconnect");
|
||||
if (method == nullptr) {
|
||||
HILOG_ERROR("Failed to get onDisconnect from ServiceExtension object");
|
||||
return;
|
||||
}
|
||||
nativeEngine->CallFunction(value, method, argv, ARGC_ONE);
|
||||
HILOG_INFO("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
void JsServiceExtension::OnCommand(const AAFwk::Want &want, bool restart, int startId)
|
||||
{
|
||||
Extension::OnCommand(want, restart, startId);
|
||||
HILOG_INFO("%{public}s begin restart=%{public}s,startId=%{public}d.",
|
||||
__func__,
|
||||
restart ? "true" : "false",
|
||||
startId);
|
||||
// wrap want
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
NativeEngine* nativeEngine = &jsRuntime_.GetNativeEngine();
|
||||
napi_value napiWant = OHOS::AppExecFwk::WrapWant(reinterpret_cast<napi_env>(nativeEngine), want);
|
||||
NativeValue* nativeWant = reinterpret_cast<NativeValue*>(napiWant);
|
||||
// wrap startId
|
||||
napi_value napiStartId = nullptr;
|
||||
napi_create_int32(reinterpret_cast<napi_env>(nativeEngine), startId, &napiStartId);
|
||||
NativeValue* nativeStartId = reinterpret_cast<NativeValue*>(napiStartId);
|
||||
NativeValue* argv[] = {nativeWant, nativeStartId};
|
||||
CallObjectMethod("onRequest", argv, ARGC_TWO);
|
||||
HILOG_INFO("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
NativeValue* JsServiceExtension::CallObjectMethod(const char* name, NativeValue* const* argv, size_t argc)
|
||||
{
|
||||
HILOG_INFO("JsServiceExtension::CallObjectMethod(%{public}s), begin", name);
|
||||
|
||||
if (!jsObj_) {
|
||||
HILOG_WARN("Not found ServiceExtension.js");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
auto& nativeEngine = jsRuntime_.GetNativeEngine();
|
||||
|
||||
NativeValue* value = jsObj_->Get();
|
||||
NativeObject* obj = ConvertNativeValueTo<NativeObject>(value);
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("Failed to get ServiceExtension object");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue* method = obj->GetProperty(name);
|
||||
if (method == nullptr) {
|
||||
HILOG_ERROR("Failed to get '%{public}s' from ServiceExtension object", name);
|
||||
return nullptr;
|
||||
}
|
||||
HILOG_INFO("JsServiceExtension::CallFunction(%{public}s), success", name);
|
||||
return nativeEngine.CallFunction(value, method, argv, argc);
|
||||
}
|
||||
}
|
||||
}
|
396
frameworks/kits/ability/native/src/js_service_extension_context.cpp
Executable file
396
frameworks/kits/ability/native/src/js_service_extension_context.cpp
Executable file
@ -0,0 +1,396 @@
|
||||
/*
|
||||
* 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 "js_service_extension_context.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_extension_context.h"
|
||||
#include "js_runtime.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "napi_common_want.h"
|
||||
#include "napi_remote_object.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
namespace {
|
||||
constexpr int32_t INDEX_ZERO = 0;
|
||||
constexpr int32_t INDEX_ONE = 1;
|
||||
constexpr int32_t ERROR_CODE_ONE = 1;
|
||||
constexpr int32_t ERROR_CODE_TWO = 2;
|
||||
constexpr size_t ARGC_ZERO = 0;
|
||||
constexpr size_t ARGC_ONE = 1;
|
||||
constexpr size_t ARGC_TWO = 2;
|
||||
|
||||
class JsServiceExtensionContext final {
|
||||
public:
|
||||
JsServiceExtensionContext(const std::shared_ptr<ServiceExtensionContext>& context) : context_(context) {}
|
||||
~JsServiceExtensionContext() = default;
|
||||
|
||||
static void Finalizer(NativeEngine* engine, void* data, void* hint)
|
||||
{
|
||||
HILOG_INFO("JsAbilityContext::Finalizer is called");
|
||||
std::unique_ptr<JsServiceExtensionContext>(static_cast<JsServiceExtensionContext*>(data));
|
||||
}
|
||||
|
||||
static NativeValue* StartAbility(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsServiceExtensionContext* me = CheckParamsAndGetThis<JsServiceExtensionContext>(engine, info);
|
||||
return (me != nullptr) ? me->OnStartAbility(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
static NativeValue* TerminateAbility(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsServiceExtensionContext* me = CheckParamsAndGetThis<JsServiceExtensionContext>(engine, info);
|
||||
return (me != nullptr) ? me->OnTerminateAbility(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
static NativeValue* ConnectAbility(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsServiceExtensionContext* me = CheckParamsAndGetThis<JsServiceExtensionContext>(engine, info);
|
||||
return (me != nullptr) ? me->OnConnectAbility(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
static NativeValue* DisconnectAbility(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsServiceExtensionContext* me = CheckParamsAndGetThis<JsServiceExtensionContext>(engine, info);
|
||||
return (me != nullptr) ? me->OnDisconnectAbility(*engine, *info) : nullptr;
|
||||
}
|
||||
private:
|
||||
std::weak_ptr<ServiceExtensionContext> context_;
|
||||
|
||||
NativeValue* OnStartAbility(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
HILOG_INFO("OnStartAbility is called");
|
||||
// only support one or two params
|
||||
if (info.argc != ARGC_ONE && info.argc != ARGC_TWO) {
|
||||
HILOG_ERROR("Not enough params");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
AAFwk::Want want;
|
||||
OHOS::AppExecFwk::UnwrapWant(reinterpret_cast<napi_env>(&engine),
|
||||
reinterpret_cast<napi_value>(info.argv[INDEX_ZERO]), want);
|
||||
HILOG_INFO("%{public}s bundlename:%{public}s abilityname:%{public}s",
|
||||
__func__,
|
||||
want.GetBundle().c_str(),
|
||||
want.GetElement().GetAbilityName().c_str());
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[weak = context_, want](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
HILOG_INFO("startAbility begin");
|
||||
auto context = weak.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is released");
|
||||
task.Reject(engine, CreateJsError(engine, ERROR_CODE_ONE, "Context is released"));
|
||||
return;
|
||||
}
|
||||
|
||||
context->StartAbility(want);
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc == ARGC_ONE) ? nullptr : info.argv[INDEX_ONE];
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue* OnTerminateAbility(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
HILOG_INFO("OnTerminateAbility is called");
|
||||
// only support one or zero params
|
||||
if (info.argc != ARGC_ZERO && info.argc != ARGC_ONE) {
|
||||
HILOG_ERROR("Not enough params");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[weak = context_](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
HILOG_INFO("TerminateAbility begin");
|
||||
auto context = weak.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is released");
|
||||
task.Reject(engine, CreateJsError(engine, ERROR_CODE_ONE, "Context is released"));
|
||||
return;
|
||||
}
|
||||
|
||||
context->TerminateAbility();
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc == ARGC_ZERO) ? nullptr : info.argv[INDEX_ZERO];
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue* OnConnectAbility(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
HILOG_INFO("OnConnectAbility is called");
|
||||
// only support two params
|
||||
if (info.argc != ARGC_TWO) {
|
||||
HILOG_ERROR("Not enough params");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
// unwrap want
|
||||
AAFwk::Want want;
|
||||
OHOS::AppExecFwk::UnwrapWant(reinterpret_cast<napi_env>(&engine),
|
||||
reinterpret_cast<napi_value>(info.argv[INDEX_ZERO]), want);
|
||||
HILOG_INFO("%{public}s bundlename:%{public}s abilityname:%{public}s",
|
||||
__func__,
|
||||
want.GetBundle().c_str(),
|
||||
want.GetElement().GetAbilityName().c_str());
|
||||
// unwarp connection
|
||||
sptr<JSServiceExtensionConnection> connection = new JSServiceExtensionConnection();
|
||||
connection->SetNativeEngine(&engine);
|
||||
connection->SetJsConnectionObject(info.argv[1]);
|
||||
int64_t connectId = serialNumber_;
|
||||
ConnecttionKey key;
|
||||
key.id = serialNumber_;
|
||||
key.want = want;
|
||||
connects_.emplace(key, connection);
|
||||
if (serialNumber_ < INT64_MAX) {
|
||||
serialNumber_++;
|
||||
} else {
|
||||
serialNumber_ = 0;
|
||||
}
|
||||
HILOG_INFO("%{public}s not find connection, make new one:%{public}p.", __func__, connection.GetRefPtr());
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[weak = context_, want, connection, connectId](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
HILOG_INFO("OnConnectAbility begin");
|
||||
auto context = weak.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is released");
|
||||
task.Reject(engine, CreateJsError(engine, ERROR_CODE_ONE, "Context is released"));
|
||||
return;
|
||||
}
|
||||
HILOG_INFO("context->ConnectAbility connection:%{public}d", (int32_t)connectId);
|
||||
if (!context->ConnectAbility(want, connection)) {
|
||||
connection->CallJsFailed();
|
||||
}
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
};
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, nullptr, nullptr, std::move(complete), &result));
|
||||
return engine.CreateNumber(connectId);
|
||||
}
|
||||
|
||||
NativeValue* OnDisconnectAbility(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
HILOG_INFO("OnDisconnectAbility is called");
|
||||
// only support one or two params
|
||||
if (info.argc != ARGC_ONE && info.argc != ARGC_TWO) {
|
||||
HILOG_ERROR("Not enough params");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
// unwrap connectId
|
||||
int64_t connectId = -1;
|
||||
sptr<JSServiceExtensionConnection> connection = nullptr;
|
||||
napi_get_value_int64(reinterpret_cast<napi_env>(&engine),
|
||||
reinterpret_cast<napi_value>(info.argv[INDEX_ZERO]), &connectId);
|
||||
HILOG_INFO("OnDisconnectAbility connection:%{public}d", (int32_t)connectId);
|
||||
auto item = std::find_if(connects_.begin(),
|
||||
connects_.end(),
|
||||
[&connectId](const std::map<ConnecttionKey, sptr<JSServiceExtensionConnection>>::value_type &obj) {
|
||||
return connectId == obj.first.id;
|
||||
});
|
||||
if (item != connects_.end()) {
|
||||
// match id
|
||||
connection = item->second;
|
||||
HILOG_INFO("%{public}s find conn ability:%{public}p exist", __func__, item->second.GetRefPtr());
|
||||
} else {
|
||||
HILOG_INFO("%{public}s not find conn exist.", __func__);
|
||||
}
|
||||
// begin disconnect
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[weak = context_, connection](
|
||||
NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
HILOG_INFO("OnDisconnectAbility begin");
|
||||
auto context = weak.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is released");
|
||||
task.Reject(engine, CreateJsError(engine, ERROR_CODE_ONE, "Context is released"));
|
||||
return;
|
||||
}
|
||||
if (connection == nullptr) {
|
||||
HILOG_WARN("connection nullptr");
|
||||
task.Reject(engine, CreateJsError(engine, ERROR_CODE_TWO, "not found connection"));
|
||||
return;
|
||||
}
|
||||
HILOG_INFO("context->DisconnectAbility");
|
||||
context->DisconnectAbility(connection);
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc == ARGC_ONE) ? nullptr : info.argv[INDEX_ONE];
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
NativeValue* CreateJsServiceExtensionContext(NativeEngine& engine, std::shared_ptr<ServiceExtensionContext> context)
|
||||
{
|
||||
HILOG_INFO("CreateJsServiceExtensionContext begin");
|
||||
NativeValue* objValue = CreateJsExtensionContext(engine, context);
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
|
||||
std::unique_ptr<JsServiceExtensionContext> jsContext = std::make_unique<JsServiceExtensionContext>(context);
|
||||
object->SetNativePointer(jsContext.release(), JsServiceExtensionContext::Finalizer, nullptr);
|
||||
|
||||
BindNativeFunction(engine, *object, "startAbility", JsServiceExtensionContext::StartAbility);
|
||||
BindNativeFunction(engine, *object, "terminateSelf", JsServiceExtensionContext::TerminateAbility);
|
||||
BindNativeFunction(engine, *object, "connectAbility", JsServiceExtensionContext::ConnectAbility);
|
||||
BindNativeFunction(engine, *object, "disconnectAbility", JsServiceExtensionContext::DisconnectAbility);
|
||||
|
||||
return objValue;
|
||||
}
|
||||
|
||||
void JSServiceExtensionConnection::OnAbilityConnectDone(const AppExecFwk::ElementName &element,
|
||||
const sptr<IRemoteObject> &remoteObject, int resultCode)
|
||||
{
|
||||
HILOG_INFO("OnAbilityConnectDone begin, resultCode:%{public}d", resultCode);
|
||||
// wrap ElementName
|
||||
napi_value napiElementName = OHOS::AppExecFwk::WrapElementName(reinterpret_cast<napi_env>(engine_), element);
|
||||
NativeValue* nativeElementName = reinterpret_cast<NativeValue*>(napiElementName);
|
||||
|
||||
// wrap RemoteObject
|
||||
HILOG_INFO("OnAbilityConnectDone begin NAPI_ohos_rpc_CreateJsRemoteObject");
|
||||
napi_value napiRemoteObject = NAPI_ohos_rpc_CreateJsRemoteObject(
|
||||
reinterpret_cast<napi_env>(engine_), remoteObject);
|
||||
NativeValue* nativeRemoteObject = reinterpret_cast<NativeValue*>(napiRemoteObject);
|
||||
NativeValue* argv[] = {nativeElementName, nativeRemoteObject};
|
||||
if (jsConnectionObject_ == nullptr) {
|
||||
HILOG_ERROR("jsConnectionObject_ nullptr");
|
||||
return;
|
||||
}
|
||||
NativeValue* value = jsConnectionObject_->Get();
|
||||
NativeObject* obj = ConvertNativeValueTo<NativeObject>(value);
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("Failed to get object");
|
||||
return;
|
||||
}
|
||||
NativeValue* methodOnConnect = obj->GetProperty("onConnect");
|
||||
if (methodOnConnect == nullptr) {
|
||||
HILOG_ERROR("Failed to get onConnect from object");
|
||||
return;
|
||||
}
|
||||
HILOG_INFO("JSServiceExtensionConnection::CallFunction onConnect, success");
|
||||
// two params
|
||||
if (engine_ == nullptr) {
|
||||
HILOG_ERROR("engine_ nullptr");
|
||||
return;
|
||||
}
|
||||
engine_->CallFunction(value, methodOnConnect, argv, ARGC_TWO);
|
||||
HILOG_INFO("OnAbilityConnectDone end");
|
||||
}
|
||||
|
||||
void JSServiceExtensionConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode)
|
||||
{
|
||||
HILOG_INFO("OnAbilityDisconnectDone begin, resultCode:%{public}d", resultCode);
|
||||
napi_value napiElementName = OHOS::AppExecFwk::WrapElementName(reinterpret_cast<napi_env>(engine_), element);
|
||||
NativeValue* nativeElementName = reinterpret_cast<NativeValue*>(napiElementName);
|
||||
NativeValue* argv[] = {nativeElementName};
|
||||
if (jsConnectionObject_ == nullptr) {
|
||||
HILOG_ERROR("jsConnectionObject_ nullptr");
|
||||
return;
|
||||
}
|
||||
NativeValue* value = jsConnectionObject_->Get();
|
||||
NativeObject* obj = ConvertNativeValueTo<NativeObject>(value);
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("Failed to get object");
|
||||
return;
|
||||
}
|
||||
|
||||
NativeValue* method = obj->GetProperty("onDisconnect");
|
||||
if (method == nullptr) {
|
||||
HILOG_ERROR("Failed to get onDisconnect from object");
|
||||
return;
|
||||
}
|
||||
|
||||
// release connect
|
||||
HILOG_INFO("OnAbilityDisconnectDone connects_.size:%{public}zu", connects_.size());
|
||||
std::string bundleName = element.GetBundleName();
|
||||
std::string abilityName = element.GetAbilityName();
|
||||
auto item = std::find_if(connects_.begin(),
|
||||
connects_.end(),
|
||||
[bundleName, abilityName](
|
||||
const std::map<ConnecttionKey, sptr<JSServiceExtensionConnection>>::value_type &obj) {
|
||||
return (bundleName == obj.first.want.GetBundle()) &&
|
||||
(abilityName == obj.first.want.GetElement().GetAbilityName());
|
||||
});
|
||||
if (item != connects_.end()) {
|
||||
// match bundlename && abilityname
|
||||
connects_.erase(item);
|
||||
HILOG_INFO("OnAbilityDisconnectDone erase connects_.size:%{public}zu", connects_.size());
|
||||
}
|
||||
// one params
|
||||
if (engine_ == nullptr) {
|
||||
HILOG_ERROR("engine_ nullptr");
|
||||
return;
|
||||
}
|
||||
HILOG_INFO("OnAbilityDisconnectDone CallFunction success");
|
||||
engine_->CallFunction(value, method, argv, ARGC_ONE);
|
||||
}
|
||||
|
||||
void JSServiceExtensionConnection::SetNativeEngine(NativeEngine* engine)
|
||||
{
|
||||
engine_ = engine;
|
||||
}
|
||||
|
||||
void JSServiceExtensionConnection::SetJsConnectionObject(NativeValue* jsConnectionObject)
|
||||
{
|
||||
jsConnectionObject_ = std::unique_ptr<NativeReference>(engine_->CreateReference(jsConnectionObject, 1));
|
||||
}
|
||||
|
||||
void JSServiceExtensionConnection::CallJsFailed()
|
||||
{
|
||||
HILOG_INFO("CallJsFailed begin");
|
||||
if (jsConnectionObject_ == nullptr) {
|
||||
HILOG_ERROR("jsConnectionObject_ nullptr");
|
||||
return;
|
||||
}
|
||||
NativeValue* value = jsConnectionObject_->Get();
|
||||
NativeObject* obj = ConvertNativeValueTo<NativeObject>(value);
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("Failed to get object");
|
||||
return;
|
||||
}
|
||||
|
||||
NativeValue* method = obj->GetProperty("onFailed");
|
||||
if (method == nullptr) {
|
||||
HILOG_ERROR("Failed to get onFailed from object");
|
||||
return;
|
||||
}
|
||||
if (engine_ == nullptr) {
|
||||
HILOG_ERROR("engine_ nullptr");
|
||||
return;
|
||||
}
|
||||
HILOG_INFO("CallJsFailed CallFunction success");
|
||||
// no params
|
||||
engine_->CallFunction(value, method, nullptr, ARGC_ZERO);
|
||||
HILOG_INFO("CallJsFailed end");
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
102
frameworks/kits/ability/native/src/new_ability_impl.cpp
Executable file
102
frameworks/kits/ability/native/src/new_ability_impl.cpp
Executable file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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 "new_ability_impl.h"
|
||||
#include "app_log_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
using AbilityManagerClient = OHOS::AAFwk::AbilityManagerClient;
|
||||
/**
|
||||
* @brief Handling the life cycle switching of NewAbility.
|
||||
*
|
||||
* @param want Indicates the structure containing information about the ability.
|
||||
* @param targetState The life cycle state to switch to.
|
||||
*
|
||||
*/
|
||||
|
||||
void NewAbilityImpl::HandleAbilityTransaction(const Want &want, const AAFwk::LifeCycleStateInfo &targetState)
|
||||
{
|
||||
APP_LOGI("NewAbilityImpl::HandleAbilityTransaction begin sourceState:%{public}d; targetState: %{public}d; "
|
||||
"isNewWant: %{public}d",
|
||||
lifecycleState_,
|
||||
targetState.state,
|
||||
targetState.isNewWant);
|
||||
if ((lifecycleState_ == targetState.state) && !targetState.isNewWant) {
|
||||
APP_LOGE("Org lifeCycleState equals to Dst lifeCycleState.");
|
||||
return;
|
||||
}
|
||||
|
||||
SetLifeCycleStateInfo(targetState);
|
||||
|
||||
if (lifecycleState_ == AAFwk::ABILITY_STATE_INITIAL) {
|
||||
ability_->SetStartAbilitySetting(targetState.setting);
|
||||
ability_->SetLaunchParam(targetState.launchParam);
|
||||
Start(want);
|
||||
CheckAndRestore();
|
||||
}
|
||||
|
||||
bool ret = false;
|
||||
ret = AbilityTransaction(want, targetState);
|
||||
if (ret) {
|
||||
APP_LOGI("AbilityThread::HandleAbilityTransaction before AbilityManagerClient->AbilityTransitionDone");
|
||||
AbilityManagerClient::GetInstance()->AbilityTransitionDone(token_, targetState.state, GetRestoreData());
|
||||
APP_LOGI("AbilityThread::HandleAbilityTransaction after AbilityManagerClient->AbilityTransitionDone");
|
||||
}
|
||||
APP_LOGI("NewAbilityImpl::HandleAbilityTransaction end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Handling the life cycle switching of NewAbility in switch.
|
||||
*
|
||||
* @param want Indicates the structure containing information about the ability.
|
||||
* @param targetState The life cycle state to switch to.
|
||||
*
|
||||
* @return return true if need notify ams, otherwise return false.
|
||||
*
|
||||
*/
|
||||
bool NewAbilityImpl::AbilityTransaction(const Want &want, const AAFwk::LifeCycleStateInfo &targetState)
|
||||
{
|
||||
APP_LOGI("NewAbilityImpl::AbilityTransaction begin");
|
||||
bool ret = true;
|
||||
switch (targetState.state) {
|
||||
case AAFwk::ABILITY_STATE_INITIAL: {
|
||||
if (lifecycleState_ == AAFwk::ABILITY_STATE_FOREGROUND_NEW) {
|
||||
Background();
|
||||
}
|
||||
Stop();
|
||||
break;
|
||||
}
|
||||
case AAFwk::ABILITY_STATE_FOREGROUND_NEW: {
|
||||
Foreground(want);
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
case AAFwk::ABILITY_STATE_BACKGROUND_NEW: {
|
||||
Background();
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
ret = false;
|
||||
APP_LOGE("NewAbilityImpl::HandleAbilityTransaction state error");
|
||||
break;
|
||||
}
|
||||
}
|
||||
APP_LOGI("NewAbilityImpl::AbilityTransaction end: retVal = %{public}d", (int)ret);
|
||||
return ret;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
@ -121,52 +121,50 @@ bool PageAbilityImpl::AbilityTransaction(const Want &want, const AAFwk::LifeCycl
|
||||
|
||||
/**
|
||||
* @brief Execution the KeyDown callback of the ability
|
||||
* @param keyCode Indicates the code of the key pressed.
|
||||
* @param keyEvent Indicates the key-down event.
|
||||
*
|
||||
* @return Returns true if this event is handled and will not be passed further; returns false if this event is
|
||||
* not handled and should be passed to other handlers.
|
||||
*
|
||||
*/
|
||||
bool PageAbilityImpl::DoKeyDown(int keyCode, const KeyEvent &keyEvent)
|
||||
void PageAbilityImpl::DoKeyDown(const std::shared_ptr<MMI::KeyEvent>& keyEvent)
|
||||
{
|
||||
APP_LOGI("PageAbilityImpl::DoKeyDown begin");
|
||||
if (ability_ == nullptr) {
|
||||
APP_LOGE("PageAbilityImpl::DoKeyDown ability_ == nullptr");
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
auto abilitInfo = ability_->GetAbilityInfo();
|
||||
APP_LOGI("PageAbilityImpl::DoKeyDown called %{public}s And Focus is %{public}s",
|
||||
abilitInfo->name.c_str(),
|
||||
ability_->HasWindowFocus() ? "true" : "false");
|
||||
|
||||
ability_->OnKeyDown(keyEvent);
|
||||
APP_LOGI("PageAbilityImpl::DoKeyDown end");
|
||||
return ability_->OnKeyDown(keyCode, keyEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Execution the KeyUp callback of the ability
|
||||
* @param keyCode Indicates the code of the key released.
|
||||
* @param keyEvent Indicates the key-up event.
|
||||
*
|
||||
* @return Returns true if this event is handled and will not be passed further; returns false if this event is
|
||||
* not handled and should be passed to other handlers.
|
||||
*
|
||||
*/
|
||||
bool PageAbilityImpl::DoKeyUp(int keyCode, const KeyEvent &keyEvent)
|
||||
void PageAbilityImpl::DoKeyUp(const std::shared_ptr<MMI::KeyEvent>& keyEvent)
|
||||
{
|
||||
APP_LOGI("PageAbilityImpl::DoKeyUp begin");
|
||||
if (ability_ == nullptr) {
|
||||
APP_LOGE("PageAbilityImpl::DoKeyUp ability_ == nullptr");
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
auto abilitInfo = ability_->GetAbilityInfo();
|
||||
APP_LOGI("PageAbilityImpl::DoKeyUp called %{public}s And Focus is %{public}s",
|
||||
abilitInfo->name.c_str(),
|
||||
ability_->HasWindowFocus() ? "true" : "false");
|
||||
|
||||
ability_->OnKeyUp(keyEvent);
|
||||
APP_LOGI("PageAbilityImpl::DoKeyUp end");
|
||||
return ability_->OnKeyUp(keyCode, keyEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -177,20 +175,20 @@ bool PageAbilityImpl::DoKeyUp(int keyCode, const KeyEvent &keyEvent)
|
||||
* @return Returns true if the event is handled; returns false otherwise.
|
||||
*
|
||||
*/
|
||||
bool PageAbilityImpl::DoTouchEvent(const TouchEvent &touchEvent)
|
||||
void PageAbilityImpl::DoPointerEvent(std::shared_ptr<MMI::PointerEvent>& pointerEvent)
|
||||
{
|
||||
APP_LOGI("PageAbilityImpl::DoTouchEvent begin");
|
||||
APP_LOGI("PageAbilityImpl::DoPointerEvent begin");
|
||||
if (ability_ == nullptr) {
|
||||
APP_LOGE("PageAbilityImpl::DoTouchEvent ability_ == nullptr");
|
||||
return false;
|
||||
APP_LOGE("PageAbilityImpl::DoPointerEvent ability_ == nullptr");
|
||||
return;
|
||||
}
|
||||
auto abilitInfo = ability_->GetAbilityInfo();
|
||||
APP_LOGI("PageAbilityImpl::OnTouchEvent called %{public}s And Focus is %{public}s",
|
||||
APP_LOGI("PageAbilityImpl::DoPointerEvent called %{public}s And Focus is %{public}s",
|
||||
abilitInfo->name.c_str(),
|
||||
ability_->HasWindowFocus() ? "true" : "false");
|
||||
|
||||
APP_LOGI("PageAbilityImpl::DoTouchEvent end");
|
||||
return ability_->OnTouchEvent(touchEvent);
|
||||
ability_->OnPointerEvent(pointerEvent);
|
||||
APP_LOGI("PageAbilityImpl::DoPointerEvent end");
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
68
frameworks/kits/ability/native/src/service_extension.cpp
Executable file
68
frameworks/kits/ability/native/src/service_extension.cpp
Executable file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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 "service_extension.h"
|
||||
|
||||
#include "ability_loader.h"
|
||||
#include "extension_base.cpp"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_service_extension.h"
|
||||
#include "runtime.h"
|
||||
#include "service_extension_context.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
using namespace OHOS::AppExecFwk;
|
||||
ServiceExtension* ServiceExtension::Create(const std::unique_ptr<Runtime>& runtime)
|
||||
{
|
||||
if (!runtime) {
|
||||
return new ServiceExtension();
|
||||
}
|
||||
HILOG_INFO("ServiceExtension::Create runtime");
|
||||
switch (runtime->GetLanguage()) {
|
||||
case Runtime::Language::JS:
|
||||
return JsServiceExtension::Create(runtime);
|
||||
|
||||
default:
|
||||
return new ServiceExtension();
|
||||
}
|
||||
}
|
||||
|
||||
void ServiceExtension::Init(const std::shared_ptr<AbilityLocalRecord> &record,
|
||||
const std::shared_ptr<OHOSApplication> &application,
|
||||
std::shared_ptr<AbilityHandler> &handler,
|
||||
const sptr<IRemoteObject> &token)
|
||||
{
|
||||
ExtensionBase<ServiceExtensionContext>::Init(record, application, handler, token);
|
||||
HILOG_INFO("ServiceExtension begin init context");
|
||||
}
|
||||
|
||||
std::shared_ptr<ServiceExtensionContext> ServiceExtension::CreateAndInitContext(
|
||||
const std::shared_ptr<AbilityLocalRecord> &record,
|
||||
const std::shared_ptr<OHOSApplication> &application,
|
||||
std::shared_ptr<AbilityHandler> &handler,
|
||||
const sptr<IRemoteObject> &token)
|
||||
{
|
||||
std::shared_ptr<ServiceExtensionContext> context =
|
||||
ExtensionBase<ServiceExtensionContext>::CreateAndInitContext(record, application, handler, token);
|
||||
if (record == nullptr) {
|
||||
HILOG_ERROR("ServiceExtension::CreateAndInitContext record is nullptr");
|
||||
return context;
|
||||
}
|
||||
context->SetAbilityInfo(record->GetAbilityInfo());
|
||||
return context;
|
||||
}
|
||||
}
|
||||
}
|
@ -99,6 +99,7 @@ ohos_unittest("ability_test") {
|
||||
configs = [ ":module_private_config" ]
|
||||
|
||||
deps = [
|
||||
"${INNERKITS_PATH}/base:base",
|
||||
"${INNERKITS_PATH}/want:want",
|
||||
"//base/global/resmgr_standard/frameworks/resmgr:global_resmgr",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
|
||||
@ -110,6 +111,7 @@ ohos_unittest("ability_test") {
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/task_dispatcher:appkit_dispatcher_td",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/task_dispatcher:appkit_dispatcher_td",
|
||||
"//foundation/appexecfwk/standard/kits:app_context",
|
||||
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
"//foundation/graphic/standard:libwmclient",
|
||||
@ -118,6 +120,7 @@ ohos_unittest("ability_test") {
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"aafwk_standard:runtime",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"multimodalinput_base:libmmi-client",
|
||||
@ -137,6 +140,7 @@ ohos_unittest("ability_lifecycle_test") {
|
||||
configs = [ ":module_private_config" ]
|
||||
|
||||
deps = [
|
||||
"${INNERKITS_PATH}/base:base",
|
||||
"${INNERKITS_PATH}/want:want",
|
||||
"//base/global/resmgr_standard/frameworks/resmgr:global_resmgr",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
|
||||
@ -146,6 +150,7 @@ ohos_unittest("ability_lifecycle_test") {
|
||||
"//foundation/appexecfwk/standard/common:libappexecfwk_common",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
|
||||
"//foundation/appexecfwk/standard/kits:app_context",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//utils/native/base:utils",
|
||||
@ -177,6 +182,7 @@ ohos_unittest("ability_lifecycle_executor_test") {
|
||||
"//foundation/appexecfwk/standard/common:libappexecfwk_common",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
|
||||
"//foundation/appexecfwk/standard/kits:app_context",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//utils/native/base:utils",
|
||||
@ -206,6 +212,7 @@ ohos_unittest("ability_context_for_task_dispacher_test") {
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/task_dispatcher:appkit_dispatcher_td",
|
||||
"//foundation/appexecfwk/standard/kits:app_context",
|
||||
"//foundation/appexecfwk/standard/kits:appkit_native",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
"//third_party/googletest:gmock_main",
|
||||
@ -238,6 +245,7 @@ ohos_unittest("ability_context_interface_test") {
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
|
||||
"//foundation/appexecfwk/standard/kits:app_context",
|
||||
"//foundation/appexecfwk/standard/kits:appkit_native",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
"//third_party/googletest:gmock_main",
|
||||
@ -262,13 +270,21 @@ ohos_unittest("ability_context_test") {
|
||||
"unittest/ability_context_test.cpp",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common",
|
||||
"//foundation/ace/napi/interfaces/kits",
|
||||
]
|
||||
|
||||
configs = [ ":module_ability_context_config" ]
|
||||
|
||||
deps = [
|
||||
"${INNERKITS_PATH}/want:want",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager",
|
||||
"//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common:napi_common",
|
||||
"//foundation/ace/napi:ace_napi",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
|
||||
"//foundation/appexecfwk/standard/kits:app_context",
|
||||
"//foundation/appexecfwk/standard/kits:appkit_native",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
"//third_party/googletest:gmock_main",
|
||||
@ -279,6 +295,7 @@ ohos_unittest("ability_context_test") {
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"multimodalinput_base:libmmi-client",
|
||||
]
|
||||
}
|
||||
|
||||
@ -301,8 +318,10 @@ ohos_unittest("page_ability_impl_test") {
|
||||
"//foundation/appexecfwk/standard/common:libappexecfwk_common",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
|
||||
"//foundation/appexecfwk/standard/kits:app_context",
|
||||
"//foundation/appexecfwk/standard/kits:appkit_native",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
"//foundation/multimodalinput/input/frameworks/proxy:libmmi-common",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
@ -332,6 +351,39 @@ ohos_unittest("service_ability_impl_test") {
|
||||
"//foundation/appexecfwk/standard/common:libappexecfwk_common",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
|
||||
"//foundation/appexecfwk/standard/kits:app_context",
|
||||
"//foundation/appexecfwk/standard/kits:appkit_native",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"multimodalinput_base:libmmi-client",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_unittest("scene_created_test") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
include_dirs = [ "//foundation/windowmanager/interfaces/innerkits/wm" ]
|
||||
|
||||
configs = [ ":module_ability_context_config" ]
|
||||
|
||||
sources = [ "unittest/scene_created_test.cpp" ]
|
||||
|
||||
deps = [
|
||||
"${INNERKITS_PATH}/want:want",
|
||||
"//base/global/resmgr_standard/frameworks/resmgr:global_resmgr",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/base:base",
|
||||
"//foundation/appexecfwk/standard/common:libappexecfwk_common",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
|
||||
"//foundation/appexecfwk/standard/kits:app_context",
|
||||
"//foundation/appexecfwk/standard/kits:appkit_native",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
"//third_party/googletest:gtest_main",
|
||||
@ -354,11 +406,13 @@ ohos_unittest("data_ability_helper_test") {
|
||||
configs = [ ":module_ability_context_config" ]
|
||||
|
||||
deps = [
|
||||
"${INNERKITS_PATH}/base:base",
|
||||
"${INNERKITS_PATH}/want:want",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
|
||||
"//foundation/appexecfwk/standard/kits:app_context",
|
||||
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
|
||||
"//third_party/googletest:gmock_main",
|
||||
"//third_party/googletest:gtest_main",
|
||||
@ -390,6 +444,7 @@ ohos_unittest("data_ability_operation_test") {
|
||||
"//foundation/appexecfwk/standard/common:libappexecfwk_common",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
|
||||
"//foundation/appexecfwk/standard/kits:app_context",
|
||||
"//foundation/appexecfwk/standard/kits:appkit_native",
|
||||
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
@ -429,6 +484,7 @@ ohos_unittest("ability_impl_active_test") {
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/task_dispatcher:appkit_dispatcher_td",
|
||||
"//foundation/appexecfwk/standard/kits:app_context",
|
||||
"//foundation/appexecfwk/standard/kits:appkit_native",
|
||||
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
@ -437,6 +493,7 @@ ohos_unittest("ability_impl_active_test") {
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"aafwk_standard:runtime",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"multimodalinput_base:libmmi-client",
|
||||
@ -465,14 +522,17 @@ ohos_unittest("ability_impl_test") {
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/task_dispatcher:appkit_dispatcher_td",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/task_dispatcher:appkit_dispatcher_td",
|
||||
"//foundation/appexecfwk/standard/kits:app_context",
|
||||
"//foundation/appexecfwk/standard/kits:appkit_native",
|
||||
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
"//foundation/multimodalinput/input/frameworks/proxy:libmmi-common",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"aafwk_standard:runtime",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"multimodalinput_base:libmmi-client",
|
||||
@ -512,6 +572,7 @@ ohos_unittest("ability_thread_test") {
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/task_dispatcher:appkit_dispatcher_td",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/task_dispatcher:appkit_dispatcher_td",
|
||||
"//foundation/appexecfwk/standard/kits:app_context",
|
||||
"//foundation/appexecfwk/standard/kits:appkit_native",
|
||||
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
@ -521,6 +582,7 @@ ohos_unittest("ability_thread_test") {
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"aafwk_standard:runtime",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"multimodalinput_base:libmmi-client",
|
||||
@ -556,6 +618,7 @@ ohos_unittest("form_provider_client_test") {
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
|
||||
"//foundation/appexecfwk/standard/kits:app_context",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
"//foundation/graphic/standard:libwmclient",
|
||||
"//third_party/googletest:gtest_main",
|
||||
@ -586,6 +649,7 @@ ohos_unittest("data_ability_impl_test") {
|
||||
configs = [ ":module_private_config" ]
|
||||
|
||||
deps = [
|
||||
"${INNERKITS_PATH}/base:base",
|
||||
"${INNERKITS_PATH}/want:want",
|
||||
"//base/global/resmgr_standard/frameworks/resmgr:global_resmgr",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
|
||||
@ -596,6 +660,7 @@ ohos_unittest("data_ability_impl_test") {
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/task_dispatcher:appkit_dispatcher_td",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/task_dispatcher:appkit_dispatcher_td",
|
||||
"//foundation/appexecfwk/standard/kits:app_context",
|
||||
"//foundation/appexecfwk/standard/kits:appkit_native",
|
||||
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
@ -605,6 +670,7 @@ ohos_unittest("data_ability_impl_test") {
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"aafwk_standard:runtime",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"multimodalinput_base:libmmi-client",
|
||||
@ -631,6 +697,7 @@ ohos_unittest("data_ability_impl_file_secondpart_test") {
|
||||
configs = [ ":module_private_config" ]
|
||||
|
||||
deps = [
|
||||
"${INNERKITS_PATH}/base:base",
|
||||
"${INNERKITS_PATH}/want:want",
|
||||
"//base/global/resmgr_standard/frameworks/resmgr:global_resmgr",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
|
||||
@ -641,6 +708,7 @@ ohos_unittest("data_ability_impl_file_secondpart_test") {
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/task_dispatcher:appkit_dispatcher_td",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/task_dispatcher:appkit_dispatcher_td",
|
||||
"//foundation/appexecfwk/standard/kits:app_context",
|
||||
"//foundation/appexecfwk/standard/kits:appkit_native",
|
||||
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
@ -650,6 +718,7 @@ ohos_unittest("data_ability_impl_file_secondpart_test") {
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"aafwk_standard:runtime",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"multimodalinput_base:libmmi-client",
|
||||
@ -676,6 +745,7 @@ ohos_unittest("data_ability_impl_file_test") {
|
||||
configs = [ ":module_private_config" ]
|
||||
|
||||
deps = [
|
||||
"${INNERKITS_PATH}/base:base",
|
||||
"${INNERKITS_PATH}/want:want",
|
||||
"//base/global/resmgr_standard/frameworks/resmgr:global_resmgr",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
|
||||
@ -686,6 +756,7 @@ ohos_unittest("data_ability_impl_file_test") {
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/task_dispatcher:appkit_dispatcher_td",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/task_dispatcher:appkit_dispatcher_td",
|
||||
"//foundation/appexecfwk/standard/kits:app_context",
|
||||
"//foundation/appexecfwk/standard/kits:appkit_native",
|
||||
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
@ -695,6 +766,7 @@ ohos_unittest("data_ability_impl_file_test") {
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"aafwk_standard:runtime",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"multimodalinput_base:libmmi-client",
|
||||
@ -734,6 +806,7 @@ ohos_unittest("ability_thread_dataability_test") {
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/task_dispatcher:appkit_dispatcher_td",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/task_dispatcher:appkit_dispatcher_td",
|
||||
"//foundation/appexecfwk/standard/kits:app_context",
|
||||
"//foundation/appexecfwk/standard/kits:appkit_native",
|
||||
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
@ -743,6 +816,7 @@ ohos_unittest("ability_thread_dataability_test") {
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"aafwk_standard:runtime",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"multimodalinput_base:libmmi-client",
|
||||
@ -783,6 +857,7 @@ ohos_unittest("data_uri_utils_test") {
|
||||
"//foundation/appexecfwk/standard/common:libappexecfwk_common",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
|
||||
"//foundation/appexecfwk/standard/kits:app_context",
|
||||
"//foundation/appexecfwk/standard/kits:appkit_native",
|
||||
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
|
||||
"//third_party/googletest:gtest_main",
|
||||
@ -836,6 +911,7 @@ ohos_unittest("ability_permission_test") {
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
|
||||
"//foundation/appexecfwk/standard/kits:app_context",
|
||||
"//foundation/appexecfwk/standard/kits:appkit_native",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
"//third_party/googletest:gmock_main",
|
||||
@ -884,6 +960,7 @@ ohos_unittest("ability_thread_for_ability_on_configuration_update") {
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/want:want",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
|
||||
"//foundation/appexecfwk/standard/kits:app_context",
|
||||
"//foundation/appexecfwk/standard/kits:appkit_native",
|
||||
"//third_party/googletest:gmock_main",
|
||||
"//third_party/googletest:gtest_main",
|
||||
@ -941,6 +1018,7 @@ ohos_unittest("form_host_client_test") {
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/task_dispatcher:appkit_dispatcher_td",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/task_dispatcher:appkit_dispatcher_td",
|
||||
"//foundation/appexecfwk/standard/kits:app_context",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
"//foundation/graphic/standard:libwmclient",
|
||||
"//third_party/googletest:gmock_main",
|
||||
@ -949,6 +1027,7 @@ ohos_unittest("form_host_client_test") {
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"aafwk_standard:runtime",
|
||||
"appexecfwk_standard:fmskit_native",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
@ -956,6 +1035,47 @@ ohos_unittest("form_host_client_test") {
|
||||
]
|
||||
}
|
||||
|
||||
ohos_unittest("continuation_test") {
|
||||
module_out_path = module_output_path
|
||||
sources = [
|
||||
"//foundation/appexecfwk/standard/kits/appkit/native/app/src/app_loader.cpp",
|
||||
"//foundation/appexecfwk/standard/kits/appkit/native/app/src/application_context.cpp",
|
||||
"//foundation/appexecfwk/standard/kits/appkit/native/app/src/ohos_application.cpp",
|
||||
"unittest/continuation_test.cpp",
|
||||
]
|
||||
|
||||
configs = [ ":module_private_config" ]
|
||||
|
||||
deps = [
|
||||
"${INNERKITS_PATH}/want:want",
|
||||
"//base/global/resmgr_standard/frameworks/resmgr:global_resmgr",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/base:base",
|
||||
"//foundation/appexecfwk/standard/common:libappexecfwk_common",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/task_dispatcher:appkit_dispatcher_td",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/task_dispatcher:appkit_dispatcher_td",
|
||||
"//foundation/appexecfwk/standard/kits:app_context",
|
||||
"//foundation/appexecfwk/standard/kits:appkit_native",
|
||||
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"aafwk_standard:runtime",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"multimodalinput_base:libmmi-client",
|
||||
"native_appdatamgr:native_appdatafwk",
|
||||
"native_appdatamgr:native_dataability",
|
||||
"native_appdatamgr:native_rdb",
|
||||
]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
|
||||
group("unittest") {
|
||||
@ -971,6 +1091,7 @@ group("unittest") {
|
||||
":ability_test",
|
||||
":ability_thread_dataability_test",
|
||||
":ability_thread_test",
|
||||
":continuation_test",
|
||||
":data_ability_helper_test",
|
||||
":data_ability_impl_file_secondpart_test",
|
||||
":data_ability_impl_file_test",
|
||||
|
@ -191,7 +191,7 @@ public:
|
||||
virtual bool IsSafeMode() = 0;
|
||||
virtual bool CleanBundleCacheFiles(
|
||||
const std::string &bundleName, const sptr<ICleanCacheCallback> &cleanCacheCallback) = 0;
|
||||
virtual bool CleanBundleDataFiles(const std::string &bundleName) = 0;
|
||||
virtual bool CleanBundleDataFiles(const std::string &bundleName, const int userId = 0) = 0;
|
||||
virtual bool RegisterBundleStatusCallback(const sptr<IBundleStatusCallback> &bundleStatusCallback) = 0;
|
||||
virtual bool ClearBundleStatusCallback(const sptr<IBundleStatusCallback> &bundleStatusCallback) = 0;
|
||||
virtual bool UnregisterBundleStatusCallback() = 0;
|
||||
|
2
frameworks/kits/ability/native/test/mock/include/mock_ability.cpp
Normal file → Executable file
2
frameworks/kits/ability/native/test/mock/include/mock_ability.cpp
Normal file → Executable file
@ -13,8 +13,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "ability.h"
|
||||
#include <gtest/gtest.h>
|
||||
#include "ability_loader.h"
|
||||
#include "app_log_wrapper.h"
|
||||
#include "iservice_registry.h"
|
||||
|
2
frameworks/kits/ability/native/test/mock/include/mock_ability_impl.h
Normal file → Executable file
2
frameworks/kits/ability/native/test/mock/include/mock_ability_impl.h
Normal file → Executable file
@ -16,9 +16,9 @@
|
||||
#ifndef FOUNDATION_APPEXECFWK_OHOS_MOCK_INHERITANCE_IMPL_H
|
||||
#define FOUNDATION_APPEXECFWK_OHOS_MOCK_INHERITANCE_IMPL_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "ability.h"
|
||||
#include "ability_impl.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
|
1
frameworks/kits/ability/native/test/mock/include/mock_ability_manager_client.h
Normal file → Executable file
1
frameworks/kits/ability/native/test/mock/include/mock_ability_manager_client.h
Normal file → Executable file
@ -126,6 +126,7 @@ public:
|
||||
{
|
||||
return std::vector<std::shared_ptr<AppExecFwk::DataAbilityResult>>();
|
||||
};
|
||||
virtual void NotifyContinuationResult(const int32_t result){};
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
@ -45,6 +45,10 @@ public:
|
||||
}
|
||||
int TerminateAbility(
|
||||
const sptr<IRemoteObject> &token, int resultCode = -1, const Want *resultWant = nullptr) override;
|
||||
int MinimizeAbility(const sptr<IRemoteObject> &token) override
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int ConnectAbility(
|
||||
const Want &want, const sptr<IAbilityConnection> &connect, const sptr<IRemoteObject> &callerToken) override;
|
||||
int DisconnectAbility(const sptr<IAbilityConnection> &connect) override;
|
||||
@ -118,6 +122,8 @@ public:
|
||||
MOCK_METHOD1(GetPendinTerminateAbilityTestgRequestWant, void(int id));
|
||||
MOCK_METHOD1(GetSystemMemoryAttr, void(AppExecFwk::SystemMemoryAttr &memoryInfo));
|
||||
MOCK_METHOD2(GetWantSenderInfo, int(const sptr<IWantSender> &target, std::shared_ptr<WantSenderInfo> &info));
|
||||
MOCK_METHOD2(StartContinuation, int(const Want &want, const sptr<IRemoteObject> &abilityToken));
|
||||
MOCK_METHOD2(NotifyContinuationResult, int(const sptr<IRemoteObject> &abilityToken, const int32_t result));
|
||||
int RemoveMission(int id) override;
|
||||
|
||||
int RemoveStack(int id) override;
|
||||
|
1
frameworks/kits/ability/native/test/mock/include/mock_ability_scheduler_for_observer.h
Normal file → Executable file
1
frameworks/kits/ability/native/test/mock/include/mock_ability_scheduler_for_observer.h
Normal file → Executable file
@ -60,6 +60,7 @@ public:
|
||||
MOCK_METHOD1(ExecuteBatch,
|
||||
std::vector<std::shared_ptr<AppExecFwk::DataAbilityResult>>
|
||||
(const std::vector<std::shared_ptr<AppExecFwk::DataAbilityOperation>> &operation));
|
||||
MOCK_METHOD1(NotifyContinuationResult, void(const int32_t result));
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
2
frameworks/kits/ability/native/test/mock/include/mock_ability_thread.h
Normal file → Executable file
2
frameworks/kits/ability/native/test/mock/include/mock_ability_thread.h
Normal file → Executable file
@ -16,10 +16,10 @@
|
||||
#ifndef FOUNDATION_APPEXECFWK_OHOS_MOCK_ABILITY_THREAD_H
|
||||
#define FOUNDATION_APPEXECFWK_OHOS_MOCK_ABILITY_THREAD_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "ability.h"
|
||||
#include "ability_impl.h"
|
||||
#include "ability_thread.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
|
@ -165,7 +165,7 @@ bool BundleMgrProxy::CleanBundleCacheFiles(
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrProxy::CleanBundleDataFiles(const std::string &bundleName)
|
||||
bool BundleMgrProxy::CleanBundleDataFiles(const std::string &bundleName, const int userId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -418,7 +418,7 @@ bool BundleMgrService::CleanBundleCacheFiles(
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::CleanBundleDataFiles(const std::string &bundleName)
|
||||
bool BundleMgrService::CleanBundleDataFiles(const std::string &bundleName, const int userId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ public:
|
||||
virtual bool IsSafeMode() override;
|
||||
virtual bool CleanBundleCacheFiles(
|
||||
const std::string &bundleName, const sptr<ICleanCacheCallback> &cleanCacheCallback) override;
|
||||
virtual bool CleanBundleDataFiles(const std::string &bundleName) override;
|
||||
virtual bool CleanBundleDataFiles(const std::string &bundleName, const int userId = 0) override;
|
||||
virtual bool RegisterBundleStatusCallback(const sptr<IBundleStatusCallback> &bundleStatusCallback) override;
|
||||
virtual bool ClearBundleStatusCallback(const sptr<IBundleStatusCallback> &bundleStatusCallback) override;
|
||||
virtual bool UnregisterBundleStatusCallback() override;
|
||||
@ -145,7 +145,7 @@ public:
|
||||
virtual bool IsSafeMode() override;
|
||||
virtual bool CleanBundleCacheFiles(
|
||||
const std::string &bundleName, const sptr<ICleanCacheCallback> &cleanCacheCallback) override;
|
||||
virtual bool CleanBundleDataFiles(const std::string &bundleName) override;
|
||||
virtual bool CleanBundleDataFiles(const std::string &bundleName, const int userId) override;
|
||||
virtual bool RegisterBundleStatusCallback(const sptr<IBundleStatusCallback> &bundleStatusCallback) override;
|
||||
virtual bool ClearBundleStatusCallback(const sptr<IBundleStatusCallback> &bundleStatusCallback) override;
|
||||
virtual bool UnregisterBundleStatusCallback() override;
|
||||
|
6
frameworks/kits/ability/native/test/mock/include/mock_bundle_manager_form.h
Normal file → Executable file
6
frameworks/kits/ability/native/test/mock/include/mock_bundle_manager_form.h
Normal file → Executable file
@ -151,7 +151,7 @@ public:
|
||||
{
|
||||
return true;
|
||||
}
|
||||
virtual bool CleanBundleDataFiles(const std::string &bundleName, const int userId) override
|
||||
virtual bool CleanBundleDataFiles(const std::string &bundleName, const int userId = 0) override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -268,6 +268,10 @@ public:
|
||||
{
|
||||
return true;
|
||||
};
|
||||
virtual bool QueryAbilityInfosForClone(const Want &want, std::vector<AbilityInfo> &abilityInfos) override
|
||||
{
|
||||
return true;
|
||||
};
|
||||
virtual bool GetBundleNameForUid(const int uid, std::string &bundleName) override
|
||||
{
|
||||
bundleName = "com.form.provider.service";
|
||||
|
@ -13,29 +13,33 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_APPEXECFWK_OHOS_ABILITY_TOUCHEVENT_HANDLE_H
|
||||
#define FOUNDATION_APPEXECFWK_OHOS_ABILITY_TOUCHEVENT_HANDLE_H
|
||||
#ifndef FOUNDATION_APPEXECFWK_OHOS_MOCK_CONTINUATION_ABILITY_H
|
||||
#define FOUNDATION_APPEXECFWK_OHOS_MOCK_CONTINUATION_ABILITY_H
|
||||
|
||||
#include <memory>
|
||||
#include "multimodal_event_handler.h"
|
||||
#include "touch_event_handler.h"
|
||||
#include "ability.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class AbilityImpl;
|
||||
class AbilityTouchEventHandle : public MMI::TouchEventHandler {
|
||||
using Want = OHOS::AAFwk::Want;
|
||||
|
||||
class MockContinuationAbility : public Ability {
|
||||
public:
|
||||
AbilityTouchEventHandle(std::shared_ptr<AbilityImpl> ability);
|
||||
virtual ~AbilityTouchEventHandle();
|
||||
MockContinuationAbility() = default;
|
||||
virtual ~MockContinuationAbility() = default;
|
||||
|
||||
/**
|
||||
* @brief Called back when on touch.
|
||||
*/
|
||||
virtual bool OnTouch(const TouchEvent& touchEvent) override;
|
||||
bool OnStartContinuation()
|
||||
{
|
||||
GTEST_LOG_(INFO) << "MockContinuationAbility::OnStartContinuation called";
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<AbilityImpl> abilityImpl_ = nullptr;
|
||||
bool OnSaveData(WantParams &saveData)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "MockContinuationAbility::OnSaveData called";
|
||||
return true;
|
||||
}
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
#endif // FOUNDATION_APPEXECFWK_OHOS_ABILITY_TOUCHEVENT_HANDLE_H
|
||||
#endif // FOUNDATION_APPEXECFWK_OHOS_MOCK_PAGE_ABILITY_H
|
2
frameworks/kits/ability/native/test/mock/include/mock_data_ability.h
Normal file → Executable file
2
frameworks/kits/ability/native/test/mock/include/mock_data_ability.h
Normal file → Executable file
@ -16,8 +16,8 @@
|
||||
#ifndef FOUNDATION_APPEXECFWK_OHOS_MOCK_DATA_ABILITY_H
|
||||
#define FOUNDATION_APPEXECFWK_OHOS_MOCK_DATA_ABILITY_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "ability.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "abs_shared_result_set.h"
|
||||
#include "data_ability_predicates.h"
|
||||
|
2
frameworks/kits/ability/native/test/mock/include/mock_data_ability_impl.cpp
Normal file → Executable file
2
frameworks/kits/ability/native/test/mock/include/mock_data_ability_impl.cpp
Normal file → Executable file
@ -13,11 +13,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "abs_shared_result_set.h"
|
||||
#include "data_ability_predicates.h"
|
||||
#include "values_bucket.h"
|
||||
#include "data_ability_impl.h"
|
||||
#include <gtest/gtest.h>
|
||||
#include "app_log_wrapper.h"
|
||||
|
||||
const int returnValueOpenfile = 11;
|
||||
|
2
frameworks/kits/ability/native/test/mock/include/mock_lifecycle_observer.h
Normal file → Executable file
2
frameworks/kits/ability/native/test/mock/include/mock_lifecycle_observer.h
Normal file → Executable file
@ -16,9 +16,9 @@
|
||||
#ifndef FOUNDATION_APPEXECFWK_OHOS_MOCK_LIFECYCLE_OBSERVER_INTERFACE_H
|
||||
#define FOUNDATION_APPEXECFWK_OHOS_MOCK_LIFECYCLE_OBSERVER_INTERFACE_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "want.h"
|
||||
#include "ability_lifecycle_observer_interface.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
|
11
frameworks/kits/ability/native/test/mock/include/mock_page_ability.h
Normal file → Executable file
11
frameworks/kits/ability/native/test/mock/include/mock_page_ability.h
Normal file → Executable file
@ -16,8 +16,8 @@
|
||||
#ifndef FOUNDATION_APPEXECFWK_OHOS_MOCK_PAGE_ABILITY_H
|
||||
#define FOUNDATION_APPEXECFWK_OHOS_MOCK_PAGE_ABILITY_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "ability.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
@ -30,22 +30,19 @@ public:
|
||||
|
||||
enum Event { ON_ACTIVE = 0, ON_BACKGROUND, ON_FOREGROUND, ON_INACTIVE, ON_START, ON_STOP, UNDEFINED };
|
||||
|
||||
bool OnKeyDown(int keyCode, const KeyEvent &keyEvent)
|
||||
void OnKeyDown(const std::shared_ptr<MMI::KeyEvent>& keyEvent)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "MockPageAbility::OnKeyDown called";
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OnKeyUp(int keyCode, const KeyEvent &keyEvent)
|
||||
void OnKeyUp(const std::shared_ptr<MMI::KeyEvent>& keyEvent)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "MockPageAbility::OnKeyUp called";
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OnTouchEvent(const TouchEvent &touchEvent)
|
||||
void OnPointerEvent(std::shared_ptr<MMI::PointerEvent>& pointerEvent)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "MockPageAbility::OnTouchEvent called";
|
||||
return true;
|
||||
}
|
||||
|
||||
void OnAbilityResult(int requestCode, int resultCode, const AAFwk::Want &resultData)
|
||||
|
17
frameworks/kits/ability/native/test/mock/include/mock_replace_ability_impl.cpp
Normal file → Executable file
17
frameworks/kits/ability/native/test/mock/include/mock_replace_ability_impl.cpp
Normal file → Executable file
@ -13,8 +13,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "ability_impl.h"
|
||||
#include <gtest/gtest.h>
|
||||
#include "ability_local_record.h"
|
||||
#include "app_log_wrapper.h"
|
||||
|
||||
@ -132,20 +132,11 @@ int AbilityImpl::GetCurrentState()
|
||||
return lifecycleState_;
|
||||
}
|
||||
|
||||
bool AbilityImpl::DoKeyDown(int keyCode, const KeyEvent &keyEvent)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
void AbilityImpl::DoKeyDown(const std::shared_ptr<MMI::KeyEvent>& keyEvent) {}
|
||||
|
||||
bool AbilityImpl::DoKeyUp(int keyCode, const KeyEvent &keyEvent)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
void AbilityImpl::DoKeyUp(const std::shared_ptr<MMI::KeyEvent>& keyEvent) {}
|
||||
|
||||
bool AbilityImpl::DoTouchEvent(const TouchEvent &touchEvent)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
void AbilityImpl::DoPointerEvent(std::shared_ptr<MMI::PointerEvent>& pointerEvent) {}
|
||||
|
||||
void AbilityImpl::SendResult(int requestCode, int resultCode, const Want &resultData)
|
||||
{
|
||||
|
@ -1,41 +1,41 @@
|
||||
/*
|
||||
* 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 FOUNDATION_APPEXECFWK_OHOS_ABILITY_KEYEVENT_HANDLE_H
|
||||
#define FOUNDATION_APPEXECFWK_OHOS_ABILITY_KEYEVENT_HANDLE_H
|
||||
|
||||
#include <memory>
|
||||
#include "multimodal_event_handler.h"
|
||||
#include "key_event_handler.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class AbilityImpl;
|
||||
class AbilityKeyEventHandle : public MMI::KeyEventHandler {
|
||||
public:
|
||||
AbilityKeyEventHandle(const std::shared_ptr<AbilityImpl> &ability);
|
||||
~AbilityKeyEventHandle();
|
||||
|
||||
/**
|
||||
* @brief Called back when on key.
|
||||
*/
|
||||
virtual bool OnKey(const KeyEvent& keyEvent) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<AbilityImpl> abilityImpl_ = nullptr;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
#endif // FOUNDATION_APPEXECFWK_OHOS_ABILITY_KEYEVENT_HANDLE_H
|
||||
/*
|
||||
* 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 FOUNDATION_APPEXECFWK_OHOS_MOCK_ABILITY_SCENE_H
|
||||
#define FOUNDATION_APPEXECFWK_OHOS_MOCK_ABILITY_SCENE_H
|
||||
|
||||
#include "ability.h"
|
||||
#include "window_scene.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class MockSceneCreatedAbility : public Ability {
|
||||
public:
|
||||
MockSceneCreatedAbility() = default;
|
||||
virtual ~MockSceneCreatedAbility() = default;
|
||||
|
||||
void OnSceneCreated() {
|
||||
++time;
|
||||
}
|
||||
|
||||
int GetTriggerTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
int time = 0;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
#endif // FOUNDATION_APPEXECFWK_OHOS_MOCK_ABILITY_SCENE_H
|
9
frameworks/kits/ability/native/test/mock/include/mock_service_ability.h
Normal file → Executable file
9
frameworks/kits/ability/native/test/mock/include/mock_service_ability.h
Normal file → Executable file
@ -28,22 +28,19 @@ public:
|
||||
MockServiceAbility() = default;
|
||||
virtual ~MockServiceAbility() = default;
|
||||
|
||||
bool OnKeyDown(int keyCode, const KeyEvent &keyEvent)
|
||||
void OnKeyDown(const std::shared_ptr<MMI::KeyEvent>& keyEvent)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "MockServiceAbility::OnKeyDown called";
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OnKeyUp(int keyCode, const KeyEvent &keyEvent)
|
||||
void OnKeyUp(const std::shared_ptr<MMI::KeyEvent>& keyEvent)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "MockServiceAbility::OnKeyUp called";
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OnTouchEvent(const TouchEvent &touchEvent)
|
||||
void OnPointerEvent(std::shared_ptr<MMI::PointerEvent>& pointerEvent)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "MockServiceAbility::OnTouchEvent called";
|
||||
return true;
|
||||
}
|
||||
|
||||
void OnAbilityResult(int requestCode, int resultCode, const AAFwk::Want &resultData)
|
||||
|
55
frameworks/kits/ability/native/test/unittest/ability_context_test.cpp
Normal file → Executable file
55
frameworks/kits/ability/native/test/unittest/ability_context_test.cpp
Normal file → Executable file
@ -24,6 +24,8 @@
|
||||
#include "iservice_registry.h"
|
||||
#include "mock_bundle_manager.h"
|
||||
#include "mock_ability_manager_service.h"
|
||||
#include "napi_common_ability.h"
|
||||
#include "ohos_application.h"
|
||||
#include "system_ability_definition.h"
|
||||
#include "sys_mgr_client.h"
|
||||
#include "sa_mgr_client.h"
|
||||
@ -499,6 +501,41 @@ HWTEST_F(AbilityContextTest, AaFwk_AbilityContext_ConnectAbility_0200, Function
|
||||
EXPECT_FALSE(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AaFwk_AbilityContext_ConnectAbility_0300
|
||||
* @tc.desc: Test the attachbasecontext call to verify that the return value of connectability is true.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000GI8I8
|
||||
*/
|
||||
HWTEST_F(AbilityContextTest, AaFwk_AbilityContext_ConnectAbility_0300, Function | MediumTest | Level1)
|
||||
{
|
||||
std::shared_ptr<ContextDeal> deal = std::make_shared<ContextDeal>();
|
||||
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
|
||||
|
||||
abilityInfo->type = AppExecFwk::AbilityType::SERVICE;
|
||||
deal->SetAbilityInfo(abilityInfo);
|
||||
context_->AttachBaseContext(deal);
|
||||
|
||||
Want want;
|
||||
OHOS::sptr<AAFwk::IAbilityConnection> callback = new NAPIAbilityConnection();
|
||||
bool ret = context_->ConnectAbility(want, callback);
|
||||
EXPECT_TRUE(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AaFwk_AbilityContext_ConnectAbility_0400
|
||||
* @tc.desc: Test the attachbasecontext call to verify that the return value of connectability is false.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000GI8I8
|
||||
*/
|
||||
HWTEST_F(AbilityContextTest, AaFwk_AbilityContext_ConnectAbility_0400, Function | MediumTest | Level3)
|
||||
{
|
||||
Want want;
|
||||
OHOS::sptr<AAFwk::IAbilityConnection> callback = new NAPIAbilityConnection();
|
||||
bool ret = context_->ConnectAbility(want, callback);
|
||||
EXPECT_FALSE(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: AaFwk_AbilityContext_DisconnectAbility_0100
|
||||
* @tc.name: DisconnectAbility
|
||||
@ -515,6 +552,24 @@ HWTEST_F(AbilityContextTest, AaFwk_AbilityContext_DisconnectAbility_0100, Functi
|
||||
context_->DisconnectAbility(nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AaFwk_AbilityContext_DisconnectAbility_0200
|
||||
* @tc.desc: Test whether the disconnectability is called normally.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000GI8I8
|
||||
*/
|
||||
HWTEST_F(AbilityContextTest, AaFwk_AbilityContext_DisconnectAbility_0200, Function | MediumTest | Level1)
|
||||
{
|
||||
std::shared_ptr<ContextDeal> deal = std::make_shared<ContextDeal>();
|
||||
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
|
||||
|
||||
abilityInfo->type = AppExecFwk::AbilityType::SERVICE;
|
||||
deal->SetAbilityInfo(abilityInfo);
|
||||
context_->AttachBaseContext(deal);
|
||||
OHOS::sptr<AAFwk::IAbilityConnection> callback = new NAPIAbilityConnection();
|
||||
context_->DisconnectAbility(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: AaFwk_AbilityContext_StopAbility_0100
|
||||
* @tc.name: StopAbility
|
||||
|
381
frameworks/kits/ability/native/test/unittest/ability_impl_test.cpp
Normal file → Executable file
381
frameworks/kits/ability/native/test/unittest/ability_impl_test.cpp
Normal file → Executable file
@ -37,6 +37,7 @@ namespace AppExecFwk {
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
const int TARGET_VERSION_THRESHOLDS = 8;
|
||||
|
||||
class AbilityImplTest : public testing::Test {
|
||||
public:
|
||||
@ -592,6 +593,366 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Background_002, TestSize.Level1)
|
||||
GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Background_002 end";
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AbilityImpl
|
||||
* Function: Foreground
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: Foreground
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Test the normal behavior of the AbilityImpl::Foreground
|
||||
*/
|
||||
HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_New_Foreground_001, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_New_Foreground_001 start";
|
||||
std::shared_ptr<MockAbilityimpl> mockAbilityimpl = std::make_shared<MockAbilityimpl>();
|
||||
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
|
||||
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
|
||||
abilityInfo->name = "pageAbility";
|
||||
sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
|
||||
EXPECT_NE(token, nullptr);
|
||||
if (token != nullptr) {
|
||||
std::shared_ptr<AbilityLocalRecord> record = std::make_shared<AbilityLocalRecord>(abilityInfo, token);
|
||||
std::shared_ptr<EventRunner> eventRunner = EventRunner::Create(abilityInfo->name);
|
||||
sptr<AbilityThread> abilityThread = sptr<AbilityThread>(new (std::nothrow) AbilityThread());
|
||||
EXPECT_NE(abilityThread, nullptr);
|
||||
if (abilityThread != nullptr) {
|
||||
std::shared_ptr<AbilityHandler> handler = std::make_shared<AbilityHandler>(eventRunner, abilityThread);
|
||||
std::shared_ptr<Ability> ability = nullptr;
|
||||
MockPageAbility *pMocKPageAbility = new (std::nothrow) MockPageAbility();
|
||||
EXPECT_NE(pMocKPageAbility, nullptr);
|
||||
if (pMocKPageAbility != nullptr) {
|
||||
ability.reset(pMocKPageAbility);
|
||||
ability->SetTargetVersion(TARGET_VERSION_THRESHOLDS);
|
||||
std::shared_ptr<ContextDeal> contextDeal = std::make_shared<ContextDeal>();
|
||||
mockAbilityimpl->Init(application, record, ability, handler, token, contextDeal);
|
||||
|
||||
Want want;
|
||||
mockAbilityimpl->ImplForeground(want);
|
||||
|
||||
EXPECT_EQ(MockPageAbility::Event::ON_FOREGROUND, pMocKPageAbility->state_);
|
||||
EXPECT_EQ(AAFwk::ABILITY_STATE_FOREGROUND_NEW, mockAbilityimpl->GetCurrentState());
|
||||
}
|
||||
}
|
||||
}
|
||||
GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_New_Foreground_001 end";
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AbilityImpl
|
||||
* Function: Foreground
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: Foreground
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Test the normal behavior of the AbilityImpl::Foreground
|
||||
*/
|
||||
HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_New_Foreground_002, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_New_Foreground_002 start";
|
||||
std::shared_ptr<MockAbilityimpl> mockAbilityimpl = std::make_shared<MockAbilityimpl>();
|
||||
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
|
||||
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
|
||||
abilityInfo->name = "pageAbility";
|
||||
sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
|
||||
EXPECT_NE(token, nullptr);
|
||||
if (token != nullptr) {
|
||||
std::shared_ptr<AbilityLocalRecord> record = std::make_shared<AbilityLocalRecord>(abilityInfo, token);
|
||||
std::shared_ptr<EventRunner> eventRunner = EventRunner::Create(abilityInfo->name);
|
||||
sptr<AbilityThread> abilityThread = sptr<AbilityThread>(new (std::nothrow) AbilityThread());
|
||||
EXPECT_NE(abilityThread, nullptr);
|
||||
if (abilityThread != nullptr) {
|
||||
std::shared_ptr<AbilityHandler> handler = std::make_shared<AbilityHandler>(eventRunner, abilityThread);
|
||||
std::shared_ptr<Ability> ability = nullptr;
|
||||
MockPageAbility *pMocKPageAbility = new (std::nothrow) MockPageAbility();
|
||||
EXPECT_NE(pMocKPageAbility, nullptr);
|
||||
if (pMocKPageAbility != nullptr) {
|
||||
ability.reset(pMocKPageAbility);
|
||||
ability->SetTargetVersion(TARGET_VERSION_THRESHOLDS);
|
||||
std::shared_ptr<ContextDeal> contextDeal = std::make_shared<ContextDeal>();
|
||||
mockAbilityimpl->Init(application, record, ability, handler, token, contextDeal);
|
||||
|
||||
Want want;
|
||||
mockAbilityimpl->ImplForeground(want);
|
||||
mockAbilityimpl->ImplForeground(want);
|
||||
mockAbilityimpl->ImplForeground(want);
|
||||
|
||||
EXPECT_EQ(MockPageAbility::Event::ON_FOREGROUND, pMocKPageAbility->state_);
|
||||
EXPECT_EQ(AAFwk::ABILITY_STATE_FOREGROUND_NEW, mockAbilityimpl->GetCurrentState());
|
||||
}
|
||||
}
|
||||
}
|
||||
GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_New_Foreground_002 end";
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AbilityImpl
|
||||
* Function: Background
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: Background
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Test the normal behavior of the AbilityImpl::Background
|
||||
*/
|
||||
HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_New_Background_001, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_New_Foreground_001 start";
|
||||
std::shared_ptr<MockAbilityimpl> mockAbilityimpl = std::make_shared<MockAbilityimpl>();
|
||||
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
|
||||
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
|
||||
abilityInfo->name = "pageAbility";
|
||||
sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
|
||||
EXPECT_NE(token, nullptr);
|
||||
if (token != nullptr) {
|
||||
std::shared_ptr<AbilityLocalRecord> record = std::make_shared<AbilityLocalRecord>(abilityInfo, token);
|
||||
std::shared_ptr<EventRunner> eventRunner = EventRunner::Create(abilityInfo->name);
|
||||
sptr<AbilityThread> abilityThread = sptr<AbilityThread>(new (std::nothrow) AbilityThread());
|
||||
EXPECT_NE(abilityThread, nullptr);
|
||||
if (abilityThread != nullptr) {
|
||||
std::shared_ptr<AbilityHandler> handler = std::make_shared<AbilityHandler>(eventRunner, abilityThread);
|
||||
std::shared_ptr<Ability> ability = nullptr;
|
||||
MockPageAbility *pMocKPageAbility = new (std::nothrow) MockPageAbility();
|
||||
EXPECT_NE(pMocKPageAbility, nullptr);
|
||||
if (pMocKPageAbility != nullptr) {
|
||||
ability.reset(pMocKPageAbility);
|
||||
ability->SetTargetVersion(TARGET_VERSION_THRESHOLDS);
|
||||
std::shared_ptr<ContextDeal> contextDeal = std::make_shared<ContextDeal>();
|
||||
mockAbilityimpl->Init(application, record, ability, handler, token, contextDeal);
|
||||
|
||||
mockAbilityimpl->ImplBackground();
|
||||
|
||||
EXPECT_EQ(MockPageAbility::Event::ON_BACKGROUND, pMocKPageAbility->state_);
|
||||
EXPECT_EQ(AAFwk::ABILITY_STATE_BACKGROUND, mockAbilityimpl->GetCurrentState());
|
||||
}
|
||||
}
|
||||
}
|
||||
GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_New_Background_001 end";
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AbilityImpl
|
||||
* Function: Background
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: Background
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Test the normal behavior of the AbilityImpl::Background
|
||||
*/
|
||||
HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_New_Background_002, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_New_Background_002 start";
|
||||
std::shared_ptr<MockAbilityimpl> mockAbilityimpl = std::make_shared<MockAbilityimpl>();
|
||||
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
|
||||
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
|
||||
abilityInfo->name = "pageAbility";
|
||||
sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
|
||||
EXPECT_NE(token, nullptr);
|
||||
if (token != nullptr) {
|
||||
std::shared_ptr<AbilityLocalRecord> record = std::make_shared<AbilityLocalRecord>(abilityInfo, token);
|
||||
std::shared_ptr<EventRunner> eventRunner = EventRunner::Create(abilityInfo->name);
|
||||
sptr<AbilityThread> abilityThread = sptr<AbilityThread>(new (std::nothrow) AbilityThread());
|
||||
EXPECT_NE(abilityThread, nullptr);
|
||||
if (abilityThread != nullptr) {
|
||||
std::shared_ptr<AbilityHandler> handler = std::make_shared<AbilityHandler>(eventRunner, abilityThread);
|
||||
std::shared_ptr<Ability> ability = nullptr;
|
||||
MockPageAbility *pMocKPageAbility = new (std::nothrow) MockPageAbility();
|
||||
EXPECT_NE(pMocKPageAbility, nullptr);
|
||||
if (pMocKPageAbility != nullptr) {
|
||||
ability.reset(pMocKPageAbility);
|
||||
ability->SetTargetVersion(TARGET_VERSION_THRESHOLDS);
|
||||
std::shared_ptr<ContextDeal> contextDeal = std::make_shared<ContextDeal>();
|
||||
mockAbilityimpl->Init(application, record, ability, handler, token, contextDeal);
|
||||
|
||||
mockAbilityimpl->ImplBackground();
|
||||
mockAbilityimpl->ImplBackground();
|
||||
mockAbilityimpl->ImplBackground();
|
||||
|
||||
EXPECT_EQ(MockPageAbility::Event::ON_BACKGROUND, pMocKPageAbility->state_);
|
||||
EXPECT_EQ(AAFwk::ABILITY_STATE_BACKGROUND_NEW, mockAbilityimpl->GetCurrentState());
|
||||
}
|
||||
}
|
||||
}
|
||||
GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_New_Background_002 end";
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AbilityImpl
|
||||
* Function: Background
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: Background
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Test the normal behavior of the AbilityImpl::Background
|
||||
*/
|
||||
HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_New_Foreground_Background_001, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_New_Foreground_Background_001 start";
|
||||
std::shared_ptr<MockAbilityimpl> mockAbilityimpl = std::make_shared<MockAbilityimpl>();
|
||||
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
|
||||
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
|
||||
abilityInfo->name = "pageAbility";
|
||||
sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
|
||||
EXPECT_NE(token, nullptr);
|
||||
if (token != nullptr) {
|
||||
std::shared_ptr<AbilityLocalRecord> record = std::make_shared<AbilityLocalRecord>(abilityInfo, token);
|
||||
std::shared_ptr<EventRunner> eventRunner = EventRunner::Create(abilityInfo->name);
|
||||
sptr<AbilityThread> abilityThread = sptr<AbilityThread>(new (std::nothrow) AbilityThread());
|
||||
EXPECT_NE(abilityThread, nullptr);
|
||||
if (abilityThread != nullptr) {
|
||||
std::shared_ptr<AbilityHandler> handler = std::make_shared<AbilityHandler>(eventRunner, abilityThread);
|
||||
std::shared_ptr<Ability> ability = nullptr;
|
||||
MockPageAbility *pMocKPageAbility = new (std::nothrow) MockPageAbility();
|
||||
EXPECT_NE(pMocKPageAbility, nullptr);
|
||||
if (pMocKPageAbility != nullptr) {
|
||||
ability.reset(pMocKPageAbility);
|
||||
ability->SetTargetVersion(TARGET_VERSION_THRESHOLDS);
|
||||
std::shared_ptr<ContextDeal> contextDeal = std::make_shared<ContextDeal>();
|
||||
mockAbilityimpl->Init(application, record, ability, handler, token, contextDeal);
|
||||
|
||||
Want want;
|
||||
mockAbilityimpl->ImplForeground(want);
|
||||
mockAbilityimpl->ImplBackground();
|
||||
|
||||
EXPECT_EQ(MockPageAbility::Event::ON_BACKGROUND, pMocKPageAbility->state_);
|
||||
EXPECT_EQ(AAFwk::ABILITY_STATE_BACKGROUND_NEW, mockAbilityimpl->GetCurrentState());
|
||||
}
|
||||
}
|
||||
}
|
||||
GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_New_Foreground_Background_001 end";
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AbilityImpl
|
||||
* Function: Background
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: Background
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Test the normal behavior of the AbilityImpl::Background
|
||||
*/
|
||||
HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_New_Foreground_Background_002, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_New_Foreground_Background_002 start";
|
||||
std::shared_ptr<MockAbilityimpl> mockAbilityimpl = std::make_shared<MockAbilityimpl>();
|
||||
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
|
||||
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
|
||||
abilityInfo->name = "pageAbility";
|
||||
sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
|
||||
EXPECT_NE(token, nullptr);
|
||||
if (token != nullptr) {
|
||||
std::shared_ptr<AbilityLocalRecord> record = std::make_shared<AbilityLocalRecord>(abilityInfo, token);
|
||||
std::shared_ptr<EventRunner> eventRunner = EventRunner::Create(abilityInfo->name);
|
||||
sptr<AbilityThread> abilityThread = sptr<AbilityThread>(new (std::nothrow) AbilityThread());
|
||||
EXPECT_NE(abilityThread, nullptr);
|
||||
if (abilityThread != nullptr) {
|
||||
std::shared_ptr<AbilityHandler> handler = std::make_shared<AbilityHandler>(eventRunner, abilityThread);
|
||||
std::shared_ptr<Ability> ability = nullptr;
|
||||
MockPageAbility *pMocKPageAbility = new (std::nothrow) MockPageAbility();
|
||||
EXPECT_NE(pMocKPageAbility, nullptr);
|
||||
if (pMocKPageAbility != nullptr) {
|
||||
ability.reset(pMocKPageAbility);
|
||||
ability->SetTargetVersion(TARGET_VERSION_THRESHOLDS);
|
||||
std::shared_ptr<ContextDeal> contextDeal = std::make_shared<ContextDeal>();
|
||||
mockAbilityimpl->Init(application, record, ability, handler, token, contextDeal);
|
||||
|
||||
Want want;
|
||||
mockAbilityimpl->ImplForeground(want);
|
||||
mockAbilityimpl->ImplBackground();
|
||||
mockAbilityimpl->ImplForeground(want);
|
||||
|
||||
EXPECT_EQ(MockPageAbility::Event::ON_FOREGROUND, pMocKPageAbility->state_);
|
||||
EXPECT_EQ(AAFwk::ABILITY_STATE_FOREGROUND_NEW, mockAbilityimpl->GetCurrentState());
|
||||
}
|
||||
}
|
||||
}
|
||||
GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_New_Foreground_Background_002 end";
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AbilityImpl
|
||||
* Function: Background
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: Background
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Test the normal behavior of the AbilityImpl::Background
|
||||
*/
|
||||
HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_New_Foreground_Background_003, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_New_Foreground_Background_002 start";
|
||||
std::shared_ptr<MockAbilityimpl> mockAbilityimpl = std::make_shared<MockAbilityimpl>();
|
||||
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
|
||||
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
|
||||
abilityInfo->name = "pageAbility";
|
||||
sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
|
||||
EXPECT_NE(token, nullptr);
|
||||
if (token != nullptr) {
|
||||
std::shared_ptr<AbilityLocalRecord> record = std::make_shared<AbilityLocalRecord>(abilityInfo, token);
|
||||
std::shared_ptr<EventRunner> eventRunner = EventRunner::Create(abilityInfo->name);
|
||||
sptr<AbilityThread> abilityThread = sptr<AbilityThread>(new (std::nothrow) AbilityThread());
|
||||
EXPECT_NE(abilityThread, nullptr);
|
||||
if (abilityThread != nullptr) {
|
||||
std::shared_ptr<AbilityHandler> handler = std::make_shared<AbilityHandler>(eventRunner, abilityThread);
|
||||
std::shared_ptr<Ability> ability = nullptr;
|
||||
MockPageAbility *pMocKPageAbility = new (std::nothrow) MockPageAbility();
|
||||
EXPECT_NE(pMocKPageAbility, nullptr);
|
||||
if (pMocKPageAbility != nullptr) {
|
||||
ability.reset(pMocKPageAbility);
|
||||
ability->SetTargetVersion(TARGET_VERSION_THRESHOLDS);
|
||||
std::shared_ptr<ContextDeal> contextDeal = std::make_shared<ContextDeal>();
|
||||
mockAbilityimpl->Init(application, record, ability, handler, token, contextDeal);
|
||||
|
||||
Want want;
|
||||
mockAbilityimpl->ImplBackground();
|
||||
mockAbilityimpl->ImplForeground(want);
|
||||
|
||||
EXPECT_EQ(MockPageAbility::Event::ON_FOREGROUND, pMocKPageAbility->state_);
|
||||
EXPECT_EQ(AAFwk::ABILITY_STATE_FOREGROUND_NEW, mockAbilityimpl->GetCurrentState());
|
||||
}
|
||||
}
|
||||
}
|
||||
GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_New_Foreground_Background_003 end";
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AbilityImpl
|
||||
* Function: Background
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: Background
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Test the normal behavior of the AbilityImpl::Background
|
||||
*/
|
||||
HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_New_Foreground_Background_004, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_New_Foreground_Background_004 start";
|
||||
std::shared_ptr<MockAbilityimpl> mockAbilityimpl = std::make_shared<MockAbilityimpl>();
|
||||
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
|
||||
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
|
||||
abilityInfo->name = "pageAbility";
|
||||
sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
|
||||
EXPECT_NE(token, nullptr);
|
||||
if (token != nullptr) {
|
||||
std::shared_ptr<AbilityLocalRecord> record = std::make_shared<AbilityLocalRecord>(abilityInfo, token);
|
||||
std::shared_ptr<EventRunner> eventRunner = EventRunner::Create(abilityInfo->name);
|
||||
sptr<AbilityThread> abilityThread = sptr<AbilityThread>(new (std::nothrow) AbilityThread());
|
||||
EXPECT_NE(abilityThread, nullptr);
|
||||
if (abilityThread != nullptr) {
|
||||
std::shared_ptr<AbilityHandler> handler = std::make_shared<AbilityHandler>(eventRunner, abilityThread);
|
||||
std::shared_ptr<Ability> ability = nullptr;
|
||||
MockPageAbility *pMocKPageAbility = new (std::nothrow) MockPageAbility();
|
||||
EXPECT_NE(pMocKPageAbility, nullptr);
|
||||
if (pMocKPageAbility != nullptr) {
|
||||
ability.reset(pMocKPageAbility);
|
||||
ability->SetTargetVersion(TARGET_VERSION_THRESHOLDS);
|
||||
std::shared_ptr<ContextDeal> contextDeal = std::make_shared<ContextDeal>();
|
||||
mockAbilityimpl->Init(application, record, ability, handler, token, contextDeal);
|
||||
|
||||
Want want;
|
||||
mockAbilityimpl->ImplBackground();
|
||||
mockAbilityimpl->ImplForeground(want);
|
||||
mockAbilityimpl->ImplBackground();
|
||||
|
||||
EXPECT_EQ(MockPageAbility::Event::ON_BACKGROUND, pMocKPageAbility->state_);
|
||||
EXPECT_EQ(AAFwk::ABILITY_STATE_BACKGROUND_NEW, mockAbilityimpl->GetCurrentState());
|
||||
}
|
||||
}
|
||||
}
|
||||
GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_New_Foreground_Background_004 end";
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AbilityImpl
|
||||
* Function: DisoatcgSaveAbilityState
|
||||
@ -936,13 +1297,10 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_GetCurrentState_001, TestSize.Level1
|
||||
*/
|
||||
HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_DoKeyDown_001, TestSize.Level1)
|
||||
{
|
||||
|
||||
GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_DoKeyDown_001 start";
|
||||
|
||||
int keyCode = 0;
|
||||
KeyEvent keyEvent;
|
||||
|
||||
EXPECT_EQ(false, AbilityImpl_->DoKeyDown(keyCode, keyEvent));
|
||||
|
||||
auto keyEvent = MMI::KeyEvent::Create();
|
||||
AbilityImpl_->DoKeyDown(keyEvent);
|
||||
GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_DoKeyDown_001 end";
|
||||
}
|
||||
|
||||
@ -957,10 +1315,8 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_DoKeyDown_001, TestSize.Level1)
|
||||
HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_DoKeyUp_001, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_DoKeyUp_001 start";
|
||||
int keyCode = 0;
|
||||
KeyEvent keyEvent;
|
||||
|
||||
EXPECT_EQ(false, AbilityImpl_->DoKeyUp(keyCode, keyEvent));
|
||||
auto keyEvent = MMI::KeyEvent::Create();
|
||||
AbilityImpl_->DoKeyUp(keyEvent);
|
||||
GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_DoKeyUp_001 end";
|
||||
}
|
||||
|
||||
@ -975,9 +1331,8 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_DoKeyUp_001, TestSize.Level1)
|
||||
HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_DoTouchEvent_001, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_DoTouchEvent_001 start";
|
||||
TouchEvent touchEvent;
|
||||
|
||||
EXPECT_EQ(false, AbilityImpl_->DoTouchEvent(touchEvent));
|
||||
auto pointerEvent = MMI::PointerEvent::Create();
|
||||
AbilityImpl_->DoPointerEvent(pointerEvent);
|
||||
GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_DoTouchEvent_001 end";
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@ using namespace testing::ext;
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
using OHOS::Parcel;
|
||||
const int TARGET_VERSION_THRESHOLDS = 8;
|
||||
|
||||
class AbilityBaseTest : public testing::Test {
|
||||
public:
|
||||
@ -673,6 +674,37 @@ HWTEST_F(AbilityBaseTest, AaFwk_Ability_OnForeground_0200, Function | MediumTest
|
||||
GTEST_LOG_(INFO) << "AaFwk_Ability_OnForeground_0200 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: AaFwk_Ability_OnForeground_0300
|
||||
* @tc.name: OnForeground
|
||||
* @tc.desc: Test the OnForeground exception.
|
||||
*/
|
||||
HWTEST_F(AbilityBaseTest, AaFwk_Ability_OnForeground_0300, Function | MediumTest | Level3)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "AaFwk_Ability_OnForeground_0300 start";
|
||||
|
||||
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
|
||||
AbilityType type = AbilityType::PAGE;
|
||||
abilityInfo->type = type;
|
||||
std::shared_ptr<OHOSApplication> application = nullptr;
|
||||
std::shared_ptr<AbilityHandler> handler = nullptr;
|
||||
sptr<IRemoteObject> token = nullptr;
|
||||
ability_->Init(abilityInfo, application, handler, token);
|
||||
ability_->SetTargetVersion(TARGET_VERSION_THRESHOLDS);
|
||||
Want want;
|
||||
ability_->OnForeground(want);
|
||||
|
||||
AbilityLifecycleExecutor::LifecycleState state = ability_->GetState();
|
||||
std::shared_ptr<LifeCycle> lifeCycle = ability_->GetLifecycle();
|
||||
LifeCycle::Event lifeCycleState = lifeCycle->GetLifecycleState();
|
||||
|
||||
EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::FOREGROUND_NEW, state);
|
||||
EXPECT_EQ(LifeCycle::Event::ON_FOREGROUND, lifeCycleState);
|
||||
|
||||
GTEST_LOG_(INFO) << "AaFwk_Ability_OnForeground_0300 end";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @tc.number: AaFwk_Ability_OnBackground_0100
|
||||
* @tc.name: OnBackground
|
||||
@ -722,6 +754,35 @@ HWTEST_F(AbilityBaseTest, AaFwk_Ability_OnBackground_0200, Function | MediumTest
|
||||
GTEST_LOG_(INFO) << "AaFwk_Ability_OnBackground_0200 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: AaFwk_Ability_OnBackground_0300
|
||||
* @tc.name: OnBackground
|
||||
* @tc.desc: Test the OnBackground exception.
|
||||
*/
|
||||
HWTEST_F(AbilityBaseTest, AaFwk_Ability_OnBackground_0300, Function | MediumTest | Level3)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "AaFwk_Ability_OnBackground_0300 start";
|
||||
|
||||
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
|
||||
AbilityType type = AbilityType::PAGE;
|
||||
abilityInfo->type = type;
|
||||
std::shared_ptr<OHOSApplication> application = nullptr;
|
||||
std::shared_ptr<AbilityHandler> handler = nullptr;
|
||||
sptr<IRemoteObject> token = nullptr;
|
||||
ability_->Init(abilityInfo, application, handler, token);
|
||||
ability_->SetTargetVersion(TARGET_VERSION_THRESHOLDS);
|
||||
ability_->OnBackground();
|
||||
|
||||
AbilityLifecycleExecutor::LifecycleState state = ability_->GetState();
|
||||
std::shared_ptr<LifeCycle> lifeCycle = ability_->GetLifecycle();
|
||||
LifeCycle::Event lifeCycleState = lifeCycle->GetLifecycleState();
|
||||
|
||||
EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::BACKGROUND_NEW, state);
|
||||
EXPECT_EQ(LifeCycle::Event::ON_BACKGROUND, lifeCycleState);
|
||||
|
||||
GTEST_LOG_(INFO) << "AaFwk_Ability_OBackground_0300 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: AaFwk_Ability_OnConnect_0100
|
||||
* @tc.name: OnConnect
|
||||
|
10
frameworks/kits/ability/native/test/unittest/ability_thread_dataability_test.cpp
Normal file → Executable file
10
frameworks/kits/ability/native/test/unittest/ability_thread_dataability_test.cpp
Normal file → Executable file
@ -100,7 +100,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_Query_0100, Function | MediumTes
|
||||
std::shared_ptr<AbilityLocalRecord> abilityRecord =
|
||||
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
|
||||
std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(abilityInfo->name);
|
||||
abilitythread->Attach(application, abilityRecord, mainRunner);
|
||||
abilitythread->Attach(application, abilityRecord, mainRunner, nullptr);
|
||||
std::shared_ptr<MockDataAbility> mockdataability = std::make_shared<MockDataAbility>();
|
||||
|
||||
Uri uri("dataabilitytest:///com.example.myapplication5.DataAbilityTest");
|
||||
@ -165,7 +165,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_GetFileTypes_0100, Function | Me
|
||||
std::shared_ptr<AbilityLocalRecord> abilityRecord =
|
||||
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
|
||||
std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(abilityInfo->name);
|
||||
abilitythread->Attach(application, abilityRecord, mainRunner);
|
||||
abilitythread->Attach(application, abilityRecord, mainRunner, nullptr);
|
||||
std::shared_ptr<MockDataAbility> mockdataability = std::make_shared<MockDataAbility>();
|
||||
|
||||
Uri uri("dataabilitytest://com.example.myapplication5.DataAbilityTest");
|
||||
@ -234,7 +234,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_OpenFile_0100, Function | Medium
|
||||
std::shared_ptr<AbilityLocalRecord> abilityRecord =
|
||||
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
|
||||
std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(abilityInfo->name);
|
||||
abilitythread->Attach(application, abilityRecord, mainRunner);
|
||||
abilitythread->Attach(application, abilityRecord, mainRunner, nullptr);
|
||||
std::shared_ptr<MockDataAbility> mockdataability = std::make_shared<MockDataAbility>();
|
||||
|
||||
Uri uri("dataabilitytest://com.example.myapplication5.DataAbilityTest");
|
||||
@ -294,7 +294,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_Insert_0100, Function | MediumTe
|
||||
std::shared_ptr<AbilityLocalRecord> abilityRecord =
|
||||
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
|
||||
std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(abilityInfo->name);
|
||||
abilitythread->Attach(application, abilityRecord, mainRunner);
|
||||
abilitythread->Attach(application, abilityRecord, mainRunner, nullptr);
|
||||
std::shared_ptr<MockDataAbility> mockdataability = std::make_shared<MockDataAbility>();
|
||||
|
||||
Uri uri("dataabilitytest://com.example.myapplication5.DataAbilityTest");
|
||||
@ -350,7 +350,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_Update_0100, Function | MediumTe
|
||||
std::shared_ptr<AbilityLocalRecord> abilityRecord =
|
||||
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
|
||||
std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(abilityInfo->name);
|
||||
abilitythread->Attach(application, abilityRecord, mainRunner);
|
||||
abilitythread->Attach(application, abilityRecord, mainRunner, nullptr);
|
||||
std::shared_ptr<MockDataAbility> mockdataability = std::make_shared<MockDataAbility>();
|
||||
|
||||
Uri uri("dataabilitytest://com.example.myapplication5.DataAbilityTest");
|
||||
|
30
frameworks/kits/ability/native/test/unittest/ability_thread_test.cpp
Normal file → Executable file
30
frameworks/kits/ability/native/test/unittest/ability_thread_test.cpp
Normal file → Executable file
@ -97,7 +97,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_ScheduleSaveAbilityState_0100, F
|
||||
std::shared_ptr<AbilityLocalRecord> abilityRecord =
|
||||
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
|
||||
std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(abilityInfo->name);
|
||||
abilitythread->Attach(application, abilityRecord, mainRunner);
|
||||
abilitythread->Attach(application, abilityRecord, mainRunner, nullptr);
|
||||
|
||||
abilitythread->ScheduleSaveAbilityState();
|
||||
|
||||
@ -146,7 +146,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_ScheduleRestoreAbilityState_0100
|
||||
std::shared_ptr<AbilityLocalRecord> abilityRecord =
|
||||
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
|
||||
std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(abilityInfo->name);
|
||||
abilitythread->Attach(application, abilityRecord, mainRunner);
|
||||
abilitythread->Attach(application, abilityRecord, mainRunner, nullptr);
|
||||
PacMap state;
|
||||
|
||||
abilitythread->ScheduleRestoreAbilityState(state);
|
||||
@ -195,7 +195,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_Attach_3_Param_0100, Function |
|
||||
std::shared_ptr<AbilityLocalRecord> abilityRecord =
|
||||
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
|
||||
std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(abilityInfo->name);
|
||||
abilitythread->Attach(application, abilityRecord, mainRunner);
|
||||
abilitythread->Attach(application, abilityRecord, mainRunner, nullptr);
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
@ -223,7 +223,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_Attach_3_Param_0200, Function |
|
||||
std::shared_ptr<AbilityLocalRecord> abilityRecord =
|
||||
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
|
||||
std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(abilityInfo->name);
|
||||
abilitythread->Attach(application, abilityRecord, mainRunner);
|
||||
abilitythread->Attach(application, abilityRecord, mainRunner, nullptr);
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
@ -251,7 +251,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_Attach_2_Param_0100, Function |
|
||||
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
|
||||
std::shared_ptr<AbilityLocalRecord> abilityRecord =
|
||||
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
|
||||
abilitythread->Attach(application, abilityRecord);
|
||||
abilitythread->Attach(application, abilityRecord, nullptr);
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
@ -281,7 +281,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_Attach_2_Param_0200, Function |
|
||||
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
|
||||
std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(abilityInfo->name);
|
||||
|
||||
abilitythread->Attach(application, abilityRecord);
|
||||
abilitythread->Attach(application, abilityRecord, nullptr);
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
@ -311,7 +311,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_ScheduleAbilityTransaction_0100,
|
||||
std::shared_ptr<AbilityLocalRecord> abilityRecord =
|
||||
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
|
||||
std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(abilityInfo->name);
|
||||
abilitythread->Attach(application, abilityRecord, mainRunner);
|
||||
abilitythread->Attach(application, abilityRecord, mainRunner, nullptr);
|
||||
|
||||
Want want;
|
||||
LifeCycleStateInfo lifeCycleStateInfo;
|
||||
@ -375,7 +375,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_ScheduleConnectAbility_0100, Fun
|
||||
std::shared_ptr<AbilityLocalRecord> abilityRecord =
|
||||
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
|
||||
std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(abilityInfo->name);
|
||||
abilitythread->Attach(application, abilityRecord, mainRunner);
|
||||
abilitythread->Attach(application, abilityRecord, mainRunner, nullptr);
|
||||
|
||||
Want want;
|
||||
abilitythread->ScheduleConnectAbility(want);
|
||||
@ -426,7 +426,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_ScheduleDisconnectAbility_0100,
|
||||
std::shared_ptr<AbilityLocalRecord> abilityRecord =
|
||||
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
|
||||
std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(abilityInfo->name);
|
||||
abilitythread->Attach(application, abilityRecord, mainRunner);
|
||||
abilitythread->Attach(application, abilityRecord, mainRunner, nullptr);
|
||||
|
||||
Want want;
|
||||
abilitythread->ScheduleDisconnectAbility(want);
|
||||
@ -480,7 +480,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_ScheduleCommandAbility_0100, Fun
|
||||
std::shared_ptr<AbilityLocalRecord> abilityRecord =
|
||||
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
|
||||
std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(abilityInfo->name);
|
||||
abilitythread->Attach(application, abilityRecord, mainRunner);
|
||||
abilitythread->Attach(application, abilityRecord, mainRunner, nullptr);
|
||||
|
||||
Want want;
|
||||
bool restart = true;
|
||||
@ -538,7 +538,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_SendResult_0100, Function | Medi
|
||||
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
|
||||
std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(abilityInfo->name);
|
||||
std::shared_ptr<AbilityImpl> abilityimpl = std::make_shared<AbilityImpl>();
|
||||
abilitythread->Attach(application, abilityRecord, mainRunner);
|
||||
abilitythread->Attach(application, abilityRecord, mainRunner, nullptr);
|
||||
|
||||
int requestCode = 0;
|
||||
int resultCode = 0;
|
||||
@ -595,7 +595,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_AbilityThreadMain_0100, Function
|
||||
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
|
||||
std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(abilityInfo->name);
|
||||
|
||||
abilitythread->AbilityThreadMain(application, abilityRecord, mainRunner);
|
||||
abilitythread->AbilityThreadMain(application, abilityRecord, mainRunner, nullptr);
|
||||
}
|
||||
}
|
||||
GTEST_LOG_(INFO) << "AaFwk_AbilityThread_AbilityThreadMain_0100 end";
|
||||
@ -623,7 +623,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_AbilityThreadMain_0200, Function
|
||||
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
|
||||
std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(abilityInfo->name);
|
||||
|
||||
abilitythread->AbilityThreadMain(application, abilityRecord, mainRunner);
|
||||
abilitythread->AbilityThreadMain(application, abilityRecord, mainRunner, nullptr);
|
||||
}
|
||||
}
|
||||
GTEST_LOG_(INFO) << "AaFwk_AbilityThread_AbilityThreadMain_0200 end";
|
||||
@ -651,7 +651,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_AbilityThreadMain_0300, Function
|
||||
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
|
||||
std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(abilityInfo->name);
|
||||
|
||||
abilitythread->AbilityThreadMain(application, abilityRecord);
|
||||
abilitythread->AbilityThreadMain(application, abilityRecord, nullptr);
|
||||
}
|
||||
}
|
||||
GTEST_LOG_(INFO) << "AaFwk_AbilityThread_AbilityThreadMain_0300 end";
|
||||
@ -679,7 +679,7 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_AbilityThreadMain_0400, Function
|
||||
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
|
||||
std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(abilityInfo->name);
|
||||
|
||||
abilitythread->AbilityThreadMain(application, abilityRecord);
|
||||
abilitythread->AbilityThreadMain(application, abilityRecord, nullptr);
|
||||
}
|
||||
}
|
||||
GTEST_LOG_(INFO) << "AaFwk_AbilityThread_AbilityThreadMain_0400 end";
|
||||
|
208
frameworks/kits/ability/native/test/unittest/continuation_test.cpp
Executable file
208
frameworks/kits/ability/native/test/unittest/continuation_test.cpp
Executable file
@ -0,0 +1,208 @@
|
||||
/*
|
||||
* 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 <gtest/gtest.h>
|
||||
|
||||
#include "ability.h"
|
||||
#include "ability_impl.h"
|
||||
#include "ability_state.h"
|
||||
#include "abs_shared_result_set.h"
|
||||
#include "app_log_wrapper.h"
|
||||
#include "context_deal.h"
|
||||
#include "continuation_manager.h"
|
||||
#include "continuation_handler.h"
|
||||
#include "data_ability_predicates.h"
|
||||
#include "foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include/uri.h"
|
||||
#include "mock_ability_impl.h"
|
||||
#include "mock_ability_lifecycle_callbacks.h"
|
||||
#include "mock_ability_token.h"
|
||||
#include "mock_continuation_ability.h"
|
||||
#include "ohos_application.h"
|
||||
#include "page_ability_impl.h"
|
||||
#include "values_bucket.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
|
||||
class ContinuationTest : public testing::Test {
|
||||
public:
|
||||
ContinuationTest() : continuationManager_(nullptr), ability_(nullptr), abilityInfo_(nullptr),
|
||||
continueToken_(nullptr)
|
||||
{}
|
||||
~ContinuationTest()
|
||||
{}
|
||||
std::shared_ptr<ContinuationManager> continuationManager_;
|
||||
std::shared_ptr<Ability> ability_;
|
||||
std::shared_ptr<AbilityInfo> abilityInfo_;
|
||||
sptr<IRemoteObject> continueToken_;
|
||||
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void ContinuationTest::SetUpTestCase(void)
|
||||
{}
|
||||
|
||||
void ContinuationTest::TearDownTestCase(void)
|
||||
{}
|
||||
|
||||
void ContinuationTest::SetUp(void)
|
||||
{
|
||||
continuationManager_ = std::make_shared<ContinuationManager>();
|
||||
continueToken_ = sptr<IRemoteObject>(new (std::nothrow)MockAbilityToken());
|
||||
abilityInfo_ = std::make_shared<AbilityInfo>();
|
||||
abilityInfo_->name = "ability";
|
||||
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
|
||||
std::shared_ptr<EventRunner> eventRunner = EventRunner::Create(abilityInfo_->name);
|
||||
sptr<AbilityThread> abilityThread = sptr<AbilityThread>(new (std::nothrow)AbilityThread());
|
||||
std::shared_ptr<AbilityHandler> handler = std::make_shared<AbilityHandler>(eventRunner, abilityThread);
|
||||
ability_ = std::make_shared<MockContinuationAbility>();
|
||||
ability_->Init(abilityInfo_, application, handler, continueToken_);
|
||||
}
|
||||
|
||||
void ContinuationTest::TearDown(void)
|
||||
{}
|
||||
|
||||
/*
|
||||
* @tc.name: continue_manager_init_001
|
||||
* @tc.desc: init ContinuationManager with illegal ability
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000GI8IP
|
||||
*/
|
||||
HWTEST_F(ContinuationTest, continue_manager_init_001, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "continue_manager_init_001 start";
|
||||
|
||||
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
|
||||
std::weak_ptr<Ability> abilityTmp = ability_;
|
||||
std::shared_ptr<ContinuationHandler> continuationHandler =
|
||||
std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
|
||||
std::shared_ptr<Ability> ability = nullptr;
|
||||
bool result = continuationManager_->Init(ability, continueToken_, abilityInfo_, continuationHandler);
|
||||
EXPECT_FALSE(result);
|
||||
GTEST_LOG_(INFO) << "continue_manager_init_001 end";
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: continue_manager_init_002
|
||||
* @tc.desc: init ContinuationManager with illegal continueToken
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000GI8IP
|
||||
*/
|
||||
HWTEST_F(ContinuationTest, continue_manager_init_002, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "continue_manager_init_002 start";
|
||||
|
||||
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
|
||||
std::weak_ptr<Ability> abilityTmp = ability_;
|
||||
std::shared_ptr<ContinuationHandler> continuationHandler =
|
||||
std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
|
||||
sptr<IRemoteObject> continueToken = nullptr;
|
||||
bool result = continuationManager_->Init(ability_, continueToken, abilityInfo_, continuationHandler);
|
||||
EXPECT_FALSE(result);
|
||||
GTEST_LOG_(INFO) << "continue_manager_init_002 end";
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: continue_manager_start_continuation_001
|
||||
* @tc.desc: call StartContinuation
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000GI8IP
|
||||
*/
|
||||
HWTEST_F(ContinuationTest, continue_manager_start_continuation_001, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "continue_manager_start_continuation_001 start";
|
||||
|
||||
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
|
||||
std::weak_ptr<Ability> abilityTmp = ability_;
|
||||
std::shared_ptr<ContinuationHandler> continuationHandler =
|
||||
std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
|
||||
continuationManager_->Init(ability_, continueToken_, abilityInfo_, continuationHandler);
|
||||
bool startResult = continuationManager_->StartContinuation();
|
||||
EXPECT_TRUE(startResult);
|
||||
GTEST_LOG_(INFO) << "continue_manager_start_continuation_001 end";
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: continue_manager_save_data_001
|
||||
* @tc.desc: call SaveData
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000GI8IP
|
||||
*/
|
||||
HWTEST_F(ContinuationTest, continue_manager_save_data_001, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "continue_manager_save_data_001 start";
|
||||
|
||||
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
|
||||
std::weak_ptr<Ability> abilityTmp = ability_;
|
||||
std::shared_ptr<ContinuationHandler> continuationHandler =
|
||||
std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
|
||||
continuationManager_->Init(ability_, continueToken_, abilityInfo_, continuationHandler);
|
||||
WantParams wantParams;
|
||||
bool saveDataResult = continuationManager_->SaveData(wantParams);
|
||||
EXPECT_TRUE(saveDataResult);
|
||||
GTEST_LOG_(INFO) << "continue_manager_save_data_001 end";
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: continue_handler_start_continue_001
|
||||
* @tc.desc: call HandleStartContinuation with illegal token
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000GI8IP
|
||||
*/
|
||||
HWTEST_F(ContinuationTest, continue_handler_start_continue_001, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "continue_handler_start_continue_001 start";
|
||||
|
||||
std::shared_ptr<Ability> ability = std::make_shared<MockContinuationAbility>();
|
||||
sptr<IRemoteObject> continueToken = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
|
||||
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
|
||||
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
|
||||
std::weak_ptr<Ability> abilityTmp = ability;
|
||||
std::shared_ptr<ContinuationHandler> continuationHandler =
|
||||
std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
|
||||
bool result = continuationHandler->HandleStartContinuation(nullptr, "mock_deviceId");
|
||||
EXPECT_FALSE(result);
|
||||
GTEST_LOG_(INFO) << "continue_handler_start_continue_001 end";
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: continue_handler_start_continue_002
|
||||
* @tc.desc: call HandleStartContinuation without call SetAbilityInfo
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000GI8IP
|
||||
*/
|
||||
HWTEST_F(ContinuationTest, continue_handler_start_continue_002, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "continue_handler_start_continue_002 start";
|
||||
|
||||
std::shared_ptr<Ability> ability = std::make_shared<MockContinuationAbility>();
|
||||
sptr<IRemoteObject> continueToken = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
|
||||
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
|
||||
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
|
||||
std::weak_ptr<Ability> abilityTmp = ability;
|
||||
std::shared_ptr<ContinuationHandler> continuationHandler =
|
||||
std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
|
||||
bool result = continuationHandler->HandleStartContinuation(continueToken, "mock_deviceId");
|
||||
EXPECT_FALSE(result);
|
||||
GTEST_LOG_(INFO) << "continue_handler_start_continue_002 end";
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
2
frameworks/kits/ability/native/test/unittest/data_ability_impl_file_test.cpp
Normal file → Executable file
2
frameworks/kits/ability/native/test/unittest/data_ability_impl_file_test.cpp
Normal file → Executable file
@ -74,7 +74,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_GetType_001, Function |
|
||||
std::shared_ptr<EventRunner> eventRunner = EventRunner::Create(abilityInfo->name);
|
||||
sptr<AbilityThread> abilityThread = sptr<AbilityThread>(new (std::nothrow) AbilityThread());
|
||||
std::shared_ptr<AbilityHandler> handler = std::make_shared<AbilityHandler>(eventRunner, abilityThread);
|
||||
std::shared_ptr<Ability> ability = std::make_shared<MockDataAbility>();;
|
||||
std::shared_ptr<Ability> ability = std::make_shared<MockDataAbility>();
|
||||
std::shared_ptr<ContextDeal> contextDeal = std::make_shared<ContextDeal>();
|
||||
dataabilityimpl->Init(application, record, ability, handler, token, contextDeal);
|
||||
Uri uri("\nullptr");
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user