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;
200d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwaltimport android.content.res.Resources;
216bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwaltimport android.net.ConnectivityManager;
22e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport android.net.NetworkCapabilities;
233fad7daba62dcb7aafc4adc7f8cc123726ed5a7cRobert Greenwaltimport android.net.NetworkConfig;
24e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport android.net.NetworkRequest;
2599c2e1d6749cfad2a8ca94a47857d8c3bfc09454Wink Savilleimport android.telephony.Rlog;
26801a47b6bd24dec45fa0cd554bcf301478e93f47Sukanya Rajkhowaimport android.text.TextUtils;
272dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwaltimport android.util.LocalLog;
280d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwaltimport android.util.SparseIntArray;
290825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
3043c93591d6261be6dad375979e98b0f6ad2771fdWink Savilleimport com.android.internal.R;
314918296afe1c667e9523cdfc799f558f7ebc2bfbWink Savilleimport com.android.internal.telephony.DctConstants;
324918296afe1c667e9523cdfc799f558f7ebc2bfbWink Savilleimport com.android.internal.telephony.Phone;
33e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport com.android.internal.telephony.PhoneConstants;
340e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yuimport com.android.internal.telephony.RetryManager;
3551f4bf7f29ffeaa60a8e7d4d1da7b30f20e8a420Robert Greenwaltimport com.android.internal.util.IndentingPrintWriter;
364918296afe1c667e9523cdfc799f558f7ebc2bfbWink Saville
370825495a331bb44df395a0cdb79fab85e68db5d5Wink Savilleimport java.io.FileDescriptor;
380825495a331bb44df395a0cdb79fab85e68db5d5Wink Savilleimport java.io.PrintWriter;
399521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwaltimport java.util.ArrayDeque;
400825495a331bb44df395a0cdb79fab85e68db5d5Wink Savilleimport java.util.ArrayList;
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) {
2310e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu        return mRetryManager.getDelayForNextApn(failFastEnabled);
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
3400e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu    /** Check if the data call is in connected or connecting state.
3410e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu     * @return True if the data call is in connected or connecting state
3420e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu     */
343e9063f6973039d66e12d0d930af03906d377969eWink Saville    public boolean isConnectedOrConnecting() {
344e9063f6973039d66e12d0d930af03906d377969eWink Saville        return isReady() && ((mState == DctConstants.State.CONNECTED)
345e9063f6973039d66e12d0d930af03906d377969eWink Saville                                || (mState == DctConstants.State.CONNECTING)
346e9063f6973039d66e12d0d930af03906d377969eWink Saville                                || (mState == DctConstants.State.SCANNING)
347e9063f6973039d66e12d0d930af03906d377969eWink Saville                                || (mState == DctConstants.State.RETRYING));
348e9063f6973039d66e12d0d930af03906d377969eWink Saville    }
349e9063f6973039d66e12d0d930af03906d377969eWink Saville
3500e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu    /**
3510e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu     * Set data call enabled/disabled state.
3520e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu     * @param enabled True if data call is enabled
3530e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu     */
3540825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    public void setEnabled(boolean enabled) {
3550825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville        if (DBG) {
3560825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville            log("set enabled as " + enabled + ", current state is " + mDataEnabled.get());
3570825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville        }
3580825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville        mDataEnabled.set(enabled);
3590825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    }
3600825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
3610e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu    /**
3620e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu     * Check if the data call is enabled or not.
3630e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu     * @return True if enabled
3640e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu     */
3650825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    public boolean isEnabled() {
3660825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville        return mDataEnabled.get();
3670825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    }
3680825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
3690825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    public void setDependencyMet(boolean met) {
3700825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville        if (DBG) {
3710825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville            log("set mDependencyMet as " + met + " current state is " + mDependencyMet.get());
3720825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville        }
3730825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville        mDependencyMet.set(met);
3740825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    }
3750825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
3760825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    public boolean getDependencyMet() {
3770825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville       return mDependencyMet.get();
3780825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    }
3790825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
38043c93591d6261be6dad375979e98b0f6ad2771fdWink Saville    public boolean isProvisioningApn() {
3810e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu        String provisioningApn = mPhone.getContext().getResources()
382608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt                .getString(R.string.mobile_provisioning_apn);
383801a47b6bd24dec45fa0cd554bcf301478e93f47Sukanya Rajkhowa        if (!TextUtils.isEmpty(provisioningApn) &&
384801a47b6bd24dec45fa0cd554bcf301478e93f47Sukanya Rajkhowa                (mApnSetting != null) && (mApnSetting.apn != null)) {
385608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt            return (mApnSetting.apn.equals(provisioningApn));
386608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt        } else {
387608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt            return false;
38843c93591d6261be6dad375979e98b0f6ad2771fdWink Saville        }
38943c93591d6261be6dad375979e98b0f6ad2771fdWink Saville    }
39043c93591d6261be6dad375979e98b0f6ad2771fdWink Saville
3912dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt    private final ArrayList<LocalLog> mLocalLogs = new ArrayList<LocalLog>();
3929521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt    private final ArrayDeque<LocalLog> mHistoryLogs = new ArrayDeque<LocalLog>();
3939521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt    private final static int MAX_HISTORY_LOG_COUNT = 4;
3942dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt
3952dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt    public void requestLog(String str) {
396071b9f85ac559a35430ed37c03a66271977b9d17Robert Greenwalt        synchronized (mRefCountLock) {
3972dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt            for (LocalLog l : mLocalLogs) {
3982dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt                l.log(str);
3992dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt            }
4002dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt        }
4012dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt    }
4022dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt
4032f5e0f602beab84c8ba1a9c8ee7736c9df62b0beRobert Greenwalt    public void incRefCount(LocalLog log) {
4042dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt        synchronized (mRefCountLock) {
4052dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt            if (mLocalLogs.contains(log)) {
4062dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt                log.log("ApnContext.incRefCount has duplicate add - " + mRefCount);
4072dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt            } else {
4082dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt                mLocalLogs.add(log);
4092dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt                log.log("ApnContext.incRefCount - " + mRefCount);
4102dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt            }
411071b9f85ac559a35430ed37c03a66271977b9d17Robert Greenwalt            if (mRefCount++ == 0) {
412e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                mDcTracker.setEnabled(apnIdForApnName(mApnType), true);
413071b9f85ac559a35430ed37c03a66271977b9d17Robert Greenwalt            }
414071b9f85ac559a35430ed37c03a66271977b9d17Robert Greenwalt        }
415071b9f85ac559a35430ed37c03a66271977b9d17Robert Greenwalt    }
416071b9f85ac559a35430ed37c03a66271977b9d17Robert Greenwalt
4172f5e0f602beab84c8ba1a9c8ee7736c9df62b0beRobert Greenwalt    public void decRefCount(LocalLog log) {
418071b9f85ac559a35430ed37c03a66271977b9d17Robert Greenwalt        synchronized (mRefCountLock) {
4199521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt            if (mLocalLogs.remove(log)) {
4209521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt                log.log("ApnContext.decRefCount - " + mRefCount);
4219521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt                mHistoryLogs.addFirst(log);
4229521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt                while (mHistoryLogs.size() > MAX_HISTORY_LOG_COUNT) {
4239521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt                    mHistoryLogs.removeLast();
4242dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt                }
4252dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt            } else {
4269521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt                log.log("ApnContext.decRefCount didn't find log - " + mRefCount);
4272dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt            }
428071b9f85ac559a35430ed37c03a66271977b9d17Robert Greenwalt            if (mRefCount-- == 1) {
429e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                mDcTracker.setEnabled(apnIdForApnName(mApnType), false);
430071b9f85ac559a35430ed37c03a66271977b9d17Robert Greenwalt            }
431e8b308038b3449509c92478ee26096302d768855Robert Greenwalt            if (mRefCount < 0) {
432e8b308038b3449509c92478ee26096302d768855Robert Greenwalt                log.log("ApnContext.decRefCount went to " + mRefCount);
433e8b308038b3449509c92478ee26096302d768855Robert Greenwalt                mRefCount = 0;
434e8b308038b3449509c92478ee26096302d768855Robert Greenwalt            }
435071b9f85ac559a35430ed37c03a66271977b9d17Robert Greenwalt        }
436071b9f85ac559a35430ed37c03a66271977b9d17Robert Greenwalt    }
437071b9f85ac559a35430ed37c03a66271977b9d17Robert Greenwalt
4380d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt    private final SparseIntArray mRetriesLeftPerErrorCode = new SparseIntArray();
4390d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt
4400d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt    public void resetErrorCodeRetries() {
4410d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt        requestLog("ApnContext.resetErrorCodeRetries");
4420d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt        if (DBG) log("ApnContext.resetErrorCodeRetries");
4430d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt
4449e0be93719c4de0cedec33508c799f3b2f223454Jack Yu        String[] config = mPhone.getContext().getResources().getStringArray(
4450d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                com.android.internal.R.array.config_cell_retries_per_error_code);
4460d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt        synchronized (mRetriesLeftPerErrorCode) {
4470d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt            mRetriesLeftPerErrorCode.clear();
4480d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt
4490d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt            for (String c : config) {
4500d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                String errorValue[] = c.split(",");
4510d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                if (errorValue != null && errorValue.length == 2) {
4520d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                    int count = 0;
4530d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                    int errorCode = 0;
4540d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                    try {
4550d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                        errorCode = Integer.parseInt(errorValue[0]);
4560d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                        count = Integer.parseInt(errorValue[1]);
4570d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                    } catch (NumberFormatException e) {
4580d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                        log("Exception parsing config_retries_per_error_code: " + e);
4590d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                        continue;
4600d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                    }
4610d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                    if (count > 0 && errorCode > 0) {
4620d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                        mRetriesLeftPerErrorCode.put(errorCode, count);
4630d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                    }
4640d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                } else {
4650d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                    log("Exception parsing config_retries_per_error_code: " + c);
4660d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                }
4670d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt            }
4680d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt        }
4690d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt    }
4700d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt
4710d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt    public boolean restartOnError(int errorCode) {
4720d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt        boolean result = false;
4730d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt        int retriesLeft = 0;
4740d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt        synchronized(mRetriesLeftPerErrorCode) {
4750d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt            retriesLeft = mRetriesLeftPerErrorCode.get(errorCode);
4760d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt            switch (retriesLeft) {
4770d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                case 0: {
4780d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                    // not set, never restart modem
4790d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                    break;
4800d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                }
4810d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                case 1: {
4820d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                    resetErrorCodeRetries();
4830d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                    result = true;
4840d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                    break;
4850d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                }
4860d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                default: {
4870d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                    mRetriesLeftPerErrorCode.put(errorCode, retriesLeft - 1);
4880d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                    result = false;
4890d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                }
4900d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt            }
4910d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt        }
4920d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt        String str = "ApnContext.restartOnError(" + errorCode + ") found " + retriesLeft +
4930d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt                " and returned " + result;
4940d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt        if (DBG) log(str);
4950d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt        requestLog(str);
4960d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt        return result;
4970d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt    }
4980d2abb5518d6a86619d2c2db04867c338b2092d4Robert Greenwalt
499ea763d93b231bccf7e476b625fa028bef7874bf8Robert Greenwalt    public int incAndGetConnectionGeneration() {
500ea763d93b231bccf7e476b625fa028bef7874bf8Robert Greenwalt        return mConnectionGeneration.incrementAndGet();
501ea763d93b231bccf7e476b625fa028bef7874bf8Robert Greenwalt    }
502ea763d93b231bccf7e476b625fa028bef7874bf8Robert Greenwalt
503ea763d93b231bccf7e476b625fa028bef7874bf8Robert Greenwalt    public int getConnectionGeneration() {
504ea763d93b231bccf7e476b625fa028bef7874bf8Robert Greenwalt        return mConnectionGeneration.get();
505ea763d93b231bccf7e476b625fa028bef7874bf8Robert Greenwalt    }
506ea763d93b231bccf7e476b625fa028bef7874bf8Robert Greenwalt
5070e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu    public long getInterApnDelay(boolean failFastEnabled) {
5080e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu        return mRetryManager.getInterApnDelay(failFastEnabled);
5090e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu    }
5100e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu
5116bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt    public static int apnIdForType(int networkType) {
5126bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt        switch (networkType) {
5136bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt        case ConnectivityManager.TYPE_MOBILE:
5146bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt            return DctConstants.APN_DEFAULT_ID;
5156bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt        case ConnectivityManager.TYPE_MOBILE_MMS:
5166bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt            return DctConstants.APN_MMS_ID;
5176bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt        case ConnectivityManager.TYPE_MOBILE_SUPL:
5186bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt            return DctConstants.APN_SUPL_ID;
5196bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt        case ConnectivityManager.TYPE_MOBILE_DUN:
5206bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt            return DctConstants.APN_DUN_ID;
5216bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt        case ConnectivityManager.TYPE_MOBILE_FOTA:
5226bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt            return DctConstants.APN_FOTA_ID;
5236bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt        case ConnectivityManager.TYPE_MOBILE_IMS:
5246bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt            return DctConstants.APN_IMS_ID;
5256bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt        case ConnectivityManager.TYPE_MOBILE_CBS:
5266bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt            return DctConstants.APN_CBS_ID;
5276bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt        case ConnectivityManager.TYPE_MOBILE_IA:
5286bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt            return DctConstants.APN_IA_ID;
5296bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt        case ConnectivityManager.TYPE_MOBILE_EMERGENCY:
5306bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt            return DctConstants.APN_EMERGENCY_ID;
5316bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt        default:
5326bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt            return DctConstants.APN_INVALID_ID;
5336bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt        }
5346bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt    }
5356bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt
536e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    public static int apnIdForNetworkRequest(NetworkRequest nr) {
537e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        NetworkCapabilities nc = nr.networkCapabilities;
538e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        // For now, ignore the bandwidth stuff
539e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (nc.getTransportTypes().length > 0 &&
540e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                nc.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) == false) {
541e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            return DctConstants.APN_INVALID_ID;
542e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
543e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
544e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        // in the near term just do 1-1 matches.
545e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        // TODO - actually try to match the set of capabilities
546e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        int apnId = DctConstants.APN_INVALID_ID;
547e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        boolean error = false;
548e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
549e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) {
550e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            apnId = DctConstants.APN_DEFAULT_ID;
551e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
552e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_MMS)) {
553e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            if (apnId != DctConstants.APN_INVALID_ID) error = true;
554e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            apnId = DctConstants.APN_MMS_ID;
555e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
556e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_SUPL)) {
557e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            if (apnId != DctConstants.APN_INVALID_ID) error = true;
558e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            apnId = DctConstants.APN_SUPL_ID;
559e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
560e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_DUN)) {
561e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            if (apnId != DctConstants.APN_INVALID_ID) error = true;
562e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            apnId = DctConstants.APN_DUN_ID;
563e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
564e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_FOTA)) {
565e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            if (apnId != DctConstants.APN_INVALID_ID) error = true;
566e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            apnId = DctConstants.APN_FOTA_ID;
567e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
568e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_IMS)) {
569e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            if (apnId != DctConstants.APN_INVALID_ID) error = true;
570e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            apnId = DctConstants.APN_IMS_ID;
571e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
572e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_CBS)) {
573e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            if (apnId != DctConstants.APN_INVALID_ID) error = true;
574e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            apnId = DctConstants.APN_CBS_ID;
575e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
576e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_IA)) {
577e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            if (apnId != DctConstants.APN_INVALID_ID) error = true;
578e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            apnId = DctConstants.APN_IA_ID;
579e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
580e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_RCS)) {
581e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            if (apnId != DctConstants.APN_INVALID_ID) error = true;
582e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
583e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            Rlog.d(SLOG_TAG, "RCS APN type not yet supported");
584e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
585e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_XCAP)) {
586e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            if (apnId != DctConstants.APN_INVALID_ID) error = true;
587e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
588e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            Rlog.d(SLOG_TAG, "XCAP APN type not yet supported");
589e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
590e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_EIMS)) {
591e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            if (apnId != DctConstants.APN_INVALID_ID) error = true;
592e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            apnId = DctConstants.APN_MMS_ID;
593e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
594e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (error) {
595e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            // TODO: If this error condition is removed, the framework's handling of
596e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            // NET_CAPABILITY_NOT_RESTRICTED will need to be updated so requests for
597e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            // say FOTA and INTERNET are marked as restricted.  This is not how
598e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            // NetworkCapabilities.maybeMarkCapabilitiesRestricted currently works.
599e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            Rlog.d(SLOG_TAG, "Multiple apn types specified in request - result is unspecified!");
600e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
601e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        if (apnId == DctConstants.APN_INVALID_ID) {
602e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            Rlog.d(SLOG_TAG, "Unsupported NetworkRequest in Telephony: nr=" + nr);
603e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
604e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        return apnId;
605e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    }
606e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
607e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    // TODO - kill The use of these strings
608e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    public static int apnIdForApnName(String type) {
609e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        switch (type) {
610e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            case PhoneConstants.APN_TYPE_DEFAULT:
611e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                return DctConstants.APN_DEFAULT_ID;
612e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            case PhoneConstants.APN_TYPE_MMS:
613e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                return DctConstants.APN_MMS_ID;
614e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            case PhoneConstants.APN_TYPE_SUPL:
615e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                return DctConstants.APN_SUPL_ID;
616e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            case PhoneConstants.APN_TYPE_DUN:
617e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                return DctConstants.APN_DUN_ID;
618e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            case PhoneConstants.APN_TYPE_HIPRI:
619e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                return DctConstants.APN_HIPRI_ID;
620e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            case PhoneConstants.APN_TYPE_IMS:
621e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                return DctConstants.APN_IMS_ID;
622e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            case PhoneConstants.APN_TYPE_FOTA:
623e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                return DctConstants.APN_FOTA_ID;
624e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            case PhoneConstants.APN_TYPE_CBS:
625e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                return DctConstants.APN_CBS_ID;
626e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            case PhoneConstants.APN_TYPE_IA:
627e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                return DctConstants.APN_IA_ID;
628e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            case PhoneConstants.APN_TYPE_EMERGENCY:
629e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                return DctConstants.APN_EMERGENCY_ID;
630e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            default:
631e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                return DctConstants.APN_INVALID_ID;
632e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
633e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    }
634e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
635e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    private static String apnNameForApnId(int id) {
636e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        switch (id) {
637e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            case DctConstants.APN_DEFAULT_ID:
638e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                return PhoneConstants.APN_TYPE_DEFAULT;
639e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            case DctConstants.APN_MMS_ID:
640e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                return PhoneConstants.APN_TYPE_MMS;
641e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            case DctConstants.APN_SUPL_ID:
642e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                return PhoneConstants.APN_TYPE_SUPL;
643e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            case DctConstants.APN_DUN_ID:
644e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                return PhoneConstants.APN_TYPE_DUN;
645e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            case DctConstants.APN_HIPRI_ID:
646e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                return PhoneConstants.APN_TYPE_HIPRI;
647e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            case DctConstants.APN_IMS_ID:
648e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                return PhoneConstants.APN_TYPE_IMS;
649e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            case DctConstants.APN_FOTA_ID:
650e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                return PhoneConstants.APN_TYPE_FOTA;
651e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            case DctConstants.APN_CBS_ID:
652e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                return PhoneConstants.APN_TYPE_CBS;
653e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            case DctConstants.APN_IA_ID:
654e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                return PhoneConstants.APN_TYPE_IA;
655e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            case DctConstants.APN_EMERGENCY_ID:
656e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                return PhoneConstants.APN_TYPE_EMERGENCY;
657e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            default:
658e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                Rlog.d(SLOG_TAG, "Unknown id (" + id + ") in apnIdToType");
659e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                return PhoneConstants.APN_TYPE_DEFAULT;
660e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        }
661e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    }
662e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
6630825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    @Override
6640f94d3aebcf0daf154bf0876164844d09067f904Wink Saville    public synchronized String toString() {
6650825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville        // We don't print mDataConnection because its recursive.
6662dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt        return "{mApnType=" + mApnType + " mState=" + getState() + " mWaitingApns={" +
6670e664d8c9ff3a1f2ab03d2bef4268615335ea1a2Jack Yu                mRetryManager.getWaitingApns() + "}" + " mApnSetting={" + mApnSetting +
6682dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt                "} mReason=" + mReason + " mDataEnabled=" + mDataEnabled + " mDependencyMet=" +
6692dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt                mDependencyMet + "}";
6700825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    }
6710825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
6722dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt    private void log(String s) {
67399c2e1d6749cfad2a8ca94a47857d8c3bfc09454Wink Saville        Rlog.d(LOG_TAG, "[ApnContext:" + mApnType + "] " + s);
6740825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    }
6750825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
67651f4bf7f29ffeaa60a8e7d4d1da7b30f20e8a420Robert Greenwalt    public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
67751f4bf7f29ffeaa60a8e7d4d1da7b30f20e8a420Robert Greenwalt        final IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, "  ");
67851f4bf7f29ffeaa60a8e7d4d1da7b30f20e8a420Robert Greenwalt        synchronized (mRefCountLock) {
67951f4bf7f29ffeaa60a8e7d4d1da7b30f20e8a420Robert Greenwalt            pw.println(toString());
6809521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt            pw.increaseIndent();
6819521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt            for (LocalLog l : mLocalLogs) {
6829521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt                l.dump(fd, pw, args);
6839521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt            }
6849521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt            if (mHistoryLogs.size() > 0) pw.println("Historical Logs:");
6859521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt            for (LocalLog l : mHistoryLogs) {
6869521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt                l.dump(fd, pw, args);
68751f4bf7f29ffeaa60a8e7d4d1da7b30f20e8a420Robert Greenwalt            }
6889521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt            pw.decreaseIndent();
6899521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt            pw.println("mRetryManager={" + mRetryManager.toString() + "}");
69051f4bf7f29ffeaa60a8e7d4d1da7b30f20e8a420Robert Greenwalt        }
6910825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    }
6920825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville}
693