[Android] Fix crash when opening the pin code activity while using a custom locale
Nicolas Pomepuy
git at videolan.org
Wed Jul 31 12:08:38 UTC 2024
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Jul 30 13:37:55 2024 +0200| [73e24e8b0709a22d9f938fa38f77d6f0bcf00f19] | committer: Nicolas Pomepuy
Fix crash when opening the pin code activity while using a custom locale
Fixes #3075
> https://code.videolan.org/videolan/vlc-android/commit/73e24e8b0709a22d9f938fa38f77d6f0bcf00f19
---
.../src/main/java/org/videolan/resources/util/Extensions.kt | 8 ++++++++
.../vlc-android/src/org/videolan/vlc/gui/PinCodeActivity.kt | 3 ++-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/application/resources/src/main/java/org/videolan/resources/util/Extensions.kt b/application/resources/src/main/java/org/videolan/resources/util/Extensions.kt
index c91aabac77..7684350162 100644
--- a/application/resources/src/main/java/org/videolan/resources/util/Extensions.kt
+++ b/application/resources/src/main/java/org/videolan/resources/util/Extensions.kt
@@ -1,11 +1,13 @@
package org.videolan.resources.util
import android.annotation.SuppressLint
+import android.app.Application
import android.app.ForegroundServiceStartNotAllowedException
import android.app.Notification
import android.app.Service
import android.content.BroadcastReceiver
import android.content.Context
+import android.content.ContextWrapper
import android.content.Intent
import android.content.IntentFilter
import android.content.pm.PackageInfo
@@ -326,3 +328,9 @@ suspend inline fun <T> observeLiveDataUntil(
}
}
}
+
+
+fun Context.retrieveApplication():Application {
+ if (this is ContextWrapper) return baseContext.retrieveApplication()
+ return applicationContext as Application
+}
\ No newline at end of file
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/PinCodeActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/PinCodeActivity.kt
index 56e9b0f1a1..6fa1fd4fa6 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/PinCodeActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/PinCodeActivity.kt
@@ -45,6 +45,7 @@ import androidx.lifecycle.ViewModelProvider
import com.google.android.material.textfield.TextInputEditText
import org.videolan.resources.AndroidDevices
import org.videolan.resources.util.applyOverscanMargin
+import org.videolan.resources.util.retrieveApplication
import org.videolan.tools.KEY_SAFE_MODE_PIN
import org.videolan.tools.Settings
import org.videolan.tools.putSingle
@@ -427,7 +428,7 @@ class SafeModeModel(application: Application, val reason: PinCodeReason) : Andro
class Factory(private val context: Context, private val reason: PinCodeReason) : ViewModelProvider.NewInstanceFactory() {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
@Suppress("UNCHECKED_CAST")
- return SafeModeModel(context.applicationContext as Application, reason) as T
+ return SafeModeModel(context.retrieveApplication().applicationContext as Application, reason) as T
}
}
}
More information about the Android
mailing list