Update LocalBluetoothProfile api
This CL include following change: 1. Rename isPreferred() to isEnabled(). 2. Rename getPreferred() to getConnectionPolicy(). 3. Rename setPreferred() to setEnabled(). 4. Remove connect()/disconnect() since when call setEnabled() BT stack will base on input state to do connect/disconnect automatically. 5. Add/update test case. Bug: 141582844 Test: make -j42 RunSettingsLibRoboTests Change-Id: I9aa7d5157028671fcda705bf5cb957c26c4204ad Merged-In: I9aa7d5157028671fcda705bf5cb957c26c4204ad
This commit is contained in:
@@ -150,21 +150,6 @@ public class A2dpProfile implements LocalBluetoothProfile {
|
|||||||
return mService.getDevicesMatchingConnectionStates(states);
|
return mService.getDevicesMatchingConnectionStates(states);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean connect(BluetoothDevice device) {
|
|
||||||
if (mService == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return mService.setConnectionPolicy(device, CONNECTION_POLICY_ALLOWED);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean disconnect(BluetoothDevice device) {
|
|
||||||
if (mService == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getConnectionStatus(BluetoothDevice device) {
|
public int getConnectionStatus(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return BluetoothProfile.STATE_DISCONNECTED;
|
return BluetoothProfile.STATE_DISCONNECTED;
|
||||||
@@ -182,31 +167,37 @@ public class A2dpProfile implements LocalBluetoothProfile {
|
|||||||
return mService.getActiveDevice();
|
return mService.getActiveDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPreferred(BluetoothDevice device) {
|
@Override
|
||||||
|
public boolean isEnabled(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return mService.getConnectionPolicy(device) > CONNECTION_POLICY_FORBIDDEN;
|
return mService.getConnectionPolicy(device) > CONNECTION_POLICY_FORBIDDEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPreferred(BluetoothDevice device) {
|
@Override
|
||||||
|
public int getConnectionPolicy(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return CONNECTION_POLICY_FORBIDDEN;
|
return CONNECTION_POLICY_FORBIDDEN;
|
||||||
}
|
}
|
||||||
return mService.getConnectionPolicy(device);
|
return mService.getConnectionPolicy(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPreferred(BluetoothDevice device, boolean preferred) {
|
@Override
|
||||||
|
public boolean setEnabled(BluetoothDevice device, boolean enabled) {
|
||||||
|
boolean isEnabled = false;
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
if (preferred) {
|
if (enabled) {
|
||||||
if (mService.getConnectionPolicy(device) < CONNECTION_POLICY_ALLOWED) {
|
if (mService.getConnectionPolicy(device) < CONNECTION_POLICY_ALLOWED) {
|
||||||
mService.setConnectionPolicy(device, CONNECTION_POLICY_ALLOWED);
|
isEnabled = mService.setConnectionPolicy(device, CONNECTION_POLICY_ALLOWED);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
isEnabled = mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return isEnabled;
|
||||||
}
|
}
|
||||||
boolean isA2dpPlaying() {
|
boolean isA2dpPlaying() {
|
||||||
if (mService == null) return false;
|
if (mService == null) return false;
|
||||||
|
|||||||
@@ -115,21 +115,6 @@ final class A2dpSinkProfile implements LocalBluetoothProfile {
|
|||||||
BluetoothProfile.STATE_DISCONNECTING});
|
BluetoothProfile.STATE_DISCONNECTING});
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean connect(BluetoothDevice device) {
|
|
||||||
if (mService == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return mService.setConnectionPolicy(device, CONNECTION_POLICY_ALLOWED);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean disconnect(BluetoothDevice device) {
|
|
||||||
if (mService == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getConnectionStatus(BluetoothDevice device) {
|
public int getConnectionStatus(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return BluetoothProfile.STATE_DISCONNECTED;
|
return BluetoothProfile.STATE_DISCONNECTED;
|
||||||
@@ -137,31 +122,37 @@ final class A2dpSinkProfile implements LocalBluetoothProfile {
|
|||||||
return mService.getConnectionState(device);
|
return mService.getConnectionState(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPreferred(BluetoothDevice device) {
|
@Override
|
||||||
|
public boolean isEnabled(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return mService.getConnectionPolicy(device) > CONNECTION_POLICY_FORBIDDEN;
|
return mService.getConnectionPolicy(device) > CONNECTION_POLICY_FORBIDDEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPreferred(BluetoothDevice device) {
|
@Override
|
||||||
|
public int getConnectionPolicy(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return CONNECTION_POLICY_FORBIDDEN;
|
return CONNECTION_POLICY_FORBIDDEN;
|
||||||
}
|
}
|
||||||
return mService.getConnectionPolicy(device);
|
return mService.getConnectionPolicy(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPreferred(BluetoothDevice device, boolean preferred) {
|
@Override
|
||||||
|
public boolean setEnabled(BluetoothDevice device, boolean enabled) {
|
||||||
|
boolean isEnabled = false;
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
if (preferred) {
|
if (enabled) {
|
||||||
if (mService.getConnectionPolicy(device) < CONNECTION_POLICY_ALLOWED) {
|
if (mService.getConnectionPolicy(device) < CONNECTION_POLICY_ALLOWED) {
|
||||||
mService.setConnectionPolicy(device, CONNECTION_POLICY_ALLOWED);
|
isEnabled = mService.setConnectionPolicy(device, CONNECTION_POLICY_ALLOWED);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
isEnabled = mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return isEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isAudioPlaying() {
|
boolean isAudioPlaying() {
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
synchronized (mProfileLock) {
|
synchronized (mProfileLock) {
|
||||||
if (newProfileState == BluetoothProfile.STATE_CONNECTED) {
|
if (newProfileState == BluetoothProfile.STATE_CONNECTED) {
|
||||||
if (profile instanceof MapProfile) {
|
if (profile instanceof MapProfile) {
|
||||||
profile.setPreferred(mDevice, true);
|
profile.setEnabled(mDevice, true);
|
||||||
}
|
}
|
||||||
if (!mProfiles.contains(profile)) {
|
if (!mProfiles.contains(profile)) {
|
||||||
mRemovedProfiles.remove(profile);
|
mRemovedProfiles.remove(profile);
|
||||||
@@ -148,7 +148,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
}
|
}
|
||||||
} else if (profile instanceof MapProfile
|
} else if (profile instanceof MapProfile
|
||||||
&& newProfileState == BluetoothProfile.STATE_DISCONNECTED) {
|
&& newProfileState == BluetoothProfile.STATE_DISCONNECTED) {
|
||||||
profile.setPreferred(mDevice, false);
|
profile.setEnabled(mDevice, false);
|
||||||
} else if (mLocalNapRoleConnected && profile instanceof PanProfile
|
} else if (mLocalNapRoleConnected && profile instanceof PanProfile
|
||||||
&& ((PanProfile) profile).isLocalRoleNap(mDevice)
|
&& ((PanProfile) profile).isLocalRoleNap(mDevice)
|
||||||
&& newProfileState == BluetoothProfile.STATE_DISCONNECTED) {
|
&& newProfileState == BluetoothProfile.STATE_DISCONNECTED) {
|
||||||
@@ -172,12 +172,12 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
PbapServerProfile PbapProfile = mProfileManager.getPbapProfile();
|
PbapServerProfile PbapProfile = mProfileManager.getPbapProfile();
|
||||||
if (PbapProfile != null && isConnectedProfile(PbapProfile))
|
if (PbapProfile != null && isConnectedProfile(PbapProfile))
|
||||||
{
|
{
|
||||||
PbapProfile.disconnect(mDevice);
|
PbapProfile.setEnabled(mDevice, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disconnect(LocalBluetoothProfile profile) {
|
public void disconnect(LocalBluetoothProfile profile) {
|
||||||
if (profile.disconnect(mDevice)) {
|
if (profile.setEnabled(mDevice, false)) {
|
||||||
if (BluetoothUtils.D) {
|
if (BluetoothUtils.D) {
|
||||||
Log.d(TAG, "Command sent successfully:DISCONNECT " + describe(profile));
|
Log.d(TAG, "Command sent successfully:DISCONNECT " + describe(profile));
|
||||||
}
|
}
|
||||||
@@ -264,7 +264,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
if (!ensurePaired()) {
|
if (!ensurePaired()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (profile.connect(mDevice)) {
|
if (profile.setEnabled(mDevice, true)) {
|
||||||
if (BluetoothUtils.D) {
|
if (BluetoothUtils.D) {
|
||||||
Log.d(TAG, "Command sent successfully:CONNECT " + describe(profile));
|
Log.d(TAG, "Command sent successfully:CONNECT " + describe(profile));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,21 +111,6 @@ public class HeadsetProfile implements LocalBluetoothProfile {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean connect(BluetoothDevice device) {
|
|
||||||
if (mService == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return mService.setConnectionPolicy(device, CONNECTION_POLICY_ALLOWED);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean disconnect(BluetoothDevice device) {
|
|
||||||
if (mService == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getConnectionStatus(BluetoothDevice device) {
|
public int getConnectionStatus(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return BluetoothProfile.STATE_DISCONNECTED;
|
return BluetoothProfile.STATE_DISCONNECTED;
|
||||||
@@ -161,31 +146,37 @@ public class HeadsetProfile implements LocalBluetoothProfile {
|
|||||||
return mService.getAudioState(device);
|
return mService.getAudioState(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPreferred(BluetoothDevice device) {
|
@Override
|
||||||
|
public boolean isEnabled(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return mService.getConnectionPolicy(device) > CONNECTION_POLICY_FORBIDDEN;
|
return mService.getConnectionPolicy(device) > CONNECTION_POLICY_FORBIDDEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPreferred(BluetoothDevice device) {
|
@Override
|
||||||
|
public int getConnectionPolicy(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return CONNECTION_POLICY_FORBIDDEN;
|
return CONNECTION_POLICY_FORBIDDEN;
|
||||||
}
|
}
|
||||||
return mService.getConnectionPolicy(device);
|
return mService.getConnectionPolicy(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPreferred(BluetoothDevice device, boolean preferred) {
|
@Override
|
||||||
|
public boolean setEnabled(BluetoothDevice device, boolean enabled) {
|
||||||
|
boolean isEnabled = false;
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
if (preferred) {
|
if (enabled) {
|
||||||
if (mService.getConnectionPolicy(device) < CONNECTION_POLICY_ALLOWED) {
|
if (mService.getConnectionPolicy(device) < CONNECTION_POLICY_ALLOWED) {
|
||||||
mService.setConnectionPolicy(device, CONNECTION_POLICY_ALLOWED);
|
isEnabled = mService.setConnectionPolicy(device, CONNECTION_POLICY_ALLOWED);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
isEnabled = mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return isEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<BluetoothDevice> getConnectedDevices() {
|
public List<BluetoothDevice> getConnectedDevices() {
|
||||||
|
|||||||
@@ -148,21 +148,6 @@ public class HearingAidProfile implements LocalBluetoothProfile {
|
|||||||
return mService.getDevicesMatchingConnectionStates(states);
|
return mService.getDevicesMatchingConnectionStates(states);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean connect(BluetoothDevice device) {
|
|
||||||
if (mService == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return mService.setConnectionPolicy(device, CONNECTION_POLICY_ALLOWED);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean disconnect(BluetoothDevice device) {
|
|
||||||
if (mService == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getConnectionStatus(BluetoothDevice device) {
|
public int getConnectionStatus(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return BluetoothProfile.STATE_DISCONNECTED;
|
return BluetoothProfile.STATE_DISCONNECTED;
|
||||||
@@ -180,31 +165,37 @@ public class HearingAidProfile implements LocalBluetoothProfile {
|
|||||||
return mService.getActiveDevices();
|
return mService.getActiveDevices();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPreferred(BluetoothDevice device) {
|
@Override
|
||||||
|
public boolean isEnabled(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return mService.getConnectionPolicy(device) > CONNECTION_POLICY_FORBIDDEN;
|
return mService.getConnectionPolicy(device) > CONNECTION_POLICY_FORBIDDEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPreferred(BluetoothDevice device) {
|
@Override
|
||||||
|
public int getConnectionPolicy(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return CONNECTION_POLICY_FORBIDDEN;
|
return CONNECTION_POLICY_FORBIDDEN;
|
||||||
}
|
}
|
||||||
return mService.getConnectionPolicy(device);
|
return mService.getConnectionPolicy(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPreferred(BluetoothDevice device, boolean preferred) {
|
@Override
|
||||||
|
public boolean setEnabled(BluetoothDevice device, boolean enabled) {
|
||||||
|
boolean isEnabled = false;
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
if (preferred) {
|
if (enabled) {
|
||||||
if (mService.getConnectionPolicy(device) < CONNECTION_POLICY_ALLOWED) {
|
if (mService.getConnectionPolicy(device) < CONNECTION_POLICY_ALLOWED) {
|
||||||
mService.setConnectionPolicy(device, CONNECTION_POLICY_ALLOWED);
|
isEnabled = mService.setConnectionPolicy(device, CONNECTION_POLICY_ALLOWED);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
isEnabled = mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return isEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVolume(int volume) {
|
public void setVolume(int volume) {
|
||||||
|
|||||||
@@ -124,23 +124,6 @@ final class HfpClientProfile implements LocalBluetoothProfile {
|
|||||||
BluetoothProfile.STATE_DISCONNECTING});
|
BluetoothProfile.STATE_DISCONNECTING});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean connect(BluetoothDevice device) {
|
|
||||||
if (mService == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return mService.setConnectionPolicy(device, CONNECTION_POLICY_ALLOWED);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean disconnect(BluetoothDevice device) {
|
|
||||||
if (mService == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getConnectionStatus(BluetoothDevice device) {
|
public int getConnectionStatus(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
@@ -150,7 +133,7 @@ final class HfpClientProfile implements LocalBluetoothProfile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPreferred(BluetoothDevice device) {
|
public boolean isEnabled(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -158,7 +141,7 @@ final class HfpClientProfile implements LocalBluetoothProfile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getPreferred(BluetoothDevice device) {
|
public int getConnectionPolicy(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return CONNECTION_POLICY_FORBIDDEN;
|
return CONNECTION_POLICY_FORBIDDEN;
|
||||||
}
|
}
|
||||||
@@ -166,17 +149,20 @@ final class HfpClientProfile implements LocalBluetoothProfile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPreferred(BluetoothDevice device, boolean preferred) {
|
public boolean setEnabled(BluetoothDevice device, boolean enabled) {
|
||||||
|
boolean isEnabled = false;
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
if (preferred) {
|
if (enabled) {
|
||||||
if (mService.getConnectionPolicy(device) < CONNECTION_POLICY_ALLOWED) {
|
if (mService.getConnectionPolicy(device) < CONNECTION_POLICY_ALLOWED) {
|
||||||
mService.setConnectionPolicy(device, CONNECTION_POLICY_ALLOWED);
|
isEnabled = mService.setConnectionPolicy(device, CONNECTION_POLICY_ALLOWED);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
isEnabled = mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return isEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.settingslib.bluetooth;
|
package com.android.settingslib.bluetooth;
|
||||||
|
|
||||||
|
import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothClass;
|
import android.bluetooth.BluetoothClass;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
@@ -101,20 +103,6 @@ public class HidDeviceProfile implements LocalBluetoothProfile {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean connect(BluetoothDevice device) {
|
|
||||||
// Don't invoke method in service because settings is not allowed to connect this profile.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean disconnect(BluetoothDevice device) {
|
|
||||||
if (mService == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return mService.disconnect(device);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getConnectionStatus(BluetoothDevice device) {
|
public int getConnectionStatus(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
@@ -124,21 +112,24 @@ public class HidDeviceProfile implements LocalBluetoothProfile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPreferred(BluetoothDevice device) {
|
public boolean isEnabled(BluetoothDevice device) {
|
||||||
return getConnectionStatus(device) != BluetoothProfile.STATE_DISCONNECTED;
|
return getConnectionStatus(device) != BluetoothProfile.STATE_DISCONNECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getPreferred(BluetoothDevice device) {
|
public int getConnectionPolicy(BluetoothDevice device) {
|
||||||
return PREFERRED_VALUE;
|
return PREFERRED_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPreferred(BluetoothDevice device, boolean preferred) {
|
public boolean setEnabled(BluetoothDevice device, boolean enabled) {
|
||||||
|
boolean isEnabled = false;
|
||||||
// if set preferred to false, then disconnect to the current device
|
// if set preferred to false, then disconnect to the current device
|
||||||
if (!preferred) {
|
if (!enabled) {
|
||||||
mService.disconnect(device);
|
isEnabled = mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return isEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -101,20 +101,6 @@ public class HidProfile implements LocalBluetoothProfile {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean connect(BluetoothDevice device) {
|
|
||||||
if (mService == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return mService.setConnectionPolicy(device, CONNECTION_POLICY_ALLOWED);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean disconnect(BluetoothDevice device) {
|
|
||||||
if (mService == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getConnectionStatus(BluetoothDevice device) {
|
public int getConnectionStatus(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return BluetoothProfile.STATE_DISCONNECTED;
|
return BluetoothProfile.STATE_DISCONNECTED;
|
||||||
@@ -122,29 +108,37 @@ public class HidProfile implements LocalBluetoothProfile {
|
|||||||
return mService.getConnectionState(device);
|
return mService.getConnectionState(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPreferred(BluetoothDevice device) {
|
@Override
|
||||||
|
public boolean isEnabled(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return mService.getConnectionPolicy(device) != CONNECTION_POLICY_FORBIDDEN;
|
return mService.getConnectionPolicy(device) != CONNECTION_POLICY_FORBIDDEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPreferred(BluetoothDevice device) {
|
@Override
|
||||||
|
public int getConnectionPolicy(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return CONNECTION_POLICY_FORBIDDEN;
|
return CONNECTION_POLICY_FORBIDDEN;
|
||||||
}
|
}
|
||||||
return mService.getConnectionPolicy(device);
|
return mService.getConnectionPolicy(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPreferred(BluetoothDevice device, boolean preferred) {
|
@Override
|
||||||
if (mService == null) return;
|
public boolean setEnabled(BluetoothDevice device, boolean enabled) {
|
||||||
if (preferred) {
|
boolean isEnabled = false;
|
||||||
|
if (mService == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (enabled) {
|
||||||
if (mService.getConnectionPolicy(device) < CONNECTION_POLICY_ALLOWED) {
|
if (mService.getConnectionPolicy(device) < CONNECTION_POLICY_ALLOWED) {
|
||||||
mService.setConnectionPolicy(device, CONNECTION_POLICY_ALLOWED);
|
isEnabled = mService.setConnectionPolicy(device, CONNECTION_POLICY_ALLOWED);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
isEnabled = mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return isEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|||||||
@@ -35,17 +35,26 @@ public interface LocalBluetoothProfile {
|
|||||||
*/
|
*/
|
||||||
boolean isAutoConnectable();
|
boolean isAutoConnectable();
|
||||||
|
|
||||||
boolean connect(BluetoothDevice device);
|
|
||||||
|
|
||||||
boolean disconnect(BluetoothDevice device);
|
|
||||||
|
|
||||||
int getConnectionStatus(BluetoothDevice device);
|
int getConnectionStatus(BluetoothDevice device);
|
||||||
|
|
||||||
boolean isPreferred(BluetoothDevice device);
|
/**
|
||||||
|
* Return {@code true} if the profile is enabled, otherwise return {@code false}.
|
||||||
|
* @param device the device to query for enable status
|
||||||
|
*/
|
||||||
|
boolean isEnabled(BluetoothDevice device);
|
||||||
|
|
||||||
int getPreferred(BluetoothDevice device);
|
/**
|
||||||
|
* Get the connection policy of the profile.
|
||||||
|
* @param device the device to query for enable status
|
||||||
|
*/
|
||||||
|
int getConnectionPolicy(BluetoothDevice device);
|
||||||
|
|
||||||
void setPreferred(BluetoothDevice device, boolean preferred);
|
/**
|
||||||
|
* Enable the profile if {@code enabled} is {@code true}, otherwise disable profile.
|
||||||
|
* @param device the device to set profile status
|
||||||
|
* @param enabled {@code true} for enable profile, otherwise disable profile.
|
||||||
|
*/
|
||||||
|
boolean setEnabled(BluetoothDevice device, boolean enabled);
|
||||||
|
|
||||||
boolean isProfileReady();
|
boolean isProfileReady();
|
||||||
|
|
||||||
|
|||||||
@@ -528,14 +528,14 @@ public class LocalBluetoothProfileManager {
|
|||||||
(mMapProfile.getConnectionStatus(device) == BluetoothProfile.STATE_CONNECTED)) {
|
(mMapProfile.getConnectionStatus(device) == BluetoothProfile.STATE_CONNECTED)) {
|
||||||
profiles.add(mMapProfile);
|
profiles.add(mMapProfile);
|
||||||
removedProfiles.remove(mMapProfile);
|
removedProfiles.remove(mMapProfile);
|
||||||
mMapProfile.setPreferred(device, true);
|
mMapProfile.setEnabled(device, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((mPbapProfile != null) &&
|
if ((mPbapProfile != null) &&
|
||||||
(mPbapProfile.getConnectionStatus(device) == BluetoothProfile.STATE_CONNECTED)) {
|
(mPbapProfile.getConnectionStatus(device) == BluetoothProfile.STATE_CONNECTED)) {
|
||||||
profiles.add(mPbapProfile);
|
profiles.add(mPbapProfile);
|
||||||
removedProfiles.remove(mPbapProfile);
|
removedProfiles.remove(mPbapProfile);
|
||||||
mPbapProfile.setPreferred(device, true);
|
mPbapProfile.setEnabled(device, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mMapClientProfile != null) {
|
if (mMapClientProfile != null) {
|
||||||
|
|||||||
@@ -114,21 +114,6 @@ public final class MapClientProfile implements LocalBluetoothProfile {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean connect(BluetoothDevice device) {
|
|
||||||
if (mService == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return mService.setConnectionPolicy(device, CONNECTION_POLICY_ALLOWED);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean disconnect(BluetoothDevice device) {
|
|
||||||
if (mService == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getConnectionStatus(BluetoothDevice device) {
|
public int getConnectionStatus(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return BluetoothProfile.STATE_DISCONNECTED;
|
return BluetoothProfile.STATE_DISCONNECTED;
|
||||||
@@ -136,31 +121,37 @@ public final class MapClientProfile implements LocalBluetoothProfile {
|
|||||||
return mService.getConnectionState(device);
|
return mService.getConnectionState(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPreferred(BluetoothDevice device) {
|
@Override
|
||||||
|
public boolean isEnabled(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return mService.getConnectionPolicy(device) > CONNECTION_POLICY_FORBIDDEN;
|
return mService.getConnectionPolicy(device) > CONNECTION_POLICY_FORBIDDEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPreferred(BluetoothDevice device) {
|
@Override
|
||||||
|
public int getConnectionPolicy(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return CONNECTION_POLICY_FORBIDDEN;
|
return CONNECTION_POLICY_FORBIDDEN;
|
||||||
}
|
}
|
||||||
return mService.getConnectionPolicy(device);
|
return mService.getConnectionPolicy(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPreferred(BluetoothDevice device, boolean preferred) {
|
@Override
|
||||||
|
public boolean setEnabled(BluetoothDevice device, boolean enabled) {
|
||||||
|
boolean isEnabled = false;
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
if (preferred) {
|
if (enabled) {
|
||||||
if (mService.getConnectionPolicy(device) < CONNECTION_POLICY_ALLOWED) {
|
if (mService.getConnectionPolicy(device) < CONNECTION_POLICY_ALLOWED) {
|
||||||
mService.setConnectionPolicy(device, CONNECTION_POLICY_ALLOWED);
|
isEnabled = mService.setConnectionPolicy(device, CONNECTION_POLICY_ALLOWED);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
isEnabled = mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return isEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<BluetoothDevice> getConnectedDevices() {
|
public List<BluetoothDevice> getConnectedDevices() {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settingslib.bluetooth;
|
package com.android.settingslib.bluetooth;
|
||||||
|
|
||||||
|
import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_ALLOWED;
|
||||||
import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
|
import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
@@ -112,19 +113,6 @@ public class MapProfile implements LocalBluetoothProfile {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean connect(BluetoothDevice device) {
|
|
||||||
Log.d(TAG, "connect() - should not get called");
|
|
||||||
return false; // MAP never connects out
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean disconnect(BluetoothDevice device) {
|
|
||||||
if (mService == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getConnectionStatus(BluetoothDevice device) {
|
public int getConnectionStatus(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return BluetoothProfile.STATE_DISCONNECTED;
|
return BluetoothProfile.STATE_DISCONNECTED;
|
||||||
@@ -132,31 +120,37 @@ public class MapProfile implements LocalBluetoothProfile {
|
|||||||
return mService.getConnectionState(device);
|
return mService.getConnectionState(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPreferred(BluetoothDevice device) {
|
@Override
|
||||||
|
public boolean isEnabled(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return mService.getConnectionPolicy(device) > CONNECTION_POLICY_FORBIDDEN;
|
return mService.getConnectionPolicy(device) > CONNECTION_POLICY_FORBIDDEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPreferred(BluetoothDevice device) {
|
@Override
|
||||||
|
public int getConnectionPolicy(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return CONNECTION_POLICY_FORBIDDEN;
|
return CONNECTION_POLICY_FORBIDDEN;
|
||||||
}
|
}
|
||||||
return mService.getConnectionPolicy(device);
|
return mService.getConnectionPolicy(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPreferred(BluetoothDevice device, boolean preferred) {
|
@Override
|
||||||
|
public boolean setEnabled(BluetoothDevice device, boolean enabled) {
|
||||||
|
boolean isEnabled = false;
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
if (preferred) {
|
if (enabled) {
|
||||||
if (mService.getConnectionPolicy(device) < BluetoothProfile.CONNECTION_POLICY_ALLOWED) {
|
if (mService.getConnectionPolicy(device) < CONNECTION_POLICY_ALLOWED) {
|
||||||
mService.setConnectionPolicy(device, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
|
isEnabled = mService.setConnectionPolicy(device, CONNECTION_POLICY_ALLOWED);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
isEnabled = mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return isEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<BluetoothDevice> getConnectedDevices() {
|
public List<BluetoothDevice> getConnectedDevices() {
|
||||||
|
|||||||
@@ -40,27 +40,23 @@ final class OppProfile implements LocalBluetoothProfile {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean connect(BluetoothDevice device) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean disconnect(BluetoothDevice device) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getConnectionStatus(BluetoothDevice device) {
|
public int getConnectionStatus(BluetoothDevice device) {
|
||||||
return BluetoothProfile.STATE_DISCONNECTED; // Settings app doesn't handle OPP
|
return BluetoothProfile.STATE_DISCONNECTED; // Settings app doesn't handle OPP
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPreferred(BluetoothDevice device) {
|
@Override
|
||||||
|
public boolean isEnabled(BluetoothDevice device) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPreferred(BluetoothDevice device) {
|
@Override
|
||||||
|
public int getConnectionPolicy(BluetoothDevice device) {
|
||||||
return BluetoothProfile.CONNECTION_POLICY_FORBIDDEN; // Settings app doesn't handle OPP
|
return BluetoothProfile.CONNECTION_POLICY_FORBIDDEN; // Settings app doesn't handle OPP
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPreferred(BluetoothDevice device, boolean preferred) {
|
@Override
|
||||||
|
public boolean setEnabled(BluetoothDevice device, boolean enabled) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isProfileReady() {
|
public boolean isProfileReady() {
|
||||||
|
|||||||
@@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
package com.android.settingslib.bluetooth;
|
package com.android.settingslib.bluetooth;
|
||||||
|
|
||||||
|
import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_ALLOWED;
|
||||||
|
import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothClass;
|
import android.bluetooth.BluetoothClass;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
@@ -83,22 +86,6 @@ public class PanProfile implements LocalBluetoothProfile {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean connect(BluetoothDevice device) {
|
|
||||||
if (mService == null) return false;
|
|
||||||
List<BluetoothDevice> sinks = mService.getConnectedDevices();
|
|
||||||
if (sinks != null) {
|
|
||||||
for (BluetoothDevice sink : sinks) {
|
|
||||||
mService.disconnect(sink);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return mService.connect(device);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean disconnect(BluetoothDevice device) {
|
|
||||||
if (mService == null) return false;
|
|
||||||
return mService.disconnect(device);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getConnectionStatus(BluetoothDevice device) {
|
public int getConnectionStatus(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return BluetoothProfile.STATE_DISCONNECTED;
|
return BluetoothProfile.STATE_DISCONNECTED;
|
||||||
@@ -106,16 +93,36 @@ public class PanProfile implements LocalBluetoothProfile {
|
|||||||
return mService.getConnectionState(device);
|
return mService.getConnectionState(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPreferred(BluetoothDevice device) {
|
@Override
|
||||||
|
public boolean isEnabled(BluetoothDevice device) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPreferred(BluetoothDevice device) {
|
@Override
|
||||||
|
public int getConnectionPolicy(BluetoothDevice device) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPreferred(BluetoothDevice device, boolean preferred) {
|
@Override
|
||||||
// ignore: isPreferred is always true for PAN
|
public boolean setEnabled(BluetoothDevice device, boolean enabled) {
|
||||||
|
boolean isEnabled = false;
|
||||||
|
if (mService == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enabled) {
|
||||||
|
final List<BluetoothDevice> sinks = mService.getConnectedDevices();
|
||||||
|
if (sinks != null) {
|
||||||
|
for (BluetoothDevice sink : sinks) {
|
||||||
|
mService.setConnectionPolicy(sink, CONNECTION_POLICY_FORBIDDEN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
isEnabled = mService.setConnectionPolicy(device, CONNECTION_POLICY_ALLOWED);
|
||||||
|
} else {
|
||||||
|
isEnabled = mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
return isEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|||||||
@@ -126,23 +126,6 @@ public final class PbapClientProfile implements LocalBluetoothProfile {
|
|||||||
BluetoothProfile.STATE_DISCONNECTING});
|
BluetoothProfile.STATE_DISCONNECTING});
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean connect(BluetoothDevice device) {
|
|
||||||
Log.d(TAG,"PBAPClientProfile got connect request");
|
|
||||||
if (mService == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Log.d(TAG,"PBAPClientProfile attempting to connect to " + device.getAddress());
|
|
||||||
return mService.setConnectionPolicy(device, CONNECTION_POLICY_ALLOWED);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean disconnect(BluetoothDevice device) {
|
|
||||||
Log.d(TAG,"PBAPClientProfile got disconnect request");
|
|
||||||
if (mService == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getConnectionStatus(BluetoothDevice device) {
|
public int getConnectionStatus(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return BluetoothProfile.STATE_DISCONNECTED;
|
return BluetoothProfile.STATE_DISCONNECTED;
|
||||||
@@ -150,31 +133,37 @@ public final class PbapClientProfile implements LocalBluetoothProfile {
|
|||||||
return mService.getConnectionState(device);
|
return mService.getConnectionState(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPreferred(BluetoothDevice device) {
|
@Override
|
||||||
|
public boolean isEnabled(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return mService.getConnectionPolicy(device) > CONNECTION_POLICY_FORBIDDEN;
|
return mService.getConnectionPolicy(device) > CONNECTION_POLICY_FORBIDDEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPreferred(BluetoothDevice device) {
|
@Override
|
||||||
|
public int getConnectionPolicy(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return CONNECTION_POLICY_FORBIDDEN;
|
return CONNECTION_POLICY_FORBIDDEN;
|
||||||
}
|
}
|
||||||
return mService.getConnectionPolicy(device);
|
return mService.getConnectionPolicy(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPreferred(BluetoothDevice device, boolean preferred) {
|
@Override
|
||||||
|
public boolean setEnabled(BluetoothDevice device, boolean enabled) {
|
||||||
|
boolean isEnabled = false;
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
if (preferred) {
|
if (enabled) {
|
||||||
if (mService.getConnectionPolicy(device) < CONNECTION_POLICY_ALLOWED) {
|
if (mService.getConnectionPolicy(device) < CONNECTION_POLICY_ALLOWED) {
|
||||||
mService.setConnectionPolicy(device, CONNECTION_POLICY_ALLOWED);
|
isEnabled = mService.setConnectionPolicy(device, CONNECTION_POLICY_ALLOWED);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
isEnabled = mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return isEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|||||||
@@ -91,34 +91,33 @@ public class PbapServerProfile implements LocalBluetoothProfile {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean connect(BluetoothDevice device) {
|
|
||||||
/*Can't connect from server */
|
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean disconnect(BluetoothDevice device) {
|
|
||||||
if (mService == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getConnectionStatus(BluetoothDevice device) {
|
public int getConnectionStatus(BluetoothDevice device) {
|
||||||
if (mService == null) return BluetoothProfile.STATE_DISCONNECTED;
|
if (mService == null) return BluetoothProfile.STATE_DISCONNECTED;
|
||||||
return mService.getConnectionState(device);
|
return mService.getConnectionState(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPreferred(BluetoothDevice device) {
|
@Override
|
||||||
|
public boolean isEnabled(BluetoothDevice device) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPreferred(BluetoothDevice device) {
|
@Override
|
||||||
|
public int getConnectionPolicy(BluetoothDevice device) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPreferred(BluetoothDevice device, boolean preferred) {
|
@Override
|
||||||
// ignore: isPreferred is always true for PBAP
|
public boolean setEnabled(BluetoothDevice device, boolean enabled) {
|
||||||
|
boolean isEnabled = false;
|
||||||
|
if (mService == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!enabled) {
|
||||||
|
isEnabled = mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
return isEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|||||||
@@ -111,21 +111,6 @@ final class SapProfile implements LocalBluetoothProfile {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean connect(BluetoothDevice device) {
|
|
||||||
if (mService == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return mService.setConnectionPolicy(device, CONNECTION_POLICY_ALLOWED);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean disconnect(BluetoothDevice device) {
|
|
||||||
if (mService == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getConnectionStatus(BluetoothDevice device) {
|
public int getConnectionStatus(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return BluetoothProfile.STATE_DISCONNECTED;
|
return BluetoothProfile.STATE_DISCONNECTED;
|
||||||
@@ -133,31 +118,37 @@ final class SapProfile implements LocalBluetoothProfile {
|
|||||||
return mService.getConnectionState(device);
|
return mService.getConnectionState(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPreferred(BluetoothDevice device) {
|
@Override
|
||||||
|
public boolean isEnabled(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return mService.getConnectionPolicy(device) > CONNECTION_POLICY_FORBIDDEN;
|
return mService.getConnectionPolicy(device) > CONNECTION_POLICY_FORBIDDEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPreferred(BluetoothDevice device) {
|
@Override
|
||||||
|
public int getConnectionPolicy(BluetoothDevice device) {
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return CONNECTION_POLICY_FORBIDDEN;
|
return CONNECTION_POLICY_FORBIDDEN;
|
||||||
}
|
}
|
||||||
return mService.getConnectionPolicy(device);
|
return mService.getConnectionPolicy(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPreferred(BluetoothDevice device, boolean preferred) {
|
@Override
|
||||||
|
public boolean setEnabled(BluetoothDevice device, boolean enabled) {
|
||||||
|
boolean isEnabled = false;
|
||||||
if (mService == null) {
|
if (mService == null) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
if (preferred) {
|
if (enabled) {
|
||||||
if (mService.getConnectionPolicy(device) < CONNECTION_POLICY_ALLOWED) {
|
if (mService.getConnectionPolicy(device) < CONNECTION_POLICY_ALLOWED) {
|
||||||
mService.setConnectionPolicy(device, CONNECTION_POLICY_ALLOWED);
|
isEnabled = mService.setConnectionPolicy(device, CONNECTION_POLICY_ALLOWED);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
isEnabled = mService.setConnectionPolicy(device, CONNECTION_POLICY_FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return isEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<BluetoothDevice> getConnectedDevices() {
|
public List<BluetoothDevice> getConnectedDevices() {
|
||||||
|
|||||||
@@ -108,9 +108,9 @@ public class BluetoothMediaManager extends MediaManager implements BluetoothCall
|
|||||||
|
|
||||||
Log.d(TAG, "addConnectableA2dpDevices() device : " + cachedDevice.getName()
|
Log.d(TAG, "addConnectableA2dpDevices() device : " + cachedDevice.getName()
|
||||||
+ ", is connected : " + cachedDevice.isConnected()
|
+ ", is connected : " + cachedDevice.isConnected()
|
||||||
+ ", is preferred : " + a2dpProfile.isPreferred(device));
|
+ ", is enabled : " + a2dpProfile.isEnabled(device));
|
||||||
|
|
||||||
if (a2dpProfile.isPreferred(device)
|
if (a2dpProfile.isEnabled(device)
|
||||||
&& BluetoothDevice.BOND_BONDED == cachedDevice.getBondState()) {
|
&& BluetoothDevice.BOND_BONDED == cachedDevice.getBondState()) {
|
||||||
addMediaDevice(cachedDevice);
|
addMediaDevice(cachedDevice);
|
||||||
}
|
}
|
||||||
@@ -140,13 +140,13 @@ public class BluetoothMediaManager extends MediaManager implements BluetoothCall
|
|||||||
|
|
||||||
Log.d(TAG, "addConnectableHearingAidDevices() device : " + cachedDevice.getName()
|
Log.d(TAG, "addConnectableHearingAidDevices() device : " + cachedDevice.getName()
|
||||||
+ ", is connected : " + cachedDevice.isConnected()
|
+ ", is connected : " + cachedDevice.isConnected()
|
||||||
+ ", is preferred : " + hapProfile.isPreferred(device));
|
+ ", is enabled : " + hapProfile.isEnabled(device));
|
||||||
|
|
||||||
final long hiSyncId = hapProfile.getHiSyncId(device);
|
final long hiSyncId = hapProfile.getHiSyncId(device);
|
||||||
|
|
||||||
// device with same hiSyncId should not be shown in the UI.
|
// device with same hiSyncId should not be shown in the UI.
|
||||||
// So do not add it into connectedDevices.
|
// So do not add it into connectedDevices.
|
||||||
if (!devicesHiSyncIds.contains(hiSyncId) && hapProfile.isPreferred(device)
|
if (!devicesHiSyncIds.contains(hiSyncId) && hapProfile.isEnabled(device)
|
||||||
&& BluetoothDevice.BOND_BONDED == cachedDevice.getBondState()) {
|
&& BluetoothDevice.BOND_BONDED == cachedDevice.getBondState()) {
|
||||||
devicesHiSyncIds.add(hiSyncId);
|
devicesHiSyncIds.add(hiSyncId);
|
||||||
addMediaDevice(cachedDevice);
|
addMediaDevice(cachedDevice);
|
||||||
|
|||||||
@@ -16,12 +16,8 @@
|
|||||||
|
|
||||||
package com.android.settingslib.bluetooth;
|
package com.android.settingslib.bluetooth;
|
||||||
|
|
||||||
import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_ALLOWED;
|
|
||||||
import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothA2dpSink;
|
import android.bluetooth.BluetoothA2dpSink;
|
||||||
@@ -67,18 +63,6 @@ public class A2dpSinkProfileTest {
|
|||||||
mServiceListener.onServiceConnected(BluetoothProfile.A2DP_SINK, mService);
|
mServiceListener.onServiceConnected(BluetoothProfile.A2DP_SINK, mService);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void connect_shouldConnectBluetoothA2dpSink() {
|
|
||||||
mProfile.connect(mBluetoothDevice);
|
|
||||||
verify(mService).setConnectionPolicy(mBluetoothDevice, CONNECTION_POLICY_ALLOWED);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void disconnect_shouldDisconnectBluetoothA2dpSink() {
|
|
||||||
mProfile.disconnect(mBluetoothDevice);
|
|
||||||
verify(mService).setConnectionPolicy(mBluetoothDevice, CONNECTION_POLICY_FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getConnectionStatus_shouldReturnConnectionState() {
|
public void getConnectionStatus_shouldReturnConnectionState() {
|
||||||
when(mService.getConnectionState(mBluetoothDevice)).
|
when(mService.getConnectionState(mBluetoothDevice)).
|
||||||
|
|||||||
@@ -16,12 +16,8 @@
|
|||||||
|
|
||||||
package com.android.settingslib.bluetooth;
|
package com.android.settingslib.bluetooth;
|
||||||
|
|
||||||
import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_ALLOWED;
|
|
||||||
import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
@@ -67,18 +63,6 @@ public class HfpClientProfileTest {
|
|||||||
mServiceListener.onServiceConnected(BluetoothProfile.HEADSET_CLIENT, mService);
|
mServiceListener.onServiceConnected(BluetoothProfile.HEADSET_CLIENT, mService);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void connect_shouldConnectBluetoothHeadsetClient() {
|
|
||||||
mProfile.connect(mBluetoothDevice);
|
|
||||||
verify(mService).setConnectionPolicy(mBluetoothDevice, CONNECTION_POLICY_ALLOWED);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void disconnect_shouldDisconnectBluetoothHeadsetClient() {
|
|
||||||
mProfile.disconnect(mBluetoothDevice);
|
|
||||||
verify(mService).setConnectionPolicy(mBluetoothDevice, CONNECTION_POLICY_FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getConnectionStatus_shouldReturnConnectionState() {
|
public void getConnectionStatus_shouldReturnConnectionState() {
|
||||||
when(mService.getConnectionState(mBluetoothDevice)).
|
when(mService.getConnectionState(mBluetoothDevice)).
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ package com.android.settingslib.bluetooth;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
@@ -64,17 +63,6 @@ public class HidDeviceProfileTest {
|
|||||||
mServiceListener.onServiceConnected(BluetoothProfile.HID_DEVICE, mService);
|
mServiceListener.onServiceConnected(BluetoothProfile.HID_DEVICE, mService);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void connect_shouldReturnFalse() {
|
|
||||||
assertThat(mProfile.connect(mBluetoothDevice)).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void disconnect_shouldDisconnectBluetoothHidDevice() {
|
|
||||||
mProfile.disconnect(mBluetoothDevice);
|
|
||||||
verify(mService).disconnect(mBluetoothDevice);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getConnectionStatus_shouldReturnConnectionState() {
|
public void getConnectionStatus_shouldReturnConnectionState() {
|
||||||
when(mService.getConnectionState(mBluetoothDevice)).
|
when(mService.getConnectionState(mBluetoothDevice)).
|
||||||
|
|||||||
@@ -16,12 +16,8 @@
|
|||||||
|
|
||||||
package com.android.settingslib.bluetooth;
|
package com.android.settingslib.bluetooth;
|
||||||
|
|
||||||
import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_ALLOWED;
|
|
||||||
import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
@@ -67,18 +63,6 @@ public class MapClientProfileTest {
|
|||||||
mServiceListener.onServiceConnected(BluetoothProfile.MAP_CLIENT, mService);
|
mServiceListener.onServiceConnected(BluetoothProfile.MAP_CLIENT, mService);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void connect_shouldConnectBluetoothMapClient() {
|
|
||||||
mProfile.connect(mBluetoothDevice);
|
|
||||||
verify(mService).setConnectionPolicy(mBluetoothDevice, CONNECTION_POLICY_ALLOWED);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void disconnect_shouldDisconnectBluetoothMapClient() {
|
|
||||||
mProfile.disconnect(mBluetoothDevice);
|
|
||||||
verify(mService).setConnectionPolicy(mBluetoothDevice, CONNECTION_POLICY_FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getConnectionStatus_shouldReturnConnectionState() {
|
public void getConnectionStatus_shouldReturnConnectionState() {
|
||||||
when(mService.getConnectionState(mBluetoothDevice)).
|
when(mService.getConnectionState(mBluetoothDevice)).
|
||||||
|
|||||||
@@ -16,12 +16,8 @@
|
|||||||
|
|
||||||
package com.android.settingslib.bluetooth;
|
package com.android.settingslib.bluetooth;
|
||||||
|
|
||||||
import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_ALLOWED;
|
|
||||||
import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
@@ -67,18 +63,6 @@ public class PbapClientProfileTest {
|
|||||||
mServiceListener.onServiceConnected(BluetoothProfile.PBAP_CLIENT, mService);
|
mServiceListener.onServiceConnected(BluetoothProfile.PBAP_CLIENT, mService);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void connect_shouldConnectBluetoothPbapClient() {
|
|
||||||
mProfile.connect(mBluetoothDevice);
|
|
||||||
verify(mService).setConnectionPolicy(mBluetoothDevice, CONNECTION_POLICY_ALLOWED);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void disconnect_shouldDisconnectBluetoothPbapClient() {
|
|
||||||
mProfile.disconnect(mBluetoothDevice);
|
|
||||||
verify(mService).setConnectionPolicy(mBluetoothDevice, CONNECTION_POLICY_FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getConnectionStatus_shouldReturnConnectionState() {
|
public void getConnectionStatus_shouldReturnConnectionState() {
|
||||||
when(mService.getConnectionState(mBluetoothDevice)).
|
when(mService.getConnectionState(mBluetoothDevice)).
|
||||||
|
|||||||
@@ -16,12 +16,8 @@
|
|||||||
|
|
||||||
package com.android.settingslib.bluetooth;
|
package com.android.settingslib.bluetooth;
|
||||||
|
|
||||||
import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_ALLOWED;
|
|
||||||
import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
@@ -66,18 +62,6 @@ public class SapProfileTest {
|
|||||||
mServiceListener.onServiceConnected(BluetoothProfile.SAP, mService);
|
mServiceListener.onServiceConnected(BluetoothProfile.SAP, mService);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void connect_shouldConnectBluetoothSap() {
|
|
||||||
mProfile.connect(mBluetoothDevice);
|
|
||||||
verify(mService).setConnectionPolicy(mBluetoothDevice, CONNECTION_POLICY_ALLOWED);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void disconnect_shouldDisconnectBluetoothSap() {
|
|
||||||
mProfile.disconnect(mBluetoothDevice);
|
|
||||||
verify(mService).setConnectionPolicy(mBluetoothDevice, CONNECTION_POLICY_FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getConnectionStatus_shouldReturnConnectionState() {
|
public void getConnectionStatus_shouldReturnConnectionState() {
|
||||||
when(mService.getConnectionState(mBluetoothDevice)).
|
when(mService.getConnectionState(mBluetoothDevice)).
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ public class BluetoothMediaManagerTest {
|
|||||||
when(mA2dpProfile.getConnectableDevices()).thenReturn(devices);
|
when(mA2dpProfile.getConnectableDevices()).thenReturn(devices);
|
||||||
when(mCachedDeviceManager.findDevice(bluetoothDevice)).thenReturn(cachedDevice);
|
when(mCachedDeviceManager.findDevice(bluetoothDevice)).thenReturn(cachedDevice);
|
||||||
when(cachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
|
when(cachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
|
||||||
when(mA2dpProfile.isPreferred(bluetoothDevice)).thenReturn(true);
|
when(mA2dpProfile.isEnabled(bluetoothDevice)).thenReturn(true);
|
||||||
|
|
||||||
assertThat(mMediaManager.mMediaDevices).isEmpty();
|
assertThat(mMediaManager.mMediaDevices).isEmpty();
|
||||||
mMediaManager.startScan();
|
mMediaManager.startScan();
|
||||||
@@ -113,7 +113,7 @@ public class BluetoothMediaManagerTest {
|
|||||||
when(mA2dpProfile.getConnectableDevices()).thenReturn(devices);
|
when(mA2dpProfile.getConnectableDevices()).thenReturn(devices);
|
||||||
when(mCachedDeviceManager.findDevice(bluetoothDevice)).thenReturn(cachedDevice);
|
when(mCachedDeviceManager.findDevice(bluetoothDevice)).thenReturn(cachedDevice);
|
||||||
when(cachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_NONE);
|
when(cachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_NONE);
|
||||||
when(mA2dpProfile.isPreferred(bluetoothDevice)).thenReturn(true);
|
when(mA2dpProfile.isEnabled(bluetoothDevice)).thenReturn(true);
|
||||||
|
|
||||||
assertThat(mMediaManager.mMediaDevices).isEmpty();
|
assertThat(mMediaManager.mMediaDevices).isEmpty();
|
||||||
mMediaManager.startScan();
|
mMediaManager.startScan();
|
||||||
@@ -141,7 +141,7 @@ public class BluetoothMediaManagerTest {
|
|||||||
when(mHapProfile.getConnectableDevices()).thenReturn(devices);
|
when(mHapProfile.getConnectableDevices()).thenReturn(devices);
|
||||||
when(mCachedDeviceManager.findDevice(bluetoothDevice)).thenReturn(cachedDevice);
|
when(mCachedDeviceManager.findDevice(bluetoothDevice)).thenReturn(cachedDevice);
|
||||||
when(cachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
|
when(cachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
|
||||||
when(mHapProfile.isPreferred(bluetoothDevice)).thenReturn(true);
|
when(mHapProfile.isEnabled(bluetoothDevice)).thenReturn(true);
|
||||||
|
|
||||||
assertThat(mMediaManager.mMediaDevices).isEmpty();
|
assertThat(mMediaManager.mMediaDevices).isEmpty();
|
||||||
mMediaManager.startScan();
|
mMediaManager.startScan();
|
||||||
|
|||||||
Reference in New Issue
Block a user