blob: 06b4917c379c35c8b5a56955c0f607d0b2474595 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001 /*
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 */
27constexpr int Phone_utils::NETWORK_MODE_WCDMA_PREF; /* GSM/WCDMA (WCDMA preferred) */
28constexpr int Phone_utils::NETWORK_MODE_GSM_ONLY; /* GSM only */
29constexpr int Phone_utils::NETWORK_MODE_WCDMA_ONLY ; /* WCDMA only */
30constexpr int Phone_utils::NETWORK_MODE_GSM_UMTS; /* GSM/WCDMA (auto mode, according to PRL)
31 AVAILABLE Application Settings menu*/
32constexpr int Phone_utils::NETWORK_MODE_CDMA; /* CDMA and EvDo (auto mode, according to PRL)
33 AVAILABLE Application Settings menu*/
34constexpr int Phone_utils::NETWORK_MODE_CDMA_NO_EVDO; /* CDMA only */
35constexpr int Phone_utils::NETWORK_MODE_EVDO_NO_CDMA; /* EvDo only */
36constexpr int Phone_utils::NETWORK_MODE_GLOBAL; /* GSM/WCDMA, CDMA, and EvDo (auto mode, according to PRL)
37 AVAILABLE Application Settings menu*/
38constexpr int Phone_utils::NETWORK_MODE_LTE_CDMA_EVDO; /* LTE, CDMA and EvDo */
39constexpr int Phone_utils::NETWORK_MODE_LTE_GSM_WCDMA; /* LTE, GSM/WCDMA */
40constexpr int Phone_utils::NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA; /* LTE, CDMA, EvDo, GSM/WCDMA */
41constexpr int Phone_utils::NETWORK_MODE_LTE_ONLY; /* LTE Only mode. */
42constexpr int Phone_utils::NETWORK_MODE_LTE_WCDMA; /* LTE/WCDMA */
43constexpr int Phone_utils::NETWORK_MODE_TDSCDMA_ONLY; /* TD-SCDMA only */
44constexpr int Phone_utils::NETWORK_MODE_TDSCDMA_WCDMA; /* TD-SCDMA and WCDMA */
45constexpr int Phone_utils::NETWORK_MODE_LTE_TDSCDMA; /* TD-SCDMA and LTE */
46constexpr int Phone_utils::NETWORK_MODE_TDSCDMA_GSM; /* TD-SCDMA and GSM */
47constexpr int Phone_utils::NETWORK_MODE_LTE_TDSCDMA_GSM; /* TD-SCDMA,GSM and LTE */
48constexpr int Phone_utils::NETWORK_MODE_TDSCDMA_GSM_WCDMA; /* TD-SCDMA, GSM/WCDMA */
49constexpr int Phone_utils::NETWORK_MODE_LTE_TDSCDMA_WCDMA; /* TD-SCDMA, WCDMA and LTE */
50constexpr int Phone_utils::NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA; /* TD-SCDMA, GSM/WCDMA and LTE */
51constexpr int Phone_utils::NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA; /*TD-SCDMA,EvDo,CDMA,GSM/WCDMA*/
52constexpr 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. @{
54constexpr int Phone_utils::NETWORK_MODE_LTE_GSM; /*LTE/GSM */
55constexpr int Phone_utils::NETWORK_MODE_LTE_TDD_ONLY; /* LTE TDD Only mode. */
56constexpr int Phone_utils::NETWORK_MODE_CDMA_GSM; /* CDMA,GSM(2G Global) */
57constexpr int Phone_utils::NETWORK_MODE_CDMA_EVDO_GSM; /* CDMA,EVDO,GSM */
58constexpr int Phone_utils::NETWORK_MODE_LTE_CDMA_EVDO_GSM; /* LTE,CDMA,EVDO,GSM(4G Global, 4M) */
59
60const int Phone_utils::PHONE_TYPE_NONE = 0;
61const int Phone_utils::PHONE_TYPE_GSM = 1;
62const int Phone_utils::PHONE_TYPE_CDMA = 2;
63const int Phone_utils::PHONE_TYPE_SIP = 3;
64const int Phone_utils::PHONE_TYPE_THIRD_PARTY = 4;
65const 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 */
75constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_UNKNOWN;
76constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_GPRS;
77constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_EDGE;
78constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_UMTS;
79constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_IS95A;
80constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_IS95B;
81constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_1xRTT;
82constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_EVDO_0;
83constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_EVDO_A;
84constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_HSDPA;
85constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_HSUPA;
86constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_HSPA;
87constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_EVDO_B;
88constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_EHRPD;
89constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_LTE;
90constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_HSPAP;
91constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_GSM;
92constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_TD_SCDMA;
93constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_IWLAN;
94constexpr int Phone_utils::RIL_RADIO_TECHNOLOGY_LTE_CA;
95
96int Phone_utils::PREFERRED_NETWORK_MODE = init();
97
98const int Phone_utils::APP_FAM_3GPP = 1;
99const int Phone_utils::APP_FAM_3GPP2 = 2;
100const int Phone_utils::APP_FAM_IMS = 3;
101
102const std::string Phone_utils::RADIO_DSSS_SIM_DISABLE = "persist.radio.dsss.sim.disable";
103int32_t Phone_utils::disable_sim = -1;
104
105int 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
134int 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
148Phone_utils::Phone_utils() {
149 // TODO Auto-generated constructor stub
150
151}
152
153Phone_utils::~Phone_utils() {
154 // TODO Auto-generated destructor stub
155}
156
157int Phone_utils::get_phone_count() {
158 int phoneCount = 1;
159 if(utils::is_support_dsds()) {
160 phoneCount = 2;
161 }
162 return phoneCount;
163}
164
165int 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
175bool 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
190bool 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
200bool Phone_utils::isLte(int radioTechnology){
201 return radioTechnology == RIL_RADIO_TECHNOLOGY_LTE ||
202 radioTechnology == RIL_RADIO_TECHNOLOGY_LTE_CA;
203}