优化session管理:

-拆分napi和native
-对外接口隔离

Signed-off-by: xiahaiqin <xiahaiqin1@huawei.com>
Change-Id: I663b2924749efb81c47ea2b994a902b2953485f7
This commit is contained in:
xiahaiqin 2022-12-14 15:30:56 +08:00
parent 0e5ea42a0a
commit dc3934a72f
29 changed files with 180 additions and 141 deletions

View File

@ -60,7 +60,8 @@
"//foundation/window/window_manager/snapshot:snapshot_display",
"//foundation/window/window_manager/interfaces/kits/napi/window_runtime/window_stage_napi:windowstage",
"//foundation/window/window_manager/interfaces/kits/napi:napi_packages",
"//foundation/window/window_manager/resources:window_resources"
"//foundation/window/window_manager/resources:window_resources",
"//foundation/window/window_manager/window_scene/interfaces/kits/napi/host:window_scene_napi"
],
"fwk_group": [
"//foundation/window/window_manager/interfaces/kits/js/declaration:window",
@ -69,7 +70,8 @@
"//foundation/window/window_manager/extension/window_extension:libwindow_extension",
"//foundation/window/window_manager/extension/window_extension:window_extension_module",
"//foundation/window/window_manager/wm:libwm",
"//foundation/window/window_manager/utils:libwmutil"
"//foundation/window/window_manager/utils:libwmutil",
"//foundation/window/window_manager/window_scene:window_scene"
],
"service_group": [
"//foundation/window/window_manager/sa_profile:wms_sa_profile",

View File

@ -24,6 +24,6 @@ group("napi_packages") {
"window_runtime:window_napi",
"window_runtime:window_native_kit",
"window_runtime:windowstage_kit",
"window_scene:window_scene_napi",
"//foundation/window/window_manager/window_scene/interfaces/kits/napi/host:window_scene_napi",
]
}

View File

@ -25,8 +25,9 @@ config("window_scene_private_config") {
config("window_scene_public_config") {
include_dirs = [
"interfaces/innerkits",
"interfaces/kits/napi/host",
"utils/include",
"session/container/include",
"session/host/include",
]
}
@ -43,9 +44,6 @@ ohos_shared_library("window_scene") {
"session/host/src/session.cpp",
"session/host/src/zidl/scene_session_proxy.cpp",
"session/host/src/zidl/scene_session_stub.cpp",
"interfaces/kits/napi/host/js_scene_session_manager.cpp",
"interfaces/kits/napi/host/js_scene_session.cpp",
"interfaces/kits/napi/host/js_scene_utils.cpp",
]
cflags_cc = [ "-std=c++17" ]
@ -60,11 +58,8 @@ ohos_shared_library("window_scene") {
"hilog_native:libhilog",
"input:libmmi-client",
"ipc:ipc_core",
"napi:ace_napi",
"ability_runtime:runtime",
]
relative_install_dir = "module"
part_name = "window_manager"
subsystem_name = "window"
}

View File

@ -17,9 +17,9 @@
#define OHOS_SCENE_SESSION_INTERFACE_H
#include "zidl/session_interface.h"
#include "zidl/scene_session_stage_interface.h"
#include "scene_session_stage_interface.h"
#include "window_scene_common.h"
#include "zidl/window_event_channel_interface.h"
#include "window_event_channel_interface.h"
namespace OHOS::Rosen {
class ISceneSession : public ISession {

View File

@ -16,7 +16,7 @@
#ifndef OHOS_SCEEN_SESSION_STAGE_INTERFACE_H
#define OHOS_SCEEN_SESSION_STAGE_INTERFACE_H
#include "zidl/session_stage_interface.h"
#include "session_stage_interface.h"
#include "window_scene_common.h"
namespace OHOS::Rosen {

View File

@ -18,10 +18,12 @@
#include <string>
#include <refbase.h>
#include <ui/rs_surface_node.h>
#include "window_scene_common.h"
namespace OHOS::Rosen {
class RSSurfaceNode;
class Session {
public:
Session(const std::string& name);
@ -39,7 +41,7 @@ protected:
bool IsSessionValid() const;
private:
RSSurfaceNode::SharedPtr CreateSurfaceNode(std::string name);
std::shared_ptr<RSSurfaceNode> CreateSurfaceNode(std::string name);
uint32_t persistentId_ = INVALID_SESSION_ID;
std::shared_ptr<RSSurfaceNode> surfaceNode_ = nullptr;

View File

@ -20,7 +20,7 @@
#include <mutex>
#include <i_input_event_consumer.h>
#include "window_scene_common.h"
#include "zidl/window_event_channel_interface.h"
#include "window_event_channel_interface.h"
namespace OHOS::Rosen {
class ISessionStateListener {

View File

@ -18,9 +18,12 @@
#include <iremote_broker.h>
#include "window_scene_common.h"
#include "axis_event.h"
#include "key_event.h"
#include "pointer_event.h"
namespace OHOS::MMI {
class PointerEvent;
class KeyEvent;
class AxisEvent;
}
namespace OHOS::Rosen {
class IWindowEventChannel : public IRemoteBroker {

View File

@ -13,9 +13,33 @@
import("//build/ohos.gni")
config("window_scene_napi_private_config") {
visibility = [ ":*" ]
include_dirs =
[ "//foundation/window/window_manager/window_scene/interfaces/kits/napi/host", ]
}
ohos_shared_library("window_scene_napi") {
sources = [
"js_scene_session.cpp",
"js_scene_session_manager.cpp",
"js_scene_utils.cpp",
]
cflags_cc = [ "-std=c++17" ]
configs = [ ":window_scene_napi_private_config" ]
deps = [
"//foundation/window/window_manager/window_scene:window_scene"
]
external_deps = [
"c_utils:utils",
"ability_runtime:runtime",
"hilog_native:libhilog",
"ipc:ipc_core",
"napi:ace_napi",
]
relative_install_dir = "module"

View File

@ -29,15 +29,14 @@ namespace {
const std::string START_SCENE_CB = "startScene";
}
NativeValue* CreateJsSceneSessionObject(NativeEngine& engine, const sptr<SceneSession>& session,
const std::shared_ptr<JsSceneSession>& jsSceneSession)
NativeValue* CreateJsSceneSessionObject(NativeEngine& engine, const sptr<SceneSession>& session)
{
NativeValue* objValue = engine.CreateObject();
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
WLOGFI("[NAPI]CreateJsSceneSession");
object->SetNativePointer(new std::weak_ptr<JsSceneSession>(jsSceneSession), JsSceneSession::Finalizer, nullptr);
std::unique_ptr<JsSceneSession> jsSceneSession = std::make_unique<JsSceneSession>(&engine, session);
object->SetNativePointer(jsSceneSession.release(), JsSceneSession::Finalizer, nullptr);
object->SetProperty("abilityInfo", CreateJsAbilityInfo(engine, session));
object->SetProperty("persistentId", CreateJsValue(engine, session->GetPersistentId()));
BindFunctions(engine, object, "JsSceneSession");
@ -47,7 +46,7 @@ NativeValue* CreateJsSceneSessionObject(NativeEngine& engine, const sptr<SceneSe
void JsSceneSession::Finalizer(NativeEngine* engine, void* data, void* hint)
{
WLOGFI("[NAPI]Finalizer");
delete static_cast<std::weak_ptr<JsSceneSession>*>(data);
std::unique_ptr<JsSceneSession>(static_cast<JsSceneSession*>(data));
}
void BindFunctions(NativeEngine& engine, NativeObject* object, const char *moduleName)
@ -79,39 +78,60 @@ NativeValue* JsSceneSession::OnRegisterCallback(NativeEngine& engine, NativeCall
}
NativeValue* value = info.argv[1];
if (!value->IsCallable()) {
WLOGFI("[NAPI]Callback(info->argv[1]) is not callable");
WLOGFE("[NAPI]Callback(info->argv[1]) is not callable");
engine.Throw(CreateJsError(engine, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
"Input parameter is missing or invalid"));
return engine.CreateUndefined();
}
if (IsCallbackRegistered(cbType, value)) {
return engine.CreateUndefined();
}
if (session_ == nullptr) {
WLOGFE("[NAPI]session_ is nullptr");
engine.Throw(CreateJsError(engine, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
"Input parameter is missing or invalid"));
return engine.CreateUndefined();
}
std::weak_ptr<JsSceneSession> sessionWptr(shared_from_this());
NotifyStartSceneFunc func = [sessionWptr](const sptr<SceneSession>& session) {
auto jsSceneSession = sessionWptr.lock();
if (jsSceneSession == nullptr || session == nullptr) {
WLOGFE("[NAPI]this scene session or target session is nullptr");
return;
}
jsSceneSession->StartScene(session);
};
session_->RegisterStartSceneEventListener(func);
std::shared_ptr<NativeReference> callbackRef;
callbackRef.reset(engine.CreateReference(value, 1));
jsCbMap_.insert(std::make_pair(cbType, callbackRef));
jsCbMap_[cbType] = callbackRef;
WLOGFI("[NAPI]Register end, type = %{public}s, callback = %{public}p", cbType.c_str(), value);
return engine.CreateUndefined();
}
void JsSceneSession::StartScene(const sptr<SceneSession>& session)
{
if (jsCbMap_.find(START_SCENE_CB) == jsCbMap_.end()) {
auto iter = jsCbMap_.find(START_SCENE_CB);
if (iter == jsCbMap_.end()) {
return;
}
jsCallBack_ = jsCbMap_[START_SCENE_CB];
jsCallBack_ = iter->second;
WLOGFI("[NAPI]start scene: name = %{public}s, id = %{public}u", session->GetAbilityInfo().abilityName_.c_str(),
session->GetPersistentId());
std::weak_ptr<JsSceneSession> sessionWptr(shared_from_this());
auto complete = std::make_unique<AsyncTask::CompleteCallback> (
[sessionWptr, session, eng = engine_](NativeEngine& engine, AsyncTask& task, int32_t status) {
auto jsSceneSession = sessionWptr.lock();
if (jsSceneSession == nullptr || eng == nullptr || session) {
if (jsSceneSession == nullptr || eng == nullptr || session == nullptr) {
WLOGFE("[NAPI]this scene session or target session or engine is nullptr");
return;
}
auto jsSceneSessionRef = session->GetJsSceneSessionRef();
if (jsSceneSessionRef == nullptr) {
NativeValue* jsSceneSessionObj = CreateJsSceneSessionObject(*eng, session);
if (jsSceneSessionObj == nullptr) {
WLOGFE("[NAPI]this target session reference is nullptr");
}
NativeValue* argv[] = { jsSceneSessionRef->Get() };
NativeValue* argv[] = { jsSceneSessionObj };
jsSceneSession->CallJsMethod(START_SCENE_CB.c_str(), argv, ArraySize(argv));
}
);
@ -136,4 +156,25 @@ void JsSceneSession::CallJsMethod(const char* methodName, NativeValue* const* ar
}
engine_->CallFunction(engine_->CreateUndefined(), method, argv, argc);
}
bool JsSceneSession::IsCallbackRegistered(std::string type, NativeValue* jsListenerObject)
{
if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) {
WLOGFI("[NAPI]Method %{public}s has not been registered", type.c_str());
return false;
}
for (auto iter = jsCbMap_.begin(); iter != jsCbMap_.end(); ++iter) {
if (jsListenerObject->StrictEquals(iter->second->Get())) {
WLOGFE("[NAPI]Method %{public}s has already been registered", type.c_str());
return true;
}
}
return false;
}
sptr<SceneSession> JsSceneSession::GetNativeSession() const
{
return session_;
}
}

View File

@ -16,6 +16,7 @@
#ifndef OHOS_JS_SCENE_SESSION_H
#define OHOS_JS_SCENE_SESSION_H
#include <memory>
#include <map>
#include <string>
#include <refbase.h>
@ -27,25 +28,27 @@ namespace OHOS::Rosen {
class SceneSession;
class JsSceneSession final : public std::enable_shared_from_this<JsSceneSession> {
public:
explicit JsSceneSession(NativeEngine* engine) : engine_(engine) {}
explicit JsSceneSession(NativeEngine* engine, sptr<SceneSession> session) : engine_(engine), session_(session) {}
~JsSceneSession() = default;
static void Finalizer(NativeEngine* engine, void* data, void* hint);
static NativeValue* RegisterCallback(NativeEngine* engine, NativeCallbackInfo* info);
void StartScene(const sptr<SceneSession>& session);
sptr<SceneSession> GetNativeSession() const;
private:
NativeValue* OnRegisterCallback(NativeEngine& engine, NativeCallbackInfo& info);
void CallJsMethod(const char* methodName, NativeValue* const* argv, size_t argc);
bool IsCallbackRegistered(std::string type, NativeValue* jsListenerObject);
std::map<std::string, std::shared_ptr<NativeReference>> jsCbMap_;
NativeEngine* engine_ = nullptr;
sptr<SceneSession> session_ = nullptr;
std::map<std::string, std::shared_ptr<NativeReference>> jsCbMap_;
std::shared_ptr<NativeReference> jsCallBack_ = nullptr;
};
NativeValue* CreateJsSceneSessionObject(NativeEngine& engine, const sptr<SceneSession>& session,
const std::shared_ptr<JsSceneSession>& jsSceneSession);
NativeValue* CreateJsSceneSessionObject(NativeEngine& engine, const sptr<SceneSession>& session);
void BindFunctions(NativeEngine& engine, NativeObject* object, const char *moduleName);
}
#endif // OHOS_JS_SCENE_SESSION_H

View File

@ -18,6 +18,7 @@
#include <memory>
#include <js_runtime_utils.h>
#include "js_scene_session.h"
#include "window_scene_hilog.h"
#include "scene_session_manager.h"
#include "js_scene_utils.h"
@ -132,23 +133,23 @@ NativeValue* JsSceneSessionManager::OnRequestSceneSession(NativeEngine& engine,
}
WLOGFI("[NAPI]Ability name = %{public}s, option = %{public}u, err = %{public}d", abilityInfo.abilityName_.c_str(),
static_cast<uint32_t>(sessionOption), errCode);
sptr<SceneSession> sceneSession = SceneSessionManager::GetInstance().RequestSceneSession(abilityInfo,
sessionOption, engine);
sptr<SceneSession> sceneSession = SceneSessionManager::GetInstance().RequestSceneSession(abilityInfo, sessionOption);
if (sceneSession == nullptr) {
engine.Throw(CreateJsError(engine, static_cast<int32_t>(WSErrorCode::WS_ERROR_STATE_ABNORMALLY),
"System is abnormal"));
return engine.CreateUndefined();
} else {
auto jsSceneSessionRef = sceneSession->GetJsSceneSessionRef();
if (jsSceneSessionRef == nullptr) {
WLOGFE("[NAPI]Ability name = %{public}s, jsSceneSessionRef is nullptr", abilityInfo.abilityName_.c_str());
NativeValue* jsSceneSessionObj = CreateJsSceneSessionObject(engine, sceneSession);
if (jsSceneSessionObj == nullptr) {
WLOGFE("[NAPI]Ability name = %{public}s, jsSceneSessionObj is nullptr", abilityInfo.abilityName_.c_str());
engine.Throw(CreateJsError(engine, static_cast<int32_t>(WSErrorCode::WS_ERROR_STATE_ABNORMALLY),
"System is abnormal"));
}
return jsSceneSessionRef->Get();
return jsSceneSessionObj;
}
}
NativeValue* JsSceneSessionManager::OnRequestSceneSessionActivation(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("[NAPI]OnRequestSceneSessionActivation");
@ -158,15 +159,15 @@ NativeValue* JsSceneSessionManager::OnRequestSceneSessionActivation(NativeEngine
errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
}
sptr<SceneSession> sceneSession = nullptr;
SceneSession* sceneSession = nullptr;
if (errCode == WSErrorCode::WS_OK) {
// find scene session
NativeValue* jsSceneSessionObj = info.argv[0];
auto jsSceneSessionObj = ConvertNativeValueTo<NativeObject>(info.argv[0]);
if (jsSceneSessionObj == nullptr) {
WLOGFE("[NAPI]Failed to get js scene session value");
WLOGFE("[NAPI]Failed to get js scene session object");
errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
} else {
sceneSession = SceneSessionManager::GetInstance().FindSceneSession(jsSceneSessionObj);
sceneSession = static_cast<SceneSession*>(jsSceneSessionObj->GetNativePointer());
if (sceneSession == nullptr) {
WLOGFE("[NAPI]Failed to find scene session From Js Object");
errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
@ -182,18 +183,16 @@ NativeValue* JsSceneSessionManager::OnRequestSceneSessionActivation(NativeEngine
WLOGFI("[NAPI]RequestSceneSessionActivation: ability name = %{public}s",
sceneSession->GetAbilityInfo().abilityName_.c_str());
wptr<SceneSession> sceneSessionToken(sceneSession);
AsyncTask::CompleteCallback complete =
[sceneSessionToken](NativeEngine& engine, AsyncTask& task, int32_t status) {
auto weakSceneSession = sceneSessionToken.promote();
if (weakSceneSession == nullptr) {
[sceneSession](NativeEngine& engine, AsyncTask& task, int32_t status) {
if (sceneSession == nullptr) {
task.Reject(engine,
CreateJsError(engine, static_cast<int32_t>(WSErrorCode::WS_ERROR_STATE_ABNORMALLY),
"Invalidate params."));
return;
}
WSErrorCode ret = WS_JS_TO_ERROR_CODE_MAP.at(
SceneSessionManager::GetInstance().RequestSceneSessionActivation(weakSceneSession));
SceneSessionManager::GetInstance().RequestSceneSessionActivation(sceneSession));
if (ret == WSErrorCode::WS_OK) {
task.Resolve(engine, engine.CreateUndefined());
} else {
@ -201,7 +200,7 @@ NativeValue* JsSceneSessionManager::OnRequestSceneSessionActivation(NativeEngine
"Request scene session activation failed"));
}
WLOGFI("[NAPI]Session [%{public}s] request scene session activation end",
weakSceneSession->GetAbilityInfo().abilityName_.c_str());
sceneSession->GetAbilityInfo().abilityName_.c_str());
};
NativeValue* lastParam = (info.argc <= 1) ? nullptr :
@ -222,15 +221,15 @@ NativeValue* JsSceneSessionManager::OnRequestSceneSessionBackground(NativeEngine
errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
}
sptr<SceneSession> sceneSession = nullptr;
SceneSession* sceneSession = nullptr;
if (errCode == WSErrorCode::WS_OK) {
// find scene session
NativeValue* jsSceneSessionObj = info.argv[0];
auto jsSceneSessionObj = ConvertNativeValueTo<NativeObject>(info.argv[0]);
if (jsSceneSessionObj == nullptr) {
WLOGFE("[NAPI]Failed to get js scene session value");
WLOGFE("[NAPI]Failed to get js scene session object");
errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
} else {
sceneSession = SceneSessionManager::GetInstance().FindSceneSession(jsSceneSessionObj);
sceneSession = static_cast<SceneSession*>(jsSceneSessionObj->GetNativePointer());
if (sceneSession == nullptr) {
WLOGFE("[NAPI]Failed to find scene session From Js Object");
errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
@ -246,18 +245,16 @@ NativeValue* JsSceneSessionManager::OnRequestSceneSessionBackground(NativeEngine
WLOGFI("[NAPI]RequestSceneSessionBackground: ability name = %{public}s",
sceneSession->GetAbilityInfo().abilityName_.c_str());
wptr<SceneSession> sceneSessionToken(sceneSession);
AsyncTask::CompleteCallback complete =
[sceneSessionToken](NativeEngine& engine, AsyncTask& task, int32_t status) {
auto weakSceneSession = sceneSessionToken.promote();
if (weakSceneSession == nullptr) {
[sceneSession](NativeEngine& engine, AsyncTask& task, int32_t status) {
if (sceneSession == nullptr) {
task.Reject(engine,
CreateJsError(engine, static_cast<int32_t>(WSErrorCode::WS_ERROR_STATE_ABNORMALLY),
"Invalidate params."));
return;
}
WSErrorCode ret = WS_JS_TO_ERROR_CODE_MAP.at(
SceneSessionManager::GetInstance().RequestSceneSessionBackground(weakSceneSession));
SceneSessionManager::GetInstance().RequestSceneSessionBackground(sceneSession));
if (ret == WSErrorCode::WS_OK) {
task.Resolve(engine, engine.CreateUndefined());
} else {
@ -265,7 +262,7 @@ NativeValue* JsSceneSessionManager::OnRequestSceneSessionBackground(NativeEngine
"Request scene session background failed"));
}
WLOGFI("[NAPI]Session [%{public}s] request scene session background end",
weakSceneSession->GetAbilityInfo().abilityName_.c_str());
sceneSession->GetAbilityInfo().abilityName_.c_str());
};
NativeValue* lastParam = (info.argc <= 1) ? nullptr :
@ -286,15 +283,15 @@ NativeValue* JsSceneSessionManager::OnRequestSceneSessionDestruction(NativeEngin
errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
}
sptr<SceneSession> sceneSession = nullptr;
SceneSession* sceneSession = nullptr;
if (errCode == WSErrorCode::WS_OK) {
// find scene session
NativeValue* jsSceneSessionObj = info.argv[0];
auto jsSceneSessionObj = ConvertNativeValueTo<NativeObject>(info.argv[0]);
if (jsSceneSessionObj == nullptr) {
WLOGFE("[NAPI]Failed to get js scene session value");
WLOGFE("[NAPI]Failed to get js scene session object");
errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
} else {
sceneSession = SceneSessionManager::GetInstance().FindSceneSession(jsSceneSessionObj);
sceneSession = static_cast<SceneSession*>(jsSceneSessionObj->GetNativePointer());
if (sceneSession == nullptr) {
WLOGFE("[NAPI]Failed to find scene session From Js Object");
errCode = WSErrorCode::WS_ERROR_INVALID_PARAM;
@ -310,18 +307,16 @@ NativeValue* JsSceneSessionManager::OnRequestSceneSessionDestruction(NativeEngin
WLOGFI("[NAPI]OnRequestSceneSessionDestruction: ability name = %{public}s",
sceneSession->GetAbilityInfo().abilityName_.c_str());
wptr<SceneSession> sceneSessionToken(sceneSession);
AsyncTask::CompleteCallback complete =
[sceneSessionToken](NativeEngine& engine, AsyncTask& task, int32_t status) {
auto weakSceneSession = sceneSessionToken.promote();
if (weakSceneSession == nullptr) {
[sceneSession](NativeEngine& engine, AsyncTask& task, int32_t status) {
if (sceneSession == nullptr) {
task.Reject(engine,
CreateJsError(engine, static_cast<int32_t>(WSErrorCode::WS_ERROR_STATE_ABNORMALLY),
"Invalidate params."));
return;
}
WSErrorCode ret = WS_JS_TO_ERROR_CODE_MAP.at(
SceneSessionManager::GetInstance().RequestSceneSessionBackground(weakSceneSession));
SceneSessionManager::GetInstance().RequestSceneSessionBackground(sceneSession));
if (ret == WSErrorCode::WS_OK) {
task.Resolve(engine, engine.CreateUndefined());
} else {
@ -329,7 +324,7 @@ NativeValue* JsSceneSessionManager::OnRequestSceneSessionDestruction(NativeEngin
"Request scene session destruction failed"));
}
WLOGFI("[NAPI]Session [%{public}s] request scene session destruction end",
weakSceneSession->GetAbilityInfo().abilityName_.c_str());
sceneSession->GetAbilityInfo().abilityName_.c_str());
};
NativeValue* lastParam = (info.argc <= 1) ? nullptr :

View File

@ -16,6 +16,7 @@
#include "js_scene_utils.h"
#include <js_runtime_utils.h>
#include "window_scene_hilog.h"
#include "window_scene_common.h"

View File

@ -19,8 +19,9 @@
#include <js_runtime_utils.h>
#include <native_engine/native_value.h>
#include <native_engine/native_engine.h>
#include "scene_session.h"
#include "scene_session.h"
#include "window_scene_common.h"
namespace OHOS::Rosen {
bool GetAbilityInfoFromJs(NativeEngine& engine, NativeObject* jsObject,
AbilityInfo& abilityInfo);

View File

@ -17,6 +17,7 @@
#define OHOS_WINDOW_EVENT_CHANNEL_H
#include "zidl/window_event_channel_stub.h"
#include "window_scene_common.h"
namespace OHOS::Rosen {

View File

@ -18,7 +18,7 @@
#include <iremote_proxy.h>
#include "zidl/scene_session_stage_interface.h"
#include "scene_session_stage_interface.h"
#include "window_scene_common.h"
namespace OHOS::Rosen {

View File

@ -18,7 +18,7 @@
#include <map>
#include <iremote_stub.h>
#include "zidl/scene_session_stage_interface.h"
#include "scene_session_stage_interface.h"
namespace OHOS::Rosen {
class SceneSessionStageStub;

View File

@ -18,7 +18,7 @@
#include <iremote_proxy.h>
#include "zidl/window_event_channel_interface.h"
#include "window_event_channel_interface.h"
#include "window_scene_common.h"
namespace OHOS::Rosen {

View File

@ -18,7 +18,7 @@
#include <map>
#include <iremote_stub.h>
#include "zidl/window_event_channel_interface.h"
#include "window_event_channel_interface.h"
namespace OHOS::Rosen {
class WindowEventChannelStub;

View File

@ -12,3 +12,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "window_event_channel.h"
#include <axis_event.h>
#include <key_event.h>
#include <pointer_event.h>

View File

@ -16,6 +16,9 @@
#include <ipc_types.h>
#include <message_option.h>
#include <message_parcel.h>
#include <axis_event.h>
#include <key_event.h>
#include <pointer_event.h>
#include "window_scene_hilog.h"
namespace OHOS::Rosen {

View File

@ -15,6 +15,9 @@
#include "zidl/window_event_channel_stub.h"
#include <ipc_types.h>
#include <axis_event.h>
#include <key_event.h>
#include <pointer_event.h>
#include "window_scene_hilog.h"
namespace OHOS::Rosen {

View File

@ -17,18 +17,20 @@
#define OHOS_SCENE_SESSION_H
#include "zidl/scene_session_stub.h"
#include "session.h"
#include "js_scene_session.h"
#include "zidl/scene_session_stage_interface.h"
#include "foundation/window/window_manager/window_scene/interfaces/innerkits/session.h"
#include "scene_session_stage_interface.h"
#include "window_scene_common.h"
namespace OHOS::Rosen {
class SceneSession : public SceneSessionStub, public Session{
class SceneSession;
using NotifyStartSceneFunc = std::function<void(const sptr<SceneSession>& session)>;
class SceneSession : public SceneSessionStub, public Session {
public:
explicit SceneSession(const AbilityInfo& info, NativeEngine& engine);
explicit SceneSession(const AbilityInfo& info);
~SceneSession() = default;
virtual WSError Connect(const sptr<ISceneSessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel) override;
virtual WSError Connect(const sptr<ISceneSessionStage>& sessionStage,
const sptr<IWindowEventChannel>& eventChannel) override;
virtual WSError Foreground() override;
virtual WSError Background() override;
virtual WSError Disconnect() override;
@ -41,18 +43,14 @@ public:
virtual WSError SetActive(bool active) override;
const AbilityInfo& GetAbilityInfo() const;
std::shared_ptr<NativeReference> GetJsSceneSessionRef() const;
std::shared_ptr<JsSceneSession> GetJsSceneSession() const;
void RegisterStartSceneEventListener(const NotifyStartSceneFunc& func);
private:
sptr<ISceneSessionStage> sceneSessionStage_;
sptr<IWindowEventChannel> windowEventChannel_;
AbilityInfo abilityInfo_;
std::string sessionType_ = "";
bool isActive_ = false;
NativeEngine& engine_;
std::shared_ptr<NativeReference> jsSceneSessionRef_;
std::shared_ptr<JsSceneSession> jsSceneSession_;
NotifyStartSceneFunc startSceneFunc_;
};
}
#endif // OHOS_SCENE_SESSION_H

View File

@ -21,7 +21,6 @@
#include <map>
#include <unistd.h>
#include <native_engine/native_engine.h>
#include "ws_single_instance.h"
#include "window_scene_common.h"
#include "scene_session.h"
@ -30,13 +29,11 @@ namespace OHOS::Rosen {
class SceneSessionManager {
WS_DECLARE_SINGLE_INSTANCE(SceneSessionManager)
public:
sptr<SceneSession> RequestSceneSession(const AbilityInfo& abilityInfo, SessionOption option, NativeEngine& engine);
sptr<SceneSession> RequestSceneSession(const AbilityInfo& abilityInfo, SessionOption option);
WSError RequestSceneSessionActivation(const sptr<SceneSession>& sceneSession);
WSError RequestSceneSessionBackground(const sptr<SceneSession>& sceneSession);
WSError RequestSceneSessionDestruction(const sptr<SceneSession>& sceneSession);
sptr<SceneSession> FindSceneSession(NativeValue* jsSceneSessionObj);
private:
uint32_t GenSessionId();
@ -45,8 +42,6 @@ private:
std::vector<sptr<SceneSession>> sessions_;
int pid_ = getpid();
std::atomic<uint32_t> sessionId_ = INVALID_SESSION_ID;
std::map<std::shared_ptr<NativeReference>, sptr<SceneSession>> jsSceneSessionMap_;
};
}
#endif // OHOS_ROSEN_SCENE_SESSION_MANAGER_H

View File

@ -22,24 +22,14 @@ namespace OHOS::Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SceneSession"};
}
SceneSession::SceneSession(const AbilityInfo& info, NativeEngine& engine) : Session(info.bundleName_),
abilityInfo_(info), engine_(engine)
SceneSession::SceneSession(const AbilityInfo& info) : Session(info.bundleName_), abilityInfo_(info)
{
std::shared_ptr<JsSceneSession> jsSceneSession = std::make_shared<JsSceneSession>(&engine);
sptr<SceneSession> sceneSession(this);
NativeValue* jsSceneSessionObj = CreateJsSceneSessionObject(engine_, sceneSession, jsSceneSession);
jsSceneSessionRef_ = std::unique_ptr<NativeReference>(engine_.CreateReference(jsSceneSessionObj, 1));
jsSceneSession_ = jsSceneSession;
}
std::shared_ptr<NativeReference> SceneSession::GetJsSceneSessionRef() const
void SceneSession::RegisterStartSceneEventListener(const NotifyStartSceneFunc& func)
{
return jsSceneSessionRef_;
}
std::shared_ptr<JsSceneSession> SceneSession::GetJsSceneSession() const
{
return jsSceneSession_;
startSceneFunc_ = func;
}
WSError SceneSession::Connect(const sptr<ISceneSessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel)
@ -157,13 +147,13 @@ WSError SceneSession::Maximum()
WSError SceneSession::StartScene(const AbilityInfo& info, SessionOption sessionOption)
{
auto sceneSession = SceneSessionManager::GetInstance().RequestSceneSession(info, sessionOption, engine_);
auto sceneSession = SceneSessionManager::GetInstance().RequestSceneSession(info, sessionOption);
if (sceneSession == nullptr) {
return WSError::WS_ERROR_NULLPTR;
}
auto jsSceneSession = sceneSession->GetJsSceneSession();
// TODO: native->ts startScene
jsSceneSession->StartScene(sceneSession);
if (startSceneFunc_) {
startSceneFunc_(sceneSession);
}
return WSError::WS_OK;
}

View File

@ -15,9 +15,6 @@
#include "scene_session_manager.h"
#include <native_engine/native_engine.h>
#include <native_engine/native_value.h>
#include "window_scene_hilog.h"
namespace OHOS::Rosen {
@ -27,29 +24,15 @@ namespace {
WS_IMPLEMENT_SINGLE_INSTANCE(SceneSessionManager)
sptr<SceneSession> SceneSessionManager::FindSceneSession(NativeValue* jsSceneSessionObj)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
for (auto iter = jsSceneSessionMap_.begin(); iter != jsSceneSessionMap_.end(); iter++) {
if (jsSceneSessionObj->StrictEquals(iter->first->Get())) {
return iter->second;
}
}
WLOGFE("Cannot find FindSceneSession!");
return nullptr;
}
sptr<SceneSession> SceneSessionManager::RequestSceneSession(const AbilityInfo& abilityInfo, SessionOption option,
NativeEngine& engine)
sptr<SceneSession> SceneSessionManager::RequestSceneSession(const AbilityInfo& abilityInfo, SessionOption option)
{
WLOGFI("abilityInfo: bundleName: %{public}s, abilityName: %{public}s", abilityInfo.bundleName_.c_str(),
abilityInfo.abilityName_.c_str());
sptr<SceneSession> session = new SceneSession(abilityInfo, engine);
sptr<SceneSession> session = new SceneSession(abilityInfo);
uint32_t persistentId = pid_ + GenSessionId();
session->SetPersistentId(persistentId);
std::lock_guard<std::recursive_mutex> lock(mutex_);
sessions_.emplace_back(session);
jsSceneSessionMap_.insert(std::make_pair(session->GetJsSceneSessionRef(), session));
return session;
}
@ -87,15 +70,6 @@ WSError SceneSessionManager::RequestSceneSessionDestruction(const sptr<SceneSess
return WSError::WS_DO_NOTHING;
}
sessions_.erase(iter);
auto jsSceneSessionIter = std::find_if(jsSceneSessionMap_.begin(), jsSceneSessionMap_.end(),
[sceneSession](const std::map<std::shared_ptr<NativeReference>, sptr<SceneSession>>::value_type& pair) {
return sceneSession == pair.second;
});
if (jsSceneSessionIter == jsSceneSessionMap_.end()) {
WLOGFI("cannot find jsSceneSession");
return WSError::WS_DO_NOTHING;
}
jsSceneSessionMap_.erase(jsSceneSessionIter);
return WSError::WS_OK;
}

View File

@ -15,6 +15,8 @@
#include "session.h"
#include <ui/rs_surface_node.h>
#include "window_scene_hilog.h"
namespace OHOS::Rosen {