Skip to content

Commit

Permalink
feat: Sync with September source of crDroid
Browse files Browse the repository at this point in the history
* Synced with latest td source

Signed-off-by: naz664 <[email protected]>
  • Loading branch information
naz664 committed Sep 22, 2023
1 parent b8f83d0 commit 6931557
Showing 1 changed file with 210 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
From 9f920fdd797fb340fbd1b43647f0d119816d3779 Mon Sep 17 00:00:00 2001
From: jgudec <[email protected]>
Date: Fri, 18 Aug 2023 08:41:49 +0100
Subject: [PATCH] Add initial Xiaomi FOD implementation for recent Xiaomi
devices

Huge thanks to phhusson for the help and guidance.
---
packages/SystemUI/Android.bp | 2 +
.../android/systemui/biometrics/UdfpsView.kt | 43 +++++++++++++++++
services/core/Android.bp | 1 +
.../server/biometrics/AuthService.java | 47 +++++++++++++++++++
4 files changed, 93 insertions(+)

diff --git a/packages/SystemUI/Android.bp b/packages/SystemUI/Android.bp
index 8411fbb45d9c..ed21a95c41ee 100644
--- a/packages/SystemUI/Android.bp
+++ b/packages/SystemUI/Android.bp
@@ -178,6 +178,8 @@ android_library {
"LowLightDreamLib",
"motion_tool_lib",
"vendor.goodix.hardware.biometrics.fingerprint-V2.1-java",
+ "vendor.xiaomi.hw.touchfeature-V1.0-java",
+ "vendor.xiaomi.hardware.fingerprintextension-V1.0-java",
"vendor.lineage.powershare-V1.0-java",
"faceunlock_framework",
],
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsView.kt b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsView.kt
index d9ce84c38833..61b2fc21b400 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsView.kt
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsView.kt
@@ -38,6 +38,12 @@ import java.io.File

import vendor.goodix.hardware.biometrics.fingerprint.V2_1.IGoodixFingerprintDaemon

+import vendor.xiaomi.hw.touchfeature.V1_0.ITouchFeature
+import vendor.xiaomi.hardware.fingerprintextension.V1_0.IXiaomiFingerprint
+
+import android.os.Handler
+import android.os.HandlerThread
+
private const val TAG = "UdfpsView"

/**
@@ -227,6 +233,12 @@ Log.d("PHH", "Surface destroyed!")
val hasSamsungMask = File(samsungActualMaskBrightness).exists()
var fodFileObserver: FileObserver? = null

+ val xiaomiDispParam = "/sys/class/mi_display/disp-DSI-0/disp_param"
+ var hasXiaomiLhbm = File(xiaomiDispParam).exists()
+
+ private val handlerThread = HandlerThread("UDFPS").also { it.start() }
+ val myHandler = Handler(handlerThread.looper)
+
fun configureDisplay(onDisplayConfigured: Runnable) {
isDisplayConfigured = true
animationViewController?.onDisplayConfiguring()
@@ -269,6 +281,34 @@ Log.d("PHH", "Surface destroyed!")
if(android.os.SystemProperties.get("ro.vendor.build.fingerprint").contains("ASUS")) {
goodixCmd(200001)
}
+
+ if(hasXiaomiLhbm){
+ Log.d("PHH-Enroll", "Xiaomi scenario in UdfpsView reached!")
+ mySurfaceView.setVisibility(INVISIBLE)
+
+ IXiaomiFingerprint.getService().extCmd(android.os.SystemProperties.getInt("persist.phh.xiaomi.fod.enrollment.id", 4), 1);
+ var res = ITouchFeature.getService().setTouchMode(0, 10, 1);
+ if(res != 0){
+ Log.d("PHH-Enroll", "SetTouchMode 10,1 was NOT executed successfully. Res is " + res)
+ }
+
+ myHandler.postDelayed({
+ var ret200 = ITouchFeature.getService().setTouchMode(0, 10, 1);
+
+ if(ret200 != 0){
+ Log.d("PHH-Enroll", "myHandler.postDelayed 200ms -SetTouchMode was NOT executed successfully. Ret is " + ret200)
+ }
+
+ myHandler.postDelayed({
+ Log.d("PHH-Enroll", "myHandler.postDelayed 600ms - line prior to setTouchMode 10,0")
+ var ret600 = ITouchFeature.getService().setTouchMode(0, 10, 0);
+
+ if(ret600 != 0){
+ Log.d("PHH-Enroll", "myHandler.postDelayed 600ms -SetTouchMode 10,0 was NOT executed successfully. Ret is " + ret600)
+ }
+ }, 600)
+ }, 200)
+ }
}

private fun doIlluminate(surface: Surface?, onDisplayConfigured: Runnable?) {
@@ -325,6 +365,9 @@ Log.d("PHH", "Surface destroyed!")
}
};
fodFileObserver?.startWatching();
+ } else if(hasXiaomiLhbm) {
+ IXiaomiFingerprint.getService().extCmd(android.os.SystemProperties.getInt("persist.phh.xiaomi.fod.enrollment.id", 4), 0);
+ ITouchFeature.getService().setTouchMode(0, 10, 0);
} else {
dimUpdate(0.0f)
}
diff --git a/services/core/Android.bp b/services/core/Android.bp
index 75b7c4148de6..60ef9a212919 100644
--- a/services/core/Android.bp
+++ b/services/core/Android.bp
@@ -184,6 +184,7 @@ java_library_static {
"vendor.samsung.hardware.biometrics.fingerprint-V3.0-java",
"vendor.oplus.hardware.biometrics.fingerprint-V2.1-java",
"vendor.oppo.hardware.biometrics.fingerprint-V2.1-java",
+ "vendor.xiaomi.hardware.fingerprintextension-V1.0-java",
"kotlin-stdlib",
"kotlinx_coroutines_android",
"kotlinx_coroutines",
diff --git a/services/core/java/com/android/server/biometrics/AuthService.java b/services/core/java/com/android/server/biometrics/AuthService.java
index e1aa633205fb..6048eded0121 100644
--- a/services/core/java/com/android/server/biometrics/AuthService.java
+++ b/services/core/java/com/android/server/biometrics/AuthService.java
@@ -66,6 +66,7 @@ import android.os.ServiceManager;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.provider.Settings;
+import android.text.TextUtils;
import android.util.Slog;

import com.android.internal.R;
@@ -93,6 +94,8 @@ import vendor.samsung.hardware.biometrics.fingerprint.V3_0.ISehBiometricsFingerp
import vendor.goodix.hardware.biometrics.fingerprint.V2_1.IGoodixFingerprintDaemon;
import vendor.samsung.hardware.sysinput.V1_0.ISehSysInputDev;

+import vendor.xiaomi.hardware.fingerprintextension.V1_0.IXiaomiFingerprint;
+
/**
* System service that provides an interface for authenticating with biometrics and
* PIN/pattern/password to BiometricPrompt and lock screen.
@@ -114,6 +117,8 @@ public class AuthService extends SystemService {
private FileObserver fodFileObserver = null;
private ISehBiometricsFingerprint mSamsungFingerprint = null;

+ private IXiaomiFingerprint mXiaomiFingerprint = null;
+
/**
* Class for injecting dependencies into AuthService.
* TODO(b/141025588): Replace with a dependency injection framework (e.g. Guice, Dagger).
@@ -677,6 +682,12 @@ public class AuthService extends SystemService {
} catch(Exception e) {
android.util.Log.e("PHH", "Failed getting Samsung fingerprint HAL", e);
}
+ try {
+ mXiaomiFingerprint = IXiaomiFingerprint.getService();
+ android.util.Log.e("PHH", "Got xiaomi fingerprint HAL");
+ } catch(Exception e) {
+ android.util.Log.e("PHH", "Failed getting xiaomi fingerprint HAL", e);
+ }
if(samsungHasCmd("fod_enable") && mSamsungFingerprint != null) {
samsungCmd("fod_enable,1,1,0");
String actualMaskBrightnessPath = "/sys/class/lcd/panel/actual_mask_brightness";
@@ -737,6 +748,30 @@ public class AuthService extends SystemService {
fodFileObserver.startWatching();
}

+ String xiaomiFodPressedStatusPath = "/sys/class/touch/touch_dev/fod_press_status";
+ if(new File(xiaomiFodPressedStatusPath).exists() && mXiaomiFingerprint != null) {
+ fodFileObserver = new FileObserver(xiaomiFodPressedStatusPath, FileObserver.MODIFY) {
+ @Override
+ public void onEvent(int event, String path) {
+ String isFodPressed = readFile(xiaomiFodPressedStatusPath);
+ Slog.d("PHH-Enroll", "Fod pressed status: " + isFodPressed);
+ Slog.d("PHH-Enroll", "Within xiaomi scenario for FOD");
+
+ try {
+ if("0".equals(isFodPressed)) {
+ Slog.d("PHH-Enroll", "Fod un-pressed!");
+ mXiaomiFingerprint.extCmd(android.os.SystemProperties.getInt("phh.xiaomi.fod.enrollment.id", 4), 0);
+ } else if("1".equals(isFodPressed)) {
+ Slog.d("PHH-Enroll", "Fod pressed!");
+ mXiaomiFingerprint.extCmd(android.os.SystemProperties.getInt("phh.xiaomi.fod.enrollment.id", 4), 1);
+ }
+ } catch(Exception e) {
+ Slog.d("PHH-Enroll", "Failed Xiaomi async extcmd", e);
+ }
+ }
+ };
+ fodFileObserver.startWatching();
+ }
}

/**
@@ -938,6 +973,18 @@ public class AuthService extends SystemService {
return udfpsProps;
}

+ if(!TextUtils.isEmpty(android.os.SystemProperties.get("persist.vendor.sys.fp.fod.location.X_Y"))) {
+ int[] udfpsProps = new int[3];
+ String[] coordinates = android.os.SystemProperties.get("persist.vendor.sys.fp.fod.location.X_Y").split(",");
+ udfpsProps[0] = displayRealSize.x/2;
+ udfpsProps[1] = Integer.parseInt(coordinates[1]) + 100;
+
+ String[] widthHeight = android.os.SystemProperties.get("persist.vendor.sys.fp.fod.size.width_height").split(",");
+
+ udfpsProps[2] = (Integer.parseInt(widthHeight[0]) /2);
+ return udfpsProps;
+ }
+
return new int[0];
}

--
2.34.1

0 comments on commit 6931557

Please sign in to comment.