From 2b1c32faf733a170b5822100346b24fd362afb08 Mon Sep 17 00:00:00 2001 From: Kr328 <39107975+Kr328@users.noreply.github.com> Date: Wed, 20 Nov 2019 17:37:12 +0800 Subject: [PATCH] IClashService --- app/src/main/aidl/com/github/kr328/clash/IClashService.aidl | 2 +- app/src/main/java/com/github/kr328/clash/ClashService.kt | 5 +++-- app/src/main/java/com/github/kr328/clash/TunService.kt | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/aidl/com/github/kr328/clash/IClashService.aidl b/app/src/main/aidl/com/github/kr328/clash/IClashService.aidl index 7158770..5302be8 100644 --- a/app/src/main/aidl/com/github/kr328/clash/IClashService.aidl +++ b/app/src/main/aidl/com/github/kr328/clash/IClashService.aidl @@ -6,7 +6,7 @@ import com.github.kr328.clash.IClashObserver; interface IClashService { void start(); void stop(); - void registerObserver(String id, in IClashObserver observer); + void registerObserver(String id, boolean notifyCurrent, in IClashObserver observer); void unregisterObserver(String id); void loadProfile(in Uri path); void startTunDevice(in ParcelFileDescriptor fd, int mtu); diff --git a/app/src/main/java/com/github/kr328/clash/ClashService.kt b/app/src/main/java/com/github/kr328/clash/ClashService.kt index ed029a7..da76490 100644 --- a/app/src/main/java/com/github/kr328/clash/ClashService.kt +++ b/app/src/main/java/com/github/kr328/clash/ClashService.kt @@ -31,13 +31,14 @@ class ClashService : Service() { private val observers = mutableMapOf() private inner class ClashServiceImpl : IClashService.Stub() { - override fun registerObserver(id: String?, observer: IClashObserver?) { + override fun registerObserver(id: String?, notifyCurrent: Boolean, observer: IClashObserver?) { if (id == null || observer == null) throw RemoteException() observers[id] = observer - observer.onStatusChanged(ClashStatus(status)) + if ( notifyCurrent ) + observer.onStatusChanged(ClashStatus(status)) observer.asBinder().linkToDeath({ observers.remove(id) diff --git a/app/src/main/java/com/github/kr328/clash/TunService.kt b/app/src/main/java/com/github/kr328/clash/TunService.kt index b4b018f..49d44d4 100644 --- a/app/src/main/java/com/github/kr328/clash/TunService.kt +++ b/app/src/main/java/com/github/kr328/clash/TunService.kt @@ -33,7 +33,7 @@ class TunService : VpnService() { val clash = IClashService.Stub.asInterface(service) ?: throw NullPointerException() clash.start() - clash.registerObserver("tun", object: IClashObserver.Stub() { + clash.registerObserver("tun", false, object: IClashObserver.Stub() { override fun onStatusChanged(status: ClashStatus?) { if ( status == null ) return