Fix direct boot

This commit is contained in:
Mygod
2018-07-22 00:25:42 +08:00
parent 9220f9f113
commit 2578c1c6ec
5 changed files with 35 additions and 9 deletions

View File

@@ -11,7 +11,7 @@ android {
minSdkVersion 21
targetSdkVersion 28
resConfigs "zh-rCN"
versionCode 30
versionCode 31
versionName "1.3.5"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

View File

@@ -41,6 +41,9 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data android:name="firebase_crashlytics_collection_enabled"
android:value="false"/>
<activity
android:name=".MainActivity"
android:label="@string/app_name"

View File

@@ -2,7 +2,6 @@ package be.mygod.vpnhotspot
import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import android.content.SharedPreferences
import android.content.res.Configuration
import android.net.ConnectivityManager
@@ -10,10 +9,13 @@ import android.net.wifi.WifiManager
import android.os.Build
import android.os.Handler
import android.preference.PreferenceManager
import androidx.annotation.StringRes
import android.widget.Toast
import androidx.annotation.StringRes
import androidx.core.content.getSystemService
import be.mygod.vpnhotspot.util.DeviceStorageApp
import be.mygod.vpnhotspot.util.Event0
import com.crashlytics.android.Crashlytics
import io.fabric.sdk.android.Fabric
class App : Application() {
companion object {
@@ -28,9 +30,10 @@ class App : Application() {
super.onCreate()
app = this
if (Build.VERSION.SDK_INT >= 24) {
deviceContext = createDeviceProtectedStorageContext()
deviceContext.moveSharedPreferencesFrom(this, PreferenceManager.getDefaultSharedPreferencesName(this))
} else deviceContext = this
deviceStorage = DeviceStorageApp(this)
deviceStorage.moveSharedPreferencesFrom(this, PreferenceManager.getDefaultSharedPreferencesName(this))
} else deviceStorage = this
Fabric.with(deviceStorage, Crashlytics())
ServiceNotification.updateNotificationChannels()
}
@@ -39,9 +42,9 @@ class App : Application() {
ServiceNotification.updateNotificationChannels()
}
lateinit var deviceContext: Context
lateinit var deviceStorage: Application
val handler = Handler()
val pref: SharedPreferences by lazy { PreferenceManager.getDefaultSharedPreferences(deviceContext) }
val pref: SharedPreferences by lazy { PreferenceManager.getDefaultSharedPreferences(deviceStorage) }
val connectivity by lazy { getSystemService<ConnectivityManager>()!! }
val wifi by lazy { getSystemService<WifiManager>()!! }

View File

@@ -0,0 +1,20 @@
package be.mygod.vpnhotspot.util
import android.annotation.SuppressLint
import android.annotation.TargetApi
import android.app.Application
import android.content.Context
@SuppressLint("Registered")
@TargetApi(24)
class DeviceStorageApp(context: Context) : Application() {
init {
attachBaseContext(context.createDeviceProtectedStorageContext())
}
/**
* Thou shalt not get the REAL underlying application context which would no longer be operating under device
* protected storage.
*/
override fun getApplicationContext(): Context = this
}

View File

@@ -14,7 +14,7 @@ private class SuFailure : RuntimeException()
fun loggerSuStream(command: String): InputStream? {
val process = try {
ProcessBuilder("su", "-c", command)
.directory(app.deviceContext.cacheDir)
.directory(app.deviceStorage.cacheDir)
.redirectErrorStream(true)
.start()
} catch (e: IOException) {