1 /*
2  * Copyright (C) 2017 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.development;
18 
19 import android.annotation.FlaggedApi;
20 import android.bluetooth.BluetoothCodecConfig;
21 import android.bluetooth.BluetoothCodecType;
22 
23 import androidx.annotation.NonNull;
24 import androidx.annotation.Nullable;
25 
26 /** Utility class for storing current Bluetooth A2DP profile values */
27 public class BluetoothA2dpConfigStore {
28 
29     // init default values
30     private int mCodecTypeNative = BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID;
31     @Nullable private BluetoothCodecType mCodecType = null;
32     private int mCodecPriority = BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT;
33     private int mSampleRate = BluetoothCodecConfig.SAMPLE_RATE_NONE;
34     private int mBitsPerSample = BluetoothCodecConfig.BITS_PER_SAMPLE_NONE;
35     private int mChannelMode = BluetoothCodecConfig.CHANNEL_MODE_NONE;
36     private long mCodecSpecific1Value;
37     private long mCodecSpecific2Value;
38     private long mCodecSpecific3Value;
39     private long mCodecSpecific4Value;
40 
setCodecType(int codecType)41     public void setCodecType(int codecType) {
42         mCodecTypeNative = codecType;
43     }
44 
setCodecType(@ullable BluetoothCodecType codecType)45     public void setCodecType(@Nullable BluetoothCodecType codecType) {
46         mCodecType = codecType;
47     }
48 
setCodecPriority(int codecPriority)49     public void setCodecPriority(int codecPriority) {
50         mCodecPriority = codecPriority;
51     }
52 
setSampleRate(int sampleRate)53     public void setSampleRate(int sampleRate) {
54         mSampleRate = sampleRate;
55     }
56 
setBitsPerSample(int bitsPerSample)57     public void setBitsPerSample(int bitsPerSample) {
58         mBitsPerSample = bitsPerSample;
59     }
60 
setChannelMode(int channelMode)61     public void setChannelMode(int channelMode) {
62         mChannelMode = channelMode;
63     }
64 
setCodecSpecific1Value(long codecSpecific1Value)65     public void setCodecSpecific1Value(long codecSpecific1Value) {
66         mCodecSpecific1Value = codecSpecific1Value;
67     }
68 
setCodecSpecific2Value(int codecSpecific2Value)69     public void setCodecSpecific2Value(int codecSpecific2Value) {
70         mCodecSpecific2Value = codecSpecific2Value;
71     }
72 
setCodecSpecific3Value(int codecSpecific3Value)73     public void setCodecSpecific3Value(int codecSpecific3Value) {
74         mCodecSpecific3Value = codecSpecific3Value;
75     }
76 
setCodecSpecific4Value(int codecSpecific4Value)77     public void setCodecSpecific4Value(int codecSpecific4Value) {
78         mCodecSpecific4Value = codecSpecific4Value;
79     }
80 
81     /** Create codec config utilizing {@link BluetoothCodecConfig.SourceCodecType} */
createCodecConfig()82     public BluetoothCodecConfig createCodecConfig() {
83         return new BluetoothCodecConfig.Builder()
84                 .setCodecType(mCodecTypeNative)
85                 .setCodecPriority(mCodecPriority)
86                 .setSampleRate(mSampleRate)
87                 .setBitsPerSample(mBitsPerSample)
88                 .setChannelMode(mChannelMode)
89                 .setCodecSpecific1(mCodecSpecific1Value)
90                 .setCodecSpecific2(mCodecSpecific2Value)
91                 .setCodecSpecific3(mCodecSpecific3Value)
92                 .setCodecSpecific4(mCodecSpecific4Value)
93                 .build();
94     }
95 
96     /** Create codec config utilizing {@link BluetoothCodecType} */
97     @FlaggedApi(Flags.FLAG_A2DP_OFFLOAD_CODEC_EXTENSIBILITY_SETTINGS)
createCodecConfigFromCodecType()98     public @NonNull BluetoothCodecConfig createCodecConfigFromCodecType() {
99         return new BluetoothCodecConfig.Builder()
100                 .setExtendedCodecType(mCodecType)
101                 .setCodecPriority(mCodecPriority)
102                 .setSampleRate(mSampleRate)
103                 .setBitsPerSample(mBitsPerSample)
104                 .setChannelMode(mChannelMode)
105                 .setCodecSpecific1(mCodecSpecific1Value)
106                 .setCodecSpecific2(mCodecSpecific2Value)
107                 .setCodecSpecific3(mCodecSpecific3Value)
108                 .setCodecSpecific4(mCodecSpecific4Value)
109                 .build();
110     }
111 }
112