rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | #include <cutils/properties.h> |
| 17 | #include <string> |
| 18 | |
| 19 | #include "log_extra.h" |
| 20 | #include "Phone_utils.h" |
| 21 | #include "utils.h" |
| 22 | #include "common.h" |
| 23 | |
| 24 | #define LOG_TAG "DEMO_PHONE_UTILS" |
| 25 | |
| 26 | /* NETWORK_MODE_* See ril.h RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE */ |
| 27 | constexpr int Phone_utils::NETWORK_MODE_WCDMA_PREF; /* GSM/WCDMA (WCDMA preferred) */ |
| 28 | constexpr int Phone_utils::NETWORK_MODE_GSM_ONLY; /* GSM only */ |
| 29 | constexpr int Phone_utils::NETWORK_MODE_WCDMA_ONLY ; /* WCDMA only */ |
| 30 | constexpr int Phone_utils::NETWORK_MODE_GSM_UMTS; /* GSM/WCDMA (auto mode, according to PRL) |
| 31 | AVAILABLE Application Settings menu*/ |
| 32 | constexpr int Phone_utils::NETWORK_MODE_CDMA; /* CDMA and EvDo (auto mode, according to PRL) |
| 33 | AVAILABLE Application Settings menu*/ |
| 34 | constexpr int Phone_utils::NETWORK_MODE_CDMA_NO_EVDO; /* CDMA only */ |
| 35 | constexpr int Phone_utils::NETWORK_MODE_EVDO_NO_CDMA; /* EvDo only */ |
| 36 | constexpr int Phone_utils::NETWORK_MODE_GLOBAL; /* GSM/WCDMA, CDMA, and EvDo (auto mode, according to PRL) |
| 37 | AVAILABLE Application Settings menu*/ |
| 38 | constexpr int Phone_utils::NETWORK_MODE_LTE_CDMA_EVDO; /* LTE, CDMA and EvDo */ |
| 39 | constexpr int Phone_utils::NETWORK_MODE_LTE_GSM_WCDMA; /* LTE, GSM/WCDMA */ |
| 40 | constexpr int Phone_utils::NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA; /* LTE, CDMA, EvDo, GSM/WCDMA */ |
| 41 | constexpr int Phone_utils::NETWORK_MODE_LTE_ONLY; /* LTE Only mode. */ |
| 42 | constexpr int Phone_utils::NETWORK_MODE_LTE_WCDMA; /* LTE/WCDMA */ |
| 43 | constexpr int Phone_utils::NETWORK_MODE_TDSCDMA_ONLY; /* TD-SCDMA only */ |
| 44 | constexpr int Phone_utils::NETWORK_MODE_TDSCDMA_WCDMA; /* TD-SCDMA and WCDMA */ |
| 45 | constexpr int Phone_utils::NETWORK_MODE_LTE_TDSCDMA; /* TD-SCDMA and LTE */ |
| 46 | constexpr int Phone_utils::NETWORK_MODE_TDSCDMA_GSM; /* TD-SCDMA and GSM */ |
| 47 | constexpr int Phone_utils::NETWORK_MODE_LTE_TDSCDMA_GSM; /* TD-SCDMA,GSM and LTE */ |
| 48 | constexpr int Phone_utils::NETWORK_MODE_TDSCDMA_GSM_WCDMA; /* TD-SCDMA, GSM/WCDMA */ |
| 49 | constexpr int Phone_utils::NETWORK_MODE_LTE_TDSCDMA_WCDMA; /* TD-SCDMA, WCDMA and LTE */ |
| 50 | constexpr int Phone_utils::NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA; /* TD-SCDMA, GSM/WCDMA and LTE */ |
| 51 | constexpr int Phone_utils::NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA; /*TD-SCDMA,EvDo,CDMA,GSM/WCDMA*/ |
| 52 | constexpr int Phone_utils::NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA; /* TD-SCDMA/LTE/GSM/WCDMA, CDMA, and EvDo */ |
| 53 | /// M: [Network][C2K]Add the MTK new network type. @{ |
| 54 | constexpr int Phone_utils::NETWORK_MODE_LTE_GSM; /*LTE/GSM */ |
| 55 | constexpr int Phone_utils::NETWORK_MODE_LTE_TDD_ONLY; /* LTE TDD Only mode. */ |
| 56 | constexpr int Phone_utils::NETWORK_MODE_CDMA_GSM; /* CDMA,GSM(2G Global) */ |
| 57 | constexpr int Phone_utils::NETWORK_MODE_CDMA_EVDO_GSM; /* CDMA,EVDO,GSM */ |
| 58 | constexpr int Phone_utils::NETWORK_MODE_LTE_CDMA_EVDO_GSM; /* LTE,CDMA,EVDO,GSM(4G Global, 4M) */ |
| 59 | |
| 60 | const int Phone_utils::PHONE_TYPE_NONE = 0; |
| 61 | const int Phone_utils::PHONE_TYPE_GSM = 1; |
| 62 | const int Phone_utils::PHONE_TYPE_CDMA = 2; |
| 63 | const int Phone_utils::PHONE_TYPE_SIP = 3; |
| 64 | const int Phone_utils::PHONE_TYPE_THIRD_PARTY = 4; |
| 65 | const int Phone_utils::PHONE_TYPE_IMS = 5; |
| 66 | |
| 67 | /// @} |
| 68 | |
| 69 | /** |
| 70 | * Available radio technologies for GSM, UMTS and CDMA. |
| 71 | * Duplicates the constants from hardware/radio/include/ril.h |
| 72 | * This should only be used by agents working with the ril. Others |
| 73 | * should use the equivalent TelephonyManager.NETWORK_TYPE_* |
| 74 | */ |
| 75 | constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_UNKNOWN; |
| 76 | constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_GPRS; |
| 77 | constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_EDGE; |
| 78 | constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_UMTS; |
| 79 | constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_IS95A; |
| 80 | constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_IS95B; |
| 81 | constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_1xRTT; |
| 82 | constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_EVDO_0; |
| 83 | constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_EVDO_A; |
| 84 | constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_HSDPA; |
| 85 | constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_HSUPA; |
| 86 | constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_HSPA; |
| 87 | constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_EVDO_B; |
| 88 | constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_EHRPD; |
| 89 | constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_LTE; |
| 90 | constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_HSPAP; |
| 91 | constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_GSM; |
| 92 | constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_TD_SCDMA; |
| 93 | constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_IWLAN; |
| 94 | constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_LTE_CA; |
| 95 | |
| 96 | int Phone_utils::PREFERRED_NETWORK_MODE = init(); |
| 97 | |
| 98 | const int Phone_utils::APP_FAM_3GPP = 1; |
| 99 | const int Phone_utils::APP_FAM_3GPP2 = 2; |
| 100 | const int Phone_utils::APP_FAM_IMS = 3; |
| 101 | |
| 102 | const std::string Phone_utils::RADIO_DSSS_SIM_DISABLE = "persist.radio.dsss.sim.disable"; |
| 103 | int32_t Phone_utils::disable_sim = -1; |
| 104 | |
| 105 | int Phone_utils::init() { |
| 106 | char mtk_protocol1_rat_config[PROPERTY_VALUE_MAX] = { 0 }; |
| 107 | char opt_ps1_rat[PROPERTY_VALUE_MAX] = { 0 }; |
| 108 | char default_network[PROPERTY_VALUE_MAX] = { 0 }; |
| 109 | utils::mtk_property_get("ro.mtk_protocol1_rat_config",mtk_protocol1_rat_config, ""); |
| 110 | utils::mtk_property_get("ro.boot.opt_ps1_rat",opt_ps1_rat, ""); |
| 111 | utils::mtk_property_get("ro.telephony.default_network",default_network, ""); |
| 112 | std::string mtk_rat(mtk_protocol1_rat_config); |
| 113 | std::string rat(opt_ps1_rat); |
| 114 | std::string default_rat(default_network); |
| 115 | if("C/Lf" == mtk_rat ) { |
| 116 | return NETWORK_MODE_LTE_CDMA_EVDO; |
| 117 | } else { |
| 118 | if(rat.find("C") != std::string::npos) { |
| 119 | if(rat.find("L") != std::string::npos) { |
| 120 | return NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA; |
| 121 | } else { |
| 122 | return NETWORK_MODE_GLOBAL; |
| 123 | } |
| 124 | } else { |
| 125 | if(rat.find("L") != std::string::npos) { |
| 126 | return NETWORK_MODE_LTE_GSM_WCDMA; |
| 127 | } else { |
| 128 | return NETWORK_MODE_WCDMA_PREF; |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | int Phone_utils::get_enable_sim_for_dsss() { |
| 135 | if(disable_sim == -1) { |
| 136 | disable_sim = utils::mtk_property_get_int32(RADIO_DSSS_SIM_DISABLE.c_str(), -1); |
| 137 | LOG_D(LOG_TAG,"get_enable_sim_for_dsss: %d", disable_sim); |
| 138 | } |
| 139 | |
| 140 | if(disable_sim == 2) { |
| 141 | return 0; //slot 0 enable, slot 1 disable |
| 142 | }else if(disable_sim == 1) { |
| 143 | return 1; //slot 1 enable, slot 0 disable |
| 144 | } |
| 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | Phone_utils::Phone_utils() { |
| 149 | // TODO Auto-generated constructor stub |
| 150 | |
| 151 | } |
| 152 | |
| 153 | Phone_utils::~Phone_utils() { |
| 154 | // TODO Auto-generated destructor stub |
| 155 | } |
| 156 | |
| 157 | int Phone_utils::get_phone_count() { |
| 158 | int phoneCount = 1; |
| 159 | if(utils::is_support_dsds()) { |
| 160 | phoneCount = 2; |
| 161 | } |
| 162 | return phoneCount; |
| 163 | } |
| 164 | |
| 165 | int Phone_utils::get_phone_type(int slot) { |
| 166 | int tech = get_voice_radio_tech(slot); |
| 167 | LOG_D(LOG_TAG,"get_phone_type: %d", tech); |
| 168 | if(isCdma(tech)){ |
| 169 | return PHONE_TYPE_CDMA; |
| 170 | } else { |
| 171 | return PHONE_TYPE_GSM; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | bool Phone_utils::isGsm(int radioTechnology){ |
| 176 | return radioTechnology == RIL_RADIO_TECHNOLOGY_GPRS |
| 177 | || radioTechnology == RIL_RADIO_TECHNOLOGY_EDGE |
| 178 | || radioTechnology == RIL_RADIO_TECHNOLOGY_UMTS |
| 179 | || radioTechnology == RIL_RADIO_TECHNOLOGY_HSDPA |
| 180 | || radioTechnology == RIL_RADIO_TECHNOLOGY_HSUPA |
| 181 | || radioTechnology == RIL_RADIO_TECHNOLOGY_HSPA |
| 182 | || radioTechnology == RIL_RADIO_TECHNOLOGY_LTE |
| 183 | || radioTechnology == RIL_RADIO_TECHNOLOGY_HSPAP |
| 184 | || radioTechnology == RIL_RADIO_TECHNOLOGY_GSM |
| 185 | || radioTechnology == RIL_RADIO_TECHNOLOGY_TD_SCDMA |
| 186 | || radioTechnology == RIL_RADIO_TECHNOLOGY_IWLAN |
| 187 | || radioTechnology == RIL_RADIO_TECHNOLOGY_LTE_CA; |
| 188 | } |
| 189 | |
| 190 | bool Phone_utils::isCdma(int radioTechnology){ |
| 191 | return radioTechnology == RIL_RADIO_TECHNOLOGY_IS95A |
| 192 | || radioTechnology == RIL_RADIO_TECHNOLOGY_IS95B |
| 193 | || radioTechnology == RIL_RADIO_TECHNOLOGY_1xRTT |
| 194 | || radioTechnology == RIL_RADIO_TECHNOLOGY_EVDO_0 |
| 195 | || radioTechnology == RIL_RADIO_TECHNOLOGY_EVDO_A |
| 196 | || radioTechnology == RIL_RADIO_TECHNOLOGY_EVDO_B |
| 197 | || radioTechnology == RIL_RADIO_TECHNOLOGY_EHRPD; |
| 198 | } |
| 199 | |
| 200 | bool Phone_utils::isLte(int radioTechnology){ |
| 201 | return radioTechnology == RIL_RADIO_TECHNOLOGY_LTE || |
| 202 | radioTechnology == RIL_RADIO_TECHNOLOGY_LTE_CA; |
| 203 | } |