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

Commit f16ea680 authored by Doris Ling's avatar Doris Ling
Browse files

Move BluetoothA2dpWrapper to the wrapper package.

- and get rid of the interface/impl implementation.

Change-Id: Ic9c6f15f388d1ca25af2fc9cfd688440b579a900
Fixes: 65634579
Test: make RunSettingsLibRoboTests
parent 4b62d5eb
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ 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;
@@ -42,7 +43,6 @@ public class A2dpProfile implements LocalBluetoothProfile {
    private Context mContext;

    private BluetoothA2dp mService;
    BluetoothA2dpWrapper.Factory mWrapperFactory;
    private BluetoothA2dpWrapper mServiceWrapper;
    private boolean mIsProfileReady;

@@ -67,7 +67,7 @@ public class A2dpProfile implements LocalBluetoothProfile {
        public void onServiceConnected(int profile, BluetoothProfile proxy) {
            if (V) Log.d(TAG,"Bluetooth service connected");
            mService = (BluetoothA2dp) proxy;
            mServiceWrapper = mWrapperFactory.getInstance(mService);
            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()) {
@@ -101,14 +101,13 @@ public class A2dpProfile implements LocalBluetoothProfile {
        mLocalAdapter = adapter;
        mDeviceManager = deviceManager;
        mProfileManager = profileManager;
        mWrapperFactory = new BluetoothA2dpWrapperImpl.Factory();
        mLocalAdapter.getProfileProxy(context, new A2dpServiceListener(),
                BluetoothProfile.A2DP);
    }

    @VisibleForTesting
    void setWrapperFactory(BluetoothA2dpWrapper.Factory factory) {
        mWrapperFactory = factory;
    void setBluetoothA2dpWrapper(BluetoothA2dpWrapper wrapper) {
        mServiceWrapper = wrapper;
    }

    public boolean isConnectable() {
+0 −58
Original line number Diff line number Diff line
/*
 * 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.bluetooth;

import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothCodecStatus;
import android.bluetooth.BluetoothDevice;

/**
 * This interface 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 interface BluetoothA2dpWrapper {

    static interface Factory {
        BluetoothA2dpWrapper getInstance(BluetoothA2dp service);
    }

    /**
     * @return the real {@code BluetoothA2dp} object
     */
    BluetoothA2dp getService();

    /**
     * Wraps {@code BluetoothA2dp.getCodecStatus}
     */
    public BluetoothCodecStatus getCodecStatus();

    /**
     * Wraps {@code BluetoothA2dp.supportsOptionalCodecs}
     */
    int supportsOptionalCodecs(BluetoothDevice device);

    /**
     * Wraps {@code BluetoothA2dp.getOptionalCodecsEnabled}
     */
    int getOptionalCodecsEnabled(BluetoothDevice device);

    /**
     * Wraps {@code BluetoothA2dp.setOptionalCodecsEnabled}
     */
    void setOptionalCodecsEnabled(BluetoothDevice device, int value);
}
+23 −15
Original line number Diff line number Diff line
@@ -14,48 +14,56 @@
 * limitations under the License.
 */

package com.android.settingslib.bluetooth;
package com.android.settingslib.wrapper;

import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothCodecStatus;
import android.bluetooth.BluetoothDevice;

public class BluetoothA2dpWrapperImpl implements BluetoothA2dpWrapper {

    public static class Factory implements BluetoothA2dpWrapper.Factory {
        @Override
        public BluetoothA2dpWrapper getInstance(BluetoothA2dp service) {
            return new BluetoothA2dpWrapperImpl(service);
        }
    }
/**
 * 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 BluetoothA2dpWrapperImpl(BluetoothA2dp service) {
    public BluetoothA2dpWrapper(BluetoothA2dp service) {
        mService = service;
    }

    @Override
    /**
     * @return the real {@code BluetoothA2dp} object
     */
    public BluetoothA2dp getService() {
        return mService;
    }

    @Override
    /**
     * Wraps {@code BluetoothA2dp.getCodecStatus}
     */
    public BluetoothCodecStatus getCodecStatus() {
        return mService.getCodecStatus();
    }

    @Override
    /**
     * Wraps {@code BluetoothA2dp.supportsOptionalCodecs}
     */
    public int supportsOptionalCodecs(BluetoothDevice device) {
        return mService.supportsOptionalCodecs(device);
    }

    @Override
    /**
     * Wraps {@code BluetoothA2dp.getOptionalCodecsEnabled}
     */
    public int getOptionalCodecsEnabled(BluetoothDevice device) {
        return mService.getOptionalCodecsEnabled(device);
    }

    @Override
    /**
     * Wraps {@code BluetoothA2dp.setOptionalCodecsEnabled}
     */
    public void setOptionalCodecsEnabled(BluetoothDevice device, int value) {
        mService.setOptionalCodecsEnabled(device, value);
    }
+2 −1
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.content.res.Resources;

import com.android.settingslib.R;
import com.android.settingslib.TestConfig;
import com.android.settingslib.wrapper.BluetoothA2dpWrapper;

import org.junit.Before;
import org.junit.Test;
@@ -73,8 +74,8 @@ public class A2dpProfileTest {
        }).when(mAdapter).getProfileProxy(any(Context.class), any(), eq(BluetoothProfile.A2DP));

        mProfile = new A2dpProfile(mContext, mAdapter, mDeviceManager, mProfileManager);
        mProfile.setWrapperFactory((service) -> { return mBluetoothA2dpWrapper; });
        mServiceListener.onServiceConnected(BluetoothProfile.A2DP, mBluetoothA2dp);
        mProfile.setBluetoothA2dpWrapper(mBluetoothA2dpWrapper);
    }

    @Test