Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
magnusja committed Aug 4, 2019
2 parents 6a33f82 + c5cf3fa commit d595740
Show file tree
Hide file tree
Showing 86 changed files with 3,107 additions and 3,059 deletions.
23 changes: 21 additions & 2 deletions ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
<!---
PLEASE NOTE:
Before creating an issue, please think about wheter you are really reporting an issue or just have a question/problem. The latter are better suited for Stackoverflow or gitter (https://gitter.im/libaums). The best approach for a question or problem regarding libaums is to ask on Stackoverflow and hint me to the question via gitter!

If you are sure that you would like to open an issue, please delete all of this message and continue.
Thank you!
-->

### Problem


### Expected behavior


### Actual behavior


#### Stacktrace of Excpetion

```
(if exists)
```


### Code where problem occurs

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ 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
compile 'com.github.mjdev:libaums:0.5.5'
compile 'com.github.mjdev:libaums:0.6.0'
```

If you need the HTTP or the storage provider module:

```ruby
compile 'com.github.mjdev:libaums-httpserver:0.5.2'
compile 'com.github.mjdev:libaums-httpserver:0.5.3'
compile 'com.github.mjdev:libaums-storageprovider:0.5.1'
```

Expand Down Expand Up @@ -48,7 +48,7 @@ for(UsbMassStorageDevice device: devices) {
Your app needs to get permission from the user at run time to be able to communicate the device. From a `UsbMassStorageDevice` you can get the underlying `android.usb.UsbDevice` to do so.

```java
PendingIntent permissionIntent = PendingIntent.getBroadcast(this, 0, new Inten(ACTION_USB_PERMISSION), 0);
PendingIntent permissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
usbManager.requestPermission(device.getUsbDevice(), permissionIntent);
```

Expand Down
8 changes: 5 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.41'
repositories {
jcenter()
maven {
Expand All @@ -13,13 +14,14 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.android.tools.build:gradle:3.4.2'

classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath 'com.dicedmelon.gradle:jacoco-android:0.1.3'
classpath 'com.dicedmelon.gradle:jacoco-android:0.1.4'

classpath 'org.codehaus.groovy:groovy-all:2.4.15'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -43,7 +45,7 @@ ext {

developerId = 'mjdev'
developerName = 'mjahnen'
developerEmail = '[email protected]'
developerEmail = '[email protected]'

licenseName = 'The Apache Software License, Version 2.0'
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
11 changes: 9 additions & 2 deletions httpserver/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'

project.archivesBaseName = 'libaums-httpserver'

Expand Down Expand Up @@ -40,12 +42,17 @@ dependencies {
api 'com.koushikdutta.async:androidasync:2.+'

api fileTree(include: ['*.jar'], dir: 'libs')
api 'androidx.annotation:annotation:1.0.0-beta01'
api 'androidx.core:core:1.0.0-beta01'
api 'androidx.annotation:annotation:1.1.0'
api 'androidx.core:core:1.1.0-beta01'
api project(':libaums')
api "androidx.core:core-ktx:1.0.2"
api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

task bintray {
apply from: '../install.gradle'
apply from: '../bintray.gradle'
}
repositories {
mavenCentral()
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* (C) Copyright 2016 mjahnen <[email protected]>
*
* 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 com.github.mjdev.libaums.server.http

import android.util.Log
import android.util.LruCache

import com.github.mjdev.libaums.fs.UsbFile
import com.github.mjdev.libaums.server.http.exception.NotAFileException
import com.github.mjdev.libaums.server.http.server.HttpServer


import java.io.FileNotFoundException
import java.io.IOException

/**
* This class allows to start a HTTP web server which can serve [com.github.mjdev.libaums.fs.UsbFile]s
* to another app.
*
* For instance it can make an image available to the Web Browser without copying it to the internal
* storage, or a video file to a video file as a HTTP stream.
*/
class UsbFileHttpServer(private val rootFile: UsbFile, private val server: HttpServer) : UsbFileProvider {
private val fileCache = LruCache<String, UsbFile>(100)

val baseUrl: String
get() {
var hostname: String? = server.hostname
if (hostname == null) {
hostname = "localhost"
}
return "http://" + hostname + ":" + server.listeningPort + "/"
}

val isAlive: Boolean
get() = server.isAlive

init {
server.setUsbFileProvider(this)
}

@Throws(IOException::class)
fun start() {
server.start()
}

@Throws(IOException::class)
fun stop() {
server.stop()
fileCache.evictAll()
}

@Throws(IOException::class)
override fun determineFileToServe(uri: String): UsbFile {
var fileToServe: UsbFile? = fileCache.get(uri)

if (fileToServe == null) {
Log.d(TAG, "Searching file on USB (URI: $uri)")
if (!rootFile.isDirectory) {
Log.d(TAG, "Serving root file")
if ("/" != uri && "/" + rootFile.name != uri) {
Log.d(TAG, "Invalid request, respond with 404")
throw FileNotFoundException("Not found $uri")
}


fileToServe = rootFile
} else {
fileToServe = rootFile.search(uri.substring(1))
}
} else {
Log.d(TAG, "Using lru cache for $uri")
}


if (fileToServe == null) {
Log.d(TAG, "fileToServe == null")
throw FileNotFoundException("Not found $uri")
}

if (fileToServe.isDirectory) {
throw NotAFileException()
}

fileCache.put(uri, fileToServe)

return fileToServe
}

companion object {

private val TAG = UsbFileHttpServer::class.java.simpleName
}
}
Loading

0 comments on commit d595740

Please sign in to comment.