From a318699c8331e5679ac0db6471bb4b0ebfa40f9c Mon Sep 17 00:00:00 2001 From: Hugh Chen Date: Tue, 7 Dec 2021 09:13:22 +0000 Subject: [PATCH] Update test case for RECEIVER_EXPORTED Bug: 208875751 Test: make -j64 RunSettingsLibRoboTests Change-Id: Ie79354ca68338acc40f16812076f70909f546c6a --- .../bluetooth/BluetoothEventManager.java | 6 ++++++ .../bluetooth/BluetoothEventManagerTest.java | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java index 389892ed15e4e..8ac4e38677fab 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java @@ -169,6 +169,12 @@ public class BluetoothEventManager { } } + @VisibleForTesting + void registerIntentReceiver() { + mContext.registerReceiverAsUser(mBroadcastReceiver, mUserHandle, mAdapterIntentFilter, + null, mReceiverHandler); + } + @VisibleForTesting void addProfileHandler(String action, Handler handler) { mHandlerMap.put(action, handler); diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothEventManagerTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothEventManagerTest.java index 4bff78f4af2ce..bee466d39c23b 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothEventManagerTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothEventManagerTest.java @@ -109,7 +109,7 @@ public class BluetoothEventManagerTest { /* handler= */ null, /* userHandle= */ null); verify(mockContext).registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class), - eq(null), eq(null)); + eq(null), eq(null), eq(Context.RECEIVER_EXPORTED)); } @Test @@ -120,7 +120,7 @@ public class BluetoothEventManagerTest { /* handler= */ null, UserHandle.ALL); verify(mockContext).registerReceiverAsUser(any(BroadcastReceiver.class), eq(UserHandle.ALL), - any(IntentFilter.class), eq(null), eq(null)); + any(IntentFilter.class), eq(null), eq(null), eq(Context.RECEIVER_EXPORTED)); } /** @@ -129,6 +129,7 @@ public class BluetoothEventManagerTest { @Test public void intentWithExtraState_audioStateChangedShouldDispatchToRegisterCallback() { mBluetoothEventManager.registerCallback(mBluetoothCallback); + mBluetoothEventManager.registerIntentReceiver(); mIntent = new Intent(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED); mContext.sendBroadcast(mIntent); @@ -142,6 +143,7 @@ public class BluetoothEventManagerTest { @Test public void intentWithExtraState_phoneStateChangedShouldDispatchToRegisterCallback() { mBluetoothEventManager.registerCallback(mBluetoothCallback); + mBluetoothEventManager.registerIntentReceiver(); mIntent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED); mContext.sendBroadcast(mIntent); @@ -167,6 +169,7 @@ public class BluetoothEventManagerTest { @Test public void dispatchAclConnectionStateChanged_aclDisconnected_shouldDispatchCallback() { mBluetoothEventManager.registerCallback(mBluetoothCallback); + mBluetoothEventManager.registerIntentReceiver(); mIntent = new Intent(BluetoothDevice.ACTION_ACL_DISCONNECTED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mBluetoothDevice); @@ -179,6 +182,7 @@ public class BluetoothEventManagerTest { @Test public void dispatchAclConnectionStateChanged_aclConnected_shouldDispatchCallback() { mBluetoothEventManager.registerCallback(mBluetoothCallback); + mBluetoothEventManager.registerIntentReceiver(); mIntent = new Intent(BluetoothDevice.ACTION_ACL_CONNECTED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mBluetoothDevice); @@ -192,6 +196,7 @@ public class BluetoothEventManagerTest { public void dispatchAclConnectionStateChanged_aclDisconnected_shouldNotCallbackSubDevice() { when(mCachedDeviceManager.isSubDevice(mBluetoothDevice)).thenReturn(true); mBluetoothEventManager.registerCallback(mBluetoothCallback); + mBluetoothEventManager.registerIntentReceiver(); mIntent = new Intent(BluetoothDevice.ACTION_ACL_DISCONNECTED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mBluetoothDevice); @@ -205,6 +210,7 @@ public class BluetoothEventManagerTest { public void dispatchAclConnectionStateChanged_aclConnected_shouldNotCallbackSubDevice() { when(mCachedDeviceManager.isSubDevice(mBluetoothDevice)).thenReturn(true); mBluetoothEventManager.registerCallback(mBluetoothCallback); + mBluetoothEventManager.registerIntentReceiver(); mIntent = new Intent(BluetoothDevice.ACTION_ACL_CONNECTED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mBluetoothDevice); @@ -218,6 +224,7 @@ public class BluetoothEventManagerTest { public void dispatchAclConnectionStateChanged_findDeviceReturnNull_shouldNotDispatchCallback() { when(mCachedDeviceManager.findDevice(mBluetoothDevice)).thenReturn(null); mBluetoothEventManager.registerCallback(mBluetoothCallback); + mBluetoothEventManager.registerIntentReceiver(); mIntent = new Intent(BluetoothDevice.ACTION_ACL_CONNECTED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mBluetoothDevice); @@ -354,6 +361,7 @@ public class BluetoothEventManagerTest { @Test public void showUnbondMessage_reasonAuthTimeout_showCorrectedErrorCode() { + mBluetoothEventManager.registerIntentReceiver(); mIntent = new Intent(BluetoothDevice.ACTION_BOND_STATE_CHANGED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mBluetoothDevice); mIntent.putExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.BOND_NONE); @@ -369,6 +377,7 @@ public class BluetoothEventManagerTest { @Test public void showUnbondMessage_reasonRemoteDeviceDown_showCorrectedErrorCode() { + mBluetoothEventManager.registerIntentReceiver(); mIntent = new Intent(BluetoothDevice.ACTION_BOND_STATE_CHANGED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mBluetoothDevice); mIntent.putExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.BOND_NONE); @@ -385,6 +394,7 @@ public class BluetoothEventManagerTest { @Test public void showUnbondMessage_reasonAuthRejected_showCorrectedErrorCode() { + mBluetoothEventManager.registerIntentReceiver(); mIntent = new Intent(BluetoothDevice.ACTION_BOND_STATE_CHANGED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mBluetoothDevice); mIntent.putExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.BOND_NONE); @@ -400,6 +410,7 @@ public class BluetoothEventManagerTest { @Test public void showUnbondMessage_reasonAuthFailed_showCorrectedErrorCode() { + mBluetoothEventManager.registerIntentReceiver(); mIntent = new Intent(BluetoothDevice.ACTION_BOND_STATE_CHANGED); mIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mBluetoothDevice); mIntent.putExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.BOND_NONE);