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 CardType GetCardType(); 37 std::string GetIccid(); 38 int32_t SetModemInit(bool state); 39 int32_t UnlockPin(int32_t slotId, const std::string &pin, LockStatusResponse &response); 40 int32_t UnlockPuk(int32_t slotId, const std::string &newPin, const std::string &puk, LockStatusResponse &response); 41 int32_t AlterPin( 42 int32_t slotId, const std::string &newPin, const std::string &oldPin, LockStatusResponse &response); 43 int32_t SetLockState(int32_t slotId, const LockInfo &options, LockStatusResponse &response); 44 int32_t GetLockState(int32_t slotId, LockType lockType, LockState &lockState); 45 int32_t RefreshSimState(int32_t slotId); 46 int32_t UnlockPin2(int32_t slotId, const std::string &pin2, LockStatusResponse &response); 47 int32_t UnlockPuk2( 48 int32_t slotId, const std::string &newPin2, const std::string &puk2, LockStatusResponse &response); 49 int32_t AlterPin2( 50 int32_t slotId, const std::string &newPin2, const std::string &oldPin2, LockStatusResponse &response); 51 int32_t UnlockSimLock(int32_t slotId, const PersoLockInfo &lockInfo, LockStatusResponse &response); 52 void RegisterCoreNotify(const HANDLE &handler, int what); 53 void UnRegisterCoreNotify(const HANDLE &observerCallBack, int what); 54 int32_t SimAuthentication( 55 int32_t slotId, AuthType authType, const std::string &authData, SimAuthenticationResponse &response); 56 int32_t SendSimMatchedOperatorInfo( 57 int32_t slotId, int32_t state, const std::string &operName, const std::string &operKey); 58 bool IfModemInitDone(); 59 int32_t GetSimIO(int32_t slotId, SimIoRequestInfo requestInfo, SimAuthenticationResponse &response); 60 void SyncCmdResponse(); 61 62 public: 63 bool responseReady_ = false; 64 std::mutex ctx_; 65 std::condition_variable cv_; 66 67 private: 68 void RequestUnlock(UnlockCmd type); 69 70 private: 71 std::shared_ptr<Telephony::ITelRilManager> telRilManager_ = nullptr; 72 std::shared_ptr<SimStateHandle> simStateHandle_ = nullptr; 73 SimHandleRun simStateRun_ = STATE_NOT_START; 74 static std::mutex mtx_; 75 }; 76 } // namespace Telephony 77 } // namespace OHOS 78 #endif // OHOS_SIM_STATE_MANAGER_H 79