mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2025-04-01 06:53:22 +00:00
adapt to background task
Signed-off-by: lanshouren <lanshouren@huawei.com> Change-Id: Iafe18b788d20b0ca0ff1d2f057f8f4a5ad6484b2
This commit is contained in:
parent
bad640936f
commit
cd71ac34cc
@ -136,6 +136,7 @@ template("ace_osal_ohos_source_set") {
|
||||
external_deps += [ "multimedia_image:image" ]
|
||||
}
|
||||
sources += [
|
||||
"background_task_helper_ohos.cpp",
|
||||
"drawing_color_filter_ohos.cpp",
|
||||
"file_uri_helper_ohos.cpp",
|
||||
"image_packer_ohos.cpp",
|
||||
@ -150,7 +151,9 @@ template("ace_osal_ohos_source_set") {
|
||||
external_deps += [
|
||||
"ability_runtime:abilitykit_native",
|
||||
"ability_runtime:app_manager",
|
||||
"ability_runtime:wantagent_innerkits",
|
||||
"app_file_service:fileuri_native",
|
||||
"background_task_mgr:bgtaskmgr_innerkits",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"graphic_2d:2d_graphics",
|
||||
"graphic_2d:drawing_napi_impl",
|
||||
|
62
adapter/ohos/osal/background_task_helper_ohos.cpp
Normal file
62
adapter/ohos/osal/background_task_helper_ohos.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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 "background_task_helper_ohos.h"
|
||||
|
||||
#include "background_mode.h"
|
||||
#include "background_task_mgr_helper.h"
|
||||
#include "continuous_task_callback_info.h"
|
||||
|
||||
#include "core/common/ace_application_info.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
|
||||
BackgroundTaskHelper& BackgroundTaskHelper::GetInstance()
|
||||
{
|
||||
static BackgroundTaskHelperOhos instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
bool BackgroundTaskHelperOhos::HasBackgroundTask()
|
||||
{
|
||||
int32_t creatorUid = AceApplicationInfo::GetInstance().GetUid();
|
||||
uint32_t backgroundMode = BackgroundTaskMgr::BackgroundMode::AUDIO_PLAYBACK;
|
||||
|
||||
std::vector<std::shared_ptr<BackgroundTaskMgr::ContinuousTaskCallbackInfo>> continuousTaskList;
|
||||
ErrCode code = BackgroundTaskMgr::BackgroundTaskMgrHelper::GetContinuousTaskApps(continuousTaskList);
|
||||
if (code != OHOS::ERR_OK) {
|
||||
TAG_LOGW(AceLogTag::ACE_VIDEO, "uid=%{public}d no continuous task list, code=%{public}d", creatorUid, code);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const auto &task : continuousTaskList) {
|
||||
TAG_LOGW(AceLogTag::ACE_VIDEO, "uid=%{public}d taskCreatorUid=%{public}d", creatorUid, task->GetCreatorUid());
|
||||
if (task->GetCreatorUid() != creatorUid) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::vector<uint32_t> bgModeIds = task->GetTypeIds();
|
||||
auto it = std::find_if(bgModeIds.begin(), bgModeIds.end(), [ backgroundMode ](auto mode) {
|
||||
return (mode == backgroundMode);
|
||||
});
|
||||
if (it != bgModeIds.end()) {
|
||||
TAG_LOGW(AceLogTag::ACE_VIDEO, "uid=%{public}d is audio playback", creatorUid);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace
|
32
adapter/ohos/osal/background_task_helper_ohos.h
Normal file
32
adapter/ohos/osal/background_task_helper_ohos.h
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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 FOUNDATION_ACE_ADAPTER_OHOS_OSAL_BACKGROUND_TASK_HELPER_OHOS_H
|
||||
#define FOUNDATION_ACE_ADAPTER_OHOS_OSAL_BACKGROUND_TASK_HELPER_OHOS_H
|
||||
|
||||
#include "base/background_task_helper/background_task_helper.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
|
||||
class BackgroundTaskHelperOhos : public BackgroundTaskHelper {
|
||||
DECLARE_ACE_TYPE(BackgroundTaskHelperOhos, BackgroundTaskHelper);
|
||||
|
||||
public:
|
||||
bool HasBackgroundTask() override;
|
||||
};
|
||||
|
||||
} // namespace OHOS::Ace
|
||||
|
||||
#endif // FOUNDATION_ACE_ADAPTER_OHOS_OSAL_BACKGROUND_TASK_HELPER_OHOS_H
|
@ -89,7 +89,8 @@
|
||||
"opengles",
|
||||
"zlib",
|
||||
"skia",
|
||||
"libuv"
|
||||
"libuv",
|
||||
"background_task_mgr"
|
||||
],
|
||||
"third_party": []
|
||||
},
|
||||
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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 FOUNDATION_ACE_FRAMEWORKS_BASE_BACKGROUND_TASK_HELPER_H
|
||||
#define FOUNDATION_ACE_FRAMEWORKS_BASE_BACKGROUND_TASK_HELPER_H
|
||||
|
||||
#include "base/utils/macros.h"
|
||||
#include "base/memory/ace_type.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
|
||||
class ACE_FORCE_EXPORT BackgroundTaskHelper : public virtual AceType {
|
||||
DECLARE_ACE_TYPE(BackgroundTaskHelper, AceType);
|
||||
public:
|
||||
static BackgroundTaskHelper& GetInstance();
|
||||
|
||||
virtual bool HasBackgroundTask() = 0;
|
||||
};
|
||||
|
||||
} // namespace OHOS::Ace
|
||||
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_BASE_BACKGROUND_TASK_HELPER_H
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "video_node.h"
|
||||
|
||||
#include "base/background_task_helper/background_task_helper.h"
|
||||
#include "base/geometry/dimension.h"
|
||||
#include "base/geometry/ng/size_t.h"
|
||||
#include "base/i18n/localization.h"
|
||||
@ -727,6 +728,9 @@ void VideoPattern::OnAttachToFrameNode()
|
||||
}
|
||||
auto host = GetHost();
|
||||
CHECK_NULL_VOID(host);
|
||||
auto pipeline = host->GetContext();
|
||||
CHECK_NULL_VOID(pipeline);
|
||||
pipeline->AddWindowStateChangedCallback(host->GetId());
|
||||
auto renderContext = host->GetRenderContext();
|
||||
CHECK_NULL_VOID(renderContext);
|
||||
|
||||
@ -751,6 +755,15 @@ void VideoPattern::OnAttachToFrameNode()
|
||||
renderContext->SetClipToBounds(true);
|
||||
}
|
||||
|
||||
void VideoPattern::OnDetachFromFrameNode(FrameNode* frameNode)
|
||||
{
|
||||
CHECK_NULL_VOID(frameNode);
|
||||
auto id = frameNode->GetId();
|
||||
auto pipeline = frameNode->GetContext();
|
||||
CHECK_NULL_VOID(pipeline);
|
||||
pipeline->RemoveWindowStateChangedCallback(id);
|
||||
}
|
||||
|
||||
void VideoPattern::OnDetachFromMainTree()
|
||||
{
|
||||
auto host = GetHost();
|
||||
@ -1810,4 +1823,16 @@ bool VideoPattern::GetAnalyzerState()
|
||||
CHECK_NULL_RETURN(imageAnalyzerManager_, false);
|
||||
return imageAnalyzerManager_->IsOverlayCreated();
|
||||
}
|
||||
|
||||
void VideoPattern::OnWindowHide()
|
||||
{
|
||||
#if defined(OHOS_PLATFORM)
|
||||
if (!BackgroundTaskHelper::GetInstance().HasBackgroundTask()) {
|
||||
Pause();
|
||||
}
|
||||
#else
|
||||
Pause();
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
@ -266,10 +266,12 @@ protected:
|
||||
|
||||
private:
|
||||
void OnAttachToFrameNode() override;
|
||||
void OnDetachFromFrameNode(FrameNode* frameNode) override;
|
||||
void OnDetachFromMainTree() override;
|
||||
void OnModifyDone() override;
|
||||
bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
|
||||
void OnRebuildFrame() override;
|
||||
void OnWindowHide() override;
|
||||
|
||||
// Set properties for media player.
|
||||
void PrepareMediaPlayer();
|
||||
|
Loading…
x
Reference in New Issue
Block a user