Commit 234caa15 authored by Max Lv's avatar Max Lv

fix a crash on devices without tun.ko

parent 4a51f6e4
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
<string name="service_failed">Please check your network status and try again.</string> <string name="service_failed">Please check your network status and try again.</string>
<string name="stop">Stop the service</string> <string name="stop">Stop the service</string>
<string name="vpn_status">You can only disable the VPN service through the notification bar.</string> <string name="vpn_status">You can only disable the VPN service through the notification bar.</string>
<string name="vpn_error">Unable to start VPN service: "%s". It seems a compatibility issue on your device. Please consider to use ROOT mode instead.</string>
<!-- alert category --> <!-- alert category -->
<string name="ok_iknow">OK</string> <string name="ok_iknow">OK</string>
......
...@@ -79,6 +79,8 @@ class ShadowVpnService extends VpnService { ...@@ -79,6 +79,8 @@ class ShadowVpnService extends VpnService {
val MSG_CONNECT_FAIL: Int = 3 val MSG_CONNECT_FAIL: Int = 3
val MSG_HOST_CHANGE: Int = 4 val MSG_HOST_CHANGE: Int = 4
val MSG_STOP_SELF: Int = 5 val MSG_STOP_SELF: Int = 5
val MSG_VPN_ERROR: Int = 6
val VPN_MTU = 1500 val VPN_MTU = 1500
val PRIVATE_VLAN_10 = "10.254.254.%d" val PRIVATE_VLAN_10 = "10.254.254.%d"
...@@ -107,6 +109,7 @@ class ShadowVpnService extends VpnService { ...@@ -107,6 +109,7 @@ class ShadowVpnService extends VpnService {
msg.what match { msg.what match {
case MSG_CONNECT_START => case MSG_CONNECT_START =>
ed.putBoolean("isConnecting", true) ed.putBoolean("isConnecting", true)
ed.remove("vpnError")
case MSG_CONNECT_FINISH => case MSG_CONNECT_FINISH =>
ed.putBoolean("isConnecting", false) ed.putBoolean("isConnecting", false)
case MSG_CONNECT_SUCCESS => case MSG_CONNECT_SUCCESS =>
...@@ -115,6 +118,8 @@ class ShadowVpnService extends VpnService { ...@@ -115,6 +118,8 @@ class ShadowVpnService extends VpnService {
ed.putBoolean("isRunning", false) ed.putBoolean("isRunning", false)
case MSG_HOST_CHANGE => case MSG_HOST_CHANGE =>
ed.putString("appHost", appHost) ed.putString("appHost", appHost)
case MSG_VPN_ERROR =>
if (msg.obj != null) ed.putString("vpnError", msg.obj.asInstanceOf[String])
case MSG_STOP_SELF => case MSG_STOP_SELF =>
destroy() destroy()
stopSelf() stopSelf()
...@@ -310,7 +315,19 @@ class ShadowVpnService extends VpnService { ...@@ -310,7 +315,19 @@ class ShadowVpnService extends VpnService {
} }
} }
try {
conn = builder.establish() 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) { if (conn == null) {
stopSelf() stopSelf()
return return
......
...@@ -471,16 +471,24 @@ class Shadowsocks ...@@ -471,16 +471,24 @@ class Shadowsocks
switchButton.setChecked(false) switchButton.setChecked(false)
Crouton.cancelAllCroutons() 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 (key == "isConnecting") {
if (settings.getBoolean("isConnecting", false)) { if (settings.getBoolean("isConnecting", false)) {
Log.d(Shadowsocks.TAG, "Connecting start")
if (progressDialog == null) { if (progressDialog == null) {
progressDialog = ProgressDialog.show(this, "", getString(R.string.connecting), true, true) progressDialog = ProgressDialog.show(this, "", getString(R.string.connecting), true, true)
} }
} else { } else {
Log.d(Shadowsocks.TAG, "Connecting finish")
if (progressDialog != null) { if (progressDialog != null) {
progressDialog.dismiss() progressDialog.dismiss()
progressDialog = null progressDialog = null
......
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