aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/pixart')
-rw-r--r--src/main/java/de/pixart/messenger/services/UpdateService.java48
-rw-r--r--src/main/java/de/pixart/messenger/ui/UpdaterActivity.java178
2 files changed, 120 insertions, 106 deletions
diff --git a/src/main/java/de/pixart/messenger/services/UpdateService.java b/src/main/java/de/pixart/messenger/services/UpdateService.java
index c08dab683..da940f7b7 100644
--- a/src/main/java/de/pixart/messenger/services/UpdateService.java
+++ b/src/main/java/de/pixart/messenger/services/UpdateService.java
@@ -26,25 +26,21 @@ import de.pixart.messenger.Config;
import de.pixart.messenger.R;
import de.pixart.messenger.ui.UpdaterActivity;
+import static de.pixart.messenger.http.HttpConnectionManager.getProxy;
import static de.pixart.messenger.services.NotificationService.UPDATE_NOTIFICATION_ID;
public class UpdateService extends AsyncTask<String, Object, UpdateService.Wrapper> {
- public UpdateService (){
- }
-
+ XmppConnectionService mXmppConnectionService;
+ private boolean mUseTor;
private Context context;
private boolean playstore;
+ public UpdateService() {
+ }
public UpdateService(Context context, boolean PlayStore) {
this.context = context;
this.playstore = PlayStore;
- }
-
- public class Wrapper
- {
- public boolean UpdateAvailable = false;
- public boolean NoUpdate = false;
- public boolean isError = false;
+ this.mUseTor = mXmppConnectionService.useTorToConnect();
}
@Override
@@ -60,9 +56,13 @@ public class UpdateService extends AsyncTask<String, Object, UpdateService.Wrapp
HttpsURLConnection connection = null;
- try {
+ try {
URL url = new URL(Config.UPDATE_URL);
- connection = (HttpsURLConnection)url.openConnection();
+ if (mUseTor) {
+ connection = (HttpsURLConnection) url.openConnection(getProxy());
+ } else {
+ connection = (HttpsURLConnection) url.openConnection();
+ }
connection.setConnectTimeout(Config.SOCKET_TIMEOUT * 1000);
connection.setReadTimeout(Config.SOCKET_TIMEOUT * 1000);
connection.setRequestProperty("User-Agent", context.getString(R.string.app_name));
@@ -128,18 +128,14 @@ public class UpdateService extends AsyncTask<String, Object, UpdateService.Wrapp
return;
}
Handler handler = new Handler(Looper.getMainLooper());
- handler.post(new Runnable() {
-
- @Override
- public void run() {
- String ToastMessage = "";
- if (error) {
- ToastMessage = context.getString(R.string.failed);
- } else {
- ToastMessage = context.getString(R.string.no_update_available);
- }
- Toast.makeText(context, ToastMessage, Toast.LENGTH_LONG).show();
+ handler.post(() -> {
+ String ToastMessage = "";
+ if (error) {
+ ToastMessage = context.getString(R.string.failed);
+ } else {
+ ToastMessage = context.getString(R.string.no_update_available);
}
+ Toast.makeText(context, ToastMessage, Toast.LENGTH_LONG).show();
});
}
@@ -211,4 +207,10 @@ public class UpdateService extends AsyncTask<String, Object, UpdateService.Wrapp
}
return 0;
}
+
+ public class Wrapper {
+ public boolean UpdateAvailable = false;
+ public boolean NoUpdate = false;
+ public boolean isError = false;
+ }
} \ No newline at end of file
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();
- }
}