Update preference migration implementation

Only try to read preference through content provider when the app
is fresh install and a previous package ID is set. Also catch all
Exceptions to prevent crashing the app.

This prevents malicious settings injection and crashes when multiple
manager is installed.

Fix #3542
This commit is contained in:
topjohnwu 2020-12-09 02:07:58 -08:00
parent 039d4936cb
commit 1232113772
5 changed files with 11 additions and 10 deletions

View File

@ -12,7 +12,7 @@
<application
android:icon="@drawable/ic_launcher"
android:name="a.e"
android:allowBackup="true"
android:allowBackup="false"
tools:ignore="UnusedAttribute,GoogleAppIndexingWarning">
<!-- Splash -->

View File

@ -18,7 +18,6 @@ import com.topjohnwu.magisk.ktx.inject
import com.topjohnwu.magisk.ui.theme.Theme
import org.xmlpull.v1.XmlPullParser
import java.io.File
import java.io.IOException
import java.io.InputStream
object Config : PreferenceModel, DBConfig {
@ -159,12 +158,13 @@ object Config : PreferenceModel, DBConfig {
private const val SU_FINGERPRINT = "su_fingerprint"
fun load(pkg: String) {
try {
fun load(pkg: String?) {
// Only try to load prefs when fresh install and a previous package name is set
if (pkg != null && prefs.all.isEmpty()) runCatching {
context.contentResolver.openInputStream(Provider.PREFS_URI(pkg))?.use {
prefs.edit { parsePrefs(it) }
}
} catch (e: IOException) {}
}
prefs.edit {
// Settings migration

View File

@ -58,7 +58,7 @@ object Const {
object Key {
// intents
const val OPEN_SECTION = "section"
const val HIDDEN_PKG = "hidden_pkg"
const val PREV_PKG = "prev_pkg"
}
object Value {

View File

@ -48,10 +48,10 @@ open class SplashActivity : Activity() {
// Pre-initialize root shell
Shell.getShell()
val hiddenPackage = intent.getStringExtra(Const.Key.HIDDEN_PKG)
val prevPkg = intent.getStringExtra(Const.Key.PREV_PKG)
Config.load(hiddenPackage ?: APPLICATION_ID)
handleRepackage(hiddenPackage)
Config.load(prevPkg)
handleRepackage(prevPkg)
Notifications.setup(this)
UpdateCheckService.schedule(this)
Shortcuts.setupDynamic(this)

View File

@ -123,6 +123,7 @@ object HideAPK {
Config.suManager = pkg
grantUriPermission(pkg, APK_URI, Intent.FLAG_GRANT_READ_URI_PERMISSION)
grantUriPermission(pkg, PREFS_URI, Intent.FLAG_GRANT_READ_URI_PERMISSION)
intent.putExtra(Const.Key.PREV_PKG, packageName)
startActivity(intent)
}
@ -167,7 +168,7 @@ object HideAPK {
Config.suManager = ""
grantUriPermission(APPLICATION_ID, APK_URI, Intent.FLAG_GRANT_READ_URI_PERMISSION)
grantUriPermission(APPLICATION_ID, PREFS_URI, Intent.FLAG_GRANT_READ_URI_PERMISSION)
intent.putExtra(Const.Key.HIDDEN_PKG, packageName)
intent.putExtra(Const.Key.PREV_PKG, packageName)
startActivity(intent)
}