Merge "[LE Audio] Set activity for result after scanning the QR code" into udc-dev
This commit is contained in:
@@ -11871,7 +11871,8 @@
|
|||||||
<string name="find_broadcast_password_dialog_connection_error">Can\u2019t connect. Try again.</string>
|
<string name="find_broadcast_password_dialog_connection_error">Can\u2019t connect. Try again.</string>
|
||||||
<!-- The error message of enter password dialog in bluetooth find broadcast page [CHAR LIMIT=none] -->
|
<!-- The error message of enter password dialog in bluetooth find broadcast page [CHAR LIMIT=none] -->
|
||||||
<string name="find_broadcast_password_dialog_password_error">Wrong password</string>
|
<string name="find_broadcast_password_dialog_password_error">Wrong password</string>
|
||||||
|
<!-- The error message of join the broadcast session by scanning the QR code [CHAR LIMIT=none] -->
|
||||||
|
<string name="find_broadcast_join_broadcast_error">Can\u2019t join the broadcast</string>
|
||||||
|
|
||||||
<!-- [CHAR LIMIT=NONE] Le audio QR code scanner sub-title -->
|
<!-- [CHAR LIMIT=NONE] Le audio QR code scanner sub-title -->
|
||||||
<string name="bt_le_audio_scan_qr_code_scanner">To start listening, center the QR code below</string>
|
<string name="bt_le_audio_scan_qr_code_scanner">To start listening, center the QR code below</string>
|
||||||
|
@@ -19,6 +19,7 @@ package com.android.settings.bluetooth;
|
|||||||
import static android.bluetooth.BluetoothDevice.BOND_NONE;
|
import static android.bluetooth.BluetoothDevice.BOND_NONE;
|
||||||
import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;
|
import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
@@ -27,6 +28,7 @@ import android.bluetooth.BluetoothLeBroadcastMetadata;
|
|||||||
import android.bluetooth.BluetoothLeBroadcastReceiveState;
|
import android.bluetooth.BluetoothLeBroadcastReceiveState;
|
||||||
import android.bluetooth.le.ScanFilter;
|
import android.bluetooth.le.ScanFilter;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -34,6 +36,7 @@ import android.view.View;
|
|||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
@@ -43,6 +46,7 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.dashboard.RestrictedDashboardFragment;
|
import com.android.settings.dashboard.RestrictedDashboardFragment;
|
||||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant;
|
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant;
|
||||||
|
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastMetadata;
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
|
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
@@ -65,6 +69,7 @@ public class BluetoothFindBroadcastsFragment extends RestrictedDashboardFragment
|
|||||||
|
|
||||||
public static final String KEY_DEVICE_ADDRESS = "device_address";
|
public static final String KEY_DEVICE_ADDRESS = "device_address";
|
||||||
public static final String PREF_KEY_BROADCAST_SOURCE_LIST = "broadcast_source_list";
|
public static final String PREF_KEY_BROADCAST_SOURCE_LIST = "broadcast_source_list";
|
||||||
|
public static final int REQUEST_SCAN_BT_BROADCAST_QR_CODE = 0;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
String mDeviceAddress;
|
String mDeviceAddress;
|
||||||
@@ -79,6 +84,7 @@ public class BluetoothFindBroadcastsFragment extends RestrictedDashboardFragment
|
|||||||
BluetoothFindBroadcastsHeaderController mBluetoothFindBroadcastsHeaderController;
|
BluetoothFindBroadcastsHeaderController mBluetoothFindBroadcastsHeaderController;
|
||||||
|
|
||||||
private LocalBluetoothLeBroadcastAssistant mLeBroadcastAssistant;
|
private LocalBluetoothLeBroadcastAssistant mLeBroadcastAssistant;
|
||||||
|
private LocalBluetoothLeBroadcastMetadata mLocalBroadcastMetadata;
|
||||||
private Executor mExecutor;
|
private Executor mExecutor;
|
||||||
private int mSourceId;
|
private int mSourceId;
|
||||||
|
|
||||||
@@ -183,6 +189,7 @@ public class BluetoothFindBroadcastsFragment extends RestrictedDashboardFragment
|
|||||||
mCachedDevice = getCachedDevice(mDeviceAddress);
|
mCachedDevice = getCachedDevice(mDeviceAddress);
|
||||||
mLeBroadcastAssistant = getLeBroadcastAssistant();
|
mLeBroadcastAssistant = getLeBroadcastAssistant();
|
||||||
mExecutor = Executors.newSingleThreadExecutor();
|
mExecutor = Executors.newSingleThreadExecutor();
|
||||||
|
mLocalBroadcastMetadata = new LocalBluetoothLeBroadcastMetadata();
|
||||||
|
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
if (mCachedDevice == null || mLeBroadcastAssistant == null) {
|
if (mCachedDevice == null || mLeBroadcastAssistant == null) {
|
||||||
@@ -229,6 +236,34 @@ public class BluetoothFindBroadcastsFragment extends RestrictedDashboardFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
Log.d(TAG, "onActivityResult: " + requestCode + ", resultCode: " + resultCode);
|
||||||
|
if (requestCode == REQUEST_SCAN_BT_BROADCAST_QR_CODE) {
|
||||||
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
|
|
||||||
|
//Get BroadcastMetadata
|
||||||
|
String broadcastMetadata = data.getStringExtra(
|
||||||
|
QrCodeScanModeFragment.KEY_BROADCAST_METADATA);
|
||||||
|
BluetoothLeBroadcastMetadata source = convertToBroadcastMetadata(broadcastMetadata);
|
||||||
|
|
||||||
|
if (source != null) {
|
||||||
|
Log.d(TAG, "onActivityResult source Id = " + source.getBroadcastId());
|
||||||
|
//Create preference for the broadcast source
|
||||||
|
updateListCategoryFromBroadcastMetadata(source, false);
|
||||||
|
//Add Source
|
||||||
|
addSource(mBroadcastSourceListCategory.findPreference(
|
||||||
|
Integer.toString(source.getBroadcastId())));
|
||||||
|
} else {
|
||||||
|
Toast.makeText(getContext(),
|
||||||
|
R.string.find_broadcast_join_broadcast_error, Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void finishFragmentIfNecessary() {
|
void finishFragmentIfNecessary() {
|
||||||
if (mCachedDevice.getBondState() == BOND_NONE) {
|
if (mCachedDevice.getBondState() == BOND_NONE) {
|
||||||
@@ -466,4 +501,8 @@ public class BluetoothFindBroadcastsFragment extends RestrictedDashboardFragment
|
|||||||
public void setSourceId(int sourceId) {
|
public void setSourceId(int sourceId) {
|
||||||
mSourceId = sourceId;
|
mSourceId = sourceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private BluetoothLeBroadcastMetadata convertToBroadcastMetadata(String qrCodeString) {
|
||||||
|
return mLocalBroadcastMetadata.convertToBroadcastMetadata(qrCodeString);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -137,7 +137,8 @@ public class BluetoothFindBroadcastsHeaderController extends BluetoothDetailsCon
|
|||||||
.putExtra(BluetoothBroadcastUtils.EXTRA_BLUETOOTH_SINK_IS_GROUP, true)
|
.putExtra(BluetoothBroadcastUtils.EXTRA_BLUETOOTH_SINK_IS_GROUP, true)
|
||||||
.putExtra(BluetoothBroadcastUtils.EXTRA_BLUETOOTH_DEVICE_SINK,
|
.putExtra(BluetoothBroadcastUtils.EXTRA_BLUETOOTH_DEVICE_SINK,
|
||||||
mCachedDevice.getDevice());
|
mCachedDevice.getDevice());
|
||||||
mContext.startActivity(intent);
|
mBluetoothFindBroadcastsFragment.startActivityForResult(intent,
|
||||||
|
BluetoothFindBroadcastsFragment.REQUEST_SCAN_BT_BROADCAST_QR_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -1,63 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (C) 2022 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.settings.bluetooth;
|
|
||||||
|
|
||||||
import android.bluetooth.BluetoothDevice;
|
|
||||||
import android.bluetooth.BluetoothLeBroadcastMetadata;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
|
||||||
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
|
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant;
|
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastMetadata;
|
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
|
|
||||||
|
|
||||||
public class QrCodeScanModeController {
|
|
||||||
|
|
||||||
private static final boolean DEBUG = BluetoothUtils.D;
|
|
||||||
private static final String TAG = "QrCodeScanModeController";
|
|
||||||
|
|
||||||
private LocalBluetoothLeBroadcastMetadata mLocalBroadcastMetadata;
|
|
||||||
private LocalBluetoothLeBroadcastAssistant mLocalBroadcastAssistant;
|
|
||||||
private LocalBluetoothManager mLocalBluetoothManager;
|
|
||||||
private LocalBluetoothProfileManager mProfileManager;
|
|
||||||
|
|
||||||
public QrCodeScanModeController(Context context) {
|
|
||||||
if (DEBUG) {
|
|
||||||
Log.d(TAG, "QrCodeScanModeController constructor.");
|
|
||||||
}
|
|
||||||
mLocalBluetoothManager = Utils.getLocalBtManager(context);
|
|
||||||
mProfileManager = mLocalBluetoothManager.getProfileManager();
|
|
||||||
mLocalBroadcastMetadata = new LocalBluetoothLeBroadcastMetadata();
|
|
||||||
CachedBluetoothDeviceManager cachedDeviceManager = new CachedBluetoothDeviceManager(context,
|
|
||||||
mLocalBluetoothManager);
|
|
||||||
mLocalBroadcastAssistant = new LocalBluetoothLeBroadcastAssistant(context,
|
|
||||||
cachedDeviceManager, mProfileManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
private BluetoothLeBroadcastMetadata convertToBroadcastMetadata(String qrCodeString) {
|
|
||||||
return mLocalBroadcastMetadata.convertToBroadcastMetadata(qrCodeString);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addSource(BluetoothDevice sink, String sourceMetadata,
|
|
||||||
boolean isGroupOp) {
|
|
||||||
mLocalBroadcastAssistant.addSource(sink,
|
|
||||||
convertToBroadcastMetadata(sourceMetadata), isGroupOp);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -16,9 +16,11 @@
|
|||||||
|
|
||||||
package com.android.settings.bluetooth;
|
package com.android.settings.bluetooth;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.graphics.Matrix;
|
import android.graphics.Matrix;
|
||||||
import android.graphics.Outline;
|
import android.graphics.Outline;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
@@ -67,13 +69,14 @@ public class QrCodeScanModeFragment extends InstrumentedFragment implements
|
|||||||
|
|
||||||
private static final Duration VIBRATE_DURATION_QR_CODE_RECOGNITION = Duration.ofMillis(3);
|
private static final Duration VIBRATE_DURATION_QR_CODE_RECOGNITION = Duration.ofMillis(3);
|
||||||
|
|
||||||
|
public static final String KEY_BROADCAST_METADATA = "key_broadcast_metadata";
|
||||||
|
|
||||||
private boolean mIsGroupOp;
|
private boolean mIsGroupOp;
|
||||||
private int mCornerRadius;
|
private int mCornerRadius;
|
||||||
private BluetoothDevice mSink;
|
private BluetoothDevice mSink;
|
||||||
private String mBroadcastMetadata;
|
private String mBroadcastMetadata;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private QrCamera mCamera;
|
private QrCamera mCamera;
|
||||||
private QrCodeScanModeController mController;
|
|
||||||
private TextureView mTextureView;
|
private TextureView mTextureView;
|
||||||
private TextView mSummary;
|
private TextView mSummary;
|
||||||
private TextView mErrorMessage;
|
private TextView mErrorMessage;
|
||||||
@@ -87,7 +90,6 @@ public class QrCodeScanModeFragment extends InstrumentedFragment implements
|
|||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
mContext = getContext();
|
mContext = getContext();
|
||||||
mController = new QrCodeScanModeController(mContext);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -215,10 +217,10 @@ public class QrCodeScanModeFragment extends InstrumentedFragment implements
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case MESSAGE_SCAN_BROADCAST_SUCCESS:
|
case MESSAGE_SCAN_BROADCAST_SUCCESS:
|
||||||
/* TODO(b/265281156) : Move the logic to BluetoothFindBroadcastsFragment.
|
Log.d(TAG, "scan success");
|
||||||
* We only pass the QR code string to the previous page.
|
final Intent resultIntent = new Intent();
|
||||||
*/
|
resultIntent.putExtra(KEY_BROADCAST_METADATA, mBroadcastMetadata);
|
||||||
mController.addSource(mSink, mBroadcastMetadata, mIsGroupOp);
|
getActivity().setResult(Activity.RESULT_OK, resultIntent);
|
||||||
notifyUserForQrCodeRecognition();
|
notifyUserForQrCodeRecognition();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
Reference in New Issue
Block a user