diff --git a/dm/BUILD.gn b/dm/BUILD.gn index 65b3bd51216f23fe2e160102972f47a0cd1c16a1..b109df9fe6b9f9a263cc08a0843bd390023a211c 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 bbb41432a1b7051dfa3a4190d904d0b8a52d2bec..2676f8c97baf354d7bab37f0cfaffaac53d01e9c 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 59ee85214a4f444976253ebd26151168ecdd7d9d..b0972d8eb8ad1bb0bc05bb07cd778156ef07809e 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 0000000000000000000000000000000000000000..2b7297de26c8bd4b85bbd32ffef0aa6880bca52b --- /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 0000000000000000000000000000000000000000..62918fe2795aa72d958956548367c45dc43fc862 --- /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 0000000000000000000000000000000000000000..23e4f5a9aef43a00ed7829bb33eed6e7bf53b380 --- /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 0000000000000000000000000000000000000000..c847abdef7887d56711443bc35715a21d498316d --- /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 0000000000000000000000000000000000000000..7eab83fd18a3ce2f0b6ef898da553a1f0d9788f7 --- /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 1de686cdac4191b9d4f52b95ab4e7a57f53f7f75..f1ad13f4822e7a7283c760ebfc00b6b55291c76c 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 f9eab11ac1f294b0b7820a60229e69ef81d27041..83e3ea5bf6026ab7b522a0c1d9847cdb80cf1401 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 5735ba649bcffa79fe7df5aece96e86945347317..82a1839c6014a6b6c0659c622367f375c46c92c0 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 c47e7f62a25bf15b08e9049500a010a1fcc34eaf..355463068e8f35015dcbb2c0e3136017bc0cc619 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 0000000000000000000000000000000000000000..e547b2f924def529445308fbe2ec8efbcbac7426 --- /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 0000000000000000000000000000000000000000..c4f039ed8fd9a8081c6187289c5d483b4ca6fc87 --- /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 0000000000000000000000000000000000000000..943cd36403d4f64a01d68b2eb9418e2f949de634 --- /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 0000000000000000000000000000000000000000..7eab83fd18a3ce2f0b6ef898da553a1f0d9788f7 --- /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 de6cceec79d0d24398e069184e875287f2b65e2d..50958e609047fbb6583b431d9b140d4c0bdd0c16 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 132de619ec33face968b4627f86c42acb4760674..7c70d8ac1ca3ee58660da06ff4983a1c68ab1270 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 0f34908059a9918ed46d73fd3727fdaf003dae1c..abcba1cc0d077461a68c7a6cb8321b1426c29648 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 68df6f71cf0de63a3f670869388d0b025b429428..0a9dc059c3ffa7633ac5ef968e714367ea8f9e2b 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 67d3906e8b6ce327e0e9ccd259442799b0b1c697..8bb280bd13fb8d750ea20bef403c562b81b20a63 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 b4b1afad9f16cfabacac8d59ef8b2879a43dcbb3..f70a5138f64f52af8cbfa53cad939e5056996abe 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 d3a8daca9b82f608e8867894e4bb0d9f927d0004..219b92a7057877b9233d25227922c88d6eb93927 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 5d765103e7d4a81c9fd3f953ffb3ec161f8b5e6d..8499557ce80c340ff33bd9c66474af793162bf6b 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 84fc9d3df1842e6dcab0271f38f5dc9cac0d51a8..83635bdf6c0dc23efa58ebd91da07103e42309f8 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 d5234ad6f99baf04095d9a03b89c8964b5aa302d..b7731b2cfcd8d59bb5d3182aac1594a11f705bb4 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 404f46270be8f55d647de8a1506f8d26651f22f4..bea2db952b7f453c61ed730d21f6b967968309cf 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 7e9cf0916f48fa6225487fdb6772f5d71a231d1c..44cc4f93cd6fc1416e4a32a0fcd2c33ddef7cca5 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 b98c44da68d0bdcdf39adc8753e24b9cae41baaf..8c893567a02b34627cd13170e677bc599f848341 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 5d81f9c60294d8256b322c9d7c4456f23d37b314..cf8fd38032a5b236e6a9b604c54d1bd2e79be5a3 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 1c8791eb7542aa23bd98b5d0a11da8ec57f2e913..98c0613d94f8623e55e73451134a9e025ad9eb75 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 1d5b53ffa1457ded6f6cff482437196090148f0c..b600a5eeb43a87ad3ca2ec6b7e1891d463e8b8fb 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 11c66b7dd9abdbdee7509db734675c8aefad657d..2e08848329cfc33f4d308e62f036e19d57cd6a02 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 0000000000000000000000000000000000000000..d9b07990024022594265306adc684e9ec8fda618 --- /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 0000000000000000000000000000000000000000..34ac8f8074539e0b6d24a9b4c0762d9475e62766 --- /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 0000000000000000000000000000000000000000..998cb3e5dffe8d713d5b7133dfc34b4b85103156 --- /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 0000000000000000000000000000000000000000..64f5735013a33cee2c44871918289dd1ec4e2424 --- /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 0000000000000000000000000000000000000000..cedcb28e0e057f1e597f088b52be7c5960b6ce17 --- /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 0000000000000000000000000000000000000000..cfdf982013ec68203a036ba8c352234ae0ef8c74 --- /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 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/window_scene/sm/src/session_manager.cpp b/window_scene/sm/src/session_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..15a998b4c947f2b5b476170970c51f3690ffd950 --- /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 0000000000000000000000000000000000000000..3ad8dab9760989c4c110088fe7d7a65001038d1e --- /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 0000000000000000000000000000000000000000..64a04e4baf2eac7cefbeec4d8a07863457018955 --- /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