From 2a4736219562a868c116aca8c1c249fda45210c6 Mon Sep 17 00:00:00 2001 From: Mygod Date: Thu, 15 Sep 2016 00:11:37 +0800 Subject: [PATCH] Fix profile name not updated in ShadowsocksTileService --- .../github/shadowsocks/aidl/IShadowsocksService.aidl | 1 + .../shadowsocks/aidl/IShadowsocksServiceCallback.aidl | 2 +- .../scala/com/github/shadowsocks/BaseService.scala | 4 +++- .../github/shadowsocks/ProfileManagerActivity.scala | 4 ++-- .../scala/com/github/shadowsocks/Shadowsocks.scala | 2 +- .../github/shadowsocks/ShadowsocksNotification.scala | 2 +- .../github/shadowsocks/ShadowsocksTileService.scala | 10 +++------- 7 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/main/aidl/com/github/shadowsocks/aidl/IShadowsocksService.aidl b/src/main/aidl/com/github/shadowsocks/aidl/IShadowsocksService.aidl index d8999810..94e732e3 100644 --- a/src/main/aidl/com/github/shadowsocks/aidl/IShadowsocksService.aidl +++ b/src/main/aidl/com/github/shadowsocks/aidl/IShadowsocksService.aidl @@ -4,6 +4,7 @@ import com.github.shadowsocks.aidl.IShadowsocksServiceCallback; interface IShadowsocksService { int getState(); + String getProfileName(); oneway void registerCallback(IShadowsocksServiceCallback cb); oneway void unregisterCallback(IShadowsocksServiceCallback cb); diff --git a/src/main/aidl/com/github/shadowsocks/aidl/IShadowsocksServiceCallback.aidl b/src/main/aidl/com/github/shadowsocks/aidl/IShadowsocksServiceCallback.aidl index 8718118d..d3b5d05d 100644 --- a/src/main/aidl/com/github/shadowsocks/aidl/IShadowsocksServiceCallback.aidl +++ b/src/main/aidl/com/github/shadowsocks/aidl/IShadowsocksServiceCallback.aidl @@ -1,6 +1,6 @@ package com.github.shadowsocks.aidl; interface IShadowsocksServiceCallback { - oneway void stateChanged(int state, String msg); + oneway void stateChanged(int state, String profileName, String msg); oneway void trafficUpdated(long txRate, long rxRate, long txTotal, long rxTotal); } diff --git a/src/main/scala/com/github/shadowsocks/BaseService.scala b/src/main/scala/com/github/shadowsocks/BaseService.scala index 7f726718..56a61351 100644 --- a/src/main/scala/com/github/shadowsocks/BaseService.scala +++ b/src/main/scala/com/github/shadowsocks/BaseService.scala @@ -91,6 +91,8 @@ trait BaseService extends Service { state } + override def getProfileName: String = if (profile == null) null else profile.name + override def unregisterCallback(cb: IShadowsocksServiceCallback) { if (cb != null && callbacks.unregister(cb)) { callbacksCount -= 1 @@ -282,7 +284,7 @@ trait BaseService extends Service { val n = callbacks.beginBroadcast() for (i <- 0 until n) { try { - callbacks.getBroadcastItem(i).stateChanged(s, msg) + callbacks.getBroadcastItem(i).stateChanged(s, binder.getProfileName, msg) } catch { case _: Exception => // Ignore } diff --git a/src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala b/src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala index 185d54e3..e7ba61b8 100644 --- a/src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala +++ b/src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala @@ -235,7 +235,7 @@ final class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClic }).attachToRecyclerView(profilesList) attachService(new IShadowsocksServiceCallback.Stub { - def stateChanged(state: Int, msg: String) = () // ignore + def stateChanged(state: Int, profileName: String, msg: String) = () // ignore def trafficUpdated(txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long) = if (selectedItem != null) selectedItem.updateText(txTotal, rxTotal) }) @@ -276,7 +276,7 @@ final class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClic updateNfcState() } - override def onNewIntent(intent: Intent): Unit ={ + override def onNewIntent(intent: Intent) { super.onNewIntent(intent) handleShareIntent(intent) } diff --git a/src/main/scala/com/github/shadowsocks/Shadowsocks.scala b/src/main/scala/com/github/shadowsocks/Shadowsocks.scala index 90abd27b..5f3a3fbc 100644 --- a/src/main/scala/com/github/shadowsocks/Shadowsocks.scala +++ b/src/main/scala/com/github/shadowsocks/Shadowsocks.scala @@ -111,7 +111,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext { // Services private val callback = new IShadowsocksServiceCallback.Stub { - def stateChanged(s: Int, m: String) { + def stateChanged(s: Int, profileName: String, m: String) { handler.post(() => { s match { case State.CONNECTING => diff --git a/src/main/scala/com/github/shadowsocks/ShadowsocksNotification.scala b/src/main/scala/com/github/shadowsocks/ShadowsocksNotification.scala index f80389cc..3fc2f914 100644 --- a/src/main/scala/com/github/shadowsocks/ShadowsocksNotification.scala +++ b/src/main/scala/com/github/shadowsocks/ShadowsocksNotification.scala @@ -19,7 +19,7 @@ class ShadowsocksNotification(private val service: BaseService, profileName: Str private val keyGuard = service.getSystemService(Context.KEYGUARD_SERVICE).asInstanceOf[KeyguardManager] private lazy val nm = service.getSystemService(Context.NOTIFICATION_SERVICE).asInstanceOf[NotificationManager] private lazy val callback = new Stub { - override def stateChanged(state: Int, msg: String) = () // ignore + override def stateChanged(state: Int, profileName: String, msg: String) = () // ignore override def trafficUpdated(txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long) { val txr = TrafficMonitor.formatTraffic(txRate) val rxr = TrafficMonitor.formatTraffic(rxRate) diff --git a/src/main/scala/com/github/shadowsocks/ShadowsocksTileService.scala b/src/main/scala/com/github/shadowsocks/ShadowsocksTileService.scala index bb74a8a8..59a5766c 100644 --- a/src/main/scala/com/github/shadowsocks/ShadowsocksTileService.scala +++ b/src/main/scala/com/github/shadowsocks/ShadowsocksTileService.scala @@ -5,7 +5,6 @@ import android.graphics.drawable.Icon import android.service.quicksettings.{Tile, TileService} import com.github.shadowsocks.aidl.IShadowsocksServiceCallback import com.github.shadowsocks.utils.{State, Utils} -import com.github.shadowsocks.ShadowsocksApplication.app /** * @author Mygod @@ -23,7 +22,7 @@ final class ShadowsocksTileService extends TileService with ServiceBoundContext private lazy val iconConnected = Icon.createWithResource(this, R.drawable.ic_start_connected) private lazy val callback = new IShadowsocksServiceCallback.Stub { def trafficUpdated(txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long) = () - def stateChanged(state: Int, msg: String) { + def stateChanged(state: Int, profileName: String, msg: String) { val tile = getQsTile if (tile != null) { state match { @@ -33,10 +32,7 @@ final class ShadowsocksTileService extends TileService with ServiceBoundContext tile.setState(Tile.STATE_INACTIVE) case State.CONNECTED => tile.setIcon(iconConnected) - tile.setLabel(app.currentProfile match { - case Some(profile) => profile.name - case None => getString(R.string.app_name) - }) + tile.setLabel(if (profileName == null) getString(R.string.app_name) else profileName) tile.setState(Tile.STATE_ACTIVE) case _ => tile.setIcon(iconBusy) @@ -48,7 +44,7 @@ final class ShadowsocksTileService extends TileService with ServiceBoundContext } } - override def onServiceConnected() = callback.stateChanged(bgService.getState, null) + override def onServiceConnected() = callback.stateChanged(bgService.getState, bgService.getProfileName, null) override def onCreate { super.onCreate