From b8ba293ee073ce8f68df54afe8a16e18f78318f4 Mon Sep 17 00:00:00 2001 From: Mygod Date: Wed, 29 Jul 2020 03:49:58 +0800 Subject: [PATCH] Fix root server crash on certain LG Android 8.1 devices See also: https://github.com/Chainfire/librootjava/issues/20 --- mobile/src/main/java/be/mygod/vpnhotspot/App.kt | 2 +- .../src/main/java/be/mygod/vpnhotspot/root/RootManager.kt | 2 +- mobile/src/main/java/be/mygod/vpnhotspot/util/Services.kt | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/App.kt b/mobile/src/main/java/be/mygod/vpnhotspot/App.kt index 9956fcb1..9a17ac79 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/App.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/App.kt @@ -48,7 +48,7 @@ class App : Application() { deviceStorage.moveSharedPreferencesFrom(this, PreferenceManager(this).sharedPreferencesName) deviceStorage.moveDatabaseFrom(this, AppDatabase.DB_NAME) } else deviceStorage = this - Services.init(this) + Services.init { this } // overhead of debug mode is minimal: https://github.com/Kotlin/kotlinx.coroutines/blob/f528898/docs/debugging.md#debug-mode System.setProperty(DEBUG_PROPERTY_NAME, DEBUG_PROPERTY_VALUE_ON) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/root/RootManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/root/RootManager.kt index 6996861d..3e5f0c30 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/root/RootManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/root/RootManager.kt @@ -29,7 +29,7 @@ object RootManager : RootSession() { } } }) - Services.init(systemContext) + Services.init { systemContext } return null } } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/util/Services.kt b/mobile/src/main/java/be/mygod/vpnhotspot/util/Services.kt index 87750f25..03ae7e29 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/util/Services.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/util/Services.kt @@ -11,9 +11,10 @@ import timber.log.Timber @SuppressLint("LogNotTimber") object Services { - lateinit var context: Context - fun init(context: Context) { - this.context = context + private lateinit var contextInit: () -> Context + val context by lazy { contextInit() } + fun init(context: () -> Context) { + contextInit = context } val connectivity by lazy { context.getSystemService()!! }