Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java +5 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ import java.util.concurrent.CopyOnWriteArrayList; */ public class BluetoothEventManager { private static final String TAG = "BluetoothEventManager"; private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); private final LocalBluetoothAdapter mLocalAdapter; private final CachedBluetoothDeviceManager mDeviceManager; Loading Loading @@ -366,6 +367,9 @@ public class BluetoothEventManager { * BluetoothDevice.UNBOND_REASON_* */ private void showUnbondMessage(Context context, String name, int reason) { if (DEBUG) { Log.d(TAG, "showUnbondMessage() name : " + name + ", reason : " + reason); } int errorMsg; switch (reason) { Loading @@ -382,6 +386,7 @@ public class BluetoothEventManager { case BluetoothDevice.UNBOND_REASON_AUTH_TIMEOUT: case BluetoothDevice.UNBOND_REASON_REPEATED_ATTEMPTS: case BluetoothDevice.UNBOND_REASON_REMOTE_AUTH_CANCELED: case BluetoothDevice.UNBOND_REASON_REMOVED: errorMsg = R.string.bluetooth_pairing_error_message; break; default: Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothEventManagerTest.java +83 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,8 @@ import android.content.IntentFilter; import android.os.UserHandle; import android.telephony.TelephonyManager; import com.android.settingslib.R; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; Loading @@ -49,6 +51,8 @@ import java.util.List; @RunWith(RobolectricTestRunner.class) public class BluetoothEventManagerTest { private static final String DEVICE_NAME = "test_device_name"; @Mock private LocalBluetoothAdapter mLocalAdapter; @Mock Loading @@ -71,6 +75,8 @@ public class BluetoothEventManagerTest { private BluetoothDevice mDevice2; @Mock private LocalBluetoothProfileManager mLocalProfileManager; @Mock private BluetoothUtils.ErrorListener mErrorListener; private Context mContext; private Intent mIntent; Loading @@ -92,6 +98,7 @@ public class BluetoothEventManagerTest { mCachedDevice1 = new CachedBluetoothDevice(mContext, mLocalProfileManager, mDevice1); mCachedDevice2 = new CachedBluetoothDevice(mContext, mLocalProfileManager, mDevice2); BluetoothUtils.setErrorListener(mErrorListener); } @Test Loading Loading @@ -344,4 +351,80 @@ public class BluetoothEventManagerTest { assertThat(mCachedDevice2.isActiveDevice(BluetoothProfile.HEADSET)).isFalse(); assertThat(mCachedDevice2.isActiveDevice(BluetoothProfile.HEARING_AID)).isFalse(); } @Test public void showUnbondMessage_reasonRemoved_showCorrectedErrorCode() { mIntent = new Intent(BluetoothDevice.ACTION_BOND_STATE_CHANGED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mBluetoothDevice); mIntent.putExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.BOND_NONE); mIntent.putExtra(BluetoothDevice.EXTRA_REASON, BluetoothDevice.UNBOND_REASON_REMOVED); when(mCachedDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedDevice1); when(mCachedDevice1.getName()).thenReturn(DEVICE_NAME); mContext.sendBroadcast(mIntent); verify(mErrorListener).onShowError(any(Context.class), eq(DEVICE_NAME), eq(R.string.bluetooth_pairing_error_message)); } @Test public void showUnbondMessage_reasonAuthTimeout_showCorrectedErrorCode() { mIntent = new Intent(BluetoothDevice.ACTION_BOND_STATE_CHANGED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mBluetoothDevice); mIntent.putExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.BOND_NONE); mIntent.putExtra(BluetoothDevice.EXTRA_REASON, BluetoothDevice.UNBOND_REASON_AUTH_TIMEOUT); when(mCachedDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedDevice1); when(mCachedDevice1.getName()).thenReturn(DEVICE_NAME); mContext.sendBroadcast(mIntent); verify(mErrorListener).onShowError(any(Context.class), eq(DEVICE_NAME), eq(R.string.bluetooth_pairing_error_message)); } @Test public void showUnbondMessage_reasonRemoteDeviceDown_showCorrectedErrorCode() { mIntent = new Intent(BluetoothDevice.ACTION_BOND_STATE_CHANGED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mBluetoothDevice); mIntent.putExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.BOND_NONE); mIntent.putExtra(BluetoothDevice.EXTRA_REASON, BluetoothDevice.UNBOND_REASON_REMOTE_DEVICE_DOWN); when(mCachedDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedDevice1); when(mCachedDevice1.getName()).thenReturn(DEVICE_NAME); mContext.sendBroadcast(mIntent); verify(mErrorListener).onShowError(any(Context.class), eq(DEVICE_NAME), eq(R.string.bluetooth_pairing_device_down_error_message)); } @Test public void showUnbondMessage_reasonAuthRejected_showCorrectedErrorCode() { mIntent = new Intent(BluetoothDevice.ACTION_BOND_STATE_CHANGED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mBluetoothDevice); mIntent.putExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.BOND_NONE); mIntent.putExtra(BluetoothDevice.EXTRA_REASON, BluetoothDevice.UNBOND_REASON_AUTH_REJECTED); when(mCachedDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedDevice1); when(mCachedDevice1.getName()).thenReturn(DEVICE_NAME); mContext.sendBroadcast(mIntent); verify(mErrorListener).onShowError(any(Context.class), eq(DEVICE_NAME), eq(R.string.bluetooth_pairing_rejected_error_message)); } @Test public void showUnbondMessage_reasonAuthFailed_showCorrectedErrorCode() { mIntent = new Intent(BluetoothDevice.ACTION_BOND_STATE_CHANGED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mBluetoothDevice); mIntent.putExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.BOND_NONE); mIntent.putExtra(BluetoothDevice.EXTRA_REASON, BluetoothDevice.UNBOND_REASON_AUTH_FAILED); when(mCachedDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedDevice1); when(mCachedDevice1.getName()).thenReturn(DEVICE_NAME); mContext.sendBroadcast(mIntent); verify(mErrorListener).onShowError(any(Context.class), eq(DEVICE_NAME), eq(R.string.bluetooth_pairing_pin_error_message)); } } Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java +5 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ import java.util.concurrent.CopyOnWriteArrayList; */ public class BluetoothEventManager { private static final String TAG = "BluetoothEventManager"; private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); private final LocalBluetoothAdapter mLocalAdapter; private final CachedBluetoothDeviceManager mDeviceManager; Loading Loading @@ -366,6 +367,9 @@ public class BluetoothEventManager { * BluetoothDevice.UNBOND_REASON_* */ private void showUnbondMessage(Context context, String name, int reason) { if (DEBUG) { Log.d(TAG, "showUnbondMessage() name : " + name + ", reason : " + reason); } int errorMsg; switch (reason) { Loading @@ -382,6 +386,7 @@ public class BluetoothEventManager { case BluetoothDevice.UNBOND_REASON_AUTH_TIMEOUT: case BluetoothDevice.UNBOND_REASON_REPEATED_ATTEMPTS: case BluetoothDevice.UNBOND_REASON_REMOTE_AUTH_CANCELED: case BluetoothDevice.UNBOND_REASON_REMOVED: errorMsg = R.string.bluetooth_pairing_error_message; break; default: Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothEventManagerTest.java +83 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,8 @@ import android.content.IntentFilter; import android.os.UserHandle; import android.telephony.TelephonyManager; import com.android.settingslib.R; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; Loading @@ -49,6 +51,8 @@ import java.util.List; @RunWith(RobolectricTestRunner.class) public class BluetoothEventManagerTest { private static final String DEVICE_NAME = "test_device_name"; @Mock private LocalBluetoothAdapter mLocalAdapter; @Mock Loading @@ -71,6 +75,8 @@ public class BluetoothEventManagerTest { private BluetoothDevice mDevice2; @Mock private LocalBluetoothProfileManager mLocalProfileManager; @Mock private BluetoothUtils.ErrorListener mErrorListener; private Context mContext; private Intent mIntent; Loading @@ -92,6 +98,7 @@ public class BluetoothEventManagerTest { mCachedDevice1 = new CachedBluetoothDevice(mContext, mLocalProfileManager, mDevice1); mCachedDevice2 = new CachedBluetoothDevice(mContext, mLocalProfileManager, mDevice2); BluetoothUtils.setErrorListener(mErrorListener); } @Test Loading Loading @@ -344,4 +351,80 @@ public class BluetoothEventManagerTest { assertThat(mCachedDevice2.isActiveDevice(BluetoothProfile.HEADSET)).isFalse(); assertThat(mCachedDevice2.isActiveDevice(BluetoothProfile.HEARING_AID)).isFalse(); } @Test public void showUnbondMessage_reasonRemoved_showCorrectedErrorCode() { mIntent = new Intent(BluetoothDevice.ACTION_BOND_STATE_CHANGED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mBluetoothDevice); mIntent.putExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.BOND_NONE); mIntent.putExtra(BluetoothDevice.EXTRA_REASON, BluetoothDevice.UNBOND_REASON_REMOVED); when(mCachedDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedDevice1); when(mCachedDevice1.getName()).thenReturn(DEVICE_NAME); mContext.sendBroadcast(mIntent); verify(mErrorListener).onShowError(any(Context.class), eq(DEVICE_NAME), eq(R.string.bluetooth_pairing_error_message)); } @Test public void showUnbondMessage_reasonAuthTimeout_showCorrectedErrorCode() { mIntent = new Intent(BluetoothDevice.ACTION_BOND_STATE_CHANGED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mBluetoothDevice); mIntent.putExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.BOND_NONE); mIntent.putExtra(BluetoothDevice.EXTRA_REASON, BluetoothDevice.UNBOND_REASON_AUTH_TIMEOUT); when(mCachedDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedDevice1); when(mCachedDevice1.getName()).thenReturn(DEVICE_NAME); mContext.sendBroadcast(mIntent); verify(mErrorListener).onShowError(any(Context.class), eq(DEVICE_NAME), eq(R.string.bluetooth_pairing_error_message)); } @Test public void showUnbondMessage_reasonRemoteDeviceDown_showCorrectedErrorCode() { mIntent = new Intent(BluetoothDevice.ACTION_BOND_STATE_CHANGED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mBluetoothDevice); mIntent.putExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.BOND_NONE); mIntent.putExtra(BluetoothDevice.EXTRA_REASON, BluetoothDevice.UNBOND_REASON_REMOTE_DEVICE_DOWN); when(mCachedDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedDevice1); when(mCachedDevice1.getName()).thenReturn(DEVICE_NAME); mContext.sendBroadcast(mIntent); verify(mErrorListener).onShowError(any(Context.class), eq(DEVICE_NAME), eq(R.string.bluetooth_pairing_device_down_error_message)); } @Test public void showUnbondMessage_reasonAuthRejected_showCorrectedErrorCode() { mIntent = new Intent(BluetoothDevice.ACTION_BOND_STATE_CHANGED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mBluetoothDevice); mIntent.putExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.BOND_NONE); mIntent.putExtra(BluetoothDevice.EXTRA_REASON, BluetoothDevice.UNBOND_REASON_AUTH_REJECTED); when(mCachedDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedDevice1); when(mCachedDevice1.getName()).thenReturn(DEVICE_NAME); mContext.sendBroadcast(mIntent); verify(mErrorListener).onShowError(any(Context.class), eq(DEVICE_NAME), eq(R.string.bluetooth_pairing_rejected_error_message)); } @Test public void showUnbondMessage_reasonAuthFailed_showCorrectedErrorCode() { mIntent = new Intent(BluetoothDevice.ACTION_BOND_STATE_CHANGED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mBluetoothDevice); mIntent.putExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.BOND_NONE); mIntent.putExtra(BluetoothDevice.EXTRA_REASON, BluetoothDevice.UNBOND_REASON_AUTH_FAILED); when(mCachedDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedDevice1); when(mCachedDevice1.getName()).thenReturn(DEVICE_NAME); mContext.sendBroadcast(mIntent); verify(mErrorListener).onShowError(any(Context.class), eq(DEVICE_NAME), eq(R.string.bluetooth_pairing_pin_error_message)); } }