Add log to capture the hardware status.

Sometimes Settings Search show the items that are not supported by
the hardware. e.g. FaceLock.
Add log to check the HW status when the problem occurred.

Bug: 156667203
Test: watch the log output.
Change-Id: Ie6a89f338aac6f7bdefc69fc84cfa5bf848ed015
This commit is contained in:
Stanley Wang
2020-06-18 16:19:26 +08:00
parent 6217af3fe1
commit f7e6c1e4c5
9 changed files with 40 additions and 22 deletions

View File

@@ -95,9 +95,20 @@ public class FaceSettings extends DashboardFragment {
private final FaceSettingsEnrollButtonPreferenceController.Listener mEnrollListener = intent -> private final FaceSettingsEnrollButtonPreferenceController.Listener mEnrollListener = intent ->
startActivityForResult(intent, ENROLL_REQUEST); startActivityForResult(intent, ENROLL_REQUEST);
public static boolean isAvailable(Context context) { /**
* @param context
* @return true if the Face hardware is detected.
*/
public static boolean isFaceHardwareDetected(Context context) {
FaceManager manager = Utils.getFaceManagerOrNull(context); FaceManager manager = Utils.getFaceManagerOrNull(context);
return manager != null && manager.isHardwareDetected(); boolean isHardwareDetected = false;
if (manager == null) {
Log.d(TAG, "FaceManager is null");
} else {
isHardwareDetected = manager.isHardwareDetected();
Log.d(TAG, "FaceManager is not null. Hardware detected: " + isHardwareDetected);
}
return manager != null && isHardwareDetected;
} }
@Override @Override
@@ -126,7 +137,7 @@ public class FaceSettings extends DashboardFragment {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
final Context context = getPrefContext(); final Context context = getPrefContext();
if (!isAvailable(context)) { if (!isFaceHardwareDetected(context)) {
Log.w(TAG, "no faceManager, finish this"); Log.w(TAG, "no faceManager, finish this");
finish(); finish();
return; return;
@@ -273,7 +284,7 @@ public class FaceSettings extends DashboardFragment {
@Override @Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
if (!isAvailable(context)) { if (!isFaceHardwareDetected(context)) {
return null; return null;
} }
mControllers = buildPreferenceControllers(context, getSettingsLifecycle()); mControllers = buildPreferenceControllers(context, getSettingsLifecycle());
@@ -314,7 +325,7 @@ public class FaceSettings extends DashboardFragment {
@Override @Override
public List<AbstractPreferenceController> createPreferenceControllers( public List<AbstractPreferenceController> createPreferenceControllers(
Context context) { Context context) {
if (isAvailable(context)) { if (isFaceHardwareDetected(context)) {
return buildPreferenceControllers(context, null /* lifecycle */); return buildPreferenceControllers(context, null /* lifecycle */);
} else { } else {
return null; return null;
@@ -323,7 +334,7 @@ public class FaceSettings extends DashboardFragment {
@Override @Override
protected boolean isPageSearchEnabled(Context context) { protected boolean isPageSearchEnabled(Context context) {
if (isAvailable(context)) { if (isFaceHardwareDetected(context)) {
return hasEnrolledBiometrics(context); return hasEnrolledBiometrics(context);
} }
@@ -333,7 +344,10 @@ public class FaceSettings extends DashboardFragment {
@Override @Override
public List<String> getNonIndexableKeys(Context context) { public List<String> getNonIndexableKeys(Context context) {
final List<String> keys = super.getNonIndexableKeys(context); final List<String> keys = super.getNonIndexableKeys(context);
if (isAvailable(context)) { final boolean isFaceHardwareDetected = isFaceHardwareDetected(context);
Log.d(TAG, "Get non indexable keys. isFaceHardwareDetected: "
+ isFaceHardwareDetected + ", size:" + keys.size());
if (isFaceHardwareDetected) {
final boolean hasEnrolled = hasEnrolledBiometrics(context); final boolean hasEnrolled = hasEnrolledBiometrics(context);
keys.add(hasEnrolled ? PREF_KEY_ENROLL_FACE_UNLOCK keys.add(hasEnrolled ? PREF_KEY_ENROLL_FACE_UNLOCK
: PREF_KEY_DELETE_FACE_DATA); : PREF_KEY_DELETE_FACE_DATA);

View File

@@ -22,10 +22,10 @@ import android.content.Context;
import android.hardware.face.FaceManager; import android.hardware.face.FaceManager;
import android.provider.Settings; import android.provider.Settings;
import com.android.settings.Utils;
import androidx.preference.Preference; import androidx.preference.Preference;
import com.android.settings.Utils;
/** /**
* Preference controller for Face settings page controlling the ability to use * Preference controller for Face settings page controlling the ability to use
* Face authentication in apps (through BiometricPrompt). * Face authentication in apps (through BiometricPrompt).
@@ -51,7 +51,7 @@ public class FaceSettingsAppPreferenceController extends FaceSettingsPreferenceC
@Override @Override
public boolean isChecked() { public boolean isChecked() {
if (!FaceSettings.isAvailable(mContext)) { if (!FaceSettings.isFaceHardwareDetected(mContext)) {
return false; return false;
} }
return Settings.Secure.getIntForUser( return Settings.Secure.getIntForUser(
@@ -67,7 +67,7 @@ public class FaceSettingsAppPreferenceController extends FaceSettingsPreferenceC
@Override @Override
public void updateState(Preference preference) { public void updateState(Preference preference) {
super.updateState(preference); super.updateState(preference);
if (!FaceSettings.isAvailable(mContext)) { if (!FaceSettings.isFaceHardwareDetected(mContext)) {
preference.setEnabled(false); preference.setEnabled(false);
} else if (!mFaceManager.hasEnrolledTemplates(getUserId())) { } else if (!mFaceManager.hasEnrolledTemplates(getUserId())) {
preference.setEnabled(false); preference.setEnabled(false);

View File

@@ -93,7 +93,7 @@ public class FaceSettingsAttentionPreferenceController extends FaceSettingsPrefe
@Override @Override
public boolean isChecked() { public boolean isChecked() {
if (!FaceSettings.isAvailable(mContext)) { if (!FaceSettings.isFaceHardwareDetected(mContext)) {
return true; return true;
} }
// Set to disabled until we know the true value. // Set to disabled until we know the true value.

View File

@@ -25,7 +25,6 @@ import android.provider.Settings;
import androidx.preference.Preference; import androidx.preference.Preference;
import com.android.settings.Utils; import com.android.settings.Utils;
import com.android.settings.core.TogglePreferenceController;
/** /**
* Preference controller giving the user an option to always require confirmation. * Preference controller giving the user an option to always require confirmation.
@@ -65,7 +64,7 @@ public class FaceSettingsConfirmPreferenceController extends FaceSettingsPrefere
@Override @Override
public void updateState(Preference preference) { public void updateState(Preference preference) {
super.updateState(preference); super.updateState(preference);
if (!FaceSettings.isAvailable(mContext)) { if (!FaceSettings.isFaceHardwareDetected(mContext)) {
preference.setEnabled(false); preference.setEnabled(false);
} else if (!mFaceManager.hasEnrolledTemplates(getUserId())) { } else if (!mFaceManager.hasEnrolledTemplates(getUserId())) {
preference.setEnabled(false); preference.setEnabled(false);

View File

@@ -53,7 +53,7 @@ public class FaceSettingsKeyguardPreferenceController extends FaceSettingsPrefer
@Override @Override
public boolean isChecked() { public boolean isChecked() {
if (!FaceSettings.isAvailable(mContext)) { if (!FaceSettings.isFaceHardwareDetected(mContext)) {
return false; return false;
} else if (getRestrictingAdmin() != null) { } else if (getRestrictingAdmin() != null) {
return false; return false;
@@ -77,7 +77,7 @@ public class FaceSettingsKeyguardPreferenceController extends FaceSettingsPrefer
public void updateState(Preference preference) { public void updateState(Preference preference) {
EnforcedAdmin admin; EnforcedAdmin admin;
super.updateState(preference); super.updateState(preference);
if (!FaceSettings.isAvailable(mContext)) { if (!FaceSettings.isFaceHardwareDetected(mContext)) {
preference.setEnabled(false); preference.setEnabled(false);
} else if ((admin = getRestrictingAdmin()) != null) { } else if ((admin = getRestrictingAdmin()) != null) {
((RestrictedSwitchPreference) preference).setDisabledByAdmin(admin); ((RestrictedSwitchPreference) preference).setDisabledByAdmin(admin);

View File

@@ -47,7 +47,7 @@ public class FaceSettingsLockscreenBypassPreferenceController
@Override @Override
public boolean isChecked() { public boolean isChecked() {
if (!FaceSettings.isAvailable(mContext)) { if (!FaceSettings.isFaceHardwareDetected(mContext)) {
return false; return false;
} else if (getRestrictingAdmin() != null) { } else if (getRestrictingAdmin() != null) {
return false; return false;
@@ -69,7 +69,7 @@ public class FaceSettingsLockscreenBypassPreferenceController
public void updateState(Preference preference) { public void updateState(Preference preference) {
EnforcedAdmin admin; EnforcedAdmin admin;
super.updateState(preference); super.updateState(preference);
if (!FaceSettings.isAvailable(mContext)) { if (!FaceSettings.isFaceHardwareDetected(mContext)) {
preference.setEnabled(false); preference.setEnabled(false);
} else if ((admin = getRestrictingAdmin()) != null) { } else if ((admin = getRestrictingAdmin()) != null) {
((RestrictedSwitchPreference) preference).setDisabledByAdmin(admin); ((RestrictedSwitchPreference) preference).setDisabledByAdmin(admin);

View File

@@ -165,7 +165,7 @@ public class FaceSettingsRemoveButtonPreferenceController extends BasePreference
.findViewById(R.id.security_settings_face_settings_remove_button); .findViewById(R.id.security_settings_face_settings_remove_button);
mButton.setOnClickListener(this); mButton.setOnClickListener(this);
if (!FaceSettings.isAvailable(mContext)) { if (!FaceSettings.isFaceHardwareDetected(mContext)) {
mButton.setEnabled(false); mButton.setEnabled(false);
} else { } else {
mButton.setEnabled(!mRemoving); mButton.setEnabled(!mRemoving);

View File

@@ -41,7 +41,7 @@ public class FaceStatusPreferenceController extends BiometricStatusPreferenceCon
@Override @Override
protected boolean isDeviceSupported() { protected boolean isDeviceSupported() {
return mFaceManager != null && mFaceManager.isHardwareDetected(); return FaceSettings.isFaceHardwareDetected(mContext);
} }
@Override @Override

View File

@@ -21,6 +21,7 @@ import static android.provider.Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENA
import android.content.Context; import android.content.Context;
import android.provider.Settings; import android.provider.Settings;
import android.util.Log;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference; import androidx.preference.Preference;
@@ -31,6 +32,7 @@ import com.android.settings.overlay.FeatureFactory;
public class AssistGestureSettingsPreferenceController extends GesturePreferenceController { public class AssistGestureSettingsPreferenceController extends GesturePreferenceController {
private static final String TAG = "AssistGesture";
private static final String PREF_KEY_VIDEO = "gesture_assist_video"; private static final String PREF_KEY_VIDEO = "gesture_assist_video";
private static final String SECURE_KEY_ASSIST = ASSIST_GESTURE_ENABLED; private static final String SECURE_KEY_ASSIST = ASSIST_GESTURE_ENABLED;
@@ -55,8 +57,11 @@ public class AssistGestureSettingsPreferenceController extends GesturePreference
@Override @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
final boolean isAvailable = mAssistOnly ? mFeatureProvider.isSupported(mContext) final boolean isSupported = mFeatureProvider.isSupported(mContext);
: mFeatureProvider.isSensorAvailable(mContext); final boolean isSensorAvailable = mFeatureProvider.isSensorAvailable(mContext);
final boolean isAvailable = mAssistOnly ? isSupported : isSensorAvailable;
Log.d(TAG, "mAssistOnly:" + mAssistOnly + ", isSupported:" + isSupported
+ ", isSensorAvailable:" + isSensorAvailable);
return isAvailable ? AVAILABLE : UNSUPPORTED_ON_DEVICE; return isAvailable ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
} }