proxy_;
bool CheckUsedNoLock();
diff --git a/interfaces/kits/js/@ohos.power.d.ts b/interfaces/kits/js/@ohos.power.d.ts
index 042b39bd052142dfe9a5f70e94f1232e594123de..9d1d90d18872c0fcf15700cfb5148b86a1399717 100644
--- a/interfaces/kits/js/@ohos.power.d.ts
+++ b/interfaces/kits/js/@ohos.power.d.ts
@@ -19,8 +19,8 @@ import {AsyncCallback} from './basic';
* Provides interfaces to manage power.
*
* @SysCap SystemCapability.PowerMgr.PowerManager
- * @devices phone, tablet
- * @since 6
+ * @devices phone, tablet, tv, wearable
+ * @since 7
*/
declare namespace power {
/**
@@ -29,9 +29,10 @@ declare namespace power {
* This method requires the ohos.permission.SHUTDOWN permission.
*
* @param reason Indicates the shutdown reason.
- * @since 6
+ * @systemapi
+ * @since 7
*/
- function shutownDevice(reason: string): void;
+ function shutdownDevice(reason: string): void;
/**
* Restarts the system.
@@ -40,7 +41,7 @@ declare namespace power {
*
* @param reason Indicates the restart reason. For example, "recovery" indicates entering the recovery mode
* after the restart. If the parameter is not specified, the system enters the normal mode after the restart.
- * @since 6
+ * @since 7
*/
function rebootDevice(reason: string): void;
@@ -48,7 +49,7 @@ declare namespace power {
* Checks whether the screen of a device is on or off.
*
* @return Returns true if the screen is on; returns false otherwise.
- * @since 6
+ * @since 7
*/
function isScreenOn(callback: AsyncCallback): void;
function isScreenOn(): Promise;
diff --git a/interfaces/kits/js/@ohos.runninglock.d.ts b/interfaces/kits/js/@ohos.runninglock.d.ts
index 6e363fc7ba96a4e07ea3a5bca3a5a7474b56aaa7..808ea5f13d328919cec4621a25e6149f2fd8a5d1 100644
--- a/interfaces/kits/js/@ohos.runninglock.d.ts
+++ b/interfaces/kits/js/@ohos.runninglock.d.ts
@@ -25,18 +25,17 @@ import {AsyncCallback} from './basic.d.ts';
* RunningLock} is set.
*
* @SysCap SystemCapability.PowerMgr.PowerManager
- * @devices phone, tablet
- * @since 6
+ * @devices phone, tablet, tv, wearable
+ * @since 7
*/
declare namespace runningLock {
-
class RunningLock {
/**
* Prevents the system from hibernating and sets the lock duration.
*
* @param timeout Indicates the lock duration (ms). After the lock duration times out, the lock is automatically
* released and the system hibernates if no other {@link RunningLock} is set.
- * @since 6
+ * @since 7
*/
function lock(timeout: number): void;
@@ -44,14 +43,14 @@ declare namespace runningLock {
* Checks whether a lock is held or in use.
*
* @return Returns true if the lock is held or in use; returns false if the lock has been released.
- * @since 6
+ * @since 7
*/
function isUsed(): boolean;
/**
* Release the {@link RunningLock} that prevents the system from hibernating.
*
- * @since 6
+ * @since 7
*/
function unlock(): void;
}
@@ -63,7 +62,7 @@ declare namespace runningLock {
* {@link BACKGROUND} ensures that applications can run in the background.
* {@link PROXIMITY_SCREEN_CONTROL} determines whether to turn on or off the screen based on the proximity sensor.
*
- * @since 6
+ * @since 7
*/
export enum RunningLockType {
/**
@@ -85,7 +84,7 @@ declare namespace runningLock {
* @param type Indicates the specified {@link RunningLockType}.
* @return Returns true if the specified {@link RunningLockType} is supported;
* returns false otherwise.
- * @since 6
+ * @since 7
*/
function isRunningLockTypeSupported(type: RunningLockType, callback: AsyncCallback): void;
function isRunningLockTypeSupported(type: RunningLockType): Promise;
@@ -100,7 +99,7 @@ declare namespace runningLock {
* a suffix.
* @param type Indicates the {@link RunningLockType}.
* @return Returns the {@link RunningLock} object.
- * @since 6
+ * @since 7
*/
function createRunningLock(name: string, type: RunningLockType, callback: AsyncCallback): void;
function createRunningLock(name: string, type: RunningLockType): Promise;
diff --git a/ohos.build b/ohos.build
index 79b3bcced20e9eefc8c25fd97352b8433aaa9734..c48be5c0f0fcdca20ad38496b481455fa47e1cde 100644
--- a/ohos.build
+++ b/ohos.build
@@ -4,8 +4,12 @@
"power_manager_native": {
"module_list": [
"//base/powermgr/power_manager/interfaces/innerkits:powermgr_client",
+ "//base/powermgr/power_manager/frameworks/napi/power:power",
+ "//base/powermgr/power_manager/frameworks/napi/runninglock:runninglock",
"//base/powermgr/power_manager/sa_profile:powermgr_sa_profile",
- "//base/powermgr/power_manager/services:powermgrservice"
+ "//base/powermgr/power_manager/services:powermgrservice",
+ "//base/powermgr/power_manager/hdi:hdi_group",
+ "//base/powermgr/power_manager/services:power_service"
],
"inner_kits": [
{
@@ -26,7 +30,8 @@
}
],
"test_list": [
- "//base/powermgr/power_manager/services/native/test:powermgr_test"
+ "//base/powermgr/power_manager/services/native/test:powermgr_test",
+ "//base/powermgr/power_manager/test:systemtest"
]
}
}
diff --git a/powermgr.gni b/powermgr.gni
index c9a674986a44d780314551bceb458b425fb0c463..6064d0282e382d72bd08fdf0bb317488ef98fc32 100644
--- a/powermgr.gni
+++ b/powermgr.gni
@@ -19,6 +19,10 @@ powermgr_root_path = "//base/powermgr/power_manager"
powermgr_service_path = "${powermgr_root_path}/services"
+powermgr_framework_path = "${powermgr_root_path}/frameworks"
+
+powermgr_hdi_path = "${powermgr_root_path}/hdi"
+
powermgr_interfaces_path = "${powermgr_root_path}/interfaces"
powermgr_native_innerkits_path = "${powermgr_interfaces_path}/innerkits"
diff --git a/services/BUILD.gn b/services/BUILD.gn
index 6d240a2462520abf06bb4dbb507d38f09c147fcf..0992420b72759db0e76aebdb84ce62cbf6933481 100644
--- a/services/BUILD.gn
+++ b/services/BUILD.gn
@@ -38,6 +38,11 @@ ohos_shared_library("powermgrservice") {
"native/src/shutdown_service.cpp",
"zidl/src/power_mgr_stub.cpp",
"zidl/src/power_state_callback_stub.cpp",
+ "zidl/src/power_shutdown_callback_stub.cpp",
+ "zidl/src/power_mode_callback_stub.cpp",
+ "native/src/power_mode_policy.cpp",
+ "native/src/power_mode_module.cpp",
+ "native/src/power_save_model.cpp",
]
configs = [
@@ -52,6 +57,7 @@ ohos_shared_library("powermgrservice") {
"${powermgr_utils_path}:powermgr_utils",
"native/src/actions:powermgr_actions",
"//utils/native/base:utils",
+ "//drivers/peripheral/display/hal:hdi_display_device",
]
external_deps = [
@@ -69,3 +75,9 @@ ohos_shared_library("powermgrservice") {
part_name = "${powermgr_native_part_name}"
}
+
+group("power_service") {
+ deps = [
+ "native/profile:power_mode_config"
+ ]
+}
diff --git a/services/native/include/actions/idevice_state_action.h b/services/native/include/actions/idevice_state_action.h
index 9289012c59fd75830f493d6dca76e887209198f6..0debe62013e13cdc5a0bd741a715e8225b52b3fa 100644
--- a/services/native/include/actions/idevice_state_action.h
+++ b/services/native/include/actions/idevice_state_action.h
@@ -22,6 +22,12 @@
namespace OHOS {
namespace PowerMgr {
+
+enum ActionResult {
+ SUCCESS = 0,
+ FAILED = 1,
+};
+
class IDeviceStateAction {
public:
IDeviceStateAction() = default;
@@ -32,6 +38,9 @@ public:
virtual void Wakeup(int64_t callTimeMs, WakeupDeviceType type, const std::string& details,
const std::string& pkgName) = 0;
virtual void RefreshActivity(int64_t callTimeMs, UserActivityType type, uint32_t flags) = 0;
+ virtual DisplayState GetDisplayState() = 0;
+ virtual uint32_t SetDisplayState(DisplayState state) = 0;
+ virtual uint32_t GoToSleep(std::function onSuspend, std::function onWakeup, bool force) = 0;
};
} // namespace PowerMgr
} // namespace OHOS
diff --git a/services/native/include/actions/irunning_lock_action.h b/services/native/include/actions/irunning_lock_action.h
index 89b80058d76a2383a41dfcdb9f476e145f6c7a4b..36d0aaccda9df8d698e346a8ef4d4756b65f1a0d 100644
--- a/services/native/include/actions/irunning_lock_action.h
+++ b/services/native/include/actions/irunning_lock_action.h
@@ -34,8 +34,8 @@ public:
return LOCK_TAGS[ToUnderlying(type)];
}
- void Acquire(RunningLockType type);
- void Release(RunningLockType type);
+ virtual void Acquire(RunningLockType type);
+ virtual void Release(RunningLockType type);
virtual void Lock(RunningLockType type, const std::string& tag) = 0;
virtual void Unlock(RunningLockType type, const std::string& tag) = 0;
diff --git a/services/native/include/power_mgr_service.h b/services/native/include/power_mgr_service.h
index e7647fc37dfa69376ec7308129add4133baa7f88..79fd4388802d4a921f35504d9eadff4d2bbdd5e3 100644
--- a/services/native/include/power_mgr_service.h
+++ b/services/native/include/power_mgr_service.h
@@ -28,6 +28,10 @@
#include "running_lock_mgr.h"
#include "shutdown_service.h"
#include "sp_singleton.h"
+#include "power_mode_module.h"
+#include "power_save_model.h"
+
+#define APP_FIRST_UID_VALUE 10000
namespace OHOS {
namespace PowerMgr {
@@ -45,8 +49,12 @@ public:
virtual void SuspendDevice(int64_t callTimeMs, SuspendDeviceType reason, bool suspendImmed) override;
virtual void WakeupDevice(int64_t callTimeMs, WakeupDeviceType reason, const std::string& details) override;
virtual void RefreshActivity(int64_t callTimeMs, UserActivityType type, bool needChangeBacklight) override;
+ virtual PowerState GetState() override;
virtual bool IsScreenOn() override;
virtual bool ForceSuspendDevice(int64_t callTimeMs) override;
+ virtual void CreateRunningLock(const sptr& token, const RunningLockInfo& runningLockInfo) override;
+ virtual void ReleaseRunningLock(const sptr& token) override;
+ virtual bool IsRunningLockTypeSupported(uint32_t type) override;
void Lock(const sptr& token, const RunningLockInfo& runningLockInfo, uint32_t timeOutMS) override;
void UnLock(const sptr& token) override;
void ForceUnLock(const sptr& token);
@@ -57,6 +65,10 @@ public:
void UnRegisterPowerStateCallback(const sptr& callback) override;
void RegisterShutdownCallback(const sptr& callback) override;
void UnRegisterShutdownCallback(const sptr& callback) override;
+ void RegisterPowerModeCallback(const sptr& callback) override;
+ void UnRegisterPowerModeCallback(const sptr& callback) override;
+ virtual void SetDeviceMode(const uint32_t& mode) override;
+ virtual uint32_t GetDeviceMode() override;
std::shared_ptr GetHandler() const
{
@@ -82,7 +94,33 @@ public:
{
return ready_;
}
+ void SetDisplayOffTime(int64_t time)
+ {
+ powerStateMachine_->SetDisplayOffTime(time);
+ }
+ void SetSleepTime(int64_t time)
+ {
+ powerStateMachine_->SetSleepTime(time);
+ }
+ void EnableMock(IDeviceStateAction* stateAction, IDevicePowerAction* powerAction,
+ IRunningLockAction* lockAction)
+ {
+ POWER_HILOGE(MODULE_SERVICE, "Service EnableMock:%{public}d", mockCount_++);
+ runningLockMgr_->EnableMock(lockAction);
+ powerStateMachine_->EnableMock(stateAction);
+ shutdownService_.EnableMock(powerAction);
+ }
+ void MockProximity(uint32_t status)
+ {
+ POWER_HILOGE(MODULE_SERVICE, "MockProximity: fun is start");
+ runningLockMgr_->SetProximity(status);
+ POWER_HILOGE(MODULE_SERVICE, "MockProximity: fun is end");
+ }
+ void MockSystemWakeup()
+ {
+ PowerStateMachine::onWakeup();
+ }
private:
bool Init();
bool PowerStateMachineInit();
@@ -96,6 +134,8 @@ private:
std::shared_ptr powerStateMachine_;
std::shared_ptr powerMgrNotify_;
ShutdownService shutdownService_;
+ PowerModeModule powerModeModule_;
+ uint32_t mockCount_{0};
};
} // namespace PowerMgr
} // namespace OHOS
diff --git a/services/native/include/power_mode_module.h b/services/native/include/power_mode_module.h
new file mode 100644
index 0000000000000000000000000000000000000000..93eacbb312b4179eacdb7350a2168c23707ca631
--- /dev/null
+++ b/services/native/include/power_mode_module.h
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "ipower_mode_callback.h"
+
+#ifndef POWER_MODE_THREAD_H
+#define POWER_MODE_THREAD_H
+
+#define FLAG_FALSE -1
+#define LAST_MODE_FLAG 0
+#define SETTINGS_PRIVIDER_VALUE_LCD_BRIGHTNESS 99
+#define SETTINGS_PRIVIDER_VALUE_VIBRATION 1
+#define SETTINGS_PRIVIDER_VALUE_ROTATION 1
+
+namespace OHOS {
+namespace PowerMgr {
+class PowerModeModule {
+public:
+ enum {
+ EXTREAM_MODE = 601,
+ NORMAL_MODE,
+ SAVE_MODE,
+ LOWPOWER_MODE
+ };
+ PowerModeModule();
+ ~PowerModeModule() = default;
+ void SetModeItem(uint32_t mode);
+ uint32_t GetModeItem();
+ void EnableMode(uint32_t mode);
+ void AddPowerModeCallback(const sptr& callback);
+ void DelPowerModeCallback(const sptr& callback);
+
+private:
+ using IntentWant = OHOS::AAFwk::Want;
+
+ class CallbackManager : public IRemoteObject::DeathRecipient {
+ public:
+ void OnRemoteDied(const wptr& remote) override;
+ void AddCallback(const sptr& callback);
+ void RemoveCallback(const sptr& callback);
+ void WaitingCallback();
+
+ private:
+ std::mutex mutex_;
+ std::set> callbacks_;
+ };
+
+ uint32_t mode_;
+ uint32_t lastMode_;
+
+ void Prepare();
+ void PublishPowerModeEvent();
+
+ CallbackManager callbackMgr_;
+ void UpdateModepolicy();
+ void RunAction();
+ void SetLcdBrightness();
+ void SetVibration();
+ void OnOffRotation();
+
+ std::atomic started_;
+ std::map recoverValue;
+ std::map::iterator recoverValueiter;
+ std::mutex mutex_;
+
+};
+} // namespace PowerMgr
+} // namespace OHOS
+#endif //POWER_MODE_THREAD_H
diff --git a/services/native/include/power_mode_policy.h b/services/native/include/power_mode_policy.h
new file mode 100644
index 0000000000000000000000000000000000000000..d5399893af180ff92ffa8560b93cfbf9e2cfb1b6
--- /dev/null
+++ b/services/native/include/power_mode_policy.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef POWER_MODE_POLICY_H
+#define POWER_MODE_POLICY_H
+
+#include
+#include