summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2021-09-02 22:20:02 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2021-09-02 22:20:02 +0000
commit1400c5acc5682c0546488c9f83148d742d4c1bca (patch)
tree3e376b1ea5c7bec7636974da24b245f57582dbd6
parentdbd54bdca3fcf03715af9d0840239687ae1283de (diff)
parentbebf4be00fb6ee5406f98525c4762d2602b36786 (diff)
downloadbase-1400c5acc5682c0546488c9f83148d742d4c1bca.tar.gz
Merge "settinglib: add VolumeControl profile for auto-connect"
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManager.java17
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/bluetooth/VolumeControlProfile.java96
2 files changed, 113 insertions, 0 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManager.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManager.java
index 34fdc1e45567..c4cb6a1e7197 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManager.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManager.java
@@ -101,6 +101,7 @@ public class LocalBluetoothProfileManager {
private PbapServerProfile mPbapProfile;
private HearingAidProfile mHearingAidProfile;
private SapProfile mSapProfile;
+ private VolumeControlProfile mVolumeControlProfile;
/**
* Mapping from profile name, e.g. "HEADSET" to profile object.
@@ -220,6 +221,16 @@ public class LocalBluetoothProfileManager {
mSapProfile = new SapProfile(mContext, mDeviceManager, this);
addProfile(mSapProfile, SapProfile.NAME, BluetoothSap.ACTION_CONNECTION_STATE_CHANGED);
}
+ if (mVolumeControlProfile == null
+ && supportedList.contains(BluetoothProfile.VOLUME_CONTROL)) {
+ if (DEBUG) {
+ Log.d(TAG, "Adding local Volume Control profile");
+ }
+ mVolumeControlProfile = new VolumeControlProfile();
+ // Note: no event handler for VCP, only for being connectable.
+ mProfileNameMap.put(VolumeControlProfile.NAME, mVolumeControlProfile);
+ }
+
mEventManager.registerProfileIntentReceiver();
}
@@ -565,6 +576,12 @@ public class LocalBluetoothProfileManager {
removedProfiles.remove(mSapProfile);
}
+ if (mVolumeControlProfile != null
+ && ArrayUtils.contains(uuids, BluetoothUuid.VOLUME_CONTROL)) {
+ profiles.add(mVolumeControlProfile);
+ removedProfiles.remove(mVolumeControlProfile);
+ }
+
if (DEBUG) {
Log.d(TAG,"New Profiles" + profiles.toString());
}
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/VolumeControlProfile.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/VolumeControlProfile.java
new file mode 100644
index 000000000000..511df282ea4b
--- /dev/null
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/VolumeControlProfile.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2021 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.settingslib.bluetooth;
+
+import android.bluetooth.BluetoothClass;
+import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothProfile;
+
+/**
+ * VolumeControlProfile handles Bluetooth Volume Control Controller role
+ */
+public class VolumeControlProfile implements LocalBluetoothProfile {
+ private static final String TAG = "VolumeControlProfile";
+ static final String NAME = "VCP";
+ // Order of this profile in device profiles list
+ private static final int ORDINAL = 23;
+
+ @Override
+ public boolean accessProfileEnabled() {
+ return false;
+ }
+
+ @Override
+ public boolean isAutoConnectable() {
+ return true;
+ }
+
+ @Override
+ public int getConnectionStatus(BluetoothDevice device) {
+ return BluetoothProfile.STATE_DISCONNECTED; // Settings app doesn't handle VCP
+ }
+
+ @Override
+ public boolean isEnabled(BluetoothDevice device) {
+ return false;
+ }
+
+ @Override
+ public int getConnectionPolicy(BluetoothDevice device) {
+ return BluetoothProfile.CONNECTION_POLICY_FORBIDDEN; // Settings app doesn't handle VCP
+ }
+
+ @Override
+ public boolean setEnabled(BluetoothDevice device, boolean enabled) {
+ return false;
+ }
+
+ @Override
+ public boolean isProfileReady() {
+ return true;
+ }
+
+ @Override
+ public int getProfileId() {
+ return BluetoothProfile.VOLUME_CONTROL;
+ }
+
+ public String toString() {
+ return NAME;
+ }
+
+ @Override
+ public int getOrdinal() {
+ return ORDINAL;
+ }
+
+ @Override
+ public int getNameResource(BluetoothDevice device) {
+ return 0; // VCP profile not displayed in UI
+ }
+
+ @Override
+ public int getSummaryResourceForDevice(BluetoothDevice device) {
+ return 0; // VCP profile not displayed in UI
+ }
+
+ @Override
+ public int getDrawableResource(BluetoothClass btClass) {
+ // no icon for VCP
+ return 0;
+ }
+}