Merge "[LE] Error handling for updating the Broadcast Code and Name" into tm-dev am: 3c1b946692 am: 806069f727
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18185743 Change-Id: I2321908104189132bdabb5e206ca7e040b142745 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -76,6 +76,7 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog implements
|
|||||||
private static final String PREF_NAME = "MediaOutputDialog";
|
private static final String PREF_NAME = "MediaOutputDialog";
|
||||||
private static final String PREF_IS_LE_BROADCAST_FIRST_LAUNCH = "PrefIsLeBroadcastFirstLaunch";
|
private static final String PREF_IS_LE_BROADCAST_FIRST_LAUNCH = "PrefIsLeBroadcastFirstLaunch";
|
||||||
private static final boolean DEBUG = true;
|
private static final boolean DEBUG = true;
|
||||||
|
private static final int HANDLE_BROADCAST_FAILED_DELAY = 3000;
|
||||||
|
|
||||||
private final Handler mMainThreadHandler = new Handler(Looper.getMainLooper());
|
private final Handler mMainThreadHandler = new Handler(Looper.getMainLooper());
|
||||||
private final RecyclerView.LayoutManager mLayoutManager;
|
private final RecyclerView.LayoutManager mLayoutManager;
|
||||||
@@ -119,7 +120,7 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog implements
|
|||||||
Log.d(TAG, "onBroadcastStarted(), reason = " + reason
|
Log.d(TAG, "onBroadcastStarted(), reason = " + reason
|
||||||
+ ", broadcastId = " + broadcastId);
|
+ ", broadcastId = " + broadcastId);
|
||||||
}
|
}
|
||||||
mMainThreadHandler.post(() -> startLeBroadcastDialog());
|
mMainThreadHandler.post(() -> handleLeBroadcastStarted());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -127,7 +128,8 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog implements
|
|||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "onBroadcastStartFailed(), reason = " + reason);
|
Log.d(TAG, "onBroadcastStartFailed(), reason = " + reason);
|
||||||
}
|
}
|
||||||
handleLeBroadcastStartFailed();
|
mMainThreadHandler.postDelayed(() -> handleLeBroadcastStartFailed(),
|
||||||
|
HANDLE_BROADCAST_FAILED_DELAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -137,7 +139,7 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog implements
|
|||||||
Log.d(TAG, "onBroadcastMetadataChanged(), broadcastId = " + broadcastId
|
Log.d(TAG, "onBroadcastMetadataChanged(), broadcastId = " + broadcastId
|
||||||
+ ", metadata = " + metadata);
|
+ ", metadata = " + metadata);
|
||||||
}
|
}
|
||||||
mMainThreadHandler.post(() -> refresh());
|
mMainThreadHandler.post(() -> handleLeBroadcastMetadataChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -146,7 +148,7 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog implements
|
|||||||
Log.d(TAG, "onBroadcastStopped(), reason = " + reason
|
Log.d(TAG, "onBroadcastStopped(), reason = " + reason
|
||||||
+ ", broadcastId = " + broadcastId);
|
+ ", broadcastId = " + broadcastId);
|
||||||
}
|
}
|
||||||
mMainThreadHandler.post(() -> refresh());
|
mMainThreadHandler.post(() -> handleLeBroadcastStopped());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -154,7 +156,7 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog implements
|
|||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "onBroadcastStopFailed(), reason = " + reason);
|
Log.d(TAG, "onBroadcastStopFailed(), reason = " + reason);
|
||||||
}
|
}
|
||||||
mMainThreadHandler.post(() -> refresh());
|
mMainThreadHandler.post(() -> handleLeBroadcastStopFailed());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -163,7 +165,7 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog implements
|
|||||||
Log.d(TAG, "onBroadcastUpdated(), reason = " + reason
|
Log.d(TAG, "onBroadcastUpdated(), reason = " + reason
|
||||||
+ ", broadcastId = " + broadcastId);
|
+ ", broadcastId = " + broadcastId);
|
||||||
}
|
}
|
||||||
mMainThreadHandler.post(() -> refresh());
|
mMainThreadHandler.post(() -> handleLeBroadcastUpdated());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -172,7 +174,7 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog implements
|
|||||||
Log.d(TAG, "onBroadcastUpdateFailed(), reason = " + reason
|
Log.d(TAG, "onBroadcastUpdateFailed(), reason = " + reason
|
||||||
+ ", broadcastId = " + broadcastId);
|
+ ", broadcastId = " + broadcastId);
|
||||||
}
|
}
|
||||||
mMainThreadHandler.post(() -> refresh());
|
mMainThreadHandler.post(() -> handleLeBroadcastUpdateFailed());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -384,10 +386,34 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog implements
|
|||||||
Bitmap.createScaledBitmap(bitmap, size, size, false));
|
Bitmap.createScaledBitmap(bitmap, size, size, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleLeBroadcastStartFailed() {
|
public void handleLeBroadcastStarted() {
|
||||||
|
startLeBroadcastDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleLeBroadcastStartFailed() {
|
||||||
mStopButton.setText(R.string.media_output_broadcast_start_failed);
|
mStopButton.setText(R.string.media_output_broadcast_start_failed);
|
||||||
mStopButton.setEnabled(false);
|
mStopButton.setEnabled(false);
|
||||||
mMainThreadHandler.postDelayed(() -> refresh(), 3000);
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleLeBroadcastMetadataChanged() {
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleLeBroadcastStopped() {
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleLeBroadcastStopFailed() {
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleLeBroadcastUpdated() {
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleLeBroadcastUpdateFailed() {
|
||||||
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void startLeBroadcast() {
|
protected void startLeBroadcast() {
|
||||||
|
|||||||
@@ -61,6 +61,10 @@ public class MediaOutputBroadcastDialog extends MediaOutputBaseDialog {
|
|||||||
private ImageView mBroadcastCodeEdit;
|
private ImageView mBroadcastCodeEdit;
|
||||||
private AlertDialog mAlertDialog;
|
private AlertDialog mAlertDialog;
|
||||||
private TextView mBroadcastErrorMessage;
|
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_NAME = 0;
|
||||||
static final int METADATA_BROADCAST_CODE = 1;
|
static final int METADATA_BROADCAST_CODE = 1;
|
||||||
@@ -144,8 +148,6 @@ public class MediaOutputBroadcastDialog extends MediaOutputBaseDialog {
|
|||||||
|
|
||||||
//init UI component
|
//init UI component
|
||||||
mBroadcastQrCodeView = getDialogView().requireViewById(R.id.qrcode_view);
|
mBroadcastQrCodeView = getDialogView().requireViewById(R.id.qrcode_view);
|
||||||
//Set the QR code view
|
|
||||||
setQrCodeView();
|
|
||||||
|
|
||||||
mBroadcastNotify = getDialogView().requireViewById(R.id.broadcast_info);
|
mBroadcastNotify = getDialogView().requireViewById(R.id.broadcast_info);
|
||||||
mBroadcastNotify.setOnClickListener(v -> {
|
mBroadcastNotify.setOnClickListener(v -> {
|
||||||
@@ -171,8 +173,16 @@ public class MediaOutputBroadcastDialog extends MediaOutputBaseDialog {
|
|||||||
launchBroadcastUpdatedDialog(true, mBroadcastCode.getText().toString());
|
launchBroadcastUpdatedDialog(true, mBroadcastCode.getText().toString());
|
||||||
});
|
});
|
||||||
|
|
||||||
mBroadcastName.setText(getBroadcastMetadataInfo(METADATA_BROADCAST_NAME));
|
refreshUi();
|
||||||
mBroadcastCode.setText(getBroadcastMetadataInfo(METADATA_BROADCAST_CODE));
|
}
|
||||||
|
|
||||||
|
private void refreshUi() {
|
||||||
|
setQrCodeView();
|
||||||
|
|
||||||
|
mCurrentBroadcastName = getBroadcastMetadataInfo(METADATA_BROADCAST_NAME);
|
||||||
|
mCurrentBroadcastCode = getBroadcastMetadataInfo(METADATA_BROADCAST_CODE);
|
||||||
|
mBroadcastName.setText(mCurrentBroadcastName);
|
||||||
|
mBroadcastCode.setText(mCurrentBroadcastCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void inflateBroadcastInfoArea() {
|
private void inflateBroadcastInfoArea() {
|
||||||
@@ -239,52 +249,99 @@ public class MediaOutputBroadcastDialog extends MediaOutputBaseDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isBroadcastCode) {
|
if (isBroadcastCode) {
|
||||||
handleBroadcastCodeUpdated(updatedString);
|
/* If the user wants to update the Broadcast Code, the Broadcast session should be
|
||||||
|
* stopped then used the new Broadcast code to start the Broadcast.
|
||||||
|
*/
|
||||||
|
mIsStopbyUpdateBroadcastCode = true;
|
||||||
|
mMediaOutputController.setBroadcastCode(updatedString);
|
||||||
|
if (!mMediaOutputController.stopBluetoothLeBroadcast()) {
|
||||||
|
handleLeBroadcastStopFailed();
|
||||||
|
return;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
handleBroadcastNameUpdated(updatedString);
|
/* If the user wants to update the Broadcast Name, we don't need to stop the Broadcast
|
||||||
|
* session. Only use the new Broadcast name to update the broadcast session.
|
||||||
|
*/
|
||||||
|
mMediaOutputController.setBroadcastName(updatedString);
|
||||||
|
if (!mMediaOutputController.updateBluetoothLeBroadcast()) {
|
||||||
|
handleLeBroadcastUpdateFailed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleBroadcastNameUpdated(String name) {
|
@Override
|
||||||
// TODO(b/230473995) Add the retry mechanism and error handling when update fails
|
public void handleLeBroadcastStarted() {
|
||||||
String currentName = mMediaOutputController.getBroadcastName();
|
mRetryCount = 0;
|
||||||
int retryCount = MAX_BROADCAST_INFO_UPDATE;
|
if (mAlertDialog != null) {
|
||||||
mMediaOutputController.setBroadcastName(name);
|
mAlertDialog.dismiss();
|
||||||
if (!mMediaOutputController.updateBluetoothLeBroadcast()) {
|
}
|
||||||
mMediaOutputController.setBroadcastName(currentName);
|
refreshUi();
|
||||||
handleLeUpdateBroadcastFailed(retryCount);
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleLeBroadcastStartFailed() {
|
||||||
|
mMediaOutputController.setBroadcastCode(mCurrentBroadcastCode);
|
||||||
|
mRetryCount++;
|
||||||
|
|
||||||
|
handleUpdateFailedUi();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleLeBroadcastMetadataChanged() {
|
||||||
|
refreshUi();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleLeBroadcastUpdated() {
|
||||||
|
mRetryCount = 0;
|
||||||
|
if (mAlertDialog != null) {
|
||||||
|
mAlertDialog.dismiss();
|
||||||
|
}
|
||||||
|
refreshUi();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleLeBroadcastUpdateFailed() {
|
||||||
|
//Change the value in shared preferences back to it original value
|
||||||
|
mMediaOutputController.setBroadcastName(mCurrentBroadcastName);
|
||||||
|
mRetryCount++;
|
||||||
|
|
||||||
|
handleUpdateFailedUi();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleLeBroadcastStopped() {
|
||||||
|
if (mIsStopbyUpdateBroadcastCode) {
|
||||||
|
mIsStopbyUpdateBroadcastCode = false;
|
||||||
|
mRetryCount = 0;
|
||||||
|
if (!mMediaOutputController.startBluetoothLeBroadcast()) {
|
||||||
|
handleLeBroadcastStartFailed();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dismiss();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleBroadcastCodeUpdated(String newPassword) {
|
@Override
|
||||||
// TODO(b/230473995) Add the retry mechanism and error handling when update fails
|
public void handleLeBroadcastStopFailed() {
|
||||||
String currentPassword = mMediaOutputController.getBroadcastCode();
|
//Change the value in shared preferences back to it original value
|
||||||
int retryCount = MAX_BROADCAST_INFO_UPDATE;
|
mMediaOutputController.setBroadcastCode(mCurrentBroadcastCode);
|
||||||
if (!mMediaOutputController.stopBluetoothLeBroadcast()) {
|
mRetryCount++;
|
||||||
mMediaOutputController.setBroadcastCode(currentPassword);
|
|
||||||
handleLeUpdateBroadcastFailed(retryCount);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mMediaOutputController.setBroadcastCode(newPassword);
|
handleUpdateFailedUi();
|
||||||
if (!mMediaOutputController.startBluetoothLeBroadcast()) {
|
|
||||||
mMediaOutputController.setBroadcastCode(currentPassword);
|
|
||||||
handleLeUpdateBroadcastFailed(retryCount);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mAlertDialog.dismiss();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleLeUpdateBroadcastFailed(int retryCount) {
|
private void handleUpdateFailedUi() {
|
||||||
final Button positiveBtn = mAlertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
final Button positiveBtn = mAlertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||||
mBroadcastErrorMessage.setVisibility(View.VISIBLE);
|
mBroadcastErrorMessage.setVisibility(View.VISIBLE);
|
||||||
if (retryCount < MAX_BROADCAST_INFO_UPDATE) {
|
if (mRetryCount < MAX_BROADCAST_INFO_UPDATE) {
|
||||||
if (positiveBtn != null) {
|
if (positiveBtn != null) {
|
||||||
positiveBtn.setEnabled(true);
|
positiveBtn.setEnabled(true);
|
||||||
}
|
}
|
||||||
mBroadcastErrorMessage.setText(R.string.media_output_broadcast_update_error);
|
mBroadcastErrorMessage.setText(R.string.media_output_broadcast_update_error);
|
||||||
} else {
|
} else {
|
||||||
|
mRetryCount = 0;
|
||||||
mBroadcastErrorMessage.setText(R.string.media_output_broadcast_last_update_error);
|
mBroadcastErrorMessage.setText(R.string.media_output_broadcast_last_update_error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user