Commit c35a92a9 authored by Max Lv's avatar Max Lv

fix a crash

parent c05a63a7
...@@ -28,7 +28,7 @@ libraryDependencies ++= Seq( ...@@ -28,7 +28,7 @@ libraryDependencies ++= Seq(
) )
libraryDependencies ++= Seq( libraryDependencies ++= Seq(
"de.keyboardsurfer.android.widget" % "crouton" % "1.8.1" exclude("com.google.android", "support-v4"), "de.keyboardsurfer.android.widget" % "crouton" % "1.8.4" exclude("com.google.android", "support-v4"),
"com.nostra13.universalimageloader" % "universal-image-loader" % "1.8.4", "com.nostra13.universalimageloader" % "universal-image-loader" % "1.8.4",
"com.j256.ormlite" % "ormlite-core" % "4.47", "com.j256.ormlite" % "ormlite-core" % "4.47",
"com.j256.ormlite" % "ormlite-android" % "4.47" "com.j256.ormlite" % "ormlite-android" % "4.47"
......
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
<string name="forward_stop">后台服务已停止。</string> <string name="forward_stop">后台服务已停止。</string>
<string name="service_failed">请检查你的网络状态后并重试。</string> <string name="service_failed">请检查你的网络状态后并重试。</string>
<string name="stop">停止服务</string> <string name="stop">停止服务</string>
<string name="vpn_error">无法启动 VPN 服务:\"%s\"。看来和你的设备存在兼容性问题,请使用 Root 模式</string> <string name="vpn_error">无法启动服务:\"%s\"</string>
<string name="ok_iknow">确定</string> <string name="ok_iknow">确定</string>
<string name="port_alert">端口号应大于1024</string> <string name="port_alert">端口号应大于1024</string>
<string name="port_empty">端口号不能为空</string> <string name="port_empty">端口号不能为空</string>
......
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
<string name="forward_stop">Shadowsocks stopped.</string> <string name="forward_stop">Shadowsocks stopped.</string>
<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_error">Unable to start VPN service: "%s". It seems to be a compatibility issue with your device. Please consider using ROOT mode instead.</string> <string name="vpn_error">Unable to start service: "%s".</string>
<!-- alert category --> <!-- alert category -->
<string name="ok_iknow">OK</string> <string name="ok_iknow">OK</string>
......
...@@ -928,8 +928,6 @@ class Shadowsocks ...@@ -928,8 +928,6 @@ class Shadowsocks
bgService.start(ConfigUtils.load(settings)) bgService.start(ConfigUtils.load(settings))
if (isVpnEnabled) { if (isVpnEnabled) {
val style = new Style.Builder().setBackgroundColorValue(Style.holoBlueLight).build()
val config = new Configuration.Builder().setDuration(Configuration.DURATION_LONG).build()
changeSwitch(checked = false) changeSwitch(checked = false)
} }
true true
...@@ -995,7 +993,6 @@ class Shadowsocks ...@@ -995,7 +993,6 @@ class Shadowsocks
changeSwitch(checked = false) changeSwitch(checked = false)
Crouton.cancelAllCroutons() Crouton.cancelAllCroutons()
if (m != null) { if (m != null) {
Crouton.cancelAllCroutons()
val style = new Style.Builder().setBackgroundColorValue(Style.holoRedLight).build() val style = new Style.Builder().setBackgroundColorValue(Style.holoRedLight).build()
val config = new Configuration.Builder() val config = new Configuration.Builder()
.setDuration(Configuration.DURATION_LONG) .setDuration(Configuration.DURATION_LONG)
......
...@@ -254,22 +254,6 @@ class ShadowsocksNatService extends Service with BaseService { ...@@ -254,22 +254,6 @@ class ShadowsocksNatService extends Service with BaseService {
startForegroundCompat(1, builder.build) startForegroundCompat(1, builder.build)
} }
def notifyAlert(title: String, info: String) {
val openIntent: Intent = new Intent(this, classOf[Shadowsocks])
openIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
val contentIntent: PendingIntent = PendingIntent.getActivity(this, 0, openIntent, 0)
val builder: NotificationCompat.Builder = new NotificationCompat.Builder(this)
builder
.setSmallIcon(R.drawable.ic_stat_shadowsocks)
.setWhen(0)
.setTicker(title)
.setContentTitle(getString(R.string.app_name))
.setContentText(info)
.setContentIntent(contentIntent)
.setAutoCancel(true)
notificationManager.notify(1, builder.build)
}
def onBind(intent: Intent): IBinder = { def onBind(intent: Intent): IBinder = {
Log.d(TAG, "onBind") Log.d(TAG, "onBind")
if (Action.SERVICE == intent.getAction) { if (Action.SERVICE == intent.getAction) {
...@@ -492,44 +476,46 @@ class ShadowsocksNatService extends Service with BaseService { ...@@ -492,44 +476,46 @@ class ShadowsocksNatService extends Service with BaseService {
} }
spawn { spawn {
if (config.proxy == "198.199.101.152") { if (config.proxy == "198.199.101.152") {
val holder = application.containerHolder val holder = application.containerHolder
try { try {
config = ConfigUtils.getPublicConfig(getBaseContext, holder.getContainer, config) config = ConfigUtils.getPublicConfig(getBaseContext, holder.getContainer, config)
} catch { } catch {
case ex: Exception => case ex: Exception =>
notifyAlert(getString(R.string.forward_fail), getString(R.string.service_failed)) changeState(State.STOPPED, getString(R.string.service_failed))
stopRunner() stopRunner()
changeState(State.STOPPED) config = null
return
} }
} }
killProcesses() if (config != null) {
var resolved: Boolean = false killProcesses()
if (!InetAddressUtils.isIPv4Address(config.proxy) &&
!InetAddressUtils.isIPv6Address(config.proxy)) { var resolved: Boolean = false
Utils.resolve(config.proxy, enableIPv6 = true) match { if (!InetAddressUtils.isIPv4Address(config.proxy) &&
case Some(a) => !InetAddressUtils.isIPv6Address(config.proxy)) {
config.proxy = a Utils.resolve(config.proxy, enableIPv6 = true) match {
resolved = true case Some(a) =>
case None => resolved = false config.proxy = a
resolved = true
case None => resolved = false
}
} else {
resolved = true
} }
} else {
resolved = true
}
hasRedirectSupport = Utils.getHasRedirectSupport hasRedirectSupport = Utils.getHasRedirectSupport
if (resolved && handleConnection) { if (resolved && handleConnection) {
notifyForegroundAlert(getString(R.string.forward_success), notifyForegroundAlert(getString(R.string.forward_success),
getString(R.string.service_running).format(config.profileName)) getString(R.string.service_running).format(config.profileName))
changeState(State.CONNECTED) changeState(State.CONNECTED)
} else { } else {
notifyAlert(getString(R.string.forward_fail), getString(R.string.service_failed)) changeState(State.STOPPED, getString(R.string.service_failed))
stopRunner() stopRunner()
changeState(State.STOPPED) }
} }
} }
} }
......
...@@ -214,18 +214,6 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -214,18 +214,6 @@ class ShadowsocksVpnService extends VpnService with BaseService {
true true
} }
def notifyAlert(title: String, info: String) {
val builder = new NotificationCompat.Builder(this)
builder
.setSmallIcon(R.drawable.ic_stat_shadowsocks)
.setWhen(0)
.setTicker(title)
.setContentTitle(getString(R.string.app_name))
.setContentText(info)
.setAutoCancel(true)
notificationManager.notify(1, builder.build)
}
override def onBind(intent: Intent): IBinder = { override def onBind(intent: Intent): IBinder = {
val action = intent.getAction val action = intent.getAction
if (VpnService.SERVICE_INTERFACE == action) { if (VpnService.SERVICE_INTERFACE == action) {
...@@ -297,36 +285,37 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -297,36 +285,37 @@ class ShadowsocksVpnService extends VpnService with BaseService {
config = ConfigUtils.getPublicConfig(getBaseContext, holder.getContainer, config) config = ConfigUtils.getPublicConfig(getBaseContext, holder.getContainer, config)
} catch { } catch {
case ex: Exception => case ex: Exception =>
notifyAlert(getString(R.string.forward_fail), getString(R.string.service_failed)) changeState(State.STOPPED, getString(R.string.service_failed))
stopRunner() stopRunner()
changeState(State.STOPPED) config = null
return
} }
} }
// reset the context if (config != null) {
killProcesses()
// reset the context
// Resolve the server address killProcesses()
var resolved: Boolean = false
if (!InetAddressUtils.isIPv4Address(config.proxy) && // Resolve the server address
!InetAddressUtils.isIPv6Address(config.proxy)) { var resolved: Boolean = false
Utils.resolve(config.proxy, enableIPv6 = true) match { if (!InetAddressUtils.isIPv4Address(config.proxy) &&
case Some(addr) => !InetAddressUtils.isIPv6Address(config.proxy)) {
config.proxy = addr Utils.resolve(config.proxy, enableIPv6 = true) match {
resolved = true case Some(addr) =>
case None => resolved = false config.proxy = addr
resolved = true
case None => resolved = false
}
} else {
resolved = true
} }
} else {
resolved = true
}
if (resolved && handleConnection) { if (resolved && handleConnection) {
changeState(State.CONNECTED) changeState(State.CONNECTED)
} else { } else {
notifyAlert(getString(R.string.forward_fail), getString(R.string.service_failed)) changeState(State.STOPPED, getString(R.string.service_failed))
changeState(State.STOPPED) stopRunner()
stopRunner() }
} }
} }
} }
...@@ -362,9 +351,6 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -362,9 +351,6 @@ class ShadowsocksVpnService extends VpnService with BaseService {
unregisterReceiver(receiver) unregisterReceiver(receiver)
receiver = null receiver = null
} }
// reset notifications
notificationManager.cancel(1)
} }
override def stopBackgroundService() { override def stopBackgroundService() {
......
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