DataConnectionAc.java revision 01758e81b3ad89934581885bb2fc7006510ec639
1/* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.internal.telephony; 18 19import com.android.internal.util.AsyncChannel; 20import com.android.internal.util.Protocol; 21 22import android.net.LinkCapabilities; 23import android.net.LinkProperties; 24import android.net.ProxyProperties; 25import android.os.Message; 26 27/** 28 * AsyncChannel to a DataConnection 29 */ 30public class DataConnectionAc extends AsyncChannel { 31 private static final boolean DBG = true; 32 private String mLogTag; 33 34 public DataConnection dataConnection; 35 36 public static final int BASE = Protocol.BASE_DATA_CONNECTION_AC; 37 38 public static final int REQ_IS_INACTIVE = BASE + 0; 39 public static final int RSP_IS_INACTIVE = BASE + 1; 40 41 public static final int REQ_GET_CID = BASE + 2; 42 public static final int RSP_GET_CID = BASE + 3; 43 44 public static final int REQ_GET_APNSETTING = BASE + 4; 45 public static final int RSP_GET_APNSETTING = BASE + 5; 46 47 public static final int REQ_GET_LINK_PROPERTIES = BASE + 6; 48 public static final int RSP_GET_LINK_PROPERTIES = BASE + 7; 49 50 public static final int REQ_SET_LINK_PROPERTIES_HTTP_PROXY = BASE + 8; 51 public static final int RSP_SET_LINK_PROPERTIES_HTTP_PROXY = BASE + 9; 52 53 public static final int REQ_GET_LINK_CAPABILITIES = BASE + 10; 54 public static final int RSP_GET_LINK_CAPABILITIES = BASE + 11; 55 56 public static final int REQ_UPDATE_LINK_PROPERTIES_DATA_CALL_STATE = BASE + 12; 57 public static final int RSP_UPDATE_LINK_PROPERTIES_DATA_CALL_STATE = BASE + 13; 58 59 public static final int REQ_RESET = BASE + 14; 60 public static final int RSP_RESET = BASE + 15; 61 62 public DataConnectionAc(DataConnection dc, String logTag) { 63 dataConnection = dc; 64 mLogTag = logTag; 65 } 66 67 /** 68 * Request if the state machine is in the inactive state. 69 * Response {@link #rspIsInactive} 70 */ 71 public void reqIsInactive() { 72 sendMessage(REQ_IS_INACTIVE); 73 if (DBG) log("reqIsInactive"); 74 } 75 76 /** 77 * Evaluate RSP_IS_INACTIVE. 78 * 79 * @return true if the state machine is in the inactive state. 80 */ 81 public boolean rspIsInactive(Message response) { 82 boolean retVal = response.arg1 == 1; 83 if (DBG) log("rspIsInactive=" + retVal); 84 return retVal; 85 } 86 87 /** 88 * @return true if the state machine is in the inactive state. 89 */ 90 public boolean isInactiveSync() { 91 Message response = sendMessageSynchronously(REQ_IS_INACTIVE); 92 if ((response != null) && (response.what == RSP_IS_INACTIVE)) { 93 return rspIsInactive(response); 94 } else { 95 log("rspIsInactive error response=" + response); 96 return false; 97 } 98 } 99 100 /** 101 * Request the Connection ID. 102 * Response {@link #rspCid} 103 */ 104 public void reqCid() { 105 sendMessage(REQ_GET_CID); 106 if (DBG) log("reqCid"); 107 } 108 109 /** 110 * Evaluate a RSP_GET_CID message and return the cid. 111 * 112 * @param response Message 113 * @return connection id or -1 if an error 114 */ 115 public int rspCid(Message response) { 116 int retVal = response.arg1; 117 if (DBG) log("rspCid=" + retVal); 118 return retVal; 119 } 120 121 /** 122 * @return connection id or -1 if an error 123 */ 124 public int getCidSync() { 125 Message response = sendMessageSynchronously(REQ_GET_CID); 126 if ((response != null) && (response.what == RSP_GET_CID)) { 127 return rspCid(response); 128 } else { 129 log("rspCid error response=" + response); 130 return -1; 131 } 132 } 133 134 /** 135 * Request the connections ApnSetting. 136 * Response {@link #rspApnSetting} 137 */ 138 public void reqApnSetting() { 139 sendMessage(REQ_GET_APNSETTING); 140 if (DBG) log("reqApnSetting"); 141 } 142 143 /** 144 * Evaluate a RSP_APN_SETTING message and return the ApnSetting. 145 * 146 * @param response Message 147 * @return ApnSetting, maybe null 148 */ 149 public ApnSetting rspApnSetting(Message response) { 150 ApnSetting retVal = (ApnSetting) response.obj; 151 if (DBG) log("rspApnSetting=" + retVal); 152 return retVal; 153 } 154 155 /** 156 * Get the connections ApnSetting. 157 * 158 * @return ApnSetting or null if an error 159 */ 160 public ApnSetting getApnSettingSync() { 161 Message response = sendMessageSynchronously(REQ_GET_APNSETTING); 162 if ((response != null) && (response.what == RSP_GET_APNSETTING)) { 163 return rspApnSetting(response); 164 } else { 165 log("getApnSetting error response=" + response); 166 return null; 167 } 168 } 169 170 /** 171 * Request the connections LinkProperties. 172 * Response {@link #rspLinkProperties} 173 */ 174 public void reqLinkProperties() { 175 sendMessage(REQ_GET_LINK_PROPERTIES); 176 if (DBG) log("reqLinkProperties"); 177 } 178 179 /** 180 * Evaluate RSP_GET_LINK_PROPERTIES 181 * 182 * @param response 183 * @return LinkProperties, maybe null. 184 */ 185 public LinkProperties rspLinkProperties(Message response) { 186 LinkProperties retVal = (LinkProperties) response.obj; 187 if (DBG) log("rspLinkProperties=" + retVal); 188 return retVal; 189 } 190 191 /** 192 * Get the connections LinkProperties. 193 * 194 * @return LinkProperties or null if an error 195 */ 196 public LinkProperties getLinkPropertiesSync() { 197 Message response = sendMessageSynchronously(REQ_GET_LINK_PROPERTIES); 198 if ((response != null) && (response.what == RSP_GET_LINK_PROPERTIES)) { 199 return rspLinkProperties(response); 200 } else { 201 log("getLinkProperties error response=" + response); 202 return null; 203 } 204 } 205 206 /** 207 * Request setting the connections LinkProperties.HttpProxy. 208 * Response RSP_SET_LINK_PROPERTIES when complete. 209 */ 210 public void reqSetLinkPropertiesHttpProxy(ProxyProperties proxy) { 211 sendMessage(REQ_SET_LINK_PROPERTIES_HTTP_PROXY, proxy); 212 if (DBG) log("reqSetLinkPropertiesHttpProxy proxy=" + proxy); 213 } 214 215 /** 216 * Set the connections LinkProperties.HttpProxy 217 */ 218 public void setLinkPropertiesHttpProxySync(ProxyProperties proxy) { 219 Message response = 220 sendMessageSynchronously(REQ_SET_LINK_PROPERTIES_HTTP_PROXY, proxy); 221 if ((response != null) && (response.what == RSP_SET_LINK_PROPERTIES_HTTP_PROXY)) { 222 if (DBG) log("setLinkPropertiesHttpPoxy ok"); 223 } else { 224 log("setLinkPropertiesHttpPoxy error response=" + response); 225 } 226 } 227 228 /** 229 * Request update LinkProperties from DataCallState 230 * Response {@link #rspUpdateLinkPropertiesDataCallState} 231 */ 232 public void reqUpdateLinkPropertiesDataCallState(DataCallState newState) { 233 sendMessage(REQ_UPDATE_LINK_PROPERTIES_DATA_CALL_STATE, newState); 234 if (DBG) log("reqUpdateLinkPropertiesDataCallState"); 235 } 236 237 public boolean rspUpdateLinkPropertiesDataCallState(Message response) { 238 boolean retVal = response.arg1 == 1; 239 if (DBG) log("rspUpdateLinkPropertiesState=" + retVal); 240 return retVal; 241 } 242 243 /** 244 * Update link properties in the data connection 245 * 246 * @return true if link property has been updated. false otherwise. 247 */ 248 public boolean updateLinkPropertiesDataCallStateSync(DataCallState newState) { 249 Message response = 250 sendMessageSynchronously(REQ_UPDATE_LINK_PROPERTIES_DATA_CALL_STATE, newState); 251 if ((response != null) && 252 (response.what == RSP_UPDATE_LINK_PROPERTIES_DATA_CALL_STATE)) { 253 return rspUpdateLinkPropertiesDataCallState(response); 254 } else { 255 log("getLinkProperties error response=" + response); 256 return false; 257 } 258 } 259 260 /** 261 * Request the connections LinkCapabilities. 262 * Response {@link #rspLinkCapabilities} 263 */ 264 public void reqLinkCapabilities() { 265 sendMessage(REQ_GET_LINK_CAPABILITIES); 266 if (DBG) log("reqLinkCapabilities"); 267 } 268 269 /** 270 * Evaluate RSP_GET_LINK_CAPABILITIES 271 * 272 * @param response 273 * @return LinkCapabilites, maybe null. 274 */ 275 public LinkCapabilities rspLinkCapabilities(Message response) { 276 LinkCapabilities retVal = (LinkCapabilities) response.obj; 277 if (DBG) log("rspLinkCapabilities=" + retVal); 278 return retVal; 279 } 280 281 /** 282 * Get the connections LinkCapabilities. 283 * 284 * @return LinkCapabilities or null if an error 285 */ 286 public LinkCapabilities getLinkCapabilitiesSync() { 287 Message response = sendMessageSynchronously(REQ_GET_LINK_CAPABILITIES); 288 if ((response != null) && (response.what == RSP_GET_LINK_CAPABILITIES)) { 289 return rspLinkCapabilities(response); 290 } else { 291 log("getLinkCapabilities error response=" + response); 292 return null; 293 } 294 } 295 296 /** 297 * Request the connections LinkCapabilities. 298 * Response RSP_RESET when complete 299 */ 300 public void reqReset() { 301 sendMessage(REQ_RESET); 302 if (DBG) log("reqReset"); 303 } 304 305 /** 306 * Reset the connection and wait for it to complete. 307 */ 308 public void resetSync() { 309 Message response = sendMessageSynchronously(REQ_RESET); 310 if ((response != null) && (response.what == RSP_RESET)) { 311 if (DBG) log("restSync ok"); 312 } else { 313 if (DBG) log("restSync error response=" + response); 314 } 315 } 316 317 private void log(String s) { 318 android.util.Log.d(mLogTag, "DataConnectionAc " + s); 319 } 320} 321