Migrate FINGERPRINT_WAKE_UNLOCK to the new AOSP setting

Change-Id: If5ad35077cfa4fb222928e97db4d50b68a0567c3
diff --git a/packages/LineageSettingsProvider/src/org/lineageos/lineagesettings/LineageDatabaseHelper.java b/packages/LineageSettingsProvider/src/org/lineageos/lineagesettings/LineageDatabaseHelper.java
index 52d97a9..f728489 100644
--- a/packages/LineageSettingsProvider/src/org/lineageos/lineagesettings/LineageDatabaseHelper.java
+++ b/packages/LineageSettingsProvider/src/org/lineageos/lineagesettings/LineageDatabaseHelper.java
@@ -60,7 +60,7 @@
     private static final boolean LOCAL_LOGV = false;
 
     private static final String DATABASE_NAME = "lineagesettings.db";
-    private static final int DATABASE_VERSION = 17;
+    private static final int DATABASE_VERSION = 18;
 
     private static final String DATABASE_NAME_OLD = "cmsettings.db";
 
@@ -428,6 +428,35 @@
             }, true);
             upgradeVersion = 17;
         }
+
+        if (upgradeVersion < 18) {
+            // Default config_requireScreenOnToAuthEnabled value is false
+            Integer oldSetting = 0;
+            db.beginTransaction();
+            SQLiteStatement stmt = null;
+            try {
+                stmt = db.compileStatement("SELECT value FROM system WHERE name=?");
+                // Used to be LineageSettings.System.FINGERPRINT_WAKE_UNLOCK
+                stmt.bindString(1, "fingerprint_wake_unlock");
+                oldSetting = Integer.parseInt(stmt.simpleQueryForString());
+
+                // Reverse 0/1 values, leave 2 as-is
+                if (oldSetting.equals(0)) {
+                    oldSetting = 1;
+                } else if (oldSetting.equals(1)) {
+                    oldSetting = 0;
+                }
+            } catch (SQLiteDoneException ex) {
+                // LineageSettings.System.FINGERPRINT_WAKE_UNLOCK is not set
+            } finally {
+                if (stmt != null) stmt.close();
+                db.endTransaction();
+            }
+            Settings.Secure.putInt(mContext.getContentResolver(),
+                    Settings.Secure.SFPS_REQUIRE_SCREEN_ON_TO_AUTH_ENABLED,
+                    oldSetting);
+            upgradeVersion = 18;
+        }
         // *** Remember to update DATABASE_VERSION above!
         if (upgradeVersion != newVersion) {
             Log.wtf(TAG, "warning: upgrading settings database to version "
diff --git a/sdk/src/java/lineageos/providers/LineageSettings.java b/sdk/src/java/lineageos/providers/LineageSettings.java
index 3761291..d8612b5 100644
--- a/sdk/src/java/lineageos/providers/LineageSettings.java
+++ b/sdk/src/java/lineageos/providers/LineageSettings.java
@@ -2037,15 +2037,6 @@
                 sBooleanValidator;
 
         /**
-         * Whether to enable fingerprint wake-and-unlock.
-         */
-        public static final String FINGERPRINT_WAKE_UNLOCK = "fingerprint_wake_unlock";
-
-        /** @hide */
-        public static final Validator FINGERPRINT_WAKE_UNLOCK_VALIDATOR =
-                sNonNegativeIntegerValidator;
-
-        /**
          * I can haz more bukkits
          * @hide
          */
@@ -2309,8 +2300,6 @@
                     CLICK_PARTIAL_SCREENSHOT_VALIDATOR);
             VALIDATORS.put(ENABLE_TASKBAR,
                     ENABLE_TASKBAR_VALIDATOR);
-            VALIDATORS.put(FINGERPRINT_WAKE_UNLOCK,
-                    FINGERPRINT_WAKE_UNLOCK_VALIDATOR);
             VALIDATORS.put(__MAGICAL_TEST_PASSING_ENABLER,
                     __MAGICAL_TEST_PASSING_ENABLER_VALIDATOR);
         };