Convert all Log.* messages in KeyguardUpdateMonitor to use LogBuffer

Create a new helper class for logging.

Current messages being logged to Logcat won't be logged anymore, the
LogBuffer logs can be accessed by a dumpsys.

For debugging, LogBuffer can configured to echo to Logcat as well
using the following command:

```
adb shell settings put global systemui/buffer/KeyguardUpdateMonitorLog
<LogLevel>
```

Test: atest SystemUI passes
Fixes: 239819049
Change-Id: I8f234f930d1aab92ae3535d8f850d26c2eab6729
This commit is contained in:
Chandru
2022-07-22 15:45:08 +00:00
parent 40f7ea9ef3
commit e3022817d6
5 changed files with 497 additions and 198 deletions

View File

@@ -66,7 +66,6 @@ import android.hardware.fingerprint.FingerprintManager.AuthenticationCallback;
import android.hardware.fingerprint.FingerprintManager.AuthenticationResult; import android.hardware.fingerprint.FingerprintManager.AuthenticationResult;
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal; import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
import android.nfc.NfcAdapter; import android.nfc.NfcAdapter;
import android.os.Build;
import android.os.CancellationSignal; import android.os.CancellationSignal;
import android.os.Handler; import android.os.Handler;
import android.os.IRemoteCallback; import android.os.IRemoteCallback;
@@ -96,6 +95,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.jank.InteractionJankMonitor; import com.android.internal.jank.InteractionJankMonitor;
import com.android.internal.util.LatencyTracker; import com.android.internal.util.LatencyTracker;
import com.android.internal.widget.LockPatternUtils; import com.android.internal.widget.LockPatternUtils;
import com.android.keyguard.logging.KeyguardUpdateMonitorLogger;
import com.android.settingslib.WirelessUtils; import com.android.settingslib.WirelessUtils;
import com.android.settingslib.fuelgauge.BatteryStatus; import com.android.settingslib.fuelgauge.BatteryStatus;
import com.android.systemui.Dumpable; import com.android.systemui.Dumpable;
@@ -141,12 +141,6 @@ import javax.inject.Inject;
public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpable { public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpable {
private static final String TAG = "KeyguardUpdateMonitor"; private static final String TAG = "KeyguardUpdateMonitor";
private static final boolean DEBUG = KeyguardConstants.DEBUG;
private static final boolean DEBUG_SIM_STATES = KeyguardConstants.DEBUG_SIM_STATES;
private static final boolean DEBUG_FACE = Build.IS_DEBUGGABLE;
private static final boolean DEBUG_FINGERPRINT = Build.IS_DEBUGGABLE;
private static final boolean DEBUG_ACTIVE_UNLOCK = Build.IS_DEBUGGABLE;
private static final boolean DEBUG_SPEW = false;
private static final int BIOMETRIC_LOCKOUT_RESET_DELAY_MS = 600; private static final int BIOMETRIC_LOCKOUT_RESET_DELAY_MS = 600;
// Callback messages // Callback messages
@@ -241,6 +235,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
} }
private final Context mContext; private final Context mContext;
private final KeyguardUpdateMonitorLogger mLogger;
private final boolean mIsPrimaryUser; private final boolean mIsPrimaryUser;
private final AuthController mAuthController; private final AuthController mAuthController;
private final StatusBarStateController mStatusBarStateController; private final StatusBarStateController mStatusBarStateController;
@@ -337,17 +332,9 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
private static final int HAL_ERROR_RETRY_TIMEOUT = 500; // ms private static final int HAL_ERROR_RETRY_TIMEOUT = 500; // ms
private static final int HAL_ERROR_RETRY_MAX = 20; private static final int HAL_ERROR_RETRY_MAX = 20;
private final Runnable mFpCancelNotReceived = () -> { private final Runnable mFpCancelNotReceived = this::onFingerprintCancelNotReceived;
Log.e(TAG, "Fp cancellation not received, transitioning to STOPPED");
mFingerprintRunningState = BIOMETRIC_STATE_STOPPED;
updateFingerprintListeningState(BIOMETRIC_ACTION_STOP);
};
private final Runnable mFaceCancelNotReceived = () -> { private final Runnable mFaceCancelNotReceived = this::onFaceCancelNotReceived;
Log.e(TAG, "Face cancellation not received, transitioning to STOPPED");
mFaceRunningState = BIOMETRIC_STATE_STOPPED;
updateFaceListeningState(BIOMETRIC_ACTION_STOP);
};
private final Handler mHandler; private final Handler mHandler;
@@ -470,17 +457,15 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
private void handleSimSubscriptionInfoChanged() { private void handleSimSubscriptionInfoChanged() {
Assert.isMainThread(); Assert.isMainThread();
if (DEBUG_SIM_STATES) { mLogger.v("onSubscriptionInfoChanged()");
Log.v(TAG, "onSubscriptionInfoChanged()");
List<SubscriptionInfo> sil = mSubscriptionManager List<SubscriptionInfo> sil = mSubscriptionManager
.getCompleteActiveSubscriptionInfoList(); .getCompleteActiveSubscriptionInfoList();
if (sil != null) { if (sil != null) {
for (SubscriptionInfo subInfo : sil) { for (SubscriptionInfo subInfo : sil) {
Log.v(TAG, "SubInfo:" + subInfo); mLogger.logSubInfo(subInfo);
} }
} else { } else {
Log.v(TAG, "onSubscriptionInfoChanged: list is null"); mLogger.v("onSubscriptionInfoChanged: list is null");
}
} }
List<SubscriptionInfo> subscriptionInfos = getSubscriptionInfo(true /* forceReload */); List<SubscriptionInfo> subscriptionInfos = getSubscriptionInfo(true /* forceReload */);
@@ -504,8 +489,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
while (iter.hasNext()) { while (iter.hasNext()) {
Map.Entry<Integer, SimData> simData = iter.next(); Map.Entry<Integer, SimData> simData = iter.next();
if (!activeSubIds.contains(simData.getKey())) { if (!activeSubIds.contains(simData.getKey())) {
Log.i(TAG, "Previously active sub id " + simData.getKey() + " is now invalid, " mLogger.logInvalidSubId(simData.getKey());
+ "will remove");
iter.remove(); iter.remove();
SimData data = simData.getValue(); SimData data = simData.getValue();
@@ -690,7 +674,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
try { try {
mDreamManager.awaken(); mDreamManager.awaken();
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(TAG, "Unable to awaken from dream"); mLogger.logException(e, "Unable to awaken from dream");
} }
} }
} }
@@ -774,15 +758,15 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
try { try {
userId = ActivityManager.getService().getCurrentUser().id; userId = ActivityManager.getService().getCurrentUser().id;
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(TAG, "Failed to get current user id: ", e); mLogger.logException(e, "Failed to get current user id");
return; return;
} }
if (userId != authUserId) { if (userId != authUserId) {
Log.d(TAG, "Fingerprint authenticated for wrong user: " + authUserId); mLogger.logFingerprintAuthForWrongUser(authUserId);
return; return;
} }
if (isFingerprintDisabled(userId)) { if (isFingerprintDisabled(userId)) {
Log.d(TAG, "Fingerprint disabled by DPM for userId: " + userId); mLogger.logFingerprintDisabledForUser(userId);
return; return;
} }
onFingerprintAuthenticated(userId, isStrongBiometric); onFingerprintAuthenticated(userId, isStrongBiometric);
@@ -805,8 +789,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
private Runnable mRetryFingerprintAuthentication = new Runnable() { private Runnable mRetryFingerprintAuthentication = new Runnable() {
@Override @Override
public void run() { public void run() {
Log.w(TAG, mLogger.logRetryAfterFpHwUnavailable(mHardwareFingerprintUnavailableRetryCount);
"Retrying fingerprint attempt: " + mHardwareFingerprintUnavailableRetryCount);
if (mFpm.isHardwareDetected()) { if (mFpm.isHardwareDetected()) {
updateFingerprintListeningState(BIOMETRIC_ACTION_UPDATE); updateFingerprintListeningState(BIOMETRIC_ACTION_UPDATE);
} else if (mHardwareFingerprintUnavailableRetryCount < HAL_ERROR_RETRY_MAX) { } else if (mHardwareFingerprintUnavailableRetryCount < HAL_ERROR_RETRY_MAX) {
@@ -816,6 +799,12 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
} }
}; };
private void onFingerprintCancelNotReceived() {
mLogger.e("Fp cancellation not received, transitioning to STOPPED");
mFingerprintRunningState = BIOMETRIC_STATE_STOPPED;
KeyguardUpdateMonitor.this.updateFingerprintListeningState(BIOMETRIC_ACTION_STOP);
}
private void handleFingerprintError(int msgId, String errString) { private void handleFingerprintError(int msgId, String errString) {
Assert.isMainThread(); Assert.isMainThread();
if (mHandler.hasCallbacks(mFpCancelNotReceived)) { if (mHandler.hasCallbacks(mFpCancelNotReceived)) {
@@ -843,7 +832,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
if (msgId == FingerprintManager.FINGERPRINT_ERROR_LOCKOUT_PERMANENT) { if (msgId == FingerprintManager.FINGERPRINT_ERROR_LOCKOUT_PERMANENT) {
lockedOutStateChanged |= !mFingerprintLockedOutPermanent; lockedOutStateChanged |= !mFingerprintLockedOutPermanent;
mFingerprintLockedOutPermanent = true; mFingerprintLockedOutPermanent = true;
Log.d(TAG, "Fingerprint locked out - requiring strong auth"); mLogger.d("Fingerprint locked out - requiring strong auth");
mLockPatternUtils.requireStrongAuth( mLockPatternUtils.requireStrongAuth(
STRONG_AUTH_REQUIRED_AFTER_LOCKOUT, getCurrentUser()); STRONG_AUTH_REQUIRED_AFTER_LOCKOUT, getCurrentUser());
} }
@@ -871,7 +860,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
} }
private void handleFingerprintLockoutReset(@LockoutMode int mode) { private void handleFingerprintLockoutReset(@LockoutMode int mode) {
Log.d(TAG, "handleFingerprintLockoutReset: " + mode); mLogger.logFingerprintLockoutReset(mode);
final boolean wasLockout = mFingerprintLockedOut; final boolean wasLockout = mFingerprintLockedOut;
final boolean wasLockoutPermanent = mFingerprintLockedOutPermanent; final boolean wasLockoutPermanent = mFingerprintLockedOutPermanent;
mFingerprintLockedOut = (mode == BIOMETRIC_LOCKOUT_TIMED) mFingerprintLockedOut = (mode == BIOMETRIC_LOCKOUT_TIMED)
@@ -902,7 +891,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
boolean wasRunning = mFingerprintRunningState == BIOMETRIC_STATE_RUNNING; boolean wasRunning = mFingerprintRunningState == BIOMETRIC_STATE_RUNNING;
boolean isRunning = fingerprintRunningState == BIOMETRIC_STATE_RUNNING; boolean isRunning = fingerprintRunningState == BIOMETRIC_STATE_RUNNING;
mFingerprintRunningState = fingerprintRunningState; mFingerprintRunningState = fingerprintRunningState;
Log.d(TAG, "fingerprintRunningState: " + mFingerprintRunningState); mLogger.logFingerprintRunningState(mFingerprintRunningState);
// Clients of KeyguardUpdateMonitor don't care about the internal state about the // Clients of KeyguardUpdateMonitor don't care about the internal state about the
// asynchronousness of the cancel cycle. So only notify them if the actually running state // asynchronousness of the cancel cycle. So only notify them if the actually running state
// has changed. // has changed.
@@ -969,7 +958,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
private void handleFaceAcquired(int acquireInfo) { private void handleFaceAcquired(int acquireInfo) {
Assert.isMainThread(); Assert.isMainThread();
if (DEBUG_FACE) Log.d(TAG, "Face acquired acquireInfo=" + acquireInfo); mLogger.logFaceAcquired(acquireInfo);
for (int i = 0; i < mCallbacks.size(); i++) { for (int i = 0; i < mCallbacks.size(); i++) {
KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
if (cb != null) { if (cb != null) {
@@ -982,25 +971,25 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
Trace.beginSection("KeyGuardUpdateMonitor#handlerFaceAuthenticated"); Trace.beginSection("KeyGuardUpdateMonitor#handlerFaceAuthenticated");
try { try {
if (mGoingToSleep) { if (mGoingToSleep) {
Log.d(TAG, "Aborted successful auth because device is going to sleep."); mLogger.d("Aborted successful auth because device is going to sleep.");
return; return;
} }
final int userId; final int userId;
try { try {
userId = ActivityManager.getService().getCurrentUser().id; userId = ActivityManager.getService().getCurrentUser().id;
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(TAG, "Failed to get current user id: ", e); mLogger.logException(e, "Failed to get current user id");
return; return;
} }
if (userId != authUserId) { if (userId != authUserId) {
Log.d(TAG, "Face authenticated for wrong user: " + authUserId); mLogger.logFaceAuthForWrongUser(authUserId);
return; return;
} }
if (isFaceDisabled(userId)) { if (isFaceDisabled(userId)) {
Log.d(TAG, "Face authentication disabled by DPM for userId: " + userId); mLogger.logFaceAuthDisabledForUser(userId);
return; return;
} }
if (DEBUG_FACE) Log.d(TAG, "Face auth succeeded for user " + userId); mLogger.logFaceAuthSuccess(userId);
onFaceAuthenticated(userId, isStrongBiometric); onFaceAuthenticated(userId, isStrongBiometric);
} finally { } finally {
setFaceRunningState(BIOMETRIC_STATE_STOPPED); setFaceRunningState(BIOMETRIC_STATE_STOPPED);
@@ -1010,7 +999,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
private void handleFaceHelp(int msgId, String helpString) { private void handleFaceHelp(int msgId, String helpString) {
Assert.isMainThread(); Assert.isMainThread();
if (DEBUG_FACE) Log.d(TAG, "Face help received: " + helpString); mLogger.logFaceAuthHelpMsg(msgId, helpString);
for (int i = 0; i < mCallbacks.size(); i++) { for (int i = 0; i < mCallbacks.size(); i++) {
KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
if (cb != null) { if (cb != null) {
@@ -1022,15 +1011,21 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
private Runnable mRetryFaceAuthentication = new Runnable() { private Runnable mRetryFaceAuthentication = new Runnable() {
@Override @Override
public void run() { public void run() {
Log.w(TAG, "Retrying face after HW unavailable, attempt " + mLogger.logRetryingAfterFaceHwUnavailable(mHardwareFaceUnavailableRetryCount);
mHardwareFaceUnavailableRetryCount);
updateFaceListeningState(BIOMETRIC_ACTION_UPDATE); updateFaceListeningState(BIOMETRIC_ACTION_UPDATE);
} }
}; };
private void handleFaceError(int msgId, String errString) { private void onFaceCancelNotReceived() {
mLogger.e("Face cancellation not received, transitioning to STOPPED");
mFaceRunningState = BIOMETRIC_STATE_STOPPED;
KeyguardUpdateMonitor.this.updateFaceListeningState(BIOMETRIC_ACTION_STOP);
}
private void handleFaceError(int msgId, final String originalErrMsg) {
Assert.isMainThread(); Assert.isMainThread();
if (DEBUG_FACE) Log.d(TAG, "Face error received: " + errString + " msgId=" + msgId); String errString = originalErrMsg;
mLogger.logFaceAuthError(msgId, originalErrMsg);
if (mHandler.hasCallbacks(mFaceCancelNotReceived)) { if (mHandler.hasCallbacks(mFaceCancelNotReceived)) {
mHandler.removeCallbacks(mFaceCancelNotReceived); mHandler.removeCallbacks(mFaceCancelNotReceived);
} }
@@ -1087,7 +1082,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
} }
private void handleFaceLockoutReset(@LockoutMode int mode) { private void handleFaceLockoutReset(@LockoutMode int mode) {
Log.d(TAG, "handleFaceLockoutReset: " + mode); mLogger.logFaceLockoutReset(mode);
final boolean wasLockoutPermanent = mFaceLockedOutPermanent; final boolean wasLockoutPermanent = mFaceLockedOutPermanent;
mFaceLockedOutPermanent = (mode == BIOMETRIC_LOCKOUT_PERMANENT); mFaceLockedOutPermanent = (mode == BIOMETRIC_LOCKOUT_PERMANENT);
final boolean changed = (mFaceLockedOutPermanent != wasLockoutPermanent); final boolean changed = (mFaceLockedOutPermanent != wasLockoutPermanent);
@@ -1105,7 +1100,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
boolean wasRunning = mFaceRunningState == BIOMETRIC_STATE_RUNNING; boolean wasRunning = mFaceRunningState == BIOMETRIC_STATE_RUNNING;
boolean isRunning = faceRunningState == BIOMETRIC_STATE_RUNNING; boolean isRunning = faceRunningState == BIOMETRIC_STATE_RUNNING;
mFaceRunningState = faceRunningState; mFaceRunningState = faceRunningState;
Log.d(TAG, "faceRunningState: " + mFaceRunningState); mLogger.logFaceRunningState(mFaceRunningState);
// Clients of KeyguardUpdateMonitor don't care about the internal state or about the // Clients of KeyguardUpdateMonitor don't care about the internal state or about the
// asynchronousness of the cancel cycle. So only notify them if the actually running state // asynchronousness of the cancel cycle. So only notify them if the actually running state
// has changed. // has changed.
@@ -1221,8 +1216,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
mDevicePolicyManager.getProfileOwnerOrDeviceOwnerSupervisionComponent( mDevicePolicyManager.getProfileOwnerOrDeviceOwnerSupervisionComponent(
UserHandle.of(userId)); UserHandle.of(userId));
if (supervisorComponent == null) { if (supervisorComponent == null) {
Log.e(TAG, "No Profile Owner or Device Owner supervision app found for User " mLogger.logMissingSupervisorAppError(userId);
+ userId);
} else { } else {
Intent intent = Intent intent =
new Intent(DevicePolicyManager.ACTION_BIND_SECONDARY_LOCKSCREEN_SERVICE) new Intent(DevicePolicyManager.ACTION_BIND_SECONDARY_LOCKSCREEN_SERVICE)
@@ -1354,7 +1348,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
final String action = intent.getAction(); final String action = intent.getAction();
if (DEBUG) Log.d(TAG, "received broadcast " + action); mLogger.logBroadcastReceived(action);
if (Intent.ACTION_TIME_TICK.equals(action) if (Intent.ACTION_TIME_TICK.equals(action)
|| Intent.ACTION_TIME_CHANGED.equals(action)) { || Intent.ACTION_TIME_CHANGED.equals(action)) {
@@ -1381,12 +1375,10 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
} }
return; return;
} }
if (DEBUG_SIM_STATES) { mLogger.logSimStateFromIntent(action,
Log.v(TAG, "action " + action intent.getStringExtra(Intent.EXTRA_SIM_STATE),
+ " state: " + intent.getStringExtra( args.slotId,
Intent.EXTRA_SIM_STATE) args.subId);
+ " slotId: " + args.slotId + " subid: " + args.subId);
}
mHandler.obtainMessage(MSG_SIM_STATE_CHANGE, args.subId, args.slotId, args.simState) mHandler.obtainMessage(MSG_SIM_STATE_CHANGE, args.subId, args.slotId, args.simState)
.sendToTarget(); .sendToTarget();
} else if (TelephonyManager.ACTION_PHONE_STATE_CHANGED.equals(action)) { } else if (TelephonyManager.ACTION_PHONE_STATE_CHANGED.equals(action)) {
@@ -1398,10 +1390,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
ServiceState serviceState = ServiceState.newFromBundle(intent.getExtras()); ServiceState serviceState = ServiceState.newFromBundle(intent.getExtras());
int subId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, int subId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
SubscriptionManager.INVALID_SUBSCRIPTION_ID); SubscriptionManager.INVALID_SUBSCRIPTION_ID);
if (DEBUG) { mLogger.logServiceStateIntent(action, serviceState, subId);
Log.v(TAG, "action " + action + " serviceState=" + serviceState + " subId="
+ subId);
}
mHandler.sendMessage( mHandler.sendMessage(
mHandler.obtainMessage(MSG_SERVICE_STATE_CHANGE, subId, 0, serviceState)); mHandler.obtainMessage(MSG_SERVICE_STATE_CHANGE, subId, 0, serviceState));
} else if (TelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED.equals(action)) { } else if (TelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED.equals(action)) {
@@ -1521,7 +1510,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
*/ */
@Override @Override
public void onUdfpsPointerDown(int sensorId) { public void onUdfpsPointerDown(int sensorId) {
Log.d(TAG, "onUdfpsPointerDown, sensorId: " + sensorId); mLogger.logUdfpsPointerDown(sensorId);
requestFaceAuth(true); requestFaceAuth(true);
} }
@@ -1530,7 +1519,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
*/ */
@Override @Override
public void onUdfpsPointerUp(int sensorId) { public void onUdfpsPointerUp(int sensorId) {
Log.d(TAG, "onUdfpsPointerUp, sensorId: " + sensorId); mLogger.logUdfpsPointerUp(sensorId);
} }
}; };
@@ -1826,7 +1815,9 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
TelephonyListenerManager telephonyListenerManager, TelephonyListenerManager telephonyListenerManager,
InteractionJankMonitor interactionJankMonitor, InteractionJankMonitor interactionJankMonitor,
LatencyTracker latencyTracker, LatencyTracker latencyTracker,
ActiveUnlockConfig activeUnlockConfiguration) { ActiveUnlockConfig activeUnlockConfiguration,
KeyguardUpdateMonitorLogger logger) {
mLogger = logger;
mContext = context; mContext = context;
mSubscriptionManager = SubscriptionManager.from(context); mSubscriptionManager = SubscriptionManager.from(context);
mTelephonyListenerManager = telephonyListenerManager; mTelephonyListenerManager = telephonyListenerManager;
@@ -2170,13 +2161,13 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
|| mFingerprintRunningState == BIOMETRIC_STATE_CANCELLING_RESTARTING; || mFingerprintRunningState == BIOMETRIC_STATE_CANCELLING_RESTARTING;
if (runningOrRestarting && !shouldListenForFingerprint) { if (runningOrRestarting && !shouldListenForFingerprint) {
if (action == BIOMETRIC_ACTION_START) { if (action == BIOMETRIC_ACTION_START) {
Log.v(TAG, "Ignoring stopListeningForFingerprint()"); mLogger.v("Ignoring stopListeningForFingerprint()");
return; return;
} }
stopListeningForFingerprint(); stopListeningForFingerprint();
} else if (!runningOrRestarting && shouldListenForFingerprint) { } else if (!runningOrRestarting && shouldListenForFingerprint) {
if (action == BIOMETRIC_ACTION_STOP) { if (action == BIOMETRIC_ACTION_STOP) {
Log.v(TAG, "Ignoring startListeningForFingerprint()"); mLogger.v("Ignoring startListeningForFingerprint()");
return; return;
} }
startListeningForFingerprint(); startListeningForFingerprint();
@@ -2202,7 +2193,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
* @param active If the interrupt started or ended. * @param active If the interrupt started or ended.
*/ */
public void onAuthInterruptDetected(boolean active) { public void onAuthInterruptDetected(boolean active) {
if (DEBUG) Log.d(TAG, "onAuthInterruptDetected(" + active + ")"); mLogger.logAuthInterruptDetected(active);
if (mAuthInterruptActive == active) { if (mAuthInterruptActive == active) {
return; return;
} }
@@ -2217,7 +2208,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
* @param userInitiatedRequest true if the user explicitly requested face auth * @param userInitiatedRequest true if the user explicitly requested face auth
*/ */
public void requestFaceAuth(boolean userInitiatedRequest) { public void requestFaceAuth(boolean userInitiatedRequest) {
if (DEBUG) Log.d(TAG, "requestFaceAuth() userInitiated=" + userInitiatedRequest); mLogger.logFaceAuthRequested(userInitiatedRequest);
mIsFaceAuthUserRequested |= userInitiatedRequest; mIsFaceAuthUserRequested |= userInitiatedRequest;
updateFaceListeningState(BIOMETRIC_ACTION_START); updateFaceListeningState(BIOMETRIC_ACTION_START);
} }
@@ -2243,14 +2234,14 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
boolean shouldListenForFace = shouldListenForFace(); boolean shouldListenForFace = shouldListenForFace();
if (mFaceRunningState == BIOMETRIC_STATE_RUNNING && !shouldListenForFace) { if (mFaceRunningState == BIOMETRIC_STATE_RUNNING && !shouldListenForFace) {
if (action == BIOMETRIC_ACTION_START) { if (action == BIOMETRIC_ACTION_START) {
Log.v(TAG, "Ignoring stopListeningForFace()"); mLogger.v("Ignoring stopListeningForFace()");
return; return;
} }
mIsFaceAuthUserRequested = false; mIsFaceAuthUserRequested = false;
stopListeningForFace(); stopListeningForFace();
} else if (mFaceRunningState != BIOMETRIC_STATE_RUNNING && shouldListenForFace) { } else if (mFaceRunningState != BIOMETRIC_STATE_RUNNING && shouldListenForFace) {
if (action == BIOMETRIC_ACTION_STOP) { if (action == BIOMETRIC_ACTION_STOP) {
Log.v(TAG, "Ignoring startListeningForFace()"); mLogger.v("Ignoring startListeningForFace()");
return; return;
} }
startListeningForFace(); startListeningForFace();
@@ -2267,9 +2258,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
} }
if (shouldTriggerActiveUnlock()) { if (shouldTriggerActiveUnlock()) {
if (DEBUG_ACTIVE_UNLOCK) { mLogger.logActiveUnlockTriggered(reason);
Log.d("ActiveUnlock", "initiate active unlock triggerReason=" + reason);
}
mTrustManager.reportUserMayRequestUnlock(KeyguardUpdateMonitor.getCurrentUser()); mTrustManager.reportUserMayRequestUnlock(KeyguardUpdateMonitor.getCurrentUser());
} }
} }
@@ -2297,12 +2286,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
} }
if (allowRequest && shouldTriggerActiveUnlock()) { if (allowRequest && shouldTriggerActiveUnlock()) {
if (DEBUG_ACTIVE_UNLOCK) { mLogger.logUserRequestedUnlock(requestOrigin, reason, dismissKeyguard);
Log.d("ActiveUnlock", "reportUserRequestedUnlock"
+ " origin=" + requestOrigin.name()
+ " reason=" + reason
+ " dismissKeyguard=" + dismissKeyguard);
}
mTrustManager.reportUserRequestedUnlock(KeyguardUpdateMonitor.getCurrentUser(), mTrustManager.reportUserRequestedUnlock(KeyguardUpdateMonitor.getCurrentUser(),
dismissKeyguard); dismissKeyguard);
} }
@@ -2452,7 +2436,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
final boolean shouldListen = shouldListenKeyguardState && shouldListenUserState final boolean shouldListen = shouldListenKeyguardState && shouldListenUserState
&& shouldListenBouncerState && shouldListenUdfpsState && !isFingerprintLockedOut(); && shouldListenBouncerState && shouldListenUdfpsState && !isFingerprintLockedOut();
if (DEBUG_FINGERPRINT || DEBUG_SPEW) {
maybeLogListenerModelData( maybeLogListenerModelData(
new KeyguardFingerprintListenModel( new KeyguardFingerprintListenModel(
System.currentTimeMillis(), System.currentTimeMillis(),
@@ -2477,7 +2460,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
mSwitchingUser, mSwitchingUser,
isUdfps, isUdfps,
userDoesNotHaveTrust)); userDoesNotHaveTrust));
}
return shouldListen; return shouldListen;
} }
@@ -2552,7 +2534,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
&& !fpLockedout; && !fpLockedout;
// Aggregate relevant fields for debug logging. // Aggregate relevant fields for debug logging.
if (DEBUG_FACE || DEBUG_SPEW) {
maybeLogListenerModelData( maybeLogListenerModelData(
new KeyguardFaceListenModel( new KeyguardFaceListenModel(
System.currentTimeMillis(), System.currentTimeMillis(),
@@ -2574,37 +2555,28 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
mSecureCameraLaunched, mSecureCameraLaunched,
mSwitchingUser, mSwitchingUser,
mUdfpsBouncerShowing)); mUdfpsBouncerShowing));
}
return shouldListen; return shouldListen;
} }
private void maybeLogListenerModelData(KeyguardListenModel model) { private void maybeLogListenerModelData(KeyguardListenModel model) {
// Too chatty, but very useful when debugging issues. mLogger.logKeyguardListenerModel(model);
if (DEBUG_SPEW) {
Log.v(TAG, model.toString());
}
if (DEBUG_ACTIVE_UNLOCK if (model instanceof KeyguardActiveUnlockModel) {
&& model instanceof KeyguardActiveUnlockModel) {
mListenModels.add(model); mListenModels.add(model);
return; return;
} }
// Add model data to the historical buffer. // Add model data to the historical buffer.
final boolean notYetRunning = final boolean notYetRunning =
(DEBUG_FACE (model instanceof KeyguardFaceListenModel
&& model instanceof KeyguardFaceListenModel
&& mFaceRunningState != BIOMETRIC_STATE_RUNNING) && mFaceRunningState != BIOMETRIC_STATE_RUNNING)
|| (DEBUG_FINGERPRINT || (model instanceof KeyguardFingerprintListenModel
&& model instanceof KeyguardFingerprintListenModel
&& mFingerprintRunningState != BIOMETRIC_STATE_RUNNING); && mFingerprintRunningState != BIOMETRIC_STATE_RUNNING);
final boolean running = final boolean running =
(DEBUG_FACE (model instanceof KeyguardFaceListenModel
&& model instanceof KeyguardFaceListenModel
&& mFaceRunningState == BIOMETRIC_STATE_RUNNING) && mFaceRunningState == BIOMETRIC_STATE_RUNNING)
|| (DEBUG_FINGERPRINT || (model instanceof KeyguardFingerprintListenModel
&& model instanceof KeyguardFingerprintListenModel
&& mFingerprintRunningState == BIOMETRIC_STATE_RUNNING); && mFingerprintRunningState == BIOMETRIC_STATE_RUNNING);
if (notYetRunning && model.getListening() if (notYetRunning && model.getListening()
|| running && !model.getListening()) { || running && !model.getListening()) {
@@ -2616,9 +2588,9 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
final int userId = getCurrentUser(); final int userId = getCurrentUser();
final boolean unlockPossible = isUnlockWithFingerprintPossible(userId); final boolean unlockPossible = isUnlockWithFingerprintPossible(userId);
if (mFingerprintCancelSignal != null) { if (mFingerprintCancelSignal != null) {
Log.e(TAG, "Cancellation signal is not null, high chance of bug in fp auth lifecycle" mLogger.logUnexpectedFpCancellationSignalState(
+ " management. FP state: " + mFingerprintRunningState mFingerprintRunningState,
+ ", unlockPossible: " + unlockPossible); unlockPossible);
} }
if (mFingerprintRunningState == BIOMETRIC_STATE_CANCELLING) { if (mFingerprintRunningState == BIOMETRIC_STATE_CANCELLING) {
@@ -2629,7 +2601,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
// Waiting for restart via handleFingerprintError(). // Waiting for restart via handleFingerprintError().
return; return;
} }
if (DEBUG) Log.v(TAG, "startListeningForFingerprint()"); mLogger.v("startListeningForFingerprint()");
if (unlockPossible) { if (unlockPossible) {
mFingerprintCancelSignal = new CancellationSignal(); mFingerprintCancelSignal = new CancellationSignal();
@@ -2650,9 +2622,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
final int userId = getCurrentUser(); final int userId = getCurrentUser();
final boolean unlockPossible = isUnlockWithFacePossible(userId); final boolean unlockPossible = isUnlockWithFacePossible(userId);
if (mFaceCancelSignal != null) { if (mFaceCancelSignal != null) {
Log.e(TAG, "Cancellation signal is not null, high chance of bug in face auth lifecycle" mLogger.logUnexpectedFaceCancellationSignalState(mFaceRunningState, unlockPossible);
+ " management. Face state: " + mFaceRunningState
+ ", unlockPossible: " + unlockPossible);
} }
if (mFaceRunningState == BIOMETRIC_STATE_CANCELLING) { if (mFaceRunningState == BIOMETRIC_STATE_CANCELLING) {
@@ -2662,7 +2632,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
// Waiting for ERROR_CANCELED before requesting auth again // Waiting for ERROR_CANCELED before requesting auth again
return; return;
} }
if (DEBUG) Log.v(TAG, "startListeningForFace(): " + mFaceRunningState); mLogger.logStartedListeningForFace(mFaceRunningState);
if (unlockPossible) { if (unlockPossible) {
mFaceCancelSignal = new CancellationSignal(); mFaceCancelSignal = new CancellationSignal();
@@ -2728,7 +2698,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
} }
private void stopListeningForFingerprint() { private void stopListeningForFingerprint() {
if (DEBUG) Log.v(TAG, "stopListeningForFingerprint()"); mLogger.v("stopListeningForFingerprint()");
if (mFingerprintRunningState == BIOMETRIC_STATE_RUNNING) { if (mFingerprintRunningState == BIOMETRIC_STATE_RUNNING) {
if (mFingerprintCancelSignal != null) { if (mFingerprintCancelSignal != null) {
mFingerprintCancelSignal.cancel(); mFingerprintCancelSignal.cancel();
@@ -2744,7 +2714,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
} }
private void stopListeningForFace() { private void stopListeningForFace() {
if (DEBUG) Log.v(TAG, "stopListeningForFace()"); mLogger.v("stopListeningForFace()");
if (mFaceRunningState == BIOMETRIC_STATE_RUNNING) { if (mFaceRunningState == BIOMETRIC_STATE_RUNNING) {
if (mFaceCancelSignal != null) { if (mFaceCancelSignal != null) {
mFaceCancelSignal.cancel(); mFaceCancelSignal.cancel();
@@ -2773,7 +2743,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
if (mDeviceProvisioned) { if (mDeviceProvisioned) {
mHandler.sendEmptyMessage(MSG_DEVICE_PROVISIONED); mHandler.sendEmptyMessage(MSG_DEVICE_PROVISIONED);
} }
if (DEBUG) Log.d(TAG, "DEVICE_PROVISIONED state = " + mDeviceProvisioned); mLogger.logDeviceProvisionedState(mDeviceProvisioned);
} }
}; };
@@ -2878,7 +2848,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
*/ */
private void handlePhoneStateChanged(String newState) { private void handlePhoneStateChanged(String newState) {
Assert.isMainThread(); Assert.isMainThread();
if (DEBUG) Log.d(TAG, "handlePhoneStateChanged(" + newState + ")"); mLogger.logPhoneStateChanged(newState);
if (TelephonyManager.EXTRA_STATE_IDLE.equals(newState)) { if (TelephonyManager.EXTRA_STATE_IDLE.equals(newState)) {
mPhoneState = TelephonyManager.CALL_STATE_IDLE; mPhoneState = TelephonyManager.CALL_STATE_IDLE;
} else if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(newState)) { } else if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(newState)) {
@@ -2899,7 +2869,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
*/ */
private void handleTimeUpdate() { private void handleTimeUpdate() {
Assert.isMainThread(); Assert.isMainThread();
if (DEBUG) Log.d(TAG, "handleTimeUpdate"); mLogger.d("handleTimeUpdate");
for (int i = 0; i < mCallbacks.size(); i++) { for (int i = 0; i < mCallbacks.size(); i++) {
KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
if (cb != null) { if (cb != null) {
@@ -2913,7 +2883,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
*/ */
private void handleTimeZoneUpdate(String timeZone) { private void handleTimeZoneUpdate(String timeZone) {
Assert.isMainThread(); Assert.isMainThread();
if (DEBUG) Log.d(TAG, "handleTimeZoneUpdate"); mLogger.d("handleTimeZoneUpdate");
for (int i = 0; i < mCallbacks.size(); i++) { for (int i = 0; i < mCallbacks.size(); i++) {
KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
if (cb != null) { if (cb != null) {
@@ -2931,7 +2901,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
*/ */
private void handleTimeFormatUpdate(String timeFormat) { private void handleTimeFormatUpdate(String timeFormat) {
Assert.isMainThread(); Assert.isMainThread();
if (DEBUG) Log.d(TAG, "handleTimeFormatUpdate timeFormat=" + timeFormat); mLogger.logTimeFormatChanged(timeFormat);
for (int i = 0; i < mCallbacks.size(); i++) { for (int i = 0; i < mCallbacks.size(); i++) {
KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
if (cb != null) { if (cb != null) {
@@ -2945,7 +2915,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
*/ */
private void handleBatteryUpdate(BatteryStatus status) { private void handleBatteryUpdate(BatteryStatus status) {
Assert.isMainThread(); Assert.isMainThread();
if (DEBUG) Log.d(TAG, "handleBatteryUpdate"); mLogger.d("handleBatteryUpdate");
final boolean batteryUpdateInteresting = isBatteryUpdateInteresting(mBatteryStatus, status); final boolean batteryUpdateInteresting = isBatteryUpdateInteresting(mBatteryStatus, status);
mBatteryStatus = status; mBatteryStatus = status;
if (batteryUpdateInteresting) { if (batteryUpdateInteresting) {
@@ -2982,14 +2952,11 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
@VisibleForTesting @VisibleForTesting
void handleSimStateChange(int subId, int slotId, int state) { void handleSimStateChange(int subId, int slotId, int state) {
Assert.isMainThread(); Assert.isMainThread();
if (DEBUG_SIM_STATES) { mLogger.logSimState(subId, slotId, state);
Log.d(TAG, "handleSimStateChange(subId=" + subId + ", slotId="
+ slotId + ", state=" + state + ")");
}
boolean becameAbsent = false; boolean becameAbsent = false;
if (!SubscriptionManager.isValidSubscriptionId(subId)) { if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Log.w(TAG, "invalid subId in handleSimStateChange()"); mLogger.w("invalid subId in handleSimStateChange()");
/* Only handle No SIM(ABSENT) and Card Error(CARD_IO_ERROR) due to /* Only handle No SIM(ABSENT) and Card Error(CARD_IO_ERROR) due to
* handleServiceStateChange() handle other case */ * handleServiceStateChange() handle other case */
if (state == TelephonyManager.SIM_STATE_ABSENT) { if (state == TelephonyManager.SIM_STATE_ABSENT) {
@@ -3038,13 +3005,10 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
*/ */
@VisibleForTesting @VisibleForTesting
void handleServiceStateChange(int subId, ServiceState serviceState) { void handleServiceStateChange(int subId, ServiceState serviceState) {
if (DEBUG) { mLogger.logServiceStateChange(subId, serviceState);
Log.d(TAG,
"handleServiceStateChange(subId=" + subId + ", serviceState=" + serviceState);
}
if (!SubscriptionManager.isValidSubscriptionId(subId)) { if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Log.w(TAG, "invalid subId in handleServiceStateChange()"); mLogger.w("invalid subId in handleServiceStateChange()");
return; return;
} else { } else {
updateTelephonyCapable(true); updateTelephonyCapable(true);
@@ -3066,7 +3030,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
*/ */
public void onKeyguardVisibilityChanged(boolean showing) { public void onKeyguardVisibilityChanged(boolean showing) {
Assert.isMainThread(); Assert.isMainThread();
Log.d(TAG, "onKeyguardVisibilityChanged(" + showing + ")"); mLogger.logKeyguardVisibilityChanged(showing);
mKeyguardIsVisible = showing; mKeyguardIsVisible = showing;
if (showing) { if (showing) {
@@ -3086,7 +3050,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
* Handle {@link #MSG_KEYGUARD_RESET} * Handle {@link #MSG_KEYGUARD_RESET}
*/ */
private void handleKeyguardReset() { private void handleKeyguardReset() {
if (DEBUG) Log.d(TAG, "handleKeyguardReset"); mLogger.d("handleKeyguardReset");
updateBiometricListeningState(BIOMETRIC_ACTION_UPDATE); updateBiometricListeningState(BIOMETRIC_ACTION_UPDATE);
mNeedsSlowUnlockTransition = resolveNeedsSlowUnlockTransition(); mNeedsSlowUnlockTransition = resolveNeedsSlowUnlockTransition();
} }
@@ -3100,8 +3064,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
0 /* flags */, getCurrentUser()); 0 /* flags */, getCurrentUser());
if (resolveInfo == null) { if (resolveInfo == null) {
Log.w(TAG, "resolveNeedsSlowUnlockTransition: returning false since activity " mLogger.w("resolveNeedsSlowUnlockTransition: returning false since activity could "
+ "could not be resolved."); + "not be resolved.");
return false; return false;
} }
@@ -3119,11 +3083,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
final boolean wasBouncerFullyShown = mBouncerFullyShown; final boolean wasBouncerFullyShown = mBouncerFullyShown;
mBouncerIsOrWillBeShowing = bouncerIsOrWillBeShowing == 1; mBouncerIsOrWillBeShowing = bouncerIsOrWillBeShowing == 1;
mBouncerFullyShown = bouncerFullyShown == 1; mBouncerFullyShown = bouncerFullyShown == 1;
if (DEBUG) { mLogger.logKeyguardBouncerChanged(mBouncerIsOrWillBeShowing, mBouncerFullyShown);
Log.d(TAG, "handleKeyguardBouncerChanged"
+ " bouncerIsOrWillBeShowing=" + mBouncerIsOrWillBeShowing
+ " bouncerFullyShowing=" + mBouncerFullyShown);
}
if (mBouncerFullyShown) { if (mBouncerFullyShown) {
// If the bouncer is shown, always clear this flag. This can happen in the following // If the bouncer is shown, always clear this flag. This can happen in the following
@@ -3243,9 +3203,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
*/ */
public void removeCallback(KeyguardUpdateMonitorCallback callback) { public void removeCallback(KeyguardUpdateMonitorCallback callback) {
Assert.isMainThread(); Assert.isMainThread();
if (DEBUG) { mLogger.logUnregisterCallback(callback);
Log.v(TAG, "*** unregister callback for " + callback);
}
mCallbacks.removeIf(el -> el.get() == callback); mCallbacks.removeIf(el -> el.get() == callback);
} }
@@ -3258,15 +3216,14 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
*/ */
public void registerCallback(KeyguardUpdateMonitorCallback callback) { public void registerCallback(KeyguardUpdateMonitorCallback callback) {
Assert.isMainThread(); Assert.isMainThread();
if (DEBUG) Log.v(TAG, "*** register callback for " + callback); mLogger.logRegisterCallback(callback);
// Prevent adding duplicate callbacks // Prevent adding duplicate callbacks
for (int i = 0; i < mCallbacks.size(); i++) { for (int i = 0; i < mCallbacks.size(); i++) {
if (mCallbacks.get(i).get() == callback) { if (mCallbacks.get(i).get() == callback) {
if (DEBUG) { mLogger.logException(
Log.e(TAG, "Object tried to add another callback", new Exception("Called by"),
new Exception("Called by")); "Object tried to add another callback");
}
return; return;
} }
} }
@@ -3316,11 +3273,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
*/ */
public void sendKeyguardBouncerChanged(boolean bouncerIsOrWillBeShowing, public void sendKeyguardBouncerChanged(boolean bouncerIsOrWillBeShowing,
boolean bouncerFullyShown) { boolean bouncerFullyShown) {
if (DEBUG) { mLogger.logSendKeyguardBouncerChanged(bouncerIsOrWillBeShowing, bouncerFullyShown);
Log.d(TAG, "sendKeyguardBouncerChanged"
+ " bouncerIsOrWillBeShowing=" + bouncerIsOrWillBeShowing
+ " bouncerFullyShown=" + bouncerFullyShown);
}
Message message = mHandler.obtainMessage(MSG_KEYGUARD_BOUNCER_CHANGED); Message message = mHandler.obtainMessage(MSG_KEYGUARD_BOUNCER_CHANGED);
message.arg1 = bouncerIsOrWillBeShowing ? 1 : 0; message.arg1 = bouncerIsOrWillBeShowing ? 1 : 0;
message.arg2 = bouncerFullyShown ? 1 : 0; message.arg2 = bouncerFullyShown ? 1 : 0;
@@ -3337,7 +3290,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
*/ */
@MainThread @MainThread
public void reportSimUnlocked(int subId) { public void reportSimUnlocked(int subId) {
if (DEBUG_SIM_STATES) Log.v(TAG, "reportSimUnlocked(subId=" + subId + ")"); mLogger.logSimUnlocked(subId);
handleSimStateChange(subId, getSlotId(subId), TelephonyManager.SIM_STATE_READY); handleSimStateChange(subId, getSlotId(subId), TelephonyManager.SIM_STATE_READY);
} }
@@ -3614,7 +3567,9 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
try { try {
ActivityManager.getService().unregisterUserSwitchObserver(mUserSwitchObserver); ActivityManager.getService().unregisterUserSwitchObserver(mUserSwitchObserver);
} catch (RemoteException e) { } catch (RemoteException e) {
Log.d(TAG, "RemoteException onDestroy. cannot unregister userSwitchObserver"); mLogger.logException(
e,
"RemoteException onDestroy. cannot unregister userSwitchObserver");
} }
TaskStackChangeListeners.getInstance().unregisterTaskStackListener(mTaskStackListener); TaskStackChangeListeners.getInstance().unregisterTaskStackListener(mTaskStackListener);

View File

@@ -0,0 +1,326 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.keyguard.logging
import android.hardware.biometrics.BiometricConstants.LockoutMode
import android.telephony.ServiceState
import android.telephony.SubscriptionInfo
import com.android.keyguard.ActiveUnlockConfig
import com.android.keyguard.KeyguardListenModel
import com.android.keyguard.KeyguardUpdateMonitorCallback
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.LogLevel
import com.android.systemui.log.LogLevel.DEBUG
import com.android.systemui.log.LogLevel.ERROR
import com.android.systemui.log.LogLevel.INFO
import com.android.systemui.log.LogLevel.VERBOSE
import com.android.systemui.log.LogLevel.WARNING
import com.android.systemui.log.dagger.KeyguardUpdateMonitorLog
import com.google.errorprone.annotations.CompileTimeConstant
import javax.inject.Inject
private const val TAG = "KeyguardUpdateMonitorLog"
/**
* Helper class for logging for [com.android.keyguard.KeyguardUpdateMonitor]
*/
class KeyguardUpdateMonitorLogger @Inject constructor(
@KeyguardUpdateMonitorLog private val logBuffer: LogBuffer
) {
fun d(@CompileTimeConstant msg: String) = log(msg, DEBUG)
fun e(@CompileTimeConstant msg: String) = log(msg, ERROR)
fun v(@CompileTimeConstant msg: String) = log(msg, ERROR)
fun w(@CompileTimeConstant msg: String) = log(msg, WARNING)
fun log(@CompileTimeConstant msg: String, level: LogLevel) = logBuffer.log(TAG, level, msg)
fun logActiveUnlockTriggered(reason: String) {
logBuffer.log("ActiveUnlock", DEBUG,
{ str1 = reason },
{ "initiate active unlock triggerReason=$str1" })
}
fun logAuthInterruptDetected(active: Boolean) {
logBuffer.log(TAG, DEBUG,
{ bool1 = active },
{ "onAuthInterruptDetected($bool1)" })
}
fun logBroadcastReceived(action: String?) {
logBuffer.log(TAG, DEBUG, { str1 = action }, { "received broadcast $str1" })
}
fun logDeviceProvisionedState(deviceProvisioned: Boolean) {
logBuffer.log(TAG, DEBUG,
{ bool1 = deviceProvisioned },
{ "DEVICE_PROVISIONED state = $bool1" })
}
fun logException(ex: Exception, @CompileTimeConstant logMsg: String) {
logBuffer.log(TAG, ERROR, {}, { logMsg }, exception = ex)
}
fun logFaceAcquired(acquireInfo: Int) {
logBuffer.log(TAG, DEBUG,
{ int1 = acquireInfo },
{ "Face acquired acquireInfo=$int1" })
}
fun logFaceAuthDisabledForUser(userId: Int) {
logBuffer.log(TAG, DEBUG,
{ int1 = userId },
{ "Face authentication disabled by DPM for userId: $int1" })
}
fun logFaceAuthError(msgId: Int, originalErrMsg: String) {
logBuffer.log(TAG, DEBUG, {
str1 = originalErrMsg
int1 = msgId
}, { "Face error received: $str1 msgId= $int1" })
}
fun logFaceAuthForWrongUser(authUserId: Int) {
logBuffer.log(TAG, DEBUG,
{ int1 = authUserId },
{ "Face authenticated for wrong user: $int1" })
}
fun logFaceAuthHelpMsg(msgId: Int, helpMsg: String) {
logBuffer.log(TAG, DEBUG, {
int1 = msgId
str1 = helpMsg
}, { "Face help received, msgId: $int1 msg: $str1" })
}
fun logFaceAuthRequested(userInitiatedRequest: Boolean) {
logBuffer.log(TAG, DEBUG,
{ bool1 = userInitiatedRequest },
{ "requestFaceAuth() userInitiated=$bool1" })
}
fun logFaceAuthSuccess(userId: Int) {
logBuffer.log(TAG, DEBUG,
{ int1 = userId },
{ "Face auth succeeded for user $int1" })
}
fun logFaceLockoutReset(@LockoutMode mode: Int) {
logBuffer.log(TAG, DEBUG, { int1 = mode }, { "handleFaceLockoutReset: $int1" })
}
fun logFaceRunningState(faceRunningState: Int) {
logBuffer.log(TAG, DEBUG, { int1 = faceRunningState }, { "faceRunningState: $int1" })
}
fun logFingerprintAuthForWrongUser(authUserId: Int) {
logBuffer.log(TAG, DEBUG,
{ int1 = authUserId },
{ "Fingerprint authenticated for wrong user: $int1" })
}
fun logFingerprintDisabledForUser(userId: Int) {
logBuffer.log(TAG, DEBUG,
{ int1 = userId },
{ "Fingerprint disabled by DPM for userId: $int1" })
}
fun logFingerprintLockoutReset(@LockoutMode mode: Int) {
logBuffer.log(TAG, DEBUG, { int1 = mode }, { "handleFingerprintLockoutReset: $int1" })
}
fun logFingerprintRunningState(fingerprintRunningState: Int) {
logBuffer.log(TAG, DEBUG,
{ int1 = fingerprintRunningState },
{ "fingerprintRunningState: $int1" })
}
fun logInvalidSubId(subId: Int) {
logBuffer.log(TAG, INFO,
{ int1 = subId },
{ "Previously active sub id $int1 is now invalid, will remove" })
}
fun logKeyguardBouncerChanged(bouncerIsOrWillBeShowing: Boolean, bouncerFullyShown: Boolean) {
logBuffer.log(TAG, DEBUG, {
bool1 = bouncerIsOrWillBeShowing
bool2 = bouncerFullyShown
}, {
"handleKeyguardBouncerChanged " +
"bouncerIsOrWillBeShowing=$bool1 bouncerFullyShowing=$bool2"
})
}
fun logKeyguardListenerModel(model: KeyguardListenModel) {
logBuffer.log(TAG, VERBOSE, { str1 = "$model" }, { str1!! })
}
fun logKeyguardVisibilityChanged(showing: Boolean) {
logBuffer.log(TAG, DEBUG, { bool1 = showing }, { "onKeyguardVisibilityChanged($bool1)" })
}
fun logMissingSupervisorAppError(userId: Int) {
logBuffer.log(TAG, ERROR,
{ int1 = userId },
{ "No Profile Owner or Device Owner supervision app found for User $int1" })
}
fun logPhoneStateChanged(newState: String) {
logBuffer.log(TAG, DEBUG,
{ str1 = newState },
{ "handlePhoneStateChanged($str1)" })
}
fun logRegisterCallback(callback: KeyguardUpdateMonitorCallback?) {
logBuffer.log(TAG, VERBOSE,
{ str1 = "$callback" },
{ "*** register callback for $str1" })
}
fun logRetryingAfterFaceHwUnavailable(retryCount: Int) {
logBuffer.log(TAG, WARNING,
{ int1 = retryCount },
{ "Retrying face after HW unavailable, attempt $int1" })
}
fun logRetryAfterFpHwUnavailable(retryCount: Int) {
logBuffer.log(TAG, WARNING,
{ int1 = retryCount },
{ "Retrying fingerprint attempt: $int1" })
}
fun logSendKeyguardBouncerChanged(
bouncerIsOrWillBeShowing: Boolean,
bouncerFullyShown: Boolean,
) {
logBuffer.log(TAG, DEBUG, {
bool1 = bouncerIsOrWillBeShowing
bool2 = bouncerFullyShown
}, {
"sendKeyguardBouncerChanged bouncerIsOrWillBeShowing=$bool1 " +
"bouncerFullyShown=$bool2"
})
}
fun logServiceStateChange(subId: Int, serviceState: ServiceState?) {
logBuffer.log(TAG, DEBUG, {
int1 = subId
str1 = "$serviceState"
}, { "handleServiceStateChange(subId=$int1, serviceState=$str1)" })
}
fun logServiceStateIntent(action: String, serviceState: ServiceState?, subId: Int) {
logBuffer.log(TAG, VERBOSE, {
str1 = action
str2 = "$serviceState"
int1 = subId
}, { "action $str1 serviceState=$str2 subId=$int1" })
}
fun logSimState(subId: Int, slotId: Int, state: Int) {
logBuffer.log(TAG, DEBUG, {
int1 = subId
int2 = slotId
long1 = state.toLong()
}, { "handleSimStateChange(subId=$int1, slotId=$int2, state=$long1)" })
}
fun logSimStateFromIntent(action: String, extraSimState: String, slotId: Int, subId: Int) {
logBuffer.log(TAG, VERBOSE, {
str1 = action
str2 = extraSimState
int1 = slotId
int2 = subId
}, { "action $str1 state: $str2 slotId: $int1 subid: $int2" })
}
fun logSimUnlocked(subId: Int) {
logBuffer.log(TAG, VERBOSE, { int1 = subId }, { "reportSimUnlocked(subId=$int1)" })
}
fun logStartedListeningForFace(faceRunningState: Int) {
logBuffer.log(TAG, VERBOSE,
{ int1 = faceRunningState },
{ "startListeningForFace(): $int1" })
}
fun logSubInfo(subInfo: SubscriptionInfo?) {
logBuffer.log(TAG, VERBOSE,
{ str1 = "$subInfo" },
{ "SubInfo:$str1" })
}
fun logTimeFormatChanged(newTimeFormat: String) {
logBuffer.log(TAG, DEBUG,
{ str1 = newTimeFormat },
{ "handleTimeFormatUpdate timeFormat=$str1" })
}
fun logUdfpsPointerDown(sensorId: Int) {
logBuffer.log(TAG, DEBUG,
{ int1 = sensorId },
{ "onUdfpsPointerDown, sensorId: $int1" })
}
fun logUdfpsPointerUp(sensorId: Int) {
logBuffer.log(TAG, DEBUG,
{ int1 = sensorId },
{ "onUdfpsPointerUp, sensorId: $int1" })
}
fun logUnexpectedFaceCancellationSignalState(faceRunningState: Int, unlockPossible: Boolean) {
logBuffer.log(TAG, ERROR, {
int1 = faceRunningState
bool1 = unlockPossible
}, {
"Cancellation signal is not null, high chance of bug in " +
"face auth lifecycle management. " +
"Face state: $int1, unlockPossible: $bool1"
})
}
fun logUnexpectedFpCancellationSignalState(
fingerprintRunningState: Int,
unlockPossible: Boolean
) {
logBuffer.log(TAG, ERROR, {
int1 = fingerprintRunningState
bool1 = unlockPossible
}, {
"Cancellation signal is not null, high chance of bug in " +
"fp auth lifecycle management. FP state: $int1, unlockPossible: $bool1"
})
}
fun logUnregisterCallback(callback: KeyguardUpdateMonitorCallback?) {
logBuffer.log(TAG, VERBOSE,
{ str1 = "$callback" },
{ "*** unregister callback for $str1" })
}
fun logUserRequestedUnlock(
requestOrigin: ActiveUnlockConfig.ACTIVE_UNLOCK_REQUEST_ORIGIN,
reason: String,
dismissKeyguard: Boolean
) {
logBuffer.log("ActiveUnlock", DEBUG, {
str1 = requestOrigin.name
str2 = reason
bool1 = dismissKeyguard
}, { "reportUserRequestedUnlock origin=$str1 reason=$str2 dismissKeyguard=$bool1" })
}
}

View File

@@ -0,0 +1,4 @@
package com.android.systemui.log.dagger
/** A [com.android.systemui.log.LogBuffer] for KeyguardUpdateMonitor. */
annotation class KeyguardUpdateMonitorLog

View File

@@ -277,4 +277,14 @@ public class LogModule {
public static LogBuffer provideStatusBarNetworkControllerBuffer(LogBufferFactory factory) { public static LogBuffer provideStatusBarNetworkControllerBuffer(LogBufferFactory factory) {
return factory.create("StatusBarNetworkControllerLog", 20); return factory.create("StatusBarNetworkControllerLog", 20);
} }
/**
* Provides a {@link LogBuffer} for use by {@link com.android.keyguard.KeyguardUpdateMonitor}.
*/
@Provides
@SysUISingleton
@KeyguardUpdateMonitorLog
public static LogBuffer provideKeyguardUpdateMonitorLogBuffer(LogBufferFactory factory) {
return factory.create("KeyguardUpdateMonitorLog", 200);
}
} }

View File

@@ -86,6 +86,7 @@ import com.android.internal.util.LatencyTracker;
import com.android.internal.widget.ILockSettings; import com.android.internal.widget.ILockSettings;
import com.android.internal.widget.LockPatternUtils; import com.android.internal.widget.LockPatternUtils;
import com.android.keyguard.KeyguardUpdateMonitor.BiometricAuthenticated; import com.android.keyguard.KeyguardUpdateMonitor.BiometricAuthenticated;
import com.android.keyguard.logging.KeyguardUpdateMonitorLogger;
import com.android.systemui.SysuiTestCase; import com.android.systemui.SysuiTestCase;
import com.android.systemui.biometrics.AuthController; import com.android.systemui.biometrics.AuthController;
import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.broadcast.BroadcastDispatcher;
@@ -179,6 +180,8 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
private KeyguardUpdateMonitorCallback mTestCallback; private KeyguardUpdateMonitorCallback mTestCallback;
@Mock @Mock
private ActiveUnlockConfig mActiveUnlockConfig; private ActiveUnlockConfig mActiveUnlockConfig;
@Mock
private KeyguardUpdateMonitorLogger mKeyguardUpdateMonitorLogger;
// Direct executor // Direct executor
private Executor mBackgroundExecutor = Runnable::run; private Executor mBackgroundExecutor = Runnable::run;
private Executor mMainExecutor = Runnable::run; private Executor mMainExecutor = Runnable::run;
@@ -1189,7 +1192,8 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
mBackgroundExecutor, mMainExecutor, mBackgroundExecutor, mMainExecutor,
mStatusBarStateController, mLockPatternUtils, mStatusBarStateController, mLockPatternUtils,
mAuthController, mTelephonyListenerManager, mAuthController, mTelephonyListenerManager,
mInteractionJankMonitor, mLatencyTracker, mActiveUnlockConfig); mInteractionJankMonitor, mLatencyTracker, mActiveUnlockConfig,
mKeyguardUpdateMonitorLogger);
setStrongAuthTracker(KeyguardUpdateMonitorTest.this.mStrongAuthTracker); setStrongAuthTracker(KeyguardUpdateMonitorTest.this.mStrongAuthTracker);
} }