Commit 2a473621 authored by Mygod's avatar Mygod

Fix profile name not updated in ShadowsocksTileService

parent 02d5951f
...@@ -4,6 +4,7 @@ import com.github.shadowsocks.aidl.IShadowsocksServiceCallback; ...@@ -4,6 +4,7 @@ import com.github.shadowsocks.aidl.IShadowsocksServiceCallback;
interface IShadowsocksService { interface IShadowsocksService {
int getState(); int getState();
String getProfileName();
oneway void registerCallback(IShadowsocksServiceCallback cb); oneway void registerCallback(IShadowsocksServiceCallback cb);
oneway void unregisterCallback(IShadowsocksServiceCallback cb); oneway void unregisterCallback(IShadowsocksServiceCallback cb);
......
package com.github.shadowsocks.aidl; package com.github.shadowsocks.aidl;
interface IShadowsocksServiceCallback { 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); oneway void trafficUpdated(long txRate, long rxRate, long txTotal, long rxTotal);
} }
...@@ -91,6 +91,8 @@ trait BaseService extends Service { ...@@ -91,6 +91,8 @@ trait BaseService extends Service {
state state
} }
override def getProfileName: String = if (profile == null) null else profile.name
override def unregisterCallback(cb: IShadowsocksServiceCallback) { override def unregisterCallback(cb: IShadowsocksServiceCallback) {
if (cb != null && callbacks.unregister(cb)) { if (cb != null && callbacks.unregister(cb)) {
callbacksCount -= 1 callbacksCount -= 1
...@@ -282,7 +284,7 @@ trait BaseService extends Service { ...@@ -282,7 +284,7 @@ trait BaseService extends Service {
val n = callbacks.beginBroadcast() val n = callbacks.beginBroadcast()
for (i <- 0 until n) { for (i <- 0 until n) {
try { try {
callbacks.getBroadcastItem(i).stateChanged(s, msg) callbacks.getBroadcastItem(i).stateChanged(s, binder.getProfileName, msg)
} catch { } catch {
case _: Exception => // Ignore case _: Exception => // Ignore
} }
......
...@@ -235,7 +235,7 @@ final class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClic ...@@ -235,7 +235,7 @@ final class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClic
}).attachToRecyclerView(profilesList) }).attachToRecyclerView(profilesList)
attachService(new IShadowsocksServiceCallback.Stub { 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) = def trafficUpdated(txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long) =
if (selectedItem != null) selectedItem.updateText(txTotal, rxTotal) if (selectedItem != null) selectedItem.updateText(txTotal, rxTotal)
}) })
...@@ -276,7 +276,7 @@ final class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClic ...@@ -276,7 +276,7 @@ final class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClic
updateNfcState() updateNfcState()
} }
override def onNewIntent(intent: Intent): Unit ={ override def onNewIntent(intent: Intent) {
super.onNewIntent(intent) super.onNewIntent(intent)
handleShareIntent(intent) handleShareIntent(intent)
} }
......
...@@ -111,7 +111,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext { ...@@ -111,7 +111,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
// Services // Services
private val callback = new IShadowsocksServiceCallback.Stub { private val callback = new IShadowsocksServiceCallback.Stub {
def stateChanged(s: Int, m: String) { def stateChanged(s: Int, profileName: String, m: String) {
handler.post(() => { handler.post(() => {
s match { s match {
case State.CONNECTING => case State.CONNECTING =>
......
...@@ -19,7 +19,7 @@ class ShadowsocksNotification(private val service: BaseService, profileName: Str ...@@ -19,7 +19,7 @@ class ShadowsocksNotification(private val service: BaseService, profileName: Str
private val keyGuard = service.getSystemService(Context.KEYGUARD_SERVICE).asInstanceOf[KeyguardManager] private val keyGuard = service.getSystemService(Context.KEYGUARD_SERVICE).asInstanceOf[KeyguardManager]
private lazy val nm = service.getSystemService(Context.NOTIFICATION_SERVICE).asInstanceOf[NotificationManager] private lazy val nm = service.getSystemService(Context.NOTIFICATION_SERVICE).asInstanceOf[NotificationManager]
private lazy val callback = new Stub { 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) { override def trafficUpdated(txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long) {
val txr = TrafficMonitor.formatTraffic(txRate) val txr = TrafficMonitor.formatTraffic(txRate)
val rxr = TrafficMonitor.formatTraffic(rxRate) val rxr = TrafficMonitor.formatTraffic(rxRate)
......
...@@ -5,7 +5,6 @@ import android.graphics.drawable.Icon ...@@ -5,7 +5,6 @@ import android.graphics.drawable.Icon
import android.service.quicksettings.{Tile, TileService} import android.service.quicksettings.{Tile, TileService}
import com.github.shadowsocks.aidl.IShadowsocksServiceCallback import com.github.shadowsocks.aidl.IShadowsocksServiceCallback
import com.github.shadowsocks.utils.{State, Utils} import com.github.shadowsocks.utils.{State, Utils}
import com.github.shadowsocks.ShadowsocksApplication.app
/** /**
* @author Mygod * @author Mygod
...@@ -23,7 +22,7 @@ final class ShadowsocksTileService extends TileService with ServiceBoundContext ...@@ -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 iconConnected = Icon.createWithResource(this, R.drawable.ic_start_connected)
private lazy val callback = new IShadowsocksServiceCallback.Stub { private lazy val callback = new IShadowsocksServiceCallback.Stub {
def trafficUpdated(txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long) = () 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 val tile = getQsTile
if (tile != null) { if (tile != null) {
state match { state match {
...@@ -33,10 +32,7 @@ final class ShadowsocksTileService extends TileService with ServiceBoundContext ...@@ -33,10 +32,7 @@ final class ShadowsocksTileService extends TileService with ServiceBoundContext
tile.setState(Tile.STATE_INACTIVE) tile.setState(Tile.STATE_INACTIVE)
case State.CONNECTED => case State.CONNECTED =>
tile.setIcon(iconConnected) tile.setIcon(iconConnected)
tile.setLabel(app.currentProfile match { tile.setLabel(if (profileName == null) getString(R.string.app_name) else profileName)
case Some(profile) => profile.name
case None => getString(R.string.app_name)
})
tile.setState(Tile.STATE_ACTIVE) tile.setState(Tile.STATE_ACTIVE)
case _ => case _ =>
tile.setIcon(iconBusy) tile.setIcon(iconBusy)
...@@ -48,7 +44,7 @@ final class ShadowsocksTileService extends TileService with ServiceBoundContext ...@@ -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 { override def onCreate {
super.onCreate super.onCreate
......
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