Skip to content

Commit

Permalink
Patch crashing webview by calls from multiple processes
Browse files Browse the repository at this point in the history
  • Loading branch information
cyb3rko committed Jan 24, 2022
1 parent 23c9068 commit 105bb58
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions app/src/main/java/com/cyb3rko/logviewerforopenhab/App.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.cyb3rko.logviewerforopenhab

import android.app.ActivityManager
import android.app.Application
import android.content.Context
import android.os.Build
import android.os.Process
import android.webkit.WebView
import androidx.appcompat.app.AppCompatDelegate

class App: Application() {
Expand All @@ -9,5 +14,27 @@ class App: Application() {
super.onCreate()
val mySPR = getSharedPreferences(SHARED_PREFERENCE, MODE_PRIVATE)
AppCompatDelegate.setDefaultNightMode(mySPR.getString(NIGHTMODE, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM.toString())!!.toInt())

setWebViewDataDirectorySuffix()
}

private fun setWebViewDataDirectorySuffix() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
val processName = getProcessName(this)
if (processName != "com.cyb3rko.logviewerforopenhab" && processName != null) {
WebView.setDataDirectorySuffix(processName)
}
}
}

private fun getProcessName(context: Context?): String? {
if (context == null) return null
val manager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
for (processInfo in manager.runningAppProcesses) {
if (processInfo.pid == Process.myPid()) {
return processInfo.processName
}
}
return null
}
}

0 comments on commit 105bb58

Please sign in to comment.