Skip to content

Commit

Permalink
Merge pull request #378 from magnusja/develop
Browse files Browse the repository at this point in the history
core v0.9.4
  • Loading branch information
magnusja authored Mar 10, 2023
2 parents ea6c0f8 + 9d087d6 commit 37d2ed3
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ A library to access USB mass storage devices (pen drives, external HDDs, card re
The library can be included into your project like this:

```ruby
implementation 'me.jahnen.libaums:core:0.9.3'
implementation 'me.jahnen.libaums:core:0.9.4'
```

If you need the HTTP or the storage provider module:
Expand Down
11 changes: 6 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 32
compileSdkVersion 33
buildToolsVersion '30.0.3'

defaultConfig {
applicationId "com.github.mjdev.usbfileman"
minSdkVersion 16
targetSdkVersion 32
targetSdkVersion 33
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
Expand All @@ -27,9 +28,9 @@ android {

dependencies {
api fileTree(include: ['*.jar'], dir: 'libs')
implementation 'junit:junit:4.13'
api 'androidx.appcompat:appcompat:1.4.0'
api 'com.google.android.material:material:1.6.0-alpha01'
implementation 'junit:junit:4.13.1'
api 'androidx.appcompat:appcompat:1.6.1'
api 'com.google.android.material:material:1.9.0-alpha02'
api project(':libaums')
api project(':httpserver')
api project(':storageprovider')
Expand Down
7 changes: 3 additions & 4 deletions libaums/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jacoco {

ext {
PUBLISH_GROUP_ID = 'me.jahnen.libaums'
PUBLISH_VERSION = '0.9.3'
PUBLISH_VERSION = '0.9.4'
PUBLISH_ARTIFACT_ID = 'core'
}

Expand All @@ -20,12 +20,12 @@ configurations {
}

android {
compileSdkVersion 32
compileSdkVersion 33
buildToolsVersion '30.0.3'

defaultConfig {
minSdkVersion 15
targetSdkVersion 32
targetSdkVersion 33

externalNativeBuild {
cmake {
Expand Down Expand Up @@ -80,7 +80,6 @@ dependencies {

api 'androidx.annotation:annotation:1.6.0'
javadocDeps 'androidx.annotation:annotation:1.6.0'
api 'androidx.core:core:1.12.0-alpha01'
api "androidx.core:core-ktx:1.9.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@ class ScsiBlockDevice(private val usbCommunication: UsbCommunication, private va
}

var transferLength = command.dCbwDataTransferLength
inBuffer.clear()
inBuffer.limit(transferLength)
inBuffer.limit(inBuffer.position() + transferLength)

var read = 0
if (transferLength > 0) {
Expand All @@ -278,7 +277,7 @@ class ScsiBlockDevice(private val usbCommunication: UsbCommunication, private va
read += usbCommunication.bulkInTransfer(inBuffer)
if (command.bCbwDynamicSize) {
transferLength = command.dynamicSizeFromPartialResponse(inBuffer)
inBuffer.limit(transferLength)
inBuffer.limit(inBuffer.position() + transferLength)
}
} while (read < transferLength)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package me.jahnen.libaums.core.usb

import android.hardware.usb.*
import android.os.Build
import androidx.annotation.RequiresApi

import java.io.IOException
import java.nio.ByteBuffer
Expand All @@ -21,10 +23,26 @@ internal class UsbRequestCommunication(
private val inRequest = UsbRequest().apply { initialize(deviceConnection, inEndpoint) }
private val workaroundBuffer = ByteBuffer.allocate(1024 * 32 * 4)


@Synchronized

@Throws(IOException::class)
override fun bulkOutTransfer(src: ByteBuffer): Int {
@RequiresApi(Build.VERSION_CODES.O)
fun bulkOutTransferApiO(src: ByteBuffer): Int {
val oldPosition = src.position();
if (!outRequest.queue(src)) {
throw IOException("Error queueing request.")
}

val request = deviceConnection!!.requestWait()
if (request === outRequest) {
return workaroundBuffer.position() - oldPosition
}

throw IOException("requestWait failed! Request: $request")
}


@Throws(IOException::class)
fun bulkOutTransferApiLesserO(src: ByteBuffer): Int {
val length = src.remaining()
val oldPosition = src.position()

Expand All @@ -45,9 +63,20 @@ internal class UsbRequestCommunication(
throw IOException("requestWait failed! Request: $request")
}


@Synchronized
@Throws(IOException::class)
override fun bulkInTransfer(dest: ByteBuffer): Int {
override fun bulkOutTransfer(src: ByteBuffer): Int {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
bulkOutTransferApiO(src)
} else {
bulkOutTransferApiLesserO(src)
}
}


@Throws(IOException::class)
fun bulkInTransferApiLesserO(dest: ByteBuffer): Int {
val length = dest.remaining()

// workaround: UsbRequest.queue always writes at position 0 :/
Expand All @@ -67,4 +96,30 @@ internal class UsbRequestCommunication(

throw IOException("requestWait failed! Request: $request")
}

@Throws(IOException::class)
@RequiresApi(Build.VERSION_CODES.O)
fun bulkInTransferApiO(dest: ByteBuffer): Int {
val oldPosition = dest.position();
if (!inRequest.queue(dest)) {
throw IOException("Error queueing request.")
}

val request = deviceConnection!!.requestWait()
if (request === outRequest) {
return workaroundBuffer.position() - oldPosition
}

throw IOException("requestWait failed! Request: $request")
}

@Synchronized
@Throws(IOException::class)
override fun bulkInTransfer(dest: ByteBuffer): Int {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
bulkInTransferApiO(dest)
} else {
bulkInTransferApiLesserO(dest)
}
}
}
4 changes: 2 additions & 2 deletions libusbcommunication/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ ext {
apply from: "${rootProject.projectDir}/publish-module.gradle"

android {
compileSdkVersion 32
compileSdkVersion 33

defaultConfig {
minSdkVersion 15
targetSdkVersion 32
targetSdkVersion 33

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
Expand Down

0 comments on commit 37d2ed3

Please sign in to comment.