From 7b0af007a717c72d957ed413bb91ae17da9343a1 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Sun, 26 Nov 2017 23:41:50 -0500 Subject: New NDK and OpenSSL Speed test --- main/src/main/AndroidManifest.xml | 62 ++++--- .../java/android/support/v4n/view/ViewPager.java | 12 -- .../de/blinkt/openvpn/activities/OpenSSLSpeed.java | 192 +++++++++++++++++++++ .../java/de/blinkt/openvpn/core/NativeUtils.java | 7 + .../blinkt/openvpn/fragments/GeneralSettings.java | 5 + main/src/main/res/layout/openssl_speed.xml | 40 +++++ main/src/main/res/layout/speedviewitem.xml | 54 ++++++ main/src/main/res/values/strings.xml | 8 + main/src/main/res/values/untranslatable.xml | 6 +- main/src/main/res/xml/general_settings.xml | 4 + 10 files changed, 343 insertions(+), 47 deletions(-) create mode 100644 main/src/main/java/de/blinkt/openvpn/activities/OpenSSLSpeed.java create mode 100644 main/src/main/res/layout/openssl_speed.xml create mode 100644 main/src/main/res/layout/speedviewitem.xml (limited to 'main/src') diff --git a/main/src/main/AndroidManifest.xml b/main/src/main/AndroidManifest.xml index 925d7945..e57cf096 100644 --- a/main/src/main/AndroidManifest.xml +++ b/main/src/main/AndroidManifest.xml @@ -1,10 +1,7 @@ - - - - +--> @@ -16,6 +13,7 @@ + - - + android:permission="android.permission.BIND_VPN_SERVICE" + android:process=":openvpn"> - - - - - - - + + android:label="@string/qs_title" + android:permission="android.permission.BIND_QUICK_SETTINGS_TILE" + android:value="true"> - @@ -119,7 +112,6 @@ - @@ -130,7 +122,8 @@ android:taskAffinity=".ConfigConverter" android:uiOptions="splitActionBarWhenNarrow" tools:ignore="ExportedActivity"> - @@ -139,7 +132,8 @@ - @@ -181,8 +175,6 @@ - - - - + @@ -218,7 +209,6 @@ android:grantUriPermissions="true" tools:ignore="ExportedContentProvider" /> - + + + - + \ No newline at end of file diff --git a/main/src/main/java/android/support/v4n/view/ViewPager.java b/main/src/main/java/android/support/v4n/view/ViewPager.java index 4e44bd99..53daa70d 100644 --- a/main/src/main/java/android/support/v4n/view/ViewPager.java +++ b/main/src/main/java/android/support/v4n/view/ViewPager.java @@ -33,7 +33,6 @@ import android.support.annotation.DrawableRes; import android.support.v4.os.ParcelableCompat; import android.support.v4.os.ParcelableCompatCreatorCallbacks; import android.support.v4.view.AccessibilityDelegateCompat; -import android.support.v4.view.KeyEventCompat; import android.support.v4.view.MotionEventCompat; import android.support.v4.view.VelocityTrackerCompat; import android.support.v4.view.ViewCompat; @@ -2508,17 +2507,6 @@ public class ViewPager extends ViewGroup { case KeyEvent.KEYCODE_DPAD_RIGHT: handled = arrowScroll(FOCUS_RIGHT); break; - case KeyEvent.KEYCODE_TAB: - if (Build.VERSION.SDK_INT >= 11) { - // The focus finder had a bug handling FOCUS_FORWARD and FOCUS_BACKWARD - // before Android 3.0. Ignore the tab key on those devices. - if (KeyEventCompat.hasNoModifiers(event)) { - handled = arrowScroll(FOCUS_FORWARD); - } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) { - handled = arrowScroll(FOCUS_BACKWARD); - } - } - break; } } return handled; diff --git a/main/src/main/java/de/blinkt/openvpn/activities/OpenSSLSpeed.java b/main/src/main/java/de/blinkt/openvpn/activities/OpenSSLSpeed.java new file mode 100644 index 00000000..e10778f1 --- /dev/null +++ b/main/src/main/java/de/blinkt/openvpn/activities/OpenSSLSpeed.java @@ -0,0 +1,192 @@ +/* + * 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.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.util.Pair; +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 { + + 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 { + + + private boolean mCancel = false; + + @Override + protected SpeedResult[] doInBackground(String... strings) { + Vector mResult = new Vector<>(); + + for (String algorithm : strings) { + + for (int i = 0; i < NativeUtils.openSSLlengths.length && !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/main/java/de/blinkt/openvpn/core/NativeUtils.java b/main/src/main/java/de/blinkt/openvpn/core/NativeUtils.java index ea003d41..70c7455a 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/NativeUtils.java +++ b/main/src/main/java/de/blinkt/openvpn/core/NativeUtils.java @@ -18,6 +18,13 @@ public class NativeUtils { public static native String getNativeAPI(); + + public final static int[] openSSLlengths = { + 16, 64, 256, 1024, 8 * 1024, 16 * 1024 + }; + + public static native double[] getOpenSSLSpeed(String algorithm, int testnum); + static { System.loadLibrary("opvpnutil"); if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN) diff --git a/main/src/main/java/de/blinkt/openvpn/fragments/GeneralSettings.java b/main/src/main/java/de/blinkt/openvpn/fragments/GeneralSettings.java index 700095d7..ef49c656 100644 --- a/main/src/main/java/de/blinkt/openvpn/fragments/GeneralSettings.java +++ b/main/src/main/java/de/blinkt/openvpn/fragments/GeneralSettings.java @@ -12,6 +12,7 @@ import android.app.AlertDialog.Builder; import android.app.Dialog; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; +import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; @@ -28,6 +29,7 @@ import android.preference.PreferenceManager; import de.blinkt.openvpn.BuildConfig; import de.blinkt.openvpn.R; import de.blinkt.openvpn.VpnProfile; +import de.blinkt.openvpn.activities.OpenSSLSpeed; import de.blinkt.openvpn.api.ExternalAppDatabase; import de.blinkt.openvpn.core.ProfileManager; @@ -66,6 +68,7 @@ public class GeneralSettings extends PreferenceFragment implements OnPreferenceC Preference clearapi = findPreference("clearapi"); clearapi.setOnPreferenceClickListener(this); + findPreference("osslspeed").setOnPreferenceClickListener(this); if(devHacks.getPreferenceCount()==0) getPreferenceScreen().removePreference(devHacks); @@ -168,6 +171,8 @@ public class GeneralSettings extends PreferenceFragment implements OnPreferenceC builder.setNegativeButton(android.R.string.cancel, null); builder.setMessage(getString(R.string.clearappsdialog,getExtAppList("\n"))); builder.show(); + } else if (preference.getKey().equals("osslspeed")) { + startActivity(new Intent(getActivity(), OpenSSLSpeed.class)); } return true; diff --git a/main/src/main/res/layout/openssl_speed.xml b/main/src/main/res/layout/openssl_speed.xml new file mode 100644 index 00000000..c23d3567 --- /dev/null +++ b/main/src/main/res/layout/openssl_speed.xml @@ -0,0 +1,40 @@ + + + + + + + + + +