Commit 70e0b399 authored by Mygod's avatar Mygod

Misc improvements for plugin design

parent 0ffae32a
...@@ -18,11 +18,8 @@ ...@@ -18,11 +18,8 @@
android:targetSdkVersion="25"/> android:targetSdkVersion="25"/>
<application <application
android:allowBackup="true"
android:name=".ShadowsocksApplication" android:name=".ShadowsocksApplication"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher"
android:backupAgent=".ShadowsocksBackupAgent" android:backupAgent=".ShadowsocksBackupAgent"
android:label="@string/app_name" android:label="@string/app_name"
android:banner="@drawable/ic_start_connected"> android:banner="@drawable/ic_start_connected">
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
<string name="connection_test_error_status_code">Error code: #%d</string> <string name="connection_test_error_status_code">Error code: #%d</string>
<!-- proxy category --> <!-- proxy category -->
<string name="proxy_cat">Server Settings</string>
<string name="profile_name">Profile Name</string> <string name="profile_name">Profile Name</string>
<string name="proxy">Server</string> <string name="proxy">Server</string>
<string name="remote_port">Remote Port</string> <string name="remote_port">Remote Port</string>
...@@ -35,7 +34,6 @@ ...@@ -35,7 +34,6 @@
<string name="enc_method">Encrypt Method</string> <string name="enc_method">Encrypt Method</string>
<!-- feature category --> <!-- feature category -->
<string name="feature_cat">Feature Settings</string>
<string name="ipv6">IPv6 Route</string> <string name="ipv6">IPv6 Route</string>
<string name="ipv6_summary">Redirect IPv6 traffic to remote</string> <string name="ipv6_summary">Redirect IPv6 traffic to remote</string>
<string name="onetime_auth">One-time Authentication</string> <string name="onetime_auth">One-time Authentication</string>
...@@ -75,8 +73,6 @@ ...@@ -75,8 +73,6 @@
<string name="profile_invalid_input">No valid profile data found.</string> <string name="profile_invalid_input">No valid profile data found.</string>
<!-- alert category --> <!-- alert category -->
<string name="yes">Yes</string>
<string name="no">No</string>
<string name="close">Close</string> <string name="close">Close</string>
<string name="profile_empty">Please select a profile</string> <string name="profile_empty">Please select a profile</string>
<string name="proxy_empty">Proxy/Password should not be empty</string> <string name="proxy_empty">Proxy/Password should not be empty</string>
...@@ -105,8 +101,6 @@ ...@@ -105,8 +101,6 @@
<!-- profile --> <!-- profile -->
<string name="profile_config">Profile config</string> <string name="profile_config">Profile config</string>
<string name="unsaved_changes_prompt">Changes not saved. Do you want to save?</string>
<string name="apply">Apply</string>
<string name="delete">Remove</string> <string name="delete">Remove</string>
<string name="delete_confirm_prompt">Are you sure you want to remove this profile?</string> <string name="delete_confirm_prompt">Are you sure you want to remove this profile?</string>
<string name="share_qr_nfc">QR code/NFC</string> <string name="share_qr_nfc">QR code/NFC</string>
......
...@@ -38,7 +38,9 @@ object PluginManager { ...@@ -38,7 +38,9 @@ object PluginManager {
case null => case null =>
case path => return path case path => return path
} catch { } catch {
case t: Throwable => if (throwable == null) throwable = t case t: Throwable =>
t.printStackTrace()
if (throwable == null) throwable = t
} }
// add other plugin types here // add other plugin types here
......
...@@ -3,6 +3,7 @@ package com.github.shadowsocks.plugin; ...@@ -3,6 +3,7 @@ package com.github.shadowsocks.plugin;
import android.text.TextUtils; import android.text.TextUtils;
import java.util.HashMap; import java.util.HashMap;
import java.util.Objects;
import java.util.StringTokenizer; import java.util.StringTokenizer;
/** /**
...@@ -23,7 +24,7 @@ public final class PluginOptions extends HashMap<String, String> { ...@@ -23,7 +24,7 @@ public final class PluginOptions extends HashMap<String, String> {
super(initialCapacity, loadFactor); super(initialCapacity, loadFactor);
} }
private PluginOptions(String options, boolean parseId) throws IllegalArgumentException { private PluginOptions(String options, boolean parseId) {
if (TextUtils.isEmpty(options)) return; if (TextUtils.isEmpty(options)) return;
final StringTokenizer tokenizer = new StringTokenizer(options, "\\=;", true); final StringTokenizer tokenizer = new StringTokenizer(options, "\\=;", true);
final StringBuilder current = new StringBuilder(); final StringBuilder current = new StringBuilder();
...@@ -31,8 +32,7 @@ public final class PluginOptions extends HashMap<String, String> { ...@@ -31,8 +32,7 @@ public final class PluginOptions extends HashMap<String, String> {
while (tokenizer.hasMoreTokens()) { while (tokenizer.hasMoreTokens()) {
String nextToken = tokenizer.nextToken(); String nextToken = tokenizer.nextToken();
if ("\\".equals(nextToken)) current.append(tokenizer.nextToken()); if ("\\".equals(nextToken)) current.append(tokenizer.nextToken());
else if ("=".equals(nextToken)) { else if ("=".equals(nextToken) && key == null) {
if (key != null) throw new IllegalArgumentException("Duplicate keys in " + options);
key = current.toString(); key = current.toString();
current.setLength(0); current.setLength(0);
} else if (";".equals(nextToken)) } else if (";".equals(nextToken))
...@@ -46,12 +46,13 @@ public final class PluginOptions extends HashMap<String, String> { ...@@ -46,12 +46,13 @@ public final class PluginOptions extends HashMap<String, String> {
put(current.toString(), null); put(current.toString(), null);
current.setLength(0); current.setLength(0);
} }
else current.append(nextToken);
} }
} }
public PluginOptions(String options) throws IllegalArgumentException { public PluginOptions(String options) {
this(options, true); this(options, true);
} }
public PluginOptions(String id, String options) throws IllegalArgumentException { public PluginOptions(String id, String options) {
this(options, false); this(options, false);
this.id = id; this.id = id;
} }
...@@ -85,4 +86,18 @@ public final class PluginOptions extends HashMap<String, String> { ...@@ -85,4 +86,18 @@ public final class PluginOptions extends HashMap<String, String> {
public String toString() { public String toString() {
return toString(true); return toString(true);
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
PluginOptions that = (PluginOptions) o;
return Objects.equals(id, that.id) && super.equals(that);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), id);
}
} }
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="proxy_cat">Server Settings</string>
<string name="feature_cat">Feature Settings</string>
<string name="unsaved_changes_prompt">Changes not saved. Do you want to save?</string>
<string name="yes">Yes</string>
<string name="no">No</string>
<string name="apply">Apply</string>
</resources>
...@@ -14,8 +14,8 @@ import android.os.ParcelFileDescriptor ...@@ -14,8 +14,8 @@ import android.os.ParcelFileDescriptor
* ... * ...
* &lt;application&gt; * &lt;application&gt;
* ... * ...
* &lt;provider android:name="com.github.shadowsocks.$PLUGIN_ID.PluginProvider" * &lt;provider android:name="com.github.shadowsocks.$PLUGIN_ID.BinaryProvider"
* android:authorities="com.github.shadowsocks.$PLUGIN_ID"&gt; * android:authorities="com.github.shadowsocks.plugin.$PLUGIN_ID"&gt;
* &lt;intent-filter&gt; * &lt;intent-filter&gt;
* &lt;category android:name="com.github.shadowsocks.plugin.CATEGORY_NATIVE_PLUGIN" /&gt; * &lt;category android:name="com.github.shadowsocks.plugin.CATEGORY_NATIVE_PLUGIN" /&gt;
* &lt;/intent-filter&gt; * &lt;/intent-filter&gt;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment