Merge branch 'master' of gitee.com:openharmony/ability_ability_runtime into DuLiBianYi_20241014

Signed-off-by: jiangzhijun8 <jiangzhijun7@huawei.com>
This commit is contained in:
jiangzhijun8
2024-10-15 08:45:04 +00:00
committed by Gitee
141 changed files with 3208 additions and 323 deletions
+1
View File
@@ -87,6 +87,7 @@
"os_account",
"power_manager",
"preferences",
"qos_manager",
"relational_store",
"resource_management",
"resource_schedule_service",
+3
View File
@@ -53,8 +53,11 @@ ohos_shared_library("cj_ability_ffi") {
sources = [
"cj_ability_delegator.cpp",
"cj_ability_delegator_args.cpp",
"cj_ability_lifecycle_callback.cpp",
"cj_application_context.cpp",
"cj_application_state_change_callback.cpp",
"cj_element_name_ffi.cpp",
"cj_environment_callback.cpp",
"cj_utils_ffi.cpp",
"cj_want_ffi.cpp",
]
+1 -1
View File
@@ -150,7 +150,7 @@ int32_t FFIAbilityDelegatorApplicationContext(int64_t id)
TAG_LOGE(AAFwkTag::DELEGATOR, "null cj delegator");
return INVALID_CODE;
}
auto appContext = FFI::FFIData::Create<ApplicationContextCJ::CJApplicationContext>(cjDelegator->GetAppContext());
auto appContext = ApplicationContextCJ::CJApplicationContext::GetCJApplicationContext(cjDelegator->GetAppContext());
if (appContext == nullptr) {
TAG_LOGE(AAFwkTag::DELEGATOR, "null app context");
return INVALID_CODE;
@@ -0,0 +1,470 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "cj_ability_lifecycle_callback.h"
#include "cj_lambda.h"
#include "hilog_tag_wrapper.h"
namespace OHOS {
namespace AbilityRuntime {
CjAbilityLifecycleCallback::CjAbilityLifecycleCallback()
{
}
int32_t CjAbilityLifecycleCallback::serialNumber_ = 0;
void EmplaceAbilityFunc(int32_t callbackId, int64_t cFuncId,
std::map<int32_t, std::function<void(int64_t)>> &cFuncMap)
{
auto callback = CJLambda::Create(reinterpret_cast<void(*)(int64_t)>(cFuncId));
cFuncMap.emplace(callbackId, callback);
}
void EmplaceAbilityWindowStageFunc(int32_t callbackId, int64_t cFuncId,
std::map<int32_t, std::function<void(int64_t, WindowStagePtr)>> &cFuncMap)
{
auto callback = CJLambda::Create(reinterpret_cast<void(*)(int64_t, WindowStagePtr)>(cFuncId));
cFuncMap.emplace(callbackId, callback);
}
int32_t CjAbilityLifecycleCallback::Register(CArrI64 cFuncIds, bool isSync)
{
int32_t callbackId = serialNumber_;
if (serialNumber_ < INT32_MAX) {
serialNumber_++;
} else {
serialNumber_ = 0;
}
if (isSync) {
return -1;
} else {
int64_t i = 0;
EmplaceAbilityFunc(callbackId, cFuncIds.head[i++], onAbilityCreatecallbacks_);
EmplaceAbilityWindowStageFunc(callbackId, cFuncIds.head[i++], onWindowStageCreatecallbacks_);
EmplaceAbilityWindowStageFunc(callbackId, cFuncIds.head[i++], onWindowStageActivecallbacks_);
EmplaceAbilityWindowStageFunc(callbackId, cFuncIds.head[i++], onWindowStageInactivecallbacks_);
EmplaceAbilityWindowStageFunc(callbackId, cFuncIds.head[i++], onWindowStageDestroycallbacks_);
EmplaceAbilityFunc(callbackId, cFuncIds.head[i++], onAbilityDestroycallbacks_);
EmplaceAbilityFunc(callbackId, cFuncIds.head[i++], onAbilityForegroundcallbacks_);
EmplaceAbilityFunc(callbackId, cFuncIds.head[i++], onAbilityBackgroundcallbacks_);
EmplaceAbilityFunc(callbackId, cFuncIds.head[i++], onAbilityContinuecallbacks_);
// optional callbacks
EmplaceAbilityFunc(callbackId, cFuncIds.head[i++], onAbilityWillCreatecallbacks_);
EmplaceAbilityWindowStageFunc(callbackId, cFuncIds.head[i++], onWindowStageWillCreatecallbacks_);
EmplaceAbilityWindowStageFunc(callbackId, cFuncIds.head[i++], onWindowStageWillDestroycallbacks_);
EmplaceAbilityFunc(callbackId, cFuncIds.head[i++], onAbilityWillForegroundcallbacks_);
EmplaceAbilityFunc(callbackId, cFuncIds.head[i++], onAbilityWillDestroycallbacks_);
EmplaceAbilityFunc(callbackId, cFuncIds.head[i++], onAbilityWillBackgroundcallbacks_);
EmplaceAbilityFunc(callbackId, cFuncIds.head[i++], onWillNewWantcallbacks_);
EmplaceAbilityFunc(callbackId, cFuncIds.head[i++], onNewWantcallbacks_);
EmplaceAbilityFunc(callbackId, cFuncIds.head[i++], onAbilityWillContinuecallbacks_);
EmplaceAbilityWindowStageFunc(callbackId, cFuncIds.head[i++], onWindowStageWillRestorecallbacks_);
EmplaceAbilityWindowStageFunc(callbackId, cFuncIds.head[i++], onWindowStageRestorecallbacks_);
EmplaceAbilityFunc(callbackId, cFuncIds.head[i++], onAbilityWillSaveStatecallbacks_);
EmplaceAbilityFunc(callbackId, cFuncIds.head[i++], onAbilitySaveStatecallbacks_);
}
return callbackId;
}
bool CjAbilityLifecycleCallback::UnRegister(int32_t callbackId, bool isSync)
{
TAG_LOGI(AAFwkTag::APPKIT, "callbackId : %{public}d", callbackId);
if (isSync) {
return false;
}
auto it = onAbilityCreatecallbacks_.find(callbackId);
if (it == onAbilityCreatecallbacks_.end()) {
TAG_LOGE(AAFwkTag::APPKIT, "callbackId: %{public}d is not in callbacks_", callbackId);
return false;
}
onAbilityCreatecallbacks_.erase(callbackId);
onWindowStageCreatecallbacks_.erase(callbackId);
onWindowStageActivecallbacks_.erase(callbackId);
onWindowStageInactivecallbacks_.erase(callbackId);
onWindowStageDestroycallbacks_.erase(callbackId);
onAbilityDestroycallbacks_.erase(callbackId);
onAbilityForegroundcallbacks_.erase(callbackId);
onAbilityBackgroundcallbacks_.erase(callbackId);
onAbilityContinuecallbacks_.erase(callbackId);
// optional callbacks
onAbilityWillCreatecallbacks_.erase(callbackId);
onWindowStageWillCreatecallbacks_.erase(callbackId);
onWindowStageWillDestroycallbacks_.erase(callbackId);
onAbilityWillForegroundcallbacks_.erase(callbackId);
onAbilityWillDestroycallbacks_.erase(callbackId);
onAbilityWillBackgroundcallbacks_.erase(callbackId);
onWillNewWantcallbacks_.erase(callbackId);
onNewWantcallbacks_.erase(callbackId);
onAbilityWillContinuecallbacks_.erase(callbackId);
onWindowStageWillRestorecallbacks_.erase(callbackId);
onWindowStageRestorecallbacks_.erase(callbackId);
onAbilityWillSaveStatecallbacks_.erase(callbackId);
return onAbilitySaveStatecallbacks_.erase(callbackId) == 1;
}
void CjAbilityLifecycleCallback::OnAbilityCreate(const int64_t &ability)
{
TAG_LOGD(AAFwkTag::APPKIT, "methodName = OnAbilityCreate");
if (!ability) {
TAG_LOGE(AAFwkTag::APPKIT, "ability is nullptr");
return;
}
for (auto &callback : onAbilityCreatecallbacks_) {
if (!callback.second) {
TAG_LOGE(AAFwkTag::APPKIT, "Invalid cjCallback");
return;
}
callback.second(ability);
}
}
void CjAbilityLifecycleCallback::OnWindowStageCreate(const int64_t &ability, WindowStagePtr windowStage)
{
TAG_LOGD(AAFwkTag::APPKIT, "methodName = OnWindowStageCreate");
if (!ability || !windowStage) {
TAG_LOGE(AAFwkTag::APPKIT, "ability or windowStage is nullptr");
return;
}
for (auto &callback : onWindowStageCreatecallbacks_) {
if (!callback.second) {
TAG_LOGE(AAFwkTag::APPKIT, "Invalid cjCallback");
return;
}
callback.second(ability, windowStage);
}
}
void CjAbilityLifecycleCallback::OnWindowStageActive(const int64_t &ability, WindowStagePtr windowStage)
{
TAG_LOGD(AAFwkTag::APPKIT, "methodName = OnWindowStageActive");
if (!ability || !windowStage) {
TAG_LOGE(AAFwkTag::APPKIT, "ability or windowStage is nullptr");
return;
}
for (auto &callback : onWindowStageActivecallbacks_) {
if (!callback.second) {
TAG_LOGE(AAFwkTag::APPKIT, "Invalid cjCallback");
return;
}
callback.second(ability, windowStage);
}
}
void CjAbilityLifecycleCallback::OnWindowStageInactive(const int64_t &ability, WindowStagePtr windowStage)
{
TAG_LOGD(AAFwkTag::APPKIT, "methodName = OnWindowStageInactive");
if (!ability || !windowStage) {
TAG_LOGE(AAFwkTag::APPKIT, "ability or windowStage is nullptr");
return;
}
for (auto &callback : onWindowStageInactivecallbacks_) {
if (!callback.second) {
TAG_LOGE(AAFwkTag::APPKIT, "Invalid cjCallback");
return;
}
callback.second(ability, windowStage);
}
}
void CjAbilityLifecycleCallback::OnWindowStageDestroy(const int64_t &ability, WindowStagePtr windowStage)
{
TAG_LOGD(AAFwkTag::APPKIT, "methodName = OnWindowStageDestroy");
if (!ability || !windowStage) {
TAG_LOGE(AAFwkTag::APPKIT, "ability or windowStage is nullptr");
return;
}
for (auto &callback : onWindowStageDestroycallbacks_) {
if (!callback.second) {
TAG_LOGE(AAFwkTag::APPKIT, "Invalid cjCallback");
return;
}
callback.second(ability, windowStage);
}
}
void CjAbilityLifecycleCallback::OnAbilityDestroy(const int64_t &ability)
{
TAG_LOGD(AAFwkTag::APPKIT, "methodName = OnAbilityDestroy");
if (!ability) {
TAG_LOGE(AAFwkTag::APPKIT, "ability is nullptr");
return;
}
for (auto &callback : onAbilityDestroycallbacks_) {
if (!callback.second) {
TAG_LOGE(AAFwkTag::APPKIT, "Invalid cjCallback");
return;
}
callback.second(ability);
}
}
void CjAbilityLifecycleCallback::OnAbilityForeground(const int64_t &ability)
{
TAG_LOGD(AAFwkTag::APPKIT, "methodName = OnAbilityForeground");
if (!ability) {
TAG_LOGE(AAFwkTag::APPKIT, "ability is nullptr");
return;
}
for (auto &callback : onAbilityForegroundcallbacks_) {
if (!callback.second) {
TAG_LOGE(AAFwkTag::APPKIT, "Invalid cjCallback");
return;
}
callback.second(ability);
}
}
void CjAbilityLifecycleCallback::OnAbilityBackground(const int64_t &ability)
{
TAG_LOGD(AAFwkTag::APPKIT, "methodName = OnAbilityBackground");
if (!ability) {
TAG_LOGE(AAFwkTag::APPKIT, "ability is nullptr");
return;
}
for (auto &callback : onAbilityBackgroundcallbacks_) {
if (!callback.second) {
TAG_LOGE(AAFwkTag::APPKIT, "Invalid cjCallback");
return;
}
callback.second(ability);
}
}
void CjAbilityLifecycleCallback::OnAbilityContinue(const int64_t &ability)
{
TAG_LOGD(AAFwkTag::APPKIT, "methodName = OnAbilityContinue");
if (!ability) {
TAG_LOGE(AAFwkTag::APPKIT, "ability is nullptr");
return;
}
for (auto &callback : onAbilityContinuecallbacks_) {
if (!callback.second) {
TAG_LOGE(AAFwkTag::APPKIT, "Invalid cjCallback");
return;
}
callback.second(ability);
}
}
// optional callbacks
void CjAbilityLifecycleCallback::OnAbilityWillCreate(const int64_t &ability)
{
TAG_LOGD(AAFwkTag::APPKIT, "methodName = OnAbilityWillCreate");
if (!ability) {
TAG_LOGE(AAFwkTag::APPKIT, "ability is nullptr");
return;
}
for (auto &callback : onAbilityWillCreatecallbacks_) {
if (!callback.second) {
TAG_LOGE(AAFwkTag::APPKIT, "Invalid cjCallback");
return;
}
callback.second(ability);
}
}
void CjAbilityLifecycleCallback::OnWindowStageWillCreate(const int64_t &ability, WindowStagePtr windowStage)
{
TAG_LOGD(AAFwkTag::APPKIT, "methodName = OnWindowStageWillCreate");
if (!ability || !windowStage) {
TAG_LOGE(AAFwkTag::APPKIT, "ability or windowStage is nullptr");
return;
}
for (auto &callback : onWindowStageWillCreatecallbacks_) {
if (!callback.second) {
TAG_LOGE(AAFwkTag::APPKIT, "Invalid cjCallback");
return;
}
callback.second(ability, windowStage);
}
}
void CjAbilityLifecycleCallback::OnWindowStageWillDestroy(const int64_t &ability, WindowStagePtr windowStage)
{
TAG_LOGD(AAFwkTag::APPKIT, "methodName = OnWindowStageWillDestroy");
if (!ability || !windowStage) {
TAG_LOGE(AAFwkTag::APPKIT, "ability or windowStage is nullptr");
return;
}
for (auto &callback : onWindowStageWillDestroycallbacks_) {
if (!callback.second) {
TAG_LOGE(AAFwkTag::APPKIT, "Invalid cjCallback");
return;
}
callback.second(ability, windowStage);
}
}
void CjAbilityLifecycleCallback::OnAbilityWillDestroy(const int64_t &ability)
{
TAG_LOGD(AAFwkTag::APPKIT, "methodName = OnAbilityWillDestroy");
if (!ability) {
TAG_LOGE(AAFwkTag::APPKIT, "ability is nullptr");
return;
}
for (auto &callback : onAbilityWillDestroycallbacks_) {
if (!callback.second) {
TAG_LOGE(AAFwkTag::APPKIT, "Invalid cjCallback");
return;
}
callback.second(ability);
}
}
void CjAbilityLifecycleCallback::OnAbilityWillForeground(const int64_t &ability)
{
TAG_LOGD(AAFwkTag::APPKIT, "methodName = OnAbilityWillForeground");
if (!ability) {
TAG_LOGE(AAFwkTag::APPKIT, "ability is nullptr");
return;
}
for (auto &callback : onAbilityWillForegroundcallbacks_) {
if (!callback.second) {
TAG_LOGE(AAFwkTag::APPKIT, "Invalid cjCallback");
return;
}
callback.second(ability);
}
}
void CjAbilityLifecycleCallback::OnAbilityWillBackground(const int64_t &ability)
{
TAG_LOGD(AAFwkTag::APPKIT, "methodName = OnAbilityWillBackground");
if (!ability) {
TAG_LOGE(AAFwkTag::APPKIT, "ability is nullptr");
return;
}
for (auto &callback : onAbilityWillBackgroundcallbacks_) {
if (!callback.second) {
TAG_LOGE(AAFwkTag::APPKIT, "Invalid cjCallback");
return;
}
callback.second(ability);
}
}
void CjAbilityLifecycleCallback::OnNewWant(const int64_t &ability)
{
TAG_LOGD(AAFwkTag::APPKIT, "methodName = OnNewWant");
if (!ability) {
TAG_LOGE(AAFwkTag::APPKIT, "ability is nullptr");
return;
}
for (auto &callback : onNewWantcallbacks_) {
if (!callback.second) {
TAG_LOGE(AAFwkTag::APPKIT, "Invalid cjCallback");
return;
}
callback.second(ability);
}
}
void CjAbilityLifecycleCallback::OnWillNewWant(const int64_t &ability)
{
TAG_LOGD(AAFwkTag::APPKIT, "methodName = OnWillNewWant");
if (!ability) {
TAG_LOGE(AAFwkTag::APPKIT, "ability is nullptr");
return;
}
for (auto &callback : onWillNewWantcallbacks_) {
if (!callback.second) {
TAG_LOGE(AAFwkTag::APPKIT, "Invalid cjCallback");
return;
}
callback.second(ability);
}
}
void CjAbilityLifecycleCallback::OnAbilityWillContinue(const int64_t &ability)
{
TAG_LOGD(AAFwkTag::APPKIT, "methodName = OnAbilityWillContinue");
if (!ability) {
TAG_LOGE(AAFwkTag::APPKIT, "ability is nullptr");
return;
}
for (auto &callback : onAbilityWillContinuecallbacks_) {
if (!callback.second) {
TAG_LOGE(AAFwkTag::APPKIT, "Invalid cjCallback");
return;
}
callback.second(ability);
}
}
void CjAbilityLifecycleCallback::OnWindowStageWillRestore(const int64_t &ability, WindowStagePtr windowStage)
{
TAG_LOGD(AAFwkTag::APPKIT, "methodName = OnWindowStageWillRestore");
if (!ability || !windowStage) {
TAG_LOGE(AAFwkTag::APPKIT, "ability or windowStage is nullptr");
return;
}
for (auto &callback : onWindowStageWillRestorecallbacks_) {
if (!callback.second) {
TAG_LOGE(AAFwkTag::APPKIT, "Invalid cjCallback");
return;
}
callback.second(ability, windowStage);
}
}
void CjAbilityLifecycleCallback::OnWindowStageRestore(const int64_t &ability, WindowStagePtr windowStage)
{
TAG_LOGD(AAFwkTag::APPKIT, "methodName = OnWindowStageRestore");
if (!ability || !windowStage) {
TAG_LOGE(AAFwkTag::APPKIT, "ability or windowStage is nullptr");
return;
}
for (auto &callback : onWindowStageRestorecallbacks_) {
if (!callback.second) {
TAG_LOGE(AAFwkTag::APPKIT, "Invalid cjCallback");
return;
}
callback.second(ability, windowStage);
}
}
void CjAbilityLifecycleCallback::OnAbilityWillSaveState(const int64_t &ability)
{
TAG_LOGD(AAFwkTag::APPKIT, "methodName = OnAbilityWillSaveState");
if (!ability) {
TAG_LOGE(AAFwkTag::APPKIT, "ability is nullptr");
return;
}
for (auto &callback : onAbilityWillSaveStatecallbacks_) {
if (!callback.second) {
TAG_LOGE(AAFwkTag::APPKIT, "Invalid cjCallback");
return;
}
callback.second(ability);
}
}
void CjAbilityLifecycleCallback::OnAbilitySaveState(const int64_t &ability)
{
TAG_LOGD(AAFwkTag::APPKIT, "methodName = OnAbilitySaveState");
if (!ability) {
TAG_LOGE(AAFwkTag::APPKIT, "ability is nullptr");
return;
}
for (auto &callback : onAbilitySaveStatecallbacks_) {
if (!callback.second) {
TAG_LOGE(AAFwkTag::APPKIT, "Invalid cjCallback");
return;
}
callback.second(ability);
}
}
} // namespace AbilityRuntime
} // namespace OHOS
@@ -0,0 +1,88 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_ABILITY_RUNTIME_CJ_CONTEXT_ABILITY_LIFECYCLE_CALLBACK_H
#define OHOS_ABILITY_RUNTIME_CJ_CONTEXT_ABILITY_LIFECYCLE_CALLBACK_H
#include <map>
#include <memory>
#include "cj_common_ffi.h"
#include "ability_lifecycle_callback.h"
using WindowStagePtr = void*;
namespace OHOS {
namespace AbilityRuntime {
class CjAbilityLifecycleCallback : public std::enable_shared_from_this<CjAbilityLifecycleCallback> {
public:
explicit CjAbilityLifecycleCallback();
void OnAbilityCreate(const int64_t &ability);
void OnWindowStageCreate(const int64_t &ability, WindowStagePtr windowStage);
void OnWindowStageActive(const int64_t &ability, WindowStagePtr windowStage);
void OnWindowStageInactive(const int64_t &ability, WindowStagePtr windowStage);
void OnWindowStageDestroy(const int64_t &ability, WindowStagePtr windowStage);
void OnAbilityDestroy(const int64_t &ability);
void OnAbilityForeground(const int64_t &ability);
void OnAbilityBackground(const int64_t &ability);
void OnAbilityContinue(const int64_t &ability);
// optional callbacks
void OnAbilityWillCreate(const int64_t &ability);
void OnWindowStageWillCreate(const int64_t &ability, WindowStagePtr windowStage);
void OnWindowStageWillDestroy(const int64_t &ability, WindowStagePtr windowStage);
void OnAbilityWillDestroy(const int64_t &ability);
void OnAbilityWillForeground(const int64_t &ability);
void OnAbilityWillBackground(const int64_t &ability);
void OnNewWant(const int64_t &ability);
void OnWillNewWant(const int64_t &ability);
void OnAbilityWillContinue(const int64_t &ability);
void OnWindowStageWillRestore(const int64_t &ability, WindowStagePtr windowStage);
void OnWindowStageRestore(const int64_t &ability, WindowStagePtr windowStage);
void OnAbilityWillSaveState(const int64_t &ability);
void OnAbilitySaveState(const int64_t &ability);
int32_t Register(CArrI64 cFuncIds, bool isSync = false);
bool UnRegister(int32_t callbackId, bool isSync = false);
bool IsEmpty() const;
static int32_t serialNumber_;
private:
std::map<int32_t, std::function<void(int64_t)>> onAbilityCreatecallbacks_;
std::map<int32_t, std::function<void(int64_t, WindowStagePtr)>> onWindowStageCreatecallbacks_;
std::map<int32_t, std::function<void(int64_t, WindowStagePtr)>> onWindowStageActivecallbacks_;
std::map<int32_t, std::function<void(int64_t, WindowStagePtr)>> onWindowStageInactivecallbacks_;
std::map<int32_t, std::function<void(int64_t, WindowStagePtr)>> onWindowStageDestroycallbacks_;
std::map<int32_t, std::function<void(int64_t)>> onAbilityDestroycallbacks_;
std::map<int32_t, std::function<void(int64_t)>> onAbilityForegroundcallbacks_;
std::map<int32_t, std::function<void(int64_t)>> onAbilityBackgroundcallbacks_;
std::map<int32_t, std::function<void(int64_t)>> onAbilityContinuecallbacks_;
// optional callbacks
std::map<int32_t, std::function<void(int64_t)>> onAbilityWillCreatecallbacks_;
std::map<int32_t, std::function<void(int64_t, WindowStagePtr)>> onWindowStageWillCreatecallbacks_;
std::map<int32_t, std::function<void(int64_t, WindowStagePtr)>> onWindowStageWillDestroycallbacks_;
std::map<int32_t, std::function<void(int64_t)>> onAbilityWillForegroundcallbacks_;
std::map<int32_t, std::function<void(int64_t)>> onAbilityWillDestroycallbacks_;
std::map<int32_t, std::function<void(int64_t)>> onAbilityWillBackgroundcallbacks_;
std::map<int32_t, std::function<void(int64_t)>> onWillNewWantcallbacks_;
std::map<int32_t, std::function<void(int64_t)>> onNewWantcallbacks_;
std::map<int32_t, std::function<void(int64_t)>> onAbilityWillContinuecallbacks_;
std::map<int32_t, std::function<void(int64_t, WindowStagePtr)>> onWindowStageWillRestorecallbacks_;
std::map<int32_t, std::function<void(int64_t, WindowStagePtr)>> onWindowStageRestorecallbacks_;
std::map<int32_t, std::function<void(int64_t)>> onAbilityWillSaveStatecallbacks_;
std::map<int32_t, std::function<void(int64_t)>> onAbilitySaveStatecallbacks_;
};
} // namespace AbilityRuntime
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_CJ_CONTEXT_ABILITY_LIFECYCLE_CALLBACK_H
@@ -0,0 +1,92 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_CJ_ABILITY_RUNTIME_ABILITY_RUNTIME_ERROR_H
#define OHOS_CJ_ABILITY_RUNTIME_ABILITY_RUNTIME_ERROR_H
#include <string>
namespace OHOS {
namespace AbilityRuntime {
enum {
ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_ABILITY_NAME = 16000001,
ERR_ABILITY_RUNTIME_EXTERNAL_NOT_SUPPORT_OPERATION = 16000002,
ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_ID = 16000003,
ERR_ABILITY_RUNTIME_EXTERNAL_VISIBILITY_VERIFICATION_FAILED = 16000004,
ERR_ABILITY_RUNTIME_EXTERNAL_CROSS_USER_OPERATION = 16000006,
ERR_ABILITY_RUNTIME_EXTERNAL_SERVICE_BUSY = 16000007,
ERR_ABILITY_RUNTIME_EXTERNAL_CROWDTEST_APP_EXPIRATION = 16000008,
ERR_ABILITY_RUNTIME_EXTERNAL_WUKONG_MODE = 16000009,
ERR_ABILITY_RUNTIME_EXTERNAL_OPERATION_WITH_CONTINUE_FLAG = 16000010,
ERR_ABILITY_RUNTIME_EXTERNAL_CONTEXT_NOT_EXIST = 16000011,
ERR_ABILITY_RUNTIME_EXTERNAL_ABILITY_ALREADY_AT_TOP = 16000012,
ERR_ABILITY_RUNTIME_EXTERNAL_CONNECTION_NOT_EXIST = 16000013,
ERR_ABILITY_RUNTIME_EXTERNAL_CONNECTION_STATE_ABNORMAL = 16000014,
ERR_ABILITY_RUNTIME_EXTERNAL_SERVICE_TIMEOUT = 16000015,
ERR_ABILITY_RUNTIME_EXTERNAL_APP_UNDER_CONTROL = 16000016,
ERR_ABILITY_RUNTIME_EXTERNAL_START_ABILITY_WAITTING = 16000017,
ERR_ABILITY_RUNTIME_EXTERNAL_NOT_SUPPORT_CROSS_APP_START = 16000018,
ERR_ABILITY_RUNTIME_EXTERNAL_CANNOT_MATCH_ANY_COMPONENT = 16000019,
ERR_ABILITY_RUNTIME_EXTERNAL_INTERNAL_ERROR = 16000050,
ERR_ABILITY_RUNTIME_EXTERNAL_NETWORK_ERROR = 16000051,
ERR_ABILITY_RUNTIME_EXTERNAL_FREE_INSTALL_NOT_SUPPORT = 16000052,
ERR_ABILITY_RUNTIME_EXTERNAL_NOT_TOP_ABILITY = 16000053,
ERR_ABILITY_RUNTIME_EXTERNAL_FREE_INSTALL_BUSY = 16000054,
ERR_ABILITY_RUNTIME_EXTERNAL_FREE_INSTALL_TIMEOUT = 16000055,
ERR_ABILITY_RUNTIME_EXTERNAL_CANNOT_FREE_INSTALL_OTHER_ABILITY = 16000056,
ERR_ABILITY_RUNTIME_EXTERNAL_NOT_SUPPORT_CROSS_DEVICE_FREE_INSTALL = 16000057,
ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_URI_FLAG = 16000058,
ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_URI_TYPE = 16000059,
ERR_ABILITY_RUNTIME_EXTERNAL_GRANT_URI_PERMISSION = 16000060,
ERR_ABILITY_RUNTIME_OPERATION_NOT_SUPPORTED = 16000061,
ERR_ABILITY_RUNTIME_CHILD_PROCESS_NUMBER_EXCEEDS_UPPER_BOUND = 16000062,
ERR_ABILITY_RUNTIME_RESTART_APP_INCORRECT_ABILITY = 16000063,
ERR_ABILITY_RUNTIME_RESTART_APP_FREQUENT = 16000064,
ERR_ABILITY_RUNTIME_EXTERNAL_EXECUTE_SHELL_COMMAND_FAILED = 16000101,
ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_WANTAGENT = 16000151,
ERR_ABILITY_RUNTIME_EXTERNAL_WANTAGENT_NOT_FOUND = 16000152,
ERR_ABILITY_RUNTIME_EXTERNAL_WANTAGENT_CANCELED = 16000153,
ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_URI_ABILITY = 16100001,
ERR_ABILITY_RUNTIME_EXTERNAL_FA_NOT_SUPPORT_OPERATION = 16100002,
ERR_ABILITY_RUNTIME_EXTERNAL_CALLER_RELEASED = 16200001,
ERR_ABILITY_RUNTIME_EXTERNAL_CALLEE_INVALID = 16200002,
ERR_ABILITY_RUNTIME_EXTERNAL_RELEASE_ERROR = 16200003,
ERR_ABILITY_RUNTIME_EXTERNAL_METHOED_REGISTERED = 16200004,
ERR_ABILITY_RUNTIME_EXTERNAL_METHOED_NOT_REGISTERED = 16200005,
ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_MISSION = 16300001,
ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_MISSION_LISTENER = 16300002,
ERR_ABILITY_RUNTIME_EXTERNAL_NOT_SYSTEM_HSP = 16400001,
ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_BUNDLENAME = 18500001,
ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_HQF = 18500002,
ERR_ABILITY_RUNTIME_EXTERNAL_DEPLOY_HQF_FAILED = 18500003,
ERR_ABILITY_RUNTIME_EXTERNAL_SWITCH_HQF_FAILED = 18500004,
ERR_ABILITY_RUNTIME_EXTERNAL_DELETE_HQF_FAILED = 18500005,
ERR_ABILITY_RUNTIME_EXTERNAL_LOAD_PATCH_FAILED = 18500006,
ERR_ABILITY_RUNTIME_EXTERNAL_UNLOAD_PATCH_FAILED = 18500007,
ERR_ABILITY_RUNTIME_EXTERNAL_QUICK_FIX_INTERNAL_ERROR = 18500008,
ERR_ABILITY_RUNTIME_EXTERNAL_NO_ACCESS_PERMISSION = 201,
ERR_ABILITY_RUNTIME_NOT_SYSTEM_APP = 202,
ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER = 401,
ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_SYSCAP = 801,
};
} // namespace AbilityRuntime
} // namespace OHOS
#endif // OHOS_CJ_ABILITY_RUNTIME_ABILITY_RUNTIME_ERROR_H
@@ -18,13 +18,28 @@
#include "ability_delegator_registry.h"
#include "application_context.h"
#include "cj_utils_ffi.h"
#include "cj_lambda.h"
#include "hilog_tag_wrapper.h"
#include "cj_ability_runtime_error.h"
namespace OHOS {
namespace ApplicationContextCJ {
using namespace OHOS::FFI;
using namespace OHOS::AbilityRuntime;
std::vector<std::shared_ptr<CjAbilityLifecycleCallback>> CJApplicationContext::callbacks_;
CJApplicationContext* CJApplicationContext::cjApplicationContext_ = nullptr;
CJApplicationContext* CJApplicationContext::GetCJApplicationContext(
std::weak_ptr<AbilityRuntime::ApplicationContext> &&applicationContext)
{
if (cjApplicationContext_) {
return cjApplicationContext_;
}
cjApplicationContext_ = FFIData::Create<CJApplicationContext>(applicationContext);
return cjApplicationContext_;
}
int CJApplicationContext::GetArea()
{
auto context = applicationContext_.lock();
@@ -45,6 +60,499 @@ std::shared_ptr<AppExecFwk::ApplicationInfo> CJApplicationContext::GetApplicatio
return context->GetApplicationInfo();
}
bool CJApplicationContext::IsAbilityLifecycleCallbackEmpty()
{
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
return callbacks_.empty();
}
void CJApplicationContext::RegisterAbilityLifecycleCallback(
const std::shared_ptr<CjAbilityLifecycleCallback> &abilityLifecycleCallback)
{
TAG_LOGD(AAFwkTag::CONTEXT, "called");
if (abilityLifecycleCallback == nullptr) {
return;
}
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
callbacks_.push_back(abilityLifecycleCallback);
}
void CJApplicationContext::UnregisterAbilityLifecycleCallback(
const std::shared_ptr<CjAbilityLifecycleCallback> &abilityLifecycleCallback)
{
TAG_LOGD(AAFwkTag::CONTEXT, "called");
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
auto it = std::find(callbacks_.begin(), callbacks_.end(), abilityLifecycleCallback);
if (it != callbacks_.end()) {
callbacks_.erase(it);
}
}
void CJApplicationContext::DispatchOnAbilityCreate(const int64_t &ability)
{
TAG_LOGD(AAFwkTag::APPKIT, "called");
if (!ability) {
TAG_LOGE(AAFwkTag::CONTEXT, "ability is null");
return;
}
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
for (auto callback : callbacks_) {
if (callback != nullptr) {
callback->OnAbilityCreate(ability);
}
}
}
void CJApplicationContext::DispatchOnWindowStageCreate(const int64_t &ability, WindowStagePtr windowStage)
{
TAG_LOGD(AAFwkTag::APPKIT, "called");
if (!ability || !windowStage) {
TAG_LOGE(AAFwkTag::CONTEXT, "ability or windowStage is nullptr");
return;
}
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
for (auto callback : callbacks_) {
if (callback != nullptr) {
callback->OnWindowStageCreate(ability, windowStage);
}
}
}
void CJApplicationContext::DispatchWindowStageFocus(const int64_t &ability, WindowStagePtr windowStage)
{
TAG_LOGD(AAFwkTag::APPKIT, "called");
if (!ability || !windowStage) {
TAG_LOGE(AAFwkTag::APPKIT, "ability or windowStage is null");
return;
}
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
for (auto callback : callbacks_) {
if (callback != nullptr) {
callback->OnWindowStageActive(ability, windowStage);
}
}
}
void CJApplicationContext::DispatchWindowStageUnfocus(const int64_t &ability, WindowStagePtr windowStage)
{
TAG_LOGD(AAFwkTag::APPKIT, "called");
if (!ability || !windowStage) {
TAG_LOGE(AAFwkTag::APPKIT, "ability or windowStage is nullptr");
return;
}
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
for (auto callback : callbacks_) {
if (callback != nullptr) {
callback->OnWindowStageInactive(ability, windowStage);
}
}
}
void CJApplicationContext::DispatchOnWindowStageDestroy(const int64_t &ability, WindowStagePtr windowStage)
{
TAG_LOGD(AAFwkTag::APPKIT, "called");
if (!ability || !windowStage) {
TAG_LOGE(AAFwkTag::CONTEXT, "ability or windowStage is nullptr");
return;
}
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
for (auto callback : callbacks_) {
if (callback != nullptr) {
callback->OnWindowStageDestroy(ability, windowStage);
}
}
}
void CJApplicationContext::DispatchOnAbilityDestroy(const int64_t &ability)
{
TAG_LOGD(AAFwkTag::APPKIT, "called");
if (!ability) {
TAG_LOGE(AAFwkTag::APPKIT, "ability is null");
return;
}
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
for (auto callback : callbacks_) {
if (callback != nullptr) {
callback->OnAbilityDestroy(ability);
}
}
}
void CJApplicationContext::DispatchOnAbilityForeground(const int64_t &ability)
{
TAG_LOGD(AAFwkTag::APPKIT, "called");
if (!ability) {
TAG_LOGE(AAFwkTag::CONTEXT, "ability is null");
return;
}
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
for (auto callback : callbacks_) {
if (callback != nullptr) {
callback->OnAbilityForeground(ability);
}
}
}
void CJApplicationContext::DispatchOnAbilityBackground(const int64_t &ability)
{
TAG_LOGD(AAFwkTag::APPKIT, "called");
if (!ability) {
TAG_LOGE(AAFwkTag::CONTEXT, "ability is null");
return;
}
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
for (auto callback : callbacks_) {
if (callback != nullptr) {
callback->OnAbilityBackground(ability);
}
}
}
void CJApplicationContext::DispatchOnAbilityContinue(const int64_t &ability)
{
TAG_LOGD(AAFwkTag::APPKIT, "called");
if (!ability) {
TAG_LOGE(AAFwkTag::APPKIT, "ability is null");
return;
}
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
for (auto callback : callbacks_) {
if (callback != nullptr) {
callback->OnAbilityContinue(ability);
}
}
}
void CJApplicationContext::DispatchOnAbilityWillCreate(const int64_t &ability)
{
TAG_LOGD(AAFwkTag::APPKIT, "called");
if (!ability) {
TAG_LOGE(AAFwkTag::APPKIT, "ability is null");
return;
}
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
for (auto callback : callbacks_) {
if (callback != nullptr) {
callback->OnAbilityWillCreate(ability);
}
}
}
void CJApplicationContext::DispatchOnWindowStageWillCreate(const int64_t &ability, WindowStagePtr windowStage)
{
TAG_LOGD(AAFwkTag::APPKIT, "called");
if (!ability || !windowStage) {
TAG_LOGE(AAFwkTag::APPKIT, "ability or windowStage is null");
return;
}
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
for (auto callback : callbacks_) {
if (callback != nullptr) {
callback->OnWindowStageWillCreate(ability, windowStage);
}
}
}
void CJApplicationContext::DispatchOnWindowStageWillDestroy(const int64_t &ability, WindowStagePtr windowStage)
{
TAG_LOGD(AAFwkTag::APPKIT, "called");
if (!ability || !windowStage) {
TAG_LOGE(AAFwkTag::APPKIT, "ability or windowStage is null");
return;
}
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
for (auto callback : callbacks_) {
if (callback != nullptr) {
callback->OnWindowStageWillDestroy(ability, windowStage);
}
}
}
void CJApplicationContext::DispatchOnAbilityWillDestroy(const int64_t &ability)
{
TAG_LOGD(AAFwkTag::APPKIT, "called");
if (!ability) {
TAG_LOGE(AAFwkTag::APPKIT, "ability is null");
return;
}
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
for (auto callback : callbacks_) {
if (callback != nullptr) {
callback->OnAbilityWillDestroy(ability);
}
}
}
void CJApplicationContext::DispatchOnAbilityWillForeground(const int64_t &ability)
{
TAG_LOGD(AAFwkTag::APPKIT, "called");
if (!ability) {
TAG_LOGE(AAFwkTag::APPKIT, "ability is null");
return;
}
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
for (auto callback : callbacks_) {
if (callback != nullptr) {
callback->OnAbilityWillForeground(ability);
}
}
}
void CJApplicationContext::DispatchOnAbilityWillBackground(const int64_t &ability)
{
TAG_LOGD(AAFwkTag::APPKIT, "called");
if (!ability) {
TAG_LOGE(AAFwkTag::APPKIT, "ability is null");
return;
}
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
for (auto callback : callbacks_) {
if (callback != nullptr) {
callback->OnAbilityWillBackground(ability);
}
}
}
void CJApplicationContext::DispatchOnNewWant(const int64_t &ability)
{
TAG_LOGD(AAFwkTag::APPKIT, "called");
if (!ability) {
TAG_LOGE(AAFwkTag::APPKIT, "ability is null");
return;
}
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
for (auto callback : callbacks_) {
if (callback != nullptr) {
callback->OnNewWant(ability);
}
}
}
void CJApplicationContext::DispatchOnWillNewWant(const int64_t &ability)
{
TAG_LOGD(AAFwkTag::APPKIT, "called");
if (!ability) {
TAG_LOGE(AAFwkTag::APPKIT, "ability is null");
return;
}
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
for (auto callback : callbacks_) {
if (callback != nullptr) {
callback->OnWillNewWant(ability);
}
}
}
void CJApplicationContext::DispatchOnAbilityWillContinue(const int64_t &ability)
{
TAG_LOGD(AAFwkTag::APPKIT, "Dispatch onAbilityWillContinue");
if (!ability) {
TAG_LOGE(AAFwkTag::APPKIT, "ability is null");
return;
}
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
for (auto callback : callbacks_) {
if (callback != nullptr) {
callback->OnAbilityWillContinue(ability);
}
}
}
void CJApplicationContext::DispatchOnWindowStageWillRestore(const int64_t &ability, WindowStagePtr windowStage)
{
TAG_LOGD(AAFwkTag::APPKIT, "Dispatch onWindowStageWillRestore");
if (!ability || windowStage == nullptr) {
TAG_LOGE(AAFwkTag::APPKIT, "ability or windowStage is null");
return;
}
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
for (auto callback : callbacks_) {
if (callback != nullptr) {
callback->OnWindowStageWillRestore(ability, windowStage);
}
}
}
void CJApplicationContext::DispatchOnWindowStageRestore(const int64_t &ability, WindowStagePtr windowStage)
{
TAG_LOGD(AAFwkTag::APPKIT, "Dispatch onWindowStageRestore");
if (!ability || windowStage == nullptr) {
TAG_LOGE(AAFwkTag::APPKIT, "ability or windowStage is null");
return;
}
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
for (auto callback : callbacks_) {
if (callback != nullptr) {
callback->OnWindowStageRestore(ability, windowStage);
}
}
}
void CJApplicationContext::DispatchOnAbilityWillSaveState(const int64_t &ability)
{
TAG_LOGD(AAFwkTag::APPKIT, "Dispatch onAbilityWillSaveState");
if (!ability) {
TAG_LOGE(AAFwkTag::APPKIT, "ability is null");
return;
}
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
for (auto callback : callbacks_) {
if (callback != nullptr) {
callback->OnAbilityWillSaveState(ability);
}
}
}
void CJApplicationContext::DispatchOnAbilitySaveState(const int64_t &ability)
{
TAG_LOGD(AAFwkTag::APPKIT, "called");
if (!ability) {
TAG_LOGE(AAFwkTag::APPKIT, "ability is null");
return;
}
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
for (auto callback : callbacks_) {
if (callback != nullptr) {
callback->OnAbilitySaveState(ability);
}
}
}
int32_t CJApplicationContext::OnOnEnvironment(void (*cfgCallback)(CConfiguration),
void (*memCallback)(int32_t), bool isSync, int32_t *errCode)
{
auto context = applicationContext_.lock();
if (context == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "null context");
*errCode = ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER;
return -1;
}
if (envCallback_ != nullptr) {
TAG_LOGD(AAFwkTag::CONTEXT, "envCallback_ is not nullptr.");
return envCallback_->Register(CJLambda::Create(cfgCallback), CJLambda::Create(memCallback), isSync);
}
envCallback_ = std::make_shared<CjEnvironmentCallback>();
int32_t callbackId = envCallback_->Register(CJLambda::Create(cfgCallback), CJLambda::Create(memCallback), isSync);
context->RegisterEnvironmentCallback(envCallback_);
TAG_LOGD(AAFwkTag::CONTEXT, "OnOnEnvironment is end");
return callbackId;
}
int32_t CJApplicationContext::OnOnAbilityLifecycle(CArrI64 cFuncIds, bool isSync, int32_t *errCode)
{
auto context = applicationContext_.lock();
if (context == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "null context");
*errCode = ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER;
return -1;
}
if (callback_ != nullptr) {
TAG_LOGD(AAFwkTag::CONTEXT, "callback_ is not nullptr.");
return callback_->Register(cFuncIds, isSync);
}
callback_ = std::make_shared<CjAbilityLifecycleCallback>();
int32_t callbackId = callback_->Register(cFuncIds, isSync);
RegisterAbilityLifecycleCallback(callback_);
return callbackId;
}
int32_t CJApplicationContext::OnOnApplicationStateChange(void (*foregroundCallback)(void),
void (*backgroundCallback)(void), int32_t *errCode)
{
auto context = applicationContext_.lock();
if (context == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "null context");
*errCode = ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER;
return -1;
}
std::lock_guard<std::mutex> lock(applicationStateCallbackLock_);
if (applicationStateCallback_ != nullptr) {
return applicationStateCallback_->Register(CJLambda::Create(foregroundCallback),
CJLambda::Create(backgroundCallback));
}
applicationStateCallback_ = std::make_shared<CjApplicationStateChangeCallback>();
int32_t callbackId = applicationStateCallback_->Register(CJLambda::Create(foregroundCallback),
CJLambda::Create(backgroundCallback));
context->RegisterApplicationStateChangeCallback(applicationStateCallback_);
return callbackId;
}
void CJApplicationContext::OnOffEnvironment(int32_t callbackId, int32_t *errCode)
{
auto context = applicationContext_.lock();
if (context == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "null context");
*errCode = ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER;
return;
}
std::weak_ptr<CjEnvironmentCallback> envCallbackWeak(envCallback_);
auto env_callback = envCallbackWeak.lock();
if (env_callback == nullptr) {
TAG_LOGD(AAFwkTag::CONTEXT, "env_callback is not nullptr.");
*errCode = ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER;
return;
}
TAG_LOGD(AAFwkTag::CONTEXT, "OnOffEnvironment begin");
if (!env_callback->UnRegister(callbackId, false)) {
TAG_LOGE(AAFwkTag::CONTEXT, "call UnRegister failed");
*errCode = ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER;
return;
}
}
void CJApplicationContext::OnOffAbilityLifecycle(int32_t callbackId, int32_t *errCode)
{
auto context = applicationContext_.lock();
if (context == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "null context");
*errCode = ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER;
return;
}
std::weak_ptr<CjAbilityLifecycleCallback> callbackWeak(callback_);
auto lifecycle_callback = callbackWeak.lock();
if (lifecycle_callback == nullptr) {
TAG_LOGD(AAFwkTag::CONTEXT, "env_callback is not nullptr.");
*errCode = ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER;
return;
}
TAG_LOGD(AAFwkTag::CONTEXT, "OnOffAbilityLifecycle begin");
if (!lifecycle_callback->UnRegister(callbackId, false)) {
TAG_LOGE(AAFwkTag::CONTEXT, "call UnRegister failed");
*errCode = ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER;
return;
}
}
void CJApplicationContext::OnOffApplicationStateChange(int32_t callbackId, int32_t *errCode)
{
auto context = applicationContext_.lock();
if (context == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "null context");
*errCode = ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER;
return;
}
std::lock_guard<std::mutex> lock(applicationStateCallbackLock_);
if (applicationStateCallback_ == nullptr) {
TAG_LOGD(AAFwkTag::CONTEXT, "env_callback is not nullptr.");
*errCode = ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER;
return;
}
TAG_LOGD(AAFwkTag::CONTEXT, "OnOffApplicationStateChange begin");
if (!applicationStateCallback_->UnRegister(callbackId)) {
TAG_LOGE(AAFwkTag::CONTEXT, "call UnRegister failed");
*errCode = ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER;
return;
}
if (applicationStateCallback_->IsEmpty()) {
applicationStateCallback_.reset();
}
}
extern "C" {
int64_t FFIGetArea(int64_t id)
{
@@ -73,6 +581,64 @@ CApplicationInfo* FFICJApplicationInfo(int64_t id)
buffer->bundleName = CreateCStringFromString(appInfo->bundleName);
return buffer;
}
int32_t FfiCJApplicationContextOnOnEnvironment(int64_t id, void (*cfgCallback)(CConfiguration),
void (*memCallback)(int32_t), int32_t *errCode)
{
auto context = FFI::FFIData::GetData<CJApplicationContext>(id);
if (context == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "null context");
*errCode = ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER;
return -1;
}
return context->OnOnEnvironment(cfgCallback, memCallback, false, errCode);
}
int32_t FfiCJApplicationContextOnOnAbilityLifecycle(int64_t id, CArrI64 cFuncIds, int32_t *errCode)
{
auto context = FFI::FFIData::GetData<CJApplicationContext>(id);
if (context == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "null context");
*errCode = ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER;
return -1;
}
return context->OnOnAbilityLifecycle(cFuncIds, false, errCode);
}
int32_t FfiCJApplicationContextOnOnApplicationStateChange(int64_t id, void (*foregroundCallback)(void),
void (*backgroundCallback)(void), int32_t *errCode)
{
auto context = FFI::FFIData::GetData<CJApplicationContext>(id);
if (context == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "null context");
*errCode = ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER;
return -1;
}
return context->OnOnApplicationStateChange(foregroundCallback, backgroundCallback, errCode);
}
void FfiCJApplicationContextOnOff(int64_t id, const char* type, int32_t callbackId, int32_t *errCode)
{
auto context = FFI::FFIData::GetData<CJApplicationContext>(id);
if (context == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "null context");
*errCode = ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER;
return;
}
auto typeString = std::string(type);
if (typeString == "environment") {
return context->OnOffEnvironment(callbackId, errCode);
}
if (typeString == "abilityLifecycle") {
return context->OnOffAbilityLifecycle(callbackId, errCode);
}
if (typeString == "applicationStateChange") {
return context->OnOffApplicationStateChange(callbackId, errCode);
}
TAG_LOGE(AAFwkTag::CONTEXT, "off function type not match");
*errCode = ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER;
return;
}
}
}
}
+59 -2
View File
@@ -17,23 +17,74 @@
#define OHOS_ABILITY_RUNTIME_CJ_APPLICATION_CONTEXT_H
#include <cstdint>
#include <shared_mutex>
#include "cj_macro.h"
#include "cj_environment_callback.h"
#include "cj_ability_lifecycle_callback.h"
#include "cj_application_state_change_callback.h"
#include "cj_common_ffi.h"
#include "ffi_remote_data.h"
#include "ability_delegator_registry.h"
namespace OHOS {
namespace ApplicationContextCJ {
using namespace OHOS::AbilityRuntime;
class CJApplicationContext : public FFI::FFIData {
public:
explicit CJApplicationContext(std::weak_ptr<AbilityRuntime::Context> &&applicationContext)
explicit CJApplicationContext(std::weak_ptr<AbilityRuntime::ApplicationContext> &&applicationContext)
: applicationContext_(std::move(applicationContext)) {};
int GetArea();
std::shared_ptr<AppExecFwk::ApplicationInfo> GetApplicationInfo();
void RegisterAbilityLifecycleCallback(const std::shared_ptr<CjAbilityLifecycleCallback> &abilityLifecycleCallback);
void UnregisterAbilityLifecycleCallback(
const std::shared_ptr<CjAbilityLifecycleCallback> &abilityLifecycleCallback);
bool IsAbilityLifecycleCallbackEmpty();
void DispatchOnAbilityCreate(const int64_t &ability);
void DispatchOnWindowStageCreate(const int64_t &ability, WindowStagePtr windowStage);
void DispatchWindowStageFocus(const int64_t &ability, WindowStagePtr windowStage);
void DispatchWindowStageUnfocus(const int64_t &ability, WindowStagePtr windowStage);
void DispatchOnWindowStageDestroy(const int64_t &ability, WindowStagePtr windowStage);
void DispatchOnAbilityDestroy(const int64_t &ability);
void DispatchOnAbilityForeground(const int64_t &ability);
void DispatchOnAbilityBackground(const int64_t &ability);
void DispatchOnAbilityContinue(const int64_t &ability);
// optional callbacks
void DispatchOnAbilityWillCreate(const int64_t &ability);
void DispatchOnWindowStageWillCreate(const int64_t &ability, WindowStagePtr windowStage);
void DispatchOnWindowStageWillDestroy(const int64_t &ability, WindowStagePtr windowStage);
void DispatchOnAbilityWillDestroy(const int64_t &ability);
void DispatchOnAbilityWillForeground(const int64_t &ability);
void DispatchOnAbilityWillBackground(const int64_t &ability);
void DispatchOnNewWant(const int64_t &ability);
void DispatchOnWillNewWant(const int64_t &ability);
void DispatchOnAbilityWillContinue(const int64_t &ability);
void DispatchOnWindowStageWillRestore(const int64_t &ability, WindowStagePtr windowStage);
void DispatchOnWindowStageRestore(const int64_t &ability, WindowStagePtr windowStage);
void DispatchOnAbilityWillSaveState(const int64_t &ability);
void DispatchOnAbilitySaveState(const int64_t &ability);
int32_t OnOnEnvironment(void (*cfgCallback)(AbilityRuntime::CConfiguration),
void (*memCallback)(int32_t), bool isSync, int32_t *errCode);
int32_t OnOnAbilityLifecycle(CArrI64 cFuncIds, bool isSync, int32_t *errCode);
int32_t OnOnApplicationStateChange(void (*foregroundCallback)(void),
void (*backgroundCallback)(void), int32_t *errCode);
void OnOffEnvironment(int32_t callbackId, int32_t *errCode);
void OnOffAbilityLifecycle(int32_t callbackId, int32_t *errCode);
void OnOffApplicationStateChange(int32_t callbackId, int32_t *errCode);
static CJApplicationContext* GetCJApplicationContext(
std::weak_ptr<AbilityRuntime::ApplicationContext> &&applicationContext);
private:
std::weak_ptr<AbilityRuntime::Context> applicationContext_;
std::weak_ptr<AbilityRuntime::ApplicationContext> applicationContext_;
std::shared_ptr<AbilityRuntime::CjAbilityLifecycleCallback> callback_;
std::shared_ptr<AbilityRuntime::CjEnvironmentCallback> envCallback_;
std::shared_ptr<CjApplicationStateChangeCallback> applicationStateCallback_;
std::mutex applicationStateCallbackLock_;
std::recursive_mutex callbackLock_;
static std::vector<std::shared_ptr<CjAbilityLifecycleCallback>> callbacks_;
static CJApplicationContext* cjApplicationContext_;
};
extern "C" {
@@ -44,6 +95,12 @@ struct CApplicationInfo {
CJ_EXPORT int64_t FFIGetArea(int64_t id);
CJ_EXPORT CApplicationInfo* FFICJApplicationInfo(int64_t id);
CJ_EXPORT int32_t FfiCJApplicationContextOnOnEnvironment(int64_t id, void (*cfgCallback)(CConfiguration),
void (*memCallback)(int32_t), int32_t *errCode);
CJ_EXPORT int32_t FfiCJApplicationContextOnOnAbilityLifecycle(int64_t id, CArrI64 cFuncIds, int32_t *errCode);
CJ_EXPORT int32_t FfiCJApplicationContextOnOnApplicationStateChange(int64_t id, void (*foregroundCallback)(void),
void (*backgroundCallback)(void), int32_t *errCode);
CJ_EXPORT void FfiCJApplicationContextOnOff(int64_t id, const char* type, int32_t callbackId, int32_t *errCode);
};
}
}
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "cj_application_state_change_callback.h"
#include "hilog_tag_wrapper.h"
namespace OHOS {
namespace AbilityRuntime {
int32_t CjApplicationStateChangeCallback::serialNumber_ = 0;
CjApplicationStateChangeCallback::CjApplicationStateChangeCallback()
{
}
void CjApplicationStateChangeCallback::NotifyApplicationForeground()
{
TAG_LOGD(AAFwkTag::APPKIT, "MethodName = onApplicationForeground");
for (auto &callback : foregroundCallbacks_) {
if (callback.second) {
callback.second();
}
}
}
void CjApplicationStateChangeCallback::NotifyApplicationBackground()
{
TAG_LOGD(AAFwkTag::APPKIT, "MethodName = onApplicationBackground");
for (auto &callback : backgroundCallbacks_) {
if (callback.second) {
callback.second();
}
}
}
int32_t CjApplicationStateChangeCallback::Register(std::function<void(void)> foregroundCallback,
std::function<void(void)> backgroundCallback)
{
int32_t callbackId = serialNumber_;
if (serialNumber_ < INT32_MAX) {
serialNumber_++;
} else {
serialNumber_ = 0;
}
foregroundCallbacks_.emplace(callbackId, foregroundCallback);
backgroundCallbacks_.emplace(callbackId, backgroundCallback);
return callbackId;
}
bool CjApplicationStateChangeCallback::UnRegister(int32_t callbackId)
{
if (callbackId < 0) {
TAG_LOGI(AAFwkTag::APPKIT, "delete all callback");
foregroundCallbacks_.clear();
backgroundCallbacks_.clear();
return true;
}
auto it = foregroundCallbacks_.find(callbackId);
if (it == foregroundCallbacks_.end()) {
TAG_LOGE(AAFwkTag::APPKIT, "callbackId: %{public}d is not in callbacks_", callbackId);
return false;
}
TAG_LOGD(AAFwkTag::APPKIT, "callbacks_.callbackId : %{public}d", it->first);
return foregroundCallbacks_.erase(callbackId) == 1 && backgroundCallbacks_.erase(callbackId) == 1;
}
bool CjApplicationStateChangeCallback::IsEmpty() const
{
return foregroundCallbacks_.empty() && backgroundCallbacks_.empty();
}
} // namespace AbilityRuntime
} // namespace OHOS
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_ABILITY_RUNTIME_CJ_APPLICATION_STATE_CHANGE_CALLBACK_H
#define OHOS_ABILITY_RUNTIME_CJ_APPLICATION_STATE_CHANGE_CALLBACK_H
#include <map>
#include "application_state_change_callback.h"
namespace OHOS {
namespace AbilityRuntime {
class CjApplicationStateChangeCallback : public ApplicationStateChangeCallback,
public std::enable_shared_from_this<CjApplicationStateChangeCallback> {
public:
explicit CjApplicationStateChangeCallback();
virtual ~CjApplicationStateChangeCallback() = default;
void NotifyApplicationForeground() override;
void NotifyApplicationBackground() override;
int32_t Register(std::function<void(void)> foregroundCallback, std::function<void(void)> backgroundCallback);
bool UnRegister(int32_t callbackId);
bool IsEmpty() const;
private:
std::map<int32_t, std::function<void(void)>> foregroundCallbacks_;
std::map<int32_t, std::function<void(void)>> backgroundCallbacks_;
static int32_t serialNumber_;
};
} // namespace AbilityRuntime
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_CJ_APPLICATION_STATE_CHANGE_CALLBACK_H
@@ -0,0 +1,198 @@
/*
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "cj_environment_callback.h"
#include "hilog_tag_wrapper.h"
namespace OHOS {
namespace AbilityRuntime {
CjEnvironmentCallback::CjEnvironmentCallback()
{
}
int32_t CjEnvironmentCallback::serialNumber_ = 0;
int32_t ConvertColorMode(std::string colormode)
{
auto resolution = -1;
static const std::vector<std::pair<std::string, int32_t>> resolutions = {
{ "dark", 0 },
{ "light", 1 },
};
for (const auto& [tempColorMode, value] : resolutions) {
if (tempColorMode == colormode) {
resolution = value;
break;
}
}
return resolution;
}
int32_t ConvertDirection(std::string direction)
{
auto resolution = -1;
static const std::vector<std::pair<std::string, int32_t>> resolutions = {
{ "vertical", 0 },
{ "horizontal", 1 },
};
for (const auto& [tempDirection, value] : resolutions) {
if (tempDirection == direction) {
resolution = value;
break;
}
}
return resolution;
}
int32_t ConvertDensity(std::string density)
{
auto resolution = 0;
static const std::vector<std::pair<std::string, int32_t>> resolutions = {
{ "sdpi", 120 },
{ "mdpi", 160 },
{ "ldpi", 240 },
{ "xldpi", 320 },
{ "xxldpi", 480 },
{ "xxxldpi", 640 },
};
for (const auto& [tempdensity, value] : resolutions) {
if (tempdensity == density) {
resolution = value;
break;
}
}
return resolution;
}
int32_t ConvertDisplayId(std::string displayId)
{
if (displayId == AppExecFwk::ConfigurationInner::EMPTY_STRING) {
return -1;
}
return std::stoi(displayId);
}
CConfiguration CreateCConfiguration(const AppExecFwk::Configuration &configuration)
{
CConfiguration cfg;
cfg.language = CreateCStringFromString(configuration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE));
cfg.colorMode = ConvertColorMode(configuration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_COLORMODE));
std::string direction = configuration.GetItem(AppExecFwk::ConfigurationInner::APPLICATION_DIRECTION);
cfg.direction = ConvertDirection(direction);
std::string density = configuration.GetItem(AppExecFwk::ConfigurationInner::APPLICATION_DENSITYDPI);
cfg.screenDensity = ConvertDensity(density);
cfg.displayId = ConvertDisplayId(configuration.GetItem(AppExecFwk::ConfigurationInner::APPLICATION_DISPLAYID));
std::string hasPointerDevice = configuration.GetItem(AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE);
cfg.hasPointerDevice = hasPointerDevice == "true" ? true : false;
std::string fontSizeScale = configuration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_FONT_SIZE_SCALE);
cfg.fontSizeScale = fontSizeScale == "" ? 1.0 : std::stod(fontSizeScale);
std::string fontWeightScale = configuration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_FONT_WEIGHT_SCALE);
cfg.fontWeightScale = fontWeightScale == "" ? 1.0 : std::stod(fontWeightScale);
cfg.mcc = CreateCStringFromString(configuration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_MCC));
cfg.mnc = CreateCStringFromString(configuration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_MNC));
return cfg;
}
void CjEnvironmentCallback::CallConfigurationUpdatedInner(const AppExecFwk::Configuration &config,
const std::map<int32_t, std::function<void(CConfiguration)>> &callbacks)
{
TAG_LOGD(AAFwkTag::APPKIT, "methodName = onConfiguration");
for (auto &callback : callbacks) {
if (!callback.second) {
TAG_LOGE(AAFwkTag::APPKIT, " Invalid cjCallback");
return;
}
auto cfg = CreateCConfiguration(config);
callback.second(cfg);
}
}
void CjEnvironmentCallback::OnConfigurationUpdated(const AppExecFwk::Configuration &config)
{
std::weak_ptr<CjEnvironmentCallback> thisWeakPtr(shared_from_this());
std::shared_ptr<CjEnvironmentCallback> cjEnvCallback = thisWeakPtr.lock();
if (cjEnvCallback) {
cjEnvCallback->CallConfigurationUpdatedInner(config, onConfigurationUpdatedCallbacks_);
}
}
void CjEnvironmentCallback::CallMemoryLevelInner(const int level,
const std::map<int32_t, std::function<void(int32_t)>> &callbacks)
{
TAG_LOGD(AAFwkTag::APPKIT, "onMemoryLevel");
for (auto &callback : callbacks) {
if (!callback.second) {
TAG_LOGE(AAFwkTag::APPKIT, "Invalid jsCallback");
return;
}
callback.second(static_cast<int32_t>(level));
}
}
void CjEnvironmentCallback::OnMemoryLevel(const int level)
{
std::weak_ptr<CjEnvironmentCallback> thisWeakPtr(shared_from_this());
std::shared_ptr<CjEnvironmentCallback> cjEnvCallback = thisWeakPtr.lock();
if (cjEnvCallback) {
cjEnvCallback->CallMemoryLevelInner(level, onMemoryLevelCallbacks_);
}
}
int32_t CjEnvironmentCallback::Register(std::function<void(CConfiguration)> cfgCallback,
std::function<void(int32_t)> memCallback, bool isSync)
{
int32_t callbackId = serialNumber_;
if (serialNumber_ < INT32_MAX) {
serialNumber_++;
} else {
serialNumber_ = 0;
}
if (isSync) {
return -1;
} else {
onConfigurationUpdatedCallbacks_.emplace(callbackId, cfgCallback);
onMemoryLevelCallbacks_.emplace(callbackId, memCallback);
}
return callbackId;
}
bool CjEnvironmentCallback::UnRegister(int32_t callbackId, bool isSync)
{
TAG_LOGD(AAFwkTag::APPKIT, "callbackId : %{public}d", callbackId);
if (isSync) {
return false;
}
auto itCfg = onConfigurationUpdatedCallbacks_.find(callbackId);
if (itCfg == onConfigurationUpdatedCallbacks_.end()) {
TAG_LOGE(AAFwkTag::APPKIT, "callbackId: %{public}d is not in callbacks_", callbackId);
return false;
}
TAG_LOGD(AAFwkTag::APPKIT, "callbacks_.callbackId : %{public}d", itCfg->first);
auto itMem = onMemoryLevelCallbacks_.find(callbackId);
if (itMem == onMemoryLevelCallbacks_.end()) {
TAG_LOGE(AAFwkTag::APPKIT, "callbackId: %{public}d is not in callbacks_", callbackId);
return false;
}
TAG_LOGD(AAFwkTag::APPKIT, "callbacks_.callbackId : %{public}d", itMem->first);
return onConfigurationUpdatedCallbacks_.erase(callbackId) == 1 && onMemoryLevelCallbacks_.erase(callbackId) == 1;
}
bool CjEnvironmentCallback::IsEmpty() const
{
return onConfigurationUpdatedCallbacks_.empty() && onMemoryLevelCallbacks_.empty();
}
} // namespace AbilityRuntime
} // namespace OHOS
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_ABILITY_RUNTIME_CJ_ENVIRONMENT_CALLBACK_H
#define OHOS_ABILITY_RUNTIME_CJ_ENVIRONMENT_CALLBACK_H
#include <map>
#include <memory>
#include "cj_utils_ffi.h"
#include "configuration.h"
#include "environment_callback.h"
namespace OHOS {
namespace AbilityRuntime {
class CjEnvironmentCallback : public EnvironmentCallback,
public std::enable_shared_from_this<CjEnvironmentCallback> {
public:
explicit CjEnvironmentCallback();
void OnConfigurationUpdated(const AppExecFwk::Configuration &config) override;
void OnMemoryLevel(const int level) override;
int32_t Register(std::function<void(CConfiguration)> cfgCallback,
std::function<void(int32_t)> memCallback, bool isSync);
bool UnRegister(int32_t callbackId, bool isSync = false);
bool IsEmpty() const;
static int32_t serialNumber_;
private:
std::map<int32_t, std::function<void(CConfiguration)>> onConfigurationUpdatedCallbacks_;
std::map<int32_t, std::function<void(int32_t)>> onMemoryLevelCallbacks_;
void CallConfigurationUpdatedInner(const AppExecFwk::Configuration &config,
const std::map<int32_t, std::function<void(CConfiguration)>> &callbacks);
void CallMemoryLevelInner(const int level,
const std::map<int32_t, std::function<void(int32_t)>> &callbacks);
};
} // namespace AbilityRuntime
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_CJ_ENVIRONMENT_CALLBACK_H
+19
View File
@@ -18,6 +18,25 @@
#include <string>
namespace OHOS {
namespace AbilityRuntime {
struct CConfiguration {
char* language;
int32_t colorMode;
int32_t direction;
int32_t screenDensity;
int32_t displayId;
bool hasPointerDevice;
double fontSizeScale;
double fontWeightScale;
char* mcc;
char* mnc;
};
}
}
// The return variable needs free in CJ.
char* CreateCStringFromString(const std::string& source);
@@ -55,7 +55,7 @@ int LocalCallContainer::StartAbilityByCallInner(const Want& want, std::shared_pt
return ERR_OK;
}
}
sptr<CallerConnection> connect = new (std::nothrow) CallerConnection();
sptr<CallerConnection> connect = sptr<CallerConnection>::MakeSptr();
if (connect == nullptr) {
TAG_LOGE(AAFwkTag::LOCAL_CALL, "connection failed");
return ERR_INVALID_VALUE;
@@ -221,7 +221,7 @@ void LocalCallContainer::DumpCalls(std::vector<std::string>& info)
tempstr += " state #REQUESTING";
}
info.emplace_back(tempstr);
}
}
}
return;
}
@@ -67,7 +67,7 @@ void LocalCallRecord::SetRemoteObject(const sptr<IRemoteObject>& call)
}
record->OnCallStubDied(remote);
};
callRecipient_ = new CallRecipient(diedTask);
callRecipient_ = sptr<CallRecipient>::MakeSptr(diedTask);
}
remoteObject_->AddDeathRecipient(callRecipient_);
}
@@ -667,6 +667,7 @@ ohos_shared_library("uiabilitykit_native") {
"${ability_runtime_path}/frameworks/cj/ffi",
"${ability_runtime_path}/cj_environment/interfaces/inner_api",
]
deps += [ "${ability_runtime_path}/frameworks/cj/ffi:cj_ability_ffi" ]
defines = [ "CJ_FRONTEND" ]
external_deps += [
"napi:cj_bind_ffi",
@@ -45,29 +45,27 @@ void LifeCycle::DispatchLifecycle(const LifeCycle::Event &event, const Want &wan
}
state_ = event;
if (callbacks_.size() != 0) {
for (auto &callback : callbacks_) {
switch (event) {
for (auto &callback : callbacks_) {
switch (event) {
#ifdef SUPPORT_GRAPHICS
case ON_FOREGROUND: {
if (callback != nullptr) {
callback->OnForeground(want);
}
break;
case ON_FOREGROUND: {
if (callback != nullptr) {
callback->OnForeground(want);
}
break;
}
#endif
case ON_START: {
if (callback != nullptr) {
callback->OnStart(want);
}
break;
case ON_START: {
if (callback != nullptr) {
callback->OnStart(want);
}
default:
break;
}
if (callback != nullptr) {
callback->OnStateChanged(event, want);
break;
}
default:
break;
}
if (callback != nullptr) {
callback->OnStateChanged(event, want);
}
}
}
@@ -82,41 +80,39 @@ void LifeCycle::DispatchLifecycle(const LifeCycle::Event &event)
}
state_ = event;
if (callbacks_.size() != 0) {
for (auto &callback : callbacks_) {
switch (event) {
case ON_ACTIVE: {
if (callback != nullptr) {
callback->OnActive();
}
break;
for (auto &callback : callbacks_) {
switch (event) {
case ON_ACTIVE: {
if (callback != nullptr) {
callback->OnActive();
}
break;
}
#ifdef SUPPORT_GRAPHICS
case ON_BACKGROUND: {
if (callback != nullptr) {
callback->OnBackground();
}
break;
case ON_BACKGROUND: {
if (callback != nullptr) {
callback->OnBackground();
}
break;
}
#endif
case ON_INACTIVE: {
if (callback != nullptr) {
callback->OnInactive();
}
break;
case ON_INACTIVE: {
if (callback != nullptr) {
callback->OnInactive();
}
case ON_STOP: {
if (callback != nullptr) {
callback->OnStop();
}
break;
break;
}
case ON_STOP: {
if (callback != nullptr) {
callback->OnStop();
}
default:
break;
}
if (callback != nullptr) {
callback->OnStateChanged(event);
break;
}
default:
break;
}
if (callback != nullptr) {
callback->OnStateChanged(event);
}
}
}
@@ -115,6 +115,16 @@ void CJAbilityObject::OnSceneRestored(OHOS::Rosen::CJWindowStageImpl* cjWindowSt
g_cjAbilityFuncs->cjAbilityOnSceneRestored(id_, windowStage);
}
void CJAbilityObject::OnSceneWillDestroy(OHOS::Rosen::CJWindowStageImpl* cjWindowStage) const
{
if (g_cjAbilityFuncs == nullptr || g_cjAbilityFuncs->cjAbilityOnSceneWillDestroy == nullptr) {
TAG_LOGE(AAFwkTag::UIABILITY, "null cjAbilityFunc");
return;
}
WindowStagePtr windowStage = reinterpret_cast<WindowStagePtr>(cjWindowStage);
g_cjAbilityFuncs->cjAbilityOnSceneWillDestroy(id_, windowStage);
}
void CJAbilityObject::OnSceneDestroyed() const
{
if (g_cjAbilityFuncs == nullptr) {
@@ -143,6 +153,15 @@ void CJAbilityObject::OnBackground() const
g_cjAbilityFuncs->cjAbilityOnBackground(id_);
}
bool CJAbilityObject::OnBackPress(bool defaultRet) const
{
if (g_cjAbilityFuncs == nullptr || g_cjAbilityFuncs->cjAbilityOnBackPress == nullptr) {
TAG_LOGE(AAFwkTag::UIABILITY, "null cjAbilityFunc");
return defaultRet;
}
return g_cjAbilityFuncs->cjAbilityOnBackPress(id_);
}
void CJAbilityObject::OnConfigurationUpdated(const std::shared_ptr<AppExecFwk::Configuration>& configuration) const
{
if (g_cjAbilityFuncs == nullptr) {
@@ -204,5 +223,10 @@ void CJAbilityObject::Init(AbilityHandle ability) const
}
g_cjAbilityFuncs->cjAbilityInit(id_, ability);
}
int64_t CJAbilityObject::GetId() const
{
return id_;
}
} // namespace AbilityRuntime
} // namespace OHOS
@@ -36,6 +36,7 @@
#include "cj_runtime.h"
#include "cj_ability_object.h"
#include "cj_ability_context.h"
#include "cj_application_context.h"
#include "time_util.h"
#ifdef SUPPORT_SCREEN
#include "scene_board_judgement.h"
@@ -57,6 +58,8 @@ const int32_t BASE_DISPLAY_ID_NUM (10);
#endif
const char* CJWINDOW_FFI_LIBNAME = "libcj_window_ffi.z.so";
const char* FUNC_CREATE_CJWINDOWSTAGE = "OHOS_CreateCJWindowStage";
constexpr const int32_t API12 = 12;
constexpr const int32_t API_VERSION_MOD = 100;
using CFFICreateCJWindowStage = int64_t (*)(std::shared_ptr<Rosen::WindowScene>&);
sptr<Rosen::CJWindowStageImpl> CreateCJWindowStage(std::shared_ptr<Rosen::WindowScene> windowScene)
@@ -150,6 +153,13 @@ void CJUIAbility::OnStart(const Want &want, sptr<AAFwk::SessionInfo> sessionInfo
TAG_LOGE(AAFwkTag::UIABILITY, "null cJAbility");
return;
}
auto applicationContext = AbilityRuntime::Context::GetApplicationContext();
if (applicationContext != nullptr) {
auto appContext = ApplicationContextCJ::CJApplicationContext::GetCJApplicationContext(applicationContext);
if (appContext != nullptr) {
appContext->DispatchOnAbilityWillCreate(cjAbilityObj_->GetId());
}
}
std::string methodName = "OnStart";
AddLifecycleEventBeforeCall(FreezeUtil::TimeoutState::FOREGROUND, methodName);
cjAbilityObj_->OnStart(want, GetLaunchParam());
@@ -160,6 +170,13 @@ void CJUIAbility::OnStart(const Want &want, sptr<AAFwk::SessionInfo> sessionInfo
TAG_LOGD(AAFwkTag::UIABILITY, "call PostPerformStart");
delegator->PostPerformStart(CreateADelegatorAbilityProperty());
}
applicationContext = AbilityRuntime::Context::GetApplicationContext();
if (applicationContext != nullptr) {
auto appContext = ApplicationContextCJ::CJApplicationContext::GetCJApplicationContext(applicationContext);
if (appContext != nullptr) {
appContext->DispatchOnAbilityCreate(cjAbilityObj_->GetId());
}
}
}
void CJUIAbility::AddLifecycleEventBeforeCall(FreezeUtil::TimeoutState state, const std::string &methodName) const
@@ -195,6 +212,13 @@ void CJUIAbility::OnStop()
TAG_LOGE(AAFwkTag::UIABILITY, "null cjAbilityObj");
return;
}
auto applicationContext = AbilityRuntime::Context::GetApplicationContext();
if (applicationContext != nullptr) {
auto appContext = ApplicationContextCJ::CJApplicationContext::GetCJApplicationContext(applicationContext);
if (appContext != nullptr) {
appContext->DispatchOnAbilityWillDestroy(cjAbilityObj_->GetId());
}
}
cjAbilityObj_->OnStop();
CJUIAbility::OnStopCallback();
TAG_LOGD(AAFwkTag::UIABILITY, "end");
@@ -216,6 +240,13 @@ void CJUIAbility::OnStop(AppExecFwk::AbilityTransactionCallbackInfo<> *callbackI
}
UIAbility::OnStop();
auto applicationContext = AbilityRuntime::Context::GetApplicationContext();
if (applicationContext != nullptr) {
auto appContext = ApplicationContextCJ::CJApplicationContext::GetCJApplicationContext(applicationContext);
if (appContext != nullptr) {
appContext->DispatchOnAbilityWillDestroy(cjAbilityObj_->GetId());
}
}
cjAbilityObj_->OnStop();
OnStopCallback();
TAG_LOGD(AAFwkTag::UIABILITY, "end");
@@ -234,6 +265,15 @@ void CJUIAbility::OnStopCallback()
TAG_LOGE(AAFwkTag::UIABILITY, "the service connection is disconnected");
}
ConnectionManager::GetInstance().ReportConnectionLeakEvent(getpid(), gettid());
auto applicationContext = AbilityRuntime::Context::GetApplicationContext();
if (applicationContext == nullptr) {
TAG_LOGE(AAFwkTag::UIABILITY, "null application context");
return;
}
auto appContext = ApplicationContextCJ::CJApplicationContext::GetCJApplicationContext(applicationContext);
if (appContext != nullptr) {
appContext->DispatchOnAbilityDestroy(cjAbilityObj_->GetId());
}
TAG_LOGD(AAFwkTag::UIABILITY, "end");
}
@@ -254,7 +294,14 @@ void CJUIAbility::OnSceneCreated()
TAG_LOGE(AAFwkTag::UIABILITY, "create CJWindowStage object failed");
return;
}
auto applicationContext = AbilityRuntime::Context::GetApplicationContext();
if (applicationContext != nullptr) {
auto appContext = ApplicationContextCJ::CJApplicationContext::GetCJApplicationContext(applicationContext);
if (appContext != nullptr) {
WindowStagePtr windowStage = reinterpret_cast<WindowStagePtr>(cjWindowStage_.GetRefPtr());
appContext->DispatchOnWindowStageWillCreate(cjAbilityObj_->GetId(), windowStage);
}
}
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, "onWindowStageCreate");
std::string methodName = "OnSceneCreated";
@@ -268,7 +315,14 @@ void CJUIAbility::OnSceneCreated()
TAG_LOGD(AAFwkTag::UIABILITY, "call PostPerformScenceCreated");
delegator->PostPerformScenceCreated(CreateADelegatorAbilityProperty());
}
applicationContext = AbilityRuntime::Context::GetApplicationContext();
if (applicationContext != nullptr) {
auto appContext = ApplicationContextCJ::CJApplicationContext::GetCJApplicationContext(applicationContext);
if (appContext != nullptr) {
WindowStagePtr windowStage = reinterpret_cast<WindowStagePtr>(cjWindowStage_.GetRefPtr());
appContext->DispatchOnWindowStageCreate(cjAbilityObj_->GetId(), windowStage);
}
}
TAG_LOGD(AAFwkTag::UIABILITY, "end");
}
@@ -289,7 +343,23 @@ void CJUIAbility::OnSceneRestored()
return;
}
}
auto applicationContext = AbilityRuntime::Context::GetApplicationContext();
if (applicationContext != nullptr) {
auto appContext = ApplicationContextCJ::CJApplicationContext::GetCJApplicationContext(applicationContext);
if (appContext != nullptr) {
WindowStagePtr windowStage = reinterpret_cast<WindowStagePtr>(cjWindowStage_.GetRefPtr());
appContext->DispatchOnWindowStageWillRestore(cjAbilityObj_->GetId(), windowStage);
}
}
cjAbilityObj_->OnSceneRestored(cjWindowStage_.GetRefPtr());
applicationContext = AbilityRuntime::Context::GetApplicationContext();
if (applicationContext != nullptr) {
auto appContext = ApplicationContextCJ::CJApplicationContext::GetCJApplicationContext(applicationContext);
if (appContext != nullptr) {
WindowStagePtr windowStage = reinterpret_cast<WindowStagePtr>(cjWindowStage_.GetRefPtr());
appContext->DispatchOnWindowStageRestore(cjAbilityObj_->GetId(), windowStage);
}
}
auto delegator = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator();
if (delegator) {
@@ -298,7 +368,21 @@ void CJUIAbility::OnSceneRestored()
}
}
void CJUIAbility::OnSceneDestroyed()
void CJUIAbility::OnSceneWillDestroy()
{
TAG_LOGD(AAFwkTag::UIABILITY, "ability: %{public}s", GetAbilityName().c_str());
if (!cjAbilityObj_) {
TAG_LOGE(AAFwkTag::UIABILITY, "null cjAbilityObj");
return;
}
if (!cjWindowStage_) {
TAG_LOGE(AAFwkTag::UIABILITY, "null CJWindowStage object");
return;
}
cjAbilityObj_->OnSceneWillDestroy(cjWindowStage_.GetRefPtr());
}
void CJUIAbility::onSceneDestroyed()
{
TAG_LOGD(AAFwkTag::UIABILITY, "ability is %{public}s", GetAbilityName().c_str());
UIAbility::onSceneDestroyed();
@@ -307,6 +391,14 @@ void CJUIAbility::OnSceneDestroyed()
TAG_LOGE(AAFwkTag::UIABILITY, "null cjAbilityObj");
return;
}
auto applicationContext = AbilityRuntime::Context::GetApplicationContext();
if (applicationContext != nullptr) {
auto appContext = ApplicationContextCJ::CJApplicationContext::GetCJApplicationContext(applicationContext);
if (appContext != nullptr) {
WindowStagePtr windowStage = reinterpret_cast<WindowStagePtr>(cjWindowStage_.GetRefPtr());
appContext->DispatchOnWindowStageWillDestroy(cjAbilityObj_->GetId(), windowStage);
}
}
cjAbilityObj_->OnSceneDestroyed();
if (scene_ != nullptr) {
@@ -322,6 +414,14 @@ void CJUIAbility::OnSceneDestroyed()
TAG_LOGD(AAFwkTag::UIABILITY, "call PostPerformScenceDestroyed");
delegator->PostPerformScenceDestroyed(CreateADelegatorAbilityProperty());
}
applicationContext = AbilityRuntime::Context::GetApplicationContext();
if (applicationContext != nullptr) {
auto appContext = ApplicationContextCJ::CJApplicationContext::GetCJApplicationContext(applicationContext);
if (appContext != nullptr) {
WindowStagePtr windowStage = reinterpret_cast<WindowStagePtr>(cjWindowStage_.GetRefPtr());
appContext->DispatchOnWindowStageDestroy(cjAbilityObj_->GetId(), windowStage);
}
}
TAG_LOGD(AAFwkTag::UIABILITY, "end");
}
@@ -340,6 +440,13 @@ void CJUIAbility::CallOnForegroundFunc(const Want &want)
TAG_LOGE(AAFwkTag::UIABILITY, "null cjAbilityObj");
return;
}
auto applicationContext = AbilityRuntime::Context::GetApplicationContext();
if (applicationContext != nullptr) {
auto appContext = ApplicationContextCJ::CJApplicationContext::GetCJApplicationContext(applicationContext);
if (appContext != nullptr) {
appContext->DispatchOnAbilityWillForeground(cjAbilityObj_->GetId());
}
}
std::string methodName = "OnForeground";
AddLifecycleEventBeforeCall(FreezeUtil::TimeoutState::FOREGROUND, methodName);
cjAbilityObj_->OnForeground(want);
@@ -350,7 +457,13 @@ void CJUIAbility::CallOnForegroundFunc(const Want &want)
TAG_LOGD(AAFwkTag::UIABILITY, "call PostPerformForeground");
delegator->PostPerformForeground(CreateADelegatorAbilityProperty());
}
applicationContext = AbilityRuntime::Context::GetApplicationContext();
if (applicationContext != nullptr) {
auto appContext = ApplicationContextCJ::CJApplicationContext::GetCJApplicationContext(applicationContext);
if (appContext != nullptr) {
appContext->DispatchOnAbilityForeground(cjAbilityObj_->GetId());
}
}
TAG_LOGD(AAFwkTag::UIABILITY, "end");
}
@@ -358,6 +471,13 @@ void CJUIAbility::OnBackground()
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
TAG_LOGD(AAFwkTag::UIABILITY, "ability: %{public}s", GetAbilityName().c_str());
auto applicationContext = AbilityRuntime::Context::GetApplicationContext();
if (applicationContext != nullptr) {
auto appContext = ApplicationContextCJ::CJApplicationContext::GetCJApplicationContext(applicationContext);
if (appContext != nullptr && cjAbilityObj_) {
appContext->DispatchOnAbilityWillBackground(cjAbilityObj_->GetId());
}
}
UIAbility::OnBackground();
@@ -376,15 +496,49 @@ void CJUIAbility::OnBackground()
delegator->PostPerformBackground(CreateADelegatorAbilityProperty());
}
applicationContext = AbilityRuntime::Context::GetApplicationContext();
if (applicationContext != nullptr) {
auto appContext = ApplicationContextCJ::CJApplicationContext::GetCJApplicationContext(applicationContext);
if (appContext != nullptr) {
appContext->DispatchOnAbilityBackground(cjAbilityObj_->GetId());
}
}
TAG_LOGD(AAFwkTag::UIABILITY, "end");
}
void CJUIAbility::OnAfterFocusedCommon(bool isFocused)
{
if (!cjAbilityObj_) {
TAG_LOGE(AAFwkTag::UIABILITY, "null cjAbilityObj");
return;
}
auto applicationContext = AbilityRuntime::Context::GetApplicationContext();
if (applicationContext != nullptr) {
auto appContext = ApplicationContextCJ::CJApplicationContext::GetCJApplicationContext(applicationContext);
if (appContext != nullptr && !(appContext->IsAbilityLifecycleCallbackEmpty())) {
WindowStagePtr windowStage = reinterpret_cast<WindowStagePtr>(cjWindowStage_.GetRefPtr());
if (isFocused) {
appContext->DispatchWindowStageFocus(cjAbilityObj_->GetId(), windowStage);
} else {
appContext->DispatchWindowStageUnfocus(cjAbilityObj_->GetId(), windowStage);
}
}
}
}
bool CJUIAbility::OnBackPress()
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
TAG_LOGD(AAFwkTag::UIABILITY, "ability: %{public}s", GetAbilityName().c_str());
UIAbility::OnBackPress();
return true;
bool defaultRet = BackPressDefaultValue();
if (!cjAbilityObj_) {
TAG_LOGE(AAFwkTag::UIABILITY, "null cjAbilityObj");
return defaultRet;
}
bool ret = cjAbilityObj_->OnBackPress(defaultRet);
TAG_LOGD(AAFwkTag::UIABILITY, "end ret: %{public}d", ret);
return ret;
}
bool CJUIAbility::OnPrepareTerminate()
@@ -649,14 +803,41 @@ int32_t CJUIAbility::OnContinue(WantParams &wantParams)
TAG_LOGE(AAFwkTag::UIABILITY, "null cjAbilityObj_");
return AppExecFwk::ContinuationManagerStage::OnContinueResult::REJECT;
}
auto applicationContext = AbilityRuntime::Context::GetApplicationContext();
if (applicationContext != nullptr) {
auto appContext = ApplicationContextCJ::CJApplicationContext::GetCJApplicationContext(applicationContext);
if (appContext != nullptr) {
appContext->DispatchOnAbilityWillContinue(cjAbilityObj_->GetId());
}
}
auto res = cjAbilityObj_->OnContinue(wantParams);
TAG_LOGD(AAFwkTag::UIABILITY, "end, value: %{public}d", res);
applicationContext = AbilityRuntime::Context::GetApplicationContext();
if (applicationContext != nullptr) {
auto appContext = ApplicationContextCJ::CJApplicationContext::GetCJApplicationContext(applicationContext);
if (appContext != nullptr) {
appContext->DispatchOnAbilityContinue(cjAbilityObj_->GetId());
}
}
return res;
}
int32_t CJUIAbility::OnSaveState(int32_t reason, WantParams &wantParams)
{
auto applicationContext = AbilityRuntime::Context::GetApplicationContext();
if (applicationContext != nullptr) {
auto appContext = ApplicationContextCJ::CJApplicationContext::GetCJApplicationContext(applicationContext);
if (appContext != nullptr) {
appContext->DispatchOnAbilityWillSaveState(cjAbilityObj_->GetId());
}
}
applicationContext = AbilityRuntime::Context::GetApplicationContext();
if (applicationContext != nullptr) {
auto appContext = ApplicationContextCJ::CJApplicationContext::GetCJApplicationContext(applicationContext);
if (appContext != nullptr) {
appContext->DispatchOnAbilitySaveState(cjAbilityObj_->GetId());
}
}
return 0;
}
@@ -706,11 +887,24 @@ void CJUIAbility::OnNewWant(const Want &want)
TAG_LOGE(AAFwkTag::UIABILITY, "null cjAbilityObj_");
return;
}
auto applicationContext = AbilityRuntime::Context::GetApplicationContext();
if (applicationContext != nullptr) {
auto appContext = ApplicationContextCJ::CJApplicationContext::GetCJApplicationContext(applicationContext);
if (appContext != nullptr && cjAbilityObj_) {
appContext->DispatchOnWillNewWant(cjAbilityObj_->GetId());
}
}
std::string methodName = "OnNewWant";
AddLifecycleEventBeforeCall(FreezeUtil::TimeoutState::FOREGROUND, methodName);
cjAbilityObj_->OnNewWant(want, GetLaunchParam());
AddLifecycleEventAfterCall(FreezeUtil::TimeoutState::FOREGROUND, methodName);
applicationContext = AbilityRuntime::Context::GetApplicationContext();
if (applicationContext != nullptr) {
auto appContext = ApplicationContextCJ::CJApplicationContext::GetCJApplicationContext(applicationContext);
if (appContext != nullptr && cjAbilityObj_) {
appContext->DispatchOnNewWant(cjAbilityObj_->GetId());
}
}
TAG_LOGD(AAFwkTag::UIABILITY, "end");
}
@@ -775,5 +969,21 @@ std::shared_ptr<CJAbilityObject> CJUIAbility::GetCJAbility()
}
return cjAbilityObj_;
}
bool CJUIAbility::CheckSatisfyTargetAPIVersion(int32_t version)
{
auto applicationInfo = GetApplicationInfo();
if (!applicationInfo) {
TAG_LOGE(AAFwkTag::UIABILITY, "null targetAPIVersion");
return false;
}
TAG_LOGD(AAFwkTag::UIABILITY, "targetAPIVersion: %{public}d", applicationInfo->apiTargetVersion);
return applicationInfo->apiTargetVersion % API_VERSION_MOD >= version;
}
bool CJUIAbility::BackPressDefaultValue()
{
return CheckSatisfyTargetAPIVersion(API12) ? true : false;
}
} // namespace AbilityRuntime
} // namespace OHOS
@@ -218,7 +218,8 @@ void JsUIAbility::SetAbilityContext(std::shared_ptr<AbilityInfo> abilityInfo,
HandleScope handleScope(jsRuntime_);
auto env = jsRuntime_.GetNapiEnv();
jsAbilityObj_ = jsRuntime_.LoadModule(
moduleName, srcPath, abilityInfo->hapPath, abilityInfo->compileMode == AppExecFwk::CompileMode::ES_MODULE);
moduleName, srcPath, abilityInfo->hapPath, abilityInfo->compileMode == AppExecFwk::CompileMode::ES_MODULE,
false, abilityInfo->srcEntrance);
if (jsAbilityObj_ == nullptr || abilityContext_ == nullptr || want == nullptr) {
TAG_LOGE(AAFwkTag::UIABILITY, "null jsAbilityObj_ or abilityContext_ or want");
return;
@@ -88,10 +88,11 @@ void AbilityThread::AbilityThreadMain(const std::shared_ptr<OHOSApplication> &ap
TAG_LOGD(AAFwkTag::ABILITY, "end");
}
void AbilityThread::ScheduleAbilityTransaction(
bool AbilityThread::ScheduleAbilityTransaction(
const Want &want, const LifeCycleStateInfo &targetState, sptr<SessionInfo> sessionInfo)
{
TAG_LOGD(AAFwkTag::ABILITY, "called");
return true;
}
void AbilityThread::ScheduleShareData(const int32_t &requestCode)
@@ -357,7 +357,7 @@ std::unique_ptr<AbilityRuntime::Runtime> ChildProcessManager::CreateRuntime(cons
options.loadAce = true;
options.jitEnabled = jitEnabled;
for (auto moduleItem : bundleInfo.hapModuleInfos) {
for (auto &moduleItem : bundleInfo.hapModuleInfos) {
options.pkgContextInfoJsonStringMap[moduleItem.moduleName] = moduleItem.hapPath;
options.packageNameList[moduleItem.moduleName] = moduleItem.packageName;
}
@@ -82,7 +82,7 @@ void DataAbilityHelperImpl::AddDataAbilityDeathRecipient(const sptr<IRemoteObjec
if (callerDeathRecipient_ == nullptr) {
std::weak_ptr<DataAbilityHelperImpl> thisWeakPtr(shared_from_this());
callerDeathRecipient_ =
new DataAbilityDeathRecipient([thisWeakPtr](const wptr<IRemoteObject> &remote) {
new (std::nothrow) DataAbilityDeathRecipient([thisWeakPtr](const wptr<IRemoteObject> &remote) {
auto DataAbilityHelperImpl = thisWeakPtr.lock();
if (DataAbilityHelperImpl) {
DataAbilityHelperImpl->OnSchedulerDied(remote);
@@ -105,13 +105,6 @@ void DataAbilityHelperImpl::OnSchedulerDied(const wptr<IRemoteObject> &remote)
uri_ = nullptr;
}
/**
* @brief Creates a DataAbilityHelperImpl instance without specifying the Uri based on the given Context.
*
* @param context Indicates the Context object on OHOS.
*
* @return Returns the created DataAbilityHelperImpl instance where Uri is not specified.
*/
std::shared_ptr<DataAbilityHelperImpl> DataAbilityHelperImpl::Creator(const std::shared_ptr<Context> &context)
{
if (context == nullptr) {
@@ -374,6 +374,68 @@
"UIAbilityContext",
"nfctech",
"tagSession"
],
"FenceExtension": [
"ability.featureAbility",
"ability.particleAbility",
"accessibility.config",
"account.appAccount",
"account.distributedAccount",
"account.osAccount",
"app.ability.quickFixManager",
"app.form.formHost",
"application.formError",
"application.formHost",
"backgroundTaskManager",
"bundle.bundleMonitor",
"bundle.distributedBundleManager",
"bundle.freeInstall",
"bundle.innerBundleManager",
"bundle.installer",
"bundle.launcherBundleManager",
"connectedTag",
"contact",
"continuation.continuationManager",
"data.distributedData",
"data.distributedDataObject",
"data.distributedKVStore",
"distributedBundle",
"distributedMissionManager",
"enterprise.adminManager",
"enterprise.dataTimeManager",
"enterprise.deviceInfo",
"filemanagement.userFileManager",
"hidebug",
"multimedia.audio",
"multimedia.avsession",
"multimedia.camera",
"multimedia.media",
"nfc.cardEmulation",
"nfc.controller",
"nfc.tag",
"privacyManager",
"reminderAgent",
"reminderAgentManager",
"request",
"resourceschedule.backgroundTaskManager",
"resourceschedule.usageStatistics",
"telephony.call",
"telephony.data",
"telephony.observer",
"telephony.radio",
"telephony.sim",
"telephony.sms",
"update",
"userIAM.faceAuth",
"userIAM.userAuth",
"vibrator",
"wallpaper",
"window",
"Context",
"ServiceExtensionContext",
"UIAbilityContext",
"nfctech",
"tagSession"
]
}
}
@@ -50,6 +50,7 @@ constexpr static char FILEACCESS_EXT_ABILITY[] = "FileAccessExtension";
constexpr static char ENTERPRISE_ADMIN_EXTENSION[] = "EnterpriseAdminExtension";
constexpr static char INPUTMETHOD_EXTENSION[] = "InputMethodExtensionAbility";
constexpr static char APP_ACCOUNT_AUTHORIZATION_EXTENSION[] = "AppAccountAuthorizationExtension";
constexpr static char FENCE_EXTENSION[] = "FenceExtension";
}
const std::map<AppExecFwk::ExtensionAbilityType, std::string> UI_EXTENSION_NAME_MAP = {
@@ -152,6 +153,9 @@ void ExtensionAbilityThread::CreateExtensionAbilityName(
if (abilityInfo->extensionAbilityType == AppExecFwk::ExtensionAbilityType::APP_ACCOUNT_AUTHORIZATION) {
abilityName = APP_ACCOUNT_AUTHORIZATION_EXTENSION;
}
if (abilityInfo->extensionAbilityType == AppExecFwk::ExtensionAbilityType::FENCE) {
abilityName = FENCE_EXTENSION;
}
#ifdef SUPPORT_GRAPHICS
if (abilityInfo->extensionAbilityType == AppExecFwk::ExtensionAbilityType::SYSDIALOG_USERAUTH) {
abilityName = USER_AUTH_EXTENSION;
@@ -369,7 +373,7 @@ void ExtensionAbilityThread::HandleExtensionUpdateConfiguration(const AppExecFwk
TAG_LOGD(AAFwkTag::EXT, "End");
}
void ExtensionAbilityThread::ScheduleAbilityTransaction(
bool ExtensionAbilityThread::ScheduleAbilityTransaction(
const Want &want, const LifeCycleStateInfo &lifeCycleStateInfo, sptr<AAFwk::SessionInfo> sessionInfo)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
@@ -377,11 +381,11 @@ void ExtensionAbilityThread::ScheduleAbilityTransaction(
want.GetElement().GetAbilityName().c_str(), lifeCycleStateInfo.state, lifeCycleStateInfo.isNewWant);
if (token_ == nullptr) {
TAG_LOGE(AAFwkTag::EXT, "null token_");
return;
return false;
}
if (abilityHandler_ == nullptr) {
TAG_LOGE(AAFwkTag::EXT, "null abilityHandler_");
return;
return false;
}
wptr<ExtensionAbilityThread> weak = this;
auto task = [weak, want, lifeCycleStateInfo, sessionInfo]() {
@@ -395,7 +399,9 @@ void ExtensionAbilityThread::ScheduleAbilityTransaction(
bool ret = abilityHandler_->PostTask(task, AppExecFwk::EventQueue::Priority::HIGH);
if (!ret) {
TAG_LOGE(AAFwkTag::EXT, "PostTask error");
return false;
}
return true;
}
void ExtensionAbilityThread::ScheduleConnectAbility(const Want &want)
@@ -710,7 +710,7 @@ void FAAbilityThread::HandleExtensionUpdateConfiguration(const AppExecFwk::Confi
extensionImpl_->ScheduleUpdateConfiguration(config);
}
void FAAbilityThread::ScheduleAbilityTransaction(
bool FAAbilityThread::ScheduleAbilityTransaction(
const Want &want, const LifeCycleStateInfo &lifeCycleStateInfo, sptr<AAFwk::SessionInfo> sessionInfo)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
@@ -723,11 +723,11 @@ void FAAbilityThread::ScheduleAbilityTransaction(
if (token_ == nullptr) {
TAG_LOGE(AAFwkTag::FA, "null token_");
return;
return false;
}
if (abilityHandler_ == nullptr) {
TAG_LOGE(AAFwkTag::FA, "null abilityHandler_");
return;
return false;
}
wptr<FAAbilityThread> weak = this;
auto task = [weak, want, lifeCycleStateInfo, sessionInfo]() {
@@ -747,7 +747,9 @@ void FAAbilityThread::ScheduleAbilityTransaction(
bool ret = abilityHandler_->PostTask(task, "FAAbilityThread:AbilityTransaction");
if (!ret) {
TAG_LOGE(AAFwkTag::FA, "PostTask error");
return false;
}
return true;
}
void FAAbilityThread::ScheduleShareData(const int32_t &uniqueId)
@@ -70,8 +70,15 @@ void JsFreeInstallObserver::OnInstallFinished(const std::string &bundleName, con
const std::string &startTime, napi_value abilityResult)
{
TAG_LOGD(AAFwkTag::FREE_INSTALL, "call");
for (auto it = jsObserverObjectList_.begin(); it != jsObserverObjectList_.end();) {
if ((it->bundleName == bundleName) && (it->abilityName == abilityName) && (it->startTime == startTime)) {
std::vector<napi_deferred> promises;
std::vector<napi_ref> callbacks;
{
std::unique_lock<std::mutex> lock(jsObserverObjectListLock_);
for (auto it = jsObserverObjectList_.begin(); it != jsObserverObjectList_.end();) {
if ((it->bundleName != bundleName) || (it->abilityName != abilityName) || (it->startTime != startTime)) {
it++;
continue;
}
if (it->callback == nullptr && it->deferred == nullptr) {
it++;
continue;
@@ -81,44 +88,63 @@ void JsFreeInstallObserver::OnInstallFinished(const std::string &bundleName, con
continue;
}
if (it->deferred != nullptr) {
CallPromise(it->deferred, abilityResult);
promises.emplace_back(it->deferred);
} else {
CallCallback(it->callback, abilityResult);
callbacks.emplace_back(it->callback);
}
FinishAsyncTrace(HITRACE_TAG_ABILITY_MANAGER, "StartFreeInstall", atoi(startTime.c_str()));
it = jsObserverObjectList_.erase(it);
TAG_LOGD(AAFwkTag::FREE_INSTALL,
"jsObserverObjectList_ size:%{public}zu", jsObserverObjectList_.size());
} else {
it++;
}
}
for (const napi_deferred& promise : promises) {
CallPromise(promise, abilityResult);
FinishAsyncTrace(HITRACE_TAG_ABILITY_MANAGER, "StartFreeInstall", atoi(startTime.c_str()));
}
for (const napi_ref& callback : callbacks) {
CallCallback(callback, abilityResult);
FinishAsyncTrace(HITRACE_TAG_ABILITY_MANAGER, "StartFreeInstall", atoi(startTime.c_str()));
}
}
void JsFreeInstallObserver::HandleOnInstallFinished(const std::string &bundleName, const std::string &abilityName,
const std::string &startTime, const int &resultCode)
{
TAG_LOGD(AAFwkTag::FREE_INSTALL, "call");
for (auto it = jsObserverObjectList_.begin(); it != jsObserverObjectList_.end();) {
if ((it->bundleName != bundleName) || (it->abilityName != abilityName) || (it->startTime != startTime)) {
it++;
continue;
}
if (it->callback == nullptr && it->deferred == nullptr) {
it++;
continue;
}
if (it->isAbilityResult && resultCode == ERR_OK) {
it++;
continue;
}
if (it->deferred != nullptr) {
CallPromise(it->deferred, resultCode);
} else {
CallCallback(it->callback, resultCode);
std::vector<napi_deferred> promises;
std::vector<napi_ref> callbacks;
{
std::unique_lock<std::mutex> lock(jsObserverObjectListLock_);
for (auto it = jsObserverObjectList_.begin(); it != jsObserverObjectList_.end();) {
if ((it->bundleName != bundleName) || (it->abilityName != abilityName) || (it->startTime != startTime)) {
it++;
continue;
}
if (it->callback == nullptr && it->deferred == nullptr) {
it++;
continue;
}
if (it->isAbilityResult && resultCode == ERR_OK) {
it++;
continue;
}
if (it->deferred != nullptr) {
promises.emplace_back(it->deferred);
} else {
callbacks.emplace_back(it->callback);
}
it = jsObserverObjectList_.erase(it);
}
}
for (const napi_deferred& promise : promises) {
CallPromise(promise, resultCode);
FinishAsyncTrace(HITRACE_TAG_ABILITY_MANAGER, "StartFreeInstall", atoi(startTime.c_str()));
}
for (const napi_ref& callback : callbacks) {
CallCallback(callback, resultCode);
FinishAsyncTrace(HITRACE_TAG_ABILITY_MANAGER, "StartFreeInstall", atoi(startTime.c_str()));
it = jsObserverObjectList_.erase(it);
}
}
@@ -126,26 +152,39 @@ void JsFreeInstallObserver::HandleOnInstallFinishedByUrl(const std::string &star
const int &resultCode)
{
TAG_LOGD(AAFwkTag::FREE_INSTALL, "call");
for (auto it = jsObserverObjectList_.begin(); it != jsObserverObjectList_.end();) {
if ((it->startTime != startTime) || (it->url != url)) {
it++;
continue;
}
if (it->callback == nullptr && it->deferred == nullptr) {
it++;
continue;
}
if (it->isAbilityResult && resultCode == ERR_OK) {
it++;
continue;
}
if (it->deferred != nullptr) {
CallPromise(it->deferred, resultCode);
} else {
CallCallback(it->callback, resultCode);
std::vector<napi_deferred> promises;
std::vector<napi_ref> callbacks;
{
std::unique_lock<std::mutex> lock(jsObserverObjectListLock_);
for (auto it = jsObserverObjectList_.begin(); it != jsObserverObjectList_.end();) {
if ((it->startTime != startTime) || (it->url != url)) {
it++;
continue;
}
if (it->callback == nullptr && it->deferred == nullptr) {
it++;
continue;
}
if (it->isAbilityResult && resultCode == ERR_OK) {
it++;
continue;
}
if (it->deferred != nullptr) {
promises.emplace_back(it->deferred);
} else {
callbacks.emplace_back(it->callback);
}
it = jsObserverObjectList_.erase(it);
}
}
for (const napi_deferred& promise : promises) {
CallPromise(promise, resultCode);
FinishAsyncTrace(HITRACE_TAG_ABILITY_MANAGER, "StartFreeInstall", atoi(startTime.c_str()));
}
for (const napi_ref& callback : callbacks) {
CallCallback(callback, resultCode);
FinishAsyncTrace(HITRACE_TAG_ABILITY_MANAGER, "StartFreeInstall", atoi(startTime.c_str()));
it = jsObserverObjectList_.erase(it);
}
}
@@ -212,11 +251,14 @@ void JsFreeInstallObserver::AddJsObserverObject(const std::string &bundleName, c
const std::string &startTime, napi_value jsObserverObject, napi_value* result, bool isAbilityResult)
{
TAG_LOGD(AAFwkTag::FREE_INSTALL, "call");
for (auto it = jsObserverObjectList_.begin(); it != jsObserverObjectList_.end(); ++it) {
if (it->bundleName == bundleName && it->abilityName == abilityName &&
it->startTime == startTime) {
TAG_LOGW(AAFwkTag::FREE_INSTALL, "The jsObject has been added");
return;
{
std::unique_lock<std::mutex> lock(jsObserverObjectListLock_);
for (auto it = jsObserverObjectList_.begin(); it != jsObserverObjectList_.end(); ++it) {
if (it->bundleName == bundleName && it->abilityName == abilityName &&
it->startTime == startTime) {
TAG_LOGW(AAFwkTag::FREE_INSTALL, "The jsObject has been added");
return;
}
}
}
@@ -232,10 +274,13 @@ void JsFreeInstallObserver::AddJsObserverObject(const std::string &startTime, co
napi_value jsObserverObject, napi_value* result, bool isAbilityResult)
{
TAG_LOGD(AAFwkTag::FREE_INSTALL, "call");
for (auto it = jsObserverObjectList_.begin(); it != jsObserverObjectList_.end(); ++it) {
if (it->startTime == startTime && it->url == url) {
TAG_LOGW(AAFwkTag::FREE_INSTALL, "The jsObject has been added");
return;
{
std::unique_lock<std::mutex> lock(jsObserverObjectListLock_);
for (auto it = jsObserverObjectList_.begin(); it != jsObserverObjectList_.end(); ++it) {
if (it->startTime == startTime && it->url == url) {
TAG_LOGW(AAFwkTag::FREE_INSTALL, "The jsObject has been added");
return;
}
}
}
@@ -265,6 +310,7 @@ void JsFreeInstallObserver::AddJsObserverCommon(JsFreeInstallObserverObject &obj
object.deferred = nullptr;
object.callback = ref;
}
std::unique_lock<std::mutex> lock(jsObserverObjectListLock_);
jsObserverObjectList_.emplace_back(object);
}
} // namespace AbilityRuntime
@@ -666,6 +666,12 @@ void UIAbility::OnBackground()
AAFwk::EventReport::SendAbilityEvent(AAFwk::EventName::ABILITY_ONBACKGROUND, HiSysEventType::BEHAVIOR, eventInfo);
}
void UIAbility::OnAfterFocusedCommon(bool isFocused)
{
TAG_LOGD(AAFwkTag::UIABILITY, "called");
return;
}
bool UIAbility::OnPrepareTerminate()
{
TAG_LOGI(AAFwkTag::UIABILITY, "called");
@@ -104,7 +104,7 @@ void UIAbilityImpl::Stop(bool &isAsyncCallback)
isAsyncCallback = false;
return;
}
std::weak_ptr<UIAbilityImpl> weakPtr = shared_from_this();
std::weak_ptr<UIAbilityImpl> weakPtr = weak_from_this();
auto asyncCallback = [abilityImplWeakPtr = weakPtr, state = AAFwk::ABILITY_STATE_INITIAL]() {
auto abilityImpl = abilityImplWeakPtr.lock();
if (abilityImpl == nullptr) {
@@ -400,6 +400,7 @@ void UIAbilityImpl::AfterFocusedCommon(bool isFocused)
TAG_LOGE(AAFwkTag::UIABILITY, "null abilityContext");
return;
}
impl->ability_->OnAfterFocusedCommon(focuseMode);
auto applicationContext = abilityContext->GetApplicationContext();
if (applicationContext == nullptr || applicationContext->IsAbilityLifecycleCallbackEmpty()) {
TAG_LOGE(AAFwkTag::UIABILITY, "null applicationContext or lifecycleCallback");
@@ -306,7 +306,7 @@ void UIAbilityThread::HandleUpdateConfiguration(const AppExecFwk::Configuration
abilityImpl_->ScheduleUpdateConfiguration(config);
}
void UIAbilityThread::ScheduleAbilityTransaction(
bool UIAbilityThread::ScheduleAbilityTransaction(
const Want &want, const LifeCycleStateInfo &lifeCycleStateInfo, sptr<AAFwk::SessionInfo> sessionInfo)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
@@ -319,11 +319,11 @@ void UIAbilityThread::ScheduleAbilityTransaction(
if (token_ == nullptr) {
TAG_LOGE(AAFwkTag::UIABILITY, "null token_");
return;
return false;
}
if (abilityHandler_ == nullptr) {
TAG_LOGE(AAFwkTag::UIABILITY, "null abilityHandler_");
return;
return false;
}
wptr<UIAbilityThread> weak = this;
auto task = [weak, want, lifeCycleStateInfo, sessionInfo]() {
@@ -338,7 +338,9 @@ void UIAbilityThread::ScheduleAbilityTransaction(
bool ret = abilityHandler_->PostTask(task, "UIAbilityThread:AbilityTransaction");
if (!ret) {
TAG_LOGE(AAFwkTag::UIABILITY, "postTask error");
return false;
}
return true;
}
void UIAbilityThread::ScheduleShareData(const int32_t &uniqueId)
+11 -18
View File
@@ -410,7 +410,7 @@ std::shared_ptr<EventHandler> MainThread::GetMainHandler() const
* @brief Schedule the foreground lifecycle of application.
*
*/
void MainThread::ScheduleForegroundApplication()
bool MainThread::ScheduleForegroundApplication()
{
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
TAG_LOGD(AAFwkTag::APPKIT, "called");
@@ -429,10 +429,10 @@ void MainThread::ScheduleForegroundApplication()
auto tmpWatchdog = watchdog_;
if (tmpWatchdog == nullptr) {
TAG_LOGE(AAFwkTag::APPKIT, "Watch dog is nullptr.");
return;
} else {
tmpWatchdog->SetBackgroundStatus(false);
}
tmpWatchdog->SetBackgroundStatus(false);
tmpWatchdog = nullptr;
return true;
}
/**
@@ -800,15 +800,12 @@ void MainThread::ScheduleConfigurationUpdated(const Configuration &config)
bool MainThread::CheckLaunchApplicationParam(const AppLaunchData &appLaunchData) const
{
ApplicationInfo appInfo = appLaunchData.GetApplicationInfo();
ProcessInfo processInfo = appLaunchData.GetProcessInfo();
if (appInfo.name.empty()) {
if (appLaunchData.GetApplicationInfo().name.empty()) {
TAG_LOGE(AAFwkTag::APPKIT, "applicationName is empty");
return false;
}
if (processInfo.GetProcessName().empty()) {
if (appLaunchData.GetProcessInfo().GetProcessName().empty()) {
TAG_LOGE(AAFwkTag::APPKIT, "processName is empty");
return false;
}
@@ -913,7 +910,7 @@ void MainThread::HandleProcessSecurityExit()
TAG_LOGE(AAFwkTag::APPKIT, "application_ is null");
return;
}
std::vector<sptr<IRemoteObject>> tokens = (abilityRecordMgr_->GetAllTokens());
std::vector<sptr<IRemoteObject>> tokens = abilityRecordMgr_->GetAllTokens();
for (auto iter = tokens.begin(); iter != tokens.end(); ++iter) {
HandleCleanAbilityLocal(*iter);
@@ -1049,7 +1046,7 @@ void MainThread::OnStartAbility(const std::string &bundleName,
loadPath = std::regex_replace(loadPath, pattern, std::string(LOCAL_CODE_PATH));
TAG_LOGD(AAFwkTag::APPKIT, "ModuleResPath: %{public}s", loadPath.c_str());
// getOverlayPath
if (overlayModuleInfos_.size() == 0) {
if (overlayModuleInfos_.empty()) {
if (!resourceManager->AddResource(loadPath.c_str())) {
TAG_LOGE(AAFwkTag::APPKIT, "AddResource failed");
}
@@ -1163,7 +1160,7 @@ void MainThread::HandleOnOverlayChanged(const EventFwk::CommonEventData &data,
}
// 2.add/remove overlay hapPath
if (loadPath.empty() || overlayModuleInfos.size() == 0) {
if (loadPath.empty() || overlayModuleInfos.empty()) {
TAG_LOGW(AAFwkTag::APPKIT, "There is not any hapPath in overlayModuleInfo");
} else {
if (isEnable) {
@@ -1191,12 +1188,8 @@ bool IsNeedLoadLibrary(const std::string &bundleName)
"com.ohos.formrenderservice"
};
for (const auto &item : needLoadLibraryBundleNames) {
if (item == bundleName) {
return true;
}
}
return false;
return std::find(needLoadLibraryBundleNames.begin(), needLoadLibraryBundleNames.end(), bundleName)
!= needLoadLibraryBundleNames.end();
}
bool GetBundleForLaunchApplication(std::shared_ptr<BundleMgrHelper> bundleMgrHelper, const std::string &bundleName,
@@ -106,8 +106,7 @@ void ConnectServerManager::StartConnectServer(const std::string& bundleName, int
auto startServerForSocketPair =
reinterpret_cast<StartServerForSocketPair>(dlsym(handlerConnectServerSo_, "StartServerForSocketPair"));
if (startServerForSocketPair == nullptr) {
TAG_LOGE(
AAFwkTag::JSRUNTIME, "null startServerForSocketPair");
TAG_LOGE(AAFwkTag::JSRUNTIME, "null startServerForSocketPair");
return;
}
startServerForSocketPair(socketFd);
+25 -8
View File
@@ -521,10 +521,18 @@ bool JsRuntime::LoadScript(const std::string& path, std::vector<uint8_t>* buffer
return jsEnv_->LoadScript(path, buffer, isBundle);
}
bool JsRuntime::LoadScript(const std::string& path, uint8_t* buffer, size_t len, bool isBundle)
bool JsRuntime::LoadScript(const std::string& path, uint8_t* buffer, size_t len, bool isBundle,
const std::string& srcEntrance)
{
TAG_LOGD(AAFwkTag::JSRUNTIME, "path: %{private}s", path.c_str());
CHECK_POINTER_AND_RETURN(jsEnv_, false);
if (isOhmUrl_ && !moduleName_.empty()) {
auto vm = GetEcmaVm();
CHECK_POINTER_AND_RETURN(vm, false);
std::string srcFilename = "";
srcFilename = BUNDLE_INSTALL_PATH + moduleName_ + MERGE_ABC_PATH;
return panda::JSNApi::ExecuteSecureWithOhmUrl(vm, buffer, len, srcFilename, srcEntrance);
}
return jsEnv_->LoadScript(path, buffer, len, isBundle);
}
@@ -932,17 +940,23 @@ napi_value JsRuntime::LoadJsBundle(const std::string& path, const std::string& h
return exportObj;
}
napi_value JsRuntime::LoadJsModule(const std::string& path, const std::string& hapPath)
napi_value JsRuntime::LoadJsModule(const std::string& path, const std::string& hapPath, const std::string& srcEntrance)
{
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
if (!RunScript(path, hapPath, false)) {
if (!RunScript(path, hapPath, false, srcEntrance)) {
TAG_LOGE(AAFwkTag::JSRUNTIME, "Failed to run script: %{private}s", path.c_str());
return nullptr;
}
auto vm = GetEcmaVm();
CHECK_POINTER_AND_RETURN(vm, nullptr);
panda::Local<panda::ObjectRef> exportObj = panda::JSNApi::GetExportObject(vm, path, "default");
panda::Local<panda::ObjectRef> exportObj;
if (isOhmUrl_) {
exportObj = panda::JSNApi::GetExportObjectFromOhmUrl(vm, srcEntrance, "default");
} else {
exportObj = panda::JSNApi::GetExportObject(vm, path, "default");
}
if (exportObj->IsNull()) {
TAG_LOGE(AAFwkTag::JSRUNTIME, "Get export object failed");
return nullptr;
@@ -954,7 +968,7 @@ napi_value JsRuntime::LoadJsModule(const std::string& path, const std::string& h
}
std::unique_ptr<NativeReference> JsRuntime::LoadModule(const std::string& moduleName, const std::string& modulePath,
const std::string& hapPath, bool esmodule, bool useCommonChunk)
const std::string& hapPath, bool esmodule, bool useCommonChunk, const std::string& srcEntrance)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
TAG_LOGD(AAFwkTag::JSRUNTIME, "Load module(%{public}s, %{private}s, %{private}s, %{public}s)",
@@ -965,6 +979,7 @@ std::unique_ptr<NativeReference> JsRuntime::LoadModule(const std::string& module
panda::JSNApi::NotifyLoadModule(vm);
auto env = GetNapiEnv();
CHECK_POINTER_AND_RETURN(env, std::unique_ptr<NativeReference>());
isOhmUrl_ = panda::JSNApi::IsOhmUrl(srcEntrance);
HandleScope handleScope(*this);
@@ -992,7 +1007,8 @@ std::unique_ptr<NativeReference> JsRuntime::LoadModule(const std::string& module
return std::unique_ptr<NativeReference>();
}
}
classValue = esmodule ? LoadJsModule(fileName, hapPath) : LoadJsBundle(fileName, hapPath, useCommonChunk);
classValue = esmodule ? LoadJsModule(fileName, hapPath, srcEntrance)
: LoadJsBundle(fileName, hapPath, useCommonChunk);
if (classValue == nullptr) {
return std::unique_ptr<NativeReference>();
}
@@ -1043,7 +1059,8 @@ std::unique_ptr<NativeReference> JsRuntime::LoadSystemModule(
return std::unique_ptr<NativeReference>(reinterpret_cast<NativeReference*>(resultRef));
}
bool JsRuntime::RunScript(const std::string& srcPath, const std::string& hapPath, bool useCommonChunk)
bool JsRuntime::RunScript(const std::string& srcPath, const std::string& hapPath, bool useCommonChunk,
const std::string& srcEntrance)
{
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
auto vm = GetEcmaVm();
@@ -1081,7 +1098,7 @@ bool JsRuntime::RunScript(const std::string& srcPath, const std::string& hapPath
TAG_LOGE(AAFwkTag::JSRUNTIME, "Get safeData abc file failed");
return false;
}
return LoadScript(abcPath, safeData->GetDataPtr(), safeData->GetDataLen(), isBundle_);
return LoadScript(abcPath, safeData->GetDataPtr(), safeData->GetDataLen(), isBundle_, srcEntrance);
} else {
std::unique_ptr<uint8_t[]> data;
size_t dataLen = 0;
@@ -35,6 +35,7 @@ const std::unordered_map<std::string, ExtensionAbilityType> EXTENSION_TYPE_MAP =
{ "dataShare", ExtensionAbilityType::DATASHARE },
{ "fileShare", ExtensionAbilityType::FILESHARE },
{ "staticSubscriber", ExtensionAbilityType::STATICSUBSCRIBER },
{ "fence", ExtensionAbilityType::FENCE },
{ "wallpaper", ExtensionAbilityType::WALLPAPER },
{ "backup", ExtensionAbilityType::BACKUP },
{ "window", ExtensionAbilityType::WINDOW },
@@ -56,6 +56,7 @@ enum class ExtensionAbilityType {
PUSH = 17,
DRIVER = 18,
APP_ACCOUNT_AUTHORIZATION = 19,
FENCE = 24,
UNSPECIFIED = 255,
UI = 256,
HMS_ACCOUNT = 257,
@@ -52,7 +52,7 @@ public:
* @param targetState, The lifecycle state to be transformed
* @param sessionInfo, The session info
*/
virtual void ScheduleAbilityTransaction(const Want &want, const LifeCycleStateInfo &targetState,
virtual bool ScheduleAbilityTransaction(const Want &want, const LifeCycleStateInfo &targetState,
sptr<SessionInfo> sessionInfo = nullptr) = 0;
/*
@@ -389,7 +389,7 @@ public:
DUMP_ABILITY_RUNNER_INNER,
SCHEDULE_CALL,
SCHEDULE_SHARE_DATA,
// ipc id for scheduling service ability to prepare terminate (30)
@@ -74,6 +74,11 @@ enum class AbilityLoadState: uint8_t {
LOADED,
FAILED
};
enum class FreezeStrategy : uint8_t {
PRINT_FREEZE_LOG,
NOTIFY_FREEZE_MGR,
};
} // namespace AAFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_ABILITY_STATE_H
@@ -61,6 +61,9 @@ ohos_shared_library("app_manager") {
"src/appmgr/app_debug_info.cpp",
"src/appmgr/app_debug_listener_proxy.cpp",
"src/appmgr/app_debug_listener_stub.cpp",
"src/appmgr/app_exception_callback_proxy.cpp",
"src/appmgr/app_exception_callback_stub.cpp",
"src/appmgr/app_exception_manager.cpp",
"src/appmgr/app_foreground_state_observer_proxy.cpp",
"src/appmgr/app_foreground_state_observer_stub.cpp",
"src/appmgr/app_jsheap_mem_info.cpp",
@@ -443,6 +443,8 @@ public:
return false;
}
virtual void SetAppExceptionCallback(sptr<IRemoteObject> callback) {}
enum class Message {
LOAD_ABILITY = 0,
TERMINATE_ABILITY,
@@ -496,6 +498,7 @@ public:
FORCE_KILL_APPLICATION_BY_ACCESS_TOKEN_ID = 49,
IS_PROCESS_ATTACHED,
IS_APP_KILLING,
SET_APP_EXCEPTION_CALLBACK,
// Add enumeration values above
END
};
@@ -390,6 +390,8 @@ public:
virtual bool IsAppKilling(sptr<IRemoteObject> token) override;
virtual void SetAppExceptionCallback(sptr<IRemoteObject> callback) override;
private:
bool WriteInterfaceToken(MessageParcel &data);
int32_t SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
@@ -102,6 +102,7 @@ private:
int32_t HandleIsProcessContainsOnlyUIAbility(MessageParcel &data, MessageParcel &reply);
int32_t HandleIsProcessAttached(MessageParcel &data, MessageParcel &reply);
int32_t HandleIsAppKilling(MessageParcel &data, MessageParcel &reply);
int32_t HandleSetAppExceptionCallback(MessageParcel &data, MessageParcel &reply);
DISALLOW_COPY_AND_MOVE(AmsMgrStub);
};
} // namespace AppExecFwk
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_ABILITY_RUNTIME_APP_EXCEPTION_CALLBACK_PROXY_H
#define OHOS_ABILITY_RUNTIME_APP_EXCEPTION_CALLBACK_PROXY_H
#include "iapp_exception_callback.h"
#include "iremote_proxy.h"
namespace OHOS {
namespace AppExecFwk {
class AppExceptionCallbackProxy : public IRemoteProxy<IAppExceptionCallback> {
public:
explicit AppExceptionCallbackProxy(const sptr<IRemoteObject> &impl);
virtual ~AppExceptionCallbackProxy() = default;
/**
* Notify abilityManager lifecycle exception.
*
* @param type lifecycle failed type
* @param token associated ability
*/
virtual void OnLifecycleException(LifecycleException type, sptr<IRemoteObject> token);
private:
bool WriteInterfaceToken(MessageParcel &data);
static inline BrokerDelegator<AppExceptionCallbackProxy> delegator_;
int32_t SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_APP_EXCEPTION_CALLBACK_PROXY_H
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_ABILITY_RUNTIME_APP_EXCEPTION_CALLBACK_STUB_H
#define OHOS_ABILITY_RUNTIME_APP_EXCEPTION_CALLBACK_STUB_H
#include "iapp_exception_callback.h"
#include "iremote_stub.h"
#include "nocopyable.h"
namespace OHOS {
namespace AppExecFwk {
class AppExceptionCallbackStub : public IRemoteStub<IAppExceptionCallback> {
public:
AppExceptionCallbackStub() = default;
virtual ~AppExceptionCallbackStub() = default;
virtual int32_t OnRemoteRequest(
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
private:
int32_t HandleLifecycleException(MessageParcel &data, MessageParcel &reply);
DISALLOW_COPY_AND_MOVE(AppExceptionCallbackStub);
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_APP_EXCEPTION_CALLBACK_STUB_H
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_ABILITY_RUNTIME_APP_EXCEPTION_MANAGER_H
#define OHOS_ABILITY_RUNTIME_APP_EXCEPTION_MANAGER_H
#include "iapp_exception_callback.h"
namespace OHOS {
namespace AppExecFwk {
class AppExceptionManager {
public:
static AppExceptionManager &GetInstance();
AppExceptionManager(AppExceptionManager &) = delete;
void operator=(AppExceptionManager &) = delete;
void LaunchAbilityFailed(sptr<IRemoteObject> token, const std::string &msg);
void ForegroundAppFailed(sptr<IRemoteObject> token, const std::string &msg);
void ForegroundAppWait(sptr<IRemoteObject> token, const std::string &msg);
void NotifyLifecycleException(LifecycleException type, sptr<IRemoteObject> token);
void SetExceptionCallback(sptr<IAppExceptionCallback> exceptionCallback);
sptr<IAppExceptionCallback> GetExceptionCallback() const;
private:
AppExceptionManager() = default;
mutable std::mutex exceptionCallbackMutex_;
sptr<IAppExceptionCallback> exceptionCallback_;
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_APP_EXCEPTION_MANAGER_H
@@ -39,7 +39,7 @@ public:
*
* @return
*/
virtual void ScheduleForegroundApplication() = 0;
virtual bool ScheduleForegroundApplication() = 0;
/**
* ScheduleBackgroundApplication, call ScheduleBackgroundApplication() through proxy project,
@@ -34,7 +34,7 @@ public:
*
* @return
*/
virtual void ScheduleForegroundApplication() override;
virtual bool ScheduleForegroundApplication() override;
/**
* ScheduleBackgroundApplication, call ScheduleBackgroundApplication() through proxy project,
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_ABILITY_RUNTIME_I_APP_EXCEPTION_CALLBACK_H
#define OHOS_ABILITY_RUNTIME_I_APP_EXCEPTION_CALLBACK_H
#include "iremote_broker.h"
#include "iremote_object.h"
namespace OHOS {
namespace AppExecFwk {
enum class LifecycleException {
LAUNCH_ABILITY_FAIL,
FOREGROUND_APP_FAIL,
FOREGROUND_APP_WAIT,
END
};
class IAppExceptionCallback : public IRemoteBroker {
public:
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.AppExceptionCallback");
/**
* Notify abilityManager lifecycle exception.
*
* @param type lifecycle failed type
* @param token associated ability
*/
virtual void OnLifecycleException(LifecycleException type, sptr<IRemoteObject> token) {}
enum class Message {
LIFECYCLE_EXCEPTION_MSG_ID = 0,
};
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_I_APP_EXCEPTION_CALLBACK_H
@@ -1320,5 +1320,27 @@ bool AmsMgrProxy::IsAppKilling(sptr<IRemoteObject> token)
}
return reply.ReadBool();
}
void AmsMgrProxy::SetAppExceptionCallback(sptr<IRemoteObject> callback)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!WriteInterfaceToken(data)) {
TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
return;
}
if (!data.WriteRemoteObject(callback.GetRefPtr())) {
TAG_LOGE(AAFwkTag::APPMGR, "Failed to write callback");
return;
}
auto ret = SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::SET_APP_EXCEPTION_CALLBACK),
data, reply, option);
if (ret != NO_ERROR) {
TAG_LOGE(AAFwkTag::APPMGR, "Send request failed, error code is %{public}d.", ret);
return;
}
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -855,5 +855,12 @@ int32_t AmsMgrStub::HandleIsAppKilling(MessageParcel &data, MessageParcel &reply
}
return NO_ERROR;
}
int32_t AmsMgrStub::HandleSetAppExceptionCallback(MessageParcel &data, MessageParcel &reply)
{
sptr<IRemoteObject> callback = data.ReadRemoteObject();
SetAppExceptionCallback(callback);
return NO_ERROR;
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "app_exception_callback_proxy.h"
#include "hilog_tag_wrapper.h"
namespace OHOS {
namespace AppExecFwk {
AppExceptionCallbackProxy::AppExceptionCallbackProxy(const sptr<IRemoteObject> &impl)
: IRemoteProxy<IAppExceptionCallback>(impl) {}
bool AppExceptionCallbackProxy::WriteInterfaceToken(MessageParcel &data)
{
if (!data.WriteInterfaceToken(AppExceptionCallbackProxy::GetDescriptor())) {
TAG_LOGE(AAFwkTag::APPMGR, "write interface token failed");
return false;
}
return true;
}
int32_t AppExceptionCallbackProxy::SendTransactCmd(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option)
{
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "Remote is nullptr.");
return ERR_NULL_OBJECT;
}
auto ret = remote->SendRequest(code, data, reply, option);
if (ret != NO_ERROR) {
TAG_LOGE(AAFwkTag::APPMGR, "Send request failed with error code: %{public}d", ret);
return ret;
}
return ret;
}
void AppExceptionCallbackProxy::OnLifecycleException(LifecycleException type, sptr<IRemoteObject> token)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_ASYNC);
if (!WriteInterfaceToken(data)) {
return;
}
int32_t exceptionType = static_cast<int32_t>(type);
if (!data.WriteInt32(exceptionType)) {
TAG_LOGE(AAFwkTag::APPMGR, "Failed to write exceptionType");
return;
}
if (token) {
if (!data.WriteBool(true) || !data.WriteRemoteObject(token.GetRefPtr())) {
TAG_LOGE(AAFwkTag::APPMGR, "Failed to write flag and token");
return;
}
} else {
if (!data.WriteBool(false)) {
TAG_LOGE(AAFwkTag::APPMGR, "Failed to write flag");
return;
}
}
int32_t ret = SendTransactCmd(
static_cast<uint32_t>(IAppExceptionCallback::Message::LIFECYCLE_EXCEPTION_MSG_ID), data, reply, option);
if (ret != NO_ERROR) {
TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
}
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "app_exception_callback_stub.h"
#include "hilog_tag_wrapper.h"
namespace OHOS {
namespace AppExecFwk {
int32_t AppExceptionCallbackStub::OnRemoteRequest(
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
{
std::u16string descriptor = AppExceptionCallbackStub::GetDescriptor();
std::u16string remoteDescriptor = data.ReadInterfaceToken();
if (descriptor != remoteDescriptor) {
TAG_LOGE(AAFwkTag::APPMGR, "local descriptor is not equal to remote");
return ERR_INVALID_STATE;
}
switch (code) {
case static_cast<uint32_t>(IAppExceptionCallback::Message::LIFECYCLE_EXCEPTION_MSG_ID):
return HandleLifecycleException(data, reply);
default:
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
}
int32_t AppExceptionCallbackStub::HandleLifecycleException(MessageParcel &data, MessageParcel &reply)
{
auto type = data.ReadInt32();
if (type < 0 || type > static_cast<int32_t>(LifecycleException::END)) {
return ERR_INVALID_STATE;
}
auto lifecycleExceptType = static_cast<LifecycleException>(type);
sptr<IRemoteObject> token;
if (data.ReadBool()) {
token = data.ReadRemoteObject();
}
OnLifecycleException(lifecycleExceptType, token);
return ERR_OK;
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -0,0 +1,78 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "app_exception_manager.h"
#include "freeze_util.h"
#include "hilog_tag_wrapper.h"
namespace OHOS {
using AbilityRuntime::FreezeUtil;
namespace AppExecFwk {
AppExceptionManager &AppExceptionManager::GetInstance()
{
static AppExceptionManager appExceptionMgr;
return appExceptionMgr;
}
void AppExceptionManager::LaunchAbilityFailed(sptr<IRemoteObject> token, const std::string &msg)
{
FreezeUtil::LifecycleFlow flow{token, FreezeUtil::TimeoutState::LOAD};
FreezeUtil::GetInstance().AppendLifecycleEvent(flow, std::string("LaunchAbilityFailed: " + msg));
NotifyLifecycleException(LifecycleException::LAUNCH_ABILITY_FAIL, token);
}
void AppExceptionManager::ForegroundAppFailed(sptr<IRemoteObject> token, const std::string &msg)
{
FreezeUtil::LifecycleFlow flow{token, FreezeUtil::TimeoutState::FOREGROUND};
FreezeUtil::GetInstance().AppendLifecycleEvent(flow, std::string("ForegroundAppFailed: " + msg));
NotifyLifecycleException(LifecycleException::FOREGROUND_APP_FAIL, token);
}
void AppExceptionManager::ForegroundAppWait(sptr<IRemoteObject> token, const std::string &msg)
{
FreezeUtil::LifecycleFlow flow{token, FreezeUtil::TimeoutState::FOREGROUND};
FreezeUtil::GetInstance().AppendLifecycleEvent(flow, std::string("ForegroundAppWait: " + msg));
NotifyLifecycleException(LifecycleException::FOREGROUND_APP_WAIT, token);
}
void AppExceptionManager::NotifyLifecycleException(LifecycleException type, sptr<IRemoteObject> token)
{
auto callback = GetExceptionCallback();
if (callback != nullptr) {
TAG_LOGI(AAFwkTag::APPMGR, "notify app exception");
callback->OnLifecycleException(type, token);
}
}
void AppExceptionManager::SetExceptionCallback(sptr<IAppExceptionCallback> exceptionCallback)
{
if (exceptionCallback == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "callback null");
}
std::lock_guard lock(exceptionCallbackMutex_);
if (exceptionCallback_ != nullptr) {
TAG_LOGI(AAFwkTag::APPMGR, "inner callback not null");
}
exceptionCallback_ = exceptionCallback;
}
sptr<IAppExceptionCallback> AppExceptionManager::GetExceptionCallback() const
{
std::lock_guard lock(exceptionCallbackMutex_);
return exceptionCallback_;
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -336,14 +336,13 @@ int32_t AppSchedulerHost::HandleScheduleClearPageStack(MessageParcel &data, Mess
int32_t AppSchedulerHost::HandleScheduleAcceptWant(MessageParcel &data, MessageParcel &reply)
{
HITRACE_METER(HITRACE_TAG_APP);
AAFwk::Want *want = data.ReadParcelable<AAFwk::Want>();
auto want = std::shared_ptr<AAFwk::Want>(data.ReadParcelable<AAFwk::Want>());
if (want == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "want is nullptr");
return ERR_INVALID_VALUE;
}
auto moduleName = data.ReadString();
ScheduleAcceptWant(*want, moduleName);
delete want;
return NO_ERROR;
}
@@ -351,14 +350,13 @@ int32_t AppSchedulerHost::HandleScheduleNewProcessRequest(MessageParcel &data, M
{
TAG_LOGD(AAFwkTag::APPMGR, "call.");
HITRACE_METER(HITRACE_TAG_APP);
AAFwk::Want *want = data.ReadParcelable<AAFwk::Want>();
auto want = std::shared_ptr<AAFwk::Want>(data.ReadParcelable<AAFwk::Want>());
if (want == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "want is nullptr");
return ERR_INVALID_VALUE;
}
auto moduleName = data.ReadString();
ScheduleNewProcessRequest(*want, moduleName);
delete want;
return NO_ERROR;
}
@@ -15,6 +15,7 @@
#include "app_scheduler_proxy.h"
#include "app_exception_manager.h"
#include "hilog_tag_wrapper.h"
#include "hitrace_meter.h"
#include "ipc_types.h"
@@ -35,14 +36,14 @@ bool AppSchedulerProxy::WriteInterfaceToken(MessageParcel &data)
return true;
}
void AppSchedulerProxy::ScheduleForegroundApplication()
bool AppSchedulerProxy::ScheduleForegroundApplication()
{
TAG_LOGD(AAFwkTag::APPMGR, "AppSchedulerProxy::ScheduleForegroundApplication start");
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_ASYNC);
if (!WriteInterfaceToken(data)) {
return;
return false;
}
int32_t ret =
SendTransactCmd(static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_FOREGROUND_APPLICATION_TRANSACTION),
@@ -51,7 +52,9 @@ void AppSchedulerProxy::ScheduleForegroundApplication()
option);
if (ret != NO_ERROR) {
TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
return false;
}
return true;
}
void AppSchedulerProxy::ScheduleBackgroundApplication()
@@ -214,6 +217,8 @@ void AppSchedulerProxy::ScheduleLaunchAbility(const AbilityInfo &info, const spt
static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_LAUNCH_ABILITY_TRANSACTION), data, reply, option);
if (ret != NO_ERROR) {
TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
AppExceptionManager::GetInstance().LaunchAbilityFailed(token, std::string("SendRequest is failed") +
std::to_string(ret));
}
}
@@ -92,7 +92,8 @@ public:
void ResumeVM(uint32_t tid) override;
bool RunSandboxScript(const std::string& path, const std::string& hapPath);
bool RunScript(const std::string& path, const std::string& hapPath, bool useCommonChunk = false);
bool RunScript(const std::string& path, const std::string& hapPath, bool useCommonChunk = false,
const std::string& srcEntrance = "");
void PreloadSystemModule(const std::string& moduleName) override;
@@ -104,7 +105,8 @@ public:
bool NotifyHotReloadPage() override;
void RegisterUncaughtExceptionHandler(const JsEnv::UncaughtExceptionInfo& uncaughtExceptionInfo);
bool LoadScript(const std::string& path, std::vector<uint8_t>* buffer = nullptr, bool isBundle = false);
bool LoadScript(const std::string& path, uint8_t* buffer, size_t len, bool isBundle);
bool LoadScript(const std::string& path, uint8_t* buffer, size_t len, bool isBundle,
const std::string& srcEntrance = "");
bool StartDebugger(bool needBreakPoint, uint32_t instanceId);
void StopDebugger();
@@ -130,7 +132,8 @@ public:
static std::unique_ptr<NativeReference> LoadSystemModuleByEngine(napi_env env,
const std::string& moduleName, const napi_value* argv, size_t argc);
std::unique_ptr<NativeReference> LoadModule(const std::string& moduleName, const std::string& modulePath,
const std::string& hapPath, bool esmodule = false, bool useCommonChunk = false);
const std::string& hapPath, bool esmodule = false, bool useCommonChunk = false,
const std::string& srcEntrance = "");
std::unique_ptr<NativeReference> LoadSystemModule(
const std::string& moduleName, const napi_value* argv = nullptr, size_t argc = 0);
void SetDeviceDisconnectCallback(const std::function<bool()> &cb) override;
@@ -138,17 +141,16 @@ public:
private:
void FinishPreload() override;
bool Initialize(const Options& options);
void Deinitialize();
int32_t JsperfProfilerCommandParse(const std::string &command, int32_t defaultValue);
napi_value LoadJsBundle(const std::string& path, const std::string& hapPath, bool useCommonChunk = false);
napi_value LoadJsModule(const std::string& path, const std::string& hapPath);
napi_value LoadJsModule(const std::string& path, const std::string& hapPath, const std::string& srcEntrance = "");
bool preloaded_ = false;
bool isBundle_ = true;
bool isOhmUrl_ = false;
std::string codePath_;
std::string moduleName_;
std::unique_ptr<NativeReference> methodRequireNapiRef_;
@@ -23,7 +23,6 @@
#include "cancel_listener.h"
#include "context/application_context.h"
#include "completed_dispatcher.h"
#include "event_handler.h"
#include "want.h"
#include "want_agent_constant.h"
#include "want_params.h"
@@ -1349,7 +1349,6 @@ private:
std::shared_ptr<ContinuationHandler> continuationHandler_ = nullptr;
std::shared_ptr<ContinuationManager> continuationManager_ = nullptr;
std::shared_ptr<ContinuationRegisterManager> continuationRegisterManager_ = nullptr;
std::shared_ptr<AbilityHandler> handler_ = nullptr;
std::shared_ptr<LifeCycle> lifecycle_ = nullptr;
std::shared_ptr<AbilityLifecycleExecutor> abilityLifecycleExecutor_ = nullptr;
@@ -65,6 +65,8 @@ struct CJAbilityFuncs {
VectorStringHandle (*cjAbilityDump)(int64_t id, VectorStringHandle params);
int32_t (*cjAbilityOnContinue)(int64_t id, const char* params);
void (*cjAbilityInit)(int64_t id, void* ability);
bool (*cjAbilityOnBackPress)(int64_t id);
void (*cjAbilityOnSceneWillDestroy)(int64_t id, WindowStagePtr cjWindowStage);
};
CJ_EXPORT void RegisterCJAbilityFuncs(void (*registerFunc)(CJAbilityFuncs*));
@@ -87,14 +89,17 @@ public:
void OnStop() const;
void OnSceneCreated(OHOS::Rosen::CJWindowStageImpl* cjWindowStage) const;
void OnSceneRestored(OHOS::Rosen::CJWindowStageImpl* cjWindowStage) const;
void OnSceneWillDestroy(OHOS::Rosen::CJWindowStageImpl* cjWindowStage) const;
void OnSceneDestroyed() const;
void OnForeground(const AAFwk::Want& want) const;
void OnBackground() const;
bool OnBackPress(bool defaultRet) const;
void OnConfigurationUpdated(const std::shared_ptr<AppExecFwk::Configuration>& configuration) const;
void OnNewWant(const AAFwk::Want& want, const AAFwk::LaunchParam& launchParam) const;
void Dump(const std::vector<std::string>& params, std::vector<std::string>& info) const;
int32_t OnContinue(AAFwk::WantParams &wantParams) const;
void Init(AbilityHandle ability) const;
int64_t GetId() const;
private:
int64_t id_ = 0;
@@ -21,6 +21,7 @@
#include "ui_ability.h"
#ifdef SUPPORT_GRAPHICS
#include "window_stage_impl.h"
#include "cj_ability_object.h"
#endif
namespace OHOS {
@@ -179,7 +180,13 @@ public:
* @brief Called after ability stoped.
* You can override this function to implement your own processing logic.
*/
void OnSceneDestroyed() ;
void OnSceneWillDestroy() override;
/**
* @brief Called after ability stoped.
* You can override this function to implement your own processing logic.
*/
void onSceneDestroyed() override;
/**
* @brief Called after ability restored.
@@ -214,6 +221,12 @@ public:
* You can override this function to implement your own processing logic.
*/
void OnBackground() override;
/**
* @brief Called after window stage focused or unfocused
* You can override this function to implement your own processing logic.
*/
void OnAfterFocusedCommon(bool isFocused) override;
/**
* Called when back press is dispatched.
@@ -279,6 +292,8 @@ private:
void InitSceneDoOnForeground(std::shared_ptr<Rosen::WindowScene> scene, const Want &want);
void AddLifecycleEventBeforeCall(FreezeUtil::TimeoutState state, const std::string &methodName) const;
void AddLifecycleEventAfterCall(FreezeUtil::TimeoutState state, const std::string &methodName) const;
bool CheckSatisfyTargetAPIVersion(int32_t targetAPIVersion);
bool BackPressDefaultValue();
CJRuntime &cjRuntime_;
std::shared_ptr<CJAbilityObject> cjAbilityObj_;
@@ -94,7 +94,7 @@ public:
* @param targetState Indicates the lifecycle state.
* @param sessionInfo Indicates the session info.
*/
void ScheduleAbilityTransaction(
bool ScheduleAbilityTransaction(
const Want &want, const LifeCycleStateInfo &targetState, sptr<SessionInfo> sessionInfo = nullptr) override;
/**
@@ -63,7 +63,7 @@ public:
* @param targetState Indicates the lifecycle state.
* @param sessionInfo Indicates the session info.
*/
void ScheduleAbilityTransaction(const Want &want, const LifeCycleStateInfo &targetState,
bool ScheduleAbilityTransaction(const Want &want, const LifeCycleStateInfo &targetState,
sptr<AAFwk::SessionInfo> sessionInfo = nullptr) override;
/**
@@ -71,7 +71,7 @@ public:
* @param targetState Indicates the lifecycle state.
* @param sessionInfo Indicates the session info.
*/
void ScheduleAbilityTransaction(const Want &want, const LifeCycleStateInfo &targetState,
bool ScheduleAbilityTransaction(const Want &want, const LifeCycleStateInfo &targetState,
sptr<AAFwk::SessionInfo> sessionInfo = nullptr) override;
/**
@@ -563,7 +563,7 @@ private:
std::shared_ptr<AbilityContext> BuildAbilityContext(const std::shared_ptr<AppExecFwk::AbilityInfo> &abilityInfo,
const std::shared_ptr<AppExecFwk::OHOSApplication> &application, const sptr<IRemoteObject> &token,
const std::shared_ptr<Context> &stageContext);
void AddLifecycleEvent(uint32_t state, std::string &methodName) const;
std::shared_ptr<AppExecFwk::AbilityImpl> abilityImpl_;
@@ -108,6 +108,7 @@ private:
void AddJsObserverCommon(JsFreeInstallObserverObject &object,
napi_value jsObserverObject, napi_value* result, bool isAbilityResult);
napi_env env_;
std::mutex jsObserverObjectListLock_;
std::vector<JsFreeInstallObserverObject> jsObserverObjectList_;
};
} // namespace AbilityRuntime
@@ -403,6 +403,12 @@ public:
*/
virtual void OnBackground();
/**
* @brief Called after window stage focused or unfocused
* You can override this function to implement your own processing logic.
*/
virtual void OnAfterFocusedCommon(bool isFocused);
/**
* @brief Called when ability prepare terminate.
* @return Return true if ability need to stop terminating; return false if ability need to terminate.
@@ -76,7 +76,7 @@ public:
* @param targetState Indicates the lifecycle state.
* @param sessionInfo Indicates the session info.
*/
void ScheduleAbilityTransaction(const Want &want, const LifeCycleStateInfo &targetState,
bool ScheduleAbilityTransaction(const Want &want, const LifeCycleStateInfo &targetState,
sptr<AAFwk::SessionInfo> sessionInfo = nullptr) override;
/**
@@ -134,7 +134,7 @@ public:
* @brief Schedule the foreground lifecycle of application.
*
*/
void ScheduleForegroundApplication() override;
bool ScheduleForegroundApplication() override;
/**
*
@@ -657,7 +657,6 @@ private:
MainThreadState mainThreadState_ = MainThreadState::INIT;
sptr<IAppMgr> appMgr_ = nullptr; // appMgrService Handler
sptr<IRemoteObject::DeathRecipient> deathRecipient_ = nullptr;
std::string aceApplicationName_ = "AceApplication";
std::string pathSeparator_ = "/";
std::string abilityLibraryType_ = ".so";
static std::weak_ptr<OHOSApplication> applicationForDump_;
+1
View File
@@ -170,6 +170,7 @@ ohos_shared_library("abilityms") {
"json:nlohmann_json_static",
"kv_store:distributeddata_inner",
"os_account:os_account_innerkits",
"qos_manager:concurrent_task_client",
"relational_store:native_appdatafwk",
"relational_store:native_dataability",
"relational_store:native_rdb",
+1
View File
@@ -28,6 +28,7 @@ abilityms_files = [
"src/ability_manager_xcollie.cpp",
"src/ability_scheduler_proxy.cpp",
"src/ability_token_stub.cpp",
"src/app_exception_handler.cpp",
"src/app_scheduler.cpp",
"src/app_exit_reason_helper.cpp",
"src/assert_fault_callback_death_mgr.cpp",
@@ -330,6 +330,9 @@ public:
std::shared_ptr<AAFwk::AbilityRecord> GetUIExtensionRootHostInfo(const sptr<IRemoteObject> token);
void UninstallApp(const std::string &bundleName);
int32_t UpdateKeepAliveEnableState(const std::string &bundleName, const std::string &moduleName,
const std::string &mainElement, bool updateEnable);
// MSG 0 - 20 represents timeout message
static constexpr uint32_t CONNECT_TIMEOUT_MSG = 1;
@@ -1811,6 +1811,9 @@ public:
void EnableListForSCBRecovery(int32_t userId) const;
int32_t UpdateKeepAliveEnableState(const std::string &bundleName, const std::string &moduleName,
const std::string &mainElement, bool updateEnable, int32_t userId);
// MSG 0 - 20 represents timeout message
static constexpr uint32_t LOAD_TIMEOUT_MSG = 0;
static constexpr uint32_t ACTIVE_TIMEOUT_MSG = 1;
@@ -1118,6 +1118,16 @@ public:
return securityFlag_;
}
FreezeStrategy GetFreezeStrategy() const
{
return freezeStrategy_;
}
void SetFreezeStrategy(FreezeStrategy value)
{
freezeStrategy_ = value;
}
protected:
void SendEvent(uint32_t msg, uint32_t timeOut, int32_t param = -1, bool isExtension = false);
@@ -1343,6 +1353,7 @@ private:
LaunchDebugInfo launchDebugInfo_;
std::string instanceKey_ = "";
bool securityFlag_ = false;
std::atomic<FreezeStrategy> freezeStrategy_{FreezeStrategy::NOTIFY_FREEZE_MGR};
};
} // namespace AAFwk
} // namespace OHOS
@@ -47,7 +47,7 @@ public:
* @param Want, Special Want for service type's ability.
* @param stateInfo, The lifecycle state to be transformed.
*/
void ScheduleAbilityTransaction(const Want &want, const LifeCycleStateInfo &stateInfo,
bool ScheduleAbilityTransaction(const Want &want, const LifeCycleStateInfo &stateInfo,
sptr<SessionInfo> sessionInfo = nullptr) override;
/*
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_ABILITY_RUNTIME_APP_EXCEPTION_HANDLER_H
#define OHOS_ABILITY_RUNTIME_APP_EXCEPTION_HANDLER_H
#include <string>
#include "iremote_object.h"
namespace OHOS {
namespace AAFwk {
class AppExceptionHandler {
public:
static AppExceptionHandler &GetInstance();
AppExceptionHandler(AppExceptionHandler &) = delete;
void operator=(AppExceptionHandler &) = delete;
void RegisterAppExceptionCallback();
void AbilityForegroundFailed(sptr<IRemoteObject> token, const std::string &msg);
private:
AppExceptionHandler() = default;
};
} // namespace AAFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_APP_EXCEPTION_HANDLER_H
@@ -100,7 +100,7 @@ public:
const std::tuple<std::string, std::string, std::string, std::string> extensionRecordMapKey);
bool RemovePreloadUIExtensionRecordById(
const std::tuple<std::string, std::string, std::string, std::string> extensionRecordMapKey,
const std::tuple<std::string, std::string, std::string, std::string> &extensionRecordMapKey,
int32_t extensionRecordId);
int32_t GetOrCreateExtensionRecord(const AAFwk::AbilityRequest &abilityRequest, const std::string &hostBundleName,
+1 -1
View File
@@ -73,7 +73,7 @@ public:
/**
* schedule ability life cycle to foreground
*/
void ForegroundNew(const Want &want, LifeCycleStateInfo &stateInfo,
bool ForegroundNew(const Want &want, LifeCycleStateInfo &stateInfo,
sptr<SessionInfo> sessionInfo = nullptr);
/**
* schedule ability life cycle to background
@@ -100,6 +100,9 @@ private:
std::string &mainElement, std::set<uint32_t> &needEraseIndexSet, size_t bundleInfoIndex, int32_t userId = 0);
void UpdateResidentProcessesStatus(const std::string &bundleName, bool localEnable, bool updateEnable);
void AddFailedResidentAbility(const std::string &bundleName, const std::string &abilityName, int32_t userId);
void NotifyDisableResidentProcess(const std::vector<AppExecFwk::BundleInfo> &bundleInfos, int32_t userId);
void UpdateMainElement(const std::string &bundleName, const std::string &moduleName,
const std::string &mainElement, bool updateEnable, int32_t userId);
std::mutex residentAbilityInfoMutex_;
std::list<ResidentAbilityInfo> residentAbilityInfos_;
@@ -462,7 +462,7 @@ private:
ffrt::mutex statusBarDelegateManagerLock_;
std::shared_ptr<StatusBarDelegateManager> statusBarDelegateManager_;
bool isSCBRecovery_ = false;
std::unordered_set<int32_t> codeStartInSCBRecovery_;
std::unordered_set<int32_t> coldStartInSCBRecovery_;
};
} // namespace AAFwk
} // namespace OHOS
@@ -40,6 +40,9 @@ void AbilityCacheManager::Init(uint32_t devCapacity, uint32_t procCapacity)
void AbilityCacheManager::RemoveAbilityRecInDevList(std::shared_ptr<AbilityRecord> abilityRecord)
{
if (abilityRecord == nullptr) {
return;
}
auto it = devRecLru_.begin();
uint32_t accessTokenId = abilityRecord->GetApplicationInfo().accessTokenId;
while (it != devRecLru_.end()) {
@@ -55,6 +58,9 @@ void AbilityCacheManager::RemoveAbilityRecInDevList(std::shared_ptr<AbilityRecor
void AbilityCacheManager::RemoveAbilityRecInProcList(std::shared_ptr<AbilityRecord> abilityRecord)
{
if (abilityRecord == nullptr) {
return;
}
uint32_t accessTokenId = abilityRecord->GetApplicationInfo().accessTokenId;
auto findProcInfo = procLruMap_.find(accessTokenId);
if (findProcInfo == procLruMap_.end()) {
@@ -79,6 +85,9 @@ void AbilityCacheManager::RemoveAbilityRecInProcList(std::shared_ptr<AbilityReco
std::shared_ptr<AbilityRecord> AbilityCacheManager::AddToProcLru(std::shared_ptr<AbilityRecord> abilityRecord)
{
if (abilityRecord == nullptr) {
return nullptr;
}
auto findProcInfo = procLruMap_.find(abilityRecord->GetApplicationInfo().accessTokenId);
if (findProcInfo == procLruMap_.end()) {
std::list<std::shared_ptr<AbilityRecord>> recList;
@@ -147,7 +156,8 @@ void AbilityCacheManager::Remove(std::shared_ptr<AbilityRecord> abilityRecord)
bool AbilityCacheManager::IsRecInfoSame(const AbilityRequest& abilityRequest,
std::shared_ptr<AbilityRecord> abilityRecord)
{
return abilityRequest.abilityInfo.moduleName == abilityRecord->GetAbilityInfo().moduleName &&
return abilityRecord != nullptr &&
abilityRequest.abilityInfo.moduleName == abilityRecord->GetAbilityInfo().moduleName &&
abilityRequest.want.GetElement().GetAbilityName() == abilityRecord->GetWant().GetElement().GetAbilityName();
}
@@ -161,7 +161,7 @@ int AbilityConnectionStub::OnRemoteRequest(
}
}
void AbilityConnectCallbackRecipient::OnRemoteDied(const wptr<IRemoteObject> &__attribute__((unused)) remote)
void AbilityConnectCallbackRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
if (handler_) {
@@ -188,8 +188,7 @@ int AbilityConnectManager::StartAbilityLocked(const AbilityRequest &abilityReque
AddUIExtWindowDeathRecipient(remoteObj);
}
auto &abilityInfo = abilityRequest.abilityInfo;
ret = ReportXiaoYiToRSSIfNeeded(abilityInfo);
ret = ReportXiaoYiToRSSIfNeeded(abilityRequest.abilityInfo);
if (ret != ERR_OK) {
return ret;
}
@@ -949,6 +948,7 @@ int AbilityConnectManager::AbilityWindowConfigTransactionDone(const sptr<IRemote
void AbilityConnectManager::ProcessPreload(const std::shared_ptr<AbilityRecord> &record) const
{
auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper();
CHECK_POINTER(record);
CHECK_POINTER(bundleMgrHelper);
auto abilityInfo = record->GetAbilityInfo();
Want want;
@@ -1321,12 +1321,6 @@ std::shared_ptr<AbilityRecord> AbilityConnectManager::GetUIExtensionBySessionInf
CHECK_POINTER_AND_RETURN(sessionInfo, nullptr);
auto sessionToken = iface_cast<Rosen::ISession>(sessionInfo->sessionToken);
CHECK_POINTER_AND_RETURN(sessionToken, nullptr);
std::string descriptor = Str16ToStr8(sessionToken->GetDescriptor());
if (descriptor != "OHOS.ISession") {
TAG_LOGE(AAFwkTag::ABILITYMGR, "token not a sessionToken, token->GetDescriptor(): %{public}s",
descriptor.c_str());
return nullptr;
}
std::lock_guard guard(uiExtensionMapMutex_);
auto it = uiExtensionMap_.find(sessionToken->AsObject());
@@ -1756,6 +1750,7 @@ void AbilityConnectManager::ResumeConnectAbility(const std::shared_ptr<AbilityRe
void AbilityConnectManager::CommandAbility(const std::shared_ptr<AbilityRecord> &abilityRecord)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
CHECK_POINTER(abilityRecord);
if (taskHandler_ != nullptr) {
// first connect ability, There is at most one connect record.
int recordId = abilityRecord->GetRecordId();
@@ -3257,5 +3252,24 @@ void AbilityConnectManager::UninstallApp(const std::string &bundleName)
}
}
}
int32_t AbilityConnectManager::UpdateKeepAliveEnableState(const std::string &bundleName,
const std::string &moduleName, const std::string &mainElement, bool updateEnable)
{
std::lock_guard lock(serviceMapMutex_);
for (const auto &[key, abilityRecord]: serviceMap_) {
CHECK_POINTER_AND_RETURN(abilityRecord, ERR_NULL_OBJECT);
if (abilityRecord->GetAbilityInfo().bundleName == bundleName &&
abilityRecord->GetAbilityInfo().name == mainElement &&
abilityRecord->GetAbilityInfo().moduleName == moduleName) {
TAG_LOGI(AAFwkTag::ABILITYMGR,
"update keepAlive,bundle:%{public}s,module:%{public}s,ability:%{public}s,enable:%{public}d",
bundleName.c_str(), moduleName.c_str(), mainElement.c_str(), updateEnable);
abilityRecord->SetKeepAliveBundle(updateEnable);
return ERR_OK;
}
}
return ERR_OK;
}
} // namespace AAFwk
} // namespace OHOS
@@ -21,12 +21,14 @@
#include "ability_resident_process_rdb.h"
#include "accesstoken_kit.h"
#include "ability_manager_xcollie.h"
#include "app_exception_handler.h"
#include "app_utils.h"
#include "app_exit_reason_data_manager.h"
#include "application_util.h"
#include "app_mgr_util.h"
#include "recovery_info_timer.h"
#include "assert_fault_callback_death_mgr.h"
#include "concurrent_task_client.h"
#include "connection_state_manager.h"
#include "display_manager.h"
#include "distributed_client.h"
@@ -300,6 +302,10 @@ void AbilityManagerService::OnStart()
AddSystemAbilityListener(MULTIMODAL_INPUT_SERVICE_ID);
#endif
TAG_LOGI(AAFwkTag::ABILITYMGR, "onStart success");
auto pid = getpid();
std::unordered_map<std::string, std::string> payload;
payload["pid"] = std::to_string(pid);
OHOS::ConcurrentTask::ConcurrentTaskClient::GetInstance().RequestAuth(payload);
}
bool AbilityManagerService::Init()
@@ -3658,7 +3664,10 @@ int AbilityManagerService::CloseUIAbilityBySCB(const sptr<SessionInfo> &sessionI
if (!forceKillProcess) {
IN_PROCESS_CALL_WITHOUT_RET(DelayedSingleton<AppScheduler>::GetInstance()->SetProcessCacheStatus(
abilityRecord->GetPid(), true));
}
} else {
IN_PROCESS_CALL_WITHOUT_RET(DelayedSingleton<AppScheduler>::GetInstance()->SetProcessCacheStatus(
abilityRecord->GetPid(), false));
}
EventInfo eventInfo;
eventInfo.bundleName = abilityRecord->GetAbilityInfo().bundleName;
eventInfo.abilityName = abilityRecord->GetAbilityInfo().name;
@@ -7116,6 +7125,7 @@ void AbilityManagerService::ConnectServices()
TAG_LOGE(AAFwkTag::ABILITYMGR, "failed init appScheduler");
usleep(REPOLL_TIME_MICRO_SECONDS);
}
AppExceptionHandler::GetInstance().RegisterAppExceptionCallback();
TAG_LOGI(AAFwkTag::ABILITYMGR, "waiting bundleMgr service run completed");
while (AbilityUtil::GetBundleManagerHelper() == nullptr) {
@@ -12026,6 +12036,9 @@ int32_t AbilityManagerService::CleanUIAbilityBySCB(const sptr<SessionInfo> &sess
if (!forceKillProcess) {
IN_PROCESS_CALL_WITHOUT_RET(DelayedSingleton<AppScheduler>::GetInstance()->SetProcessCacheStatus(
abilityRecord->GetPid(), true));
} else {
IN_PROCESS_CALL_WITHOUT_RET(DelayedSingleton<AppScheduler>::GetInstance()->SetProcessCacheStatus(
abilityRecord->GetPid(), false));
}
int32_t errCode = uiAbilityManager->CleanUIAbility(abilityRecord, forceKillProcess);
ReportCleanSession(sessionInfo, abilityRecord, errCode);
@@ -12128,7 +12141,7 @@ void AbilityManagerService::SetAbilityRequestSessionInfo(AbilityRequest &ability
auto sceneSessionManager = Rosen::SessionManagerLite::GetInstance().
GetSceneSessionManagerLiteProxy();
CHECK_POINTER_LOG(sceneSessionManager, "sceneSessionManager is nullptr");
auto err = sceneSessionManager->GetRootMainWindowId(static_cast<int32_t>(callerSessionInfo->hostWindowId),mainWindowId);
auto err = sceneSessionManager->GetRootMainWindowId(static_cast<int32_t>(callerSessionInfo->hostWindowId),mainWindowId);
TAG_LOGI(AAFwkTag::ABILITYMGR, "callerSessionInfo->hostWindowId = %{public}d, mainWindowId = %{public}d, err = %{public}d",
callerSessionInfo->hostWindowId, mainWindowId, err);
abilityRequest.want.SetParam(WANT_PARAMS_HOST_WINDOW_ID_KEY, mainWindowId);
@@ -12214,5 +12227,17 @@ void AbilityManagerService::EnableListForSCBRecovery(int32_t userId) const
CHECK_POINTER_LOG(uiAbilityManager, "UIAbilityMgr not exist.");
uiAbilityManager->EnableListForSCBRecovery();
}
int32_t AbilityManagerService::UpdateKeepAliveEnableState(const std::string &bundleName,
const std::string &moduleName, const std::string &mainElement, bool updateEnable, int32_t userId)
{
auto connectManager = GetConnectManagerByUserId(userId);
CHECK_POINTER_AND_RETURN(connectManager, ERR_NULL_OBJECT);
int32_t ret = connectManager->UpdateKeepAliveEnableState(bundleName, moduleName, mainElement, updateEnable);
if (ret != ERR_OK) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "UpdateKeepAliveEnableState failed, err:%{public}d", ret);
}
return ret;
}
} // namespace AAFwk
} // namespace OHOS
+6 -1
View File
@@ -20,6 +20,7 @@
#include "ability_manager_service.h"
#include "ability_resident_process_rdb.h"
#include "ability_scheduler_stub.h"
#include "app_exception_handler.h"
#include "app_exit_reason_data_manager.h"
#include "app_utils.h"
#include "array_wrapper.h"
@@ -398,7 +399,9 @@ void AbilityRecord::ForegroundAbility(uint32_t sceneFlag)
lifeCycleStateInfo_.sceneFlag = sceneFlag;
Want want = GetWant();
UpdateDmsCallerInfo(want);
lifecycleDeal_->ForegroundNew(want, lifeCycleStateInfo_, GetSessionInfo());
if (!lifecycleDeal_->ForegroundNew(want, lifeCycleStateInfo_, GetSessionInfo()) && token_) {
AppExceptionHandler::GetInstance().AbilityForegroundFailed(token_->AsObject(), "ForegroundNew");
}
lifeCycleStateInfo_.sceneFlag = 0;
lifeCycleStateInfo_.sceneFlagBak = 0;
{
@@ -494,6 +497,7 @@ void AbilityRecord::RemoveForegroundTimeoutTask()
CHECK_POINTER(handler);
handler->RemoveEvent(AbilityManagerService::FOREGROUND_HALF_TIMEOUT_MSG, GetAbilityRecordId());
handler->RemoveEvent(AbilityManagerService::FOREGROUND_TIMEOUT_MSG, GetAbilityRecordId());
SetFreezeStrategy(FreezeStrategy::NOTIFY_FREEZE_MGR);
}
void AbilityRecord::RemoveLoadTimeoutTask()
@@ -502,6 +506,7 @@ void AbilityRecord::RemoveLoadTimeoutTask()
CHECK_POINTER(handler);
handler->RemoveEvent(AbilityManagerService::LOAD_HALF_TIMEOUT_MSG, GetAbilityRecordId());
handler->RemoveEvent(AbilityManagerService::LOAD_TIMEOUT_MSG, GetAbilityRecordId());
SetFreezeStrategy(FreezeStrategy::NOTIFY_FREEZE_MGR);
}
void AbilityRecord::PostUIExtensionAbilityTimeoutTask(uint32_t messageId)
@@ -39,7 +39,7 @@ bool AbilitySchedulerProxy::WriteInterfaceToken(MessageParcel &data)
return true;
}
void AbilitySchedulerProxy::ScheduleAbilityTransaction(const Want &want, const LifeCycleStateInfo &stateInfo,
bool AbilitySchedulerProxy::ScheduleAbilityTransaction(const Want &want, const LifeCycleStateInfo &stateInfo,
sptr<SessionInfo> sessionInfo)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
@@ -50,26 +50,27 @@ void AbilitySchedulerProxy::ScheduleAbilityTransaction(const Want &want, const L
MessageParcel reply;
MessageOption option(MessageOption::TF_ASYNC);
if (!WriteInterfaceToken(data)) {
return;
return false;
}
if (!data.WriteParcelable(&want)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "write want failed");
return;
return false;
}
data.WriteParcelable(&stateInfo);
if (sessionInfo) {
if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "write sessionInfo failed");
return;
return false;
}
} else {
if (!data.WriteBool(false)) {
return;
return false;
}
}
int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_ABILITY_TRANSACTION, data, reply, option);
if (err != NO_ERROR) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
return false;
}
int64_t cost = std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::system_clock::now().time_since_epoch()).count() - start;
@@ -82,6 +83,7 @@ void AbilitySchedulerProxy::ScheduleAbilityTransaction(const Want &want, const L
"ScheduleAbilityTransaction proxy cost %{public}" PRId64 "mirco seconds, data size: %{public}zu",
cost, data.GetWritePosition());
}
return true;
}
void AbilitySchedulerProxy::ScheduleShareData(const int32_t &uniqueId)
@@ -0,0 +1,88 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "app_exception_handler.h"
#include "ability_record.h"
#include "app_exception_callback_stub.h"
#include "app_mgr_util.h"
#include "freeze_util.h"
#include "hilog_tag_wrapper.h"
namespace OHOS {
using AppExecFwk::LifecycleException;
using AbilityRuntime::FreezeUtil;
namespace AAFwk {
namespace {
class AppExceptionCallback : public AppExecFwk::AppExceptionCallbackStub {
/**
* Notify abilityManager lifecycle exception.
*
* @param type lifecycle failed type
* @param token associated ability
*/
void OnLifecycleException(LifecycleException type, sptr<IRemoteObject> token) override
{
auto abilityRecord = Token::GetAbilityRecordByToken(token);
if (abilityRecord == nullptr) {
TAG_LOGW(AAFwkTag::ABILITYMGR, "abilityRecord null");
return;
}
TAG_LOGI(AAFwkTag::ABILITYMGR, "lifecycle exception: %{public}s, %{public}d",
abilityRecord->GetURI().c_str(), type);
abilityRecord->SetFreezeStrategy(FreezeStrategy::NOTIFY_FREEZE_MGR);
}
};
}
AppExceptionHandler &AppExceptionHandler::GetInstance()
{
static AppExceptionHandler appExceptionHandler;
return appExceptionHandler;
}
void AppExceptionHandler::RegisterAppExceptionCallback()
{
auto appMgr = AppMgrUtil::GetAppMgr();
if (appMgr == nullptr) {
TAG_LOGW(AAFwkTag::ABILITYMGR, "AppMgrUtil::GetAppMgr failed");
return;
}
auto service = appMgr->GetAmsMgr();
if (service == nullptr) {
TAG_LOGW(AAFwkTag::ABILITYMGR, "GetAmsMgr failed");
return;
}
auto callback = sptr<AppExceptionCallback>(new AppExceptionCallback());
service->SetAppExceptionCallback(callback->AsObject());
}
void AppExceptionHandler::AbilityForegroundFailed(sptr<IRemoteObject> token, const std::string &msg)
{
auto abilityRecord = Token::GetAbilityRecordByToken(token);
if (abilityRecord == nullptr) {
TAG_LOGW(AAFwkTag::ABILITYMGR, "abilityRecord null");
return;
}
FreezeUtil::LifecycleFlow flow{token, FreezeUtil::TimeoutState::FOREGROUND};
FreezeUtil::GetInstance().AppendLifecycleEvent(flow, std::string("AbilityForegroundFailed: " + msg));
TAG_LOGI(AAFwkTag::ABILITYMGR, "AbilityForegroundFailed: %{public}s", abilityRecord->GetURI().c_str());
abilityRecord->SetFreezeStrategy(FreezeStrategy::NOTIFY_FREEZE_MGR);
}
} // namespace AAFwk
} // namespace OHOS
@@ -360,7 +360,7 @@ bool ExtensionRecordManager::IsPreloadExtensionRecord(const AAFwk::AbilityReques
}
bool ExtensionRecordManager::RemovePreloadUIExtensionRecordById(
const std::tuple<std::string, std::string, std::string, std::string> extensionRecordMapKey,
const std::tuple<std::string, std::string, std::string, std::string> &extensionRecordMapKey,
int32_t extensionRecordId)
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "call.");
+3 -3
View File
@@ -126,17 +126,17 @@ void LifecycleDeal::RestoreAbilityState(const PacMap &inState)
abilityScheduler->ScheduleRestoreAbilityState(inState);
}
void LifecycleDeal::ForegroundNew(const Want &want, LifeCycleStateInfo &stateInfo,
bool LifecycleDeal::ForegroundNew(const Want &want, LifeCycleStateInfo &stateInfo,
sptr<SessionInfo> sessionInfo)
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "call");
auto abilityScheduler = GetScheduler();
CHECK_POINTER(abilityScheduler);
CHECK_POINTER_AND_RETURN(abilityScheduler, false);
TAG_LOGD(AAFwkTag::ABILITYMGR, "caller %{public}s, %{public}s",
stateInfo.caller.bundleName.c_str(),
stateInfo.caller.abilityName.c_str());
stateInfo.state = AbilityLifeCycleState::ABILITY_STATE_FOREGROUND_NEW;
abilityScheduler->ScheduleAbilityTransaction(want, stateInfo, sessionInfo);
return abilityScheduler->ScheduleAbilityTransaction(want, stateInfo, sessionInfo);
}
void LifecycleDeal::BackgroundNew(const Want &want, LifeCycleStateInfo &stateInfo,
@@ -2212,11 +2212,7 @@ void MissionListManager::PostMissionLabelUpdateTask(int missionId) const
#endif // SUPPORT_SCREEN
void MissionListManager::PrintTimeOutLog(const std::shared_ptr<AbilityRecord> &ability, uint32_t msgId, bool isHalf)
{
if (ability == nullptr) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "ability null");
return;
}
CHECK_POINTER_LOG(ability, "ability null");
AppExecFwk::RunningProcessInfo processInfo = {};
DelayedSingleton<AppScheduler>::GetInstance()->GetRunningProcessInfoByToken(ability->GetToken(), processInfo);
if (processInfo.pid_ == 0) {
@@ -2234,9 +2230,8 @@ void MissionListManager::PrintTimeOutLog(const std::shared_ptr<AbilityRecord> &a
std::string eventName = isHalf ?
AppExecFwk::AppFreezeType::LIFECYCLE_HALF_TIMEOUT : AppExecFwk::AppFreezeType::LIFECYCLE_TIMEOUT;
TAG_LOGW(AAFwkTag::ABILITYMGR,
"%{public}s: uid: %{public}d, pid: %{public}d, bundleName: %{public}s, abilityName: %{public}s,"
"msg: %{public}s!",
TAG_LOGW(AAFwkTag::ABILITYMGR, "%{public}s: uid: %{public}d, pid: %{public}d, bundleName: %{public}s, "
"abilityName: %{public}s, msg: %{public}s!",
eventName.c_str(), processInfo.uid_, processInfo.pid_, ability->GetAbilityInfo().bundleName.c_str(),
ability->GetAbilityInfo().name.c_str(), msgContent.c_str());
@@ -2246,8 +2241,8 @@ void MissionListManager::PrintTimeOutLog(const std::shared_ptr<AbilityRecord> &a
.eventName = eventName,
.bundleName = ability->GetAbilityInfo().bundleName,
};
FreezeUtil::LifecycleFlow flow;
if (state != FreezeUtil::TimeoutState::UNKNOWN) {
FreezeUtil::LifecycleFlow flow;
if (ability->GetToken() != nullptr) {
flow.token = ability->GetToken()->AsObject();
flow.state = state;
@@ -2256,10 +2251,13 @@ void MissionListManager::PrintTimeOutLog(const std::shared_ptr<AbilityRecord> &a
if (!isHalf) {
FreezeUtil::GetInstance().DeleteLifecycleEvent(flow);
}
AppExecFwk::AppfreezeManager::GetInstance()->LifecycleTimeoutHandle(info, flow);
} else {
info.msg = msgContent;
AppExecFwk::AppfreezeManager::GetInstance()->LifecycleTimeoutHandle(info);
}
if (ability->GetFreezeStrategy() == FreezeStrategy::NOTIFY_FREEZE_MGR) {
AppExecFwk::AppfreezeManager::GetInstance()->LifecycleTimeoutHandle(info, flow);
} else {
TAG_LOGW(AAFwkTag::ABILITYMGR, "%{public}s", info.msg.c_str());
}
}
@@ -120,6 +120,7 @@ void ResidentProcessManager::StartResidentProcessWithMainElement(std::vector<App
hapModuleInfo.bundleName.c_str(), mainElement.c_str());
auto ret = DelayedSingleton<AbilityManagerService>::GetInstance()->StartAbility(want, userId,
DEFAULT_INVAL_VALUE);
UpdateMainElement(hapModuleInfo.bundleName, hapModuleInfo.name, mainElement, true, userId);
if (ret != ERR_OK) {
AddFailedResidentAbility(hapModuleInfo.bundleName, mainElement, userId);
}
@@ -132,6 +133,35 @@ void ResidentProcessManager::StartResidentProcessWithMainElement(std::vector<App
}
}
void ResidentProcessManager::NotifyDisableResidentProcess(const std::vector<AppExecFwk::BundleInfo> &bundleInfos,
int32_t userId)
{
std::set<uint32_t> needEraseIndexSet; // no use
for (size_t i = 0; i < bundleInfos.size(); i++) {
std::string processName = bundleInfos[i].applicationInfo.process;
for (const auto &hapModuleInfo : bundleInfos[i].hapModuleInfos) {
std::string mainElement;
if (!CheckMainElement(hapModuleInfo, processName, mainElement, needEraseIndexSet, i, userId)) {
continue;
}
UpdateMainElement(hapModuleInfo.bundleName, hapModuleInfo.name, mainElement, false, userId);
}
}
}
void ResidentProcessManager::UpdateMainElement(const std::string &bundleName, const std::string &moduleName,
const std::string &mainElement, bool updateEnable, int32_t userId)
{
auto abilityMs = DelayedSingleton<AbilityManagerService>::GetInstance();
CHECK_POINTER(abilityMs);
auto ret = abilityMs->UpdateKeepAliveEnableState(bundleName, moduleName, mainElement, updateEnable, userId);
if (ret != ERR_OK) {
TAG_LOGE(AAFwkTag::ABILITYMGR,
"update keepAlive fail,bundle:%{public}s,mainElement:%{public}s,enable:%{public}d,userId:%{public}d",
bundleName.c_str(), mainElement.c_str(), updateEnable, userId);
}
}
bool ResidentProcessManager::CheckMainElement(const AppExecFwk::HapModuleInfo &hapModuleInfo,
const std::string &processName, std::string &mainElement,
std::set<uint32_t> &needEraseIndexSet, size_t bundleInfoIndex, int32_t userId)
@@ -256,13 +286,17 @@ void ResidentProcessManager::UpdateResidentProcessesStatus(
break;
}
// need start
if (updateEnable && !localEnable) {
// need start
std::vector<AppExecFwk::BundleInfo> bundleInfos{ bundleInfo };
StartResidentProcessWithMainElement(bundleInfos, userId);
if (!bundleInfos.empty()) {
StartResidentProcess(bundleInfos);
}
} else if (!updateEnable && localEnable) {
// just update
std::vector<AppExecFwk::BundleInfo> bundleInfos{ bundleInfo };
NotifyDisableResidentProcess(bundleInfos, userId);
}
}
}
@@ -142,7 +142,7 @@ std::shared_ptr<AbilityRecord> UIAbilityLifecycleManager::GenerateAbilityRecord(
isColdStart = true;
UpdateProcessName(abilityRequest, uiAbilityRecord);
if (isSCBRecovery_) {
codeStartInSCBRecovery_.insert(sessionInfo->persistentId);
coldStartInSCBRecovery_.insert(sessionInfo->persistentId);
}
auto abilityInfo = abilityRequest.abilityInfo;
MoreAbilityNumbersSendEventInfo(
@@ -1100,10 +1100,7 @@ void UIAbilityLifecycleManager::NotifyAbilityToken(const sptr<IRemoteObject> &to
void UIAbilityLifecycleManager::PrintTimeOutLog(std::shared_ptr<AbilityRecord> ability, uint32_t msgId, bool isHalf)
{
if (ability == nullptr) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "null ability");
return;
}
CHECK_POINTER_LOG(ability, "null ability");
AppExecFwk::RunningProcessInfo processInfo = {};
DelayedSingleton<AppScheduler>::GetInstance()->GetRunningProcessInfoByToken(ability->GetToken(), processInfo);
if (processInfo.pid_ == 0) {
@@ -1120,9 +1117,8 @@ void UIAbilityLifecycleManager::PrintTimeOutLog(std::shared_ptr<AbilityRecord> a
std::string eventName = isHalf ?
AppExecFwk::AppFreezeType::LIFECYCLE_HALF_TIMEOUT : AppExecFwk::AppFreezeType::LIFECYCLE_TIMEOUT;
TAG_LOGW(AAFwkTag::ABILITYMGR,
"%{public}s: uid: %{public}d, pid: %{public}d, bundleName: %{public}s, abilityName: %{public}s,"
"msg: %{public}s",
TAG_LOGW(AAFwkTag::ABILITYMGR, "%{public}s: uid: %{public}d, pid: %{public}d, bundleName: %{public}s, "
"abilityName: %{public}s, msg: %{public}s",
eventName.c_str(), processInfo.uid_, processInfo.pid_, ability->GetAbilityInfo().bundleName.c_str(),
ability->GetAbilityInfo().name.c_str(), msgContent.c_str());
@@ -1133,8 +1129,8 @@ void UIAbilityLifecycleManager::PrintTimeOutLog(std::shared_ptr<AbilityRecord> a
.bundleName = ability->GetAbilityInfo().bundleName,
};
FreezeUtil::TimeoutState state = MsgId2State(msgId);
FreezeUtil::LifecycleFlow flow;
if (state != FreezeUtil::TimeoutState::UNKNOWN) {
FreezeUtil::LifecycleFlow flow;
if (ability->GetToken() != nullptr) {
flow.token = ability->GetToken()->AsObject();
flow.state = state;
@@ -1143,10 +1139,13 @@ void UIAbilityLifecycleManager::PrintTimeOutLog(std::shared_ptr<AbilityRecord> a
if (!isHalf) {
FreezeUtil::GetInstance().DeleteLifecycleEvent(flow);
}
AppExecFwk::AppfreezeManager::GetInstance()->LifecycleTimeoutHandle(info, flow);
} else {
info.msg = msgContent;
AppExecFwk::AppfreezeManager::GetInstance()->LifecycleTimeoutHandle(info);
}
if (ability->GetFreezeStrategy() == FreezeStrategy::NOTIFY_FREEZE_MGR) {
AppExecFwk::AppfreezeManager::GetInstance()->LifecycleTimeoutHandle(info, flow);
} else {
TAG_LOGW(AAFwkTag::ABILITYMGR, "%{public}s", info.msg.c_str());
}
}
@@ -2612,11 +2611,11 @@ int32_t UIAbilityLifecycleManager::UpdateSessionInfoBySCB(std::list<SessionInfo>
break;
}
}
if (!isFind && codeStartInSCBRecovery_.count(sessionId) == 0) {
if (!isFind && coldStartInSCBRecovery_.count(sessionId) == 0) {
abilitySet.emplace(abilityRecord);
}
}
codeStartInSCBRecovery_.clear();
coldStartInSCBRecovery_.clear();
}
for (const auto &info : sessionInfos) {
sessionIds.emplace_back(info.persistentId);
@@ -2728,7 +2727,7 @@ void UIAbilityLifecycleManager::EnableListForSCBRecovery()
{
std::lock_guard<ffrt::mutex> guard(sessionLock_);
isSCBRecovery_ = true;
codeStartInSCBRecovery_.clear();
coldStartInSCBRecovery_.clear();
}
} // namespace AAFwk
} // namespace OHOS
@@ -417,6 +417,8 @@ public:
virtual bool IsAppKilling(sptr<IRemoteObject> token) override;
virtual void SetAppExceptionCallback(sptr<IRemoteObject> callback) override;
private:
/**
* @brief Judge whether the application service is ready.
+2 -2
View File
@@ -84,9 +84,9 @@ public:
* ScheduleForegroundRunning, call ScheduleForegroundApplication() through proxy project,
* Notify application to switch to foreground.
*
* @return
* @return bool operation status
*/
void ScheduleForegroundRunning();
bool ScheduleForegroundRunning();
/**
* ScheduleBackgroundRunning, call ScheduleBackgroundApplication() through proxy project,
+2 -2
View File
@@ -944,9 +944,9 @@ public:
/**
* ScheduleForegroundRunning, Notify application to switch to foreground.
*
* @return
* @return bool operation status
*/
void ScheduleForegroundRunning();
bool ScheduleForegroundRunning();
/**
* ScheduleBackgroundRunning, Notify application to switch to background.
+21
View File
@@ -22,6 +22,7 @@
#include "accesstoken_kit.h"
#include "app_death_recipient.h"
#include "app_exception_manager.h"
#include "app_mgr_constants.h"
#include "app_utils.h"
#include "hilog_tag_wrapper.h"
@@ -734,5 +735,25 @@ bool AmsMgrScheduler::IsAppKilling(sptr<IRemoteObject> token)
}
return amsMgrServiceInner_->IsAppKilling(token);
}
void AmsMgrScheduler::SetAppExceptionCallback(sptr<IRemoteObject> callback)
{
if (!IsReady()) {
TAG_LOGE(AAFwkTag::APPMGR, "AmsMgrService is not ready.");
return;
}
pid_t callingPid = IPCSkeleton::GetCallingPid();
pid_t procPid = getprocpid();
if (callingPid != procPid) {
TAG_LOGE(AAFwkTag::APPMGR, "not allow other process to call");
return;
}
if (callback == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "callback null");
}
auto exceptionCallback = iface_cast<IAppExceptionCallback>(callback);
return AppExceptionManager::GetInstance().SetExceptionCallback(exceptionCallback);
}
} // namespace AppExecFwk
} // namespace OHOS
+3 -3
View File
@@ -98,16 +98,16 @@ void AppLifeCycleDeal::ScheduleTerminate(bool isLastProcess)
appThread->ScheduleTerminateApplication(isLastProcess);
}
void AppLifeCycleDeal::ScheduleForegroundRunning()
bool AppLifeCycleDeal::ScheduleForegroundRunning()
{
auto appThread = GetApplicationClient();
if (!appThread) {
TAG_LOGE(AAFwkTag::APPMGR, "null appThread");
return;
return false;
}
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
appThread->ScheduleForegroundApplication();
return appThread->ScheduleForegroundApplication();
}
void AppLifeCycleDeal::ScheduleBackgroundRunning()
@@ -1227,13 +1227,14 @@ void AppMgrServiceInner::ApplicationBackgrounded(const int32_t recordId)
TAG_LOGW(AAFwkTag::APPMGR, "app name(%{public}s), app state(%{public}d)",
appRecord->GetName().c_str(), static_cast<ApplicationState>(appRecord->GetState()));
}
if (appRecord->GetApplicationPendingState() == ApplicationPendingState::FOREGROUNDING) {
auto pendingState = appRecord->GetApplicationPendingState();
TAG_LOGI(AAFwkTag::APPMGR, "app backgrounded: %{public}s, pState: %{public}d", appRecord->GetBundleName().c_str(),
pendingState);
if (pendingState == ApplicationPendingState::FOREGROUNDING) {
appRecord->ScheduleForegroundRunning();
} else if (appRecord->GetApplicationPendingState() == ApplicationPendingState::BACKGROUNDING) {
} else if (pendingState == ApplicationPendingState::BACKGROUNDING) {
appRecord->SetApplicationPendingState(ApplicationPendingState::READY);
}
TAG_LOGI(AAFwkTag::APPMGR, "ApplicationBackgrounded, bundle: %{public}s", appRecord->GetBundleName().c_str());
auto eventInfo = BuildEventInfo(appRecord);
AAFwk::EventReport::SendAppBackgroundEvent(AAFwk::EventName::APP_BACKGROUND, eventInfo);
}
+13 -8
View File
@@ -14,6 +14,7 @@
*/
#include "ability_window_configuration.h"
#include "app_exception_manager.h"
#include "app_running_record.h"
#include "app_mgr_service_inner.h"
#include "event_report.h"
@@ -661,12 +662,13 @@ void AppRunningRecord::LaunchPendingAbilities()
moduleRecord->LaunchPendingAbilities();
}
}
void AppRunningRecord::ScheduleForegroundRunning()
bool AppRunningRecord::ScheduleForegroundRunning()
{
SetApplicationScheduleState(ApplicationScheduleState::SCHEDULE_FOREGROUNDING);
if (appLifeCycleDeal_) {
appLifeCycleDeal_->ScheduleForegroundRunning();
return appLifeCycleDeal_->ScheduleForegroundRunning();
}
return false;
}
void AppRunningRecord::ScheduleBackgroundRunning()
@@ -989,8 +991,8 @@ void AppRunningRecord::AbilityForeground(const std::shared_ptr<AbilityRunningRec
return;
}
TAG_LOGI(AAFwkTag::APPMGR, "appState: %{public}d, bundle: %{public}s, ability: %{public}s",
curState_, mainBundleName_.c_str(), ability->GetName().c_str());
TAG_LOGI(AAFwkTag::APPMGR, "appState: %{public}d, pState: %{public}d, bundle: %{public}s, ability: %{public}s",
curState_, pendingState_, mainBundleName_.c_str(), ability->GetName().c_str());
// We need schedule application to foregrounded when current application state is ready or background running.
if (curState_ == ApplicationState::APP_STATE_FOREGROUND
&& pendingState_ != ApplicationPendingState::BACKGROUNDING) {
@@ -1010,11 +1012,14 @@ void AppRunningRecord::AbilityForeground(const std::shared_ptr<AbilityRunningRec
}
if (curState_ == ApplicationState::APP_STATE_READY || curState_ == ApplicationState::APP_STATE_BACKGROUND
|| curState_ == ApplicationState::APP_STATE_FOREGROUND) {
TAG_LOGD(AAFwkTag::APPMGR, "application foregrounding.");
auto pendingState = pendingState_;
SetApplicationPendingState(ApplicationPendingState::FOREGROUNDING);
if (pendingState == ApplicationPendingState::READY) {
ScheduleForegroundRunning();
if (!ScheduleForegroundRunning()) {
AppExceptionManager::GetInstance().ForegroundAppFailed(ability->GetToken(), "schedule failed");
}
} else {
AppExceptionManager::GetInstance().ForegroundAppWait(ability->GetToken(), "pendingState not ready");
}
foregroundingAbilityTokens_.insert(ability->GetToken());
TAG_LOGD(AAFwkTag::APPMGR, "foregroundingAbility size: %{public}d",
@@ -2061,8 +2066,9 @@ void AppRunningRecord::OnWindowVisibilityChanged(
}
}
TAG_LOGI(AAFwkTag::APPMGR, "window id empty: %{public}d, pState: %{public}d, cState: %{public}d",
windowIds_.empty(), pendingState_, curState_);
if (pendingState_ == ApplicationPendingState::READY) {
TAG_LOGD(AAFwkTag::APPMGR, "pending state is READY.");
if (!windowIds_.empty() && curState_ != ApplicationState::APP_STATE_FOREGROUND) {
SetApplicationPendingState(ApplicationPendingState::FOREGROUNDING);
ScheduleForegroundRunning();
@@ -2072,7 +2078,6 @@ void AppRunningRecord::OnWindowVisibilityChanged(
ScheduleBackgroundRunning();
}
} else {
TAG_LOGI(AAFwkTag::APPMGR, "not READY");
if (!windowIds_.empty()) {
SetApplicationPendingState(ApplicationPendingState::FOREGROUNDING);
}
@@ -16,6 +16,8 @@
#ifndef ABILITY_ABILITY_RUNTIME_UPMS_POLICY_INFO_H
#define ABILITY_ABILITY_RUNTIME_UPMS_POLICY_INFO_H
#include <string>
namespace OHOS {
namespace AAFwk {
struct PolicyInfo final {
@@ -42,9 +42,11 @@ public:
AbilitySchedulerStubFuzzTest() = default;
virtual ~AbilitySchedulerStubFuzzTest()
{};
void ScheduleAbilityTransaction(const Want& want, const LifeCycleStateInfo& targetState,
bool ScheduleAbilityTransaction(const Want& want, const LifeCycleStateInfo& targetState,
sptr<SessionInfo> sessionInfo = nullptr) override
{}
{
return true;
}
void ScheduleShareData(const int32_t &uniqueId) override
{}
void SendResult(int requestCode, int resultCode, const Want& resultWant) override
@@ -39,9 +39,11 @@ public:
AbilitySchedulerFuzzTest() = default;
virtual ~AbilitySchedulerFuzzTest()
{};
void ScheduleAbilityTransaction(const Want& want, const LifeCycleStateInfo& targetState,
bool ScheduleAbilityTransaction(const Want& want, const LifeCycleStateInfo& targetState,
sptr<SessionInfo> sessionInfo = nullptr) override
{}
{
return true;
}
void ScheduleShareData(const int32_t &uniqueId) override
{}
void SendResult(int requestCode, int resultCode, const Want& resultWant) override
@@ -48,8 +48,11 @@ public:
class MockAbilityThread : public IRemoteStub<AAFwk::IAbilityScheduler> {
public:
virtual void ScheduleAbilityTransaction(const Want& want, const LifeCycleStateInfo& targetState,
sptr<SessionInfo> sessionInfo = nullptr) {};
virtual bool ScheduleAbilityTransaction(const Want& want, const LifeCycleStateInfo& targetState,
sptr<SessionInfo> sessionInfo = nullptr)
{
return true;
}
virtual void SendResult(int requestCode, int resultCode, const Want& resultWant) {};
virtual void ScheduleConnectAbility(const Want& want) {};
virtual void ScheduleDisconnectAbility(const Want& want) {};

Some files were not shown because too many files have changed in this diff Show More