Limit package name overriding to Android 8+ (related to #6846)

This commit is contained in:
arkon 2022-04-15 13:43:54 -04:00
parent 554dfb5874
commit 0b2794e843

View File

@ -1,5 +1,6 @@
package eu.kanade.tachiyomi package eu.kanade.tachiyomi
import android.annotation.SuppressLint
import android.app.ActivityManager import android.app.ActivityManager
import android.app.Application import android.app.Application
import android.app.PendingIntent import android.app.PendingIntent
@ -57,6 +58,7 @@ open class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory {
private val disableIncognitoReceiver = DisableIncognitoReceiver() private val disableIncognitoReceiver = DisableIncognitoReceiver()
@SuppressLint("LaunchActivityFromNotification")
override fun onCreate() { override fun onCreate() {
super<Application>.onCreate() super<Application>.onCreate()
@ -151,14 +153,20 @@ open class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory {
} }
override fun getPackageName(): String { override fun getPackageName(): String {
try { // This causes freezes in Android 6/7 for some reason
// Override the value passed as X-Requested-With in WebView requests if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val stackTrace = Looper.getMainLooper().thread.stackTrace try {
val chromiumElement = stackTrace.find { it.className.equals("org.chromium.base.BuildInfo", ignoreCase = true) } // Override the value passed as X-Requested-With in WebView requests
if (chromiumElement?.methodName.equals("getAll", ignoreCase = true)) { val stackTrace = Looper.getMainLooper().thread.stackTrace
return WebViewUtil.SPOOF_PACKAGE_NAME val chromiumElement = stackTrace.find {
it.className.equals("org.chromium.base.BuildInfo",
ignoreCase = true)
}
if (chromiumElement?.methodName.equals("getAll", ignoreCase = true)) {
return WebViewUtil.SPOOF_PACKAGE_NAME
}
} catch (e: Exception) {
} }
} catch (e: Exception) {
} }
return super.getPackageName() return super.getPackageName()
} }