Commit 92b9c529 authored by Max Lv's avatar Max Lv

Merge branch 'master' of github.com:shadowsocks/shadowsocks-android

parents 7d01ca81 4f3ebf93
...@@ -56,6 +56,7 @@ trait BaseService extends Service { ...@@ -56,6 +56,7 @@ trait BaseService extends Service {
var trafficMonitorThread: TrafficMonitorThread = null var trafficMonitorThread: TrafficMonitorThread = null
final val callbacks = new RemoteCallbackList[IShadowsocksServiceCallback] final val callbacks = new RemoteCallbackList[IShadowsocksServiceCallback]
var callbacksCount: Int = _
val binder = new IShadowsocksService.Stub { val binder = new IShadowsocksService.Stub {
override def getMode: Int = { override def getMode: Int = {
...@@ -67,19 +68,19 @@ trait BaseService extends Service { ...@@ -67,19 +68,19 @@ trait BaseService extends Service {
} }
override def unregisterCallback(cb: IShadowsocksServiceCallback) { override def unregisterCallback(cb: IShadowsocksServiceCallback) {
if (cb != null ) { if (cb != null && callbacks.unregister(cb)) {
callbacks.unregister(cb) callbacksCount -= 1
} if (callbacksCount == 0 && timer != null) {
if (callbacks.getRegisteredCallbackCount == 0 && timer != null) { timer.cancel()
timer.cancel() timer = null
timer = null }
} }
} }
override def registerCallback(cb: IShadowsocksServiceCallback) { override def registerCallback(cb: IShadowsocksServiceCallback) {
if (cb != null) { if (cb != null && callbacks.register(cb)) {
callbacks.register(cb) callbacksCount += 1
if (callbacks.getRegisteredCallbackCount != 0 && timer == null) { if (callbacksCount != 0 && timer == null) {
val task = new TimerTask { val task = new TimerTask {
def run { def run {
if (TrafficMonitor.updateRate()) updateTrafficRate() if (TrafficMonitor.updateRate()) updateTrafficRate()
...@@ -160,7 +161,7 @@ trait BaseService extends Service { ...@@ -160,7 +161,7 @@ trait BaseService extends Service {
def updateTrafficRate() { def updateTrafficRate() {
val handler = new Handler(getContext.getMainLooper) val handler = new Handler(getContext.getMainLooper)
handler.post(() => { handler.post(() => {
if (callbacks.getRegisteredCallbackCount > 0) { if (callbacksCount > 0) {
val txRate = TrafficMonitor.getTxRate val txRate = TrafficMonitor.getTxRate
val rxRate = TrafficMonitor.getRxRate val rxRate = TrafficMonitor.getRxRate
val txTotal = TrafficMonitor.getTxTotal val txTotal = TrafficMonitor.getTxTotal
...@@ -181,7 +182,7 @@ trait BaseService extends Service { ...@@ -181,7 +182,7 @@ trait BaseService extends Service {
protected def changeState(s: Int, msg: String) { protected def changeState(s: Int, msg: String) {
val handler = new Handler(getContext.getMainLooper) val handler = new Handler(getContext.getMainLooper)
handler.post(() => if (state != s) { handler.post(() => if (state != s) {
if (callbacks.getRegisteredCallbackCount > 0) { if (callbacksCount > 0) {
val n = callbacks.beginBroadcast() val n = callbacks.beginBroadcast()
for (i <- 0 until n) { for (i <- 0 until n) {
try { try {
......
...@@ -104,7 +104,6 @@ class Shadowsocks ...@@ -104,7 +104,6 @@ class Shadowsocks
var progressDialog: ProgressDialog = _ var progressDialog: ProgressDialog = _
var progressTag = -1 var progressTag = -1
var state = State.STOPPED var state = State.STOPPED
var prepared = false
var currentProfile = new Profile var currentProfile = new Profile
var vpnEnabled = -1 var vpnEnabled = -1
var trafficCache: String = _ var trafficCache: String = _
...@@ -402,7 +401,6 @@ class Shadowsocks ...@@ -402,7 +401,6 @@ class Shadowsocks
protected override def onPause() { protected override def onPause() {
super.onPause() super.onPause()
ShadowsocksApplication.profileManager.save ShadowsocksApplication.profileManager.save
prepared = false
} }
private def stateUpdate() { private def stateUpdate() {
...@@ -517,7 +515,6 @@ class Shadowsocks ...@@ -517,7 +515,6 @@ class Shadowsocks
override def onActivityResult(requestCode: Int, resultCode: Int, data: Intent) = resultCode match { override def onActivityResult(requestCode: Int, resultCode: Int, data: Intent) = resultCode match {
case Activity.RESULT_OK => case Activity.RESULT_OK =>
prepared = true
serviceStart() serviceStart()
case _ => case _ =>
cancelStart() cancelStart()
......
...@@ -166,18 +166,16 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan ...@@ -166,18 +166,16 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
isProxyApps.setChecked(ShadowsocksApplication.settings.getBoolean(Key.isProxyApps, false)) // update isProxyApps.setChecked(ShadowsocksApplication.settings.getBoolean(Key.isProxyApps, false)) // update
} }
override def onPause { override def onDestroy {
super.onPause() super.onDestroy()
ShadowsocksApplication.settings.unregisterOnSharedPreferenceChangeListener(this) ShadowsocksApplication.settings.unregisterOnSharedPreferenceChangeListener(this)
} }
def onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) = key match { def onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) = key match {
case Key.isNAT => case Key.isNAT => activity.handler.post(() => {
activity.handler.post(() => { activity.deattachService
activity.deattachService activity.attachService
activity.attachService })
})
setEnabled(enabled)
case _ => case _ =>
} }
......
...@@ -105,17 +105,14 @@ class DBHelper(val context: Context) ...@@ -105,17 +105,14 @@ class DBHelper(val context: Context)
" ipv6, individual FROM `tmp`;") " ipv6, individual FROM `tmp`;")
profileDao.executeRawNoArgs("DROP TABLE `tmp`;") profileDao.executeRawNoArgs("DROP TABLE `tmp`;")
profileDao.executeRawNoArgs("COMMIT;") profileDao.executeRawNoArgs("COMMIT;")
return } else if (oldVersion < 13) {
}
if (oldVersion < 13) {
profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN tx LONG;") profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN tx LONG;")
profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN rx LONG;") profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN rx LONG;")
profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN date VARCHAR;") profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN date VARCHAR;")
} }
if (oldVersion < 15) { if (oldVersion < 15) {
profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN userOrder LONG;") if (oldVersion >= 12) profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN userOrder LONG;")
var i = 0 var i = 0
for (profile <- profileDao.queryForAll.asScala) { for (profile <- profileDao.queryForAll.asScala) {
if (oldVersion < 14) profile.individual = updateProxiedApps(context, profile.individual) if (oldVersion < 14) profile.individual = updateProxiedApps(context, profile.individual)
......
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