Commit c35a92a9 authored by Max Lv's avatar Max Lv

fix a crash

parent c05a63a7
......@@ -28,7 +28,7 @@ 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.j256.ormlite" % "ormlite-core" % "4.47",
"com.j256.ormlite" % "ormlite-android" % "4.47"
......
......@@ -44,7 +44,7 @@
<string name="forward_stop">后台服务已停止。</string>
<string name="service_failed">请检查你的网络状态后并重试。</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="port_alert">端口号应大于1024</string>
<string name="port_empty">端口号不能为空</string>
......
......@@ -57,7 +57,7 @@
<string name="forward_stop">Shadowsocks stopped.</string>
<string name="service_failed">Please check your network status and try again.</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 -->
<string name="ok_iknow">OK</string>
......
......@@ -928,8 +928,6 @@ class Shadowsocks
bgService.start(ConfigUtils.load(settings))
if (isVpnEnabled) {
val style = new Style.Builder().setBackgroundColorValue(Style.holoBlueLight).build()
val config = new Configuration.Builder().setDuration(Configuration.DURATION_LONG).build()
changeSwitch(checked = false)
}
true
......@@ -995,7 +993,6 @@ class Shadowsocks
changeSwitch(checked = false)
Crouton.cancelAllCroutons()
if (m != null) {
Crouton.cancelAllCroutons()
val style = new Style.Builder().setBackgroundColorValue(Style.holoRedLight).build()
val config = new Configuration.Builder()
.setDuration(Configuration.DURATION_LONG)
......
......@@ -254,22 +254,6 @@ class ShadowsocksNatService extends Service with BaseService {
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 = {
Log.d(TAG, "onBind")
if (Action.SERVICE == intent.getAction) {
......@@ -492,19 +476,21 @@ class ShadowsocksNatService extends Service with BaseService {
}
spawn {
if (config.proxy == "198.199.101.152") {
val holder = application.containerHolder
try {
config = ConfigUtils.getPublicConfig(getBaseContext, holder.getContainer, config)
} catch {
case ex: Exception =>
notifyAlert(getString(R.string.forward_fail), getString(R.string.service_failed))
changeState(State.STOPPED, getString(R.string.service_failed))
stopRunner()
changeState(State.STOPPED)
return
config = null
}
}
if (config != null) {
killProcesses()
var resolved: Boolean = false
......@@ -527,9 +513,9 @@ class ShadowsocksNatService extends Service with BaseService {
getString(R.string.service_running).format(config.profileName))
changeState(State.CONNECTED)
} else {
notifyAlert(getString(R.string.forward_fail), getString(R.string.service_failed))
changeState(State.STOPPED, getString(R.string.service_failed))
stopRunner()
changeState(State.STOPPED)
}
}
}
}
......
......@@ -214,18 +214,6 @@ class ShadowsocksVpnService extends VpnService with BaseService {
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 = {
val action = intent.getAction
if (VpnService.SERVICE_INTERFACE == action) {
......@@ -297,13 +285,14 @@ class ShadowsocksVpnService extends VpnService with BaseService {
config = ConfigUtils.getPublicConfig(getBaseContext, holder.getContainer, config)
} catch {
case ex: Exception =>
notifyAlert(getString(R.string.forward_fail), getString(R.string.service_failed))
changeState(State.STOPPED, getString(R.string.service_failed))
stopRunner()
changeState(State.STOPPED)
return
config = null
}
}
if (config != null) {
// reset the context
killProcesses()
......@@ -324,12 +313,12 @@ class ShadowsocksVpnService extends VpnService with BaseService {
if (resolved && handleConnection) {
changeState(State.CONNECTED)
} else {
notifyAlert(getString(R.string.forward_fail), getString(R.string.service_failed))
changeState(State.STOPPED)
changeState(State.STOPPED, getString(R.string.service_failed))
stopRunner()
}
}
}
}
override def stopRunner() {
......@@ -362,9 +351,6 @@ class ShadowsocksVpnService extends VpnService with BaseService {
unregisterReceiver(receiver)
receiver = null
}
// reset notifications
notificationManager.cancel(1)
}
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