From 23f503c71b3c59bbf920c7554cf1e60ef6d1465e Mon Sep 17 00:00:00 2001 From: yanxuejun Date: Mon, 21 Apr 2025 15:39:19 +0800 Subject: [PATCH] fix: taihe idl for power_manager Signed-off-by: yanxuejun --- bundle.json | 5 ++ state_manager/frameworks/ets/taihe/BUILD.gn | 19 +++++ .../ets/taihe/ability_delegator/BUILD.gn | 80 +++++++++++++++++++ .../idl/ohos.brightness.taihe | 25 ++++++ .../ability_delegator/src/ani_constructor.cpp | 29 +++++++ .../src/ohos.brightness.impl.cpp | 63 +++++++++++++++ 6 files changed, 221 insertions(+) create mode 100644 state_manager/frameworks/ets/taihe/BUILD.gn create mode 100644 state_manager/frameworks/ets/taihe/ability_delegator/BUILD.gn create mode 100644 state_manager/frameworks/ets/taihe/ability_delegator/idl/ohos.brightness.taihe create mode 100644 state_manager/frameworks/ets/taihe/ability_delegator/src/ani_constructor.cpp create mode 100644 state_manager/frameworks/ets/taihe/ability_delegator/src/ohos.brightness.impl.cpp diff --git a/bundle.json b/bundle.json index 3b15b89..5f5a6f3 100644 --- a/bundle.json +++ b/bundle.json @@ -45,6 +45,7 @@ "jsoncpp", "napi", "power_manager", + "runtime_core", "safwk", "samgr", "sensor", @@ -57,6 +58,7 @@ "base_group": [], "fwk_group": [ "//base/powermgr/display_manager/state_manager/frameworks/napi:brightness", + "//base/powermgr/display_manager/state_manager/frameworks/ets/taihe:display_manager_taihe", "//base/powermgr/display_manager/state_manager/interfaces/inner_api:displaymgr" ], "service_group": [ @@ -70,6 +72,9 @@ "inner_api": [ { "name": "//base/powermgr/display_manager/state_manager/interfaces/inner_api:displaymgr" + }, + { + "name": "//base/powermgr/display_manager/state_manager/frameworks/ets/taihe/ability_delegator:copy_display_manager" } ], "test": [ diff --git a/state_manager/frameworks/ets/taihe/BUILD.gn b/state_manager/frameworks/ets/taihe/BUILD.gn new file mode 100644 index 0000000..278b84d --- /dev/null +++ b/state_manager/frameworks/ets/taihe/BUILD.gn @@ -0,0 +1,19 @@ +# Copyright (c) 2025 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. + +group("display_manager_taihe") { + deps = [ + "ability_delegator:brightness_etc", + "ability_delegator:display_manager_brightness_taihe_native", + ] +} \ No newline at end of file diff --git a/state_manager/frameworks/ets/taihe/ability_delegator/BUILD.gn b/state_manager/frameworks/ets/taihe/ability_delegator/BUILD.gn new file mode 100644 index 0000000..16db850 --- /dev/null +++ b/state_manager/frameworks/ets/taihe/ability_delegator/BUILD.gn @@ -0,0 +1,80 @@ +# Copyright (c) 2025 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/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//build/ohos/taihe_idl/taihe.gni") +import("../../../../../displaymgr.gni") + +copy_taihe_idl("copy_display_manager") { + sources = [ "idl/ohos.brightness.taihe" ] +} + +subsystem_name = "powermgr" +part_name = "display_manager" +taihe_generated_file_path = "$taihe_file_path/out/$subsystem_name/$part_name" + +ohos_taihe("run_taihe") { + taihe_generated_file_path = "$taihe_generated_file_path" + deps = [ ":copy_display_manager" ] + outputs = [ + "$taihe_generated_file_path/src/ohos.brightness.ani.cpp", + "$taihe_generated_file_path/src/ohos.brightness.abi.c", + ] +} + +taihe_shared_library("display_manager_brightness_taihe_native") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + taihe_generated_file_path = "$taihe_generated_file_path" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + sources = get_target_outputs(":run_taihe") + include_dirs = [ "./include" ] + configs = [ + "${displaymgr_utils_path}:utils_config", + "${displaymgr_utils_path}:coverage_flags", + ] + sources += [ + "src/ani_constructor.cpp", + "src/ohos.brightness.impl.cpp", + ] + deps = [ + ":run_taihe", + "${displaymgr_inner_api}:displaymgr", + ] + external_deps = [ + "hilog:libhilog", + "power_manager:powermgr_client", + ] +} + +generate_static_abc("brightness_abc") { + base_url = "$taihe_generated_file_path" + files = [ "$taihe_generated_file_path/@ohos.brightness.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/brightness_abc.abc" + dependencies = [ ":run_taihe" ] +} + +ohos_prebuilt_etc("brightness_etc") { + source = "$target_out_dir/brightness_abc.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":brightness_abc" ] +} \ No newline at end of file diff --git a/state_manager/frameworks/ets/taihe/ability_delegator/idl/ohos.brightness.taihe b/state_manager/frameworks/ets/taihe/ability_delegator/idl/ohos.brightness.taihe new file mode 100644 index 0000000..cf13065 --- /dev/null +++ b/state_manager/frameworks/ets/taihe/ability_delegator/idl/ohos.brightness.taihe @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +@!namespace("@ohos.brightness","brightness") + +@!sts_inject(""" +static { loadLibrary("display_manager_brightness_taihe_native.z") }""") + +@overload("setValue") +function SetValueInt(value: i32): void; + +@overload("setValue") +function SetValueContinuous(value: i32, continuous: bool): void; \ No newline at end of file diff --git a/state_manager/frameworks/ets/taihe/ability_delegator/src/ani_constructor.cpp b/state_manager/frameworks/ets/taihe/ability_delegator/src/ani_constructor.cpp new file mode 100644 index 0000000..95adf36 --- /dev/null +++ b/state_manager/frameworks/ets/taihe/ability_delegator/src/ani_constructor.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 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 "ohos.brightness.ani.hpp" +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + ani_env *env; + if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { + return ANI_ERROR; + } + if (ANI_OK != ohos::brightness::ANIRegister(env)) { + std::cerr << "Error from ohos::brightness::ANIRegister" << std::endl; + return ANI_ERROR; + } + *result = ANI_VERSION_1; + return ANI_OK; +} diff --git a/state_manager/frameworks/ets/taihe/ability_delegator/src/ohos.brightness.impl.cpp b/state_manager/frameworks/ets/taihe/ability_delegator/src/ohos.brightness.impl.cpp new file mode 100644 index 0000000..98d2e29 --- /dev/null +++ b/state_manager/frameworks/ets/taihe/ability_delegator/src/ohos.brightness.impl.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2025 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 "ohos.brightness.proj.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" +#include "display_power_mgr_client.h" +#include "display_log.h" +#include "display_mgr_errors.h" +#include "ohos.brightness.impl.hpp" + +using namespace taihe; +using namespace OHOS::DisplayPowerMgr; + +namespace { +const uint32_t MAX_BRIGHTNESS = DisplayPowerMgrClient::GetInstance().GetMaxBrightness(); +const uint32_t MIN_BRIGHTNESS = DisplayPowerMgrClient::GetInstance().GetMinBrightness(); + +std::map errorTable = { + {DisplayErrors::ERR_CONNECTION_FAIL, "Failed to connect to the service."}, + {DisplayErrors::ERR_PERMISSION_DENIED, "Permission is denied" }, + {DisplayErrors::ERR_SYSTEM_API_DENIED, "System permission is denied" }, + {DisplayErrors::ERR_PARAM_INVALID, "Invalid input parameter." } +}; + +void SetValueInt(int32_t value) +{ + bool continuous = false; + SetValueContinuous(value, continuous); +} + +void SetValueContinuous(int32_t value, bool continuous) +{ + DISPLAY_HILOGD(FEAT_BRIGHTNESS, "ets brightness interface"); + DISPLAY_HILOGI(FEAT_BRIGHTNESS, "Set brightness: %{public}d, %{public}d", value, continuous); + value = value > static_cast(MAX_BRIGHTNESS) ? static_cast(MAX_BRIGHTNESS) : value; + value = value < static_cast(MIN_BRIGHTNESS) ? static_cast(MIN_BRIGHTNESS) : value; + bool isSucc = DisplayPowerMgrClient::GetInstance().SetBrightness(value, 0, continuous); + if (!isSucc) { + DISPLAY_HILOGW(FEAT_BRIGHTNESS, "Failed to set brightness: %{public}d", value); + DisplayErrors error = DisplayPowerMgrClient::GetInstance().GetError(); + if (error != DisplayErrors::ERR_OK) { + taihe::set_business_error(static_cast(error), errorTable[error]); + } + } +} +} // namespace + +TH_EXPORT_CPP_API_SetValueInt(SetValueInt); +TH_EXPORT_CPP_API_SetValueContinuous(SetValueContinuous); -- Gitee