1 /* 2 * Copyright (c) 2022 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 16 #ifndef VIBRATION_PRIORITY_MANAGER_H 17 #define VIBRATION_PRIORITY_MANAGER_H 18 19 #include <cstdint> 20 #include <cstring> 21 #include <memory> 22 #include <vector> 23 24 #include "singleton.h" 25 26 #include "vibrator_infos.h" 27 #include "vibrator_thread.h" 28 #include "json_parser.h" 29 30 namespace OHOS { 31 namespace Sensors { 32 enum VibrateStatus { 33 VIBRATION = 0, 34 IGNORE_BACKGROUND = 1, 35 IGNORE_LOW_POWER = 2, 36 IGNORE_GLOBAL_SETTINGS = 3, 37 IGNORE_RINGTONE = 4, 38 IGNORE_REPEAT = 5, 39 IGNORE_ALARM = 6, 40 IGNORE_UNKNOWN = 7, 41 }; 42 43 struct PriorityItem { 44 std::vector<std::string> byPassUsages; 45 std::vector<std::string> byPassPkgs; 46 std::vector<std::string> filterUsages; 47 std::vector<std::string> filterPkgs; 48 }; 49 50 struct SpecialForeground { 51 PriorityItem calling; 52 PriorityItem camera; 53 }; 54 55 struct PriorityConfig { 56 std::vector<std::string> privilegePkgs; 57 PriorityItem globalSettings; 58 PriorityItem lowPowerMode; 59 SpecialForeground specialForeground; 60 }; 61 62 class VibrationPriorityManager { 63 DECLARE_DELAYED_SINGLETON(VibrationPriorityManager); 64 public: 65 DISALLOW_COPY_AND_MOVE(VibrationPriorityManager); 66 VibrateStatus ShouldIgnoreVibrate(const VibrateInfo &vibrateInfo, 67 std::shared_ptr<VibratorThread> vibratorThread); 68 int32_t LoadPriorityConfig(const std::string &configPath, PriorityConfig &config); 69 70 private: 71 bool IsPrivilegeApp(const std::string &name) const; 72 bool IsCurrentVibrate(std::shared_ptr<VibratorThread> vibratorThread) const; 73 bool IsLoopVibrate(const VibrateInfo &vibrateInfo) const; 74 VibrateStatus ShouldIgnoreVibrate(const VibrateInfo &vibrateInfo, VibrateInfo currentVibrateInfo) const; 75 void CopyPriorityConfig(PriorityConfig config); 76 int32_t ParserPriorityItem(const JsonParser &parser, cJSON *json, const std::string &key, 77 PriorityItem &item); 78 PriorityConfig priorityConfig_; 79 }; 80 #define PriorityManager DelayedSingleton<VibrationPriorityManager>::GetInstance() 81 } // namespace Sensors 82 } // namespace OHOS 83 #endif // VIBRATION_PRIORITY_MANAGER_H