diff --git a/src/com/android/settings/password/ChooseLockGeneric.java b/src/com/android/settings/password/ChooseLockGeneric.java index f55d65c165b..81d5036a740 100644 --- a/src/com/android/settings/password/ChooseLockGeneric.java +++ b/src/com/android/settings/password/ChooseLockGeneric.java @@ -297,7 +297,8 @@ public class ChooseLockGeneric extends SettingsActivity { getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE); // Can only run during setup if factory reset protection has already been cleared - return (pdbm != null && pdbm.getDataBlockSize() == 0); + // or if the device does not support FRP. + return (pdbm == null || pdbm.getDataBlockSize() == 0); } protected Class getInternalActivityClass() { diff --git a/tests/robotests/src/com/android/settings/password/ChooseLockGenericTest.java b/tests/robotests/src/com/android/settings/password/ChooseLockGenericTest.java index b535bc142d3..036df2cea8b 100644 --- a/tests/robotests/src/com/android/settings/password/ChooseLockGenericTest.java +++ b/tests/robotests/src/com/android/settings/password/ChooseLockGenericTest.java @@ -34,6 +34,7 @@ import static org.robolectric.Shadows.shadowOf; import android.app.Activity; import android.app.admin.DevicePolicyManager; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.provider.Settings.Global; @@ -48,7 +49,6 @@ import com.android.settings.biometrics.BiometricEnrollBase; import com.android.settings.password.ChooseLockGeneric.ChooseLockGenericFragment; import com.android.settings.search.SearchFeatureProvider; import com.android.settings.testutils.shadow.ShadowLockPatternUtils; -import com.android.settings.testutils.shadow.ShadowPersistentDataBlockManager; import com.android.settings.testutils.shadow.ShadowStorageManager; import com.android.settings.testutils.shadow.ShadowUserManager; import com.android.settings.testutils.shadow.ShadowUtils; @@ -62,6 +62,8 @@ import org.junit.runner.RunWith; import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; +import org.robolectric.shadows.ShadowApplication; +import org.robolectric.shadows.ShadowPersistentDataBlockManager; @RunWith(RobolectricTestRunner.class) @Config( @@ -99,6 +101,17 @@ public class ChooseLockGenericTest { assertThat(mActivity.isFinishing()).isTrue(); } + @Test + public void onCreate_deviceNotProvisioned_persistentDataServiceNotAvailable_shouldNotFinish() { + Global.putInt(application.getContentResolver(), Global.DEVICE_PROVISIONED, 0); + ShadowPersistentDataBlockManager.setDataBlockSize(1000); + ShadowApplication.getInstance().setSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE, + null); + + initActivity(null); + assertThat(mActivity.isFinishing()).isFalse(); + } + @Test public void onActivityResult_nullIntentData_shouldNotCrash() { initActivity(null); diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowPersistentDataBlockManager.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowPersistentDataBlockManager.java deleted file mode 100644 index dbbdd3d57de..00000000000 --- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowPersistentDataBlockManager.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2020 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.settings.testutils.shadow; - -import android.service.persistentdata.PersistentDataBlockManager; - -import org.robolectric.annotation.Implementation; -import org.robolectric.annotation.Implements; -import org.robolectric.annotation.Resetter; - -@Implements(PersistentDataBlockManager.class) -public class ShadowPersistentDataBlockManager { - private static int sDataBlockSize = 0; - - @Resetter - public static void reset() { - sDataBlockSize = 0; - } - - @Implementation - protected int getDataBlockSize() { - return sDataBlockSize; - } - - public static void setDataBlockSize(int dataBlockSize) { - sDataBlockSize = dataBlockSize; - } -}