fix a crash on devices without tun.ko
This commit is contained in:
@@ -58,6 +58,7 @@
|
||||
<string name="service_failed">Please check your network status and try again.</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_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 -->
|
||||
<string name="ok_iknow">OK</string>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user