[Android] Use raw resources instead of assets
Robert Stone
git at videolan.org
Mon Oct 17 07:30:55 UTC 2022
vlc-android | branch: master | Robert Stone <rhstone at gmail.com> | Sun Oct 16 20:59:25 2022 -0700| [ad4a0ebff8ef0390652931f898c8de4313618a8d] | committer: Robert Stone
Use raw resources instead of assets
> https://code.videolan.org/videolan/vlc-android/commit/ad4a0ebff8ef0390652931f898c8de4313618a8d
---
.../debug/{assets => res/raw}/basic_stub.json | 0
.../{assets => res/raw}/authorized_keys.json | 0
.../vlc-android/{assets => res/raw}/authors.json | 0
.../vlc-android/{assets => res/raw}/libraries.json | 0
.../{assets => res/raw}/vlc_license.txt | 0
.../{assets => res/raw}/vlc_locales.json | 0
.../src/org/videolan/vlc/MediaParsingService.kt | 5 +++-
.../src/org/videolan/vlc/gui/AuthorsActivity.kt | 2 +-
.../src/org/videolan/vlc/gui/LibrariesActivity.kt | 2 +-
.../src/org/videolan/vlc/gui/helpers/UiTools.kt | 2 +-
.../src/org/videolan/vlc/util/AccessControl.kt | 4 +--
.../src/org/videolan/vlc/util/LocaleUtil.kt | 3 +-
.../vlc-android/src/org/videolan/vlc/util/Util.kt | 33 ----------------------
13 files changed, 11 insertions(+), 40 deletions(-)
diff --git a/application/vlc-android/flavors/debug/assets/basic_stub.json b/application/vlc-android/flavors/debug/res/raw/basic_stub.json
similarity index 100%
rename from application/vlc-android/flavors/debug/assets/basic_stub.json
rename to application/vlc-android/flavors/debug/res/raw/basic_stub.json
diff --git a/application/vlc-android/assets/authorized_keys.json b/application/vlc-android/res/raw/authorized_keys.json
similarity index 100%
rename from application/vlc-android/assets/authorized_keys.json
rename to application/vlc-android/res/raw/authorized_keys.json
diff --git a/application/vlc-android/assets/authors.json b/application/vlc-android/res/raw/authors.json
similarity index 100%
rename from application/vlc-android/assets/authors.json
rename to application/vlc-android/res/raw/authors.json
diff --git a/application/vlc-android/assets/libraries.json b/application/vlc-android/res/raw/libraries.json
similarity index 100%
rename from application/vlc-android/assets/libraries.json
rename to application/vlc-android/res/raw/libraries.json
diff --git a/application/vlc-android/assets/vlc_license.txt b/application/vlc-android/res/raw/vlc_license.txt
similarity index 100%
rename from application/vlc-android/assets/vlc_license.txt
rename to application/vlc-android/res/raw/vlc_license.txt
diff --git a/application/vlc-android/assets/vlc_locales.json b/application/vlc-android/res/raw/vlc_locales.json
similarity index 100%
rename from application/vlc-android/assets/vlc_locales.json
rename to application/vlc-android/res/raw/vlc_locales.json
diff --git a/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt b/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
index 5cb306315..2af2dffb7 100644
--- a/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
@@ -297,7 +297,10 @@ class MediaParsingService : LifecycleService(), DevicesDiscoveryCb {
private fun startScan(shouldInit: Boolean, upgrade: Boolean) {
scanActivated = true
if (MLServiceLocator.getLocatorMode() == MLServiceLocator.LocatorMode.TESTS) {
- (medialibrary as StubMedialibrary).loadJsonData(Util.readAsset("basic_stub.json", ""))
+ val jsonData = AppContextProvider.appResources.openRawResource(R.raw.basic_stub).bufferedReader().use {
+ it.readText()
+ }
+ (medialibrary as StubMedialibrary).loadJsonData(jsonData)
}
when {
shouldInit -> {
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/AuthorsActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/AuthorsActivity.kt
index bb14e36e5..d7bc50770 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/AuthorsActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/AuthorsActivity.kt
@@ -61,7 +61,7 @@ class AuthorsActivity : BaseActivity() {
private fun loadAuthors() {
lifecycleScope.launchWhenStarted {
val authors = withContext(Dispatchers.IO) {
- val jsonData = AppContextProvider.appContext.assets.open("authors.json").bufferedReader().use {
+ val jsonData = AppContextProvider.appResources.openRawResource(R.raw.authors).bufferedReader().use {
it.readText()
}
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/LibrariesActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/LibrariesActivity.kt
index 4360f40ac..a38e1190a 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/LibrariesActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/LibrariesActivity.kt
@@ -93,7 +93,7 @@ class LicenseModel : ViewModel() {
*/
suspend fun refresh() {
val parsedLicenses = withContext(Dispatchers.IO) {
- val jsonData = AppContextProvider.appContext.assets.open("libraries.json").bufferedReader().use {
+ val jsonData = AppContextProvider.appResources.openRawResource(R.raw.libraries).bufferedReader().use {
it.readText()
}
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
index 610d0c1f2..64ee06cf2 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
@@ -406,7 +406,7 @@ object UiTools {
v.findViewById<View>(R.id.about_vlc_card).setOnClickListener {
var licenseText = ""
activity.lifecycleScope.launchWhenStarted {
- licenseText = AppContextProvider.appContext.assets.open("vlc_license.txt").bufferedReader().use {
+ licenseText = AppContextProvider.appResources.openRawResource(R.raw.vlc_license).bufferedReader().use {
it.readText()
}
}
diff --git a/application/vlc-android/src/org/videolan/vlc/util/AccessControl.kt b/application/vlc-android/src/org/videolan/vlc/util/AccessControl.kt
index b4893e5fa..6c1f069f3 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/AccessControl.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/AccessControl.kt
@@ -30,6 +30,7 @@ import kotlinx.coroutines.withContext
import org.json.JSONArray
import org.json.JSONObject
import org.videolan.resources.AppContextProvider
+import org.videolan.vlc.R
import java.security.MessageDigest
import java.security.NoSuchAlgorithmException
@@ -109,8 +110,7 @@ object AccessControl {
private suspend fun loadAuthorizedKeys(): Map<String, CertInfo> {
return withContext(Dispatchers.IO) {
val certificateAllowList = mutableMapOf<String, CertInfo>()
- val ctx = AppContextProvider.appContext
- val jsonData = ctx.assets.open("authorized_keys.json").bufferedReader().use {
+ val jsonData = AppContextProvider.appResources.openRawResource(R.raw.authorized_keys).bufferedReader().use {
it.readText()
}
val signatures = JSONArray(jsonData)
diff --git a/application/vlc-android/src/org/videolan/vlc/util/LocaleUtil.kt b/application/vlc-android/src/org/videolan/vlc/util/LocaleUtil.kt
index 9bfebdd7e..e5eca49e3 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/LocaleUtil.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/LocaleUtil.kt
@@ -32,6 +32,7 @@ import org.videolan.libvlc.interfaces.IMedia
import org.videolan.libvlc.MediaPlayer
import org.videolan.resources.AppContextProvider
import org.videolan.tools.firstLetterUppercase
+import org.videolan.vlc.R
import java.util.*
/**
@@ -99,7 +100,7 @@ object LocaleUtil {
*/
private val vlcLocaleList by lazy {
- val jsonData = AppContextProvider.appContext.assets.open("vlc_locales.json").bufferedReader().use {
+ val jsonData = AppContextProvider.appResources.openRawResource(R.raw.vlc_locales).bufferedReader().use {
it.readText()
}
diff --git a/application/vlc-android/src/org/videolan/vlc/util/Util.kt b/application/vlc-android/src/org/videolan/vlc/util/Util.kt
index d2b2141e2..8537c4224 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/Util.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/Util.kt
@@ -23,47 +23,14 @@ package org.videolan.vlc.util
import android.app.Activity
import android.app.Service
import android.content.Context
-import android.text.TextUtils
-import org.videolan.resources.AppContextProvider
import org.videolan.resources.VLCInstance
-import org.videolan.tools.CloseableUtils
import org.videolan.tools.runBackground
import org.videolan.tools.runOnMainThread
import org.videolan.vlc.gui.video.VideoPlayerActivity
-import java.io.BufferedReader
-import java.io.IOException
-import java.io.InputStream
-import java.io.InputStreamReader
object Util {
const val TAG = "VLC/Util"
- fun readAsset(assetName: String, defaultS: String): String {
- var inputStream: InputStream? = null
- var r: BufferedReader? = null
- try {
- inputStream = AppContextProvider.appResources.assets.open(assetName)
- r = BufferedReader(InputStreamReader(inputStream, "UTF8"))
- val sb = StringBuilder()
- var line: String? = r.readLine()
- if (line != null) {
- sb.append(line)
- line = r.readLine()
- while (line != null) {
- sb.append('\n')
- sb.append(line)
- line = r.readLine()
- }
- }
- return sb.toString()
- } catch (e: IOException) {
- return defaultS
- } finally {
- CloseableUtils.close(inputStream)
- CloseableUtils.close(r)
- }
- }
-
fun checkCpuCompatibility(ctx: Context) {
runBackground(Runnable {
if (!VLCInstance.testCompatibleCPU(ctx))
More information about the Android
mailing list