Allow skipping PIN setup screen
So that setup wizard can show PIN option by default.
Test: Added Robolectric and instrumentation tests
Bug: 38509560
Change-Id: Id72744dd444b9b026ca5f28f230bae3bec254b2f
(cherry picked from commit 0f897d79f6
)
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.fingerprint;
|
||||
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.robolectric.RuntimeEnvironment.application;
|
||||
|
||||
import android.app.KeyguardManager;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.password.SetupSkipDialog;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowEventLogWriter;
|
||||
import com.android.settings.testutils.shadow.ShadowLockPatternUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.Shadows;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowActivity;
|
||||
import org.robolectric.shadows.ShadowKeyguardManager;
|
||||
import org.robolectric.util.ActivityController;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(
|
||||
manifest = TestConfig.MANIFEST_PATH,
|
||||
sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {
|
||||
ShadowEventLogWriter.class,
|
||||
ShadowLockPatternUtils.class,
|
||||
ShadowUserManager.class
|
||||
})
|
||||
public class SetupFingerprintEnrollIntroductionTest {
|
||||
|
||||
@Mock
|
||||
private UserInfo mUserInfo;
|
||||
|
||||
private ActivityController<SetupFingerprintEnrollIntroduction> mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
final Intent intent = new Intent();
|
||||
mController = Robolectric.buildActivity(SetupFingerprintEnrollIntroduction.class, intent);
|
||||
|
||||
ShadowUserManager.getShadow().setUserInfo(0, mUserInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testKeyguardNotSecure_shouldFinishWithSetupSkipDialogResultSkip() {
|
||||
getShadowKeyguardManager().setIsKeyguardSecure(false);
|
||||
|
||||
mController.create().resume();
|
||||
|
||||
final Button skipButton = mController.get().findViewById(R.id.fingerprint_cancel_button);
|
||||
assertThat(skipButton.getVisibility()).named("Skip visible").isEqualTo(View.VISIBLE);
|
||||
skipButton.performClick();
|
||||
|
||||
ShadowActivity shadowActivity = Shadows.shadowOf(mController.get());
|
||||
assertThat(mController.get().isFinishing()).named("Is finishing").isTrue();
|
||||
assertThat(shadowActivity.getResultCode()).named("Result code")
|
||||
.isEqualTo(SetupSkipDialog.RESULT_SKIP);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testKeyguardSecure_shouldFinishWithFingerprintResultSkip() {
|
||||
getShadowKeyguardManager().setIsKeyguardSecure(true);
|
||||
|
||||
mController.create().resume();
|
||||
|
||||
final Button skipButton = mController.get().findViewById(R.id.fingerprint_cancel_button);
|
||||
assertThat(skipButton.getVisibility()).named("Skip visible").isEqualTo(View.VISIBLE);
|
||||
skipButton.performClick();
|
||||
|
||||
ShadowActivity shadowActivity = Shadows.shadowOf(mController.get());
|
||||
assertThat(mController.get().isFinishing()).named("Is finishing").isTrue();
|
||||
assertThat(shadowActivity.getResultCode()).named("Result code")
|
||||
.isEqualTo(FingerprintEnrollBase.RESULT_SKIP);
|
||||
}
|
||||
|
||||
private ShadowKeyguardManager getShadowKeyguardManager() {
|
||||
return Shadows.shadowOf(application.getSystemService(KeyguardManager.class));
|
||||
}
|
||||
}
|
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.testutils.shadow;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
@@ -27,4 +29,9 @@ public class ShadowLockPatternUtils {
|
||||
public boolean isSecure(int id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public int getActivePasswordQuality(int userId) {
|
||||
return DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
|
||||
}
|
||||
}
|
||||
|
@@ -16,11 +16,19 @@
|
||||
|
||||
package com.android.settings.testutils.shadow;
|
||||
|
||||
import android.annotation.UserIdInt;
|
||||
import android.content.Context;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.UserManager;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.internal.ShadowExtractor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class provides the API 24 implementation of UserManager.get(Context).
|
||||
@@ -28,8 +36,34 @@ import org.robolectric.annotation.Implements;
|
||||
@Implements(UserManager.class)
|
||||
public class ShadowUserManager {
|
||||
|
||||
private SparseArray<UserInfo> mUserInfos = new SparseArray<>();
|
||||
|
||||
public void setUserInfo(int userHandle, UserInfo userInfo) {
|
||||
mUserInfos.put(userHandle, userInfo);
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public UserInfo getUserInfo(int userHandle) {
|
||||
return mUserInfos.get(userHandle);
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public List<UserInfo> getProfiles(@UserIdInt int userHandle) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public int getCredentialOwnerProfile(@UserIdInt int userHandle) {
|
||||
return userHandle;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static UserManager get(Context context) {
|
||||
return (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
}
|
||||
|
||||
public static ShadowUserManager getShadow() {
|
||||
return (ShadowUserManager) ShadowExtractor.extract(
|
||||
RuntimeEnvironment.application.getSystemService(UserManager.class));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user