Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1e50792d authored by Kevin Chyn's avatar Kevin Chyn
Browse files

Check PackageManager for feature before getting system service

Fixes: 130756217

Test: See comment #3 in the bug above
Change-Id: I0008f2b2958c9ac0df4e1f8ce4f5edcd9aac4292
parent 0a510f8b
Loading
Loading
Loading
Loading
+13 −4
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package android.security.keystore;
package android.security.keystore;


import android.content.pm.PackageManager;
import android.hardware.face.FaceManager;
import android.hardware.face.FaceManager;
import android.hardware.fingerprint.FingerprintManager;
import android.hardware.fingerprint.FingerprintManager;
import android.security.GateKeeper;
import android.security.GateKeeper;
@@ -122,12 +123,20 @@ public abstract class KeymasterUtils {
        }
        }


        if (spec.getUserAuthenticationValidityDurationSeconds() == -1) {
        if (spec.getUserAuthenticationValidityDurationSeconds() == -1) {
            PackageManager pm = KeyStore.getApplicationContext().getPackageManager();
            // Every use of this key needs to be authorized by the user. This currently means
            // Every use of this key needs to be authorized by the user. This currently means
            // fingerprint or face auth.
            // fingerprint or face auth.
            FingerprintManager fingerprintManager =
            FingerprintManager fingerprintManager = null;
                    KeyStore.getApplicationContext().getSystemService(FingerprintManager.class);
            FaceManager faceManager = null;
            FaceManager faceManager =

                    KeyStore.getApplicationContext().getSystemService(FaceManager.class);
            if (pm.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)) {
                fingerprintManager = KeyStore.getApplicationContext()
                        .getSystemService(FingerprintManager.class);
            }
            if (pm.hasSystemFeature(PackageManager.FEATURE_FACE)) {
                faceManager = KeyStore.getApplicationContext().getSystemService(FaceManager.class);
            }

            // TODO: Restore USE_FINGERPRINT permission check in
            // TODO: Restore USE_FINGERPRINT permission check in
            // FingerprintManager.getAuthenticatorId once the ID is no longer needed here.
            // FingerprintManager.getAuthenticatorId once the ID is no longer needed here.
            final long fingerprintOnlySid =
            final long fingerprintOnlySid =