From d5d219789f1f20062fac58100ec0818eb4faa0e4 Mon Sep 17 00:00:00 2001 From: Kr328 <39107975+Kr328@users.noreply.github.com> Date: Mon, 13 Apr 2020 12:15:37 +0800 Subject: [PATCH] add clone support --- .../github/kr328/clash/service/IProfileService.aidl | 1 + .../com/github/kr328/clash/service/ProfileService.kt | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/service/src/main/aidl/com/github/kr328/clash/service/IProfileService.aidl b/service/src/main/aidl/com/github/kr328/clash/service/IProfileService.aidl index 375b402..b21a58c 100644 --- a/service/src/main/aidl/com/github/kr328/clash/service/IProfileService.aidl +++ b/service/src/main/aidl/com/github/kr328/clash/service/IProfileService.aidl @@ -6,6 +6,7 @@ import com.github.kr328.clash.service.model.ProfileMetadata; interface IProfileService { long acquireUnused(String type); + long acquireCloned(long id); void updateMetadata(long id, in ProfileMetadata metadata); void commit(long id, in IStreamCallback callback); void cancel(long id); diff --git a/service/src/main/java/com/github/kr328/clash/service/ProfileService.kt b/service/src/main/java/com/github/kr328/clash/service/ProfileService.kt index 9c2bf84..75fe180 100644 --- a/service/src/main/java/com/github/kr328/clash/service/ProfileService.kt +++ b/service/src/main/java/com/github/kr328/clash/service/ProfileService.kt @@ -78,6 +78,16 @@ class ProfileService : BaseService() { } } + override fun acquireCloned(id: Long): Long { + return runBlocking { + val clonedId = (ProfileDao.queryAllIds() + pending.keys).max()?.plus(1) ?: 0 + + pending[clonedId] = queryMetadataById(id) ?: return@runBlocking -1 + + clonedId + } + } + override fun queryActive(): ProfileMetadata? { return runBlocking { ProfileDao.queryActive()?.toProfileMetadata(service)