From e21d34ee5405c018c2ceed5cc22c54fdee8e6f0e Mon Sep 17 00:00:00 2001 From: Mygod Date: Thu, 22 Feb 2018 12:20:52 -0800 Subject: [PATCH] Implement direct boot awareness for tile service --- mobile/src/main/AndroidManifest.xml | 5 ++++- mobile/src/main/java/be/mygod/vpnhotspot/App.kt | 11 ++++++++++- mobile/src/main/java/be/mygod/vpnhotspot/Utils.kt | 3 ++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/mobile/src/main/AndroidManifest.xml b/mobile/src/main/AndroidManifest.xml index bd31842d..b43e1900 100644 --- a/mobile/src/main/AndroidManifest.xml +++ b/mobile/src/main/AndroidManifest.xml @@ -39,12 +39,15 @@ - + diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/App.kt b/mobile/src/main/java/be/mygod/vpnhotspot/App.kt index b3c7153f..229b63bd 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/App.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/App.kt @@ -1,8 +1,11 @@ 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.os.Build import android.os.Handler import android.preference.PreferenceManager import android.support.annotation.StringRes @@ -12,12 +15,17 @@ class App : Application() { companion object { const val ACTION_CLEAN_ROUTINGS = "be.mygod.vpnhotspot.CLEAN_ROUTINGS" + @SuppressLint("StaticFieldLeak") lateinit var app: App } override fun onCreate() { super.onCreate() app = this + if (Build.VERSION.SDK_INT >= 24) { + deviceContext = createDeviceProtectedStorageContext() + deviceContext.moveSharedPreferencesFrom(this, PreferenceManager.getDefaultSharedPreferencesName(this)) + } else deviceContext = this ServiceNotification.updateNotificationChannels() } @@ -26,8 +34,9 @@ class App : Application() { ServiceNotification.updateNotificationChannels() } + lateinit var deviceContext: Context val handler = Handler() - val pref: SharedPreferences by lazy { PreferenceManager.getDefaultSharedPreferences(this) } + val pref: SharedPreferences by lazy { PreferenceManager.getDefaultSharedPreferences(deviceContext) } fun toast(@StringRes resId: Int) = handler.post { Toast.makeText(this, resId, Toast.LENGTH_SHORT).show() } } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/Utils.kt b/mobile/src/main/java/be/mygod/vpnhotspot/Utils.kt index 17ef0999..88c7b7b0 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/Utils.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/Utils.kt @@ -43,9 +43,10 @@ fun loggerSuStream(command: String): InputStream? { val process = try { ProcessBuilder("su", "-c", command) .redirectErrorStream(true) - .directory(app.cacheDir) + .directory(app.deviceContext.cacheDir) .start() } catch (e: IOException) { + e.printStackTrace() return null } try {