rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | /* Copyright Statement: |
| 2 | * |
| 3 | * This software/firmware and related documentation ("MediaTek Software") are |
| 4 | * protected under relevant copyright laws. The information contained herein |
| 5 | * is confidential and proprietary to MediaTek Inc. and/or its licensors. |
| 6 | * Without the prior written permission of MediaTek inc. and/or its licensors, |
| 7 | * any reproduction, modification, use or disclosure of MediaTek Software, |
| 8 | * and information contained herein, in whole or in part, shall be strictly prohibited. |
| 9 | * |
| 10 | * MediaTek Inc. (C) 2016. All rights reserved. |
| 11 | * |
| 12 | * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| 13 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| 14 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON |
| 15 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, |
| 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF |
| 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. |
| 18 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE |
| 19 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR |
| 20 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH |
| 21 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES |
| 22 | * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES |
| 23 | * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK |
| 24 | * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR |
| 25 | * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND |
| 26 | * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, |
| 27 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, |
| 28 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO |
| 29 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| 30 | * |
| 31 | * The following software/firmware and/or related documentation ("MediaTek Software") |
| 32 | * have been modified by MediaTek Inc. All revisions are subject to any receiver's |
| 33 | * applicable license agreements with MediaTek Inc. |
| 34 | */ |
| 35 | |
| 36 | #ifndef SRC_UTIL_PROXYCONTROLLER_H_ |
| 37 | #define SRC_UTIL_PROXYCONTROLLER_H_ |
| 38 | |
| 39 | #include <vector> |
| 40 | #include <atomic> |
| 41 | #include <mutex> |
| 42 | #include <string> |
| 43 | |
| 44 | #include <utils/Looper.h> |
| 45 | #include <utils/Thread.h> |
| 46 | #include <utils/RefBase.h> |
| 47 | #include <vendor-ril/telephony/ril.h> |
| 48 | |
| 49 | using ::android::Looper; |
| 50 | using ::android::Thread; |
| 51 | using ::android::MessageHandler; |
| 52 | using ::android::Message; |
| 53 | using ::android::sp; |
| 54 | using ::android::RefBase; |
| 55 | |
| 56 | class Proxy_controller: public RefBase { |
| 57 | public: |
| 58 | static constexpr int EVENT_NOTIFICATION_RC_CHANGED = 1; |
| 59 | static constexpr int EVENT_START_RC_RESPONSE = 2; |
| 60 | static constexpr int EVENT_APPLY_RC_RESPONSE = 3; |
| 61 | static constexpr int EVENT_FINISH_RC_RESPONSE = 4; |
| 62 | static constexpr int EVENT_TIMEOUT = 5; |
| 63 | |
| 64 | static const int SET_RC_STATUS_IDLE; |
| 65 | static const int SET_RC_STATUS_STARTING; |
| 66 | static const int SET_RC_STATUS_STARTED; |
| 67 | static const int SET_RC_STATUS_APPLYING; |
| 68 | static const int SET_RC_STATUS_SUCCESS; |
| 69 | static const int SET_RC_STATUS_FAIL; |
| 70 | |
| 71 | // The entire transaction must complete within this amount of time |
| 72 | // or a FINISH will be issued to each Logical Modem with the old |
| 73 | // Radio Access Family. |
| 74 | static const int SET_RC_TIMEOUT_WAITING_MSEC; |
| 75 | static const std::string PROPERTY_CAPABILITY_SWITCH; |
| 76 | static const std::string PROPERTY_CAPABILITY_SWITCH_STATE; |
| 77 | |
| 78 | // event 1-5 is defined in ProxyController |
| 79 | static const int EVENT_RADIO_AVAILABLE; |
| 80 | static const int EVENT_RIL_CONNECTED; |
| 81 | |
| 82 | // marker for retry cause |
| 83 | static const int RC_RETRY_CAUSE_NONE; |
| 84 | static const int RC_RETRY_CAUSE_WORLD_MODE_SWITCHING; |
| 85 | static const int RC_RETRY_CAUSE_CAPABILITY_SWITCHING; |
| 86 | static const int RC_RETRY_CAUSE_IN_CALL; |
| 87 | static const int RC_RETRY_CAUSE_RADIO_UNAVAILABLE; |
| 88 | static const int RC_RETRY_CAUSE_AIRPLANE_MODE; |
| 89 | static const int RC_RETRY_CAUSE_RESULT_ERROR; |
| 90 | |
| 91 | // marker for switch conditions pre-checking |
| 92 | static const int RC_DO_SWITCH; |
| 93 | static const int RC_NO_NEED_SWITCH; |
| 94 | static const int RC_CANNOT_SWITCH; |
| 95 | //***** Class Variables |
| 96 | private: |
| 97 | bool mIsCapSwitching; |
| 98 | bool mHasRegisterWorldModeReceiver; |
| 99 | bool mHasRegisterPhoneStateReceiver; |
| 100 | bool mHasRegisterEccStateReceiver; |
| 101 | bool mIsRildReconnected; |
| 102 | std::vector<RIL_RadioAccessFamily> mNextRafs; |
| 103 | int mSetRafRetryCause; |
| 104 | // Exception counter |
| 105 | int onExceptionCount; |
| 106 | public: |
| 107 | static Proxy_controller* sInstance; |
| 108 | static Proxy_controller *getInstance(); |
| 109 | |
| 110 | Proxy_controller(); |
| 111 | virtual ~Proxy_controller(); |
| 112 | int checkRadioCapabilitySwitchConditions(std::vector<RIL_RadioAccessFamily> rafs); |
| 113 | bool isNeedSimSwitch(int majorPhoneId, int phoneNum); |
| 114 | bool isEccInProgress(); |
| 115 | class Handle_thread: public Thread { |
| 116 | public: |
| 117 | Handle_thread(); |
| 118 | virtual ~Handle_thread(); |
| 119 | sp<Looper> getLooper(); |
| 120 | |
| 121 | protected: |
| 122 | virtual bool threadLoop(); |
| 123 | private: |
| 124 | sp<Looper> m_looper; |
| 125 | }; |
| 126 | |
| 127 | class Request_message: public RefBase { |
| 128 | public: |
| 129 | Request_message(); |
| 130 | virtual ~Request_message() {}; |
| 131 | |
| 132 | public: |
| 133 | int what; |
| 134 | int slot; |
| 135 | int id; |
| 136 | RIL_Errno e; |
| 137 | RIL_RadioCapability cap; |
| 138 | bool is_rc_set; |
| 139 | }; |
| 140 | |
| 141 | class Request_handler: public MessageHandler { |
| 142 | public: |
| 143 | Request_handler(Proxy_controller* proxy): proxy_controller(proxy){} |
| 144 | virtual ~Request_handler() {} |
| 145 | |
| 146 | public: |
| 147 | void sendMessage(sp<Request_message> msg, int delayms); |
| 148 | void handleMessage(const Message& message); |
| 149 | sp<Request_message> msg; |
| 150 | // dummy message that makes handler happy |
| 151 | Message m_dummyMsg; |
| 152 | private: |
| 153 | Proxy_controller* proxy_controller; |
| 154 | }; |
| 155 | public: |
| 156 | // send message to request handler |
| 157 | sp<Request_handler> sendMessage(sp<Request_message> msg, int delayms); |
| 158 | void handle_request_resp(RIL_RadioCapability* cap, RIL_Errno e, int slot); |
| 159 | void handle_message_notify(RIL_RadioCapability* cap,int slot); |
| 160 | bool doSetRadioCapabilities(std::vector<RIL_RadioAccessFamily> rafs); |
| 161 | bool set_Radio_Capability(std::vector<RIL_RadioAccessFamily> rafs); |
| 162 | private: |
| 163 | sp<Request_handler> timeout_handle; |
| 164 | sp<Handle_thread> handle_thread; |
| 165 | void init(); |
| 166 | void clearTransaction(); |
| 167 | void resetRadioAccessFamilyStatusCounter(); |
| 168 | std::string getLogicalModemIdFromRaf(int raf); |
| 169 | void sendRadioCapabilityRequest(int phoneId, int sessionId, int rcPhase, |
| 170 | int radioFamily, std::string logicalModemId, int status, int eventId); |
| 171 | void onStartRadioCapabilityResponse(sp<Request_message> msg); |
| 172 | void onApplyRadioCapabilityResponse(sp<Request_message> msg); |
| 173 | void onApplyRadioCapabilityErrorHandler(sp<Request_message> msg); |
| 174 | void onFinishRadioCapabilityResponse(sp<Request_message> msg); |
| 175 | void onTimeoutRadioCapability(sp<Request_message> msg); |
| 176 | void onApplyExceptionHandler(sp<Request_message> msg); |
| 177 | void onNotificationRadioCapabilityChanged(sp<Request_message> msg); |
| 178 | void completeRadioCapabilityTransaction(); |
| 179 | void issueFinish(int sessionId); |
| 180 | private: |
| 181 | std::atomic_int mRadioCapabilitySessionId; |
| 182 | std::mutex m_mutex; |
| 183 | // record each phone's set radio capability status |
| 184 | std::vector<int> mSetRadioAccessFamilyStatus; |
| 185 | int mRadioAccessFamilyStatusCounter; |
| 186 | bool mTransactionFailed; |
| 187 | |
| 188 | std::vector<std::string> mCurrentLogicalModemIds; |
| 189 | std::vector<std::string> mNewLogicalModemIds; |
| 190 | |
| 191 | // Record new and old Radio Access Family (raf) configuration. |
| 192 | // The old raf configuration is used to restore each logical modem raf when FINISH is |
| 193 | // issued if any requests fail. |
| 194 | std::vector<int> mNewRadioAccessFamily; |
| 195 | std::vector<int> mOldRadioAccessFamily; |
| 196 | std::vector<int> m_eventId; |
| 197 | }; |
| 198 | |
| 199 | |
| 200 | #endif /* SRC_UTIL_PROXYCONTROLLER_H_ */ |