[Audiosharing] Clean up unused code.
Test: atest -c com.android.settings.connecteddevice.audiosharing.audiostreams Bug: 308368124 Change-Id: Iea1aede53aefe2034b5a083ff503bb21a4f546cb
This commit is contained in:
@@ -5216,17 +5216,6 @@
|
|||||||
android:value="com.android.settings.connecteddevice.audiosharing.AudioSharingDashboardFragment"/>
|
android:value="com.android.settings.connecteddevice.audiosharing.AudioSharingDashboardFragment"/>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity
|
|
||||||
android:name="com.android.settings.connecteddevice.audiosharing.audiostreams.qrcode.QrCodeScanModeActivity"
|
|
||||||
android:permission="android.permission.BLUETOOTH_CONNECT"
|
|
||||||
android:screenOrientation="portrait"
|
|
||||||
android:exported="false">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.settings.BLUETOOTH_LE_AUDIO_QR_CODE_SCANNER"/>
|
|
||||||
<category android:name="android.intent.category.DEFAULT"/>
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name="com.android.settings.connecteddevice.audiosharing.audiostreams.AudioStreamConfirmDialogActivity"
|
android:name="com.android.settings.connecteddevice.audiosharing.audiostreams.AudioStreamConfirmDialogActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
|
@@ -70,8 +70,6 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="16dp"
|
||||||
android:layout_marginStart="?attr/sudMarginStart"
|
|
||||||
android:layout_marginEnd="?attr/sudMarginEnd"
|
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:visibility="invisible"/>
|
android:visibility="invisible"/>
|
||||||
|
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.settings.connecteddevice.audiosharing.audiostreams;
|
package com.android.settings.connecteddevice.audiosharing.audiostreams;
|
||||||
|
|
||||||
|
import static com.android.settings.connecteddevice.audiosharing.audiostreams.AudioStreamsDashboardFragment.KEY_BROADCAST_METADATA;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
@@ -30,7 +32,6 @@ import androidx.annotation.Nullable;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.bluetooth.Utils;
|
import com.android.settings.bluetooth.Utils;
|
||||||
import com.android.settings.connecteddevice.audiosharing.AudioSharingUtils;
|
import com.android.settings.connecteddevice.audiosharing.AudioSharingUtils;
|
||||||
import com.android.settings.connecteddevice.audiosharing.audiostreams.qrcode.QrCodeScanModeFragment;
|
|
||||||
import com.android.settings.core.SubSettingLauncher;
|
import com.android.settings.core.SubSettingLauncher;
|
||||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||||
import com.android.settingslib.bluetooth.BluetoothLeBroadcastMetadataExt;
|
import com.android.settingslib.bluetooth.BluetoothLeBroadcastMetadataExt;
|
||||||
@@ -41,7 +42,6 @@ import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
|
|||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
|
|
||||||
public class AudioStreamConfirmDialog extends InstrumentedDialogFragment {
|
public class AudioStreamConfirmDialog extends InstrumentedDialogFragment {
|
||||||
public static final String KEY_BROADCAST_METADATA = "key_broadcast_metadata";
|
|
||||||
private static final String TAG = "AudioStreamConfirmDialog";
|
private static final String TAG = "AudioStreamConfirmDialog";
|
||||||
private static final int DEFAULT_DEVICE_NAME = R.string.audio_streams_dialog_default_device;
|
private static final int DEFAULT_DEVICE_NAME = R.string.audio_streams_dialog_default_device;
|
||||||
@Nullable private LocalBluetoothManager mLocalBluetoothManager;
|
@Nullable private LocalBluetoothManager mLocalBluetoothManager;
|
||||||
@@ -63,8 +63,7 @@ public class AudioStreamConfirmDialog extends InstrumentedDialogFragment {
|
|||||||
mLocalBluetoothManager = Utils.getLocalBluetoothManager(mActivity);
|
mLocalBluetoothManager = Utils.getLocalBluetoothManager(mActivity);
|
||||||
mProfileManager =
|
mProfileManager =
|
||||||
mLocalBluetoothManager == null ? null : mLocalBluetoothManager.getProfileManager();
|
mLocalBluetoothManager == null ? null : mLocalBluetoothManager.getProfileManager();
|
||||||
mBroadcastMetadataStr =
|
mBroadcastMetadataStr = mActivity.getIntent().getStringExtra(KEY_BROADCAST_METADATA);
|
||||||
mActivity.getIntent().getStringExtra(QrCodeScanModeFragment.KEY_BROADCAST_METADATA);
|
|
||||||
if (Strings.isNullOrEmpty(mBroadcastMetadataStr)) {
|
if (Strings.isNullOrEmpty(mBroadcastMetadataStr)) {
|
||||||
Log.w(TAG, "onCreate() mBroadcastMetadataStr is null or empty!");
|
Log.w(TAG, "onCreate() mBroadcastMetadataStr is null or empty!");
|
||||||
return;
|
return;
|
||||||
|
@@ -28,7 +28,6 @@ import android.util.Log;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.connecteddevice.audiosharing.audiostreams.qrcode.QrCodeScanModeFragment;
|
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settingslib.bluetooth.BluetoothLeBroadcastMetadataExt;
|
import com.android.settingslib.bluetooth.BluetoothLeBroadcastMetadataExt;
|
||||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||||
@@ -36,6 +35,7 @@ import com.android.settingslib.bluetooth.BluetoothUtils;
|
|||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
|
|
||||||
public class AudioStreamsDashboardFragment extends DashboardFragment {
|
public class AudioStreamsDashboardFragment extends DashboardFragment {
|
||||||
|
public static final String KEY_BROADCAST_METADATA = "key_broadcast_metadata";
|
||||||
private static final String TAG = "AudioStreamsDashboardFrag";
|
private static final String TAG = "AudioStreamsDashboardFrag";
|
||||||
private static final boolean DEBUG = BluetoothUtils.D;
|
private static final boolean DEBUG = BluetoothUtils.D;
|
||||||
private AudioStreamsProgressCategoryController mAudioStreamsProgressCategoryController;
|
private AudioStreamsProgressCategoryController mAudioStreamsProgressCategoryController;
|
||||||
@@ -78,8 +78,7 @@ public class AudioStreamsDashboardFragment extends DashboardFragment {
|
|||||||
mAudioStreamsProgressCategoryController.setFragment(this);
|
mAudioStreamsProgressCategoryController.setFragment(this);
|
||||||
|
|
||||||
if (getArguments() != null) {
|
if (getArguments() != null) {
|
||||||
String broadcastMetadataStr =
|
String broadcastMetadataStr = getArguments().getString(KEY_BROADCAST_METADATA);
|
||||||
getArguments().getString(AudioStreamConfirmDialog.KEY_BROADCAST_METADATA);
|
|
||||||
if (!Strings.isNullOrEmpty(broadcastMetadataStr)) {
|
if (!Strings.isNullOrEmpty(broadcastMetadataStr)) {
|
||||||
BluetoothLeBroadcastMetadata broadcastMetadata =
|
BluetoothLeBroadcastMetadata broadcastMetadata =
|
||||||
BluetoothLeBroadcastMetadataExt.INSTANCE.convertToBroadcastMetadata(
|
BluetoothLeBroadcastMetadataExt.INSTANCE.convertToBroadcastMetadata(
|
||||||
@@ -112,9 +111,7 @@ public class AudioStreamsDashboardFragment extends DashboardFragment {
|
|||||||
if (requestCode == REQUEST_SCAN_BT_BROADCAST_QR_CODE) {
|
if (requestCode == REQUEST_SCAN_BT_BROADCAST_QR_CODE) {
|
||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
String broadcastMetadata =
|
String broadcastMetadata =
|
||||||
data != null
|
data != null ? data.getStringExtra(KEY_BROADCAST_METADATA) : "";
|
||||||
? data.getStringExtra(QrCodeScanModeFragment.KEY_BROADCAST_METADATA)
|
|
||||||
: "";
|
|
||||||
BluetoothLeBroadcastMetadata source =
|
BluetoothLeBroadcastMetadata source =
|
||||||
BluetoothLeBroadcastMetadataExt.INSTANCE.convertToBroadcastMetadata(
|
BluetoothLeBroadcastMetadataExt.INSTANCE.convertToBroadcastMetadata(
|
||||||
broadcastMetadata);
|
broadcastMetadata);
|
||||||
|
@@ -14,7 +14,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.settings.connecteddevice.audiosharing.audiostreams.qrcode;
|
package com.android.settings.connecteddevice.audiosharing.audiostreams;
|
||||||
|
|
||||||
|
import static com.android.settings.connecteddevice.audiosharing.audiostreams.AudioStreamsDashboardFragment.KEY_BROADCAST_METADATA;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
@@ -26,6 +28,7 @@ import android.graphics.Rect;
|
|||||||
import android.graphics.SurfaceTexture;
|
import android.graphics.SurfaceTexture;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.VibrationEffect;
|
import android.os.VibrationEffect;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
@@ -41,11 +44,9 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.StringRes;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.bluetooth.Utils;
|
import com.android.settings.bluetooth.Utils;
|
||||||
import com.android.settings.connecteddevice.audiosharing.audiostreams.AudioStreamsHelper;
|
|
||||||
import com.android.settings.core.InstrumentedFragment;
|
import com.android.settings.core.InstrumentedFragment;
|
||||||
import com.android.settingslib.bluetooth.BluetoothBroadcastUtils;
|
import com.android.settingslib.bluetooth.BluetoothBroadcastUtils;
|
||||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||||
@@ -54,34 +55,54 @@ import com.android.settingslib.qrcode.QrCamera;
|
|||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
|
||||||
public class QrCodeScanModeFragment extends InstrumentedFragment
|
public class AudioStreamsQrCodeScanFragment extends InstrumentedFragment
|
||||||
implements TextureView.SurfaceTextureListener, QrCamera.ScannerCallback {
|
implements TextureView.SurfaceTextureListener, QrCamera.ScannerCallback {
|
||||||
private static final boolean DEBUG = BluetoothUtils.D;
|
private static final boolean DEBUG = BluetoothUtils.D;
|
||||||
private static final String TAG = "QrCodeScanModeFragment";
|
private static final String TAG = "AudioStreamsQrCodeScanFragment";
|
||||||
|
|
||||||
/** Message sent to hide error message */
|
|
||||||
private static final int MESSAGE_HIDE_ERROR_MESSAGE = 1;
|
private static final int MESSAGE_HIDE_ERROR_MESSAGE = 1;
|
||||||
|
|
||||||
/** Message sent to show error message */
|
|
||||||
private static final int MESSAGE_SHOW_ERROR_MESSAGE = 2;
|
private static final int MESSAGE_SHOW_ERROR_MESSAGE = 2;
|
||||||
|
|
||||||
/** Message sent to broadcast QR code */
|
|
||||||
private static final int MESSAGE_SCAN_BROADCAST_SUCCESS = 3;
|
private static final int MESSAGE_SCAN_BROADCAST_SUCCESS = 3;
|
||||||
|
|
||||||
private static final long SHOW_ERROR_MESSAGE_INTERVAL = 10000;
|
private static final long SHOW_ERROR_MESSAGE_INTERVAL = 10000;
|
||||||
private static final long SHOW_SUCCESS_SQUARE_INTERVAL = 1000;
|
private static final long SHOW_SUCCESS_SQUARE_INTERVAL = 1000;
|
||||||
|
|
||||||
private static final Duration VIBRATE_DURATION_QR_CODE_RECOGNITION = Duration.ofMillis(3);
|
private static final Duration VIBRATE_DURATION_QR_CODE_RECOGNITION = Duration.ofMillis(3);
|
||||||
|
private final Handler mHandler =
|
||||||
public static final String KEY_BROADCAST_METADATA = "key_broadcast_metadata";
|
new Handler(Looper.getMainLooper()) {
|
||||||
|
@Override
|
||||||
|
public void handleMessage(Message msg) {
|
||||||
|
switch (msg.what) {
|
||||||
|
case MESSAGE_HIDE_ERROR_MESSAGE:
|
||||||
|
mErrorMessage.setVisibility(View.INVISIBLE);
|
||||||
|
break;
|
||||||
|
case MESSAGE_SHOW_ERROR_MESSAGE:
|
||||||
|
String errorMessage = (String) msg.obj;
|
||||||
|
mErrorMessage.setVisibility(View.VISIBLE);
|
||||||
|
mErrorMessage.setText(errorMessage);
|
||||||
|
mErrorMessage.sendAccessibilityEvent(
|
||||||
|
AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
|
||||||
|
// Cancel any pending messages to hide error view and requeue the
|
||||||
|
// message so user has time to see error
|
||||||
|
removeMessages(MESSAGE_HIDE_ERROR_MESSAGE);
|
||||||
|
sendEmptyMessageDelayed(
|
||||||
|
MESSAGE_HIDE_ERROR_MESSAGE, SHOW_ERROR_MESSAGE_INTERVAL);
|
||||||
|
break;
|
||||||
|
case MESSAGE_SCAN_BROADCAST_SUCCESS:
|
||||||
|
Log.d(TAG, "scan success");
|
||||||
|
Intent resultIntent = new Intent();
|
||||||
|
resultIntent.putExtra(KEY_BROADCAST_METADATA, mBroadcastMetadata);
|
||||||
|
if (getActivity() != null) {
|
||||||
|
getActivity().setResult(Activity.RESULT_OK, resultIntent);
|
||||||
|
notifyUserForQrCodeRecognition();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
private LocalBluetoothManager mLocalBluetoothManager;
|
private LocalBluetoothManager mLocalBluetoothManager;
|
||||||
private int mCornerRadius;
|
private int mCornerRadius;
|
||||||
@Nullable private String mBroadcastMetadata;
|
@Nullable private String mBroadcastMetadata;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
@Nullable private QrCamera mCamera;
|
@Nullable private QrCamera mCamera;
|
||||||
private TextureView mTextureView;
|
private TextureView mTextureView;
|
||||||
private TextView mSummary;
|
|
||||||
private TextView mErrorMessage;
|
private TextView mErrorMessage;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -119,35 +140,23 @@ public class QrCodeScanModeFragment extends InstrumentedFragment
|
|||||||
var device =
|
var device =
|
||||||
AudioStreamsHelper.getCachedBluetoothDeviceInSharingOrLeConnected(
|
AudioStreamsHelper.getCachedBluetoothDeviceInSharingOrLeConnected(
|
||||||
mLocalBluetoothManager);
|
mLocalBluetoothManager);
|
||||||
mSummary = view.findViewById(android.R.id.summary);
|
TextView summary = view.findViewById(android.R.id.summary);
|
||||||
if (mSummary != null && device.isPresent()) {
|
if (summary != null && device.isPresent()) {
|
||||||
mSummary.setText(
|
summary.setText(
|
||||||
getString(
|
getString(
|
||||||
R.string.audio_streams_main_page_qr_code_scanner_summary,
|
R.string.audio_streams_main_page_qr_code_scanner_summary,
|
||||||
device.get().getName()));
|
device.get().getName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initCamera(SurfaceTexture surface) {
|
@Override
|
||||||
// Check if the camera has already created.
|
public void onSurfaceTextureAvailable(@NonNull SurfaceTexture surface, int width, int height) {
|
||||||
if (mCamera == null) {
|
if (mCamera == null) {
|
||||||
mCamera = new QrCamera(mContext, this);
|
mCamera = new QrCamera(mContext, this);
|
||||||
mCamera.start(surface);
|
mCamera.start(surface);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void destroyCamera() {
|
|
||||||
if (mCamera != null) {
|
|
||||||
mCamera.stop();
|
|
||||||
mCamera = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSurfaceTextureAvailable(@NonNull SurfaceTexture surface, int width, int height) {
|
|
||||||
initCamera(surface);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSurfaceTextureSizeChanged(
|
public void onSurfaceTextureSizeChanged(
|
||||||
@NonNull SurfaceTexture surface, int width, int height) {}
|
@NonNull SurfaceTexture surface, int width, int height) {}
|
||||||
@@ -167,7 +176,8 @@ public class QrCodeScanModeFragment extends InstrumentedFragment
|
|||||||
Log.d(TAG, "handleSuccessfulResult(), get the qr code string.");
|
Log.d(TAG, "handleSuccessfulResult(), get the qr code string.");
|
||||||
}
|
}
|
||||||
mBroadcastMetadata = qrCode;
|
mBroadcastMetadata = qrCode;
|
||||||
handleBtLeAudioScanner();
|
Message message = mHandler.obtainMessage(MESSAGE_SCAN_BROADCAST_SUCCESS);
|
||||||
|
mHandler.sendMessageDelayed(message, SHOW_SUCCESS_SQUARE_INTERVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -194,52 +204,21 @@ public class QrCodeScanModeFragment extends InstrumentedFragment
|
|||||||
public boolean isValid(String qrCode) {
|
public boolean isValid(String qrCode) {
|
||||||
if (qrCode.startsWith(BluetoothBroadcastUtils.SCHEME_BT_BROADCAST_METADATA)) {
|
if (qrCode.startsWith(BluetoothBroadcastUtils.SCHEME_BT_BROADCAST_METADATA)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
showErrorMessage(R.string.audio_streams_qr_code_is_not_valid_format);
|
Message message =
|
||||||
|
mHandler.obtainMessage(
|
||||||
|
MESSAGE_SHOW_ERROR_MESSAGE,
|
||||||
|
getString(R.string.audio_streams_qr_code_is_not_valid_format));
|
||||||
|
message.sendToTarget();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isDecodeTaskAlive() {
|
private void destroyCamera() {
|
||||||
return mCamera != null && mCamera.isDecodeTaskAlive();
|
if (mCamera != null) {
|
||||||
}
|
mCamera.stop();
|
||||||
|
mCamera = null;
|
||||||
private final Handler mHandler =
|
|
||||||
new Handler() {
|
|
||||||
@Override
|
|
||||||
public void handleMessage(Message msg) {
|
|
||||||
switch (msg.what) {
|
|
||||||
case MESSAGE_HIDE_ERROR_MESSAGE:
|
|
||||||
mErrorMessage.setVisibility(View.INVISIBLE);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MESSAGE_SHOW_ERROR_MESSAGE:
|
|
||||||
final String errorMessage = (String) msg.obj;
|
|
||||||
|
|
||||||
mErrorMessage.setVisibility(View.VISIBLE);
|
|
||||||
mErrorMessage.setText(errorMessage);
|
|
||||||
mErrorMessage.sendAccessibilityEvent(
|
|
||||||
AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
|
|
||||||
|
|
||||||
// Cancel any pending messages to hide error view and requeue the
|
|
||||||
// message so
|
|
||||||
// user has time to see error
|
|
||||||
removeMessages(MESSAGE_HIDE_ERROR_MESSAGE);
|
|
||||||
sendEmptyMessageDelayed(
|
|
||||||
MESSAGE_HIDE_ERROR_MESSAGE, SHOW_ERROR_MESSAGE_INTERVAL);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MESSAGE_SCAN_BROADCAST_SUCCESS:
|
|
||||||
Log.d(TAG, "scan success");
|
|
||||||
final Intent resultIntent = new Intent();
|
|
||||||
resultIntent.putExtra(KEY_BROADCAST_METADATA, mBroadcastMetadata);
|
|
||||||
getActivity().setResult(Activity.RESULT_OK, resultIntent);
|
|
||||||
notifyUserForQrCodeRecognition();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
private void notifyUserForQrCodeRecognition() {
|
private void notifyUserForQrCodeRecognition() {
|
||||||
if (mCamera != null) {
|
if (mCamera != null) {
|
||||||
@@ -249,10 +228,12 @@ public class QrCodeScanModeFragment extends InstrumentedFragment
|
|||||||
mErrorMessage.setVisibility(View.INVISIBLE);
|
mErrorMessage.setVisibility(View.INVISIBLE);
|
||||||
mTextureView.setVisibility(View.INVISIBLE);
|
mTextureView.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
triggerVibrationForQrCodeRecognition(getContext());
|
triggerVibrationForQrCodeRecognition(mContext);
|
||||||
|
|
||||||
|
if (getActivity() != null) {
|
||||||
getActivity().finish();
|
getActivity().finish();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void triggerVibrationForQrCodeRecognition(Context context) {
|
private static void triggerVibrationForQrCodeRecognition(Context context) {
|
||||||
Vibrator vibrator = context.getSystemService(Vibrator.class);
|
Vibrator vibrator = context.getSystemService(Vibrator.class);
|
||||||
@@ -265,17 +246,6 @@ public class QrCodeScanModeFragment extends InstrumentedFragment
|
|||||||
VibrationEffect.DEFAULT_AMPLITUDE));
|
VibrationEffect.DEFAULT_AMPLITUDE));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showErrorMessage(@StringRes int messageResId) {
|
|
||||||
final Message message =
|
|
||||||
mHandler.obtainMessage(MESSAGE_SHOW_ERROR_MESSAGE, getString(messageResId));
|
|
||||||
message.sendToTarget();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleBtLeAudioScanner() {
|
|
||||||
Message message = mHandler.obtainMessage(MESSAGE_SCAN_BROADCAST_SUCCESS);
|
|
||||||
mHandler.sendMessageDelayed(message, SHOW_SUCCESS_SQUARE_INTERVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMetricsCategory() {
|
public int getMetricsCategory() {
|
||||||
return SettingsEnums.LE_AUDIO_BROADCAST_SCAN_QR_CODE;
|
return SettingsEnums.LE_AUDIO_BROADCAST_SCAN_QR_CODE;
|
@@ -16,9 +16,9 @@
|
|||||||
|
|
||||||
package com.android.settings.connecteddevice.audiosharing.audiostreams;
|
package com.android.settings.connecteddevice.audiosharing.audiostreams;
|
||||||
|
|
||||||
|
import android.app.settings.SettingsEnums;
|
||||||
import android.bluetooth.BluetoothProfile;
|
import android.bluetooth.BluetoothProfile;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@@ -28,10 +28,10 @@ import androidx.lifecycle.LifecycleOwner;
|
|||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
import com.android.settings.bluetooth.Utils;
|
import com.android.settings.bluetooth.Utils;
|
||||||
import com.android.settings.connecteddevice.audiosharing.audiostreams.qrcode.QrCodeScanModeActivity;
|
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settingslib.bluetooth.BluetoothBroadcastUtils;
|
import com.android.settings.core.SubSettingLauncher;
|
||||||
import com.android.settingslib.bluetooth.BluetoothCallback;
|
import com.android.settingslib.bluetooth.BluetoothCallback;
|
||||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||||
@@ -107,13 +107,12 @@ public class AudioStreamsScanQrCodeController extends BasePreferenceController
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (preference.getKey().equals(KEY)) {
|
if (preference.getKey().equals(KEY)) {
|
||||||
Intent intent = new Intent(mContext, QrCodeScanModeActivity.class);
|
new SubSettingLauncher(mContext)
|
||||||
intent.setAction(
|
.setTitleRes(R.string.audio_streams_main_page_scan_qr_code_title)
|
||||||
BluetoothBroadcastUtils.ACTION_BLUETOOTH_LE_AUDIO_QR_CODE_SCANNER);
|
.setDestination(AudioStreamsQrCodeScanFragment.class.getName())
|
||||||
mFragment.startActivityForResult(intent, REQUEST_SCAN_BT_BROADCAST_QR_CODE);
|
.setResultListener(mFragment, REQUEST_SCAN_BT_BROADCAST_QR_CODE)
|
||||||
if (DEBUG) {
|
.setSourceMetricsCategory(SettingsEnums.PAGE_UNKNOWN)
|
||||||
Log.w(TAG, "displayPreference() sent intent : " + intent);
|
.launch();
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@@ -19,15 +19,14 @@ package com.android.settings.connecteddevice.audiosharing.audiostreams;
|
|||||||
import static com.android.settings.connecteddevice.audiosharing.audiostreams.AudioStreamsScanQrCodeController.REQUEST_SCAN_BT_BROADCAST_QR_CODE;
|
import static com.android.settings.connecteddevice.audiosharing.audiostreams.AudioStreamsScanQrCodeController.REQUEST_SCAN_BT_BROADCAST_QR_CODE;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.connecteddevice.audiosharing.audiostreams.qrcode.QrCodeScanModeActivity;
|
import com.android.settings.core.SubSettingLauncher;
|
||||||
import com.android.settingslib.bluetooth.BluetoothBroadcastUtils;
|
|
||||||
import com.android.settingslib.utils.ThreadUtils;
|
import com.android.settingslib.utils.ThreadUtils;
|
||||||
|
|
||||||
class WaitForSyncState extends AudioStreamStateHandler {
|
class WaitForSyncState extends AudioStreamStateHandler {
|
||||||
@@ -102,14 +101,16 @@ class WaitForSyncState extends AudioStreamStateHandler {
|
|||||||
.setRightButtonOnClickListener(
|
.setRightButtonOnClickListener(
|
||||||
dialog -> {
|
dialog -> {
|
||||||
if (controller.getFragment() != null) {
|
if (controller.getFragment() != null) {
|
||||||
Intent intent = new Intent(context, QrCodeScanModeActivity.class);
|
new SubSettingLauncher(context)
|
||||||
intent.setAction(
|
.setTitleRes(
|
||||||
BluetoothBroadcastUtils
|
R.string.audio_streams_main_page_scan_qr_code_title)
|
||||||
.ACTION_BLUETOOTH_LE_AUDIO_QR_CODE_SCANNER);
|
.setDestination(
|
||||||
controller
|
AudioStreamsQrCodeScanFragment.class.getName())
|
||||||
.getFragment()
|
.setResultListener(
|
||||||
.startActivityForResult(
|
controller.getFragment(),
|
||||||
intent, REQUEST_SCAN_BT_BROADCAST_QR_CODE);
|
REQUEST_SCAN_BT_BROADCAST_QR_CODE)
|
||||||
|
.setSourceMetricsCategory(SettingsEnums.PAGE_UNKNOWN)
|
||||||
|
.launch();
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -1,117 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2023 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.connecteddevice.audiosharing.audiostreams.qrcode;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.fragment.app.FragmentTransaction;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.connecteddevice.audiosharing.AudioSharingUtils;
|
|
||||||
import com.android.settingslib.bluetooth.BluetoothBroadcastUtils;
|
|
||||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Finding a broadcast through QR code.
|
|
||||||
*
|
|
||||||
* <p>To use intent action {@link
|
|
||||||
* BluetoothBroadcastUtils#ACTION_BLUETOOTH_LE_AUDIO_QR_CODE_SCANNER}, specify the bluetooth device
|
|
||||||
* sink of the broadcast to be provisioned in {@link
|
|
||||||
* BluetoothBroadcastUtils#EXTRA_BLUETOOTH_DEVICE_SINK} and check the operation for all coordinated
|
|
||||||
* set members throughout one session or not by {@link
|
|
||||||
* BluetoothBroadcastUtils#EXTRA_BLUETOOTH_SINK_IS_GROUP}.
|
|
||||||
*/
|
|
||||||
public class QrCodeScanModeActivity extends QrCodeScanModeBaseActivity {
|
|
||||||
private static final boolean DEBUG = BluetoothUtils.D;
|
|
||||||
private static final String TAG = "QrCodeScanModeActivity";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void handleIntent(Intent intent) {
|
|
||||||
if (!AudioSharingUtils.isFeatureEnabled()) {
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
String action = intent != null ? intent.getAction() : null;
|
|
||||||
if (DEBUG) {
|
|
||||||
Log.d(TAG, "handleIntent(), action = " + action);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (action == null) {
|
|
||||||
finish();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (action) {
|
|
||||||
case BluetoothBroadcastUtils.ACTION_BLUETOOTH_LE_AUDIO_QR_CODE_SCANNER:
|
|
||||||
showQrCodeScannerFragment(intent);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (DEBUG) {
|
|
||||||
Log.e(TAG, "Launch with an invalid action");
|
|
||||||
}
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showQrCodeScannerFragment(Intent intent) {
|
|
||||||
if (intent == null) {
|
|
||||||
if (DEBUG) {
|
|
||||||
Log.d(TAG, "intent is null, can not get bluetooth information from intent.");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DEBUG) {
|
|
||||||
Log.d(TAG, "showQrCodeScannerFragment");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DEBUG) {
|
|
||||||
Log.d(TAG, "get extra from intent");
|
|
||||||
}
|
|
||||||
|
|
||||||
QrCodeScanModeFragment fragment =
|
|
||||||
(QrCodeScanModeFragment)
|
|
||||||
mFragmentManager.findFragmentByTag(
|
|
||||||
BluetoothBroadcastUtils.TAG_FRAGMENT_QR_CODE_SCANNER);
|
|
||||||
|
|
||||||
if (fragment == null) {
|
|
||||||
fragment = new QrCodeScanModeFragment();
|
|
||||||
} else {
|
|
||||||
if (fragment.isVisible()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// When the fragment in back stack but not on top of the stack, we can simply pop
|
|
||||||
// stack because current fragment transactions are arranged in an order
|
|
||||||
mFragmentManager.popBackStackImmediate();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
|
|
||||||
|
|
||||||
fragmentTransaction.replace(
|
|
||||||
R.id.fragment_container,
|
|
||||||
fragment,
|
|
||||||
BluetoothBroadcastUtils.TAG_FRAGMENT_QR_CODE_SCANNER);
|
|
||||||
fragmentTransaction.commit();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2023 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.connecteddevice.audiosharing.audiostreams.qrcode;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.SystemProperties;
|
|
||||||
|
|
||||||
import androidx.fragment.app.FragmentManager;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settingslib.core.lifecycle.ObservableActivity;
|
|
||||||
|
|
||||||
import com.google.android.setupdesign.util.ThemeHelper;
|
|
||||||
import com.google.android.setupdesign.util.ThemeResolver;
|
|
||||||
|
|
||||||
public abstract class QrCodeScanModeBaseActivity extends ObservableActivity {
|
|
||||||
|
|
||||||
private static final String THEME_KEY = "setupwizard.theme";
|
|
||||||
private static final String THEME_DEFAULT_VALUE = "SudThemeGlifV3_DayNight";
|
|
||||||
protected FragmentManager mFragmentManager;
|
|
||||||
|
|
||||||
protected abstract void handleIntent(Intent intent);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
|
||||||
int defaultTheme =
|
|
||||||
ThemeHelper.isSetupWizardDayNightEnabled(this)
|
|
||||||
? com.google.android.setupdesign.R.style.SudThemeGlifV3_DayNight
|
|
||||||
: com.google.android.setupdesign.R.style.SudThemeGlifV3_Light;
|
|
||||||
ThemeResolver themeResolver =
|
|
||||||
new ThemeResolver.Builder(ThemeResolver.getDefault())
|
|
||||||
.setDefaultTheme(defaultTheme)
|
|
||||||
.setUseDayNight(true)
|
|
||||||
.build();
|
|
||||||
setTheme(
|
|
||||||
themeResolver.resolve(
|
|
||||||
SystemProperties.get(THEME_KEY, THEME_DEFAULT_VALUE),
|
|
||||||
/* suppressDayNight= */ !ThemeHelper.isSetupWizardDayNightEnabled(this)));
|
|
||||||
|
|
||||||
setContentView(R.layout.qrcode_scan_mode_activity);
|
|
||||||
mFragmentManager = getSupportFragmentManager();
|
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
|
||||||
handleIntent(getIntent());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user