Skip to content

Commit b62a09b

Browse files
committed
Use WebSettingsCompat.setSafeBrowsingEnabled
1 parent 87317c6 commit b62a09b

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ dependencies {
241241
implementation "androidx.work:work-runtime-ktx:${androidxWorkVersion}"
242242
implementation "androidx.work:work-rxjava3:${androidxWorkVersion}"
243243
implementation 'com.google.android.material:material:1.11.0'
244+
implementation "androidx.webkit:webkit:1.9.0"
244245

245246
/** Third-party libraries **/
246247
// Instance state boilerplate elimination

app/src/main/java/org/schabi/newpipe/util/potoken/PoTokenWebView.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.schabi.newpipe.util.potoken
22

33
import android.content.Context
4-
import android.os.Build
54
import android.os.Handler
65
import android.os.Looper
76
import android.util.Log
@@ -10,6 +9,8 @@ import android.webkit.JavascriptInterface
109
import android.webkit.WebChromeClient
1110
import android.webkit.WebView
1211
import androidx.annotation.MainThread
12+
import androidx.webkit.WebSettingsCompat
13+
import androidx.webkit.WebViewFeature
1314
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
1415
import io.reactivex.rxjava3.core.Single
1516
import io.reactivex.rxjava3.core.SingleEmitter
@@ -31,14 +32,14 @@ class PoTokenWebView private constructor(
3132

3233
//region Initialization
3334
init {
34-
val webviewSettings = webView.settings
35+
val webViewSettings = webView.settings
3536
//noinspection SetJavaScriptEnabled we want to use JavaScript!
36-
webviewSettings.javaScriptEnabled = true
37-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
38-
webviewSettings.safeBrowsingEnabled = false
37+
webViewSettings.javaScriptEnabled = true
38+
if (WebViewFeature.isFeatureSupported(WebViewFeature.SAFE_BROWSING_ENABLE)) {
39+
WebSettingsCompat.setSafeBrowsingEnabled(webViewSettings, false)
3940
}
40-
webviewSettings.userAgentString = USER_AGENT
41-
webviewSettings.blockNetworkLoads = true // the WebView does not need internet access
41+
webViewSettings.userAgentString = USER_AGENT
42+
webViewSettings.blockNetworkLoads = true // the WebView does not need internet access
4243

4344
// so that we can run async functions and get back the result
4445
webView.addJavascriptInterface(this, JS_INTERFACE)

0 commit comments

Comments
 (0)