diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index a8efa503..6e27a63a 100755
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -58,6 +58,7 @@
Please check your network status and try again.
Stop the service
You can only disable the VPN service through the notification bar.
+ Unable to start VPN service: "%s". It seems a compatibility issue on your device. Please consider to use ROOT mode instead.
OK
diff --git a/src/main/scala/com/github/shadowsocks/ShadowVpnService.scala b/src/main/scala/com/github/shadowsocks/ShadowVpnService.scala
index 6ef4dc8f..5564fef3 100644
--- a/src/main/scala/com/github/shadowsocks/ShadowVpnService.scala
+++ b/src/main/scala/com/github/shadowsocks/ShadowVpnService.scala
@@ -79,6 +79,8 @@ class ShadowVpnService extends VpnService {
val MSG_CONNECT_FAIL: Int = 3
val MSG_HOST_CHANGE: Int = 4
val MSG_STOP_SELF: Int = 5
+ val MSG_VPN_ERROR: Int = 6
+
val VPN_MTU = 1500
val PRIVATE_VLAN_10 = "10.254.254.%d"
@@ -107,6 +109,7 @@ class ShadowVpnService extends VpnService {
msg.what match {
case MSG_CONNECT_START =>
ed.putBoolean("isConnecting", true)
+ ed.remove("vpnError")
case MSG_CONNECT_FINISH =>
ed.putBoolean("isConnecting", false)
case MSG_CONNECT_SUCCESS =>
@@ -115,6 +118,8 @@ class ShadowVpnService extends VpnService {
ed.putBoolean("isRunning", false)
case MSG_HOST_CHANGE =>
ed.putString("appHost", appHost)
+ case MSG_VPN_ERROR =>
+ if (msg.obj != null) ed.putString("vpnError", msg.obj.asInstanceOf[String])
case MSG_STOP_SELF =>
destroy()
stopSelf()
@@ -310,7 +315,19 @@ class ShadowVpnService extends VpnService {
}
}
- conn = builder.establish()
+ try {
+ conn = builder.establish()
+ } catch {
+ case ex: IllegalStateException => {
+ val msg = new Message()
+ msg.what = MSG_VPN_ERROR
+ msg.obj = ex.getMessage
+ handler.sendMessage(msg)
+ conn = null
+ }
+ case ex: Exception => conn = null
+ }
+
if (conn == null) {
stopSelf()
return
diff --git a/src/main/scala/com/github/shadowsocks/Shadowsocks.scala b/src/main/scala/com/github/shadowsocks/Shadowsocks.scala
index 2af8a972..659d29a7 100644
--- a/src/main/scala/com/github/shadowsocks/Shadowsocks.scala
+++ b/src/main/scala/com/github/shadowsocks/Shadowsocks.scala
@@ -471,16 +471,24 @@ class Shadowsocks
switchButton.setChecked(false)
Crouton.cancelAllCroutons()
}
+
+ val msg = settings.getString("vpnError", null)
+ if (msg != null) {
+ Crouton.cancelAllCroutons()
+ val style = new Style.Builder()
+ .setBackgroundColorValue(Style.holoRedLight)
+ .setDuration(Style.DURATION_INFINITE)
+ .build()
+ Crouton.makeText(this, getString(R.string.vpn_error).format(msg), style).show()
+ }
}
}
if (key == "isConnecting") {
if (settings.getBoolean("isConnecting", false)) {
- Log.d(Shadowsocks.TAG, "Connecting start")
if (progressDialog == null) {
progressDialog = ProgressDialog.show(this, "", getString(R.string.connecting), true, true)
}
} else {
- Log.d(Shadowsocks.TAG, "Connecting finish")
if (progressDialog != null) {
progressDialog.dismiss()
progressDialog = null
@@ -661,4 +669,4 @@ class Shadowsocks
val alert: AlertDialog = builder.create
alert.show()
}
-}
\ No newline at end of file
+}