DcAsyncChannel.java revision 608588e9af271f0f5640236809f27c626f9d98e9
10825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville/* 20825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Copyright (C) 2011 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 com.android.internal.telephony.dataconnection.DataConnection.ConnectionParams; 20ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Savilleimport com.android.internal.telephony.dataconnection.DataConnection.DisconnectParams; 210825495a331bb44df395a0cdb79fab85e68db5d5Wink Savilleimport com.android.internal.util.AsyncChannel; 220825495a331bb44df395a0cdb79fab85e68db5d5Wink Savilleimport com.android.internal.util.Protocol; 230825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 240825495a331bb44df395a0cdb79fab85e68db5d5Wink Savilleimport android.net.LinkProperties; 25608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwaltimport android.net.NetworkCapabilities; 269c180aedfc9f0d20525c0128487d3500e6c0a715Jason Monkimport android.net.ProxyInfo; 270825495a331bb44df395a0cdb79fab85e68db5d5Wink Savilleimport android.os.Message; 280825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 290825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville/** 300825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * AsyncChannel to a DataConnection 310825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 32454b1dfd508844b42eb775e4ab2359be74d3672bWink Savillepublic class DcAsyncChannel extends AsyncChannel { 330825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville private static final boolean DBG = false; 340825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville private String mLogTag; 350825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 36ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville private DataConnection mDc; 37ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville private long mDcThreadId; 380825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 390825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static final int BASE = Protocol.BASE_DATA_CONNECTION_AC; 400825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 410825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static final int REQ_IS_INACTIVE = BASE + 0; 420825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static final int RSP_IS_INACTIVE = BASE + 1; 430825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 440825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static final int REQ_GET_CID = BASE + 2; 450825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static final int RSP_GET_CID = BASE + 3; 460825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 470825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static final int REQ_GET_APNSETTING = BASE + 4; 480825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static final int RSP_GET_APNSETTING = BASE + 5; 490825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 500825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static final int REQ_GET_LINK_PROPERTIES = BASE + 6; 510825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static final int RSP_GET_LINK_PROPERTIES = BASE + 7; 520825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 530825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static final int REQ_SET_LINK_PROPERTIES_HTTP_PROXY = BASE + 8; 540825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static final int RSP_SET_LINK_PROPERTIES_HTTP_PROXY = BASE + 9; 550825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 56608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt public static final int REQ_GET_NETWORK_CAPABILITIES = BASE + 10; 57608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt public static final int RSP_GET_NETWORK_CAPABILITIES = BASE + 11; 58608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt 59608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt public static final int REQ_RESET = BASE + 12; 60608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt public static final int RSP_RESET = BASE + 13; 610825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 62ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville private static final int CMD_TO_STRING_COUNT = RSP_RESET - BASE + 1; 630825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville private static String[] sCmdToString = new String[CMD_TO_STRING_COUNT]; 640825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville static { 650825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville sCmdToString[REQ_IS_INACTIVE - BASE] = "REQ_IS_INACTIVE"; 660825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville sCmdToString[RSP_IS_INACTIVE - BASE] = "RSP_IS_INACTIVE"; 670825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville sCmdToString[REQ_GET_CID - BASE] = "REQ_GET_CID"; 680825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville sCmdToString[RSP_GET_CID - BASE] = "RSP_GET_CID"; 690825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville sCmdToString[REQ_GET_APNSETTING - BASE] = "REQ_GET_APNSETTING"; 700825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville sCmdToString[RSP_GET_APNSETTING - BASE] = "RSP_GET_APNSETTING"; 710825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville sCmdToString[REQ_GET_LINK_PROPERTIES - BASE] = "REQ_GET_LINK_PROPERTIES"; 720825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville sCmdToString[RSP_GET_LINK_PROPERTIES - BASE] = "RSP_GET_LINK_PROPERTIES"; 730825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville sCmdToString[REQ_SET_LINK_PROPERTIES_HTTP_PROXY - BASE] = 740825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville "REQ_SET_LINK_PROPERTIES_HTTP_PROXY"; 750825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville sCmdToString[RSP_SET_LINK_PROPERTIES_HTTP_PROXY - BASE] = 760825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville "RSP_SET_LINK_PROPERTIES_HTTP_PROXY"; 77608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt sCmdToString[REQ_GET_NETWORK_CAPABILITIES - BASE] = "REQ_GET_NETWORK_CAPABILITIES"; 78608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt sCmdToString[RSP_GET_NETWORK_CAPABILITIES - BASE] = "RSP_GET_NETWORK_CAPABILITIES"; 790825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville sCmdToString[REQ_RESET - BASE] = "REQ_RESET"; 800825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville sCmdToString[RSP_RESET - BASE] = "RSP_RESET"; 810825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 82ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville 83ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville // Convert cmd to string or null if unknown 840825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville protected static String cmdToString(int cmd) { 850825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville cmd -= BASE; 860825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville if ((cmd >= 0) && (cmd < sCmdToString.length)) { 870825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return sCmdToString[cmd]; 880825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } else { 890825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return AsyncChannel.cmdToString(cmd + BASE); 900825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 910825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 920825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 930825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 940825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * enum used to notify action taken or necessary to be 950825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * taken after the link property is changed. 960825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 970825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public enum LinkPropertyChangeAction { 980825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville NONE, CHANGED, RESET; 990825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 1000825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static LinkPropertyChangeAction fromInt(int value) { 1010825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville if (value == NONE.ordinal()) { 1020825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return NONE; 1030825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } else if (value == CHANGED.ordinal()) { 1040825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return CHANGED; 1050825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } else if (value == RESET.ordinal()) { 1060825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return RESET; 1070825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } else { 1080825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville throw new RuntimeException("LinkPropertyChangeAction.fromInt: bad value=" + value); 1090825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 1100825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 1110825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 1120825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 113454b1dfd508844b42eb775e4ab2359be74d3672bWink Saville public DcAsyncChannel(DataConnection dc, String logTag) { 114ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville mDc = dc; 115ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville mDcThreadId = mDc.getHandler().getLooper().getThread().getId(); 1160825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville mLogTag = logTag; 1170825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 1180825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 1190825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 1200825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Request if the state machine is in the inactive state. 1210825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Response {@link #rspIsInactive} 1220825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 1230825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public void reqIsInactive() { 1240825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville sendMessage(REQ_IS_INACTIVE); 1250825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville if (DBG) log("reqIsInactive"); 1260825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 1270825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 1280825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 1290825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Evaluate RSP_IS_INACTIVE. 1300825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 1310825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @return true if the state machine is in the inactive state. 1320825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 1330825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public boolean rspIsInactive(Message response) { 1340825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville boolean retVal = response.arg1 == 1; 1350825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville if (DBG) log("rspIsInactive=" + retVal); 1360825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return retVal; 1370825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 1380825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 1390825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 140ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville * @return true if the state machine is in the inactive state 141ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville * and can be used for a new connection. 1420825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 1430825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public boolean isInactiveSync() { 144ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville boolean value; 145ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville if (isCallerOnDifferentThread()) { 146ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville Message response = sendMessageSynchronously(REQ_IS_INACTIVE); 147ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville if ((response != null) && (response.what == RSP_IS_INACTIVE)) { 148ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville value = rspIsInactive(response); 149ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville } else { 150ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville log("rspIsInactive error response=" + response); 151ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville value = false; 152ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville } 1530825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } else { 154ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville value = mDc.getIsInactive(); 1550825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 156ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville return value; 1570825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 1580825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 1590825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 1600825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Request the Connection ID. 1610825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Response {@link #rspCid} 1620825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 1630825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public void reqCid() { 1640825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville sendMessage(REQ_GET_CID); 1650825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville if (DBG) log("reqCid"); 1660825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 1670825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 1680825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 1690825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Evaluate a RSP_GET_CID message and return the cid. 1700825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 1710825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @param response Message 1720825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @return connection id or -1 if an error 1730825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 1740825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public int rspCid(Message response) { 1750825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville int retVal = response.arg1; 1760825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville if (DBG) log("rspCid=" + retVal); 1770825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return retVal; 1780825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 1790825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 1800825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 1810825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @return connection id or -1 if an error 1820825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 1830825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public int getCidSync() { 184ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville int value; 185ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville if (isCallerOnDifferentThread()) { 186ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville Message response = sendMessageSynchronously(REQ_GET_CID); 187ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville if ((response != null) && (response.what == RSP_GET_CID)) { 188ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville value = rspCid(response); 189ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville } else { 190ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville log("rspCid error response=" + response); 191ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville value = -1; 192ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville } 1930825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } else { 194ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville value = mDc.getCid(); 1950825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 196ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville return value; 1970825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 1980825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 1990825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 2000825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Request the connections ApnSetting. 2010825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Response {@link #rspApnSetting} 2020825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 2030825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public void reqApnSetting() { 2040825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville sendMessage(REQ_GET_APNSETTING); 2050825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville if (DBG) log("reqApnSetting"); 2060825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 2070825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 2080825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 2090825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Evaluate a RSP_APN_SETTING message and return the ApnSetting. 2100825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 2110825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @param response Message 2120825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @return ApnSetting, maybe null 2130825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 2140825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public ApnSetting rspApnSetting(Message response) { 2150825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville ApnSetting retVal = (ApnSetting) response.obj; 2160825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville if (DBG) log("rspApnSetting=" + retVal); 2170825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return retVal; 2180825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 2190825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 2200825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 2210825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Get the connections ApnSetting. 2220825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 2230825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @return ApnSetting or null if an error 2240825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 2250825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public ApnSetting getApnSettingSync() { 226ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville ApnSetting value; 227ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville if (isCallerOnDifferentThread()) { 228ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville Message response = sendMessageSynchronously(REQ_GET_APNSETTING); 229ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville if ((response != null) && (response.what == RSP_GET_APNSETTING)) { 230ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville value = rspApnSetting(response); 231ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville } else { 232ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville log("getApnSetting error response=" + response); 233ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville value = null; 234ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville } 2350825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } else { 236ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville value = mDc.getApnSetting(); 2370825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 238ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville return value; 2390825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 2400825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 2410825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 2420825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Request the connections LinkProperties. 2430825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Response {@link #rspLinkProperties} 2440825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 2450825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public void reqLinkProperties() { 2460825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville sendMessage(REQ_GET_LINK_PROPERTIES); 2470825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville if (DBG) log("reqLinkProperties"); 2480825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 2490825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 2500825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 2510825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Evaluate RSP_GET_LINK_PROPERTIES 2520825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 2530825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @param response 2540825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @return LinkProperties, maybe null. 2550825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 2560825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public LinkProperties rspLinkProperties(Message response) { 2570825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville LinkProperties retVal = (LinkProperties) response.obj; 2580825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville if (DBG) log("rspLinkProperties=" + retVal); 2590825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return retVal; 2600825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 2610825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 2620825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 2630825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Get the connections LinkProperties. 2640825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 2650825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @return LinkProperties or null if an error 2660825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 2670825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public LinkProperties getLinkPropertiesSync() { 268ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville LinkProperties value; 269ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville if (isCallerOnDifferentThread()) { 270ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville Message response = sendMessageSynchronously(REQ_GET_LINK_PROPERTIES); 271ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville if ((response != null) && (response.what == RSP_GET_LINK_PROPERTIES)) { 272ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville value = rspLinkProperties(response); 273ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville } else { 274ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville log("getLinkProperties error response=" + response); 275ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville value = null; 276ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville } 2770825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } else { 278ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville value = mDc.getCopyLinkProperties(); 2790825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 280ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville return value; 2810825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 2820825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 2830825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 2840825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Request setting the connections LinkProperties.HttpProxy. 2850825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Response RSP_SET_LINK_PROPERTIES when complete. 2860825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 2879c180aedfc9f0d20525c0128487d3500e6c0a715Jason Monk public void reqSetLinkPropertiesHttpProxy(ProxyInfo proxy) { 2880825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville sendMessage(REQ_SET_LINK_PROPERTIES_HTTP_PROXY, proxy); 2890825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville if (DBG) log("reqSetLinkPropertiesHttpProxy proxy=" + proxy); 2900825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 2910825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 2920825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 2930825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Set the connections LinkProperties.HttpProxy 2940825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 2959c180aedfc9f0d20525c0128487d3500e6c0a715Jason Monk public void setLinkPropertiesHttpProxySync(ProxyInfo proxy) { 296ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville if (isCallerOnDifferentThread()) { 297ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville Message response = 298ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville sendMessageSynchronously(REQ_SET_LINK_PROPERTIES_HTTP_PROXY, proxy); 299ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville if ((response != null) && (response.what == RSP_SET_LINK_PROPERTIES_HTTP_PROXY)) { 300ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville if (DBG) log("setLinkPropertiesHttpPoxy ok"); 301ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville } else { 302ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville log("setLinkPropertiesHttpPoxy error response=" + response); 303ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville } 3040825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } else { 305ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville mDc.setLinkPropertiesHttpProxy(proxy); 3060825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 3070825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 3080825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 3090825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 310608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt * Request the connections NetworkCapabilities. 311608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt * Response {@link #rspNetworkCapabilities} 312608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt */ 313608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt public void reqNetworkCapabilities() { 314608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt sendMessage(REQ_GET_NETWORK_CAPABILITIES); 315608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt if (DBG) log("reqNetworkCapabilities"); 316608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt } 317608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt 318608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt /** 319608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt * Evaluate RSP_GET_NETWORK_CAPABILITIES 320608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt * 321608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt * @param response 322608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt * @return NetworkCapabilites, maybe null. 323608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt */ 324608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt public NetworkCapabilities rspNetworkCapabilities(Message response) { 325608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt NetworkCapabilities retVal = (NetworkCapabilities) response.obj; 326608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt if (DBG) log("rspNetworkCapabilities=" + retVal); 327608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt return retVal; 328608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt } 329608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt 330608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt /** 331608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt * Get the connections NetworkCapabilities. 332608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt * 333608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt * @return NetworkCapabilities or null if an error 334608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt */ 335608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt public NetworkCapabilities getNetworkCapabilitiesSync() { 336608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt NetworkCapabilities value; 337608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt if (isCallerOnDifferentThread()) { 338608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt Message response = sendMessageSynchronously(REQ_GET_NETWORK_CAPABILITIES); 339608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt if ((response != null) && (response.what == RSP_GET_NETWORK_CAPABILITIES)) { 340608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt value = rspNetworkCapabilities(response); 341608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt } else { 342608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt value = null; 343608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt } 344608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt } else { 345608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt value = mDc.getCopyNetworkCapabilities(); 346608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt } 347608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt return value; 348608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt } 349608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt 350608588e9af271f0f5640236809f27c626f9d98e9Robert Greenwalt /** 3510825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Response RSP_RESET when complete 3520825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 3530825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public void reqReset() { 3540825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville sendMessage(REQ_RESET); 3550825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville if (DBG) log("reqReset"); 3560825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 3570825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 3580825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 359ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville * Bring up a connection to the apn and return an AsyncResult in onCompletedMsg. 360ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville * Used for cellular networks that use Acesss Point Names (APN) such 361ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville * as GSM networks. 3620825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 363ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville * @param apnContext is the Access Point Name to bring up a connection to 364ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville * @param initialMaxRetry the number of retires for initial bringup. 365ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville * @param profileId for the conneciton 366ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville * @param onCompletedMsg is sent with its msg.obj as an AsyncResult object. 367ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville * With AsyncResult.userObj set to the original msg.obj, 368ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville * AsyncResult.result = FailCause and AsyncResult.exception = Exception(). 369ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville */ 370ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville public void bringUp(ApnContext apnContext, int initialMaxRetry, int profileId, 371203e588e3c42a81aa8a56f595119c181a63b12caWink Saville int rilRadioTechnology, Message onCompletedMsg) { 372ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville if (DBG) { 373ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville log("bringUp: apnContext=" + apnContext + " initialMaxRetry=" + initialMaxRetry 374ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville + " onCompletedMsg=" + onCompletedMsg); 3750825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 376ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville sendMessage(DataConnection.EVENT_CONNECT, 377203e588e3c42a81aa8a56f595119c181a63b12caWink Saville new ConnectionParams(apnContext, initialMaxRetry, profileId, 378203e588e3c42a81aa8a56f595119c181a63b12caWink Saville rilRadioTechnology, onCompletedMsg)); 3790825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 3800825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 3810825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 382ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville * Tear down the connection through the apn on the network. 3830825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 384ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville * @param onCompletedMsg is sent with its msg.obj as an AsyncResult object. 385ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville * With AsyncResult.userObj set to the original msg.obj. 3860825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 387ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville public void tearDown(ApnContext apnContext, String reason, Message onCompletedMsg) { 388ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville if (DBG) { 389ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville log("tearDown: apnContext=" + apnContext 390ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville + " reason=" + reason + " onCompletedMsg=" + onCompletedMsg); 3910825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 392ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville sendMessage(DataConnection.EVENT_DISCONNECT, 393ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville new DisconnectParams(apnContext, reason, onCompletedMsg)); 3940825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 3950825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 3960825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 397ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville * Tear down the connection through the apn on the network. Ignores refcount and 398ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville * and always tears down. 3990825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 400ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville * @param onCompletedMsg is sent with its msg.obj as an AsyncResult object. 401ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville * With AsyncResult.userObj set to the original msg.obj. 4020825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 403ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville public void tearDownAll(String reason, Message onCompletedMsg) { 404ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville if (DBG) log("tearDownAll: reason=" + reason + " onCompletedMsg=" + onCompletedMsg); 405ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville sendMessage(DataConnection.EVENT_DISCONNECT_ALL, 406ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville new DisconnectParams(null, reason, onCompletedMsg)); 4070825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 4080825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 4090825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 410ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville * @return connection id 4110825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 412ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville public int getDataConnectionIdSync() { 413ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville // Safe because this is owned by the caller. 414ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville return mDc.getDataConnectionId(); 4150825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 4160825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 4170825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville @Override 4180825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public String toString() { 419ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville return mDc.getName(); 420ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville } 421ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville 422ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville private boolean isCallerOnDifferentThread() { 423ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville long curThreadId = Thread.currentThread().getId(); 424ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville boolean value = mDcThreadId != curThreadId; 425ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville if (DBG) log("isCallerOnDifferentThread: " + value); 426ff4e317d24f0d23bdc0f306d53ddc51f2f1ecf6aWink Saville return value; 4270825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 4280825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 4290825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville private void log(String s) { 43099c2e1d6749cfad2a8ca94a47857d8c3bfc09454Wink Saville android.telephony.Rlog.d(mLogTag, "DataConnectionAc " + s); 4310825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 4320825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville} 433