diff options
author | Narayan Kamath <narayan@google.com> | 2014-12-12 13:53:28 +0000 |
---|---|---|
committer | Narayan Kamath <narayan@google.com> | 2014-12-15 14:32:38 +0000 |
commit | 7a250b82882c5ccc93cdd73ab62471470fa43e2c (patch) | |
tree | fb983c7da820b72f3ecf3bd6ad6cd3cdfd01ef9d /tests/src | |
parent | fe3b679090adfe16cbc1834e3d33bc17ac00ce17 (diff) | |
download | packages_apps_Settings-7a250b82882c5ccc93cdd73ab62471470fa43e2c.zip packages_apps_Settings-7a250b82882c5ccc93cdd73ab62471470fa43e2c.tar.gz packages_apps_Settings-7a250b82882c5ccc93cdd73ab62471470fa43e2c.tar.bz2 |
Stop using apache-http in settings.
Most of this usage is from crufty "test" code, and is trivially
replacable.
bug: 18027885
(cherry picked from commit f25627c0c960cd31e069a0aed62798dd3a6416aa)
Change-Id: I62b0c4e79812ae69767d778eb9e866cbba1d50e0
Diffstat (limited to 'tests/src')
-rw-r--r-- | tests/src/com/android/settings/vpn2/VpnTests.java | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/tests/src/com/android/settings/vpn2/VpnTests.java b/tests/src/com/android/settings/vpn2/VpnTests.java index 7d5961d..6a01cc5 100644 --- a/tests/src/com/android/settings/vpn2/VpnTests.java +++ b/tests/src/com/android/settings/vpn2/VpnTests.java @@ -18,8 +18,6 @@ package com.android.settings.vpn2; import android.content.Context; import android.net.IConnectivityManager; -import android.net.LinkAddress; -import android.net.RouteInfo; import android.os.Bundle; import android.os.Environment; 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.VpnProfile; +import java.net.HttpURLConnection; +import java.net.URL; import junit.framework.Assert; -import org.apache.http.HttpResponse; -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 libcore.io.Streams; import org.json.JSONException; import org.json.JSONObject; @@ -228,14 +224,21 @@ public class VpnTests extends InstrumentationTestCase { */ private String getIpAddress() { String ip = null; + HttpURLConnection urlConnection = null; try { - HttpClient httpClient = new DefaultHttpClient(); - HttpGet httpGet = new HttpGet(EXTERNAL_SERVER); - HttpResponse httpResponse = httpClient.execute(httpGet); - Log.i(TAG, "Response from httpget: " + httpResponse.getStatusLine().toString()); + URL url = new URL(EXTERNAL_SERVER); + urlConnection = (HttpURLConnection) url.openConnection(); + Log.i(TAG, "Response from httpget: " + urlConnection.getResponseCode()); - String entityStr = EntityUtils.toString(httpResponse.getEntity()); - JSONObject json_data = new JSONObject(entityStr); + InputStream is = urlConnection.getInputStream(); + 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"); Log.v(TAG, "json_data: " + ip); } catch (IllegalArgumentException e) { @@ -244,6 +247,10 @@ public class VpnTests extends InstrumentationTestCase { Log.e(TAG, "IOException while getting IP: " + e.toString()); } catch (JSONException e) { Log.e(TAG, "exception while creating JSONObject: " + e.toString()); + } finally { + if (urlConnection != null) { + urlConnection.disconnect(); + } } return ip; } |