mirror of
https://github.com/gsantner/dandelion
synced 2024-11-22 04:12:08 +01:00
Let elements other than the webView use the proxy (HttpsUrlConnections)
This commit is contained in:
parent
61c92349aa
commit
af0070df66
3 changed files with 60 additions and 28 deletions
|
@ -28,12 +28,6 @@ import android.util.Log;
|
|||
|
||||
import com.github.dfa.diaspora_android.App;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.StatusLine;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
|
@ -44,6 +38,10 @@ import java.io.InputStreamReader;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
import info.guardianproject.netcipher.NetCipher;
|
||||
|
||||
public class GetPodsService extends Service {
|
||||
public static final String MESSAGE_PODS_RECEIVED = "com.github.dfa.diaspora.podsreceived";
|
||||
private static final String TAG = App.TAG;
|
||||
|
@ -73,24 +71,28 @@ public class GetPodsService extends Service {
|
|||
// TODO: Update deprecated code
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
HttpClient client = new DefaultHttpClient();
|
||||
//HttpClient client = new DefaultHttpClient();
|
||||
List<String> list = null;
|
||||
HttpsURLConnection connection;
|
||||
InputStream inStream;
|
||||
try {
|
||||
HttpGet httpGet = new HttpGet("http://podupti.me/api.php?key=4r45tg&format=json");
|
||||
HttpResponse response = client.execute(httpGet);
|
||||
StatusLine statusLine = response.getStatusLine();
|
||||
int statusCode = statusLine.getStatusCode();
|
||||
connection = NetCipher.getHttpsURLConnection("https://podupti.me/api.php?key=4r45tg&format=json");
|
||||
int statusCode = connection.getResponseCode();
|
||||
if (statusCode == 200) {
|
||||
HttpEntity entity = response.getEntity();
|
||||
InputStream content = entity.getContent();
|
||||
inStream = connection.getInputStream();
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(content));
|
||||
new InputStreamReader(inStream));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
builder.append(line);
|
||||
}
|
||||
|
||||
try {
|
||||
inStream.close();
|
||||
} catch (IOException e) {/*Nothing to do*/}
|
||||
|
||||
connection.disconnect();
|
||||
} else {
|
||||
//TODO Notify User about failure
|
||||
Log.e(TAG, "Failed to download list of pods");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -13,7 +13,12 @@ import java.io.FileOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
import info.guardianproject.netcipher.NetCipher;
|
||||
|
||||
/**
|
||||
* Task that can be used to download images from URLs and store them in storage
|
||||
* Created by Gregor Santner (gsantner) on 24.03.16.
|
||||
*/
|
||||
public class ImageDownloadTask extends AsyncTask<String, Void, Bitmap> {
|
||||
|
@ -35,9 +40,12 @@ public class ImageDownloadTask extends AsyncTask<String, Void, Bitmap> {
|
|||
String url = urls[0];
|
||||
Bitmap bitmap = null;
|
||||
FileOutputStream out = null;
|
||||
InputStream inStream;
|
||||
HttpsURLConnection connection;
|
||||
try {
|
||||
InputStream in = new java.net.URL(url).openStream();
|
||||
bitmap = BitmapFactory.decodeStream(in);
|
||||
connection = NetCipher.getHttpsURLConnection(url);
|
||||
inStream = connection.getInputStream();
|
||||
bitmap = BitmapFactory.decodeStream(inStream);
|
||||
|
||||
// Save to file if not null
|
||||
if (savePath != null) {
|
||||
|
@ -45,6 +53,12 @@ public class ImageDownloadTask extends AsyncTask<String, Void, Bitmap> {
|
|||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
|
||||
}
|
||||
|
||||
try {
|
||||
inStream.close();
|
||||
} catch (IOException e) {/*Nothing*/}
|
||||
|
||||
connection.disconnect();
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e(App.TAG, e.getMessage());
|
||||
} finally {
|
||||
|
|
|
@ -10,11 +10,16 @@ import com.github.dfa.diaspora_android.data.PodUserProfile;
|
|||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
import info.guardianproject.netcipher.NetCipher;
|
||||
|
||||
/**
|
||||
* AsyncTask to fetch a users profile
|
||||
* Created by Gregor Santner (gsantner) on 30.03.16.
|
||||
*/
|
||||
public class ProfileFetchTask extends AsyncTask<Void, Void, Void> {
|
||||
|
@ -37,18 +42,21 @@ public class ProfileFetchTask extends AsyncTask<Void, Void, Void> {
|
|||
String cookies = cookieManager.getCookie("https://" + app.getSettings().getPodDomain());
|
||||
Log.d(App.TAG, cookies);
|
||||
|
||||
HttpsURLConnection connection;
|
||||
InputStream inStream;
|
||||
try {
|
||||
URL url = new URL("https://" + app.getSettings().getPodDomain() + "/stream");
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setReadTimeout(10000);
|
||||
conn.setConnectTimeout(15000);
|
||||
conn.setRequestMethod("GET");
|
||||
connection = NetCipher.getHttpsURLConnection(url);
|
||||
connection.setReadTimeout(10000);
|
||||
connection.setConnectTimeout(15000);
|
||||
connection.setRequestMethod("GET");
|
||||
if (cookies != null) {
|
||||
conn.setRequestProperty("Cookie", cookies);
|
||||
connection.setRequestProperty("Cookie", cookies);
|
||||
}
|
||||
conn.connect();
|
||||
connection.connect();
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
inStream = connection.getInputStream();
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(inStream));
|
||||
String line;
|
||||
final String TARGET_TAG = "window.gon={};gon.user=";
|
||||
while ((line = br.readLine()) != null && !line.startsWith("<body")) {
|
||||
|
@ -57,6 +65,14 @@ public class ProfileFetchTask extends AsyncTask<Void, Void, Void> {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
try{
|
||||
br.close();
|
||||
inStream.close();
|
||||
} catch (IOException e){/*Nothing*/}
|
||||
|
||||
connection.disconnect();
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue