Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d8711672 authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change 21581 into eclair

* changes:
  Fix CDMA to startup/shutdown based on apn en/disab
parents 736c24a8 25a5d3db
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -49,7 +49,6 @@ public class MobileDataStateTracker extends NetworkStateTracker {

    private String mApnType;
    private boolean mEnabled;
    private boolean mTeardownRequested;

    /**
     * Create a new MobileDataStateTracker
@@ -66,7 +65,6 @@ public class MobileDataStateTracker extends NetworkStateTracker {
                TelephonyManager.getDefault().getNetworkTypeName());
        mApnType = apnType;
        mPhoneService = null;
        mTeardownRequested = false;
        if(netType == ConnectivityManager.TYPE_MOBILE) {
            mEnabled = true;
        } else {
@@ -81,7 +79,9 @@ public class MobileDataStateTracker extends NetworkStateTracker {
                "net.eth0.dns3",
                "net.eth0.dns4",
                "net.gprs.dns1",
                "net.gprs.dns2"};
                "net.gprs.dns2",
                "net.ppp0.dns1",
                "net.ppp0.dns2"};

    }

@@ -160,9 +160,9 @@ public class MobileDataStateTracker extends NetworkStateTracker {

                    switch (state) {
                    case DISCONNECTED:
                        if(mTeardownRequested) {
                        if(isTeardownRequested()) {
                            mEnabled = false;
                            mTeardownRequested = false;
                            setTeardownRequested(false);
                        }

                        setDetailedState(DetailedState.DISCONNECTED, reason, apnName);
@@ -277,7 +277,7 @@ public class MobileDataStateTracker extends NetworkStateTracker {
     */
    @Override
    public boolean teardown() {
        mTeardownRequested = true;
        setTeardownRequested(true);
        return (setEnableApn(mApnType, false) != Phone.APN_REQUEST_FAILED);
    }

@@ -286,7 +286,7 @@ public class MobileDataStateTracker extends NetworkStateTracker {
     */
    public boolean reconnect() {
        mEnabled = true;
        mTeardownRequested = false;
        setTeardownRequested(false);
        mEnabled = (setEnableApn(mApnType, true) !=
                Phone.APN_REQUEST_FAILED);
        return mEnabled;
+2 −1
Original line number Diff line number Diff line
@@ -1428,7 +1428,8 @@ public class ListView extends AbsListView {
                throw new IllegalStateException("The content of the adapter has changed but "
                        + "ListView did not receive a notification. Make sure the content of "
                        + "your adapter is not modified from a background thread, but only "
                        + "from the UI thread.");
                        + "from the UI thread. [in ListView(" + getId() + ", " + getClass() 
                        + ") with Adapter(" + mAdapter.getClass() + ")]");
            }

            setSelectedPositionInt(mNextSelectedPosition);
+182 −10
Original line number Diff line number Diff line
@@ -24,14 +24,18 @@ import android.os.Message;
import android.os.RemoteException;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.text.TextUtils;
import android.util.Log;

import java.util.ArrayList;

/**
 * {@hide}
 *
 */
public abstract class DataConnectionTracker extends Handler {
    private static final boolean DBG = true;
    protected static final boolean DBG = true;
    protected final String LOG_TAG = "DataConnectionTracker";

    /**
     * IDLE: ready to start data connection setup, default state
@@ -98,6 +102,20 @@ public abstract class DataConnectionTracker extends Handler {

    //***** Constants

    protected static final int APN_INVALID_ID = -1;
    protected static final int APN_DEFAULT_ID = 0;
    protected static final int APN_MMS_ID = 1;
    protected static final int APN_SUPL_ID = 2;
    protected static final int APN_DUN_ID = 3;
    protected static final int APN_HIPRI_ID = 4;
    protected static final int APN_NUM_TYPES = 5;

    protected boolean[] dataEnabled = new boolean[APN_NUM_TYPES];
    protected int enabledCount = 0;

    /* Currently requested APN type */
    protected String mRequestedApnType = Phone.APN_TYPE_DEFAULT;

    /** Retry configuration: A doubling of retry times from 5secs to 30minutes */
    protected static final String DEFAULT_DATA_RETRY_CONFIG = "default_randomization=2000,"
        + "5000,10000,20000,40000,80000:5000,160000:5000,"
@@ -167,6 +185,8 @@ public abstract class DataConnectionTracker extends Handler {
        this.phone = phone;
    }

    public abstract void dispose();

    public Activity getActivity() {
        return activity;
    }
@@ -301,30 +321,182 @@ public abstract class DataConnectionTracker extends Handler {
     * @return {@code false} if data connectivity has been explicitly disabled,
     * {@code true} otherwise.
     */
    public abstract boolean getDataEnabled();
    public boolean getDataEnabled() {
        return dataEnabled[APN_DEFAULT_ID];
    }

    /**
     * Report on whether data connectivity is enabled
     * @return {@code false} if data connectivity has been explicitly disabled,
     * {@code true} otherwise.
     */
    public abstract boolean getAnyDataEnabled();
    public boolean getAnyDataEnabled() {
        return (enabledCount != 0);
    }

    protected abstract void startNetStatPoll();

    protected abstract void stopNetStatPoll();

    protected abstract void restartRadio();

    protected abstract void log(String s);

    protected int apnTypeToId(String type) {
        if (TextUtils.equals(type, Phone.APN_TYPE_DEFAULT)) {
            return APN_DEFAULT_ID;
        } else if (TextUtils.equals(type, Phone.APN_TYPE_MMS)) {
            return APN_MMS_ID;
        } else if (TextUtils.equals(type, Phone.APN_TYPE_SUPL)) {
            return APN_SUPL_ID;
        } else if (TextUtils.equals(type, Phone.APN_TYPE_DUN)) {
            return APN_DUN_ID;
        } else if (TextUtils.equals(type, Phone.APN_TYPE_HIPRI)) {
            return APN_HIPRI_ID;
        } else {
            return APN_INVALID_ID;
        }
    }

    protected abstract boolean isApnTypeActive(String type);

    protected abstract boolean isApnTypeAvailable(String type);

    protected abstract String[] getActiveApnTypes();

    protected abstract String getActiveApnString();

    public abstract ArrayList<DataConnection> getAllDataConnections();

    protected abstract String getInterfaceName(String apnType);

    protected abstract String getIpAddress(String apnType);

    protected abstract String getGateway(String apnType);

    protected abstract String[] getDnsServers(String apnType);

    protected abstract void setState(State s);

    protected boolean isEnabled(int id) {
        if (id != APN_INVALID_ID) {
            return dataEnabled[id];
        }
        return false;
    }

    /**
     * Ensure that we are connected to an APN of the specified type.
     * @param type the APN type (currently the only valid values
     * are {@link Phone#APN_TYPE_MMS} and {@link Phone#APN_TYPE_SUPL})
     * @return the result of the operation. Success is indicated by
     * a return value of either {@code Phone.APN_ALREADY_ACTIVE} or
     * {@code Phone.APN_REQUEST_STARTED}. In the latter case, a broadcast
     * will be sent by the ConnectivityManager when a connection to
     * the APN has been established.
     */
    public int enableApnType(String type) {
        int id = apnTypeToId(type);
        if (id == APN_INVALID_ID) {
            return Phone.APN_REQUEST_FAILED;
        }

        // If already active, return
        if(DBG) Log.d(LOG_TAG, "enableApnType("+type+"), isApnTypeActive = "
                + isApnTypeActive(type) + " and state = " + state);

        if (isApnTypeActive(type)) {
            if (state == State.INITING) return Phone.APN_REQUEST_STARTED;
            else if (state == State.CONNECTED) return Phone.APN_ALREADY_ACTIVE;
        }

        if (!isApnTypeAvailable(type)) {
            return Phone.APN_TYPE_NOT_AVAILABLE;
        }

        setEnabled(id, true);
        mRequestedApnType = type;
        sendMessage(obtainMessage(EVENT_ENABLE_NEW_APN));
        return Phone.APN_REQUEST_STARTED;
    }

    /**
     * The APN of the specified type is no longer needed. Ensure that if
     * use of the default APN has not been explicitly disabled, we are connected
     * to the default APN.
     * @param type the APN type. The only valid values are currently
     * {@link Phone#APN_TYPE_MMS} and {@link Phone#APN_TYPE_SUPL}.
     * @return
     */
    public int disableApnType(String type) {
        if (DBG) Log.d(LOG_TAG, "disableApnType("+type+")");
        int id = apnTypeToId(type);
        if (id == APN_INVALID_ID) {
            return Phone.APN_REQUEST_FAILED;
        }
        if (isEnabled(id)) {
            setEnabled(id, false);
            if (isApnTypeActive(Phone.APN_TYPE_DEFAULT)) {
                mRequestedApnType = Phone.APN_TYPE_DEFAULT;
                if (dataEnabled[APN_DEFAULT_ID]) {
                    return Phone.APN_ALREADY_ACTIVE;
                } else {
                    return Phone.APN_REQUEST_STARTED;
                }
            } else {
                return Phone.APN_REQUEST_STARTED;
            }
        } else {
            return Phone.APN_REQUEST_FAILED;
        }
    }

    protected synchronized void setEnabled(int id, boolean enable) {
        if (DBG) Log.d(LOG_TAG, "setEnabled(" + id + ", " + enable + ')');
        if (dataEnabled[id] != enable) {
            dataEnabled[id] = enable;

            if (enable) {
                enabledCount++;
            } else {
                enabledCount--;
            }

            if (enabledCount == 0) {
                setPrivateDataEnabled(false);
            } else if (enabledCount == 1) {
                setPrivateDataEnabled(true);
            }
        }
    }

    /**
     * Prevent mobile data connections from being established,
     * or once again allow mobile data connections. If the state
     * toggles, then either tear down or set up data, as
     * appropriate to match the new state.
     * <p>This operation only affects the default APN, and if the same APN is
     * currently being used for MMS traffic, the teardown will not happen
     * even when {@code enable} is {@code false}.</p>
     * @param enable indicates whether to enable ({@code true}) or disable ({@code false}) data
     * @return {@code true} if the operation succeeded
     */
    public abstract boolean setDataEnabled(boolean enable);

    protected abstract void startNetStatPoll();

    protected abstract void stopNetStatPoll();
    public boolean setDataEnabled(boolean enable) {
        if (DBG) Log.d(LOG_TAG, "setDataEnabled("+enable+")");
        setEnabled(APN_DEFAULT_ID, enable);
        return true;
    }

    protected abstract void restartRadio();
    private void setPrivateDataEnabled(boolean enable) {
        if (DBG) Log.d(LOG_TAG, "setPrivateDataEnabled("+enable+")");
        if (enable) {
            sendMessage(obtainMessage(EVENT_TRY_SETUP_DATA));
        } else {
            Message msg = obtainMessage(EVENT_CLEAN_UP_CONNECTION);
            msg.arg1 = 1; // tearDown is true
            msg.obj = Phone.REASON_DATA_DISABLED;
            sendMessage(msg);
        }
    }

    protected abstract void log(String s);
}
+68 −0
Original line number Diff line number Diff line
@@ -109,6 +109,7 @@ public abstract class PhoneBase implements Phone {
    public CommandsInterface mCM;
    protected IccFileHandler mIccFileHandler;
    boolean mDnsCheckDisabled = false;
    public DataConnectionTracker mDataConnection;

    /**
     * Set a system property, unless we're in unit test mode
@@ -824,4 +825,71 @@ public abstract class PhoneBase implements Phone {
        // This function should be overridden by the class CDMAPhone. Not implemented in GSMPhone.
         Log.e(LOG_TAG, "Error! This function should never be executed, inactive CDMAPhone.");
     }

    public String getInterfaceName(String apnType) {
        return mDataConnection.getInterfaceName(apnType);
    }

    public String getIpAddress(String apnType) {
        return mDataConnection.getIpAddress(apnType);
    }

    public boolean isDataConnectivityEnabled() {
        return mDataConnection.getDataEnabled();
    }

    public String getGateway(String apnType) {
        return mDataConnection.getGateway(apnType);
    }

    public String[] getDnsServers(String apnType) {
        return mDataConnection.getDnsServers(apnType);
    }

    public String[] getActiveApnTypes() {
        return mDataConnection.getActiveApnTypes();
    }

    public String getActiveApn() {
        return mDataConnection.getActiveApnString();
    }

    public int enableApnType(String type) {
        return mDataConnection.enableApnType(type);
    }

    public int disableApnType(String type) {
        return mDataConnection.disableApnType(type);
    }

    /**
     * simulateDataConnection
     *
     * simulates various data connection states. This messes with
     * DataConnectionTracker's internal states, but doesn't actually change
     * the underlying radio connection states.
     *
     * @param state Phone.DataState enum.
     */
    public void simulateDataConnection(Phone.DataState state) {
        DataConnectionTracker.State dcState;

        switch (state) {
            case CONNECTED:
                dcState = DataConnectionTracker.State.CONNECTED;
                break;
            case SUSPENDED:
                dcState = DataConnectionTracker.State.CONNECTED;
                break;
            case DISCONNECTED:
                dcState = DataConnectionTracker.State.FAILED;
                break;
            default:
                dcState = DataConnectionTracker.State.CONNECTING;
                break;
        }

        mDataConnection.setState(dcState);
        notifyDataConnection(null);
    }
}
+0 −56
Original line number Diff line number Diff line
@@ -95,7 +95,6 @@ public class CDMAPhone extends PhoneBase {
    CdmaCallTracker mCT;
    CdmaSMSDispatcher mSMS;
    CdmaServiceStateTracker mSST;
    CdmaDataConnectionTracker mDataConnection;
    RuimFileHandler mRuimFileHandler;
    RuimRecords mRuimRecords;
    RuimCard mRuimCard;
@@ -369,42 +368,11 @@ public class CDMAPhone extends PhoneBase {
        return mCT.backgroundCall;
    }

    public String getGateway(String apnType) {
        return mDataConnection.getGateway();
    }

    public boolean handleInCallMmiCommands(String dialString) {
        Log.e(LOG_TAG, "method handleInCallMmiCommands is NOT supported in CDMA!");
        return false;
    }

    public int enableApnType(String type) {
        // This request is mainly used to enable MMS APN
        // In CDMA there is no need to enable/disable a different APN for MMS
        Log.d(LOG_TAG, "Request to enableApnType("+type+")");
        if (TextUtils.equals(type, Phone.APN_TYPE_MMS)) {
            return Phone.APN_ALREADY_ACTIVE;
        } else {
            return Phone.APN_REQUEST_FAILED;
        }
    }

    public int disableApnType(String type) {
        // This request is mainly used to disable MMS APN
        // In CDMA there is no need to enable/disable a different APN for MMS
        Log.d(LOG_TAG, "Request to disableApnType("+type+")");
        if (TextUtils.equals(type, Phone.APN_TYPE_MMS)) {
            return Phone.APN_REQUEST_STARTED;
        } else {
            return Phone.APN_REQUEST_FAILED;
        }
    }

    public String getActiveApn() {
        Log.d(LOG_TAG, "Request to getActiveApn()");
        return null;
    }

    public void
    setNetworkSelectionModeAutomatic(Message response) {
        Log.e(LOG_TAG, "method setNetworkSelectionModeAutomatic is NOT supported in CDMA!");
@@ -481,10 +449,6 @@ public class CDMAPhone extends PhoneBase {
        return false;
    }

    public String getInterfaceName(String apnType) {
        return mDataConnection.getInterfaceName();
    }

    public CellLocation getCellLocation() {
        return mSST.cellLoc;
    }
@@ -512,10 +476,6 @@ public class CDMAPhone extends PhoneBase {
        return false;
    }

    public boolean isDataConnectivityEnabled() {
        return mDataConnection.getDataEnabled();
    }

    public boolean isDataConnectivityPossible() {
        boolean noData = mDataConnection.getDataEnabled() &&
                getDataConnectionState() == DataState.DISCONNECTED;
@@ -528,10 +488,6 @@ public class CDMAPhone extends PhoneBase {
        Log.e(LOG_TAG, "setLine1Number: not possible in CDMA");
    }

    public String[] getDnsServers(String apnType) {
        return mDataConnection.getDnsServers();
    }

    public IccCard getIccCard() {
        return mRuimCard;
    }
@@ -584,10 +540,6 @@ public class CDMAPhone extends PhoneBase {
        mCT.unregisterForCallWaiting(h);
    }

    public String getIpAddress(String apnType) {
        return mDataConnection.getIpAddress();
    }

    public void
    getNeighboringCids(Message response) {
        /*
@@ -701,14 +653,6 @@ public class CDMAPhone extends PhoneBase {
        Log.e(LOG_TAG, "getAvailableNetworks: not possible in CDMA");
    }

    public String[] getActiveApnTypes() {
        String[] result;
        Log.d(LOG_TAG, "Request to getActiveApn()");
        result = new String[1];
        result[0] = Phone.APN_TYPE_DEFAULT;
        return result;
    }

    public void setOutgoingCallerIdDisplay(int commandInterfaceCLIRMode, Message onComplete) {
        Log.e(LOG_TAG, "setOutgoingCallerIdDisplay: not possible in CDMA");
    }
Loading