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 61 private: 62 void Finalize(); 63 void UpdateData(const TelephonyStateRegistryRecord &record); 64 65 private: 66 bool CheckPermission(uint32_t mask); 67 bool VerifySlotId(int32_t slotId); 68 std::u16string GetCallIncomingNumberForSlotId(TelephonyStateRegistryRecord record, int32_t slotId); 69 bool PublishCommonEvent(const AAFwk::Want &want, int32_t eventCode, const std::string &eventData); 70 void SendCallStateChanged(int32_t slotId, int32_t state, const std::u16string &number); 71 void SendSignalInfoChanged(int32_t slotId, const std::vector<sptr<SignalInformation>> &vec); 72 void SendNetworkStateChanged(int32_t slotId, const sptr<NetworkState> &networkState); 73 void SendSimStateChanged(int32_t slotId, CardType type, SimState state, LockReason reason); 74 void SendCellInfoChanged(int32_t slotId, const std::vector<sptr<CellInformation>> &vec); 75 void SendCellularDataConnectStateChanged(int32_t slotId, int32_t dataState, int32_t networkType); 76 void SendCellularDataFlowChanged(int32_t slotId, int32_t dataFlowType); 77 78 private: 79 ServiceRunningState state_ = ServiceRunningState::STATE_STOPPED; 80 std::mutex lock_; 81 int32_t slotSize_ = 0; 82 int64_t bindStartTime_ = 0L; 83 int64_t bindEndTime_ = 0L; 84 int64_t bindSpendTime_ = 0L; 85 std::map<int32_t, int32_t> callState_; 86 std::map<int32_t, std::u16string> callIncomingNumber_; 87 std::map<int32_t, std::vector<sptr<SignalInformation>>> signalInfos_; 88 std::map<int32_t, std::vector<sptr<CellInformation>>> cellInfos_; 89 std::map<int32_t, sptr<NetworkState>> searchNetworkState_; 90 std::vector<TelephonyStateRegistryRecord> stateRecords_; 91 std::map<int32_t, SimState> simState_; 92 std::map<int32_t, CardType> cardType_; 93 std::map<int32_t, LockReason> simReason_; 94 std::map<int32_t, int32_t> cellularDataConnectionState_; 95 std::map<int32_t, int32_t> cellularDataConnectionNetworkType_; 96 std::map<int32_t, int32_t> cellularDataFlow_; 97 98 private: 99 const std::string CELL_INFO_CHANGE_ACTION = "com.hos.action.CELL_INFO_CHANGE"; 100 const std::string CALL_STATE_CHANGE_ACTION = "com.hos.action.CALL_STATE_CHANGE"; 101 const std::string SEARCH_NET_WORK_STATE_CHANGE_ACTION = "com.hos.action.SEARCH_NET_WORK_STATE_CHANGE"; 102 const std::string SEARCH_SIGNAL_INFO_CHANGE_ACTION = "com.hos.action.SEARCH_SIGNAL_INFO_CHANGE"; 103 const std::string CELLULAR_DATA_STATE_CHANGE_ACTION = "com.hos.action.CELLULAR_DATA_STATE_CHANGE"; 104 const std::string CELLULAR_DATA_FLOW_ACTION = "com.hos.action.CELLULAR_DATA_FLOW_CHANGE"; 105 const std::string SIM_STATE_CHANGE_ACTION = "com.hos.action.SIM_STATE_CHANGE"; 106 }; 107 } // namespace Telephony 108 } // namespace OHOS 109 #endif // TELEPHONY_STATE_REGISTRY_SERVICE_H 110