Screenrecord: Hide HEVC option when no HW codec is available
Change-Id: I1e5c265980f34a943b2466b1d84d57e009961f8d
diff --git a/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenRecordPermissionContentManager.kt b/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenRecordPermissionContentManager.kt
index 84b10c7..818c7858 100644
--- a/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenRecordPermissionContentManager.kt
+++ b/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenRecordPermissionContentManager.kt
@@ -21,6 +21,9 @@
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 @@
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 @@
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) {