• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "sim_state_type.h"
20 #include "sim_state_handle.h"
21 #include "i_tel_ril_manager.h"
22 
23 namespace OHOS {
24 namespace Telephony {
25 enum SimHandleRun {
26     STATE_NOT_START,
27     STATE_RUNNING
28 };
29 
30 class SimStateManager : public std::enable_shared_from_this<SimStateManager> {
31 public:
32     using HANDLE = const std::shared_ptr<AppExecFwk::EventHandler>;
33     SimStateManager(std::shared_ptr<ITelRilManager> telRilManager);
34     ~SimStateManager();
35     void Init(int32_t slotId);
36     bool HasSimCard();
37     SimState GetSimState();
38     CardType GetCardType();
39     bool UnlockPin(int32_t slotId, std::string pin, LockStatusResponse &response);
40     bool UnlockPuk(
41         int32_t slotId, std::string newPin, std::string puk, LockStatusResponse &response);
42     bool AlterPin(
43         int32_t slotId, std::string newPin, std::string oldPin, LockStatusResponse &response);
44     bool SetLockState(int32_t slotId, const LockInfo &options, LockStatusResponse &response);
45     int32_t GetLockState(int32_t slotId, LockType lockType);
46     int32_t RefreshSimState(int32_t slotId);
47     bool UnlockPin2(int32_t slotId, std::string pin2, LockStatusResponse &response);
48     bool UnlockPuk2(
49         int32_t slotId, std::string newPin2, std::string puk2, LockStatusResponse &response);
50     bool AlterPin2(
51         int32_t slotId, std::string newPin2, std::string oldPin2, LockStatusResponse &response);
52     bool UnlockSimLock(
53         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 
57 public:
58     static bool responseReady_;
59     static std::mutex ctx_;
60     static std::condition_variable cv_;
61 
62 private:
63     void RequestUnlock(UnlockCmd type);
64 
65 private:
66     std::shared_ptr<Telephony::ITelRilManager> telRilManager_ = nullptr;
67     std::shared_ptr<SimStateHandle> simStateHandle_ = nullptr;
68     std::shared_ptr<AppExecFwk::EventRunner> eventLoop_ = nullptr;
69     SimHandleRun simStateRun_ = STATE_NOT_START;
70     static std::mutex mtx_;
71 };
72 } // namespace Telephony
73 } // namespace OHOS
74 #endif // OHOS_SIM_STATE_MANAGER_H
75