diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-07-28 11:59:22 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-07-28 11:59:22 +0200 |
commit | ef6dc57d5a3d01cb3a79123efc63803f7067ff8b (patch) | |
tree | ecd1364f7ac518a149a90c08d98b7105d998d0d0 /src/main/java/de/pixart/messenger/ui | |
parent | b1d97bd55d3cbf1352cdec494430702dc1b0ff62 (diff) |
use TOR for updater
Diffstat (limited to 'src/main/java/de/pixart/messenger/ui')
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/UpdaterActivity.java | 178 |
1 files changed, 95 insertions, 83 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java b/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java index f98872b7c..2a30d07f2 100644 --- a/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java +++ b/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java @@ -33,24 +33,29 @@ import java.util.List; import de.pixart.messenger.Config; import de.pixart.messenger.R; import de.pixart.messenger.persistance.FileBackend; +import de.pixart.messenger.services.XmppConnectionService; import de.pixart.messenger.utils.WakeLockHelper; +import static de.pixart.messenger.http.HttpConnectionManager.getProxy; + public class UpdaterActivity extends XmppActivity { static final private String FileName = "update.apk"; - String appURI = ""; String changelog = ""; Integer filesize = 0; boolean playstore = false; ProgressDialog mProgressDialog; DownloadTask downloadTask; + XmppConnectionService mXmppConnectionService; + private boolean mUseTor; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //set activity setContentView(R.layout.activity_updater); - + this.mUseTor = mXmppConnectionService.useTorToConnect(); this.mTheme = findTheme(); setTheme(this.mTheme); @@ -65,7 +70,7 @@ public class UpdaterActivity extends XmppActivity { } }; mProgressDialog.setMessage(getString(R.string.download_started)); - mProgressDialog.setProgressNumberFormat (null); + mProgressDialog.setProgressNumberFormat(null); mProgressDialog.setIndeterminate(true); mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); mProgressDialog.setCancelable(false); @@ -140,7 +145,8 @@ public class UpdaterActivity extends XmppActivity { } } else { Toast.makeText(getApplicationContext(), getText(R.string.download_started), Toast.LENGTH_LONG).show(); - downloadTask = new DownloadTask(UpdaterActivity.this) {}; + downloadTask = new DownloadTask(UpdaterActivity.this) { + }; downloadTask.execute(appURI); } } else { @@ -188,14 +194,90 @@ public class UpdaterActivity extends XmppActivity { super.onRestoreInstanceState(savedInstanceState); } + //check for internet connection + private boolean isNetworkAvailable(Context context) { + ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + if (connectivity != null) { + NetworkInfo[] info = connectivity.getAllNetworkInfo(); + if (info != null) { + for (int i = 0; i < info.length; i++) { + if (info[i].getState() == NetworkInfo.State.CONNECTED) { + return true; + } + } + } + } + return false; + } + + public boolean isStoragePermissionGranted() { + if (Build.VERSION.SDK_INT >= 23) { + if (checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE) + == PackageManager.PERMISSION_GRANTED) { + return true; + } else { + + ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1); + return false; + } + } else { //permission is automatically granted on sdk<23 upon installation + return true; + } + } + + //show warning on back pressed + @Override + public void onBackPressed() { + showCancelDialog(); + } + + private void showCancelDialog() { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setMessage(R.string.cancel_update) + .setCancelable(false) + .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + if (!downloadTask.getStatus().equals(AsyncTask.Status.FINISHED)) { + downloadTask.cancel(true); + } + if (mProgressDialog.isShowing()) { + mProgressDialog.dismiss(); + } + UpdaterActivity.this.finish(); + } + }) + .setNegativeButton(R.string.no, (dialog, id) -> dialog.cancel()); + AlertDialog alert = builder.create(); + alert.show(); + } + + @Override + public void onPause() { + super.onPause(); + if (downloadTask != null && !downloadTask.getStatus().equals(AsyncTask.Status.FINISHED)) { + downloadTask.cancel(true); + } + UpdaterActivity.this.finish(); + } + + @Override + protected void onStop() { + super.onStop(); + if (downloadTask != null && !downloadTask.getStatus().equals(AsyncTask.Status.FINISHED)) { + downloadTask.cancel(true); + } + UpdaterActivity.this.finish(); + } + private class DownloadTask extends AsyncTask<String, Integer, String> { + File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + FileBackend.getDirectoryName("Update", false)); + File file = new File(dir, FileName); private Context context; - private PowerManager.WakeLock mWakeLock; private long startTime = 0; - File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + FileBackend.getDirectoryName("Update", false)); - File file = new File(dir, FileName); + public DownloadTask(Context context) { this.context = context; } @@ -233,7 +315,12 @@ public class UpdaterActivity extends XmppActivity { Log.d(Config.LOGTAG, "AppUpdater: download update from url: " + sUrl[0] + " to file name: " + file.toString()); URL url = new URL(sUrl[0]); - connection = (HttpURLConnection) url.openConnection(); + + if (mUseTor) { + connection = (HttpURLConnection) url.openConnection(getProxy()); + } else { + connection = (HttpURLConnection) url.openConnection(); + } connection.connect(); // expect HTTP 200 OK, so we don't mistakenly save error report @@ -309,79 +396,4 @@ public class UpdaterActivity extends XmppActivity { } } - //check for internet connection - private boolean isNetworkAvailable(Context context) { - ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - if (connectivity != null) { - NetworkInfo[] info = connectivity.getAllNetworkInfo(); - if (info != null) { - for (int i = 0; i < info.length; i++) { - if (info[i].getState() == NetworkInfo.State.CONNECTED) { - return true; - } - } - } - } - return false; - } - - public boolean isStoragePermissionGranted() { - if (Build.VERSION.SDK_INT >= 23) { - if (checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE) - == PackageManager.PERMISSION_GRANTED) { - return true; - } else { - - ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1); - return false; - } - } else { //permission is automatically granted on sdk<23 upon installation - return true; - } - } - - //show warning on back pressed - @Override - public void onBackPressed() { - showCancelDialog(); - } - - private void showCancelDialog() { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setMessage(R.string.cancel_update) - .setCancelable(false) - .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - if (!downloadTask.getStatus().equals(AsyncTask.Status.FINISHED)) { - downloadTask.cancel(true); - } - if (mProgressDialog.isShowing()) { - mProgressDialog.dismiss(); - } - UpdaterActivity.this.finish(); - } - }) - .setNegativeButton(R.string.no, (dialog, id) -> dialog.cancel()); - AlertDialog alert = builder.create(); - alert.show(); - } - - @Override - public void onPause() { - super.onPause(); - if (downloadTask != null && !downloadTask.getStatus().equals(AsyncTask.Status.FINISHED)) { - downloadTask.cancel(true); - } - UpdaterActivity.this.finish(); - } - - @Override - protected void onStop() { - super.onStop(); - if (downloadTask != null && !downloadTask.getStatus().equals(AsyncTask.Status.FINISHED)) { - downloadTask.cancel(true); - } - UpdaterActivity.this.finish(); - } } |