• 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 <cstdint>
20 #include <cstring>
21 #include <memory>
22 #include <vector>
23 
24 #include "datashare_helper.h"
25 #include "iremote_object.h"
26 #include "singleton.h"
27 
28 #include "miscdevice_observer.h"
29 #include "vibrator_infos.h"
30 #include "vibrator_thread.h"
31 
32 namespace OHOS {
33 namespace Sensors {
34 enum VibrateStatus {
35     VIBRATION = 0,
36     IGNORE_BACKGROUND = 1,
37     IGNORE_LOW_POWER = 2,
38     IGNORE_GLOBAL_SETTINGS = 3,
39     IGNORE_RINGTONE = 4,
40     IGNORE_REPEAT = 5,
41     IGNORE_ALARM = 6,
42     IGNORE_UNKNOWN = 7,
43     IGNORE_RINGER_MODE = 8,
44     IGNORE_FEEDBACK = 9,
45 };
46 
47 enum RingerMode {
48     RINGER_MODE_INVALID = -1,
49     RINGER_MODE_SILENT = 0,
50     RINGER_MODE_VIBRATE = 1,
51     RINGER_MODE_NORMAL = 2
52 };
53 
54 enum FeedbackMode {
55     FEEDBACK_MODE_INVALID = -1,
56     FEEDBACK_MODE_OFF = 0,
57     FEEDBACK_MODE_ON = 1
58 };
59 
60 class VibrationPriorityManager {
61     DECLARE_DELAYED_SINGLETON(VibrationPriorityManager);
62 public:
63     DISALLOW_COPY_AND_MOVE(VibrationPriorityManager);
64     VibrateStatus ShouldIgnoreVibrate(const VibrateInfo &vibrateInfo, std::shared_ptr<VibratorThread> vibratorThread);
65 
66 private:
67     bool IsCurrentVibrate(std::shared_ptr<VibratorThread> vibratorThread) const;
68     bool IsLoopVibrate(const VibrateInfo &vibrateInfo) const;
69     VibrateStatus ShouldIgnoreVibrate(const VibrateInfo &vibrateInfo, VibrateInfo currentVibrateInfo) const;
70     static void ExecRegisterCb(const sptr<MiscDeviceObserver> &observer);
71     int32_t RegisterObserver(const sptr<MiscDeviceObserver> &observer);
72     int32_t UnregisterObserver(const sptr<MiscDeviceObserver> &observer);
73     int32_t GetIntValue(const std::string &key, int32_t &value);
74     int32_t GetLongValue(const std::string &key, int64_t &value);
75     int32_t GetStringValue(const std::string &key, std::string &value);
76     Uri AssembleUri(const std::string &key);
77     std::shared_ptr<DataShare::DataShareHelper> CreateDataShareHelper();
78     bool ReleaseDataShareHelper(std::shared_ptr<DataShare::DataShareHelper> &helper);
79     sptr<MiscDeviceObserver> CreateObserver(const MiscDeviceObserver::UpdateFunc &func);
80     void Initialize();
81     void UpdateStatus();
82     sptr<IRemoteObject> remoteObj_ { nullptr };
83     sptr<MiscDeviceObserver> observer_ { nullptr };
84     std::atomic_int32_t miscFeedback_ = FEEDBACK_MODE_INVALID;
85     std::atomic_int32_t miscAudioRingerMode_ = RINGER_MODE_INVALID;
86 };
87 #define PriorityManager DelayedSingleton<VibrationPriorityManager>::GetInstance()
88 }  // namespace Sensors
89 }  // namespace OHOS
90 #endif  // VIBRATION_PRIORITY_MANAGER_H