• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.connecteddevice.audiosharing.audiostreams;
18 
19 import static com.android.settings.connecteddevice.audiosharing.audiostreams.AudioStreamsScanQrCodeController.REQUEST_SCAN_BT_BROADCAST_QR_CODE;
20 
21 import android.app.Activity;
22 import android.app.settings.SettingsEnums;
23 import android.bluetooth.BluetoothLeBroadcastMetadata;
24 import android.content.Context;
25 import android.content.Intent;
26 import android.util.Log;
27 
28 import androidx.annotation.Nullable;
29 
30 import com.android.settings.R;
31 import com.android.settings.dashboard.DashboardFragment;
32 import com.android.settingslib.bluetooth.BluetoothLeBroadcastMetadataExt;
33 import com.android.settingslib.bluetooth.BluetoothUtils;
34 
35 public class AudioStreamsDashboardFragment extends DashboardFragment {
36     public static final String KEY_BROADCAST_METADATA = "key_broadcast_metadata";
37     private static final String TAG = "AudioStreamsDashboardFrag";
38     private static final boolean DEBUG = BluetoothUtils.D;
39     private AudioStreamsProgressCategoryController mAudioStreamsProgressCategoryController;
40 
AudioStreamsDashboardFragment()41     public AudioStreamsDashboardFragment() {
42         super();
43     }
44 
45     @Override
getMetricsCategory()46     public int getMetricsCategory() {
47         return SettingsEnums.AUDIO_STREAM_MAIN;
48     }
49 
50     @Override
getLogTag()51     protected String getLogTag() {
52         return TAG;
53     }
54 
55     @Override
getHelpResource()56     public int getHelpResource() {
57         return R.string.help_url_audio_sharing;
58     }
59 
60     @Override
getPreferenceScreenResId()61     protected int getPreferenceScreenResId() {
62         return R.xml.bluetooth_le_audio_streams;
63     }
64 
65     @Override
onAttach(Context context)66     public void onAttach(Context context) {
67         super.onAttach(context);
68         use(AudioStreamsScanQrCodeController.class).setFragment(this);
69         mAudioStreamsProgressCategoryController = use(AudioStreamsProgressCategoryController.class);
70         mAudioStreamsProgressCategoryController.setFragment(this);
71 
72         if (getArguments() != null) {
73             var broadcastMetadata =
74                     getArguments()
75                             .getParcelable(
76                                     KEY_BROADCAST_METADATA, BluetoothLeBroadcastMetadata.class);
77             if (broadcastMetadata != null) {
78                 mAudioStreamsProgressCategoryController.setSourceFromQrCode(
79                         broadcastMetadata, SourceOriginForLogging.QR_CODE_SCAN_OTHER);
80                 mMetricsFeatureProvider.action(
81                         getContext(),
82                         SettingsEnums.ACTION_AUDIO_STREAM_QR_CODE_SCAN_SUCCEED,
83                         SourceOriginForLogging.QR_CODE_SCAN_OTHER.ordinal());
84             }
85         }
86     }
87 
88     @Override
onActivityResult(int requestCode, int resultCode, @Nullable Intent data)89     public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
90         super.onActivityResult(requestCode, resultCode, data);
91         if (DEBUG) {
92             Log.d(
93                     TAG,
94                     "onActivityResult() requestCode : "
95                             + requestCode
96                             + " resultCode : "
97                             + resultCode);
98         }
99         if (requestCode == REQUEST_SCAN_BT_BROADCAST_QR_CODE) {
100             if (resultCode == Activity.RESULT_OK) {
101                 String broadcastMetadata =
102                         data != null ? data.getStringExtra(KEY_BROADCAST_METADATA) : "";
103                 BluetoothLeBroadcastMetadata source =
104                         BluetoothLeBroadcastMetadataExt.INSTANCE.convertToBroadcastMetadata(
105                                 broadcastMetadata);
106                 if (source == null) {
107                     Log.w(TAG, "onActivityResult() source is null!");
108                     return;
109                 }
110                 if (DEBUG) {
111                     Log.d(TAG, "onActivityResult() broadcastId : " + source.getBroadcastId());
112                 }
113                 if (mAudioStreamsProgressCategoryController == null) {
114                     Log.w(
115                             TAG,
116                             "onActivityResult() AudioStreamsProgressCategoryController is null!");
117                     return;
118                 }
119                 mAudioStreamsProgressCategoryController.setSourceFromQrCode(
120                         source, SourceOriginForLogging.QR_CODE_SCAN_SETTINGS);
121                 mMetricsFeatureProvider.action(
122                         getContext(),
123                         SettingsEnums.ACTION_AUDIO_STREAM_QR_CODE_SCAN_SUCCEED,
124                         SourceOriginForLogging.QR_CODE_SCAN_SETTINGS.ordinal());
125             }
126         }
127     }
128 }
129