• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "app_mgr_client.h"
20 #include "datashare_helper.h"
21 
22 #include "miscdevice_observer.h"
23 #include "vibrator_thread.h"
24 
25 namespace OHOS {
26 namespace Sensors {
27 enum VibrateStatus {
28     VIBRATION = 0,
29     IGNORE_BACKGROUND = 1,
30     IGNORE_LOW_POWER = 2,
31     IGNORE_GLOBAL_SETTINGS = 3,
32     IGNORE_RINGTONE = 4,
33     IGNORE_REPEAT = 5,
34     IGNORE_ALARM = 6,
35     IGNORE_UNKNOWN = 7,
36     IGNORE_RINGER_MODE = 8,
37     IGNORE_FEEDBACK = 9,
38 };
39 
40 enum RingerMode {
41     RINGER_MODE_INVALID = -1,
42     RINGER_MODE_SILENT = 0,
43     RINGER_MODE_VIBRATE = 1,
44     RINGER_MODE_NORMAL = 2
45 };
46 
47 enum FeedbackMode {
48     FEEDBACK_MODE_INVALID = -1,
49     FEEDBACK_MODE_OFF = 0,
50     FEEDBACK_MODE_ON = 1
51 };
52 
53 #ifdef OHOS_BUILD_ENABLE_VIBRATOR_CROWN
54 enum FeedbackIntensity {
55     FEEDBACK_INTENSITY_INVALID = -1,
56     FEEDBACK_INTENSITY_WEAK = 0,
57     FEEDBACK_INTENSITY_STRONGE = 1,
58     FEEDBACK_INTENSITY_NONE = 2,
59 };
60 #endif
61 
62 class VibrationPriorityManager {
63     DECLARE_DELAYED_SINGLETON(VibrationPriorityManager);
64 public:
65     DISALLOW_COPY_AND_MOVE(VibrationPriorityManager);
66     bool Init();
67     VibrateStatus ShouldIgnoreVibrate(const VibrateInfo &vibrateInfo, std::shared_ptr<VibratorThread> vibratorThread);
68 #ifdef OHOS_BUILD_ENABLE_VIBRATOR_CROWN
69     bool ShouldIgnoreByIntensity(const VibrateInfo &vibrateInfo);
70     void MiscCrownIntensityFeedbackInit(void);
71 #endif
72 
73 private:
74     bool IsCurrentVibrate(std::shared_ptr<VibratorThread> vibratorThread) const;
75     bool IsLoopVibrate(const VibrateInfo &vibrateInfo) const;
76     VibrateStatus ShouldIgnoreVibrate(const VibrateInfo &vibrateInfo, VibrateInfo currentVibrateInfo) const;
77 #ifdef OHOS_BUILD_ENABLE_VIBRATOR_INPUT_METHOD
78     bool ShouldIgnoreInputMethod(const VibrateInfo &vibrateInfo);
79 #endif // OHOS_BUILD_ENABLE_VIBRATOR_INPUT_METHOD
80     static void ExecRegisterCb(const sptr<MiscDeviceObserver> &observer);
81     int32_t RegisterObserver(const sptr<MiscDeviceObserver> &observer);
82     int32_t UnregisterObserver(const sptr<MiscDeviceObserver> &observer);
83     int32_t GetIntValue(const std::string &key, int32_t &value);
84     int32_t GetLongValue(const std::string &key, int64_t &value);
85     int32_t GetStringValue(const std::string &key, std::string &value);
86     Uri AssembleUri(const std::string &key);
87     std::shared_ptr<DataShare::DataShareHelper> CreateDataShareHelper();
88     bool ReleaseDataShareHelper(std::shared_ptr<DataShare::DataShareHelper> &helper);
89     sptr<MiscDeviceObserver> CreateObserver(const MiscDeviceObserver::UpdateFunc &func);
90     void UpdateStatus();
91     bool IsSystemServiceCalling();
92     bool IsSystemCalling();
93     sptr<IRemoteObject> remoteObj_ { nullptr };
94     sptr<MiscDeviceObserver> observer_ { nullptr };
95     std::shared_ptr<AppExecFwk::AppMgrClient> appMgrClientPtr_ {nullptr};
96     std::atomic_int32_t miscFeedback_ = FEEDBACK_MODE_INVALID;
97     std::atomic_int32_t miscAudioRingerMode_ = RINGER_MODE_INVALID;
98 #ifdef OHOS_BUILD_ENABLE_VIBRATOR_CROWN
99     std::atomic_int32_t miscCrownFeedback_ = FEEDBACK_MODE_INVALID;
100     std::atomic_int32_t miscIntensity_ = FEEDBACK_INTENSITY_INVALID;
101 #endif
102 };
103 #define PriorityManager DelayedSingleton<VibrationPriorityManager>::GetInstance()
104 }  // namespace Sensors
105 }  // namespace OHOS
106 #endif  // VIBRATION_PRIORITY_MANAGER_H