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