OmniControl: Add back FingerprintSettingsFragment
Change-Id: Idfc34650e0ca2e89cd93716f8aa4a2ca3495bc6e
diff --git a/app/src/main/java/org/omnirom/control/FingerprintSettingsFragment.kt b/app/src/main/java/org/omnirom/control/FingerprintSettingsFragment.kt
index 31f8da0..3d5a0a9 100644
--- a/app/src/main/java/org/omnirom/control/FingerprintSettingsFragment.kt
+++ b/app/src/main/java/org/omnirom/control/FingerprintSettingsFragment.kt
@@ -1,284 +1,284 @@
-///*
-// * Copyright (C) 2023 The OmniROM Project
-// *
-// * This program is free software: you can redistribute it and/or modify
-// * it under the terms of the GNU General Public License as published by
-// * the Free Software Foundation, either version 2 of the License, or
-// * (at your option) any later version.
-// *
-// * This program is distributed in the hope that it will be useful,
-// * but WITHOUT ANY WARRANTY; without even the implied warranty of
-// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// * GNU General Public License for more details.
-// *
-// * You should have received a copy of the GNU General Public License
-// * along with this program. If not, see <http://www.gnu.org/licenses/>.
-// *
-// */
-//package org.omnirom.control
-//
-//import android.app.Activity
-//import android.content.ComponentName
-//import android.content.Context
-//import android.content.Intent
-//import android.content.ServiceConnection
-//import android.graphics.Bitmap
-//import android.graphics.BitmapFactory
-//import android.graphics.drawable.BitmapDrawable
-//import android.net.Uri
-//import android.os.Bundle
-//import android.os.IBinder
-//import android.provider.MediaStore
-//import android.provider.Settings
-//import android.util.Log
-//import androidx.activity.result.contract.ActivityResultContract
-//import androidx.activity.result.contract.ActivityResultContracts
-//import androidx.annotation.DrawableRes
-//import androidx.annotation.XmlRes
-//import androidx.preference.Preference
-//import androidx.preference.SwitchPreference
-//import com.android.systemui.shared.omni.IOmniSystemUiProxy
-//import org.omnirom.omnilib.utils.OmniSettings
-//import java.io.File
-//import java.io.FileOutputStream
-//import java.io.IOException
-//
-//
-//class FingerprintSettingsFragment : AbstractSettingsFragment() {
-// private val TAG = "FingerprintSettingsFragment"
-// private val FINGERPRINT_CUSTOM_ICON_SELECT = "custom_fingerprint_icon_select"
-// private val FINGERPRINT_CUSTOM_ICON_ENABLE = "custom_fingerprint_icon_enable"
-// private val UFPSIMAGE_FILE_NAME = "ufpsImage"
-//
-// companion object {
-// @DrawableRes
-// val ICON_RES = R.drawable.ic_settings_fingerprint
-// @XmlRes
-// val XML_RES = R.xml.fingerprint_preferences
-//
-// fun isEnabled(context: Context) : Boolean {
-// return context.resources.getBoolean(R.bool.config_has_udfps)
-// }
-// }
-//
-// class PickSinglePhotoContract : ActivityResultContract<Void?, Uri?>() {
-// override fun createIntent(context: Context, input: Void?): Intent {
-// return Intent(Intent(MediaStore.ACTION_PICK_IMAGES)).apply { type = "image/*" }
-// }
-//
-// override fun parseResult(resultCode: Int, intent: Intent?): Uri? {
-// return intent.takeIf { resultCode == Activity.RESULT_OK }?.data
-// }
-// }
-//
-// var pickImageLegacy = registerForActivityResult<String, Uri>(
-// ActivityResultContracts.GetContent()
-// ) { uri: Uri? ->
-// if (uri != null) {
-// try {
-// requireContext().contentResolver.openInputStream(uri).use { inputStream ->
-// val bitmap = BitmapFactory.decodeStream(inputStream)
-// systemUIProxy?.setUfpsImageBitmap(bitmap)
-// savePickerIcon(bitmap)
-// }
-//
-// Settings.System.putString(
-// requireContext().contentResolver,
-// OmniSettings.OMNI_CUSTOM_FP_ICON_UPDATE,
-// System.currentTimeMillis().toString()
-// )
-// } catch (e: Exception) {
-// Log.d(TAG, "pickImage", e);
-// }
-// }
-// }
-//
-// private val pickImage =
-// registerForActivityResult(PickSinglePhotoContract()) { uri ->
-// Log.d(TAG, "pickImage uri = " + uri)
-// if (uri != null) {
-// // TODO we should do some check if the image is even a useful one eg size
-// try {
-// requireContext().contentResolver.openInputStream(uri).use { inputStream ->
-// val bitmap = BitmapFactory.decodeStream(inputStream)
-// systemUIProxy?.setUfpsImageBitmap(bitmap)
-// savePickerIcon(bitmap)
-// }
-//
-// Settings.System.putString(
-// requireContext().contentResolver,
-// OmniSettings.OMNI_CUSTOM_FP_ICON_UPDATE,
-// System.currentTimeMillis().toString()
-// )
-// } catch (e: Exception) {
-// Log.d(TAG, "pickImage", e);
-// }
-// }
-// }
-//
-//
-// private val mSystemUIProxyService: ServiceConnection = object : ServiceConnection {
-// override fun onServiceConnected(name: ComponentName, service: IBinder) {
-// Log.d(
-// TAG,
-// "onServiceConnected $name $service"
-// )
-// systemUIProxy = IOmniSystemUiProxy.Stub.asInterface(service)
-// }
-//
-// override fun onServiceDisconnected(name: ComponentName) {
-// Log.d(TAG, "onServiceDisconnected $name")
-// }
-// }
-//
-// private var mSystemUIProxyBound = false
-// private var systemUIProxy: IOmniSystemUiProxy? = null
-// private var mFilePicker: Preference? = null
-// private var mEnableCustom: SwitchPreference? = null
-//
-//
-// private fun bindSystemUIProxyService() {
-// if (!mSystemUIProxyBound) {
-// Log.d(TAG, "bindSystemUIProxyService")
-// val serviceIntent = Intent("android.intent.action.OMNI_SYSTEMUI_SERVICE")
-// .setPackage("com.android.systemui")
-// try {
-// mSystemUIProxyBound = requireActivity().bindService(
-// serviceIntent,
-// mSystemUIProxyService,
-// Context.BIND_AUTO_CREATE
-// )
-// } catch (e: SecurityException) {
-// Log.e(
-// TAG,
-// "Unable to bind because of security error",
-// e
-// )
-// }
-// }
-// }
-//
-// private fun unbindSystemUIProxyService() {
-// if (mSystemUIProxyBound) {
-// Log.d(TAG, "unbindSystemUIProxyService")
-// requireActivity().unbindService(mSystemUIProxyService)
-// mSystemUIProxyBound = false
-// }
-// }
-//
-// override fun getFragmentTitle(): String {
-// return getString(R.string.fprint_title)
-// }
-//
-// override fun getFragmentSummary(): String {
-// return getString(R.string.fprint_summary)
-// }
-//
-// override fun getFragmentIcon(): Int {
-// return ICON_RES
-// }
-//
-// override fun onDestroy() {
-// super.onDestroy()
-// unbindSystemUIProxyService()
-// }
-//
-// override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
-// setPreferencesFromResource(XML_RES, rootKey)
-//
-// mEnableCustom = findPreference<SwitchPreference>(FINGERPRINT_CUSTOM_ICON_ENABLE)
-// mEnableCustom?.let {
-// it.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
-// if (newValue as Boolean) {
-// if (getCustomImagePath().exists()) {
-// enablePickerIcon()
-// }
-// } else {
-// systemUIProxy?.resetUfpsImage()
-// }
-// true
-// }
-// }
-// mFilePicker = findPreference(FINGERPRINT_CUSTOM_ICON_SELECT)
-// mFilePicker?.let {
-// bindSystemUIProxyService()
-//
-// if (getCustomImagePath().exists()) {
-// setPickerIcon()
-// }
-//
-// it.onPreferenceClickListener = Preference.OnPreferenceClickListener {
-// pickImageLegacy.launch("image/*")
-// //pickImage.launch(null)
-// true
-// }
-// }
-// }
-//
-// private fun getCustomImagePath(): File {
-// return File(requireContext().filesDir, UFPSIMAGE_FILE_NAME)
-// }
-//
-// private fun setPickerIcon() {
-// try {
-// val parcelFileDescriptor = requireContext().contentResolver.openFileDescriptor(
-// Uri.fromFile(getCustomImagePath()),
-// "r"
-// )
-// parcelFileDescriptor?.let { it ->
-// val bitmap = BitmapFactory.decodeFileDescriptor(it.fileDescriptor)
-// it.close()
-// val d = BitmapDrawable(resources, bitmap)
-// mFilePicker?.icon = d
-// }
-// } catch (e: Exception) {
-// Log.e(
-// TAG,
-// "setPickerIcon",
-// e
-// )
-// }
-// }
-//
-// private fun enablePickerIcon() {
-// try {
-// val parcelFileDescriptor = requireContext().contentResolver.openFileDescriptor(
-// Uri.fromFile(getCustomImagePath()),
-// "r"
-// )
-// parcelFileDescriptor?.let { it ->
-// val bitmap = BitmapFactory.decodeFileDescriptor(it.fileDescriptor)
-// it.close()
-// systemUIProxy?.setUfpsImageBitmap(bitmap)
-// }
-// } catch (e: Exception) {
-// Log.e(
-// TAG,
-// "setPickerIcon",
-// e
-// )
-// }
-// }
-//
-// private fun savePickerIcon(bitmap: Bitmap) {
-// try {
-// val fos = FileOutputStream(getCustomImagePath())
-// bitmap.compress(Bitmap.CompressFormat.PNG, 90, fos)
-// fos.close()
-// val d = BitmapDrawable(resources, bitmap)
-// mFilePicker?.icon = d
-// } catch (e: Exception) {
-// Log.e(
-// TAG,
-// "savePickerIcon",
-// e
-// )
-// }
-// }
-//
-// private fun deletePickerIcon() {
-// if (getCustomImagePath().exists()) {
-// getCustomImagePath().delete()
-// }
-// }
-//}
\ No newline at end of file
+/*
+ * Copyright (C) 2023 The OmniROM Project
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.omnirom.control
+
+import android.app.Activity
+import android.content.ComponentName
+import android.content.Context
+import android.content.Intent
+import android.content.ServiceConnection
+import android.graphics.Bitmap
+import android.graphics.BitmapFactory
+import android.graphics.drawable.BitmapDrawable
+import android.net.Uri
+import android.os.Bundle
+import android.os.IBinder
+import android.provider.MediaStore
+import android.provider.Settings
+import android.util.Log
+import androidx.activity.result.contract.ActivityResultContract
+import androidx.activity.result.contract.ActivityResultContracts
+import androidx.annotation.DrawableRes
+import androidx.annotation.XmlRes
+import androidx.preference.Preference
+import androidx.preference.SwitchPreference
+import com.android.systemui.shared.omni.IOmniSystemUiProxy
+import org.omnirom.omnilib.utils.OmniSettings
+import java.io.File
+import java.io.FileOutputStream
+import java.io.IOException
+
+
+class FingerprintSettingsFragment : AbstractSettingsFragment() {
+ private val TAG = "FingerprintSettingsFragment"
+ private val FINGERPRINT_CUSTOM_ICON_SELECT = "custom_fingerprint_icon_select"
+ private val FINGERPRINT_CUSTOM_ICON_ENABLE = "custom_fingerprint_icon_enable"
+ private val UFPSIMAGE_FILE_NAME = "ufpsImage"
+
+ companion object {
+ @DrawableRes
+ val ICON_RES = R.drawable.ic_settings_fingerprint
+ @XmlRes
+ val XML_RES = R.xml.fingerprint_preferences
+
+ fun isEnabled(context: Context) : Boolean {
+ return context.resources.getBoolean(R.bool.config_has_udfps)
+ }
+ }
+
+ class PickSinglePhotoContract : ActivityResultContract<Void?, Uri?>() {
+ override fun createIntent(context: Context, input: Void?): Intent {
+ return Intent(Intent(MediaStore.ACTION_PICK_IMAGES)).apply { type = "image/*" }
+ }
+
+ override fun parseResult(resultCode: Int, intent: Intent?): Uri? {
+ return intent.takeIf { resultCode == Activity.RESULT_OK }?.data
+ }
+ }
+
+ var pickImageLegacy = registerForActivityResult<String, Uri>(
+ ActivityResultContracts.GetContent()
+ ) { uri: Uri? ->
+ if (uri != null) {
+ try {
+ requireContext().contentResolver.openInputStream(uri).use { inputStream ->
+ val bitmap = BitmapFactory.decodeStream(inputStream)
+ systemUIProxy?.setUfpsImageBitmap(bitmap)
+ savePickerIcon(bitmap)
+ }
+
+ Settings.System.putString(
+ requireContext().contentResolver,
+ OmniSettings.OMNI_CUSTOM_FP_ICON_UPDATE,
+ System.currentTimeMillis().toString()
+ )
+ } catch (e: Exception) {
+ Log.d(TAG, "pickImage", e);
+ }
+ }
+ }
+
+ private val pickImage =
+ registerForActivityResult(PickSinglePhotoContract()) { uri ->
+ Log.d(TAG, "pickImage uri = " + uri)
+ if (uri != null) {
+ // TODO we should do some check if the image is even a useful one eg size
+ try {
+ requireContext().contentResolver.openInputStream(uri).use { inputStream ->
+ val bitmap = BitmapFactory.decodeStream(inputStream)
+ systemUIProxy?.setUfpsImageBitmap(bitmap)
+ savePickerIcon(bitmap)
+ }
+
+ Settings.System.putString(
+ requireContext().contentResolver,
+ OmniSettings.OMNI_CUSTOM_FP_ICON_UPDATE,
+ System.currentTimeMillis().toString()
+ )
+ } catch (e: Exception) {
+ Log.d(TAG, "pickImage", e);
+ }
+ }
+ }
+
+
+ private val mSystemUIProxyService: ServiceConnection = object : ServiceConnection {
+ override fun onServiceConnected(name: ComponentName, service: IBinder) {
+ Log.d(
+ TAG,
+ "onServiceConnected $name $service"
+ )
+ systemUIProxy = IOmniSystemUiProxy.Stub.asInterface(service)
+ }
+
+ override fun onServiceDisconnected(name: ComponentName) {
+ Log.d(TAG, "onServiceDisconnected $name")
+ }
+ }
+
+ private var mSystemUIProxyBound = false
+ private var systemUIProxy: IOmniSystemUiProxy? = null
+ private var mFilePicker: Preference? = null
+ private var mEnableCustom: SwitchPreference? = null
+
+
+ private fun bindSystemUIProxyService() {
+ if (!mSystemUIProxyBound) {
+ Log.d(TAG, "bindSystemUIProxyService")
+ val serviceIntent = Intent("android.intent.action.OMNI_SYSTEMUI_SERVICE")
+ .setPackage("com.android.systemui")
+ try {
+ mSystemUIProxyBound = requireActivity().bindService(
+ serviceIntent,
+ mSystemUIProxyService,
+ Context.BIND_AUTO_CREATE
+ )
+ } catch (e: SecurityException) {
+ Log.e(
+ TAG,
+ "Unable to bind because of security error",
+ e
+ )
+ }
+ }
+ }
+
+ private fun unbindSystemUIProxyService() {
+ if (mSystemUIProxyBound) {
+ Log.d(TAG, "unbindSystemUIProxyService")
+ requireActivity().unbindService(mSystemUIProxyService)
+ mSystemUIProxyBound = false
+ }
+ }
+
+ override fun getFragmentTitle(): String {
+ return getString(R.string.fprint_title)
+ }
+
+ override fun getFragmentSummary(): String {
+ return getString(R.string.fprint_summary)
+ }
+
+ override fun getFragmentIcon(): Int {
+ return ICON_RES
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ unbindSystemUIProxyService()
+ }
+
+ override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
+ setPreferencesFromResource(XML_RES, rootKey)
+
+ mEnableCustom = findPreference<SwitchPreference>(FINGERPRINT_CUSTOM_ICON_ENABLE)
+ mEnableCustom?.let {
+ it.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
+ if (newValue as Boolean) {
+ if (getCustomImagePath().exists()) {
+ enablePickerIcon()
+ }
+ } else {
+ systemUIProxy?.resetUfpsImage()
+ }
+ true
+ }
+ }
+ mFilePicker = findPreference(FINGERPRINT_CUSTOM_ICON_SELECT)
+ mFilePicker?.let {
+ bindSystemUIProxyService()
+
+ if (getCustomImagePath().exists()) {
+ setPickerIcon()
+ }
+
+ it.onPreferenceClickListener = Preference.OnPreferenceClickListener {
+ pickImageLegacy.launch("image/*")
+ pickImage.launch(null)
+ true
+ }
+ }
+ }
+
+ private fun getCustomImagePath(): File {
+ return File(requireContext().filesDir, UFPSIMAGE_FILE_NAME)
+ }
+
+ private fun setPickerIcon() {
+ try {
+ val parcelFileDescriptor = requireContext().contentResolver.openFileDescriptor(
+ Uri.fromFile(getCustomImagePath()),
+ "r"
+ )
+ parcelFileDescriptor?.let { it ->
+ val bitmap = BitmapFactory.decodeFileDescriptor(it.fileDescriptor)
+ it.close()
+ val d = BitmapDrawable(resources, bitmap)
+ mFilePicker?.icon = d
+ }
+ } catch (e: Exception) {
+ Log.e(
+ TAG,
+ "setPickerIcon",
+ e
+ )
+ }
+ }
+
+ private fun enablePickerIcon() {
+ try {
+ val parcelFileDescriptor = requireContext().contentResolver.openFileDescriptor(
+ Uri.fromFile(getCustomImagePath()),
+ "r"
+ )
+ parcelFileDescriptor?.let { it ->
+ val bitmap = BitmapFactory.decodeFileDescriptor(it.fileDescriptor)
+ it.close()
+ systemUIProxy?.setUfpsImageBitmap(bitmap)
+ }
+ } catch (e: Exception) {
+ Log.e(
+ TAG,
+ "setPickerIcon",
+ e
+ )
+ }
+ }
+
+ private fun savePickerIcon(bitmap: Bitmap) {
+ try {
+ val fos = FileOutputStream(getCustomImagePath())
+ bitmap.compress(Bitmap.CompressFormat.PNG, 90, fos)
+ fos.close()
+ val d = BitmapDrawable(resources, bitmap)
+ mFilePicker?.icon = d
+ } catch (e: Exception) {
+ Log.e(
+ TAG,
+ "savePickerIcon",
+ e
+ )
+ }
+ }
+
+ private fun deletePickerIcon() {
+ if (getCustomImagePath().exists()) {
+ getCustomImagePath().delete()
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/org/omnirom/control/GridViewFragment.kt b/app/src/main/java/org/omnirom/control/GridViewFragment.kt
index 0e633e4..aa05401 100644
--- a/app/src/main/java/org/omnirom/control/GridViewFragment.kt
+++ b/app/src/main/java/org/omnirom/control/GridViewFragment.kt
@@ -131,16 +131,16 @@
)
)
}
-// if (resources.getBoolean(R.bool.config_has_udfps)) {
-// gridItems.add(
-// FragmentGridItem(
-// R.string.fprint_title,
-// R.string.fprint_summary,
-// R.drawable.ic_settings_fingerprint,
-// FingerprintSettingsFragment()
-// )
-// )
-// }
+ if (resources.getBoolean(R.bool.config_has_udfps)) {
+ gridItems.add(
+ FragmentGridItem(
+ R.string.fprint_title,
+ R.string.fprint_summary,
+ R.drawable.ic_settings_fingerprint,
+ FingerprintSettingsFragment()
+ )
+ )
+ }
gridItems.add(
FragmentGridItem(
R.string.lockscreen_item_title,
diff --git a/app/src/main/java/org/omnirom/control/search/SearchProvider.kt b/app/src/main/java/org/omnirom/control/search/SearchProvider.kt
index 9fd3ad8..76a8583 100644
--- a/app/src/main/java/org/omnirom/control/search/SearchProvider.kt
+++ b/app/src/main/java/org/omnirom/control/search/SearchProvider.kt
@@ -26,7 +26,7 @@
import org.omnirom.control.BatteryLightSettingsFragment
import org.omnirom.control.ButtonSettingsFragment
import org.omnirom.control.DialerSettingsFragment
-//import org.omnirom.control.FingerprintSettingsFragment
+import org.omnirom.control.FingerprintSettingsFragment
import org.omnirom.control.LockscreenSettingsFragment
import org.omnirom.control.MoreSettingsFragment
//import org.omnirom.control.QSSettingsFragment
@@ -96,15 +96,15 @@
// this::isEnabled
// )
// )
-//
-// searchItemList.add(
-// SearchItem(
-// FingerprintSettingsFragment.XML_RES,
-// FingerprintSettingsFragment().javaClass.canonicalName,
-// FingerprintSettingsFragment.ICON_RES,
-// FingerprintSettingsFragment::isEnabled
-// )
-// )
+
+ searchItemList.add(
+ SearchItem(
+ FingerprintSettingsFragment.XML_RES,
+ FingerprintSettingsFragment().javaClass.canonicalName,
+ FingerprintSettingsFragment.ICON_RES,
+ FingerprintSettingsFragment::isEnabled
+ )
+ )
searchItemList.add(
SearchItem(