Stop using apache-http in settings.

Most of this usage is from crufty "test" code, and is trivially
replacable.

bug: 18027885

Change-Id: If4441a5e76405eba068479a4dcaa6012b5a74cbf
This commit is contained in:
Narayan Kamath
2014-12-12 13:53:28 +00:00
parent e6af93277c
commit f25627c0c9
3 changed files with 43 additions and 34 deletions

View File

@@ -17,7 +17,6 @@
package com.android.settings; package com.android.settings;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
@@ -55,10 +54,8 @@ import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.PhoneFactory; import com.android.internal.telephony.PhoneFactory;
import com.android.internal.telephony.PhoneStateIntentReceiver; import com.android.internal.telephony.PhoneStateIntentReceiver;
import com.android.internal.telephony.TelephonyProperties; import com.android.internal.telephony.TelephonyProperties;
import org.apache.http.HttpResponse; import java.net.HttpURLConnection;
import org.apache.http.client.HttpClient; import java.net.URL;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import java.io.IOException; import java.io.IOException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
@@ -745,18 +742,22 @@ public class RadioInfo extends Activity {
* This function checks for basic functionality of HTTP Client. * This function checks for basic functionality of HTTP Client.
*/ */
private void httpClientTest() { private void httpClientTest() {
HttpClient client = new DefaultHttpClient(); HttpURLConnection urlConnection = null;
try { try {
HttpGet request = new HttpGet("http://www.google.com"); // TODO: Hardcoded for now, make it UI configurable
HttpResponse response = client.execute(request); URL url = new URL("http://www.google.com");
if (response.getStatusLine().getStatusCode() == 200) { urlConnection = (HttpURLConnection) url.openConnection();
if (urlConnection.getResponseCode() == 200) {
mHttpClientTestResult = "Pass"; mHttpClientTestResult = "Pass";
} else { } else {
mHttpClientTestResult = "Fail: Code: " + String.valueOf(response); mHttpClientTestResult = "Fail: Code: " + urlConnection.getResponseMessage();
} }
request.abort();
} catch (IOException e) { } catch (IOException e) {
mHttpClientTestResult = "Fail: IOException"; mHttpClientTestResult = "Fail: IOException";
} finally {
if (urlConnection != null) {
urlConnection.disconnect();
}
} }
} }

View File

@@ -18,10 +18,8 @@ package com.android.settings.wifi;
import com.android.settings.R; import com.android.settings.R;
import android.net.wifi.ScanResult; import android.net.wifi.ScanResult;
import org.apache.http.HttpResponse; import java.net.HttpURLConnection;
import org.apache.http.client.HttpClient; import java.net.URL;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import java.util.List; import java.util.List;
import android.app.Activity; import android.app.Activity;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
@@ -388,19 +386,22 @@ public class WifiStatusTest extends Activity {
} }
private void httpClientTest() { private void httpClientTest() {
HttpClient client = new DefaultHttpClient(); HttpURLConnection urlConnection = null;
try { try {
// TODO: Hardcoded for now, make it UI configurable // TODO: Hardcoded for now, make it UI configurable
HttpGet request = new HttpGet("http://www.google.com"); URL url = new URL("http://www.google.com");
HttpResponse response = client.execute(request); urlConnection = (HttpURLConnection) url.openConnection();
if (response.getStatusLine().getStatusCode() == 200) { if (urlConnection.getResponseCode() == 200) {
mHttpClientTestResult = "Pass"; mHttpClientTestResult = "Pass";
} else { } else {
mHttpClientTestResult = "Fail: Code: " + String.valueOf(response); mHttpClientTestResult = "Fail: Code: " + urlConnection.getResponseMessage();
} }
request.abort();
} catch (IOException e) { } catch (IOException e) {
mHttpClientTestResult = "Fail: IOException"; mHttpClientTestResult = "Fail: IOException";
} finally {
if (urlConnection != null) {
urlConnection.disconnect();
}
} }
} }

View File

@@ -18,8 +18,6 @@ package com.android.settings.vpn2;
import android.content.Context; import android.content.Context;
import android.net.IConnectivityManager; import android.net.IConnectivityManager;
import android.net.LinkAddress;
import android.net.RouteInfo;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.os.RemoteException; import android.os.RemoteException;
@@ -35,13 +33,11 @@ import com.android.internal.net.LegacyVpnInfo;
import com.android.internal.net.VpnConfig; import com.android.internal.net.VpnConfig;
import com.android.internal.net.VpnProfile; import com.android.internal.net.VpnProfile;
import java.net.HttpURLConnection;
import java.net.URL;
import junit.framework.Assert; import junit.framework.Assert;
import org.apache.http.HttpResponse; import libcore.io.Streams;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@@ -228,14 +224,21 @@ public class VpnTests extends InstrumentationTestCase {
*/ */
private String getIpAddress() { private String getIpAddress() {
String ip = null; String ip = null;
HttpURLConnection urlConnection = null;
try { try {
HttpClient httpClient = new DefaultHttpClient(); URL url = new URL(EXTERNAL_SERVER);
HttpGet httpGet = new HttpGet(EXTERNAL_SERVER); urlConnection = (HttpURLConnection) url.openConnection();
HttpResponse httpResponse = httpClient.execute(httpGet); Log.i(TAG, "Response from httpget: " + urlConnection.getResponseCode());
Log.i(TAG, "Response from httpget: " + httpResponse.getStatusLine().toString());
String entityStr = EntityUtils.toString(httpResponse.getEntity()); InputStream is = urlConnection.getInputStream();
JSONObject json_data = new JSONObject(entityStr); String response;
try {
response = new String(Streams.readFully(is), StandardCharsets.UTF_8);
} finally {
is.close();
}
JSONObject json_data = new JSONObject(response);
ip = json_data.getString("ip"); ip = json_data.getString("ip");
Log.v(TAG, "json_data: " + ip); Log.v(TAG, "json_data: " + ip);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
@@ -244,6 +247,10 @@ public class VpnTests extends InstrumentationTestCase {
Log.e(TAG, "IOException while getting IP: " + e.toString()); Log.e(TAG, "IOException while getting IP: " + e.toString());
} catch (JSONException e) { } catch (JSONException e) {
Log.e(TAG, "exception while creating JSONObject: " + e.toString()); Log.e(TAG, "exception while creating JSONObject: " + e.toString());
} finally {
if (urlConnection != null) {
urlConnection.disconnect();
}
} }
return ip; return ip;
} }