diff --git a/bundle.json b/bundle.json index 643681cbd07dda628e392b625d0f96f50d222acb..2464480c754a5c8f6cc096c4b1ac836181fe65a2 100644 --- a/bundle.json +++ b/bundle.json @@ -38,7 +38,6 @@ "power_manager_feature_pickup", "power_manager_feature_force_sleep_broadcast", "power_manager_feature_movement", - "power_manager_feature_screen_on_timeout_check", "power_manager_feature_dialog_path", "power_manager_feature_charging_type_setting", "power_manager_feature_external_screen_management", @@ -46,7 +45,8 @@ "power_manager_feature_judging_takeover_shutdown", "power_manager_feature_watch_limit_screen_common_event_publish", "power_manager_feature_watch_update_adapt", - "power_manager_feature_surport_takeover_suspend", + "power_manager_feature_watch_boot_completed", + "power_manager_feature_proximity_controller_override", "power_manager_feature_enable_lid_check" ], "adapted_system_type": [ @@ -145,8 +145,7 @@ "shutdown/shutdown_priority.h", "shutdown/sync_shutdown_callback_stub.h", "shutdown/takeover_info.h", - "shutdown/takeover_shutdown_callback_stub.h", - "suspend/itake_over_suspend_callback.h" + "shutdown/takeover_shutdown_callback_stub.h" ], "header_base": "//base/powermgr/power_manager/interfaces/inner_api/native/include" } diff --git a/etc/para/powermgr.para b/etc/para/powermgr.para index 6097b990cec735662129e8b88810035a92dbfd8c..ea6e69449cac1d1c1b440b4e1ce3326c9449c20d 100644 --- a/etc/para/powermgr.para +++ b/etc/para/powermgr.para @@ -17,4 +17,5 @@ persist.dfx.userclicktime = 0 persist.dfx.shutdownactiontime = 0 persist.dfx.shutdowncompletetime = 0 persist.dfx.eventtype = 0 -const.power.during_call_state_enable = false \ No newline at end of file +const.power.during_call_state_enable = false +const.powerkey.down_duration = 3000 \ No newline at end of file diff --git a/etc/para/powermgr.para.dac b/etc/para/powermgr.para.dac index 017af2ea7005793b8af589c72be8467a67884d1e..5fd0222c71bd762d88821d101f4f311d1431907f 100644 --- a/etc/para/powermgr.para.dac +++ b/etc/para/powermgr.para.dac @@ -17,4 +17,5 @@ persist.dfx.userclicktime = powermgr:powermgr:0776 persist.dfx.shutdownactiontime = powermgr:powermgr:0776 persist.dfx.shutdowncompletetime = powermgr:powermgr:0776 persist.dfx.eventtype = powermgr:powermgr:0776 -const.power.during_call_state_enable = powermgr:powermgr:0444 \ No newline at end of file +const.power.during_call_state_enable = powermgr:powermgr:0444 +const.powerkey.down_duration = powermgr:powermgr:0444 \ No newline at end of file diff --git a/frameworks/napi/power/power.cpp b/frameworks/napi/power/power.cpp index 12ea1edc34551c3b75eda800ae9a02e5e67360ae..8cf927f9dd6a0e72d9cd186e860ad981add88e29 100644 --- a/frameworks/napi/power/power.cpp +++ b/frameworks/napi/power/power.cpp @@ -77,7 +77,7 @@ void Power::IsScreenOnCallBack(napi_env env, std::unique_ptr(data); @@ -102,7 +102,8 @@ void Power::IsScreenOnCallBack(napi_env env, std::unique_ptr(asCallbackInfoPtr.get()), &asCallbackInfoPtr->asyncWork); - if (napi_ok == napi_queue_async_work_with_qos(env, asCallbackInfoPtr->asyncWork, napi_qos_utility)) { + if (napi_ok == napi_queue_async_work_with_qos(env, asCallbackInfoPtr->asyncWork, napi_qos_utility) + && ret == napi_ok) { asCallbackInfoPtr.release(); } } @@ -117,12 +118,14 @@ napi_value Power::IsScreenOn(napi_env env, napi_callback_info info) napi_status status = napi_get_cb_info(env, info, &argc, args, &jsthis, &data); NAPI_ASSERT(env, (status == napi_ok), "Failed to get cb info"); - std::unique_ptr asyncCallbackInfo = std::make_unique(); + auto asyncCallbackInfo = new PowerAsyncCallbackInfo(); if (asyncCallbackInfo == nullptr) { POWER_HILOGE(COMP_FWK, "Failed to create asyncCallbackInfo"); return nullptr; } asyncCallbackInfo->env = env; + + std::unique_ptr asCallbackInfoPtr(asCallbackInfo); napi_valuetype type; if (argc == 1) { NAPI_CALL(env, napi_typeof(env, args[0], &type)); @@ -140,7 +143,7 @@ napi_value Power::IsScreenOn(napi_env env, napi_callback_info info) POWER_HILOGD(COMP_FWK, "callbackRef is not null"); napi_get_undefined(env, &result); } - IsScreenOnCallBack(env, asyncCallbackInfo); + IsScreenOnCallBack(env, asCallbackInfoPtr); return result; } diff --git a/frameworks/native/power_mgr_client.cpp b/frameworks/native/power_mgr_client.cpp index bb7f756c2a2f58f4417a6de97c2d12e7c904f3a7..09178c1c92842250fb4af6c392768d7d3c59ffe1 100644 --- a/frameworks/native/power_mgr_client.cpp +++ b/frameworks/native/power_mgr_client.cpp @@ -458,31 +458,6 @@ bool PowerMgrClient::UnRegisterSyncSleepCallback(const sptr& return ret == ERR_OK; } -bool PowerMgrClient::RegisterSuspendTakeoverCallback(const sptr& callback, - TakeOverSuspendPriority priority) -{ - POWER_HILOGI(FEATURE_SUSPEND, "%{public}s start", __func__); - sptr proxy = GetPowerMgrProxy(); - if ((callback == nullptr) || (proxy == nullptr)) { - POWER_HILOGE(FEATURE_SUSPEND, "%{public}s callback or proxy is nullptr", __func__); - return false; - } - int32_t ret = proxy->RegisterSuspendTakeoverCallbackIpc(callback, static_cast(priority)); - return ret == ERR_OK; -} - -bool PowerMgrClient::UnRegisterSuspendTakeoverCallback(const sptr& callback) -{ - POWER_HILOGI(FEATURE_SUSPEND, "%{public}s start", __func__); - sptr proxy = GetPowerMgrProxy(); - if ((callback == nullptr) || (proxy == nullptr)) { - POWER_HILOGE(FEATURE_SUSPEND, "%{public}s callback or proxy is nullptr", __func__); - return false; - } - int32_t ret = proxy->UnRegisterSuspendTakeoverCallbackIpc(callback); - return ret == ERR_OK; -} - bool PowerMgrClient::RegisterSyncHibernateCallback(const sptr& callback) { sptr proxy = GetPowerMgrProxy(); diff --git a/interfaces/inner_api/BUILD.gn b/interfaces/inner_api/BUILD.gn index 6a25965bdacb0abd28adca17e596b4360e132970..48b3ec3b3587deee1a41543d887136360efc0591 100644 --- a/interfaces/inner_api/BUILD.gn +++ b/interfaces/inner_api/BUILD.gn @@ -39,16 +39,16 @@ config("powermgr_ipc_config") { "${target_gen_dir}", ] } - + idl_gen_interface("powermgr_interface") { sources = [ "IPowerMgr.idl" ] - + log_domainid = "0xD002902" log_tag = "PowerSvc" subsystem_name = "powermgr" part_name = "${powermgr_part_name}" } - + ohos_source_set("powermgr_proxy") { sanitize = { cfi = true @@ -61,22 +61,22 @@ ohos_source_set("powermgr_proxy") { "${powermgr_utils_path}:utils_config", "${powermgr_utils_path}:coverage_flags", ] - + public_configs = [ ":powermgr_ipc_config" ] - + deps = [ ":powermgr_interface" ] - + external_deps = [ "c_utils:utils", "hilog:libhilog", "ipc:ipc_core", "ipc:ipc_single", ] - + subsystem_name = "powermgr" part_name = "${powermgr_part_name}" } - + ohos_source_set("powermgr_stub") { sanitize = { cfi = true @@ -93,19 +93,19 @@ ohos_source_set("powermgr_stub") { "${powermgr_service_zidl}/src/screen_off_pre_callback_stub.cpp", "${powermgr_service_zidl}/src/sync_sleep_callback_stub.cpp", ] - + configs = [ "${powermgr_utils_path}:utils_config", "${powermgr_utils_path}:coverage_flags", ] - + public_configs = [ ":powermgr_ipc_config" ] - + deps = [ ":powermgr_interface", ":powermgr_client", ] - + external_deps = [ "c_utils:utils", "hicollie:libhicollie", @@ -113,11 +113,11 @@ ohos_source_set("powermgr_stub") { "ipc:ipc_core", "ipc:ipc_single", ] - + subsystem_name = "powermgr" part_name = "${powermgr_part_name}" } - + ohos_shared_library("powermgr_client") { branch_protector_ret = "pac_ret" @@ -147,8 +147,6 @@ ohos_shared_library("powermgr_client") { "${powermgr_service_zidl}/src/sync_hibernate_callback_stub.cpp", "${powermgr_service_zidl}/src/sync_sleep_callback_proxy.cpp", "${powermgr_service_zidl}/src/sync_sleep_callback_stub.cpp", - "${powermgr_service_zidl}/src/takeover_suspend_callback_proxy.cpp", - "${powermgr_service_zidl}/src/takeover_suspend_callback_stub.cpp", ] output_values = get_target_outputs(":powermgr_interface") @@ -161,8 +159,8 @@ ohos_shared_library("powermgr_client") { ] public_configs = [ - ":powermgr_ipc_config", ":powermgr_public_config", + ":powermgr_ipc_config", "${powermgr_utils_path}:utils_config", ] diff --git a/interfaces/inner_api/IPowerMgr.idl b/interfaces/inner_api/IPowerMgr.idl index f5f4a495a8c2bf92552f68c0c68a397cff68edf7..76cdef41da504fe01b1a5db8b02314ffad4eac5d 100644 --- a/interfaces/inner_api/IPowerMgr.idl +++ b/interfaces/inner_api/IPowerMgr.idl @@ -26,7 +26,6 @@ interface OHOS.PowerMgr.IAsyncShutdownCallback; interface OHOS.PowerMgr.ISyncShutdownCallback; interface OHOS.PowerMgr.IPowerRunninglockCallback; interface OHOS.PowerMgr.IPowerMgrAsync; -interface OHOS.PowerMgr.ITakeOverSuspendCallback; interface OHOS.PowerMgr.IPowerMgr { [ipccode 0] void CreateRunningLockIpc( @@ -69,9 +68,6 @@ interface OHOS.PowerMgr.IPowerMgr { void RegisterSyncSleepCallbackIpc([in] ISyncSleepCallback powerCallback, [in] int priorityValue); void UnRegisterSyncSleepCallbackIpc([in] ISyncSleepCallback powerCallback); - void RegisterSuspendTakeoverCallbackIpc([in] ITakeOverSuspendCallback takeOverSuspendCallback, [in] int priority); - void UnRegisterSuspendTakeoverCallbackIpc([in] ITakeOverSuspendCallback takeOverSuspendCallback); - void RegisterSyncHibernateCallbackIpc([in] ISyncHibernateCallback powerCallback); void UnRegisterSyncHibernateCallbackIpc([in] ISyncHibernateCallback powerCallback); diff --git a/interfaces/inner_api/native/include/power_mgr_client.h b/interfaces/inner_api/native/include/power_mgr_client.h index f7429f41c5676be6dc6f4afc4d9410b78d33765f..bf33b7c0b3f7f371502c502735459dbdfb5c83a3 100644 --- a/interfaces/inner_api/native/include/power_mgr_client.h +++ b/interfaces/inner_api/native/include/power_mgr_client.h @@ -21,12 +21,14 @@ #include "power_state_machine_info.h" #include "running_lock.h" -#include "suspend/itake_over_suspend_callback.h" -#include "isync_sleep_callback.h" namespace OHOS { namespace PowerMgr { class PowerMgrClient final { +private: + PowerMgrClient(); + DISALLOW_COPY_AND_MOVE(PowerMgrClient); + public: static PowerMgrClient& GetInstance(); virtual ~PowerMgrClient(); @@ -195,9 +197,6 @@ public: bool UnRegisterSyncHibernateCallback(const sptr& callback); bool RegisterSyncSleepCallback(const sptr& callback, SleepPriority priority); bool UnRegisterSyncSleepCallback(const sptr& callback); - bool RegisterSuspendTakeoverCallback( - const sptr& callback, TakeOverSuspendPriority priority); - bool UnRegisterSuspendTakeoverCallback(const sptr& callback); bool RegisterPowerModeCallback(const sptr& callback); bool UnRegisterPowerModeCallback(const sptr& callback); void RecoverRunningLocks(); @@ -240,10 +239,6 @@ private: static std::mutex runningLocksMutex_; sptr token_ {nullptr}; PowerErrors error_ = PowerErrors::ERR_OK; - -private: - PowerMgrClient(); - DISALLOW_COPY_AND_MOVE(PowerMgrClient); }; } // namespace PowerMgr } // namespace OHOS diff --git a/interfaces/inner_api/native/include/suspend/itake_over_suspend_callback.h b/interfaces/inner_api/native/include/suspend/itake_over_suspend_callback.h deleted file mode 100644 index 09c93510cbd54d469a4a79372027421059d8ff0f..0000000000000000000000000000000000000000 --- a/interfaces/inner_api/native/include/suspend/itake_over_suspend_callback.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ - -#ifndef POWERMGR_ITAKEOVER_SUSPEND_CALLBACK_H -#define POWERMGR_ITAKEOVER_SUSPEND_CALLBACK_H - -#include -#include "takeover_suspend_priority.h" -#include "power_state_machine_info.h" - -namespace OHOS { -namespace PowerMgr { -class ITakeOverSuspendCallback : public IRemoteBroker { -public: - virtual ~ITakeOverSuspendCallback() = default; - /** - * If return true, the registrant should trigger the screen off process subsequently. - */ - virtual bool OnTakeOverSuspend(SuspendDeviceType type) = 0; - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.powermgr.ITakeOverSuspendCallback"); -}; -} // namespace PowerMgr -} // namespace OHOS -#endif // POWERMGR_ITAKEOVER_SUSPEND_CALLBACK_H \ No newline at end of file diff --git a/interfaces/inner_api/native/include/suspend/take_over_callback_ipc_interface_code.h b/interfaces/inner_api/native/include/suspend/take_over_callback_ipc_interface_code.h deleted file mode 100644 index f3bede167754b105b2b348695a309f6d0a681000..0000000000000000000000000000000000000000 --- a/interfaces/inner_api/native/include/suspend/take_over_callback_ipc_interface_code.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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. - */ -#ifndef TAKE_OVER_SUSPEND_CALLBACK_INTERFACE_CODE_H -#define TAKE_OVER_SUSPEND_CALLBACK_INTERFACE_CODE_H -namespace OHOS { -namespace PowerMgr { -enum class TakeOverSuspendCallbackInterfaceCode { - CMD_ON_TAKEOVER_SUSPEND = 0, -}; -} // namespace PowerMgr -} // namespace OHOS -#endif // TAKE_OVER_SUSPEND_CALLBACK_INTERFACE_CODE_H \ No newline at end of file diff --git a/interfaces/inner_api/native/include/suspend/takeover_suspend_priority.h b/interfaces/inner_api/native/include/suspend/takeover_suspend_priority.h deleted file mode 100644 index 55d1fd8db5046f6ba65c735d889dbc09be4238a1..0000000000000000000000000000000000000000 --- a/interfaces/inner_api/native/include/suspend/takeover_suspend_priority.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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. - */ -#ifndef POWERMGR_SUSPEND_PRIORITY_H -#define POWERMGR_SUSPEND_PRIORITY_H - -namespace OHOS { -namespace PowerMgr { -/** - * Suspend or reboot priority - */ -enum class TakeOverSuspendPriority : uint32_t { - /** Low priority */ - LOW = 0, - /** Default priority */ - DEFAULT = 1, - /** High priority */ - HIGH = 2, -}; -} // namespace PowerMgr -} // namespace OHOS -#endif // POWERMGR_SUSPEND_PRIORITY_H \ No newline at end of file diff --git a/power_dialog/build-profile.json5 b/power_dialog/build-profile.json5 index 8d874b057222e9c5778ab11636cc5eafa09491c3..8d3a53dfc831fc25f442d0abd9687e5426f0ffb0 100644 --- a/power_dialog/build-profile.json5 +++ b/power_dialog/build-profile.json5 @@ -18,8 +18,7 @@ { "name": "default", "compileSdkVersion": 20, - "compatibleSdkVersion": 20, - "targetSdkVersion": 20, + "compatibleSdkVersion": 16, "runtimeOS": "OpenHarmony", "signingConfig": "default" } diff --git a/powermgr.gni b/powermgr.gni index fb7d30b6488fd3585777b86a790a28323aa478c6..d9cc69e900884c016219281cd43999d80cce8def 100644 --- a/powermgr.gni +++ b/powermgr.gni @@ -40,27 +40,18 @@ declare_args() { power_manager_feature_watch_limit_screen_common_event_publish = false power_manager_feature_watch_update_adapt = false power_manager_feature_watch_boot_completed = false - power_manager_feature_surport_takeover_suspend = false - power_manager_feature_init_proximity_controller = false + power_manager_feature_proximity_controller_override = false power_manager_feature_enable_lid_check = false } defines = [] -if (power_manager_feature_enable_s4) { - defines += [ "POWER_MANAGER_POWER_ENABLE_S4" ] -} - -if (power_manager_feature_enable_suspend_with_tag) { - defines += [ "POWER_MANAGER_ENABLE_SUSPEND_WITH_TAG" ] -} - if (power_manager_feature_audio_lock_unproxy) { defines += [ "POWER_MANAGER_AUDIO_LOCK_UNPROXY" ] } -if (power_manager_feature_init_proximity_controller) { - defines += [ "POWER_MANAGER_INIT_PROXIMITY_CONTROLLER" ] +if (power_manager_feature_proximity_controller_override) { + defines += [ "POWER_MANAGER_PROXIMITY_CONTROLLER_OVERRIDE" ] } if (power_manager_feature_enable_lid_check) { @@ -130,6 +121,14 @@ if (!defined(global_parts_info) || has_ability_runtime_part = false } +if (power_manager_feature_enable_s4) { + defines += [ "POWER_MANAGER_POWER_ENABLE_S4" ] +} + +if (power_manager_feature_enable_suspend_with_tag) { + defines += [ "POWER_MANAGER_ENABLE_SUSPEND_WITH_TAG" ] +} + ability_runtime_path = "//foundation/ability/ability_runtime" ability_runtime_inner_api_path = "${ability_runtime_path}/interfaces/inner_api" diff --git a/services/BUILD.gn b/services/BUILD.gn index f65d7af9d0a3229e7d7995882c202e5bb9d233e4..872baa643953943fa9a2720c18ca52edc3f5a7b9 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -104,6 +104,7 @@ ohos_shared_library("powermgrservice") { "${powermgr_utils_path}/permission:power_permission", "${powermgr_utils_path}/vibrator:power_vibrator", "native/src/actions:powermgr_actions", + "${powermgr_utils_path}/appmgr:power_appmgr", ] external_deps = [ @@ -242,6 +243,7 @@ ohos_shared_library("powermgrservice") { defines += [ "CONFIG_FACTORY_MODE" ] } + if (power_manager_feature_judging_takeover_shutdown) { defines += [ "POWER_MANAGER_ENABLE_JUDGING_TAKEOVER_SHUTDOWN" ] } @@ -264,13 +266,6 @@ ohos_shared_library("powermgrservice") { defines += [ "POWER_MANAGER_ENABLE_WATCH_BOOT_COMPLETED" ] } - if (power_manager_feature_surport_takeover_suspend) { - sources += [ - "native/src/suspend/suspend_takeover_callback_holder.cpp", - ] - defines += [ "POWER_MANAGER_TAKEOVER_SUSPEND" ] - } - subsystem_name = "powermgr" part_name = "${powermgr_part_name}" } diff --git a/services/native/include/power_hdi_callback.h b/services/native/include/power_hdi_callback.h index 7800c407a660b1cd4d0de81dbdff180ffb13847b..b615ddac01c5ffa76ba2b09f76edef5822861bef 100644 --- a/services/native/include/power_hdi_callback.h +++ b/services/native/include/power_hdi_callback.h @@ -40,6 +40,7 @@ public: int32_t OnWakeupWithTag(const std::string& tag) override; }; -} // OHOS -} // PowerMgr + +} // namespace PowerMgr +} // namespace OHOS #endif // POWERMGR_POWER_MANAGER_POWER_HDI_CALLBACK_H diff --git a/services/native/include/power_mgr_service.h b/services/native/include/power_mgr_service.h index 801f6893a194cda1cd74a384ca8d3cd1e3f73fec..24d010f8c7eec6af7e2660ed0d4b6d2671b11b1a 100644 --- a/services/native/include/power_mgr_service.h +++ b/services/native/include/power_mgr_service.h @@ -117,9 +117,6 @@ public: virtual bool RegisterSyncSleepCallback(const sptr& callback, SleepPriority priority) override; virtual bool UnRegisterSyncSleepCallback(const sptr& callback) override; - virtual bool RegisterSuspendTakeoverCallback(const sptr& callback, - TakeOverSuspendPriority priority) override; - virtual bool UnRegisterSuspendTakeoverCallback(const sptr& callback) override; virtual bool RegisterSyncHibernateCallback(const sptr& callback) override; virtual bool UnRegisterSyncHibernateCallback(const sptr& callback) override; diff --git a/services/native/include/power_mgr_service_ipc_adapter.h b/services/native/include/power_mgr_service_ipc_adapter.h index 7f7260894080a350ec3224ab90788eda74160d08..39bbfc33d1b634c574b816f800bfbe9793d8974c 100644 --- a/services/native/include/power_mgr_service_ipc_adapter.h +++ b/services/native/include/power_mgr_service_ipc_adapter.h @@ -71,10 +71,6 @@ public: virtual int32_t RegisterSyncHibernateCallbackIpc(const sptr& callback) override; virtual int32_t UnRegisterSyncHibernateCallbackIpc(const sptr& callback) override; - virtual int32_t RegisterSuspendTakeoverCallbackIpc( - const sptr& callback, int32_t priority) override; - virtual int32_t UnRegisterSuspendTakeoverCallbackIpc(const sptr& callback) override; - virtual int32_t RegisterPowerModeCallbackIpc(const sptr& callback) override; virtual int32_t UnRegisterPowerModeCallbackIpc(const sptr& callback) override; @@ -175,10 +171,6 @@ public: virtual void UnRegisterShutdownCallback(const sptr& callback) = 0; virtual void RegisterShutdownCallback(const sptr& callback, ShutdownPriority priority) = 0; virtual void UnRegisterShutdownCallback(const sptr& callback) = 0; - - virtual bool RegisterSuspendTakeoverCallback( - const sptr& callback, TakeOverSuspendPriority priority) = 0; - virtual bool UnRegisterSuspendTakeoverCallback(const sptr& callback) = 0; }; } // namespace PowerMgr } // namespace OHOS diff --git a/services/native/include/power_state_machine.h b/services/native/include/power_state_machine.h index a2665ed5ece6b4be2536d1951f74da6c3cf10f02..52266a2384b183bdf2fa86e7be07259508e4820b 100644 --- a/services/native/include/power_state_machine.h +++ b/services/native/include/power_state_machine.h @@ -31,7 +31,6 @@ #include "running_lock_info.h" #include "power_mgr_notify.h" #include "window_manager_lite.h" -#include "suspend/itake_over_suspend_callback.h" #include "parameters.h" namespace OHOS { @@ -66,7 +65,6 @@ enum class TransitResult { DISPLAY_OFF_ERR = 5, FORBID_TRANSIT = 6, PRE_BRIGHT_ERR = 7, - TAKEN_OVER = 8, OTHER_ERR = 99 }; @@ -80,7 +78,7 @@ public: CHECK_USER_ACTIVITY_OFF_TIMEOUT_MSG, CHECK_PRE_BRIGHT_AUTH_TIMEOUT_MSG, CHECK_PROXIMITY_SCREEN_OFF_MSG, - SET_INTERNAL_SCREEN_STATE_MSG, + SWITCH_TRIGGER_WAKEUP_OR_SUSPEND_MSG, CHECK_PROXIMITY_SCREEN_SWITCH_TO_SUB_MSG, }; @@ -93,7 +91,7 @@ public: #ifdef POWER_MANAGER_ENABLE_CHARGING_TYPE_SETTING static constexpr int32_t DEFAULT_AC_DISPLAY_OFF_TIME_MS = 600000; - static constexpr int32_t DEFAULT_DC_DISPLAY_OFF_TIME_MS = 300000 + static constexpr int32_t DEFAULT_DC_DISPLAY_OFF_TIME_MS = 300000; static constexpr int32_t DEFAULT_DISPLAY_OFF_TIME_MS = DEFAULT_DC_DISPLAY_OFF_TIME_MS; #else static constexpr int32_t DEFAULT_DISPLAY_OFF_TIME_MS = 30000; @@ -164,7 +162,6 @@ public: void SetDisplaySuspend(bool enable); void WriteHiSysEvent(TransitResult ret, StateChangeReason reason, int32_t beginTimeMs, PowerState state); bool IsTransitFailed(TransitResult ret); - SuspendDeviceType GetSuspendTypeByReason(StateChangeReason reason); StateChangeReason GetReasonByWakeType(WakeupDeviceType type); StateChangeReason GetReasonBySuspendType(SuspendDeviceType type); #ifdef POWER_MANAGER_ENABLE_EXTERNAL_SCREEN_MANAGEMENT @@ -397,9 +394,6 @@ private: bool ReportScreenOffInvalidEvent(StateChangeReason reason); bool ReportAbnormalScreenOffEvent(StateChangeReason reason); #endif -#ifdef POWER_MANAGER_TAKEOVER_SUSPEND - TransitResult TakeOverSuspendAction(StateChangeReason reason); -#endif const wptr pms_; std::shared_ptr ffrtTimer_ {nullptr}; diff --git a/services/native/src/actions/default/device_power_action.cpp b/services/native/src/actions/default/device_power_action.cpp index 8a7308775bd8774d48594b55b079b88a9eb73c0d..b3716931110b7ae81058d00fe2442a4f04146a45 100644 --- a/services/native/src/actions/default/device_power_action.cpp +++ b/services/native/src/actions/default/device_power_action.cpp @@ -26,26 +26,18 @@ const std::string INVALID_CMD = "invalid_cmd"; const std::string UPDATER_CMD = "updater"; const std::string REBOOT_CMD = ""; const std::string SHUTDOWN_CMD = "shutdown"; -const std::string FLASH_CMD = "flash"; } namespace OHOS { namespace PowerMgr { void DevicePowerAction::Reboot(const std::string& reason) { - std::string rebootCmd; - RebootCmdInfo rebootInfo = {.rebootReason = reason, .rebootCmd = INVALID_CMD}; - HOOK_EXEC_OPTIONS options {TRAVERSE_STOP_WHEN_ERROR, nullptr, nullptr}; + RebootCmdInfo rebootInfo = {.rebootReason = reason, .rebootCmd = Updater(reason)}; HOOK_MGR* hookMgr = GetPowerHookMgr(); - if (HookMgrExecute(hookMgr, static_cast(PowerHookStage::POWER_PRE_DO_REBOOT), - &rebootInfo, &options) == 0) { - rebootCmd = rebootInfo.rebootCmd; - } else { - rebootCmd = Updater(reason); - } - POWER_KHILOGI(FEATURE_SHUTDOWN, - "Reboot reason: %{public}s, command: %{public}s", reason.c_str(), rebootCmd.c_str()); - DoRebootExt(rebootCmd.c_str(), reason.c_str()); + HookMgrExecute(hookMgr, static_cast(PowerHookStage::POWER_PRE_DO_REBOOT), &rebootInfo, nullptr); + POWER_KHILOGI(FEATURE_SHUTDOWN, "Reboot reason: %{public}s, command: %{public}s", reason.c_str(), + rebootInfo.rebootCmd.c_str()); + DoRebootExt(rebootInfo.rebootCmd.c_str(), reason.c_str()); } void DevicePowerAction::Shutdown(const std::string& reason) diff --git a/services/native/src/actions/default/system_suspend_controller.cpp b/services/native/src/actions/default/system_suspend_controller.cpp index f1bb4eb075ae11d04820c159c1cf2393f91cc2aa..68469fcad547c7cee38175faeb0759ac63d1372c 100644 --- a/services/native/src/actions/default/system_suspend_controller.cpp +++ b/services/native/src/actions/default/system_suspend_controller.cpp @@ -29,6 +29,7 @@ constexpr uint32_t RETRY_TIME = 1000; constexpr int32_t ERR_FAILED = -1; using namespace OHOS::HDI::Power; using namespace OHOS::HDI::Power::V1_2; + } // namespace SystemSuspendController::SystemSuspendController() {} diff --git a/services/native/src/power_hdi_callback.cpp b/services/native/src/power_hdi_callback.cpp index 65556b1ccb7d60631ce772bcdae1cf34575f14e9..57e8c453dcf3783acd55c302c49a63e966944e3b 100644 --- a/services/native/src/power_hdi_callback.cpp +++ b/services/native/src/power_hdi_callback.cpp @@ -30,20 +30,20 @@ int32_t PowerHdiCallback::OnSuspend() int32_t PowerHdiCallback::OnWakeup() { - POWER_HILOGD(FEATURE_WAKEUP, "OnSuspend"); + POWER_HILOGD(FEATURE_WAKEUP, "OnWakeup"); return HDF_SUCCESS; } -int32_t PowerHdiCallbackExt::OnSuspendWithTag(const std::string& tag) +int32_t PowerHdiCallbackExt::OnSuspendWithTag(const std::string &tag) { POWER_HILOGD(FEATURE_SUSPEND, "OnSuspendWithTag, tag:%{public}s", tag.c_str()); return HDF_SUCCESS; } -int32_t PowerHdiCallbackExt::OnWakeupWithTag(const std::string& tag) +int32_t PowerHdiCallbackExt::OnWakeupWithTag(const std::string &tag) { POWER_HILOGD(FEATURE_WAKEUP, "OnWakeupWithTag, tag:%{public}s", tag.c_str()); return HDF_SUCCESS; } -} // OHOS } // PowerMgr +} // OHOS diff --git a/services/native/src/power_mgr_service.cpp b/services/native/src/power_mgr_service.cpp index 550085d3d6c70b1c3d5c13a60719caffe2fc1819..9523b5eedf7b25a122615e288655d6ada11416a3 100644 --- a/services/native/src/power_mgr_service.cpp +++ b/services/native/src/power_mgr_service.cpp @@ -38,8 +38,8 @@ #include "ability_manager_client.h" #include "ffrt_utils.h" #include "permission.h" -#include "power_common.h" #include "power_ext_intf_wrapper.h" +#include "power_common.h" #include "power_mgr_dumper.h" #include "power_vibrator.h" #include "power_xcollie.h" @@ -133,7 +133,7 @@ void PowerMgrService::OnStart() SystemSuspendController::GetInstance().RegisterHdiStatusListener(); PowerExtIntfWrapper::Instance().Init(); #endif - + if (!Publish(DelayedSpSingleton::GetInstance())) { POWER_HILOGE(COMP_SVC, "Register to system ability manager failed"); return; @@ -176,7 +176,7 @@ void PowerMgrService::RegisterBootCompletedCallback() POWER_HILOGI(COMP_SVC, "plan to RegisterBootCompletedCallback."); g_bootCompletedCallback = []() { std::lock_guard lock(powerInitMutex_); - if (!isNeedReInit_ ) { + if (!isNeedReInit_) { POWER_HILOGW(COMP_SVC, "Power initialization is not required."); return; } @@ -205,6 +205,7 @@ void PowerMgrService::RegisterBootCompletedCallback() #endif power->SwitchSubscriberInit(); power->InputMonitorInit(); + SettingHelper::UpdateCurrentUserId(); power->SuspendControllerInit(); power->WakeupControllerInit(); power->SubscribeCommonEvent(); @@ -789,13 +790,18 @@ void PowerMgrService::OnAddSystemAbility(int32_t systemAbilityId, const std::str this->GetPowerModeModule().InitPowerMode(); } } +#ifdef HAS_DISPLAY_MANAGER_PART if (systemAbilityId == DISPLAY_MANAGER_SERVICE_ID) { +#else + if (systemAbilityId == DISPLAY_MANAGER_SERVICE_SA_ID) { +#endif std::lock_guard lock(powerInitMutex_); POWER_HILOGI(COMP_SVC, "get DISPLAY_MANAGER_SERVICE_ID in PowerService"); isNeedReInit_ = true; RegisterBootCompletedCallback(); } +#ifdef HAS_DISPLAY_MANAGER_PART if (systemAbilityId == DISPLAY_MANAGER_SERVICE_SA_ID) { std::lock_guard lock(powerInitMutex_); POWER_HILOGI(COMP_SVC, "get DISPLAY_MANAGER_SERVICE_SA_ID in PowerService"); @@ -805,6 +811,7 @@ void PowerMgrService::OnAddSystemAbility(int32_t systemAbilityId, const std::str displayManagerServiceCrash_ = false; } } +#endif #ifdef MSDP_MOVEMENT_ENABLE if (systemAbilityId == MSDP_MOVEMENT_SERVICE_ID) { auto power = DelayedSpSingleton::GetInstance(); @@ -1113,7 +1120,7 @@ PowerErrors PowerMgrService::SuspendDevice( #ifdef POWER_MANAGER_ENABLE_WATCH_BOOT_COMPLETED if (isBootCompleted_ == false) { - POWER_HILOGI(FEATURE_SUSPEND, "SuspendDevice failed, not boot completed, pid: %{public}d, uid: %{public}d", + POWER_HILOGE(FEATURE_SUSPEND, "SuspendDevice failed, not boot completed, pid: %{public}d, uid: %{public}d", pid, uid); return PowerErrors::ERR_FAILURE; } @@ -1146,7 +1153,7 @@ PowerErrors PowerMgrService::WakeupDevice( #ifdef POWER_MANAGER_ENABLE_WATCH_BOOT_COMPLETED if (isBootCompleted_ == false) { - POWER_HILOGI(FEATURE_WAKEUP, "WakeupDevice failed, not boot completed, pid: %{public}d, uid: %{public}d", + POWER_HILOGE(FEATURE_WAKEUP, "WakeupDevice failed, not boot completed, pid: %{public}d, uid: %{public}d", pid, uid); return PowerErrors::ERR_FAILURE; } @@ -1656,47 +1663,6 @@ bool PowerMgrService::UnRegisterSyncSleepCallback(const sptr return true; } -bool PowerMgrService::RegisterSuspendTakeoverCallback( - const sptr& callback, TakeOverSuspendPriority priority) -{ -#ifdef POWER_MANAGER_TAKEOVER_SUSPEND - std::lock_guard lock(suspendMutex_); - pid_t pid = IPCSkeleton::GetCallingPid(); - auto uid = IPCSkeleton::GetCallingUid(); - if (!Permission::IsPermissionGranted("ohos.permission.POWER_MANAGER")) { - POWER_HILOGE(FEATURE_SUSPEND, "Permission deny"); - return false; - } - POWER_HILOGI(FEATURE_SUSPEND, "Func %{public}s: pid: %{public}d, uid: %{public}d", __func__, pid, uid); - if (suspendController_ == nullptr) { - POWER_HILOGE(FEATURE_SUSPEND, "suspendController_ is nullptr"); - return false; - } - suspendController_->AddCallback(callback, priority); - return true; -#else - return true; -#endif -} - -bool PowerMgrService::UnRegisterSuspendTakeoverCallback(const sptr& callback) -{ -#ifdef POWER_MANAGER_TAKEOVER_SUSPEND - std::lock_guard lock(suspendMutex_); - pid_t pid = IPCSkeleton::GetCallingPid(); - auto uid = IPCSkeleton::GetCallingUid(); - if (!Permission::IsPermissionGranted("ohos.permission.POWER_MANAGER")) { - POWER_HILOGE(FEATURE_SUSPEND, "Permission deny"); - return false; - } - POWER_HILOGI(FEATURE_SUSPEND, "Func %{public}s: pid: %{public}d, uid: %{public}d", __func__, pid, uid); - suspendController_->RemoveCallback(callback); - return true; -#else - return true; -#endif -} - bool PowerMgrService::RegisterSyncHibernateCallback(const sptr& callback) { #ifdef POWER_MANAGER_POWER_ENABLE_S4 @@ -2118,7 +2084,7 @@ void PowerMgrInputMonitor::OnInputEvent(std::shared_ptr keyEvent) cons stateMachine->IsRunningLockEnabled(RunningLockType::RUNNINGLOCK_COORDINATION) && stateMachine->GetState() == PowerState::AWAKE) { stateMachine->SetState(PowerState::DIM, StateChangeReason::STATE_CHANGE_REASON_COORDINATION, true); - POWER_HILOGD(FEATURE_INPUT, "remote key event in coordinated state, override screen off time"); + POWER_HILOGD(FEATURE_INPUT, "remote Key event in coordinated state, override screen off time"); } } diff --git a/services/native/src/power_mgr_service_ipc_adapter.cpp b/services/native/src/power_mgr_service_ipc_adapter.cpp index 4b55d65144618fec4b9f17b764f75c61f50f7e0b..fea9c685f76cb9599cff6c1174bd264ce9e7e58c 100644 --- a/services/native/src/power_mgr_service_ipc_adapter.cpp +++ b/services/native/src/power_mgr_service_ipc_adapter.cpp @@ -307,42 +307,6 @@ int32_t PowerMgrServiceAdapter::RegisterPowerModeCallbackIpc(const sptr& callback, int32_t priority) -{ -#ifdef POWER_MANAGER_TAKEOVER_SUSPEND - if (callback == nullptr) { - POWER_HILOGE(FEATURE_SUSPEND, "callback is nullptr"); - return INIT_VALUE; - } - PowerXCollie powerXCollie("PowerMgrServiceAdapter::RegisterSuspendTakeoverCallback", false); - if (priority < static_cast(TakeOverSuspendPriority::LOW) || - priority > static_cast(TakeOverSuspendPriority::HIGH)) { - return INIT_VALUE; - } - TakeOverSuspendPriority takeOverSuspendPriority = static_cast(priority); - RegisterSuspendTakeoverCallback(callback, takeOverSuspendPriority); - return ERR_OK; -#else - return ERR_OK; -#endif -} - -int32_t PowerMgrServiceAdapter::UnRegisterSuspendTakeoverCallbackIpc(const sptr& callback) -{ -#ifdef POWER_MANAGER_TAKEOVER_SUSPEND - if (callback == nullptr) { - POWER_HILOGE(FEATURE_SUSPEND, "callback is nullptr"); - return INIT_VALUE; - } - PowerXCollie powerXCollie("PowerMgrServiceAdapter::UnRegisterSuspendTakeoverCallback", false); - UnRegisterSuspendTakeoverCallback(callback); - return ERR_OK; -#else - return ERR_OK; -#endif -} - int32_t PowerMgrServiceAdapter::UnRegisterPowerModeCallbackIpc(const sptr& callback) { PowerXCollie powerXCollie("PowerMgrServiceAdapter::UnRegisterPowerModeCallback", false); diff --git a/services/native/src/power_state_machine.cpp b/services/native/src/power_state_machine.cpp index dfe4a104bb2290e75222e4d04dbeb817eda4f2ba..765c33d8b4ba73f056aabfb549345beee4115372 100644 --- a/services/native/src/power_state_machine.cpp +++ b/services/native/src/power_state_machine.cpp @@ -358,12 +358,6 @@ void PowerStateMachine::EmplaceInactive() controllerMap_.emplace(PowerState::INACTIVE, std::make_shared(PowerState::INACTIVE, shared_from_this(), [this](StateChangeReason reason) { POWER_HILOGD(FEATURE_POWER_STATE, "[UL_POWER] StateController_INACTIVE lambda start"); -#ifdef POWER_MANAGER_TAKEOVER_SUSPEND - TransitResult result = TakeOverSuspendAction(reason); - if (result != TransitResult::SUCCESS) { - return result; - } -#endif #ifdef HAS_HIVIEWDFX_HISYSEVENT_PART HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::POWER_UE, "SCREEN_OFF", HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "PNAMEID", "PowerManager", "PVERSIONID", "1.0", @@ -453,6 +447,7 @@ void PowerStateMachine::EmplaceDim() if (reason == StateChangeReason::STATE_CHANGE_REASON_COORDINATION) { dimTime = COORDINATED_STATE_SCREEN_OFF_TIME_MS; } + DisplayState dispState = stateAction_->GetDisplayState(); uint32_t ret = stateAction_->SetDisplayState(DisplayState::DISPLAY_DIM, reason); if (ret != ActionResult::SUCCESS) { // failed but not return, still need to set screen off @@ -657,12 +652,12 @@ void PowerStateMachine::HandlePreBrightWakeUp(int64_t callTimeMs, WakeupDeviceTy bool PowerStateMachine::IsWakeupDeviceSkip() { bool ret = false; - ret |= !IsSwitchOpen(); + ret = ret || !IsSwitchOpen(); #ifdef POWER_MANAGER_POWER_ENABLE_S4 - ret |= IsHibernating(); + ret = ret || IsHibernating(); #endif #ifdef POWER_MANAGER_ENABLE_LID_CHECK - ret |= PowerMgrService::isInLidMode_; + ret = ret || PowerMgrService::isInLidMode_; #endif return ret; } @@ -803,14 +798,8 @@ bool PowerStateMachine::RestoreScreenOffTimeInner() bool PowerStateMachine::ForceSuspendDeviceInner(pid_t pid, int64_t callTimeMs) { -#ifdef POWER_MANAGER_TAKEOVER_SUSPEND - auto setStateRet = SetState( - PowerState::INACTIVE, GetReasonBySuspendType(SuspendDeviceType::SUSPEND_DEVICE_REASON_FORCE_SUSPEND), true); - RETURN_IF_WITH_RET(!setStateRet, true); -#else SetState( PowerState::INACTIVE, GetReasonBySuspendType(SuspendDeviceType::SUSPEND_DEVICE_REASON_FORCE_SUSPEND), true); -#endif auto pms = DelayedSpSingleton::GetInstance(); auto suspendController = pms->GetSuspendController(); if (suspendController != nullptr) { @@ -975,7 +964,9 @@ void PowerStateMachine::RollbackHibernate( } } } +#endif +#ifdef POWER_MANAGER_POWER_ENABLE_S4 bool PowerStateMachine::HibernateInner(bool clearMemory, const std::string& reason) { POWER_HILOGI(FEATURE_POWER_STATE, "HibernateInner begin."); @@ -991,7 +982,6 @@ bool PowerStateMachine::HibernateInner(bool clearMemory, const std::string& reas POWER_HILOGE(FEATURE_SUSPEND, "shutdown controller or hibernate controller or notify is nullptr."); return false; } - if (clearMemory) { // do takeover only when user presses "shutdown" menu bool takenOver = shutdownController->TriggerTakeOverHibernateCallback(TakeOverInfo("hibernate", clearMemory)); @@ -1230,7 +1220,6 @@ void PowerStateMachine::SendEventToPowerMgrNotify(PowerState state, int64_t call case PowerState::AWAKE: { DelayedSingleton::GetInstance()->SendCustomizedScreenEvent( notify, PowerState::AWAKE, callTime); - notify->PublishScreenOnEvents(callTime); isAwakeNotified_.store(true, std::memory_order_relaxed); #ifdef POWER_MANAGER_ENABLE_FORCE_SLEEP_BROADCAST auto suspendController = pms->GetSuspendController(); @@ -1245,7 +1234,6 @@ void PowerStateMachine::SendEventToPowerMgrNotify(PowerState state, int64_t call case PowerState::INACTIVE: { DelayedSingleton::GetInstance()->SendCustomizedScreenEvent( notify, PowerState::INACTIVE, callTime); - notify->PublishScreenOffEvents(callTime); isAwakeNotified_.store(false, std::memory_order_relaxed); break; } @@ -1874,11 +1862,10 @@ void PowerStateMachine::ScreenChangeCheck::ReportSysEvent(const std::string& msg return; } lastReportTime = now; -#ifdef HAS_HIVIEWDFX_HISYSEVENT_PART + HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::POWER, eventName, HiviewDFX::HiSysEvent::EventType::FAULT, "PID", pid_, "UID", uid_, "PACKAGE_NAME", "", "PROCESS_NAME", "", "MSG", msg.c_str(), "REASON", PowerUtils::GetReasonTypeString(reason_).c_str()); -#endif } std::shared_ptr PowerStateMachine::GetStateController(PowerState state) @@ -2247,30 +2234,6 @@ StateChangeReason PowerStateMachine::GetReasonByWakeType(WakeupDeviceType type) return ret; } -SuspendDeviceType PowerStateMachine::GetSuspendTypeByReason(StateChangeReason reason) -{ - POWER_HILOGD(FEATURE_SUSPEND, "GetSuspendTypeByReason reason: %{public}u", reason); - SuspendDeviceType ret = SuspendDeviceType::SUSPEND_DEVICE_REASON_APPLICATION; - switch (reason) { - case StateChangeReason::STATE_CHANGE_REASON_TIMEOUT: - ret = SuspendDeviceType::SUSPEND_DEVICE_REASON_TIMEOUT; - break; - case StateChangeReason::STATE_CHANGE_REASON_TIMEOUT_NO_SCREEN_LOCK: - ret = SuspendDeviceType::SUSPEND_DEVICE_REASON_TIMEOUT; - break; - case StateChangeReason::STATE_CHANGE_REASON_HARD_KEY: - ret = SuspendDeviceType::SUSPEND_DEVICE_REASON_POWER_KEY; - break; - case StateChangeReason::STATE_CHANGE_REASON_SYSTEM: - ret = SuspendDeviceType::SUSPEND_DEVICE_REASON_FORCE_SUSPEND; - break; - default: - break; - } - POWER_HILOGD(FEATURE_SUSPEND, "SuspendDeviceType: %{public}u", ret); - return ret; -} - StateChangeReason PowerStateMachine::GetReasonBySuspendType(SuspendDeviceType type) { POWER_HILOGD(FEATURE_SUSPEND, "SuspendDeviceType: %{public}u", type); @@ -2463,7 +2426,7 @@ TransitResult PowerStateMachine::StateController::TransitTo(StateChangeReason re if (needNotify) { owner->NotifyPowerStateChanged(owner->currentState_, reason); } - } else if (IsReallyFailed(reason) && (ret != TransitResult::TAKEN_OVER)) { + } else if (IsReallyFailed(reason)) { RecordFailure(owner->currentState_, reason, ret); } @@ -2650,15 +2613,17 @@ bool PowerStateMachine::ReportScreenOffInvalidEvent(StateChangeReason reason) return false; } FFRTTask task = [this] { + auto pms = DelayedSpSingleton::GetInstance(); + if (pms == nullptr) { + POWER_HILOGE(FEATURE_POWER_STATE, "ReportScreenOffInvalidEvent fail, Pms is nullptr"); + return; + } // condition 1: no audiolock // condition 2: has screenlock - if (!IsRunningLockEnabled(RunningLockType::RUNNINGLOCK_BACKGROUND_AUDIO)) { + bool result = true; + pms->IsRunningLockEnabled(RunningLockType::RUNNINGLOCK_BACKGROUND_AUDIO, result); + if (!result) { std::map screenOnLockLists; - auto pms = DelayedSpSingleton::GetInstance(); - if (pms == nullptr) { - POWER_HILOGE(FEATURE_POWER_STATE, "ReportScreenOffInvalidEvent fail, Pms is nullptr"); - return; - } pms->QueryRunningLockListsInner(screenOnLockLists); for (const auto &it : screenOnLockLists) { HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::POWER, "SCREEN_OFF_EXCEPTION", @@ -2707,29 +2672,5 @@ bool PowerStateMachine::ReportAbnormalScreenOffEvent(StateChangeReason reason) FFRTUtils::SubmitTask(task); return true; } - -#ifdef POWER_MANAGER_TAKEOVER_SUSPEND -TransitResult PowerStateMachine::TakeOverSuspendAction(StateChangeReason reason) -{ - auto pms = DelayedSpSingleton::GetInstance(); - if (pms == nullptr) { - POWER_HILOGE(FEATURE_SUSPEND, "pms is nullptr"); - return TransitResult::OTHER_ERR; - } - - auto suspendController = pms->GetSuspendController(); - if (suspendController == nullptr) { - POWER_HILOGE(FEATURE_SUSPEND, "suspendController is nullptr"); - return TransitResult::OTHER_ERR; - } - - bool isTakenOver = suspendController->TriggerTakeOverSuspendCallback(GetSuspendTypeByReason(reason)); - if (isTakenOver) { - POWER_HILOGE(FEATURE_SUSPEND, "Suspend is taken over by OnTakeOverSuspend callback"); - return TransitResult::TAKEN_OVER; - } - return TransitResult::SUCCESS; -} -#endif } // namespace PowerMgr } // namespace OHOS diff --git a/services/native/src/runninglock/running_lock_mgr.cpp b/services/native/src/runninglock/running_lock_mgr.cpp index 73f6619de868c880c1129de5c45310d4f88e76a6..94e33066f41553297995f8943f31dc6ae9ef654c 100644 --- a/services/native/src/runninglock/running_lock_mgr.cpp +++ b/services/native/src/runninglock/running_lock_mgr.cpp @@ -40,8 +40,10 @@ namespace PowerMgr { namespace { const string TASK_RUNNINGLOCK_FORCEUNLOCK = "RunningLock_ForceUnLock"; constexpr int32_t VALID_PID_LIMIT = 1; +constexpr uint32_t COORDINATION_LOCK_AUTO_SUSPEND_DELAY_TIME = 0; sptr g_runningLockCallback = nullptr; const string INCALL_APP_BUNDLE_NAME = "com.ohos.callui"; +const string WECHAT_APP_BUNDLE_NAME = "com.tencent.wechat"; #ifdef HAS_SENSORS_SENSOR_PART constexpr uint32_t FOREGROUND_INCALL_DELAY_TIME_MS = 300; constexpr uint32_t BACKGROUND_INCALL_DELAY_TIME_MS = 800; @@ -145,7 +147,7 @@ bool RunningLockMgr::InitProximityController() if (proximityController_ != nullptr) { return true; } -#ifdef POWER_MANAGER_INIT_PROXIMITY_CONTROLLER +#ifdef POWER_MANAGER_PROXIMITY_CONTROLLER_OVERRIDE auto action = [](uint32_t status) { auto pms = DelayedSpSingleton::GetInstance(); if (pms == nullptr) { @@ -536,6 +538,7 @@ bool RunningLockMgr::UnLock(const sptr remoteObj, const std::stri if (lockInner->IsProxied()) { POWER_HILOGW(FEATURE_RUNNING_LOCK, "Runninglock is proxied, unProxy"); runninglockProxy_->UpdateProxyState(lockInner->GetPid(), lockInner->GetUid(), remoteObj, false); + lockInner->SetState(RunningLockState::RUNNINGLOCK_STATE_DISABLE); } auto lockInnerParam = lockInner->GetParam(); // try unlock @@ -741,6 +744,10 @@ void RunningLockMgr::UnlockInnerByProxy(const sptr& remoteObj, POWER_HILOGW(FEATURE_RUNNING_LOCK, "Unlock Disable"); return; } + if (lastState == RunningLockState::RUNNINGLOCK_STATE_PROXIED) { + POWER_HILOGW(FEATURE_RUNNING_LOCK, "UnlockInnerByProxy failed, runninglock Proxied"); + return; + } RunningLockParam lockInnerParam = lockInner->GetParam(); POWER_HILOGD(FEATURE_RUNNING_LOCK, "try UnlockInnerByProxy, name: %{public}s, type: %{public}d", lockInnerParam.name.c_str(), lockInnerParam.type); @@ -944,6 +951,22 @@ void RunningLockMgr::ProximityController::OnAway() runningLock->HandleProximityAwayEvent(); } +bool RunningLockMgr::IsVoiceAppForeground() +{ + if (PowerUtils::IsForegroundApplication(INCALL_APP_BUNDLE_NAME)) { + POWER_HILOGI(FEATURE_RUNNING_LOCK, "call in foreground"); + return true; + } + + if (PowerUtils::IsForegroundApplication(WECHAT_APP_BUNDLE_NAME)) { + POWER_HILOGI(FEATURE_RUNNING_LOCK, "WeChat is in foreground"); + return true; + } + + POWER_HILOGI(FEATURE_RUNNING_LOCK, "No voice app is in foreground"); + return false; +} + void RunningLockMgr::HandleProximityCloseEvent() { auto pms = DelayedSpSingleton::GetInstance(); @@ -959,7 +982,7 @@ void RunningLockMgr::HandleProximityCloseEvent() if (GetValidRunningLockNum(RunningLockType::RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL) > 0) { POWER_HILOGI(FEATURE_RUNNING_LOCK, "Change state to INACITVE when holding PROXIMITY LOCK"); uint32_t delayTime = FOREGROUND_INCALL_DELAY_TIME_MS; - if (!PowerUtils::IsForegroundApplication(INCALL_APP_BUNDLE_NAME)) { + if (!IsVoiceAppForeground()) { delayTime = BACKGROUND_INCALL_DELAY_TIME_MS; } if (pms->IsDuringCallStateEnable() && stateMachine->IsDuringCall() && stateMachine->IsScreenOn()) { diff --git a/services/native/src/runninglock/running_lock_mgr.h b/services/native/src/runninglock/running_lock_mgr.h index ef94ff26b747148bc55fd5f6f930155a7c121037..ca317018253eab96662861308a29c183bbc6c574 100644 --- a/services/native/src/runninglock/running_lock_mgr.h +++ b/services/native/src/runninglock/running_lock_mgr.h @@ -90,6 +90,7 @@ private: bool InitProximityController(); void HandleProximityCloseEvent(); void HandleProximityAwayEvent(); + bool IsVoiceAppForeground(); #endif class LockCounter { diff --git a/services/native/src/setting/setting_helper.cpp b/services/native/src/setting/setting_helper.cpp index aaae63436b72dcf5df18fee216bdea88de6c4ffb..6b09501f843a8b05714c724fa1431a06915c03d0 100644 --- a/services/native/src/setting/setting_helper.cpp +++ b/services/native/src/setting/setting_helper.cpp @@ -642,7 +642,7 @@ void SettingHelper::SetSettingWakeupLid(bool enable) #ifdef POWER_MANAGER_ENABLE_BLOCK_LONG_PRESS const std::string SettingHelper::GetBlockLongPress() { - SettingProvider& SettingProvider = SettingProvider::GetInstance(POWER_MANAGER_SERVICE_ID); + SettingProvider& settingProvider = SettingProvider::GetInstance(POWER_MANAGER_SERVICE_ID); std::string longPress; ErrCode ret = settingProvider.GetStringValue(SETTING_POWER_BLOCK_LONG_PRESS_KEY, longPress); if (ret != ERR_OK) { diff --git a/services/native/src/shutdown/shutdown_dialog.cpp b/services/native/src/shutdown/shutdown_dialog.cpp index 8a33c9ca68a725cf7bfbcb92b7b8eab8daa3211a..bec8b40abf39b313a924a6ba3d6ae6bff5b6ec12 100644 --- a/services/native/src/shutdown/shutdown_dialog.cpp +++ b/services/native/src/shutdown/shutdown_dialog.cpp @@ -35,6 +35,7 @@ #include "power_log.h" #include "power_mgr_service.h" #include "power_vibrator.h" +#include "sysparam.h" #ifdef POWER_MANAGER_ENABLE_BLOCK_LONG_PRESS #include "setting_helper.h" @@ -56,6 +57,7 @@ std::atomic_bool g_longPressShow = false; int32_t g_retryCount = 1; sptr g_remoteObject = nullptr; const std::string DIALOG_CONFIG_PATH = "etc/systemui/poweroff_config.json"; +const std::string KEY_DOWN_DURATION = "const.powerkey.down_duration"; #ifdef POWER_MANAGER_ENABLE_BLOCK_LONG_PRESS const std::string BLOCK_LONG_PRESS = "1"; #endif @@ -84,7 +86,9 @@ void ShutdownDialog::KeyMonitorInit() keyOption->SetPreKeys(preKeys); keyOption->SetFinalKey(KeyEvent::KEYCODE_POWER); keyOption->SetFinalKeyDown(true); - keyOption->SetFinalKeyDownDuration(LONG_PRESS_DELAY_MS); + int32_t downDuration = SysParam::GetIntValue(KEY_DOWN_DURATION, LONG_PRESS_DELAY_MS); + POWER_HILOGI(FEATURE_SHUTDOWN, "Initialize powerkey down duration %{public}d.", downDuration); + keyOption->SetFinalKeyDownDuration(downDuration); auto inputManager = InputManager::GetInstance(); if (!inputManager) { POWER_HILOGE(FEATURE_SHUTDOWN, "KeyMonitorInit inputManager is null"); @@ -144,15 +148,14 @@ bool ShutdownDialog::ConnectSystemUi() return true; } - Want want; - want.SetElementName(dialogBundleName_, dialogAbilityName_); - - void *handler = dlopen("libpower_ability.z.so", RTLD_NOW | RTLD_NODELETE); + void *handler = dlopen("libpower_ability.z.so", RTLD_LAZY | RTLD_NODELETE); if (handler == nullptr) { POWER_HILOGE(FEATURE_SHUTDOWN, "dlopen libpower_ability.z.so failed, reason : %{public}s", dlerror()); return false; } + Want want; + want.SetElementName(dialogBundleName_, dialogAbilityName_); auto powerConnectAbility = reinterpret_cast&, int32_t)>(dlsym(handler, "PowerConnectAbility")); if (powerConnectAbility == nullptr) { diff --git a/services/native/src/suspend/sleep_callback_holder.cpp b/services/native/src/suspend/sleep_callback_holder.cpp index 82b16ba06855c3ff866d903ace242d777719370b..6c2be384f5de8de2595e2efb547324eee69acfc3 100644 --- a/services/native/src/suspend/sleep_callback_holder.cpp +++ b/services/native/src/suspend/sleep_callback_holder.cpp @@ -26,15 +26,15 @@ void SleepCallbackHolder::AddCallback(const sptr& callback, std::lock_guard lock(mutex_); switch (priority) { case SleepPriority::LOW: { - lowPriorityCallbacks_.insert(callback); + auto iter = lowPriorityCallbacks_.insert(callback); break; } case SleepPriority::DEFAULT: { - defaultPriorityCallbacks_.insert(callback); + auto iter = defaultPriorityCallbacks_.insert(callback); break; } case SleepPriority::HIGH: { - highPriorityCallbacks_.insert(callback); + auto iter = highPriorityCallbacks_.insert(callback); break; } default: { diff --git a/services/native/src/suspend/suspend_controller.cpp b/services/native/src/suspend/suspend_controller.cpp index 04028365c5da4bbec1d0901289cc1a2e2b9aaa2d..9b6f98c73dc5990cc30de1d1cec2ce2c12ea1b1e 100644 --- a/services/native/src/suspend/suspend_controller.cpp +++ b/services/native/src/suspend/suspend_controller.cpp @@ -84,34 +84,6 @@ void SuspendController::RemoveCallback(const sptr& callback) IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid()); } -void SuspendController::AddCallback(const sptr& callback, TakeOverSuspendPriority priority) -{ -#ifdef POWER_MANAGER_TAKEOVER_SUSPEND - if (callback == nullptr) { - POWER_HILOGE(FEATURE_SUSPEND, "callback is nullptr"); - return; - } - TakeOverSuspendCallbackHolder::GetInstance().AddCallback(callback, priority); - POWER_HILOGI(FEATURE_SUSPEND, - "TakeOver Suspend callback added, priority=%{public}u, pid=%{public}d, uid=%{public}d", priority, - IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid()); -#endif -} - -void SuspendController::RemoveCallback(const sptr& callback) -{ -#ifdef POWER_MANAGER_TAKEOVER_SUSPEND - if (callback == nullptr) { - POWER_HILOGE(FEATURE_SUSPEND, "callback is nullptr"); - return; - } - TakeOverSuspendCallbackHolder::GetInstance().RemoveCallback(callback); - POWER_HILOGI(FEATURE_SUSPEND, - "TakeOver Suspend callback removed, pid=%{public}d, uid=%{public}d", - IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid()); -#endif -} - void SuspendController::TriggerSyncSleepCallback(bool isWakeup) { std::lock_guard lock(sleepCbMutex_); @@ -147,51 +119,6 @@ void SuspendController::TriggerSyncSleepCallbackInner( } } -#ifdef POWER_MANAGER_TAKEOVER_SUSPEND -bool SuspendController::TriggerTakeOverSuspendCallback(SuspendDeviceType type) -{ - bool isTakeover = false; - POWER_HILOGI(FEATURE_SUSPEND, "TriggerTakeOverSuspendCallback, type=%{public}d", type); - auto highPriorityCallbacks = TakeOverSuspendCallbackHolder::GetInstance().GetHighPriorityCallbacks(); - isTakeover = TriggerTakeOverSuspendCallbackInner(highPriorityCallbacks, "High", type); - RETURN_IF_WITH_RET(isTakeover, true); - auto defaultPriorityCallbacks = TakeOverSuspendCallbackHolder::GetInstance().GetDefaultPriorityCallbacks(); - isTakeover = TriggerTakeOverSuspendCallbackInner(defaultPriorityCallbacks, "Default", type); - RETURN_IF_WITH_RET(isTakeover, true); - auto lowPriorityCallbacks = TakeOverSuspendCallbackHolder::GetInstance().GetLowPriorityCallbacks(); - isTakeover = TriggerTakeOverSuspendCallbackInner(lowPriorityCallbacks, "Low", type); - return isTakeover; -} -#endif - -#ifdef POWER_MANAGER_TAKEOVER_SUSPEND -bool SuspendController::TriggerTakeOverSuspendCallbackInner( - TakeOverSuspendCallbackHolder::TakeoverSuspendCallbackContainerType& callbacks, - const std::string& priority, SuspendDeviceType type) -{ - uint32_t id = 0; - bool isTakeover = false; - if (callbacks.size() == 0) { - POWER_HILOGI(FEATURE_SUSPEND, "callbacks size is zero"); - return isTakeover; - } - for (const auto& callback : callbacks) { - auto pidUid = TakeOverSuspendCallbackHolder::GetInstance().FindCallbackPidUid(callback); - if (callback == nullptr) { - POWER_HILOGE(FEATURE_SUSPEND, "callback is nullptr"); - continue; - } - int64_t start = GetTickCount(); - isTakeover = isTakeover || callback->OnTakeOverSuspend(type); - int64_t count = GetTickCount() - start; - POWER_HILOGI(FEATURE_SUSPEND, - "Trigger %{public}s takeovercb [%{public}u] success, P=%{public}d U=%{public}d T=%{public}" PRId64, - priority.c_str(), ++id, pidUid.first, pidUid.second, count); - } - return isTakeover; -} -#endif - class SuspendPowerStateCallback : public PowerStateCallbackStub { public: explicit SuspendPowerStateCallback(std::shared_ptr controller) : controller_(controller) {}; @@ -254,7 +181,7 @@ void SuspendController::Init() void SuspendController::ExecSuspendMonitorByReason(SuspendDeviceType reason) { - FFRTUtils::SubmitTask([this, reason] { + FFRTTask suspendTask = [this, reason]() { g_monitorMutex.lock(); auto suspendMonitor = GetSpecifiedSuspendMonitor(reason); if (suspendMonitor == nullptr) { @@ -264,7 +191,15 @@ void SuspendController::ExecSuspendMonitorByReason(SuspendDeviceType reason) } suspendMonitor->Notify(); g_monitorMutex.unlock(); - }); + }; + + if (reason == SuspendDeviceType::SUSPEND_DEVICE_REASON_SWITCH) { + // make sure that open/close switch tasks are processed in the order they were created + POWER_HILOGI(FEATURE_SUSPEND, "switch trigger suspend"); + stateMachine_->SetDelayTimer(0, PowerStateMachine::SWITCH_TRIGGER_WAKEUP_OR_SUSPEND_MSG, suspendTask); + } else { + FFRTUtils::SubmitTask(suspendTask); + } } void SuspendController::UpdateSuspendSources() @@ -515,12 +450,32 @@ void SuspendController::SuspendWhenScreenOff(SuspendDeviceType reason, uint32_t void SuspendController::ControlListener(SuspendDeviceType reason, uint32_t action, uint32_t delay) { + auto pms = DelayedSpSingleton::GetInstance(); + if (pms == nullptr) { + return; + } if (stateMachine_ == nullptr) { POWER_HILOGE(FEATURE_SUSPEND, "get PowerStateMachine instance error"); return; } - - if (NeedToSkipCurrentSuspend(reason, action, delay)) { + if (pms->CheckDialogAndShuttingDown()) { + return; + } + if (reason == SuspendDeviceType::SUSPEND_DEVICE_REASON_SWITCH) { + stateMachine_->SetSwitchAction(action); + } + bool isScreenOn = stateMachine_->IsScreenOn(); + if (!isScreenOn) { + SuspendWhenScreenOff(reason, action, delay); + return true; + } +#ifdef POWER_MANAGER_ENABLE_EXTERNAL_SCREEN_MANAGEMENT + if (IsPowerOffInernalScreenOnlyScene(reason, static_cast(action), isScreenOn)) { + ProcessPowerOffInternalScreenOnly(pms, reason); + return; + } +#endif + if (CheckDuringCall(pms, reason)) { return; } pid_t pid = IPCSkeleton::GetCallingPid(); @@ -545,25 +500,8 @@ void SuspendController::ControlListener(SuspendDeviceType reason, uint32_t actio } } -bool SuspendController::NeedToSkipCurrentSuspend(SuspendDeviceType reason, uint32_t action, uint32_t delay) +bool SuspendController::CheckDuringCall(const sptr& pms, SuspendDeviceType reason) { - auto pms = DelayedSpSingleton::GetInstance(); - if (pms == nullptr) { - POWER_HILOGE(FEATURE_SUSPEND, "get PowerMgrService instance error"); - return true; - } - if (pms->CheckDialogAndShuttingDown()) { - return true; - } - - if (reason == SuspendDeviceType::SUSPEND_DEVICE_REASON_SWITCH) { - stateMachine_->SetSwitchAction(action); - } - bool isScreenOn = stateMachine_->IsScreenOn(); - if (!isScreenOn) { - SuspendWhenScreenOff(reason, action, delay); - return true; - } if (pms->IsDuringCallStateEnable()) { if (reason == SuspendDeviceType::SUSPEND_DEVICE_REASON_POWER_KEY && Rosen::DisplayManagerLite::GetInstance().GetFoldDisplayMode() == Rosen::FoldDisplayMode::SUB && @@ -572,13 +510,6 @@ bool SuspendController::NeedToSkipCurrentSuspend(SuspendDeviceType reason, uint3 return true; } } - -#ifdef POWER_MANAGER_ENABLE_EXTERNAL_SCREEN_MANAGEMENT - if (IsPowerOffInernalScreenOnlyScene(reason, static_cast(action), isScreenOn)) { - ProcessPowerOffInternalScreenOnly(pms, reason); - return true; - } -#endif return false; } @@ -830,10 +761,18 @@ bool PowerKeySuspendMonitor::Init() return true; } std::shared_ptr keyOption = std::make_shared(); + if (keyOption == nullptr) { + POWER_HILOGE(FEATURE_SUSPEND, "keyOption is nullptr"); + return false; + } std::set preKeys; keyOption.reset(); keyOption = std::make_shared(); + if (keyOption == nullptr) { + POWER_HILOGE(FEATURE_SUSPEND, "keyOption is nullptr"); + return false; + } keyOption->SetPreKeys(preKeys); keyOption->SetFinalKey(OHOS::MMI::KeyEvent::KEYCODE_POWER); keyOption->SetFinalKeyDown(false); @@ -888,8 +827,8 @@ void PowerKeySuspendMonitor::ReceivePowerkeyCallback(std::shared_ptr #include +#include "event_handler.h" #include "ffrt_utils.h" #include "power_state_machine.h" #ifdef HAS_SENSORS_SENSOR_PART @@ -33,9 +34,6 @@ #ifdef HAS_MULTIMODALINPUT_INPUT_PART #include "i_input_event_consumer.h" #endif -#ifdef POWER_MANAGER_TAKEOVER_SUSPEND -#include "suspend_takeover_callback_holder.h" -#endif namespace OHOS { namespace PowerMgr { @@ -62,11 +60,8 @@ public: bool GetPowerkeyDownWhenScreenOff(); void AddCallback(const sptr& callback, SleepPriority priority); - void AddCallback(const sptr& callback, TakeOverSuspendPriority priority); void RemoveCallback(const sptr& callback); - void RemoveCallback(const sptr& callback); void TriggerSyncSleepCallback(bool isWakeup); - bool TriggerTakeOverSuspendCallback(SuspendDeviceType type); void UpdateSuspendSources(); std::shared_ptr GetStateMachine() const @@ -117,14 +112,9 @@ private: void TriggerSyncSleepCallbackInner( SleepCallbackHolder::SleepCallbackContainerType& callbacks, const std::string& priority, bool isWakeup); -#ifdef POWER_MANAGER_TAKEOVER_SUSPEND - bool TriggerTakeOverSuspendCallbackInner( - TakeOverSuspendCallbackHolder::TakeoverSuspendCallbackContainerType& callbacks, - const std::string& priority, SuspendDeviceType type); -#endif static constexpr int32_t FORCE_SLEEP_DELAY_MS = 8000; void SuspendWhenScreenOff(SuspendDeviceType reason, uint32_t action, uint32_t delay); - bool NeedToSkipCurrentSuspend(SuspendDeviceType reason, uint32_t action, uint32_t delay); + bool CheckDuringCall(const sptr& pms, SuspendDeviceType reason); std::vector sourceList_; std::map> monitorMap_; std::shared_ptr shutdownController_; @@ -137,7 +127,6 @@ private: bool powerkeyDownWhenScreenOff_ = false; std::mutex mutex_; std::mutex sleepCbMutex_; - std::mutex suspendMutex_; std::shared_ptr ffrtTimer_; FFRTMutexMap ffrtMutexMap_; #ifdef POWER_MANAGER_ENABLE_FORCE_SLEEP_BROADCAST diff --git a/services/native/src/suspend/suspend_takeover_callback_holder.cpp b/services/native/src/suspend/suspend_takeover_callback_holder.cpp deleted file mode 100644 index 187388a39b2554517bcc6c38bd1e9a3c2b27a465..0000000000000000000000000000000000000000 --- a/services/native/src/suspend/suspend_takeover_callback_holder.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* - * 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 "suspend_takeover_callback_holder.h" -#include "power_common.h" - -namespace OHOS { -namespace PowerMgr { -TakeOverSuspendCallbackHolder::TakeOverSuspendCallbackHolder() {} -TakeOverSuspendCallbackHolder::~TakeOverSuspendCallbackHolder() = default; - -void TakeOverSuspendCallbackHolder::AddCallback( - const sptr& callback, TakeOverSuspendPriority priority) -{ - std::lock_guard lock(mutex_); - switch (priority) { - case TakeOverSuspendPriority::LOW: { - auto iter = lowPriorityCallbacks_.insert(callback); - break; - } - case TakeOverSuspendPriority::DEFAULT: { - auto iter = defaultPriorityCallbacks_.insert(callback); - break; - } - case TakeOverSuspendPriority::HIGH: { - auto iter = highPriorityCallbacks_.insert(callback); - break; - } - default: - break; - } - AddCallbackPidUid(callback); -} - -void TakeOverSuspendCallbackHolder::AddCallbackPidUid(const sptr& callback) -{ - pid_t pid = IPCSkeleton::GetCallingPid(); - auto uid = IPCSkeleton::GetCallingUid(); - cachedRegister_.emplace(callback, std::make_pair(pid, uid)); -} - -using CallbackContainer = TakeOverSuspendCallbackHolder::TakeoverSuspendCallbackContainerType; - -CallbackContainer TakeOverSuspendCallbackHolder::GetHighPriorityCallbacks() -{ - std::lock_guard lock(mutex_); - return highPriorityCallbacks_; -} - -CallbackContainer TakeOverSuspendCallbackHolder::GetDefaultPriorityCallbacks() -{ - std::lock_guard lock(mutex_); - return defaultPriorityCallbacks_; -} - -CallbackContainer TakeOverSuspendCallbackHolder::GetLowPriorityCallbacks() -{ - std::lock_guard lock(mutex_); - return lowPriorityCallbacks_; -} - -void TakeOverSuspendCallbackHolder::RemoveCallback(const sptr& callback) -{ - std::lock_guard lock(mutex_); - RemoveCallback(lowPriorityCallbacks_, callback); - RemoveCallback(defaultPriorityCallbacks_, callback); - RemoveCallback(highPriorityCallbacks_, callback); - RemoveCallbackPidUid(callback); -} - -void TakeOverSuspendCallbackHolder::RemoveCallback( - TakeOverSuspendCallbackHolder::TakeoverSuspendCallbackContainerType& callbacks, - const sptr& callback) -{ - auto iter = callbacks.find(callback); - if (iter == callbacks.end()) { - POWER_HILOGE(FEATURE_SUSPEND, "Cannot find the takeover suspend callback"); - return; - } - callbacks.erase(iter); -} - -void TakeOverSuspendCallbackHolder::RemoveCallbackPidUid(const sptr& callback) -{ - auto iter = cachedRegister_.find(callback); - if (iter != cachedRegister_.end()) { - cachedRegister_.erase(iter); - } -} - -std::pair TakeOverSuspendCallbackHolder::FindCallbackPidUid( - const sptr& callback) -{ - std::lock_guard lock(mutex_); - auto iter = cachedRegister_.find(callback); - return (iter != cachedRegister_.end()) ? iter->second : std::make_pair(0, 0); -} -} // namespace PowerMgr -} // namespace OHOS \ No newline at end of file diff --git a/services/native/src/suspend/suspend_takeover_callback_holder.h b/services/native/src/suspend/suspend_takeover_callback_holder.h deleted file mode 100644 index 4de52259bffb48b9fc148f982a8f6aa2bb11f4fa..0000000000000000000000000000000000000000 --- a/services/native/src/suspend/suspend_takeover_callback_holder.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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. - */ -#ifndef POWERMGR_POWER_MANAGER_TAKEOVER_CALLBACK_HOLDER_H -#define POWERMGR_POWER_MANAGER_TAKEOVER_CALLBACK_HOLDER_H - -#include -#include -#include -#include "ipc_skeleton.h" -#include "iremote_object.h" -#include "suspend/itake_over_suspend_callback.h" - -namespace OHOS { -namespace PowerMgr { -class TakeOverSuspendCallbackHolder final : public DelayedRefSingleton { - DECLARE_DELAYED_REF_SINGLETON(TakeOverSuspendCallbackHolder); - DISALLOW_COPY_AND_MOVE(TakeOverSuspendCallbackHolder); -public: - struct TakeoverSuspendCallbackCompare { - bool operator()(const sptr& lhs, const sptr& rhs) const - { - return lhs->AsObject() < rhs->AsObject(); - } - }; - - using TakeoverSuspendCallbackContainerType = std::set, - TakeoverSuspendCallbackCompare>; - using TakeoverSuspendCallbackCachedRegister = - std::map, std::pair, TakeoverSuspendCallbackCompare>; - void AddCallback(const sptr& callback, TakeOverSuspendPriority priority); - void RemoveCallback(const sptr& callback); - TakeoverSuspendCallbackContainerType GetHighPriorityCallbacks(); - TakeoverSuspendCallbackContainerType GetDefaultPriorityCallbacks(); - TakeoverSuspendCallbackContainerType GetLowPriorityCallbacks(); - std::pair FindCallbackPidUid(const sptr& callback); -private: - static void RemoveCallback( - TakeoverSuspendCallbackContainerType& callbacks, const sptr& callback); - void AddCallbackPidUid(const sptr& callback); - void RemoveCallbackPidUid(const sptr& callback); - - std::mutex mutex_; - TakeoverSuspendCallbackContainerType highPriorityCallbacks_; - TakeoverSuspendCallbackContainerType defaultPriorityCallbacks_; - TakeoverSuspendCallbackContainerType lowPriorityCallbacks_; - TakeoverSuspendCallbackCachedRegister cachedRegister_; -}; -} // namespace PowerMgr -} // namespace OHOS -#endif // POWERMGR_POWER_MANAGER_TAKEOVER_CALLBACK_HOLDER_H \ No newline at end of file diff --git a/services/native/src/wakeup/wakeup_controller.cpp b/services/native/src/wakeup/wakeup_controller.cpp index a6dc33a75e4438c4f678fa550d97e31c79c1d7d9..f5626b7c90e1313d7b50339335a87b445d2ffec6 100644 --- a/services/native/src/wakeup/wakeup_controller.cpp +++ b/services/native/src/wakeup/wakeup_controller.cpp @@ -42,6 +42,7 @@ #include "customized_screen_event_rules.h" #include "singleton.h" + namespace OHOS { namespace PowerMgr { using namespace OHOS::MMI; @@ -461,13 +462,20 @@ void WakeupController::LidWakeupParseJsonConfig(bool updataEnable, std::string& void WakeupController::ExecWakeupMonitorByReason(WakeupDeviceType reason) { - FFRTUtils::SubmitTask([this, reason] { + FFRTTask wakeupTask = [this, reason]() { std::lock_guard lock(monitorMutex_); if (monitorMap_.find(reason) != monitorMap_.end()) { auto monitor = monitorMap_[reason]; monitor->Notify(); } - }); + }; + if (reason == WakeupDeviceType::WAKEUP_DEVICE_SWITCH) { + // make sure that open/close switch tasks are processed in the order they were created + POWER_HILOGI(FEATURE_WAKEUP, "switch trigger wakeup"); + stateMachine_->SetDelayTimer(0, PowerStateMachine::SWITCH_TRIGGER_WAKEUP_OR_SUSPEND_MSG, wakeupTask); + } else { + FFRTUtils::SubmitTask(wakeupTask); + } } void WakeupController::Wakeup() @@ -579,7 +587,7 @@ void WakeupController::HandleWakeup(const sptr& pms, WakeupDevi } #ifdef POWER_MANAGER_ENABLE_EXTERNAL_SCREEN_MANAGEMENT if (suspendController != nullptr && stateMachine_->GetExternalScreenNumber() > 0 && - !stateMachine_->IsSwitchOpenByPath()) { + reason != WakeupDeviceType::WAKEUP_DEVICE_SWITCH && !stateMachine_->IsSwitchOpenByPath()) { suspendController->PowerOffInternalScreen(SuspendDeviceType::SUSPEND_DEVICE_REASON_SWITCH); } #endif @@ -867,9 +875,6 @@ bool WakeupController::NeedToSkipCurrentWakeup(const sptr& pms, #endif if (skipWakeup) { POWER_HILOGI(FEATURE_WAKEUP, "[UL_POWER] Switch is closed, skip current wakeup reason: %{public}u", reason); -#ifdef POWER_MANAGER_ENABLE_WATCH_CUSTOMIZED_SCREEN_COMMON_EVENT_RULES - DelayedSingleton::GetInstance()->NotifyScreenOnEventAgain(reason); -#endif return true; } @@ -886,6 +891,9 @@ bool WakeupController::NeedToSkipCurrentWakeup(const sptr& pms, (reason != WakeupDeviceType::WAKEUP_DEVICE_LID); if (skipWakeup) { POWER_HILOGI(FEATURE_WAKEUP, "[UL_POWER] Screen is on, skip current wakeup reason: %{public}u", reason); +#ifdef POWER_MANAGER_ENABLE_WATCH_CUSTOMIZED_SCREEN_COMMON_EVENT_RULES + DelayedSingleton::GetInstance()->NotifyScreenOnEventAgain(reason); +#endif return true; } @@ -998,6 +1006,7 @@ void PowerkeyWakeupMonitor::ReceivePowerkeyCallback(std::shared_ptr suspendController = pms->GetSuspendController(); if (suspendController == nullptr) { POWER_HILOGE(FEATURE_WAKEUP, "[UL_POWER] suspendController is nullptr"); @@ -1005,7 +1014,7 @@ void PowerkeyWakeupMonitor::ReceivePowerkeyCallback(std::shared_ptrIsLowCapacityWakeup(reason)) { + if (wakeupController->IsLowCapacityWakeup(WakeupDeviceType::WAKEUP_DEVICE_POWER_BUTTON)) { wakeupController->ProcessLowCapacityWakeup(); suspendController->SetLowCapacityPowerKeyFlag(true); return; diff --git a/services/native/src/watch_customized_screen_common_event/customized_screen_event_rules.cpp b/services/native/src/watch_customized_screen_common_event/customized_screen_event_rules.cpp index 269f1d883cdc726d4f2836f750097b74d96fec0f..6a0645fe7d9104095003e70bebaeefaf2aed791f 100644 --- a/services/native/src/watch_customized_screen_common_event/customized_screen_event_rules.cpp +++ b/services/native/src/watch_customized_screen_common_event/customized_screen_event_rules.cpp @@ -35,7 +35,7 @@ std::vector CustomizedScreenEventRules::GetForegroundBundleNames() std::vector appList; AppManagerUtils::GetForegroundApplications(appList); for (const auto &curApp : appList) { - if (std::find(bundleNames.begin(), bundleNames.end(), cuiApp.bundleName) == bundleNames.end()) { + if (std::find(bundleNames.begin(), bundleNames.end(), curApp.bundleName) == bundleNames.end()) { bundleNames.push_back(curApp.bundleName); } } @@ -50,6 +50,11 @@ void CustomizedScreenEventRules::SetScreenOnEventRules(StateChangeReason reason, PowerExtIntfWrapper::Instance().SetScreenOnEventRules(reason, stateChangeReason, wakeupDeviceTypes); } +void CustomizedScreenEventRules::NotifyOperateEventAfterScreenOn() +{ + PowerExtIntfWrapper::Instance().NotifyOperateEventAfterScreenOn(bundleNames); +} + void CustomizedScreenEventRules::PublishCustomizedScreenEvent(PowerState state) { if (!g_watchCurrentStateChangeReason.empty() && @@ -65,11 +70,6 @@ bool CustomizedScreenEventRules::NotifyScreenOnEventAgain(WakeupDeviceType reaso { return PowerExtIntfWrapper::Instance().NotifyScreenOnEventAgain(reason, bundleNames); } - -void CustomizedScreenEventRules::NotifyOperateEventAfterScreenOn() -{ - PowerExtIntfWrapper::Instance().NotifyOperateEventAfterScreenOn(bundleNames); -} #endif void CustomizedScreenEventRules::SendCustomizedScreenEvent( @@ -90,5 +90,5 @@ void CustomizedScreenEventRules::SendCustomizedScreenEvent( #endif } -} //namespace PowerMgr -} //namespace OHOS \ No newline at end of file +} // namespace PowerMgr +} // namespace OHOS \ No newline at end of file diff --git a/services/zidl/include/takeover_suspend_callback_proxy.h b/services/zidl/include/takeover_suspend_callback_proxy.h deleted file mode 100644 index fc1789f02be52666e5fd6e503ec91f930a658b78..0000000000000000000000000000000000000000 --- a/services/zidl/include/takeover_suspend_callback_proxy.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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. - */ -#ifndef TAKEOVER_SUSPEND_CALLBACK_PROXY_H -#define TAKEOVER_SUSPEND_CALLBACK_PROXY_H - -#include -#include -#include "refbase.h" -#include "iremote_broker.h" -#include "iremote_object.h" -#include "itake_over_suspend_callback.h" - -namespace OHOS { -namespace PowerMgr { -class TakeOverSuspendCallbackProxy : public IRemoteProxy { -public: - explicit TakeOverSuspendCallbackProxy(const sptr& impl) - : IRemoteProxy(impl) {} - virtual ~TakeOverSuspendCallbackProxy() = default; - virtual bool OnTakeOverSuspend(SuspendDeviceType type) override; - -private: - static inline BrokerDelegator delegator_; -}; -} // namespace PowerMgr -} // namespace OHOS -#endif // TAKEOVER_SUSPEND_CALLBACK_PROXY_H \ No newline at end of file diff --git a/services/zidl/include/takeover_suspend_callback_stub.h b/services/zidl/include/takeover_suspend_callback_stub.h deleted file mode 100644 index 3e9d6f30454874e69c12f0f1d0d5e65cf30a59c1..0000000000000000000000000000000000000000 --- a/services/zidl/include/takeover_suspend_callback_stub.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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. - */ -#ifndef TAKEOVER_SUSPEND_CALLBACK_STUB_H -#define TAKEOVER_SUSPEND_CALLBACK_STUB_H - -#include -#include -#include "itake_over_suspend_callback.h" - -namespace OHOS { -namespace PowerMgr { -class TakeOverSuspendCallbackStub : public IRemoteStub { -public: - DISALLOW_COPY_AND_MOVE(TakeOverSuspendCallbackStub); - TakeOverSuspendCallbackStub() = default; - virtual ~TakeOverSuspendCallbackStub() = default; - int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; - bool OnTakeOverSuspend(SuspendDeviceType __attribute__((unused)) type) override - { - return false; - } - -private: - int32_t OnTakeOverSuspendCallbackStub(MessageParcel& data, MessageParcel& reply); -}; -} // namespace PowerMgr -} // namespace OHOS -#endif // TAKEOVER_SUSPEND_CALLBACK_STUB_H \ No newline at end of file diff --git a/services/zidl/src/takeover_suspend_callback_proxy.cpp b/services/zidl/src/takeover_suspend_callback_proxy.cpp deleted file mode 100644 index 47fa1182d630c3d3e33b5b5a93bbe543b44ff4e3..0000000000000000000000000000000000000000 --- a/services/zidl/src/takeover_suspend_callback_proxy.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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 "takeover_suspend_callback_proxy.h" -#include "iremote_object.h" -#include "message_option.h" -#include "message_parcel.h" -#include "power_common.h" -#include "take_over_callback_ipc_interface_code.h" - -namespace OHOS { -namespace PowerMgr { -bool TakeOverSuspendCallbackProxy::OnTakeOverSuspend(SuspendDeviceType type) -{ - sptr remote = Remote(); - if (remote == nullptr) { - POWER_HILOGE(FEATURE_SUSPEND, "remote is nullptr"); - return false; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(TakeOverSuspendCallbackProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_SUSPEND, "Write descriptor failed"); - return false; - } - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Uint32, static_cast(type), false); - int ret = remote->SendRequest( - static_cast(PowerMgr::TakeOverSuspendCallbackInterfaceCode::CMD_ON_TAKEOVER_SUSPEND), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_SUSPEND, "SendRequest is failed, ret=%{public}d", ret); - return false; - } - - bool isTakeOver = false; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Bool, isTakeOver, false); - return isTakeOver; -} -} // namespace PowerMgr -} // namespace OHOS \ No newline at end of file diff --git a/services/zidl/src/takeover_suspend_callback_stub.cpp b/services/zidl/src/takeover_suspend_callback_stub.cpp deleted file mode 100644 index 3332b8093dbe90e4396cfc79bb3b87153744804a..0000000000000000000000000000000000000000 --- a/services/zidl/src/takeover_suspend_callback_stub.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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 "takeover_suspend_callback_stub.h" -#include "takeover_suspend_callback_proxy.h" -#include "message_parcel.h" -#include "power_common.h" -#include "take_over_callback_ipc_interface_code.h" -#include "xcollie/xcollie.h" -#include "xcollie/xcollie_define.h" - -namespace OHOS { -namespace PowerMgr { -int TakeOverSuspendCallbackStub::OnRemoteRequest( - uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) -{ - const int32_t DFX_DELAY_S = 60; - int32_t id = HiviewDFX::XCollie::GetInstance().SetTimer( - "PowerSuspendCallback", DFX_DELAY_S, nullptr, nullptr, HiviewDFX::XCOLLIE_FLAG_LOG); - std::u16string descripter = TakeOverSuspendCallbackStub::GetDescriptor(); - std::u16string remoteDescripter = data.ReadInterfaceToken(); - if (descripter != remoteDescripter) { - POWER_HILOGE(COMP_SVC, "Descriptor is not match"); - HiviewDFX::XCollie::GetInstance().CancelTimer(id); - return E_GET_POWER_SERVICE_FAILED; - } - - int32_t ret = ERR_OK; - if (code == static_cast(TakeOverSuspendCallbackInterfaceCode::CMD_ON_TAKEOVER_SUSPEND)) { - ret = OnTakeOverSuspendCallbackStub(data, reply); - } else { - ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - HiviewDFX::XCollie::GetInstance().CancelTimer(id); - return ret; -} - -int32_t TakeOverSuspendCallbackStub::OnTakeOverSuspendCallbackStub(MessageParcel& data, MessageParcel& reply) -{ - uint32_t rawType = 0; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, rawType, E_READ_PARCEL_ERROR); - SuspendDeviceType type = static_cast(rawType); - bool isSuspendDeviceType = - type >= SuspendDeviceType::SUSPEND_DEVICE_REASON_MIN && - type <= SuspendDeviceType::SUSPEND_DEVICE_REASON_MAX; - - if (!isSuspendDeviceType) { - return E_INNER_ERR; - } - bool isTakeOver = OnTakeOverSuspend(type); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Bool, isTakeOver, E_WRITE_PARCEL_ERROR); - return ERR_OK; -} -} // namespace PowerMgr -} // namespace OHOS \ No newline at end of file diff --git a/test/autotest/choose_device.py b/test/autotest/choose_device.py deleted file mode 100644 index 31c2f087eb4f94ee3735b9bb4f30f735d68e84f8..0000000000000000000000000000000000000000 --- a/test/autotest/choose_device.py +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env python3 -#-*- coding: utf-8 -*- - -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import json -import os - - -def read_json_files_in_directory(path, type_device): - """ - @func:Configuration file to be modified - @param path: path name - @param type_device:Types that need to be modified - """ - if not os.path.exists(path): - print(f"path:'{path}'not exist") - return - for root, dirs, files in os.walk(path): - for filename in files: - if filename.endswith('.json'): - filepath = os.path.join(root, filename) - with open(filepath, 'r', encoding='utf-8') as f: - data = json.load(f) - for item in data['environment']: - item['label'] = type_device - data = json.dumps(data, indent=4, ensure_ascii=False) - with open(filepath, 'w', encoding='utf-8') as f: - f.write(data) - - -json_path = "testcases" - -all_types = ["phone", "car", "tv", "watch", "tablet", "2in1"] -all_types_name = ["phone", "car", "tv", "watch", "tablet", "pc"] -print("Please enter the serial number of the device to be tested:1 2 3 4 5 6") -print("1:phone") -print("2:car") -print("3:tv") -print("4:watch") -print("5:tablet") -print("6:pc") -print("please input:") -type_number = int(input()) -numbers = [1, 2, 3, 4, 5, 6] -if type_number not in numbers: - print("Input error, please execute again") -else: - type_device = all_types[type_number - 1] - read_json_files_in_directory(json_path, type_device) - print("Select Test " + all_types_name[type_number - 1] + " successfully!") diff --git a/test/autotest/config/use_config.xml b/test/autotest/config/use_config.xml deleted file mode 100644 index 7b5ac00759798c99d726493ba7a0322f50d9e41c..0000000000000000000000000000000000000000 --- a/test/autotest/config/use_config.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - testcases - - - - - - - - - - - - - DEBUG - ON - \ No newline at end of file diff --git a/test/autotest/main.py b/test/autotest/main.py deleted file mode 100644 index baba3a10c5638f3a5f75c72579bab2a6de6573fb..0000000000000000000000000000000000000000 --- a/test/autotest/main.py +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env python3 -#-*- coding: utf-8 -*- - -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from xdevice.__main__ import main_process - -main_process("run -l testcases/level0") \ No newline at end of file diff --git a/test/autotest/testcases/level0/SUB_KILL_FOUNDATION_TEST.json b/test/autotest/testcases/level0/SUB_KILL_FOUNDATION_TEST.json deleted file mode 100644 index b4168f8588049a2f2590ede5a174b4e10e5085e2..0000000000000000000000000000000000000000 --- a/test/autotest/testcases/level0/SUB_KILL_FOUNDATION_TEST.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "description": "Kill foundation process, check screen states", - "environment": [ - { - "type": "device", - "label": "phone" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": [ - "testcases/level0/SUB_KILL_FOUNDATION_TEST.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/testcases/level0/SUB_KILL_FOUNDATION_TEST.py b/test/autotest/testcases/level0/SUB_KILL_FOUNDATION_TEST.py deleted file mode 100644 index 12bd12932800d3e985c34a3b917019a6a20d9f28..0000000000000000000000000000000000000000 --- a/test/autotest/testcases/level0/SUB_KILL_FOUNDATION_TEST.py +++ /dev/null @@ -1,107 +0,0 @@ -#!/usr/bin/env python3 -#-*- coding: utf-8 -*- - -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from devicetest.core.test_case import TestCase, Step, CheckPoint, get_report_dir -from hypium import UiDriver -import time -from hypium import * -from hypium.action.os_hypium.device_logger import DeviceLogger -from hypium.action.host import host -from hypium.model import UiParam - - -class SUB_KILL_FOUNDATION_TEST(TestCase): - - def __init__(self, configs): - self.TAG = self.__class__.__name__ - TestCase.__init__(self, self.TAG, configs) - self.tests = [ - "test_step" - ] - self.driver = UiDriver(self.device1) - self.driver_width, self.driver_height = self.driver.get_display_size() - self.sn = self.device1.device_sn - - def setup(self): - self.log.info("SUB_KILL_FOUNDATION_TEST start") - #处理可能会弹出的USB连接方式弹窗 - self.driver.touch(BY.text("确定"), EXCEPTION=False) - - Step("预置条件1:设置休眠时长1min") - self.driver.Screen.set_sleep_time(60) - - Step("预置条件2:关闭AOD息屏显示") - self.driver.start_app("com.huawei.hmos.settings") - - #点击顶部搜索设置项 - self.driver.touch(BY.type('SearchField')) - self.driver.wait(0.5) - - self.driver.wait(2) - - #处理可能会弹出的小艺使用请求 - self.driver.touch(BY.text("同意").type("Button"), EXCEPTION=False) - self.driver.touch(BY.text("下一步").type("Button"), EXCEPTION=False) - - #输入xiping - self.driver.input_text(BY.type("SearchField"), "xiping") - - #点击弹出的熄屏显示控件 - self.driver.touch(BY.text("桌面和个性化 > 熄屏显示设置")) - self.driver.switch_component_status(BY.type('Toggle'), False) - - #回到桌面 - self.driver.go_home() - - #清除日志 - host.shell("hdc -t {} shell rm -r /data/log/hilog".format(self.sn)) - host.shell("hdc -t {} shell hilog -d /system/bin/samgr".format(self.sn)) - - def test_step(self): - Step("kill foundation进程") - self.driver.System.execute_command("kill -9 `pidof foundation`") - - Step("等待7s") - time.sleep(7) - - Step("7s后解锁进入桌面") - self.driver.ScreenLock.unlock() - - Step("按键灭屏") - self.driver.press_key(KeyCode.POWER) - self.driver.wait(2) - - Step("检查是否为灭屏状态") - self.driver.Screen.check_on(expect_on=False) - - time.sleep(2) - - Step("按键亮屏") - self.driver.press_key(KeyCode.POWER) - self.driver.wait(1) - - Step("检查是否为亮屏状态") - self.driver.Screen.check_on() - - - - def teardown(self): - Step("收尾工作") - self.log.info("SUB_KILL_FOUNDATION_TEST down") - self.driver.stop_app("com.huawei.hmos.settings") - - #回到桌面 - self.driver.go_home() \ No newline at end of file diff --git a/test/autotest/testcases/level0/SUB_MUSIC_TEST.json b/test/autotest/testcases/level0/SUB_MUSIC_TEST.json deleted file mode 100644 index c20edf8cacbcac4c46c4dfdac4ffaaf25ba487c5..0000000000000000000000000000000000000000 --- a/test/autotest/testcases/level0/SUB_MUSIC_TEST.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "description": "Verify the music switching function", - "environment": [ - { - "type": "device", - "label": "phone" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": [ - "testcases/level0/SUB_MUSIC_TEST.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/testcases/level0/SUB_MUSIC_TEST.py b/test/autotest/testcases/level0/SUB_MUSIC_TEST.py deleted file mode 100644 index 62fd07032326cab663722ba87b4b84d882c6059e..0000000000000000000000000000000000000000 --- a/test/autotest/testcases/level0/SUB_MUSIC_TEST.py +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env python3 -#-*- coding: utf-8 -*- - -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from devicetest.utils.file_util import get_resource_path -from devicetest.core.test_case import TestCase, Step, CheckPoint, get_report_dir -from hypium import UiDriver -import time -from hypium import * -from hypium.action.os_hypium.device_logger import DeviceLogger -from hypium.action.host import host -from hypium.model import UiParam - - -class SUB_MUSIC_TEST(TestCase): - - def __init__(self, configs): - self.TAG = self.__class__.__name__ - TestCase.__init__(self, self.TAG, configs) - self.tests = [ - "test_step" - ] - self.driver = UiDriver(self.device1) - self.driver_width, self.driver_height = self.driver.get_display_size() - self.sn = self.device1.device_sn - - def setup(self): - self.log.info("SUB_MUSIC_TEST start") - #处理可能会弹出的USB连接方式弹窗 - self.driver.touch(BY.text("确定"), EXCEPTION=False) - - #清除日志 - host.shell("hdc -t {} shell rm -r /data/log/hilog".format(self.sn)) - host.shell("hdc -t {} shell hilog -d /system/bin/samgr".format(self.sn)) - - #回到桌面 - self.driver.go_home() - - def test_step(self): - Step("启动音乐应用") - app = Launcher.find.app(self.driver, "音乐") - host.check(app is not None, fail_msg='找不到音乐应用') - self.driver.touch(app) - self.driver.wait(0.5) - - #处理第一次弹出的同意使用app的选项 - self.driver.touch(BY.text("同意").type("Button"), EXCEPTION=False) - self.driver.wait(0.5) - - #通过相对位置点击控件,开始播放音乐 - self.driver.touch(BY.isAfter(BY.key('uiplus_cover')).isBefore(BY.key('uiplus_title_right')).key('uiplus_rl_play').type('SymbolGlyph')) - self.driver.wait(0.5) - - - self.driver.wait(100) - self.driver.Audio.start_check_audio_in_background(VolumeType.MEDIA, 100) - self.driver.Audio.check_audio_result_in_background(VolumeType.MEDIA, expect_play=True) - - - def teardown(self): - Step("收尾工作") - self.log.info("SUB_MUSIC_TEST down") - self.driver.stop_app("com.huawei.hmsapp.music") - - #回到桌面 - self.driver.go_home() \ No newline at end of file diff --git a/test/autotest/testcases/level0/SUB_POWER_SHELL_SETMODE_TEST.json b/test/autotest/testcases/level0/SUB_POWER_SHELL_SETMODE_TEST.json deleted file mode 100644 index 5e1e6ed24496913e9ed37e4e7462fa3ab9705230..0000000000000000000000000000000000000000 --- a/test/autotest/testcases/level0/SUB_POWER_SHELL_SETMODE_TEST.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "description": "power-shell setmode functions", - "environment": [ - { - "type": "device", - "label": "phone" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": [ - "testcases/level0/SUB_POWER_SHELL_SETMODE_TEST.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/testcases/level0/SUB_POWER_SHELL_SETMODE_TEST.py b/test/autotest/testcases/level0/SUB_POWER_SHELL_SETMODE_TEST.py deleted file mode 100644 index f0517290077a1aefdc93f873033e84dbb7a463c2..0000000000000000000000000000000000000000 --- a/test/autotest/testcases/level0/SUB_POWER_SHELL_SETMODE_TEST.py +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/env python3 -#-*- coding: utf-8 -*- - -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from devicetest.utils.file_util import get_resource_path -from devicetest.core.test_case import TestCase, Step, CheckPoint, get_report_dir -from hypium import UiDriver -import time -from hypium import * -from hypium.action.os_hypium.device_logger import DeviceLogger -from hypium.action.host import host -from hypium.model import UiParam - - -class SUB_POWER_SHELL_SETMODE_TEST(TestCase): - - def __init__(self, configs): - self.TAG = self.__class__.__name__ - TestCase.__init__(self, self.TAG, configs) - self.tests = [ - "test_step" - ] - self.driver = UiDriver(self.device1) - self.driver_width, self.driver_height = self.driver.get_display_size() - self.sn = self.device1.device_sn - - def setup(self): - self.log.info("SUB_POWER_SHELL_SETMODE_TEST start") - - - #回到桌面 - self.driver.go_home() - - #清除日志 - host.shell("hdc -t {} shell rm -r /data/log/hilog".format(self.sn)) - host.shell("hdc -t {} shell hilog -d /system/bin/samgr".format(self.sn)) - - def test_step(self): - Step("hdc shell 下执行power-shell setmode 601") - result = self.driver.System.execute_command("power-shell setmode 601") - CheckPoint("power-shell命令是否可以正常使用") - assert "Set Mode: 601" in result - assert "Set Mode Success!" in result - - - Step("hdc shell 下执行power-shell setmode 602") - result = self.driver.System.execute_command("power-shell setmode 602") - CheckPoint("power-shell命令是否可以正常使用") - assert "Set Mode: 602" in result - assert "Set Mode Success!" in result - - Step("hdc shell 下执行power-shell setmode 601") - result = self.driver.System.execute_command("power-shell setmode 603") - CheckPoint("power-shell命令是否可以正常使用") - assert "Set Mode: 603" in result - assert "Set Mode Success!" in result - - Step("hdc shell 下执行power-shell setmode 600") - result = self.driver.System.execute_command("power-shell setmode 600") - CheckPoint("power-shell命令是否可以正常使用") - assert "Set Mode: 600" in result - assert "Set Mode Success!" in result - - - def teardown(self): - Step("收尾工作") - self.log.info("SUB_POWER_SHELL_SETMODE_TEST down") - - #回到桌面 - self.driver.go_home() \ No newline at end of file diff --git a/test/autotest/testcases/level0/SUB_POWER_SHELL_TEST.json b/test/autotest/testcases/level0/SUB_POWER_SHELL_TEST.json deleted file mode 100644 index 77d36610fc094b6fc775deed7c765e1ea993d17b..0000000000000000000000000000000000000000 --- a/test/autotest/testcases/level0/SUB_POWER_SHELL_TEST.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "description": "power-shell basic functions", - "environment": [ - { - "type": "device", - "label": "phone" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": [ - "testcases/level0/SUB_POWER_SHELL_TEST.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/testcases/level0/SUB_POWER_SHELL_TEST.py b/test/autotest/testcases/level0/SUB_POWER_SHELL_TEST.py deleted file mode 100644 index 58a3d4051991da4efa6f4c9ba965508f9e79cb46..0000000000000000000000000000000000000000 --- a/test/autotest/testcases/level0/SUB_POWER_SHELL_TEST.py +++ /dev/null @@ -1,118 +0,0 @@ -#!/usr/bin/env python3 -#-*- coding: utf-8 -*- - -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from devicetest.utils.file_util import get_resource_path -from devicetest.core.test_case import TestCase, Step, CheckPoint, get_report_dir -from hypium import UiDriver -import time -from hypium import * -from hypium.action.os_hypium.device_logger import DeviceLogger -from hypium.action.host import host -from hypium.model import UiParam - - -class SUB_POWER_SHELL_TEST(TestCase): - - def __init__(self, configs): - self.TAG = self.__class__.__name__ - TestCase.__init__(self, self.TAG, configs) - self.tests = [ - "test_step" - ] - self.driver = UiDriver(self.device1) - self.driver_width, self.driver_height = self.driver.get_display_size() - self.sn = self.device1.device_sn - - def setup(self): - self.log.info("SUB_POWER_SHELL_TEST start") - #处理可能会弹出的USB连接方式弹窗 - self.driver.touch(BY.text("确定"), EXCEPTION=False) - - Step("预置条件1:设置休眠时长15s") - self.driver.Screen.set_sleep_time(15) - - Step("预置条件2:关闭AOD息屏显示") - self.driver.start_app("com.huawei.hmos.settings") - - #点击顶部搜索设置项 - self.driver.touch(BY.type('SearchField')) - self.driver.wait(0.5) - - self.driver.wait(2) - - #处理可能会弹出的小艺使用请求 - self.driver.touch(BY.text("同意").type("Button"), EXCEPTION=False) - self.driver.touch(BY.text("下一步").type("Button"), EXCEPTION=False) - - #输入xiping - self.driver.input_text(BY.type("SearchField"), "xiping") - - #点击弹出的熄屏显示控件 - self.driver.touch(BY.text("桌面和个性化 > 熄屏显示设置")) - self.driver.switch_component_status(BY.type('Toggle'), False) - - - #回到桌面 - self.driver.go_home() - - #清除日志 - host.shell("hdc -t {} shell rm -r /data/log/hilog".format(self.sn)) - host.shell("hdc -t {} shell hilog -d /system/bin/samgr".format(self.sn)) - - def test_step(self): - Step("hdc shell 下执行power-shell --help") - result = self.driver.System.execute_command("power-shell --help") - - CheckPoint("只打印setmode、wakeup、suspend、timeout、help命令,其他不打印,且命令功能正常") - assert "setmode : Set power mode" in result - assert "wakeup : Wakeup system and turn screen on" in result - assert "suspend : Suspend system and turn screen off" in result - assert "timeout : Override or Restore screen off time" in result - assert "help : Show this help menu" in result - - - Step("设备执行pwoer-shell命令:power-shell suspend") - self.driver.System.execute_command("power-shell suspend") - - CheckPoint("原本的power-shell命令可以正常使用") - self.driver.Screen.check_on(expect_on=False) - - Step("设备执行pwoer-shell命令:power-shell wakeup") - self.driver.System.execute_command("power-shell wakeup") - self.driver.Screen.check_on() - - Step("设备执行pwoer-shell命令:power-shell timeout -o 5000") - self.driver.System.execute_command("power-shell timeout -o 5000") - time.sleep(5) - self.driver.Screen.check_on(expect_on=False) - - Step("设备执行pwoer-shell命令:power-shell timeout -r") - self.driver.System.execute_command("power-shell timeout -r") - #恢复超时灭屏时间后唤醒设备 - self.driver.System.execute_command("power-shell wakeup") - #解锁进入桌面 - self.driver.ScreenLock.unlock() - time.sleep(15) - #等待15s后灭屏 - self.driver.Screen.check_on(expect_on=False) - - - def teardown(self): - Step("收尾工作") - self.log.info("SUB_POWER_SHELL_TEST down") - - #回到桌面 - self.driver.go_home() \ No newline at end of file diff --git a/test/autotest/testcases/level0/SUB_REFRESH_SCREEN_STATE_TEST.json b/test/autotest/testcases/level0/SUB_REFRESH_SCREEN_STATE_TEST.json deleted file mode 100644 index efdea72b2276cd621858a9b424f9f7a42a87aa70..0000000000000000000000000000000000000000 --- a/test/autotest/testcases/level0/SUB_REFRESH_SCREEN_STATE_TEST.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "description": "refresh screen state", - "environment": [ - { - "type": "device", - "label": "phone" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": [ - "testcases/level0/SUB_REFRESH_SCREEN_STATE_TEST.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/testcases/level0/SUB_REFRESH_SCREEN_STATE_TEST.py b/test/autotest/testcases/level0/SUB_REFRESH_SCREEN_STATE_TEST.py deleted file mode 100644 index db48b97365bfa9c2bafaab772ad01698a910cacb..0000000000000000000000000000000000000000 --- a/test/autotest/testcases/level0/SUB_REFRESH_SCREEN_STATE_TEST.py +++ /dev/null @@ -1,112 +0,0 @@ -#!/usr/bin/env python3 -#-*- coding: utf-8 -*- - -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from devicetest.core.test_case import TestCase, Step, CheckPoint, get_report_dir -from hypium import UiDriver -import time -from hypium import * -from hypium.action.os_hypium.device_logger import DeviceLogger -from hypium.action.host import host -from hypium.model import UiParam - - -class SUB_REFRESH_SCREEN_STATE_TEST(TestCase): - - def __init__(self, configs): - self.TAG = self.__class__.__name__ - TestCase.__init__(self, self.TAG, configs) - self.tests = [ - "test_step" - ] - self.driver = UiDriver(self.device1) - self.driver_width, self.driver_height = self.driver.get_display_size() - self.sn = self.device1.device_sn - - def setup(self): - self.log.info("SUB_REFRESH_SCREEN_STATE_TEST start") - #处理可能会弹出的USB连接方式弹窗 - self.driver.touch(BY.text("确定"), EXCEPTION=False) - - self.driver.stop_app("com.huawei.hmos.settings") - - Step("预置条件1:设置休眠时长30s") - self.driver.Screen.set_sleep_time(30) - - Step("预置条件2:开启AOD息屏显示") - self.driver.start_app("com.huawei.hmos.settings") - - #点击顶部搜索设置项 - self.driver.touch(BY.type('SearchField')) - self.driver.wait(0.5) - - self.driver.wait(2) - - #处理可能会弹出的小艺使用请求 - self.driver.touch(BY.text("同意").type("Button"), EXCEPTION=False) - self.driver.touch(BY.text("下一步").type("Button"), EXCEPTION=False) - - #输入xiping - self.driver.input_text(BY.type("SearchField"), "xiping") - - #点击弹出的熄屏显示控件 - self.driver.touch(BY.text("桌面和个性化 > 熄屏显示设置")) - self.driver.switch_component_status(BY.type('Toggle'), True) - - #通过相对位置点击控件,返回上一页 - self.driver.touch(BY.type('SymbolGlyph')) - self.driver.wait(0.5) - - self.driver.touch(BY.text('注视屏幕不熄屏')) - self.driver.wait(0.5) - - #点击注释屏幕不熄屏开关 - self.driver.switch_component_status(BY.key('Setting.Display.screen_group.gaze_screen.result'), False) - - #回到桌面 - self.driver.go_home() - - #清除日志 - host.shell("hdc -t {} shell rm -r /data/log/hilog".format(self.sn)) - host.shell("hdc -t {} shell hilog -d /system/bin/samgr".format(self.sn)) - - def test_step(self): - - device_logger = DeviceLogger(self.driver).set_filter_string("powermgr") - device_logger.start_log(get_report_dir() + '//refresh_screen_state.txt') - self.driver.wait(26) - - # 点击屏幕,触发REFRESH - self.driver.touch((0.7, 0.8)) - - device_logger.stop_log() - - CheckPoint("查看dim日志") - log_check_result = device_logger.check_log("StateContriller::TransitTo DIM", EXCEPTION=True) - self.driver.Assert.equal(log_check_result, True) - CheckPoint("查看refresh日志") - - log_check_result = device_logger.check_log("Transit from DIM to AWAKE for REFRESH", EXCEPTION=True) - self.driver.Assert.equal(log_check_result, True) - self.driver.wait(30) - self.driver.Screen.check_on(expect_on=False) - - def teardown(self): - Step("收尾工作") - self.log.info("SUB_REFRESH_SCREEN_STATE_TEST down") - self.driver.stop_app("com.huawei.hmos.settings") - - #回到桌面 - self.driver.go_home() \ No newline at end of file diff --git a/test/autotest/testcases/level0/SUB_RUNNINGLOCK_TEST.json b/test/autotest/testcases/level0/SUB_RUNNINGLOCK_TEST.json deleted file mode 100644 index 5d6a196d1ead0e618edcd882dd27869d6bf83d53..0000000000000000000000000000000000000000 --- a/test/autotest/testcases/level0/SUB_RUNNINGLOCK_TEST.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "description": "Run the lock lock function", - "environment": [ - { - "type": "device", - "label": "phone" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": [ - "testcases/level0/SUB_RUNNINGLOCK_TEST.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/testcases/level0/SUB_RUNNINGLOCK_TEST.py b/test/autotest/testcases/level0/SUB_RUNNINGLOCK_TEST.py deleted file mode 100644 index 6ca113b9eca7d88cb578c74eb049036d4095eb03..0000000000000000000000000000000000000000 --- a/test/autotest/testcases/level0/SUB_RUNNINGLOCK_TEST.py +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/env python3 -#-*- coding: utf-8 -*- - -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from devicetest.utils.file_util import get_resource_path -from devicetest.core.test_case import TestCase, Step, CheckPoint, get_report_dir -from hypium import UiDriver -import time -from hypium import * -from hypium.action.os_hypium.device_logger import DeviceLogger -from hypium.action.host import host -from hypium.model import UiParam - - -class SUB_RUNNINGLOCK_TEST(TestCase): - - def __init__(self, configs): - self.TAG = self.__class__.__name__ - TestCase.__init__(self, self.TAG, configs) - self.tests = [ - "test_step" - ] - self.driver = UiDriver(self.device1) - self.driver_width, self.driver_height = self.driver.get_display_size() - self.sn = self.device1.device_sn - - def setup(self): - self.log.info("SUB_RUNNINGLOCK_TEST start") - #处理可能会弹出的USB连接方式弹窗 - self.driver.touch(BY.text("确定"), EXCEPTION=False) - - - Step("预置条件1:设置休眠时长30s") - self.driver.Screen.set_sleep_time(30) - - #清除日志 - host.shell("hdc -t {} shell rm -r /data/log/hilog".format(self.sn)) - host.shell("hdc -t {} shell hilog -d /system/bin/samgr".format(self.sn)) - - #回到桌面 - self.driver.go_home() - - def test_step(self): - Step("启动华为视频应用") - self.driver.start_app("com.huawei.hmsapp.himovie") - self.driver.wait(0.5) - - #处理第一次弹出的同意使用app的选项 - self.driver.touch(BY.text("同意").type("Button"), EXCEPTION=False) - self.driver.wait(0.5) - - - #点击免费专区 - self.driver.touch(BY.key('PafSubTabBars.Text.text').text('免费专区')) - - #通过相对位置点击控件,开始播放视频 - self.driver.touch(BY.isAfter(BY.key('3560')).isBefore(BY.type('RelativeContainer')).key('ImageTextCard.Image.imageUrl').type('Image')) - self.driver.wait(0.5) - - - self.driver.wait(30) - Step("检查是否为亮屏状态") - self.driver.Screen.check_on() - - - def teardown(self): - Step("收尾工作") - self.log.info("SUB_RUNNINGLOCK_TEST down") - self.driver.stop_app("com.huawei.hmsapp.himovie") - #回到桌面 - self.driver.go_home() \ No newline at end of file diff --git a/test/autotest/testcases/level0/SUB_RUNNINGLOCK_TIMEOUT_TEST.json b/test/autotest/testcases/level0/SUB_RUNNINGLOCK_TIMEOUT_TEST.json deleted file mode 100644 index 90990498b3a69953210f5248bf48089cb4149dbb..0000000000000000000000000000000000000000 --- a/test/autotest/testcases/level0/SUB_RUNNINGLOCK_TIMEOUT_TEST.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "description": "Run the lock timeout", - "environment": [ - { - "type": "device", - "label": "phone" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": [ - "testcases/level0/SUB_RUNNINGLOCK_TIMEOUT_TEST.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/testcases/level0/SUB_RUNNINGLOCK_TIMEOUT_TEST.py b/test/autotest/testcases/level0/SUB_RUNNINGLOCK_TIMEOUT_TEST.py deleted file mode 100644 index 215d415be4be7f9a2175a582d47ce2e6ba4d4a39..0000000000000000000000000000000000000000 --- a/test/autotest/testcases/level0/SUB_RUNNINGLOCK_TIMEOUT_TEST.py +++ /dev/null @@ -1,85 +0,0 @@ -#!/usr/bin/env python3 -#-*- coding: utf-8 -*- - -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from devicetest.utils.file_util import get_resource_path -from devicetest.core.test_case import TestCase, Step, CheckPoint, get_report_dir -from hypium import UiDriver -import time -from hypium import * -from hypium.action.os_hypium.device_logger import DeviceLogger -from hypium.action.host import host -from hypium.model import UiParam - - -class SUB_RUNNINGLOCK_TIMEOUT_TEST(TestCase): - - def __init__(self, configs): - self.TAG = self.__class__.__name__ - TestCase.__init__(self, self.TAG, configs) - self.tests = [ - "test_step" - ] - self.driver = UiDriver(self.device1) - self.driver_width, self.driver_height = self.driver.get_display_size() - self.sn = self.device1.device_sn - - def setup(self): - self.log.info("SUB_RUNNINGLOCK_TIMEOUT_TEST start") - - #清除日志 - host.shell("hdc -t {} shell rm -r /data/log/hilog".format(self.sn)) - host.shell("hdc -t {} shell hilog -d /system/bin/samgr".format(self.sn)) - self.driver.install_app(package_path=power_hap_path) - self.driver.ScreenLock.unLock() - - #回到桌面 - self.driver.go_home() - - def test_step(self): - device_logger = DeviceLogger(self.driver).set_filter_string("powermgr") - device_logger.start_log(get_report_dir() + '//runninglock_timeout.txt') - - Step("点击运行锁") - self.driver.start_app(package_name="ohos.power.powermanager") - # 通过相对位置点击控件 - self.driver.touch(BY.isAfter(BY.text('运行锁相关功能')).isBefore(BY.text('耗电统计')).type('Image')) - - self.driver.wait(0.5) - - # 输入超时时间10000 - self.driver.input_text(BY.type('TextInput'), '10000') - self.driver.wait(0.5) - - self.driver.touch(BY.type('Image').isBefore(BY.key('keyboardRightButton'))) - self.driver.wait(0.5) - - self.driver.touch(BY.type('Button').text('持锁')) - self.driver.wait(10) - device_logger.stop_log() - - log_check_result = device_logger.check_log("try Lock, name: power_sample_timeout", EXCEPTION=True) - self.driver.Assert.equal(log_check_result, True) - - log_check_result = device_logger.check_log("try UnLock, name: power_sample_timeout", EXCEPTION=True) - self.driver.Assert.equal(log_check_result, True) - - - def teardown(self): - Step("收尾工作") - self.log.info("SUB_RUNNINGLOCK_TIMEOUT_TEST down") - self.driver.stop_app(package_name="ohos.power.powermanager") - #回到桌面 - self.driver.go_home() \ No newline at end of file diff --git a/test/autotest/testcases/level0/SUB_SCREEN_STATE_WITHOUT_AOD_TEST.json b/test/autotest/testcases/level0/SUB_SCREEN_STATE_WITHOUT_AOD_TEST.json deleted file mode 100644 index 65efd453d0b42766ba7ff87a6270db5fd1bd587e..0000000000000000000000000000000000000000 --- a/test/autotest/testcases/level0/SUB_SCREEN_STATE_WITHOUT_AOD_TEST.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "description": "Turn off the AOD on/off screen", - "environment": [ - { - "type": "device", - "label": "phone" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": [ - "testcases/level0/SUB_SCREEN_STATE_WITHOUT_AOD_TEST.py" - ] - } - } \ No newline at end of file diff --git a/test/autotest/testcases/level0/SUB_SCREEN_STATE_WITHOUT_AOD_TEST.py b/test/autotest/testcases/level0/SUB_SCREEN_STATE_WITHOUT_AOD_TEST.py deleted file mode 100644 index 838a757bd9483352d43ed045fa4a751a6f108f33..0000000000000000000000000000000000000000 --- a/test/autotest/testcases/level0/SUB_SCREEN_STATE_WITHOUT_AOD_TEST.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python3 -#-*- coding: utf-8 -*- - -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from devicetest.core.test_case import TestCase, Step, CheckPoint, get_report_dir -from hypium import UiDriver -import time -from hypium import * -from hypium.action.os_hypium.device_logger import DeviceLogger -from hypium.action.host import host -from hypium.model import UiParam - - -class SUB_SCREEN_STATE_WITHOUT_AOD_TEST(TestCase): - - def __init__(self, configs): - self.TAG = self.__class__.__name__ - TestCase.__init__(self, self.TAG, configs) - self.tests = [ - "test_step" - ] - self.driver = UiDriver(self.device1) - self.driver_width, self.driver_height = self.driver.get_display_size() - self.sn = self.device1.device_sn - - def setup(self): - self.log.info("SUB_SCREEN_STATE_WITHOUT_AOD_TEST start") - #处理可能会弹出的USB连接方式弹窗 - self.driver.touch(BY.text("确定"), EXCEPTION=False) - - Step("预置条件1:设置休眠时长30s") - self.driver.Screen.set_sleep_time(30) - - Step("预置条件2:关闭AOD息屏显示") - self.driver.start_app("com.huawei.hmos.settings") - - #点击顶部搜索设置项 - self.driver.touch(BY.type('SearchField')) - self.driver.wait(0.5) - - self.driver.wait(2) - - #处理可能会弹出的小艺使用请求 - self.driver.touch(BY.text("同意").type("Button"), EXCEPTION=False) - self.driver.touch(BY.text("下一步").type("Button"), EXCEPTION=False) - - #输入xiping - self.driver.input_text(BY.type("SearchField"), "xiping") - - #点击弹出的熄屏显示控件 - self.driver.touch(BY.text("桌面和个性化 > 熄屏显示设置")) - self.driver.switch_component_status(BY.type('Toggle'), False) - - #回到桌面 - self.driver.go_home() - - #清除日志 - host.shell("hdc -t {} shell rm -r /data/log/hilog".format(self.sn)) - host.shell("hdc -t {} shell hilog -d /system/bin/samgr".format(self.sn)) - - def test_step(self): - - - Step("按键灭屏") - self.driver.press_key(KeyCode.POWER) - self.driver.wait(0.5) - - Step("检查是否为灭屏状态") - self.driver.Screen.check_on(expect_on=False) - - - Step("按键亮屏") - self.driver.press_key(KeyCode.POWER) - self.driver.wait(0.3) - - Step("检查是否为亮屏状态") - self.driver.Screen.check_on() - - def teardown(self): - Step("收尾工作") - self.log.info("SUB_SCREEN_STATE_WITHOUT_AOD_TEST down") - self.driver.stop_app("com.huawei.hmos.settings") - - #回到桌面 - self.driver.go_home() \ No newline at end of file diff --git a/test/autotest/testcases/level0/SUB_SCREEN_STATE_WITH_AOD_TEST.json b/test/autotest/testcases/level0/SUB_SCREEN_STATE_WITH_AOD_TEST.json deleted file mode 100644 index 53396c526045edefff58508d3427f3f6ea912892..0000000000000000000000000000000000000000 --- a/test/autotest/testcases/level0/SUB_SCREEN_STATE_WITH_AOD_TEST.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "description": "Turn on the AOD on/off screen", - "environment": [ - { - "type": "device", - "label": "phone" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": [ - "testcases/level0/SUB_SCREEN_STATE_WITH_AOD_TEST.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/testcases/level0/SUB_SCREEN_STATE_WITH_AOD_TEST.py b/test/autotest/testcases/level0/SUB_SCREEN_STATE_WITH_AOD_TEST.py deleted file mode 100644 index 72c88950f4caf206c98c77a7fdff0dcfc8e9dc0c..0000000000000000000000000000000000000000 --- a/test/autotest/testcases/level0/SUB_SCREEN_STATE_WITH_AOD_TEST.py +++ /dev/null @@ -1,105 +0,0 @@ -#!/usr/bin/env python3 -#-*- coding: utf-8 -*- - -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from devicetest.core.test_case import TestCase, Step, CheckPoint, get_report_dir -from hypium import UiDriver -import time -from hypium import * -from hypium.action.os_hypium.device_logger import DeviceLogger -from hypium.action.host import host -from hypium.model import UiParam - - -class SUB_SCREEN_STATE_WITH_AOD_TEST(TestCase): - - def __init__(self, configs): - self.TAG = self.__class__.__name__ - TestCase.__init__(self, self.TAG, configs) - self.tests = [ - "test_step" - ] - self.driver = UiDriver(self.device1) - self.driver_width, self.driver_height = self.driver.get_display_size() - self.sn = self.device1.device_sn - - def setup(self): - self.log.info("SUB_SCREEN_STATE_WITH_AOD_TEST start") - #处理可能会弹出的USB连接方式弹窗 - self.driver.touch(BY.text("确定"), EXCEPTION=False) - - Step("预置条件1:设置休眠时长30s") - self.driver.Screen.set_sleep_time(30) - - Step("预置条件2:开启AOD息屏显示") - self.driver.start_app("com.huawei.hmos.settings") - - #点击顶部搜索设置项 - self.driver.touch(BY.type('SearchField')) - self.driver.wait(0.5) - - self.driver.wait(2) - - #处理可能会弹出的小艺使用请求 - self.driver.touch(BY.text("同意").type("Button"), EXCEPTION=False) - self.driver.touch(BY.text("下一步").type("Button"), EXCEPTION=False) - - #输入xiping - self.driver.input_text(BY.type("SearchField"), "xiping") - - #点击弹出的熄屏显示控件 - self.driver.touch(BY.text("桌面和个性化 > 熄屏显示设置")) - self.driver.switch_component_status(BY.type('Toggle'), True) - - #通过相对位置点击控件,返回上一页 - self.driver.touch(BY.type('SymbolGlyph')) - self.driver.wait(0.5) - - self.driver.touch(BY.text('注视屏幕不熄屏')) - self.driver.wait(0.5) - - #点击注释屏幕不熄屏开关 - self.driver.switch_component_status(BY.key('Setting.Display.screen_group.gaze_screen.result'), False) - - #回到桌面 - self.driver.go_home() - - #清除日志 - host.shell("hdc -t {} shell rm -r /data/log/hilog".format(self.sn)) - host.shell("hdc -t {} shell hilog -d /system/bin/samgr".format(self.sn)) - - def test_step(self): - - - device_logger = DeviceLogger(self.driver).set_filter_string("powermgr") - device_logger.start_log(get_report_dir() + '//screen_state_with_aod.txt') - self.driver.wait(30) - device_logger.stop_log() - - CheckPoint("查看dim日志") - log_check_result = device_logger.check_log("StateContriller::TransitTo DIM", EXCEPTION=True) - self.driver.Assert.equal(log_check_result, True) - CheckPoint("查看inactive日志") - - log_check_result = device_logger.check_log("Transit from DIM to INACTIVE for TIMEOUT", EXCEPTION=True) - self.driver.Assert.equal(log_check_result, True) - - def teardown(self): - Step("收尾工作") - self.log.info("SUB_SCREEN_STATE_WITH_AOD_TEST down") - self.driver.stop_app("com.huawei.hmos.settings") - - #回到桌面 - self.driver.go_home() \ No newline at end of file diff --git a/test/autotest/testcases/level0/SUB_SHUTDOWN_REBOOT_TEST.json b/test/autotest/testcases/level0/SUB_SHUTDOWN_REBOOT_TEST.json deleted file mode 100644 index 995584467bd4cf23096ffcac6d737fc16276f753..0000000000000000000000000000000000000000 --- a/test/autotest/testcases/level0/SUB_SHUTDOWN_REBOOT_TEST.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "description": "shutdown and reboot", - "environment": [ - { - "type": "device", - "label": "phone" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": [ - "testcases/level0/SUB_SHUTDOWN_REBOOT_TEST.py" - ] - } - } \ No newline at end of file diff --git a/test/autotest/testcases/level0/SUB_SHUTDOWN_REBOOT_TEST.py b/test/autotest/testcases/level0/SUB_SHUTDOWN_REBOOT_TEST.py deleted file mode 100644 index 627b5726c8667fe1409bce9570a88a9a846f4e47..0000000000000000000000000000000000000000 --- a/test/autotest/testcases/level0/SUB_SHUTDOWN_REBOOT_TEST.py +++ /dev/null @@ -1,123 +0,0 @@ -#!/usr/bin/env python3 -#-*- coding: utf-8 -*- - -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from devicetest.utils.file_util import get_resource_path -from devicetest.core.test_case import TestCase, Step, CheckPoint, get_report_dir -from hypium import UiDriver -import time -from hypium import * -from hypium.action.os_hypium.device_logger import DeviceLogger -from hypium.action.host import host -from hypium.model import UiParam - - -class SUB_SHUTDOWN_REBOOT_TEST(TestCase): - - def __init__(self, configs): - self.TAG = self.__class__.__name__ - TestCase.__init__(self, self.TAG, configs) - self.tests = [ - "test_step" - ] - self.driver = UiDriver(self.device1) - self.driver_width, self.driver_height = self.driver.get_display_size() - self.sn = self.device1.device_sn - - def setup(self): - self.log.info("SUB_SHUTDOWN_REBOOT_TEST start") - #处理可能会弹出的USB连接方式弹窗 - self.driver.touch(BY.text("确定"), EXCEPTION=False) - - Step("预置条件1:设置休眠时长15s") - self.driver.Screen.set_sleep_time(15) - - Step("预置条件2:关闭AOD息屏显示") - self.driver.start_app("com.huawei.hmos.settings") - - #点击顶部搜索设置项 - self.driver.touch(BY.type('SearchField')) - self.driver.wait(0.5) - - self.driver.wait(2) - - #处理可能会弹出的小艺使用请求 - self.driver.touch(BY.text("同意").type("Button"), EXCEPTION=False) - self.driver.touch(BY.text("下一步").type("Button"), EXCEPTION=False) - - #输入xiping - self.driver.input_text(BY.type("SearchField"), "xiping") - - #点击弹出的熄屏显示控件 - self.driver.touch(BY.text("桌面和个性化 > 熄屏显示设置")) - self.driver.switch_component_status(BY.type('Toggle'), False) - - - #回到桌面 - self.driver.go_home() - - #点亮屏幕 - self.driver.Screen.wake_up() - - #清除日志 - host.shell("hdc -t {} shell rm -r /data/log/hilog".format(self.sn)) - host.shell("hdc -t {} shell hilog -d /system/bin/samgr".format(self.sn)) - - - - def test_step(self): - #解锁进桌面 - self.driver.ScreenLock.unlock() - self.driver.wait(3) - - Step("步骤1:长按power键") - self.driver.press_key(KeyCode.POWER, mode=UiParam.LONG, duration=5) - self.driver.wait(1) - - CheckPoint("检测点:可弹出关机重启按钮") - self.driver.check_component_exist(BY.type('Text').text('重启'), expect_exist=True) - self.driver.check_component_exist(BY.type('Text').text('关机'), expect_exist=True) - - Step("步骤2:点击关机按钮") - com = self.driver.find_all_components(BY.type('Button'), index=1) - self.driver.touch(com, wait_time=1.5) - - CheckPoint("检测点:单独显示关机按钮 用于再次确认") - self.driver.check_component_exist(BY.type('Text').text('点击关机'), expect_exist=True) - #点击空白处,回到上一个页面 - self.driver.touch((500, 1800), wait_time=1.5) - - Step("步骤3:点击重启按钮") - com = self.driver.find_all_components(BY.type('Button'), index=0) - self.driver.touch(com, wait_time=1.5) - - CheckPoint("检测点:单独显示重启按钮 用于再次确认") - self.driver.check_component_exist(BY.type('Text').text('点击重启'), expect_exist=True) - - Step("步骤4:点击重启按钮") - self.driver.touch(BY.type('Image'), wait_time=1.5) - - #等待启动完成 - self.driver.System.wait_for_boot_complete() - - - - def teardown(self): - Step("收尾工作") - self.log.info("SUB_SHUTDOWN_REBOOT_TEST down") - self.driver.stop_app("com.huawei.hmos.settings") - - #回到桌面 - self.driver.go_home() \ No newline at end of file diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 00d3e4290b15fc0be1289edbc8be848ae8013eb2..8098544f2da8be5fecc9f94800f58ea47bcc7e9b 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -121,10 +121,7 @@ ohos_unittest("test_power_key_option") { ohos_unittest("test_power_mgr_client") { module_out_path = module_output_path - sources = [ - "src/interface_test/power_mgr_client_test.cpp", - "mock/mock_power_remote_object.cpp", - ] + sources = [ "src/interface_test/power_mgr_client_test.cpp" ] sanitize = { cfi = true @@ -301,6 +298,7 @@ ohos_unittest("test_running_lock") { "${powermgr_inner_api}:powermgr_client", "${powermgr_inner_api}:powermgr_proxy", "${powermgr_service_path}:powermgrservice", + "${powermgr_utils_path}:powermgr_utils", ] external_deps = deps_ex @@ -369,48 +367,6 @@ ohos_unittest("test_power_mgr_service") { ] } -ohos_unittest("test_power_mgr_service_ipc_adapter") { - module_out_path = module_output_path - - sanitize = { - cfi = true - cfi_cross_dso = true - debug = false - blocklist = "../cfi_blocklist.txt" - } - - sources = [ - "src/interface_test/power_mgr_service_ipc_adapter_test.cpp", - ] - - if (power_manager_feature_tv_dreaming) { - defines += [ "POWER_MANAGER_TV_DREAMING" ] - } - - if (power_manager_feature_force_sleep_broadcast) { - defines += [ "POWER_MANAGER_ENABLE_FORCE_SLEEP_BROADCAST" ] - } - - configs = [ - "${powermgr_utils_path}:utils_config", - ":module_private_config", - "${powermgr_utils_path}:coverage_flags", - ] - include_dirs = [ "${powermgr_service_path}/native/include" ] - deps = [ "${powermgr_service_path}:powermgrservice" ] - - external_deps = deps_ex + [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "access_token:libtokenid_sdk", - "cJSON:cjson", - "data_share:datashare_common", - "data_share:datashare_consumer", - "selinux_adapter:librestorecon", - ] -} - ohos_unittest("test_power_mgr_service_death") { module_out_path = module_output_path @@ -952,6 +908,7 @@ ohos_unittest("test_power_mgr_dump") { deps = [ "${powermgr_inner_api}:powermgr_client", "${powermgr_service_path}:powermgrservice", + ] external_deps = deps_ex @@ -1066,6 +1023,7 @@ ohos_unittest("test_running_lock_mock") { "${powermgr_inner_api}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", + ] external_deps = deps_ex @@ -1401,24 +1359,6 @@ ohos_unittest("test_power_shutdown_clinet") { external_deps = deps_ex } -ohos_unittest("test_power_suspend_takeover") { - module_out_path = module_output_path - - sources = [ "src/interface_test/suspend_takeover_client_test.cpp" ] - - configs = [ - "${powermgr_utils_path}:utils_config", - ":module_private_config", - "${powermgr_utils_path}:coverage_flags", - ] - - deps = [ - "${powermgr_inner_api}:powermgr_client", - "${powermgr_service_path}:powermgrservice", - ] - external_deps = deps_ex -} - ohos_unittest("test_power_getcontroller_mock") { module_out_path = module_output_path @@ -1612,6 +1552,7 @@ ohos_unittest("test_power_coordination_lock") { "${powermgr_inner_api}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_service_path}/native/src/actions:powermgr_actions", + ] external_deps = deps_ex @@ -1680,13 +1621,15 @@ ohos_unittest("test_power_config_parse") { } module_out_path = module_output_path - + cflags = [ "-Dprivate=public", "-Dprotected=public", ] - sources = [ "src/power_config_parse_test.cpp" ] + sources = [ + "src/power_config_parse_test.cpp", + ] configs = [ "${powermgr_utils_path}:utils_config", @@ -1694,9 +1637,9 @@ ohos_unittest("test_power_config_parse") { ":module_mock_private_config", "${powermgr_utils_path}:coverage_flags", ] - + include_dirs = [ "${powermgr_service_path}/native/src/setting/" ] - + deps = [ "${powermgr_inner_api}:powermgr_client", "${powermgr_inner_api}:powermgr_stub", @@ -1705,7 +1648,7 @@ ohos_unittest("test_power_config_parse") { "${powermgr_utils_path}/setting:power_setting", "${powermgr_utils_path}/vibrator:power_vibrator", ] - + external_deps = [ "ability_base:zuri", "ability_runtime:ability_manager", @@ -1716,16 +1659,16 @@ ohos_unittest("test_power_config_parse") { "samgr:samgr_proxy", ] external_deps += deps_ex - + if (power_manager_feature_doubleclick) { defines += [ "POWER_DOUBLECLICK_ENABLE" ] } - + if (power_manager_feature_pickup) { defines += [ "POWER_PICKUP_ENABLE" ] } } - + ##############################test_power_config_parse_two.############################# ohos_unittest("test_power_config_parse_two") { module_out_path = module_output_path @@ -1741,20 +1684,20 @@ ohos_unittest("test_power_config_parse_two") { "-Dprivate=public", "-Dprotected=public", ] - + sources = [ "src/power_config_parse_test_two.cpp", ] - + configs = [ "${powermgr_utils_path}:utils_config", ":module_private_config", ":module_mock_private_config", "${powermgr_utils_path}:coverage_flags", ] - + include_dirs = [ "${powermgr_service_path}/native/src/setting/" ] - + deps = [ "${powermgr_inner_api}:powermgr_client", "${powermgr_inner_api}:powermgr_stub", @@ -1763,7 +1706,7 @@ ohos_unittest("test_power_config_parse_two") { "${powermgr_utils_path}/setting:power_setting", "${powermgr_utils_path}/vibrator:power_vibrator", ] - + external_deps = [ "ability_base:zuri", "ability_runtime:ability_manager", @@ -1774,20 +1717,16 @@ ohos_unittest("test_power_config_parse_two") { "samgr:samgr_proxy", ] external_deps += deps_ex - + if (power_manager_feature_doubleclick) { defines += [ "POWER_DOUBLECLICK_ENABLE" ] } - + if (power_manager_feature_pickup) { defines += [ "POWER_PICKUP_ENABLE" ] } } -if (power_manager_feature_surport_takeover_suspend) { - defines += [ "POWER_MANAGER_TAKEOVER_SUSPEND" ] -} - group("unittest") { testonly = true deps = [ @@ -1837,12 +1776,6 @@ group("unittest") { ":test_running_lock_scenario", ":test_running_lock_timer_handler", ] - if (power_manager_feature_surport_takeover_suspend) { - deps += [ - ":test_power_mgr_service_ipc_adapter", - ":test_power_suspend_takeover", - ] - } if (has_display_manager_part) { deps += [ ":test_device_state_action_native" ] } diff --git a/test/unittest/include/interface_test/power_mgr_client_test.h b/test/unittest/include/interface_test/power_mgr_client_test.h index 7234690e8eb7da5fa29d53e60431347bba207faa..455991a9099a0ddfa587b2846b485d0539c35361 100644 --- a/test/unittest/include/interface_test/power_mgr_client_test.h +++ b/test/unittest/include/interface_test/power_mgr_client_test.h @@ -43,6 +43,7 @@ constexpr uint32_t TRANSFER_NS_TO_MS = 1000000; constexpr uint32_t TRANSFER_MS_TO_S = 1000; constexpr float DIM_RATE = 0.8; constexpr uint32_t DOUBLE_TIMES = 2; +constexpr uint32_t SCREEN_OFF_SLEEP_TIME_S = 5; class PowerMgrClientTest : public testing::Test { }; diff --git a/test/unittest/include/interface_test/power_mgr_service_ipc_adapter_test.h b/test/unittest/include/interface_test/power_mgr_service_ipc_adapter_test.h deleted file mode 100644 index 8c59306033d9284657b4dfcbf1c4f2fbfe3f1a3c..0000000000000000000000000000000000000000 --- a/test/unittest/include/interface_test/power_mgr_service_ipc_adapter_test.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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. - */ - -#ifndef POWER_MGR_SERVICE_IPC_ADAPTER_TEST_H -#define POWER_MGR_SERVICE_IPC_ADAPTER_TEST_H - -#include - -namespace OHOS { -namespace PowerMgr { - -class PowerMgrServiceIpcAdapterTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); -}; -} // namespace PowerMgr -} // namespace OHOS - -#endif // POWER_MGR_SERVICE_IPC_ADAPTER_TEST_H \ No newline at end of file diff --git a/test/unittest/include/interface_test/suspend_takeover_client_test.h b/test/unittest/include/interface_test/suspend_takeover_client_test.h deleted file mode 100644 index ca286ae22d48a26087d9be802a8255c96cdda9c5..0000000000000000000000000000000000000000 --- a/test/unittest/include/interface_test/suspend_takeover_client_test.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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. - */ - -#ifndef POWERMGR_SUSPEND_TAKEOVER_TEST_H -#define POWERMGR_SUSPEND_TAKEOVER_TEST_H - -#include "takeover_suspend_callback_stub.h" -#include - -namespace OHOS { -namespace PowerMgr { -namespace UnitTest { -class SuspendTakeoverTest : public testing::Test { -public: - class TakeOverSuspendCallback : public TakeOverSuspendCallbackStub { - public: - ~TakeOverSuspendCallback() override = default; - bool OnTakeOverSuspend(SuspendDeviceType type) override; - }; -protected: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp() override; - void TearDown() override; -}; -} // namespace UnitTest -} // namespace PowerMgr -} // namespace OHOS - -#endif // POWERMGR_SUSPEND_TAKEOVER_TEST_H \ No newline at end of file diff --git a/test/unittest/include/mock_power_mgr_client.h b/test/unittest/include/mock_power_mgr_client.h deleted file mode 100644 index 1c5b31e10cb8e980b72788cf64d5bda6366b9502..0000000000000000000000000000000000000000 --- a/test/unittest/include/mock_power_mgr_client.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * 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. - */ - -#ifndef MOCK_POWER_MGR_CLIENT_H -#define MOCK_POWER_MGR_CLIENT_H - -#include "power_mgr_client.h" - -namespace OHOS { -namespace PowerMgr { -class MockPowerMgrClient { -public: - PowerErrors WakeupDevice(WakeupDeviceType reason = WakeupDeviceType::WAKEUP_DEVICE_APPLICATION, - const std::string& detail = std::string("app call")) - { - if (static_cast(reason) <= static_cast(WakeupDeviceType::WAKEUP_DEVICE_UNKNOWN) || - static_cast(reason) >= static_cast(WakeupDeviceType::WAKEUP_DEVICE_MAX)) { - state_ = false; - return PowerErrors::ERR_OK; - } - if (detail == "pre_bright") { - state_ = false; - } else if (detail == "pre_bright_auth_success") { - state_ = true; - } else if (detail == "pre_bright_auth_fail_screen_off") { - state_ = false; - } else if (detail == "pre_bright_auth_fail_screen_on") { - state_ = false; - } else { - state_ = true; - } - return PowerMgrClient::GetInstance().WakeupDevice(reason, detail); - } - - bool IsForceSleeping() - { - return PowerMgrClient::GetInstance().IsForceSleeping(); - } - - PowerErrors ForceSuspendDevice() - { - state_ = false; - PowerErrors ret = PowerMgrClient::GetInstance().ForceSuspendDevice(); - return ret; - } - - PowerErrors SuspendDevice() - { - state_ = false; - return PowerMgrClient::GetInstance().SuspendDevice(); - } - - PowerErrors OverrideScreenOffTime(int64_t timeout) - { - return PowerMgrClient::GetInstance().OverrideScreenOffTime(timeout); - } - - PowerErrors RestoreScreenOffTime() - { - return PowerMgrClient::GetInstance().RestoreScreenOffTime(); - } - - bool IsScreenOn() - { - return state_; - } - - static MockPowerMgrClient& GetInstance() - { - static MockPowerMgrClient instance; - return static_cast(instance); - } -private: - bool state_; -}; -} // PowerMgr -} // OHOS -#endif // MOCK_POWER_MGR_CLIENT_H \ No newline at end of file diff --git a/test/unittest/include/servicetest/powermgr_service_native_test.h b/test/unittest/include/servicetest/powermgr_service_native_test.h index 969b952dd70295cd48eeccd67b6f0ffb08161d48..c5e06591b5eba064b9a51539e5177f807006acab 100644 --- a/test/unittest/include/servicetest/powermgr_service_native_test.h +++ b/test/unittest/include/servicetest/powermgr_service_native_test.h @@ -23,7 +23,6 @@ #include "power_state_callback_stub.h" #include "screen_off_pre_callback_stub.h" #include "power_runninglock_callback_stub.h" -#include "suspend/itake_over_suspend_callback.h" namespace OHOS { namespace PowerMgr { diff --git a/test/unittest/include/servicetest/powermgr_service_test_proxy.h b/test/unittest/include/servicetest/powermgr_service_test_proxy.h index 01ff19ca7af6fdcc604c4e60c9866a074159d75e..0aa93d2d8bf647da6f8bbe4372c32051fb482c18 100644 --- a/test/unittest/include/servicetest/powermgr_service_test_proxy.h +++ b/test/unittest/include/servicetest/powermgr_service_test_proxy.h @@ -75,8 +75,6 @@ public: int32_t UnRegisterScreenStateCallbackIpc(const sptr& callback); int32_t RegisterRunningLockCallbackIpc(const sptr& callback); int32_t UnRegisterRunningLockCallbackIpc(const sptr& callback); - bool RegisterSuspendTakeoverCallbackIpc(const sptr& callback); - bool UnRegisterSuspendTakeoverCallbackIpc(const sptr& callback); int32_t SetDisplaySuspendIpc(bool enable); int32_t SetDeviceModeIpc(int32_t modeValue, int32_t& powerError); int32_t GetDeviceModeIpc(int32_t& powerMode); diff --git a/test/unittest/src/device_power_action_test.cpp b/test/unittest/src/device_power_action_test.cpp index 232e941f807f38f070b0615559aac86cae259b95..2feb7bcb1a903679b93fe9123026baef5044ad8b 100644 --- a/test/unittest/src/device_power_action_test.cpp +++ b/test/unittest/src/device_power_action_test.cpp @@ -27,7 +27,6 @@ using namespace ext; using namespace OHOS; using namespace PowerMgr; namespace { -int g_retval = 0; bool g_invoked = false; std::string g_cmdResult; } // namespace @@ -41,7 +40,7 @@ int DoRebootExt(const char* mode, const char* option) int HookMgrExecute(HOOK_MGR* hookMgr, int stage, void* context, const HOOK_EXEC_OPTIONS* options) { g_invoked = true; - return g_retval; + return 0; } class DevicePowerActionTest : public DevicePowerAction, public Test {}; @@ -51,11 +50,10 @@ HWTEST_F(DevicePowerActionTest, DevicePowerActionTest001, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "DevicePowerActionTest001 start!"); g_cmdResult.clear(); - g_retval = 0; g_invoked = false; Reboot(""); EXPECT_TRUE(g_invoked); - EXPECT_EQ(g_cmdResult, "invalid_cmd"); + EXPECT_EQ(g_cmdResult, ""); POWER_HILOGI(LABEL_TEST, "DevicePowerActionTest001 end!"); } @@ -63,11 +61,10 @@ HWTEST_F(DevicePowerActionTest, DevicePowerActionTest002, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "DevicePowerActionTest002 start!"); g_cmdResult.clear(); - g_retval = -1; g_invoked = false; - Reboot(""); + Reboot("updater"); EXPECT_TRUE(g_invoked); - EXPECT_EQ(g_cmdResult, ""); + EXPECT_EQ(g_cmdResult, "updater"); POWER_HILOGI(LABEL_TEST, "DevicePowerActionTest002 end!"); } @@ -75,20 +72,8 @@ HWTEST_F(DevicePowerActionTest, DevicePowerActionTest003, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "DevicePowerActionTest003 start!"); g_cmdResult.clear(); - g_retval = -1; - g_invoked = false; - Reboot("updater"); - EXPECT_TRUE(g_invoked); - EXPECT_EQ(g_cmdResult, "updater"); - POWER_HILOGI(LABEL_TEST, "DevicePowerActionTest003 end!"); -} - -HWTEST_F(DevicePowerActionTest, DevicePowerActionTest004, TestSize.Level0) -{ - POWER_HILOGI(LABEL_TEST, "DevicePowerActionTest004 start!"); - g_cmdResult.clear(); Shutdown(""); EXPECT_EQ(g_cmdResult, "shutdown"); - POWER_HILOGI(LABEL_TEST, "DevicePowerActionTest004 end!"); + POWER_HILOGI(LABEL_TEST, "DevicePowerActionTest003 end!"); } } // namespace \ No newline at end of file diff --git a/test/unittest/src/interface_test/power_key_option_test.cpp b/test/unittest/src/interface_test/power_key_option_test.cpp index 4191e946a9426b41fced1fe9ce76ab1b251f8c07..0c731714ab9c8302998cbd5325c69336f53396e6 100644 --- a/test/unittest/src/interface_test/power_key_option_test.cpp +++ b/test/unittest/src/interface_test/power_key_option_test.cpp @@ -24,7 +24,7 @@ using namespace OHOS::PowerMgr; using namespace OHOS; using namespace std; static sptr g_service; -static constexpr int SLEEP_WAIT_TIME_S = 2; +static constexpr int SLEEP_WAIT_TIME_US = 500000; void PowerKeyOptionTest::SetUpTestCase(void) { @@ -39,9 +39,9 @@ void PowerKeyOptionTest::TearDownTestCase(void) } #ifdef HAS_MULTIMODALINPUT_INPUT_PART -std::function)> callbackPowerWake_; -std::function)> callbackPowerSuspend_; -std::function)> callbackTp_; +std::function)> callbackPowerWake_ = nullptr; +std::function)> callbackPowerSuspend_ = nullptr; +std::function)> callbackTp_ = nullptr; int32_t MMI::InputManager::SubscribeKeyEvent(std::shared_ptr keyOption, std::function)> callback) @@ -76,31 +76,31 @@ HWTEST_F(PowerKeyOptionTest, PowerKeyOptionTest001, TestSize.Level0) g_service->SuspendDevice( static_cast(time(nullptr)), SuspendDeviceType::SUSPEND_DEVICE_REASON_APPLICATION, false); EXPECT_FALSE(g_service->IsScreenOn()); - - std::shared_ptr keyEventPowerkeyDown = MMI::KeyEvent::Create(); - keyEventPowerkeyDown->SetKeyAction(MMI::KeyEvent::KEY_ACTION_DOWN); - keyEventPowerkeyDown->SetKeyCode(MMI::KeyEvent::KEYCODE_POWER); - std::shared_ptr keyEventPowerkeyUp = MMI::KeyEvent::Create(); - keyEventPowerkeyUp->SetKeyAction(MMI::KeyEvent::KEY_ACTION_UP); - keyEventPowerkeyUp->SetKeyCode(MMI::KeyEvent::KEYCODE_POWER); - - EXPECT_NE(callbackPowerWake_, nullptr); - callbackPowerWake_(keyEventPowerkeyDown); - callbackPowerWake_(keyEventPowerkeyUp); - callbackPowerWake_(keyEventPowerkeyDown); - callbackPowerWake_(keyEventPowerkeyUp); - EXPECT_TRUE(g_service->IsScreenOn()); - - std::shared_ptr wakeupController = g_service->GetWakeupController(); - std::shared_ptr suspendController = g_service->GetSuspendController(); - EXPECT_NE(wakeupController, nullptr); - EXPECT_NE(suspendController, nullptr); - wakeupController->monitorMap_.clear(); - suspendController->monitorMap_.clear(); - callbackPowerWake_(keyEventPowerkeyDown); - callbackPowerWake_(keyEventPowerkeyUp); - callbackPowerWake_(keyEventPowerkeyDown); - callbackPowerWake_(keyEventPowerkeyUp); + if (callbackPowerWake_ != nullptr) { + std::shared_ptr keyEventPowerkeyDown = MMI::KeyEvent::Create(); + keyEventPowerkeyDown->SetKeyAction(MMI::KeyEvent::KEY_ACTION_DOWN); + keyEventPowerkeyDown->SetKeyCode(MMI::KeyEvent::KEYCODE_POWER); + std::shared_ptr keyEventPowerkeyUp = MMI::KeyEvent::Create(); + keyEventPowerkeyUp->SetKeyAction(MMI::KeyEvent::KEY_ACTION_UP); + keyEventPowerkeyUp->SetKeyCode(MMI::KeyEvent::KEYCODE_POWER); + + callbackPowerWake_(keyEventPowerkeyDown); + callbackPowerWake_(keyEventPowerkeyUp); + callbackPowerWake_(keyEventPowerkeyDown); + callbackPowerWake_(keyEventPowerkeyUp); + EXPECT_TRUE(g_service->IsScreenOn()); + + std::shared_ptr wakeupController = g_service->GetWakeupController(); + std::shared_ptr suspendController = g_service->GetSuspendController(); + EXPECT_NE(wakeupController, nullptr); + EXPECT_NE(suspendController, nullptr); + wakeupController->monitorMap_.clear(); + suspendController->monitorMap_.clear(); + callbackPowerWake_(keyEventPowerkeyDown); + callbackPowerWake_(keyEventPowerkeyUp); + callbackPowerWake_(keyEventPowerkeyDown); + callbackPowerWake_(keyEventPowerkeyUp); + } GTEST_LOG_(INFO) << "PowerKeyOptionTest001: end"; POWER_HILOGI(LABEL_TEST, "PowerKeyOptionTest001 function end!"); } @@ -121,28 +121,28 @@ HWTEST_F(PowerKeyOptionTest, PowerKeyOptionTest002, TestSize.Level0) g_service->WakeupDevice( static_cast(time(nullptr)), WakeupDeviceType::WAKEUP_DEVICE_PLUG_CHANGE, "plug change"); EXPECT_TRUE(g_service->IsScreenOn()); - - std::shared_ptr keyEventPowerkeyDown = MMI::KeyEvent::Create(); - keyEventPowerkeyDown->SetKeyAction(MMI::KeyEvent::KEY_ACTION_DOWN); - keyEventPowerkeyDown->SetKeyCode(MMI::KeyEvent::KEYCODE_POWER); - std::shared_ptr keyEventPowerkeyUp = MMI::KeyEvent::Create(); - keyEventPowerkeyUp->SetKeyAction(MMI::KeyEvent::KEY_ACTION_UP); - keyEventPowerkeyUp->SetKeyCode(MMI::KeyEvent::KEYCODE_POWER); - - EXPECT_NE(callbackPowerSuspend_, nullptr); - callbackPowerSuspend_(keyEventPowerkeyDown); - callbackPowerSuspend_(keyEventPowerkeyUp); - sleep(SLEEP_WAIT_TIME_S); - EXPECT_FALSE(g_service->IsScreenOn()); - - std::shared_ptr wakeupController = g_service->GetWakeupController(); - std::shared_ptr suspendController = g_service->GetSuspendController(); - EXPECT_NE(wakeupController, nullptr); - EXPECT_NE(suspendController, nullptr); - wakeupController->monitorMap_.clear(); - suspendController->monitorMap_.clear(); - callbackPowerSuspend_(keyEventPowerkeyDown); - callbackPowerSuspend_(keyEventPowerkeyUp); + if (callbackPowerSuspend_ != nullptr) { + std::shared_ptr keyEventPowerkeyDown = MMI::KeyEvent::Create(); + keyEventPowerkeyDown->SetKeyAction(MMI::KeyEvent::KEY_ACTION_DOWN); + keyEventPowerkeyDown->SetKeyCode(MMI::KeyEvent::KEYCODE_POWER); + std::shared_ptr keyEventPowerkeyUp = MMI::KeyEvent::Create(); + keyEventPowerkeyUp->SetKeyAction(MMI::KeyEvent::KEY_ACTION_UP); + keyEventPowerkeyUp->SetKeyCode(MMI::KeyEvent::KEYCODE_POWER); + + callbackPowerSuspend_(keyEventPowerkeyDown); + callbackPowerSuspend_(keyEventPowerkeyUp); + usleep(SLEEP_WAIT_TIME_US); + EXPECT_FALSE(g_service->IsFoldScreenOn()); + + std::shared_ptr wakeupController = g_service->GetWakeupController(); + std::shared_ptr suspendController = g_service->GetSuspendController(); + EXPECT_NE(wakeupController, nullptr); + EXPECT_NE(suspendController, nullptr); + wakeupController->monitorMap_.clear(); + suspendController->monitorMap_.clear(); + callbackPowerSuspend_(keyEventPowerkeyDown); + callbackPowerSuspend_(keyEventPowerkeyUp); + } GTEST_LOG_(INFO) << "PowerKeyOptionTest002: end"; POWER_HILOGI(LABEL_TEST, "PowerKeyOptionTest002 function end!"); } @@ -163,22 +163,22 @@ HWTEST_F(PowerKeyOptionTest, PowerKeyOptionTest003, TestSize.Level0) g_service->WakeupDevice( static_cast(time(nullptr)), WakeupDeviceType::WAKEUP_DEVICE_PLUG_CHANGE, "plug change"); EXPECT_TRUE(g_service->IsScreenOn()); - - std::shared_ptr keyEventTPCover = MMI::KeyEvent::Create(); - keyEventTPCover->SetKeyCode(MMI::KeyEvent::KEYCODE_SLEEP); - - EXPECT_NE(callbackTp_, nullptr); - callbackTp_(keyEventTPCover); - sleep(SLEEP_WAIT_TIME_S); - EXPECT_FALSE(g_service->IsScreenOn()); - - std::shared_ptr wakeupController = g_service->GetWakeupController(); - std::shared_ptr suspendController = g_service->GetSuspendController(); - EXPECT_NE(wakeupController, nullptr); - EXPECT_NE(suspendController, nullptr); - wakeupController->monitorMap_.clear(); - suspendController->monitorMap_.clear(); - callbackTp_(keyEventTPCover); + if (callbackTp_ != nullptr) { + std::shared_ptr keyEventTPCover = MMI::KeyEvent::Create(); + keyEventTPCover->SetKeyCode(MMI::KeyEvent::KEYCODE_SLEEP); + + callbackTp_(keyEventTPCover); + usleep(SLEEP_WAIT_TIME_US); + EXPECT_FALSE(g_service->IsFoldScreenOn()); + + std::shared_ptr wakeupController = g_service->GetWakeupController(); + std::shared_ptr suspendController = g_service->GetSuspendController(); + EXPECT_NE(wakeupController, nullptr); + EXPECT_NE(suspendController, nullptr); + wakeupController->monitorMap_.clear(); + suspendController->monitorMap_.clear(); + callbackTp_(keyEventTPCover); + } GTEST_LOG_(INFO) << "PowerKeyOptionTest003: end"; POWER_HILOGI(LABEL_TEST, "PowerKeyOptionTest003 function end!"); } diff --git a/test/unittest/src/interface_test/power_mgr_client_test.cpp b/test/unittest/src/interface_test/power_mgr_client_test.cpp index 9191d767cb18d64ec8a9dd4eccda7fc48e365c2c..a3a8a5f6353db700d2eaf4191533e4c9a7c7e1ef 100644 --- a/test/unittest/src/interface_test/power_mgr_client_test.cpp +++ b/test/unittest/src/interface_test/power_mgr_client_test.cpp @@ -30,9 +30,6 @@ #include "power_mgr_service.h" #include "power_state_machine.h" #include "running_lock_token_stub.h" -#include "mock_power_mgr_client.h" -#include "mock_power_remote_object.h" -#include "takeover_suspend_callback_proxy.h" using namespace testing::ext; using namespace OHOS::PowerMgr; @@ -232,6 +229,7 @@ HWTEST_F(PowerMgrClientTest, PowerMgrClient007, TestSize.Level2) EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient007: Prepare Fail, Screen is OFF."; powerMgrClient.RefreshActivity(abnormaltype); usleep(SCREEN_OFF_WAIT_TIME_S * TRANSFER_NS_TO_MS / PARM_TWO + WAIT_SUSPEND_TIME_MS * TRANSFER_MS_TO_S); + sleep(SCREEN_OFF_SLEEP_TIME_S); EXPECT_EQ(powerMgrClient.IsScreenOn(), false) << "PowerMgrClient007: RefreshActivity Device Fail, Screen is OFF"; powerMgrClient.OverrideScreenOffTime(PowerStateMachine::DEFAULT_SLEEP_TIME_MS); POWER_HILOGI(LABEL_TEST, "PowerMgrClient007 function end!"); @@ -279,7 +277,7 @@ HWTEST_F(PowerMgrClientTest, PowerMgrClient009, TestSize.Level0) int32_t PARM_ONE = 1; int32_t wakeupReason = (static_cast(WakeupDeviceType::WAKEUP_DEVICE_MAX)) + PARM_ONE; WakeupDeviceType abnormaltype = WakeupDeviceType(wakeupReason); - auto& powerMgrClient = MockPowerMgrClient::GetInstance(); + auto& powerMgrClient = PowerMgrClient::GetInstance(); powerMgrClient.WakeupDevice(); // Suspend Device before test @@ -1461,52 +1459,4 @@ HWTEST_F(PowerMgrClientTest, PowerMgrClient058, TestSize.Level2) powerMgrClient.OverrideScreenOffTime(PowerStateMachine::DEFAULT_SLEEP_TIME_MS); POWER_HILOGI(LABEL_TEST, "PowerMgrClient058 function end!"); } - -#ifdef POWER_MANAGER_TAKEOVER_SUSPEND -class TestTakeOverSuspendCallback : public ITakeOverSuspendCallback { - public: - TestTakeOverSuspendCallback() = default; - virtual ~TestTakeOverSuspendCallback() = default; - - bool OnTakeOverSuspend(SuspendDeviceType type) override - { - return false; - } - sptr AsObject() override - { - return nullptr; - } -}; - -/** - * @tc.name: PowerMgrClient059 - * @tc.desc: test RegisterSuspendTakeoverCallback - * @tc.type: FUNC - */ -HWTEST_F(PowerMgrClientTest, PowerMgrClient059, TestSize.Level0) { - POWER_HILOGI(LABEL_TEST, "PowerMgrClient059 function start!"); - auto& powerMgrClinet = PowerMgrClient::GetInstance(); - sptr callback = new TestTakeOverSuspendCallback(); - TakeOverSuspendPriority priority = TakeOverSuspendPriority::LOW; - powerMgrClinet.RegisterSuspendTakeoverCallback(callback, priority); - POWER_HILOGI(LABEL_TEST, "PowerMgrClient059 function end!"); -} - -/** - * @tc.name: PowerMgrClient060 - * @tc.desc: test UnRegisterSuspendTakeoverCallback - * @tc.type: FUNC - */ -HWTEST_F(PowerMgrClientTest, PowerMgrClient060, TestSize.Level0) { - POWER_HILOGI(LABEL_TEST, "PowerMgrClient060 function start!"); - auto& powerMgrClinet = PowerMgrClient::GetInstance(); - sptr callback = new TestTakeOverSuspendCallback(); - TakeOverSuspendPriority priority = TakeOverSuspendPriority::HIGH; - // first register callback - powerMgrClinet.RegisterSuspendTakeoverCallback(callback, priority); - // then test unregister callback - powerMgrClinet.UnRegisterSuspendTakeoverCallback(callback); - POWER_HILOGI(LABEL_TEST, "PowerMgrClient060 function end!"); -} -#endif } // namespace \ No newline at end of file diff --git a/test/unittest/src/interface_test/power_mgr_service_ipc_adapter_test.cpp b/test/unittest/src/interface_test/power_mgr_service_ipc_adapter_test.cpp deleted file mode 100644 index 16780a9c8b4feaf4e7a0ca5816b327eaf17d6bc3..0000000000000000000000000000000000000000 --- a/test/unittest/src/interface_test/power_mgr_service_ipc_adapter_test.cpp +++ /dev/null @@ -1,301 +0,0 @@ -/* - * 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 "power_mgr_service_ipc_adapter_test.h" -#include "ipower_mgr.h" -#include "iremote_object.h" -#include "power_log.h" -#include "power_mgr_service_ipc_adapter.h" -#include "power_mgr_stub.h" -#include "sp_singleton.h" - -using namespace testing::ext; -using namespace OHOS::PowerMgr; -using namespace OHOS; - -class TestPowerMgrServiceAdapter : public PowerMgrServiceAdapter { -public: - PowerErrors RebootDevice(const std::string& reason) - { - return PowerErrors::ERR_OK; - } - PowerErrors RebootDeviceForDeprecated(const std::string& reason) - { - return PowerErrors::ERR_OK; - } - PowerErrors ShutDownDevice(const std::string& reason) - { - return PowerErrors::ERR_OK; - } - PowerErrors SetSuspendTag(const std::string& tag) - { - return PowerErrors::ERR_OK; - } - PowerErrors SuspendDevice( - int64_t callTimeMs, SuspendDeviceType reason, bool suspendImmed, const std::string& apiVersion = "-1") - { - return PowerErrors::ERR_OK; - } - PowerErrors WakeupDevice( - int64_t callTimeMs, WakeupDeviceType reason, const std::string& details, const std::string& apiVersion = "-1") - { - return PowerErrors::ERR_OK; - } - void WakeupDeviceAsync(int64_t callTimeMs, WakeupDeviceType reason, const std::string& details) {} - bool RefreshActivity(int64_t callTimeMs, UserActivityType type, bool needChangeBacklight) - { - return true; - } - PowerErrors OverrideScreenOffTime(int64_t timeout, const std::string& apiVersion = "-1") - { - return PowerErrors::ERR_OK; - } - PowerErrors RestoreScreenOffTime(const std::string& apiVersion = "-1") - { - return PowerErrors::ERR_OK; - } - PowerState GetState() - { - return PowerState::AWAKE; - } - bool IsScreenOn(bool needPrintLog = true) - { - return true; - } - bool IsFoldScreenOn() - { - return true; - } - bool IsCollaborationScreenOn() - { - return true; - } - bool IsForceSleeping() - { - return true; - } - PowerErrors ForceSuspendDevice(int64_t callTimeMs, const std::string& apiVersion = "-1") - { - return PowerErrors::ERR_OK; - } - PowerErrors Hibernate(bool clearMemory, const std::string& reason = "", const std::string& apiVersion = "-1") - { - return PowerErrors::ERR_OK; - } - PowerErrors CreateRunningLock(const sptr& remoteObj, const RunningLockInfo& runningLockInfo) - { - return PowerErrors::ERR_OK; - } - bool ReleaseRunningLock(const sptr& remoteObj, const std::string& name = "") - { - return true; - } - bool IsRunningLockTypeSupported(RunningLockType type) - { - return true; - } - bool UpdateWorkSource(const sptr& remoteObj, const std::vector& workSources) - { - return true; - } - PowerErrors Lock(const sptr& remoteObj, int32_t timeOutMs = -1) - { - return PowerErrors::ERR_OK; - } - PowerErrors UnLock(const sptr& remoteObj, const std::string& name = "") - { - return PowerErrors::ERR_OK; - } - bool QueryRunningLockLists(std::map& runningLockLists) - { - return true; - } - bool IsUsed(const sptr& remoteObj) - { - return true; - } - bool ProxyRunningLock(bool isProxied, pid_t pid, pid_t uid) - { - return true; - } - bool ProxyRunningLocks(bool isProxied, const std::vector>& processInfos) - { - return true; - } - bool ResetRunningLocks() - { - return true; - } - bool RegisterPowerStateCallback(const sptr& callback, bool isSync = true) - { - return true; - } - bool UnRegisterPowerStateCallback(const sptr& callback) - { - return true; - } - - bool RegisterSyncSleepCallback(const sptr& callback, SleepPriority priority) - { - return true; - } - bool UnRegisterSyncSleepCallback(const sptr& callback) - { - return true; - } - bool RegisterSyncHibernateCallback(const sptr& callback) - { - return true; - } - bool UnRegisterSyncHibernateCallback(const sptr& callback) - { - return true; - } - bool RegisterPowerModeCallback(const sptr& callback) - { - return true; - } - bool UnRegisterPowerModeCallback(const sptr& callback) - { - return true; - } - - bool RegisterScreenStateCallback(int32_t remainTime, const sptr& callback) - { - return true; - } - bool UnRegisterScreenStateCallback(const sptr& callback) - { - return true; - } - - bool RegisterRunningLockCallback(const sptr& callback) - { - return true; - } - bool UnRegisterRunningLockCallback(const sptr& callback) - { - return true; - } - bool SetDisplaySuspend(bool enable) - { - return true; - } - PowerErrors SetDeviceMode(const PowerMode& mode) - { - return PowerErrors::ERR_OK; - } - PowerMode GetDeviceMode() - { - return PowerMode::NORMAL_MODE; - } - std::string ShellDump(const std::vector& args, uint32_t argc) - { - return ""; - } - PowerErrors IsStandby(bool& isStandby) - { - return PowerErrors::ERR_OK; - } - PowerErrors SetForceTimingOut(bool enabled, const sptr& token) - { - return PowerErrors::ERR_OK; - } - PowerErrors LockScreenAfterTimingOut( - bool enabledLockScreen, bool checkLock, bool sendScreenOffEvent, const sptr& token) - { - return PowerErrors::ERR_OK; - } - PowerErrors IsRunningLockEnabled(const RunningLockType type, bool& result) - { - return PowerErrors::ERR_OK; - } - - void RegisterShutdownCallback(const sptr& callback, ShutdownPriority priority) {} - void UnRegisterShutdownCallback(const sptr& callback) {} - - void RegisterShutdownCallback(const sptr& callback, ShutdownPriority priority) {} - void UnRegisterShutdownCallback(const sptr& callback) {} - void RegisterShutdownCallback(const sptr& callback, ShutdownPriority priority) {} - void UnRegisterShutdownCallback(const sptr& callback) {} - bool RegisterSuspendTakeoverCallback( - const sptr& callback, TakeOverSuspendPriority priority) - { - return true; - } - bool UnRegisterSuspendTakeoverCallback(const sptr& callback) - { - return true; - } -}; - -class TestTakeOverSuspendCallback : public ITakeOverSuspendCallback { -public: - TestTakeOverSuspendCallback() = default; - virtual ~TestTakeOverSuspendCallback() = default; - - bool OnTakeOverSuspend(SuspendDeviceType type) override - { - return false; - } - sptr AsObject() override - { - return nullptr; - } -}; - -void PowerMgrServiceIpcAdapterTest::SetUpTestCase(void) -{ -} -void PowerMgrServiceIpcAdapterTest::TearDownTestCase(void) {} -void PowerMgrServiceIpcAdapterTest::SetUp() {} -void PowerMgrServiceIpcAdapterTest::TearDown() {} - -namespace { -/** - * @tc.name: PowerMgrServiceIpcAdapter001 - * @tc.desc: test PowerMgrServiceIpcAdapter.RegisterSuspendTakeoverCallbackIpc - * @tc.type: FUNC - */ -HWTEST_F(PowerMgrServiceIpcAdapterTest, PowerMgrServiceIpcAdapter001, TestSize.Level2) { - POWER_HILOGI(LABEL_TEST, "PowerMgrServiceIpcAdapter001 function start!"); - sptr callback = new TestTakeOverSuspendCallback(); - auto adapter = DelayedSpSingleton::GetInstance(); - TakeOverSuspendPriority priority = TakeOverSuspendPriority::HIGH; - int32_t result = adapter->RegisterSuspendTakeoverCallbackIpc(callback, static_cast(priority)); - result = adapter->RegisterSuspendTakeoverCallbackIpc(callback, 10); - EXPECT_EQ(result, -1); - result = adapter->RegisterSuspendTakeoverCallbackIpc(nullptr, static_cast(priority)); - EXPECT_EQ(result, -1); - sptr callback2 = new TestTakeOverSuspendCallback(); - result = adapter->RegisterSuspendTakeoverCallbackIpc(callback2, static_cast(-1)); - POWER_HILOGI(LABEL_TEST, "PowerMgrServiceIpcAdapter001 function end!"); -} - -/** - * @tc.name: PowerMgrServiceIpcAdapter002 - * @tc.desc: test PowerMgrServiceIpcAdapter.UnRegisterSuspendTakeoverCallback - * @tc.type: FUNC - */ -HWTEST_F(PowerMgrServiceIpcAdapterTest, PowerMgrServiceIpcAdapter002, TestSize.Level2) { - POWER_HILOGI(LABEL_TEST, "PowerMgrServiceIpcAdapter002 function start!"); - sptr callback = new TestTakeOverSuspendCallback(); - auto adapter = DelayedSpSingleton::GetInstance(); - adapter->UnRegisterSuspendTakeoverCallbackIpc(callback); - int32_t result = adapter->UnRegisterSuspendTakeoverCallbackIpc(nullptr); - EXPECT_EQ(result, -1); - POWER_HILOGI(LABEL_TEST, "PowerMgrServiceIpcAdapter002 function end!"); -} -} \ No newline at end of file diff --git a/test/unittest/src/interface_test/power_mgr_service_test.cpp b/test/unittest/src/interface_test/power_mgr_service_test.cpp index e29243e24abc2825762c7ec4d1d15179fa24b423..fe5751420c284bd6eba64ab14455bf2ea555d6b0 100644 --- a/test/unittest/src/interface_test/power_mgr_service_test.cpp +++ b/test/unittest/src/interface_test/power_mgr_service_test.cpp @@ -39,7 +39,6 @@ #include "power_utils.h" #include "setting_helper.h" #include "token_setproc.h" -#include "mock_power_mgr_client.h" using namespace testing::ext; using namespace OHOS::PowerMgr; @@ -142,7 +141,7 @@ HWTEST_F (PowerMgrServiceTest, PowerMgrService003, TestSize.Level0) uint32_t PARM_THREE = 3; auto& powerMgrClient = PowerMgrClient::GetInstance(); powerMgrClient.WakeupDevice(); - usleep(50000); + sleep(1); EXPECT_EQ(powerMgrClient.OverrideScreenOffTime(1000), PowerErrors::ERR_OK); sleep(PARM_THREE); EXPECT_EQ(powerMgrClient.IsFoldScreenOn(), false) << "PowerMgrService003: Prepare Fail, Screen is ON."; @@ -190,12 +189,12 @@ HWTEST_F (PowerMgrServiceTest, PowerMgrService005, TestSize.Level0) HWTEST_F (PowerMgrServiceTest, PowerMgrService006, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService006 function start!"); - uint32_t PARM_THREE = 3; + uint32_t PARM_FIVE = 5; auto& powerMgrClient = PowerMgrClient::GetInstance(); powerMgrClient.SuspendDevice(); EXPECT_EQ(powerMgrClient.OverrideScreenOffTime(1000), PowerErrors::ERR_OK); powerMgrClient.WakeupDevice(); - sleep(PARM_THREE); + sleep(PARM_FIVE); EXPECT_EQ(powerMgrClient.IsScreenOn(), false) << "PowerMgrService006: Prepare Fail, Screen is ON."; POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService006 function end!"); } @@ -208,7 +207,7 @@ HWTEST_F (PowerMgrServiceTest, PowerMgrService006, TestSize.Level0) HWTEST_F (PowerMgrServiceTest, PowerMgrService007, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService007 function start!"); - auto& powerMgrClient = MockPowerMgrClient::GetInstance(); + auto& powerMgrClient = PowerMgrClient::GetInstance(); powerMgrClient.SuspendDevice(); EXPECT_FALSE(powerMgrClient.OverrideScreenOffTime(0) == PowerErrors::ERR_OK); powerMgrClient.WakeupDevice(); @@ -225,7 +224,7 @@ HWTEST_F (PowerMgrServiceTest, PowerMgrService007, TestSize.Level0) HWTEST_F (PowerMgrServiceTest, PowerMgrService008, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService008 function start!"); - auto& powerMgrClient = MockPowerMgrClient::GetInstance(); + auto& powerMgrClient = PowerMgrClient::GetInstance(); powerMgrClient.SuspendDevice(); EXPECT_FALSE(powerMgrClient.OverrideScreenOffTime(-1) == PowerErrors::ERR_OK); powerMgrClient.WakeupDevice(); @@ -243,7 +242,7 @@ HWTEST_F (PowerMgrServiceTest, PowerMgrService009, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService009 function start!"); uint32_t PARM_TWO = 2; - auto& powerMgrClient = MockPowerMgrClient::GetInstance(); + auto& powerMgrClient = PowerMgrClient::GetInstance(); powerMgrClient.WakeupDevice(); EXPECT_TRUE(powerMgrClient.OverrideScreenOffTime(1000) == PowerErrors::ERR_OK); EXPECT_TRUE(powerMgrClient.RestoreScreenOffTime() == PowerErrors::ERR_OK); @@ -261,7 +260,7 @@ HWTEST_F (PowerMgrServiceTest, PowerMgrService009, TestSize.Level0) HWTEST_F (PowerMgrServiceTest, PowerMgrService010, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService010 function start!"); - auto& powerMgrClient = MockPowerMgrClient::GetInstance(); + auto& powerMgrClient = PowerMgrClient::GetInstance(); powerMgrClient.WakeupDevice(); EXPECT_FALSE(powerMgrClient.OverrideScreenOffTime(0) == PowerErrors::ERR_OK); EXPECT_FALSE(powerMgrClient.RestoreScreenOffTime() == PowerErrors::ERR_OK); @@ -278,7 +277,7 @@ HWTEST_F (PowerMgrServiceTest, PowerMgrService010, TestSize.Level0) HWTEST_F (PowerMgrServiceTest, PowerMgrService011, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService011 function start!"); - auto& powerMgrClient = MockPowerMgrClient::GetInstance(); + auto& powerMgrClient = PowerMgrClient::GetInstance(); powerMgrClient.WakeupDevice(); EXPECT_FALSE(powerMgrClient.OverrideScreenOffTime(-1) == PowerErrors::ERR_OK);; EXPECT_FALSE(powerMgrClient.RestoreScreenOffTime() == PowerErrors::ERR_OK); @@ -296,7 +295,7 @@ HWTEST_F (PowerMgrServiceTest, PowerMgrService012, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService012 function start!"); uint32_t PARM_TWO = 2; - auto& powerMgrClient = MockPowerMgrClient::GetInstance(); + auto& powerMgrClient = PowerMgrClient::GetInstance(); powerMgrClient.SuspendDevice(); EXPECT_TRUE(powerMgrClient.OverrideScreenOffTime(1000) == PowerErrors::ERR_OK); EXPECT_TRUE(powerMgrClient.RestoreScreenOffTime() == PowerErrors::ERR_OK); @@ -315,7 +314,7 @@ HWTEST_F (PowerMgrServiceTest, PowerMgrService012, TestSize.Level0) HWTEST_F (PowerMgrServiceTest, PowerMgrService013, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService013 function start!"); - auto& powerMgrClient = MockPowerMgrClient::GetInstance(); + auto& powerMgrClient = PowerMgrClient::GetInstance(); powerMgrClient.SuspendDevice(); EXPECT_FALSE(powerMgrClient.OverrideScreenOffTime(0) == PowerErrors::ERR_OK); EXPECT_FALSE(powerMgrClient.RestoreScreenOffTime() == PowerErrors::ERR_OK); @@ -333,7 +332,7 @@ HWTEST_F (PowerMgrServiceTest, PowerMgrService013, TestSize.Level0) HWTEST_F (PowerMgrServiceTest, PowerMgrService014, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService014 function start!"); - auto& powerMgrClient = MockPowerMgrClient::GetInstance(); + auto& powerMgrClient = PowerMgrClient::GetInstance(); powerMgrClient.SuspendDevice(); EXPECT_FALSE(powerMgrClient.OverrideScreenOffTime(-1) == PowerErrors::ERR_OK); EXPECT_FALSE(powerMgrClient.RestoreScreenOffTime() == PowerErrors::ERR_OK); @@ -419,7 +418,7 @@ HWTEST_F (PowerMgrServiceTest, PowerMgrService018, TestSize.Level0) HWTEST_F (PowerMgrServiceTest, PowerMgrService019, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService019 function start!"); - auto& powerMgrClient = MockPowerMgrClient::GetInstance(); + auto& powerMgrClient = PowerMgrClient::GetInstance(); powerMgrClient.SuspendDevice(); EXPECT_EQ(powerMgrClient.IsScreenOn(), false); @@ -439,7 +438,7 @@ HWTEST_F (PowerMgrServiceTest, PowerMgrService019, TestSize.Level0) HWTEST_F (PowerMgrServiceTest, PowerMgrService020, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService020 function start!"); - auto& powerMgrClient = MockPowerMgrClient::GetInstance(); + auto& powerMgrClient = PowerMgrClient::GetInstance(); powerMgrClient.SuspendDevice(); EXPECT_EQ(powerMgrClient.IsScreenOn(), false); @@ -460,7 +459,7 @@ HWTEST_F (PowerMgrServiceTest, PowerMgrService020, TestSize.Level0) HWTEST_F (PowerMgrServiceTest, PowerMgrService021, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService021 function start!"); - auto& powerMgrClient = MockPowerMgrClient::GetInstance(); + auto& powerMgrClient = PowerMgrClient::GetInstance(); powerMgrClient.SuspendDevice(); EXPECT_EQ(powerMgrClient.IsScreenOn(), false); @@ -901,12 +900,12 @@ HWTEST_F(PowerMgrServiceTest, PowerMgrService033, TestSize.Level0) } auto& powerMgrClient = PowerMgrClient::GetInstance(); std::string result = powerMgrClient.Dump(cmdsList); - + POWER_HILOGI(LABEL_TEST, "result : %{public}s", result.c_str()); - EXPECT_EQ(true, result == "remote error"); - POWER_HILOGI(LABEL_TEST, "PowerMgrService032 function end!"); + EXPECT_TRUE(result == "remote error"); + POWER_HILOGI(LABEL_TEST, "PowerMgrService033 function end!"); } - + /** * @tc.name: PowerMgrService034 * @tc.desc: Test Dump. @@ -923,93 +922,9 @@ HWTEST_F(PowerMgrServiceTest, PowerMgrService034, TestSize.Level0) } auto& powerMgrClient = PowerMgrClient::GetInstance(); std::string result = powerMgrClient.Dump(cmdsList); - + POWER_HILOGI(LABEL_TEST, "result : %{public}s", result.c_str()); EXPECT_EQ(true, result.empty()); POWER_HILOGI(LABEL_TEST, "PowerMgrService034 function end!"); } - -#ifdef POWER_MANAGER_TAKEOVER_SUSPEND -class TestTakeOverSuspendCallback : public ITakeOverSuspendCallback { - public: - TestTakeOverSuspendCallback() = default; - virtual ~TestTakeOverSuspendCallback() = default; - - bool OnTakeOverSuspend(SuspendDeviceType type) override - { - return false; - } - sptr AsObject() override - { - return nullptr; - } -}; - -/** - * @tc.name: PowerMgrService035 - * @tc.desc: Test PowerStateMachine::EmplaceInactive() - * @tc.type: FUNC - */ -HWTEST_F(PowerMgrServiceTest, PowerMgrService035, TestSize.Level0) { - POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService035 function start!"); - auto powerMgrService = DelayedSpSingleton::GetInstance(); - std::shared_ptr stateMachine = powerMgrService->GetPowerStateMachine(); - stateMachine->EmplaceInactive(); - POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService035 function end!"); -} - -/** - * @tc.name: PowerMgrService036 - * @tc.desc: Test StateChangeReason Get - * @tc.type: FUNC - */ -HWTEST_F(PowerMgrServiceTest, PowerMgrService036, TestSize.Level0) { - POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService036 function start!"); - auto pmsTest_ = DelayedSpSingleton::GetInstance(); - ASSERT_TRUE(pmsTest_ != nullptr) << "PowerMgrService036 failed to get PowerMgrService"; - auto stateMachine_ = pmsTest_->GetPowerStateMachine(); - ASSERT_TRUE(stateMachine_ != nullptr) << "PowerMgrService036 failed to get PowerStateMachine"; - - stateMachine_->GetSuspendTypeByReason(StateChangeReason::STATE_CHANGE_REASON_TIMEOUT_NO_SCREEN_LOCK); - stateMachine_->GetSuspendTypeByReason(StateChangeReason::STATE_CHANGE_REASON_SYSTEM); - EXPECT_EQ(stateMachine_->GetSuspendTypeByReason(StateChangeReason::STATE_CHANGE_REASON_TIMEOUT), - SuspendDeviceType::SUSPEND_DEVICE_REASON_TIMEOUT); - EXPECT_EQ(stateMachine_->GetSuspendTypeByReason(StateChangeReason::STATE_CHANGE_REASON_TIMEOUT_NO_SCREEN_LOCK), - SuspendDeviceType::SUSPEND_DEVICE_REASON_TIMEOUT); - EXPECT_EQ(stateMachine_->GetSuspendTypeByReason(StateChangeReason::STATE_CHANGE_REASON_HARD_KEY), - SuspendDeviceType::SUSPEND_DEVICE_REASON_POWER_KEY); - EXPECT_EQ(stateMachine_->GetSuspendTypeByReason(StateChangeReason::STATE_CHANGE_REASON_SYSTEM), - SuspendDeviceType::SUSPEND_DEVICE_REASON_FORCE_SUSPEND); - EXPECT_EQ(stateMachine_->GetSuspendTypeByReason(StateChangeReason::STATE_CHANGE_REASON_UNKNOWN), - SuspendDeviceType::SUSPEND_DEVICE_REASON_APPLICATION); - POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService036 function end!"); -} - -/** - * @tc.name: PowerMgrService037 - * @tc.desc: Test RegisterSuspendTakeoverCallback - * @tc.type: FUNC - */ -HWTEST_F(PowerMgrServiceTest, PowerMgrService037, TestSize.Level0) { - POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService037 function start!"); - sptr callback = new TestTakeOverSuspendCallback(); - auto pmsTest_ = DelayedSpSingleton::GetInstance(); - TakeOverSuspendPriority priority = TakeOverSuspendPriority::HIGH; - pmsTest_->RegisterSuspendTakeoverCallback(callback, priority); - POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService037 function end!"); -} - -/** - * @tc.name: PowerMgrService038 - * @tc.desc: Test UnRegisterSuspendTakeoverCallback - * @tc.type: FUNC - */ -HWTEST_F(PowerMgrServiceTest, PowerMgrService038, TestSize.Level0) { - POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService038 function start!"); - sptr callback = new TestTakeOverSuspendCallback(); - auto pmsTest_ = DelayedSpSingleton::GetInstance(); - pmsTest_->UnRegisterSuspendTakeoverCallback(callback); - POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService038 function end!"); -} -#endif } diff --git a/test/unittest/src/interface_test/power_suspend_controller_test.cpp b/test/unittest/src/interface_test/power_suspend_controller_test.cpp index c10e8370f75f44377e46b5fd4fefd15af06d1402..4befc1a3db7a6e42fcc471f667586a8929456125 100644 --- a/test/unittest/src/interface_test/power_suspend_controller_test.cpp +++ b/test/unittest/src/interface_test/power_suspend_controller_test.cpp @@ -32,7 +32,6 @@ #include "power_state_callback_stub.h" #include "power_state_machine.h" #include "setting_helper.h" -#include "power_state_machine_info.h" using namespace testing::ext; using namespace OHOS::PowerMgr; @@ -382,7 +381,6 @@ HWTEST_F(PowerSuspendControllerTest, PowerSuspendControllerTest015, TestSize.Lev #else EXPECT_EQ(g_service->IsForceSleeping(), false); #endif - g_service->WakeupControllerInit(); g_service->wakeupController_->ExecWakeupMonitorByReason(WakeupDeviceType::WAKEUP_DEVICE_DOUBLE_CLICK); sleep(NEXT_WAIT_TIME_S); @@ -416,153 +414,4 @@ HWTEST_F(PowerSuspendControllerTest, PowerSuspendControllerTest016, TestSize.Lev GTEST_LOG_(INFO) << "PowerSuspendControllerTest016: end"; POWER_HILOGI(LABEL_TEST, "PowerSuspendControllerTest016 function end!"); } - -/** - * @tc.name: PowerSuspendControllerTest017 - * @tc.desc: test simulate powerkey event when screenon - * @tc.type: FUNC - */ -HWTEST_F(PowerSuspendControllerTest, PowerSuspendControllerTest017, TestSize.Level0) -{ - POWER_HILOGI(LABEL_TEST, "PowerSuspendControllerTest017 function start!"); - GTEST_LOG_(INFO) << "PowerSuspendControllerTest017: start"; - - g_service->WakeupControllerInit(); - g_service->SuspendControllerInit(); - g_service->WakeupDevice( - static_cast(time(nullptr)), WakeupDeviceType::WAKEUP_DEVICE_PLUG_CHANGE, "plug change"); - EXPECT_TRUE(g_service->IsScreenOn()); - std::shared_ptr suspendController = g_service->GetSuspendController(); - suspendController->monitorMap_.clear(); - - auto inputManager = MMI::InputManager::GetInstance(); - std::shared_ptr keyEventPowerkeyDown = MMI::KeyEvent::Create(); - keyEventPowerkeyDown->SetKeyAction(MMI::KeyEvent::KEY_ACTION_DOWN); - keyEventPowerkeyDown->SetKeyCode(MMI::KeyEvent::KEYCODE_POWER); - std::shared_ptr keyEventPowerkeyUp = MMI::KeyEvent::Create(); - keyEventPowerkeyUp->SetKeyAction(MMI::KeyEvent::KEY_ACTION_UP); - keyEventPowerkeyUp->SetKeyCode(MMI::KeyEvent::KEYCODE_POWER); - - inputManager->SimulateInputEvent(keyEventPowerkeyDown); - inputManager->SimulateInputEvent(keyEventPowerkeyUp); - sleep(2); - EXPECT_FALSE(g_service->IsScreenOn()); - - GTEST_LOG_(INFO) << "PowerSuspendControllerTest017: end"; - POWER_HILOGI(LABEL_TEST, "PowerSuspendControllerTest017 function end!"); -} - -#ifdef POWER_MANAGER_TAKEOVER_SUSPEND -class TestTakeOverSuspendCallback : public ITakeOverSuspendCallback { - public: - TestTakeOverSuspendCallback() = default; - virtual ~TestTakeOverSuspendCallback() = default; - - bool OnTakeOverSuspend(SuspendDeviceType type) override - { - return false; - } - sptr AsObject() override - { - return nullptr; - } -}; - -/** - * @tc.name: PowerSuspendControllerTest018 - * @tc.desc: test add takeover callback - * @tc.type: FUNC - */ -HWTEST_F(PowerSuspendControllerTest, PowerSuspendControllerTest018, TestSize.Level0) -{ - POWER_HILOGI(LABEL_TEST, "PowerSuspendControllerTest018 function start!"); - GTEST_LOG_(INFO) << "PowerSuspendControllerTest018: start"; - sptr callback = new TestTakeOverSuspendCallback(); - g_service->SuspendControllerInit(); - g_service->suspendController_->AddCallback(callback, TakeOverSuspendPriority::DEFAULT); - g_service->suspendController_->RemoveCallback(callback); - EXPECT_TRUE(g_service->suspendController_ != nullptr); - GTEST_LOG_(INFO) << "PowerSuspendControllerTest018: end"; - POWER_HILOGI(LABEL_TEST, "PowerSuspendControllerTest018 function end!"); -} - -/** - * @tc.name: PowerSuspendControllerTest019 - * @tc.desc: cover TriggerTakeOverSuspendCallback & TakeOverSuspendCallbackHolder::FindCallbackPidUid - * & TakeOverSuspendCallbackHolder::AddCallback cases - * @tc.type: FUNC - */ -HWTEST_F(PowerSuspendControllerTest, PowerSuspendControllerTest019, TestSize.Level0) { - POWER_HILOGI(LABEL_TEST, "PowerSuspendControllerTest019 function start!"); - g_service->SuspendControllerInit(); - SuspendDeviceType type = SuspendDeviceType::SUSPEND_DEVICE_REASON_MAX; - sptr callback = new TestTakeOverSuspendCallback(); - g_service->suspendController_->AddCallback(callback, TakeOverSuspendPriority::HIGH); - bool result = g_service->suspendController_->TriggerTakeOverSuspendCallback(type); - - sptr callback2 = new TestTakeOverSuspendCallback(); - g_service->suspendController_->AddCallback(callback2, TakeOverSuspendPriority::LOW); - result = g_service->suspendController_->TriggerTakeOverSuspendCallback(type); - - sptr callback3 = new TestTakeOverSuspendCallback(); - g_service->suspendController_->AddCallback(callback3, TakeOverSuspendPriority::DEFAULT); - result = g_service->suspendController_->TriggerTakeOverSuspendCallback(type); - - sptr callback4 = new TestTakeOverSuspendCallback(); - g_service->suspendController_->AddCallback(callback4, static_cast(3)); - result = g_service->suspendController_->TriggerTakeOverSuspendCallback(type); - - g_service->suspendController_->RemoveCallback(static_cast&>(callback2)); - g_service->suspendController_->TriggerTakeOverSuspendCallback(type); - TakeOverSuspendCallbackHolder holder; - POWER_HILOGI(LABEL_TEST, "PowerSuspendControllerTest019 function end!"); -} - -/** - * @tc.name: PowerSuspendControllerTest020 - * @tc.desc: cover TriggerTakeOverSuspendCallbackInner callback == nullptr case - * @tc.type: FUNC - */ -HWTEST_F(PowerSuspendControllerTest, PowerSuspendControllerTest020, TestSize.Level0) { - POWER_HILOGI(LABEL_TEST, "PowerSuspendControllerTest020 function start!"); - g_service->SuspendControllerInit(); - SuspendDeviceType type = SuspendDeviceType::SUSPEND_DEVICE_REASON_MAX; - sptr callback = nullptr; - g_service->suspendController_->AddCallback(callback, TakeOverSuspendPriority::HIGH); - g_service->suspendController_->TriggerTakeOverSuspendCallback(type); - POWER_HILOGI(LABEL_TEST, "PowerSuspendControllerTest020 function end!"); -} - -/** - * @tc.name: PowerSuspendControllerTest021 - * @tc.desc: cover TriggerTakeOverSuspendCallbackInner {RemoveCallbackPidUid() -> iter == cachedRegister_.end()} case - * @tc.type: FUNC - */ -HWTEST_F(PowerSuspendControllerTest, PowerSuspendControllerTest021, TestSize.Level0) { - POWER_HILOGI(LABEL_TEST, "PowerSuspendControllerTest021 function start!"); - g_service->SuspendControllerInit(); - SuspendDeviceType type = SuspendDeviceType::SUSPEND_DEVICE_REASON_MAX; - sptr callback = new TestTakeOverSuspendCallback(); - g_service->suspendController_->RemoveCallback(static_cast&>(callback)); - g_service->suspendController_->TriggerTakeOverSuspendCallback(type); - POWER_HILOGI(LABEL_TEST, "PowerSuspendControllerTest021 function end!"); -} - -/** - * @tc.name: PowerSuspendControllerTest022 - * @tc.desc: test add takeover callback - * @tc.type: FUNC - */ -HWTEST_F(PowerSuspendControllerTest, PowerSuspendControllerTest022, TestSize.Level0) -{ - POWER_HILOGI(LABEL_TEST, "PowerSuspendControllerTest022 function start!"); - GTEST_LOG_(INFO) << "PowerSuspendControllerTest022: start"; - sptr callback = new TestTakeOverSuspendCallback(); - g_service->SuspendControllerInit(); - g_service->suspendController_->AddCallback(callback, TakeOverSuspendPriority::DEFAULT); - EXPECT_TRUE(g_service->suspendController_ != nullptr); - GTEST_LOG_(INFO) << "PowerSuspendControllerTest022: end"; - POWER_HILOGI(LABEL_TEST, "PowerSuspendControllerTest022 function end!"); -} -#endif } // namespace \ No newline at end of file diff --git a/test/unittest/src/interface_test/running_lock_test.cpp b/test/unittest/src/interface_test/running_lock_test.cpp index e00a37b2e650fabb429ffc5474b27ed4df9640c1..4f4aeaf5c435bc7479253c45a537b0c0deb15d9d 100644 --- a/test/unittest/src/interface_test/running_lock_test.cpp +++ b/test/unittest/src/interface_test/running_lock_test.cpp @@ -74,14 +74,14 @@ HWTEST_F(RunningLockTest, RunningLockTest002, TestSize.Level1) ASSERT_TRUE(runningLock1->IsUsed()) << "runningLock1->IsUsed() != true"; runningLock1->UnLock(); ASSERT_TRUE(!runningLock1->IsUsed()) << "runningLock1->IsUsed() != false"; - POWER_HILOGI(LABEL_TEST, "PowerMgrUnitTest::RunningLockTest002 1"); + POWER_HILOGI(LABEL_TEST, "RunningLockTest002 1"); // lock 50ms runningLock1->Lock(50); usleep(4000); - POWER_HILOGI(LABEL_TEST, "PowerMgrUnitTest::RunningLockTest002 2"); + POWER_HILOGI(LABEL_TEST, "RunningLockTest002 2"); ASSERT_TRUE(runningLock1->IsUsed()) << "runningLock1->IsUsed() != true"; usleep(1000); - POWER_HILOGI(LABEL_TEST, "PowerMgrUnitTest::RunningLockTest002 3"); + POWER_HILOGI(LABEL_TEST, "RunningLockTest002 3"); ASSERT_TRUE(runningLock1->IsUsed()) << "runningLock1->IsUsed() != true"; // wait 100ms usleep(100000); @@ -105,28 +105,28 @@ HWTEST_F(RunningLockTest, RunningLockTest003, TestSize.Level1) // after 8ms unlock runningLock1->Lock(30); runningLock1->Lock(80); - POWER_HILOGI(LABEL_TEST, "PowerMgrUnitTest::RunningLockTest003 1"); + POWER_HILOGI(LABEL_TEST, "RunningLockTest003 1"); usleep(50000); ASSERT_TRUE(runningLock1->IsUsed()) << "runningLock1->IsUsed() != true"; usleep(50000); ASSERT_TRUE(!runningLock1->IsUsed()) << "runningLock1->IsUsed() != false"; // no unlock - POWER_HILOGI(LABEL_TEST, "PowerMgrUnitTest::RunningLockTest003 2"); + POWER_HILOGI(LABEL_TEST, "RunningLockTest003 2"); runningLock1->Lock(2); runningLock1->Lock(3); runningLock1->Lock(); - POWER_HILOGI(LABEL_TEST, "PowerMgrUnitTest::RunningLockTest003 3"); + POWER_HILOGI(LABEL_TEST, "RunningLockTest003 3"); usleep(8000); ASSERT_TRUE(runningLock1->IsUsed()) << "runningLock1->IsUsed() != true"; // after 3ms unlock runningLock1->Lock(30); - POWER_HILOGI(LABEL_TEST, "PowerMgrUnitTest::RunningLockTest003 4"); + POWER_HILOGI(LABEL_TEST, "RunningLockTest003 4"); usleep(50000); ASSERT_TRUE(!runningLock1->IsUsed()) << "runningLock1->IsUsed() != false"; runningLock1->Lock(5); runningLock1->UnLock(); ASSERT_TRUE(!runningLock1->IsUsed()) << "runningLock1->IsUsed() != false"; - POWER_HILOGI(LABEL_TEST, "PowerMgrUnitTest::RunningLockTest003 5"); + POWER_HILOGI(LABEL_TEST, "RunningLockTest003 end"); } POWER_HILOGI(LABEL_TEST, "RunningLockTest003 function end!"); } diff --git a/test/unittest/src/interface_test/suspend_takeover_client_test.cpp b/test/unittest/src/interface_test/suspend_takeover_client_test.cpp deleted file mode 100644 index 934db5a380e5a8c623c7e01c023171d3867d3cea..0000000000000000000000000000000000000000 --- a/test/unittest/src/interface_test/suspend_takeover_client_test.cpp +++ /dev/null @@ -1,198 +0,0 @@ -/* - * 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 "suspend_takeover_client_test.h" - -#include "power_log.h" -#include "power_mgr_client.h" -#include "power_mgr_service.h" -#include "take_over_callback_ipc_interface_code.h" -#include -#include -#include - -namespace OHOS { -namespace PowerMgr { -namespace UnitTest { -namespace { -MessageParcel g_reply; -MessageOption g_option; -bool g_isTakeOverSuspend = false; -} // namespace -using namespace testing::ext; - -void SuspendTakeoverTest::SetUpTestCase() {} - -void SuspendTakeoverTest::TearDownTestCase() {} - -void SuspendTakeoverTest::SetUp() -{ - g_isTakeOverSuspend = false; -} - -void SuspendTakeoverTest::TearDown() {} - -bool SuspendTakeoverTest::TakeOverSuspendCallback::OnTakeOverSuspend(SuspendDeviceType type) -{ - g_isTakeOverSuspend = true; - return true; -} - -/** - * @tc.name: RegisterSuspendCallback001 - * @tc.desc: Test RegisterSuspendCallback - * @tc.type: FUNC - */ -HWTEST_F(SuspendTakeoverTest, RegisterSuspendTakeoverCallback001, TestSize.Level0) -{ - POWER_HILOGI(LABEL_TEST, "RegisterSuspendTakeoverCallback001 function start!"); - auto& client = PowerMgrClient::GetInstance(); - sptr takeOverSuspendCallback = new TakeOverSuspendCallback(); - client.RegisterSuspendTakeoverCallback(takeOverSuspendCallback, TakeOverSuspendPriority::DEFAULT); - client.SuspendDevice(); - EXPECT_TRUE(g_isTakeOverSuspend); - POWER_HILOGI(LABEL_TEST, "RegisterSuspendTakeoverCallback001 function end!"); -} - -/** - * @tc.name: UnRegisterSuspendCallback001 - * @tc.desc: Test UnRegisterSuspendCallback - * @tc.type: FUNC - */ -HWTEST_F(SuspendTakeoverTest, UnRegisterSuspendTakeoverCallback001, TestSize.Level0) -{ - POWER_HILOGI(LABEL_TEST, "UnRegisterSuspendTakeoverCallback001 function start!"); - auto& client = PowerMgrClient::GetInstance(); - sptr takeOverSuspendCallback = new TakeOverSuspendCallback(); - client.RegisterSuspendTakeoverCallback(takeOverSuspendCallback, TakeOverSuspendPriority::DEFAULT); - client.UnRegisterSuspendTakeoverCallback(takeOverSuspendCallback); - client.SuspendDevice(); - EXPECT_TRUE(g_isTakeOverSuspend); - POWER_HILOGI(LABEL_TEST, "UnRegisterSuspendTakeoverCallback001 function end!"); -} - -/** - * @tc.name: TakeOverSuspendCallbackStub001 - * @tc.desc: Test TakeOverSuspendCallbackStub - * @tc.type: FUNC - */ -HWTEST_F(SuspendTakeoverTest, TakeOverSuspendCallbackStub001, TestSize.Level0) -{ - POWER_HILOGI(LABEL_TEST, "TakeOverSuspendCallbackStub001 function start!"); - int32_t code = 0; // CMD_ON_TAKEOVER_SUSPEND - MessageParcel data; - MessageParcel reply; - - TakeOverSuspendCallback takeOverSuspendCallback; - SuspendDeviceType type = SuspendDeviceType::SUSPEND_DEVICE_REASON_POWER_KEY; - data.WriteUint32(static_cast(type)); - data.WriteInterfaceToken(TakeOverSuspendCallback::GetDescriptor()); - int32_t ret = takeOverSuspendCallback.OnRemoteRequest(code, data, reply, g_option); - EXPECT_EQ(ret, ERR_OK); - EXPECT_EQ(reply.ReadBool(), true); - EXPECT_EQ(g_isTakeOverSuspend, true); - bool retVal = takeOverSuspendCallback.TakeOverSuspendCallbackStub::OnTakeOverSuspend( - SuspendDeviceType::SUSPEND_DEVICE_REASON_POWER_KEY); - EXPECT_EQ(retVal, false); - POWER_HILOGI(LABEL_TEST, "TakeOverSuspendCallbackStub001 function end!"); -} - -/** - * @tc.name: TakeOverSuspendCallbackStub002 - * @tc.desc: Test TakeOverSuspendCallbackStub - * @tc.type: FUNC - */ -HWTEST_F(SuspendTakeoverTest, TakeOverSuspendCallbackStub002, TestSize.Level0) -{ - POWER_HILOGI(LABEL_TEST, "TakeOverSuspendCallbackStub002 function start!"); - int32_t code = 2; // error code test - MessageParcel data; - MessageParcel reply; - - TakeOverSuspendCallback takeOverSuspendCallback; - SuspendDeviceType type = SuspendDeviceType::SUSPEND_DEVICE_REASON_FORCE_SUSPEND; - data.WriteInterfaceToken(TakeOverSuspendCallback::GetDescriptor()); - data.WriteUint32(static_cast(type)); - int32_t ret = takeOverSuspendCallback.OnRemoteRequest(code, data, reply, g_option); - EXPECT_EQ(ret, ERR_OK); - EXPECT_EQ(reply.ReadBool(), true); - EXPECT_EQ(g_isTakeOverSuspend, true); - bool retVal = takeOverSuspendCallback.TakeOverSuspendCallbackStub::OnTakeOverSuspend( - SuspendDeviceType::SUSPEND_DEVICE_REASON_FORCE_SUSPEND); - EXPECT_EQ(retVal, false); - POWER_HILOGI(LABEL_TEST, "TakeOverSuspendCallbackStub002 function end!"); -} - -/** - * @tc.name: TakeOverSuspendCallbackStub003 - * @tc.desc: Test TakeOverSuspendCallbackStub::OnTakeOverSuspendCallbackStub - * {descripter != remoteDescripter} case - * @tc.type: FUNC - */ -HWTEST_F(SuspendTakeoverTest, TakeOverSuspendCallbackStub003, TestSize.Level0) -{ - POWER_HILOGI(LABEL_TEST, "TakeOverSuspendCallbackStub003 function start!"); - int32_t code = static_cast(TakeOverSuspendCallbackInterfaceCode::CMD_ON_TAKEOVER_SUSPEND); - MessageParcel data; - MessageParcel reply; - data.WriteUint32(0); - data.WriteInterfaceToken(u"test.interface.token"); - TakeOverSuspendCallback takeOverSuspendCallback; - int32_t ret = takeOverSuspendCallback.OnRemoteRequest(code, data, reply, g_option); - EXPECT_EQ(ret, E_GET_POWER_SERVICE_FAILED); - POWER_HILOGI(LABEL_TEST, "TakeOverSuspendCallbackStub003 function end!"); -} - -/** - * @tc.name: TakeOverSuspendCallbackStub004 - * @tc.desc: Test TakeOverSuspendCallbackStub::OnTakeOverSuspendCallbackStub - * {data.ReadUint32(rawType) == false} case - * @tc.type: FUNC - */ -HWTEST_F(SuspendTakeoverTest, TakeOverSuspendCallbackStub004, TestSize.Level0) -{ - POWER_HILOGI(LABEL_TEST, "TakeOverSuspendCallbackStub004 function start!"); - int32_t code = static_cast(TakeOverSuspendCallbackInterfaceCode::CMD_ON_TAKEOVER_SUSPEND); - MessageParcel data; - MessageParcel reply; - TakeOverSuspendCallback takeOverSuspendCallback; - data.WriteInterfaceToken(TakeOverSuspendCallback::GetDescriptor()); - int32_t ret = takeOverSuspendCallback.OnRemoteRequest(code, data, reply, g_option); - EXPECT_EQ(ret, E_READ_PARCEL_ERROR); - POWER_HILOGI(LABEL_TEST, "TakeOverSuspendCallbackStub004 function end!"); -} - -/** - * @tc.name: TakeOverSuspendCallbackStub005 - * @tc.desc: Test TakeOverSuspendCallbackStub::OnTakeOverSuspendCallbackStub - * {data.ReadUint32(rawType), rawType > max} case - * @tc.type: FUNC - */ -HWTEST_F(SuspendTakeoverTest, TakeOverSuspendCallbackStub005, TestSize.Level0) -{ - POWER_HILOGI(LABEL_TEST, "TakeOverSuspendCallbackStub005 function start!"); - int32_t code = static_cast(TakeOverSuspendCallbackInterfaceCode::CMD_ON_TAKEOVER_SUSPEND); - MessageParcel data; - MessageParcel reply; - TakeOverSuspendCallback takeOverSuspendCallback; - data.WriteInterfaceToken(TakeOverSuspendCallback::GetDescriptor()); - data.WriteUint32(100); - int32_t ret = takeOverSuspendCallback.OnRemoteRequest(code, data, reply, g_option); - EXPECT_EQ(ret, E_READ_PARCEL_ERROR); - POWER_HILOGI(LABEL_TEST, "TakeOverSuspendCallbackStub005 function end!"); -} -} // namespace UnitTest -} // namespace PowerMgr -} // namespace OHOS diff --git a/test/unittest/src/mock/power_mock_object_test.cpp b/test/unittest/src/mock/power_mock_object_test.cpp index 4d67f7e32dfbcfa3ebfea6140fe61f85dd8470d3..9cc1985acb44bac4061ce5f3c86c73cedc377a5b 100644 --- a/test/unittest/src/mock/power_mock_object_test.cpp +++ b/test/unittest/src/mock/power_mock_object_test.cpp @@ -29,7 +29,6 @@ #include "running_lock_info.h" #include "running_lock_token_stub.h" #include "power_mgr_async_reply_stub.h" -#include "takeover_suspend_callback_proxy.h" using namespace testing::ext; using namespace OHOS::PowerMgr; @@ -75,12 +74,6 @@ HWTEST_F(PowerMockObjectTest, PowerMockObjectTest001, TestSize.Level2) std::shared_ptr stateCallbackProxy = std::make_shared(remote); PowerState state = PowerState::AWAKE; stateCallbackProxy->OnPowerStateChanged(state); -#ifdef POWER_MANAGER_TAKEOVER_SUSPEND - std::shared_ptr suspendCallbackProxy = - std::make_shared(remote); - SuspendDeviceType type = SuspendDeviceType::SUSPEND_DEVICE_REASON_POWER_KEY; - suspendCallbackProxy->OnTakeOverSuspend(type); -#endif sptr token = new RunningLockTokenStub(); RunningLockInfo info("test1", RunningLockType::RUNNINGLOCK_SCREEN); sptrProxy->CreateRunningLockIpc(token, info, powerError); diff --git a/test/unittest/src/power_device_mode_test.cpp b/test/unittest/src/power_device_mode_test.cpp index 718388ab902ed755c12ae11df564abb4ac257378..503e462e74dac7137ea12084f88c40d29e969beb 100644 --- a/test/unittest/src/power_device_mode_test.cpp +++ b/test/unittest/src/power_device_mode_test.cpp @@ -109,12 +109,12 @@ HWTEST_F (PowerDeviceModeTest, SetDeviceModeTest001, TestSize.Level2) */ HWTEST_F (PowerDeviceModeTest, GetDeviceModeTest001, TestSize.Level2) { - GTEST_LOG_(INFO) << "GetDeviceModeTest001: GetDeviceMode start."; POWER_HILOGI(LABEL_TEST, "GetDeviceModeTest001 function start!"); PowerMode modeFirst = PowerMode::NORMAL_MODE; PowerMode modeSecond = PowerMode::NORMAL_MODE; PowerMode modeThird = PowerMode::NORMAL_MODE; sleep(SLEEP_WAIT_TIME_S); + GTEST_LOG_(INFO) << "GetDeviceModeTest001: GetDeviceMode start."; auto& powerMgrClient = PowerMgrClient::GetInstance(); modeFirst = powerMgrClient.GetDeviceMode(); @@ -123,6 +123,5 @@ HWTEST_F (PowerDeviceModeTest, GetDeviceModeTest001, TestSize.Level2) EXPECT_EQ(modeSecond, modeThird); powerMgrClient.SetDeviceMode(modeFirst); POWER_HILOGI(LABEL_TEST, "GetDeviceModeTest001 function end!"); - GTEST_LOG_(INFO) << "GetDeviceModeTest001: GetDeviceMode end."; } } \ No newline at end of file diff --git a/test/unittest/src/power_get_mode_test.cpp b/test/unittest/src/power_get_mode_test.cpp index c5ac7bb6be851b586ca77c9e46992fb293ff9857..5c979bbadba5f1b9a22c9118f1f9d548aed2d8ec 100644 --- a/test/unittest/src/power_get_mode_test.cpp +++ b/test/unittest/src/power_get_mode_test.cpp @@ -42,11 +42,11 @@ namespace { */ HWTEST_F (PowerGetModeTest, GetDeviceModeTest001, TestSize.Level1) { - GTEST_LOG_(INFO) << "GetDeviceModeTest001: GetDeviceMode start."; POWER_HILOGI(LABEL_TEST, "GetDeviceModeTest001 function start!"); PowerMode modeFirst; PowerMode modeSecond = PowerMode::NORMAL_MODE; sleep(SLEEP_WAIT_TIME_S); + GTEST_LOG_(INFO) << "GetDeviceModeTest001: GetDeviceMode start."; auto& powerMgrClient = PowerMgrClient::GetInstance(); modeFirst = powerMgrClient.GetDeviceMode(); @@ -54,6 +54,5 @@ HWTEST_F (PowerGetModeTest, GetDeviceModeTest001, TestSize.Level1) EXPECT_EQ(modeSecond, powerMgrClient.GetDeviceMode()); powerMgrClient.SetDeviceMode(modeFirst); POWER_HILOGI(LABEL_TEST, "GetDeviceModeTest001 function end!"); - GTEST_LOG_(INFO) << "GetDeviceModeTest001: GetDeviceMode end."; } } \ No newline at end of file diff --git a/test/unittest/src/power_mgr_client_native_test.cpp b/test/unittest/src/power_mgr_client_native_test.cpp index 0fc7ff12b89780d7bf3abccdae15ac11d6b0e972..bab52b11cb32fd2184ef96b0c1f2199dfdee0128 100644 --- a/test/unittest/src/power_mgr_client_native_test.cpp +++ b/test/unittest/src/power_mgr_client_native_test.cpp @@ -50,7 +50,6 @@ namespace { */ HWTEST_F(PowerMgrClientNativeTest, PowerMgrClientNative001, TestSize.Level2) { - GTEST_LOG_(INFO) << "PowerMgrClientNative001 function start!"; POWER_HILOGI(LABEL_TEST, "PowerMgrClientNative001 function start!"); auto& powerMgrClient = PowerMgrClient::GetInstance(); sptr sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); @@ -69,17 +68,13 @@ HWTEST_F(PowerMgrClientNativeTest, PowerMgrClientNative001, TestSize.Level2) EXPECT_FALSE(powerMgrClient.UnRegisterPowerStateCallback(nullptr)); EXPECT_FALSE(powerMgrClient.RegisterPowerModeCallback(nullptr)); EXPECT_FALSE(powerMgrClient.UnRegisterPowerModeCallback(nullptr)); -#ifdef POWER_MANAGER_TAKEOVER_SUSPEND - EXPECT_FALSE(powerMgrClient.RegisterSuspendTakeoverCallback(nullptr, TakeOverSuspendPriority::DEFAULT)); - EXPECT_FALSE(powerMgrClient.UnRegisterSuspendTakeoverCallback(nullptr)); -#endif + EXPECT_FALSE(powerMgrClient.RegisterRunningLockCallback(nullptr)); EXPECT_FALSE(powerMgrClient.UnRegisterRunningLockCallback(nullptr)); EXPECT_FALSE(powerMgrClient.RegisterScreenStateCallback(0, nullptr)); EXPECT_FALSE(powerMgrClient.UnRegisterScreenStateCallback(nullptr)); POWER_HILOGI(LABEL_TEST, "PowerMgrClientNative001 function end!"); - GTEST_LOG_(INFO) << "PowerMgrClientNative001 function end!"; } /** @@ -90,7 +85,6 @@ HWTEST_F(PowerMgrClientNativeTest, PowerMgrClientNative001, TestSize.Level2) */ HWTEST_F(PowerMgrClientNativeTest, RunningLockNative001, TestSize.Level2) { - GTEST_LOG_(INFO) << "RunningLockNative001 function start!"; POWER_HILOGI(LABEL_TEST, "RunningLockNative001 function start!"); std::shared_ptr runningLock = std::make_shared(nullptr, "runninglock1", RunningLockType::RUNNINGLOCK_SCREEN); @@ -98,6 +92,5 @@ HWTEST_F(PowerMgrClientNativeTest, RunningLockNative001, TestSize.Level2) EXPECT_TRUE(runningLock->UnLock() != ERR_OK); runningLock->Release(); POWER_HILOGI(LABEL_TEST, "RunningLockNative001 function end!"); - GTEST_LOG_(INFO) << "RunningLockNative001 function end!"; } } \ No newline at end of file diff --git a/test/unittest/src/power_mgr_dump_test.cpp b/test/unittest/src/power_mgr_dump_test.cpp index 95222be15982e97a52d883c84515c5f03e849214..a1af484ef7d8f147befec0af42fc67a6912d7a27 100644 --- a/test/unittest/src/power_mgr_dump_test.cpp +++ b/test/unittest/src/power_mgr_dump_test.cpp @@ -64,7 +64,6 @@ namespace { */ HWTEST_F (PowerMgrDumpTest, PowerMgrDumpNative001, TestSize.Level1) { - GTEST_LOG_(INFO) << "PowerMgrDumpNative001 function start!"; POWER_HILOGI(LABEL_TEST, "PowerMgrDumpNative001 function start!"); EXPECT_TRUE(g_pmsTest != nullptr) << "PowerMgrDumpNative001 fail to get PowerMgrService"; int32_t fd = 1; @@ -73,7 +72,6 @@ HWTEST_F (PowerMgrDumpTest, PowerMgrDumpNative001, TestSize.Level1) args.push_back(arg); EXPECT_TRUE(g_pmsTest->Dump(fd, args) == ERR_OK); POWER_HILOGI(LABEL_TEST, "PowerMgrDumpNative001 function end!"); - GTEST_LOG_(INFO) << "PowerMgrDumpNative001 function end!"; } /** @@ -83,7 +81,6 @@ HWTEST_F (PowerMgrDumpTest, PowerMgrDumpNative001, TestSize.Level1) */ HWTEST_F (PowerMgrDumpTest, PowerMgrDumpNative002, TestSize.Level1) { - GTEST_LOG_(INFO) << "PowerMgrDumpNative002 function start!"; POWER_HILOGI(LABEL_TEST, "PowerMgrDumpNative002 function start!"); EXPECT_TRUE(g_pmsTest != nullptr) << "PowerMgrDumpNative002 fail to get PowerMgrService"; int32_t fd = 1; @@ -92,7 +89,6 @@ HWTEST_F (PowerMgrDumpTest, PowerMgrDumpNative002, TestSize.Level1) args.push_back(arg); EXPECT_TRUE(g_pmsTest->Dump(fd, args) == ERR_OK); POWER_HILOGI(LABEL_TEST, "PowerMgrDumpNative002 function end!"); - GTEST_LOG_(INFO) << "PowerMgrDumpNative002 function end!"; } /** @@ -102,7 +98,6 @@ HWTEST_F (PowerMgrDumpTest, PowerMgrDumpNative002, TestSize.Level1) */ HWTEST_F (PowerMgrDumpTest, PowerMgrDumpNative003, TestSize.Level1) { - GTEST_LOG_(INFO) << "PowerMgrDumpNative003 function start!"; POWER_HILOGI(LABEL_TEST, "PowerMgrDumpNative003 function start!"); EXPECT_TRUE(g_pmsTest != nullptr) << "PowerMgrDumpNative003 fail to get PowerMgrService"; int32_t fd = 1; @@ -115,7 +110,6 @@ HWTEST_F (PowerMgrDumpTest, PowerMgrDumpNative003, TestSize.Level1) args.push_back(arg2); EXPECT_TRUE(g_pmsTest->Dump(fd, args) == ERR_OK); POWER_HILOGI(LABEL_TEST, "PowerMgrDumpNative003 function end!"); - GTEST_LOG_(INFO) << "PowerMgrDumpNative003 function end!"; } /** @@ -125,7 +119,6 @@ HWTEST_F (PowerMgrDumpTest, PowerMgrDumpNative003, TestSize.Level1) */ HWTEST_F (PowerMgrDumpTest, PowerMgrDumpNative004, TestSize.Level1) { - GTEST_LOG_(INFO) << "PowerMgrDumpNative004 function start!"; POWER_HILOGI(LABEL_TEST, "PowerMgrDumpNative004 function start!"); EXPECT_TRUE(g_pmsTest != nullptr) << "PowerMgrDumpNative004 fail to get PowerMgrService"; int32_t fd = 1; @@ -134,6 +127,5 @@ HWTEST_F (PowerMgrDumpTest, PowerMgrDumpNative004, TestSize.Level1) args.push_back(arg); EXPECT_TRUE(g_pmsTest->Dump(fd, args) == ERR_OK); POWER_HILOGI(LABEL_TEST, "PowerMgrDumpNative004 function end!"); - GTEST_LOG_(INFO) << "PowerMgrDumpNative004 function end!"; } } // namespace diff --git a/test/unittest/src/power_mgr_notify_test.cpp b/test/unittest/src/power_mgr_notify_test.cpp index de0661afaacaa111086aca5cbe134eed8cf5f4a2..75714e13e4b49f2a5c772fa6e2f97139b42cee48 100644 --- a/test/unittest/src/power_mgr_notify_test.cpp +++ b/test/unittest/src/power_mgr_notify_test.cpp @@ -84,7 +84,6 @@ public: shared_ptr RegisterEvent() { GTEST_LOG_(INFO) << "PowerMgrNotifyTest:: Regist Subscriber Start!!"; - POWER_HILOGI(LABEL_TEST, "PowerMgrNotifyTest:: Regist Subscriber start!"); sptr skill = new AAFwk::Skills(); skill->AddAction(CommonEventSupport::COMMON_EVENT_SCREEN_OFF); skill->AddAction(CommonEventSupport::COMMON_EVENT_SCREEN_ON); @@ -109,7 +108,6 @@ shared_ptr RegisterEvent() GTEST_LOG_(INFO) << "PowerMgrNotifyTest:: Fail to register Subscriber!!!"; return nullptr; } - POWER_HILOGI(LABEL_TEST, "PowerMgrNotifyTest:: Regist Subscriber Success!"); GTEST_LOG_(INFO) << "PowerMgrNotifyTest:: register Subscriber Success!!"; return subscriber; } diff --git a/test/unittest/src/power_mgr_powerdialog_test.cpp b/test/unittest/src/power_mgr_powerdialog_test.cpp index 182a336c69b991fc8e66c17c959db80fe3ddf760..15a307a2fe066ff96336fe45ca98d68d6a23a225 100644 --- a/test/unittest/src/power_mgr_powerdialog_test.cpp +++ b/test/unittest/src/power_mgr_powerdialog_test.cpp @@ -63,7 +63,6 @@ constexpr int32_t SLEEP_WAIT_TIME_S = 1; */ HWTEST_F(PowerMgrPowerDialog, LongPressKeyMonitorInitTest, TestSize.Level2) { - GTEST_LOG_(INFO) << "LongPressKeyMonitorInitTest start."; POWER_HILOGI(LABEL_TEST, "LongPressKeyMonitorInitTest function start!"); ShutdownDialog shutdownDialog; shutdownDialog.KeyMonitorInit(); @@ -71,7 +70,6 @@ HWTEST_F(PowerMgrPowerDialog, LongPressKeyMonitorInitTest, TestSize.Level2) shutdownDialog.KeyMonitorCancel(); EXPECT_TRUE(shutdownDialog.longPressId_ == OHOS::ERR_OK); POWER_HILOGI(LABEL_TEST, "LongPressKeyMonitorInitTest function end!"); - GTEST_LOG_(INFO) << "LongPressKeyMonitorInitTest end."; } /** @@ -81,7 +79,6 @@ HWTEST_F(PowerMgrPowerDialog, LongPressKeyMonitorInitTest, TestSize.Level2) */ HWTEST_F(PowerMgrPowerDialog, ConnectSystemUiDialogShowTest, TestSize.Level2) { - GTEST_LOG_(INFO) << "ConnectSystemUiDialogShowTest start."; POWER_HILOGI(LABEL_TEST, "ConnectSystemUiDialogShowTest function start!"); ShutdownDialog shutdownDialog; sptr sptrRemoteObj = new MockPowerRemoteObject(); @@ -91,7 +88,6 @@ HWTEST_F(PowerMgrPowerDialog, ConnectSystemUiDialogShowTest, TestSize.Level2) sleep(SLEEP_WAIT_TIME_S); EXPECT_TRUE(shutdownDialog.ConnectSystemUi()); POWER_HILOGI(LABEL_TEST, "ConnectSystemUiDialogShowTest function end!"); - GTEST_LOG_(INFO) << "ConnectSystemUiDialogShowTest end."; } /** @@ -101,7 +97,6 @@ HWTEST_F(PowerMgrPowerDialog, ConnectSystemUiDialogShowTest, TestSize.Level2) */ HWTEST_F(PowerMgrPowerDialog, OnAbilityConnectDoneTestFail, TestSize.Level2) { - GTEST_LOG_(INFO) << "OnAbilityConnectDoneTestFail start."; POWER_HILOGI(LABEL_TEST, "OnAbilityConnectDoneTestFail function start!"); ShutdownDialog shutdownDialog; shutdownDialog.ResetLongPressFlag(); @@ -112,7 +107,6 @@ HWTEST_F(PowerMgrPowerDialog, OnAbilityConnectDoneTestFail, TestSize.Level2) sleep(SLEEP_WAIT_TIME_S); EXPECT_FALSE(shutdownDialog.IsLongPress()); POWER_HILOGI(LABEL_TEST, "OnAbilityConnectDoneTestFail function end!"); - GTEST_LOG_(INFO) << "OnAbilityConnectDoneTestFail end."; } /** @@ -122,7 +116,6 @@ HWTEST_F(PowerMgrPowerDialog, OnAbilityConnectDoneTestFail, TestSize.Level2) */ HWTEST_F(PowerMgrPowerDialog, OnAbilityConnectDoneTestRemoteNull, TestSize.Level2) { - GTEST_LOG_(INFO) << "OnAbilityConnectDoneTestRemoteNull start."; POWER_HILOGI(LABEL_TEST, "OnAbilityConnectDoneTestRemoteNull function start!"); ShutdownDialog shutdownDialog; shutdownDialog.ResetLongPressFlag(); @@ -132,7 +125,6 @@ HWTEST_F(PowerMgrPowerDialog, OnAbilityConnectDoneTestRemoteNull, TestSize.Level sleep(SLEEP_WAIT_TIME_S); EXPECT_FALSE(shutdownDialog.IsLongPress()); POWER_HILOGI(LABEL_TEST, "OnAbilityConnectDoneTestRemoteNull function end!"); - GTEST_LOG_(INFO) << "OnAbilityConnectDoneTestRemoteNull end."; } /** @@ -142,7 +134,6 @@ HWTEST_F(PowerMgrPowerDialog, OnAbilityConnectDoneTestRemoteNull, TestSize.Level */ HWTEST_F(PowerMgrPowerDialog, OnAbilityConnectDoneTest, TestSize.Level2) { - GTEST_LOG_(INFO) << "OnAbilityConnectDoneTest start."; POWER_HILOGI(LABEL_TEST, "OnAbilityConnectDoneTest function start!"); ShutdownDialog shutdownDialog; shutdownDialog.ResetLongPressFlag(); @@ -153,7 +144,6 @@ HWTEST_F(PowerMgrPowerDialog, OnAbilityConnectDoneTest, TestSize.Level2) sleep(SLEEP_WAIT_TIME_S); EXPECT_TRUE(shutdownDialog.IsLongPress()); POWER_HILOGI(LABEL_TEST, "OnAbilityConnectDoneTest function end!"); - GTEST_LOG_(INFO) << "OnAbilityConnectDoneTest end."; } /** @@ -163,7 +153,6 @@ HWTEST_F(PowerMgrPowerDialog, OnAbilityConnectDoneTest, TestSize.Level2) */ HWTEST_F(PowerMgrPowerDialog, OnAbilityDisconnectDoneTest, TestSize.Level2) { - GTEST_LOG_(INFO) << "OnAbilityDisconnectDoneTest start."; POWER_HILOGI(LABEL_TEST, "OnAbilityDisconnectDoneTest function start!"); ShutdownDialog shutdownDialog; AppExecFwk::ElementName element; @@ -171,6 +160,5 @@ HWTEST_F(PowerMgrPowerDialog, OnAbilityDisconnectDoneTest, TestSize.Level2) sleep(SLEEP_WAIT_TIME_S); EXPECT_FALSE(shutdownDialog.IsLongPress()); POWER_HILOGI(LABEL_TEST, "OnAbilityDisconnectDoneTest function end!"); - GTEST_LOG_(INFO) << "OnAbilityDisconnectDoneTest end."; } } // namespace diff --git a/test/unittest/src/power_mgr_service_death_test.cpp b/test/unittest/src/power_mgr_service_death_test.cpp index e3fba4cc8cb064124ef4f7d061bdbfe954617eac..2ffecd1da5173bc4b2438b82d196b399c3a18a89 100644 --- a/test/unittest/src/power_mgr_service_death_test.cpp +++ b/test/unittest/src/power_mgr_service_death_test.cpp @@ -33,7 +33,6 @@ namespace { */ HWTEST_F (PowerMgrServiceDeathTest, PowerMgrServiceDeathTest_001, TestSize.Level1) { - GTEST_LOG_(INFO) << "PowerMgrServiceDeathTest_001 start."; POWER_HILOGI(LABEL_TEST, "PowerMgrServiceDeathTest_001 function start!"); auto& powerMgrClient = PowerMgrClient::GetInstance(); EXPECT_TRUE(powerMgrClient.GetPowerMgrProxy() != nullptr); @@ -45,7 +44,6 @@ HWTEST_F (PowerMgrServiceDeathTest, PowerMgrServiceDeathTest_001, TestSize.Level deathRecipient->OnRemoteDied(remoteObj); EXPECT_NE(powerMgrClient.proxy_, nullptr); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceDeathTest_001 function end!"); - GTEST_LOG_(INFO) << "PowerMgrServiceDeathTest_001 end."; } /** @@ -56,7 +54,6 @@ HWTEST_F (PowerMgrServiceDeathTest, PowerMgrServiceDeathTest_001, TestSize.Level */ HWTEST_F (PowerMgrServiceDeathTest, PowerMgrServiceDeathTest_002, TestSize.Level1) { - GTEST_LOG_(INFO) << "PowerMgrServiceDeathTest_002 start."; POWER_HILOGI(LABEL_TEST, "PowerMgrServiceDeathTest_002 function start!"); auto& powerMgrClient = PowerMgrClient::GetInstance(); EXPECT_TRUE(powerMgrClient.GetPowerMgrProxy() != nullptr); @@ -69,6 +66,5 @@ HWTEST_F (PowerMgrServiceDeathTest, PowerMgrServiceDeathTest_002, TestSize.Level deathRecipient->OnRemoteDied(sptrRemoteObj); EXPECT_NE(powerMgrClient.proxy_, nullptr); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceDeathTest_002 function end!"); - GTEST_LOG_(INFO) << "PowerMgrServiceDeathTest_002 end."; } } \ No newline at end of file diff --git a/test/unittest/src/power_mgr_service_native_test.cpp b/test/unittest/src/power_mgr_service_native_test.cpp index 877ece6af57fc50e9ef755ba241a6ee26d2962dd..a56843a4eb3cfe2baa8c083c0c0311e854d38b01 100644 --- a/test/unittest/src/power_mgr_service_native_test.cpp +++ b/test/unittest/src/power_mgr_service_native_test.cpp @@ -87,7 +87,6 @@ namespace { */ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative001, TestSize.Level1) { - GTEST_LOG_(INFO) << "PowerMgrServiceNative001 start."; POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative001 function start!"); g_pmsTest->HallSensorSubscriberInit(); g_pmsTest->HallSensorSubscriberCancel(); @@ -104,7 +103,6 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative001, TestSize.Level1) g_pmsTest->monitorId_ = UNCANCELID; #endif POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative001 function end!"); - GTEST_LOG_(INFO) << "PowerMgrServiceNative001 end."; } /** @@ -115,7 +113,6 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative001, TestSize.Level1) #ifdef HAS_MULTIMODALINPUT_INPUT_PART HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative002, TestSize.Level1) { - GTEST_LOG_(INFO) << "PowerMgrServiceNative002 start."; POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative002 function start!"); int32_t keyCode = OHOS::MMI::KeyEvent::KEYCODE_F1; g_pmsTest->HandleKeyEvent(keyCode); @@ -134,7 +131,6 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative002, TestSize.Level1) SuspendDeviceType reasonSDT = SuspendDeviceType::SUSPEND_DEVICE_REASON_DEVICE_ADMIN; EXPECT_TRUE(g_pmsTest->SuspendDevice(SUSCALLTIMEMS, reasonSDT, false) == PowerErrors::ERR_OK); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative002 function end!"); - GTEST_LOG_(INFO) << "PowerMgrServiceNative002 end."; } #endif @@ -145,7 +141,6 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative002, TestSize.Level1) */ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative003, TestSize.Level1) { - GTEST_LOG_(INFO) << "PowerMgrServiceNative003 start."; POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative003 function start!"); #ifdef POWER_PICKUP_ENABLE g_pmsTest->RegisterSettingWakeupPickupGestureObserver(); @@ -156,7 +151,6 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative003, TestSize.Level1) EXPECT_TRUE(SettingHelper::pickUpObserver_ == nullptr); #endif POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative003 function end!"); - GTEST_LOG_(INFO) << "PowerMgrServiceNative003 end."; } /** @@ -166,7 +160,6 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative003, TestSize.Level1) */ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative004, TestSize.Level1) { - GTEST_LOG_(INFO) << "PowerMgrServiceNative004 start."; POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative004 function start!"); shared_ptr powerModeModuleTest = make_shared(); EXPECT_TRUE(powerModeModuleTest != nullptr); @@ -175,7 +168,6 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative004, TestSize.Level1) SettingHelper::SetSettingAutoAdjustBrightness(SettingHelper::SwitchStatus::INVALID); auto ret = SettingHelper::GetSettingAutoAdjustBrightness(INVALID_CODE); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative004 function end!"); - GTEST_LOG_(INFO) << "PowerMgrServiceNative004 end."; } /** @@ -185,7 +177,6 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative004, TestSize.Level1) */ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative005, TestSize.Level1) { - GTEST_LOG_(INFO) << "PowerMgrServiceNative005 start."; POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative005 function start!"); shared_ptr powerModeModuleTest = make_shared(); EXPECT_TRUE(powerModeModuleTest != nullptr); @@ -194,7 +185,6 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative005, TestSize.Level1) SettingHelper::SetSettingBrightness(INVALID_CODE); auto ret = SettingHelper::GetSettingAutoAdjustBrightness(INVALID_CODE); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative005 function end!"); - GTEST_LOG_(INFO) << "PowerMgrServiceNative005 end."; } /** @@ -204,7 +194,6 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative005, TestSize.Level1) */ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative006, TestSize.Level1) { - GTEST_LOG_(INFO) << "PowerMgrServiceNative006 start."; POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative006 function start!"); shared_ptr powerModeModuleTest = make_shared(); EXPECT_TRUE(powerModeModuleTest != nullptr); @@ -213,7 +202,6 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative006, TestSize.Level1) SettingHelper::SetSettingVibration(SettingHelper::SwitchStatus::INVALID); auto ret = SettingHelper::GetSettingVibration(INVALID_CODE); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative006 function end!"); - GTEST_LOG_(INFO) << "PowerMgrServiceNative006 end."; } @@ -224,7 +212,6 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative006, TestSize.Level1) */ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative007, TestSize.Level1) { - GTEST_LOG_(INFO) << "PowerMgrServiceNative007 start."; POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative007 function start!"); shared_ptr powerModeModuleTest = make_shared(); EXPECT_TRUE(powerModeModuleTest != nullptr); @@ -233,7 +220,6 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative007, TestSize.Level1) SettingHelper::SetSettingWindowRotation(SettingHelper::SwitchStatus::INVALID); auto ret = SettingHelper::GetSettingWindowRotation(INVALID_CODE); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative007 function end!"); - GTEST_LOG_(INFO) << "PowerMgrServiceNative007 end."; } /** @@ -243,7 +229,6 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative007, TestSize.Level1) */ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative008, TestSize.Level1) { - GTEST_LOG_(INFO) << "PowerMgrServiceNative008 start."; POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative008 function start!"); shared_ptr powerModeModuleTest = make_shared(); EXPECT_TRUE(powerModeModuleTest != nullptr); @@ -253,7 +238,6 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative008, TestSize.Level1) auto ret = SettingHelper::GetSettingIntellVoice(INVALID_CODE); powerModeModuleTest->UnregisterSaveModeObserver(); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative008 function end!"); - GTEST_LOG_(INFO) << "PowerMgrServiceNative008 end."; } /** @@ -263,7 +247,6 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative008, TestSize.Level1) */ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative009, TestSize.Level1) { - GTEST_LOG_(INFO) << "PowerMgrServiceNative009 start."; POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative009 function start!"); g_pmsTest->RegisterSettingPowerModeObservers(); g_pmsTest->RegisterSettingPowerModeObservers(); @@ -272,7 +255,6 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative009, TestSize.Level1) SettingHelper::UnRegisterSettingPowerModeObserver(); EXPECT_TRUE(SettingHelper::powerModeObserver_ == nullptr); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative009 function end!"); - GTEST_LOG_(INFO) << "PowerMgrServiceNative009 end."; } /** @@ -282,7 +264,6 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative009, TestSize.Level1) */ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative010, TestSize.Level1) { - GTEST_LOG_(INFO) << "PowerMgrServiceNative010 start."; POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative010 function start!"); g_pmsTest->RegisterSettingWakeUpLidObserver(); SettingHelper::SetSettingWakeupLid(true); @@ -290,7 +271,6 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative010, TestSize.Level1) SettingHelper::UnRegisterSettingWakeupLidObserver(); EXPECT_TRUE(SettingHelper::lidObserver_ == nullptr); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative010 function end!"); - GTEST_LOG_(INFO) << "PowerMgrServiceNative010 end."; } /** @@ -300,7 +280,6 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative010, TestSize.Level1) */ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative011, TestSize.Level1) { - GTEST_LOG_(INFO) << "PowerMgrServiceNative011 start."; POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative011 function start!"); #ifdef POWER_DOUBLECLICK_ENABLE g_pmsTest->RegisterSettingWakeupDoubleClickObservers(); @@ -311,7 +290,6 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative011, TestSize.Level1) EXPECT_TRUE(SettingHelper::doubleClickObserver_ == nullptr); #endif POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative011 function end!"); - GTEST_LOG_(INFO) << "PowerMgrServiceNative011 end."; } /** @@ -321,7 +299,6 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative011, TestSize.Level1) */ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative012, TestSize.Level1) { - GTEST_LOG_(INFO) << "PowerMgrServiceNative012 start."; POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative012 function start!"); #ifdef MSDP_MOVEMENT_ENABLE auto stateMachine = std::make_shared(g_pmsTest); @@ -332,7 +309,6 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative012, TestSize.Level1) EXPECT_TRUE(ret == false); #endif POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative012 function end!"); - GTEST_LOG_(INFO) << "PowerMgrServiceNative012 end."; } /** @@ -342,7 +318,6 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative012, TestSize.Level1) */ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative013, TestSize.Level1) { - GTEST_LOG_(INFO) << "PowerMgrServiceNative013 start."; POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative013 function start!"); #ifdef POWER_MANAGER_ENABLE_EXTERNAL_SCREEN_MANAGEMENT g_pmsTest->RegisterExternalScreenListener(); @@ -351,7 +326,6 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative013, TestSize.Level1) EXPECT_TRUE(g_pmsTest->externalScreenListener_ == nullptr); #endif POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative013 function end!"); - GTEST_LOG_(INFO) << "PowerMgrServiceNative013 end."; } /** @@ -361,7 +335,6 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative013, TestSize.Level1) */ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative014, TestSize.Level1) { - GTEST_LOG_(INFO) << "PowerMgrServiceNative014 start."; POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative014 function start!"); #ifdef POWER_MANAGER_ENABLE_EXTERNAL_SCREEN_MANAGEMENT g_pmsTest->SuspendControllerInit(); @@ -402,7 +375,6 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative014, TestSize.Level1) EXPECT_TRUE(g_pmsTest->externalScreenListener_ == nullptr); #endif POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative014 function end!"); - GTEST_LOG_(INFO) << "PowerMgrServiceNative014 end."; } /** @@ -412,7 +384,6 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative014, TestSize.Level1) */ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative015, TestSize.Level1) { - GTEST_LOG_(INFO) << "PowerMgrServiceNative015 start."; POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative015 function start!"); #ifdef POWER_MANAGER_ENABLE_EXTERNAL_SCREEN_MANAGEMENT g_pmsTest->SuspendControllerInit(); @@ -460,7 +431,6 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative015, TestSize.Level1) EXPECT_TRUE(g_pmsTest->externalScreenListener_ == nullptr); #endif POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative015 function end!"); - GTEST_LOG_(INFO) << "PowerMgrServiceNative015 end."; } /** diff --git a/test/unittest/src/power_mode_module_native_test.cpp b/test/unittest/src/power_mode_module_native_test.cpp index 9baba242b169f32558ebf23fd1043d23c9c3fb9d..fabfedf1e18de1097b2a1f76611e3b1f33f137c1 100644 --- a/test/unittest/src/power_mode_module_native_test.cpp +++ b/test/unittest/src/power_mode_module_native_test.cpp @@ -50,7 +50,6 @@ using ModeActionPolicy = std::function; */ HWTEST_F (PowerModeModuleNativeTest, PowerModeModuleNativeTest001, TestSize.Level1) { - GTEST_LOG_(INFO) << "PowerModeModuleNativeTest001 start."; POWER_HILOGI(LABEL_TEST, "PowerModeModuleNativeTest001 function start!"); shared_ptr powerModeModuleTest = make_shared(); powerModeModuleTest->mode_ = PowerMode::PERFORMANCE_MODE; @@ -90,7 +89,6 @@ HWTEST_F (PowerModeModuleNativeTest, PowerModeModuleNativeTest001, TestSize.Leve powerModeModuleManager->OnRemoteDied(nullptr); POWER_HILOGI(LABEL_TEST, "PowerModeModuleNativeTest001 function end!"); - GTEST_LOG_(INFO) << "PowerModeModuleNativeTest001 end."; } /** @@ -100,7 +98,6 @@ HWTEST_F (PowerModeModuleNativeTest, PowerModeModuleNativeTest001, TestSize.Leve */ HWTEST_F (PowerModeModuleNativeTest, PowerModePolicyNativeTest001, TestSize.Level1) { - GTEST_LOG_(INFO) << "PowerModePolicyNativeTest001 start."; POWER_HILOGI(LABEL_TEST, "PowerModePolicyNativeTest001 function start!"); PowerModePolicy *powerModePolicyTest = new PowerModePolicy(); EXPECT_TRUE(powerModePolicyTest->GetPowerModeValuePolicy(MODEITEM) == INIT_VALUE_FALSE); @@ -110,6 +107,5 @@ HWTEST_F (PowerModeModuleNativeTest, PowerModePolicyNativeTest001, TestSize.Leve ModeActionPolicy action; powerModePolicyTest->AddAction(MODEITEM, action); POWER_HILOGI(LABEL_TEST, "PowerModePolicyNativeTest001 function end!"); - GTEST_LOG_(INFO) << "PowerModePolicyNativeTest001 end."; } } diff --git a/test/unittest/src/power_register_callback_mode_test.cpp b/test/unittest/src/power_register_callback_mode_test.cpp index a24723f4a56c1dd7067deb8ba0f126e076cb7e03..5310f83b994e87460a2308339010df7068d34c86 100644 --- a/test/unittest/src/power_register_callback_mode_test.cpp +++ b/test/unittest/src/power_register_callback_mode_test.cpp @@ -46,7 +46,6 @@ namespace { */ HWTEST_F (PowerRegisterCallbackModeTest, PowerRegisterCallbackModeCallback001, TestSize.Level1) { - GTEST_LOG_(INFO) << "PowerRegisterCallbackModeCallback001 start."; POWER_HILOGI(LABEL_TEST, "PowerRegisterCallbackModeCallback001 function start!"); auto& powerMgrClient = PowerMgrClient::GetInstance(); sptr cb1 = new PowerModeTest1Callback(); @@ -56,6 +55,5 @@ HWTEST_F (PowerRegisterCallbackModeTest, PowerRegisterCallbackModeCallback001, T powerMgrClient.SetDeviceMode(mode); EXPECT_EQ(mode, powerMgrClient.GetDeviceMode()); POWER_HILOGI(LABEL_TEST, "PowerRegisterCallbackModeCallback001 function end!"); - GTEST_LOG_(INFO) << "PowerRegisterCallbackModeCallback001 end."; } } \ No newline at end of file diff --git a/test/unittest/src/power_set_mode_test.cpp b/test/unittest/src/power_set_mode_test.cpp index 8e5e0bb59b440a2a07173a1d819c18d3f0d2218e..a19ffa1e3971b46e62da3efbff68ee62676d6763 100644 --- a/test/unittest/src/power_set_mode_test.cpp +++ b/test/unittest/src/power_set_mode_test.cpp @@ -83,13 +83,10 @@ HWTEST_F (PowerSetModeTest, SetModeTest001, TestSize.Level1) */ HWTEST_F (PowerSetModeTest, SaveModeTest001, TestSize.Level1) { - GTEST_LOG_(INFO) << "SaveModeTest001 start."; POWER_HILOGI(LABEL_TEST, "SaveModeTest001 function start!"); - int32_t EXPECT_RESULT = -1; auto mode = std::make_shared(); int32_t ret = mode->GetSleepTime(0); - EXPECT_TRUE(ret == EXPECT_RESULT); + EXPECT_TRUE(ret == -1); POWER_HILOGI(LABEL_TEST, "SaveModeTest001 function end!"); - GTEST_LOG_(INFO) << "SaveModeTest001 end."; } } \ No newline at end of file diff --git a/test/unittest/src/running_lock_hub_native_test.cpp b/test/unittest/src/running_lock_hub_native_test.cpp index 28b99fe208e7fcc5544fbd3da42f1113eabb4b75..215bfcd517d3e98a918406ae4cf5f7a9f39632f5 100644 --- a/test/unittest/src/running_lock_hub_native_test.cpp +++ b/test/unittest/src/running_lock_hub_native_test.cpp @@ -50,7 +50,6 @@ void RunningSuspendCallback() */ HWTEST_F(RunningLockHubNativeTest, RunningLockNative001, TestSize.Level1) { - GTEST_LOG_(INFO) << "RunningLockNative001 start"; POWER_HILOGI(LABEL_TEST, "RunningLockNative001 function start!"); auto sc = std::make_shared(); auto runningLockHub = std::make_shared(sc); @@ -63,7 +62,6 @@ HWTEST_F(RunningLockHubNativeTest, RunningLockNative001, TestSize.Level1) runningLockHub->Release("333"); EXPECT_TRUE(runningLockHub->runningLockMap_.empty()); POWER_HILOGI(LABEL_TEST, "RunningLockNative001 function end!"); - GTEST_LOG_(INFO) << "RunningLockNative001 end"; } /** @@ -73,7 +71,6 @@ HWTEST_F(RunningLockHubNativeTest, RunningLockNative001, TestSize.Level1) */ HWTEST_F(RunningLockHubNativeTest, RunningLockNative002, TestSize.Level1) { - GTEST_LOG_(INFO) << "RunningLockNative002 start"; POWER_HILOGI(LABEL_TEST, "RunningLockNative002 function start!"); auto SuspendController = std::make_shared(); SuspendController->Wakeup(); @@ -88,6 +85,5 @@ HWTEST_F(RunningLockHubNativeTest, RunningLockNative002, TestSize.Level1) SuspendController->DecSuspendBlockCounter(); SuspendController->DecSuspendBlockCounter(); POWER_HILOGI(LABEL_TEST, "RunningLockNative002 function end!"); - GTEST_LOG_(INFO) << "RunningLockNative002 end"; } } // namespace \ No newline at end of file diff --git a/test/unittest/src/running_lock_mock_test.cpp b/test/unittest/src/running_lock_mock_test.cpp index 2d28d08dd8e558af5ed2554a6232124a8e763cea..77b997e9f27646f7ccf41003edacd066668d77bd 100644 --- a/test/unittest/src/running_lock_mock_test.cpp +++ b/test/unittest/src/running_lock_mock_test.cpp @@ -87,9 +87,6 @@ HWTEST_F (RunningLockMockTest, RunningLockMockTest001, TestSize.Level2) auto runningLockMgr = g_powerService->GetRunningLockMgr(); uint32_t lockActionCount = 0; uint32_t unlockActionCount = 0; - uint32_t PARAM_ZERO = 0; - uint32_t PARAM_ONE = 1; - uint32_t PARAM_TWO = 2; EXPECT_CALL(*g_lockAction, Lock(_)).WillRepeatedly([&](const RunningLockParam& param) { EXPECT_EQ(param.name, RUNNINGLOCK_BACKGROUND_NAME); @@ -111,20 +108,20 @@ HWTEST_F (RunningLockMockTest, RunningLockMockTest001, TestSize.Level2) EXPECT_EQ(PowerErrors::ERR_OK, g_powerService->CreateRunningLock(runninglockToken2, runninglockInfo2)); g_powerService->Lock(runninglockToken); - EXPECT_EQ(PARAM_ONE, runningLockMgr->GetValidRunningLockNum(runninglockInfo.type)); + EXPECT_EQ(1, runningLockMgr->GetValidRunningLockNum(runninglockInfo.type)); g_powerService->Lock(runninglockToken2); - EXPECT_EQ(PARAM_TWO, runningLockMgr->GetValidRunningLockNum(runninglockInfo2.type)); + EXPECT_EQ(2, runningLockMgr->GetValidRunningLockNum(runninglockInfo2.type)); g_powerService->UnLock(runninglockToken); - EXPECT_EQ(PARAM_ONE, runningLockMgr->GetValidRunningLockNum(runninglockInfo.type)); + EXPECT_EQ(1, runningLockMgr->GetValidRunningLockNum(runninglockInfo.type)); g_powerService->UnLock(runninglockToken2); - EXPECT_EQ(PARAM_ZERO, runningLockMgr->GetValidRunningLockNum(runninglockInfo2.type)); + EXPECT_EQ(0, runningLockMgr->GetValidRunningLockNum(runninglockInfo2.type)); g_powerService->ReleaseRunningLock(runninglockToken); g_powerService->ReleaseRunningLock(runninglockToken2); - EXPECT_EQ(lockActionCount, PARAM_ZERO); - EXPECT_EQ(unlockActionCount, PARAM_ZERO); + EXPECT_EQ(lockActionCount, 0); + EXPECT_EQ(unlockActionCount, 0); #endif POWER_HILOGI(LABEL_TEST, "RunningLockMockTest001 function end!"); } @@ -148,8 +145,6 @@ HWTEST_F (RunningLockMockTest, RunningLockMockTest002, TestSize.Level2) auto runningLockMgr = g_powerService->GetRunningLockMgr(); uint32_t lockActionCount = 0; uint32_t unlockActionCount = 0; - uint32_t PARAM_ZERO = 0; - uint32_t PARAM_ONE = 1; EXPECT_CALL(*g_lockAction, Lock(_)).WillRepeatedly([&](const RunningLockParam& param) { EXPECT_EQ(param.name, RUNNINGLOCK_BACKGROUND_NAME); @@ -169,12 +164,12 @@ HWTEST_F (RunningLockMockTest, RunningLockMockTest002, TestSize.Level2) EXPECT_EQ(PowerErrors::ERR_OK, g_powerService->CreateRunningLock(runninglockToken, runninglockInfo)); g_powerService->Lock(runninglockToken); - EXPECT_EQ(PARAM_ONE, runningLockMgr->GetValidRunningLockNum(runninglockInfo.type)); + EXPECT_EQ(1, runningLockMgr->GetValidRunningLockNum(runninglockInfo.type)); g_powerService->UnLock(runninglockToken); g_powerService->ReleaseRunningLock(runninglockToken); - EXPECT_EQ(lockActionCount, PARAM_ZERO); - EXPECT_EQ(unlockActionCount, PARAM_ZERO); + EXPECT_EQ(lockActionCount, 0); + EXPECT_EQ(unlockActionCount, 0); #endif POWER_HILOGI(LABEL_TEST, "RunningLockMockTest002 function end!"); } @@ -196,7 +191,6 @@ HWTEST_F (RunningLockMockTest, RunningLockMockTest003, TestSize.Level2) int32_t timeoutMs = -1; uint32_t lockActionCount = 0; uint32_t unlockActionCount = 0; - uint32_t PARAM_TWO = 2; auto GetRunningLockInfo = [&](RunningLockType type) { if (type == RunningLockType::RUNNINGLOCK_BACKGROUND_PHONE) { @@ -234,8 +228,8 @@ HWTEST_F (RunningLockMockTest, RunningLockMockTest003, TestSize.Level2) g_powerService->ReleaseRunningLock(phoneToken); g_powerService->ReleaseRunningLock(notifyToken); - EXPECT_EQ(lockActionCount, PARAM_TWO); - EXPECT_EQ(unlockActionCount, PARAM_TWO); + EXPECT_EQ(lockActionCount, 2); + EXPECT_EQ(unlockActionCount, 2); POWER_HILOGI(LABEL_TEST, "RunningLockMockTest003 function end!"); } @@ -256,7 +250,6 @@ HWTEST_F (RunningLockMockTest, RunningLockMockTest004, TestSize.Level2) int32_t timeoutMs = -1; uint32_t lockActionCount = 0; uint32_t unlockActionCount = 0; - uint32_t PARAM_TWO = 2; auto GetRunningLockInfo = [&](RunningLockType type) { if (type == RunningLockType::RUNNINGLOCK_BACKGROUND_AUDIO) { @@ -294,8 +287,8 @@ HWTEST_F (RunningLockMockTest, RunningLockMockTest004, TestSize.Level2) g_powerService->ReleaseRunningLock(audioToken); g_powerService->ReleaseRunningLock(sportToken); - EXPECT_EQ(lockActionCount, PARAM_TWO); - EXPECT_EQ(unlockActionCount, PARAM_TWO); + EXPECT_EQ(lockActionCount, 2); + EXPECT_EQ(unlockActionCount, 2); POWER_HILOGI(LABEL_TEST, "RunningLockMockTest004 function end!"); } @@ -316,7 +309,6 @@ HWTEST_F (RunningLockMockTest, RunningLockMockTest005, TestSize.Level2) int32_t timeoutMs = -1; uint32_t lockActionCount = 0; uint32_t unlockActionCount = 0; - uint32_t PARAM_TWO = 2; auto GetRunningLockInfo = [&](RunningLockType type) { if (type == RunningLockType::RUNNINGLOCK_BACKGROUND_NAVIGATION) { @@ -355,8 +347,8 @@ HWTEST_F (RunningLockMockTest, RunningLockMockTest005, TestSize.Level2) g_powerService->ReleaseRunningLock(naviToken); g_powerService->ReleaseRunningLock(taskToken); - EXPECT_EQ(lockActionCount, PARAM_TWO); - EXPECT_EQ(unlockActionCount, PARAM_TWO); + EXPECT_EQ(lockActionCount, 2); + EXPECT_EQ(unlockActionCount, 2); POWER_HILOGI(LABEL_TEST, "RunningLockMockTest005 function end!"); } @@ -368,18 +360,13 @@ HWTEST_F (RunningLockMockTest, RunningLockMockTest005, TestSize.Level2) */ HWTEST_F (RunningLockMockTest, RunningLockMockTest006, TestSize.Level2) { - POWER_HILOGI(LABEL_TEST, "RunningLockMockTest006 function start!"); ASSERT_NE(g_powerService, nullptr); ASSERT_NE(g_lockAction, nullptr); - RunningLockInfo runninglockPhone("RunningLockMockPhone6.1", RunningLockType::RUNNINGLOCK_BACKGROUND_PHONE); RunningLockInfo runninglockNotify("RunningLockMockNotify6.1", RunningLockType::RUNNINGLOCK_BACKGROUND_NOTIFICATION); RunningLockInfo runninglockAudio("RunningLockMockAudio6.1", RunningLockType::RUNNINGLOCK_BACKGROUND_AUDIO); - int32_t timeoutMs = 100; uint32_t lockActionCount = 0; uint32_t unlockActionCount = 0; - uint32_t PARAM_THREE = 3; - auto GetRunningLockInfo = [&](RunningLockType type) { RunningLockInfo lockInfo {}; switch (type) { @@ -393,7 +380,6 @@ HWTEST_F (RunningLockMockTest, RunningLockMockTest006, TestSize.Level2) return lockInfo; } }; - EXPECT_CALL(*g_lockAction, Lock(_)).WillRepeatedly([&](const RunningLockParam& param) { lockActionCount++; return RUNNINGLOCK_SUCCESS; @@ -405,30 +391,23 @@ HWTEST_F (RunningLockMockTest, RunningLockMockTest006, TestSize.Level2) unlockActionCount++; return RUNNINGLOCK_SUCCESS; }); - sptr phoneToken = new RunningLockTokenStub(); sptr notifyToken = new RunningLockTokenStub(); sptr audioToken = new RunningLockTokenStub(); - EXPECT_EQ(PowerErrors::ERR_OK, g_powerService->CreateRunningLock(phoneToken, runninglockPhone)); EXPECT_EQ(PowerErrors::ERR_OK, g_powerService->CreateRunningLock(notifyToken, runninglockNotify)); EXPECT_EQ(PowerErrors::ERR_OK, g_powerService->CreateRunningLock(audioToken, runninglockAudio)); - g_powerService->Lock(phoneToken); g_powerService->Lock(notifyToken); g_powerService->Lock(audioToken); - g_powerService->UnLock(phoneToken); g_powerService->UnLock(notifyToken); g_powerService->UnLock(audioToken); - g_powerService->ReleaseRunningLock(phoneToken); g_powerService->ReleaseRunningLock(notifyToken); g_powerService->ReleaseRunningLock(audioToken); - - EXPECT_EQ(lockActionCount, PARAM_THREE); - EXPECT_EQ(unlockActionCount, PARAM_THREE); - POWER_HILOGI(LABEL_TEST, "RunningLockMockTest006 function end!"); + EXPECT_EQ(lockActionCount, 3); + EXPECT_EQ(unlockActionCount, 3); } /** @@ -439,18 +418,13 @@ HWTEST_F (RunningLockMockTest, RunningLockMockTest006, TestSize.Level2) */ HWTEST_F (RunningLockMockTest, RunningLockMockTest007, TestSize.Level2) { - POWER_HILOGI(LABEL_TEST, "RunningLockMockTest007 function start!"); ASSERT_NE(g_powerService, nullptr); ASSERT_NE(g_lockAction, nullptr); - RunningLockInfo runninglockSport("RunningLockMockSport7.1", RunningLockType::RUNNINGLOCK_BACKGROUND_SPORT); RunningLockInfo runninglockNavi("RunningLockMockNavi7.1", RunningLockType::RUNNINGLOCK_BACKGROUND_NAVIGATION); RunningLockInfo runninglockTask("RunningLockMockTask7.1", RunningLockType::RUNNINGLOCK_BACKGROUND_TASK); - int32_t timeoutMs = 100; uint32_t lockActionCount = 0; uint32_t unlockActionCount = 0; - uint32_t PARAM_THREE = 3; - auto GetRunningLockInfo = [&](RunningLockType type) { RunningLockInfo lockInfo {}; switch (type) { @@ -464,7 +438,6 @@ HWTEST_F (RunningLockMockTest, RunningLockMockTest007, TestSize.Level2) return lockInfo; } }; - EXPECT_CALL(*g_lockAction, Lock(_)).WillRepeatedly([&](const RunningLockParam& param) { lockActionCount++; return RUNNINGLOCK_SUCCESS; @@ -476,30 +449,23 @@ HWTEST_F (RunningLockMockTest, RunningLockMockTest007, TestSize.Level2) unlockActionCount++; return RUNNINGLOCK_SUCCESS; }); - sptr sportToken = new RunningLockTokenStub(); sptr naviToken = new RunningLockTokenStub(); sptr taskToken = new RunningLockTokenStub(); - EXPECT_EQ(PowerErrors::ERR_OK, g_powerService->CreateRunningLock(sportToken, runninglockSport)); EXPECT_EQ(PowerErrors::ERR_OK, g_powerService->CreateRunningLock(naviToken, runninglockNavi)); EXPECT_EQ(PowerErrors::ERR_OK, g_powerService->CreateRunningLock(taskToken, runninglockTask)); - g_powerService->Lock(sportToken); g_powerService->Lock(naviToken); g_powerService->Lock(taskToken); - g_powerService->UnLock(sportToken); g_powerService->UnLock(naviToken); g_powerService->UnLock(taskToken); - g_powerService->ReleaseRunningLock(sportToken); g_powerService->ReleaseRunningLock(naviToken); g_powerService->ReleaseRunningLock(taskToken); - - EXPECT_EQ(lockActionCount, PARAM_THREE); - EXPECT_EQ(unlockActionCount, PARAM_THREE); - POWER_HILOGI(LABEL_TEST, "RunningLockMockTest007 function end!"); + EXPECT_EQ(lockActionCount, 3); + EXPECT_EQ(unlockActionCount, 3); } /** @@ -518,8 +484,6 @@ HWTEST_F (RunningLockMockTest, RunningLockMockTest008, TestSize.Level2) auto runningLockMgr = g_powerService->GetRunningLockMgr(); uint32_t lockActionCount = 0; uint32_t unlockActionCount = 0; - uint32_t PARAM_ONE = 1; - uint32_t PARAM_TWO = 2; pid_t curUid = getuid(); pid_t curPid = getpid(); @@ -543,21 +507,21 @@ HWTEST_F (RunningLockMockTest, RunningLockMockTest008, TestSize.Level2) ASSERT_NE(backgroundLock, nullptr); g_powerService->Lock(runninglockToken); EXPECT_TRUE(backgroundLock->GetState() == RunningLockState::RUNNINGLOCK_STATE_ENABLE); - EXPECT_EQ(lockActionCount, PARAM_ONE); + EXPECT_EQ(lockActionCount, 1); EXPECT_TRUE(g_powerService->ProxyRunningLock(true, curPid, curUid)); EXPECT_TRUE(backgroundLock->GetState() == RunningLockState::RUNNINGLOCK_STATE_PROXIED); - EXPECT_EQ(unlockActionCount, PARAM_ONE); + EXPECT_EQ(unlockActionCount, 1); EXPECT_TRUE(g_powerService->ProxyRunningLock(false, curPid, curUid)); EXPECT_TRUE(backgroundLock->GetState() == RunningLockState::RUNNINGLOCK_STATE_ENABLE); - EXPECT_EQ(lockActionCount, PARAM_TWO); + EXPECT_EQ(lockActionCount, 2); g_powerService->UnLock(runninglockToken); g_powerService->ReleaseRunningLock(runninglockToken); - EXPECT_EQ(unlockActionCount, PARAM_TWO); + EXPECT_EQ(unlockActionCount, 2); POWER_HILOGI(LABEL_TEST, "RunningLockMockTest008 function end!"); } @@ -637,22 +601,16 @@ HWTEST_F (RunningLockMockTest, RunningLockMockTest009, TestSize.Level2) */ HWTEST_F (RunningLockMockTest, RunningLockMockTest010, TestSize.Level2) { - POWER_HILOGI(LABEL_TEST, "RunningLockMockTest010 function start!"); ASSERT_NE(g_powerService, nullptr); ASSERT_NE(g_lockAction, nullptr); - RunningLockInfo runninglockAudio("RunningLockMockAudio10.1", RunningLockType::RUNNINGLOCK_BACKGROUND_AUDIO); RunningLockInfo runninglockSport("RunningLockMockSport10.1", RunningLockType::RUNNINGLOCK_BACKGROUND_SPORT); auto runningLockMgr = g_powerService->GetRunningLockMgr(); uint32_t lockActionCount = 0; uint32_t unlockActionCount = 0; - uint32_t PARAM_TWO = 2; - uint32_t PARAM_FOUR = 4; - auto GetRunningLockInfo = [&](RunningLockType type) { return type == RunningLockType::RUNNINGLOCK_BACKGROUND_AUDIO ? runninglockAudio : runninglockSport; }; - EXPECT_CALL(*g_lockAction, Lock(_)).WillRepeatedly([&](const RunningLockParam& param) { RunningLockInfo runninglockInfo = GetRunningLockInfo(param.type); EXPECT_EQ(param.name, runninglockInfo.name); @@ -668,37 +626,29 @@ HWTEST_F (RunningLockMockTest, RunningLockMockTest010, TestSize.Level2) unlockActionCount++; return RUNNINGLOCK_SUCCESS; }); - sptr audioToken = new RunningLockTokenStub(); sptr sportToken = new RunningLockTokenStub(); EXPECT_EQ(PowerErrors::ERR_OK, g_powerService->CreateRunningLock(audioToken, runninglockAudio)); EXPECT_EQ(PowerErrors::ERR_OK, g_powerService->CreateRunningLock(sportToken, runninglockSport)); auto audioLock = runningLockMgr->GetRunningLockInner(audioToken); auto sportLock = runningLockMgr->GetRunningLockInner(sportToken); - g_powerService->Lock(audioToken); g_powerService->Lock(sportToken); - EXPECT_EQ(lockActionCount, PARAM_TWO); + EXPECT_EQ(lockActionCount, 2); EXPECT_TRUE(audioLock->GetState() == RunningLockState::RUNNINGLOCK_STATE_ENABLE); EXPECT_TRUE(sportLock->GetState() == RunningLockState::RUNNINGLOCK_STATE_ENABLE); - EXPECT_TRUE(g_powerService->ProxyRunningLock(true, getpid(), getuid())); - - EXPECT_EQ(unlockActionCount, PARAM_TWO); + EXPECT_EQ(unlockActionCount, 2); EXPECT_TRUE(audioLock->GetState() == RunningLockState::RUNNINGLOCK_STATE_PROXIED); EXPECT_TRUE(sportLock->GetState() == RunningLockState::RUNNINGLOCK_STATE_PROXIED); - EXPECT_TRUE(g_powerService->ProxyRunningLock(false, getpid(), getuid())); - - EXPECT_EQ(lockActionCount, PARAM_FOUR); + EXPECT_EQ(lockActionCount, 4); EXPECT_TRUE(audioLock->GetState() == RunningLockState::RUNNINGLOCK_STATE_ENABLE); EXPECT_TRUE(sportLock->GetState() == RunningLockState::RUNNINGLOCK_STATE_ENABLE); - g_powerService->UnLock(audioToken); g_powerService->UnLock(sportToken); g_powerService->ReleaseRunningLock(audioToken); g_powerService->ReleaseRunningLock(sportToken); - POWER_HILOGI(LABEL_TEST, "RunningLockMockTest010 function end!"); } /** @@ -717,8 +667,6 @@ HWTEST_F (RunningLockMockTest, RunningLockMockTest011, TestSize.Level2) auto runningLockMgr = g_powerService->GetRunningLockMgr(); uint32_t lockActionCount = 0; uint32_t unlockActionCount = 0; - uint32_t PARAM_ONE = 1; - int32_t timeoutMs = -1; pid_t curUid = getuid(); pid_t curPid = getpid(); @@ -742,17 +690,17 @@ HWTEST_F (RunningLockMockTest, RunningLockMockTest011, TestSize.Level2) auto naviLock = runningLockMgr->GetRunningLockInner(naviToken); g_powerService->Lock(naviToken); - EXPECT_EQ(lockActionCount, PARAM_ONE); + EXPECT_EQ(lockActionCount, 1); EXPECT_TRUE(naviLock->GetState() == RunningLockState::RUNNINGLOCK_STATE_ENABLE); EXPECT_TRUE(g_powerService->ProxyRunningLock(true, curPid, curUid)); - EXPECT_EQ(unlockActionCount, PARAM_ONE); + EXPECT_EQ(unlockActionCount, 1); EXPECT_TRUE(naviLock->GetState() == RunningLockState::RUNNINGLOCK_STATE_PROXIED); EXPECT_TRUE(g_powerService->ProxyRunningLock(false, curPid, curUid)); - EXPECT_EQ(lockActionCount, PARAM_ONE); + EXPECT_EQ(lockActionCount, 1); EXPECT_TRUE(naviLock->GetState() == RunningLockState::RUNNINGLOCK_STATE_ENABLE); g_powerService->UnLock(naviToken); @@ -777,8 +725,6 @@ HWTEST_F (RunningLockMockTest, RunningLockMockTest012, TestSize.Level2) uint32_t lockActionCount = 0; uint32_t unlockActionCount = 0; int32_t timeoutMs = -1; - uint32_t PARAM_ONE = 1; - uint32_t PARAM_TWO = 2; pid_t curUid = getuid(); pid_t curPid = getpid(); @@ -801,17 +747,17 @@ HWTEST_F (RunningLockMockTest, RunningLockMockTest012, TestSize.Level2) auto taskLock = runningLockMgr->GetRunningLockInner(taskToken); g_powerService->Lock(taskToken); - EXPECT_EQ(lockActionCount, PARAM_ONE); + EXPECT_EQ(lockActionCount, 1); EXPECT_TRUE(taskLock->GetState() == RunningLockState::RUNNINGLOCK_STATE_ENABLE); EXPECT_TRUE(g_powerService->ProxyRunningLocks(true, {std::make_pair(curPid, curUid)})); - EXPECT_EQ(unlockActionCount, PARAM_ONE); + EXPECT_EQ(unlockActionCount, 1); EXPECT_TRUE(taskLock->GetState() == RunningLockState::RUNNINGLOCK_STATE_PROXIED); EXPECT_TRUE(g_powerService->ProxyRunningLocks(false, {std::make_pair(curPid, curUid)})); - EXPECT_EQ(lockActionCount, PARAM_TWO); + EXPECT_EQ(lockActionCount, 2); EXPECT_TRUE(taskLock->GetState() == RunningLockState::RUNNINGLOCK_STATE_ENABLE); g_powerService->UnLock(taskToken); @@ -836,7 +782,6 @@ HWTEST_F (RunningLockMockTest, RunningLockMockTest013, TestSize.Level2) uint32_t lockActionCount = 0; uint32_t unlockActionCount = 0; int32_t timeoutMs = -1; - uint32_t PARAM_ONE = 1; pid_t curUid = getuid(); pid_t curPid = getpid(); @@ -859,12 +804,12 @@ HWTEST_F (RunningLockMockTest, RunningLockMockTest013, TestSize.Level2) auto taskLock = runningLockMgr->GetRunningLockInner(taskToken); g_powerService->Lock(taskToken); - EXPECT_EQ(lockActionCount, PARAM_ONE); + EXPECT_EQ(lockActionCount, 1); EXPECT_TRUE(taskLock->GetState() == RunningLockState::RUNNINGLOCK_STATE_ENABLE); EXPECT_TRUE(g_powerService->ProxyRunningLock(true, curPid, curUid)); - EXPECT_EQ(unlockActionCount, PARAM_ONE); + EXPECT_EQ(unlockActionCount, 1); EXPECT_TRUE(taskLock->GetState() == RunningLockState::RUNNINGLOCK_STATE_PROXIED); g_powerService->UnLock(taskToken); @@ -873,7 +818,7 @@ HWTEST_F (RunningLockMockTest, RunningLockMockTest013, TestSize.Level2) EXPECT_TRUE(g_powerService->ProxyRunningLock(false, curPid, curUid)); - EXPECT_EQ(lockActionCount, PARAM_ONE); + EXPECT_EQ(lockActionCount, 1); POWER_HILOGI(LABEL_TEST, "RunningLockMockTest013 function end!"); } } diff --git a/test/unittest/src/scenario_test/proximity_controller/running_lock_mgr_abnormal_test.cpp b/test/unittest/src/scenario_test/proximity_controller/running_lock_mgr_abnormal_test.cpp index 81f75bb9c548a4533eb8095fd691406da996145e..524702c12b675d0e9328a95777fd075b0ff72ffb 100644 --- a/test/unittest/src/scenario_test/proximity_controller/running_lock_mgr_abnormal_test.cpp +++ b/test/unittest/src/scenario_test/proximity_controller/running_lock_mgr_abnormal_test.cpp @@ -40,7 +40,7 @@ void SetInstanceReal() } } // namespace -#ifdef POWER_MANAGER_INIT_PROXIMITY_CONTROLLER +#ifdef POWER_MANAGER_PROXIMITY_CONTROLLER_OVERRIDE int HookMgrExecute(HOOK_MGR* hookMgr, int stage, void* context, const HOOK_EXEC_OPTIONS* options) { if (static_cast(stage) == PowerHookStage::POWER_PROXIMITY_CONTROLLER_INIT) { @@ -322,7 +322,7 @@ HWTEST_F(RunningLockMgrAbnormalTest, RunningLockMgrAbnormalTest007, TestSize.Lev * @tc.type: FUNC * @tc.require: ICGV1M */ -#ifdef POWER_MANAGER_INIT_PROXIMITY_CONTROLLER +#ifdef POWER_MANAGER_PROXIMITY_CONTROLLER_OVERRIDE HWTEST_F(RunningLockMgrAbnormalTest, RunningLockMgrAbnormalTest008, TestSize.Level1) { POWER_HILOGI(LABEL_TEST, "RunningLockMgrAbnormalTest008 function start!"); @@ -350,19 +350,4 @@ HWTEST_F(RunningLockMgrAbnormalTest, RunningLockMgrAbnormalTest008, TestSize.Lev POWER_HILOGI(LABEL_TEST, "RunningLockMgrAbnormalTest008 function end!"); } #endif - -/** - * @tc.name: RunningLockMgrAbnormalTest009 - * @tc.desc: Test SuspendController pms == nullptr - * @tc.type: FUNC - * @tc.require: ICGV1M - */ -HWTEST_F(RunningLockMgrAbnormalTest, RunningLockMgrAbnormalTest009, TestSize.Level1) -{ - POWER_HILOGI(LABEL_TEST, "RunningLockMgrAbnormalTest009 function start!"); - auto suspendController = std::make_shared(nullptr, nullptr, nullptr); - EXPECT_TRUE(suspendController->NeedToSkipCurrentSuspend( - SuspendDeviceType::SUSPEND_DEVICE_REASON_POWER_KEY, 0, 0)); - POWER_HILOGI(LABEL_TEST, "RunningLockMgrAbnormalTest009 function end!"); -} } // namespace \ No newline at end of file diff --git a/test/unittest/src/servicetest/powermgr_service_test_proxy.cpp b/test/unittest/src/servicetest/powermgr_service_test_proxy.cpp index 4c4f03223ed430374ac2d32b413bd6c0521c945d..a704a79a92aae29a5466e4d7723dd3cd34a6a4af 100644 --- a/test/unittest/src/servicetest/powermgr_service_test_proxy.cpp +++ b/test/unittest/src/servicetest/powermgr_service_test_proxy.cpp @@ -1115,58 +1115,6 @@ int32_t PowerMgrServiceTestProxy::UnRegisterRunningLockCallbackIpc(const sptr& callback) -{ - RETURN_IF_WITH_RET((stub_ == nullptr || (callback == nullptr)), false); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_SUSPEND, "Write descriptor failed"); - return false; - } - - data.WriteRemoteObject(callback->AsObject()); - - int ret = stub_->OnRemoteRequest( - static_cast(IPowerMgrIpcCode::COMMAND_REGISTER_SUSPEND_TAKEOVER_CALLBACK_IPC), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_SUSPEND, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; - } - return true; -} - -bool PowerMgrServiceTestProxy::UnRegisterSuspendTakeoverCallbackIpc(const sptr& callback) -{ - RETURN_IF_WITH_RET((stub_ == nullptr || (callback == nullptr)), false); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_SUSPEND, "Write descriptor failed"); - return false; - } - - data.WriteRemoteObject(callback->AsObject()); - - int ret = stub_->OnRemoteRequest( - static_cast(IPowerMgrIpcCode::COMMAND_UN_REGISTER_SUSPEND_TAKEOVER_CALLBACK_IPC), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_SUSPEND, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; - } - return true; -} -#endif - int32_t PowerMgrServiceTestProxy::SetDisplaySuspendIpc(bool enable) { RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); diff --git a/utils/hookmgr/include/power_hookmgr.h b/utils/hookmgr/include/power_hookmgr.h index 3df0fd696557046bfd09777c877fe8f95bfc123e..1e37d02d8a88fba9dcb705f435ca8cd1a00c5194 100644 --- a/utils/hookmgr/include/power_hookmgr.h +++ b/utils/hookmgr/include/power_hookmgr.h @@ -19,6 +19,7 @@ #include #include #include +#include #include "modulemgr.h" #include "iproximity_controller.h" diff --git a/utils/lib_loader/src/library_loader.cpp b/utils/lib_loader/src/library_loader.cpp index f0d0d1eb0bc39792bb40ea828202c230582fec44..ce1b6ef0931ed18d6692db2a6ba06184002b1c3d 100644 --- a/utils/lib_loader/src/library_loader.cpp +++ b/utils/lib_loader/src/library_loader.cpp @@ -59,8 +59,8 @@ void* LibraryLoader::LoadInterface(const char* symbolName) if (funcPtr != nullptr) { return funcPtr; } - POWER_HILOGE(COMP_SVC, "Failed to dlsym %{public}s, reason: %{public}s, try again(%{public}u)", - libPath_.c_str(), dlerror(), i + 1); + POWER_HILOGE(COMP_SVC, "Failed to dlsym %{public}s, reason: %{public}s, try again(%{public}u)", symbolName, + dlerror(), i + 1); } return nullptr; } diff --git a/utils/native/include/power_log.h b/utils/native/include/power_log.h index b3a065aaf2c436847627cf6c88b0ae8f0a3d3b59..29e0d2fcb5d57de6ebc2ca4cb0c8732fa3e69245 100644 --- a/utils/native/include/power_log.h +++ b/utils/native/include/power_log.h @@ -126,7 +126,7 @@ enum PowerManagerLogDomain { }; struct PowerManagerLogLabelDomain { - unsigned int domainId; + uint32_t domainId; const char* tag; }; diff --git a/utils/setting/BUILD.gn b/utils/setting/BUILD.gn index a7cc7d8a834ea5dda26d3c95be2f090c27279fc3..ec267ec66b9c7ecb44df7c9dba0e9a02dcdf4258 100644 --- a/utils/setting/BUILD.gn +++ b/utils/setting/BUILD.gn @@ -51,6 +51,8 @@ ohos_shared_library("power_setting") { "samgr:samgr_proxy", ] + defines = [] + if (power_manager_feature_charging_type_setting) { defines += [ "POWER_MANAGER_ENABLE_CHARGING_TYPE_SETTING" ] }