IClashService

This commit is contained in:
Kr328 committed 2019-11-20 17:37:12 +08:00
1 parent 4c84616797
commit 2b1c32faf7
3 files changed
+5 -4

No files matched your search

@@ -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);
@@ -31,13 +31,14 @@ class ClashService : Service() {
private val observers = mutableMapOf<String, IClashObserver>()
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)
@@ -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