Loading src/com/android/settings/bluetooth/BluetoothKeyMissingReceiver.java +9 −0 Original line number Original line Diff line number Diff line Loading @@ -55,9 +55,18 @@ public final class BluetoothKeyMissingReceiver extends BroadcastReceiver { } } BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); if (device == null) { return; } PowerManager powerManager = context.getSystemService(PowerManager.class); PowerManager powerManager = context.getSystemService(PowerManager.class); if (TextUtils.equals(action, BluetoothDevice.ACTION_KEY_MISSING)) { if (TextUtils.equals(action, BluetoothDevice.ACTION_KEY_MISSING)) { Log.d(TAG, "Receive ACTION_KEY_MISSING"); Log.d(TAG, "Receive ACTION_KEY_MISSING"); if (device.getBondState() == BluetoothDevice.BOND_NONE) { Log.d( TAG, "Device " + device.getAnonymizedAddress() + " is already unbonded, skip."); return; } Integer keyMissingCount = BluetoothUtils.getKeyMissingCount(device); Integer keyMissingCount = BluetoothUtils.getKeyMissingCount(device); if (keyMissingCount != null && keyMissingCount != 1) { if (keyMissingCount != null && keyMissingCount != 1) { Log.d(TAG, "Key missing count is " + keyMissingCount + ", skip."); Log.d(TAG, "Key missing count is " + keyMissingCount + ", skip."); Loading tests/robotests/src/com/android/settings/bluetooth/BluetoothKeyMissingReceiverTest.java +2 −0 Original line number Original line Diff line number Diff line Loading @@ -127,6 +127,7 @@ public class BluetoothKeyMissingReceiverTest { public void broadcastReceiver_background_showNotification() { public void broadcastReceiver_background_showNotification() { Intent intent = spy(new Intent(BluetoothDevice.ACTION_KEY_MISSING)); Intent intent = spy(new Intent(BluetoothDevice.ACTION_KEY_MISSING)); when(intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE)).thenReturn(mBluetoothDevice); when(intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE)).thenReturn(mBluetoothDevice); when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); BluetoothKeyMissingReceiver bluetoothKeyMissingReceiver = getReceiver(intent); BluetoothKeyMissingReceiver bluetoothKeyMissingReceiver = getReceiver(intent); bluetoothKeyMissingReceiver.onReceive(mContext, intent); bluetoothKeyMissingReceiver.onReceive(mContext, intent); Loading @@ -141,6 +142,7 @@ public class BluetoothKeyMissingReceiverTest { when(mLocalBtManager.isForegroundActivity()).thenReturn(true); when(mLocalBtManager.isForegroundActivity()).thenReturn(true); Intent intent = spy(new Intent(BluetoothDevice.ACTION_KEY_MISSING)); Intent intent = spy(new Intent(BluetoothDevice.ACTION_KEY_MISSING)); when(intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE)).thenReturn(mBluetoothDevice); when(intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE)).thenReturn(mBluetoothDevice); when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); BluetoothKeyMissingReceiver bluetoothKeyMissingReceiver = getReceiver(intent); BluetoothKeyMissingReceiver bluetoothKeyMissingReceiver = getReceiver(intent); bluetoothKeyMissingReceiver.onReceive(mContext, intent); bluetoothKeyMissingReceiver.onReceive(mContext, intent); Loading Loading
src/com/android/settings/bluetooth/BluetoothKeyMissingReceiver.java +9 −0 Original line number Original line Diff line number Diff line Loading @@ -55,9 +55,18 @@ public final class BluetoothKeyMissingReceiver extends BroadcastReceiver { } } BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); if (device == null) { return; } PowerManager powerManager = context.getSystemService(PowerManager.class); PowerManager powerManager = context.getSystemService(PowerManager.class); if (TextUtils.equals(action, BluetoothDevice.ACTION_KEY_MISSING)) { if (TextUtils.equals(action, BluetoothDevice.ACTION_KEY_MISSING)) { Log.d(TAG, "Receive ACTION_KEY_MISSING"); Log.d(TAG, "Receive ACTION_KEY_MISSING"); if (device.getBondState() == BluetoothDevice.BOND_NONE) { Log.d( TAG, "Device " + device.getAnonymizedAddress() + " is already unbonded, skip."); return; } Integer keyMissingCount = BluetoothUtils.getKeyMissingCount(device); Integer keyMissingCount = BluetoothUtils.getKeyMissingCount(device); if (keyMissingCount != null && keyMissingCount != 1) { if (keyMissingCount != null && keyMissingCount != 1) { Log.d(TAG, "Key missing count is " + keyMissingCount + ", skip."); Log.d(TAG, "Key missing count is " + keyMissingCount + ", skip."); Loading
tests/robotests/src/com/android/settings/bluetooth/BluetoothKeyMissingReceiverTest.java +2 −0 Original line number Original line Diff line number Diff line Loading @@ -127,6 +127,7 @@ public class BluetoothKeyMissingReceiverTest { public void broadcastReceiver_background_showNotification() { public void broadcastReceiver_background_showNotification() { Intent intent = spy(new Intent(BluetoothDevice.ACTION_KEY_MISSING)); Intent intent = spy(new Intent(BluetoothDevice.ACTION_KEY_MISSING)); when(intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE)).thenReturn(mBluetoothDevice); when(intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE)).thenReturn(mBluetoothDevice); when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); BluetoothKeyMissingReceiver bluetoothKeyMissingReceiver = getReceiver(intent); BluetoothKeyMissingReceiver bluetoothKeyMissingReceiver = getReceiver(intent); bluetoothKeyMissingReceiver.onReceive(mContext, intent); bluetoothKeyMissingReceiver.onReceive(mContext, intent); Loading @@ -141,6 +142,7 @@ public class BluetoothKeyMissingReceiverTest { when(mLocalBtManager.isForegroundActivity()).thenReturn(true); when(mLocalBtManager.isForegroundActivity()).thenReturn(true); Intent intent = spy(new Intent(BluetoothDevice.ACTION_KEY_MISSING)); Intent intent = spy(new Intent(BluetoothDevice.ACTION_KEY_MISSING)); when(intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE)).thenReturn(mBluetoothDevice); when(intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE)).thenReturn(mBluetoothDevice); when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); BluetoothKeyMissingReceiver bluetoothKeyMissingReceiver = getReceiver(intent); BluetoothKeyMissingReceiver bluetoothKeyMissingReceiver = getReceiver(intent); bluetoothKeyMissingReceiver.onReceive(mContext, intent); bluetoothKeyMissingReceiver.onReceive(mContext, intent); Loading