Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1840c2de authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "settinglib: add VolumeControl profile for auto-connect" am: 1400c5ac

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1810279

Change-Id: If9614369c424fb7557bb51e07754d1262dca873a
parents d2dbb3cb 1400c5ac
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -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();
    }

@@ -569,6 +580,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());
        }
+96 −0
Original line number Diff line number Diff line
/*
 * 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;
    }
}