Loading core/tests/bluetoothtests/AndroidManifest.xml +3 −0 Original line number Diff line number Diff line Loading @@ -31,5 +31,8 @@ <instrumentation android:name="android.bluetooth.BluetoothTestRunner" android:targetPackage="com.android.bluetooth.tests" android:label="Bluetooth Tests" /> <instrumentation android:name="android.bluetooth.BluetoothInstrumentation" android:targetPackage="com.android.bluetooth.tests" android:label="Bluetooth Test Utils" /> </manifest> core/tests/bluetoothtests/src/android/bluetooth/BluetoothInstrumentation.java 0 → 100644 +96 −0 Original line number Diff line number Diff line /* * Copyright (C) 2014 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.bluetooth; import android.app.Activity; import android.app.Instrumentation; import android.content.Context; import android.os.Bundle; public class BluetoothInstrumentation extends Instrumentation { private BluetoothTestUtils mUtils = null; private BluetoothAdapter mAdapter = null; private Bundle mArgs = null; private BluetoothTestUtils getBluetoothTestUtils() { if (mUtils == null) { mUtils = new BluetoothTestUtils(getContext(), BluetoothInstrumentation.class.getSimpleName()); } return mUtils; } private BluetoothAdapter getBluetoothAdapter() { if (mAdapter == null) { mAdapter = ((BluetoothManager)getContext().getSystemService( Context.BLUETOOTH_SERVICE)).getAdapter(); } return mAdapter; } @Override public void onCreate(Bundle arguments) { super.onCreate(arguments); mArgs = arguments; start(); } @Override public void onStart() { String command = mArgs.getString("command"); if ("enable".equals(command)) { enable(); } else if ("disable".equals(command)) { disable(); } else if ("unpairAll".equals(command)) { unpairAll(); } else if ("getName".equals(command)) { getName(); } else { finish(null); } } public void enable() { getBluetoothTestUtils().enable(getBluetoothAdapter()); finish(null); } public void disable() { getBluetoothTestUtils().disable(getBluetoothAdapter()); finish(null); } public void unpairAll() { getBluetoothTestUtils().unpairAll(getBluetoothAdapter()); finish(null); } public void getName() { String name = getBluetoothAdapter().getName(); Bundle bundle = new Bundle(); bundle.putString("name", name); finish(bundle); } public void finish(Bundle result) { if (result == null) { result = new Bundle(); } finish(Activity.RESULT_OK, result); } } core/tests/bluetoothtests/src/android/bluetooth/BluetoothTestUtils.java +12 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Set; public class BluetoothTestUtils extends Assert { Loading Loading @@ -892,6 +893,17 @@ public class BluetoothTestUtils extends Assert { methodName, state, BluetoothDevice.BOND_BONDED, firedFlags, mask)); } /** * Deletes all pairings of remote devices * @param adapter the BT adapter */ public void unpairAll(BluetoothAdapter adapter) { Set<BluetoothDevice> devices = adapter.getBondedDevices(); for (BluetoothDevice device : devices) { unpair(adapter, device); } } /** * Connects a profile from the local device to a remote device and checks to make sure that the * profile is connected and that the correct actions were broadcast. Loading Loading
core/tests/bluetoothtests/AndroidManifest.xml +3 −0 Original line number Diff line number Diff line Loading @@ -31,5 +31,8 @@ <instrumentation android:name="android.bluetooth.BluetoothTestRunner" android:targetPackage="com.android.bluetooth.tests" android:label="Bluetooth Tests" /> <instrumentation android:name="android.bluetooth.BluetoothInstrumentation" android:targetPackage="com.android.bluetooth.tests" android:label="Bluetooth Test Utils" /> </manifest>
core/tests/bluetoothtests/src/android/bluetooth/BluetoothInstrumentation.java 0 → 100644 +96 −0 Original line number Diff line number Diff line /* * Copyright (C) 2014 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.bluetooth; import android.app.Activity; import android.app.Instrumentation; import android.content.Context; import android.os.Bundle; public class BluetoothInstrumentation extends Instrumentation { private BluetoothTestUtils mUtils = null; private BluetoothAdapter mAdapter = null; private Bundle mArgs = null; private BluetoothTestUtils getBluetoothTestUtils() { if (mUtils == null) { mUtils = new BluetoothTestUtils(getContext(), BluetoothInstrumentation.class.getSimpleName()); } return mUtils; } private BluetoothAdapter getBluetoothAdapter() { if (mAdapter == null) { mAdapter = ((BluetoothManager)getContext().getSystemService( Context.BLUETOOTH_SERVICE)).getAdapter(); } return mAdapter; } @Override public void onCreate(Bundle arguments) { super.onCreate(arguments); mArgs = arguments; start(); } @Override public void onStart() { String command = mArgs.getString("command"); if ("enable".equals(command)) { enable(); } else if ("disable".equals(command)) { disable(); } else if ("unpairAll".equals(command)) { unpairAll(); } else if ("getName".equals(command)) { getName(); } else { finish(null); } } public void enable() { getBluetoothTestUtils().enable(getBluetoothAdapter()); finish(null); } public void disable() { getBluetoothTestUtils().disable(getBluetoothAdapter()); finish(null); } public void unpairAll() { getBluetoothTestUtils().unpairAll(getBluetoothAdapter()); finish(null); } public void getName() { String name = getBluetoothAdapter().getName(); Bundle bundle = new Bundle(); bundle.putString("name", name); finish(bundle); } public void finish(Bundle result) { if (result == null) { result = new Bundle(); } finish(Activity.RESULT_OK, result); } }
core/tests/bluetoothtests/src/android/bluetooth/BluetoothTestUtils.java +12 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Set; public class BluetoothTestUtils extends Assert { Loading Loading @@ -892,6 +893,17 @@ public class BluetoothTestUtils extends Assert { methodName, state, BluetoothDevice.BOND_BONDED, firedFlags, mask)); } /** * Deletes all pairings of remote devices * @param adapter the BT adapter */ public void unpairAll(BluetoothAdapter adapter) { Set<BluetoothDevice> devices = adapter.getBondedDevices(); for (BluetoothDevice device : devices) { unpair(adapter, device); } } /** * Connects a profile from the local device to a remote device and checks to make sure that the * profile is connected and that the correct actions were broadcast. Loading