summaryrefslogtreecommitdiffhomepage
path: root/app/src
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-11-27 01:28:43 +0100
committerSamuel Holland <samuel@sholland.org>2017-11-27 01:28:43 +0100
commitb0bb46382c2887559d664f85581060748db3cd79 (patch)
treea9aedd69966fea6770987cc7d177e221798c202e /app/src
parentd43c87a869188d526a7a77c91d14673cc049defd (diff)
ConfigImporter: give updates when something goes wrong
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/com/wireguard/android/backends/VpnService.java25
1 files changed, 20 insertions, 5 deletions
diff --git a/app/src/main/java/com/wireguard/android/backends/VpnService.java b/app/src/main/java/com/wireguard/android/backends/VpnService.java
index 95736de5..8f4ba5a6 100644
--- a/app/src/main/java/com/wireguard/android/backends/VpnService.java
+++ b/app/src/main/java/com/wireguard/android/backends/VpnService.java
@@ -15,6 +15,7 @@ import android.preference.PreferenceManager;
import android.provider.OpenableColumns;
import android.service.quicksettings.TileService;
import android.util.Log;
+import android.widget.Toast;
import com.wireguard.android.QuickTileService;
import com.wireguard.android.bindings.ObservableSortedMap;
@@ -279,7 +280,7 @@ public class VpnService extends Service
}
}
- private class ConfigImporter extends AsyncTask<Uri, Void, List<File>> {
+ private class ConfigImporter extends AsyncTask<Uri, String, List<File>> {
@Override
protected List<File> doInBackground(final Uri... uris) {
final ContentResolver contentResolver = getContentResolver();
@@ -310,12 +311,14 @@ public class VpnService extends Service
name = name + ".conf";
if (!Config.isNameValid(name.substring(0, name.length() - 5))) {
Log.v(getClass().getSimpleName(), "Detected name is not valid: " + name);
- name = "ImportedConfig.conf";
+ publishProgress(name + ": Invalid config filename");
+ continue;
}
Log.d(getClass().getSimpleName(), "Mapped URI " + uri + " to file name " + name);
final File output = new File(getFilesDir(), name);
if (output.exists()) {
- Log.w(getClass().getSimpleName(), "Config file for " + uri + " already exists");
+ Log.w(getClass().getSimpleName(), "Config file " + name + " already exists");
+ publishProgress(name + " already exists");
continue;
}
try (final InputStream in = contentResolver.openInputStream(uri);
@@ -330,18 +333,24 @@ public class VpnService extends Service
files.add(output);
} catch (final IOException e) {
Log.w(getClass().getSimpleName(), "Failed to import config from " + uri, e);
+ publishProgress(name + ": " + e.getMessage());
}
}
return files;
}
@Override
+ protected void onProgressUpdate(final String... errors) {
+ Toast.makeText(getApplicationContext(), errors[0], Toast.LENGTH_SHORT).show();
+ }
+
+ @Override
protected void onPostExecute(final List<File> files) {
new ConfigLoader().execute(files.toArray(new File[files.size()]));
}
}
- private class ConfigLoader extends AsyncTask<File, Void, List<Config>> {
+ private class ConfigLoader extends AsyncTask<File, String, List<Config>> {
@Override
protected List<Config> doInBackground(final File... files) {
final List<Config> configs = new LinkedList<>();
@@ -375,12 +384,18 @@ public class VpnService extends Service
Log.w(TAG, "Could not remove " + fileName, e2);
}
Log.w(TAG, "Failed to load config from " + fileName, e);
+ publishProgress(fileName + ": " + e.getMessage());
}
}
return configs;
}
@Override
+ protected void onProgressUpdate(final String... errors) {
+ Toast.makeText(getApplicationContext(), errors[0], Toast.LENGTH_SHORT).show();
+ }
+
+ @Override
protected void onPostExecute(final List<Config> configs) {
if (configs == null)
return;
@@ -453,7 +468,7 @@ public class VpnService extends Service
if (isAddOrRename() && configurations.containsKey(newName))
throw new IllegalStateException("Configuration " + newName + " already exists");
if (newConfig.getInterface().getPublicKey() == null)
- throw new IllegalArgumentException("This configuration must have a valid keypair");
+ throw new IllegalArgumentException("This configuration needs a valid private key");
for (final Peer peer : newConfig.getPeers())
if (peer.getPublicKey() == null || peer.getPublicKey().isEmpty())
throw new IllegalArgumentException("Each peer must have a valid public key");