[Android] Add a settings restricted acess setting
Nicolas Pomepuy
git at videolan.org
Wed Jul 12 08:30:36 UTC 2023
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Jun 26 12:59:48 2023 +0200| [1de5a9d8c5fee91ecd8ec5c0624e120fdf49145f] | committer: Duncan McNamara
Add a settings restricted acess setting
> https://code.videolan.org/videolan/vlc-android/commit/1de5a9d8c5fee91ecd8ec5c0624e120fdf49145f
---
application/resources/src/main/res/values/strings.xml | 1 +
.../tools/src/main/java/org/videolan/tools/Settings.kt | 1 +
.../vlc-android/res/xml/preferences_parental_control.xml | 7 +++++++
.../src/org/videolan/vlc/gui/PinCodeActivity.kt | 4 ++++
.../videolan/vlc/gui/preferences/PreferencesActivity.kt | 15 +++++++++++++++
5 files changed, 28 insertions(+)
diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index e7b72cac98..e848dbbf9a 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -977,6 +977,7 @@
<string name="pin_code_reason_modify">Change your PIN code</string>
<string name="pin_code_modified">PIN code successfully modified</string>
<string name="pin_code_reason_check">Access restricted. Please enter your PIN code</string>
+ <string name="restrict_settings">Restrict settings access</string>
<string name="search_prefs">Search settings</string>
<string name="video_match_frame_rate_title">Match Display Frame Rate</string>
<string name="video_match_frame_rate_summary">Match display refresh rate to media frame rate. For example, a 24p film should play at 24p</string>
diff --git a/application/tools/src/main/java/org/videolan/tools/Settings.kt b/application/tools/src/main/java/org/videolan/tools/Settings.kt
index 0dd0e16424..2434fa10aa 100644
--- a/application/tools/src/main/java/org/videolan/tools/Settings.kt
+++ b/application/tools/src/main/java/org/videolan/tools/Settings.kt
@@ -204,6 +204,7 @@ const val ALBUMS_SHOW_TRACK_NUMBER = "albums_show_track_number"
const val WIDGETS_PREVIEW_PLAYING = "widgets_preview_playing"
const val KEY_SAFE_MODE_PIN = "safe_mode_pin"
+const val KEY_RESTRICT_SETTINGS = "restrict_settings"
class DeviceInfo(context: Context) {
val pm = context.packageManager
diff --git a/application/vlc-android/res/xml/preferences_parental_control.xml b/application/vlc-android/res/xml/preferences_parental_control.xml
index 4e3ecbc1fc..bd249623f9 100644
--- a/application/vlc-android/res/xml/preferences_parental_control.xml
+++ b/application/vlc-android/res/xml/preferences_parental_control.xml
@@ -18,6 +18,13 @@
app:iconSpaceReserved="false"
app:singleLineTitle="false" />
+ <CheckBoxPreference
+ android:defaultValue="false"
+ android:dependency="parental_control_enabled"
+ android:key="restrict_settings"
+ android:title="@string/restrict_settings"
+ app:iconSpaceReserved="false"
+ app:singleLineTitle="false" />
<CheckBoxPreference
android:defaultValue="false"
android:dependency="parental_control_enabled"
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 26f8799513..a51cb85d0a 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/PinCodeActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/PinCodeActivity.kt
@@ -88,6 +88,10 @@ class PinCodeActivity : BaseActivity() {
model = ViewModelProvider.AndroidViewModelFactory(this.application).create(SafeModeModel::class.java)
model.step.observe(this) { step ->
+ if (reason == PinCodeReason.CHECK && model.step.value !in arrayOf( PinStep.INVALID, PinStep.ENTER_EXISTING)) {
+ setResult(RESULT_OK)
+ finish()
+ }
when (step) {
PinStep.ENTER_EXISTING -> binding.pinCodeTitle.text = getString(R.string.safe_mode_pin)
PinStep.ENTER_NEW -> binding.pinCodeTitle.text = getString(R.string.safe_mode_new_pin)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesActivity.kt
index 1d6d36dec2..4b3dd1d20d 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesActivity.kt
@@ -20,11 +20,13 @@
package org.videolan.vlc.gui.preferences
+import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.View
+import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.widget.Toolbar
import androidx.core.os.bundleOf
import androidx.core.view.ViewCompat
@@ -34,12 +36,16 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.videolan.resources.ACTIVITY_RESULT_PREFERENCES
import org.videolan.resources.util.parcelable
+import org.videolan.tools.KEY_RESTRICT_SETTINGS
import org.videolan.tools.RESULT_RESTART
import org.videolan.tools.RESULT_RESTART_APP
import org.videolan.tools.RESULT_UPDATE_ARTISTS
+import org.videolan.tools.Settings
import org.videolan.vlc.PlaybackService
import org.videolan.vlc.R
import org.videolan.vlc.gui.BaseActivity
+import org.videolan.vlc.gui.PinCodeActivity
+import org.videolan.vlc.gui.PinCodeReason
import org.videolan.vlc.gui.preferences.search.PreferenceItem
import org.videolan.vlc.gui.preferences.search.PreferenceParser
import org.videolan.vlc.gui.preferences.search.PreferenceSearchActivity
@@ -50,10 +56,19 @@ class PreferencesActivity : BaseActivity() {
private val searchRequestCode = 167
private var mAppBarLayout: AppBarLayout? = null
override val displayTitle = true
+ private var pinCodeResult = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
+ if (result.resultCode != Activity.RESULT_OK) {
+ finish()
+ }
+ }
override fun getSnackAnchorView(overAudioPlayer:Boolean): View? = findViewById(android.R.id.content)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
+ if (Settings.getInstance(this).getBoolean(KEY_RESTRICT_SETTINGS, false)) {
+ val intent = PinCodeActivity.getIntent(this, PinCodeReason.CHECK)
+ pinCodeResult.launch(intent)
+ }
setContentView(R.layout.preferences_activity)
setSupportActionBar(findViewById<View>(R.id.main_toolbar) as Toolbar)
More information about the Android
mailing list