Merge "settinglib: add VolumeControl profile for auto-connect"

This commit is contained in:
Treehugger Robot
2021-09-02 22:20:02 +00:00
committed by Gerrit Code Review
2 changed files with 113 additions and 0 deletions

View File

@@ -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());
}

View File

@@ -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;
}
}