-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #502 from chirayudesai/78-skipapk
Skip installing APKs if not allowed by policy
- Loading branch information
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