[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"/>
|
||||
</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
|
||||
android:name="com.android.settings.connecteddevice.audiosharing.audiostreams.AudioStreamConfirmDialogActivity"
|
||||
android:exported="true"
|
||||
|
@@ -70,8 +70,6 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginStart="?attr/sudMarginStart"
|
||||
android:layout_marginEnd="?attr/sudMarginEnd"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="center"
|
||||
android:visibility="invisible"/>
|
||||
|
@@ -16,6 +16,8 @@
|
||||
|
||||
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.Dialog;
|
||||
import android.app.settings.SettingsEnums;
|
||||
@@ -30,7 +32,6 @@ import androidx.annotation.Nullable;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
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.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settingslib.bluetooth.BluetoothLeBroadcastMetadataExt;
|
||||
@@ -41,7 +42,6 @@ import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
public class AudioStreamConfirmDialog extends InstrumentedDialogFragment {
|
||||
public static final String KEY_BROADCAST_METADATA = "key_broadcast_metadata";
|
||||
private static final String TAG = "AudioStreamConfirmDialog";
|
||||
private static final int DEFAULT_DEVICE_NAME = R.string.audio_streams_dialog_default_device;
|
||||
@Nullable private LocalBluetoothManager mLocalBluetoothManager;
|
||||
@@ -63,8 +63,7 @@ public class AudioStreamConfirmDialog extends InstrumentedDialogFragment {
|
||||
mLocalBluetoothManager = Utils.getLocalBluetoothManager(mActivity);
|
||||
mProfileManager =
|
||||
mLocalBluetoothManager == null ? null : mLocalBluetoothManager.getProfileManager();
|
||||
mBroadcastMetadataStr =
|
||||
mActivity.getIntent().getStringExtra(QrCodeScanModeFragment.KEY_BROADCAST_METADATA);
|
||||
mBroadcastMetadataStr = mActivity.getIntent().getStringExtra(KEY_BROADCAST_METADATA);
|
||||
if (Strings.isNullOrEmpty(mBroadcastMetadataStr)) {
|
||||
Log.w(TAG, "onCreate() mBroadcastMetadataStr is null or empty!");
|
||||
return;
|
||||
|
@@ -28,7 +28,6 @@ import android.util.Log;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.connecteddevice.audiosharing.audiostreams.qrcode.QrCodeScanModeFragment;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settingslib.bluetooth.BluetoothLeBroadcastMetadataExt;
|
||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||
@@ -36,6 +35,7 @@ import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
public class AudioStreamsDashboardFragment extends DashboardFragment {
|
||||
public static final String KEY_BROADCAST_METADATA = "key_broadcast_metadata";
|
||||
private static final String TAG = "AudioStreamsDashboardFrag";
|
||||
private static final boolean DEBUG = BluetoothUtils.D;
|
||||
private AudioStreamsProgressCategoryController mAudioStreamsProgressCategoryController;
|
||||
@@ -78,8 +78,7 @@ public class AudioStreamsDashboardFragment extends DashboardFragment {
|
||||
mAudioStreamsProgressCategoryController.setFragment(this);
|
||||
|
||||
if (getArguments() != null) {
|
||||
String broadcastMetadataStr =
|
||||
getArguments().getString(AudioStreamConfirmDialog.KEY_BROADCAST_METADATA);
|
||||
String broadcastMetadataStr = getArguments().getString(KEY_BROADCAST_METADATA);
|
||||
if (!Strings.isNullOrEmpty(broadcastMetadataStr)) {
|
||||
BluetoothLeBroadcastMetadata broadcastMetadata =
|
||||
BluetoothLeBroadcastMetadataExt.INSTANCE.convertToBroadcastMetadata(
|
||||
@@ -112,9 +111,7 @@ public class AudioStreamsDashboardFragment extends DashboardFragment {
|
||||
if (requestCode == REQUEST_SCAN_BT_BROADCAST_QR_CODE) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
String broadcastMetadata =
|
||||
data != null
|
||||
? data.getStringExtra(QrCodeScanModeFragment.KEY_BROADCAST_METADATA)
|
||||
: "";
|
||||
data != null ? data.getStringExtra(KEY_BROADCAST_METADATA) : "";
|
||||
BluetoothLeBroadcastMetadata source =
|
||||
BluetoothLeBroadcastMetadataExt.INSTANCE.convertToBroadcastMetadata(
|
||||
broadcastMetadata);
|
||||
|
@@ -14,7 +14,9 @@
|
||||
* 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.settings.SettingsEnums;
|
||||
@@ -26,6 +28,7 @@ import android.graphics.Rect;
|
||||
import android.graphics.SurfaceTexture;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.VibrationEffect;
|
||||
import android.os.Vibrator;
|
||||
@@ -41,11 +44,9 @@ import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settings.connecteddevice.audiosharing.audiostreams.AudioStreamsHelper;
|
||||
import com.android.settings.core.InstrumentedFragment;
|
||||
import com.android.settingslib.bluetooth.BluetoothBroadcastUtils;
|
||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||
@@ -54,34 +55,54 @@ import com.android.settingslib.qrcode.QrCamera;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
public class QrCodeScanModeFragment extends InstrumentedFragment
|
||||
public class AudioStreamsQrCodeScanFragment extends InstrumentedFragment
|
||||
implements TextureView.SurfaceTextureListener, QrCamera.ScannerCallback {
|
||||
private static final boolean DEBUG = BluetoothUtils.D;
|
||||
private static final String TAG = "QrCodeScanModeFragment";
|
||||
|
||||
/** Message sent to hide error message */
|
||||
private static final String TAG = "AudioStreamsQrCodeScanFragment";
|
||||
private static final int MESSAGE_HIDE_ERROR_MESSAGE = 1;
|
||||
|
||||
/** Message sent to show error message */
|
||||
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 long SHOW_ERROR_MESSAGE_INTERVAL = 10000;
|
||||
private static final long SHOW_SUCCESS_SQUARE_INTERVAL = 1000;
|
||||
|
||||
private static final Duration VIBRATE_DURATION_QR_CODE_RECOGNITION = Duration.ofMillis(3);
|
||||
|
||||
public static final String KEY_BROADCAST_METADATA = "key_broadcast_metadata";
|
||||
|
||||
private final Handler mHandler =
|
||||
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 int mCornerRadius;
|
||||
@Nullable private String mBroadcastMetadata;
|
||||
private Context mContext;
|
||||
@Nullable private QrCamera mCamera;
|
||||
private TextureView mTextureView;
|
||||
private TextView mSummary;
|
||||
private TextView mErrorMessage;
|
||||
|
||||
@Override
|
||||
@@ -119,35 +140,23 @@ public class QrCodeScanModeFragment extends InstrumentedFragment
|
||||
var device =
|
||||
AudioStreamsHelper.getCachedBluetoothDeviceInSharingOrLeConnected(
|
||||
mLocalBluetoothManager);
|
||||
mSummary = view.findViewById(android.R.id.summary);
|
||||
if (mSummary != null && device.isPresent()) {
|
||||
mSummary.setText(
|
||||
TextView summary = view.findViewById(android.R.id.summary);
|
||||
if (summary != null && device.isPresent()) {
|
||||
summary.setText(
|
||||
getString(
|
||||
R.string.audio_streams_main_page_qr_code_scanner_summary,
|
||||
device.get().getName()));
|
||||
}
|
||||
}
|
||||
|
||||
private void initCamera(SurfaceTexture surface) {
|
||||
// Check if the camera has already created.
|
||||
@Override
|
||||
public void onSurfaceTextureAvailable(@NonNull SurfaceTexture surface, int width, int height) {
|
||||
if (mCamera == null) {
|
||||
mCamera = new QrCamera(mContext, this);
|
||||
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
|
||||
public void onSurfaceTextureSizeChanged(
|
||||
@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.");
|
||||
}
|
||||
mBroadcastMetadata = qrCode;
|
||||
handleBtLeAudioScanner();
|
||||
Message message = mHandler.obtainMessage(MESSAGE_SCAN_BROADCAST_SUCCESS);
|
||||
mHandler.sendMessageDelayed(message, SHOW_SUCCESS_SQUARE_INTERVAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -194,53 +204,22 @@ public class QrCodeScanModeFragment extends InstrumentedFragment
|
||||
public boolean isValid(String qrCode) {
|
||||
if (qrCode.startsWith(BluetoothBroadcastUtils.SCHEME_BT_BROADCAST_METADATA)) {
|
||||
return true;
|
||||
} else {
|
||||
showErrorMessage(R.string.audio_streams_qr_code_is_not_valid_format);
|
||||
return false;
|
||||
}
|
||||
Message message =
|
||||
mHandler.obtainMessage(
|
||||
MESSAGE_SHOW_ERROR_MESSAGE,
|
||||
getString(R.string.audio_streams_qr_code_is_not_valid_format));
|
||||
message.sendToTarget();
|
||||
return false;
|
||||
}
|
||||
|
||||
private void destroyCamera() {
|
||||
if (mCamera != null) {
|
||||
mCamera.stop();
|
||||
mCamera = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isDecodeTaskAlive() {
|
||||
return mCamera != null && mCamera.isDecodeTaskAlive();
|
||||
}
|
||||
|
||||
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() {
|
||||
if (mCamera != null) {
|
||||
mCamera.stop();
|
||||
@@ -249,9 +228,11 @@ public class QrCodeScanModeFragment extends InstrumentedFragment
|
||||
mErrorMessage.setVisibility(View.INVISIBLE);
|
||||
mTextureView.setVisibility(View.INVISIBLE);
|
||||
|
||||
triggerVibrationForQrCodeRecognition(getContext());
|
||||
triggerVibrationForQrCodeRecognition(mContext);
|
||||
|
||||
getActivity().finish();
|
||||
if (getActivity() != null) {
|
||||
getActivity().finish();
|
||||
}
|
||||
}
|
||||
|
||||
private static void triggerVibrationForQrCodeRecognition(Context context) {
|
||||
@@ -265,17 +246,6 @@ public class QrCodeScanModeFragment extends InstrumentedFragment
|
||||
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
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.LE_AUDIO_BROADCAST_SCAN_QR_CODE;
|
@@ -16,9 +16,9 @@
|
||||
|
||||
package com.android.settings.connecteddevice.audiosharing.audiostreams;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -28,10 +28,10 @@ import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settings.connecteddevice.audiosharing.audiostreams.qrcode.QrCodeScanModeActivity;
|
||||
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.BluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
@@ -107,13 +107,12 @@ public class AudioStreamsScanQrCodeController extends BasePreferenceController
|
||||
return false;
|
||||
}
|
||||
if (preference.getKey().equals(KEY)) {
|
||||
Intent intent = new Intent(mContext, QrCodeScanModeActivity.class);
|
||||
intent.setAction(
|
||||
BluetoothBroadcastUtils.ACTION_BLUETOOTH_LE_AUDIO_QR_CODE_SCANNER);
|
||||
mFragment.startActivityForResult(intent, REQUEST_SCAN_BT_BROADCAST_QR_CODE);
|
||||
if (DEBUG) {
|
||||
Log.w(TAG, "displayPreference() sent intent : " + intent);
|
||||
}
|
||||
new SubSettingLauncher(mContext)
|
||||
.setTitleRes(R.string.audio_streams_main_page_scan_qr_code_title)
|
||||
.setDestination(AudioStreamsQrCodeScanFragment.class.getName())
|
||||
.setResultListener(mFragment, REQUEST_SCAN_BT_BROADCAST_QR_CODE)
|
||||
.setSourceMetricsCategory(SettingsEnums.PAGE_UNKNOWN)
|
||||
.launch();
|
||||
return true;
|
||||
}
|
||||
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 android.app.AlertDialog;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.connecteddevice.audiosharing.audiostreams.qrcode.QrCodeScanModeActivity;
|
||||
import com.android.settingslib.bluetooth.BluetoothBroadcastUtils;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
|
||||
class WaitForSyncState extends AudioStreamStateHandler {
|
||||
@@ -102,14 +101,16 @@ class WaitForSyncState extends AudioStreamStateHandler {
|
||||
.setRightButtonOnClickListener(
|
||||
dialog -> {
|
||||
if (controller.getFragment() != null) {
|
||||
Intent intent = new Intent(context, QrCodeScanModeActivity.class);
|
||||
intent.setAction(
|
||||
BluetoothBroadcastUtils
|
||||
.ACTION_BLUETOOTH_LE_AUDIO_QR_CODE_SCANNER);
|
||||
controller
|
||||
.getFragment()
|
||||
.startActivityForResult(
|
||||
intent, REQUEST_SCAN_BT_BROADCAST_QR_CODE);
|
||||
new SubSettingLauncher(context)
|
||||
.setTitleRes(
|
||||
R.string.audio_streams_main_page_scan_qr_code_title)
|
||||
.setDestination(
|
||||
AudioStreamsQrCodeScanFragment.class.getName())
|
||||
.setResultListener(
|
||||
controller.getFragment(),
|
||||
REQUEST_SCAN_BT_BROADCAST_QR_CODE)
|
||||
.setSourceMetricsCategory(SettingsEnums.PAGE_UNKNOWN)
|
||||
.launch();
|
||||
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