Fix the logic error on PBAP permission assignment
-add test case Bug: 114808220 Test: make -j42 RunSettingsRoboTests Change-Id: Id77ade12c28e31a21c1c7a5dcb28906112d3465b
This commit is contained in:
@@ -54,8 +54,7 @@ public class BluetoothPairingController implements OnCheckedChangeListener,
|
|||||||
|
|
||||||
// Bluetooth dependencies for the connection we are trying to establish
|
// Bluetooth dependencies for the connection we are trying to establish
|
||||||
private LocalBluetoothManager mBluetoothManager;
|
private LocalBluetoothManager mBluetoothManager;
|
||||||
@VisibleForTesting
|
private BluetoothDevice mDevice;
|
||||||
BluetoothDevice mDevice;
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
int mType;
|
int mType;
|
||||||
private String mUserInput;
|
private String mUserInput;
|
||||||
@@ -189,15 +188,15 @@ public class BluetoothPairingController implements OnCheckedChangeListener,
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void setContactSharingState() {
|
public void setContactSharingState() {
|
||||||
if ((mDevice.getPhonebookAccessPermission() != BluetoothDevice.ACCESS_ALLOWED)
|
final int permission = mDevice.getPhonebookAccessPermission();
|
||||||
&& (mDevice.getPhonebookAccessPermission() != BluetoothDevice.ACCESS_REJECTED)) {
|
if (permission == BluetoothDevice.ACCESS_ALLOWED
|
||||||
if (mDevice.getBluetoothClass().getDeviceClass()
|
|| (permission == BluetoothDevice.ACCESS_UNKNOWN && mDevice.getBluetoothClass().
|
||||||
== BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE) {
|
getDeviceClass() == BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE)) {
|
||||||
onCheckedChanged(null, true);
|
onCheckedChanged(null, true);
|
||||||
} else {
|
} else {
|
||||||
onCheckedChanged(null, false);
|
onCheckedChanged(null, false);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -17,9 +17,10 @@ package com.android.settings.bluetooth;
|
|||||||
|
|
||||||
import static android.bluetooth.BluetoothDevice.PAIRING_VARIANT_CONSENT;
|
import static android.bluetooth.BluetoothDevice.PAIRING_VARIANT_CONSENT;
|
||||||
|
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.bluetooth.BluetoothClass;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -39,6 +40,8 @@ import org.robolectric.annotation.Config;
|
|||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@Config(shadows = {ShadowBluetoothPan.class, ShadowBluetoothAdapter.class})
|
@Config(shadows = {ShadowBluetoothPan.class, ShadowBluetoothAdapter.class})
|
||||||
public class BluetoothPairingControllerTest {
|
public class BluetoothPairingControllerTest {
|
||||||
|
private final BluetoothClass mBluetoothClass =
|
||||||
|
new BluetoothClass(BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE);
|
||||||
@Mock
|
@Mock
|
||||||
private BluetoothDevice mBluetoothDevice;
|
private BluetoothDevice mBluetoothDevice;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
@@ -51,7 +54,7 @@ public class BluetoothPairingControllerTest {
|
|||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
final Intent intent = new Intent();
|
final Intent intent = new Intent();
|
||||||
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mBluetoothDevice);
|
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mBluetoothDevice);
|
||||||
mBluetoothPairingController = spy(new BluetoothPairingController(intent, mContext));
|
mBluetoothPairingController = new BluetoothPairingController(intent, mContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -63,4 +66,36 @@ public class BluetoothPairingControllerTest {
|
|||||||
|
|
||||||
verify(mBluetoothDevice).setPhonebookAccessPermission(BluetoothDevice.ACCESS_ALLOWED);
|
verify(mBluetoothDevice).setPhonebookAccessPermission(BluetoothDevice.ACCESS_ALLOWED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onSetContactSharingState_permissionAllowed_setPBAPAllowed() {
|
||||||
|
when(mBluetoothDevice.getPhonebookAccessPermission()).thenReturn(
|
||||||
|
BluetoothDevice.ACCESS_ALLOWED);
|
||||||
|
mBluetoothPairingController.setContactSharingState();
|
||||||
|
mBluetoothPairingController.onDialogPositiveClick(null);
|
||||||
|
|
||||||
|
verify(mBluetoothDevice).setPhonebookAccessPermission(BluetoothDevice.ACCESS_ALLOWED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onSetContactSharingState_permissionUnknown_audioVideoHandsfree_setPBAPAllowed() {
|
||||||
|
when(mBluetoothDevice.getPhonebookAccessPermission()).thenReturn(
|
||||||
|
BluetoothDevice.ACCESS_UNKNOWN);
|
||||||
|
when(mBluetoothDevice.getBluetoothClass()).thenReturn(mBluetoothClass);
|
||||||
|
mBluetoothPairingController.setContactSharingState();
|
||||||
|
mBluetoothPairingController.onDialogPositiveClick(null);
|
||||||
|
|
||||||
|
verify(mBluetoothDevice).setPhonebookAccessPermission(BluetoothDevice.ACCESS_ALLOWED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onSetContactSharingState_permissionRejected_setPBAPRejected() {
|
||||||
|
when(mBluetoothDevice.getPhonebookAccessPermission()).thenReturn(
|
||||||
|
BluetoothDevice.ACCESS_REJECTED);
|
||||||
|
when(mBluetoothDevice.getBluetoothClass()).thenReturn(mBluetoothClass);
|
||||||
|
mBluetoothPairingController.setContactSharingState();
|
||||||
|
mBluetoothPairingController.onDialogPositiveClick(null);
|
||||||
|
|
||||||
|
verify(mBluetoothDevice).setPhonebookAccessPermission(BluetoothDevice.ACCESS_REJECTED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user