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