From fc8a40aad92aca20a4ba0cd3212e8571e5f47325 Mon Sep 17 00:00:00 2001 From: LooKeR Date: Wed, 3 Jul 2024 03:11:09 +0530 Subject: [PATCH] Add option to ignore signature key when installing app --- .../ui/appDetail/AppDetailFragment.kt | 40 +++++++++++-------- .../ui/appDetail/AppDetailViewModel.kt | 4 ++ .../droidify/ui/settings/SettingsFragment.kt | 8 ++++ .../droidify/ui/settings/SettingsViewModel.kt | 6 +++ app/src/main/res/layout/settings_page.xml | 4 ++ core/common/src/main/res/values/strings.xml | 2 + 6 files changed, 48 insertions(+), 16 deletions(-) diff --git a/app/src/main/kotlin/com/looker/droidify/ui/appDetail/AppDetailFragment.kt b/app/src/main/kotlin/com/looker/droidify/ui/appDetail/AppDetailFragment.kt index 8e2ad74df..11a6a71d1 100644 --- a/app/src/main/kotlin/com/looker/droidify/ui/appDetail/AppDetailFragment.kt +++ b/app/src/main/kotlin/com/looker/droidify/ui/appDetail/AppDetailFragment.kt @@ -466,29 +466,37 @@ class AppDetailFragment() : ScreenFragment(), AppDetailAdapter.Callbacks { } installedItem != null && installedItem.signature != release.signature -> { - MessageDialog(Message.ReleaseSignatureMismatch).show( - childFragmentManager - ) + lifecycleScope.launch { + if (viewModel.shouldIgnoreSignature()) { + queueReleaseInstall(release, installedItem) + } else { + MessageDialog(Message.ReleaseSignatureMismatch).show(childFragmentManager) + } + } } else -> { - val productRepository = - products.asSequence().filter { (product, _) -> - product.releases.any { it === release } - }.firstOrNull() - if (productRepository != null) { - downloadConnection.binder?.enqueue( - viewModel.packageName, - productRepository.first.name, - productRepository.second, - release, - installedItem != null - ) - } + queueReleaseInstall(release, installedItem) } } } + private fun queueReleaseInstall(release: Release, installedItem: InstalledItem?) { + val productRepository = + products.asSequence().filter { (product, _) -> + product.releases.any { it === release } + }.firstOrNull() + if (productRepository != null) { + downloadConnection.binder?.enqueue( + viewModel.packageName, + productRepository.first.name, + productRepository.second, + release, + installedItem != null + ) + } + } + override fun onRequestAddRepository(address: String) { screenActivity.navigateAddRepository(address) } diff --git a/app/src/main/kotlin/com/looker/droidify/ui/appDetail/AppDetailViewModel.kt b/app/src/main/kotlin/com/looker/droidify/ui/appDetail/AppDetailViewModel.kt index d6054efa2..77b12a5a2 100644 --- a/app/src/main/kotlin/com/looker/droidify/ui/appDetail/AppDetailViewModel.kt +++ b/app/src/main/kotlin/com/looker/droidify/ui/appDetail/AppDetailViewModel.kt @@ -62,6 +62,10 @@ class AppDetailViewModel @Inject constructor( ) }.asStateFlow(AppDetailUiState()) + suspend fun shouldIgnoreSignature(): Boolean { + return settingsRepository.getInitial().ignoreSignature + } + fun setFavouriteState() { viewModelScope.launch { settingsRepository.toggleFavourites(packageName) diff --git a/app/src/main/kotlin/com/looker/droidify/ui/settings/SettingsFragment.kt b/app/src/main/kotlin/com/looker/droidify/ui/settings/SettingsFragment.kt index 0e1806c62..043345ff3 100644 --- a/app/src/main/kotlin/com/looker/droidify/ui/settings/SettingsFragment.kt +++ b/app/src/main/kotlin/com/looker/droidify/ui/settings/SettingsFragment.kt @@ -153,6 +153,11 @@ class SettingsFragment : Fragment() { contentText = getString(CommonR.string.unstable_updates_summary), setting = viewModel.getInitialSetting { unstableUpdate } ) + ignoreSignature.connect( + titleText = getString(CommonR.string.ignore_signature), + contentText = getString(CommonR.string.ignore_signature_summary), + setting = viewModel.getInitialSetting { ignoreSignature } + ) incompatibleUpdates.connect( titleText = getString(CommonR.string.incompatible_versions), contentText = getString(CommonR.string.incompatible_versions_summary), @@ -349,6 +354,9 @@ class SettingsFragment : Fragment() { unstableUpdates.checked.setOnCheckedChangeListener { _, checked -> viewModel.setUnstableUpdates(checked) } + ignoreSignature.checked.setOnCheckedChangeListener { _, checked -> + viewModel.setIgnoreSignature(checked) + } incompatibleUpdates.checked.setOnCheckedChangeListener { _, checked -> viewModel.setIncompatibleUpdates(checked) } diff --git a/app/src/main/kotlin/com/looker/droidify/ui/settings/SettingsViewModel.kt b/app/src/main/kotlin/com/looker/droidify/ui/settings/SettingsViewModel.kt index db06689c4..3e4a58161 100644 --- a/app/src/main/kotlin/com/looker/droidify/ui/settings/SettingsViewModel.kt +++ b/app/src/main/kotlin/com/looker/droidify/ui/settings/SettingsViewModel.kt @@ -125,6 +125,12 @@ class SettingsViewModel } } + fun setIgnoreSignature(enable: Boolean) { + viewModelScope.launch { + settingsRepository.setIgnoreSignature(enable) + } + } + fun setIncompatibleUpdates(enable: Boolean) { viewModelScope.launch { settingsRepository.enableIncompatibleVersion(enable) diff --git a/app/src/main/res/layout/settings_page.xml b/app/src/main/res/layout/settings_page.xml index 91f3b4150..7005048cd 100644 --- a/app/src/main/res/layout/settings_page.xml +++ b/app/src/main/res/layout/settings_page.xml @@ -102,6 +102,10 @@ android:id="@+id/unstable_updates" layout="@layout/switch_type" /> + + diff --git a/core/common/src/main/res/values/strings.xml b/core/common/src/main/res/values/strings.xml index 393c4785a..3e8ec94ce 100644 --- a/core/common/src/main/res/values/strings.xml +++ b/core/common/src/main/res/values/strings.xml @@ -213,6 +213,8 @@ Unsigned Unstable updates Suggest installing unstable versions + Ignore Signature + Ignore signature verification when installing apk, for LSPosed users or advanced users Unverified Update Updates