1 /* 2 * Copyright (c) 2025 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 SWITCH_OBSERVER_H 17 #define SWITCH_OBSERVER_H 18 19 #include <vector> 20 #include <map> 21 #include <memory> 22 #include "singleton.h" 23 #include "data_ability_observer_stub.h" 24 25 namespace OHOS { 26 namespace NetManagerStandard { 27 28 struct TrafficSettingsInfo { 29 int32_t beginDate = 0; 30 int8_t unLimitedDataEnable = 0; 31 int8_t monthlyLimitdNotifyType = -1; 32 uint64_t monthlyLimit = UINT64_MAX; // B 33 uint16_t monthlyMark = UINT16_MAX; 34 uint16_t dailyMark = UINT16_MAX; 35 bool isCanNotifyMonthlyLimit = false; 36 bool isCanNotifyMonthlyMark = false; 37 bool isCanNotifyDailyMark = false; 38 int32_t lastMonAlertTime = 0; 39 int32_t lastMonNotifyTime = 0; 40 int32_t lastDayNotifyTime = 0; 41 }; 42 43 // 无限流量 44 class UnlimitTrafficEnableObserver : public AAFwk::DataAbilityObserverStub { 45 public: 46 UnlimitTrafficEnableObserver(int32_t simId); 47 ~UnlimitTrafficEnableObserver() = default; 48 void OnChange() override; 49 private: 50 int32_t simId_; 51 }; 52 53 // 套餐限额 54 class TrafficMonthlyValueObserver : public AAFwk::DataAbilityObserverStub { 55 public: 56 TrafficMonthlyValueObserver(int32_t simId); 57 ~TrafficMonthlyValueObserver() = default; 58 void OnChange() override; 59 private: 60 int32_t simId_; 61 }; 62 63 // 每月起始日期 64 class TrafficMonthlyBeginDateObserver : public AAFwk::DataAbilityObserverStub { 65 public: 66 TrafficMonthlyBeginDateObserver(int32_t simId); 67 ~TrafficMonthlyBeginDateObserver() = default; 68 void OnChange() override; 69 private: 70 int32_t simId_; 71 }; 72 73 // 月提醒类型——弹窗/断网 74 class TrafficMonthlyNotifyTypeObserver : public AAFwk::DataAbilityObserverStub { 75 public: 76 TrafficMonthlyNotifyTypeObserver(int32_t simId); 77 ~TrafficMonthlyNotifyTypeObserver() = default; 78 void OnChange() override; 79 private: 80 int32_t simId_; 81 }; 82 83 // 月超额 84 class TrafficMonthlyMarkObserver : public AAFwk::DataAbilityObserverStub { 85 public: 86 TrafficMonthlyMarkObserver(int32_t simId); 87 ~TrafficMonthlyMarkObserver() = default; 88 void OnChange() override; 89 private: 90 int32_t simId_; 91 }; 92 93 // 日超额 94 class TrafficDailyMarkObserver : public AAFwk::DataAbilityObserverStub { 95 public: 96 TrafficDailyMarkObserver(int32_t simId); 97 ~TrafficDailyMarkObserver() = default; 98 void OnChange() override; 99 private: 100 int32_t simId_; 101 }; 102 103 class CellularDataObserver : public AAFwk::DataAbilityObserverStub { 104 public: 105 CellularDataObserver() = default; 106 ~CellularDataObserver() = default; 107 void OnChange() override; 108 }; 109 110 class TrafficDataObserver { 111 public: 112 TrafficDataObserver(int32_t simId_); 113 ~TrafficDataObserver() = default; 114 void RegisterTrafficDataSettingObserver(); 115 void UnRegisterTrafficDataSettingObserver(); 116 void ReadTrafficDataSettings(std::shared_ptr<TrafficSettingsInfo> info); 117 void ReadTrafficDataSettingsPart2(std::shared_ptr<TrafficSettingsInfo> info); 118 119 public: 120 int32_t simId_ { -1 }; 121 sptr<UnlimitTrafficEnableObserver> mUnlimitTrafficEnableObserver_ { nullptr} ; 122 sptr<TrafficMonthlyValueObserver> mTrafficMonthlyValueObserver_ { nullptr} ; 123 sptr<TrafficMonthlyBeginDateObserver> mTrafficMonthlyBeginDateObserver_ { nullptr} ; 124 sptr<TrafficMonthlyNotifyTypeObserver> mTrafficMonthlyNotifyTypeObserver_ { nullptr} ; 125 sptr<TrafficMonthlyMarkObserver> mTrafficMonthlyMarkObserver_ { nullptr} ; 126 sptr<TrafficDailyMarkObserver> mTrafficDailyMarkObserver_ { nullptr} ; 127 sptr<CellularDataObserver> mCellularDataObserver_ { nullptr} ; 128 }; 129 } 130 } 131 #endif 132