Skip to content

Commit

Permalink
Add option to ignore signature key when installing app
Browse files Browse the repository at this point in the history
  • Loading branch information
Iamlooker committed Jul 2, 2024
1 parent 00f93bb commit fc8a40a
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ class SettingsViewModel
}
}

fun setIgnoreSignature(enable: Boolean) {
viewModelScope.launch {
settingsRepository.setIgnoreSignature(enable)
}
}

fun setIncompatibleUpdates(enable: Boolean) {
viewModelScope.launch {
settingsRepository.enableIncompatibleVersion(enable)
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/layout/settings_page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@
android:id="@+id/unstable_updates"
layout="@layout/switch_type" />

<include
android:id="@+id/ignore_signature"
layout="@layout/switch_type" />

<include
android:id="@+id/incompatible_updates"
layout="@layout/switch_type" />
Expand Down
2 changes: 2 additions & 0 deletions core/common/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@
<string name="unsigned">Unsigned</string>
<string name="unstable_updates">Unstable updates</string>
<string name="unstable_updates_summary">Suggest installing unstable versions</string>
<string name="ignore_signature">Ignore Signature</string>
<string name="ignore_signature_summary">Ignore signature verification when installing apk, for LSPosed users or advanced users</string>
<string name="unverified">Unverified</string>
<string name="update">Update</string>
<string name="updates">Updates</string>
Expand Down

0 comments on commit fc8a40a

Please sign in to comment.