PPU: Make CTS/Play Integrity pass again (again and again and again)

[someone5678] Adapt to this project

Co-authored-by: Dyneteve <dyneteve@hentaios.com>
Change-Id: If3a865849c7c99a9c7080114ba94a8f8878bb4f2
Signed-off-by: someone5678 <someone5678@users.noreply.github.com>
Signed-off-by: Dmitrii <bankersenator@gmail.com>
Signed-off-by: Jis G Jacob <studiokeys@blissroms.org>
diff --git a/core/java/com/android/internal/util/bliss/PixelPropsUtils.java b/core/java/com/android/internal/util/bliss/PixelPropsUtils.java
index d9b28c0..e35aa32 100644
--- a/core/java/com/android/internal/util/bliss/PixelPropsUtils.java
+++ b/core/java/com/android/internal/util/bliss/PixelPropsUtils.java
@@ -19,18 +19,22 @@
 
 package com.android.internal.util.bliss;
 
-
 import android.app.Application;
 import android.os.Build;
+import android.content.res.Resources;
 import android.os.SystemProperties;
 import android.util.Log;
 
+import com.android.internal.R;
+
 import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
 
 public class PixelPropsUtils {
 
@@ -38,6 +42,9 @@
     private static final String DEVICE = "ro.product.device";
     private static final boolean DEBUG = false;
 
+    private static final String[] sCertifiedProps =
+            Resources.getSystem().getStringArray(R.array.config_certifiedBuildProperties);
+
     private static final Map<String, Object> propsToChangeGeneric;
     private static final Map<String, Object> propsToChangePixel5;
     private static final Map<String, Object> propsToChangePixel7Pro;
@@ -224,6 +231,24 @@
         propsToChangeF5.put("MANUFACTURER", "Xiaomi");
     }
 
+    private static String getBuildID(String fingerprint) {
+        Pattern pattern = Pattern.compile("([A-Za-z0-9]+\\.\\d+\\.\\d+\\.\\w+)");
+        Matcher matcher = pattern.matcher(fingerprint);
+
+        if (matcher.find()) {
+            return matcher.group(1);
+        }
+        return "";
+    }
+
+    private static String getDeviceName(String fingerprint) {
+        String[] parts = fingerprint.split("/");
+        if (parts.length >= 2) {
+            return parts[1];
+        }
+        return "";
+    }
+
     public static void setProps(String packageName) {
         propsToChangeGeneric.forEach((k, v) -> setPropValue(k, v));
 
@@ -383,14 +408,17 @@
     }
 
     private static void spoofBuildGms() {
+        if (sCertifiedProps == null || sCertifiedProps.length == 0) return;
         // Alter build parameters to avoid hardware attestation enforcement
-        setPropValue("BRAND", "NVIDIA");
-        setPropValue("MANUFACTURER", "NVIDIA");
-        setPropValue("DEVICE", "foster");
-        setPropValue("FINGERPRINT", "NVIDIA/foster_e/foster:7.0/NRD90M/2427173_1038.2788:user/release-keys");
-        setPropValue("MODEL", "SHIELD Android TV");
-        setPropValue("PRODUCT", "foster_e");
-        setVersionFieldString("SECURITY_PATCH", "2018-01-05");
+        setPropValue("BRAND", sCertifiedProps[0]);
+        setPropValue("MANUFACTURER", sCertifiedProps[1]);
+        setPropValue("ID", sCertifiedProps[2].isEmpty() ? getBuildID(sCertifiedProps[6]) : sCertifiedProps[2]);
+        setPropValue("DEVICE", sCertifiedProps[3].isEmpty() ? getDeviceName(sCertifiedProps[6]) : sCertifiedProps[3]);
+        setPropValue("PRODUCT", sCertifiedProps[4].isEmpty() ? getDeviceName(sCertifiedProps[6]) : sCertifiedProps[4]);
+        setPropValue("MODEL", sCertifiedProps[5]);
+        setPropValue("FINGERPRINT", sCertifiedProps[6]);
+        setPropValue("TYPE", sCertifiedProps[7].isEmpty() ? "user" : sCertifiedProps[7]);
+        setPropValue("TAGS", sCertifiedProps[8].isEmpty() ? "release-keys" : sCertifiedProps[8]);
     }
 
     private static boolean isCallerSafetyNet() {
diff --git a/core/res/res/values/bliss_arrays.xml b/core/res/res/values/bliss_arrays.xml
index a6a4e0a..09d1892 100644
--- a/core/res/res/values/bliss_arrays.xml
+++ b/core/res/res/values/bliss_arrays.xml
@@ -90,4 +90,20 @@
     <string-array name="notification_light_package_mapping" translatable="false">
         <item>com.google.android.gsf|com.google.android.talk</item>
     </string-array>
+
+    <!-- Build properties from a GMS certified device -->
+    <string-array name="config_certifiedBuildProperties" translatable="false">
+      <!--
+        <item>Build.BRAND</item>
+        <item>Build.MANUFACTURER</item>
+        <item>Build.ID</item>
+        <item>Build.DEVICE</item>
+        <item>Build.PRODUCT</item>
+        <item>Build.MODEL</item>
+        <item>Build.FINGERPRINT</item>
+        <item>Build.TYPE</item>
+        <item>Build.TAGS</item>
+      -->
+    </string-array>
+
 </resources>
diff --git a/core/res/res/values/bliss_config.xml b/core/res/res/values/bliss_config.xml
index e4cfe0d..b30a871 100644
--- a/core/res/res/values/bliss_config.xml
+++ b/core/res/res/values/bliss_config.xml
@@ -19,14 +19,6 @@
     <!-- Build fingerprint from the stock ROM -->
     <string name="config_stockFingerprint" translatable="false"></string>
 
-    <!-- Build properties from a GMS certified device against current platform SPL level -->
-    <string-array name="config_certifiedBuildProperties" translatable="false">
-        <item>marlin</item>   <!-- Build.DEVICE -->
-        <item>marlin</item>   <!-- Build.PRODUCT -->
-        <item>Pixel XL</item> <!-- Build.MODEL -->
-        <item>google/marlin/marlin:7.1.2/NJH47F/4146041:user/release-keys</item> <!-- Build.FINGERPRINT -->
-    </string-array>
-
     <!-- The list of package IDs that are allowed to use aux cameras.
          NOTE: If this list is empty then all apps will be able to use aux cameras. -->
     <string-array name="config_cameraAuxPackageAllowList" translatable="false" />
diff --git a/core/res/res/values/bliss_symbols.xml b/core/res/res/values/bliss_symbols.xml
index 45297e9..53d0ed2 100644
--- a/core/res/res/values/bliss_symbols.xml
+++ b/core/res/res/values/bliss_symbols.xml
@@ -167,4 +167,7 @@
     <!-- Lock gesture -->
     <java-symbol type="string" name="gesture_locked_warning" />
 
+    <!-- Build properties from a GMS certified device -->
+    <java-symbol type="array" name="config_certifiedBuildProperties" />
+
 </resources>