/* * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef POWERMGR_POWER_MGR_CLIENT_H #define POWERMGR_POWER_MGR_CLIENT_H #include #include #include "power_state_machine_info.h" #include "running_lock.h" namespace OHOS { namespace PowerMgr { class PowerMgrClient final : public DelayedRefSingleton { DECLARE_DELAYED_REF_SINGLETON(PowerMgrClient) public: DISALLOW_COPY_AND_MOVE(PowerMgrClient); static const uint32_t CONNECT_RETRY_COUNT = 5; static const uint32_t CONNECT_RETRY_MS = 800000; /** * Reboot the device. * * @param reason The reason for rebooting the device. e.g.updater */ PowerErrors RebootDevice(const std::string& reason); PowerErrors RebootDeviceForDeprecated(const std::string& reason); /** * Shut down the device. * * @param reason The reason for shutting down the device. * */ PowerErrors ShutDownDevice(const std::string& reason); /** * Suspend device and set screen off. * * @param reason The reason why will you suspend the device, such as timeout/powerkey/forcesuspend and so on. */ PowerErrors SuspendDevice(SuspendDeviceType reason = SuspendDeviceType::SUSPEND_DEVICE_REASON_APPLICATION, bool suspendImmed = false); /** * Wake up the device and set the screen on. * * @param reason The reason for waking up the device, such as powerkey/plugin/application. */ PowerErrors WakeupDevice(WakeupDeviceType reason = WakeupDeviceType::WAKEUP_DEVICE_APPLICATION, const std::string& detail = std::string("app call")); /** * Refresh the screentimeout time, and keep the screen on. RefreshActivity works only when the screen is on. * * @param type The RefreshActivity type, such as touch/button/accessibility and so on. * @param needChangeBacklight Whether to change the backlight state, for example, from DIM to BRIGHT. * Set it to false if you don't want to change the backlight state. */ bool RefreshActivity(UserActivityType type = UserActivityType::USER_ACTIVITY_TYPE_OTHER); /** * Windows overwrite timeout * @param timeout Specifies the timeout duration. */ bool OverrideScreenOffTime(int64_t timeout); /** * Windows restores timeout */ bool RestoreScreenOffTime(); /** * Check whether the device screen is on. The result may be true or false, depending on the system state. */ bool IsScreenOn(); /** * Get Power state. The result is PowerState type. */ PowerState GetState(); /** * Forcibly suspend the device into deepsleep, and return the suspend result. */ bool ForceSuspendDevice(); /** * Check whether the type of running lock is supported */ bool IsRunningLockTypeSupported(RunningLockType type); /** * Enable/disable display suspend state */ bool SetDisplaySuspend(bool enable); /* Set the device mode. * * @param set The mode the device. */ PowerErrors SetDeviceMode(const PowerMode mode); /** * Get the device mode. * * @param Get The mode the device. */ PowerMode GetDeviceMode(); /** * Check if the device has entered standby mode. */ PowerErrors IsStandby(bool& isStandby); /** * Query the list of lock information. */ bool QueryRunningLockLists(std::map& runningLockLists); std::shared_ptr CreateRunningLock(const std::string& name, RunningLockType type); bool ProxyRunningLock(bool isProxied, pid_t pid, pid_t uid); bool ProxyRunningLocks(bool isProxied, const std::vector>& processInfos); bool ResetRunningLocks(); bool RegisterPowerStateCallback(const sptr& callback); bool UnRegisterPowerStateCallback(const sptr& callback); bool RegisterSyncSleepCallback(const sptr& callback, SleepPriority priority); bool UnRegisterSyncSleepCallback(const sptr& callback); bool RegisterPowerModeCallback(const sptr& callback); bool UnRegisterPowerModeCallback(const sptr& callback); void RecoverRunningLocks(); std::string Dump(const std::vector& args); PowerErrors GetError(); #ifndef POWERMGR_SERVICE_DEATH_UT private: #endif class PowerMgrDeathRecipient : public IRemoteObject::DeathRecipient { public: explicit PowerMgrDeathRecipient(PowerMgrClient& client) : client_(client) {} ~PowerMgrDeathRecipient() = default; void OnRemoteDied(const wptr& remote); private: DISALLOW_COPY_AND_MOVE(PowerMgrDeathRecipient); PowerMgrClient& client_; }; ErrCode Connect(); void ResetProxy(const wptr& remote); sptr proxy_ {nullptr}; sptr deathRecipient_ {nullptr}; std::mutex mutex_; static std::vector> runningLocks_; static std::mutex runningLocksMutex_; PowerErrors error_ = PowerErrors::ERR_OK; }; } // namespace PowerMgr } // namespace OHOS #endif // POWERMGR_POWER_MGR_CLIENT_H