diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-10-27 02:14:42 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-10-27 02:14:42 +0000 |
commit | 0e6e41947f8c11f3e0bbb2e233b04a1a28c24972 (patch) | |
tree | 762542b78802a443dbad4a44df146b4a3b38b77b | |
parent | 86682abf2a60b5878cf3e7e1263dc77ab1145057 (diff) | |
parent | 443d2001aaeaae28a293b79e6260b98c88e3da17 (diff) | |
download | cts-android13-qpr1-s1-release.tar.gz |
Merge cherrypicks of [20258955] into tm-qpr1-release.android-13.0.0_r18android-13.0.0_r17android-13.0.0_r16android13-qpr1-s1-release
Change-Id: I91275a65acf82578cb046a487a453f6165b99466
19 files changed, 200 insertions, 944 deletions
diff --git a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothA2dpSinkTest.java b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothA2dpSinkTest.java index 8675697a0bb..7a20e9bd8b4 100644 --- a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothA2dpSinkTest.java +++ b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothA2dpSinkTest.java @@ -48,8 +48,8 @@ public class BluetoothA2dpSinkTest extends AndroidTestCase { private BluetoothA2dpSink mBluetoothA2dpSink; private boolean mIsA2dpSinkSupported; private boolean mIsProfileReady; - private Condition mConditionProfileConnection; - private ReentrantLock mProfileConnectionlock; + private Condition mConditionProfileIsConnected; + private ReentrantLock mProfileConnectedlock; @Override public void setUp() throws Exception { @@ -68,8 +68,8 @@ public class BluetoothA2dpSinkTest extends AndroidTestCase { mAdapter = manager.getAdapter(); assertTrue(BTAdapterUtils.enableAdapter(mAdapter, mContext)); - mProfileConnectionlock = new ReentrantLock(); - mConditionProfileConnection = mProfileConnectionlock.newCondition(); + mProfileConnectedlock = new ReentrantLock(); + mConditionProfileIsConnected = mProfileConnectedlock.newCondition(); mIsProfileReady = false; mBluetoothA2dpSink = null; @@ -96,18 +96,6 @@ public class BluetoothA2dpSinkTest extends AndroidTestCase { mAdapter = null; } - public void test_closeProfileProxy() { - if (!(mHasBluetooth && mIsA2dpSinkSupported)) return; - - assertTrue(waitForProfileConnect()); - assertNotNull(mBluetoothA2dpSink); - assertTrue(mIsProfileReady); - - mAdapter.closeProfileProxy(BluetoothProfile.A2DP_SINK, mBluetoothA2dpSink); - assertTrue(waitForProfileDisconnect()); - assertFalse(mIsProfileReady); - } - public void test_getConnectedDevices() { if (!(mHasBluetooth && mIsA2dpSinkSupported)) return; @@ -205,11 +193,11 @@ public class BluetoothA2dpSinkTest extends AndroidTestCase { } private boolean waitForProfileConnect() { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); try { // Wait for the Adapter to be disabled while (!mIsProfileReady) { - if (!mConditionProfileConnection.await( + if (!mConditionProfileIsConnected.await( PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { // Timeout Log.e(TAG, "Timeout while waiting for Profile Connect"); @@ -219,55 +207,28 @@ public class BluetoothA2dpSinkTest extends AndroidTestCase { } catch (InterruptedException e) { Log.e(TAG, "waitForProfileConnect: interrrupted"); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } return mIsProfileReady; } - private boolean waitForProfileDisconnect() { - mConditionProfileConnection = mProfileConnectionlock.newCondition(); - mProfileConnectionlock.lock(); - try { - while (mIsProfileReady) { - if (!mConditionProfileConnection.await( - PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { - // Timeout - Log.e(TAG, "Timeout while waiting for Profile Disconnect"); - break; - } // else spurious wakeups - } - } catch (InterruptedException e) { - Log.e(TAG, "waitForProfileDisconnect: interrrupted"); - } finally { - mProfileConnectionlock.unlock(); - } - return !mIsProfileReady; - } - private final class BluetoothA2dpSinkServiceListener implements BluetoothProfile.ServiceListener { @Override public void onServiceConnected(int profile, BluetoothProfile proxy) { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); mBluetoothA2dpSink = (BluetoothA2dpSink) proxy; mIsProfileReady = true; try { - mConditionProfileConnection.signal(); + mConditionProfileIsConnected.signal(); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } } @Override public void onServiceDisconnected(int profile) { - mProfileConnectionlock.lock(); - mIsProfileReady = false; - try { - mConditionProfileConnection.signal(); - } finally { - mProfileConnectionlock.unlock(); - } } } } diff --git a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothA2dpTest.java b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothA2dpTest.java index 10bd06008c2..515f0ef6921 100644 --- a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothA2dpTest.java +++ b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothA2dpTest.java @@ -49,8 +49,8 @@ public class BluetoothA2dpTest extends AndroidTestCase { private BluetoothA2dp mBluetoothA2dp; private boolean mIsA2dpSupported; private boolean mIsProfileReady; - private ReentrantLock mProfileConnectionlock; - private Condition mConditionProfileConnection; + private Condition mConditionProfileIsConnected; + private ReentrantLock mProfileConnectedlock; @Override public void setUp() throws Exception { @@ -69,9 +69,8 @@ public class BluetoothA2dpTest extends AndroidTestCase { mAdapter = manager.getAdapter(); assertTrue(BTAdapterUtils.enableAdapter(mAdapter, mContext)); - mProfileConnectionlock = new ReentrantLock(); - mConditionProfileConnection = mProfileConnectionlock.newCondition(); - + mProfileConnectedlock = new ReentrantLock(); + mConditionProfileIsConnected = mProfileConnectedlock.newCondition(); mIsProfileReady = false; mBluetoothA2dp = null; @@ -97,18 +96,6 @@ public class BluetoothA2dpTest extends AndroidTestCase { mUiAutomation.dropShellPermissionIdentity(); } - public void test_closeProfileProxy() { - if (!(mHasBluetooth && mIsA2dpSupported)) return; - - assertTrue(waitForProfileConnect()); - assertNotNull(mBluetoothA2dp); - assertTrue(mIsProfileReady); - - mAdapter.closeProfileProxy(BluetoothProfile.A2DP, mBluetoothA2dp); - assertTrue(waitForProfileDisconnect()); - assertFalse(mIsProfileReady); - } - public void test_getConnectedDevices() { if (!(mHasBluetooth && mIsA2dpSupported)) return; @@ -345,11 +332,11 @@ public class BluetoothA2dpTest extends AndroidTestCase { } private boolean waitForProfileConnect() { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); try { // Wait for the Adapter to be disabled while (!mIsProfileReady) { - if (!mConditionProfileConnection.await( + if (!mConditionProfileIsConnected.await( PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { // Timeout Log.e(TAG, "Timeout while waiting for Profile Connect"); @@ -359,55 +346,28 @@ public class BluetoothA2dpTest extends AndroidTestCase { } catch (InterruptedException e) { Log.e(TAG, "waitForProfileConnect: interrrupted"); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } return mIsProfileReady; } - private boolean waitForProfileDisconnect() { - mConditionProfileConnection = mProfileConnectionlock.newCondition(); - mProfileConnectionlock.lock(); - try { - while (mIsProfileReady) { - if (!mConditionProfileConnection.await( - PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { - // Timeout - Log.e(TAG, "Timeout while waiting for Profile Disconnect"); - break; - } // else spurious wakeups - } - } catch (InterruptedException e) { - Log.e(TAG, "waitForProfileDisconnect: interrrupted"); - } finally { - mProfileConnectionlock.unlock(); - } - return !mIsProfileReady; - } - private final class BluetoothA2dpServiceListener implements BluetoothProfile.ServiceListener { @Override public void onServiceConnected(int profile, BluetoothProfile proxy) { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); mBluetoothA2dp = (BluetoothA2dp) proxy; mIsProfileReady = true; try { - mConditionProfileConnection.signal(); + mConditionProfileIsConnected.signal(); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } } @Override public void onServiceDisconnected(int profile) { - mProfileConnectionlock.lock(); - mIsProfileReady = false; - try { - mConditionProfileConnection.signal(); - } finally { - mProfileConnectionlock.unlock(); - } } } } diff --git a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothCsipSetCoordinatorTest.java b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothCsipSetCoordinatorTest.java index c31ecf027ca..50a8c46d150 100644 --- a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothCsipSetCoordinatorTest.java +++ b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothCsipSetCoordinatorTest.java @@ -21,19 +21,23 @@ import static android.Manifest.permission.BLUETOOTH_PRIVILEGED; import static org.junit.Assert.assertThrows; +import android.app.UiAutomation; import android.bluetooth.BluetoothAdapter; -import android.bluetooth.BluetoothCsipSetCoordinator; import android.bluetooth.BluetoothDevice; +import android.bluetooth.BluetoothCsipSetCoordinator; import android.bluetooth.BluetoothManager; import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothStatusCodes; import android.bluetooth.BluetoothUuid; import android.content.pm.PackageManager; +import android.content.res.Resources; import android.os.Build; import android.os.ParcelUuid; import android.test.AndroidTestCase; import android.util.Log; +import androidx.test.InstrumentationRegistry; + import com.android.compatibility.common.util.ApiLevelUtil; import java.util.List; @@ -55,8 +59,8 @@ public class BluetoothCsipSetCoordinatorTest extends AndroidTestCase { private BluetoothCsipSetCoordinator mBluetoothCsipSetCoordinator; private boolean mIsCsipSetCoordinatorSupported; private boolean mIsProfileReady; - private Condition mConditionProfileConnection; - private ReentrantLock mProfileConnectionlock; + private Condition mConditionProfileIsConnected; + private ReentrantLock mProfileConnectedlock; private boolean mGroupLockCallbackCalled; private TestCallback mTestCallback; private Executor mTestExecutor; @@ -90,8 +94,8 @@ public class BluetoothCsipSetCoordinatorTest extends AndroidTestCase { mAdapter = manager.getAdapter(); assertTrue(BTAdapterUtils.enableAdapter(mAdapter, mContext)); - mProfileConnectionlock = new ReentrantLock(); - mConditionProfileConnection = mProfileConnectionlock.newCondition(); + mProfileConnectedlock = new ReentrantLock(); + mConditionProfileIsConnected = mProfileConnectedlock.newCondition(); mIsProfileReady = false; mBluetoothCsipSetCoordinator = null; @@ -138,19 +142,6 @@ public class BluetoothCsipSetCoordinatorTest extends AndroidTestCase { } } - public void testCloseProfileProxy() { - if (!(mHasBluetooth && mIsCsipSetCoordinatorSupported)) return; - - assertTrue(waitForProfileConnect()); - assertNotNull(mBluetoothCsipSetCoordinator); - assertTrue(mIsProfileReady); - - mAdapter.closeProfileProxy( - BluetoothProfile.CSIP_SET_COORDINATOR, mBluetoothCsipSetCoordinator); - assertTrue(waitForProfileDisconnect()); - assertFalse(mIsProfileReady); - } - public void testGetConnectedDevices() { if (!(mHasBluetooth && mIsCsipSetCoordinatorSupported)) return; @@ -274,11 +265,11 @@ public class BluetoothCsipSetCoordinatorTest extends AndroidTestCase { } private boolean waitForProfileConnect() { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); try { // Wait for the Adapter to be disabled while (!mIsProfileReady) { - if (!mConditionProfileConnection.await( + if (!mConditionProfileIsConnected.await( PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { // Timeout Log.e(TAG, "Timeout while waiting for Profile Connect"); @@ -288,55 +279,28 @@ public class BluetoothCsipSetCoordinatorTest extends AndroidTestCase { } catch (InterruptedException e) { Log.e(TAG, "waitForProfileConnect: interrrupted"); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } return mIsProfileReady; } - private boolean waitForProfileDisconnect() { - mConditionProfileConnection = mProfileConnectionlock.newCondition(); - mProfileConnectionlock.lock(); - try { - while (mIsProfileReady) { - if (!mConditionProfileConnection.await( - PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { - // Timeout - Log.e(TAG, "Timeout while waiting for Profile Disconnect"); - break; - } // else spurious wakeups - } - } catch (InterruptedException e) { - Log.e(TAG, "waitForProfileDisconnect: interrrupted"); - } finally { - mProfileConnectionlock.unlock(); - } - return !mIsProfileReady; - } - private final class BluetoothCsipServiceListener implements BluetoothProfile.ServiceListener { @Override public void onServiceConnected(int profile, BluetoothProfile proxy) { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); mBluetoothCsipSetCoordinator = (BluetoothCsipSetCoordinator) proxy; mIsProfileReady = true; try { - mConditionProfileConnection.signal(); + mConditionProfileIsConnected.signal(); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } } @Override public void onServiceDisconnected(int profile) { - mProfileConnectionlock.lock(); - mIsProfileReady = false; - try { - mConditionProfileConnection.signal(); - } finally { - mProfileConnectionlock.unlock(); - } } } } diff --git a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothHapClientTest.java b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothHapClientTest.java index 15fd9bd7112..fb5f241620c 100644 --- a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothHapClientTest.java +++ b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothHapClientTest.java @@ -20,7 +20,6 @@ import static android.Manifest.permission.BLUETOOTH_CONNECT; import static android.Manifest.permission.BLUETOOTH_PRIVILEGED; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThrows; @@ -70,8 +69,8 @@ public class BluetoothHapClientTest { private BluetoothHapClient mBluetoothHapClient; private boolean mIsHapClientSupported; private boolean mIsProfileReady; - private Condition mConditionProfileConnection; - private ReentrantLock mProfileConnectionlock; + private Condition mConditionProfileIsConnected; + private ReentrantLock mProfileConnectedlock; private boolean mOnPresetSelected = false; private boolean mOnPresetSelectionFailed = false; @@ -108,8 +107,8 @@ public class BluetoothHapClientTest { mAdapter = TestUtils.getBluetoothAdapterOrDie(); assertTrue(BTAdapterUtils.enableAdapter(mAdapter, mContext)); - mProfileConnectionlock = new ReentrantLock(); - mConditionProfileConnection = mProfileConnectionlock.newCondition(); + mProfileConnectedlock = new ReentrantLock(); + mConditionProfileIsConnected = mProfileConnectedlock.newCondition(); mIsProfileReady = false; mBluetoothHapClient = null; @@ -135,21 +134,6 @@ public class BluetoothHapClientTest { } @Test - public void test_closeProfileProxy() { - if (shouldSkipTest()) { - return; - } - - assertTrue(waitForProfileConnect()); - assertNotNull(mBluetoothHapClient); - assertTrue(mIsProfileReady); - - mAdapter.closeProfileProxy(BluetoothProfile.HAP_CLIENT, mBluetoothHapClient); - assertTrue(waitForProfileDisconnect()); - assertFalse(mIsProfileReady); - } - - @Test public void testGetConnectedDevices() { if (shouldSkipTest()) { return; @@ -482,11 +466,11 @@ public class BluetoothHapClientTest { } private boolean waitForProfileConnect() { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); try { // Wait for the Adapter to be disabled while (!mIsProfileReady) { - if (!mConditionProfileConnection.await( + if (!mConditionProfileIsConnected.await( PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { // Timeout Log.e(TAG, "Timeout while waiting for Profile Connect"); @@ -496,55 +480,28 @@ public class BluetoothHapClientTest { } catch (InterruptedException e) { Log.e(TAG, "waitForProfileConnect: interrupted"); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } return mIsProfileReady; } - private boolean waitForProfileDisconnect() { - mConditionProfileConnection = mProfileConnectionlock.newCondition(); - mProfileConnectionlock.lock(); - try { - while (mIsProfileReady) { - if (!mConditionProfileConnection.await( - PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { - // Timeout - Log.e(TAG, "Timeout while waiting for Profile Disconnect"); - break; - } // else spurious wakeups - } - } catch (InterruptedException e) { - Log.e(TAG, "waitForProfileDisconnect: interrrupted"); - } finally { - mProfileConnectionlock.unlock(); - } - return !mIsProfileReady; - } - private final class BluetoothHapClientServiceListener implements BluetoothProfile.ServiceListener { @Override public void onServiceConnected(int profile, BluetoothProfile proxy) { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); mBluetoothHapClient = (BluetoothHapClient) proxy; mIsProfileReady = true; try { - mConditionProfileConnection.signal(); + mConditionProfileIsConnected.signal(); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } } @Override public void onServiceDisconnected(int profile) { - mProfileConnectionlock.lock(); - mIsProfileReady = false; - try { - mConditionProfileConnection.signal(); - } finally { - mProfileConnectionlock.unlock(); - } } } } diff --git a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothHeadsetClientTest.java b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothHeadsetClientTest.java index 08f26cf5d83..69b57474ee6 100644 --- a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothHeadsetClientTest.java +++ b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothHeadsetClientTest.java @@ -49,8 +49,8 @@ public class BluetoothHeadsetClientTest extends AndroidTestCase { private BluetoothHeadsetClient mBluetoothHeadsetClient; private boolean mIsHeadsetClientSupported; private boolean mIsProfileReady; - private Condition mConditionProfileConnection; - private ReentrantLock mProfileConnectionlock; + private Condition mConditionProfileIsConnected; + private ReentrantLock mProfileConnectedlock; @Override public void setUp() throws Exception { @@ -69,8 +69,8 @@ public class BluetoothHeadsetClientTest extends AndroidTestCase { mAdapter = manager.getAdapter(); assertTrue(BTAdapterUtils.enableAdapter(mAdapter, mContext)); - mProfileConnectionlock = new ReentrantLock(); - mConditionProfileConnection = mProfileConnectionlock.newCondition(); + mProfileConnectedlock = new ReentrantLock(); + mConditionProfileIsConnected = mProfileConnectedlock.newCondition(); mIsProfileReady = false; mBluetoothHeadsetClient = null; @@ -96,18 +96,6 @@ public class BluetoothHeadsetClientTest extends AndroidTestCase { mAdapter = null; } - public void test_closeProfileProxy() { - if (!(mHasBluetooth && mIsHeadsetClientSupported)) return; - - assertTrue(waitForProfileConnect()); - assertNotNull(mBluetoothHeadsetClient); - assertTrue(mIsProfileReady); - - mAdapter.closeProfileProxy(BluetoothProfile.HEADSET_CLIENT, mBluetoothHeadsetClient); - assertTrue(waitForProfileDisconnect()); - assertFalse(mIsProfileReady); - } - public void test_getConnectedDevices() { if (!(mHasBluetooth && mIsHeadsetClientSupported)) return; @@ -231,11 +219,11 @@ public class BluetoothHeadsetClientTest extends AndroidTestCase { } private boolean waitForProfileConnect() { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); try { // Wait for the Adapter to be disabled while (!mIsProfileReady) { - if (!mConditionProfileConnection.await( + if (!mConditionProfileIsConnected.await( PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { // Timeout Log.e(TAG, "Timeout while waiting for Profile Connect"); @@ -245,55 +233,28 @@ public class BluetoothHeadsetClientTest extends AndroidTestCase { } catch (InterruptedException e) { Log.e(TAG, "waitForProfileConnect: interrrupted"); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } return mIsProfileReady; } - private boolean waitForProfileDisconnect() { - mConditionProfileConnection = mProfileConnectionlock.newCondition(); - mProfileConnectionlock.lock(); - try { - while (mIsProfileReady) { - if (!mConditionProfileConnection.await( - PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { - // Timeout - Log.e(TAG, "Timeout while waiting for Profile Disconnect"); - break; - } // else spurious wakeups - } - } catch (InterruptedException e) { - Log.e(TAG, "waitForProfileDisconnect: interrrupted"); - } finally { - mProfileConnectionlock.unlock(); - } - return !mIsProfileReady; - } - private final class BluetoothHeadsetClientServiceListener implements BluetoothProfile.ServiceListener { @Override public void onServiceConnected(int profile, BluetoothProfile proxy) { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); mBluetoothHeadsetClient = (BluetoothHeadsetClient) proxy; mIsProfileReady = true; try { - mConditionProfileConnection.signal(); + mConditionProfileIsConnected.signal(); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } } @Override public void onServiceDisconnected(int profile) { - mProfileConnectionlock.lock(); - mIsProfileReady = false; - try { - mConditionProfileConnection.signal(); - } finally { - mProfileConnectionlock.unlock(); - } } } } diff --git a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothHeadsetTest.java b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothHeadsetTest.java index d7ab5da893d..cb2c2b4ee44 100644 --- a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothHeadsetTest.java +++ b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothHeadsetTest.java @@ -49,8 +49,8 @@ public class BluetoothHeadsetTest extends AndroidTestCase { private BluetoothHeadset mBluetoothHeadset; private boolean mIsHeadsetSupported; private boolean mIsProfileReady; - private Condition mConditionProfileConnection; - private ReentrantLock mProfileConnectionlock; + private Condition mConditionProfileIsConnected; + private ReentrantLock mProfileConnectedlock; @Override public void setUp() throws Exception { @@ -69,8 +69,8 @@ public class BluetoothHeadsetTest extends AndroidTestCase { mAdapter = manager.getAdapter(); assertTrue(BTAdapterUtils.enableAdapter(mAdapter, mContext)); - mProfileConnectionlock = new ReentrantLock(); - mConditionProfileConnection = mProfileConnectionlock.newCondition(); + mProfileConnectedlock = new ReentrantLock(); + mConditionProfileIsConnected = mProfileConnectedlock.newCondition(); mIsProfileReady = false; mBluetoothHeadset = null; @@ -96,18 +96,6 @@ public class BluetoothHeadsetTest extends AndroidTestCase { mUiAutomation.dropShellPermissionIdentity(); } - public void test_closeProfileProxy() { - if (!(mHasBluetooth && mIsHeadsetSupported)) return; - - assertTrue(waitForProfileConnect()); - assertNotNull(mBluetoothHeadset); - assertTrue(mIsProfileReady); - - mAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset); - assertTrue(waitForProfileDisconnect()); - assertFalse(mIsProfileReady); - } - public void test_getConnectedDevices() { if (!(mHasBluetooth && mIsHeadsetSupported)) return; @@ -388,11 +376,11 @@ public class BluetoothHeadsetTest extends AndroidTestCase { } private boolean waitForProfileConnect() { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); try { // Wait for the Adapter to be disabled while (!mIsProfileReady) { - if (!mConditionProfileConnection.await( + if (!mConditionProfileIsConnected.await( PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { // Timeout Log.e(TAG, "Timeout while waiting for Profile Connect"); @@ -402,55 +390,28 @@ public class BluetoothHeadsetTest extends AndroidTestCase { } catch (InterruptedException e) { Log.e(TAG, "waitForProfileConnect: interrrupted"); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } return mIsProfileReady; } - private boolean waitForProfileDisconnect() { - mConditionProfileConnection = mProfileConnectionlock.newCondition(); - mProfileConnectionlock.lock(); - try { - while (mIsProfileReady) { - if (!mConditionProfileConnection.await( - PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { - // Timeout - Log.e(TAG, "Timeout while waiting for Profile Disconnect"); - break; - } // else spurious wakeups - } - } catch (InterruptedException e) { - Log.e(TAG, "waitForProfileDisconnect: interrrupted"); - } finally { - mProfileConnectionlock.unlock(); - } - return !mIsProfileReady; - } - private final class BluetoothHeadsetServiceListener implements BluetoothProfile.ServiceListener { @Override public void onServiceConnected(int profile, BluetoothProfile proxy) { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); mBluetoothHeadset = (BluetoothHeadset) proxy; mIsProfileReady = true; try { - mConditionProfileConnection.signal(); + mConditionProfileIsConnected.signal(); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } } @Override public void onServiceDisconnected(int profile) { - mProfileConnectionlock.lock(); - mIsProfileReady = false; - try { - mConditionProfileConnection.signal(); - } finally { - mProfileConnectionlock.unlock(); - } } } } diff --git a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothHidDeviceTest.java b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothHidDeviceTest.java index 1815d76f1cc..d94deabbbf5 100644 --- a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothHidDeviceTest.java +++ b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothHidDeviceTest.java @@ -59,8 +59,8 @@ public class BluetoothHidDeviceTest extends AndroidTestCase { private boolean mIsProfileReady; private BluetoothAdapter mAdapter; private UiAutomation mUiAutomation; - private Condition mConditionProfileConnection; - private ReentrantLock mProfileConnectionlock; + private Condition mConditionProfileIsConnected; + private ReentrantLock mProfileConnectedlock; private BluetoothHidDevice mBluetoothHidDevice; @@ -81,8 +81,8 @@ public class BluetoothHidDeviceTest extends AndroidTestCase { mAdapter = manager.getAdapter(); assertTrue(BTAdapterUtils.enableAdapter(mAdapter, mContext)); - mProfileConnectionlock = new ReentrantLock(); - mConditionProfileConnection = mProfileConnectionlock.newCondition(); + mProfileConnectedlock = new ReentrantLock(); + mConditionProfileIsConnected = mProfileConnectedlock.newCondition(); mIsProfileReady = false; mBluetoothHidDevice = null; @@ -109,18 +109,6 @@ public class BluetoothHidDeviceTest extends AndroidTestCase { mUiAutomation.dropShellPermissionIdentity(); } - public void test_closeProfileProxy() { - if (!(mHasBluetooth && mIsHidSupported)) return; - - assertTrue(waitForProfileConnect()); - assertNotNull(mBluetoothHidDevice); - assertTrue(mIsProfileReady); - - mAdapter.closeProfileProxy(BluetoothProfile.HID_DEVICE, mBluetoothHidDevice); - assertTrue(waitForProfileDisconnect()); - assertFalse(mIsProfileReady); - } - public void test_getDevicesMatchingConnectionStates() { if (!(mHasBluetooth && mIsHidSupported)) return; @@ -218,12 +206,13 @@ public class BluetoothHidDeviceTest extends AndroidTestCase { testDevice, BluetoothProfile.CONNECTION_POLICY_FORBIDDEN)); } + private boolean waitForProfileConnect() { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); try { // Wait for the Adapter to be disabled while (!mIsProfileReady) { - if (!mConditionProfileConnection.await( + if (!mConditionProfileIsConnected.await( PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { // Timeout Log.e(TAG, "Timeout while waiting for Profile Connect"); @@ -233,54 +222,28 @@ public class BluetoothHidDeviceTest extends AndroidTestCase { } catch (InterruptedException e) { Log.e(TAG, "waitForProfileConnect: interrrupted"); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } return mIsProfileReady; } - private boolean waitForProfileDisconnect() { - mConditionProfileConnection = mProfileConnectionlock.newCondition(); - mProfileConnectionlock.lock(); - try { - while (mIsProfileReady) { - if (!mConditionProfileConnection.await( - PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { - // Timeout - Log.e(TAG, "Timeout while waiting for Profile Disconnect"); - break; - } // else spurious wakeups - } - } catch (InterruptedException e) { - Log.e(TAG, "waitForProfileDisconnect: interrrupted"); - } finally { - mProfileConnectionlock.unlock(); - } - return !mIsProfileReady; - } - private final class BluetoothHidServiceListener implements BluetoothProfile.ServiceListener { @Override public void onServiceConnected(int profile, BluetoothProfile proxy) { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); mBluetoothHidDevice = (BluetoothHidDevice) proxy; mIsProfileReady = true; try { - mConditionProfileConnection.signal(); + mConditionProfileIsConnected.signal(); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } } @Override public void onServiceDisconnected(int profile) { - mProfileConnectionlock.lock(); - mIsProfileReady = false; - try { - mConditionProfileConnection.signal(); - } finally { - mProfileConnectionlock.unlock(); - } + } } diff --git a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothHidHostTest.java b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothHidHostTest.java index e7db6d29024..5c2e86e652b 100644 --- a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothHidHostTest.java +++ b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothHidHostTest.java @@ -50,8 +50,8 @@ public class BluetoothHidHostTest extends AndroidTestCase { private UiAutomation mUiAutomation; private boolean mIsProfileReady; - private Condition mConditionProfileConnection; - private ReentrantLock mProfileConnectionlock; + private Condition mConditionProfileIsConnected; + private ReentrantLock mProfileConnectedlock; @Override public void setUp() throws Exception { @@ -71,8 +71,8 @@ public class BluetoothHidHostTest extends AndroidTestCase { mAdapter = manager.getAdapter(); assertTrue(BTAdapterUtils.enableAdapter(mAdapter, mContext)); - mProfileConnectionlock = new ReentrantLock(); - mConditionProfileConnection = mProfileConnectionlock.newCondition(); + mProfileConnectedlock = new ReentrantLock(); + mConditionProfileIsConnected = mProfileConnectedlock.newCondition(); mIsProfileReady = false; mHidHost = null; @@ -96,18 +96,6 @@ public class BluetoothHidHostTest extends AndroidTestCase { mAdapter = null; } - public void test_closeProfileProxy() { - if (!(mHasBluetooth && mIsHidHostSupported)) return; - - assertTrue(waitForProfileConnect()); - assertNotNull(mHidHost); - assertTrue(mIsProfileReady); - - mAdapter.closeProfileProxy(BluetoothProfile.HID_HOST, mHidHost); - assertTrue(waitForProfileDisconnect()); - assertFalse(mIsProfileReady); - } - public void test_getConnectedDevices() { if (!(mHasBluetooth && mIsHidHostSupported)) return; @@ -214,11 +202,11 @@ public class BluetoothHidHostTest extends AndroidTestCase { } private boolean waitForProfileConnect() { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); try { // Wait for the Adapter to be disabled while (!mIsProfileReady) { - if (!mConditionProfileConnection.await( + if (!mConditionProfileIsConnected.await( PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { // Timeout Log.e(TAG, "Timeout while waiting for Profile Connect"); @@ -228,54 +216,28 @@ public class BluetoothHidHostTest extends AndroidTestCase { } catch (InterruptedException e) { Log.e(TAG, "waitForProfileConnect: interrupted"); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } return mIsProfileReady; } - private boolean waitForProfileDisconnect() { - mConditionProfileConnection = mProfileConnectionlock.newCondition(); - mProfileConnectionlock.lock(); - try { - while (mIsProfileReady) { - if (!mConditionProfileConnection.await( - PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { - // Timeout - Log.e(TAG, "Timeout while waiting for Profile Disconnect"); - break; - } // else spurious wakeups - } - } catch (InterruptedException e) { - Log.e(TAG, "waitForProfileDisconnect: interrrupted"); - } finally { - mProfileConnectionlock.unlock(); - } - return !mIsProfileReady; - } - private final class BluetoothHidHostListener implements BluetoothProfile.ServiceListener { @Override public void onServiceConnected(int profile, BluetoothProfile proxy) { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); try { mHidHost = (BluetoothHidHost) proxy; mIsProfileReady = true; - mConditionProfileConnection.signal(); + mConditionProfileIsConnected.signal(); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } } @Override public void onServiceDisconnected(int profile) { - mProfileConnectionlock.lock(); - mIsProfileReady = false; - try { - mConditionProfileConnection.signal(); - } finally { - mProfileConnectionlock.unlock(); - } + // Do nothing } } } diff --git a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothLeAudioTest.java b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothLeAudioTest.java index f75b344ce38..3df5b1fda1f 100644 --- a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothLeAudioTest.java +++ b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothLeAudioTest.java @@ -54,8 +54,8 @@ public class BluetoothLeAudioTest extends AndroidTestCase { private BluetoothLeAudio mBluetoothLeAudio; private boolean mIsLeAudioSupported; private boolean mIsProfileReady; - private Condition mConditionProfileConnection; - private ReentrantLock mProfileConnectionlock; + private Condition mConditionProfileIsConnected; + private ReentrantLock mProfileConnectedlock; private Executor mTestExecutor; private TestCallback mTestCallback; private boolean mCodecConfigChangedCalled; @@ -124,8 +124,8 @@ public class BluetoothLeAudioTest extends AndroidTestCase { mAdapter = manager.getAdapter(); assertTrue(BTAdapterUtils.enableAdapter(mAdapter, mContext)); - mProfileConnectionlock = new ReentrantLock(); - mConditionProfileConnection = mProfileConnectionlock.newCondition(); + mProfileConnectedlock = new ReentrantLock(); + mConditionProfileIsConnected = mProfileConnectedlock.newCondition(); mIsProfileReady = false; mBluetoothLeAudio = null; @@ -159,18 +159,6 @@ public class BluetoothLeAudioTest extends AndroidTestCase { mAdapter = null; } - public void test_closeProfileProxy() { - if (!(mHasBluetooth && mIsLeAudioSupported)) return; - - assertTrue(waitForProfileConnect()); - assertNotNull(mBluetoothLeAudio); - assertTrue(mIsProfileReady); - - mAdapter.closeProfileProxy(BluetoothProfile.LE_AUDIO, mBluetoothLeAudio); - assertTrue(waitForProfileDisconnect()); - assertFalse(mIsProfileReady); - } - public void test_getConnectedDevices() { if (!(mHasBluetooth && mIsLeAudioSupported)) return; @@ -372,11 +360,11 @@ public class BluetoothLeAudioTest extends AndroidTestCase { } private boolean waitForProfileConnect() { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); try { // Wait for the Adapter to be disabled while (!mIsProfileReady) { - if (!mConditionProfileConnection.await( + if (!mConditionProfileIsConnected.await( PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { // Timeout Log.e(TAG, "Timeout while waiting for Profile Connect"); @@ -386,55 +374,28 @@ public class BluetoothLeAudioTest extends AndroidTestCase { } catch (InterruptedException e) { Log.e(TAG, "waitForProfileConnect: interrrupted"); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } return mIsProfileReady; } - private boolean waitForProfileDisconnect() { - mConditionProfileConnection = mProfileConnectionlock.newCondition(); - mProfileConnectionlock.lock(); - try { - while (mIsProfileReady) { - if (!mConditionProfileConnection.await( - PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { - // Timeout - Log.e(TAG, "Timeout while waiting for Profile Disconnect"); - break; - } // else spurious wakeups - } - } catch (InterruptedException e) { - Log.e(TAG, "waitForProfileDisconnect: interrrupted"); - } finally { - mProfileConnectionlock.unlock(); - } - return !mIsProfileReady; - } - private final class BluetoothLeAudioServiceListener implements BluetoothProfile.ServiceListener { @Override public void onServiceConnected(int profile, BluetoothProfile proxy) { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); mBluetoothLeAudio = (BluetoothLeAudio) proxy; mIsProfileReady = true; try { - mConditionProfileConnection.signal(); + mConditionProfileIsConnected.signal(); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } } @Override public void onServiceDisconnected(int profile) { - mProfileConnectionlock.lock(); - mIsProfileReady = false; - try { - mConditionProfileConnection.signal(); - } finally { - mProfileConnectionlock.unlock(); - } } } } diff --git a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothLeBroadcastAssistantTest.java b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothLeBroadcastAssistantTest.java index 5853c530577..6138f389d96 100644 --- a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothLeBroadcastAssistantTest.java +++ b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothLeBroadcastAssistantTest.java @@ -98,8 +98,8 @@ public class BluetoothLeBroadcastAssistantTest { private BluetoothLeBroadcastAssistant mBluetoothLeBroadcastAssistant; private boolean mIsBroadcastAssistantSupported; private boolean mIsProfileReady; - private Condition mConditionProfileConnection; - private ReentrantLock mProfileConnectionlock; + private Condition mConditionProfileIsConnected; + private ReentrantLock mProfileConnectedLock; @Mock BluetoothLeBroadcastAssistant.Callback mCallbacks; @@ -120,8 +120,8 @@ public class BluetoothLeBroadcastAssistantTest { mAdapter = TestUtils.getBluetoothAdapterOrDie(); assertTrue(BTAdapterUtils.enableAdapter(mAdapter, mContext)); - mProfileConnectionlock = new ReentrantLock(); - mConditionProfileConnection = mProfileConnectionlock.newCondition(); + mProfileConnectedLock = new ReentrantLock(); + mConditionProfileIsConnected = mProfileConnectedLock.newCondition(); mIsProfileReady = false; mBluetoothLeBroadcastAssistant = null; @@ -156,22 +156,6 @@ public class BluetoothLeBroadcastAssistantTest { } @Test - public void testCloseProfileProxy() { - if (shouldSkipTest()) { - return; - } - - assertTrue(waitForProfileConnect()); - assertNotNull(mBluetoothLeBroadcastAssistant); - assertTrue(mIsProfileReady); - - mAdapter.closeProfileProxy( - BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT, mBluetoothLeBroadcastAssistant); - assertTrue(waitForProfileDisconnect()); - assertFalse(mIsProfileReady); - } - - @Test public void testAddSource() { if (shouldSkipTest()) { return; @@ -557,11 +541,11 @@ public class BluetoothLeBroadcastAssistantTest { } private boolean waitForProfileConnect() { - mProfileConnectionlock.lock(); + mProfileConnectedLock.lock(); try { // Wait for the Adapter to be disabled while (!mIsProfileReady) { - if (!mConditionProfileConnection.await( + if (!mConditionProfileIsConnected.await( PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { // Timeout Log.e(TAG, "Timeout while waiting for Profile Connect"); @@ -571,54 +555,27 @@ public class BluetoothLeBroadcastAssistantTest { } catch (InterruptedException e) { Log.e(TAG, "waitForProfileConnect: interrrupted"); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedLock.unlock(); } return mIsProfileReady; } - private boolean waitForProfileDisconnect() { - mConditionProfileConnection = mProfileConnectionlock.newCondition(); - mProfileConnectionlock.lock(); - try { - while (mIsProfileReady) { - if (!mConditionProfileConnection.await( - PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { - // Timeout - Log.e(TAG, "Timeout while waiting for Profile Disconnect"); - break; - } // else spurious wakeups - } - } catch (InterruptedException e) { - Log.e(TAG, "waitForProfileDisconnect: interrrupted"); - } finally { - mProfileConnectionlock.unlock(); - } - return !mIsProfileReady; - } - private final class ServiceListener implements BluetoothProfile.ServiceListener { @Override public void onServiceConnected(int profile, BluetoothProfile proxy) { - mProfileConnectionlock.lock(); + mProfileConnectedLock.lock(); mBluetoothLeBroadcastAssistant = (BluetoothLeBroadcastAssistant) proxy; mIsProfileReady = true; try { - mConditionProfileConnection.signal(); + mConditionProfileIsConnected.signal(); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedLock.unlock(); } } @Override public void onServiceDisconnected(int profile) { - mProfileConnectionlock.lock(); - mIsProfileReady = false; - try { - mConditionProfileConnection.signal(); - } finally { - mProfileConnectionlock.unlock(); - } } } diff --git a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothLeBroadcastTest.java b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothLeBroadcastTest.java index 794a50d09b3..e70d6ba1131 100644 --- a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothLeBroadcastTest.java +++ b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothLeBroadcastTest.java @@ -93,8 +93,8 @@ public class BluetoothLeBroadcastTest { private BluetoothLeBroadcast mBluetoothLeBroadcast; private boolean mIsLeBroadcastSupported; private boolean mIsProfileReady; - private Condition mConditionProfileConnection; - private ReentrantLock mProfileConnectionlock; + private Condition mConditionProfileIsConnected; + private ReentrantLock mProfileConnectedlock; private boolean mOnBroadcastStartedCalled = false; private boolean mOnBroadcastStartFailedCalled = false; @@ -167,8 +167,8 @@ public class BluetoothLeBroadcastTest { mAdapter = TestUtils.getBluetoothAdapterOrDie(); assertTrue(BTAdapterUtils.enableAdapter(mAdapter, mContext)); - mProfileConnectionlock = new ReentrantLock(); - mConditionProfileConnection = mProfileConnectionlock.newCondition(); + mProfileConnectedlock = new ReentrantLock(); + mConditionProfileIsConnected = mProfileConnectedlock.newCondition(); mIsProfileReady = false; mBluetoothLeBroadcast = null; @@ -207,21 +207,6 @@ public class BluetoothLeBroadcastTest { } @Test - public void testCloseProfileProxy() { - if (shouldSkipTest()) { - return; - } - - assertTrue(waitForProfileConnect()); - assertNotNull(mBluetoothLeBroadcast); - assertTrue(mIsProfileReady); - - mAdapter.closeProfileProxy(BluetoothProfile.LE_AUDIO_BROADCAST, mBluetoothLeBroadcast); - assertTrue(waitForProfileDisconnect()); - assertFalse(mIsProfileReady); - } - - @Test public void testGetConnectedDevices() { if (shouldSkipTest()) { return; @@ -567,11 +552,11 @@ public class BluetoothLeBroadcastTest { } private boolean waitForProfileConnect() { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); try { // Wait for the Adapter to be disabled while (!mIsProfileReady) { - if (!mConditionProfileConnection.await( + if (!mConditionProfileIsConnected.await( PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { // Timeout Log.e(TAG, "Timeout while waiting for Profile Connect"); @@ -581,55 +566,28 @@ public class BluetoothLeBroadcastTest { } catch (InterruptedException e) { Log.e(TAG, "waitForProfileConnect: interrrupted"); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } return mIsProfileReady; } - private boolean waitForProfileDisconnect() { - mConditionProfileConnection = mProfileConnectionlock.newCondition(); - mProfileConnectionlock.lock(); - try { - while (mIsProfileReady) { - if (!mConditionProfileConnection.await( - PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { - // Timeout - Log.e(TAG, "Timeout while waiting for Profile Disconnect"); - break; - } // else spurious wakeups - } - } catch (InterruptedException e) { - Log.e(TAG, "waitForProfileDisconnect: interrrupted"); - } finally { - mProfileConnectionlock.unlock(); - } - return !mIsProfileReady; - } - private final class ServiceListener implements BluetoothProfile.ServiceListener { @Override public void onServiceConnected(int profile, BluetoothProfile proxy) { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); mBluetoothLeBroadcast = (BluetoothLeBroadcast) proxy; mIsProfileReady = true; try { - mConditionProfileConnection.signal(); + mConditionProfileIsConnected.signal(); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } } @Override public void onServiceDisconnected(int profile) { - mProfileConnectionlock.lock(); - mIsProfileReady = false; - try { - mConditionProfileConnection.signal(); - } finally { - mProfileConnectionlock.unlock(); - } } } } diff --git a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothMapClientTest.java b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothMapClientTest.java index fa547bca3c0..4a6cd0698f1 100644 --- a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothMapClientTest.java +++ b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothMapClientTest.java @@ -62,8 +62,8 @@ public class BluetoothMapClientTest extends AndroidTestCase { private BluetoothMapClient mBluetoothMapClient; private boolean mIsMapClientSupported; private boolean mIsProfileReady; - private Condition mConditionProfileConnection; - private ReentrantLock mProfileConnectionlock; + private Condition mConditionProfileIsConnected; + private ReentrantLock mProfileConnectedlock; @Override public void setUp() throws Exception { @@ -83,8 +83,8 @@ public class BluetoothMapClientTest extends AndroidTestCase { mAdapter = manager.getAdapter(); assertTrue(BTAdapterUtils.enableAdapter(mAdapter, mContext)); - mProfileConnectionlock = new ReentrantLock(); - mConditionProfileConnection = mProfileConnectionlock.newCondition(); + mProfileConnectedlock = new ReentrantLock(); + mConditionProfileIsConnected = mProfileConnectedlock.newCondition(); mIsProfileReady = false; mBluetoothMapClient = null; @@ -111,18 +111,6 @@ public class BluetoothMapClientTest extends AndroidTestCase { mAdapter = null; } - public void test_closeProfileProxy() { - if (!(mHasBluetooth && mIsMapClientSupported)) return; - - assertTrue(waitForProfileConnect()); - assertNotNull(mBluetoothMapClient); - assertTrue(mIsProfileReady); - - mAdapter.closeProfileProxy(BluetoothProfile.MAP_CLIENT, mBluetoothMapClient); - assertTrue(waitForProfileDisconnect()); - assertFalse(mIsProfileReady); - } - public void test_getConnectedDevices() { if (!(mHasBluetooth && mIsMapClientSupported)) return; @@ -237,11 +225,11 @@ public class BluetoothMapClientTest extends AndroidTestCase { } private boolean waitForProfileConnect() { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); try { // Wait for the Adapter to be disabled while (!mIsProfileReady) { - if (!mConditionProfileConnection.await( + if (!mConditionProfileIsConnected.await( PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { // Timeout Log.e(TAG, "Timeout while waiting for Profile Connect"); @@ -251,55 +239,28 @@ public class BluetoothMapClientTest extends AndroidTestCase { } catch (InterruptedException e) { Log.e(TAG, "waitForProfileConnect: interrrupted"); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } return mIsProfileReady; } - private boolean waitForProfileDisconnect() { - mConditionProfileConnection = mProfileConnectionlock.newCondition(); - mProfileConnectionlock.lock(); - try { - while (mIsProfileReady) { - if (!mConditionProfileConnection.await( - PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { - // Timeout - Log.e(TAG, "Timeout while waiting for Profile Disconnect"); - break; - } // else spurious wakeups - } - } catch (InterruptedException e) { - Log.e(TAG, "waitForProfileDisconnect: interrrupted"); - } finally { - mProfileConnectionlock.unlock(); - } - return !mIsProfileReady; - } - private final class BluetoothMapClientServiceListener implements BluetoothProfile.ServiceListener { @Override public void onServiceConnected(int profile, BluetoothProfile proxy) { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); mBluetoothMapClient = (BluetoothMapClient) proxy; mIsProfileReady = true; try { - mConditionProfileConnection.signal(); + mConditionProfileIsConnected.signal(); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } } @Override public void onServiceDisconnected(int profile) { - mProfileConnectionlock.lock(); - mIsProfileReady = false; - try { - mConditionProfileConnection.signal(); - } finally { - mProfileConnectionlock.unlock(); - } } } } diff --git a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothMapTest.java b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothMapTest.java index 4bfd2f25525..6a7fe345f3d 100644 --- a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothMapTest.java +++ b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothMapTest.java @@ -51,8 +51,8 @@ public class BluetoothMapTest extends AndroidTestCase { private BluetoothMap mBluetoothMap; private boolean mIsMapSupported; private boolean mIsProfileReady; - private Condition mConditionProfileConnection; - private ReentrantLock mProfileConnectionlock; + private Condition mConditionProfileIsConnected; + private ReentrantLock mProfileConnectedlock; @Override public void setUp() throws Exception { @@ -72,8 +72,8 @@ public class BluetoothMapTest extends AndroidTestCase { mAdapter = manager.getAdapter(); assertTrue(BTAdapterUtils.enableAdapter(mAdapter, mContext)); - mProfileConnectionlock = new ReentrantLock(); - mConditionProfileConnection = mProfileConnectionlock.newCondition(); + mProfileConnectedlock = new ReentrantLock(); + mConditionProfileIsConnected = mProfileConnectedlock.newCondition(); mIsProfileReady = false; mBluetoothMap = null; @@ -99,18 +99,6 @@ public class BluetoothMapTest extends AndroidTestCase { mAdapter = null; } - public void test_closeProfileProxy() { - if (!(mHasBluetooth && mIsMapSupported)) return; - - assertTrue(waitForProfileConnect()); - assertNotNull(mBluetoothMap); - assertTrue(mIsProfileReady); - - mAdapter.closeProfileProxy(BluetoothProfile.MAP, mBluetoothMap); - assertTrue(waitForProfileDisconnect()); - assertFalse(mIsProfileReady); - } - public void test_getConnectedDevices() { if (!(mHasBluetooth && mIsMapSupported)) return; @@ -198,11 +186,11 @@ public class BluetoothMapTest extends AndroidTestCase { } private boolean waitForProfileConnect() { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); try { // Wait for the Adapter to be disabled while (!mIsProfileReady) { - if (!mConditionProfileConnection.await( + if (!mConditionProfileIsConnected.await( PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { // Timeout Log.e(TAG, "Timeout while waiting for Profile Connect"); @@ -212,55 +200,28 @@ public class BluetoothMapTest extends AndroidTestCase { } catch (InterruptedException e) { Log.e(TAG, "waitForProfileConnect: interrupted"); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } return mIsProfileReady; } - private boolean waitForProfileDisconnect() { - mConditionProfileConnection = mProfileConnectionlock.newCondition(); - mProfileConnectionlock.lock(); - try { - while (mIsProfileReady) { - if (!mConditionProfileConnection.await( - PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { - // Timeout - Log.e(TAG, "Timeout while waiting for Profile Disconnect"); - break; - } // else spurious wakeups - } - } catch (InterruptedException e) { - Log.e(TAG, "waitForProfileDisconnect: interrrupted"); - } finally { - mProfileConnectionlock.unlock(); - } - return !mIsProfileReady; - } - private final class BluetoothMapServiceListener implements BluetoothProfile.ServiceListener { @Override public void onServiceConnected(int profile, BluetoothProfile proxy) { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); try { mBluetoothMap = (BluetoothMap) proxy; mIsProfileReady = true; - mConditionProfileConnection.signal(); + mConditionProfileIsConnected.signal(); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } } @Override public void onServiceDisconnected(int profile) { - mProfileConnectionlock.lock(); - mIsProfileReady = false; - try { - mConditionProfileConnection.signal(); - } finally { - mProfileConnectionlock.unlock(); - } } } } diff --git a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothPanTest.java b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothPanTest.java index b417d613caf..733d9f38923 100644 --- a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothPanTest.java +++ b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothPanTest.java @@ -46,8 +46,8 @@ public class BluetoothPanTest extends AndroidTestCase { private BluetoothPan mBluetoothPan; private boolean mIsPanSupported; private boolean mIsProfileReady; - private Condition mConditionProfileConnection; - private ReentrantLock mProfileConnectionlock; + private Condition mConditionProfileIsConnected; + private ReentrantLock mProfileConnectedlock; @Override public void setUp() throws Exception { @@ -66,8 +66,8 @@ public class BluetoothPanTest extends AndroidTestCase { mAdapter = manager.getAdapter(); assertTrue(BTAdapterUtils.enableAdapter(mAdapter, mContext)); - mProfileConnectionlock = new ReentrantLock(); - mConditionProfileConnection = mProfileConnectionlock.newCondition(); + mProfileConnectedlock = new ReentrantLock(); + mConditionProfileIsConnected = mProfileConnectedlock.newCondition(); mIsProfileReady = false; mBluetoothPan = null; @@ -93,18 +93,6 @@ public class BluetoothPanTest extends AndroidTestCase { TestUtils.dropPermissionAsShellUid(); } - public void test_closeProfileProxy() { - if (!(mHasBluetooth && mIsPanSupported)) return; - - assertTrue(waitForProfileConnect()); - assertNotNull(mBluetoothPan); - assertTrue(mIsProfileReady); - - mAdapter.closeProfileProxy(BluetoothProfile.PAN, mBluetoothPan); - assertTrue(waitForProfileDisconnect()); - assertFalse(mIsProfileReady); - } - public void test_getConnectedDevices() { if (!(mHasBluetooth && mIsPanSupported)) return; @@ -188,11 +176,11 @@ public class BluetoothPanTest extends AndroidTestCase { } private boolean waitForProfileConnect() { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); try { // Wait for the Adapter to be disabled while (!mIsProfileReady) { - if (!mConditionProfileConnection.await( + if (!mConditionProfileIsConnected.await( PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { // Timeout Log.e(TAG, "Timeout while waiting for Profile Connect"); @@ -202,54 +190,27 @@ public class BluetoothPanTest extends AndroidTestCase { } catch (InterruptedException e) { Log.e(TAG, "waitForProfileConnect: interrrupted"); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } return mIsProfileReady; } - private boolean waitForProfileDisconnect() { - mConditionProfileConnection = mProfileConnectionlock.newCondition(); - mProfileConnectionlock.lock(); - try { - while (mIsProfileReady) { - if (!mConditionProfileConnection.await( - PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { - // Timeout - Log.e(TAG, "Timeout while waiting for Profile Disconnect"); - break; - } // else spurious wakeups - } - } catch (InterruptedException e) { - Log.e(TAG, "waitForProfileDisconnect: interrrupted"); - } finally { - mProfileConnectionlock.unlock(); - } - return !mIsProfileReady; - } - private final class BluetoothPanServiceListener implements BluetoothProfile.ServiceListener { @Override public void onServiceConnected(int profile, BluetoothProfile proxy) { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); mBluetoothPan = (BluetoothPan) proxy; mIsProfileReady = true; try { - mConditionProfileConnection.signal(); + mConditionProfileIsConnected.signal(); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } } @Override public void onServiceDisconnected(int profile) { - mProfileConnectionlock.lock(); - mIsProfileReady = false; - try { - mConditionProfileConnection.signal(); - } finally { - mProfileConnectionlock.unlock(); - } } } } diff --git a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothPbapClientTest.java b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothPbapClientTest.java index 89a1b463c23..7b3df4e3cc4 100644 --- a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothPbapClientTest.java +++ b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothPbapClientTest.java @@ -48,8 +48,8 @@ public class BluetoothPbapClientTest extends AndroidTestCase { private BluetoothPbapClient mBluetoothPbapClient; private boolean mIsPbapClientSupported; private boolean mIsProfileReady; - private Condition mConditionProfileConnection; - private ReentrantLock mProfileConnectionlock; + private Condition mConditionProfileIsConnected; + private ReentrantLock mProfileConnectedlock; @Override public void setUp() throws Exception { @@ -68,8 +68,8 @@ public class BluetoothPbapClientTest extends AndroidTestCase { mAdapter = manager.getAdapter(); assertTrue(BTAdapterUtils.enableAdapter(mAdapter, mContext)); - mProfileConnectionlock = new ReentrantLock(); - mConditionProfileConnection = mProfileConnectionlock.newCondition(); + mProfileConnectedlock = new ReentrantLock(); + mConditionProfileIsConnected = mProfileConnectedlock.newCondition(); mIsProfileReady = false; mBluetoothPbapClient = null; @@ -95,18 +95,6 @@ public class BluetoothPbapClientTest extends AndroidTestCase { mAdapter = null; } - public void test_closeProfileProxy() { - if (!(mHasBluetooth && mIsPbapClientSupported)) return; - - assertTrue(waitForProfileConnect()); - assertNotNull(mBluetoothPbapClient); - assertTrue(mIsProfileReady); - - mAdapter.closeProfileProxy(BluetoothProfile.PBAP_CLIENT, mBluetoothPbapClient); - assertTrue(waitForProfileDisconnect()); - assertFalse(mIsProfileReady); - } - public void test_getConnectedDevices() { if (!(mHasBluetooth && mIsPbapClientSupported)) return; @@ -194,11 +182,11 @@ public class BluetoothPbapClientTest extends AndroidTestCase { } private boolean waitForProfileConnect() { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); try { // Wait for the Adapter to be disabled while (!mIsProfileReady) { - if (!mConditionProfileConnection.await( + if (!mConditionProfileIsConnected.await( PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { // Timeout Log.e(TAG, "Timeout while waiting for Profile Connect"); @@ -208,55 +196,28 @@ public class BluetoothPbapClientTest extends AndroidTestCase { } catch (InterruptedException e) { Log.e(TAG, "waitForProfileConnect: interrrupted"); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } return mIsProfileReady; } - private boolean waitForProfileDisconnect() { - mConditionProfileConnection = mProfileConnectionlock.newCondition(); - mProfileConnectionlock.lock(); - try { - while (mIsProfileReady) { - if (!mConditionProfileConnection.await( - PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { - // Timeout - Log.e(TAG, "Timeout while waiting for Profile Disconnect"); - break; - } // else spurious wakeups - } - } catch (InterruptedException e) { - Log.e(TAG, "waitForProfileDisconnect: interrrupted"); - } finally { - mProfileConnectionlock.unlock(); - } - return !mIsProfileReady; - } - private final class BluetoothPbapClientServiceListener implements BluetoothProfile.ServiceListener { @Override public void onServiceConnected(int profile, BluetoothProfile proxy) { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); mBluetoothPbapClient = (BluetoothPbapClient) proxy; mIsProfileReady = true; try { - mConditionProfileConnection.signal(); + mConditionProfileIsConnected.signal(); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } } @Override public void onServiceDisconnected(int profile) { - mProfileConnectionlock.lock(); - mIsProfileReady = false; - try { - mConditionProfileConnection.signal(); - } finally { - mProfileConnectionlock.unlock(); - } } } } diff --git a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothPbapTest.java b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothPbapTest.java index e8fe8cd5f3e..382a2924d88 100644 --- a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothPbapTest.java +++ b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothPbapTest.java @@ -49,8 +49,8 @@ public class BluetoothPbapTest extends AndroidTestCase { private BluetoothPbap mBluetoothPbap; private boolean mIsPbapSupported; private boolean mIsProfileReady; - private Condition mConditionProfileConnection; - private ReentrantLock mProfileConnectionlock; + private Condition mConditionProfileIsConnected; + private ReentrantLock mProfileConnectedlock; @Override public void setUp() throws Exception { @@ -70,8 +70,8 @@ public class BluetoothPbapTest extends AndroidTestCase { mAdapter = manager.getAdapter(); assertTrue(BTAdapterUtils.enableAdapter(mAdapter, mContext)); - mProfileConnectionlock = new ReentrantLock(); - mConditionProfileConnection = mProfileConnectionlock.newCondition(); + mProfileConnectedlock = new ReentrantLock(); + mConditionProfileIsConnected = mProfileConnectedlock.newCondition(); mIsProfileReady = false; mBluetoothPbap = null; @@ -97,18 +97,6 @@ public class BluetoothPbapTest extends AndroidTestCase { mAdapter = null; } - public void test_closeProfileProxy() { - if (!(mHasBluetooth && mIsPbapSupported)) return; - - assertTrue(waitForProfileConnect()); - assertNotNull(mBluetoothPbap); - assertTrue(mIsProfileReady); - - mAdapter.closeProfileProxy(BluetoothProfile.PBAP, mBluetoothPbap); - assertTrue(waitForProfileDisconnect()); - assertFalse(mIsProfileReady); - } - public void test_getConnectedDevices() { if (!(mHasBluetooth && mIsPbapSupported)) return; @@ -177,11 +165,11 @@ public class BluetoothPbapTest extends AndroidTestCase { } private boolean waitForProfileConnect() { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); try { // Wait for the Adapter to be disabled while (!mIsProfileReady) { - if (!mConditionProfileConnection.await( + if (!mConditionProfileIsConnected.await( PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { // Timeout Log.e(TAG, "Timeout while waiting for Profile Connect"); @@ -191,55 +179,28 @@ public class BluetoothPbapTest extends AndroidTestCase { } catch (InterruptedException e) { Log.e(TAG, "waitForProfileConnect: interrupted"); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } return mIsProfileReady; } - private boolean waitForProfileDisconnect() { - mConditionProfileConnection = mProfileConnectionlock.newCondition(); - mProfileConnectionlock.lock(); - try { - while (mIsProfileReady) { - if (!mConditionProfileConnection.await( - PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { - // Timeout - Log.e(TAG, "Timeout while waiting for Profile Disconnect"); - break; - } // else spurious wakeups - } - } catch (InterruptedException e) { - Log.e(TAG, "waitForProfileDisconnect: interrrupted"); - } finally { - mProfileConnectionlock.unlock(); - } - return !mIsProfileReady; - } - private final class BluetoothPbapServiceListener implements BluetoothProfile.ServiceListener { @Override public void onServiceConnected(int profile, BluetoothProfile proxy) { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); try { mBluetoothPbap = (BluetoothPbap) proxy; mIsProfileReady = true; - mConditionProfileConnection.signal(); + mConditionProfileIsConnected.signal(); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } } @Override public void onServiceDisconnected(int profile) { - mProfileConnectionlock.lock(); - mIsProfileReady = false; - try { - mConditionProfileConnection.signal(); - } finally { - mProfileConnectionlock.unlock(); - } } } } diff --git a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothSapTest.java b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothSapTest.java index 2a679f3393f..ad5cfff19a4 100644 --- a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothSapTest.java +++ b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothSapTest.java @@ -48,8 +48,8 @@ public class BluetoothSapTest extends AndroidTestCase { private BluetoothSap mBluetoothSap; private boolean mIsProfileReady; - private Condition mConditionProfileConnection; - private ReentrantLock mProfileConnectionlock; + private Condition mConditionProfileIsConnected; + private ReentrantLock mProfileConnectedlock; private boolean mIsSapSupported; @@ -70,8 +70,8 @@ public class BluetoothSapTest extends AndroidTestCase { mAdapter = getContext().getSystemService(BluetoothManager.class).getAdapter(); assertTrue(BTAdapterUtils.enableAdapter(mAdapter, mContext)); - mProfileConnectionlock = new ReentrantLock(); - mConditionProfileConnection = mProfileConnectionlock.newCondition(); + mProfileConnectedlock = new ReentrantLock(); + mConditionProfileIsConnected = mProfileConnectedlock.newCondition(); mIsProfileReady = false; mBluetoothSap = null; @@ -97,18 +97,6 @@ public class BluetoothSapTest extends AndroidTestCase { } } - public void test_closeProfileProxy() { - if (!(mHasBluetooth && mIsSapSupported)) return; - - assertTrue(waitForProfileConnect()); - assertNotNull(mBluetoothSap); - assertTrue(mIsProfileReady); - - mAdapter.closeProfileProxy(BluetoothProfile.SAP, mBluetoothSap); - assertTrue(waitForProfileDisconnect()); - assertFalse(mIsProfileReady); - } - @MediumTest public void test_getConnectedDevices() { if (!mHasBluetooth || !mIsSapSupported) return; @@ -173,11 +161,11 @@ public class BluetoothSapTest extends AndroidTestCase { } private boolean waitForProfileConnect() { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); try { // Wait for the Adapter to be disabled while (!mIsProfileReady) { - if (!mConditionProfileConnection.await( + if (!mConditionProfileIsConnected.await( PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { // Timeout Log.e(TAG, "Timeout while waiting for Profile Connect"); @@ -187,54 +175,27 @@ public class BluetoothSapTest extends AndroidTestCase { } catch (InterruptedException e) { Log.e(TAG, "waitForProfileConnect: interrrupted"); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } return mIsProfileReady; } - private boolean waitForProfileDisconnect() { - mConditionProfileConnection = mProfileConnectionlock.newCondition(); - mProfileConnectionlock.lock(); - try { - while (mIsProfileReady) { - if (!mConditionProfileConnection.await( - PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { - // Timeout - Log.e(TAG, "Timeout while waiting for Profile Disconnect"); - break; - } // else spurious wakeups - } - } catch (InterruptedException e) { - Log.e(TAG, "waitForProfileDisconnect: interrrupted"); - } finally { - mProfileConnectionlock.unlock(); - } - return !mIsProfileReady; - } - private final class BluetoothSapServiceListener implements BluetoothProfile.ServiceListener { @Override public void onServiceConnected(int profile, BluetoothProfile proxy) { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); mBluetoothSap = (BluetoothSap) proxy; mIsProfileReady = true; try { - mConditionProfileConnection.signal(); + mConditionProfileIsConnected.signal(); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } } @Override public void onServiceDisconnected(int profile) { - mProfileConnectionlock.lock(); - mIsProfileReady = false; - try { - mConditionProfileConnection.signal(); - } finally { - mProfileConnectionlock.unlock(); - } } } } diff --git a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothVolumeControlTest.java b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothVolumeControlTest.java index 7bbed5ba0a7..26237c1240d 100644 --- a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothVolumeControlTest.java +++ b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothVolumeControlTest.java @@ -47,8 +47,8 @@ public class BluetoothVolumeControlTest extends AndroidTestCase { private BluetoothVolumeControl mBluetoothVolumeControl; private boolean mIsVolumeControlSupported; private boolean mIsProfileReady; - private Condition mConditionProfileConnection; - private ReentrantLock mProfileConnectionlock; + private Condition mConditionProfileIsConnected; + private ReentrantLock mProfileConnectedlock; private boolean mVolumeOffsetChangedCallbackCalled; private TestCallback mTestCallback; private Executor mTestExecutor; @@ -78,8 +78,8 @@ public class BluetoothVolumeControlTest extends AndroidTestCase { mAdapter = manager.getAdapter(); assertTrue(BTAdapterUtils.enableAdapter(mAdapter, mContext)); - mProfileConnectionlock = new ReentrantLock(); - mConditionProfileConnection = mProfileConnectionlock.newCondition(); + mProfileConnectedlock = new ReentrantLock(); + mConditionProfileIsConnected = mProfileConnectedlock.newCondition(); mIsProfileReady = false; mBluetoothVolumeControl = null; @@ -125,18 +125,6 @@ public class BluetoothVolumeControlTest extends AndroidTestCase { } } - public void testCloseProfileProxy() { - if (!(mHasBluetooth && mIsVolumeControlSupported)) return; - - assertTrue(waitForProfileConnect()); - assertNotNull(mBluetoothVolumeControl); - assertTrue(mIsProfileReady); - - mAdapter.closeProfileProxy(BluetoothProfile.VOLUME_CONTROL, mBluetoothVolumeControl); - assertTrue(waitForProfileDisconnect()); - assertFalse(mIsProfileReady); - } - public void testGetConnectedDevices() { if (!(mHasBluetooth && mIsVolumeControlSupported)) return; @@ -302,11 +290,11 @@ public class BluetoothVolumeControlTest extends AndroidTestCase { } private boolean waitForProfileConnect() { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); try { // Wait for the Adapter to be disabled while (!mIsProfileReady) { - if (!mConditionProfileConnection.await( + if (!mConditionProfileIsConnected.await( PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { // Timeout Log.e(TAG, "Timeout while waiting for Profile Connect"); @@ -316,55 +304,28 @@ public class BluetoothVolumeControlTest extends AndroidTestCase { } catch (InterruptedException e) { Log.e(TAG, "waitForProfileConnect: interrrupted"); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } return mIsProfileReady; } - private boolean waitForProfileDisconnect() { - mConditionProfileConnection = mProfileConnectionlock.newCondition(); - mProfileConnectionlock.lock(); - try { - while (mIsProfileReady) { - if (!mConditionProfileConnection.await( - PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { - // Timeout - Log.e(TAG, "Timeout while waiting for Profile Disconnect"); - break; - } // else spurious wakeups - } - } catch (InterruptedException e) { - Log.e(TAG, "waitForProfileDisconnect: interrrupted"); - } finally { - mProfileConnectionlock.unlock(); - } - return !mIsProfileReady; - } - private final class BluetoothVolumeControlServiceListener implements BluetoothProfile.ServiceListener { @Override public void onServiceConnected(int profile, BluetoothProfile proxy) { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); mBluetoothVolumeControl = (BluetoothVolumeControl) proxy; mIsProfileReady = true; try { - mConditionProfileConnection.signal(); + mConditionProfileIsConnected.signal(); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } } @Override public void onServiceDisconnected(int profile) { - mProfileConnectionlock.lock(); - mIsProfileReady = false; - try { - mConditionProfileConnection.signal(); - } finally { - mProfileConnectionlock.unlock(); - } } } } diff --git a/tests/tests/bluetooth/src/android/bluetooth/cts/HearingAidProfileTest.java b/tests/tests/bluetooth/src/android/bluetooth/cts/HearingAidProfileTest.java index fa7867275ca..2ed393f5be8 100644 --- a/tests/tests/bluetooth/src/android/bluetooth/cts/HearingAidProfileTest.java +++ b/tests/tests/bluetooth/src/android/bluetooth/cts/HearingAidProfileTest.java @@ -69,8 +69,8 @@ public class HearingAidProfileTest extends AndroidTestCase { private BroadcastReceiver mIntentReceiver; private UiAutomation mUiAutomation;; - private Condition mConditionProfileConnection; - private ReentrantLock mProfileConnectionlock; + private Condition mConditionProfileIsConnected; + private ReentrantLock mProfileConnectedlock; private boolean mIsProfileReady; private static List<Integer> mValidConnectionStates = new ArrayList<Integer>( @@ -94,8 +94,8 @@ public class HearingAidProfileTest extends AndroidTestCase { mBluetoothAdapter = manager.getAdapter(); assertTrue(BTAdapterUtils.enableAdapter(mBluetoothAdapter, mContext)); - mProfileConnectionlock = new ReentrantLock(); - mConditionProfileConnection = mProfileConnectionlock.newCondition(); + mProfileConnectedlock = new ReentrantLock(); + mConditionProfileIsConnected = mProfileConnectedlock.newCondition(); mIsProfileReady = false; mService = null; mBluetoothAdapter.getProfileProxy(getContext(), new HearingAidsServiceListener(), @@ -113,18 +113,6 @@ public class HearingAidProfileTest extends AndroidTestCase { mUiAutomation.dropShellPermissionIdentity(); } - public void test_closeProfileProxy() { - if (!(mIsBleSupported && mIsHearingAidSupported)) return; - - assertTrue(waitForProfileConnect()); - assertNotNull(mService); - assertTrue(mIsProfileReady); - - mBluetoothAdapter.closeProfileProxy(BluetoothProfile.HEARING_AID, mService); - assertTrue(waitForProfileDisconnect()); - assertFalse(mIsProfileReady); - } - /** * Basic test case to make sure that Hearing Aid Profile Proxy can connect. */ @@ -287,11 +275,11 @@ public class HearingAidProfileTest extends AndroidTestCase { } private boolean waitForProfileConnect() { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); try { // Wait for the Adapter to be disabled while (!mIsProfileReady) { - if (!mConditionProfileConnection.await( + if (!mConditionProfileIsConnected.await( PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { // Timeout Log.e(TAG, "Timeout while waiting for Profile Connect"); @@ -301,54 +289,30 @@ public class HearingAidProfileTest extends AndroidTestCase { } catch(InterruptedException e) { Log.e(TAG, "waitForProfileConnect: interrrupted"); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } return mIsProfileReady; } - private boolean waitForProfileDisconnect() { - mConditionProfileConnection = mProfileConnectionlock.newCondition(); - mProfileConnectionlock.lock(); - try { - while (mIsProfileReady) { - if (!mConditionProfileConnection.await( - PROXY_CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { - // Timeout - Log.e(TAG, "Timeout while waiting for Profile Disconnect"); - break; - } // else spurious wakeups - } - } catch (InterruptedException e) { - Log.e(TAG, "waitForProfileDisconnect: interrrupted"); - } finally { - mProfileConnectionlock.unlock(); - } - return !mIsProfileReady; - } - private final class HearingAidsServiceListener implements BluetoothProfile.ServiceListener { public void onServiceConnected(int profile, BluetoothProfile proxy) { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); mService = (BluetoothHearingAid) proxy; mIsProfileReady = true; try { - mConditionProfileConnection.signal(); + mConditionProfileIsConnected.signal(); } finally { - mProfileConnectionlock.unlock(); + mProfileConnectedlock.unlock(); } } public void onServiceDisconnected(int profile) { - mProfileConnectionlock.lock(); + mProfileConnectedlock.lock(); mIsProfileReady = false; mService = null; - try { - mConditionProfileConnection.signal(); - } finally { - mProfileConnectionlock.unlock(); - } + mProfileConnectedlock.unlock(); } } |