From ef255d12ae3704b94441d7ac4bcacc4e2ad40f6f Mon Sep 17 00:00:00 2001 From: GDR! Date: Thu, 24 Dec 2015 14:55:33 +0100 Subject: [PATCH] Test tor code --- app/build.gradle | 3 +- .../java/org/schabi/newpipe/Downloader.java | 8 +++-- .../org/schabi/newpipe/PlayVideoActivity.java | 30 ++++++++++++++++++- app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/settings_screen.xml | 5 ++++ 5 files changed, 44 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index fb4598597..9eb3ccef7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -17,7 +17,7 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } - + lintOptions { checkReleaseBuilds false // Or, if you prefer, you can continue to check for errors in release builds, @@ -35,4 +35,5 @@ dependencies { compile 'com.android.support:recyclerview-v7:23.1.1' compile 'org.jsoup:jsoup:1.8.3' compile 'org.mozilla:rhino:1.7.7' + compile 'info.guardianproject.netcipher:netcipher:1.2' } diff --git a/app/src/main/java/org/schabi/newpipe/Downloader.java b/app/src/main/java/org/schabi/newpipe/Downloader.java index f0a19cfc5..c15c2ddc3 100644 --- a/app/src/main/java/org/schabi/newpipe/Downloader.java +++ b/app/src/main/java/org/schabi/newpipe/Downloader.java @@ -7,6 +7,8 @@ import java.net.HttpURLConnection; import java.net.URL; import java.net.UnknownHostException; +import info.guardianproject.netcipher.NetCipher; + /** * Created by Christian Schabesberger on 14.08.15. * @@ -37,10 +39,11 @@ public class Downloader { * @param language the language (usually a 2-character code) to set as the preferred language * @return the contents of the specified text file*/ public static String download(String siteUrl, String language) { + NetCipher.useTor(); String ret = ""; try { URL url = new URL(siteUrl); - HttpURLConnection con = (HttpURLConnection) url.openConnection(); + HttpURLConnection con = (HttpURLConnection) NetCipher.getHttpURLConnection(url); con.setRequestProperty("Accept-Language", language); ret = dl(con); } @@ -81,10 +84,11 @@ public class Downloader { * @return the contents of the specified text file*/ public static String download(String siteUrl) { String ret = ""; + NetCipher.useTor(); try { URL url = new URL(siteUrl); - HttpURLConnection con = (HttpURLConnection) url.openConnection(); + HttpURLConnection con = (HttpURLConnection) NetCipher.getHttpURLConnection(url); ret = dl(con); } catch(Exception e) { diff --git a/app/src/main/java/org/schabi/newpipe/PlayVideoActivity.java b/app/src/main/java/org/schabi/newpipe/PlayVideoActivity.java index d5fea8c3e..a7aeda10f 100644 --- a/app/src/main/java/org/schabi/newpipe/PlayVideoActivity.java +++ b/app/src/main/java/org/schabi/newpipe/PlayVideoActivity.java @@ -3,6 +3,7 @@ package org.schabi.newpipe; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.media.MediaPlayer; @@ -25,6 +26,7 @@ import android.widget.Button; import android.widget.MediaController; import android.widget.ProgressBar; import android.widget.VideoView; +import info.guardianproject.netcipher.NetCipher; /** * Copyright (C) Christian Schabesberger 2015 @@ -44,7 +46,7 @@ import android.widget.VideoView; * along with NewPipe. If not, see . */ -public class PlayVideoActivity extends AppCompatActivity { +public class PlayVideoActivity extends AppCompatActivity implements OnSharedPreferenceChangeListener { //// TODO: 11.09.15 add "choose stream" menu @@ -170,6 +172,9 @@ public class PlayVideoActivity extends AppCompatActivity { if(prefs.getBoolean(PREF_IS_LANDSCAPE, false) && !isLandscape) { toggleOrientation(); } + + setTorPreference(prefs); + prefs.registerOnSharedPreferenceChangeListener(this); } @Override @@ -187,6 +192,13 @@ public class PlayVideoActivity extends AppCompatActivity { videoView.pause(); } + @Override + protected void onDestroy() { + super.onDestroy(); + prefs = getPreferences(Context.MODE_PRIVATE); + prefs.unregisterOnSharedPreferenceChangeListener(this); + } + @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); @@ -348,4 +360,20 @@ public class PlayVideoActivity extends AppCompatActivity { editor.putBoolean(PREF_IS_LANDSCAPE, isLandscape); editor.apply(); } + + private void setTorPreference(SharedPreferences prefs) { + if(prefs.getBoolean(getString(R.string.useTor), false)) { + NetCipher.useTor(); + } else { + NetCipher.setProxy(null); + } + } + + @Override + public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { + if(key.equals(getString(R.string.useTor))) { + setTorPreference(prefs); + } + } + } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 12fb9275d..c2d1becdd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -63,4 +63,6 @@ Uploader thumbnail Dislikes Likes + Use Tor + Proxy connections via The Onion Router diff --git a/app/src/main/res/xml/settings_screen.xml b/app/src/main/res/xml/settings_screen.xml index d4b21426f..953ded807 100644 --- a/app/src/main/res/xml/settings_screen.xml +++ b/app/src/main/res/xml/settings_screen.xml @@ -72,5 +72,10 @@ android:summary="@string/autoPlayThroughIntentSummary" android:defaultValue="false" /> + +