Loading android/app/jni/com_android_bluetooth_avrcp_target.cpp +13 −4 Original line number Diff line number Diff line Loading @@ -785,10 +785,18 @@ static void volumeDeviceDisconnected(const RawAddress& address) { j_bdaddr); } static void sendVolumeChangedNative(JNIEnv* env, jobject object, jint volume) { static void sendVolumeChangedNative(JNIEnv* env, jobject object, jstring address, jint volume) { const char* tmp_addr = env->GetStringUTFChars(address, 0); RawAddress bdaddr; bool success = RawAddress::FromString(tmp_addr, bdaddr); env->ReleaseStringUTFChars(address, tmp_addr); if (!success) return; ALOGD("%s", __func__); for (const auto& cb : volumeCallbackMap) { cb.second.Run(volume & 0x7F); if (volumeCallbackMap.find(bdaddr) != volumeCallbackMap.end()) { volumeCallbackMap.find(bdaddr)->second.Run(volume & 0x7F); } } Loading @@ -815,7 +823,8 @@ static JNINativeMethod sMethods[] = { (void*)connectDeviceNative}, {"disconnectDeviceNative", "(Ljava/lang/String;)Z", (void*)disconnectDeviceNative}, {"sendVolumeChangedNative", "(I)V", (void*)sendVolumeChangedNative}, {"sendVolumeChangedNative", "(Ljava/lang/String;I)V", (void*)sendVolumeChangedNative}, }; int register_com_android_bluetooth_avrcp_target(JNIEnv* env) { Loading android/app/src/com/android/bluetooth/avrcp/AvrcpNativeInterface.java +3 −3 Original line number Diff line number Diff line Loading @@ -218,9 +218,9 @@ public class AvrcpNativeInterface { mAvrcpService.deviceDisconnected(device); } void sendVolumeChanged(int volume) { void sendVolumeChanged(String bdaddr, int volume) { d("sendVolumeChanged: volume=" + volume); sendVolumeChangedNative(volume); sendVolumeChangedNative(bdaddr, volume); } void setVolume(int volume) { Loading @@ -245,7 +245,7 @@ public class AvrcpNativeInterface { private native void cleanupNative(); private native boolean connectDeviceNative(String bdaddr); private native boolean disconnectDeviceNative(String bdaddr); private native void sendVolumeChangedNative(int volume); private native void sendVolumeChangedNative(String bdaddr, int volume); private static void d(String msg) { if (DEBUG) { Loading android/app/src/com/android/bluetooth/avrcp/AvrcpTargetService.java +12 −16 Original line number Diff line number Diff line Loading @@ -277,15 +277,13 @@ public class AvrcpTargetService extends ProfileService { // TODO (apanicke): Add checks to blacklist Absolute Volume devices if they behave poorly. void setVolume(int avrcpVolume) { int deviceVolume = (int) Math.floor((double) avrcpVolume * sDeviceMaxVolume / AVRCP_MAX_VOL); if (DEBUG) { Log.d(TAG, "SendVolumeChanged: avrcpVolume=" + avrcpVolume + " deviceVolume=" + deviceVolume + " sDeviceMaxVolume=" + sDeviceMaxVolume); BluetoothDevice activeDevice = mFactory.getA2dpService().getActiveDevice(); if (activeDevice == null) { Log.d(TAG, "setVolume: no active device"); return; } mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, deviceVolume, AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_BLUETOOTH_ABS_VOLUME); mVolumeManager.setVolume(activeDevice, avrcpVolume); } /** Loading @@ -293,15 +291,13 @@ public class AvrcpTargetService extends ProfileService { * volume. */ public void sendVolumeChanged(int deviceVolume) { int avrcpVolume = (int) Math.floor((double) deviceVolume * AVRCP_MAX_VOL / sDeviceMaxVolume); if (avrcpVolume > 127) avrcpVolume = 127; if (DEBUG) { Log.d(TAG, "SendVolumeChanged: avrcpVolume=" + avrcpVolume + " deviceVolume=" + deviceVolume + " sDeviceMaxVolume=" + sDeviceMaxVolume); BluetoothDevice activeDevice = mFactory.getA2dpService().getActiveDevice(); if (activeDevice == null) { Log.d(TAG, "sendVolumeChanged: no active device"); return; } mNativeInterface.sendVolumeChanged(avrcpVolume); mVolumeManager.sendVolumeChanged(activeDevice, deviceVolume); } Metadata getCurrentSongInfo() { Loading android/app/src/com/android/bluetooth/avrcp/AvrcpVolumeManager.java +27 −1 Original line number Diff line number Diff line Loading @@ -81,7 +81,7 @@ class AvrcpVolumeManager extends AudioDeviceCallback { if (mDeviceMap.get(device)) { int avrcpVolume = systemToAvrcpVolume(savedVolume); Log.i(TAG, "switchVolumeDevice: Updating device volume: avrcpVolume=" + avrcpVolume); mNativeInterface.sendVolumeChanged(avrcpVolume); mNativeInterface.sendVolumeChanged(device.getAddress(), avrcpVolume); } } Loading Loading @@ -157,6 +157,32 @@ class AvrcpVolumeManager extends AudioDeviceCallback { return sNewDeviceVolume; } void setVolume(@NonNull BluetoothDevice device, int avrcpVolume) { int deviceVolume = (int) Math.floor((double) avrcpVolume * sDeviceMaxVolume / AVRCP_MAX_VOL); if (DEBUG) { Log.d(TAG, "setVolume: avrcpVolume=" + avrcpVolume + " deviceVolume=" + deviceVolume + " sDeviceMaxVolume=" + sDeviceMaxVolume); } mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, deviceVolume, AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_BLUETOOTH_ABS_VOLUME); storeVolumeForDevice(device); } void sendVolumeChanged(@NonNull BluetoothDevice device, int deviceVolume) { int avrcpVolume = (int) Math.floor((double) deviceVolume * AVRCP_MAX_VOL / sDeviceMaxVolume); if (avrcpVolume > 127) avrcpVolume = 127; if (DEBUG) { Log.d(TAG, "sendVolumeChanged: avrcpVolume=" + avrcpVolume + " deviceVolume=" + deviceVolume + " sDeviceMaxVolume=" + sDeviceMaxVolume); } mNativeInterface.sendVolumeChanged(device.getAddress(), avrcpVolume); storeVolumeForDevice(device); } @Override public synchronized void onAudioDevicesAdded(AudioDeviceInfo[] addedDevices) { if (mCurrentDevice == null) { Loading Loading
android/app/jni/com_android_bluetooth_avrcp_target.cpp +13 −4 Original line number Diff line number Diff line Loading @@ -785,10 +785,18 @@ static void volumeDeviceDisconnected(const RawAddress& address) { j_bdaddr); } static void sendVolumeChangedNative(JNIEnv* env, jobject object, jint volume) { static void sendVolumeChangedNative(JNIEnv* env, jobject object, jstring address, jint volume) { const char* tmp_addr = env->GetStringUTFChars(address, 0); RawAddress bdaddr; bool success = RawAddress::FromString(tmp_addr, bdaddr); env->ReleaseStringUTFChars(address, tmp_addr); if (!success) return; ALOGD("%s", __func__); for (const auto& cb : volumeCallbackMap) { cb.second.Run(volume & 0x7F); if (volumeCallbackMap.find(bdaddr) != volumeCallbackMap.end()) { volumeCallbackMap.find(bdaddr)->second.Run(volume & 0x7F); } } Loading @@ -815,7 +823,8 @@ static JNINativeMethod sMethods[] = { (void*)connectDeviceNative}, {"disconnectDeviceNative", "(Ljava/lang/String;)Z", (void*)disconnectDeviceNative}, {"sendVolumeChangedNative", "(I)V", (void*)sendVolumeChangedNative}, {"sendVolumeChangedNative", "(Ljava/lang/String;I)V", (void*)sendVolumeChangedNative}, }; int register_com_android_bluetooth_avrcp_target(JNIEnv* env) { Loading
android/app/src/com/android/bluetooth/avrcp/AvrcpNativeInterface.java +3 −3 Original line number Diff line number Diff line Loading @@ -218,9 +218,9 @@ public class AvrcpNativeInterface { mAvrcpService.deviceDisconnected(device); } void sendVolumeChanged(int volume) { void sendVolumeChanged(String bdaddr, int volume) { d("sendVolumeChanged: volume=" + volume); sendVolumeChangedNative(volume); sendVolumeChangedNative(bdaddr, volume); } void setVolume(int volume) { Loading @@ -245,7 +245,7 @@ public class AvrcpNativeInterface { private native void cleanupNative(); private native boolean connectDeviceNative(String bdaddr); private native boolean disconnectDeviceNative(String bdaddr); private native void sendVolumeChangedNative(int volume); private native void sendVolumeChangedNative(String bdaddr, int volume); private static void d(String msg) { if (DEBUG) { Loading
android/app/src/com/android/bluetooth/avrcp/AvrcpTargetService.java +12 −16 Original line number Diff line number Diff line Loading @@ -277,15 +277,13 @@ public class AvrcpTargetService extends ProfileService { // TODO (apanicke): Add checks to blacklist Absolute Volume devices if they behave poorly. void setVolume(int avrcpVolume) { int deviceVolume = (int) Math.floor((double) avrcpVolume * sDeviceMaxVolume / AVRCP_MAX_VOL); if (DEBUG) { Log.d(TAG, "SendVolumeChanged: avrcpVolume=" + avrcpVolume + " deviceVolume=" + deviceVolume + " sDeviceMaxVolume=" + sDeviceMaxVolume); BluetoothDevice activeDevice = mFactory.getA2dpService().getActiveDevice(); if (activeDevice == null) { Log.d(TAG, "setVolume: no active device"); return; } mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, deviceVolume, AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_BLUETOOTH_ABS_VOLUME); mVolumeManager.setVolume(activeDevice, avrcpVolume); } /** Loading @@ -293,15 +291,13 @@ public class AvrcpTargetService extends ProfileService { * volume. */ public void sendVolumeChanged(int deviceVolume) { int avrcpVolume = (int) Math.floor((double) deviceVolume * AVRCP_MAX_VOL / sDeviceMaxVolume); if (avrcpVolume > 127) avrcpVolume = 127; if (DEBUG) { Log.d(TAG, "SendVolumeChanged: avrcpVolume=" + avrcpVolume + " deviceVolume=" + deviceVolume + " sDeviceMaxVolume=" + sDeviceMaxVolume); BluetoothDevice activeDevice = mFactory.getA2dpService().getActiveDevice(); if (activeDevice == null) { Log.d(TAG, "sendVolumeChanged: no active device"); return; } mNativeInterface.sendVolumeChanged(avrcpVolume); mVolumeManager.sendVolumeChanged(activeDevice, deviceVolume); } Metadata getCurrentSongInfo() { Loading
android/app/src/com/android/bluetooth/avrcp/AvrcpVolumeManager.java +27 −1 Original line number Diff line number Diff line Loading @@ -81,7 +81,7 @@ class AvrcpVolumeManager extends AudioDeviceCallback { if (mDeviceMap.get(device)) { int avrcpVolume = systemToAvrcpVolume(savedVolume); Log.i(TAG, "switchVolumeDevice: Updating device volume: avrcpVolume=" + avrcpVolume); mNativeInterface.sendVolumeChanged(avrcpVolume); mNativeInterface.sendVolumeChanged(device.getAddress(), avrcpVolume); } } Loading Loading @@ -157,6 +157,32 @@ class AvrcpVolumeManager extends AudioDeviceCallback { return sNewDeviceVolume; } void setVolume(@NonNull BluetoothDevice device, int avrcpVolume) { int deviceVolume = (int) Math.floor((double) avrcpVolume * sDeviceMaxVolume / AVRCP_MAX_VOL); if (DEBUG) { Log.d(TAG, "setVolume: avrcpVolume=" + avrcpVolume + " deviceVolume=" + deviceVolume + " sDeviceMaxVolume=" + sDeviceMaxVolume); } mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, deviceVolume, AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_BLUETOOTH_ABS_VOLUME); storeVolumeForDevice(device); } void sendVolumeChanged(@NonNull BluetoothDevice device, int deviceVolume) { int avrcpVolume = (int) Math.floor((double) deviceVolume * AVRCP_MAX_VOL / sDeviceMaxVolume); if (avrcpVolume > 127) avrcpVolume = 127; if (DEBUG) { Log.d(TAG, "sendVolumeChanged: avrcpVolume=" + avrcpVolume + " deviceVolume=" + deviceVolume + " sDeviceMaxVolume=" + sDeviceMaxVolume); } mNativeInterface.sendVolumeChanged(device.getAddress(), avrcpVolume); storeVolumeForDevice(device); } @Override public synchronized void onAudioDevicesAdded(AudioDeviceInfo[] addedDevices) { if (mCurrentDevice == null) { Loading