Implement direct boot awareness for tile service

This commit is contained in:
Mygod
2018-02-22 12:20:52 -08:00
parent 1bc49170d0
commit e21d34ee54
3 changed files with 16 additions and 3 deletions

View File

@@ -39,12 +39,15 @@
</intent-filter>
</activity>
<service android:name=".RepeaterService">
<service
android:name=".RepeaterService"
android:directBootAware="true">
</service>
<service android:name=".TetheringService">
</service>
<service
android:name=".RepeaterTileService"
android:directBootAware="true"
android:icon="@drawable/ic_quick_settings_tile_off"
android:label="@string/title_repeater"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">

View File

@@ -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() }
}

View File

@@ -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 {