Skip to content

Commit

Permalink
drm content support fix
Browse files Browse the repository at this point in the history
  • Loading branch information
truefedex committed Nov 27, 2022
1 parent 656974e commit 75ebf0d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ android {
applicationId = "com.phlox.tvwebbrowser"
minSdk = 21
targetSdk = 31
versionCode = 55
versionName = "1.8.3"
versionCode = 56
versionName = "1.8.4"

javaCompileOptions {
annotationProcessorOptions {
Expand Down Expand Up @@ -86,7 +86,7 @@ dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))

implementation("androidx.appcompat:appcompat:1.5.1")
implementation("androidx.webkit:webkit:1.4.0")
implementation("androidx.webkit:webkit:1.5.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("androidx.recyclerview:recyclerview:1.2.1")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.content.pm.PackageManager
import android.content.res.Configuration
import android.graphics.Bitmap
import android.graphics.Canvas
import android.media.MediaDrm
import android.net.Uri
import android.net.http.SslError
import android.os.Build
Expand All @@ -32,6 +33,8 @@ import com.phlox.tvwebbrowser.R
import com.phlox.tvwebbrowser.model.AndroidJSInterface
import com.phlox.tvwebbrowser.utils.LogUtils
import java.net.URLEncoder
import java.util.*
import kotlin.collections.ArrayList

/**
* Copyright (c) 2016 Fedir Tsapana.
Expand All @@ -43,6 +46,7 @@ class WebViewEx(context: Context, val callback: Callback, val jsInterface: Andro
const val INTERNAL_SCHEME = "internal://"
const val INTERNAL_SCHEME_WARNING_DOMAIN = "warning"
const val INTERNAL_SCHEME_WARNING_DOMAIN_TYPE_CERT = "certificate"
val WIDEVINE_UUID = UUID(-0x121074568629b532L,-0x5c37d8232ae2de13L)
}

private var webChromeClient_: WebChromeClient
Expand All @@ -53,7 +57,7 @@ class WebViewEx(context: Context, val callback: Callback, val jsInterface: Andro
private var lastTouchY: Int = 0
private var permRequestDialog: AlertDialog? = null
private var webPermissionsRequest: PermissionRequest? = null
private var reuestedResourcesForAlreadyGrantedPermissions: ArrayList<String>? = null
private var requestedWebResourcesThatDoNotNeedToGrantAndroidPermissions: ArrayList<String>? = null
private var geoPermissionOrigin: String? = null
private var geoPermissionsCallback: GeolocationPermissions.Callback? = null
var lastSSLError: SslError? = null
Expand Down Expand Up @@ -172,6 +176,20 @@ class WebViewEx(context: Context, val callback: Callback, val jsInterface: Andro
}

override fun onPermissionRequest(request: PermissionRequest) {
if (request.resources.size == 1 &&
PermissionRequest.RESOURCE_PROTECTED_MEDIA_ID == request.resources[0]) {
//fast path for grant/deny RESOURCE_PROTECTED_MEDIA_ID
if (MediaDrm.isCryptoSchemeSupported(WIDEVINE_UUID)) {
val widevineKeyDrm = MediaDrm(WIDEVINE_UUID)
val version = widevineKeyDrm.getPropertyString(MediaDrm.PROPERTY_VERSION)
Log.i(TAG, "DRM widevine version = " + version)
request.grant(request.resources)
} else {
request.deny()
}
return
}

val activity = callback.getActivity() ?: return
webPermissionsRequest = request
permRequestDialog = AlertDialog.Builder(activity)
Expand All @@ -191,31 +209,30 @@ class WebViewEx(context: Context, val callback: Callback, val jsInterface: Andro

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
val neededPermissions = ArrayList<String>()
reuestedResourcesForAlreadyGrantedPermissions = ArrayList()
val resourcesThatDoNotNeedToGrantPerms = ArrayList<String>()
for (resource in webPermissionsRequest.resources) {
if (PermissionRequest.RESOURCE_AUDIO_CAPTURE == resource) {
if (ContextCompat.checkSelfPermission(activity, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
neededPermissions.add(Manifest.permission.RECORD_AUDIO)
} else {
reuestedResourcesForAlreadyGrantedPermissions!!.add(resource)
resourcesThatDoNotNeedToGrantPerms.add(resource)
}
} else if (PermissionRequest.RESOURCE_VIDEO_CAPTURE == resource) {
if (ContextCompat.checkSelfPermission(activity, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
neededPermissions.add(Manifest.permission.CAMERA)
} else {
reuestedResourcesForAlreadyGrantedPermissions!!.add(resource)
resourcesThatDoNotNeedToGrantPerms.add(resource)
}
} else {
resourcesThatDoNotNeedToGrantPerms.add(resource)
}
}

if (neededPermissions.isNotEmpty()) {
requestedWebResourcesThatDoNotNeedToGrantAndroidPermissions = resourcesThatDoNotNeedToGrantPerms
callback.requestPermissions(neededPermissions.toTypedArray(), false)
} else {
if (reuestedResourcesForAlreadyGrantedPermissions!!.isEmpty()) {
webPermissionsRequest.deny()
} else {
webPermissionsRequest.grant(reuestedResourcesForAlreadyGrantedPermissions!!.toTypedArray())
}
webPermissionsRequest.grant(webPermissionsRequest.resources)
}
} else {
webPermissionsRequest.grant(webPermissionsRequest.resources)
Expand Down Expand Up @@ -564,9 +581,9 @@ class WebViewEx(context: Context, val callback: Callback, val jsInterface: Andro
}
}
}
reuestedResourcesForAlreadyGrantedPermissions?.apply {
requestedWebResourcesThatDoNotNeedToGrantAndroidPermissions?.apply {
resources.addAll(this)
reuestedResourcesForAlreadyGrantedPermissions = null
requestedWebResourcesThatDoNotNeedToGrantAndroidPermissions = null
}
if (resources.isEmpty()) {
this.deny()
Expand Down

0 comments on commit 75ebf0d

Please sign in to comment.