diff --git a/res/values/cherish_arrays.xml b/res/values/cherish_arrays.xml
index 63dd5cc..8d4818d 100644
--- a/res/values/cherish_arrays.xml
+++ b/res/values/cherish_arrays.xml
@@ -586,28 +586,7 @@
- 6
- 7
-
-
-
- - 5 seconds
- - 10 seconds
- - 30 seconds
- - 1 minute
- - 5 minutes
- - 10 minutes
- - 30 minutes
-
-
- - 5000
- - 10000
- - 30000
- - 60000
- - 300000
- - 600000
- - 1800000
-
-
- @string/pulse_ambient_light_color_mode_notification
diff --git a/res/values/cherish_strings.xml b/res/values/cherish_strings.xml
index 0fdf841..d203e23 100644
--- a/res/values/cherish_strings.xml
+++ b/res/values/cherish_strings.xml
@@ -622,26 +622,6 @@
Data usage
Display data usage summary in quick settings footer
-
- App lock
- Apps will require fingerprint authentication to launch
- Unlock
- Enable debugging
- Disable debugging
- Protected apps
- Select the apps to protect with biometrics or device credentials
- Auto lock timeout
- Duration of time after which an unlocked app in background should be locked
- Redact notifications
-
- Notification content will be hidden and collapsed for selected apps when they are locked.
- Heads up notifications will be automatically disabled.
-
- Protect an application first
- Enable biometrics for unlocking
- Bubbles will be automatically dismissed after timeout
- Enable protection
-
Combined QS Element Styles
Outline
diff --git a/res/values/plurals.xml b/res/values/plurals.xml
deleted file mode 100644
index d28a46b..0000000
--- a/res/values/plurals.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
- - %1$d application is protected
- - %1$d applications are protected
-
-
-
\ No newline at end of file
diff --git a/res/xml/app_lock_package_config_settings.xml b/res/xml/app_lock_package_config_settings.xml
deleted file mode 100644
index 36fd712..0000000
--- a/res/xml/app_lock_package_config_settings.xml
+++ /dev/null
@@ -1,39 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/res/xml/app_lock_package_list_settings.xml b/res/xml/app_lock_package_list_settings.xml
deleted file mode 100644
index 13994b3..0000000
--- a/res/xml/app_lock_package_list_settings.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
diff --git a/res/xml/cherish_settings_app_lock.xml b/res/xml/cherish_settings_app_lock.xml
deleted file mode 100644
index d8b3ead..0000000
--- a/res/xml/cherish_settings_app_lock.xml
+++ /dev/null
@@ -1,38 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/res/xml/cherish_settings_misc.xml b/res/xml/cherish_settings_misc.xml
index 4fe7932..916e072 100644
--- a/res/xml/cherish_settings_misc.xml
+++ b/res/xml/cherish_settings_misc.xml
@@ -37,13 +37,6 @@
android:title="@string/smart_charging_title"
android:summary="@string/smart_charging_summary"
android:fragment="com.cherish.settings.fragments.SmartCharging"/>
-
-
(preferenceKey) ?: return
- if (preference is MainSwitchPreference) {
- preference.addOnSwitchChangeListener(this)
- }
- }
-
- override fun onSwitchChanged(switchView: Switch, isChecked: Boolean) {
- setChecked(isChecked)
- }
-
- override fun getSliceHighlightMenuRes() = R.string.menu_key_cherish
-}
\ No newline at end of file
diff --git a/src/com/cherish/settings/security/applock/AppLockBiometricPreferenceController.kt b/src/com/cherish/settings/security/applock/AppLockBiometricPreferenceController.kt
deleted file mode 100644
index 2172a4f..0000000
--- a/src/com/cherish/settings/security/applock/AppLockBiometricPreferenceController.kt
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2022 cherishOS Project
- *
- * 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.cherish.settings.security.applock
-
-import android.app.AppLockManager
-import android.content.Context
-import android.hardware.biometrics.BiometricManager
-import android.hardware.biometrics.BiometricManager.Authenticators.BIOMETRIC_STRONG
-
-import androidx.preference.Preference
-import androidx.preference.PreferenceScreen
-
-import com.cherish.settings.CherishTogglePreferenceController
-
-import kotlinx.coroutines.CoroutineScope
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.launch
-import kotlinx.coroutines.withContext
-
-private const val KEY = "app_lock_biometrics_allowed"
-
-class AppLockBiometricPreferenceController(
- context: Context,
- private val coroutineScope: CoroutineScope
-) : CherishTogglePreferenceController(context, KEY) {
-
- private val appLockManager = context.getSystemService(AppLockManager::class.java)
- private val biometricManager = context.getSystemService(BiometricManager::class.java)
-
- private var preference: Preference? = null
- private var isBiometricsAllowed = false
-
- init {
- coroutineScope.launch {
- isBiometricsAllowed = withContext(Dispatchers.Default) {
- appLockManager.isBiometricsAllowed()
- }
- preference?.let {
- updateState(it)
- }
- }
- }
-
- override fun getAvailabilityStatus(): Int {
- val result = biometricManager.canAuthenticate(BIOMETRIC_STRONG)
- return if (result == BiometricManager.BIOMETRIC_SUCCESS) AVAILABLE else CONDITIONALLY_UNAVAILABLE
- }
-
- override fun isChecked() = isBiometricsAllowed
-
- override fun setChecked(checked: Boolean): Boolean {
- if (isBiometricsAllowed == checked) return false
- isBiometricsAllowed = checked
- coroutineScope.launch(Dispatchers.Default) {
- appLockManager.setBiometricsAllowed(isBiometricsAllowed)
- }
- return true
- }
-
- override fun displayPreference(screen: PreferenceScreen) {
- super.displayPreference(screen)
- preference = screen.findPreference(preferenceKey)
- }
-}
\ No newline at end of file
diff --git a/src/com/cherish/settings/security/applock/AppLockCredentialActivity.kt b/src/com/cherish/settings/security/applock/AppLockCredentialActivity.kt
deleted file mode 100644
index b946e5d..0000000
--- a/src/com/cherish/settings/security/applock/AppLockCredentialActivity.kt
+++ /dev/null
@@ -1,204 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- * Copyright (C) 2022 FlamingoOS Project
- *
- * 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.cherish.settings.security.applock
-
-import android.app.Activity
-import android.app.AppLockManager
-import android.content.Context
-import android.content.Intent
-import android.graphics.Color
-import android.hardware.biometrics.BiometricConstants
-import android.hardware.biometrics.BiometricManager.Authenticators
-import android.hardware.biometrics.BiometricPrompt
-import android.hardware.biometrics.BiometricPrompt.AuthenticationCallback
-import android.hardware.biometrics.PromptInfo
-import android.os.Bundle
-import android.os.Handler
-import android.os.Looper
-import android.os.UserHandle.USER_NULL
-import android.os.UserManager
-import android.util.Log
-import android.view.WindowManager
-
-import androidx.fragment.app.commit
-import androidx.fragment.app.FragmentActivity
-
-import com.android.internal.widget.LockPatternUtils
-import com.android.settings.R
-import com.android.settings.password.BiometricFragment
-import com.android.settings.password.ConfirmDeviceCredentialUtils
-
-class AppLockCredentialActivity : FragmentActivity() {
-
- private val handler = Handler(Looper.getMainLooper())
-
- private lateinit var lockPatternUtils: LockPatternUtils
- private lateinit var userManager: UserManager
- private lateinit var appLockManager: AppLockManager
-
- private var packageName: String? = null
- private var title: String? = null
- private var userId: Int = USER_NULL
- private var biometricFragment: BiometricFragment? = null
- private var goingToBackground = false
- private var waitingForBiometricCallback = false
-
- private val authenticationCallback = object : AuthenticationCallback() {
- override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
- if (!goingToBackground) {
- waitingForBiometricCallback = false
- if (errorCode == BiometricPrompt.BIOMETRIC_ERROR_USER_CANCELED
- || errorCode == BiometricPrompt.BIOMETRIC_ERROR_CANCELED) {
- finish()
- }
- } else if (waitingForBiometricCallback) { // goingToBackground is true
- waitingForBiometricCallback = false
- finish()
- }
- }
-
- override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
- waitingForBiometricCallback = false
- appLockManager.unlockPackage(packageName)
- ConfirmDeviceCredentialUtils.checkForPendingIntent(this@AppLockCredentialActivity)
- setResult(Activity.RESULT_OK)
- finish()
- }
-
- override fun onAuthenticationFailed() {
- waitingForBiometricCallback = false
- }
-
- override fun onSystemEvent(event: Int) {
- if (event == BiometricConstants.BIOMETRIC_SYSTEM_EVENT_EARLY_USER_CANCEL) {
- finish()
- }
- }
- }
-
- override protected fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
-
- window.apply {
- addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
- statusBarColor = Color.TRANSPARENT
- }
-
- appLockManager = getSystemService(AppLockManager::class.java)
- userManager = UserManager.get(this)
- lockPatternUtils = LockPatternUtils(this)
-
- packageName = intent.getStringExtra(Intent.EXTRA_PACKAGE_NAME)
- if (packageName == null) {
- Log.e(TAG, "Failed to get package name, aborting unlock")
- finish()
- return
- }
-
- title = intent.getStringExtra(AppLockManager.EXTRA_PACKAGE_LABEL)
-
- userId = intent.getIntExtra(Intent.EXTRA_USER_ID, USER_NULL)
- if (userId == USER_NULL) {
- Log.e(TAG, "Invalid user id, aborting")
- finish()
- return
- }
-
- val biometricsAllowed = intent.getBooleanExtra(
- AppLockManager.EXTRA_ALLOW_BIOMETRICS,
- AppLockManager.DEFAULT_BIOMETRICS_ALLOWED
- )
- var authenticators = Authenticators.DEVICE_CREDENTIAL
- if (biometricsAllowed) {
- authenticators = authenticators or Authenticators.BIOMETRIC_STRONG
- }
-
- val promptInfo = PromptInfo().also {
- it.title = getString(com.android.internal.R.string.unlock_application, title)
- it.isDisallowBiometricsIfPolicyExists = true
- it.authenticators = authenticators
- }
-
- if (isBiometricAllowed()) {
- // Don't need to check if biometrics / pin/pattern/pass are enrolled. It will go to
- // onAuthenticationError and do the right thing automatically.
- showBiometricPrompt(promptInfo)
- waitingForBiometricCallback = true
- } else {
- finish()
- }
- }
-
- override protected fun onStart() {
- super.onStart()
- // Translucent activity that is "visible", so it doesn't complain about finish()
- // not being called before onResume().
- setVisible(true)
- }
-
- override fun onPause() {
- super.onPause()
- if (!isChangingConfigurations()) {
- goingToBackground = true
- if (!waitingForBiometricCallback) {
- finish()
- }
- } else {
- goingToBackground = false
- }
- }
-
- // User could be locked while Effective user is unlocked even though the effective owns the
- // credential. Otherwise, biometric can't unlock fbe/keystore through
- // verifyTiedProfileChallenge. In such case, we also wanna show the user message that
- // biometric is disabled due to device restart.
- private fun isStrongAuthRequired() =
- !lockPatternUtils.isBiometricAllowedForUser(userId) ||
- !userManager.isUserUnlocked(userId)
-
- private fun isBiometricAllowed() =
- !isStrongAuthRequired() && !lockPatternUtils.hasPendingEscrowToken(userId)
-
- private fun showBiometricPrompt(promptInfo: PromptInfo) {
- biometricFragment = supportFragmentManager.findFragmentByTag(TAG_BIOMETRIC_FRAGMENT)
- as? BiometricFragment
- var newFragment = false
- if (biometricFragment == null) {
- biometricFragment = BiometricFragment.newInstance(promptInfo)
- newFragment = true
- }
- biometricFragment?.also {
- it.setCallbacks({
- handler.post(it)
- }, authenticationCallback)
- it.setUser(userId)
- }
- if (newFragment) {
- biometricFragment?.let {
- supportFragmentManager.commit {
- add(it, TAG_BIOMETRIC_FRAGMENT)
- }
- }
- }
- }
-
- companion object {
- private const val TAG = "AppLockCredentialActivity"
- private const val TAG_BIOMETRIC_FRAGMENT = "fragment"
- }
-}
diff --git a/src/com/cherish/settings/security/applock/AppLockNotificationRedactionPC.kt b/src/com/cherish/settings/security/applock/AppLockNotificationRedactionPC.kt
deleted file mode 100644
index 3dcfd5a..0000000
--- a/src/com/cherish/settings/security/applock/AppLockNotificationRedactionPC.kt
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (C) 2022 FlamingoOS Project
- *
- * 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.cherish.settings.security.applock
-
-import android.app.AppLockManager
-import android.content.Context
-
-import androidx.preference.Preference
-import androidx.preference.PreferenceScreen
-
-import com.cherish.settings.CherishTogglePreferenceController
-
-import kotlinx.coroutines.CoroutineScope
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.launch
-import kotlinx.coroutines.withContext
-
-private const val KEY = "redact_notifications"
-
-class AppLockNotificationRedactionPC(
- context: Context,
- private val packageName: String,
- private val coroutineScope: CoroutineScope
-) : CherishTogglePreferenceController(context, KEY) {
-
- private val appLockManager = context.getSystemService(AppLockManager::class.java)
- private var shouldRedactNotification = false
- private var preference: Preference? = null
-
- init {
- coroutineScope.launch {
- shouldRedactNotification = withContext(Dispatchers.Default) {
- appLockManager.packageData.find {
- it.packageName == packageName
- }?.shouldRedactNotification == true
- }
- preference?.let {
- updateState(it)
- }
- }
- }
-
- override fun getAvailabilityStatus() = AVAILABLE
-
- override fun isChecked() = shouldRedactNotification
-
- override fun setChecked(checked: Boolean): Boolean {
- if (shouldRedactNotification == checked) return false
- shouldRedactNotification = checked
- coroutineScope.launch(Dispatchers.Default) {
- appLockManager.setShouldRedactNotification(packageName, checked)
- }
- return true
- }
-
- override fun displayPreference(screen: PreferenceScreen) {
- super.displayPreference(screen)
- preference = screen.findPreference(preferenceKey)
- }
-}
\ No newline at end of file
diff --git a/src/com/cherish/settings/security/applock/AppLockPackageConfigFragment.kt b/src/com/cherish/settings/security/applock/AppLockPackageConfigFragment.kt
deleted file mode 100644
index fc3d8f0..0000000
--- a/src/com/cherish/settings/security/applock/AppLockPackageConfigFragment.kt
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright (C) 2022 FlamingoOS Project
- *
- * 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.cherish.settings.security.applock
-
-import android.content.Context
-import android.content.pm.PackageInfo
-import android.content.pm.PackageManager
-import android.os.Bundle
-
-import androidx.lifecycle.lifecycleScope
-
-import com.android.settings.R
-import com.android.settings.widget.EntityHeaderController
-import com.android.settingslib.core.AbstractPreferenceController
-import com.android.settingslib.widget.LayoutPreference
-import com.cherish.settings.fragments.CherishDashboardFragment
-
-private val TAG = AppLockPackageConfigFragment::class.simpleName
-private const val KEY_HEADER = "header_view"
-
-class AppLockPackageConfigFragment : CherishDashboardFragment() {
-
- private lateinit var pm: PackageManager
- private lateinit var packageInfo: PackageInfo
-
- override fun onAttach(context: Context) {
- pm = context.packageManager
- packageInfo = arguments?.getParcelable(PACKAGE_INFO, PackageInfo::class.java)!!
- super.onAttach(context)
- }
-
- override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
- super.onCreatePreferences(savedInstanceState, rootKey)
- val header = preferenceScreen.findPreference(KEY_HEADER)
- EntityHeaderController.newInstance(
- requireActivity(),
- this,
- header?.findViewById(R.id.entity_header)
- ).setRecyclerView(listView, settingsLifecycle)
- .setPackageName(packageInfo.packageName)
- .setButtonActions(
- EntityHeaderController.ActionType.ACTION_NONE,
- EntityHeaderController.ActionType.ACTION_NONE
- )
- .bindHeaderButtons()
- .setLabel(getLabel(packageInfo))
- .setIcon(getIcon(packageInfo))
- .done(requireActivity(), false /* rebindActions */)
- }
-
- private fun getLabel(packageInfo: PackageInfo) =
- packageInfo.applicationInfo.loadLabel(pm).toString()
-
- private fun getIcon(packageInfo: PackageInfo) =
- packageInfo.applicationInfo.loadIcon(pm)
-
- override protected fun createPreferenceControllers(
- context: Context
- ) : List = listOf(
- AppLockPackageProtectionPC(context, packageInfo.packageName, lifecycleScope),
- AppLockNotificationRedactionPC(context, packageInfo.packageName, lifecycleScope),
- )
-
- override protected fun getPreferenceScreenResId() = R.xml.app_lock_package_config_settings
-
- override protected fun getLogTag() = TAG
-}
\ No newline at end of file
diff --git a/src/com/cherish/settings/security/applock/AppLockPackageListFragment.kt b/src/com/cherish/settings/security/applock/AppLockPackageListFragment.kt
deleted file mode 100644
index deef54c..0000000
--- a/src/com/cherish/settings/security/applock/AppLockPackageListFragment.kt
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Copyright (C) 2022 FlamingoOS Project
- *
- * 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.cherish.settings.security.applock
-
-import android.app.AppLockManager
-import android.content.Context
-import android.content.pm.PackageInfo
-import android.content.pm.PackageManager
-import android.content.pm.PackageManager.PackageInfoFlags
-import android.os.Bundle
-import android.view.View
-
-import androidx.lifecycle.lifecycleScope
-import androidx.preference.Preference
-import androidx.preference.forEach
-
-import com.android.settings.R
-import com.android.settings.core.SubSettingLauncher
-import com.android.settingslib.PrimarySwitchPreference
-import com.android.settingslib.widget.TwoTargetPreference.ICON_SIZE_SMALL
-import com.cherish.settings.fragments.CherishDashboardFragment
-
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.launch
-import kotlinx.coroutines.withContext
-
-private val TAG = AppLockPackageListFragment::class.simpleName
-internal const val PACKAGE_INFO = "package_info"
-
-class AppLockPackageListFragment : CherishDashboardFragment() {
-
- private lateinit var appLockManager: AppLockManager
- private lateinit var pm: PackageManager
- private lateinit var whiteListedPackages: Array
-
- override fun onAttach(context: Context) {
- super.onAttach(context)
- appLockManager = context.getSystemService(AppLockManager::class.java)
- pm = context.packageManager
- whiteListedPackages = resources.getStringArray(
- com.android.internal.R.array.config_appLockAllowedSystemApps)
- }
-
- override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
- super.onCreatePreferences(savedInstanceState, rootKey)
- lifecycleScope.launch {
- val selectedPackages = getSelectedPackages()
- val preferences = withContext(Dispatchers.Default) {
- pm.getInstalledPackages(
- PackageInfoFlags.of(PackageManager.MATCH_ALL.toLong())
- ).filter {
- !it.applicationInfo.isSystemApp() || whiteListedPackages.contains(it.packageName)
- }.sortedWith { first, second ->
- getLabel(first).compareTo(getLabel(second))
- }
- }.map { packageInfo ->
- createPreference(packageInfo, selectedPackages.contains(packageInfo.packageName))
- }
- preferenceScreen?.let {
- preferences.forEach { pref ->
- it.addPreference(pref)
- }
- }
- }
- }
-
- override fun onResume() {
- super.onResume()
- lifecycleScope.launch {
- val selectedPackages = getSelectedPackages()
- preferenceScreen?.forEach {
- if (it is PrimarySwitchPreference) {
- it.isChecked = selectedPackages.contains(it.key)
- }
- }
- }
- }
-
- private suspend fun getSelectedPackages(): Set {
- return withContext(Dispatchers.IO) {
- appLockManager.packageData.map { it.packageName }.toSet()
- }
- }
-
- private fun getLabel(packageInfo: PackageInfo) =
- packageInfo.applicationInfo.loadLabel(pm).toString()
-
- private fun createPreference(packageInfo: PackageInfo, isProtected: Boolean): Preference {
- val label = getLabel(packageInfo)
- return PrimarySwitchPreference(requireContext()).apply {
- key = packageInfo.packageName
- title = label
- icon = packageInfo.applicationInfo.loadIcon(pm)
- setIconSize(ICON_SIZE_SMALL)
- isChecked = isProtected
- setOnPreferenceChangeListener { _, newValue ->
- lifecycleScope.launch(Dispatchers.IO) {
- if (newValue as Boolean) {
- appLockManager.addPackage(packageInfo.packageName)
- } else {
- appLockManager.removePackage(packageInfo.packageName)
- }
- }
- return@setOnPreferenceChangeListener true
- }
- setOnPreferenceClickListener {
- SubSettingLauncher(requireContext())
- .setDestination(AppLockPackageConfigFragment::class.qualifiedName)
- .setSourceMetricsCategory(metricsCategory)
- .setTitleText(label)
- .setArguments(
- Bundle(1).apply {
- putParcelable(PACKAGE_INFO, packageInfo)
- }
- )
- .launch()
- true
- }
- }
- }
-
- override protected fun getPreferenceScreenResId() = R.xml.app_lock_package_list_settings
-
- override protected fun getLogTag() = TAG
-}
diff --git a/src/com/cherish/settings/security/applock/AppLockPackageProtectionPC.kt b/src/com/cherish/settings/security/applock/AppLockPackageProtectionPC.kt
deleted file mode 100644
index 05c8e1a..0000000
--- a/src/com/cherish/settings/security/applock/AppLockPackageProtectionPC.kt
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (C) 2022 FlamingoOS Project
- *
- * 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.cherish.settings.security.applock
-
-import android.app.AppLockManager
-import android.content.Context
-
-import androidx.lifecycle.lifecycleScope
-import androidx.preference.Preference
-import androidx.preference.PreferenceScreen
-
-import com.cherish.settings.CherishTogglePreferenceController
-
-import kotlinx.coroutines.CoroutineScope
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.launch
-import kotlinx.coroutines.withContext
-
-private const val KEY = "main_switch"
-
-class AppLockPackageProtectionPC(
- context: Context,
- private val packageName: String,
- private val coroutineScope: CoroutineScope
-) : CherishTogglePreferenceController(context, KEY) {
-
- private val appLockManager = context.getSystemService(AppLockManager::class.java)
- private var isProtected = false
- private var preference: Preference? = null
-
- init {
- coroutineScope.launch {
- isProtected = withContext(Dispatchers.Default) {
- appLockManager.packageData.any {
- it.packageName == packageName
- }
- }
- preference?.let {
- updateState(it)
- }
- }
- }
-
- override fun getAvailabilityStatus() = AVAILABLE
-
- override fun isChecked() = isProtected
-
- override fun setChecked(checked: Boolean): Boolean {
- if (isProtected == checked) return false
- isProtected = checked
- coroutineScope.launch(Dispatchers.Default) {
- if (isProtected) {
- appLockManager.addPackage(packageName)
- } else {
- appLockManager.removePackage(packageName)
- }
- }
- return true
- }
-
- override fun displayPreference(screen: PreferenceScreen) {
- super.displayPreference(screen)
- preference = screen.findPreference(preferenceKey)
- }
-}
\ No newline at end of file
diff --git a/src/com/cherish/settings/security/applock/AppLockSettingsFragment.kt b/src/com/cherish/settings/security/applock/AppLockSettingsFragment.kt
deleted file mode 100644
index a88868e..0000000
--- a/src/com/cherish/settings/security/applock/AppLockSettingsFragment.kt
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (C) 2022 FlamingoOS Project
- *
- * 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.cherish.settings.security.applock
-
-import android.content.Context
-import android.os.SystemProperties
-import android.view.Menu
-import android.view.MenuInflater
-import android.view.MenuItem
-
-import androidx.lifecycle.lifecycleScope
-
-import com.android.settings.R
-import com.android.settings.search.BaseSearchIndexProvider
-import com.android.settingslib.core.AbstractPreferenceController
-import com.android.settingslib.search.SearchIndexable
-import com.cherish.settings.fragments.CherishDashboardFragment
-
-@SearchIndexable
-class AppLockSettingsFragment : CherishDashboardFragment(),
- MenuItem.OnMenuItemClickListener {
-
- private var debugEnabled = SystemProperties.get(DEBUG_PROPERTY, null) == LEVEL_DEBUG
- private var handledClick = false
-
- override protected fun getPreferenceScreenResId() = R.xml.cherish_settings_app_lock
-
- override protected fun getLogTag() = TAG
-
- override fun onCreateOptionsMenu(menu: Menu, menuInflater: MenuInflater) {
- super.onCreateOptionsMenu(menu, menuInflater)
- menu.add(
- 0 /* groupId */,
- MENU_ITEM_DEBUG_ID,
- 0 /* order */,
- getDebugMenuItemTitle(),
- ).setOnMenuItemClickListener(this)
- }
-
- private fun getDebugMenuItemTitle(): Int =
- if (debugEnabled) R.string.disable_debugging else R.string.enable_debugging
-
- override fun onMenuItemClick(item: MenuItem): Boolean {
- if (item.itemId == MENU_ITEM_DEBUG_ID) {
- debugEnabled = !debugEnabled
- SystemProperties.set(DEBUG_PROPERTY, if (debugEnabled) LEVEL_DEBUG else null)
- item.setTitle(getDebugMenuItemTitle())
- return true
- }
- return false
- }
-
- override protected fun createPreferenceControllers(
- context: Context
- ) : List = listOf(
- AppLockBiometricPreferenceController(context, lifecycleScope)
- )
-
- companion object {
- private const val TAG = "AppLockSettingsFragment"
-
- private const val DEBUG_PROPERTY = "log.tag.AppLockManagerService"
- private const val LEVEL_DEBUG = "DEBUG"
- private const val MENU_ITEM_DEBUG_ID = 101
-
- @JvmField
- val SEARCH_INDEX_DATA_PROVIDER = BaseSearchIndexProvider(R.xml.cherish_settings_app_lock)
- }
-}
\ No newline at end of file
diff --git a/src/com/cherish/settings/security/applock/AppLockSettingsPreferenceController.kt b/src/com/cherish/settings/security/applock/AppLockSettingsPreferenceController.kt
deleted file mode 100644
index 6a73262..0000000
--- a/src/com/cherish/settings/security/applock/AppLockSettingsPreferenceController.kt
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright (C) 2022 FlamingoOS Project
- *
- * 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.cherish.settings.security.applock
-
-import android.app.Activity
-import android.app.AppLockManager
-import android.content.Context
-import android.content.Intent
-import android.os.UserHandle
-
-import androidx.activity.result.ActivityResultLauncher
-import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult
-import androidx.lifecycle.Lifecycle.Event
-import androidx.lifecycle.LifecycleEventObserver
-import androidx.lifecycle.LifecycleOwner
-import androidx.preference.Preference
-import androidx.preference.PreferenceScreen
-
-import com.android.internal.widget.LockPatternUtils
-import com.android.settings.R
-import com.android.settings.core.SubSettingLauncher
-import com.android.settings.dashboard.DashboardFragment
-import com.android.settings.password.ConfirmDeviceCredentialActivity
-import com.android.settingslib.core.lifecycle.Lifecycle
-import com.android.settingslib.transition.SettingsTransitionHelper.TransitionType.TRANSITION_SLIDE
-import com.android.settings.core.BasePreferenceController
-
-import com.android.settings.SettingsActivity
-import com.android.settings.core.SettingsBaseActivity
-import com.android.settingslib.core.instrumentation.MetricsFeatureProvider
-
-class AppLockSettingsPreferenceController(
- context: Context,
- preferenceKey: String,
- lifecycle: Lifecycle?,
- private val host: DashboardFragment?
-) : BasePreferenceController(context, preferenceKey),
- LifecycleEventObserver {
-
- private val lockPatternUtils = LockPatternUtils(context)
- private val appLockManager = context.getSystemService(AppLockManager::class.java)
- private var preference: Preference? = null
- private val securityPromptLauncher: ActivityResultLauncher?
-
- init {
- lifecycle?.addObserver(this)
- securityPromptLauncher = host?.registerForActivityResult(
- StartActivityForResult()
- ) {
- if (it?.resultCode == Activity.RESULT_OK) {
- val intent = SubSettingLauncher(mContext)
- .setDestination(AppLockSettingsFragment::class.qualifiedName)
- .setSourceMetricsCategory(host.metricsCategory)
- .setTransitionType(TRANSITION_SLIDE)
- .toIntent()
- intent.setClass(mContext, AppLockSubSettings::class.java)
- mContext.startActivity(intent)
- }
- }
- }
-
- override fun getAvailabilityStatus() =
- if (lockPatternUtils.isSecure(UserHandle.myUserId()))
- AVAILABLE
- else
- DISABLED_DEPENDENT_SETTING
-
- override fun onStateChanged(owner: LifecycleOwner, event: Event) {
- if (event == Event.ON_START) {
- preference?.let {
- updateState(it)
- }
- }
- }
-
- override fun displayPreference(screen: PreferenceScreen) {
- super.displayPreference(screen)
- preference = screen.findPreference(preferenceKey)
- }
-
- override fun updateState(preference: Preference) {
- preference.apply {
- if (getAvailabilityStatus() == AVAILABLE) {
- setEnabled(true)
- summary = getSummaryForListSize(appLockManager.packageData.size)
- } else {
- setEnabled(false)
- summary = mContext.getString(R.string.disabled_because_no_backup_security)
- }
- }
- }
-
- private fun getSummaryForListSize(size: Int): CharSequence? =
- if (size == 0) {
- null
- } else {
- mContext.resources.getQuantityString(R.plurals.app_lock_summary, size, size)
- }
-
- override fun handlePreferenceTreeClick(preference: Preference): Boolean {
- if (preference.key == preferenceKey && securityPromptLauncher != null) {
- securityPromptLauncher.launch(
- ConfirmDeviceCredentialActivity.createIntent(
- mContext.getString(R.string.app_lock_authentication_dialog_title),
- null /* details */,
- )
- )
- return true
- }
- return super.handlePreferenceTreeClick(preference)
- }
-}
\ No newline at end of file
diff --git a/src/com/cherish/settings/security/applock/AppLockSubSettings.kt b/src/com/cherish/settings/security/applock/AppLockSubSettings.kt
deleted file mode 100644
index 392f531..0000000
--- a/src/com/cherish/settings/security/applock/AppLockSubSettings.kt
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (C) 2022 FlamingoOS Project
- *
- * 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.cherish.settings.security.applock
-
-import com.android.settings.SettingsActivity
-
-class AppLockSubSettings : SettingsActivity() {
-
- override protected fun isValidFragment(fragmentName: String): Boolean {
- return AppLockSettingsFragment::class.qualifiedName == fragmentName
- }
-}
\ No newline at end of file
diff --git a/src/com/cherish/settings/security/applock/AppLockTimeoutPreferenceController.kt b/src/com/cherish/settings/security/applock/AppLockTimeoutPreferenceController.kt
deleted file mode 100644
index 19fcc69..0000000
--- a/src/com/cherish/settings/security/applock/AppLockTimeoutPreferenceController.kt
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2022 FlamingoOS Project
- *
- * 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.cherish.settings.security.applock
-
-import android.app.AppLockManager
-import android.content.Context
-
-import androidx.preference.ListPreference
-import androidx.preference.Preference
-
-import com.android.settings.core.BasePreferenceController
-
-class AppLockTimeoutPreferenceController(
- context: Context,
- key: String,
-) : BasePreferenceController(context, key),
- Preference.OnPreferenceChangeListener {
-
- private val appLockManager = context.getSystemService(AppLockManager::class.java)
-
- override fun getAvailabilityStatus() = AVAILABLE
-
- override fun updateState(preference: Preference) {
- (preference as ListPreference).value = appLockManager.timeout.takeIf {
- it != -1L
- }?.toString()
- }
-
- override fun onPreferenceChange(preference: Preference, newValue: Any): Boolean {
- appLockManager.timeout = (newValue as String).toLong()
- return true
- }
-}
\ No newline at end of file