diff --git a/bundle.json b/bundle.json index dd669f357b451d60de8c664afccf101c279cd355..cd6d0a710a7d63a75f1ba8d3ecd652033bce8c2b 100644 --- a/bundle.json +++ b/bundle.json @@ -40,7 +40,12 @@ "safwk", "samgr", "sensor", - "time_service" + "time_service", + "call_manager", + "netmanager_base", + "wifi", + "work_scheduler", + "background_task_mgr" ], "third_party": [ "googletest" @@ -83,13 +88,16 @@ "header": { "header_base": "//foundation/resourceschedule/device_standby/services", "header_files": [ + "common/include/background_task_helper.h", "common/include/device_standby_switch.h", "common/include/time_provider.h", "common/include/timed_task.h", "core/include/ability_manager_helper.h", "core/include/allow_record.h", "core/include/app_mgr_helper.h", + "core/include/app_state_observer.h", "core/include/bundle_manager_helper.h", + "core/include/common_event_observer.h", "core/include/standby_service_impl.h", "core/include/standby_service.h", "notification/include/standby_state_subscriber.h" @@ -146,10 +154,7 @@ "standby_state/include/state_manager_adapter.h", "standby_state/include/working_state.h", "strategy/include/network_strategy.h", - "strategy/include/running_lock_strategy.h", - "strategy/include/strategy_manager_adapter.h", - "strategy/include/timer_strategy.h", - "strategy/include/work_scheduler_strategy.h" + "strategy/include/strategy_manager_adapter.h" ] }, "name": "//foundation/resourceschedule/device_standby/plugins:standby_plugin" diff --git a/frameworks/include/istandby_ipc_inteface_code.h b/frameworks/include/istandby_ipc_inteface_code.h new file mode 100644 index 0000000000000000000000000000000000000000..fcac47c6e44ff26a2174cc106be07f956745b8d2 --- /dev/null +++ b/frameworks/include/istandby_ipc_inteface_code.h @@ -0,0 +1,38 @@ +/* + * 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 FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_FRAMEWORKS_INCLUDE_ISTANDBY_IPC_INTERFACE_CODE_H +#define FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_FRAMEWORKS_INCLUDE_ISTANDBY_IPC_INTERFACE_CODE_H + +#include + +/* SAID: 1914 */ +namespace OHOS { +namespace DevStandbyMgr { + enum class IStandbyInterfaceCode { + SUBSCRIBE_STANDBY_CALLBACK = MIN_TRANSACTION_ID, + UNSUBSCRIBE_STANDBY_CALLBACK, + APPLY_ALLOW_RESOURCE, + UNAPPLY_ALLOW_RESOURCE, + GET_ALLOW_LIST, + IS_DEVICE_IN_STANDBY, + REPORT_WORK_SCHEDULER_STATUS, + GET_RESTRICT_LIST, + IS_STRATEGY_ENABLED, + REPORT_DEVICE_STATE_CHANGED, + }; +} // namespace DevStandbyMgr +} // namespace OHOS +#endif // FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_FRAMEWORKS_INCLUDE_ISTANDBY_IPC_INTERFACE_CODE_H \ No newline at end of file diff --git a/frameworks/include/istandby_service.h b/frameworks/include/istandby_service.h index 27fd2df55ecf3e2b1b630e0ce8a6666fb4ffd030..62edaafb79522c59ad8c301d8175fe0f06b0c310 100644 --- a/frameworks/include/istandby_service.h +++ b/frameworks/include/istandby_service.h @@ -30,6 +30,11 @@ namespace OHOS { namespace DevStandbyMgr { +enum class DeviceStateType: int32_t { + DIS_COMP_CHANGE = 0, + TELEPHONE_STATE_CHANGE, + WIFI_P2P_CHANGE, +}; class IStandbyService : public IRemoteBroker { public: @@ -80,6 +85,45 @@ public: virtual ErrCode GetAllowList(uint32_t allowType, std::vector& allowInfoList, uint32_t reasonCode) = 0; + /** + * @brief Get the Restrict List object. + * + * @param restrictType the restrict type to be retrieved. + * @param restrictInfoList result represents restricted types and apps. + * @param reasonCode represents the reason why invoke the api. + * @return ErrCode ERR_OK if success, others if fail. + */ + virtual ErrCode GetRestrictList(uint32_t restrictType, std::vector& restrictInfoList, + uint32_t reasonCode) = 0; + + /** + * @brief Construct a new Report Work Scheduler Status object. + * + * @param started true if the work is triggered, else false. + * @param uid uid of the applicatoin. + * @param bundleName bundleName of the application. + * @return ErrCode ERR_OK if success, others if fail. + */ + virtual ErrCode ReportWorkSchedulerStatus(bool started, int32_t uid, const std::string& bundleName) = 0; + + /** + * @brief Whether the restriction strategy enbaled or not. + * + * @param strategyName the strategy name. + * @param enabled true if the strategy is enabled. + * @return ErrCode ERR_OK if success, others if fail. + */ + virtual ErrCode IsStrategyEnabled(const std::string& strategyName, bool& isEnabled) = 0; + + /** + * @brief Report event when device state change, such as discomponent device, bluetooth socket. + * + * @param type type of device state. + * @param enabled true if the device state is on. + * @return ErrCode ERR_OK if success, others if fail. + */ + virtual ErrCode ReportDeviceStateChanged(DeviceStateType type, bool enabled) = 0; + /** * @brief query if the device is in standby mode. * @@ -87,6 +131,7 @@ public: * @return ErrCode ERR_OK if success, others if fail. */ virtual ErrCode IsDeviceInStandby(bool& isStandby) = 0; + public: DECLARE_INTERFACE_DESCRIPTOR(u"ohos.resourceschedule.IStandbyService"); @@ -98,6 +143,8 @@ protected: UNAPPLY_ALLOW_RESOURCE, GET_ALLOW_LIST, IS_DEVICE_IN_STANDBY, + REPORT_WORK_SCHEDULER_STATUS, + REPORT_DEVICE_STATE_CHANGED, }; }; } // namespace DevStandbyMgr diff --git a/frameworks/include/istandby_service_subscriber.h b/frameworks/include/istandby_service_subscriber.h index c28cb81125b1bde6899a20464e97e7f719bc74c3..7b86ca942ac6b184a813fc75aeebaa1d561a09d5 100644 --- a/frameworks/include/istandby_service_subscriber.h +++ b/frameworks/include/istandby_service_subscriber.h @@ -70,11 +70,6 @@ public: public: DECLARE_INTERFACE_DESCRIPTOR(u"ohos.resourceschedule.IStandbyServiceSubscriber"); -protected: - enum InterfaceId : uint32_t { - ON_DEVICE_IDLE_MODE = FIRST_CALL_TRANSACTION, - ON_ALLOW_LIST_CHANGED, - }; private: std::string subscriberName_; }; diff --git a/frameworks/include/standby_ipc_interface_code.h b/frameworks/include/standby_ipc_interface_code.h new file mode 100644 index 0000000000000000000000000000000000000000..1dd520d7202a965c378845170a26868dda6ea3e9 --- /dev/null +++ b/frameworks/include/standby_ipc_interface_code.h @@ -0,0 +1,30 @@ +/* + * 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 FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_FRAMEWORKS_INCLUDE_STANDBY_IPC_INTERFACE_CODE_H +#define FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_FRAMEWORKS_INCLUDE_STANDBY_IPC_INTERFACE_CODE_H + +#include + +/* SAID: 1914 */ +namespace OHOS { +namespace DevStandbyMgr { + enum class StandbySubscriberInterfaceCode { + ON_DEVICE_IDLE_MODE = FIRST_CALL_TRANSACTION, + ON_ALLOW_LIST_CHANGED, + }; +} // namespace DevStandbyMgr +} // namespace OHOS +#endif // FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_FRAMEWORKS_INCLUDE_STANDBY_IPC_INTERFACE_CODE_H \ No newline at end of file diff --git a/frameworks/include/standby_service_proxy.h b/frameworks/include/standby_service_proxy.h index 672968ebc0b523aa7b3619e9719d2142af7bbb4e..cc2f816ec190df5347503ea95aeff52df4a1866b 100644 --- a/frameworks/include/standby_service_proxy.h +++ b/frameworks/include/standby_service_proxy.h @@ -79,6 +79,42 @@ public: * @return ErrCode ERR_OK if success, others if fail. */ ErrCode IsDeviceInStandby(bool& isStandby) override; + + /** + * @brief Construct a new Report Work Scheduler Status object. + * + * @param started true if the work is triggered, else false. + * @param uid uid of the applicatoin. + * @param bundleName bundleName of the application. + */ + ErrCode ReportWorkSchedulerStatus(bool started, int32_t uid, const std::string& bundleName) override; + + /** + * @brief Get the Restrict List object. + * + * @param allowType the allow type to be retrieved. + * @param allowInfoList result represents allowed types and apps. + * @param reasonCode represents the reason why invoke the api. + * @return ErrCode ERR_OK if success, others if fail. + */ + ErrCode GetRestrictList(uint32_t restrictType, std::vector& restrictInfoList, + uint32_t reasonCode) override; + + /** + * @brief Whether the restriction strategy enbaled or not. + * + * @param strategyName the strategy name. + * @param enabled true if the strategy is enabled. + */ + ErrCode IsStrategyEnabled(const std::string& strategyName, bool& enabled) override; + + /** + * @brief Report event when device state change. + * + * @param type type of device state. + * @param enabled true if the device state is on. + */ + ErrCode ReportDeviceStateChanged(DeviceStateType type, bool enabled) override; private: ErrCode InnerTransact(uint32_t code, MessageOption& flags, MessageParcel& data, MessageParcel& reply); diff --git a/frameworks/include/standby_service_stub.h b/frameworks/include/standby_service_stub.h index 1f2472b70fd845b4ca51699e5cfdc8781df4c5a5..a0741592a93b6de0e998ff708f8f8e54364b8042 100644 --- a/frameworks/include/standby_service_stub.h +++ b/frameworks/include/standby_service_stub.h @@ -51,6 +51,10 @@ private: ErrCode HandleUnapplyAllowResource(MessageParcel& data, MessageParcel& reply); ErrCode HandleGetAllowList(MessageParcel& data, MessageParcel& reply); ErrCode HandleIsDeviceInStandby(MessageParcel& data, MessageParcel& reply); + ErrCode HandleReportWorkSchedulerStatus(MessageParcel& data, MessageParcel& reply); + ErrCode HandleGetRestrictList(MessageParcel& data, MessageParcel& reply); + ErrCode HandleIsStrategyEnabled(MessageParcel& data, MessageParcel& reply); + ErrCode HandleReportDeviceStateChanged(MessageParcel& data, MessageParcel& reply); }; } // namespace DevStandbyMgr } // namespace OHOS diff --git a/frameworks/src/standby_service_proxy.cpp b/frameworks/src/standby_service_proxy.cpp index b5325a42442984db1a1045611b6c3987eec2359f..57ffa8a0215f2c90ea03ed1af7233eb867eaaaa4 100644 --- a/frameworks/src/standby_service_proxy.cpp +++ b/frameworks/src/standby_service_proxy.cpp @@ -20,6 +20,7 @@ #include "standby_service_errors.h" #include "standby_service_log.h" +#include "istandby_ipc_inteface_code.h" namespace OHOS { namespace DevStandbyMgr { @@ -50,7 +51,8 @@ ErrCode StandbyServiceProxy::SubscribeStandbyCallback(const sptr(IStandbyInterfaceCode::SUBSCRIBE_STANDBY_CALLBACK), option, data, reply); if (result != ERR_OK) { STANDBYSERVICE_LOGW("SubscribeSleepStateEvent fail: transact ErrCode=%{public}d", result); return ERR_STANDBY_TRANSACT_FAILED; @@ -84,7 +86,8 @@ ErrCode StandbyServiceProxy::UnsubscribeStandbyCallback(const sptr(IStandbyInterfaceCode::UNSUBSCRIBE_STANDBY_CALLBACK), + option, data, reply); if (result != ERR_OK) { STANDBYSERVICE_LOGW("UnsubscribeSleepStateEvent fail: transact ErrCode=%{public}d", result); return ERR_STANDBY_TRANSACT_FAILED; @@ -114,7 +117,8 @@ ErrCode StandbyServiceProxy::ApplyAllowResource(const sptr& res return ERR_STANDBY_PARCELABLE_FAILED; } - ErrCode result = InnerTransact(APPLY_ALLOW_RESOURCE, option, data, reply); + ErrCode result = InnerTransact(static_cast(IStandbyInterfaceCode::APPLY_ALLOW_RESOURCE), + option, data, reply); if (result != ERR_OK) { STANDBYSERVICE_LOGW("ApplyAllowResource fail: transact ErrCode=%{public}d", result); return ERR_STANDBY_TRANSACT_FAILED; @@ -144,7 +148,8 @@ ErrCode StandbyServiceProxy::UnapplyAllowResource(const sptr& r return ERR_STANDBY_PARCELABLE_FAILED; } - ErrCode result = InnerTransact(UNAPPLY_ALLOW_RESOURCE, option, data, reply); + ErrCode result = InnerTransact(static_cast(IStandbyInterfaceCode::UNAPPLY_ALLOW_RESOURCE), + option, data, reply); if (result != ERR_OK) { STANDBYSERVICE_LOGW("RemoveAllowList fail: transact ErrCode=%{public}d", result); return ERR_STANDBY_TRANSACT_FAILED; @@ -175,7 +180,8 @@ ErrCode StandbyServiceProxy::GetAllowList(uint32_t allowType, std::vector(IStandbyInterfaceCode::GET_ALLOW_LIST), + option, data, reply); if (result != ERR_OK) { STANDBYSERVICE_LOGW("GetAllowList fail: transact ErrCode=%{public}d", result); return ERR_STANDBY_TRANSACT_FAILED; @@ -211,7 +217,8 @@ ErrCode StandbyServiceProxy::IsDeviceInStandby(bool& isStandby) return ERR_STANDBY_PARCELABLE_FAILED; } - ErrCode result = InnerTransact(IS_DEVICE_IN_STANDBY, option, data, reply); + ErrCode result = InnerTransact(static_cast(IStandbyInterfaceCode::IS_DEVICE_IN_STANDBY), + option, data, reply); if (result != ERR_OK) { STANDBYSERVICE_LOGW("IsDeviceInStandby fail: transact ErrCode=%{public}d", result); return ERR_STANDBY_TRANSACT_FAILED; @@ -231,6 +238,145 @@ ErrCode StandbyServiceProxy::IsDeviceInStandby(bool& isStandby) return result; } +ErrCode StandbyServiceProxy::ReportWorkSchedulerStatus(bool started, int32_t uid, const std::string& bundleName) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + if (!data.WriteInterfaceToken(StandbyServiceProxy::GetDescriptor())) { + STANDBYSERVICE_LOGW("IsDeviceInStandby write descriptor failed"); + return ERR_STANDBY_PARCELABLE_FAILED; + } + + if (!data.WriteBool(started) || !data.WriteInt32(uid) || !data.WriteString(bundleName)) { + STANDBYSERVICE_LOGW("ReportWorkSchedulerStatus write parameter failed"); + return ERR_STANDBY_PARCELABLE_FAILED; + } + ErrCode result = InnerTransact(static_cast(IStandbyInterfaceCode::REPORT_WORK_SCHEDULER_STATUS), + option, data, reply); + if (result != ERR_OK) { + STANDBYSERVICE_LOGW("ReportWorkSchedulerStatus fail: transact ErrCode=%{public}d", result); + return ERR_STANDBY_TRANSACT_FAILED; + } + if (!reply.ReadInt32(result)) { + STANDBYSERVICE_LOGW("ReportWorkSchedulerStatus fail: read result failed."); + return ERR_STANDBY_PARCELABLE_FAILED; + } + if (result != ERR_OK) { + STANDBYSERVICE_LOGW("ReportWorkSchedulerStatus failed"); + return result; + } + return result; +} + +ErrCode StandbyServiceProxy::GetRestrictList(uint32_t restrictType, std::vector& restrictInfoList, + uint32_t reasonCode) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + if (!data.WriteInterfaceToken(StandbyServiceProxy::GetDescriptor())) { + STANDBYSERVICE_LOGW("GetRestrictList write descriptor failed"); + return ERR_STANDBY_PARCELABLE_FAILED; + } + if (!data.WriteUint32(restrictType) || !data.WriteUint32(reasonCode)) { + STANDBYSERVICE_LOGW("GetRestrictList write parameter failed"); + return ERR_STANDBY_PARCELABLE_FAILED; + } + + ErrCode result = InnerTransact(static_cast(IStandbyInterfaceCode::GET_RESTRICT_LIST), + option, data, reply); + if (result != ERR_OK) { + STANDBYSERVICE_LOGW("GetRestrictList fail: transact ErrCode=%{public}d", result); + return ERR_STANDBY_TRANSACT_FAILED; + } + if (!reply.ReadInt32(result)) { + STANDBYSERVICE_LOGW("GetRestrictList fail: read result failed."); + return ERR_STANDBY_PARCELABLE_FAILED; + } + if (result != ERR_OK) { + STANDBYSERVICE_LOGW("GetRestrictList failed"); + return result; + } + uint32_t infoSize = reply.ReadUint32(); + for (uint32_t i = 0; i < infoSize; i++) { + auto info = AllowInfo::Unmarshalling(reply); + if (info == nullptr) { + STANDBYSERVICE_LOGW("GetRestrictList Read Parcelable infos failed."); + return ERR_STANDBY_PARCELABLE_FAILED; + } + restrictInfoList.emplace_back(*info); + } + + return result; +} + +ErrCode StandbyServiceProxy::IsStrategyEnabled(const std::string& strategyName, bool& enabled) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + if (!data.WriteInterfaceToken(StandbyServiceProxy::GetDescriptor())) { + STANDBYSERVICE_LOGW("IsStrategyEnabled write descriptor failed"); + return ERR_STANDBY_PARCELABLE_FAILED; + } + if (!data.WriteString(strategyName)) { + STANDBYSERVICE_LOGW("IsStrategyEnabled write parameter failed"); + return ERR_STANDBY_PARCELABLE_FAILED; + } + + ErrCode result = InnerTransact(static_cast(IStandbyInterfaceCode::IS_STRATEGY_ENABLED), + option, data, reply); + if (result != ERR_OK) { + STANDBYSERVICE_LOGW("IsStrategyEnabled fail: transact ErrCode=%{public}d", result); + return ERR_STANDBY_TRANSACT_FAILED; + } + if (!reply.ReadInt32(result)) { + STANDBYSERVICE_LOGW("IsStrategyEnabled fail: read result failed."); + return ERR_STANDBY_PARCELABLE_FAILED; + } + if (result != ERR_OK) { + STANDBYSERVICE_LOGW("IsStrategyEnabled failed"); + return result; + } + if (!reply.ReadBool(enabled)) { + STANDBYSERVICE_LOGW("IsStrategyEnabled fail: read result failed."); + return ERR_STANDBY_PARCELABLE_FAILED; + } + return result; +} + +ErrCode StandbyServiceProxy::ReportDeviceStateChanged(DeviceStateType type, bool enabled) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + if (!data.WriteInterfaceToken(StandbyServiceProxy::GetDescriptor())) { + STANDBYSERVICE_LOGW("IsDeviceInStandby write descriptor failed"); + return ERR_STANDBY_PARCELABLE_FAILED; + } + + if (!data.WriteInt32(static_cast(type)) || !data.WriteBool(enabled)) { + STANDBYSERVICE_LOGW("ReportDeviceStateChanged write parameter failed"); + return ERR_STANDBY_PARCELABLE_FAILED; + } + ErrCode result = InnerTransact(static_cast(IStandbyInterfaceCode::REPORT_DEVICE_STATE_CHANGED), + option, data, reply); + if (result != ERR_OK) { + STANDBYSERVICE_LOGW("ReportDeviceStateChanged fail: transact ErrCode=%{public}d", result); + return ERR_STANDBY_TRANSACT_FAILED; + } + if (!reply.ReadInt32(result)) { + STANDBYSERVICE_LOGW("ReportDeviceStateChanged fail: read result failed."); + return ERR_STANDBY_PARCELABLE_FAILED; + } + if (result != ERR_OK) { + STANDBYSERVICE_LOGW("ReportDeviceStateChanged failed"); + return result; + } + return result; +} + ErrCode StandbyServiceProxy::InnerTransact(uint32_t code, MessageOption& flags, MessageParcel& data, MessageParcel& reply) { diff --git a/frameworks/src/standby_service_stub.cpp b/frameworks/src/standby_service_stub.cpp index 4c34a0e946f4a17760881b0ebf1995310fa5aa65..662a994695111f0cfb7c66556912a8980a646f02 100644 --- a/frameworks/src/standby_service_stub.cpp +++ b/frameworks/src/standby_service_stub.cpp @@ -18,34 +18,13 @@ #include #include +#include "istandby_ipc_inteface_code.h" #include "standby_service_subscriber_proxy.h" #include "standby_service_errors.h" #include "standby_service_log.h" namespace OHOS { namespace DevStandbyMgr { -const std::map> - StandbyServiceStub::interfaces_ = { - {StandbyServiceStub::SUBSCRIBE_STANDBY_CALLBACK, - std::bind(&StandbyServiceStub::HandleSubscribeStandbyCallback, - std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)}, - {StandbyServiceStub::UNSUBSCRIBE_STANDBY_CALLBACK, - std::bind(&StandbyServiceStub::HandleUnsubscribeStandbyCallback, - std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)}, - {StandbyServiceStub::APPLY_ALLOW_RESOURCE, - std::bind(&StandbyServiceStub::HandleApplyAllowResource, - std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)}, - {StandbyServiceStub::UNAPPLY_ALLOW_RESOURCE, - std::bind(&StandbyServiceStub::HandleUnapplyAllowResource, - std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)}, - {StandbyServiceStub::GET_ALLOW_LIST, - std::bind(&StandbyServiceStub::HandleGetAllowList, - std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)}, - {StandbyServiceStub::IS_DEVICE_IN_STANDBY, - std::bind(&StandbyServiceStub::HandleIsDeviceInStandby, - std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)}, -}; - ErrCode StandbyServiceStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) { @@ -55,23 +34,43 @@ ErrCode StandbyServiceStub::OnRemoteRequest(uint32_t code, STANDBYSERVICE_LOGE("StandbyServiceStub: Local descriptor not match remote."); return ERR_TRANSACTION_FAILED; } - auto it = interfaces_.find(code); - if (it == interfaces_.end()) { - return IRemoteStub::OnRemoteRequest(code, data, reply, option); - } - - auto fun = it->second; - if (fun == nullptr) { - return IRemoteStub::OnRemoteRequest(code, data, reply, option); - } - ErrCode result = fun(this, data, reply); - if (SUCCEEDED(result)) { - return ERR_OK; + switch (code) { + case static_cast(IStandbyInterfaceCode::SUBSCRIBE_STANDBY_CALLBACK): + HandleSubscribeStandbyCallback(data, reply); + break; + case static_cast(IStandbyInterfaceCode::UNSUBSCRIBE_STANDBY_CALLBACK): + HandleUnsubscribeStandbyCallback(data, reply); + break; + case static_cast(IStandbyInterfaceCode::APPLY_ALLOW_RESOURCE): + HandleApplyAllowResource(data, reply); + break; + case static_cast(IStandbyInterfaceCode::UNAPPLY_ALLOW_RESOURCE): + HandleUnapplyAllowResource(data, reply); + break; + case static_cast(IStandbyInterfaceCode::GET_ALLOW_LIST): + HandleGetAllowList(data, reply); + break; + case static_cast(IStandbyInterfaceCode::IS_DEVICE_IN_STANDBY): + HandleIsDeviceInStandby(data, reply); + break; + case static_cast(IStandbyInterfaceCode::REPORT_WORK_SCHEDULER_STATUS): + HandleReportWorkSchedulerStatus(data, reply); + break; + case static_cast(IStandbyInterfaceCode::GET_RESTRICT_LIST): + HandleGetRestrictList(data, reply); + break; + case static_cast(IStandbyInterfaceCode::IS_STRATEGY_ENABLED): + HandleIsStrategyEnabled(data, reply); + break; + case static_cast(IStandbyInterfaceCode::REPORT_DEVICE_STATE_CHANGED): + HandleReportDeviceStateChanged(data, reply); + break; + default: + return IRemoteStub::OnRemoteRequest(code, data, reply, option); } - - STANDBYSERVICE_LOGW("StandbyServiceStub: Failed to call interface %{public}u, err:%{public}d", code, result); - return result; + STANDBYSERVICE_LOGW("StandbyServiceStub: Failed to call interface %{public}u,", code); + return ERR_OK; } ErrCode StandbyServiceStub::HandleSubscribeStandbyCallback(MessageParcel& data, MessageParcel& reply) @@ -93,6 +92,69 @@ ErrCode StandbyServiceStub::HandleSubscribeStandbyCallback(MessageParcel& data, return ERR_OK; } +ErrCode StandbyServiceStub::HandleReportWorkSchedulerStatus(MessageParcel& data, MessageParcel& reply) +{ + bool started {false}; + int32_t uid {0}; + std::string bundleName {""}; + if (!data.ReadBool(started) || !data.ReadInt32(uid) || !data.ReadString(bundleName)) { + STANDBYSERVICE_LOGW("HandleReportWorkSchedulerStatus ReadParcelable failed"); + return ERR_STANDBY_PARCELABLE_FAILED; + } + ErrCode result = ReportWorkSchedulerStatus(started, uid, bundleName); + if (!reply.WriteInt32(result)) { + STANDBYSERVICE_LOGW("HandleReportWorkSchedulerStatus Write result failed, ErrCode=%{public}d", result); + return ERR_STANDBY_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode StandbyServiceStub::HandleGetRestrictList(MessageParcel& data, MessageParcel& reply) +{ + uint32_t restrictType {0}; + uint32_t reasonCode {0}; + if (!data.ReadUint32(restrictType) || !data.ReadUint32(reasonCode)) { + STANDBYSERVICE_LOGW("HandleGetRestrictList ReadParcelable failed"); + return ERR_STANDBY_PARCELABLE_FAILED; + } + std::vector restrictInfoList {}; + ErrCode result = GetRestrictList(restrictType, restrictInfoList, reasonCode); + if (!reply.WriteInt32(result)) { + STANDBYSERVICE_LOGW("HandleGetRestrictList Write result failed, ErrCode=%{public}d", result); + return ERR_STANDBY_PARCELABLE_FAILED; + } + if (!reply.WriteUint32(restrictInfoList.size())) { + STANDBYSERVICE_LOGW("HandleGetRestrictList Write result size failed"); + return ERR_STANDBY_PARCELABLE_FAILED; + } + for (auto& info : restrictInfoList) { + if (!info.Marshalling(reply)) { + return ERR_STANDBY_PARCELABLE_FAILED; + } + } + return ERR_OK; +} + +ErrCode StandbyServiceStub::HandleIsStrategyEnabled(MessageParcel& data, MessageParcel& reply) +{ + bool enabled {false}; + std::string strategyName {""}; + if (!data.ReadString(strategyName)) { + STANDBYSERVICE_LOGW("HandleIsStrategyEnabled ReadParcelable failed"); + return ERR_STANDBY_PARCELABLE_FAILED; + } + ErrCode result = IsDeviceInStandby(enabled); + if (!reply.WriteInt32(result)) { + STANDBYSERVICE_LOGW("HandleIsStrategyEnabled Write result failed, ErrCode=%{public}d", result); + return ERR_STANDBY_PARCELABLE_FAILED; + } + if (!reply.WriteBool(enabled)) { + STANDBYSERVICE_LOGW("HandleIsStrategyEnabled Write enabled failed"); + return ERR_STANDBY_PARCELABLE_FAILED; + } + return ERR_OK; +} + ErrCode StandbyServiceStub::HandleUnsubscribeStandbyCallback(MessageParcel& data, MessageParcel& reply) { sptr subscriber = data.ReadRemoteObject(); @@ -179,5 +241,21 @@ ErrCode StandbyServiceStub::HandleIsDeviceInStandby(MessageParcel& data, Message } return ERR_OK; } + +ErrCode StandbyServiceStub::HandleReportDeviceStateChanged(MessageParcel& data, MessageParcel& reply) +{ + int32_t type {0}; + bool enable {false}; + if (!data.ReadInt32(type) || !data.ReadBool(enable)) { + STANDBYSERVICE_LOGW("HandleReportDeviceStateChanged ReadParcelable failed"); + return ERR_STANDBY_PARCELABLE_FAILED; + } + ErrCode result = ReportDeviceStateChanged(static_cast(type), enable); + if (!reply.WriteInt32(result)) { + STANDBYSERVICE_LOGW("HandleReportDeviceStateChanged Write result failed, ErrCode=%{public}d", result); + return ERR_STANDBY_PARCELABLE_FAILED; + } + return ERR_OK; +} } // namespace DevStandbyMgr } // namespace OHOS \ No newline at end of file diff --git a/frameworks/src/standby_service_subscriber_proxy.cpp b/frameworks/src/standby_service_subscriber_proxy.cpp index fcabe37a620ffe1c44cb31f22fb7cbbf3c0fadf5..9b11ff1789dceec276933934f995273d02269a0e 100644 --- a/frameworks/src/standby_service_subscriber_proxy.cpp +++ b/frameworks/src/standby_service_subscriber_proxy.cpp @@ -19,6 +19,7 @@ #include "standby_service_errors.h" #include "standby_service_log.h" +#include "standby_ipc_interface_code.h" namespace OHOS { namespace DevStandbyMgr { @@ -46,7 +47,8 @@ void StandbyServiceSubscriberProxy::OnDeviceIdleMode(bool napped, bool sleeping) MessageParcel reply; MessageOption option = {MessageOption::TF_ASYNC}; - int32_t ret = remote->SendRequest(ON_DEVICE_IDLE_MODE, data, reply, option); + int32_t ret = remote->SendRequest( + static_cast(StandbySubscriberInterfaceCode::ON_DEVICE_IDLE_MODE), data, reply, option); if (ret!= ERR_OK) { STANDBYSERVICE_LOGE("OnDeviceIdleMode SendRequest failed, error code: %d", ret); } @@ -74,7 +76,8 @@ void StandbyServiceSubscriberProxy::OnAllowListChanged(int32_t uid, const std::s MessageParcel reply; MessageOption option = {MessageOption::TF_ASYNC}; - int32_t ret = remote->SendRequest(ON_ALLOW_LIST_CHANGED, data, reply, option); + int32_t ret = remote->SendRequest( + static_cast(StandbySubscriberInterfaceCode::ON_ALLOW_LIST_CHANGED), data, reply, option); if (ret!= ERR_OK) { STANDBYSERVICE_LOGE("OnAllowListChanged SendRequest failed, error code: %d", ret); } diff --git a/interfaces/innerkits/include/allow_type.h b/interfaces/innerkits/include/allow_type.h index bde55c038843570903587954b9f4840a3533e716..634db733cbe39f78a8ea77a63e9ba7479bf32803 100644 --- a/interfaces/innerkits/include/allow_type.h +++ b/interfaces/innerkits/include/allow_type.h @@ -23,7 +23,7 @@ namespace OHOS { namespace DevStandbyMgr { struct AllowType { enum : uint32_t { - NET = 1, + NETWORK = 1, RUNNING_LOCK = 1 << 1, TIMER = 1 << 2, WORK_SCHEDULER = 1 << 3, @@ -36,7 +36,6 @@ struct AllowType { extern const std::vector AllowTypeName; extern const uint32_t MAX_ALLOW_TYPE_NUM; extern const uint32_t MAX_ALLOW_TYPE_NUMBER; - } // namespace DevStandbyMgr } // namespace OHOS #endif // FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_INTERFACES_INNERKITS_INCLUDE_ALLOW_TYPE_H \ No newline at end of file diff --git a/interfaces/innerkits/include/standby_service_client.h b/interfaces/innerkits/include/standby_service_client.h index a60814167d67052947e84fa90838d482cf58d499..8d86c909767fa43b02c5be920e4426cd3b04d08b 100644 --- a/interfaces/innerkits/include/standby_service_client.h +++ b/interfaces/innerkits/include/standby_service_client.h @@ -77,6 +77,45 @@ public: ErrCode GetAllowList(uint32_t allowType, std::vector& allowInfoList, uint32_t reasonCode); + /** + * @brief Get the Restrict List object. + * + * @param restrictType the restrict type to be retrieved. + * @param restrictInfoList result represents restricted types and apps. + * @param reasonCode represents the reason why invoke the api. + * @return ErrCode ERR_OK if success, others if fail. + */ + ErrCode GetRestrictList(uint32_t restrictType, std::vector& restrictInfoList, + uint32_t reasonCode); + + /** + * @brief Construct a new Report Work Scheduler Status object. + * + * @param started true if the work is triggered, else false. + * @param uid uid of the applicatoin. + * @param bundleName bundleName of the application. + * @return ErrCode ERR_OK if success, others if fail. + */ + ErrCode ReportWorkSchedulerStatus(bool started, int32_t uid, const std::string& bundleName); + + /** + * @brief Whether the restriction strategy enbaled or not. + * + * @param strategyName the strategy name. + * @param enabled true if the strategy is enabled. + * @return ErrCode ERR_OK if success, others if fail. + */ + ErrCode IsStrategyEnabled(const std::string& strategyName, bool& isEnabled); + + /** + * @brief Report event when device state change, such as discomponent device, bluetooth socket.. + * + * @param type type of device state. + * @param enabled true if the device state is on. + * @return ErrCode ERR_OK if success, others if fail. + */ + ErrCode ReportDeviceStateChanged(DeviceStateType type, bool enabled); + /** * @brief query if the device is in standby mode; * @@ -84,6 +123,7 @@ public: * @return ErrCode ERR_OK if success, else fail. */ ErrCode IsDeviceInStandby(bool& isStandby); + private: bool GetStandbyServiceProxy(); void ResetStandbyServiceClient(); diff --git a/interfaces/innerkits/src/allow_type.cpp b/interfaces/innerkits/src/allow_type.cpp index 32d27ad063b2edd39c30664082ec67788d12f052..1a03a122bfa64f9051a58d0f4aeebf6aede12a64 100644 --- a/interfaces/innerkits/src/allow_type.cpp +++ b/interfaces/innerkits/src/allow_type.cpp @@ -18,7 +18,7 @@ namespace OHOS { namespace DevStandbyMgr { const std::vector AllowTypeName = { - "NET", + "NETWORK", "RUNNING_LOCK", "TIMER", "WORK_SCHEDULER", diff --git a/interfaces/innerkits/src/standby_service_client.cpp b/interfaces/innerkits/src/standby_service_client.cpp index ffeb36ba5886c868a6983845f5e6e03f0cdf87d3..44ec6cfdd31dcf409383a789b9680f1ed5a3d0af 100644 --- a/interfaces/innerkits/src/standby_service_client.cpp +++ b/interfaces/innerkits/src/standby_service_client.cpp @@ -117,6 +117,51 @@ ErrCode StandbyServiceClient::IsDeviceInStandby(bool& isStandby) return standbyServiceProxy_->IsDeviceInStandby(isStandby); } +ErrCode StandbyServiceClient::ReportWorkSchedulerStatus(bool started, int32_t uid, const std::string& bundleName) +{ + std::lock_guard lock(mutex_); + if (!GetStandbyServiceProxy()) { + STANDBYSERVICE_LOGE("get standby service proxy failed"); + return ERR_STANDBY_SERVICE_NOT_CONNECTED; + } + return standbyServiceProxy_->ReportWorkSchedulerStatus(started, uid, bundleName); +} + +ErrCode StandbyServiceClient::GetRestrictList(uint32_t restrictType, std::vector& restrictInfoList, + uint32_t reasonCode) +{ + std::lock_guard lock(mutex_); + if (!GetStandbyServiceProxy()) { + STANDBYSERVICE_LOGE("get standby service proxy failed"); + return ERR_STANDBY_SERVICE_NOT_CONNECTED; + } + if (!restrictInfoList.empty()) { + STANDBYSERVICE_LOGW("restrict info array is not empty"); + restrictInfoList.clear(); + } + return standbyServiceProxy_->GetAllowList(restrictType, restrictInfoList, reasonCode); +} + +ErrCode StandbyServiceClient::IsStrategyEnabled(const std::string& strategyName, bool& isEnabled) +{ + std::lock_guard lock(mutex_); + if (!GetStandbyServiceProxy()) { + STANDBYSERVICE_LOGE("get standby service proxy failed"); + return ERR_STANDBY_SERVICE_NOT_CONNECTED; + } + return standbyServiceProxy_->IsStrategyEnabled(strategyName, isEnabled); +} + +ErrCode StandbyServiceClient::ReportDeviceStateChanged(DeviceStateType type, bool enabled) +{ + std::lock_guard lock(mutex_); + if (!GetStandbyServiceProxy()) { + STANDBYSERVICE_LOGE("get standby service proxy failed"); + return ERR_STANDBY_SERVICE_NOT_CONNECTED; + } + return standbyServiceProxy_->ReportDeviceStateChanged(type, enabled); +} + bool StandbyServiceClient::GetStandbyServiceProxy() { if (standbyServiceProxy_ != nullptr) { diff --git a/interfaces/innerkits/src/standby_service_subscriber_stub.cpp b/interfaces/innerkits/src/standby_service_subscriber_stub.cpp index 34c8d03fd55d99eafccffc4b2392aeb3c945d2f3..23fcebfaf6ed29bff65d0cac600cc07e644a7312 100644 --- a/interfaces/innerkits/src/standby_service_subscriber_stub.cpp +++ b/interfaces/innerkits/src/standby_service_subscriber_stub.cpp @@ -18,6 +18,7 @@ #include #include +#include "standby_ipc_interface_code.h" #include "standby_service_log.h" namespace OHOS { @@ -43,15 +44,16 @@ ErrCode StandbyServiceSubscriberStub::OnRemoteRequestInner(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) { switch (code) { - case ON_DEVICE_IDLE_MODE: { + case (static_cast(StandbySubscriberInterfaceCode::ON_DEVICE_IDLE_MODE)): { return HandleOnDeviceIdleMode(data); } - case ON_ALLOW_LIST_CHANGED: { + case (static_cast(StandbySubscriberInterfaceCode::ON_ALLOW_LIST_CHANGED)): { return HandleOnAllowListChanged(data); } default: return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } + return ERR_OK; } void StandbyServiceSubscriberStub::OnDeviceIdleMode(bool napped, bool sleeped) diff --git a/interfaces/innerkits/test/unittest/mock_standby_client_unit_test.cpp b/interfaces/innerkits/test/unittest/mock_standby_client_unit_test.cpp index 5d4ffd47d7b4cbd37805620f20b282dba3621ce3..2cecb5364f398d3ac53712a3623846d44a56f99b 100644 --- a/interfaces/innerkits/test/unittest/mock_standby_client_unit_test.cpp +++ b/interfaces/innerkits/test/unittest/mock_standby_client_unit_test.cpp @@ -55,7 +55,7 @@ HWTEST_F(StandbyServiceClientUnitTest, MockStandbyServiceClientUnitTest_001, Tes EXPECT_NE(StandbyServiceClient::GetInstance().UnapplyAllowResource(nullRequest), ERR_OK); std::vector allowInfoList; nullRequest = nullptr; - EXPECT_NE(StandbyServiceClient::GetInstance().GetAllowList(AllowType::NET, allowInfoList, 0), ERR_OK); + EXPECT_NE(StandbyServiceClient::GetInstance().GetAllowList(AllowType::NETWORK, allowInfoList, 0), ERR_OK); EXPECT_NE(StandbyServiceClient::GetInstance().GetAllowList(0, allowInfoList, 0), ERR_OK); bool isStandby {false}; EXPECT_NE(StandbyServiceClient::GetInstance().IsDeviceInStandby(isStandby), ERR_OK); diff --git a/interfaces/innerkits/test/unittest/standby_client_unit_test.cpp b/interfaces/innerkits/test/unittest/standby_client_unit_test.cpp index e1537062700290195138c0834f7a95b79b0f842d..2a8ab3ea46c68e2d7871a18781b761de0fc616fb 100644 --- a/interfaces/innerkits/test/unittest/standby_client_unit_test.cpp +++ b/interfaces/innerkits/test/unittest/standby_client_unit_test.cpp @@ -21,6 +21,7 @@ #include "singleton.h" #include "allow_type.h" +#include "standby_ipc_interface_code.h" #include "standby_service_client.h" #include "standby_service_subscriber_stub.h" using namespace testing::ext; @@ -71,7 +72,7 @@ HWTEST_F(StandbyServiceClientUnitTest, StandbyServiceClientUnitTest_002, TestSiz EXPECT_NE(StandbyServiceClient::GetInstance().ApplyAllowResource(resouarceRequest), ERR_OK); EXPECT_NE(StandbyServiceClient::GetInstance().UnapplyAllowResource(resouarceRequest), ERR_OK); - sptr validResRequest = new (std::nothrow) ResourceRequest(AllowType::NET, + sptr validResRequest = new (std::nothrow) ResourceRequest(AllowType::NETWORK, 0, "test_process", 100, "test", 1); EXPECT_EQ(StandbyServiceClient::GetInstance().ApplyAllowResource(validResRequest), ERR_OK); EXPECT_EQ(StandbyServiceClient::GetInstance().UnapplyAllowResource(validResRequest), ERR_OK); @@ -87,7 +88,7 @@ HWTEST_F(StandbyServiceClientUnitTest, StandbyServiceClientUnitTest_003, TestSiz { std::vector allowInfoList; sptr nullRequest = nullptr; - EXPECT_EQ(StandbyServiceClient::GetInstance().GetAllowList(AllowType::NET, allowInfoList, 0), ERR_OK); + EXPECT_EQ(StandbyServiceClient::GetInstance().GetAllowList(AllowType::NETWORK, allowInfoList, 0), ERR_OK); EXPECT_NE(StandbyServiceClient::GetInstance().GetAllowList(0, allowInfoList, 0), ERR_OK); EXPECT_EQ(StandbyServiceClient::GetInstance().GetAllowList((1 << 6), allowInfoList, 0), ERR_OK); allowInfoList.emplace_back(AllowInfo {}); @@ -103,7 +104,7 @@ HWTEST_F(StandbyServiceClientUnitTest, StandbyServiceClientUnitTest_003, TestSiz HWTEST_F(StandbyServiceClientUnitTest, StandbyServiceClientUnitTest_004, TestSize.Level1) { bool isStandby {false}; - EXPECT_EQ(StandbyServiceClient::GetInstance().IsDeviceInStandby(isStandby), ERR_OK); + EXPECT_NE(StandbyServiceClient::GetInstance().IsDeviceInStandby(isStandby), ERR_OK); } /** @@ -146,8 +147,10 @@ HWTEST_F(StandbyServiceClientUnitTest, StandbyServiceClientUnitTest_007, TestSiz MessageParcel data {}; MessageParcel reply {}; MessageOption option {}; - subscriber->OnRemoteRequestInner(StandbyServiceSubscriberStub::ON_ALLOW_LIST_CHANGED, data, reply, option); - subscriber->OnRemoteRequestInner(StandbyServiceSubscriberStub::ON_ALLOW_LIST_CHANGED + 1, data, reply, option); + subscriber->OnRemoteRequestInner( + (static_cast(StandbySubscriberInterfaceCode::ON_ALLOW_LIST_CHANGED)), data, reply, option); + subscriber->OnRemoteRequestInner( + (static_cast(StandbySubscriberInterfaceCode::ON_ALLOW_LIST_CHANGED)) + 1, data, reply, option); EXPECT_NE(subscriber->HandleOnDeviceIdleMode(data), ERR_OK); subscriber->HandleOnAllowListChanged(data); data.WriteBool(false); diff --git a/interfaces/kits/napi/src/init.cpp b/interfaces/kits/napi/src/init.cpp index 7bcebf93e3f4c62e12e48c4545a54c242e13e364..eec5e4348003bffd696c651b704b105615b383ec 100644 --- a/interfaces/kits/napi/src/init.cpp +++ b/interfaces/kits/napi/src/init.cpp @@ -49,7 +49,7 @@ napi_value DeviceStandbyTypeInit(napi_env env, napi_value exports) napi_value obj = nullptr; napi_create_object(env, &obj); - SetNamedPropertyByInteger(env, obj, static_cast(AllowType::NET), "NETWORK"); + SetNamedPropertyByInteger(env, obj, static_cast(AllowType::NETWORK), "NETWORK"); SetNamedPropertyByInteger(env, obj, static_cast(AllowType::RUNNING_LOCK), "RUNNING_LOCK"); SetNamedPropertyByInteger(env, obj, static_cast(AllowType::TIMER), "TIMER"); SetNamedPropertyByInteger(env, obj, static_cast(AllowType::WORK_SCHEDULER), "WORK_SCHEDULER"); diff --git a/patches/component.patch b/patches/component.patch new file mode 100644 index 0000000000000000000000000000000000000000..242b31855d9174246f241809fa423bdd1ac9f088 --- /dev/null +++ b/patches/component.patch @@ -0,0 +1,75 @@ +From e280b7e8000c24a8b3512da0985e45852447cc11 Mon Sep 17 00:00:00 2001 +From: geraltxu <36860135+geraltxu@users.noreply.github.com> +Date: Mon, 10 Jul 2023 15:13:13 +0800 +Subject: [PATCH] add standby + +Signed-off-by: xufanghan +--- + inherit/default.json | 4 ++++ + inherit/pc.json | 4 ++++ + inherit/rich.json | 4 ++++ + inherit/tablet.json | 4 ++++ + 4 files changed, 16 insertions(+) + +diff --git a/inherit/default.json b/inherit/default.json +index 3621e9e..7f1c3ef 100644 +--- a/inherit/default.json ++++ b/inherit/default.json +@@ -858,6 +858,10 @@ + { + "component": "device_usage_statistics", + "features": [] ++ }, ++ { ++ "component": "device_standby", ++ "features": [] + } + ] + }, +diff --git a/inherit/pc.json b/inherit/pc.json +index 89392c5..9801307 100644 +--- a/inherit/pc.json ++++ b/inherit/pc.json +@@ -834,6 +834,10 @@ + { + "component": "device_usage_statistics", + "features": [] ++ }, ++ { ++ "component": "device_standby", ++ "features": [] + } + ] + }, +diff --git a/inherit/rich.json b/inherit/rich.json +index 7277257..3ede13a 100644 +--- a/inherit/rich.json ++++ b/inherit/rich.json +@@ -893,6 +893,10 @@ + { + "component": "qos_manager", + "features": [] ++ }, ++ { ++ "component": "device_standby", ++ "features": [] + } + ] + }, +diff --git a/inherit/tablet.json b/inherit/tablet.json +index 1e0e322..8f2bfbe 100644 +--- a/inherit/tablet.json ++++ b/inherit/tablet.json +@@ -792,6 +792,10 @@ + { + "component": "device_usage_statistics", + "features": [] ++ }, ++ { ++ "component": "device_standby", ++ "features": [] + } + ] + }, +-- +Gitee \ No newline at end of file diff --git a/patches/patches.json b/patches/patches.json new file mode 100644 index 0000000000000000000000000000000000000000..81ad443448c0b263191f555abb09413769469339 --- /dev/null +++ b/patches/patches.json @@ -0,0 +1,17 @@ +{ + "patches":[ + { + "project":"productdefine_common", + "patch_file":"component.patch", + "path":"productdefine/common", + "pr_url":"https://gitee.com/openharmony/productdefine_common/pulls/666" + }, + { + "project":" resourceschedule_work_scheduler", + "patch_file":"workschedule.patch", + "path":"foundation/resourceschedule/work_scheduler", + "pr_url":"https://gitee.com/openharmony/resourceschedule_work_scheduler/pulls/269" + } + + ] +} \ No newline at end of file diff --git a/patches/workschedule.patch b/patches/workschedule.patch new file mode 100644 index 0000000000000000000000000000000000000000..a530d3af94ea2b08855b444fb882547f8fb18669 --- /dev/null +++ b/patches/workschedule.patch @@ -0,0 +1,25 @@ +From 94d4a38669a5a7126efc03bee4b0e9eac65997a9 Mon Sep 17 00:00:00 2001 +From: geraltxu <36860135+geraltxu@users.noreply.github.com> +Date: Fri, 7 Jul 2023 17:05:49 +0800 +Subject: [PATCH] log output bug fix + +Signed-off-by: xufanghan +--- + services/native/src/work_scheduler_service.cpp | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/services/native/src/work_scheduler_service.cpp b/services/native/src/work_scheduler_service.cpp +index 9760f1be..d85c7818 100644 +--- a/services/native/src/work_scheduler_service.cpp ++++ b/services/native/src/work_scheduler_service.cpp +@@ -780,7 +780,7 @@ bool WorkSchedulerService::CheckStandbyApplyInfo(std::string& bundleName) + std::vector allowInfoArray; + DevStandbyMgr::StandbyServiceClient::GetInstance().GetAllowList(DevStandbyMgr::AllowType::WORK_SCHEDULER, + allowInfoArray, DevStandbyMgr::ReasonCodeEnum::REASON_APP_API); +- WS_HILOGD("allowInfoArray size is %{public}ld", allowInfoArray.size()); ++ WS_HILOGD("allowInfoArray size is %{public}d", static_cast(allowInfoArray.size())); + for (const auto& item : allowInfoArray) { + if (item.GetName() == bundleName) { + return true; +-- +Gitee diff --git a/plugins/BUILD.gn b/plugins/BUILD.gn index 48dbff9c392b8491b9a03ede5bc6ee0b0902117d..44371742e20d93cbf41ab53997a98b9d5399fe64 100644 --- a/plugins/BUILD.gn +++ b/plugins/BUILD.gn @@ -32,6 +32,7 @@ ohos_shared_library("standby_plugin") { "${standby_service_constraints_path}/src/charge_state_monitor.cpp", "${standby_service_constraints_path}/src/constraint_manager_adapter.cpp", "${standby_service_constraints_path}/src/motion_sensor_monitor.cpp", + "${standby_service_message_listener_path}/src/background_task_listener.cpp", "${standby_service_message_listener_path}/src/common_event_listener.cpp", "${standby_service_message_listener_path}/src/input_manager_listener.cpp", "${standby_service_message_listener_path}/src/listener_manager_adapter.cpp", @@ -45,10 +46,7 @@ ohos_shared_library("standby_plugin") { "${standby_service_standby_state_path}/src/state_manager_adapter.cpp", "${standby_service_standby_state_path}/src/working_state.cpp", "${standby_service_strategy_path}/src/network_strategy.cpp", - "${standby_service_strategy_path}/src/running_lock_strategy.cpp", "${standby_service_strategy_path}/src/strategy_manager_adapter.cpp", - "${standby_service_strategy_path}/src/timer_strategy.cpp", - "${standby_service_strategy_path}/src/work_scheduler_strategy.cpp", ] public_configs = [ ":standby_plugin_config" ] @@ -70,15 +68,20 @@ ohos_shared_library("standby_plugin") { "access_token:libtokenid_sdk", "battery_manager:batterysrv_client", "c_utils:utils", + "call_manager:tel_call_manager_api", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", "hilog:libhilog", "init:libbegetutil", "input:libmmi-client", "ipc:ipc_single", + "netmanager_base:net_policy_manager_if", "power_manager:powermgr_client", + "samgr:samgr_proxy", "sensor:sensor_interface_native", "time_service:time_client", + "work_scheduler:workschedclient", + "wifi:wifi_sdk", ] defines = [] @@ -87,6 +90,11 @@ ohos_shared_library("standby_plugin") { defines += [ "STANDBY_CONFIG_POLICY_ENABLE" ] } + if (enable_background_task_mgr) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + defines += [ "ENABLE_BACKGROUND_TASK_MGR" ] + } + subsystem_name = "resourceschedule" part_name = "${standby_service_part_name}" } diff --git a/plugins/ext/include/ibase_strategy.h b/plugins/ext/include/ibase_strategy.h index 4483238a64cd218aa554ea8500b732507575c498..b5b1a43d050b49762c59bc19c553c7a57a5159cf 100644 --- a/plugins/ext/include/ibase_strategy.h +++ b/plugins/ext/include/ibase_strategy.h @@ -20,14 +20,56 @@ namespace OHOS { namespace DevStandbyMgr { + +struct BaseAppInfo { + std::string name_ {""}; + int32_t uid_ {-1}; + int32_t pid_ {-1}; +}; + +class ExemptionTypeFlag { +public: +enum : uint8_t { + // apps which has applied continuous task + CONTINUOUS_TASK = 1, + // apps which has applied transient task + TRANSIENT_TASK = 1 << 1, + // app with work scheduler + WORK_SCHEDULER = 1 << 2, + // foreground app will not be restricted + FOREGROUND_APP = 1 << 3, + // default exemption, used for system app or native process not configured in restriction list + DEFAULT_EXEMPTION = 1 << 4, + // applied exemption + APPLIED_EXEMPTION = 1 << 5, + // app is configured to restricted + RESTRICTED = 1 << 6, +}; + +public: + inline static bool IsExempted(uint8_t flag) { + if ((flag & APPLIED_EXEMPTION) != 0) { + return true; + } else if ((flag & RESTRICTED) != 0) { + return false; + } + return flag != 0; + } +}; + class IBaseStrategy { public: virtual void HandleEvent(const StandbyMessage& message) = 0; + /** + * @brief invoked when strategy is initialized, reset restriction status + */ virtual ErrCode OnCreated() = 0; + /** + * @brief invoked when strategy is destroyed, finalize restriction status + */ virtual ErrCode OnDestroy() = 0; + virtual void ShellDump(const std::vector& argsInStr, std::string& result) = 0; virtual ~IBaseStrategy() = default; -protected: - int32_t policyId_ {0}; }; } // namespace DevStandbyMgr } // namespace OHOS diff --git a/plugins/ext/include/ilistener_manager_adapter.h b/plugins/ext/include/ilistener_manager_adapter.h index 6c94f48dca7611dce890d503724790c647a89216..ae4f8aea20ed600c796f9ade8a5958f2e261ce10 100644 --- a/plugins/ext/include/ilistener_manager_adapter.h +++ b/plugins/ext/include/ilistener_manager_adapter.h @@ -18,6 +18,7 @@ #include #include +#include #include "event_handler.h" #include "event_runner.h" @@ -34,10 +35,12 @@ public: virtual bool UnInit() = 0; virtual ErrCode StartListener() = 0; virtual ErrCode StopListener() = 0; + virtual void HandleEvent(const StandbyMessage& message) = 0; virtual void ShellDump(const std::vector& argsInStr, std::string& result) = 0; virtual ~IListenerManagerAdapter() = default; protected: std::vector> messageListenerList_ {}; + std::map> listenerPluginMap_ {}; }; } // namespace DevStandbyMgr } // namespace OHOS diff --git a/plugins/ext/include/istrategy_manager_adapter.h b/plugins/ext/include/istrategy_manager_adapter.h index 46f214323cd2bfbf95f259f8f90a21e89c0e8b24..4523197e969b5ca52e6100351752e577ce159350 100644 --- a/plugins/ext/include/istrategy_manager_adapter.h +++ b/plugins/ext/include/istrategy_manager_adapter.h @@ -18,6 +18,7 @@ #include #include #include +#include #include "ibase_strategy.h" #include "standby_service_errors.h" @@ -28,6 +29,7 @@ class IStrategyManagerAdapter { public: virtual ~IStrategyManagerAdapter() = default; virtual bool Init() = 0; + virtual bool UnInit() = 0; virtual void HandleEvent(const StandbyMessage& message) = 0; virtual void ShellDump(const std::vector& argsInStr, std::string& result) = 0; protected: diff --git a/plugins/ext/include/standby_messsage.h b/plugins/ext/include/standby_messsage.h index 36664bc96b6d38974f9591ef9177820b65668d0d..568f4e996d84ecff64a090a18b0fb5d73e89bef8 100644 --- a/plugins/ext/include/standby_messsage.h +++ b/plugins/ext/include/standby_messsage.h @@ -33,9 +33,13 @@ struct StandbyMessageType { COMMON_EVENT = 1, STATE_TRANSIT, PHASE_TRANSIT, - RES_CTRL_CONDITION_CHANGED, + RES_CTRL_CONDITION_CHANGED, // day and night switch ALLOW_LIST_CHANGED, SCREEN_OFF_HALF_HOUR, + BG_TASK_STATUS_CHANGE, // application apply or unapply background task, start or stop work scheduler + SYS_ABILITY_STATUS_CHANGED, // system ability is added or removed + PROCESS_STATE_CHANGED, // process is created or died + DEVICE_STATE_CHANGED, // process is created or died }; }; diff --git a/plugins/ext/src/base_state.cpp b/plugins/ext/src/base_state.cpp index 73450228f4242aeb51da728e54ee5dcc3516ec2f..19757e656e908019fa33c7c00968a8eabe529caf 100644 --- a/plugins/ext/src/base_state.cpp +++ b/plugins/ext/src/base_state.cpp @@ -20,6 +20,7 @@ #include "standby_messsage.h" #include "standby_service_log.h" +#include "standby_config_manager.h" #include "istate_manager_adapter.h" #include "timed_task.h" @@ -209,9 +210,8 @@ int64_t StateWithMaint::CalculateMaintTimeOut(const std::shared_ptrGetWallTimeMs() / MSEC_PER_SEC; - TimeProvider::DiffToFixedClock(curSecTimeStamp, DAY_ENTRANCE_HOUR, DAY_ENTRANCE_MIN, timeDiff); + if (TimeProvider::GetCondition(maintIntervalTimeOut) == ConditionType::NIGHT_STANDBY && + TimeProvider::TimeDiffToDayNightSwitch(timeDiff)) { maintIntervalTimeOut *= TimeConstant::MSEC_PER_SEC; maintIntervalTimeOut += timeDiff; return maintIntervalTimeOut; diff --git a/plugins/message_listener/include/background_task_listener.h b/plugins/message_listener/include/background_task_listener.h new file mode 100644 index 0000000000000000000000000000000000000000..b119eccd08bd787bf8d1f19667a84d015aff7288 --- /dev/null +++ b/plugins/message_listener/include/background_task_listener.h @@ -0,0 +1,106 @@ +/* + * 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 FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_SERVICES_CORE_INCLUDE_BACKGROUND_TASK_LISTENER_H +#define FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_SERVICES_CORE_INCLUDE_BACKGROUND_TASK_LISTENER_H + +#ifdef STANDBY_SERVICE_UNIT_TEST +#define WEAK_FUNC __attribute__((weak)) +#else +#define WEAK_FUNC +#endif // STANDBY_SERVICE_UNIT_TEST + +#include +#include +#include "ipc_skeleton.h" +#include "iremote_object.h" +#include "background_task_subscriber.h" +#include "background_task_mgr_helper.h" +#include "resource_callback_info.h" + +#include "standby_service_log.h" +#include "standby_service_errors.h" +#include "imessage_listener.h" +#include "istate_manager_adapter.h" +#include "single_instance.h" + +namespace OHOS { +namespace DevStandbyMgr { +using namespace OHOS::BackgroundTaskMgr; +class BackgroundTaskListener : public std::enable_shared_from_this, public IMesssageListener { +public: + BackgroundTaskListener(); + ~BackgroundTaskListener() override = default; + + /** + * @brief Register background task observer. + */ + ErrCode StartListener() override; + + /** + * @brief Unregister background task observer. + */ + ErrCode StopListener() override; +private: + class BgTaskListenerImpl : public OHOS::BackgroundTaskMgr::BackgroundTaskSubscriber { + public: + BgTaskListenerImpl(); + + /** + * Called back when a continuous task start. + * + * @param info Transient task app info. + */ + virtual void OnAppTransientTaskStart(const std::shared_ptr& info) override; + + /** + * Called back when the app does not have transient task. + * + * @param info App info transient task . + */ + virtual void OnAppTransientTaskEnd(const std::shared_ptr& info) override; + + /** + * Called back when a continuous task start. + * + * @param info Continuous task app info. + */ + virtual void OnContinuousTaskStart( + const std::shared_ptr &continuousTaskCallbackInfo) override; + + /** + * Called back when a continuous task end. + * + * @param info Continuous task info. + */ + virtual void OnContinuousTaskStop( + const std::shared_ptr &continuousTaskCallbackInfo) override; + + private: + /** + * @brief dispatch BG_TASK_STATUS_CHANGE event when background task started or stopped + */ + void OnTaskStatusChanged(const std::string& type, bool started, int32_t uid, int32_t pid, + const std::string& bundleName); + private: + std::shared_ptr handler_ {nullptr}; + }; + +private: + std::unique_ptr bgTaskListenerImpl_ {nullptr}; +}; +} +} +#endif // FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_SERVICES_CORE_INCLUDE_BACKGROUND_TASK_LISTENER_H \ No newline at end of file diff --git a/plugins/message_listener/include/common_event_listener.h b/plugins/message_listener/include/common_event_listener.h index 42c7c974ca33be6bedca91b5482391f1a03bf9fc..f1aaa60d66a0d0dea090d4c345de46dc1e007561 100644 --- a/plugins/message_listener/include/common_event_listener.h +++ b/plugins/message_listener/include/common_event_listener.h @@ -46,10 +46,8 @@ public: ErrCode StopListener() override; void OnReceiveEvent(const EventFwk::CommonEventData& eventData) override; void SetEventHandler(const std::shared_ptr& handler); - private: std::shared_ptr handler_ {nullptr}; - bool isScreenOn_ {true}; }; } // namespace DevStandbyMgr } // namespace OHOS diff --git a/plugins/message_listener/include/listener_manager_adapter.h b/plugins/message_listener/include/listener_manager_adapter.h index 65c6b9e8c47eb89e0298a168ee748d98c5f63d4a..fdc11683cb74041aa98967338d937c1fd0dfd541 100644 --- a/plugins/message_listener/include/listener_manager_adapter.h +++ b/plugins/message_listener/include/listener_manager_adapter.h @@ -27,9 +27,14 @@ public: ~ListenerManagerAdapter() override = default; bool Init() override; bool UnInit() override; + void HandleEvent(const StandbyMessage& message) override; ErrCode StartListener() override; ErrCode StopListener() override; void ShellDump(const std::vector& argsInStr, std::string& result) override; +private: + void UpdateListenerList(const StandbyMessage& message); + void AddSystemServiceListener(int32_t systemAbilityId); + void RemoveSystemServiceListener(int32_t systemAbilityId); }; } // namespace DevStandbyMgr } // namespace OHOS diff --git a/plugins/message_listener/src/background_task_listener.cpp b/plugins/message_listener/src/background_task_listener.cpp new file mode 100644 index 0000000000000000000000000000000000000000..775f592ad70180900661ba1053028fadb4809da7 --- /dev/null +++ b/plugins/message_listener/src/background_task_listener.cpp @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "background_task_listener.h" +#include "system_ability_definition.h" +#include "standby_service_impl.h" + +namespace OHOS { +namespace DevStandbyMgr { + +BackgroundTaskListener::BackgroundTaskListener() +{ + bgTaskListenerImpl_ = std::make_unique(); +} + +ErrCode BackgroundTaskListener::StartListener() +{ + if (!bgTaskListenerImpl_) { + STANDBYSERVICE_LOGE("backgroundTaskListener is nullptr"); + return ERR_BGTASK_LISTENER_NULL; + } + if (BackgroundTaskMgrHelper::SubscribeBackgroundTask(*bgTaskListenerImpl_) != OHOS::ERR_OK) { + STANDBYSERVICE_LOGE("SubscribeBackgroundTask failed"); + return ERR_REGISTER_BACKGROUND_TASK_FAILED; + } + STANDBYSERVICE_LOGI("backgroundTaskListener start listener"); + return ERR_OK; +} + +ErrCode BackgroundTaskListener::StopListener() +{ + if (!bgTaskListenerImpl_) { + STANDBYSERVICE_LOGE("backgroundTaskListener is nullptr"); + return ERR_BGTASK_LISTENER_NULL; + } + if (BackgroundTaskMgrHelper::UnsubscribeBackgroundTask(*bgTaskListenerImpl_) != OHOS::ERR_OK) { + STANDBYSERVICE_LOGE("UnsubscribeBackgroundTask failed"); + return ERR_UNREGISTER_BACKGROUND_TASK_FAILED; + } + STANDBYSERVICE_LOGI("backgroundTaskListener stop listener"); + return ERR_OK; +} + +BackgroundTaskListener::BgTaskListenerImpl::BgTaskListenerImpl() +{ + handler_ = StandbyServiceImpl::GetInstance()->GetHandler(); +} + +void BackgroundTaskListener::BgTaskListenerImpl::OnAppTransientTaskStart(const + std::shared_ptr& info) +{ + STANDBYSERVICE_LOGD("Transient start called, uid is %{public}d, bundle name is %{public}s", + info->GetUid(), info->GetPackageName().c_str()); + OnTaskStatusChanged(TRANSIENT_TASK, true, info->GetUid(), info->GetPid(), info->GetPackageName()); +} + +void BackgroundTaskListener::BgTaskListenerImpl::OnAppTransientTaskEnd(const + std::shared_ptr& info) +{ + STANDBYSERVICE_LOGD("Transient stop called, uid is %{public}d, bundle name is %{public}s", + info->GetUid(), info->GetPackageName().c_str()); + OnTaskStatusChanged(TRANSIENT_TASK, false, info->GetUid(), info->GetPid(), info->GetPackageName()); +} + +void BackgroundTaskListener::BgTaskListenerImpl::OnContinuousTaskStart( + const std::shared_ptr &continuousTaskCallbackInfo) +{ + STANDBYSERVICE_LOGD("Continuous start called, uid is %{public}d", continuousTaskCallbackInfo->GetCreatorUid()); + OnTaskStatusChanged(CONTINUOUS_TASK, true, continuousTaskCallbackInfo->GetCreatorUid(), + continuousTaskCallbackInfo->GetCreatorPid(), ""); +} + +void BackgroundTaskListener::BgTaskListenerImpl::OnContinuousTaskStop( + const std::shared_ptr &continuousTaskCallbackInfo) +{ + STANDBYSERVICE_LOGD("Continuous stop called, uid is %{public}d", continuousTaskCallbackInfo->GetCreatorUid()); + OnTaskStatusChanged(CONTINUOUS_TASK, false, continuousTaskCallbackInfo->GetCreatorUid(), + continuousTaskCallbackInfo->GetCreatorPid(), ""); +} + +void BackgroundTaskListener::BgTaskListenerImpl::OnTaskStatusChanged(const std::string& type, bool started, + int32_t uid, int32_t pid, const std::string& bundleName) +{ + StandbyMessage standbyMessage {StandbyMessageType::BG_TASK_STATUS_CHANGE}; + standbyMessage.want_ = AAFwk::Want{}; + standbyMessage.want_->SetParam(BG_TASK_TYPE, type); + standbyMessage.want_->SetParam(BG_TASK_STATUS, started); + standbyMessage.want_->SetParam(BG_TASK_UID, uid); + standbyMessage.want_->SetParam(BG_TASK_BUNDLE_NAME, bundleName); + handler_->PostTask([standbyMessage]() { + StandbyServiceImpl::GetInstance()->DispatchEvent(standbyMessage); + }); +} +} // OHOS +} // DevStandbyMgr \ No newline at end of file diff --git a/plugins/message_listener/src/common_event_listener.cpp b/plugins/message_listener/src/common_event_listener.cpp index a1a284015628bcf3523a6c624fec31f51afda48a..0c679a30ace24a48ef268dd3874c29bcfef75a06 100644 --- a/plugins/message_listener/src/common_event_listener.cpp +++ b/plugins/message_listener/src/common_event_listener.cpp @@ -59,12 +59,10 @@ void CommonEventListener::OnReceiveEvent(const EventFwk::CommonEventData& eventD STANDBYSERVICE_LOGD("receive common event %{public}s", action.c_str()); if (action == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON) { handler_->PostTask([this, action]() { - isScreenOn_ = true; StandbyServiceImpl::GetInstance()->DispatchEvent(StandbyMessage(StandbyMessageType::COMMON_EVENT, action)); }); } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF) { handler_->PostTask([this, action]() { - isScreenOn_ = false; StandbyServiceImpl::GetInstance()->DispatchEvent(StandbyMessage(StandbyMessageType::COMMON_EVENT, action)); }); } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_CHARGING || @@ -72,9 +70,6 @@ void CommonEventListener::OnReceiveEvent(const EventFwk::CommonEventData& eventD action == EventFwk::CommonEventSupport::COMMON_EVENT_DISCHARGING || action == EventFwk::CommonEventSupport::COMMON_EVENT_USB_DEVICE_DETACHED) { handler_->PostTask([this, action]() { - if (isScreenOn_) { - return; - } StandbyServiceImpl::GetInstance()->DispatchEvent(StandbyMessage(StandbyMessageType::COMMON_EVENT, action)); }); } diff --git a/plugins/message_listener/src/listener_manager_adapter.cpp b/plugins/message_listener/src/listener_manager_adapter.cpp index 9fe05f1108d49c1fb63b61a3d4fc7911b54e6045..78426f584485138984508c65e8d96cc8e72a53e8 100644 --- a/plugins/message_listener/src/listener_manager_adapter.cpp +++ b/plugins/message_listener/src/listener_manager_adapter.cpp @@ -16,14 +16,22 @@ #include "listener_manager_adapter.h" +#include +#include + #include "common_event_manager.h" #include "common_event_support.h" #include "standby_service_log.h" -#include "common_event_listener.h" #include "device_standby_switch.h" #include "standby_service_impl.h" #include "input_manager_listener.h" +#include "standby_service.h" + +#include "standby_config_manager.h" +#include "common_event_listener.h" +#include "system_ability_definition.h" +#include "background_task_listener.h" namespace OHOS { namespace DevStandbyMgr { @@ -50,6 +58,10 @@ bool ListenerManagerAdapter::Init() EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills); messageListenerList_.emplace_back(std::make_shared(subscriberInfo)); messageListenerList_.emplace_back(std::make_shared()); + // network and running lock strategy need background task listener + STANDBYSERVICE_LOGI("add background task listener"); + std::shared_ptr bgtaskListener_ = std::make_shared(); + listenerPluginMap_.emplace(BACKGROUND_TASK_MANAGER_SERVICE_ID, bgtaskListener_); STANDBYSERVICE_LOGI("listener manager plugin initialization succeed"); return true; } @@ -57,20 +69,65 @@ bool ListenerManagerAdapter::Init() bool ListenerManagerAdapter::UnInit() { StopListener(); - for (auto& listener : messageListenerList_) { - listener->StopListener(); - } messageListenerList_.clear(); return true; } +void ListenerManagerAdapter::HandleEvent(const StandbyMessage& message) +{ + switch (message.eventId_) { + case StandbyMessageType::SYS_ABILITY_STATUS_CHANGED: + UpdateListenerList(message); + break; + default: + break; + } +} + +void ListenerManagerAdapter::UpdateListenerList(const StandbyMessage& message) +{ + bool isAdded = message.want_->GetBoolParam(SA_STATUS, false); + int32_t systemAbilityId = message.want_->GetIntParam(SA_ID, -1); + if (isAdded) { + // add listener if system ablity started + AddSystemServiceListener(systemAbilityId); + return; + } + RemoveSystemServiceListener(systemAbilityId); +} + +// when system ability is added, add relative listener +void ListenerManagerAdapter::AddSystemServiceListener(int32_t systemAbilityId) +{ + auto iter = listenerPluginMap_.find(systemAbilityId); + if (iter == listenerPluginMap_.end()) { + return; + } + STANDBYSERVICE_LOGI("%{public}d added, start listener", systemAbilityId); + std::shared_ptr listener = iter->second; + if (listener->StartListener() == ERR_OK) { + messageListenerList_.emplace_back(listener); + } +} + +// when system ability is removed, remove relative listener +void ListenerManagerAdapter::RemoveSystemServiceListener(int32_t systemAbilityId) +{ + auto iter = listenerPluginMap_.find(systemAbilityId); + if (iter == listenerPluginMap_.end()) { + return; + } + std::shared_ptr listener = iter->second; + auto listenerIter = std::remove(messageListenerList_.begin(), messageListenerList_.end(), iter->second); + if (listenerIter != messageListenerList_.end()) { + messageListenerList_.erase(listenerIter, messageListenerList_.end()); + } +} + ErrCode ListenerManagerAdapter::StartListener() { for (auto& listener : messageListenerList_) { - ErrCode ret = listener->StartListener(); - if (ret != ERR_OK) { - return ret; - } + listener->StartListener(); } return ERR_OK; } @@ -78,10 +135,7 @@ ErrCode ListenerManagerAdapter::StartListener() ErrCode ListenerManagerAdapter::StopListener() { for (auto& listener : messageListenerList_) { - ErrCode ret = listener->StopListener(); - if (ret != ERR_OK) { - return ret; - } + listener->StopListener(); } return ERR_OK; } diff --git a/plugins/standby_state/include/state_manager_adapter.h b/plugins/standby_state/include/state_manager_adapter.h index ed764d25b809ef33a4545ce4acff848ab7e3e47f..1298cb83acb3c7c443a26c7f675d563925c96fd7 100644 --- a/plugins/standby_state/include/state_manager_adapter.h +++ b/plugins/standby_state/include/state_manager_adapter.h @@ -50,7 +50,9 @@ private: void OnScreenOffHalfHourInner(bool scrOffHalfHourCtrl, bool repeated); void HandleCommonEvent(const StandbyMessage& message); + void HandleScreenStatus(const StandbyMessage& message); void HandleScrOffHalfHour(const StandbyMessage& message); + bool CheckEnterDarkState(const StandbyMessage& message); void DumpShowDetailInfo(const std::vector& argsInStr, std::string& result); void DumpEnterSpecifiedState(const std::vector& argsInStr, std::string& result); void DumpActivateMotion(const std::vector& argsInStr, std::string& result); @@ -61,6 +63,7 @@ private: std::shared_ptr sleepStatePtr_ {nullptr}; std::shared_ptr workingStatePtr_ {nullptr}; std::vector> indexToState_ {}; + bool isScreenOn_ {true}; }; } // namespace DevStandbyMgr } // namespace OHOS diff --git a/plugins/standby_state/src/state_manager_adapter.cpp b/plugins/standby_state/src/state_manager_adapter.cpp index 56d442e35333b48e3d9b6eb217b467e5cf29caa9..0d8760b9c2d14ed5b6f017cdadae6d181478c322 100644 --- a/plugins/standby_state/src/state_manager_adapter.cpp +++ b/plugins/standby_state/src/state_manager_adapter.cpp @@ -99,6 +99,7 @@ void StateManagerAdapter::HandleCommonEvent(const StandbyMessage& message) { HandleScrOffHalfHour(message); HandleOpenCloseLid(message); + HandleScreenStatus(message); if (message.action_ == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON || message.action_ == EventFwk::CommonEventSupport::COMMON_EVENT_CHARGING || message.action_ == EventFwk::CommonEventSupport::COMMON_EVENT_USB_DEVICE_ATTACHED) { @@ -107,12 +108,33 @@ void StateManagerAdapter::HandleCommonEvent(const StandbyMessage& message) if (curStatePtr_->GetCurState() != StandbyState::WORKING) { return; } - if (message.action_ == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF || - message.action_ == EventFwk::CommonEventSupport::COMMON_EVENT_DISCHARGING) { + if (CheckEnterDarkState(message)) { TransitToState(StandbyState::DARK); } } +void StateManagerAdapter::HandleScreenStatus(const StandbyMessage& message) +{ + if (message.action_ == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON) { + isScreenOn_ = true; + } else if (message.action_ == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF) { + isScreenOn_ = false; + } +} + +bool StateManagerAdapter::CheckEnterDarkState(const StandbyMessage& message) +{ + if (isScreenOn_) { + return false; + } + if (message.action_ == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF || + message.action_ == EventFwk::CommonEventSupport::COMMON_EVENT_DISCHARGING || + message.action_ == EventFwk::CommonEventSupport::COMMON_EVENT_USB_DEVICE_DETACHED) { + return true; + } + return true; +} + void StateManagerAdapter::HandleScrOffHalfHour(const StandbyMessage& message) { if (scrOffHalfHourTimerId_ == 0) { @@ -350,6 +372,21 @@ void StateManagerAdapter::DumpActivateMotion(const std::vector& arg BlockCurrentState(); } else if (argsInStr[DUMP_SECOND_PARAM] == "--halfhour") { OnScreenOffHalfHourInner(true, true); + } else if (argsInStr[DUMP_SECOND_PARAM] == "--poweroff") { + handler_->PostTask([this]() { + STANDBYSERVICE_LOGD("after 2000ms, start poweroff mode"); + UnblockCurrentState(); + TransitToStateInner(StandbyState::SLEEP); + OnScreenOffHalfHourInner(true, true); + std::string res {""}; + StandbyServiceImpl::GetInstance()->ShellDumpInner({"-D", "--strategy", "poweroff"}, res); + }, 20 * 1000); + } else if (argsInStr[DUMP_SECOND_PARAM] == "--powersave") { + STANDBYSERVICE_LOGD("after 3000ms, start powersavenetwork"); + UnblockCurrentState(); + TransitToStateInner(StandbyState::SLEEP); + OnScreenOffHalfHourInner(true, true); + StandbyServiceImpl::GetInstance()->ShellDumpInner({"-D", "--strategy", "powersave"}, result); } } } // namespace DevStandbyMgr diff --git a/plugins/strategy/include/network_strategy.h b/plugins/strategy/include/network_strategy.h index 019563f7b78ae307922e5db17af912a8190fe641..8d3b87f6424021e7b2b07fb892657379b56822ae 100644 --- a/plugins/strategy/include/network_strategy.h +++ b/plugins/strategy/include/network_strategy.h @@ -23,6 +23,7 @@ class NetworkStrategy : public IBaseStrategy { void HandleEvent(const StandbyMessage& message) override; ErrCode OnCreated() override; ErrCode OnDestroy() override; + void ShellDump(const std::vector& argsInStr, std::string& result) override; }; } // namespace DevStandbyMgr } // namespace OHOS diff --git a/plugins/strategy/include/strategy_manager_adapter.h b/plugins/strategy/include/strategy_manager_adapter.h index 23b9f8004c05b3581ea0312e66fa4d14c9acb1b4..0a65847b398e8569f5f057c2edd39cc2bcff1329 100644 --- a/plugins/strategy/include/strategy_manager_adapter.h +++ b/plugins/strategy/include/strategy_manager_adapter.h @@ -27,6 +27,7 @@ public: StrategyManagerAdapter() = default; ~StrategyManagerAdapter() override = default; bool Init() override; + bool UnInit() override; void HandleEvent(const StandbyMessage& messageType) override; void ShellDump(const std::vector& argsInStr, std::string& result) override; diff --git a/plugins/strategy/src/network_strategy.cpp b/plugins/strategy/src/network_strategy.cpp index 74ae4fce23b48d2a4fac4441f35924785a70d094..66846a662515993fa3fa6d02cd97771e264b898f 100644 --- a/plugins/strategy/src/network_strategy.cpp +++ b/plugins/strategy/src/network_strategy.cpp @@ -33,5 +33,9 @@ ErrCode NetworkStrategy::OnDestroy() { return ERR_OK; } + +void NetworkStrategy::ShellDump(const std::vector& argsInStr, std::string& result) +{ +} } // namespace DevStandbyMgr } // namespace OHOS \ No newline at end of file diff --git a/plugins/strategy/src/strategy_manager_adapter.cpp b/plugins/strategy/src/strategy_manager_adapter.cpp index 7706632d2069839a78e637c5694de93cd1ed4a11..99e2b8a1e0fbe85433145e9fb51c35c026f69d79 100644 --- a/plugins/strategy/src/strategy_manager_adapter.cpp +++ b/plugins/strategy/src/strategy_manager_adapter.cpp @@ -23,13 +23,15 @@ #include "ibase_strategy.h" #include "standby_service_log.h" #include "network_strategy.h" -#include "timer_strategy.h" -#include "running_lock_strategy.h" -#include "work_scheduler_strategy.h" #include "standby_config_manager.h" namespace OHOS { namespace DevStandbyMgr { +namespace { +const std::map> strategyMap_ { + {"NETWORK", std::make_shared() }, +}; +} bool StrategyManagerAdapter::Init() { @@ -47,22 +49,30 @@ bool StrategyManagerAdapter::Init() return true; } +bool StrategyManagerAdapter::UnInit() +{ + for (const auto& strategy : strategyList_) { + strategy->OnDestroy(); + } + strategyList_.clear(); + return true; +} + void StrategyManagerAdapter::RegisterPolicy(const std::vector& strategies) { - for (const auto& iter : strategies) { - std::shared_ptr strategyPtr {nullptr}; - if (iter == "NET") { - strategyPtr = std::make_shared(); - } else if (iter == "TIMER") { - strategyPtr = std::make_shared(); - } else if (iter == "RUNNING_LOCK") { - strategyPtr = std::make_shared(); - } else if (iter == "WORK_SCHEDULER") { - strategyPtr = std::make_shared(); - } else { + for (const auto& item : strategies) { + auto strategy = strategyMap_.find(item); + if (strategy == strategyMap_.end()) { continue; } - strategyList_.emplace_back(strategyPtr); + STANDBYSERVICE_LOGI("strategy manager init %{public}s", item.c_str()); + auto strategyPtr = strategy->second; + if (!strategyPtr) { + continue; + } + if (strategyPtr->OnCreated() == ERR_OK) { + strategyList_.emplace_back(strategyPtr); + } } } @@ -77,6 +87,9 @@ void StrategyManagerAdapter::HandleEvent(const StandbyMessage& message) void StrategyManagerAdapter::ShellDump(const std::vector& argsInStr, std::string& result) { + for (const auto &strategy : strategyList_) { + strategy->ShellDump(argsInStr, result); + } } } // namespace DevStandbyMgr } // namespace OHOS \ No newline at end of file diff --git a/plugins/test/unittest/standby_plugin_unit_test.cpp b/plugins/test/unittest/standby_plugin_unit_test.cpp index 4d3f9ae6f15de9ec17a56648bf3272100f108591..5b7c42951ccdb25c98473e6db7bb70aa9e4a4f5e 100644 --- a/plugins/test/unittest/standby_plugin_unit_test.cpp +++ b/plugins/test/unittest/standby_plugin_unit_test.cpp @@ -146,7 +146,7 @@ HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_001, TestSize.Level1) */ HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_002, TestSize.Level1) { - strategyManager_->RegisterPolicy({"NET", "TIMER", "RUNNING_LOCK", "WORK_SCHEDULER", ""}); + strategyManager_->RegisterPolicy({"NETWORK", "TIMER", "RUNNING_LOCK", "WORK_SCHEDULER", ""}); EXPECT_NE(strategyManager_->strategyList_.size(), 0); } @@ -344,7 +344,7 @@ HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_010, TestSize.Level1) standbyStateManager_->napStatePtr_->EndEvalCurrentState(false); standbyStateManager_->napStatePtr_->EndEvalCurrentState(true); SleepForFC(); - EXPECT_NE(standbyStateManager_->curStatePtr_->GetCurState(), StandbyState::WORKING); + EXPECT_NE(standbyStateManager_->curStatePtr_->GetCurState(), StandbyState::MAINTENANCE); } /** diff --git a/services/BUILD.gn b/services/BUILD.gn index d13e000d34c4d26c7cdd8a4e6ee3a09dc22fa28f..5006b9886c202fff8d392515209d92f7a1c08d1d 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -30,6 +30,7 @@ ohos_shared_library("standby_service") { } sources = [ + "common/src/background_task_helper.cpp", "common/src/device_standby_switch.cpp", "common/src/time_provider.cpp", "common/src/timed_task.cpp", @@ -73,6 +74,13 @@ ohos_shared_library("standby_service") { "samgr:samgr_proxy", "time_service:time_client", ] + + defines = [] + if (enable_background_task_mgr) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + defines += [ "ENABLE_BACKGROUND_TASK_MGR" ] + } + subsystem_name = "resourceschedule" part_name = "${standby_service_part_name}" @@ -82,6 +90,7 @@ ohos_shared_library("standby_service") { ohos_static_library("standby_service_static") { cflags_cc = [ "-DSTANDBY_SERVICE_UNIT_TEST" ] sources = [ + "common/src/background_task_helper.cpp", "common/src/device_standby_switch.cpp", "common/src/time_provider.cpp", "common/src/timed_task.cpp", @@ -125,6 +134,13 @@ ohos_static_library("standby_service_static") { "samgr:samgr_proxy", "time_service:time_client", ] + + defines = [] + if (enable_background_task_mgr) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + defines += [ "ENABLE_BACKGROUND_TASK_MGR" ] + } + subsystem_name = "resourceschedule" part_name = "${standby_service_part_name}" } \ No newline at end of file diff --git a/services/common/include/background_task_helper.h b/services/common/include/background_task_helper.h new file mode 100644 index 0000000000000000000000000000000000000000..2a99bb4e1113043b0df83808b00aeb0a3ce2dbe0 --- /dev/null +++ b/services/common/include/background_task_helper.h @@ -0,0 +1,54 @@ +/* + * 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 FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_SERVICES_CORE_INCLUDE_BACKGROUND_TASK_HELPER_H +#define FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_SERVICES_CORE_INCLUDE_BACKGROUND_TASK_HELPER_H + +#ifdef STANDBY_SERVICE_UNIT_TEST +#define WEAK_FUNC __attribute__((weak)) +#else +#define WEAK_FUNC +#endif // STANDBY_SERVICE_UNIT_TEST + +#include +#include +#include "ipc_skeleton.h" +#include "iremote_object.h" +#include "single_instance.h" +#include "background_task_mgr_helper.h" + +#include "standby_service_log.h" +#include "standby_service_errors.h" +#include "resource_callback_info.h" + +namespace OHOS { +namespace DevStandbyMgr { +using namespace OHOS::BackgroundTaskMgr; +class BackgroundTaskHelper : public std::enable_shared_from_this { +DECLARE_SINGLE_INSTANCE(BackgroundTaskHelper); +public: + /** + * @brief Get all running continuous task info. + */ + bool GetContinuousTaskApps(std::vector> &list); + + /** + * @brief Get all running transient task info. + */ + bool GetTransientTaskApps(std::vector> &list); +}; +} +} +#endif // FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_SERVICES_CORE_INCLUDE_BACKGROUND_TASK_HELPER_H \ No newline at end of file diff --git a/services/common/src/background_task_helper.cpp b/services/common/src/background_task_helper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..45e38a622dab54a2ae535b6f4847a9d8b6710c96 --- /dev/null +++ b/services/common/src/background_task_helper.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "background_task_helper.h" + +namespace OHOS { +namespace DevStandbyMgr { +IMPLEMENT_SINGLE_INSTANCE(BackgroundTaskHelper); + +BackgroundTaskHelper::BackgroundTaskHelper() +{ +} + +BackgroundTaskHelper::~BackgroundTaskHelper() +{ +} + +bool WEAK_FUNC BackgroundTaskHelper::GetContinuousTaskApps( + std::vector> &list) +{ + if (BackgroundTaskMgrHelper::GetContinuousTaskApps(list) != OHOS::ERR_OK) { + STANDBYSERVICE_LOGW("Get continuous task failed"); + return false; + } + return true; +} + +bool WEAK_FUNC BackgroundTaskHelper::GetTransientTaskApps(std::vector> &list) +{ + if (BackgroundTaskMgrHelper::GetTransientTaskApps(list) != OHOS::ERR_OK) { + STANDBYSERVICE_LOGE("Get transient task failed"); + return false; + } + return true; +} +} // OHOS +} // DevStandbyMgr \ No newline at end of file diff --git a/services/core/include/app_mgr_helper.h b/services/core/include/app_mgr_helper.h index 3fd04a88a7c3899c7de97cd49b1a60f2d38feaf9..37a848a9d69715f4596a56ed4ea57db222f27a9e 100644 --- a/services/core/include/app_mgr_helper.h +++ b/services/core/include/app_mgr_helper.h @@ -45,6 +45,11 @@ public: */ bool GetAppRunningStateByBundleName(const std::string &bundleName, bool& isRunning); + /** + * Get Foreground Applications. + */ + bool GetForegroundApplications(std::vector &fgApps); + /** * @brief Subscribe AppStateObserver. * diff --git a/services/core/include/app_state_observer.h b/services/core/include/app_state_observer.h index e22055508d8cf3f8deaa52090605aced0c4cf4b8..c724cde61fd39ef9bf749cc4512d933ccd1a1f7a 100644 --- a/services/core/include/app_state_observer.h +++ b/services/core/include/app_state_observer.h @@ -38,6 +38,14 @@ public: * @param processData process data. */ void OnProcessDied(const AppExecFwk::ProcessData &processData) override; + + /** + * Will be called when the process start. + * + * @param processData Process data. + */ + void OnProcessCreated(const AppExecFwk::ProcessData &processData) override; + /** * Application foreground state changed callback. * diff --git a/services/core/include/bundle_manager_helper.h b/services/core/include/bundle_manager_helper.h index a82bd51d95b8743be4e1485e5bbd4b4b4bd36ea3..8647afc94a39a1338cc484950469853f8e2a055b 100644 --- a/services/core/include/bundle_manager_helper.h +++ b/services/core/include/bundle_manager_helper.h @@ -35,7 +35,9 @@ public: std::string GetClientBundleName(int32_t uid); bool GetApplicationInfo(const std::string &appName, const AppExecFwk::ApplicationFlag flag, const int userId, AppExecFwk::ApplicationInfo &appInfo); - + bool GetApplicationInfos(const AppExecFwk::ApplicationFlag flag, int userId, + std::vector &appInfos); + bool CheckIsSystemAppByUid(const int uid, bool& isSystemApp); private: bool Connect(); diff --git a/services/core/include/standby_service.h b/services/core/include/standby_service.h index 4d31e24b64b232073c2d0303942cf4ce1ce48807..2e6ba0ab9f7d03ef832d6001777321dbfc00a0e1 100644 --- a/services/core/include/standby_service.h +++ b/services/core/include/standby_service.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include "singleton.h" @@ -52,7 +53,14 @@ public: ErrCode GetAllowList(uint32_t allowType, std::vector& allowInfoList, uint32_t reasonCode) override; ErrCode IsDeviceInStandby(bool& isStandby) override; + ErrCode ReportWorkSchedulerStatus(bool started, int32_t uid, const std::string& bundleName) override; + ErrCode GetRestrictList(uint32_t restrictType, std::vector& restrictInfoList, + uint32_t reasonCode) override; + ErrCode IsStrategyEnabled(const std::string& strategyName, bool& isEnabled) override; + ErrCode ReportDeviceStateChanged(DeviceStateType type, bool enabled) override; int32_t Dump(int32_t fd, const std::vector& args) override; + void AddPluginSysAbilityListener(int32_t systemAbilityId); + ErrCode NotifySystemAbilityStatusChanged(bool isAdded, int32_t systemAbilityId); private: void DumpUsage(std::string& result); @@ -63,6 +71,7 @@ private: std::mutex systemAbilityLock_ {}; ServiceRunningState state_ {ServiceRunningState::STATE_NOT_START}; uint32_t dependsReady_ = 0; + std::mutex listenedSALock_ {}; }; } // namespace DevStandbyMgr } // namespace OHOS diff --git a/services/core/include/standby_service_impl.h b/services/core/include/standby_service_impl.h index 20184b037532397ff161a7fa732a79a6fb1f79e1..b72e3c4ca8623f33d4d5fb04ee4be4c070251c3e 100644 --- a/services/core/include/standby_service_impl.h +++ b/services/core/include/standby_service_impl.h @@ -23,12 +23,14 @@ #include #include #include +#include #include "accesstoken_kit.h" #include "ipc_skeleton.h" #include "event_runner.h" #include "event_handler.h" +#include "istandby_service.h" #include "allow_info.h" #include "allow_record.h" #include "resourcce_request.h" @@ -71,8 +73,14 @@ public: ErrCode UnapplyAllowResource(const sptr& resourceRequest); ErrCode GetAllowList(uint32_t allowType, std::vector& allowInfoList, uint32_t reasonCode); - ErrCode GetEligiableRestrictSet(const std::string& strategyName, std::set& restrictSet); + ErrCode GetEligiableRestrictSet(uint32_t allowType, const std::string& strategyName, + uint32_t resonCode, std::set& restrictSet); ErrCode IsDeviceInStandby(bool& isStandby); + ErrCode ReportWorkSchedulerStatus(bool started, int32_t uid, const std::string& bundleName); + ErrCode GetRestrictList(uint32_t restrictType, std::vector& restrictInfoList, + uint32_t reasonCode); + ErrCode IsStrategyEnabled(const std::string& strategyName, bool& isEnabled); + ErrCode ReportDeviceStateChanged(DeviceStateType type, bool enabled); void RegisterPluginInner(IConstraintManagerAdapter* constraintManager, IListenerManagerAdapter* listenerManager, @@ -88,17 +96,22 @@ public: ErrCode RemoveAppAllowRecord(int32_t uid, const std::string &bundleName, bool resetAll); void ShellDump(const std::vector& argsInStr, std::string& result); + void ShellDumpInner(const std::vector& argsInStr, std::string& result); void GetAllowListInner(uint32_t allowType, std::vector& allowInfoList, uint32_t reasonCode); void DispatchEvent(const StandbyMessage& message); bool IsDebugMode(); + + void OnProcessStatusChanged(int32_t uid, int32_t pid, const std::string& bundleName, bool isCreated); private: void ApplyAllowResInner(const sptr& resourceRequest, int32_t pid); void UpdateRecord(std::shared_ptr& allowRecord, const sptr& resourceRequest); void UnapplyAllowResInner(int32_t uid, const std::string& name, uint32_t allowType, bool removeAll); void GetTemporaryAllowList(uint32_t allowTypeIndex, std::vector& allowInfoList, uint32_t reasonCode); - void GetPersistAllowList(uint32_t allowTypeIndex, std::vector& allowInfoList, bool isApp); + void GetPersistAllowList(uint32_t allowTypeIndex, std::vector& allowInfoList, bool isAllow, bool isApp); + void GetRestrictListInner(uint32_t restrictType, std::vector& restrictInfoList, + uint32_t reasonCode); void NotifyAllowListChanged(int32_t uid, const std::string& name, uint32_t allowType, bool added); void RecoverTimeLimitedTask(); @@ -113,7 +126,6 @@ private: ErrCode CheckRunningResourcesApply(const int32_t uid, const std::string& bundleName); int32_t GetUserIdByUid(int32_t uid); - void ShellDumpInner(const std::vector& argsInStr, std::string& result); void DumpUsage(std::string& result); void DumpShowDetailInfo(const std::vector& argsInStr, std::string& result); void DumpAllowListInfo(std::string& result); @@ -145,6 +157,17 @@ private: std::shared_ptr standbyStateManager_ {nullptr}; bool debugMode_ {false}; }; + +class DeviceStateCache { +DECLARE_SINGLE_INSTANCE(DeviceStateCache); +public: + bool SetDeviceState(int32_t type, bool enabled); + bool GetDeviceState(int32_t type); +private: + std::mutex mutex_ {}; + const static std::int32_t DEVICE_STATE_NUM = 3; + std::array deviceState_; +}; } // namespace DevStandbyMgr } // namespace OHOS #endif // FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_SERVICES_CORE_INCLUDE_STANDBY_SERVICE_IMPL_H \ No newline at end of file diff --git a/services/core/src/app_mgr_helper.cpp b/services/core/src/app_mgr_helper.cpp index 93471ba54e26b0c1ffc3675a5df0ff79742e2a78..592c8664787d5292bfb67125e265feebfee40356 100644 --- a/services/core/src/app_mgr_helper.cpp +++ b/services/core/src/app_mgr_helper.cpp @@ -39,6 +39,18 @@ bool WEAK_FUNC AppMgrHelper::GetAllRunningProcesses(std::vector &fgApps) +{ + std::lock_guard lock(connectMutex_); + if (!Connect()) { + return false; + } + if (appMgrProxy_->GetForegroundApplications(fgApps) != ERR_OK) { + return false; + } + return true; +} + bool WEAK_FUNC AppMgrHelper::GetAppRunningStateByBundleName(const std::string &bundleName, bool& isRunning) { std::lock_guard lock(connectMutex_); diff --git a/services/core/src/app_state_observer.cpp b/services/core/src/app_state_observer.cpp index f371d659e953305d7bc557d88e952c66ecb43934..c7a6130faa57bf496d29776609e74a345202fad1 100644 --- a/services/core/src/app_state_observer.cpp +++ b/services/core/src/app_state_observer.cpp @@ -36,6 +36,9 @@ void AppStateObserver::OnProcessDied(const AppExecFwk::ProcessData &processData) StandbyServiceImpl::GetInstance()->RemoveAppAllowRecord(uid, bundleName, false); }); } + handler_->PostTask([uid = processData.uid, pid = processData.pid, bundleName = processData.bundleName]() { + StandbyServiceImpl::GetInstance()->OnProcessStatusChanged(uid, pid, bundleName, false); + }); } bool AppStateObserver::CheckAlivedApp(const std::string &bundleName) @@ -49,6 +52,13 @@ bool AppStateObserver::CheckAlivedApp(const std::string &bundleName) return isRunning; } +void AppStateObserver::OnProcessCreated(const AppExecFwk::ProcessData &processData) +{ + handler_->PostTask([uid = processData.uid, pid = processData.pid, bundleName = processData.bundleName]() { + StandbyServiceImpl::GetInstance()->OnProcessStatusChanged(uid, pid, bundleName, true); + }); +} + void AppStateObserver::OnApplicationStateChanged(const AppExecFwk::AppStateData &appStateData) { if (!(appStateData.uid > 0 && appStateData.bundleName.size() > 0)) { diff --git a/services/core/src/bundle_manager_helper.cpp b/services/core/src/bundle_manager_helper.cpp index 90ee8596770830e58bffd388e0e07efe14a91724..a492e68bb1b0b0662d636f5b9f624284104f83a2 100644 --- a/services/core/src/bundle_manager_helper.cpp +++ b/services/core/src/bundle_manager_helper.cpp @@ -55,10 +55,35 @@ bool WEAK_FUNC BundleManagerHelper::GetApplicationInfo(const std::string &appNam Connect(); STANDBYSERVICE_LOGD("bundleMgr is null: %{public}d ", bundleMgr_ == nullptr); - if (bundleMgr_ != nullptr && bundleMgr_->GetApplicationInfo(appName, flag, userId, appInfo)) { - return true; + if (bundleMgr_ == nullptr || !bundleMgr_->GetApplicationInfo(appName, flag, userId, appInfo)) { + return false; + } + return true; +} + +bool WEAK_FUNC BundleManagerHelper::GetApplicationInfos(const AppExecFwk::ApplicationFlag flag, int userId, + std::vector &appInfos) +{ + std::lock_guard lock(connectionMutex_); + + Connect(); + STANDBYSERVICE_LOGD("bundleMgr is null: %{public}d ", bundleMgr_ == nullptr); + if (bundleMgr_ == nullptr || !bundleMgr_->GetApplicationInfos(flag, userId, appInfos)) { + return false; } - return false; + return true; +} + +bool WEAK_FUNC BundleManagerHelper::CheckIsSystemAppByUid(const int uid, bool& isSystemApp) +{ + std::lock_guard lock(connectionMutex_); + Connect(); + STANDBYSERVICE_LOGD("bundleMgr is null: %{public}d ", bundleMgr_ == nullptr); + if (bundleMgr_ == nullptr) { + return false; + } + isSystemApp = bundleMgr_->CheckIsSystemAppByUid(uid); + return true; } bool WEAK_FUNC BundleManagerHelper::Connect() diff --git a/services/core/src/standby_service.cpp b/services/core/src/standby_service.cpp index 3b9fd6be328cbf28f5d4f6320245df602e33f5ec..df6b97a062381863c5a3b52609c38a839156bcda 100644 --- a/services/core/src/standby_service.cpp +++ b/services/core/src/standby_service.cpp @@ -118,6 +118,7 @@ void StandbyService::OnAddSystemAbility(int32_t systemAbilityId, const std::stri dependsReady_ |= MULTIMODAL_INPUT_SERVICE_READY; break; default: + NotifySystemAbilityStatusChanged(true, systemAbilityId); break; } STANDBYSERVICE_LOGI("after add system ability, ready state : %{public}u", dependsReady_); @@ -164,6 +165,7 @@ void StandbyService::OnRemoveSystemAbility(int32_t systemAbilityId, const std::s dependsReady_ &= (~MULTIMODAL_INPUT_SERVICE_READY); break; default: + NotifySystemAbilityStatusChanged(false, systemAbilityId); break; } if (dependsReady_ != ALL_DEPENDS_READY) { @@ -227,6 +229,25 @@ ErrCode StandbyService::IsDeviceInStandby(bool& isStandby) return StandbyServiceImpl::GetInstance()->IsDeviceInStandby(isStandby); } +void StandbyService::AddPluginSysAbilityListener(int32_t systemAbilityId) +{ + std::lock_guard pluginListenerLock(listenedSALock_); + STANDBYSERVICE_LOGI("add listener to system ability %{public}d", systemAbilityId); + AddSystemAbilityListener(systemAbilityId); +} + +ErrCode StandbyService::NotifySystemAbilityStatusChanged(bool isAdded, int32_t systemAbilityId) +{ + StandbyMessage standbyMessage{StandbyMessageType::SYS_ABILITY_STATUS_CHANGED}; + standbyMessage.want_ = AAFwk::Want{}; + standbyMessage.want_->SetParam(SA_STATUS, isAdded); + standbyMessage.want_->SetParam(SA_ID, systemAbilityId); + StandbyServiceImpl::GetInstance()->GetHandler()->PostTask([standbyMessage]() { + StandbyServiceImpl::GetInstance()->DispatchEvent(standbyMessage); + }); + return ERR_OK; +} + void StandbyService::OnStop() { StandbyServiceImpl::GetInstance()->UnInit(); @@ -234,6 +255,43 @@ void StandbyService::OnStop() STANDBYSERVICE_LOGI("standby service task manager stop"); } +ErrCode StandbyService::ReportWorkSchedulerStatus(bool started, int32_t uid, const std::string& bundleName) +{ + if (state_ != ServiceRunningState::STATE_RUNNING) { + STANDBYSERVICE_LOGW("standby service is not running"); + return ERR_STANDBY_SYS_NOT_READY; + } + return StandbyServiceImpl::GetInstance()->ReportWorkSchedulerStatus(started, uid, bundleName); +} + +ErrCode StandbyService::GetRestrictList(uint32_t restrictType, std::vector& restrictInfoList, + uint32_t reasonCode) +{ + if (state_ != ServiceRunningState::STATE_RUNNING) { + STANDBYSERVICE_LOGW("standby service is not running"); + return ERR_STANDBY_SYS_NOT_READY; + } + return StandbyServiceImpl::GetInstance()->GetRestrictList(restrictType, restrictInfoList, reasonCode); +} + +ErrCode StandbyService::IsStrategyEnabled(const std::string& strategyName, bool& isEnabled) +{ + if (state_ != ServiceRunningState::STATE_RUNNING) { + STANDBYSERVICE_LOGW("standby service is not running"); + return ERR_STANDBY_SYS_NOT_READY; + } + return StandbyServiceImpl::GetInstance()->IsStrategyEnabled(strategyName, isEnabled); +} + +ErrCode StandbyService::ReportDeviceStateChanged(DeviceStateType type, bool enabled) +{ + if (state_ != ServiceRunningState::STATE_RUNNING) { + STANDBYSERVICE_LOGW("standby service is not running"); + return ERR_STANDBY_SYS_NOT_READY; + } + return StandbyServiceImpl::GetInstance()->ReportDeviceStateChanged(type, enabled); +} + int32_t StandbyService::Dump(int32_t fd, const std::vector& args) { std::vector argsInStr; diff --git a/services/core/src/standby_service_impl.cpp b/services/core/src/standby_service_impl.cpp index 02d71132bc362fb7fee0b6630a6f27f5051afc18..238c59843dcdd972775b1d0b7286ad4c97870cc9 100644 --- a/services/core/src/standby_service_impl.cpp +++ b/services/core/src/standby_service_impl.cpp @@ -44,6 +44,7 @@ #include "ability_manager_helper.h" #include "bundle_manager_helper.h" #include "common_event_observer.h" +#include "standby_service.h" namespace OHOS { namespace DevStandbyMgr { @@ -51,7 +52,6 @@ namespace { const std::string ALLOW_RECORD_FILE_PATH = "/data/service/el1/public/device_standby/allow_record"; const std::string STANDBY_MSG_HANDLER = "StandbyMsgHandler"; const std::string ON_PLUGIN_REGISTER = "OnPluginRegister"; -const std::string STANDBY_PERMISSION = "ohos.permission.DEVICE_STANDBY_EXEMPT_LIST_UPDATED"; const std::string SYSTEM_SO_PATH = "/system/lib/"; const std::string STANDBY_EXEMPTION_PERMISSION = "ohos.permission.DEVICE_STANDBY_EXEMPTION"; } @@ -115,6 +115,8 @@ void StandbyServiceImpl::InitReadyState() ParsePersistentData(); DumpPersistantData(); isServiceReady_.store(true); + StandbyService::GetInstance()->AddPluginSysAbilityListener(BACKGROUND_TASK_MANAGER_SERVICE_ID); + StandbyService::GetInstance()->AddPluginSysAbilityListener(WORK_SCHEDULE_SERVICE_ID); }, AppExecFwk::EventQueue::Priority::HIGH); } @@ -325,6 +327,8 @@ void StandbyServiceImpl::UninitReadyState() STANDBYSERVICE_LOGE("start uninit necessary observer"); listenerManager_->UnInit(); constraintManager_->UnInit(); + strategyManager_->UnInit(); + standbyStateManager_->UnInit(); isServiceReady_.store(false); }, AppExecFwk::EventQueue::Priority::HIGH); } @@ -512,6 +516,10 @@ int32_t StandbyServiceImpl::GetUserIdByUid(int32_t uid) ErrCode StandbyServiceImpl::SubscribeStandbyCallback(const sptr& subscriber) { STANDBYSERVICE_LOGI("add %{public}s subscriber to stanby service", subscriber->GetSubscriberName().c_str()); + if (CheckNativePermission(OHOS::IPCSkeleton::GetCallingTokenID()) != ERR_OK) { + STANDBYSERVICE_LOGW("invoker is unpermitted due to not native process or shell"); + return ERR_STANDBY_PERMISSION_DENIED; + } const auto& strategyConfigList = StandbyConfigManager::GetInstance()->GetStrategyConfigList(); auto item = std::find(strategyConfigList.begin(), strategyConfigList.end(), subscriber->GetSubscriberName()); if (item == strategyConfigList.end()) { @@ -524,6 +532,10 @@ ErrCode StandbyServiceImpl::SubscribeStandbyCallback(const sptr& subscriber) { STANDBYSERVICE_LOGI("add subscriber to stanby service succeed"); + if (CheckNativePermission(OHOS::IPCSkeleton::GetCallingTokenID()) != ERR_OK) { + STANDBYSERVICE_LOGW("invoker is unpermitted due to not native process or shell"); + return ERR_STANDBY_PERMISSION_DENIED; + } return StandbyStateSubscriber::GetInstance()->RemoveSubscriber(subscriber); } @@ -624,7 +636,7 @@ void StandbyServiceImpl::UpdateRecord(std::shared_ptr& allowRecord, allowTimeList.emplace_back(AllowTime{allowTypeIndex, endTime, resourceRequest->GetReason()}); } else { it->reason_ = resourceRequest->GetReason(); - it->endTime_ = std::max(it->endTime_, endTime); + it->endTime_ = std::max(static_cast(it->endTime_ - curTime), 0L); } allowRecord->allowType_ = (allowRecord->allowType_ | allowNumber); auto task = [this, uid, name, allowType] () { @@ -699,6 +711,23 @@ void StandbyServiceImpl::UnapplyAllowResInner(int32_t uid, const std::string& na DumpPersistantData(); } +void StandbyServiceImpl::OnProcessStatusChanged(int32_t uid, int32_t pid, const std::string& bundleName, bool isCreated) +{ + if (!isServiceReady_.load()) { + STANDBYSERVICE_LOGD("standby service is not ready"); + return; + } + STANDBYSERVICE_LOGD("process status change, uid: %{piblic}d, pid: %{piblic}d, name: %{piblic}s, alive: %{piblic}d", + uid, pid, bundleName.c_str(), isCreated); + StandbyMessage standbyMessage {StandbyMessageType::PROCESS_STATE_CHANGED}; + standbyMessage.want_ = AAFwk::Want{}; + standbyMessage.want_->SetParam("uid", uid); + standbyMessage.want_->SetParam("pid", pid); + standbyMessage.want_->SetParam("name", bundleName); + standbyMessage.want_->SetParam("isCreated", isCreated); + DispatchEvent(standbyMessage); +} + void StandbyServiceImpl::NotifyAllowListChanged(int32_t uid, const std::string& name, uint32_t allowType, bool added) { @@ -743,7 +772,7 @@ void StandbyServiceImpl::GetAllowListInner(uint32_t allowType, std::vector& allowInfoList, - bool isApp) + bool isAllow, bool isApp) { uint32_t condition = TimeProvider::GetCondition(); std::set psersistAllowList; if (isApp) { psersistAllowList = StandbyConfigManager::GetInstance()->GetEligiblePersistAllowConfig( - AllowTypeName[allowTypeIndex], condition, true, true); + AllowTypeName[allowTypeIndex], condition, isAllow, true); } else { psersistAllowList = StandbyConfigManager::GetInstance()->GetEligiblePersistAllowConfig( - AllowTypeName[allowTypeIndex], condition, true, false); + AllowTypeName[allowTypeIndex], condition, isAllow, false); } for (const auto& allowName : psersistAllowList) { allowInfoList.emplace_back((1 << allowTypeIndex), allowName, -1); @@ -799,28 +828,136 @@ ErrCode StandbyServiceImpl::IsDeviceInStandby(bool& isStandby) return ERR_OK; } -ErrCode StandbyServiceImpl::GetEligiableRestrictSet(const std::string& strategyName, std::set& restrictSet) +ErrCode StandbyServiceImpl::GetEligiableRestrictSet(uint32_t allowType, const std::string& strategyName, + uint32_t resonCode, std::set& restrictSet) { uint32_t condition = TimeProvider::GetCondition(); - std::set originRestrictSet = - StandbyConfigManager::GetInstance()->GetEligiblePersistAllowConfig(strategyName, condition, false, false); - + std::set originRestrictSet = StandbyConfigManager::GetInstance()->GetEligiblePersistAllowConfig( + strategyName, condition, false, resonCode == ReasonCodeEnum::REASON_APP_API); std::vector allowInfoList; - GetAllowListInner(AllowType::FREEZE, allowInfoList, ReasonCodeEnum::REASON_NATIVE_API); - STANDBYSERVICE_LOGD("allowInfoList size is %{public}d", static_cast(allowInfoList.size())); + GetAllowListInner(allowType, allowInfoList, resonCode); std::set allowSet; for_each(allowInfoList.begin(), allowInfoList.end(), [&allowSet](AllowInfo& allowInfo) { allowSet.insert(allowInfo.GetName()); }); std::set_difference(originRestrictSet.begin(), originRestrictSet.end(), allowSet.begin(), allowSet.end(), std::inserter(restrictSet, restrictSet.begin())); - STANDBYSERVICE_LOGD("restrictSet size is %{public}d", static_cast(restrictSet.size())); + STANDBYSERVICE_LOGD("origin restrict size is %{public}d, restrictSet size is %{public}d, "\ + "restrictSet size is %{public}d", static_cast(originRestrictSet.size()), + static_cast(allowInfoList.size()), static_cast(restrictSet.size())); + return ERR_OK; +} + +ErrCode StandbyServiceImpl::ReportWorkSchedulerStatus(bool started, int32_t uid, const std::string& bundleName) +{ + if (!isServiceReady_.load()) { + return ERR_STANDBY_SYS_NOT_READY; + } + STANDBYSERVICE_LOGI("work scheduler status changed, isstarted: %{public}d, uid: %{public}d, bundleName: %{public}s", + started, uid, bundleName.c_str()); + Security::AccessToken::AccessTokenID tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); + if (CheckNativePermission(tokenId) != ERR_OK) { + STANDBYSERVICE_LOGW("invoker is unpermitted due to not native process or shell"); + return ERR_STANDBY_PERMISSION_DENIED; + } + StandbyMessage standbyMessage {StandbyMessageType::BG_TASK_STATUS_CHANGE}; + standbyMessage.want_ = AAFwk::Want{}; + standbyMessage.want_->SetParam(BG_TASK_TYPE, WORK_SCHEDULER); + standbyMessage.want_->SetParam(BG_TASK_STATUS, started); + standbyMessage.want_->SetParam(BG_TASK_UID, uid); + DispatchEvent(standbyMessage); + return ERR_OK; +} + +ErrCode StandbyServiceImpl::GetRestrictList(uint32_t restrictType, std::vector& restrictInfoList, + uint32_t reasonCode) +{ + if (!isServiceReady_.load()) { + STANDBYSERVICE_LOGD("standby service is not ready"); + return ERR_STANDBY_SYS_NOT_READY; + } + STANDBYSERVICE_LOGD("start GetRestrictList"); + if (CheckNativePermission(OHOS::IPCSkeleton::GetCallingTokenID()) != ERR_OK) { + STANDBYSERVICE_LOGW("invoker is unpermitted due to not native process or shell"); + return ERR_STANDBY_PERMISSION_DENIED; + } + if (!CheckAllowTypeInfo(restrictType)) { + STANDBYSERVICE_LOGE("restrictType param is invalid"); + return ERR_RESOURCE_TYPES_INVALID; + } + handler_->PostSyncTask([this, restrictType, &restrictInfoList, reasonCode]() { + this->GetRestrictListInner(restrictType, restrictInfoList, reasonCode); + }, AppExecFwk::EventQueue::Priority::HIGH); + return ERR_OK; +} + +void StandbyServiceImpl::GetRestrictListInner(uint32_t restrictType, std::vector& restrictInfoList, + uint32_t reasonCode) +{ + STANDBYSERVICE_LOGD("start GetRestrictListInner, restrictType is %{public}d", restrictType); + for (uint32_t restrictTypeIndex = 0; restrictTypeIndex < MAX_ALLOW_TYPE_NUM; ++restrictTypeIndex) { + uint32_t restrictNumber = restrictType & (1 << restrictTypeIndex); + if (restrictNumber == 0) { + continue; + } + bool isApp = (reasonCode == ReasonCodeEnum::REASON_APP_API); + GetPersistAllowList(restrictTypeIndex, restrictInfoList, false, isApp); + } +} + +ErrCode StandbyServiceImpl::IsStrategyEnabled(const std::string& strategyName, bool& isStandby) +{ + if (!isServiceReady_.load()) { + STANDBYSERVICE_LOGD("standby service is not ready"); + return ERR_STANDBY_SYS_NOT_READY; + } + STANDBYSERVICE_LOGD("start IsStrategyEnabled"); + if (CheckNativePermission(OHOS::IPCSkeleton::GetCallingTokenID()) != ERR_OK) { + STANDBYSERVICE_LOGW("invoker is unpermitted due to not native process or shell"); + return ERR_STANDBY_PERMISSION_DENIED; + } + const auto& strategyConfigList = StandbyConfigManager::GetInstance()->GetStrategyConfigList(); + auto item = std::find(strategyConfigList.begin(), strategyConfigList.end(), strategyName); + isStandby = item != strategyConfigList.end(); + return ERR_OK; +} + +ErrCode StandbyServiceImpl::ReportDeviceStateChanged(DeviceStateType type, bool enabled) +{ + if (!isServiceReady_.load()) { + return ERR_STANDBY_SYS_NOT_READY; + } + STANDBYSERVICE_LOGI("device state changed, state type: %{public}d, enabled: %{public}d", + static_cast(type), enabled); + if (CheckNativePermission(OHOS::IPCSkeleton::GetCallingTokenID()) != ERR_OK) { + STANDBYSERVICE_LOGE("dump user is unpermitted due to not native process or shell"); + return ERR_STANDBY_PERMISSION_DENIED; + } + DeviceStateCache::GetInstance()->SetDeviceState(static_cast(type), enabled); + if (!enabled) { + return ERR_OK; + } + StandbyMessage standbyMessage {StandbyMessageType::DEVICE_STATE_CHANGED}; + standbyMessage.want_ = AAFwk::Want{}; + standbyMessage.want_->SetParam("DIS_COMP_STATE", enabled); + handler_->PostTask([standbyImpl = shared_from_this(), standbyMessage]() { + standbyImpl->DispatchEvent(standbyMessage); + }); return ERR_OK; } void StandbyServiceImpl::DispatchEvent(const StandbyMessage& message) { + if (!isServiceReady_.load()) { + STANDBYSERVICE_LOGW("standby service is not ready"); + return; + } STANDBYSERVICE_LOGD("standby service implement dispatch message %{public}d", message.eventId_); + if (!listenerManager_ || !standbyStateManager_ || !strategyManager_) { + STANDBYSERVICE_LOGE("can not dispatch event, state manager or strategy manager is nullptr"); + return; + } + listenerManager_->HandleEvent(message); standbyStateManager_->HandleEvent(message); strategyManager_->HandleEvent(message); } @@ -881,7 +1018,8 @@ void StandbyServiceImpl::DumpUsage(std::string& result) " -h help menu\n" " -D show detail information\n" " --config show all info, including config\n" - " --reset_state reset parameter, validate debug parameter " + " --reset_state reset parameter, validate debug parameter\n" + " --strategy dump strategy info\n" " -E enter the specified state:\n" " {id of state} {whether skip evalution} enter the specified state, 0-4 represent respectively\n" " woking, dark, nap, maintenance, sleep\n" @@ -891,6 +1029,7 @@ void StandbyServiceImpl::DumpUsage(std::string& result) " --get {type} {isApp} get allow list info\n" " -S simulately activate the sensor:\n" " {--motion or --repeat or --blocked or --halfhour} simulately activate the motion sensor\n" + " {--poweroff} power off strategy\n" " -T {switch name} {on or off} turn on or turn off some switches, switch can be debug,\n" " nap_switch, sleep_switch, detect_motion, other\n" " switch only be used after open debug switch\n" @@ -903,13 +1042,14 @@ void StandbyServiceImpl::DumpShowDetailInfo(const std::vector& args std::string& result) { DumpAllowListInfo(result); - strategyManager_->ShellDump(argsInStr, result); standbyStateManager_->ShellDump(argsInStr, result); if (argsInStr.size() < DUMP_DETAILED_INFO_MAX_NUMS) { return; } if (argsInStr[DUMP_SECOND_PARAM] == DUMP_DETAIL_CONFIG) { DumpStandbyConfigInfo(result); + } else if (argsInStr[DUMP_SECOND_PARAM] == DUMP_STRATGY_DETAIL) { + strategyManager_->ShellDump(argsInStr, result); } else if (argsInStr[DUMP_SECOND_PARAM] == DUMP_RESET_STATE) { standbyStateManager_->UnInit(); standbyStateManager_->Init(); @@ -999,6 +1139,12 @@ void StandbyServiceImpl::DumpModifyAllowList(const std::vector& arg "name: " + allowInfo.GetName() + "\n" + "duration: " + std::to_string(allowInfo.GetDuration()) + "\n"; } + allowInfoList.clear(); + GetRestrictListInner(allowType, allowInfoList, isApp); + for (const auto& allowInfo : allowInfoList) { + result += "restrictType: " + std::to_string(allowInfo.GetAllowType()) + "\n" + + "name: " + allowInfo.GetName() + "\n"; + } } } @@ -1055,5 +1201,35 @@ void StandbyServiceImpl::DumpSubScriberObserver(const std::vector& { StandbyStateSubscriber::GetInstance()->ShellDump(argsInStr, result); } + +IMPLEMENT_SINGLE_INSTANCE(DeviceStateCache); + +DeviceStateCache::DeviceStateCache() +{ + deviceState_ = {false, false, false}; +} + +DeviceStateCache::~DeviceStateCache() {} + +bool DeviceStateCache::SetDeviceState(int32_t type, bool enabled) +{ + if (type < 0 || type >= DEVICE_STATE_NUM) { + return false; + } + std::lock_guard lock(mutex_); + if (deviceState_[type] == enabled) { + return false; + } + deviceState_[type] = enabled; + return true; +} + +bool DeviceStateCache::GetDeviceState(int32_t type) +{ + if (type < 0 || type >= DEVICE_STATE_NUM) { + return false; + } + return deviceState_[type]; +} } // namespace DevStandbyMgr } // namespace OHOS diff --git a/services/libstandby_service.versionscript b/services/libstandby_service.versionscript index b0782e07fed1feab96edd6fddb488f90f4aa0e58..e418d986ce12e1c0c91839327b074ce8e5f7e201 100644 --- a/services/libstandby_service.versionscript +++ b/services/libstandby_service.versionscript @@ -19,6 +19,10 @@ *TimeProvider*; *StandbyStateSubscriber*; *AbilityManagerHelper*; + *AppMgrHelper*; + *BackgroundTaskHelper*; + *AbilityManagerHelper*; + *BundleManagerHelper*; local: *; }; \ No newline at end of file diff --git a/services/test/unittest/standby_service_unit_test.cpp b/services/test/unittest/standby_service_unit_test.cpp index 283fc4d24bdff16f07d346007186eb8f83840ce7..1bcbcba10f723fe7bbcc1d14960924de437c020f 100644 --- a/services/test/unittest/standby_service_unit_test.cpp +++ b/services/test/unittest/standby_service_unit_test.cpp @@ -30,11 +30,13 @@ #include "state_manager_adapter.h" #include "constraint_manager_adapter.h" +#include "istandby_ipc_inteface_code.h" #include "listener_manager_adapter.h" #include "strategy_manager_adapter.h" #include "standby_state.h" #include "allow_type.h" +#include "standby_ipc_interface_code.h" #include "standby_service_client.h" #include "standby_service.h" #include "ability_manager_helper.h" @@ -92,8 +94,6 @@ public: void StandbyServiceUnitTest::SetUpTestCase() { StandbyServiceImpl::GetInstance()->Init(); - StandbyServiceImpl::GetInstance()->InitReadyState(); - SleepForFC(); StandbyServiceImpl::GetInstance()->constraintManager_ = std::make_shared(); StandbyServiceImpl::GetInstance()->listenerManager_ = std::make_shared(); @@ -132,11 +132,8 @@ void StandbyServiceUnitTest::TearDownTestCase() */ HWTEST_F(StandbyServiceUnitTest, StandbyServiceUnitTest_001, TestSize.Level1) { - StandbyService::GetInstance()->state_ = ServiceRunningState::STATE_NOT_START; - StandbyService::GetInstance()->OnStart(); StandbyService::GetInstance()->state_ = ServiceRunningState::STATE_RUNNING; StandbyService::GetInstance()->OnStart(); - StandbyServiceImpl::GetInstance()->Init(); EXPECT_NE(StandbyServiceImpl::GetInstance()->handler_, nullptr); StandbyServiceImpl::GetInstance()->InitReadyState(); SleepForFC(); @@ -193,7 +190,7 @@ HWTEST_F(StandbyServiceUnitTest, StandbyServiceUnitTest_003, TestSize.Level1) EXPECT_NE(StandbyService::GetInstance()->UnapplyAllowResource(resourceRequest), ERR_OK); std::vector allowInfoList; - EXPECT_NE(StandbyService::GetInstance()->GetAllowList(AllowType::NET, allowInfoList, 0), ERR_OK); + EXPECT_NE(StandbyService::GetInstance()->GetAllowList(AllowType::NETWORK, allowInfoList, 0), ERR_OK); bool isStandby {false}; EXPECT_NE(StandbyService::GetInstance()->IsDeviceInStandby(isStandby), ERR_OK); StandbyService::GetInstance()->state_ = ServiceRunningState::STATE_RUNNING; @@ -202,7 +199,7 @@ HWTEST_F(StandbyServiceUnitTest, StandbyServiceUnitTest_003, TestSize.Level1) StandbyService::GetInstance()->UnsubscribeStandbyCallback(subscriber); StandbyService::GetInstance()->ApplyAllowResource(resourceRequest); StandbyService::GetInstance()->UnapplyAllowResource(resourceRequest); - EXPECT_EQ(StandbyService::GetInstance()->GetAllowList(AllowType::NET, allowInfoList, 0), ERR_OK); + EXPECT_EQ(StandbyService::GetInstance()->GetAllowList(AllowType::NETWORK, allowInfoList, 0), ERR_OK); EXPECT_EQ(StandbyService::GetInstance()->IsDeviceInStandby(isStandby), ERR_OK); } @@ -220,7 +217,7 @@ HWTEST_F(StandbyServiceUnitTest, StandbyServiceUnitTest_004, TestSize.Level1) StandbyServiceImpl::GetInstance()->ApplyAllowResource(resourceRequest); StandbyServiceImpl::GetInstance()->UnapplyAllowResource(resourceRequest); std::vector allowInfoList; - StandbyServiceImpl::GetInstance()->GetAllowList(AllowType::NET, allowInfoList, 0); + StandbyServiceImpl::GetInstance()->GetAllowList(AllowType::NETWORK, allowInfoList, 0); bool isStandby {false}; EXPECT_NE(StandbyServiceImpl::GetInstance()->IsDeviceInStandby(isStandby), ERR_OK); std::vector argsInStr {}; @@ -264,7 +261,7 @@ HWTEST_F(StandbyServiceUnitTest, StandbyServiceUnitTest_005, TestSize.Level1) StandbyServiceImpl::GetInstance()->ShellDumpInner({"-S", "--default"}, result); StandbyServiceImpl::GetInstance()->ShellDumpInner({"-D"}, result); - auto allowRecord = std::make_shared(0, 0, "name", AllowType::NET); + auto allowRecord = std::make_shared(0, 0, "name", AllowType::NETWORK); allowRecord->allowTimeList_.emplace_back(AllowTime{0, INT64_MAX, "reason"}); StandbyServiceImpl::GetInstance()->allowInfoMap_.emplace(DEFAULT_KEY, allowRecord); StandbyServiceImpl::GetInstance()->ShellDumpInner({"-D"}, result); @@ -305,11 +302,11 @@ HWTEST_F(StandbyServiceUnitTest, StandbyServiceUnitTest_007, TestSize.Level1) HWTEST_F(StandbyServiceUnitTest, StandbyServiceUnitTest_008, TestSize.Level1) { StandbyServiceImpl::GetInstance()->ParsePersistentData(); - auto allowRecord = std::make_shared(0, 0, "name", AllowType::NET); + auto allowRecord = std::make_shared(0, 0, "name", AllowType::NETWORK); allowRecord->allowTimeList_.emplace_back(AllowTime{0, INT64_MAX, "reason"}); - allowRecord = std::make_shared(-1, -1, "test", AllowType::NET); + allowRecord = std::make_shared(-1, -1, "test", AllowType::NETWORK); allowRecord->allowTimeList_.emplace_back(AllowTime{-1, INT64_MAX, "test"}); - allowRecord = std::make_shared(-1, -1, "test", AllowType::NET); + allowRecord = std::make_shared(-1, -1, "test", AllowType::NETWORK); allowRecord->allowTimeList_.emplace_back(AllowTime{-1, INT64_MAX, "test"}); StandbyServiceImpl::GetInstance()->allowInfoMap_.emplace(DEFAULT_KEY, allowRecord); StandbyServiceImpl::GetInstance()->DumpPersistantData(); @@ -464,7 +461,7 @@ HWTEST_F(StandbyServiceUnitTest, StandbyServiceUnitTest_016, TestSize.Level1) */ HWTEST_F(StandbyServiceUnitTest, StandbyServiceUnitTest_017, TestSize.Level1) { - auto allowRecord = std::make_shared(DEFAULT_UID, 0, DEFAULT_BUNDLENAME, AllowType::NET); + auto allowRecord = std::make_shared(DEFAULT_UID, 0, DEFAULT_BUNDLENAME, AllowType::NETWORK); allowRecord->allowTimeList_.emplace_back(AllowTime{0, INT64_MAX, "reason"}); StandbyServiceImpl::GetInstance()->allowInfoMap_.emplace(DEFAULT_KEY, allowRecord); @@ -482,9 +479,9 @@ HWTEST_F(StandbyServiceUnitTest, StandbyServiceUnitTest_017, TestSize.Level1) StandbyServiceImpl::GetInstance()->GetTemporaryAllowList(MAX_ALLOW_TYPE_NUMBER, allowInfoList, ReasonCodeEnum::REASON_NATIVE_API); StandbyServiceImpl::GetInstance()->GetPersistAllowList(MAX_ALLOW_TYPE_NUMBER, allowInfoList, - true); + true, true); StandbyServiceImpl::GetInstance()->GetPersistAllowList(MAX_ALLOW_TYPE_NUMBER, allowInfoList, - false); + true, false); sptr resourceRequest = new (std::nothrow) ResourceRequest(); StandbyServiceImpl::GetInstance()->UnapplyAllowResource(resourceRequest); StandbyServiceImpl::GetInstance()->DayNightSwitchCallback(); @@ -507,7 +504,7 @@ HWTEST_F(StandbyServiceUnitTest, StandbyServiceUnitTest_018, TestSize.Level1) StandbyStateSubscriber::GetInstance()->ShellDump(argsInStr, result); StandbyStateSubscriber::GetInstance()->NotifyIdleModeByCallback(false, false); StandbyStateSubscriber::GetInstance()->ReportAllowListChanged(DEFAULT_UID, DEFAULT_BUNDLENAME, - AllowType::NET, true); + AllowType::NETWORK, true); sptr nullSubscriber = nullptr; EXPECT_NE(StandbyStateSubscriber::GetInstance()->AddSubscriber(nullSubscriber), ERR_OK); EXPECT_NE(StandbyStateSubscriber::GetInstance()->RemoveSubscriber(nullSubscriber), ERR_OK); @@ -517,7 +514,7 @@ HWTEST_F(StandbyServiceUnitTest, StandbyServiceUnitTest_018, TestSize.Level1) EXPECT_NE(StandbyStateSubscriber::GetInstance()->AddSubscriber(subscriber), ERR_OK); StandbyStateSubscriber::GetInstance()->NotifyIdleModeByCallback(false, false); StandbyStateSubscriber::GetInstance()->ReportAllowListChanged(DEFAULT_UID, DEFAULT_BUNDLENAME, - AllowType::NET, true); + AllowType::NETWORK, true); EXPECT_EQ(StandbyStateSubscriber::GetInstance()->RemoveSubscriber(subscriber), ERR_OK); StandbyStateSubscriber::GetInstance()->RemoveSubscriber(subscriber); StandbyStateSubscriber::GetInstance()->AddSubscriber(subscriber); @@ -547,7 +544,7 @@ HWTEST_F(StandbyServiceUnitTest, StandbyServiceUnitTest_018, TestSize.Level1) */ HWTEST_F(StandbyServiceUnitTest, StandbyServiceUnitTest_019, TestSize.Level1) { - auto allowRecord = std::make_shared(DEFAULT_UID, 0, DEFAULT_BUNDLENAME, AllowType::NET); + auto allowRecord = std::make_shared(DEFAULT_UID, 0, DEFAULT_BUNDLENAME, AllowType::NETWORK); auto value = allowRecord->ParseToJson(); allowRecord->ParseFromJson(value); allowRecord->allowTimeList_.emplace_back(AllowTime{0, 0, "reason"}); @@ -724,7 +721,7 @@ HWMTEST_F(StandbyServiceUnitTest, StandbyServiceUnitTest_028, TestSize.Level1, 2 { sptr resourceRequest = new (std::nothrow) ResourceRequest(); StandbyServiceImpl::GetInstance()->ApplyAllowResource(resourceRequest); - sptr validResRequest = new (std::nothrow) ResourceRequest(AllowType::NET, + sptr validResRequest = new (std::nothrow) ResourceRequest(AllowType::NETWORK, 0, "test_process", 100, "test", 1); EXPECT_EQ(StandbyServiceImpl::GetInstance()->ApplyAllowResource(validResRequest), ERR_OK); StandbyServiceUnitTest::SleepForFC(); @@ -740,7 +737,7 @@ HWMTEST_F(StandbyServiceUnitTest, StandbyServiceUnitTest_029, TestSize.Level1, 2 { sptr resourceRequest = new (std::nothrow) ResourceRequest(); StandbyServiceImpl::GetInstance()->UnapplyAllowResource(resourceRequest); - sptr validResRequest = new (std::nothrow) ResourceRequest(AllowType::NET, + sptr validResRequest = new (std::nothrow) ResourceRequest(AllowType::NETWORK, 0, "test_process", 100, "test", 1); EXPECT_EQ(StandbyServiceImpl::GetInstance()->UnapplyAllowResource(validResRequest), ERR_OK); } @@ -754,7 +751,7 @@ HWMTEST_F(StandbyServiceUnitTest, StandbyServiceUnitTest_029, TestSize.Level1, 2 HWMTEST_F(StandbyServiceUnitTest, StandbyServiceUnitTest_030, TestSize.Level1, 20) { std::vector allowInfoList; - StandbyServiceImpl::GetInstance()->GetAllowList(AllowType::NET, allowInfoList, 0); + StandbyServiceImpl::GetInstance()->GetAllowList(AllowType::NETWORK, allowInfoList, 0); EXPECT_EQ(allowInfoList.size(), 0); } @@ -857,9 +854,12 @@ HWMTEST_F(StandbyServiceUnitTest, StandbyServiceUnitTest_036, TestSize.Level1, 2 MessageParcel reply {}; MessageOption option {MessageOption::TF_ASYNC}; data.WriteInterfaceToken(IStandbyServiceSubscriber::GetDescriptor()); - subscriber->OnRemoteRequest(IStandbyServiceSubscriber::ON_DEVICE_IDLE_MODE, data, reply, option); - subscriber->OnRemoteRequest(IStandbyServiceSubscriber::ON_ALLOW_LIST_CHANGED, data, reply, option); - auto ret = subscriber->OnRemoteRequest(IStandbyServiceSubscriber::ON_ALLOW_LIST_CHANGED + 1, data, reply, option); + subscriber->OnRemoteRequest( + (static_cast(StandbySubscriberInterfaceCode::ON_DEVICE_IDLE_MODE)), data, reply, option); + subscriber->OnRemoteRequest( + (static_cast(StandbySubscriberInterfaceCode::ON_ALLOW_LIST_CHANGED)), data, reply, option); + auto ret = subscriber->OnRemoteRequest( + static_cast(StandbySubscriberInterfaceCode::ON_ALLOW_LIST_CHANGED) + 1, data, reply, option); EXPECT_NE(ret, ERR_OK); } @@ -875,15 +875,21 @@ HWMTEST_F(StandbyServiceUnitTest, StandbyServiceUnitTest_037, TestSize.Level1, 2 MessageParcel reply; MessageOption option = {MessageOption::TF_ASYNC}; data.WriteInterfaceToken(IStandbyService::GetDescriptor()); - StandbyService::GetInstance()->OnRemoteRequest(StandbyServiceStub::SUBSCRIBE_STANDBY_CALLBACK, data, reply, option); - StandbyService::GetInstance()->OnRemoteRequest(StandbyServiceStub::UNSUBSCRIBE_STANDBY_CALLBACK, - data, reply, option); - StandbyService::GetInstance()->OnRemoteRequest(StandbyServiceStub::APPLY_ALLOW_RESOURCE, data, reply, option); - StandbyService::GetInstance()->OnRemoteRequest(StandbyServiceStub::UNAPPLY_ALLOW_RESOURCE, data, reply, option); - StandbyService::GetInstance()->OnRemoteRequest(StandbyServiceStub::GET_ALLOW_LIST, data, reply, option); - StandbyService::GetInstance()->OnRemoteRequest(StandbyServiceStub::IS_DEVICE_IN_STANDBY, data, reply, option); - auto ret = StandbyService::GetInstance()->OnRemoteRequest(StandbyServiceStub::IS_DEVICE_IN_STANDBY + 1, + StandbyService::GetInstance()->OnRemoteRequest( + (static_cast(IStandbyInterfaceCode::SUBSCRIBE_STANDBY_CALLBACK)), data, reply, option); + StandbyService::GetInstance()->OnRemoteRequest( + (static_cast(IStandbyInterfaceCode::UNSUBSCRIBE_STANDBY_CALLBACK)), data, reply, option); + StandbyService::GetInstance()->OnRemoteRequest( + (static_cast(IStandbyInterfaceCode::APPLY_ALLOW_RESOURCE)), data, reply, option); + StandbyService::GetInstance()->OnRemoteRequest( + (static_cast(IStandbyInterfaceCode::UNAPPLY_ALLOW_RESOURCE)), data, reply, option); + StandbyService::GetInstance()->OnRemoteRequest( + (static_cast(IStandbyInterfaceCode::GET_ALLOW_LIST)), data, reply, option); + StandbyService::GetInstance()->OnRemoteRequest( + (static_cast(IStandbyInterfaceCode::IS_DEVICE_IN_STANDBY)), data, reply, option); + auto ret = StandbyService::GetInstance()->OnRemoteRequest( + (static_cast(IStandbyInterfaceCode::IS_DEVICE_IN_STANDBY)) + 1, data, reply, option); EXPECT_NE(ret, ERR_OK); } diff --git a/standby_service.gni b/standby_service.gni index aab85c5354c804d57828a0725609b3cbc3269d74..03cadc8264c04327fe6e6155f2c1443cec4f0c4a 100644 --- a/standby_service.gni +++ b/standby_service.gni @@ -42,9 +42,15 @@ standby_service_path = "${standby_service_root_path}/services" declare_args() { enable_standby_configpolicy = true + enable_background_task_mgr = true if (defined(global_parts_info) && !defined(global_parts_info.customization_config_policy)) { enable_standby_configpolicy = false } + + if (defined(global_parts_info) && + !defined(global_parts_info.resourceschedule_background_task_mgr)) { + enable_background_task_mgr = false + } } \ No newline at end of file diff --git a/utils/common/include/common_constant.h b/utils/common/include/common_constant.h index f20674c2601e88d18349284d6718e96d4a835ec6..bc7cb124d20d1bece3f2f96a86cfca5b6eceb533 100644 --- a/utils/common/include/common_constant.h +++ b/utils/common/include/common_constant.h @@ -18,6 +18,8 @@ #include #include +#include +#include namespace OHOS { namespace DevStandbyMgr { @@ -62,6 +64,17 @@ extern const std::string CURRENT_PHASE; extern const std::string SENSOR_DETECTION; extern const std::string RES_CTRL_CONDITION; extern const std::string SCR_OFF_HALF_HOUR_STATUS; +extern const std::string BG_TASK_TYPE; +extern const std::string BG_TASK_STATUS; +extern const std::string BG_TASK_UID; +extern const std::string BG_TASK_PID; +extern const std::string BG_TASK_BUNDLE_NAME; +extern const std::string SA_STATUS; +extern const std::string SA_ID; + +extern const std::string CONTINUOUS_TASK; +extern const std::string TRANSIENT_TASK; +extern const std::string WORK_SCHEDULER; extern const std::string LID_CLOSE; extern const std::string LID_OPEN; @@ -83,6 +96,7 @@ extern const std::string DUMP_NIGHTTIME_SLEEP_MODE; extern const std::string DUMP_DEBUG_SWITCH; extern const std::string DUMP_RESET_STATE; extern const std::string DUMP_DETAIL_CONFIG; +extern const std::string DUMP_STRATGY_DETAIL; extern const std::string DUMP_DETAIL_INFO; extern const std::string DUMP_ENTER_STATE; @@ -103,6 +117,7 @@ extern const int32_t NIGHT_ENTRANCE_HOUR; extern const int32_t NIGHT_ENTRANCE_MIN; extern const int32_t DAY_ENTRANCE_HOUR; extern const int32_t DAY_ENTRANCE_MIN; +extern const std::string AIRPLANE_MODE_PARAMETER; } // namespace DevStandbyMgr } // namespace OHOS diff --git a/utils/common/include/standby_service_errors.h b/utils/common/include/standby_service_errors.h index 076f929582f25334c4b3472ee281c3d48bfe54a5..25faa0778ebd1142a519a75bb4619f8d2a86ed82 100644 --- a/utils/common/include/standby_service_errors.h +++ b/utils/common/include/standby_service_errors.h @@ -55,6 +55,9 @@ enum : int32_t { ERR_STANDBY_OBSERVER_ALREADY_EXIST = 980000701, ERR_STANDBY_OBSERVER_INIT_FAILED, ERR_STANDBY_OBSERVER_RESET_FAILED, + ERR_REGISTER_BACKGROUND_TASK_FAILED, + ERR_UNREGISTER_BACKGROUND_TASK_FAILED, + ERR_BGTASK_LISTENER_NULL, ERR_STANDBY_PLUGIN_NOT_EXIST = 980000801, ERR_STANDBY_PLUGIN_FUNC_NOT_EXIST, @@ -79,6 +82,14 @@ enum : int32_t { ERR_STANDBY_STOP_LISENER_FAILED, ERR_STANDBY_START_SENSOR_FAILED, ERR_STANDBY_SEND_NOTIFICATION_FAILED, + ERR_STANDBY_KEY_INFO_NOT_MATCH, + ERR_STANDBY_REPAET_INIT, + + ERR_STRATEGY_DEPENDS_SA_NOT_AVAILABLE = 980001001, + ERR_STANDBY_LOAD_DUMP_FAILED, + ERR_STANDBY_RESTRICTION_CONDITION_NOT_MATCH, + RR_DATASHARE_OBJECT_NULLPTR, + RR_DATASHARE_QUERY_FAILED, }; enum ParamErr: int32_t { diff --git a/utils/common/src/common_constant.cpp b/utils/common/src/common_constant.cpp index 164eec41598e3a3f27102d21bcd79415c99bd0aa..7684f64371d636baa03837b35f22025e53c5ef31 100644 --- a/utils/common/src/common_constant.cpp +++ b/utils/common/src/common_constant.cpp @@ -63,6 +63,18 @@ const std::string SCR_OFF_HALF_HOUR_STATUS = "scr_off_half_hour_status"; const std::string LID_CLOSE = "LID_CLOSE"; const std::string LID_OPEN = "LID_OPEN"; +const std::string BG_TASK_TYPE = "type"; +const std::string BG_TASK_STATUS = "started"; +const std::string BG_TASK_UID = "uid"; +const std::string BG_TASK_PID = "pid"; +const std::string BG_TASK_BUNDLE_NAME = "name"; + +const std::string SA_STATUS = "isAdded"; +const std::string SA_ID = "systemAbilityId"; + +const std::string CONTINUOUS_TASK = "continuous_task"; +const std::string TRANSIENT_TASK = "transient_task"; +const std::string WORK_SCHEDULER = "work_scheduler"; const uint32_t NO_DUMP_PARAM_NUMS = 0; const uint32_t DUMP_DETAILED_INFO_MAX_NUMS = 2; @@ -81,6 +93,7 @@ const std::string DUMP_NIGHTTIME_SLEEP_MODE = "nighttimesleep"; const std::string DUMP_DEBUG_SWITCH = "debug"; const std::string DUMP_RESET_STATE = "--reset_state"; const std::string DUMP_DETAIL_CONFIG = "--config"; +const std::string DUMP_STRATGY_DETAIL = "--strategy"; const std::string DUMP_DETAIL_INFO = "-D"; const std::string DUMP_ENTER_STATE = "-E"; @@ -102,5 +115,6 @@ const int32_t NIGHT_ENTRANCE_HOUR = 23; const int32_t NIGHT_ENTRANCE_MIN = 45; const int32_t DAY_ENTRANCE_HOUR = 6; const int32_t DAY_ENTRANCE_MIN = 0; +const std::string AIRPLANE_MODE_PARAMETER = "persist.sys.support_air_plane_mode"; } // namespace DevStandbyMgr } // namespace OHOS diff --git a/utils/policy/configs/device_standby_config.json b/utils/policy/configs/device_standby_config.json index 56ed7b9e7c9570a7c575f202724a2b7005d865ce..6cc06d085043b7dde0425ac75da752ed54c61710 100644 --- a/utils/policy/configs/device_standby_config.json +++ b/utils/policy/configs/device_standby_config.json @@ -18,7 +18,7 @@ "nap_interval": [300, 600, 900], "sleep_interval": [3600, 7200, 14400, 21600] }, - "strategy_list": ["NET", "TIMER", "RUNNING_LOCK", "WORK_SCHEDULER"], + "strategy_list": ["NETWORK", "TIMER", "RUNNING_LOCK", "WORK_SCHEDULER"], "halfhour_switch_setting": { } } \ No newline at end of file