From e8c390b56a71686ab2bbdb9113be2e97f53c6413 Mon Sep 17 00:00:00 2001 From: Malathi Gottam Date: Tue, 22 Aug 2023 02:04:24 +0530 Subject: Use encoder capabilities for determining screen recording size Using decoder capabilities for determining max size and rate can cause failure during screen record as encoder might not be capable of supporting it. As encoder supported size and rate are implicitly supported by decoder, recordings will be playable on device. CRs-Fixed: 3593702 Change-Id: I5c9eb491df248e6150cc956574ab609102db9ac9 --- .../com/android/systemui/screenrecord/ScreenMediaRecorder.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenMediaRecorder.java b/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenMediaRecorder.java index b8d96f774e02..3b4f28accd3e 100644 --- a/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenMediaRecorder.java +++ b/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenMediaRecorder.java @@ -209,11 +209,13 @@ public class ScreenMediaRecorder extends MediaProjection.Callback { throws IOException { String videoType = MediaFormat.MIMETYPE_VIDEO_AVC; - // Get max size from the decoder, to ensure recordings will be playable on device - MediaCodec decoder = MediaCodec.createDecoderByType(videoType); - MediaCodecInfo.VideoCapabilities vc = decoder.getCodecInfo() + // Get max size from the encoder, + // implicitly decoder supports this size and + // ensure recordings will be playable on device + MediaCodec encoder = MediaCodec.createEncoderByType(videoType); + MediaCodecInfo.VideoCapabilities vc = encoder.getCodecInfo() .getCapabilitiesForType(videoType).getVideoCapabilities(); - decoder.release(); + encoder.release(); // Check if we can support screen size as-is int width = vc.getSupportedWidths().getUpper(); -- cgit v1.2.3 From 7b6f178b98aaf4b01c9778e652b34ab99e1fc4f5 Mon Sep 17 00:00:00 2001 From: SongFerngWang Date: Fri, 2 Jun 2023 06:48:49 +0800 Subject: Add the limitaion for broadcast name The framework's limitaion is 0-254, and add it for broadcast name Bug: 278507301 Test: build pass and atest MediaOutputBroadcastDialogTest CRs-Fixed: 3574613 Change-Id: I3e6673a1200b208bc726e8537daa97b49be7c351 (cherry picked from commit cd4e8304aa0a33613be6a37222926d77aa902c39) --- packages/SystemUI/res/values/strings.xml | 4 +- .../media/dialog/MediaOutputBroadcastDialog.java | 98 ++++++++++++++++++++-- 2 files changed, 95 insertions(+), 7 deletions(-) diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index 09013b761ede..631e459a7b40 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -2497,8 +2497,8 @@ Can\u2019t save. Use at least 4 characters - - Use fewer than 16 characters + + Use fewer than %1$d characters Build number diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialog.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialog.java index a1b8992d2983..1c9bfb0a4acd 100644 --- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialog.java +++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialog.java @@ -20,6 +20,8 @@ import android.app.AlertDialog; import android.content.Context; import android.graphics.Bitmap; import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; import android.text.method.HideReturnsTransformationMethod; import android.text.method.PasswordTransformationMethod; import android.util.Log; @@ -34,6 +36,7 @@ import android.widget.TextView; import androidx.core.graphics.drawable.IconCompat; +import com.android.internal.annotations.VisibleForTesting; import com.android.settingslib.qrcode.QrCodeGenerator; import com.android.systemui.R; import com.android.systemui.broadcast.BroadcastSender; @@ -49,6 +52,17 @@ import com.google.zxing.WriterException; public class MediaOutputBroadcastDialog extends MediaOutputBaseDialog { private static final String TAG = "BroadcastDialog"; + static final int METADATA_BROADCAST_NAME = 0; + static final int METADATA_BROADCAST_CODE = 1; + + private static final int MAX_BROADCAST_INFO_UPDATE = 3; + @VisibleForTesting + static final int BROADCAST_CODE_MAX_LENGTH = 16; + @VisibleForTesting + static final int BROADCAST_CODE_MIN_LENGTH = 4; + @VisibleForTesting + static final int BROADCAST_NAME_MAX_LENGTH = 254; + private ViewStub mBroadcastInfoArea; private ImageView mBroadcastQrCodeView; private ImageView mBroadcastNotify; @@ -58,17 +72,89 @@ public class MediaOutputBroadcastDialog extends MediaOutputBaseDialog { private ImageView mBroadcastCodeEye; private Boolean mIsPasswordHide = true; private ImageView mBroadcastCodeEdit; - private AlertDialog mAlertDialog; + @VisibleForTesting + AlertDialog mAlertDialog; private TextView mBroadcastErrorMessage; private int mRetryCount = 0; private String mCurrentBroadcastName; private String mCurrentBroadcastCode; private boolean mIsStopbyUpdateBroadcastCode = false; - static final int METADATA_BROADCAST_NAME = 0; - static final int METADATA_BROADCAST_CODE = 1; + private TextWatcher mBroadcastCodeTextWatcher = new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + // Do nothing + } - private static final int MAX_BROADCAST_INFO_UPDATE = 3; + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + // Do nothing + } + + @Override + public void afterTextChanged(Editable s) { + if (mAlertDialog == null || mBroadcastErrorMessage == null) { + return; + } + boolean breakBroadcastCodeRuleTextLengthLessThanMin = + s.length() > 0 && s.length() < BROADCAST_CODE_MIN_LENGTH; + boolean breakBroadcastCodeRuleTextLengthMoreThanMax = + s.length() > BROADCAST_CODE_MAX_LENGTH; + boolean breakRule = breakBroadcastCodeRuleTextLengthLessThanMin + || breakBroadcastCodeRuleTextLengthMoreThanMax; + + if (breakBroadcastCodeRuleTextLengthLessThanMin) { + mBroadcastErrorMessage.setText( + R.string.media_output_broadcast_code_hint_no_less_than_min); + } else if (breakBroadcastCodeRuleTextLengthMoreThanMax) { + mBroadcastErrorMessage.setText( + mContext.getResources().getString( + R.string.media_output_broadcast_edit_hint_no_more_than_max, + BROADCAST_CODE_MAX_LENGTH)); + } + + mBroadcastErrorMessage.setVisibility(breakRule ? View.VISIBLE : View.INVISIBLE); + Button positiveBtn = mAlertDialog.getButton(AlertDialog.BUTTON_POSITIVE); + if (positiveBtn != null) { + positiveBtn.setEnabled(breakRule ? false : true); + } + } + }; + + private TextWatcher mBroadcastNameTextWatcher = new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + // Do nothing + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + // Do nothing + } + + @Override + public void afterTextChanged(Editable s) { + if (mAlertDialog == null || mBroadcastErrorMessage == null) { + return; + } + boolean breakBroadcastNameRuleTextLengthMoreThanMax = + s.length() > BROADCAST_NAME_MAX_LENGTH; + boolean breakRule = breakBroadcastNameRuleTextLengthMoreThanMax || (s.length() == 0); + + if (breakBroadcastNameRuleTextLengthMoreThanMax) { + mBroadcastErrorMessage.setText( + mContext.getResources().getString( + R.string.media_output_broadcast_edit_hint_no_more_than_max, + BROADCAST_NAME_MAX_LENGTH)); + } + mBroadcastErrorMessage.setVisibility( + breakBroadcastNameRuleTextLengthMoreThanMax ? View.VISIBLE : View.INVISIBLE); + Button positiveBtn = mAlertDialog.getButton(AlertDialog.BUTTON_POSITIVE); + if (positiveBtn != null) { + positiveBtn.setEnabled(breakRule ? false : true); + } + } + }; MediaOutputBroadcastDialog(Context context, boolean aboveStatusbar, BroadcastSender broadcastSender, MediaOutputController mediaOutputController) { @@ -225,10 +311,12 @@ public class MediaOutputBroadcastDialog extends MediaOutputBaseDialog { R.layout.media_output_broadcast_update_dialog, null); final EditText editText = layout.requireViewById(R.id.broadcast_edit_text); editText.setText(editString); + editText.addTextChangedListener( + isBroadcastCode ? mBroadcastCodeTextWatcher : mBroadcastNameTextWatcher); mBroadcastErrorMessage = layout.requireViewById(R.id.broadcast_error_message); mAlertDialog = new Builder(mContext) .setTitle(isBroadcastCode ? R.string.media_output_broadcast_code - : R.string.media_output_broadcast_name) + : R.string.media_output_broadcast_name) .setView(layout) .setNegativeButton(android.R.string.cancel, null) .setPositiveButton(R.string.media_output_broadcast_dialog_save, -- cgit v1.2.3 From ced509b78c99c4a89c71f977373cea9d068c76d8 Mon Sep 17 00:00:00 2001 From: xiaowang Date: Mon, 31 Jul 2023 16:01:54 +0800 Subject: Adjust max length of broadcast name to 32 CRs-Fixed: 3574613 Change-Id: I922c62b620ba80fdbac8237c3d440c552b4b945a --- packages/SystemUI/res/values/strings.xml | 2 +- .../com/android/systemui/media/dialog/MediaOutputBroadcastDialog.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index 631e459a7b40..46ee7e99a6ca 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -2497,7 +2497,7 @@ Can\u2019t save. Use at least 4 characters - + Use fewer than %1$d characters diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialog.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialog.java index 1c9bfb0a4acd..f9625ff579a1 100644 --- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialog.java +++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialog.java @@ -61,7 +61,7 @@ public class MediaOutputBroadcastDialog extends MediaOutputBaseDialog { @VisibleForTesting static final int BROADCAST_CODE_MIN_LENGTH = 4; @VisibleForTesting - static final int BROADCAST_NAME_MAX_LENGTH = 254; + static final int BROADCAST_NAME_MAX_LENGTH = 32; private ViewStub mBroadcastInfoArea; private ImageView mBroadcastQrCodeView; -- cgit v1.2.3