Cherish: use a new task stack for app lock fragments
* fixes fragments staying in recents on going home * also made other preferences do binder calls asynchronously Signed-off-by: jhonboy121 <alfredmathew05@gmail.com> Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
@@ -705,6 +705,7 @@
|
|||||||
|
|
||||||
<!-- App lock -->
|
<!-- App lock -->
|
||||||
<string name="app_lock_title">App lock</string>
|
<string name="app_lock_title">App lock</string>
|
||||||
|
<string name="app_lock_summary">Apps will require fingerprint authentication to launch</string>
|
||||||
<string name="app_lock_authentication_dialog_title">Unlock</string>
|
<string name="app_lock_authentication_dialog_title">Unlock</string>
|
||||||
<string name="enable_debugging">Enable debugging</string>
|
<string name="enable_debugging">Enable debugging</string>
|
||||||
<string name="disable_debugging">Disable debugging</string>
|
<string name="disable_debugging">Disable debugging</string>
|
||||||
|
|||||||
38
res/xml/cherish_settings_app_lock.xml
Normal file
38
res/xml/cherish_settings_app_lock.xml
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- 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.
|
||||||
|
-->
|
||||||
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:title="@string/app_lock_title">
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="app_lock_packages"
|
||||||
|
android:title="@string/app_lock_packages_title"
|
||||||
|
android:summary="@string/app_lock_packages_summary"
|
||||||
|
android:fragment="com.cherish.settings.security.applock.AppLockPackageListFragment" />
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:key="app_lock_timeout"
|
||||||
|
android:title="@string/app_lock_timeout_title"
|
||||||
|
android:summary="@string/app_lock_timeout_summary"
|
||||||
|
android:entries="@array/app_lock_timeout_entries"
|
||||||
|
android:entryValues="@array/app_lock_timeout_values"
|
||||||
|
android:defaultValue="0"
|
||||||
|
android:persistent="false"
|
||||||
|
settings:controller="com.cherish.settings.security.applock.AppLockTimeoutPreferenceController" />
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:key="app_lock_biometrics_allowed"
|
||||||
|
android:title="@string/app_lock_biometrics_allowed_title"
|
||||||
|
android:persistent="false" />
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
||||||
@@ -36,6 +36,13 @@
|
|||||||
android:title="@string/click_partial_screenshot_title"
|
android:title="@string/click_partial_screenshot_title"
|
||||||
android:summary="@string/click_partial_screenshot_summary"
|
android:summary="@string/click_partial_screenshot_summary"
|
||||||
android:defaultValue="false" />
|
android:defaultValue="false" />
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="app_lock"
|
||||||
|
android:title="@string/app_lock_title"
|
||||||
|
android:summary="@string/app_lock_summary"
|
||||||
|
android:fragment="com.cherish.settings.security.applock.AppLockSettingsFragment"
|
||||||
|
settings:controller="com.cherish.settings.security.applock.AppLockSettingsPreferenceController" />
|
||||||
|
|
||||||
<!-- Unlock FPS for specific games -->
|
<!-- Unlock FPS for specific games -->
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
|
|||||||
@@ -19,37 +19,59 @@ package com.cherish.settings.security.applock
|
|||||||
import android.app.AppLockManager
|
import android.app.AppLockManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.hardware.biometrics.BiometricManager
|
import android.hardware.biometrics.BiometricManager
|
||||||
import android.hardware.biometrics.BiometricManager.Authenticators
|
import android.hardware.biometrics.BiometricManager.Authenticators.BIOMETRIC_STRONG
|
||||||
|
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
import androidx.preference.SwitchPreference
|
import androidx.preference.PreferenceScreen
|
||||||
|
|
||||||
import com.android.settings.core.BasePreferenceController
|
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(
|
class AppLockBiometricPreferenceController(
|
||||||
context: Context,
|
context: Context,
|
||||||
key: String,
|
private val coroutineScope: CoroutineScope
|
||||||
) : BasePreferenceController(context, key),
|
) : CherishTogglePreferenceController(context, KEY) {
|
||||||
Preference.OnPreferenceChangeListener {
|
|
||||||
|
|
||||||
private val appLockManager = context.getSystemService(AppLockManager::class.java)
|
private val appLockManager = context.getSystemService(AppLockManager::class.java)
|
||||||
private val biometricManager = context.getSystemService(BiometricManager::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 {
|
override fun getAvailabilityStatus(): Int {
|
||||||
val biometricsAllowed = biometricManager.canAuthenticate(
|
val result = biometricManager.canAuthenticate(BIOMETRIC_STRONG)
|
||||||
Authenticators.BIOMETRIC_STRONG) == BiometricManager.BIOMETRIC_SUCCESS
|
return if (result == BiometricManager.BIOMETRIC_SUCCESS) AVAILABLE else CONDITIONALLY_UNAVAILABLE
|
||||||
return if (biometricsAllowed)
|
|
||||||
AVAILABLE
|
|
||||||
else
|
|
||||||
UNSUPPORTED_ON_DEVICE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateState(preference: Preference) {
|
override fun isChecked() = isBiometricsAllowed
|
||||||
(preference as SwitchPreference).setChecked(appLockManager.isBiometricsAllowed())
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onPreferenceChange(preference: Preference, newValue: Any): Boolean {
|
override fun setChecked(checked: Boolean): Boolean {
|
||||||
appLockManager.setBiometricsAllowed(newValue as Boolean)
|
isBiometricsAllowed = checked
|
||||||
|
coroutineScope.launch(Dispatchers.Default) {
|
||||||
|
appLockManager.setBiometricsAllowed(isBiometricsAllowed)
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun displayPreference(screen: PreferenceScreen) {
|
||||||
|
super.displayPreference(screen)
|
||||||
|
preference = screen.findPreference(preferenceKey)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -67,7 +67,7 @@ class AppLockNotificationRedactionPC(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun displayPreference(screen: PreferenceScreen) {
|
override fun displayPreference(screen: PreferenceScreen) {
|
||||||
super.displayPreference(screen);
|
super.displayPreference(screen)
|
||||||
preference = screen.findPreference(preferenceKey)
|
preference = screen.findPreference(preferenceKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,21 +22,22 @@ import android.view.Menu
|
|||||||
import android.view.MenuInflater
|
import android.view.MenuInflater
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
|
||||||
import com.android.settings.R
|
import com.android.settings.R
|
||||||
import com.android.settings.search.BaseSearchIndexProvider
|
import com.android.settings.search.BaseSearchIndexProvider
|
||||||
|
import com.android.settingslib.core.AbstractPreferenceController
|
||||||
import com.android.settingslib.search.SearchIndexable
|
import com.android.settingslib.search.SearchIndexable
|
||||||
import com.android.settings.dashboard.DashboardFragment
|
import com.cherish.settings.fragments.CherishDashboardFragment
|
||||||
|
|
||||||
@SearchIndexable
|
@SearchIndexable
|
||||||
class AppLockSettingsFragment : DashboardFragment(),
|
class AppLockSettingsFragment : CherishDashboardFragment(),
|
||||||
MenuItem.OnMenuItemClickListener {
|
MenuItem.OnMenuItemClickListener {
|
||||||
|
|
||||||
private var debugEnabled = SystemProperties.get(DEBUG_PROPERTY, null) == LEVEL_DEBUG
|
private var debugEnabled = SystemProperties.get(DEBUG_PROPERTY, null) == LEVEL_DEBUG
|
||||||
|
private var handledClick = false
|
||||||
|
|
||||||
override protected fun getPreferenceScreenResId() = R.xml.app_lock_package_config_settings
|
override protected fun getPreferenceScreenResId() = R.xml.cherish_settings_app_lock
|
||||||
|
|
||||||
override fun getMetricsCategory() = MetricsProto.MetricsEvent.CHERISH_SETTINGS
|
|
||||||
|
|
||||||
override protected fun getLogTag() = TAG
|
override protected fun getLogTag() = TAG
|
||||||
|
|
||||||
@@ -51,22 +52,24 @@ class AppLockSettingsFragment : DashboardFragment(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getDebugMenuItemTitle(): Int =
|
private fun getDebugMenuItemTitle(): Int =
|
||||||
if (debugEnabled)
|
if (debugEnabled) R.string.disable_debugging else R.string.enable_debugging
|
||||||
R.string.disable_debugging
|
|
||||||
else
|
|
||||||
R.string.enable_debugging
|
|
||||||
|
|
||||||
override fun onMenuItemClick(item: MenuItem): Boolean {
|
override fun onMenuItemClick(item: MenuItem): Boolean {
|
||||||
if (item.itemId == MENU_ITEM_DEBUG_ID) {
|
if (item.itemId == MENU_ITEM_DEBUG_ID) {
|
||||||
debugEnabled = !debugEnabled
|
debugEnabled = !debugEnabled
|
||||||
SystemProperties.set(DEBUG_PROPERTY,
|
SystemProperties.set(DEBUG_PROPERTY, if (debugEnabled) LEVEL_DEBUG else null)
|
||||||
if (debugEnabled) LEVEL_DEBUG else null)
|
|
||||||
item.setTitle(getDebugMenuItemTitle())
|
item.setTitle(getDebugMenuItemTitle())
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override protected fun createPreferenceControllers(
|
||||||
|
context: Context
|
||||||
|
) : List<AbstractPreferenceController> = listOf(
|
||||||
|
AppLockBiometricPreferenceController(context, lifecycleScope)
|
||||||
|
)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "AppLockSettingsFragment"
|
private const val TAG = "AppLockSettingsFragment"
|
||||||
|
|
||||||
@@ -75,6 +78,6 @@ class AppLockSettingsFragment : DashboardFragment(),
|
|||||||
private const val MENU_ITEM_DEBUG_ID = 101
|
private const val MENU_ITEM_DEBUG_ID = 101
|
||||||
|
|
||||||
@JvmField
|
@JvmField
|
||||||
val SEARCH_INDEX_DATA_PROVIDER = BaseSearchIndexProvider(R.xml.app_lock_package_config_settings)
|
val SEARCH_INDEX_DATA_PROVIDER = BaseSearchIndexProvider(R.xml.cherish_settings_app_lock)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,16 +36,20 @@ import com.android.settings.core.SubSettingLauncher
|
|||||||
import com.android.settings.password.ConfirmDeviceCredentialActivity
|
import com.android.settings.password.ConfirmDeviceCredentialActivity
|
||||||
import com.android.settings.security.SecuritySettings
|
import com.android.settings.security.SecuritySettings
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle
|
import com.android.settingslib.core.lifecycle.Lifecycle
|
||||||
import com.android.settingslib.transition.SettingsTransitionHelper.TransitionType
|
import com.android.settingslib.transition.SettingsTransitionHelper.TransitionType.TRANSITION_SLIDE
|
||||||
import com.android.settings.core.BasePreferenceController
|
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(
|
class AppLockSettingsPreferenceController(
|
||||||
context: Context,
|
context: Context,
|
||||||
preferenceKey: String,
|
preferenceKey: String,
|
||||||
private val host: SecuritySettings?,
|
private val host: SecuritySettings?,
|
||||||
lifecycle: Lifecycle?,
|
lifecycle: Lifecycle?,
|
||||||
) : BasePreferenceController(context, preferenceKey),
|
) : BasePreferenceController(context, preferenceKey),
|
||||||
LifecycleEventObserver {
|
LifecycleEventObserver {
|
||||||
|
|
||||||
private val lockPatternUtils = LockPatternUtils(context)
|
private val lockPatternUtils = LockPatternUtils(context)
|
||||||
private val appLockManager = context.getSystemService(AppLockManager::class.java)
|
private val appLockManager = context.getSystemService(AppLockManager::class.java)
|
||||||
@@ -58,15 +62,13 @@ class AppLockSettingsPreferenceController(
|
|||||||
StartActivityForResult()
|
StartActivityForResult()
|
||||||
) {
|
) {
|
||||||
if (it?.resultCode == Activity.RESULT_OK) {
|
if (it?.resultCode == Activity.RESULT_OK) {
|
||||||
SubSettingLauncher(mContext)
|
val intent = SubSettingLauncher(mContext)
|
||||||
.setDestination(AppLockSettingsFragment::class.qualifiedName)
|
.setDestination(AppLockSettingsFragment::class.qualifiedName)
|
||||||
.setSourceMetricsCategory(host.metricsCategory)
|
.setSourceMetricsCategory(host.metricsCategory)
|
||||||
.setTransitionType(TransitionType.TRANSITION_SLIDE)
|
.setTransitionType(TRANSITION_SLIDE)
|
||||||
.addFlags(
|
.toIntent()
|
||||||
Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS or
|
intent.setClass(mContext, AppLockSubSettings::class.java)
|
||||||
Intent.FLAG_ACTIVITY_NEW_TASK
|
mContext.startActivity(intent)
|
||||||
)
|
|
||||||
.launch()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user