import com.android.settings.connecteddevice.DevicePreferenceCallback;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
-import com.android.settingslib.bluetooth.LocalBluetoothManager;
-import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
/**
mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
}
- @VisibleForTesting
- ConnectedBluetoothDeviceUpdater(DashboardFragment fragment,
- DevicePreferenceCallback devicePreferenceCallback,
- LocalBluetoothManager localBluetoothManager) {
- super(fragment, devicePreferenceCallback, localBluetoothManager);
- mAudioManager = (AudioManager) fragment.getContext().
- getSystemService(Context.AUDIO_SERVICE);
- }
-
@Override
public void onAudioModeChanged() {
forceUpdate();
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowAudioManager;
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
+import com.android.settings.testutils.shadow.ShadowCachedBluetoothDeviceManager;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
-import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
-import com.android.settingslib.bluetooth.LocalBluetoothManager;
import org.junit.Before;
import org.junit.Test;
import java.util.Collection;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(shadows = {ShadowAudioManager.class, ShadowBluetoothAdapter.class})
+@Config(shadows = {ShadowAudioManager.class, ShadowBluetoothAdapter.class,
+ ShadowCachedBluetoothDeviceManager.class})
public class ConnectedBluetoothDeviceUpdaterTest {
@Mock
private DashboardFragment mDashboardFragment;
private CachedBluetoothDevice mCachedBluetoothDevice;
@Mock
private BluetoothDevice mBluetoothDevice;
- @Mock
- private LocalBluetoothManager mLocalManager;
- @Mock
- private CachedBluetoothDeviceManager mCachedDeviceManager;
private Context mContext;
private ConnectedBluetoothDeviceUpdater mBluetoothDeviceUpdater;
- private Collection<CachedBluetoothDevice> cachedDevices;
+ private Collection<CachedBluetoothDevice> mCachedDevices;
private ShadowAudioManager mShadowAudioManager;
private ShadowBluetoothAdapter mShadowBluetoothAdapter;
+ private ShadowCachedBluetoothDeviceManager mShadowCachedBluetoothDeviceManager;
@Before
public void setUp() {
mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
mShadowBluetoothAdapter.setEnabled(true);
mContext = RuntimeEnvironment.application;
+ mShadowCachedBluetoothDeviceManager = Shadow.extract(
+ Utils.getLocalBtManager(mContext).getCachedDeviceManager());
doReturn(mContext).when(mDashboardFragment).getContext();
- cachedDevices =
+ mCachedDevices =
new ArrayList<CachedBluetoothDevice>(new ArrayList<CachedBluetoothDevice>());
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
- when(mLocalManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
- when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(cachedDevices);
-
- mBluetoothDeviceUpdater = spy(new ConnectedBluetoothDeviceUpdater(mDashboardFragment,
- mDevicePreferenceCallback, mLocalManager));
+ mShadowCachedBluetoothDeviceManager.setCachedDevicesCopy(mCachedDevices);
+ mBluetoothDeviceUpdater = spy(new ConnectedBluetoothDeviceUpdater(mContext,
+ mDashboardFragment, mDevicePreferenceCallback));
mBluetoothDeviceUpdater.setPrefContext(mContext);
doNothing().when(mBluetoothDeviceUpdater).addPreference(any());
doNothing().when(mBluetoothDeviceUpdater).removePreference(any());
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isHfpDevice()).thenReturn(true);
- cachedDevices.add(mCachedBluetoothDevice);
+ mCachedDevices.add(mCachedBluetoothDevice);
mBluetoothDeviceUpdater.onAudioModeChanged();
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isHfpDevice()).thenReturn(true);
- cachedDevices.add(mCachedBluetoothDevice);
+ mCachedDevices.add(mCachedBluetoothDevice);
mBluetoothDeviceUpdater.onAudioModeChanged();
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isA2dpDevice()).thenReturn(true);
- cachedDevices.add(mCachedBluetoothDevice);
+ mCachedDevices.add(mCachedBluetoothDevice);
mBluetoothDeviceUpdater.onAudioModeChanged();
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isA2dpDevice()).thenReturn(true);
- cachedDevices.add(mCachedBluetoothDevice);
+ mCachedDevices.add(mCachedBluetoothDevice);
mBluetoothDeviceUpdater.onAudioModeChanged();
--- /dev/null
+/*
+ * Copyright (C) 2018 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.settings.testutils.shadow;
+
+import com.android.settingslib.bluetooth.CachedBluetoothDevice;
+import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
+
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
+
+import java.util.Collection;
+
+/**
+ * Shadow class for {@link CachedBluetoothDeviceManager} to allow tests to manages the set of
+ * remote Bluetooth devices.
+ */
+@Implements(CachedBluetoothDeviceManager.class)
+public class ShadowCachedBluetoothDeviceManager {
+
+ private Collection<CachedBluetoothDevice> mCachedDevices;
+
+ public void setCachedDevicesCopy(Collection<CachedBluetoothDevice> cachedDevices) {
+ mCachedDevices = cachedDevices;
+ }
+
+ @Implementation
+ public synchronized Collection<CachedBluetoothDevice> getCachedDevicesCopy() {
+ return mCachedDevices;
+ }
+}
\ No newline at end of file