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 OHOS_SIM_STATE_MANAGER_H 17 #define OHOS_SIM_STATE_MANAGER_H 18 19 #include "i_tel_ril_manager.h" 20 #include "sim_state_handle.h" 21 #include "sim_state_type.h" 22 #include "telephony_errors.h" 23 24 namespace OHOS { 25 namespace Telephony { 26 enum SimHandleRun { STATE_NOT_START, STATE_RUNNING }; 27 28 class SimStateManager : public std::enable_shared_from_this<SimStateManager> { 29 public: 30 using HANDLE = const std::shared_ptr<AppExecFwk::EventHandler>; 31 explicit SimStateManager(std::shared_ptr<ITelRilManager> telRilManager); 32 ~SimStateManager(); 33 void Init(int32_t slotId); 34 bool HasSimCard(); 35 SimState GetSimState(); 36 void SetSimState(SimState simState); 37 IccSimStatus GetSimIccStatus(); 38 CardType GetCardType(); 39 std::string GetIccid(); 40 int32_t SetModemInit(bool state); 41 int32_t UnlockPin(int32_t slotId, const std::string &pin, LockStatusResponse &response); 42 int32_t UnlockPuk(int32_t slotId, const std::string &newPin, const std::string &puk, LockStatusResponse &response); 43 int32_t AlterPin( 44 int32_t slotId, const std::string &newPin, const std::string &oldPin, LockStatusResponse &response); 45 int32_t SetLockState(int32_t slotId, const LockInfo &options, LockStatusResponse &response); 46 int32_t GetLockState(int32_t slotId, LockType lockType, LockState &lockState); 47 int32_t RefreshSimState(int32_t slotId); 48 int32_t UnlockPin2(int32_t slotId, const std::string &pin2, LockStatusResponse &response); 49 int32_t UnlockPuk2( 50 int32_t slotId, const std::string &newPin2, const std::string &puk2, LockStatusResponse &response); 51 int32_t AlterPin2( 52 int32_t slotId, const std::string &newPin2, const std::string &oldPin2, LockStatusResponse &response); 53 int32_t UnlockSimLock(int32_t slotId, const PersoLockInfo &lockInfo, LockStatusResponse &response); 54 void RegisterCoreNotify(const HANDLE &handler, int what); 55 void UnRegisterCoreNotify(const HANDLE &observerCallBack, int what); 56 int32_t SimAuthentication( 57 int32_t slotId, AuthType authType, const std::string &authData, SimAuthenticationResponse &response); 58 int32_t SendSimMatchedOperatorInfo( 59 int32_t slotId, int32_t state, const std::string &operName, const std::string &operKey); 60 bool IfModemInitDone(); 61 int32_t GetSimIO(int32_t slotId, SimIoRequestInfo requestInfo, SimAuthenticationResponse &response); 62 void SyncCmdResponse(); 63 void SyncSimMatchResponse(); 64 void SyncUnlockPinResponse(); 65 void SyncSimStateResponse(); 66 67 public: 68 bool responseReady_ = false; 69 bool responseSimMatchReady_ = false; 70 bool responseUnlockPinReady_ = false; 71 bool responseSimStateReady_ = false; 72 std::mutex ctx_; 73 std::mutex stx_; 74 std::mutex unlockPinCtx_; 75 std::mutex simStateCtx_; 76 std::condition_variable cv_; 77 std::condition_variable sv_; 78 std::condition_variable unlockPinCv_; 79 std::condition_variable simStateCv_; 80 81 private: 82 void RequestUnlock(UnlockCmd type); 83 84 private: 85 std::shared_ptr<Telephony::ITelRilManager> telRilManager_ = nullptr; 86 std::shared_ptr<SimStateHandle> simStateHandle_ = nullptr; 87 SimHandleRun simStateRun_ = STATE_NOT_START; 88 static std::mutex mtx_; 89 }; 90 } // namespace Telephony 91 } // namespace OHOS 92 #endif // OHOS_SIM_STATE_MANAGER_H 93