From f9dad2f1f3bfacfc1541f77c12eadf14f6ed9ccb Mon Sep 17 00:00:00 2001 From: njuptkid Date: Fri, 21 Apr 2023 14:08:31 +0800 Subject: [PATCH] add GetDefaultDisplayInfo Change-Id: I22e84288adc84684390fd157573b92c99e47d3c2 --- dm/BUILD.gn | 9 ++ dm/include/display_manager_adapter.h | 3 + dm/src/display_manager_adapter.cpp | 35 ++++++ .../api/@ohos.session_manager_service.d.ts | 26 +++++ .../napi/session_manager_service/BUILD.gn | 56 ++++++++++ .../napi/js_session_manager_service.cpp | 103 ++++++++++++++++++ .../napi/js_session_manager_service.h | 26 +++++ .../napi/session_manager_service_module.cpp | 29 +++++ test/demo/BUILD.gn | 1 + test/demo/demo_session_manager.cpp | 17 ++- window_scene/interfaces/kits/napi/BUILD.gn | 1 + .../kits/napi/screen_session_manager/BUILD.gn | 1 + .../kits/napi/session_manager/BUILD.gn | 56 ++++++++++ .../napi/js_session_manager_service.cpp | 88 +++++++++++++++ .../napi/js_session_manager_service.h | 26 +++++ .../napi/session_manager_service_module.cpp | 29 +++++ window_scene/session/BUILD.gn | 7 +- .../session/screen/include/screen_property.h | 12 ++ .../session/screen/include/screen_session.h | 3 + .../session/screen/src/screen_session.cpp | 25 +++++ window_scene/session_manager/BUILD.gn | 2 + .../include/screen_session_manager.h | 6 + .../session_manager/include/session_manager.h | 4 +- .../src/screen_session_manager.cpp | 21 ++++ .../session_manager/src/session_manager.cpp | 4 +- window_scene/session_manager_service/BUILD.gn | 6 +- .../include/session_manager_service.h | 4 +- .../session_manager_service_interface.h | 49 ++++++++- .../include/session_manager_service_proxy.h | 10 +- .../include/session_manager_service_stub.h | 2 +- .../src/session_manager_service.cpp | 20 +++- .../src/session_manager_service_proxy.cpp | 31 +++++- .../src/session_manager_service_stub.cpp | 7 +- window_scene/sm/BUILD.gn | 61 +++++++++++ window_scene/sm/include/session_manager.h | 36 ++++++ .../sm/include/session_manager_adapter.h | 14 +++ .../sm/include/session_manager_interface.h | 35 ++++++ .../sm/include/session_manager_proxy.h | 32 ++++++ .../sm/include/session_manager_stub.h | 30 +++++ .../sm/src/session_manager adapter.cpp | 0 window_scene/sm/src/session_manager.cpp | 88 +++++++++++++++ window_scene/sm/src/session_manager_proxy.cpp | 46 ++++++++ window_scene/sm/src/session_manager_stub.cpp | 47 ++++++++ 43 files changed, 1087 insertions(+), 21 deletions(-) create mode 100644 interfaces/kits/js/declaration/api/@ohos.session_manager_service.d.ts create mode 100644 interfaces/kits/napi/session_manager_service/BUILD.gn create mode 100644 interfaces/kits/napi/session_manager_service/napi/js_session_manager_service.cpp create mode 100644 interfaces/kits/napi/session_manager_service/napi/js_session_manager_service.h create mode 100644 interfaces/kits/napi/session_manager_service/napi/session_manager_service_module.cpp create mode 100644 window_scene/interfaces/kits/napi/session_manager/BUILD.gn create mode 100644 window_scene/interfaces/kits/napi/session_manager/napi/js_session_manager_service.cpp create mode 100644 window_scene/interfaces/kits/napi/session_manager/napi/js_session_manager_service.h create mode 100644 window_scene/interfaces/kits/napi/session_manager/napi/session_manager_service_module.cpp create mode 100644 window_scene/sm/BUILD.gn create mode 100644 window_scene/sm/include/session_manager.h create mode 100644 window_scene/sm/include/session_manager_adapter.h create mode 100644 window_scene/sm/include/session_manager_interface.h create mode 100644 window_scene/sm/include/session_manager_proxy.h create mode 100644 window_scene/sm/include/session_manager_stub.h create mode 100644 window_scene/sm/src/session_manager adapter.cpp create mode 100644 window_scene/sm/src/session_manager.cpp create mode 100644 window_scene/sm/src/session_manager_proxy.cpp create mode 100644 window_scene/sm/src/session_manager_stub.cpp diff --git a/dm/BUILD.gn b/dm/BUILD.gn index 65b3bd51..b109df9f 100644 --- a/dm/BUILD.gn +++ b/dm/BUILD.gn @@ -17,6 +17,9 @@ config("libdm_private_config") { include_dirs = [ "include", "../dmserver/include", + "//foundation/window/window_manager/window_scene/session_manager/include", + "//foundation/window/window_manager/window_scene/session_manager_service/include", + ] } @@ -38,6 +41,7 @@ ohos_shared_library("libdm") { "src/screen_group.cpp", "src/screen_manager.cpp", "src/zidl/display_manager_agent_stub.cpp", + "../window_scene/session_manager/src/session_manager.cpp", ] configs = [ @@ -50,14 +54,19 @@ ohos_shared_library("libdm") { deps = [ "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/window/window_manager/utils:libwmutil", + ] + # public_deps = [ "${window_base_path}/window_scene/session_manager:session_manager" ] + external_deps = [ "c_utils:utils", "hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_framework:image_native", "samgr:samgr_proxy", + "ability_base:want", + "ability_runtime:ability_manager", ] part_name = "window_manager" diff --git a/dm/include/display_manager_adapter.h b/dm/include/display_manager_adapter.h index bbb41432..2676f8c9 100644 --- a/dm/include/display_manager_adapter.h +++ b/dm/include/display_manager_adapter.h @@ -26,6 +26,7 @@ #include "dm_common.h" #include "display_manager_interface.h" #include "singleton_delegator.h" +#include "session_manager_service_interface.h" namespace OHOS::Rosen { class BaseAdapter { @@ -37,8 +38,10 @@ public: virtual void Clear(); protected: bool InitDMSProxy(); + bool InitSMSProxy(); std::recursive_mutex mutex_; sptr displayManagerServiceProxy_ = nullptr; + sptr sessionManagerServiceProxy_ = nullptr; sptr dmsDeath_ = nullptr; bool isProxyValid_ { false }; }; diff --git a/dm/src/display_manager_adapter.cpp b/dm/src/display_manager_adapter.cpp index 59ee8521..b0972d8e 100644 --- a/dm/src/display_manager_adapter.cpp +++ b/dm/src/display_manager_adapter.cpp @@ -22,6 +22,7 @@ #include "display_manager.h" #include "screen_manager.h" #include "window_manager_hilog.h" +#include "session_manager.h" namespace OHOS::Rosen { namespace { @@ -36,6 +37,10 @@ WM_IMPLEMENT_SINGLE_INSTANCE(ScreenManagerAdapter) WLOGFE("InitDMSProxy failed!"); \ return ret; \ } \ + if (!InitSMSProxy()) { \ + WLOGFE("InitSMSProxy failed!"); \ + return ret; \ + } \ } while (false) sptr DisplayManagerAdapter::GetDefaultDisplayInfo() @@ -273,6 +278,36 @@ bool BaseAdapter::InitDMSProxy() return true; } +bool BaseAdapter::InitSMSProxy() +{ + WLOGFE("InitSMSProxy begin:"); + std::lock_guard lock(mutex_); + SessionManager sessionManager; + sessionManager.Init(); + usleep(200); + + auto remoteObject = sessionManager.GetRemoteObject(); + int count = 0; + while(remoteObject == nullptr && count < 5) { + usleep(200); + remoteObject = sessionManager.GetRemoteObject(); + count++; + } + + if (!remoteObject) { + WLOGFE("remoteObject is nullptr"); + //return false; + } + + sessionManagerServiceProxy_ = iface_cast(remoteObject); + if (!sessionManagerServiceProxy_) { + WLOGFE("sessionManagerServiceProxy_ is nullptr"); + //return false; + } + WLOGFE("InitSMSProxy end:"); + return true; +} + DMSDeathRecipient::DMSDeathRecipient(BaseAdapter& adapter) : adapter_(adapter) { } diff --git a/interfaces/kits/js/declaration/api/@ohos.session_manager_service.d.ts b/interfaces/kits/js/declaration/api/@ohos.session_manager_service.d.ts new file mode 100644 index 00000000..2b7297de --- /dev/null +++ b/interfaces/kits/js/declaration/api/@ohos.session_manager_service.d.ts @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2021 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import { AsyncCallback, Callback } from './basic'; +import rpc from '@ohos.rpc'; + + +declare namespace session_manager_service { + + function getRemoteObject() : rpc.RemoteObject; + +} + +export default session_manager_service; \ No newline at end of file diff --git a/interfaces/kits/napi/session_manager_service/BUILD.gn b/interfaces/kits/napi/session_manager_service/BUILD.gn new file mode 100644 index 00000000..62918fe2 --- /dev/null +++ b/interfaces/kits/napi/session_manager_service/BUILD.gn @@ -0,0 +1,56 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//arkcompiler/ets_frontend/ts2panda/ts2abc_config.gni") +import("//build/ohos.gni") +import("//foundation/window/window_manager/windowmanager_aafwk.gni") + +config("session_manager_service_config") { + visibility = [ ":*" ] + + include_dirs = [ + "//foundation/window/window_manager/interfaces/kits/napi/screen_runtime/api", + "//foundation/window/window_manager/interfaces/kits/napi/screen_runtime/napi", + ] +} + +ohos_shared_library("session_manager_service_napi") { + sources = [ + "napi/js_session_manager_service.cpp", + "napi/session_manager_service_module.cpp", + ] + + configs = [ + ":session_manager_service_config", + "//foundation/window/window_manager/resources/config/build:coverage_flags", + ] + + deps = [ + "//foundation/window/window_manager/window_scene/session_manager_service:session_manager_service", + "//foundation/window/window_manager/utils:libwmutil", + ] + + external_deps = [ + "ability_runtime:runtime", + "c_utils:utils", + "graphic_standard:surface", # use for SurfaceUtils + "hiviewdfx_hilog_native:libhilog", + "napi:ace_napi", + "ipc:ipc_napi_common", + ] + + relative_install_dir = "module" + + part_name = "window_manager" + subsystem_name = "window" +} diff --git a/interfaces/kits/napi/session_manager_service/napi/js_session_manager_service.cpp b/interfaces/kits/napi/session_manager_service/napi/js_session_manager_service.cpp new file mode 100644 index 00000000..23e4f5a9 --- /dev/null +++ b/interfaces/kits/napi/session_manager_service/napi/js_session_manager_service.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "js_session_manager_service.h" +#include "js_runtime_utils.h" +#include "singleton_container.h" +#include "session_manager_service.h" +#include "napi_remote_object.h" + +#include "window_manager_hilog.h" + +namespace OHOS::Rosen { +using namespace OHOS::AbilityRuntime; +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "JsSessionManagerService"}; +} + +class JsSessionManagerService { +public: + explicit JsSessionManagerService(NativeEngine* engine) { + } + + ~JsSessionManagerService() = default; + + static void Finalizer(NativeEngine* engine, void* data, void* hint) + { + WLOGI("Finalizer is called"); + std::unique_ptr(static_cast(data)); + } + + static NativeValue* GetRemoteObject(NativeEngine* engine, NativeCallbackInfo* info) + { + JsSessionManagerService* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnGetRemoteObject(*engine, *info) : nullptr; + } + + static NativeValue* HelloWorld(NativeEngine* engine, NativeCallbackInfo* info) + { + WLOGI("JsSessionManagerService: HelloWorld is called"); + JsSessionManagerService* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnHelloWorld(*engine, *info) : nullptr; + } + +private: + NativeValue* OnGetRemoteObject(NativeEngine& engine, NativeCallbackInfo& info) + { + WLOGI("JsSessionManagerService: OnGetRemoteObject is called"); + auto& sessionManagerService = SingletonContainer::Get(); + IRemoteObject* remoteObject = sessionManagerService.GetRemoteObject(); + + //sptr sRemoteObject(remoteObject); + napi_env env = reinterpret_cast(&engine); + napi_value value = NAPI_ohos_rpc_CreateJsRemoteObject(env, remoteObject); + return reinterpret_cast(value); + } + + NativeValue* OnHelloWorld(NativeEngine& engine, NativeCallbackInfo& info) + { + WLOGI("JsSessionManagerService: OnHelloWorld is called"); + return nullptr; + } +}; + +NativeValue* JsSessionManagerServiceInit(NativeEngine* engine, NativeValue* exportObj) +{ + WLOGI("JsSessionManagerServiceInit is called."); + + if (engine == nullptr || exportObj == nullptr) { + WLOGFE("JsSessionManagerServiceInit engine or exportObj is nullptr"); + return nullptr; + } + + NativeObject* object = ConvertNativeValueTo(exportObj); + if (object == nullptr) { + WLOGFE("JsSessionManagerServiceInit object is nullptr"); + return nullptr; + } + + std::unique_ptr sessionManagerService = std::make_unique(engine); + object->SetNativePointer(sessionManagerService.release(), JsSessionManagerService::Finalizer, nullptr); + + // set property + + // bind function + const char* moduleName = "JsSessionManagerService"; + BindNativeFunction(*engine, *object, "helloWorld", moduleName, JsSessionManagerService::HelloWorld); + BindNativeFunction(*engine, *object, "getRemoteObject", moduleName, JsSessionManagerService::GetRemoteObject); + return engine->CreateUndefined(); +} +} // namespace OHOS::Rosen diff --git a/interfaces/kits/napi/session_manager_service/napi/js_session_manager_service.h b/interfaces/kits/napi/session_manager_service/napi/js_session_manager_service.h new file mode 100644 index 00000000..c847abde --- /dev/null +++ b/interfaces/kits/napi/session_manager_service/napi/js_session_manager_service.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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_JS_SESSION_MANAGER_SERVICE_H +#define OHOS_JS_SESSION_MANAGER_SERVICE_H + +#include "native_engine/native_engine.h" +#include "native_engine/native_value.h" + +namespace OHOS::Rosen { +NativeValue* JsSessionManagerServiceInit(NativeEngine* engine, NativeValue* exportObj); +} // namespace OHOS::Rosen + +#endif // OHOS_JS_SESSION_MANAGER_H \ No newline at end of file diff --git a/interfaces/kits/napi/session_manager_service/napi/session_manager_service_module.cpp b/interfaces/kits/napi/session_manager_service/napi/session_manager_service_module.cpp new file mode 100644 index 00000000..7eab83fd --- /dev/null +++ b/interfaces/kits/napi/session_manager_service/napi/session_manager_service_module.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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 "native_engine/native_engine.h" +#include "js_session_manager_service.h" + +extern "C" __attribute__((constructor)) void NAPI_application_sessionmanagerservice_AutoRegister() +{ + auto moduleManager = NativeModuleManager::GetInstance(); + NativeModule newModuleInfo = { + .name = "session_manager_service", + .fileName = "module/libsession_manager_service_napi.so/session_manager_service.js", + .registerCallback = OHOS::Rosen::JsSessionManagerServiceInit, + }; + + moduleManager->Register(&newModuleInfo); +} diff --git a/test/demo/BUILD.gn b/test/demo/BUILD.gn index 1de686cd..f1ad13f4 100644 --- a/test/demo/BUILD.gn +++ b/test/demo/BUILD.gn @@ -157,6 +157,7 @@ ohos_executable("demo_session_manager") { ] external_deps = [ "c_utils:utils", + "ipc:ipc_core", ] part_name = "window_manager" diff --git a/test/demo/demo_session_manager.cpp b/test/demo/demo_session_manager.cpp index f9eab11a..83e3ea5b 100644 --- a/test/demo/demo_session_manager.cpp +++ b/test/demo/demo_session_manager.cpp @@ -18,6 +18,7 @@ #include #include #include "session_manager_service_proxy.h" +#include "singleton_container.h" using namespace OHOS; using namespace OHOS::Rosen; @@ -26,21 +27,31 @@ int main(int argc, char *argv[]) { SessionManager sessionManager; sessionManager.Init(); - sleep(3); + sleep(1); auto remoteObject = sessionManager.GetRemoteObject(); if (!remoteObject) { std::cout << "remoteObject is nullptr." << std::endl; } - auto proxy = std::make_unique(remoteObject); - + auto proxy = iface_cast(remoteObject); if (!proxy) { std::cout << "proxy is nullptr." << std::endl; } else { int ret = proxy->GetValueById(1); std::cout << "ret value: " << ret << std::endl; + + sptr displayInfo = proxy->GetDefaultDisplayInfo(); + if (displayInfo == nullptr) { + std::cout << "GeGetDefaultDisplayInfo failed, displayInfo nullptr." << std::endl; + } else { + std::cout << "Name: " << displayInfo->GetName() << std::endl; + std::cout << "Id: " << displayInfo->GetDisplayId() << std::endl; + std::cout << "Height: " << displayInfo->GetWidth() << std::endl; + std::cout << "Width: " << displayInfo->GetHeight() << std::endl; + } } + return 0; } \ No newline at end of file diff --git a/window_scene/interfaces/kits/napi/BUILD.gn b/window_scene/interfaces/kits/napi/BUILD.gn index 5735ba64..82a1839c 100644 --- a/window_scene/interfaces/kits/napi/BUILD.gn +++ b/window_scene/interfaces/kits/napi/BUILD.gn @@ -17,6 +17,7 @@ group("window_scene_napi_packages") { public_deps = [ "scene_session_manager:scenesessionmanager_napi", "screen_session_manager:screensessionmanager_napi", + #"session_manager:session_manager_napi", "session_manager_service:session_manager_service_napi", ] } diff --git a/window_scene/interfaces/kits/napi/screen_session_manager/BUILD.gn b/window_scene/interfaces/kits/napi/screen_session_manager/BUILD.gn index c47e7f62..35546306 100644 --- a/window_scene/interfaces/kits/napi/screen_session_manager/BUILD.gn +++ b/window_scene/interfaces/kits/napi/screen_session_manager/BUILD.gn @@ -17,6 +17,7 @@ config("screen_session_manager_napi_public_config") { visibility = [ ":*" ] include_dirs = [ "//foundation/window/window_manager/window_scene/interfaces/kits/napi", + "//foundation/window/window_manager/interfaces/innerkits/dm", ] } diff --git a/window_scene/interfaces/kits/napi/session_manager/BUILD.gn b/window_scene/interfaces/kits/napi/session_manager/BUILD.gn new file mode 100644 index 00000000..e547b2f9 --- /dev/null +++ b/window_scene/interfaces/kits/napi/session_manager/BUILD.gn @@ -0,0 +1,56 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//arkcompiler/ets_frontend/ts2panda/ts2abc_config.gni") +import("//build/ohos.gni") +import("//foundation/window/window_manager/windowmanager_aafwk.gni") + +config("session_manager_config") { + visibility = [ ":*" ] + + include_dirs = [ + "//foundation/window/window_manager/interfaces/kits/napi/screen_runtime/api", + "//foundation/window/window_manager/interfaces/kits/napi/screen_runtime/napi", + ] +} + +ohos_shared_library("session_manager_napi") { + sources = [ + "napi/js_session_manager.cpp", + "napi/session_manager_module.cpp", + ] + + configs = [ + ":session_manager_config", + "//foundation/window/window_manager/resources/config/build:coverage_flags", + ] + + deps = [ + "//foundation/window/window_manager/window_scene/session_manager_service:session_manager_service", + "//foundation/window/window_manager/utils:libwmutil", + ] + + external_deps = [ + "ability_runtime:runtime", + "c_utils:utils", + "graphic_standard:surface", # use for SurfaceUtils + "hiviewdfx_hilog_native:libhilog", + "napi:ace_napi", + "ipc:ipc_napi_common", + ] + + relative_install_dir = "module" + + part_name = "window_manager" + subsystem_name = "window" +} diff --git a/window_scene/interfaces/kits/napi/session_manager/napi/js_session_manager_service.cpp b/window_scene/interfaces/kits/napi/session_manager/napi/js_session_manager_service.cpp new file mode 100644 index 00000000..c4f039ed --- /dev/null +++ b/window_scene/interfaces/kits/napi/session_manager/napi/js_session_manager_service.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "js_session_manager_service.h" +#include "js_runtime_utils.h" +#include "singleton_container.h" +#include "session_manager_service.h" +#include "napi_remote_object.h" + +#include "window_manager_hilog.h" + +namespace OHOS::Rosen { +using namespace OHOS::AbilityRuntime; +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "JsSessionManagerService"}; +} + +class JsSessionManagerService { +public: + explicit JsSessionManagerService(NativeEngine* engine) { + } + + ~JsSessionManagerService() = default; + + static void Finalizer(NativeEngine* engine, void* data, void* hint) + { + WLOGI("Finalizer is called"); + std::unique_ptr(static_cast(data)); + } + + static NativeValue* GetRemoteObject(NativeEngine* engine, NativeCallbackInfo* info) + { + JsSessionManagerService* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnGetRemoteObject(*engine, *info) : nullptr; + } + +private: + NativeValue* OnGetRemoteObject(NativeEngine& engine, NativeCallbackInfo& info) + { + WLOGI("JsSessionManagerService: OnGetRemoteObject is called"); + auto& sessionManagerService = SingletonContainer::Get(); + IRemoteObject* remoteObject = sessionManagerService.GetRemoteObject(); + + napi_env env = reinterpret_cast(&engine); + napi_value value = NAPI_ohos_rpc_CreateJsRemoteObject(env, remoteObject); + return reinterpret_cast(value); + } +}; + +NativeValue* JsSessionManagerServiceInit(NativeEngine* engine, NativeValue* exportObj) +{ + WLOGI("JsSessionManagerServiceInit is called."); + + if (engine == nullptr || exportObj == nullptr) { + WLOGFE("JsSessionManagerServiceInit engine or exportObj is nullptr"); + return nullptr; + } + + NativeObject* object = ConvertNativeValueTo(exportObj); + if (object == nullptr) { + WLOGFE("JsSessionManagerServiceInit object is nullptr"); + return nullptr; + } + + std::unique_ptr sessionManagerService = std::make_unique(engine); + object->SetNativePointer(sessionManagerService.release(), JsSessionManagerService::Finalizer, nullptr); + + // set property + + // bind function + const char* moduleName = "JsSessionManagerService"; + BindNativeFunction(*engine, *object, "getRemoteObject", moduleName, JsSessionManagerService::GetRemoteObject); + return engine->CreateUndefined(); +} +} // namespace OHOS::Rosen diff --git a/window_scene/interfaces/kits/napi/session_manager/napi/js_session_manager_service.h b/window_scene/interfaces/kits/napi/session_manager/napi/js_session_manager_service.h new file mode 100644 index 00000000..943cd364 --- /dev/null +++ b/window_scene/interfaces/kits/napi/session_manager/napi/js_session_manager_service.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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_JS_SESSION_MANAGER_SERVICE_H +#define OHOS_JS_SESSION_MANAGER_SERVICE_H + +#include "native_engine/native_engine.h" +#include "native_engine/native_value.h" + +namespace OHOS::Rosen { +NativeValue* JsSessionManagerServiceInit(NativeEngine* engine, NativeValue* exportObj); +} // namespace OHOS::Rosen + +#endif // OHOS_JS_SESSION_MANAGER_SERVICE_H \ No newline at end of file diff --git a/window_scene/interfaces/kits/napi/session_manager/napi/session_manager_service_module.cpp b/window_scene/interfaces/kits/napi/session_manager/napi/session_manager_service_module.cpp new file mode 100644 index 00000000..7eab83fd --- /dev/null +++ b/window_scene/interfaces/kits/napi/session_manager/napi/session_manager_service_module.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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 "native_engine/native_engine.h" +#include "js_session_manager_service.h" + +extern "C" __attribute__((constructor)) void NAPI_application_sessionmanagerservice_AutoRegister() +{ + auto moduleManager = NativeModuleManager::GetInstance(); + NativeModule newModuleInfo = { + .name = "session_manager_service", + .fileName = "module/libsession_manager_service_napi.so/session_manager_service.js", + .registerCallback = OHOS::Rosen::JsSessionManagerServiceInit, + }; + + moduleManager->Register(&newModuleInfo); +} diff --git a/window_scene/session/BUILD.gn b/window_scene/session/BUILD.gn index de6cceec..50958e60 100644 --- a/window_scene/session/BUILD.gn +++ b/window_scene/session/BUILD.gn @@ -20,6 +20,8 @@ config("session_public_config") { # for window_manager_hilog "${window_base_path}/utils/include", + "${window_base_path}/dm", + "${window_base_path}/interfaces/innerkits/dm", ] } @@ -47,6 +49,7 @@ ohos_shared_library("scene_session") { deps = [ "${graphic_base_path}/graphic_2d/rosen/modules/render_service_client:librender_service_client" ] + public_deps = [ "${window_base_path}/window_scene/common:window_scene_common" ] external_deps = [ @@ -71,7 +74,9 @@ ohos_shared_library("screen_session") { public_configs = [ ":session_public_config" ] - deps = [ "${graphic_base_path}/graphic_2d/rosen/modules/render_service_client:librender_service_client" ] + deps = [ "${graphic_base_path}/graphic_2d/rosen/modules/render_service_client:librender_service_client", + "${window_base_path}/utils:libwmutil", + ] part_name = "window_manager" subsystem_name = "window" diff --git a/window_scene/session/screen/include/screen_property.h b/window_scene/session/screen/include/screen_property.h index 132de619..7c70d8ac 100644 --- a/window_scene/session/screen/include/screen_property.h +++ b/window_scene/session/screen/include/screen_property.h @@ -17,6 +17,7 @@ #define OHOS_ROSEN_WINDOW_SCENE_SCREEN_PROPERTY_H #include "common/rs_rect.h" +#include "dm_common.h" namespace OHOS::Rosen { class ScreenProperty { @@ -32,7 +33,18 @@ public: private: float rotation_ { 0.0f }; + /* + float virtualPixelRatio_ { 1.0f }; + float xDpi_ { 0.0f }; + float yDpi_ { 0.0f }; + int32_t dpi_ { 320 }; + Orientation orientation_ { Orientation::UNSPECIFIED }; + int32_t offsetX_ { 0 }; + int32_t offsety_ { 0 }; + DisplayState displayState_ { DisplayState::UNKNOWN }; + */ RRect bounds_; + }; } // namespace OHOS::Rosen diff --git a/window_scene/session/screen/include/screen_session.h b/window_scene/session/screen/include/screen_session.h index 0f349080..abcba1cc 100644 --- a/window_scene/session/screen/include/screen_session.h +++ b/window_scene/session/screen/include/screen_session.h @@ -21,6 +21,7 @@ #include #include "screen_property.h" +#include "display_info.h" namespace OHOS::Rosen { class IScreenChangeListener : public RefBase { @@ -53,6 +54,8 @@ public: void Connect(); void Disconnect(); + sptr ConvertToDisplayInfo(); + private: ScreenId screenId_; ScreenProperty property_; diff --git a/window_scene/session/screen/src/screen_session.cpp b/window_scene/session/screen/src/screen_session.cpp index 68df6f71..0a9dc059 100644 --- a/window_scene/session/screen/src/screen_session.cpp +++ b/window_scene/session/screen/src/screen_session.cpp @@ -84,4 +84,29 @@ void ScreenSession::Disconnect() } } +sptr ScreenSession::ConvertToDisplayInfo() +{ + sptr displayInfo = new(std::nothrow) DisplayInfo(); + if (displayInfo == nullptr) { + return displayInfo; + } + //displayInfo->name_ = name_; + //displayInfo->SetOffsetX(offsetX_); + //displayInfo->SetOffsetY(offsetY_); + displayInfo->SetWidth(property_.GetBounds().rect_.GetWidth()); + displayInfo->SetHeight(property_.GetBounds().rect_.GetHeight()); + //displayInfo->SetDisplayId(id_); + //displayInfo->SetRefreshRate(refreshRate_); + displayInfo->SetScreenId(screenId_); + //displayInfo->SetScreenGroupId(screenGroupId_); + // displayInfo->SetVirtualPixelRatio(virtualPixelRatio_); + //displayInfo->SetRotation(rotation_); + //displayInfo->SetOrientation(orientation_); + //displayInfo->SetDpi(virtualPixelRatio_ * DOT_PER_INCH); + //displayInfo->displayState_ = displayState_; + //displayInfo->SetWaterfallDisplayCompressionStatus(waterfallDisplayCompressionStatus_); + //displayInfo->SetDisplayOrientation(displayOrientation_); + return displayInfo; +} + } // namespace OHOS::Rosen diff --git a/window_scene/session_manager/BUILD.gn b/window_scene/session_manager/BUILD.gn index 67d3906e..8bb280bd 100644 --- a/window_scene/session_manager/BUILD.gn +++ b/window_scene/session_manager/BUILD.gn @@ -19,6 +19,7 @@ config("session_manager_public_config") { "${window_base_path}/window_scene", "${window_base_path}/window_scene/session_manager/include", "${window_base_path}/window_scene/session_manager_service/include", + "${window_base_path}/interfaces/innerkits/dm", # for window_manager_hilog "${window_base_path}/utils/include", @@ -94,6 +95,7 @@ ohos_shared_library("session_manager") { "${window_base_path}/window_scene/common:window_scene_common", "${window_base_path}/window_scene/session:scene_session", "${window_base_path}/dmserver:libdms", + "${window_base_path}/utils:libwmutil", "${ability_runtime_services_path}/abilitymgr:abilityms", ] diff --git a/window_scene/session_manager/include/screen_session_manager.h b/window_scene/session_manager/include/screen_session_manager.h index b4b1afad..f70a5138 100644 --- a/window_scene/session_manager/include/screen_session_manager.h +++ b/window_scene/session_manager/include/screen_session_manager.h @@ -44,6 +44,10 @@ public: void RegisterScreenConnectionListener(sptr& screenConnectionListener); void UnregisterScreenConnectionListener(sptr& screenConnectionListener); + ScreenId GetDefaultScreenId(); + + sptr GetDefaultScreenSession(); + protected: ScreenSessionManager(); virtual ~ScreenSessionManager() = default; @@ -59,6 +63,8 @@ private: std::map> screenSessionMap_; std::vector> screenConnectionListenerList_; + + ScreenId defaultScreenId_ = SCREEN_ID_INVALID; }; } // namespace OHOS::Rosen diff --git a/window_scene/session_manager/include/session_manager.h b/window_scene/session_manager/include/session_manager.h index d3a8daca..219b92a7 100644 --- a/window_scene/session_manager/include/session_manager.h +++ b/window_scene/session_manager/include/session_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2023 Huawei Device Co., Ltd. + * Copyright (c) 2023 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 @@ -14,10 +14,12 @@ */ #include "iremote_object.h" +#include "wm_single_instance.h" namespace OHOS::Rosen { class AbilityConnection; class SessionManager { +WM_DECLARE_SINGLE_INSTANCE_BASE(SessionManager); public: SessionManager(); diff --git a/window_scene/session_manager/src/screen_session_manager.cpp b/window_scene/session_manager/src/screen_session_manager.cpp index 5d765103..8499557c 100644 --- a/window_scene/session_manager/src/screen_session_manager.cpp +++ b/window_scene/session_manager/src/screen_session_manager.cpp @@ -126,4 +126,25 @@ sptr ScreenSessionManager::GetOrCreateScreenSession(ScreenId scre screenSessionMap_[screenId] = session; return session; } + +ScreenId ScreenSessionManager::GetDefaultScreenId() +{ + if (defaultScreenId_ == INVALID_SCREEN_ID) { + defaultScreenId_ = rsInterface_.GetDefaultScreenId(); + } + return defaultScreenId_; +} + +sptr ScreenSessionManager::GetDefaultScreenSession() +{ + ScreenId screenId = GetDefaultScreenId(); + + for (auto& it : screenSessionMap_) { + if (it.first == screenId) { + return it.second; + } + } + return nullptr; +} + } // namespace OHOS::Rosen diff --git a/window_scene/session_manager/src/session_manager.cpp b/window_scene/session_manager/src/session_manager.cpp index 84fc9d3d..83635bdf 100644 --- a/window_scene/session_manager/src/session_manager.cpp +++ b/window_scene/session_manager/src/session_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2023 Huawei Device Co., Ltd. + * Copyright (c) 2023 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 @@ -44,6 +44,8 @@ private: sptr remoteObject_; }; +WM_IMPLEMENT_SINGLE_INSTANCE(SessionManager); + SessionManager::SessionManager() { } diff --git a/window_scene/session_manager_service/BUILD.gn b/window_scene/session_manager_service/BUILD.gn index d5234ad6..b7731b2c 100644 --- a/window_scene/session_manager_service/BUILD.gn +++ b/window_scene/session_manager_service/BUILD.gn @@ -20,6 +20,8 @@ config("session_manager_service_public_config") { # for window_manager_hilog "${window_base_path}/utils/include", + "${window_base_path}/interfaces/innerkits/dm", + "${window_base_path}/window_scene/session_manager/include", "${window_base_path}/window_scene/session_manager_service/include", ] } @@ -37,7 +39,8 @@ ohos_shared_library("session_manager_service") { deps = [ "${graphic_base_path}/graphic_2d/rosen/modules/render_service_client:librender_service_client", "${window_base_path}/window_scene/common:window_scene_common", - "${window_base_path}/window_scene/session:scene_session", + "${window_base_path}/window_scene/session:screen_session", + "${window_base_path}/window_scene/session_manager:screen_session_manager", "${window_base_path}/dmserver:libdms", "${window_base_path}/utils:libwmutil", ] @@ -45,7 +48,6 @@ ohos_shared_library("session_manager_service") { external_deps = [ "ability_base:want", "ability_runtime:ability_manager", - "ace_engine:ace_uicontent", "c_utils:utils", "ipc:ipc_core", "eventhandler:libeventhandler", diff --git a/window_scene/session_manager_service/include/session_manager_service.h b/window_scene/session_manager_service/include/session_manager_service.h index 404f4627..bea2db95 100644 --- a/window_scene/session_manager_service/include/session_manager_service.h +++ b/window_scene/session_manager_service/include/session_manager_service.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2023 Huawei Device Co., Ltd. + * Copyright (c) 2023 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 @@ -29,6 +29,8 @@ public: int GetValueById(int id) override; + sptr GetDefaultDisplayInfo() override; + IRemoteObject* GetRemoteObject(); private: diff --git a/window_scene/session_manager_service/include/session_manager_service_interface.h b/window_scene/session_manager_service/include/session_manager_service_interface.h index 7e9cf091..44cc4f93 100644 --- a/window_scene/session_manager_service/include/session_manager_service_interface.h +++ b/window_scene/session_manager_service/include/session_manager_service_interface.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2023 Huawei Device Co., Ltd. + * Copyright (c) 2023 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 @@ -17,6 +17,7 @@ #define FOUNDATION_WINDOW_SCENE_SESSION_MANAGER_SERVICE_INTERFACE_H #include +#include "display_info.h" namespace OHOS::Rosen { class ISessionManagerService : public IRemoteBroker { @@ -24,11 +25,55 @@ public: DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.ISessionManagerService"); enum class SessionManagerServiceMessage : uint32_t { - TRANS_ID_SCREEN_BASE = 0, + TRANS_ID_GET_DEFAULT_DISPLAY_INFO = 0, + TRANS_ID_GET_DISPLAY_BY_ID, + TRANS_ID_GET_DISPLAY_BY_SCREEN, + TRANS_ID_GET_DISPLAY_SNAPSHOT, + TRANS_ID_REGISTER_DISPLAY_MANAGER_AGENT, + TRANS_ID_UNREGISTER_DISPLAY_MANAGER_AGENT, + TRANS_ID_WAKE_UP_BEGIN, + TRANS_ID_WAKE_UP_END, + TRANS_ID_SUSPEND_BEGIN, + TRANS_ID_SUSPEND_END, + TRANS_ID_SET_SCREEN_POWER_FOR_ALL, + TRANS_ID_GET_SCREEN_POWER, + TRANS_ID_SET_DISPLAY_STATE, + TRANS_ID_GET_DISPLAY_STATE, + TRANS_ID_GET_ALL_DISPLAYIDS, + TRANS_ID_NOTIFY_DISPLAY_EVENT, + TRANS_ID_SET_FREEZE_EVENT, + TRANS_ID_SCREEN_BASE = 1000, + TRANS_ID_CREATE_VIRTUAL_SCREEN = TRANS_ID_SCREEN_BASE, + TRANS_ID_DESTROY_VIRTUAL_SCREEN, + TRANS_ID_SET_VIRTUAL_SCREEN_SURFACE, TRANS_ID_GET_SCREEN_INFO_BY_ID, + TRANS_ID_GET_SCREEN_GROUP_INFO_BY_ID, + TRANS_ID_SET_SCREEN_ACTIVE_MODE, + TRANS_ID_GET_ALL_SCREEN_INFOS, + TRANS_ID_SET_ORIENTATION, + TRANS_ID_SET_VIRTUAL_PIXEL_RATIO, + TRANS_ID_SCREENGROUP_BASE = 1100, + TRANS_ID_SCREEN_MAKE_MIRROR = TRANS_ID_SCREENGROUP_BASE, + TRANS_ID_SCREEN_MAKE_EXPAND, + TRANS_ID_REMOVE_VIRTUAL_SCREEN_FROM_SCREEN_GROUP, + TRANS_ID_SCREEN_GAMUT_BASE = 1200, + TRANS_ID_SCREEN_GET_SUPPORTED_COLOR_GAMUTS = TRANS_ID_SCREEN_GAMUT_BASE, + TRANS_ID_SCREEN_GET_COLOR_GAMUT, + TRANS_ID_SCREEN_SET_COLOR_GAMUT, + TRANS_ID_SCREEN_GET_GAMUT_MAP, + TRANS_ID_SCREEN_SET_GAMUT_MAP, + TRANS_ID_SCREEN_SET_COLOR_TRANSFORM, + TRANS_ID_IS_SCREEN_ROTATION_LOCKED, + TRANS_ID_SET_SCREEN_ROTATION_LOCKED, + TRANS_ID_HAS_PRIVATE_WINDOW, + TRANS_ID_GET_CUTOUT_INFO, + TRANS_ID_ADD_SURFACE_NODE, + TRANS_ID_REMOVE_SURFACE_NODE, }; virtual int GetValueById(int id) = 0; + + virtual sptr GetDefaultDisplayInfo() = 0; }; } // namespace OHOS::Rosen diff --git a/window_scene/session_manager_service/include/session_manager_service_proxy.h b/window_scene/session_manager_service/include/session_manager_service_proxy.h index b98c44da..8c893567 100644 --- a/window_scene/session_manager_service/include/session_manager_service_proxy.h +++ b/window_scene/session_manager_service/include/session_manager_service_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2023 Huawei Device Co., Ltd. + * Copyright (c) 2023 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 @@ -19,16 +19,22 @@ #include "session_manager_service_interface.h" #include +#include "singleton_delegator.h" namespace OHOS::Rosen { class SessionManagerServiceProxy : public IRemoteProxy { public: - explicit SessionManagerServiceProxy(sptr& remoteObject); + explicit SessionManagerServiceProxy(const sptr& remoteObject); ~SessionManagerServiceProxy() override; int GetValueById(int id) override; + sptr GetDefaultDisplayInfo() override; + +private: + static inline BrokerDelegator delegator_; + }; } // namespace OHOS::Rosen diff --git a/window_scene/session_manager_service/include/session_manager_service_stub.h b/window_scene/session_manager_service/include/session_manager_service_stub.h index 5d81f9c6..cf8fd380 100644 --- a/window_scene/session_manager_service/include/session_manager_service_stub.h +++ b/window_scene/session_manager_service/include/session_manager_service_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2023 Huawei Device Co., Ltd. + * Copyright (c) 2023 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 diff --git a/window_scene/session_manager_service/src/session_manager_service.cpp b/window_scene/session_manager_service/src/session_manager_service.cpp index 1c8791eb..98c0613d 100644 --- a/window_scene/session_manager_service/src/session_manager_service.cpp +++ b/window_scene/session_manager_service/src/session_manager_service.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2023 Huawei Device Co., Ltd. + * Copyright (c) 2023 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 @@ -18,10 +18,12 @@ #include #include "window_manager_hilog.h" +#include "screen_session_manager.h" + namespace OHOS::Rosen { namespace { - // constexpr HiviewDFX::HiLogLabel LEVEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "SessionManagerService"}; + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "SessionManagerService"}; } WM_IMPLEMENT_SINGLE_INSTANCE(SessionManagerService) @@ -29,6 +31,16 @@ SessionManagerService::SessionManagerService() { } +sptr SessionManagerService::GetDefaultDisplayInfo() +{ + sptr session = ScreenSessionManager::GetInstance().GetDefaultScreenSession(); + if (session == nullptr) { + WLOGFE("GetDefaultDisplayInfo, screen session is nullptr"); + return nullptr; + } + return session->ConvertToDisplayInfo(); +} + int SessionManagerService::GetValueById(int id) { return id + 1; @@ -39,4 +51,8 @@ IRemoteObject* SessionManagerService::GetRemoteObject() return dynamic_cast(this); } +void SessionManagerService::Init() +{ +} + } // namesapce OHOS::Rosen \ No newline at end of file diff --git a/window_scene/session_manager_service/src/session_manager_service_proxy.cpp b/window_scene/session_manager_service/src/session_manager_service_proxy.cpp index 1d5b53ff..b600a5ee 100644 --- a/window_scene/session_manager_service/src/session_manager_service_proxy.cpp +++ b/window_scene/session_manager_service/src/session_manager_service_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2023 Huawei Device Co., Ltd. + * Copyright (c) 2023 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 @@ -21,7 +21,7 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "SessionManagerServiceProxy"}; } -SessionManagerServiceProxy::SessionManagerServiceProxy(sptr& remoteObject) : IRemoteProxy(remoteObject) +SessionManagerServiceProxy::SessionManagerServiceProxy(const sptr& remoteObject) : IRemoteProxy(remoteObject) { } @@ -62,4 +62,31 @@ int SessionManagerServiceProxy::GetValueById(int id) return value; } + +sptr SessionManagerServiceProxy::GetDefaultDisplayInfo() +{ + sptr remote = Remote(); + if (remote == nullptr) { + WLOGFE("GetDefaultDisplayInfo remote is nullptr"); + return nullptr; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("GetDefaultDisplayInfo::WriteInterfaceToken failed"); + return nullptr; + } + if (remote->SendRequest(static_cast(SessionManagerServiceMessage::TRANS_ID_GET_DEFAULT_DISPLAY_INFO), + data, reply, option) != ERR_NONE) { + WLOGFW("GetDefaultDisplayInfo::SendRequest failed"); + return nullptr; + } + sptr info = reply.ReadParcelable(); + if (info == nullptr) { + WLOGFW("DisplayManagerProxy::GetDefaultDisplayInfo SendRequest nullptr."); + } + return info; +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/window_scene/session_manager_service/src/session_manager_service_stub.cpp b/window_scene/session_manager_service/src/session_manager_service_stub.cpp index 11c66b7d..2e088483 100644 --- a/window_scene/session_manager_service/src/session_manager_service_stub.cpp +++ b/window_scene/session_manager_service/src/session_manager_service_stub.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2023 Huawei Device Co., Ltd. + * Copyright (c) 2023 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 @@ -36,8 +36,9 @@ int32_t SessionManagerServiceStub::OnRemoteRequest(uint32_t code, MessageParcel SessionManagerServiceMessage msgId = static_cast(code); switch(msgId) { - case SessionManagerServiceMessage::TRANS_ID_SCREEN_BASE: { - // TODO + case SessionManagerServiceMessage::TRANS_ID_GET_DEFAULT_DISPLAY_INFO: { + sptr displayInfo = GetDefaultDisplayInfo(); + reply.WriteParcelable(displayInfo); break; } case SessionManagerServiceMessage::TRANS_ID_GET_SCREEN_INFO_BY_ID: { diff --git a/window_scene/sm/BUILD.gn b/window_scene/sm/BUILD.gn new file mode 100644 index 00000000..d9b07990 --- /dev/null +++ b/window_scene/sm/BUILD.gn @@ -0,0 +1,61 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//foundation/window/window_manager/windowmanager_aafwk.gni") + +config("session_manager_public_config") { + include_dirs = [ + "${window_base_path}/window_scene", + + # for window_manager_hilog + "${window_base_path}/utils/include", + "${window_base_path}/window_scene/sm/include", + "${window_base_path}/window_scene/session_manager_service/include", + "${ability_runtime_path}/interfaces/kits/native/ability/ability_runtime", + ] +} + +ohos_shared_library("session_manager") { + sources = [ + "../session_manager_service/src/session_manager_service_proxy.cpp", + "src/session_manager_stub.cpp", + "src/session_manager.cpp", + ] + + cflags_cc = [ "-std=c++17" ] + + public_configs = [ ":session_manager_public_config" ] + + deps = [ + "${graphic_base_path}/graphic_2d/rosen/modules/render_service_client:librender_service_client", + "${window_base_path}/window_scene/common:window_scene_common", + "${window_base_path}/window_scene/session:scene_session", + "${window_base_path}/dmserver:libdms", + "${ability_runtime_services_path}/abilitymgr:abilityms", + ] + + external_deps = [ + "ability_base:want", + "ability_runtime:ability_manager", + "ability_runtime:ability_context_native", + "ace_engine:ace_uicontent", + "c_utils:utils", + "ipc:ipc_core", + "eventhandler:libeventhandler", + "hilog_native:libhilog", + ] + + part_name = "window_manager" + subsystem_name = "window" +} diff --git a/window_scene/sm/include/session_manager.h b/window_scene/sm/include/session_manager.h new file mode 100644 index 00000000..34ac8f80 --- /dev/null +++ b/window_scene/sm/include/session_manager.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021-2023 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 "iremote_object.h" + +namespace OHOS::Rosen { +class AbilityConnection; +class SessionManager { +public: + SessionManager(); + + ~SessionManager(); + + void Init(); + + sptr GetRemoteObject() const; + +private: + void ConnectToService(); + + sptr abilityConnection_; +}; + +} \ No newline at end of file diff --git a/window_scene/sm/include/session_manager_adapter.h b/window_scene/sm/include/session_manager_adapter.h new file mode 100644 index 00000000..998cb3e5 --- /dev/null +++ b/window_scene/sm/include/session_manager_adapter.h @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2021-2023 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. + */ diff --git a/window_scene/sm/include/session_manager_interface.h b/window_scene/sm/include/session_manager_interface.h new file mode 100644 index 00000000..64f57350 --- /dev/null +++ b/window_scene/sm/include/session_manager_interface.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2021-2023 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_WINDOW_SCENE_SESSION_MANAGER_INTERFACE_H +#define FOUNDATION_WINDOW_SCENE_SESSION_MANAGER_INTERFACE_H + +#include + +namespace OHOS::Rosen { +class ISessionManager : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IDisplayManager"); + + enum { + TRANS_ID_ON_SCREEN_CONNECT = 1, + }; + + // test function + virtual void OnScreenConnect(uint32_t id) = 0; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_WINDOW_SCENE_SESSION_MANAGER_INTERFACE_H \ No newline at end of file diff --git a/window_scene/sm/include/session_manager_proxy.h b/window_scene/sm/include/session_manager_proxy.h new file mode 100644 index 00000000..cedcb28e --- /dev/null +++ b/window_scene/sm/include/session_manager_proxy.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2021-2023 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 +#include "session_manager_interface.h" + +namespace OHOS::Rosen { +class SessionManagerProxy : public IRemoteProxy { +public: + explicit SessionManagerProxy(const sptr& impl) : IRemoteProxy(impl) {}; + ~DisplayManagerProxy() = default; + + virtual void OnScreenConnect(uint32_t id) override; + +private: + static inline BrokerDelegator delegator_; + //static inline BrokerDelegator delegator_; +}; + +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/window_scene/sm/include/session_manager_stub.h b/window_scene/sm/include/session_manager_stub.h new file mode 100644 index 00000000..cfdf9820 --- /dev/null +++ b/window_scene/sm/include/session_manager_stub.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2021-2023 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 "session_manager_interface.h" + +#include + +namespace OHOS::Rosen { +class SessionManagerStub : public IRemoteStub { +public: + SessionManagerStub() = default; + ~SessionManagerStub() = default; + + virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, + MessageOption& option) override; +}; + +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/window_scene/sm/src/session_manager adapter.cpp b/window_scene/sm/src/session_manager adapter.cpp new file mode 100644 index 00000000..e69de29b diff --git a/window_scene/sm/src/session_manager.cpp b/window_scene/sm/src/session_manager.cpp new file mode 100644 index 00000000..15a998b4 --- /dev/null +++ b/window_scene/sm/src/session_manager.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2021-2023 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 "session_manager.h" +#include "ability_manager_client.h" +#include "ability_connect_callback_stub.h" +#include "window_manager_hilog.h" +//#include "ability_connection.h" + +namespace OHOS::Rosen { +class AbilityConnection : public AAFwk::AbilityConnectionStub { +public: + void OnAbilityConnectDone( + const AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) override + { + remoteObject_ = remoteObject; + if (remoteObject_ == nullptr) { + WLOG_W("OnAbilityConnectDone::OnAbilityConnectDone, remoteObject_ is nullptr"); + } + } + + void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override + { + remoteObject_ = nullptr; + } + + sptr GetRemoteObject() const + { + return remoteObject_; + } +private: + sptr remoteObject_; +}; + +SessionManager::SessionManager() +{ +} + +SessionManager::~SessionManager() +{ +} + +void SessionManager::Init() +{ + if (!abilityConnection_) { + ConnectToService(); + } +} + +sptr SessionManager::GetRemoteObject() const +{ + if (abilityConnection_) { + return abilityConnection_->GetRemoteObject(); + } + return nullptr; +} + +void SessionManager::ConnectToService() +{ + if (abilityConnection_ == nullptr) { + abilityConnection_ = new AbilityConnection(); + } + if (abilityConnection_ == nullptr) { + WLOG_E("SessionManager::ConnectToService, abilityConnection_ is nullptr"); + return; + } + + AAFwk::Want want; + want.SetElementName("com.ohos.launcher", "com.ohos.launcher.MainAbility"); + ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want, abilityConnection_, nullptr); + if (ret != ERR_OK) { + WLOG_E("SessionManager::ConnectToService failed, errorcode: %{public}d",ret); + } +} + +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/window_scene/sm/src/session_manager_proxy.cpp b/window_scene/sm/src/session_manager_proxy.cpp new file mode 100644 index 00000000..3ad8dab9 --- /dev/null +++ b/window_scene/sm/src/session_manager_proxy.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2021-2023 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 "session_manager_proxy.h" +#include "marshalling_helper.h" +#include "window_manager_hilog.h" + +namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLoglabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "SessionManager"}; +} + +void SessionManager::OnScreenConnect(uint32_t id) +{ + MessageParcel data; + Messageparcel reply; + MessageParcel option; + + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed."); + return; + } + + if (!data.WriteUint32(id)) { + WLOGFE("Write id failed."); + return; + } + + if (Remote()->SendRequest(TRANS_ID_ON_SCREEN_CHANGED, data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed."); + } + +} +} diff --git a/window_scene/sm/src/session_manager_stub.cpp b/window_scene/sm/src/session_manager_stub.cpp new file mode 100644 index 00000000..64a04e4b --- /dev/null +++ b/window_scene/sm/src/session_manager_stub.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2021-2023 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 "session_manager_stub.h" +#include "window_manager_hilog.h" +#include + +namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "SessionManagerStub"}; +} + +int32_t SessionManagerStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, + MessageOption& option) +{ + WLOGFI("code: %{public}u", code); + if (data.ReadInterfaceToken() != GetDescriptor()) { + WLOGFE("InterfaceToken check failed."); + return -1; + } + + switch (code) { + case TRANS_ID_ON_SCREEN_CONNECT: { + uint32_t id = data.ReadUint32(); + WLOGFE("TRANS_ID_ON_SCREEN_CONNECT(id: %u)", id); + // call service function + break; + } + default: + break; + } + + return 0; +} +} // namespace OHOS::Rosen \ No newline at end of file -- Gitee