Merge "Rename onProfileAudioStateChanged() to onAudioModeChanged()" into pi-dev

This commit is contained in:
TreeHugger Robot
2018-04-11 13:17:26 +00:00
committed by Android (Google) Code Review
5 changed files with 112 additions and 3 deletions

View File

@@ -29,5 +29,5 @@ public interface BluetoothCallback {
void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState);
void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state);
void onActiveDeviceChanged(CachedBluetoothDevice activeDevice, int bluetoothProfile);
void onProfileAudioStateChanged(int bluetoothProfile, int state);
void onAudioModeChanged();
}

View File

@@ -27,6 +27,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.telephony.TelephonyManager;
import android.util.Log;
import com.android.settingslib.R;
@@ -119,6 +120,12 @@ public class BluetoothEventManager {
addHandler(BluetoothHearingAid.ACTION_ACTIVE_DEVICE_CHANGED,
new ActiveDeviceChangedHandler());
// Headset state changed broadcasts
addHandler(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED,
new AudioModeChangedHandler());
addHandler(TelephonyManager.ACTION_PHONE_STATE_CHANGED,
new AudioModeChangedHandler());
mContext.registerReceiver(mBroadcastReceiver, mAdapterIntentFilter, null, mReceiverHandler);
mContext.registerReceiver(mProfileBroadcastReceiver, mProfileIntentFilter, null, mReceiverHandler);
}
@@ -456,4 +463,25 @@ public class BluetoothEventManager {
}
}
}
private class AudioModeChangedHandler implements Handler {
@Override
public void onReceive(Context context, Intent intent, BluetoothDevice device) {
final String action = intent.getAction();
if (action == null) {
Log.w(TAG, "AudioModeChangedHandler() action is null");
return;
}
dispatchAudioModeChanged();
}
}
private void dispatchAudioModeChanged() {
synchronized (mCallbacks) {
for (BluetoothCallback callback : mCallbacks) {
callback.onAudioModeChanged();
}
}
}
}

View File

@@ -0,0 +1,81 @@
/*
* Copyright 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.settingslib.bluetooth;
import static org.mockito.Mockito.verify;
import android.bluetooth.BluetoothHeadset;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class BluetoothEventManagerTest {
@Mock
private LocalBluetoothAdapter mLocalAdapter;
@Mock
private CachedBluetoothDeviceManager mCachedDeviceManager;
@Mock
private BluetoothCallback mBluetoothCallback;
private Context mContext;
private Intent mIntent;
private BluetoothEventManager mBluetoothEventManager;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mBluetoothEventManager = new BluetoothEventManager(mLocalAdapter,
mCachedDeviceManager, mContext);
}
/**
* Intent ACTION_AUDIO_STATE_CHANGED should dispatch to callback.
*/
@Test
public void intentWithExtraState_audioStateChangedShouldDispatchToRegisterCallback() {
mBluetoothEventManager.registerCallback(mBluetoothCallback);
mIntent = new Intent(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED);
mContext.sendBroadcast(mIntent);
verify(mBluetoothCallback).onAudioModeChanged();
}
/**
* Intent ACTION_PHONE_STATE_CHANGED should dispatch to callback.
*/
@Test
public void intentWithExtraState_phoneStateChangedShouldDispatchToRegisterCallback() {
mBluetoothEventManager.registerCallback(mBluetoothCallback);
mIntent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
mContext.sendBroadcast(mIntent);
verify(mBluetoothCallback).onAudioModeChanged();
}
}

View File

@@ -613,7 +613,7 @@ public class KeyboardUI extends SystemUI implements InputManager.OnTabletModeCha
int bluetoothProfile) { }
@Override
public void onProfileAudioStateChanged(int bluetoothProfile, int state) { }
public void onAudioModeChanged() { }
}
private final class BluetoothErrorListener implements Utils.ErrorListener {

View File

@@ -280,7 +280,7 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa
public void onActiveDeviceChanged(CachedBluetoothDevice activeDevice, int bluetoothProfile) {}
@Override
public void onProfileAudioStateChanged(int bluetoothProfile, int state) {}
public void onAudioModeChanged() {}
private ActuallyCachedState getCachedState(CachedBluetoothDevice device) {
ActuallyCachedState state = mCachedState.get(device);