import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothCodecConfig;
-import android.bluetooth.BluetoothCodecStatus;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothUuid;
import android.os.ParcelUuid;
import android.util.Log;
-import com.android.internal.annotations.VisibleForTesting;
import com.android.settingslib.R;
-import com.android.settingslib.wrapper.BluetoothA2dpWrapper;
import java.util.ArrayList;
import java.util.Arrays;
private Context mContext;
private BluetoothA2dp mService;
- private BluetoothA2dpWrapper mServiceWrapper;
private boolean mIsProfileReady;
private final LocalBluetoothAdapter mLocalAdapter;
public void onServiceConnected(int profile, BluetoothProfile proxy) {
if (V) Log.d(TAG,"Bluetooth service connected");
mService = (BluetoothA2dp) proxy;
- mServiceWrapper = new BluetoothA2dpWrapper(mService);
// We just bound to the service, so refresh the UI for any connected A2DP devices.
List<BluetoothDevice> deviceList = mService.getConnectedDevices();
while (!deviceList.isEmpty()) {
BluetoothProfile.A2DP);
}
- @VisibleForTesting
- void setBluetoothA2dpWrapper(BluetoothA2dpWrapper wrapper) {
- mServiceWrapper = wrapper;
- }
-
public boolean isConnectable() {
return true;
}
}
public boolean supportsHighQualityAudio(BluetoothDevice device) {
- int support = mServiceWrapper.supportsOptionalCodecs(device);
+ int support = mService.supportsOptionalCodecs(device);
return support == BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED;
}
public boolean isHighQualityAudioEnabled(BluetoothDevice device) {
- int enabled = mServiceWrapper.getOptionalCodecsEnabled(device);
+ int enabled = mService.getOptionalCodecsEnabled(device);
if (enabled != BluetoothA2dp.OPTIONAL_CODECS_PREF_UNKNOWN) {
return enabled == BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED;
} else if (getConnectionStatus(device) != BluetoothProfile.STATE_CONNECTED &&
return true;
}
BluetoothCodecConfig codecConfig = null;
- if (mServiceWrapper.getCodecStatus(device) != null) {
- codecConfig = mServiceWrapper.getCodecStatus(device).getCodecConfig();
+ if (mService.getCodecStatus(device) != null) {
+ codecConfig = mService.getCodecStatus(device).getCodecConfig();
}
if (codecConfig != null) {
return !codecConfig.isMandatoryCodec();
int prefValue = enabled
? BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED
: BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED;
- mServiceWrapper.setOptionalCodecsEnabled(device, prefValue);
+ mService.setOptionalCodecsEnabled(device, prefValue);
if (getConnectionStatus(device) != BluetoothProfile.STATE_CONNECTED) {
return;
}
// We want to get the highest priority codec, since that's the one that will be used with
// this device, and see if it is high-quality (ie non-mandatory).
BluetoothCodecConfig[] selectable = null;
- if (mServiceWrapper.getCodecStatus(device) != null) {
- selectable = mServiceWrapper.getCodecStatus(device).getCodecsSelectableCapabilities();
+ if (mService.getCodecStatus(device) != null) {
+ selectable = mService.getCodecStatus(device).getCodecsSelectableCapabilities();
// To get the highest priority, we sort in reverse.
Arrays.sort(selectable,
(a, b) -> {
+++ /dev/null
-/*
- * Copyright (C) 2017 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.wrapper;
-
-import android.bluetooth.BluetoothA2dp;
-import android.bluetooth.BluetoothCodecStatus;
-import android.bluetooth.BluetoothDevice;
-
-/**
- * This class replicates some methods of android.bluetooth.BluetoothA2dp that are new and not
- * yet available in our current version of Robolectric. It provides a thin wrapper to call the real
- * methods in production and a mock in tests.
- */
-public class BluetoothA2dpWrapper {
-
- private BluetoothA2dp mService;
-
- public BluetoothA2dpWrapper(BluetoothA2dp service) {
- mService = service;
- }
-
- /**
- * @return the real {@code BluetoothA2dp} object
- */
- public BluetoothA2dp getService() {
- return mService;
- }
-
- /**
- * Wraps {@code BluetoothA2dp.getCodecStatus}
- */
- public BluetoothCodecStatus getCodecStatus(BluetoothDevice device) {
- return mService.getCodecStatus(device);
- }
-
- /**
- * Wraps {@code BluetoothA2dp.supportsOptionalCodecs}
- */
- public int supportsOptionalCodecs(BluetoothDevice device) {
- return mService.supportsOptionalCodecs(device);
- }
-
- /**
- * Wraps {@code BluetoothA2dp.getOptionalCodecsEnabled}
- */
- public int getOptionalCodecsEnabled(BluetoothDevice device) {
- return mService.getOptionalCodecsEnabled(device);
- }
-
- /**
- * Wraps {@code BluetoothA2dp.setOptionalCodecsEnabled}
- */
- public void setOptionalCodecsEnabled(BluetoothDevice device, int value) {
- mService.setOptionalCodecsEnabled(device, value);
- }
-}
import android.content.res.Resources;
import com.android.settingslib.R;
-import com.android.settingslib.wrapper.BluetoothA2dpWrapper;
import org.junit.Before;
import org.junit.Test;
@Mock LocalBluetoothProfileManager mProfileManager;
@Mock BluetoothDevice mDevice;
@Mock BluetoothA2dp mBluetoothA2dp;
- @Mock BluetoothA2dpWrapper mBluetoothA2dpWrapper;
BluetoothProfile.ServiceListener mServiceListener;
A2dpProfile mProfile;
mProfile = new A2dpProfile(mContext, mAdapter, mDeviceManager, mProfileManager);
mServiceListener.onServiceConnected(BluetoothProfile.A2DP, mBluetoothA2dp);
- mProfile.setBluetoothA2dpWrapper(mBluetoothA2dpWrapper);
}
@Test
public void supportsHighQualityAudio() {
- when(mBluetoothA2dpWrapper.supportsOptionalCodecs(any())).thenReturn(
+ when(mBluetoothA2dp.supportsOptionalCodecs(any())).thenReturn(
BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED);
assertThat(mProfile.supportsHighQualityAudio(mDevice)).isTrue();
- when(mBluetoothA2dpWrapper.supportsOptionalCodecs(any())).thenReturn(
+ when(mBluetoothA2dp.supportsOptionalCodecs(any())).thenReturn(
BluetoothA2dp.OPTIONAL_CODECS_NOT_SUPPORTED);
assertThat(mProfile.supportsHighQualityAudio(mDevice)).isFalse();
- when(mBluetoothA2dpWrapper.supportsOptionalCodecs(any())).thenReturn(
+ when(mBluetoothA2dp.supportsOptionalCodecs(any())).thenReturn(
BluetoothA2dp.OPTIONAL_CODECS_SUPPORT_UNKNOWN);
assertThat(mProfile.supportsHighQualityAudio(mDevice)).isFalse();
}
@Test
public void isHighQualityAudioEnabled() {
- when(mBluetoothA2dpWrapper.getOptionalCodecsEnabled(any())).thenReturn(
+ when(mBluetoothA2dp.getOptionalCodecsEnabled(any())).thenReturn(
BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED);
assertThat(mProfile.isHighQualityAudioEnabled(mDevice)).isTrue();
- when(mBluetoothA2dpWrapper.getOptionalCodecsEnabled(any())).thenReturn(
+ when(mBluetoothA2dp.getOptionalCodecsEnabled(any())).thenReturn(
BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED);
assertThat(mProfile.isHighQualityAudioEnabled(mDevice)).isFalse();
// then isHighQualityAudioEnabled() should return true or false based on whether optional
// codecs are supported. If the device is connected then we should ask it directly, but if
// the device isn't connected then rely on the stored pref about such support.
- when(mBluetoothA2dpWrapper.getOptionalCodecsEnabled(any())).thenReturn(
+ when(mBluetoothA2dp.getOptionalCodecsEnabled(any())).thenReturn(
BluetoothA2dp.OPTIONAL_CODECS_PREF_UNKNOWN);
when(mBluetoothA2dp.getConnectionState(any())).thenReturn(
BluetoothProfile.STATE_DISCONNECTED);
- when(mBluetoothA2dpWrapper.supportsOptionalCodecs(any())).thenReturn(
+ when(mBluetoothA2dp.supportsOptionalCodecs(any())).thenReturn(
BluetoothA2dp.OPTIONAL_CODECS_NOT_SUPPORTED);
assertThat(mProfile.isHighQualityAudioEnabled(mDevice)).isFalse();
- when(mBluetoothA2dpWrapper.supportsOptionalCodecs(any())).thenReturn(
+ when(mBluetoothA2dp.supportsOptionalCodecs(any())).thenReturn(
BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED);
assertThat(mProfile.isHighQualityAudioEnabled(mDevice)).isTrue();
when(mBluetoothA2dp.getConnectionState(any())).thenReturn(
BluetoothProfile.STATE_CONNECTED);
BluetoothCodecStatus status = mock(BluetoothCodecStatus.class);
- when(mBluetoothA2dpWrapper.getCodecStatus(mDevice)).thenReturn(status);
+ when(mBluetoothA2dp.getCodecStatus(mDevice)).thenReturn(status);
BluetoothCodecConfig config = mock(BluetoothCodecConfig.class);
when(status.getCodecConfig()).thenReturn(config);
when(config.isMandatoryCodec()).thenReturn(false);
// Most tests want to simulate optional codecs being supported by the device, so do that
// by default here.
- when(mBluetoothA2dpWrapper.supportsOptionalCodecs(any())).thenReturn(
+ when(mBluetoothA2dp.supportsOptionalCodecs(any())).thenReturn(
BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED);
}
@Test
public void getLableCodecsNotSupported() {
setupLabelTest();
- when(mBluetoothA2dpWrapper.supportsOptionalCodecs(any())).thenReturn(
+ when(mBluetoothA2dp.supportsOptionalCodecs(any())).thenReturn(
BluetoothA2dp.OPTIONAL_CODECS_NOT_SUPPORTED);
assertThat(mProfile.getHighQualityAudioOptionLabel(mDevice)).isEqualTo(UNKNOWN_CODEC_LABEL);
}
BluetoothCodecStatus status = mock(BluetoothCodecStatus.class);
BluetoothCodecConfig config = mock(BluetoothCodecConfig.class);
BluetoothCodecConfig[] configs = {config};
- when(mBluetoothA2dpWrapper.getCodecStatus(mDevice)).thenReturn(status);
+ when(mBluetoothA2dp.getCodecStatus(mDevice)).thenReturn(status);
when(status.getCodecsSelectableCapabilities()).thenReturn(configs);
when(config.isMandatoryCodec()).thenReturn(true);
BluetoothCodecStatus status = mock(BluetoothCodecStatus.class);
BluetoothCodecConfig config = mock(BluetoothCodecConfig.class);
BluetoothCodecConfig[] configs = {config};
- when(mBluetoothA2dpWrapper.getCodecStatus(mDevice)).thenReturn(status);
+ when(mBluetoothA2dp.getCodecStatus(mDevice)).thenReturn(status);
when(status.getCodecsSelectableCapabilities()).thenReturn(configs);
when(config.isMandatoryCodec()).thenReturn(false);