1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_PLUGINS_EXT_INCLUDE_IBASE_STRATEGY_H 16 #define FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_PLUGINS_EXT_INCLUDE_IBASE_STRATEGY_H 17 18 #include "standby_service_errors.h" 19 #include "standby_messsage.h" 20 21 namespace OHOS { 22 namespace DevStandbyMgr { 23 class ExemptionTypeFlag { 24 public: 25 enum : uint8_t { 26 // apps which has applied continuous task 27 CONTINUOUS_TASK = 1, 28 // apps which has applied transient task 29 TRANSIENT_TASK = 1 << 1, 30 // app with work scheduler 31 WORK_SCHEDULER = 1 << 2, 32 // foreground app will not be restricted 33 FOREGROUND_APP = 1 << 3, 34 // default exemption, used for system app or native process 35 UNRESTRICTED = 1 << 4, 36 // applied exemption, used for app configured in exemption list or applied exemption 37 EXEMPTION = 1 << 5, 38 // app is configured to restricted 39 RESTRICTED = 1 << 6, 40 }; 41 42 public: IsExempted(uint8_t flag)43 inline static bool IsExempted(uint8_t flag) 44 { 45 if ((flag & EXEMPTION) != 0) { 46 return true; 47 } else if ((flag & RESTRICTED) != 0) { 48 return false; 49 } 50 return flag != 0; 51 } 52 }; 53 54 struct RestrictedAppInfo { 55 std::string name_ {""}; 56 int32_t uid_ {-1}; 57 int32_t pid_ {-1}; 58 uint8_t appExemptionFlag_ {0}; 59 }; 60 61 struct RestrictedProcInfo { 62 std::string name_ {""}; 63 int32_t uid_ {-1}; 64 std::set<int32_t> pids_ {}; 65 uint8_t appExemptionFlag_ {0}; 66 }; 67 68 class IBaseStrategy { 69 public: 70 virtual void HandleEvent(const StandbyMessage& message) = 0; 71 /** 72 * @brief invoked when strategy is initialized, reset restriction status 73 */ 74 virtual ErrCode OnCreated() = 0; 75 /** 76 * @brief invoked when strategy is destroyed, finalize restriction status 77 */ 78 virtual ErrCode OnDestroy() = 0; 79 virtual void ShellDump(const std::vector<std::string>& argsInStr, std::string& result) = 0; 80 virtual ~IBaseStrategy() = default; 81 }; 82 } // namespace DevStandbyMgr 83 } // namespace OHOS 84 #endif // FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_PLUGINS_EXT_INCLUDE_IBASE_STRATEGY_H 85