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

(cherry picked from commit 0b2794e843d499a6d1990b01a037a462c3c6466b)
This commit is contained in:
arkon 2022-04-15 13:43:54 -04:00 committed by Jobobby04
parent 3d00e85dc2
commit a4c61e49f4

View File

@ -1,5 +1,6 @@
package eu.kanade.tachiyomi
import android.annotation.SuppressLint
import android.app.ActivityManager
import android.app.Application
import android.app.PendingIntent
@ -80,6 +81,7 @@ open class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory {
private val disableIncognitoReceiver = DisableIncognitoReceiver()
@SuppressLint("LaunchActivityFromNotification")
override fun onCreate() {
super<Application>.onCreate()
// if (BuildConfig.DEBUG) Timber.plant(Timber.DebugTree())
@ -186,14 +188,20 @@ open class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory {
}
override fun getPackageName(): String {
try {
// Override the value passed as X-Requested-With in WebView requests
val stackTrace = Looper.getMainLooper().thread.stackTrace
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
// This causes freezes in Android 6/7 for some reason
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
try {
// Override the value passed as X-Requested-With in WebView requests
val stackTrace = Looper.getMainLooper().thread.stackTrace
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()
}