199552fe9Sopenharmony_ci/*
299552fe9Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
399552fe9Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
499552fe9Sopenharmony_ci * you may not use this file except in compliance with the License.
599552fe9Sopenharmony_ci * You may obtain a copy of the License at
699552fe9Sopenharmony_ci *
799552fe9Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
899552fe9Sopenharmony_ci *
999552fe9Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1099552fe9Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1199552fe9Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1299552fe9Sopenharmony_ci * See the License for the specific language governing permissions and
1399552fe9Sopenharmony_ci * limitations under the License.
1499552fe9Sopenharmony_ci */
1599552fe9Sopenharmony_ci
1699552fe9Sopenharmony_ci#ifndef FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_FRAMEWORKS_INCLUDE_ISTANDBY_SERVICE_H
1799552fe9Sopenharmony_ci#define FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_FRAMEWORKS_INCLUDE_ISTANDBY_SERVICE_H
1899552fe9Sopenharmony_ci
1999552fe9Sopenharmony_ci#include <string>
2099552fe9Sopenharmony_ci#include <vector>
2199552fe9Sopenharmony_ci
2299552fe9Sopenharmony_ci#include <ipc_types.h>
2399552fe9Sopenharmony_ci#include <iremote_broker.h>
2499552fe9Sopenharmony_ci#include <nocopyable.h>
2599552fe9Sopenharmony_ci
2699552fe9Sopenharmony_ci#include "allow_info.h"
2799552fe9Sopenharmony_ci#include "resourcce_request.h"
2899552fe9Sopenharmony_ci#include "standby_service_errors.h"
2999552fe9Sopenharmony_ci#include "istandby_service_subscriber.h"
3099552fe9Sopenharmony_ci#include "standby_res_data.h"
3199552fe9Sopenharmony_ci
3299552fe9Sopenharmony_cinamespace OHOS {
3399552fe9Sopenharmony_cinamespace DevStandbyMgr {
3499552fe9Sopenharmony_cienum class DeviceStateType: int32_t {
3599552fe9Sopenharmony_ci    DIS_COMP_CHANGE = 0,
3699552fe9Sopenharmony_ci    TELEPHONE_STATE_CHANGE,
3799552fe9Sopenharmony_ci    WIFI_P2P_CHANGE,
3899552fe9Sopenharmony_ci};
3999552fe9Sopenharmony_ci
4099552fe9Sopenharmony_ciclass IStandbyService : public IRemoteBroker {
4199552fe9Sopenharmony_cipublic:
4299552fe9Sopenharmony_ci    IStandbyService() = default;
4399552fe9Sopenharmony_ci    ~IStandbyService() override = default;
4499552fe9Sopenharmony_ci    DISALLOW_COPY_AND_MOVE(IStandbyService);
4599552fe9Sopenharmony_ci
4699552fe9Sopenharmony_ci    /**
4799552fe9Sopenharmony_ci     * @brief Subscribes standby state change event.
4899552fe9Sopenharmony_ci     *
4999552fe9Sopenharmony_ci     * @param subscriber Subscriber token.
5099552fe9Sopenharmony_ci     * @return ERR_OK if success, others if fail.
5199552fe9Sopenharmony_ci     */
5299552fe9Sopenharmony_ci    virtual ErrCode SubscribeStandbyCallback(const sptr<IStandbyServiceSubscriber>& subscriber) = 0;
5399552fe9Sopenharmony_ci
5499552fe9Sopenharmony_ci    /**
5599552fe9Sopenharmony_ci     * @brief Unsubscribes standby state change event.
5699552fe9Sopenharmony_ci     *
5799552fe9Sopenharmony_ci     * @param subscriber Subscriber token.
5899552fe9Sopenharmony_ci     * @return ERR_OK if success, others if fail.
5999552fe9Sopenharmony_ci     */
6099552fe9Sopenharmony_ci    virtual ErrCode UnsubscribeStandbyCallback(const sptr<IStandbyServiceSubscriber>& subscriber) = 0;
6199552fe9Sopenharmony_ci
6299552fe9Sopenharmony_ci    /**
6399552fe9Sopenharmony_ci     * @brief add allow list for some services or apps.
6499552fe9Sopenharmony_ci     *
6599552fe9Sopenharmony_ci     * @param resourceRequest resource to be added.
6699552fe9Sopenharmony_ci     * @return ErrCode ERR_OK if success, others if fail.
6799552fe9Sopenharmony_ci     */
6899552fe9Sopenharmony_ci    virtual ErrCode ApplyAllowResource(const sptr<ResourceRequest>& resourceRequest) = 0;
6999552fe9Sopenharmony_ci
7099552fe9Sopenharmony_ci    /**
7199552fe9Sopenharmony_ci     * @brief remove uid with allow type from allow list.
7299552fe9Sopenharmony_ci     *
7399552fe9Sopenharmony_ci     * @param resourceRequest resource to be removed.
7499552fe9Sopenharmony_ci     * @return ErrCode ErrCode ERR_OK if success, others if fail.
7599552fe9Sopenharmony_ci     */
7699552fe9Sopenharmony_ci    virtual ErrCode UnapplyAllowResource(const sptr<ResourceRequest>& resourceRequest) = 0;
7799552fe9Sopenharmony_ci
7899552fe9Sopenharmony_ci    /**
7999552fe9Sopenharmony_ci     * @brief Get the Allow List object.
8099552fe9Sopenharmony_ci     *
8199552fe9Sopenharmony_ci     * @param allowType the allow type to be retrieved.
8299552fe9Sopenharmony_ci     * @param allowInfoList result represents allowed types and apps.
8399552fe9Sopenharmony_ci     * @param reasonCode represents the reason why invoke the api.
8499552fe9Sopenharmony_ci     * @return ErrCode ERR_OK if success, others if fail.
8599552fe9Sopenharmony_ci     */
8699552fe9Sopenharmony_ci    virtual ErrCode GetAllowList(uint32_t allowType, std::vector<AllowInfo>& allowInfoList,
8799552fe9Sopenharmony_ci        uint32_t reasonCode) = 0;
8899552fe9Sopenharmony_ci
8999552fe9Sopenharmony_ci    /**
9099552fe9Sopenharmony_ci     * @brief Get the Restrict List object.
9199552fe9Sopenharmony_ci     *
9299552fe9Sopenharmony_ci     * @param restrictType the restrict type to be retrieved.
9399552fe9Sopenharmony_ci     * @param restrictInfoList result represents restricted types and apps.
9499552fe9Sopenharmony_ci     * @param reasonCode represents the reason why invoke the api.
9599552fe9Sopenharmony_ci     * @return ErrCode ERR_OK if success, others if fail.
9699552fe9Sopenharmony_ci     */
9799552fe9Sopenharmony_ci    virtual ErrCode GetRestrictList(uint32_t restrictType, std::vector<AllowInfo>& restrictInfoList,
9899552fe9Sopenharmony_ci        uint32_t reasonCode) = 0;
9999552fe9Sopenharmony_ci
10099552fe9Sopenharmony_ci    /**
10199552fe9Sopenharmony_ci     * @brief Construct a new Report Work Scheduler Status object.
10299552fe9Sopenharmony_ci     *
10399552fe9Sopenharmony_ci     * @param started true if the work is triggered, else false.
10499552fe9Sopenharmony_ci     * @param uid uid of the applicatoin.
10599552fe9Sopenharmony_ci     * @param bundleName bundleName of the application.
10699552fe9Sopenharmony_ci     * @return ErrCode ERR_OK if success, others if fail.
10799552fe9Sopenharmony_ci     */
10899552fe9Sopenharmony_ci    virtual ErrCode ReportWorkSchedulerStatus(bool started, int32_t uid, const std::string& bundleName) = 0;
10999552fe9Sopenharmony_ci
11099552fe9Sopenharmony_ci    /**
11199552fe9Sopenharmony_ci     * @brief Whether the restriction strategy enbaled or not.
11299552fe9Sopenharmony_ci     *
11399552fe9Sopenharmony_ci     * @param strategyName the strategy name.
11499552fe9Sopenharmony_ci     * @param enabled true if the strategy is enabled.
11599552fe9Sopenharmony_ci     * @return ErrCode ERR_OK if success, others if fail.
11699552fe9Sopenharmony_ci     */
11799552fe9Sopenharmony_ci    virtual ErrCode IsStrategyEnabled(const std::string& strategyName, bool& isEnabled) = 0;
11899552fe9Sopenharmony_ci
11999552fe9Sopenharmony_ci    /**
12099552fe9Sopenharmony_ci     * @brief Report event when device state change, such as discomponent device, bluetooth socket.
12199552fe9Sopenharmony_ci     *
12299552fe9Sopenharmony_ci     * @param type type of device state.
12399552fe9Sopenharmony_ci     * @param enabled true if the device state is on.
12499552fe9Sopenharmony_ci     * @return ErrCode ERR_OK if success, others if fail.
12599552fe9Sopenharmony_ci     */
12699552fe9Sopenharmony_ci    virtual ErrCode ReportDeviceStateChanged(DeviceStateType type, bool enabled) = 0;
12799552fe9Sopenharmony_ci
12899552fe9Sopenharmony_ci    /**
12999552fe9Sopenharmony_ci     * @brief query if the device is in standby mode.
13099552fe9Sopenharmony_ci     *
13199552fe9Sopenharmony_ci     * @param isStandby true if device in standby, else false.
13299552fe9Sopenharmony_ci     * @return ErrCode ERR_OK if success, others if fail.
13399552fe9Sopenharmony_ci     */
13499552fe9Sopenharmony_ci    virtual ErrCode IsDeviceInStandby(bool& isStandby) = 0;
13599552fe9Sopenharmony_ci
13699552fe9Sopenharmony_ci    /**
13799552fe9Sopenharmony_ci     * @brief set nat timeout interval.
13899552fe9Sopenharmony_ci     *
13999552fe9Sopenharmony_ci     * @param type detect type.
14099552fe9Sopenharmony_ci     * @param enable adjust or not.
14199552fe9Sopenharmony_ci     * @param interval nat timeout interval.
14299552fe9Sopenharmony_ci     * @return ErrCode ERR_OK if success, others if fail.
14399552fe9Sopenharmony_ci     */
14499552fe9Sopenharmony_ci    virtual ErrCode SetNatInterval(uint32_t& type, bool& enable, uint32_t& interval) = 0;
14599552fe9Sopenharmony_ci
14699552fe9Sopenharmony_ci    /**
14799552fe9Sopenharmony_ci     * @brief Unified handing of events
14899552fe9Sopenharmony_ci     *
14999552fe9Sopenharmony_ci     * @param resType scene type
15099552fe9Sopenharmony_ci     * @param vaule extra scene message
15199552fe9Sopenharmony_ci     * @param sceneInfo detail scene message, such as pid, uid and so on
15299552fe9Sopenharmony_ci     * @return ErrCode ERR_OK if success, others if fail.
15399552fe9Sopenharmony_ci     */
15499552fe9Sopenharmony_ci    virtual ErrCode HandleEvent(const uint32_t resType, const int64_t value, const std::string &sceneInfo) = 0;
15599552fe9Sopenharmony_ci
15699552fe9Sopenharmony_ci    /**
15799552fe9Sopenharmony_ci     * @brief Report event when a module power energy is overused according to the information from XPower
15899552fe9Sopenharmony_ci     *
15999552fe9Sopenharmony_ci     * @param module module name
16099552fe9Sopenharmony_ci     * @param level rate of power overused
16199552fe9Sopenharmony_ci     * @return ErrCode ERR_OK if success, others if fail.
16299552fe9Sopenharmony_ci     */
16399552fe9Sopenharmony_ci    virtual ErrCode ReportPowerOverused(const std::string &module, uint32_t level) = 0;
16499552fe9Sopenharmony_ci
16599552fe9Sopenharmony_cipublic:
16699552fe9Sopenharmony_ci    DECLARE_INTERFACE_DESCRIPTOR(u"ohos.resourceschedule.IStandbyService");
16799552fe9Sopenharmony_ci
16899552fe9Sopenharmony_ciprotected:
16999552fe9Sopenharmony_ci    enum InterfaceId : uint32_t {
17099552fe9Sopenharmony_ci        SUBSCRIBE_STANDBY_CALLBACK = MIN_TRANSACTION_ID,
17199552fe9Sopenharmony_ci        UNSUBSCRIBE_STANDBY_CALLBACK,
17299552fe9Sopenharmony_ci        APPLY_ALLOW_RESOURCE,
17399552fe9Sopenharmony_ci        UNAPPLY_ALLOW_RESOURCE,
17499552fe9Sopenharmony_ci        GET_ALLOW_LIST,
17599552fe9Sopenharmony_ci        IS_DEVICE_IN_STANDBY,
17699552fe9Sopenharmony_ci        REPORT_WORK_SCHEDULER_STATUS,
17799552fe9Sopenharmony_ci        REPORT_DEVICE_STATE_CHANGED,
17899552fe9Sopenharmony_ci        HANDLE_EVENT
17999552fe9Sopenharmony_ci    };
18099552fe9Sopenharmony_ci};
18199552fe9Sopenharmony_ci}  // namespace DevStandbyMgr
18299552fe9Sopenharmony_ci}  // namespace OHOS
18399552fe9Sopenharmony_ci#endif  // FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_FRAMEWORKS_INCLUDE_ISTANDBY_SERVICE_H
184