From d9642aec9d4e16f35931ee507a2003bd844a296b Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Tue, 28 May 2024 14:32:36 -0300 Subject: [PATCH] Fix InstallRestriction We had a logic bug where isAllowed actually meant isDisallowed --- .../restore/install/InstallRestriction.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/stevesoltys/seedvault/restore/install/InstallRestriction.kt b/app/src/main/java/com/stevesoltys/seedvault/restore/install/InstallRestriction.kt index 577b05edb..fbe760021 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/restore/install/InstallRestriction.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/restore/install/InstallRestriction.kt @@ -6,17 +6,23 @@ package com.stevesoltys.seedvault.restore.install import android.os.UserManager +import android.os.UserManager.DISALLOW_INSTALL_APPS +import android.os.UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES +import android.os.UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY internal fun interface InstallRestriction { fun isAllowedToInstallApks(): Boolean } -private fun UserManager.isRestricted(restriction: String): Boolean { +private fun UserManager.isDisallowed(restriction: String): Boolean { return userRestrictions.getBoolean(restriction, false) } internal fun UserManager.isAllowedToInstallApks(): Boolean { - return isRestricted(UserManager.DISALLOW_INSTALL_APPS) || - isRestricted(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES) || - isRestricted(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY) + // install isn't allowed if one of those user restrictions is set + val disallowed = isDisallowed(DISALLOW_INSTALL_APPS) || + isDisallowed(DISALLOW_INSTALL_UNKNOWN_SOURCES) || + isDisallowed(DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY) + // install is allowed, if it isn't disallowed + return !disallowed }