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