10825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville/* 20825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Copyright (C) 2006 The Android Open Source Project 30825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 40825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Licensed under the Apache License, Version 2.0 (the "License"); 50825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * you may not use this file except in compliance with the License. 60825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * You may obtain a copy of the License at 70825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 80825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * http://www.apache.org/licenses/LICENSE-2.0 90825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 100825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Unless required by applicable law or agreed to in writing, software 110825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * distributed under the License is distributed on an "AS IS" BASIS, 120825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 130825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * See the License for the specific language governing permissions and 140825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * limitations under the License. 150825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 160825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 174918296afe1c667e9523cdfc799f558f7ebc2bfbWink Savillepackage com.android.internal.telephony.dataconnection; 180825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 19ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Savilleimport android.app.PendingIntent; 206bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwaltimport android.net.ConnectivityManager; 21e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport android.net.NetworkCapabilities; 223fad7daba62dcb7aafc4adc7f8cc123726ed5a7cRobert Greenwaltimport android.net.NetworkConfig; 23e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport android.net.NetworkRequest; 2499c2e1d6749cfad2a8ca94a47857d8c3bfc09454Wink Savilleimport android.telephony.Rlog; 25801a47b6bd24dec45fa0cd554bcf301478e93f47Sukanya Rajkhowaimport android.text.TextUtils; 262dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwaltimport android.util.LocalLog; 270d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwaltimport android.util.SparseIntArray; 280825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 2943c93591d6261be6dad375979e98b0f6ad2771fdWink Savilleimport com.android.internal.R; 304918296afe1c667e9523cdfc799f558f7ebc2bfbWink Savilleimport com.android.internal.telephony.DctConstants; 314918296afe1c667e9523cdfc799f558f7ebc2bfbWink Savilleimport com.android.internal.telephony.Phone; 32e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport com.android.internal.telephony.PhoneConstants; 330e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yuimport com.android.internal.telephony.RetryManager; 3451f4bf7f29ffeaa60a8e7d4d1da7b30f20e8a420Robert Greenwaltimport com.android.internal.util.IndentingPrintWriter; 354918296afe1c667e9523cdfc799f558f7ebc2bfbWink Saville 360825495a331bb44df395a0cdb79fab85e68db5d5Wink Savilleimport java.io.FileDescriptor; 370825495a331bb44df395a0cdb79fab85e68db5d5Wink Savilleimport java.io.PrintWriter; 389521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwaltimport java.util.ArrayDeque; 390825495a331bb44df395a0cdb79fab85e68db5d5Wink Savilleimport java.util.ArrayList; 40692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwaltimport java.util.List; 410825495a331bb44df395a0cdb79fab85e68db5d5Wink Savilleimport java.util.concurrent.atomic.AtomicBoolean; 420825495a331bb44df395a0cdb79fab85e68db5d5Wink Savilleimport java.util.concurrent.atomic.AtomicInteger; 430825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 440825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville/** 450825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Maintain the Apn context 460825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 47608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwaltpublic class ApnContext { 480825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 490825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public final String LOG_TAG; 50e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt private final static String SLOG_TAG = "ApnContext"; 510825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 52608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt protected static final boolean DBG = false; 530825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 540e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu private final Phone mPhone; 5543c93591d6261be6dad375979e98b0f6ad2771fdWink Saville 560825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville private final String mApnType; 570825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 580825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville private DctConstants.State mState; 590825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 603fad7daba62dcb7aafc4adc7f8cc123726ed5a7cRobert Greenwalt public final int priority; 613fad7daba62dcb7aafc4adc7f8cc123726ed5a7cRobert Greenwalt 620825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville private ApnSetting mApnSetting; 630825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 64454b1dfd508844b42eb775e4ab2359be74d3672bWink Saville DcAsyncChannel mDcAc; 650825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 66608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt String mReason; 670825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 68ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville PendingIntent mReconnectAlarmIntent; 690825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 700825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 710825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * user/app requested connection on this APN 720825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 730825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville AtomicBoolean mDataEnabled; 740825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 75071b9f85ac559a35430ed37c03a66271977b9d17Robert Greenwalt private final Object mRefCountLock = new Object(); 76071b9f85ac559a35430ed37c03a66271977b9d17Robert Greenwalt private int mRefCount = 0; 77071b9f85ac559a35430ed37c03a66271977b9d17Robert Greenwalt 780825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 790825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * carrier requirements met 800825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 810825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville AtomicBoolean mDependencyMet; 820825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 831a87ab3d7170d618f048c4f5af8c7504a587aaa5Jack Yu private final DcTracker mDcTracker; 84071b9f85ac559a35430ed37c03a66271977b9d17Robert Greenwalt 85c2d1d6b2725b4611360d2725624a0d8905d75694Robert Greenwalt /** 86c2d1d6b2725b4611360d2725624a0d8905d75694Robert Greenwalt * Remember this as a change in this value to a more permissive state 87c2d1d6b2725b4611360d2725624a0d8905d75694Robert Greenwalt * should cause us to retry even permanent failures 88c2d1d6b2725b4611360d2725624a0d8905d75694Robert Greenwalt */ 89c2d1d6b2725b4611360d2725624a0d8905d75694Robert Greenwalt private boolean mConcurrentVoiceAndDataAllowed; 90c2d1d6b2725b4611360d2725624a0d8905d75694Robert Greenwalt 91ea763d93b231bccf7e476b625fa028bef7874bf8Robert Greenwalt /** 92ea763d93b231bccf7e476b625fa028bef7874bf8Robert Greenwalt * used to track a single connection request so disconnects can get ignored if 93ea763d93b231bccf7e476b625fa028bef7874bf8Robert Greenwalt * obsolete. 94ea763d93b231bccf7e476b625fa028bef7874bf8Robert Greenwalt */ 95ea763d93b231bccf7e476b625fa028bef7874bf8Robert Greenwalt private final AtomicInteger mConnectionGeneration = new AtomicInteger(0); 96ea763d93b231bccf7e476b625fa028bef7874bf8Robert Greenwalt 970e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu /** 980e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * Retry manager that handles the APN retry and delays. 990e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu */ 1000e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu private final RetryManager mRetryManager; 1010e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu 1020e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu /** 1030e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * AonContext constructor 1040e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @param phone phone object 1050e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @param apnType APN type (e.g. default, supl, mms, etc...) 1060e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @param logTag Tag for logging 1070e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @param config Network configuration 1080e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @param tracker Data call tracker 1090e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu */ 1100e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu public ApnContext(Phone phone, String apnType, String logTag, NetworkConfig config, 1111a87ab3d7170d618f048c4f5af8c7504a587aaa5Jack Yu DcTracker tracker) { 1120e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu mPhone = phone; 1130825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville mApnType = apnType; 1140825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville mState = DctConstants.State.IDLE; 115608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt setReason(Phone.REASON_DATA_ENABLED); 1160825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville mDataEnabled = new AtomicBoolean(false); 1173fad7daba62dcb7aafc4adc7f8cc123726ed5a7cRobert Greenwalt mDependencyMet = new AtomicBoolean(config.dependencyMet); 1183fad7daba62dcb7aafc4adc7f8cc123726ed5a7cRobert Greenwalt priority = config.priority; 1190825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville LOG_TAG = logTag; 120071b9f85ac559a35430ed37c03a66271977b9d17Robert Greenwalt mDcTracker = tracker; 1210e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu mRetryManager = new RetryManager(phone, apnType); 1220825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 1230825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 1240e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu /** 1250e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * Get the APN type 1260e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @return The APN type 1270e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu */ 1280825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public String getApnType() { 1290825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mApnType; 1300825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 1310825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 1320e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu /** 1330e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * Get the data call async channel. 1340e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @return The data call async channel 1350e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu */ 136454b1dfd508844b42eb775e4ab2359be74d3672bWink Saville public synchronized DcAsyncChannel getDcAc() { 137454b1dfd508844b42eb775e4ab2359be74d3672bWink Saville return mDcAc; 1380825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 1390825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 1400e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu /** 1410e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * Set the data call async channel. 1420e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @param dcac The data call async channel 1430e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu */ 144454b1dfd508844b42eb775e4ab2359be74d3672bWink Saville public synchronized void setDataConnectionAc(DcAsyncChannel dcac) { 1450825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville if (DBG) { 146454b1dfd508844b42eb775e4ab2359be74d3672bWink Saville log("setDataConnectionAc: old dcac=" + mDcAc + " new dcac=" + dcac 1472563e7e1ec513121b980045571a245aa5390f1c5Wink Saville + " this=" + this); 1480825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 149454b1dfd508844b42eb775e4ab2359be74d3672bWink Saville mDcAc = dcac; 1500825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 1510825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 1520e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu /** 1530e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * Release data connection. 1540e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @param reason The reason of releasing data connection 1550e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu */ 156ee665b78ad648abd98b019a9c9047f206ed22994Robert Greenwalt public synchronized void releaseDataConnection(String reason) { 157ee665b78ad648abd98b019a9c9047f206ed22994Robert Greenwalt if (mDcAc != null) { 158ee665b78ad648abd98b019a9c9047f206ed22994Robert Greenwalt mDcAc.tearDown(this, reason, null); 159ee665b78ad648abd98b019a9c9047f206ed22994Robert Greenwalt mDcAc = null; 160ee665b78ad648abd98b019a9c9047f206ed22994Robert Greenwalt } 161ee665b78ad648abd98b019a9c9047f206ed22994Robert Greenwalt setState(DctConstants.State.IDLE); 162ee665b78ad648abd98b019a9c9047f206ed22994Robert Greenwalt } 163ee665b78ad648abd98b019a9c9047f206ed22994Robert Greenwalt 1640e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu /** 1650e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * Get the reconnect intent. 1660e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @return The reconnect intent 1670e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu */ 168ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville public synchronized PendingIntent getReconnectIntent() { 169ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville return mReconnectAlarmIntent; 170ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville } 171ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville 1720e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu /** 1730e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * Save the reconnect intent which can be used for cancelling later. 1740e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @param intent The reconnect intent 1750e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu */ 176ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville public synchronized void setReconnectIntent(PendingIntent intent) { 177ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville mReconnectAlarmIntent = intent; 178ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville } 179ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville 1800e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu /** 1810e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * Get the current APN setting. 1820e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @return APN setting 1830e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu */ 1840825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public synchronized ApnSetting getApnSetting() { 1859232dafa7ea833fc0b3a6024d6c7e23fc8e961eaRobert Greenwalt if (DBG) log("getApnSetting: apnSetting=" + mApnSetting); 1860825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mApnSetting; 1870825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 1880825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 1890e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu /** 1900e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * Set the APN setting. 1910e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @param apnSetting APN setting 1920e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu */ 1930825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public synchronized void setApnSetting(ApnSetting apnSetting) { 1949232dafa7ea833fc0b3a6024d6c7e23fc8e961eaRobert Greenwalt if (DBG) log("setApnSetting: apnSetting=" + apnSetting); 1950825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville mApnSetting = apnSetting; 1960825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 1970825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 1980e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu /** 1990e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * Set the list of APN candidates which will be used for data call setup later. 2000e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @param waitingApns List of APN candidates 2010e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu */ 2020825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public synchronized void setWaitingApns(ArrayList<ApnSetting> waitingApns) { 2030e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu mRetryManager.setWaitingApns(waitingApns); 2040825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 2050825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 2060e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu /** 2070e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * Get the next available APN to try. 2080e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @return APN setting which will be used for data call setup. Return null if there is no 2090e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * APN can be retried. 2100e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu */ 2110e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu public ApnSetting getNextApnSetting() { 2120e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu return mRetryManager.getNextApnSetting(); 2130825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 2140825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 2150e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu /** 2160e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * Save the modem suggested delay for retrying the current APN. 2170e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * This method is called when we get the suggested delay from RIL. 2180e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @param delay The delay in milliseconds 2190e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu */ 2200e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu public void setModemSuggestedDelay(long delay) { 2210e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu mRetryManager.setModemSuggestedDelay(delay); 2220825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 2230825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 2240e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu /** 2250e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * Get the delay for trying the next APN setting if the current one failed. 2260e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @param failFastEnabled True if fail fast mode enabled. In this case we'll use a shorter 2270e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * delay. 2280e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @return The delay in milliseconds 2290e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu */ 2300e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu public long getDelayForNextApn(boolean failFastEnabled) { 231d9ba2683e866ca3a813684a90472062232cbc732fionaxu return mRetryManager.getDelayForNextApn(failFastEnabled || isFastRetryReason()); 2320825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 2330825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 2340e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu /** 2350e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * Mark the current APN setting permanently failed, which means it will not be retried anymore. 2360e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @param apn APN setting 2370e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu */ 2380e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu public void markApnPermanentFailed(ApnSetting apn) { 2390e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu mRetryManager.markApnPermanentFailed(apn); 240c2d1d6b2725b4611360d2725624a0d8905d75694Robert Greenwalt } 241c2d1d6b2725b4611360d2725624a0d8905d75694Robert Greenwalt 2420e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu /** 2430e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * Get the list of waiting APNs. 2440e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @return the list of waiting APNs 2450e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu */ 2460e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu public ArrayList<ApnSetting> getWaitingApns() { 2470e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu return mRetryManager.getWaitingApns(); 2480825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 2490825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 2500e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu /** 2510e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * Save the state indicating concurrent voice/data allowed. 2520e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @param allowed True if concurrent voice/data is allowed 2530e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu */ 254c2d1d6b2725b4611360d2725624a0d8905d75694Robert Greenwalt public synchronized void setConcurrentVoiceAndDataAllowed(boolean allowed) { 255c2d1d6b2725b4611360d2725624a0d8905d75694Robert Greenwalt mConcurrentVoiceAndDataAllowed = allowed; 256c2d1d6b2725b4611360d2725624a0d8905d75694Robert Greenwalt } 257c2d1d6b2725b4611360d2725624a0d8905d75694Robert Greenwalt 2580e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu /** 2590e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * Get the state indicating concurrent voice/data allowed. 2600e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @return True if concurrent voice/data is allowed 2610e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu */ 262c2d1d6b2725b4611360d2725624a0d8905d75694Robert Greenwalt public synchronized boolean isConcurrentVoiceAndDataAllowed() { 263c2d1d6b2725b4611360d2725624a0d8905d75694Robert Greenwalt return mConcurrentVoiceAndDataAllowed; 264c2d1d6b2725b4611360d2725624a0d8905d75694Robert Greenwalt } 265c2d1d6b2725b4611360d2725624a0d8905d75694Robert Greenwalt 2660e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu /** 2670e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * Set the current data call state. 2680e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @param s Current data call state 2690e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu */ 2700825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public synchronized void setState(DctConstants.State s) { 2710825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville if (DBG) { 2720825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville log("setState: " + s + ", previous state:" + mState); 2730825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 2740825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 2750825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville mState = s; 2760825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 2770825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville if (mState == DctConstants.State.FAILED) { 2780e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu if (mRetryManager.getWaitingApns() != null) { 2790e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu mRetryManager.getWaitingApns().clear(); // when teardown the connection and set to IDLE 2800825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 2810825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 2820825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 2830825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 2840e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu /** 2850e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * Get the current data call state. 2860e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @return The current data call state 2870e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu */ 2880825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public synchronized DctConstants.State getState() { 2890825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mState; 2900825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 2910825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 2920e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu /** 2930e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * Check whether the data call is disconnected or not. 2940e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @return True if the data call is disconnected 2950e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu */ 2960825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public boolean isDisconnected() { 2970825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville DctConstants.State currentState = getState(); 2980825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return ((currentState == DctConstants.State.IDLE) || 2990825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville currentState == DctConstants.State.FAILED); 3000825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 3010825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 3020e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu /** 3030e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * Set the reason for data call connection. 3040e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @param reason Reason for data call connection 3050e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu */ 3060825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public synchronized void setReason(String reason) { 3070825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville if (DBG) { 3080825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville log("set reason as " + reason + ",current state " + mState); 3090825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 310608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt mReason = reason; 3110825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 3120825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 3130e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu /** 3140e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * Get the reason for data call connection. 3150e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @return The reason for data call connection 3160e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu */ 3170825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public synchronized String getReason() { 318608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt return mReason; 3190825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 3200825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 3210e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu /** 3220e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * Check if ready for data call connection 3230e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @return True if ready, otherwise false. 3240e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu */ 3250825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public boolean isReady() { 3260825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mDataEnabled.get() && mDependencyMet.get(); 3270825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 3280825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 3290e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu /** 3300e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * Check if the data call is in the state which allow connecting. 3310e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @return True if allowed, otherwise false. 3320e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu */ 333ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville public boolean isConnectable() { 334ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville return isReady() && ((mState == DctConstants.State.IDLE) 335ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville || (mState == DctConstants.State.SCANNING) 336ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville || (mState == DctConstants.State.RETRYING) 337ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville || (mState == DctConstants.State.FAILED)); 338ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville } 339ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville 340d9ba2683e866ca3a813684a90472062232cbc732fionaxu /** 341d9ba2683e866ca3a813684a90472062232cbc732fionaxu * Check if apn reason is fast retry reason which should apply shorter delay between apn re-try. 342d9ba2683e866ca3a813684a90472062232cbc732fionaxu * @return True if it is fast retry reason, otherwise false. 343d9ba2683e866ca3a813684a90472062232cbc732fionaxu */ 344d9ba2683e866ca3a813684a90472062232cbc732fionaxu private boolean isFastRetryReason() { 3454fdc57b9bf223c908474c4545cc6f63456117a3bSanket Padawe return Phone.REASON_NW_TYPE_CHANGED.equals(mReason) || 3464fdc57b9bf223c908474c4545cc6f63456117a3bSanket Padawe Phone.REASON_APN_CHANGED.equals(mReason); 347d9ba2683e866ca3a813684a90472062232cbc732fionaxu } 348d9ba2683e866ca3a813684a90472062232cbc732fionaxu 3490e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu /** Check if the data call is in connected or connecting state. 3500e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @return True if the data call is in connected or connecting state 3510e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu */ 352e9063f6973039d66e12d0d930af03906d377969eWink Saville public boolean isConnectedOrConnecting() { 353e9063f6973039d66e12d0d930af03906d377969eWink Saville return isReady() && ((mState == DctConstants.State.CONNECTED) 354e9063f6973039d66e12d0d930af03906d377969eWink Saville || (mState == DctConstants.State.CONNECTING) 355e9063f6973039d66e12d0d930af03906d377969eWink Saville || (mState == DctConstants.State.SCANNING) 356e9063f6973039d66e12d0d930af03906d377969eWink Saville || (mState == DctConstants.State.RETRYING)); 357e9063f6973039d66e12d0d930af03906d377969eWink Saville } 358e9063f6973039d66e12d0d930af03906d377969eWink Saville 3590e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu /** 3600e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * Set data call enabled/disabled state. 3610e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @param enabled True if data call is enabled 3620e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu */ 3630825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public void setEnabled(boolean enabled) { 3640825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville if (DBG) { 3650825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville log("set enabled as " + enabled + ", current state is " + mDataEnabled.get()); 3660825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 3670825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville mDataEnabled.set(enabled); 3680825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 3690825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 3700e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu /** 3710e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * Check if the data call is enabled or not. 3720e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu * @return True if enabled 3730e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu */ 3740825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public boolean isEnabled() { 3750825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mDataEnabled.get(); 3760825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 3770825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 3780825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public void setDependencyMet(boolean met) { 3790825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville if (DBG) { 3800825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville log("set mDependencyMet as " + met + " current state is " + mDependencyMet.get()); 3810825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 3820825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville mDependencyMet.set(met); 3830825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 3840825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 3850825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public boolean getDependencyMet() { 3860825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mDependencyMet.get(); 3870825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 3880825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 38943c93591d6261be6dad375979e98b0f6ad2771fdWink Saville public boolean isProvisioningApn() { 3900e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu String provisioningApn = mPhone.getContext().getResources() 391608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt .getString(R.string.mobile_provisioning_apn); 392801a47b6bd24dec45fa0cd554bcf301478e93f47Sukanya Rajkhowa if (!TextUtils.isEmpty(provisioningApn) && 393801a47b6bd24dec45fa0cd554bcf301478e93f47Sukanya Rajkhowa (mApnSetting != null) && (mApnSetting.apn != null)) { 394608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt return (mApnSetting.apn.equals(provisioningApn)); 395608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt } else { 396608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt return false; 39743c93591d6261be6dad375979e98b0f6ad2771fdWink Saville } 39843c93591d6261be6dad375979e98b0f6ad2771fdWink Saville } 39943c93591d6261be6dad375979e98b0f6ad2771fdWink Saville 400692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt private final ArrayList<LocalLog> mLocalLogs = new ArrayList<>(); 401692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt private final ArrayList<NetworkRequest> mNetworkRequests = new ArrayList<>(); 402692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt private final ArrayDeque<LocalLog> mHistoryLogs = new ArrayDeque<>(); 4039521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt private final static int MAX_HISTORY_LOG_COUNT = 4; 4042dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt 4052dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt public void requestLog(String str) { 406071b9f85ac559a35430ed37c03a66271977b9d17Robert Greenwalt synchronized (mRefCountLock) { 4072dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt for (LocalLog l : mLocalLogs) { 4082dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt l.log(str); 4092dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt } 4102dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt } 4112dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt } 4122dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt 413692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt public void requestNetwork(NetworkRequest networkRequest, LocalLog log) { 4142dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt synchronized (mRefCountLock) { 415692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt if (mLocalLogs.contains(log) || mNetworkRequests.contains(networkRequest)) { 416692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt log.log("ApnContext.requestNetwork has duplicate add - " + mNetworkRequests.size()); 4172dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt } else { 4182dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt mLocalLogs.add(log); 419692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt mNetworkRequests.add(networkRequest); 420cda5b321ceddda71d47ec2fe619d6624dd2ea3daRobert Greenwalt mDcTracker.setEnabled(apnIdForApnName(mApnType), true); 421071b9f85ac559a35430ed37c03a66271977b9d17Robert Greenwalt } 422071b9f85ac559a35430ed37c03a66271977b9d17Robert Greenwalt } 423071b9f85ac559a35430ed37c03a66271977b9d17Robert Greenwalt } 424071b9f85ac559a35430ed37c03a66271977b9d17Robert Greenwalt 425692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt public void releaseNetwork(NetworkRequest networkRequest, LocalLog log) { 426071b9f85ac559a35430ed37c03a66271977b9d17Robert Greenwalt synchronized (mRefCountLock) { 427692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt if (mLocalLogs.contains(log) == false) { 428692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt log.log("ApnContext.releaseNetwork can't find this log"); 4292dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt } else { 430692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt mLocalLogs.remove(log); 4312dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt } 432692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt if (mNetworkRequests.contains(networkRequest) == false) { 433692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt log.log("ApnContext.releaseNetwork can't find this request (" 434692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt + networkRequest + ")"); 435692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt } else { 436692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt mNetworkRequests.remove(networkRequest); 437692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt log.log("ApnContext.releaseNetwork left with " + mNetworkRequests.size() + 438692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt " requests."); 439692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt if (mNetworkRequests.size() == 0) { 440692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt mDcTracker.setEnabled(apnIdForApnName(mApnType), false); 441692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt } 442071b9f85ac559a35430ed37c03a66271977b9d17Robert Greenwalt } 443692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt } 444692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt } 445692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt 446692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt public List<NetworkRequest> getNetworkRequests() { 447692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt synchronized (mRefCountLock) { 448692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt return new ArrayList<NetworkRequest>(mNetworkRequests); 449692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt } 450692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt } 451692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt 452443b0ae99852b74898fa688f90dee303a80c1b89Robert Greenwalt public boolean hasNoRestrictedRequests(boolean excludeDun) { 453692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt synchronized (mRefCountLock) { 454692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt for (NetworkRequest nr : mNetworkRequests) { 455443b0ae99852b74898fa688f90dee303a80c1b89Robert Greenwalt if (excludeDun && 456443b0ae99852b74898fa688f90dee303a80c1b89Robert Greenwalt nr.networkCapabilities.hasCapability( 457443b0ae99852b74898fa688f90dee303a80c1b89Robert Greenwalt NetworkCapabilities.NET_CAPABILITY_DUN)) { 458443b0ae99852b74898fa688f90dee303a80c1b89Robert Greenwalt continue; 459443b0ae99852b74898fa688f90dee303a80c1b89Robert Greenwalt } 460692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt if (nr.networkCapabilities.hasCapability( 461692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED) == false) { 462692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt return false; 463692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt } 464e8b308038b3449509c92478ee26096302d768855Robert Greenwalt } 465071b9f85ac559a35430ed37c03a66271977b9d17Robert Greenwalt } 466692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt return true; 467071b9f85ac559a35430ed37c03a66271977b9d17Robert Greenwalt } 468071b9f85ac559a35430ed37c03a66271977b9d17Robert Greenwalt 4690d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt private final SparseIntArray mRetriesLeftPerErrorCode = new SparseIntArray(); 4700d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt 4710d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt public void resetErrorCodeRetries() { 4720d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt requestLog("ApnContext.resetErrorCodeRetries"); 4730d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt if (DBG) log("ApnContext.resetErrorCodeRetries"); 4740d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt 4759e0be93719c4de0cedec33508c799f3b2f223454Jack Yu String[] config = mPhone.getContext().getResources().getStringArray( 4760d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt com.android.internal.R.array.config_cell_retries_per_error_code); 4770d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt synchronized (mRetriesLeftPerErrorCode) { 4780d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt mRetriesLeftPerErrorCode.clear(); 4790d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt 4800d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt for (String c : config) { 4810d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt String errorValue[] = c.split(","); 4820d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt if (errorValue != null && errorValue.length == 2) { 4830d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt int count = 0; 4840d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt int errorCode = 0; 4850d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt try { 4860d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt errorCode = Integer.parseInt(errorValue[0]); 4870d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt count = Integer.parseInt(errorValue[1]); 4880d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt } catch (NumberFormatException e) { 4890d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt log("Exception parsing config_retries_per_error_code: " + e); 4900d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt continue; 4910d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt } 4920d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt if (count > 0 && errorCode > 0) { 4930d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt mRetriesLeftPerErrorCode.put(errorCode, count); 4940d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt } 4950d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt } else { 4960d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt log("Exception parsing config_retries_per_error_code: " + c); 4970d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt } 4980d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt } 4990d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt } 5000d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt } 5010d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt 5020d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt public boolean restartOnError(int errorCode) { 5030d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt boolean result = false; 5040d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt int retriesLeft = 0; 5050d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt synchronized(mRetriesLeftPerErrorCode) { 5060d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt retriesLeft = mRetriesLeftPerErrorCode.get(errorCode); 5070d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt switch (retriesLeft) { 5080d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt case 0: { 5090d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt // not set, never restart modem 5100d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt break; 5110d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt } 5120d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt case 1: { 5130d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt resetErrorCodeRetries(); 5140d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt result = true; 5150d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt break; 5160d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt } 5170d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt default: { 5180d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt mRetriesLeftPerErrorCode.put(errorCode, retriesLeft - 1); 5190d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt result = false; 5200d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt } 5210d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt } 5220d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt } 5230d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt String str = "ApnContext.restartOnError(" + errorCode + ") found " + retriesLeft + 5240d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt " and returned " + result; 5250d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt if (DBG) log(str); 5260d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt requestLog(str); 5270d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt return result; 5280d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt } 5290d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt 530ea763d93b231bccf7e476b625fa028bef7874bf8Robert Greenwalt public int incAndGetConnectionGeneration() { 531ea763d93b231bccf7e476b625fa028bef7874bf8Robert Greenwalt return mConnectionGeneration.incrementAndGet(); 532ea763d93b231bccf7e476b625fa028bef7874bf8Robert Greenwalt } 533ea763d93b231bccf7e476b625fa028bef7874bf8Robert Greenwalt 534ea763d93b231bccf7e476b625fa028bef7874bf8Robert Greenwalt public int getConnectionGeneration() { 535ea763d93b231bccf7e476b625fa028bef7874bf8Robert Greenwalt return mConnectionGeneration.get(); 536ea763d93b231bccf7e476b625fa028bef7874bf8Robert Greenwalt } 537ea763d93b231bccf7e476b625fa028bef7874bf8Robert Greenwalt 538da21f0de2087657b20b18817b33d59778720bffbJack Yu long getRetryAfterDisconnectDelay() { 539da21f0de2087657b20b18817b33d59778720bffbJack Yu return mRetryManager.getRetryAfterDisconnectDelay(); 5400e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu } 5410e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu 5426bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt public static int apnIdForType(int networkType) { 5436bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt switch (networkType) { 5446bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt case ConnectivityManager.TYPE_MOBILE: 5456bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt return DctConstants.APN_DEFAULT_ID; 5466bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt case ConnectivityManager.TYPE_MOBILE_MMS: 5476bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt return DctConstants.APN_MMS_ID; 5486bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt case ConnectivityManager.TYPE_MOBILE_SUPL: 5496bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt return DctConstants.APN_SUPL_ID; 5506bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt case ConnectivityManager.TYPE_MOBILE_DUN: 5516bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt return DctConstants.APN_DUN_ID; 5526bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt case ConnectivityManager.TYPE_MOBILE_FOTA: 5536bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt return DctConstants.APN_FOTA_ID; 5546bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt case ConnectivityManager.TYPE_MOBILE_IMS: 5556bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt return DctConstants.APN_IMS_ID; 5566bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt case ConnectivityManager.TYPE_MOBILE_CBS: 5576bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt return DctConstants.APN_CBS_ID; 5586bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt case ConnectivityManager.TYPE_MOBILE_IA: 5596bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt return DctConstants.APN_IA_ID; 5606bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt case ConnectivityManager.TYPE_MOBILE_EMERGENCY: 5616bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt return DctConstants.APN_EMERGENCY_ID; 5626bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt default: 5636bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt return DctConstants.APN_INVALID_ID; 5646bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt } 5656bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt } 5666bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt 567e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt public static int apnIdForNetworkRequest(NetworkRequest nr) { 568e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt NetworkCapabilities nc = nr.networkCapabilities; 569e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt // For now, ignore the bandwidth stuff 570e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt if (nc.getTransportTypes().length > 0 && 571e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt nc.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) == false) { 572e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt return DctConstants.APN_INVALID_ID; 573e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt } 574e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt 575e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt // in the near term just do 1-1 matches. 576e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt // TODO - actually try to match the set of capabilities 577e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt int apnId = DctConstants.APN_INVALID_ID; 578e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt boolean error = false; 579e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt 580e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) { 581e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt apnId = DctConstants.APN_DEFAULT_ID; 582e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt } 583e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_MMS)) { 584e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt if (apnId != DctConstants.APN_INVALID_ID) error = true; 585e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt apnId = DctConstants.APN_MMS_ID; 586e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt } 587e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_SUPL)) { 588e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt if (apnId != DctConstants.APN_INVALID_ID) error = true; 589e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt apnId = DctConstants.APN_SUPL_ID; 590e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt } 591e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_DUN)) { 592e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt if (apnId != DctConstants.APN_INVALID_ID) error = true; 593e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt apnId = DctConstants.APN_DUN_ID; 594e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt } 595e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_FOTA)) { 596e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt if (apnId != DctConstants.APN_INVALID_ID) error = true; 597e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt apnId = DctConstants.APN_FOTA_ID; 598e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt } 599e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_IMS)) { 600e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt if (apnId != DctConstants.APN_INVALID_ID) error = true; 601e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt apnId = DctConstants.APN_IMS_ID; 602e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt } 603e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_CBS)) { 604e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt if (apnId != DctConstants.APN_INVALID_ID) error = true; 605e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt apnId = DctConstants.APN_CBS_ID; 606e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt } 607e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_IA)) { 608e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt if (apnId != DctConstants.APN_INVALID_ID) error = true; 609e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt apnId = DctConstants.APN_IA_ID; 610e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt } 611e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_RCS)) { 612e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt if (apnId != DctConstants.APN_INVALID_ID) error = true; 613e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt 614e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt Rlog.d(SLOG_TAG, "RCS APN type not yet supported"); 615e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt } 616e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_XCAP)) { 617e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt if (apnId != DctConstants.APN_INVALID_ID) error = true; 618e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt 619e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt Rlog.d(SLOG_TAG, "XCAP APN type not yet supported"); 620e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt } 621e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_EIMS)) { 622e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt if (apnId != DctConstants.APN_INVALID_ID) error = true; 6232712f31b9ad49d926c68d9c3f227acc0478cac61Sanket Padawe apnId = DctConstants.APN_EMERGENCY_ID; 624e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt } 625e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt if (error) { 626e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt // TODO: If this error condition is removed, the framework's handling of 627e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt // NET_CAPABILITY_NOT_RESTRICTED will need to be updated so requests for 628e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt // say FOTA and INTERNET are marked as restricted. This is not how 629e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt // NetworkCapabilities.maybeMarkCapabilitiesRestricted currently works. 630e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt Rlog.d(SLOG_TAG, "Multiple apn types specified in request - result is unspecified!"); 631e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt } 632e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt if (apnId == DctConstants.APN_INVALID_ID) { 633e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt Rlog.d(SLOG_TAG, "Unsupported NetworkRequest in Telephony: nr=" + nr); 634e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt } 635e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt return apnId; 636e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt } 637e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt 638e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt // TODO - kill The use of these strings 639e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt public static int apnIdForApnName(String type) { 640e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt switch (type) { 641e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt case PhoneConstants.APN_TYPE_DEFAULT: 642e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt return DctConstants.APN_DEFAULT_ID; 643e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt case PhoneConstants.APN_TYPE_MMS: 644e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt return DctConstants.APN_MMS_ID; 645e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt case PhoneConstants.APN_TYPE_SUPL: 646e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt return DctConstants.APN_SUPL_ID; 647e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt case PhoneConstants.APN_TYPE_DUN: 648e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt return DctConstants.APN_DUN_ID; 649e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt case PhoneConstants.APN_TYPE_HIPRI: 650e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt return DctConstants.APN_HIPRI_ID; 651e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt case PhoneConstants.APN_TYPE_IMS: 652e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt return DctConstants.APN_IMS_ID; 653e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt case PhoneConstants.APN_TYPE_FOTA: 654e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt return DctConstants.APN_FOTA_ID; 655e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt case PhoneConstants.APN_TYPE_CBS: 656e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt return DctConstants.APN_CBS_ID; 657e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt case PhoneConstants.APN_TYPE_IA: 658e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt return DctConstants.APN_IA_ID; 659e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt case PhoneConstants.APN_TYPE_EMERGENCY: 660e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt return DctConstants.APN_EMERGENCY_ID; 661e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt default: 662e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt return DctConstants.APN_INVALID_ID; 663e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt } 664e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt } 665e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt 666e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt private static String apnNameForApnId(int id) { 667e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt switch (id) { 668e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt case DctConstants.APN_DEFAULT_ID: 669e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt return PhoneConstants.APN_TYPE_DEFAULT; 670e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt case DctConstants.APN_MMS_ID: 671e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt return PhoneConstants.APN_TYPE_MMS; 672e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt case DctConstants.APN_SUPL_ID: 673e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt return PhoneConstants.APN_TYPE_SUPL; 674e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt case DctConstants.APN_DUN_ID: 675e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt return PhoneConstants.APN_TYPE_DUN; 676e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt case DctConstants.APN_HIPRI_ID: 677e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt return PhoneConstants.APN_TYPE_HIPRI; 678e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt case DctConstants.APN_IMS_ID: 679e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt return PhoneConstants.APN_TYPE_IMS; 680e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt case DctConstants.APN_FOTA_ID: 681e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt return PhoneConstants.APN_TYPE_FOTA; 682e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt case DctConstants.APN_CBS_ID: 683e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt return PhoneConstants.APN_TYPE_CBS; 684e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt case DctConstants.APN_IA_ID: 685e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt return PhoneConstants.APN_TYPE_IA; 686e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt case DctConstants.APN_EMERGENCY_ID: 687e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt return PhoneConstants.APN_TYPE_EMERGENCY; 688e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt default: 689e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt Rlog.d(SLOG_TAG, "Unknown id (" + id + ") in apnIdToType"); 690e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt return PhoneConstants.APN_TYPE_DEFAULT; 691e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt } 692e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt } 693e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt 6940825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville @Override 6950f94d3aebcf0daf154bf0876164844d09067f904Wink Saville public synchronized String toString() { 6960825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville // We don't print mDataConnection because its recursive. 6972dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt return "{mApnType=" + mApnType + " mState=" + getState() + " mWaitingApns={" + 6980e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu mRetryManager.getWaitingApns() + "}" + " mApnSetting={" + mApnSetting + 6992dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt "} mReason=" + mReason + " mDataEnabled=" + mDataEnabled + " mDependencyMet=" + 7002dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt mDependencyMet + "}"; 7010825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 7020825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 7032dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt private void log(String s) { 70499c2e1d6749cfad2a8ca94a47857d8c3bfc09454Wink Saville Rlog.d(LOG_TAG, "[ApnContext:" + mApnType + "] " + s); 7050825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 7060825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 70751f4bf7f29ffeaa60a8e7d4d1da7b30f20e8a420Robert Greenwalt public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) { 70851f4bf7f29ffeaa60a8e7d4d1da7b30f20e8a420Robert Greenwalt final IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " "); 70951f4bf7f29ffeaa60a8e7d4d1da7b30f20e8a420Robert Greenwalt synchronized (mRefCountLock) { 71051f4bf7f29ffeaa60a8e7d4d1da7b30f20e8a420Robert Greenwalt pw.println(toString()); 711692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt if (mNetworkRequests.size() > 0) { 712692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt pw.println("NetworkRequests:"); 713692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt pw.increaseIndent(); 714692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt for (NetworkRequest nr : mNetworkRequests) { 715692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt pw.println(nr); 716692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt } 717692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt pw.decreaseIndent(); 718692640f429efa8e292c6261472b2c682e1079f8eRobert Greenwalt } 7199521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt pw.increaseIndent(); 7209521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt for (LocalLog l : mLocalLogs) { 7219521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt l.dump(fd, pw, args); 7229521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt } 7239521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt if (mHistoryLogs.size() > 0) pw.println("Historical Logs:"); 7249521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt for (LocalLog l : mHistoryLogs) { 7259521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt l.dump(fd, pw, args); 72651f4bf7f29ffeaa60a8e7d4d1da7b30f20e8a420Robert Greenwalt } 7279521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt pw.decreaseIndent(); 728da21f0de2087657b20b18817b33d59778720bffbJack Yu pw.println(mRetryManager); 72951f4bf7f29ffeaa60a8e7d4d1da7b30f20e8a420Robert Greenwalt } 7300825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 7310825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville} 732