summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2019-11-17 11:18:51 +0100
committerArne Schwabe <arne@rfc2549.org>2019-11-17 11:18:51 +0100
commit7d9cb2f62b12453c592d949974c131f5bf1ca7c1 (patch)
treed342701c18c532a15f0e5b891416cdf39d3a3c26 /main
parentcbdaa48705855169827f29014efbaa934d212ccf (diff)
Convert OpenSSLSpeed,bugfixes for library conversion
Diffstat (limited to 'main')
-rw-r--r--main/src/main/res/values/refs.xml40
-rw-r--r--main/src/ui/java/de/blinkt/openvpn/activities/LogWindow.java2
-rw-r--r--main/src/ui/java/de/blinkt/openvpn/activities/OpenSSLSpeed.java192
-rw-r--r--main/src/ui/java/de/blinkt/openvpn/activities/OpenSSLSpeed.kt178
-rw-r--r--main/src/ui/java/de/blinkt/openvpn/fragments/LogFragment.java27
-rw-r--r--main/src/ui/res/values-night-v21/refs.xml9
-rw-r--r--main/src/ui/res/values-v21/refs.xml27
7 files changed, 210 insertions, 265 deletions
diff --git a/main/src/main/res/values/refs.xml b/main/src/main/res/values/refs.xml
index c968b05c..5d2ea134 100644
--- a/main/src/main/res/values/refs.xml
+++ b/main/src/main/res/values/refs.xml
@@ -1,27 +1,27 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
+<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2012-2016 Arne Schwabe
~ Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
-->
<resources>
- <drawable name="ic_menu_close_clear_cancel">@android:drawable/ic_menu_close_clear_cancel</drawable>
- <drawable name="ic_menu_play">@android:drawable/ic_media_play</drawable>
- <drawable name="ic_menu_pause">@android:drawable/ic_media_pause</drawable>
- <drawable name="ic_menu_share">@android:drawable/ic_menu_share </drawable>
- <drawable name="ic_menu_save">@android:drawable/ic_menu_save</drawable>
- <drawable name="ic_menu_view">@android:drawable/ic_menu_view</drawable>
- <drawable name="ic_menu_delete">@android:drawable/ic_menu_delete</drawable>
- <drawable name="ic_menu_edit">@android:drawable/ic_menu_edit</drawable>
- <drawable name="ic_menu_import">@drawable/ic_menu_archive</drawable>
- <drawable name="vpn_item_edit">@drawable/vpn_item_settings </drawable>
- <drawable name="ic_menu_add">@android:drawable/ic_menu_add</drawable>
- <drawable name="ic_dialog_alert">@android:drawable/ic_dialog_alert</drawable>
- <drawable name="ic_menu_add_grey">@android:drawable/ic_menu_add</drawable>
- <drawable name="ic_menu_import_grey">@drawable/ic_menu_archive</drawable>
- <drawable name="ic_menu_delete_grey">@android:drawable/ic_menu_delete</drawable>
- <drawable name="ic_menu_copy">@drawable/ic_menu_copy_holo_light</drawable>
- <drawable name="ic_receipt">@drawable/ic_menu_log</drawable>
- <drawable name="ic_sort">@android:drawable/ic_menu_sort_by_size</drawable>
+ <drawable name="ic_menu_close_clear_cancel">@drawable/ic_close_white_24dp</drawable>
+ <drawable name="ic_menu_play">@drawable/ic_play_arrow_white_24dp</drawable>
+ <drawable name="ic_menu_pause">@drawable/ic_pause_white_24dp</drawable>
+ <drawable name="ic_menu_share">@drawable/ic_share_white_24dp</drawable>
+ <drawable name="ic_menu_save">@drawable/ic_check_white_24dp</drawable>
+ <drawable name="ic_menu_view">@drawable/ic_filter_list_white_24dp</drawable>
+ <drawable name="ic_menu_delete">@drawable/ic_delete_white_24dp</drawable>
+ <drawable name="ic_menu_copy">@drawable/ic_content_copy_white_24dp</drawable>
+ <drawable name="ic_menu_delete_grey">@drawable/ic_delete_grey600_24dp</drawable>
+
+ <drawable name="ic_menu_edit">@drawable/ic_edit_white_24dp</drawable>
+ <drawable name="ic_menu_import">@drawable/ic_archive_white_24dp</drawable>
+ <drawable name="vpn_item_edit">@drawable/ic_edit_grey600_24dp</drawable>
+ <drawable name="ic_menu_add">@drawable/ic_add_circle_outline_white_24dp</drawable>
+ <drawable name="ic_dialog_alert">@drawable/ic_warning_black_36dp</drawable>
+ <drawable name="ic_menu_add_grey">@drawable/ic_add_circle_outline_grey600_24dp</drawable>
+ <drawable name="ic_menu_import_grey">@drawable/ic_archive_grey600_24dp</drawable>
+ <drawable name="ic_receipt">@drawable/ic_receipt_white_24dp</drawable>
+ <drawable name="ic_sort">@drawable/ic_sort_white_24dp</drawable>
</resources> \ No newline at end of file
diff --git a/main/src/ui/java/de/blinkt/openvpn/activities/LogWindow.java b/main/src/ui/java/de/blinkt/openvpn/activities/LogWindow.java
index fa0106a9..5277a25d 100644
--- a/main/src/ui/java/de/blinkt/openvpn/activities/LogWindow.java
+++ b/main/src/ui/java/de/blinkt/openvpn/activities/LogWindow.java
@@ -20,7 +20,7 @@ public class LogWindow extends BaseActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.log_window);
- getActionBar().setDisplayHomeAsUpEnabled(true);
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
diff --git a/main/src/ui/java/de/blinkt/openvpn/activities/OpenSSLSpeed.java b/main/src/ui/java/de/blinkt/openvpn/activities/OpenSSLSpeed.java
deleted file mode 100644
index eb0fe9cd..00000000
--- a/main/src/ui/java/de/blinkt/openvpn/activities/OpenSSLSpeed.java
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * Copyright (c) 2012-2017 Arne Schwabe
- * Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
- */
-
-package de.blinkt.openvpn.activities;
-
-import android.content.Context;
-import android.os.AsyncTask;
-import android.os.Bundle;
-import android.app.Activity;
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ArrayAdapter;
-import android.widget.EditText;
-import android.widget.ListView;
-import android.widget.TextView;
-
-import java.util.Locale;
-import java.util.Vector;
-
-import de.blinkt.openvpn.R;
-import de.blinkt.openvpn.core.NativeUtils;
-import de.blinkt.openvpn.core.OpenVPNService;
-
-public class OpenSSLSpeed extends Activity {
-
- private static SpeeedTest runTestAlgorithms;
- private EditText mCipher;
- private SpeedArrayAdapter mAdapter;
- private ListView mListView;
-
-
- static class SpeedArrayAdapter extends ArrayAdapter<SpeedResult> {
-
- private final Context mContext;
- private final LayoutInflater mInflater;
-
- public SpeedArrayAdapter(@NonNull Context context) {
- super(context, 0);
- mContext = context;
- mInflater = LayoutInflater.from(context);
-
- }
-
- class ViewHolder {
- TextView ciphername;
- TextView blocksize;
- TextView blocksInTime;
- TextView speed;
- }
-
- @NonNull
- @Override
- public View getView(int position, @Nullable View view, @NonNull ViewGroup parent) {
- SpeedResult res = getItem(position);
- if (view == null) {
- view = mInflater.inflate(R.layout.speedviewitem, parent, false);
- ViewHolder holder = new ViewHolder();
- holder.ciphername = view.findViewById(R.id.ciphername);
- holder.speed = view.findViewById(R.id.speed);
- holder.blocksize = view.findViewById(R.id.blocksize);
- holder.blocksInTime = view.findViewById(R.id.blocksintime);
- view.setTag(holder);
- }
-
- ViewHolder holder = (ViewHolder) view.getTag();
-
- double total = res.count * res.length;
- String size = OpenVPNService.humanReadableByteCount((long) res.length, false, mContext.getResources());
-
- holder.blocksize.setText(size);
- holder.ciphername.setText(res.algorithm);
-
- if (res.failed) {
- holder.blocksInTime.setText(R.string.openssl_error);
- holder.speed.setText("-");
- } else if (res.running) {
- holder.blocksInTime.setText(R.string.running_test);
- holder.speed.setText("-");
- } else {
- String totalBytes = OpenVPNService.humanReadableByteCount((long) total, false, mContext.getResources());
- // TODO: Fix localisation here
- String blockPerSec = OpenVPNService.humanReadableByteCount((long) (total / res.time), false, mContext.getResources()) + "/s";
- holder.speed.setText(blockPerSec);
- holder.blocksInTime.setText(String.format(Locale.ENGLISH, "%d blocks (%s) in %2.1fs", (long) res.count, totalBytes, res.time));
- }
-
- return view;
-
- }
- }
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.openssl_speed);
- getActionBar().setDisplayHomeAsUpEnabled(true);
-
- findViewById(R.id.testSpecific).setOnClickListener((view) -> {
- runAlgorithms(mCipher.getText().toString());
- });
- mCipher = (EditText) findViewById(R.id.ciphername);
-
- mListView = findViewById(R.id.results);
-
- mAdapter = new SpeedArrayAdapter(this);
- mListView.setAdapter(mAdapter);
-
- }
-
- private void runAlgorithms(String algorithms) {
- if (runTestAlgorithms != null)
- runTestAlgorithms.cancel(true);
- runTestAlgorithms = new SpeeedTest();
- runTestAlgorithms.execute(algorithms.split(" "));
- }
-
-
- static class SpeedResult {
- String algorithm;
- boolean failed = false;
-
- double count;
- double time;
- int length;
- public boolean running=true;
-
- SpeedResult(String algorithm) {
- this.algorithm = algorithm;
- }
- }
-
-
- private class SpeeedTest extends AsyncTask<String, SpeedResult, SpeedResult[]> {
-
-
- private boolean mCancel = false;
-
- @Override
- protected SpeedResult[] doInBackground(String... strings) {
- Vector<SpeedResult> mResult = new Vector<>();
-
- for (String algorithm : strings) {
-
- // Skip 16b and 16k as they are not relevevant for VPN
- for (int i = 1; i < NativeUtils.openSSLlengths.length -1 && !mCancel; i++) {
- SpeedResult result = new SpeedResult(algorithm);
- result.length = NativeUtils.openSSLlengths[i];
- mResult.add(result);
- publishProgress(result);
- double[] resi = NativeUtils.getOpenSSLSpeed(algorithm, i);
- if (resi == null) {
- result.failed = true;
- } else {
- result.count = resi[1];
- result.time = resi[2];
- }
- result.running = false;
- publishProgress(result);
- }
- }
-
- return mResult.toArray(new SpeedResult[mResult.size()]);
-
- }
-
- @Override
- protected void onProgressUpdate(SpeedResult... values) {
- for (SpeedResult r : values) {
- if (r.running)
- mAdapter.add(r);
- mAdapter.notifyDataSetChanged();
- }
- }
-
- @Override
- protected void onPostExecute(SpeedResult[] speedResult) {
-
- }
-
- @Override
- protected void onCancelled(SpeedResult[] speedResults) {
- mCancel = true;
- }
- }
-
-
-}
diff --git a/main/src/ui/java/de/blinkt/openvpn/activities/OpenSSLSpeed.kt b/main/src/ui/java/de/blinkt/openvpn/activities/OpenSSLSpeed.kt
new file mode 100644
index 00000000..429d5aa4
--- /dev/null
+++ b/main/src/ui/java/de/blinkt/openvpn/activities/OpenSSLSpeed.kt
@@ -0,0 +1,178 @@
+/*
+ * Copyright (c) 2012-2017 Arne Schwabe
+ * Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
+ */
+
+package de.blinkt.openvpn.activities
+
+import android.content.Context
+import android.os.AsyncTask
+import android.os.Bundle
+import android.app.Activity
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.widget.ArrayAdapter
+import android.widget.EditText
+import android.widget.ListView
+import android.widget.TextView
+
+import java.util.Locale
+import java.util.Vector
+
+import de.blinkt.openvpn.R
+import de.blinkt.openvpn.core.NativeUtils
+import de.blinkt.openvpn.core.OpenVPNService
+
+class OpenSSLSpeed : BaseActivity() {
+ private lateinit var mCipher: EditText
+ private lateinit var mAdapter: SpeedArrayAdapter
+ private lateinit var mListView: ListView
+
+
+ internal class SpeedArrayAdapter(private val mContext: Context) : ArrayAdapter<SpeedResult>(mContext, 0) {
+ private val mInflater: LayoutInflater
+
+ init {
+ mInflater = LayoutInflater.from(mContext)
+
+ }
+
+ internal data class ViewHolder(
+ var ciphername: TextView,
+ var speed: TextView,
+ var blocksize: TextView,
+ var blocksInTime: TextView
+ )
+
+ override fun getView(position: Int, v: View?, parent: ViewGroup): View {
+ var view = v
+ val res = getItem(position)
+ if (view == null) {
+ view = mInflater.inflate(R.layout.speedviewitem, parent, false)!!
+ val holder = ViewHolder(
+ view.findViewById(R.id.ciphername),
+ view.findViewById(R.id.speed),
+ view.findViewById(R.id.blocksize),
+ view.findViewById(R.id.blocksintime))
+ view.tag = holder
+ }
+
+ val holder = view.tag as ViewHolder
+
+ val total = res!!.count * res.length
+ val size = OpenVPNService.humanReadableByteCount(res.length.toLong(), false, mContext.resources)
+
+ holder.blocksize.text = size
+ holder.ciphername.text = res.algorithm
+
+ if (res.failed) {
+ holder.blocksInTime.setText(R.string.openssl_error)
+ holder.speed.text = "-"
+ } else if (res.running) {
+ holder.blocksInTime.setText(R.string.running_test)
+ holder.speed.text = "-"
+ } else {
+ val totalBytes = OpenVPNService.humanReadableByteCount(total.toLong(), false, mContext.resources)
+ // TODO: Fix localisation here
+ val blockPerSec = OpenVPNService.humanReadableByteCount((total / res.time).toLong(), false, mContext.resources) + "/s"
+ holder.speed.text = blockPerSec
+ holder.blocksInTime.text = String.format(Locale.ENGLISH, "%d blocks (%s) in %2.1fs", res.count.toLong(), totalBytes, res.time)
+ }
+
+ return view
+
+ }
+ }
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.openssl_speed)
+ supportActionBar!!.setDisplayHomeAsUpEnabled(true)
+
+ findViewById<View>(R.id.testSpecific).setOnClickListener { _ -> runAlgorithms(mCipher.text.toString()) }
+ mCipher = findViewById<View>(R.id.ciphername) as EditText
+
+ mListView = findViewById(R.id.results)
+
+ mAdapter = SpeedArrayAdapter(this)
+ mListView.adapter = mAdapter
+
+ }
+
+ private fun runAlgorithms(algorithms: String) {
+ if (runTestAlgorithms != null)
+ runTestAlgorithms!!.cancel(true)
+ runTestAlgorithms = SpeeedTest()
+ runTestAlgorithms!!.execute(*algorithms.split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray())
+ }
+
+
+ internal class SpeedResult(var algorithm: String) {
+ var failed = false
+
+ var count: Double = 0.toDouble()
+ var time: Double = 0.toDouble()
+ var length: Int = 0
+ var running = true
+ }
+
+
+ private inner class SpeeedTest : AsyncTask<String, SpeedResult, Array<SpeedResult>>() {
+
+
+ private var mCancel = false
+
+ override fun doInBackground(vararg strings: String): Array<SpeedResult> {
+ val mResult = Vector<SpeedResult>()
+
+ for (algorithm in strings) {
+
+ // Skip 16b and 16k as they are not relevevant for VPN
+ var i = 1
+ while (i < NativeUtils.openSSLlengths.size - 1 && !mCancel) {
+ val result = SpeedResult(algorithm)
+ result.length = NativeUtils.openSSLlengths[i]
+ mResult.add(result)
+ publishProgress(result)
+ val resi = NativeUtils.getOpenSSLSpeed(algorithm, i)
+ if (resi == null) {
+ result.failed = true
+ } else {
+ result.count = resi[1]
+ result.time = resi[2]
+ }
+ result.running = false
+ publishProgress(result)
+ i++
+ }
+ }
+
+ return mResult.toTypedArray()
+
+ }
+
+ override fun onProgressUpdate(vararg values: SpeedResult) {
+ for (r in values) {
+ if (r.running)
+ mAdapter.add(r)
+ mAdapter.notifyDataSetChanged()
+ }
+ }
+
+ override fun onPostExecute(speedResult: Array<SpeedResult>) {
+
+ }
+
+ override fun onCancelled(speedResults: Array<SpeedResult>) {
+ mCancel = true
+ }
+ }
+
+ companion object {
+
+ private var runTestAlgorithms: SpeeedTest? = null
+ }
+
+
+}
diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/LogFragment.java b/main/src/ui/java/de/blinkt/openvpn/fragments/LogFragment.java
index be2007e5..994d6e95 100644
--- a/main/src/ui/java/de/blinkt/openvpn/fragments/LogFragment.java
+++ b/main/src/ui/java/de/blinkt/openvpn/fragments/LogFragment.java
@@ -22,6 +22,8 @@ import android.os.Handler;
import android.os.Handler.Callback;
import android.os.Message;
import android.preference.PreferenceManager;
+
+import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.ListFragment;
@@ -549,7 +551,7 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar.
VpnStatus.removeStateListener(this);
VpnStatus.removeByteCountListener(this);
- getActivity().getPreferences(0).edit().putInt(LOGTIMEFORMAT, ladapter.mTimeFormat)
+ requireActivity().getPreferences(0).edit().putInt(LOGTIMEFORMAT, ladapter.mTimeFormat)
.putInt(VERBOSITYLEVEL, ladapter.mLogLevel).apply();
}
@@ -562,7 +564,7 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar.
lv.setOnItemLongClickListener((parent, view, position, id) -> {
ClipboardManager clipboard = (ClipboardManager)
- getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
+ requireActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Log Entry", ((TextView) view).getText());
clipboard.setPrimaryClip(clip);
Toast.makeText(getActivity(), R.string.copied_entry, Toast.LENGTH_SHORT).show();
@@ -632,7 +634,7 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar.
}
@Override
- public void onAttach(Context activity) {
+ public void onAttach(@NonNull Context activity) {
super.onAttach(activity);
if (getResources().getBoolean(R.bool.logSildersAlwaysVisible)) {
mShowOptionsLayout = true;
@@ -644,9 +646,6 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
-
- //getActionBar().setDisplayHomeAsUpEnabled(true);
-
}
@@ -655,17 +654,13 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar.
if (isAdded()) {
final String cleanLogMessage = VpnStatus.getLastCleanLogMessage(getActivity());
- getActivity().runOnUiThread(new Runnable() {
-
- @Override
- public void run() {
- if (isAdded()) {
- if (mSpeedView != null) {
- mSpeedView.setText(cleanLogMessage);
- }
- if (mConnectStatus != null)
- mConnectStatus.setText(cleanLogMessage);
+ requireActivity().runOnUiThread(() -> {
+ if (isAdded()) {
+ if (mSpeedView != null) {
+ mSpeedView.setText(cleanLogMessage);
}
+ if (mConnectStatus != null)
+ mConnectStatus.setText(cleanLogMessage);
}
});
}
diff --git a/main/src/ui/res/values-night-v21/refs.xml b/main/src/ui/res/values-night-v21/refs.xml
deleted file mode 100644
index bc498d41..00000000
--- a/main/src/ui/res/values-night-v21/refs.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- ~ Copyright (c) 2012-2016 Arne Schwabe
- ~ Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
- -->
-
-<resources>
- <drawable name="vpn_item_edit">@drawable/ic_edit_white_24dp</drawable>
-</resources> \ No newline at end of file
diff --git a/main/src/ui/res/values-v21/refs.xml b/main/src/ui/res/values-v21/refs.xml
deleted file mode 100644
index ae9be13f..00000000
--- a/main/src/ui/res/values-v21/refs.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- ~ Copyright (c) 2012-2016 Arne Schwabe
- ~ Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
- -->
-
-<resources>
- <drawable name="ic_menu_close_clear_cancel">@drawable/ic_close_white_24dp</drawable>
- <drawable name="ic_menu_play">@drawable/ic_play_arrow_white_24dp</drawable>
- <drawable name="ic_menu_pause">@drawable/ic_pause_white_24dp</drawable>
- <drawable name="ic_menu_share">@drawable/ic_share_white_24dp </drawable>
- <drawable name="ic_menu_save">@drawable/ic_check_white_24dp</drawable>
- <drawable name="ic_menu_view">@drawable/ic_filter_list_white_24dp</drawable>
- <drawable name="ic_menu_delete">@drawable/ic_delete_white_24dp</drawable>
- <drawable name="ic_menu_copy">@drawable/ic_content_copy_white_24dp</drawable>
- <drawable name="ic_menu_delete_grey">@drawable/ic_delete_grey600_24dp</drawable>
-
- <drawable name="ic_menu_edit">@drawable/ic_edit_white_24dp</drawable>
- <drawable name="ic_menu_import">@drawable/ic_archive_white_24dp</drawable>
- <drawable name="vpn_item_edit">@drawable/ic_edit_grey600_24dp</drawable>
- <drawable name="ic_menu_add">@drawable/ic_add_circle_outline_white_24dp</drawable>
- <drawable name="ic_dialog_alert">@drawable/ic_warning_black_36dp</drawable>
- <drawable name="ic_menu_add_grey">@drawable/ic_add_circle_outline_grey600_24dp</drawable>
- <drawable name="ic_menu_import_grey">@drawable/ic_archive_grey600_24dp</drawable>
- <drawable name="ic_receipt">@drawable/ic_receipt_white_24dp</drawable>
- <drawable name="ic_sort">@drawable/ic_sort_white_24dp</drawable>
-</resources> \ No newline at end of file