Allow the LockPatterUtils to be null

In some tests it could inconsistently become a null, crashing with NPE, for the reason I can't understand (maybe there is a race condition somewhere between mocking and accessing the LockPatterUtils in such tests)
Let's accept it gracefully

Test: atest SettingsUnitTests
Bug: 382637173
Flag: EXEMPT bugfix
Change-Id: I35d5faa1a29307fc780207a816680a32b2796bc0
This commit is contained in:
Yuri Ufimtsev
2025-02-04 14:57:33 +00:00
parent c32021846e
commit 55b7b0613d
3 changed files with 50 additions and 5 deletions

View File

@@ -23,6 +23,7 @@ import android.os.UserHandle;
import android.os.UserManager;
import android.os.storage.StorageManager;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import com.android.internal.app.UnlaunchableAppActivity;
@@ -43,6 +44,7 @@ public class ScreenLockPreferenceDetailsUtils {
private final int mUserId = UserHandle.myUserId();
private final Context mContext;
@Nullable
private final LockPatternUtils mLockPatternUtils;
private final int mProfileChallengeUserId;
private final UserManager mUm;
@@ -85,7 +87,7 @@ public class ScreenLockPreferenceDetailsUtils {
* Returns whether the lock pattern is secure.
*/
public boolean isLockPatternSecure() {
return mLockPatternUtils.isSecure(mUserId);
return mLockPatternUtils != null && mLockPatternUtils.isSecure(mUserId);
}
/**
@@ -148,6 +150,7 @@ public class ScreenLockPreferenceDetailsUtils {
// profile with unified challenge on FBE-enabled devices. Otherwise, vold would not be
// able to complete the operation due to the lack of (old) encryption key.
if (mProfileChallengeUserId != UserHandle.USER_NULL
&& mLockPatternUtils != null
&& !mLockPatternUtils.isSeparateProfileChallengeEnabled(mProfileChallengeUserId)
&& StorageManager.isFileEncrypted()) {
if (mUm.isQuietModeEnabled(UserHandle.of(mProfileChallengeUserId))) {
@@ -166,8 +169,12 @@ public class ScreenLockPreferenceDetailsUtils {
.toIntent();
}
@Nullable
@StringRes
private Integer getSummaryResId(int userId) {
if (mLockPatternUtils == null) {
return null;
}
if (!mLockPatternUtils.isSecure(userId)) {
if (userId == mProfileChallengeUserId
|| mLockPatternUtils.isLockScreenDisabled(userId)) {