1 /* 2 * Copyright (C) 2021 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 TELEPHONY_STATE_REGISTRY_SERVICE_H 17 #define TELEPHONY_STATE_REGISTRY_SERVICE_H 18 19 #include <map> 20 #include <mutex> 21 #include <string> 22 23 #include "singleton.h" 24 #include "system_ability.h" 25 #include "common_event_manager.h" 26 #include "want.h" 27 28 #include "telephony_state_registry_record.h" 29 #include "telephony_state_registry_stub.h" 30 #include "sim_state_type.h" 31 32 namespace OHOS { 33 namespace Telephony { 34 enum class ServiceRunningState { STATE_STOPPED, STATE_RUNNING }; 35 class TelephonyStateRegistryService : public SystemAbility, 36 public TelephonyStateRegistryStub, 37 public std::enable_shared_from_this<TelephonyStateRegistryService> { 38 DECLARE_DELAYED_SINGLETON(TelephonyStateRegistryService) 39 DECLARE_SYSTEM_ABILITY(TelephonyStateRegistryService) 40 public: 41 void OnStart() override; 42 void OnStop() override; 43 void OnDump() override; 44 int Dump(std::int32_t fd, const std::vector<std::u16string> &args) override; 45 std::string GetBindStartTime(); 46 std::string GetBindEndTime(); 47 std::string GetBindSpendTime(); 48 int32_t UpdateCellularDataConnectState(int32_t slotId, int32_t dataState, int32_t networkType) override; 49 int32_t UpdateCellularDataFlow(int32_t slotId, int32_t dataFlowType) override; 50 int32_t UpdateCallState(int32_t slotId, int32_t callState, const std::u16string &phoneNumber) override; 51 int32_t UpdateCallStateForSlotId( 52 int32_t slotId, int32_t callId, int32_t callState, const std::u16string &incomingNumber) override; 53 int32_t UpdateSignalInfo(int32_t slotId, const std::vector<sptr<SignalInformation>> &vec) override; 54 int32_t UpdateNetworkState(int32_t slotId, const sptr<NetworkState> &networkState) override; 55 int32_t UpdateSimState(int32_t slotId, CardType type, SimState state, LockReason reason) override; 56 int32_t UpdateCellInfo(int32_t slotId, const std::vector<sptr<CellInformation>> &vec) override; 57 int32_t RegisterStateChange(const sptr<TelephonyObserverBroker> &telephonyObserver, int32_t slotId, 58 uint32_t mask, const std::string &bundleName, bool notifyNow, pid_t pid) override; 59 int32_t UnregisterStateChange(int32_t slotId, uint32_t mask, pid_t pid) override; 60 int32_t GetServiceRunningState(); 61 int32_t GetSimState(int32_t slotId); 62 int32_t GetCallState(int32_t slotId); 63 int32_t GetCardType(int32_t slotId); 64 int32_t GetCellularDataConnectionState(int32_t slotId); 65 int32_t GetCellularDataFlow(int32_t slotId); 66 int32_t GetCellularDataConnectionNetworkType(int32_t slotId); 67 int32_t GetLockReason(int32_t slotId); 68 69 private: 70 void Finalize(); 71 void UpdateData(const TelephonyStateRegistryRecord &record); 72 73 private: 74 bool CheckPermission(uint32_t mask); 75 bool VerifySlotId(int32_t slotId); 76 std::u16string GetCallIncomingNumberForSlotId(TelephonyStateRegistryRecord record, int32_t slotId); 77 bool PublishCommonEvent(const AAFwk::Want &want, int32_t eventCode, const std::string &eventData); 78 void SendCallStateChanged(int32_t slotId, int32_t state, const std::u16string &number); 79 void SendSignalInfoChanged(int32_t slotId, const std::vector<sptr<SignalInformation>> &vec); 80 void SendNetworkStateChanged(int32_t slotId, const sptr<NetworkState> &networkState); 81 void SendSimStateChanged(int32_t slotId, CardType type, SimState state, LockReason reason); 82 void SendCellularDataConnectStateChanged(int32_t slotId, int32_t dataState, int32_t networkType); 83 bool IsCommonEventServiceAbilityExist(); 84 85 private: 86 ServiceRunningState state_ = ServiceRunningState::STATE_STOPPED; 87 std::mutex lock_; 88 int32_t slotSize_ = 0; 89 int64_t bindStartTime_ = 0L; 90 int64_t bindEndTime_ = 0L; 91 int64_t bindSpendTime_ = 0L; 92 std::map<int32_t, int32_t> callState_; 93 std::map<int32_t, std::u16string> callIncomingNumber_; 94 std::map<int32_t, std::vector<sptr<SignalInformation>>> signalInfos_; 95 std::map<int32_t, std::vector<sptr<CellInformation>>> cellInfos_; 96 std::map<int32_t, sptr<NetworkState>> searchNetworkState_; 97 std::vector<TelephonyStateRegistryRecord> stateRecords_; 98 std::map<int32_t, SimState> simState_; 99 std::map<int32_t, CardType> cardType_; 100 std::map<int32_t, LockReason> simReason_; 101 std::map<int32_t, int32_t> cellularDataConnectionState_; 102 std::map<int32_t, int32_t> cellularDataConnectionNetworkType_; 103 std::map<int32_t, int32_t> cellularDataFlow_; 104 }; 105 } // namespace Telephony 106 } // namespace OHOS 107 #endif // TELEPHONY_STATE_REGISTRY_SERVICE_H 108