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 UpdateCfuIndicator(int32_t slotId, bool cfuResult) override; 58 int32_t UpdateVoiceMailMsgIndicator(int32_t slotId, bool voiceMailMsgResult) override; 59 int32_t UpdateIccAccount() override; 60 int32_t RegisterStateChange(const sptr<TelephonyObserverBroker> &telephonyObserver, int32_t slotId, 61 uint32_t mask, const std::string &bundleName, bool notifyNow, pid_t pid) override; 62 int32_t UnregisterStateChange(int32_t slotId, uint32_t mask, pid_t pid) override; 63 int32_t GetServiceRunningState(); 64 int32_t GetSimState(int32_t slotId); 65 int32_t GetCallState(int32_t slotId); 66 int32_t GetCardType(int32_t slotId); 67 int32_t GetCellularDataConnectionState(int32_t slotId); 68 int32_t GetCellularDataFlow(int32_t slotId); 69 int32_t GetCellularDataConnectionNetworkType(int32_t slotId); 70 int32_t GetLockReason(int32_t slotId); 71 72 private: 73 void Finalize(); 74 void UpdateData(const TelephonyStateRegistryRecord &record); 75 76 private: 77 bool CheckCallerIsSystemApp(uint32_t mask); 78 bool CheckPermission(uint32_t mask); 79 bool VerifySlotId(int32_t slotId); 80 std::u16string GetCallIncomingNumberForSlotId(TelephonyStateRegistryRecord record, int32_t slotId); 81 bool PublishCommonEvent(const AAFwk::Want &want, int32_t eventCode, const std::string &eventData); 82 void SendCallStateChanged(int32_t slotId, int32_t state, const std::u16string &number); 83 void SendSignalInfoChanged(int32_t slotId, const std::vector<sptr<SignalInformation>> &vec); 84 void SendNetworkStateChanged(int32_t slotId, const sptr<NetworkState> &networkState); 85 void SendSimStateChanged(int32_t slotId, CardType type, SimState state, LockReason reason); 86 void SendCellularDataConnectStateChanged(int32_t slotId, int32_t dataState, int32_t networkType); 87 bool IsCommonEventServiceAbilityExist(); 88 89 private: 90 ServiceRunningState state_ = ServiceRunningState::STATE_STOPPED; 91 std::mutex lock_; 92 int32_t slotSize_ = 0; 93 int64_t bindStartTime_ = 0L; 94 int64_t bindEndTime_ = 0L; 95 int64_t bindSpendTime_ = 0L; 96 std::map<int32_t, bool> cfuResult_; 97 std::map<int32_t, bool> voiceMailMsgResult_; 98 std::map<int32_t, int32_t> callState_; 99 std::map<int32_t, std::u16string> callIncomingNumber_; 100 std::map<int32_t, std::vector<sptr<SignalInformation>>> signalInfos_; 101 std::map<int32_t, std::vector<sptr<CellInformation>>> cellInfos_; 102 std::map<int32_t, sptr<NetworkState>> searchNetworkState_; 103 std::vector<TelephonyStateRegistryRecord> stateRecords_; 104 std::map<int32_t, SimState> simState_; 105 std::map<int32_t, CardType> cardType_; 106 std::map<int32_t, LockReason> simReason_; 107 std::map<int32_t, int32_t> cellularDataConnectionState_; 108 std::map<int32_t, int32_t> cellularDataConnectionNetworkType_; 109 std::map<int32_t, int32_t> cellularDataFlow_; 110 }; 111 } // namespace Telephony 112 } // namespace OHOS 113 #endif // TELEPHONY_STATE_REGISTRY_SERVICE_H 114