diff --git a/src/com/github/shadowsocks/Shadowsocks.java b/src/com/github/shadowsocks/Shadowsocks.java index 0d36aec0..aae5bc7c 100755 --- a/src/com/github/shadowsocks/Shadowsocks.java +++ b/src/com/github/shadowsocks/Shadowsocks.java @@ -495,11 +495,7 @@ public class Shadowsocks extends PreferenceActivity implements public boolean serviceStart() { if (ShadowsocksService.isServiceStarted()) { - try { - stopService(new Intent(this, ShadowsocksService.class)); - } catch (Exception e) { - // Nothing - } + stopService(new Intent(this, ShadowsocksService.class)); return false; } @@ -510,29 +506,6 @@ public class Shadowsocks extends PreferenceActivity implements if (isTextEmpty(proxy, getString(R.string.proxy_empty))) return false; - if (proxy.contains("proxyofmax.appspot.com")) { - final TextView message = new TextView(this); - message.setPadding(10, 5, 10, 5); - final SpannableString s = new SpannableString( - getText(R.string.default_proxy_alert)); - Linkify.addLinks(s, Linkify.WEB_URLS); - message.setText(s); - message.setMovementMethod(LinkMovementMethod.getInstance()); - - new AlertDialog.Builder(this) - .setTitle(R.string.warning) - .setCancelable(false) - .setIcon(android.R.drawable.ic_dialog_info) - .setNegativeButton(getString(R.string.ok_iknow), - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, - int id) { - dialog.cancel(); - } - }).setView(message).create().show(); - } - String portText = settings.getString("port", ""); if (isTextEmpty(portText, getString(R.string.port_empty))) return false; @@ -547,13 +520,8 @@ public class Shadowsocks extends PreferenceActivity implements return false; } - try { - Intent it = new Intent(this, ShadowsocksService.class); - startService(it); - } catch (Exception e) { - // Nothing - return false; - } + Intent it = new Intent(this, ShadowsocksService.class); + startService(it); return true; } diff --git a/src/com/github/shadowsocks/ShadowsocksService.java b/src/com/github/shadowsocks/ShadowsocksService.java index a5e5ee57..facb4214 100755 --- a/src/com/github/shadowsocks/ShadowsocksService.java +++ b/src/com/github/shadowsocks/ShadowsocksService.java @@ -60,6 +60,8 @@ import java.io.*; import java.lang.ref.WeakReference; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.net.InetAddress; +import java.net.UnknownHostException; import java.util.HashSet; public class ShadowsocksService extends Service { @@ -254,6 +256,20 @@ public class ShadowsocksService extends Service { @Override public void run() { + boolean resolved = false; + + if (appHost != null) { + InetAddress addr = null; + try { + addr = InetAddress.getByName(appHost); + } catch (UnknownHostException ignored) { + } + if (addr != null) { + appHost = addr.getHostAddress(); + resolved = true; + } + } + handler.sendEmptyMessage(MSG_CONNECT_START); Log.d(TAG, "IPTABLES: " + Utils.getIptables()); @@ -261,7 +277,7 @@ public class ShadowsocksService extends Service { // Test for Redirect Support hasRedirectSupport = Utils.getHasRedirectSupport(); - if (handleConnection()) { + if (resolved && handleConnection()) { // Connection and forward successful notifyAlert(getString(R.string.forward_success), getString(R.string.service_running)); @@ -510,10 +526,10 @@ public class ShadowsocksService extends Service { String cmd_bypass = Utils.getIptables() + CMD_IPTABLES_RETURN; init_sb.append(cmd_bypass.replace("-d 0.0.0.0", "--dport " + remotePort)); - init_sb.append(cmd_bypass.replace("-d 0.0.0.0", "--dport " + 53)); + //init_sb.append(cmd_bypass.replace("-d 0.0.0.0", "--dport " + 53)); init_sb.append(cmd_bypass.replace("0.0.0.0", "127.0.0.1")); - init_sb.append(cmd_bypass.replace("-d 0.0.0.0", "-m owner --uid-owner " - + getApplicationInfo().uid)); + //init_sb.append(cmd_bypass.replace("-d 0.0.0.0", "-m owner --uid-owner " + //+ getApplicationInfo().uid)); if (hasRedirectSupport) { init_sb.append(Utils.getIptables()).append(" -t nat -A OUTPUT -p udp --dport 53 -j REDIRECT --to ").append(DNS_PORT).append("\n");