forked from seedvault-app/seedvault
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
restore: Skip installing APKs if not allowed by policy
* We should not bypass the OS-wide APK install restriction. * Simply treat that as just not having the APK in the first place, since we do support that as an option. * This still lets users install apps via the store it was downloaded from, if said store is installed and allowed to install apps. * Introduce InstallRestriction to make testing easier. Co-Authored-By: Torsten Grote <[email protected]> Change-Id: Ic0a56961c9078d4dd542db5d9fc75034abb27bea
- Loading branch information
1 parent
bb562a4
commit 422e3f5
Showing
5 changed files
with
69 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 6 additions & 1 deletion
7
app/src/main/java/com/stevesoltys/seedvault/restore/install/InstallModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
package com.stevesoltys.seedvault.restore.install | ||
|
||
import android.os.UserManager | ||
import org.koin.android.ext.koin.androidContext | ||
import org.koin.dsl.module | ||
|
||
val installModule = module { | ||
factory { ApkInstaller(androidContext()) } | ||
factory { DeviceInfo(androidContext()) } | ||
factory { ApkSplitCompatibilityChecker(get()) } | ||
factory { ApkRestore(androidContext(), get(), get(), get(), get(), get()) } | ||
factory { | ||
ApkRestore(androidContext(), get(), get(), get(), get(), get()) { | ||
androidContext().getSystemService(UserManager::class.java).isAllowedToInstallApks() | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
app/src/main/java/com/stevesoltys/seedvault/restore/install/InstallRestriction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.stevesoltys.seedvault.restore.install | ||
|
||
import android.os.UserManager | ||
|
||
internal fun interface InstallRestriction { | ||
fun isAllowedToInstallApks(): Boolean | ||
} | ||
|
||
private fun UserManager.isRestricted(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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters