Skip to content

Commit 5e79157

Browse files
committed
Merge branch 'release/v0.0.15'
2 parents c28d5aa + a33480d commit 5e79157

35 files changed

+286
-52
lines changed

BLE-MIDI-library/build.gradle

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,31 @@ plugins {
44
}
55

66
android {
7-
compileSdkVersion 33
7+
compileSdk 34
88

99
defaultConfig {
1010
minSdkVersion 18
11-
targetSdkVersion 33
11+
targetSdkVersion 34
1212
}
1313

1414
compileOptions {
15-
sourceCompatibility JavaVersion.VERSION_1_7
16-
targetCompatibility JavaVersion.VERSION_1_7
15+
sourceCompatibility JavaVersion.VERSION_1_8
16+
targetCompatibility JavaVersion.VERSION_1_8
17+
}
18+
19+
defaultConfig {
20+
consumerProguardFiles 'proguard-rules.pro'
1721
}
1822

1923
buildTypes {
20-
release {
24+
debug {
2125
minifyEnabled false
2226
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
2327
}
28+
release {
29+
minifyEnabled true
30+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
31+
}
2432
}
2533

2634
publishing {
@@ -50,7 +58,7 @@ publishing {
5058
release(MavenPublication) {
5159
group = 'jp.kshoji'
5260
artifactId = 'ble-midi'
53-
version = '0.0.14'
61+
version = '0.0.15'
5462

5563
afterEvaluate {
5664
from components.release

BLE-MIDI-library/proguard-rules.pro

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
1-
# Add project specific ProGuard rules here.
2-
# By default, the flags in this file are appended to flags specified
3-
# in /Applications/Android Studio 0.8.app/sdk/tools/proguard/proguard-android.txt
4-
# You can edit the include path and order by changing the proguardFiles
5-
# directive in build.gradle.
6-
#
7-
# For more details, see
8-
# http://developer.android.com/guide/developing/tools/proguard.html
1+
-keep public class jp.kshoji.blemidi.** {
2+
public protected *;
3+
}
4+
-keep public class jp.kshoji.javax.sound.midi.** {
5+
public protected *;
6+
}
7+
-keep public class jp.kshoji.unity.midi.** {
8+
public protected *;
9+
}
910

10-
# Add any project specific keep options here:
11+
-keepparameternames
12+
-renamesourcefileattribute SourceFile
13+
-keepattributes Signature,Exceptions,*Annotation*,
14+
InnerClasses,PermittedSubclasses,EnclosingMethod,
15+
Deprecated,SourceFile,LineNumberTable
1116

12-
# If your project uses WebView with JS, uncomment the following
13-
# and specify the fully qualified class name to the JavaScript interface
14-
# class:
15-
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16-
# public *;
17-
#}
17+
-keepclassmembers,allowoptimization enum * {
18+
public static **[] values();
19+
public static ** valueOf(java.lang.String);
20+
}
21+
22+
-keepclassmembers class * implements java.io.Serializable {
23+
static final long serialVersionUID;
24+
private static final java.io.ObjectStreamField[] serialPersistentFields;
25+
private void writeObject(java.io.ObjectOutputStream);
26+
private void readObject(java.io.ObjectInputStream);
27+
java.lang.Object writeReplace();
28+
java.lang.Object readResolve();
29+
}

BLE-MIDI-library/src/main/java/jp/kshoji/blemidi/central/BleMidiCallback.java

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public final class BleMidiCallback extends BluetoothGattCallback {
5151
private final Map<String, String> deviceAddressManufacturerMap = new HashMap<>();
5252
private final Map<String, String> deviceAddressModelMap = new HashMap<>();
5353

54-
List<Runnable> gattRequestQueue = new ArrayList<>();
54+
final List<Runnable> gattRequestQueue = new ArrayList<>();
5555
private final Context context;
5656

5757
private OnMidiDeviceAttachedListener midiDeviceAttachedListener;
@@ -160,10 +160,28 @@ public void run() {
160160
gattRequestQueue.add(new Runnable() {
161161
@Override
162162
public void run() {
163-
// request maximum MTU size
164-
// this calls onMtuChanged after completed
165-
boolean result = gatt.requestMtu(517); // GATT_MAX_MTU_SIZE defined at `stack/include/gatt_api.h`
166-
Log.d(Constants.TAG, "Central requestMtu address: " + gatt.getDevice().getAddress() + ", succeed: " + result);
163+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
164+
// Android 14: the default MTU size set to 517
165+
// https://developer.android.com/about/versions/14/behavior-changes-all#mtu-set-to-517
166+
final int mtu = 517;
167+
synchronized (midiOutputDevicesMap) {
168+
Set<MidiOutputDevice> midiOutputDevices = midiOutputDevicesMap.get(gatt.getDevice().getAddress());
169+
if (midiOutputDevices != null) {
170+
for (MidiOutputDevice midiOutputDevice : midiOutputDevices) {
171+
((InternalMidiOutputDevice) midiOutputDevice).setBufferSize(mtu - 3);
172+
}
173+
}
174+
}
175+
176+
if (gattRequestQueue.size() > 0) {
177+
gattRequestQueue.remove(0).run();
178+
}
179+
} else {
180+
// request maximum MTU size
181+
// this calls onMtuChanged after completed
182+
boolean result = gatt.requestMtu(517); // GATT_MAX_MTU_SIZE defined at `stack/include/gatt_api.h`
183+
Log.d(Constants.TAG, "Central requestMtu address: " + gatt.getDevice().getAddress() + ", succeed: " + result);
184+
}
167185
}
168186
});
169187
}
@@ -789,10 +807,13 @@ public void configureAsCentralDevice() {
789807

790808
@Override
791809
public void transferData(@NonNull byte[] writeBuffer) throws SecurityException {
792-
midiOutputCharacteristic.setValue(writeBuffer);
793-
794810
try {
795-
bluetoothGatt.writeCharacteristic(midiOutputCharacteristic);
811+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
812+
bluetoothGatt.writeCharacteristic(midiOutputCharacteristic, writeBuffer, BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
813+
} else {
814+
midiOutputCharacteristic.setValue(writeBuffer);
815+
bluetoothGatt.writeCharacteristic(midiOutputCharacteristic);
816+
}
796817
} catch (Throwable ignored) {
797818
// android.os.DeadObjectException will be thrown
798819
// ignore it

BLE-MIDI-library/src/main/java/jp/kshoji/blemidi/device/MidiOutputDevice.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void run() {
7676

7777
while (true) {
7878
// running
79-
while (!transferDataThreadAlive && isRunning) {
79+
while (transferDataThreadAlive && isRunning) {
8080
synchronized (transferDataStream) {
8181
if (writtenDataCount > 0) {
8282
transferData(transferDataStream.toByteArray());
@@ -167,6 +167,8 @@ private void storeTransferData(byte[] data) {
167167
writtenDataCount += data.length;
168168
} catch (IOException ignored) {
169169
}
170+
171+
transferDataThread.interrupt();
170172
}
171173
}
172174

UnityPlayerMock/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
apply plugin: 'com.android.library'
22

33
android {
4-
compileSdkVersion 33
4+
compileSdk 34
55

66
defaultConfig {
77
minSdkVersion 18
8-
targetSdkVersion 33
8+
targetSdkVersion 34
99
}
1010

1111
compileOptions {
12-
sourceCompatibility JavaVersion.VERSION_1_7
13-
targetCompatibility JavaVersion.VERSION_1_7
12+
sourceCompatibility JavaVersion.VERSION_1_8
13+
targetCompatibility JavaVersion.VERSION_1_8
1414
}
1515

1616
buildTypes {

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
google()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:8.2.0'
9+
classpath 'com.android.tools.build:gradle:8.3.1'
1010

1111
// NOTE: Do not place your application dependencies here; they belong
1212
// in the individual module build.gradle files

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ org.gradle.jvmargs=-Xmx4096m -XX:MaxMetaspaceSize=512m
2323
#android.defaults.buildfeatures.buildconfig=true
2424
android.nonTransitiveRClass=false
2525
android.nonFinalResIds=false
26+
org.gradle.configuration-cache=true

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
19e3e2462a40cb35401640b5f875359b

0 commit comments

Comments
 (0)