Browse Source

Move the webserver in its own module

transifex
Nicolas Pomepuy 3 years ago
parent
commit
5f06ff6bc9
  1. 2
      application/app/build.gradle
  2. 1
      application/resources/src/main/java/org/videolan/resources/Constants.kt
  3. 5
      application/resources/src/main/java/org/videolan/resources/util/Extensions.kt
  4. 9
      application/vlc-android/AndroidManifest.xml
  5. 21
      application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt
  6. 2
      application/vlc-android/src/org/videolan/vlc/util/FileUtils.kt
  7. 1
      application/webserver/.gitignore
  8. 48
      application/webserver/build.gradle
  9. 0
      application/webserver/consumer-rules.pro
  10. 21
      application/webserver/proguard-rules.pro
  11. 48
      application/webserver/src/androidTest/java/org/videolan/vlc/webserver/ExampleInstrumentedTest.kt
  12. 39
      application/webserver/src/main/AndroidManifest.xml
  13. 16
      application/webserver/src/main/java/org/videolan/vlc/webserver/NetworkSharingServer.kt
  14. 3
      application/webserver/src/main/java/org/videolan/vlc/webserver/WebServerService.kt
  15. 41
      application/webserver/src/test/java/org/videolan/vlc/webserver/ExampleUnitTest.kt
  16. 2
      buildsystem/network-sharing-server/webpack.config.js
  17. 2
      settings.gradle

2
application/app/build.gradle

@ -137,7 +137,9 @@ android {
dependencies {
implementation project(':application:vlc-android')
implementation project(':application:television')
implementation project(':application:webserver')
testImplementation project(':application:television')
testImplementation project(':application:webserver')
androidTestImplementation "androidx.test.espresso:espresso-contrib:$rootProject.espressoVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$rootProject.espressoVersion"

1
application/resources/src/main/java/org/videolan/resources/Constants.kt

@ -280,5 +280,6 @@ const val MOVIEPEDIA_ACTIVITY = "org.videolan.moviepedia.ui.MoviepediaActivity"
const val TV_AUDIOPLAYER_ACTIVITY = "org.videolan.television.ui.audioplayer.AudioPlayerActivity"
const val MEDIAPARSING_SERVICE = "org.videolan.vlc.MediaParsingService"
const val TV_ONBOARDING_ACTIVITY = "org.videolan.television.ui.OnboardingActivity"
const val WEBSERVER_SERVICE = "org.videolan.vlc.webserver.WebServerService"
const val ROOM_DATABASE = "/vlc_database.zip"

5
application/resources/src/main/java/org/videolan/resources/util/Extensions.kt

@ -233,3 +233,8 @@ fun PackageManager.getPackageInfoCompat(packageName: String, vararg flagArgs: In
getPackageInfo(packageName, flags)
}
}
fun Context.startWebserver() {
val intent = Intent(ACTION_INIT).setClassName(applicationContext, WEBSERVER_SERVICE)
launchForeground(intent)
}

9
application/vlc-android/AndroidManifest.xml

@ -20,7 +20,6 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/> <!-- normal -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
@ -1059,14 +1058,6 @@
<service
android:name=".MediaParsingService"
android:foregroundServiceType="dataSync" />
<service
android:name=".WebServerService"
android:foregroundServiceType="specialUse">
<property
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
android:value="HTTP server" />
</service>
<receiver
android:name=".widget.VLCAppWidgetProviderWhite"
android:exported="false"

21
application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt

@ -35,15 +35,15 @@ import androidx.appcompat.view.ActionMode
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.videolan.libvlc.util.AndroidUtil
import org.videolan.medialibrary.interfaces.Medialibrary
import org.videolan.resources.*
import org.videolan.resources.util.launchForeground
import org.videolan.resources.ACTIVITY_RESULT_OPEN
import org.videolan.resources.ACTIVITY_RESULT_PREFERENCES
import org.videolan.resources.ACTIVITY_RESULT_SECONDARY
import org.videolan.resources.EXTRA_TARGET
import org.videolan.resources.util.startWebserver
import org.videolan.tools.*
import org.videolan.vlc.*
import org.videolan.vlc.BuildConfig
import org.videolan.vlc.R
import org.videolan.vlc.StartActivity
@ -60,7 +60,7 @@ import org.videolan.vlc.gui.video.VideoGridFragment
import org.videolan.vlc.interfaces.Filterable
import org.videolan.vlc.interfaces.IRefreshable
import org.videolan.vlc.media.MediaUtils
import org.videolan.vlc.server.NetworkSharingServer
import org.videolan.vlc.reloadLibrary
import org.videolan.vlc.util.Permissions
import org.videolan.vlc.util.Util
import org.videolan.vlc.util.WidgetMigration
@ -103,14 +103,7 @@ class MainActivity : ContentActivity(),
// VLCBilling.getInstance(application).retrieveSkus()
WidgetMigration.launchIfNeeded(this)
NotificationPermissionManager.launchIfNeeded(this)
// lifecycleScope.launch {
// withContext(Dispatchers.IO) {
// val server = NetworkSharingServer.getInstance(this@MainActivity)
// }
//
// }
AppScope.launch { launchForeground(Intent(ACTION_CHECK_STORAGES, null, this@MainActivity, WebServerService::class.java)) }
startWebserver()
}
override fun onResume() {

2
application/vlc-android/src/org/videolan/vlc/util/FileUtils.kt

@ -129,7 +129,7 @@ object FileUtils {
}
@WorkerThread
internal fun copyAssetFolder(assetManager: AssetManager, fromAssetPath: String, toPath: String, force: Boolean): Boolean {
fun copyAssetFolder(assetManager: AssetManager, fromAssetPath: String, toPath: String, force: Boolean): Boolean {
try {
val files = assetManager.list(fromAssetPath)
if (files.isNullOrEmpty()) return false

1
application/webserver/.gitignore

@ -0,0 +1 @@
/build

48
application/webserver/build.gradle

@ -0,0 +1,48 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
}
android {
namespace 'org.videolan.vlc.webserver'
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
sourceSets.main {
assets.srcDirs = ['assets']
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation project(':application:vlc-android')
implementation "io.ktor:ktor:2.1.2"
implementation "io.ktor:ktor-server-netty:2.1.2"
implementation "io.ktor:ktor-gson:1.6.8"
implementation "io.ktor:ktor-server-websockets:2.1.2"
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

0
application/webserver/consumer-rules.pro

21
application/webserver/proguard-rules.pro

@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

48
application/webserver/src/androidTest/java/org/videolan/vlc/webserver/ExampleInstrumentedTest.kt

@ -0,0 +1,48 @@
/*
* ************************************************************************
* ExampleInstrumentedTest.kt
* *************************************************************************
* Copyright © 2022 VLC authors and VideoLAN
* Author: Nicolas POMEPUY
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
* **************************************************************************
*
*
*/
package org.videolan.vlc.webserver
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("org.videolan.vlc.webserver.test", appContext.packageName)
}
}

39
application/webserver/src/main/AndroidManifest.xml

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ *************************************************************************
~ AndroidManifest.xml
~ **************************************************************************
~ Copyright © 2022 VLC authors and VideoLAN
~ Author: Nicolas POMEPUY
~ This program is free software; you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation; either version 2 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program; if not, write to the Free Software
~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
~ ***************************************************************************
~
~
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
<application>
<service
android:name=".WebServerService"
android:exported="true"
android:foregroundServiceType="specialUse">
<property
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
android:value="HTTP server" />
</service>
</application>
</manifest>

16
application/vlc-android/src/org/videolan/vlc/server/NetworkSharingServer.kt → application/webserver/src/main/java/org/videolan/vlc/webserver/NetworkSharingServer.kt

@ -22,7 +22,7 @@
*
*/
package org.videolan.vlc.server
package org.videolan.vlc.webserver
import android.content.Context
import android.net.Uri
@ -55,7 +55,7 @@ import org.videolan.tools.resIdByName
import org.videolan.vlc.PlaybackService
import org.videolan.vlc.gui.helpers.AudioUtil
import org.videolan.vlc.gui.helpers.BitmapUtil
import org.videolan.vlc.server.NetworkSharingServer.init
import org.videolan.vlc.webserver.NetworkSharingServer.init
import org.videolan.vlc.util.FileUtils
import java.io.File
import java.text.DateFormat
@ -82,11 +82,11 @@ object NetworkSharingServer: SingletonHolder<NettyApplicationEngine, Context>({
private fun onServiceChanged(service: PlaybackService?) {
if (service !== null) {
this.service = service
NetworkSharingServer.service = service
service.addCallback(this)
} else this.service?.let {
} else NetworkSharingServer.service?.let {
it.removeCallback(this)
this.service = null
NetworkSharingServer.service = null
}
}
@ -256,19 +256,19 @@ object NetworkSharingServer: SingletonHolder<NettyApplicationEngine, Context>({
}
override fun update() {
generateNowPlaying()?.let {nowPlaying ->
generateNowPlaying()?.let { nowPlaying ->
AppScope.launch { websocketSession.forEach { it.send(Frame.Text(nowPlaying)) } }
}
}
override fun onMediaEvent(event: IMedia.Event) {
generateNowPlaying()?.let {nowPlaying ->
generateNowPlaying()?.let { nowPlaying ->
AppScope.launch { websocketSession.forEach {it.send(Frame.Text(nowPlaying)) }}
}
}
override fun onMediaPlayerEvent(event: MediaPlayer.Event) {
generateNowPlaying()?.let {nowPlaying ->
generateNowPlaying()?.let { nowPlaying ->
AppScope.launch { websocketSession.forEach {it.send(Frame.Text(nowPlaying)) }}
}
}

3
application/vlc-android/src/org/videolan/vlc/WebServerService.kt → application/webserver/src/main/java/org/videolan/vlc/webserver/WebServerService.kt

@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*/
package org.videolan.vlc
package org.videolan.vlc.webserver
import android.annotation.SuppressLint
import android.content.BroadcastReceiver
@ -34,7 +34,6 @@ import org.videolan.resources.AppContextProvider
import org.videolan.resources.util.registerReceiverCompat
import org.videolan.tools.getContextWithLocale
import org.videolan.vlc.gui.helpers.NotificationHelper
import org.videolan.vlc.server.NetworkSharingServer
private const val TAG = "VLC/PlaybackService"

41
application/webserver/src/test/java/org/videolan/vlc/webserver/ExampleUnitTest.kt

@ -0,0 +1,41 @@
/*
* ************************************************************************
* ExampleUnitTest.kt
* *************************************************************************
* Copyright © 2022 VLC authors and VideoLAN
* Author: Nicolas POMEPUY
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
* **************************************************************************
*
*
*/
package org.videolan.vlc.webserver
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}

2
buildsystem/network-sharing-server/webpack.config.js

@ -8,7 +8,7 @@ module.exports = [{
// This is necessary for webpack to compile
// But we never use style-bundle.js
filename: 'style-bundle.js',
path: path.join(__dirname, "../../application/vlc-android/assets/web/public"),
path: path.join(__dirname, "../../application/webserver/assets/web/public"),
assetModuleFilename: 'images/[name][ext]'
},
plugins: [

2
settings.gradle

@ -1,4 +1,4 @@
include ':libvlcjni:libvlc', ':medialibrary'
include ':application:tools', ':application:resources', ':application:mediadb', ':application:app', ':application:live-plot-graph', ':application:television', ':application:donations'
include ':application:tools', ':application:resources', ':application:mediadb', ':application:app', ':application:live-plot-graph', ':application:television', ':application:donations', ':application:webserver'
include ':application:vlc-android'
include ':application:moviepedia'

Loading…
Cancel
Save