Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit e2a4c685 authored by Ido Ben-Hur's avatar Ido Ben-Hur Committed by Michael Bestas
Browse files

Screenrecord: Hide HEVC option when no HW codec is available

Change-Id: I1e5c265980f34a943b2466b1d84d57e009961f8d
parent 06124fc4
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -21,6 +21,9 @@ import android.app.Activity
import android.app.PendingIntent
import android.content.Intent
import android.hardware.display.DisplayManager
import android.media.MediaCodecInfo
import android.media.MediaCodecList
import android.media.MediaFormat
import android.os.Build
import android.os.Bundle
import android.os.Handler
@@ -186,6 +189,12 @@ class ScreenRecordPermissionContentManager(
            audioSwitch.isChecked = true
        }

        // Disable HEVC when hardware accelerated codec is not available
        if (!hasHevcHwEncoder()) {
            Prefs.putInt(userContextProvider.userContext, PREF_HEVC, 0)
            containerView.requireViewById<View>(R.id.show_hevc).visibility = View.GONE
        }

        // disable redundant Touch & Hold accessibility action for Switch Access
        options.accessibilityDelegate =
            object : View.AccessibilityDelegate() {
@@ -257,6 +266,24 @@ class ScreenRecordPermissionContentManager(
                INTERVAL_MS, startIntent, stopIntent)
    }

    private fun hasHevcHwEncoder(): Boolean {
        val mediaCodecList = MediaCodecList(MediaCodecList.REGULAR_CODECS)

        for (codecInfo in mediaCodecList.getCodecInfos()) {
            if (!codecInfo.isEncoder() || !codecInfo.isHardwareAccelerated()) {
                continue
            }

            for (type in codecInfo.getSupportedTypes()) {
                if (type.equals(MediaFormat.MIMETYPE_VIDEO_HEVC, ignoreCase = true)) {
                    return true
                }
            }
        }

        return false
    }

    private inner class CaptureTargetResultReceiver :
        ResultReceiver(Handler(Looper.getMainLooper())) {
        override fun onReceiveResult(resultCode: Int, resultData: Bundle) {