Add fingerprint settings.

- Improved layout.
- Enrollment is now working.
- Added vibration and progress feedback.
- Better fingerprint animation logic.
- Poke userActivity() when sensor is touched.
- Added progress animation.
- Only show fingerprint menu item on devices that have fingerprint hw
- Set View state to GONE for views that aren't shown & fix resulting layout issue
- Fix bug where stage wasn't advancing when returning from ChooseLockGeneric.
- Renamed FingerprintSettings to FingerprintEnroll
- Fixed bug with storing fingerprint ids that prevented the last one from being removed.
- Added better progress indication.  When remaining is at max, count that as the first step.
- Fix whitespace formatting in CL

Fixes bug 1953439

Change-Id: I721bf440c63640203af94ce21340d8281076c249
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index e809bb5..95826e4 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -41,6 +41,8 @@
 import android.provider.Settings;
 import android.provider.Settings.SettingNotFoundException;
 import android.security.KeyStore;
+import android.service.fingerprint.FingerprintManager;
+import android.service.fingerprint.FingerprintManager.FingerprintItem;
 import android.service.trust.TrustAgentService;
 import android.telephony.TelephonyManager;
 import android.telephony.SubscriptionManager;
@@ -220,32 +222,12 @@
             }
         }
 
-        // Trust Agent preferences
+        // Fingerprint and trust agents
         PreferenceGroup securityCategory = (PreferenceGroup)
                 root.findPreference(KEY_SECURITY_CATEGORY);
         if (securityCategory != null) {
-            final boolean hasSecurity = mLockPatternUtils.isSecure();
-            ArrayList<TrustAgentComponentInfo> agents =
-                    getActiveTrustAgents(getPackageManager(), mLockPatternUtils);
-            for (int i = 0; i < agents.size(); i++) {
-                final TrustAgentComponentInfo agent = agents.get(i);
-                Preference trustAgentPreference =
-                        new Preference(securityCategory.getContext());
-                trustAgentPreference.setKey(KEY_TRUST_AGENT);
-                trustAgentPreference.setTitle(agent.title);
-                trustAgentPreference.setSummary(agent.summary);
-                // Create intent for this preference.
-                Intent intent = new Intent();
-                intent.setComponent(agent.componentName);
-                intent.setAction(Intent.ACTION_MAIN);
-                trustAgentPreference.setIntent(intent);
-                // Add preference to the settings menu.
-                securityCategory.addPreference(trustAgentPreference);
-                if (!hasSecurity) {
-                    trustAgentPreference.setEnabled(false);
-                    trustAgentPreference.setSummary(R.string.disabled_because_no_backup_security);
-                }
-            }
+            maybeAddFingerprintPreference(securityCategory);
+            addTrustAgentSettings(securityCategory);
         }
 
         // lock after preference
@@ -347,6 +329,58 @@
         return root;
     }
 
+    private void maybeAddFingerprintPreference(PreferenceGroup securityCategory) {
+        FingerprintManager fpm = (FingerprintManager) getActivity().getSystemService(
+                Context.FINGERPRINT_SERVICE);
+        if (!fpm.isHardwareDetected()) {
+            Log.v(TAG, "No fingerprint hardware detected!!");
+            return;
+        }
+        Preference fingerprintPreference = new Preference(securityCategory.getContext());
+        fingerprintPreference.setKey(KEY_TRUST_AGENT);
+        fingerprintPreference.setTitle(R.string.security_settings_fingerprint_preference_title);
+        Intent intent = new Intent();
+        List<FingerprintItem> items = fpm.getEnrolledFingerprints();
+        int fingerprintCount = items.size();
+        if (fingerprintCount > 0) {
+            fingerprintPreference.setSummary(getResources().getQuantityString(
+                    R.plurals.security_settings_fingerprint_preference_summary,
+                    fingerprintCount, fingerprintCount));
+            // TODO: Launch fingerprintSettings instead...
+            intent.setClassName("com.android.settings", FingerprintEnroll.class.getName());
+        } else {
+            // No fingerprints registered, launch directly into fingerprint enrollment wizard
+            intent.setClassName("com.android.settings", FingerprintEnroll.class.getName());
+        }
+        fingerprintPreference.setIntent(intent);
+        securityCategory.addPreference(fingerprintPreference);
+    }
+
+    private void addTrustAgentSettings(PreferenceGroup securityCategory) {
+        final boolean hasSecurity = mLockPatternUtils.isSecure();
+        ArrayList<TrustAgentComponentInfo> agents =
+                getActiveTrustAgents(getPackageManager(), mLockPatternUtils);
+        for (int i = 0; i < agents.size(); i++) {
+            final TrustAgentComponentInfo agent = agents.get(i);
+            Preference trustAgentPreference =
+                    new Preference(securityCategory.getContext());
+            trustAgentPreference.setKey(KEY_TRUST_AGENT);
+            trustAgentPreference.setTitle(agent.title);
+            trustAgentPreference.setSummary(agent.summary);
+            // Create intent for this preference.
+            Intent intent = new Intent();
+            intent.setComponent(agent.componentName);
+            intent.setAction(Intent.ACTION_MAIN);
+            trustAgentPreference.setIntent(intent);
+            // Add preference to the settings menu.
+            securityCategory.addPreference(trustAgentPreference);
+            if (!hasSecurity) {
+                trustAgentPreference.setEnabled(false);
+                trustAgentPreference.setSummary(R.string.disabled_because_no_backup_security);
+            }
+        }
+    }
+
     /* Return true if a there is a Slot that has Icc.
      */
     private boolean isSimIccReady() {