Loading jni/com_android_bluetooth_hearing_aid.cpp +0 −36 Original line number Diff line number Diff line Loading @@ -194,40 +194,6 @@ static jboolean disconnectHearingAidNative(JNIEnv* env, jobject object, return JNI_TRUE; } static jboolean addToWhiteListNative(JNIEnv* env, jobject object, jbyteArray address) { std::shared_lock<std::shared_timed_mutex> lock(interface_mutex); if (!sHearingAidInterface) return JNI_FALSE; jbyte* addr = env->GetByteArrayElements(address, nullptr); if (!addr) { jniThrowIOException(env, EINVAL); return JNI_FALSE; } RawAddress* tmpraw = (RawAddress*)addr; sHearingAidInterface->AddToWhiteList(*tmpraw); env->ReleaseByteArrayElements(address, addr, 0); return JNI_TRUE; } static jboolean removeFromWhiteListNative(JNIEnv* env, jobject object, jbyteArray address) { std::shared_lock<std::shared_timed_mutex> lock(interface_mutex); if (!sHearingAidInterface) return JNI_FALSE; jbyte* addr = env->GetByteArrayElements(address, nullptr); if (!addr) { jniThrowIOException(env, EINVAL); return JNI_FALSE; } RawAddress* tmpraw = (RawAddress*)addr; sHearingAidInterface->RemoveFromWhiteList(*tmpraw); env->ReleaseByteArrayElements(address, addr, 0); return JNI_TRUE; } static void setVolumeNative(JNIEnv* env, jclass clazz, jint volume) { if (!sHearingAidInterface) { LOG(ERROR) << __func__ Loading @@ -243,8 +209,6 @@ static JNINativeMethod sMethods[] = { {"cleanupNative", "()V", (void*)cleanupNative}, {"connectHearingAidNative", "([B)Z", (void*)connectHearingAidNative}, {"disconnectHearingAidNative", "([B)Z", (void*)disconnectHearingAidNative}, {"addToWhiteListNative", "([B)Z", (void*)addToWhiteListNative}, {"removeFromWhiteListNative", "([B)Z", (void*)removeFromWhiteListNative}, {"setVolumeNative", "(I)V", (void*)setVolumeNative}, }; Loading src/com/android/bluetooth/hearingaid/HearingAidNativeInterface.java +0 −24 Original line number Diff line number Diff line Loading @@ -104,28 +104,6 @@ public class HearingAidNativeInterface { return disconnectHearingAidNative(getByteAddress(device)); } /** * Add a hearing aid device to white list. * * @param device the remote device * @return true on success, otherwise false. */ @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) public boolean addToWhiteList(BluetoothDevice device) { return addToWhiteListNative(getByteAddress(device)); } /** * Remove a hearing aid device from white list. * * @param device the remote device * @return true on success, otherwise false. */ @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) public boolean removeFromWhiteList(BluetoothDevice device) { return removeFromWhiteListNative(getByteAddress(device)); } /** * Sets the HearingAid volume * @param volume Loading Loading @@ -190,7 +168,5 @@ public class HearingAidNativeInterface { private native void cleanupNative(); private native boolean connectHearingAidNative(byte[] address); private native boolean disconnectHearingAidNative(byte[] address); private native boolean addToWhiteListNative(byte[] address); private native boolean removeFromWhiteListNative(byte[] address); private native void setVolumeNative(int volume); } src/com/android/bluetooth/hearingaid/HearingAidService.java +13 −22 Original line number Diff line number Diff line Loading @@ -58,10 +58,6 @@ public class HearingAidService extends ProfileService { // Upper limit of all HearingAid devices: Bonded or Connected private static final int MAX_HEARING_AID_STATE_MACHINES = 10; private static HearingAidService sHearingAidService; @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) static int sConnectTimeoutForEachSideMs = 8000; @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) static int sCheckWhitelistTimeoutMs = 16000; private AdapterService mAdapterService; private HandlerThread mStateMachinesThread; Loading Loading @@ -254,6 +250,14 @@ public class HearingAidService extends ProfileService { } } synchronized (mStateMachines) { HearingAidStateMachine smConnect = getOrCreateStateMachine(device); if (smConnect == null) { Log.e(TAG, "Cannot connect to " + device + " : no state machine"); } smConnect.sendMessage(HearingAidStateMachine.CONNECT); } for (BluetoothDevice storedDevice : mDeviceHiSyncIdMap.keySet()) { if (device.equals(storedDevice)) { continue; Loading @@ -266,27 +270,14 @@ public class HearingAidService extends ProfileService { Log.e(TAG, "Ignored connect request for " + device + " : no state machine"); continue; } sm.sendMessage(HearingAidStateMachine.CONNECT, sConnectTimeoutForEachSideMs); sm.sendMessageDelayed(HearingAidStateMachine.CHECK_WHITELIST_CONNECTION, sCheckWhitelistTimeoutMs); sm.sendMessage(HearingAidStateMachine.CONNECT); } if (hiSyncId == BluetoothHearingAid.HI_SYNC_ID_INVALID && !device.equals(storedDevice)) { break; } } synchronized (mStateMachines) { HearingAidStateMachine smConnect = getOrCreateStateMachine(device); if (smConnect == null) { Log.e(TAG, "Cannot connect to " + device + " : no state machine"); } else { smConnect.sendMessage(HearingAidStateMachine.CONNECT, sConnectTimeoutForEachSideMs * 2); smConnect.sendMessageDelayed(HearingAidStateMachine.CHECK_WHITELIST_CONNECTION, sCheckWhitelistTimeoutMs); } } return true; } Loading src/com/android/bluetooth/hearingaid/HearingAidStateMachine.java +10 −17 Original line number Diff line number Diff line Loading @@ -69,15 +69,13 @@ final class HearingAidStateMachine extends StateMachine { static final int CONNECT = 1; static final int DISCONNECT = 2; static final int CHECK_WHITELIST_CONNECTION = 3; @VisibleForTesting static final int STACK_EVENT = 101; private static final int CONNECT_TIMEOUT = 201; @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) static int sConnectTimeoutMs = 16000; @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) static int sDisconnectTimeoutMs = 16000; // NOTE: the value is not "final" - it is modified in the unit tests @VisibleForTesting static int sConnectTimeoutMs = 30000; // 30s private Disconnected mDisconnected; private Connecting mConnecting; Loading Loading @@ -173,12 +171,6 @@ final class HearingAidStateMachine extends StateMachine { case DISCONNECT: Log.w(TAG, "Disconnected: DISCONNECT ignored: " + mDevice); break; case CHECK_WHITELIST_CONNECTION: if (mService.getConnectedDevices().isEmpty()) { log("No device connected, remove this device from white list"); mNativeInterface.removeFromWhiteList(mDevice); } break; case STACK_EVENT: HearingAidStackEvent event = (HearingAidStackEvent) message.obj; if (DBG) { Loading Loading @@ -267,13 +259,14 @@ final class HearingAidStateMachine extends StateMachine { deferMessage(message); break; case CONNECT_TIMEOUT: Log.w(TAG, "Connecting connection timeout: " + mDevice + ". Try whitelist"); Log.w(TAG, "Connecting connection timeout: " + mDevice); mNativeInterface.disconnectHearingAid(mDevice); mNativeInterface.addToWhiteList(mDevice); transitionTo(mDisconnected); break; case CHECK_WHITELIST_CONNECTION: deferMessage(message); HearingAidStackEvent disconnectEvent = new HearingAidStackEvent( HearingAidStackEvent.EVENT_TYPE_CONNECTION_STATE_CHANGED); disconnectEvent.device = mDevice; disconnectEvent.valueInt1 = HearingAidStackEvent.CONNECTION_STATE_DISCONNECTED; sendMessage(STACK_EVENT, disconnectEvent); break; case DISCONNECT: log("Connecting: connection canceled to " + mDevice); Loading tests/unit/src/com/android/bluetooth/hearingaid/HearingAidServiceTest.java +1 −4 Original line number Diff line number Diff line Loading @@ -118,8 +118,6 @@ public class HearingAidServiceTest { .getBondState(any(BluetoothDevice.class)); doReturn(new ParcelUuid[]{BluetoothUuid.HearingAid}).when(mAdapterService) .getRemoteUuids(any(BluetoothDevice.class)); HearingAidService.sConnectTimeoutForEachSideMs = 1000; HearingAidService.sCheckWhitelistTimeoutMs = 2000; } @After Loading Loading @@ -362,8 +360,7 @@ public class HearingAidServiceTest { mService.getConnectionState(mLeftDevice)); // Verify the connection state broadcast, and that we are in Disconnected state verifyConnectionStateIntent(HearingAidService.sConnectTimeoutForEachSideMs * 3, mLeftDevice, verifyConnectionStateIntent(HearingAidStateMachine.sConnectTimeoutMs * 2, mLeftDevice, BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.STATE_CONNECTING); Assert.assertEquals(BluetoothProfile.STATE_DISCONNECTED, Loading Loading
jni/com_android_bluetooth_hearing_aid.cpp +0 −36 Original line number Diff line number Diff line Loading @@ -194,40 +194,6 @@ static jboolean disconnectHearingAidNative(JNIEnv* env, jobject object, return JNI_TRUE; } static jboolean addToWhiteListNative(JNIEnv* env, jobject object, jbyteArray address) { std::shared_lock<std::shared_timed_mutex> lock(interface_mutex); if (!sHearingAidInterface) return JNI_FALSE; jbyte* addr = env->GetByteArrayElements(address, nullptr); if (!addr) { jniThrowIOException(env, EINVAL); return JNI_FALSE; } RawAddress* tmpraw = (RawAddress*)addr; sHearingAidInterface->AddToWhiteList(*tmpraw); env->ReleaseByteArrayElements(address, addr, 0); return JNI_TRUE; } static jboolean removeFromWhiteListNative(JNIEnv* env, jobject object, jbyteArray address) { std::shared_lock<std::shared_timed_mutex> lock(interface_mutex); if (!sHearingAidInterface) return JNI_FALSE; jbyte* addr = env->GetByteArrayElements(address, nullptr); if (!addr) { jniThrowIOException(env, EINVAL); return JNI_FALSE; } RawAddress* tmpraw = (RawAddress*)addr; sHearingAidInterface->RemoveFromWhiteList(*tmpraw); env->ReleaseByteArrayElements(address, addr, 0); return JNI_TRUE; } static void setVolumeNative(JNIEnv* env, jclass clazz, jint volume) { if (!sHearingAidInterface) { LOG(ERROR) << __func__ Loading @@ -243,8 +209,6 @@ static JNINativeMethod sMethods[] = { {"cleanupNative", "()V", (void*)cleanupNative}, {"connectHearingAidNative", "([B)Z", (void*)connectHearingAidNative}, {"disconnectHearingAidNative", "([B)Z", (void*)disconnectHearingAidNative}, {"addToWhiteListNative", "([B)Z", (void*)addToWhiteListNative}, {"removeFromWhiteListNative", "([B)Z", (void*)removeFromWhiteListNative}, {"setVolumeNative", "(I)V", (void*)setVolumeNative}, }; Loading
src/com/android/bluetooth/hearingaid/HearingAidNativeInterface.java +0 −24 Original line number Diff line number Diff line Loading @@ -104,28 +104,6 @@ public class HearingAidNativeInterface { return disconnectHearingAidNative(getByteAddress(device)); } /** * Add a hearing aid device to white list. * * @param device the remote device * @return true on success, otherwise false. */ @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) public boolean addToWhiteList(BluetoothDevice device) { return addToWhiteListNative(getByteAddress(device)); } /** * Remove a hearing aid device from white list. * * @param device the remote device * @return true on success, otherwise false. */ @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) public boolean removeFromWhiteList(BluetoothDevice device) { return removeFromWhiteListNative(getByteAddress(device)); } /** * Sets the HearingAid volume * @param volume Loading Loading @@ -190,7 +168,5 @@ public class HearingAidNativeInterface { private native void cleanupNative(); private native boolean connectHearingAidNative(byte[] address); private native boolean disconnectHearingAidNative(byte[] address); private native boolean addToWhiteListNative(byte[] address); private native boolean removeFromWhiteListNative(byte[] address); private native void setVolumeNative(int volume); }
src/com/android/bluetooth/hearingaid/HearingAidService.java +13 −22 Original line number Diff line number Diff line Loading @@ -58,10 +58,6 @@ public class HearingAidService extends ProfileService { // Upper limit of all HearingAid devices: Bonded or Connected private static final int MAX_HEARING_AID_STATE_MACHINES = 10; private static HearingAidService sHearingAidService; @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) static int sConnectTimeoutForEachSideMs = 8000; @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) static int sCheckWhitelistTimeoutMs = 16000; private AdapterService mAdapterService; private HandlerThread mStateMachinesThread; Loading Loading @@ -254,6 +250,14 @@ public class HearingAidService extends ProfileService { } } synchronized (mStateMachines) { HearingAidStateMachine smConnect = getOrCreateStateMachine(device); if (smConnect == null) { Log.e(TAG, "Cannot connect to " + device + " : no state machine"); } smConnect.sendMessage(HearingAidStateMachine.CONNECT); } for (BluetoothDevice storedDevice : mDeviceHiSyncIdMap.keySet()) { if (device.equals(storedDevice)) { continue; Loading @@ -266,27 +270,14 @@ public class HearingAidService extends ProfileService { Log.e(TAG, "Ignored connect request for " + device + " : no state machine"); continue; } sm.sendMessage(HearingAidStateMachine.CONNECT, sConnectTimeoutForEachSideMs); sm.sendMessageDelayed(HearingAidStateMachine.CHECK_WHITELIST_CONNECTION, sCheckWhitelistTimeoutMs); sm.sendMessage(HearingAidStateMachine.CONNECT); } if (hiSyncId == BluetoothHearingAid.HI_SYNC_ID_INVALID && !device.equals(storedDevice)) { break; } } synchronized (mStateMachines) { HearingAidStateMachine smConnect = getOrCreateStateMachine(device); if (smConnect == null) { Log.e(TAG, "Cannot connect to " + device + " : no state machine"); } else { smConnect.sendMessage(HearingAidStateMachine.CONNECT, sConnectTimeoutForEachSideMs * 2); smConnect.sendMessageDelayed(HearingAidStateMachine.CHECK_WHITELIST_CONNECTION, sCheckWhitelistTimeoutMs); } } return true; } Loading
src/com/android/bluetooth/hearingaid/HearingAidStateMachine.java +10 −17 Original line number Diff line number Diff line Loading @@ -69,15 +69,13 @@ final class HearingAidStateMachine extends StateMachine { static final int CONNECT = 1; static final int DISCONNECT = 2; static final int CHECK_WHITELIST_CONNECTION = 3; @VisibleForTesting static final int STACK_EVENT = 101; private static final int CONNECT_TIMEOUT = 201; @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) static int sConnectTimeoutMs = 16000; @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) static int sDisconnectTimeoutMs = 16000; // NOTE: the value is not "final" - it is modified in the unit tests @VisibleForTesting static int sConnectTimeoutMs = 30000; // 30s private Disconnected mDisconnected; private Connecting mConnecting; Loading Loading @@ -173,12 +171,6 @@ final class HearingAidStateMachine extends StateMachine { case DISCONNECT: Log.w(TAG, "Disconnected: DISCONNECT ignored: " + mDevice); break; case CHECK_WHITELIST_CONNECTION: if (mService.getConnectedDevices().isEmpty()) { log("No device connected, remove this device from white list"); mNativeInterface.removeFromWhiteList(mDevice); } break; case STACK_EVENT: HearingAidStackEvent event = (HearingAidStackEvent) message.obj; if (DBG) { Loading Loading @@ -267,13 +259,14 @@ final class HearingAidStateMachine extends StateMachine { deferMessage(message); break; case CONNECT_TIMEOUT: Log.w(TAG, "Connecting connection timeout: " + mDevice + ". Try whitelist"); Log.w(TAG, "Connecting connection timeout: " + mDevice); mNativeInterface.disconnectHearingAid(mDevice); mNativeInterface.addToWhiteList(mDevice); transitionTo(mDisconnected); break; case CHECK_WHITELIST_CONNECTION: deferMessage(message); HearingAidStackEvent disconnectEvent = new HearingAidStackEvent( HearingAidStackEvent.EVENT_TYPE_CONNECTION_STATE_CHANGED); disconnectEvent.device = mDevice; disconnectEvent.valueInt1 = HearingAidStackEvent.CONNECTION_STATE_DISCONNECTED; sendMessage(STACK_EVENT, disconnectEvent); break; case DISCONNECT: log("Connecting: connection canceled to " + mDevice); Loading
tests/unit/src/com/android/bluetooth/hearingaid/HearingAidServiceTest.java +1 −4 Original line number Diff line number Diff line Loading @@ -118,8 +118,6 @@ public class HearingAidServiceTest { .getBondState(any(BluetoothDevice.class)); doReturn(new ParcelUuid[]{BluetoothUuid.HearingAid}).when(mAdapterService) .getRemoteUuids(any(BluetoothDevice.class)); HearingAidService.sConnectTimeoutForEachSideMs = 1000; HearingAidService.sCheckWhitelistTimeoutMs = 2000; } @After Loading Loading @@ -362,8 +360,7 @@ public class HearingAidServiceTest { mService.getConnectionState(mLeftDevice)); // Verify the connection state broadcast, and that we are in Disconnected state verifyConnectionStateIntent(HearingAidService.sConnectTimeoutForEachSideMs * 3, mLeftDevice, verifyConnectionStateIntent(HearingAidStateMachine.sConnectTimeoutMs * 2, mLeftDevice, BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.STATE_CONNECTING); Assert.assertEquals(BluetoothProfile.STATE_DISCONNECTED, Loading