diff --git a/app/src/main/kotlin/dev/sanmer/mrepo/Compat.kt b/app/src/main/kotlin/dev/sanmer/mrepo/Compat.kt index 2299bbf8..45f97b8c 100644 --- a/app/src/main/kotlin/dev/sanmer/mrepo/Compat.kt +++ b/app/src/main/kotlin/dev/sanmer/mrepo/Compat.kt @@ -7,6 +7,7 @@ import dev.sanmer.mrepo.datastore.model.WorkingMode import dev.sanmer.mrepo.stub.IModuleManager import dev.sanmer.su.IServiceManager import dev.sanmer.su.ServiceManagerCompat +import dev.sanmer.su.ServiceManagerCompat.addService import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow import timber.log.Timber @@ -24,7 +25,11 @@ object Compat { val isAliveFlow get() = _isAliveFlow.asStateFlow() val moduleManager: IModuleManager by lazy { - ModuleManager.delegate(mService) + IModuleManager.Stub.asInterface( + mService.addService( + ModuleManager::class.java + ) + ) } private fun state(): Boolean { @@ -44,7 +49,7 @@ object Compat { } state() - } catch (e: Exception) { + } catch (e: Throwable) { Timber.e(e) mServiceOrNull = null diff --git a/app/src/main/kotlin/dev/sanmer/mrepo/viewmodel/InstallViewModel.kt b/app/src/main/kotlin/dev/sanmer/mrepo/viewmodel/InstallViewModel.kt index 7468d002..b8516b64 100644 --- a/app/src/main/kotlin/dev/sanmer/mrepo/viewmodel/InstallViewModel.kt +++ b/app/src/main/kotlin/dev/sanmer/mrepo/viewmodel/InstallViewModel.kt @@ -13,13 +13,13 @@ import dev.sanmer.mrepo.Compat import dev.sanmer.mrepo.compat.MediaStoreCompat.copyToDir import dev.sanmer.mrepo.compat.MediaStoreCompat.getPathForUri import dev.sanmer.mrepo.content.State -import dev.sanmer.mrepo.content.ThrowableWrapper import dev.sanmer.mrepo.model.local.LocalModule import dev.sanmer.mrepo.repository.LocalRepository import dev.sanmer.mrepo.repository.UserPreferencesRepository import dev.sanmer.mrepo.stub.IInstallCallback import dev.sanmer.mrepo.utils.extensions.now import dev.sanmer.mrepo.utils.extensions.tmpDir +import dev.sanmer.su.wrap.ThrowableWrapper import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch diff --git a/app/src/main/kotlin/dev/sanmer/mrepo/viewmodel/ModulesViewModel.kt b/app/src/main/kotlin/dev/sanmer/mrepo/viewmodel/ModulesViewModel.kt index 55d94790..b9b868d0 100644 --- a/app/src/main/kotlin/dev/sanmer/mrepo/viewmodel/ModulesViewModel.kt +++ b/app/src/main/kotlin/dev/sanmer/mrepo/viewmodel/ModulesViewModel.kt @@ -10,7 +10,6 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel import dev.sanmer.mrepo.Compat -import dev.sanmer.mrepo.content.ThrowableWrapper import dev.sanmer.mrepo.datastore.model.Homepage import dev.sanmer.mrepo.datastore.model.ModulesMenu import dev.sanmer.mrepo.datastore.model.Option @@ -25,6 +24,7 @@ import dev.sanmer.mrepo.service.DownloadService import dev.sanmer.mrepo.stub.IModuleOpsCallback import dev.sanmer.mrepo.ui.activity.InstallActivity import dev.sanmer.mrepo.utils.StrUtil +import dev.sanmer.su.wrap.ThrowableWrapper import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.combine diff --git a/core/src/main/aidl/dev/sanmer/mrepo/content/ThrowableWrapper.aidl b/core/src/main/aidl/dev/sanmer/mrepo/content/ThrowableWrapper.aidl deleted file mode 100644 index 31730ddd..00000000 --- a/core/src/main/aidl/dev/sanmer/mrepo/content/ThrowableWrapper.aidl +++ /dev/null @@ -1,3 +0,0 @@ -package dev.sanmer.mrepo.content; - -parcelable ThrowableWrapper; \ No newline at end of file diff --git a/core/src/main/aidl/dev/sanmer/mrepo/stub/IInstallCallback.aidl b/core/src/main/aidl/dev/sanmer/mrepo/stub/IInstallCallback.aidl index d0ee33c7..50c16463 100644 --- a/core/src/main/aidl/dev/sanmer/mrepo/stub/IInstallCallback.aidl +++ b/core/src/main/aidl/dev/sanmer/mrepo/stub/IInstallCallback.aidl @@ -1,7 +1,7 @@ package dev.sanmer.mrepo.stub; import dev.sanmer.mrepo.content.Module; -import dev.sanmer.mrepo.content.ThrowableWrapper; +import dev.sanmer.su.wrap.ThrowableWrapper; oneway interface IInstallCallback { void onStdout(String msg); diff --git a/core/src/main/aidl/dev/sanmer/mrepo/stub/IModuleOpsCallback.aidl b/core/src/main/aidl/dev/sanmer/mrepo/stub/IModuleOpsCallback.aidl index 5d6f0603..7cd848ed 100644 --- a/core/src/main/aidl/dev/sanmer/mrepo/stub/IModuleOpsCallback.aidl +++ b/core/src/main/aidl/dev/sanmer/mrepo/stub/IModuleOpsCallback.aidl @@ -1,6 +1,6 @@ package dev.sanmer.mrepo.stub; -import dev.sanmer.mrepo.content.ThrowableWrapper; +import dev.sanmer.su.wrap.ThrowableWrapper; oneway interface IModuleOpsCallback { void onSuccess(String id); diff --git a/core/src/main/kotlin/dev/sanmer/mrepo/ModuleManager.kt b/core/src/main/kotlin/dev/sanmer/mrepo/ModuleManager.kt index ea4b115d..67fda48d 100644 --- a/core/src/main/kotlin/dev/sanmer/mrepo/ModuleManager.kt +++ b/core/src/main/kotlin/dev/sanmer/mrepo/ModuleManager.kt @@ -5,25 +5,16 @@ import dev.sanmer.mrepo.impl.APatchModuleManagerImpl import dev.sanmer.mrepo.impl.KernelSUModuleManagerImpl import dev.sanmer.mrepo.impl.MagiskModuleManagerImpl import dev.sanmer.mrepo.impl.Shell.exec -import dev.sanmer.mrepo.stub.IModuleManager import dev.sanmer.su.IService import dev.sanmer.su.IServiceManager -import dev.sanmer.su.ServiceManagerCompat.delegate class ModuleManager : IService { override val name = "module" - override fun create(service: IServiceManager): IBinder = when { + override fun create(manager: IServiceManager): IBinder = when { "which magisk".exec().isSuccess -> MagiskModuleManagerImpl() "which ksud".exec().isSuccess -> KernelSUModuleManagerImpl() "which apd".exec().isSuccess -> APatchModuleManagerImpl() - else -> throw IllegalArgumentException("Unsupported platform (${service.seLinuxContext})") - } - - companion object { - fun delegate(service: IServiceManager): IModuleManager = - IModuleManager.Stub.asInterface( - service.delegate(ModuleManager::class.java) - ) + else -> throw IllegalStateException("Unsupported platform (${manager.seLinuxContext})") } } \ No newline at end of file diff --git a/core/src/main/kotlin/dev/sanmer/mrepo/content/ThrowableWrapper.kt b/core/src/main/kotlin/dev/sanmer/mrepo/content/ThrowableWrapper.kt deleted file mode 100644 index f1d06668..00000000 --- a/core/src/main/kotlin/dev/sanmer/mrepo/content/ThrowableWrapper.kt +++ /dev/null @@ -1,13 +0,0 @@ -package dev.sanmer.mrepo.content - -import android.os.Parcelable -import kotlinx.parcelize.Parcelize - -@Parcelize -data class ThrowableWrapper( - val original: Throwable -) : Parcelable { - companion object { - fun Throwable.wrap() = ThrowableWrapper(this) - } -} diff --git a/core/src/main/kotlin/dev/sanmer/mrepo/impl/APatchModuleManagerImpl.kt b/core/src/main/kotlin/dev/sanmer/mrepo/impl/APatchModuleManagerImpl.kt index f1af5c6f..8748bd99 100644 --- a/core/src/main/kotlin/dev/sanmer/mrepo/impl/APatchModuleManagerImpl.kt +++ b/core/src/main/kotlin/dev/sanmer/mrepo/impl/APatchModuleManagerImpl.kt @@ -1,10 +1,10 @@ package dev.sanmer.mrepo.impl import dev.sanmer.mrepo.Platform -import dev.sanmer.mrepo.content.ThrowableWrapper.Companion.wrap import dev.sanmer.mrepo.impl.Shell.exec import dev.sanmer.mrepo.stub.IInstallCallback import dev.sanmer.mrepo.stub.IModuleOpsCallback +import dev.sanmer.su.wrap.ThrowableWrapper.Companion.wrap import java.io.File import java.io.FileNotFoundException diff --git a/core/src/main/kotlin/dev/sanmer/mrepo/impl/BaseModuleManagerImpl.kt b/core/src/main/kotlin/dev/sanmer/mrepo/impl/BaseModuleManagerImpl.kt index 9e89d8ee..231ee97a 100644 --- a/core/src/main/kotlin/dev/sanmer/mrepo/impl/BaseModuleManagerImpl.kt +++ b/core/src/main/kotlin/dev/sanmer/mrepo/impl/BaseModuleManagerImpl.kt @@ -2,10 +2,10 @@ package dev.sanmer.mrepo.impl import dev.sanmer.mrepo.content.Module import dev.sanmer.mrepo.content.State -import dev.sanmer.mrepo.content.ThrowableWrapper.Companion.wrap import dev.sanmer.mrepo.impl.Shell.exec import dev.sanmer.mrepo.stub.IInstallCallback import dev.sanmer.mrepo.stub.IModuleManager +import dev.sanmer.su.wrap.ThrowableWrapper.Companion.wrap import java.io.File import java.util.zip.ZipFile diff --git a/core/src/main/kotlin/dev/sanmer/mrepo/impl/KernelSUModuleManagerImpl.kt b/core/src/main/kotlin/dev/sanmer/mrepo/impl/KernelSUModuleManagerImpl.kt index e9a87464..6a52a7b5 100644 --- a/core/src/main/kotlin/dev/sanmer/mrepo/impl/KernelSUModuleManagerImpl.kt +++ b/core/src/main/kotlin/dev/sanmer/mrepo/impl/KernelSUModuleManagerImpl.kt @@ -1,10 +1,10 @@ package dev.sanmer.mrepo.impl import dev.sanmer.mrepo.Platform -import dev.sanmer.mrepo.content.ThrowableWrapper.Companion.wrap import dev.sanmer.mrepo.impl.Shell.exec import dev.sanmer.mrepo.stub.IInstallCallback import dev.sanmer.mrepo.stub.IModuleOpsCallback +import dev.sanmer.su.wrap.ThrowableWrapper.Companion.wrap import java.io.File import java.io.FileNotFoundException diff --git a/core/src/main/kotlin/dev/sanmer/mrepo/impl/MagiskModuleManagerImpl.kt b/core/src/main/kotlin/dev/sanmer/mrepo/impl/MagiskModuleManagerImpl.kt index 18721b7e..b18a2349 100644 --- a/core/src/main/kotlin/dev/sanmer/mrepo/impl/MagiskModuleManagerImpl.kt +++ b/core/src/main/kotlin/dev/sanmer/mrepo/impl/MagiskModuleManagerImpl.kt @@ -1,9 +1,9 @@ package dev.sanmer.mrepo.impl import dev.sanmer.mrepo.Platform -import dev.sanmer.mrepo.content.ThrowableWrapper.Companion.wrap import dev.sanmer.mrepo.stub.IInstallCallback import dev.sanmer.mrepo.stub.IModuleOpsCallback +import dev.sanmer.su.wrap.ThrowableWrapper.Companion.wrap import java.io.File import java.io.FileNotFoundException