Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothCallback.java +1 −1 Original line number Diff line number Diff line Loading @@ -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(); } packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java +28 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } Loading Loading @@ -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(); } } } } packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothEventManagerTest.java 0 → 100644 +81 −0 Original line number Diff line number Diff line /* * 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(); } } packages/SystemUI/src/com/android/systemui/keyboard/KeyboardUI.java +1 −1 Original line number Diff line number Diff line Loading @@ -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 { Loading packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java +1 −1 Original line number Diff line number Diff line Loading @@ -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); Loading Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothCallback.java +1 −1 Original line number Diff line number Diff line Loading @@ -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(); }
packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java +28 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } Loading Loading @@ -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(); } } } }
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothEventManagerTest.java 0 → 100644 +81 −0 Original line number Diff line number Diff line /* * 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(); } }
packages/SystemUI/src/com/android/systemui/keyboard/KeyboardUI.java +1 −1 Original line number Diff line number Diff line Loading @@ -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 { Loading
packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java +1 −1 Original line number Diff line number Diff line Loading @@ -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); Loading