• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (C) 2022 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.bluetooth;
18 
19 import android.bluetooth.BluetoothDevice;
20 import android.bluetooth.BluetoothLeBroadcastMetadata;
21 import android.content.Context;
22 import android.util.Log;
23 
24 import com.android.settingslib.bluetooth.BluetoothUtils;
25 import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
26 import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant;
27 import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastMetadata;
28 import com.android.settingslib.bluetooth.LocalBluetoothManager;
29 import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
30 
31 public class QrCodeScanModeController {
32 
33     private static final boolean DEBUG = BluetoothUtils.D;
34     private static final String TAG = "QrCodeScanModeController";
35 
36     private LocalBluetoothLeBroadcastMetadata mLocalBroadcastMetadata;
37     private LocalBluetoothLeBroadcastAssistant mLocalBroadcastAssistant;
38     private LocalBluetoothManager mLocalBluetoothManager;
39     private LocalBluetoothProfileManager mProfileManager;
40 
QrCodeScanModeController(Context context)41     public QrCodeScanModeController(Context context) {
42         if (DEBUG) {
43             Log.d(TAG, "QrCodeScanModeController constructor.");
44         }
45         mLocalBluetoothManager = Utils.getLocalBtManager(context);
46         mProfileManager = mLocalBluetoothManager.getProfileManager();
47         mLocalBroadcastMetadata = new LocalBluetoothLeBroadcastMetadata();
48         CachedBluetoothDeviceManager cachedDeviceManager = new CachedBluetoothDeviceManager(context,
49                 mLocalBluetoothManager);
50         mLocalBroadcastAssistant = new LocalBluetoothLeBroadcastAssistant(context,
51                 cachedDeviceManager, mProfileManager);
52     }
53 
convertToBroadcastMetadata(String qrCodeString)54     private BluetoothLeBroadcastMetadata convertToBroadcastMetadata(String qrCodeString) {
55         return mLocalBroadcastMetadata.convertToBroadcastMetadata(qrCodeString);
56     }
57 
addSource(BluetoothDevice sink, String sourceMetadata, boolean isGroupOp)58     public void addSource(BluetoothDevice sink, String sourceMetadata,
59             boolean isGroupOp) {
60         mLocalBroadcastAssistant.addSource(sink,
61                 convertToBroadcastMetadata(sourceMetadata), isGroupOp);
62     }
63 }
64