diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2018-05-05 16:26:52 +0530 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-05-09 18:16:14 +0200 |
commit | 0b9bcf0f9e25122f9ee351aa9c889ebb01a238f5 (patch) | |
tree | e7e66720eca79145348adb82b763a0ee10685b3a /app/src/main/java/com/wireguard/android | |
parent | e2ab2210cdda2d598c213f07dbc1d1199499ffd3 (diff) |
global: Cleanup line lengths and misc lint warnings
I know we decided to ditch the idea of shutting up "Exception
thrown with empty param" warnings but this pesters me too
much and we can instead just treat this as a weird future proofing
thing if and when we end up needing the exception messages.
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app/src/main/java/com/wireguard/android')
8 files changed, 28 insertions, 16 deletions
diff --git a/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java b/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java index 3d85e30b..2507db67 100644 --- a/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java +++ b/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java @@ -10,6 +10,7 @@ import android.content.pm.PackageManager; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.app.ActivityCompat; +import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceFragmentCompat; @@ -36,7 +37,8 @@ public class SettingsActivity extends AppCompatActivity { public void ensurePermissions(final String[] permissions, final PermissionRequestCallback cb) { final List<String> needPermissions = new ArrayList<>(permissions.length); for (final String permission : permissions) { - if (ActivityCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) + if (ContextCompat.checkSelfPermission(this, permission) + != PackageManager.PERMISSION_GRANTED) needPermissions.add(permission); } if (needPermissions.isEmpty()) { @@ -47,7 +49,8 @@ public class SettingsActivity extends AppCompatActivity { } final int idx = permissionRequestCounter++; permissionRequestCallbacks.put(idx, cb); - ActivityCompat.requestPermissions(this, needPermissions.toArray(new String[needPermissions.size()]), idx); + ActivityCompat.requestPermissions(this, + needPermissions.toArray(new String[needPermissions.size()]), idx); } @Override @@ -72,7 +75,9 @@ public class SettingsActivity extends AppCompatActivity { } @Override - public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) { + public void onRequestPermissionsResult(final int requestCode, + @NonNull final String[] permissions, + @NonNull final int[] grantResults) { final PermissionRequestCallback f = permissionRequestCallbacks.get(requestCode); if (f != null) { permissionRequestCallbacks.remove(requestCode); diff --git a/app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java b/app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java index 39deaeb2..1ffcfb41 100644 --- a/app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java +++ b/app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java @@ -109,7 +109,8 @@ public final class WgQuickBackend implements Backend { try (FileOutputStream stream = new FileOutputStream(tempFile, false)) { stream.write(config.toString().getBytes(StandardCharsets.UTF_8)); } - final String command = String.format("wg-quick %s '%s'", state.toString().toLowerCase(), tempFile.getAbsolutePath()); + final String command = String.format("wg-quick %s '%s'", + state.toString().toLowerCase(), tempFile.getAbsolutePath()); final int result = rootShell.run(null, command); // noinspection ResultOfMethodCallIgnored tempFile.delete(); diff --git a/app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java b/app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java index 91d5131b..f7ed5e77 100644 --- a/app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java +++ b/app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java @@ -46,7 +46,7 @@ public class TunnelEditorFragment extends BaseFragment { binding.setConfig(new Config.Observable(config, name)); } - private void onConfigSaved(final Tunnel savedTunnel, final Config config, + private void onConfigSaved(final Tunnel savedTunnel, final Throwable throwable) { final String message; if (throwable == null) { @@ -141,7 +141,7 @@ public class TunnelEditorFragment extends BaseFragment { } else { Log.d(TAG, "Attempting to save config of " + tunnel.getName()); tunnel.setConfig(newConfig) - .whenComplete((a, b) -> onConfigSaved(tunnel, a, b)); + .whenComplete((a, b) -> onConfigSaved(tunnel, b)); } return true; default: @@ -192,7 +192,7 @@ public class TunnelEditorFragment extends BaseFragment { Log.d(TAG, message); // Now save the rest of configuration changes. Log.d(TAG, "Attempting to save config of renamed tunnel " + tunnel.getName()); - renamedTunnel.setConfig(newConfig).whenComplete((a, b) -> onConfigSaved(renamedTunnel, a, b)); + renamedTunnel.setConfig(newConfig).whenComplete((a, b) -> onConfigSaved(renamedTunnel, b)); } else { final String error = ExceptionLoggers.unwrap(throwable).getMessage(); message = getString(R.string.tunnel_rename_error, error); diff --git a/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java b/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java index f7c5ddb5..fcbadbfe 100644 --- a/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java +++ b/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java @@ -94,7 +94,8 @@ public class TunnelListFragment extends BaseFragment { asyncWorker.supplyAsync(() -> { final String[] columns = {OpenableColumns.DISPLAY_NAME}; String name = null; - try (Cursor cursor = contentResolver.query(uri, columns, null, null, null)) { + try (Cursor cursor = contentResolver.query(uri, columns, + null, null, null)) { if (cursor != null && cursor.moveToFirst() && !cursor.isNull(0)) name = cursor.getString(0); } diff --git a/app/src/main/java/com/wireguard/android/util/ClipboardUtils.java b/app/src/main/java/com/wireguard/android/util/ClipboardUtils.java index 04a5fe47..d855dc61 100644 --- a/app/src/main/java/com/wireguard/android/util/ClipboardUtils.java +++ b/app/src/main/java/com/wireguard/android/util/ClipboardUtils.java @@ -19,6 +19,7 @@ import android.widget.TextView; public final class ClipboardUtils { private ClipboardUtils() { + // Prevent instantiation } public static void copyTextView(final View view) { diff --git a/app/src/main/java/com/wireguard/android/util/ObservableKeyedArrayList.java b/app/src/main/java/com/wireguard/android/util/ObservableKeyedArrayList.java index 731af20d..70842052 100644 --- a/app/src/main/java/com/wireguard/android/util/ObservableKeyedArrayList.java +++ b/app/src/main/java/com/wireguard/android/util/ObservableKeyedArrayList.java @@ -25,28 +25,28 @@ public class ObservableKeyedArrayList<K, E extends Keyed<? extends K>> @Override public boolean add(final E e) { if (e == null) - throw new NullPointerException(); + throw new NullPointerException("Trying to add a null element"); return super.add(e); } @Override public void add(final int index, final E e) { if (e == null) - throw new NullPointerException(); + throw new NullPointerException("Trying to add a null element"); super.add(index, e); } @Override public boolean addAll(@NonNull final Collection<? extends E> c) { if (c.contains(null)) - throw new NullPointerException(); + throw new NullPointerException("Trying to add a collection with null element(s)"); return super.addAll(c); } @Override public boolean addAll(final int index, @NonNull final Collection<? extends E> c) { if (c.contains(null)) - throw new NullPointerException(); + throw new NullPointerException("Trying to add a collection with null element(s)"); return super.addAll(index, c); } @@ -100,7 +100,7 @@ public class ObservableKeyedArrayList<K, E extends Keyed<? extends K>> @Override public E set(final int index, final E e) { if (e == null) - throw new NullPointerException(); + throw new NullPointerException("Trying to set a null key"); return super.set(index, e); } } diff --git a/app/src/main/java/com/wireguard/android/util/ObservableSortedKeyedArrayList.java b/app/src/main/java/com/wireguard/android/util/ObservableSortedKeyedArrayList.java index 7e41a696..0612deb5 100644 --- a/app/src/main/java/com/wireguard/android/util/ObservableSortedKeyedArrayList.java +++ b/app/src/main/java/com/wireguard/android/util/ObservableSortedKeyedArrayList.java @@ -95,7 +95,9 @@ public class ObservableSortedKeyedArrayList<K, E extends Keyed<? extends K>> @Override public K firstKey() { if (isEmpty()) - throw new NoSuchElementException(); + // The parameter in the exception is only to shut + // lint up, we never care for the exception message. + throw new NoSuchElementException("Empty set"); return get(0).getKey(); } @@ -137,7 +139,9 @@ public class ObservableSortedKeyedArrayList<K, E extends Keyed<? extends K>> @Override public K lastKey() { if (isEmpty()) - throw new NoSuchElementException(); + // The parameter in the exception is only to shut + // lint up, we never care for the exception message. + throw new NoSuchElementException("Empty set"); return get(size() - 1).getKey(); } diff --git a/app/src/main/java/com/wireguard/android/util/RootShell.java b/app/src/main/java/com/wireguard/android/util/RootShell.java index a260c55f..7a73929c 100644 --- a/app/src/main/java/com/wireguard/android/util/RootShell.java +++ b/app/src/main/java/com/wireguard/android/util/RootShell.java @@ -50,7 +50,7 @@ public class RootShell { final File cacheDir = context.getCacheDir(); localBinaryDir = new File(cacheDir, "bin"); localTemporaryDir = new File(cacheDir, "tmp"); - preamble = String.format("export CALLING_PACKAGE=com.wireguard.android; export PATH=\"%s:$PATH\" TMPDIR='%s'; id -u\n", + preamble = String.format("export CALLING_PACKAGE=com.wireguard.android PATH=\"%s:$PATH\" TMPDIR='%s'; id -u\n", localBinaryDir, localTemporaryDir); } |