Merge "Hide next button when max fingerprints enrolled"

This commit is contained in:
TreeHugger Robot
2016-12-15 22:57:26 +00:00
committed by Android (Google) Code Review
4 changed files with 149 additions and 1 deletions

View File

@@ -35,6 +35,12 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/security_settings_fingerprint_enroll_introduction_message" /> android:text="@string/security_settings_fingerprint_enroll_introduction_message" />
<com.android.setupwizardlib.view.RichTextView
android:id="@+id/error_text"
style="@style/SuwDescription.Glif"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@@ -866,6 +866,10 @@
<!-- Text shown when "Add fingerprint" button is disabled --> <!-- Text shown when "Add fingerprint" button is disabled -->
<string name="fingerprint_add_max">You can add up to <xliff:g id="count" example="5">%d</xliff:g> fingerprints</string> <string name="fingerprint_add_max">You can add up to <xliff:g id="count" example="5">%d</xliff:g> fingerprints</string>
<!-- Text shown when users has enrolled a maximum number of fingerprints [CHAR LIMIT=NONE] -->
<string name="fingerprint_intro_error_max">You\u2019ve added the maximum number of fingerprints</string>
<!-- Text shown when an unknown error caused the device to be unable to add fingerprints [CHAR LIMIT=NONE] -->
<string name="fingerprint_intro_error_unknown">Can\u2019t add more fingerprints</string>
<!-- Title shown in a dialog which asks the user to confirm when the last fingerprint gets deleted by him. [CHAR LIMIT=50]--> <!-- Title shown in a dialog which asks the user to confirm when the last fingerprint gets deleted by him. [CHAR LIMIT=50]-->
<string name="fingerprint_last_delete_title">Remove all fingerprints?</string> <string name="fingerprint_last_delete_title">Remove all fingerprints?</string>

View File

@@ -52,6 +52,7 @@ public class FingerprintEnrollIntroduction extends FingerprintEnrollBase
private UserManager mUserManager; private UserManager mUserManager;
private boolean mHasPassword; private boolean mHasPassword;
private boolean mFingerprintUnlockDisabledByAdmin; private boolean mFingerprintUnlockDisabledByAdmin;
private TextView mErrorText;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@@ -67,13 +68,41 @@ public class FingerprintEnrollIntroduction extends FingerprintEnrollBase
setHeaderText(R.string.security_settings_fingerprint_enroll_introduction_title); setHeaderText(R.string.security_settings_fingerprint_enroll_introduction_title);
} }
final Button cancelButton = (Button) findViewById(R.id.fingerprint_cancel_button); Button cancelButton = (Button) findViewById(R.id.fingerprint_cancel_button);
cancelButton.setOnClickListener(this); cancelButton.setOnClickListener(this);
mErrorText = (TextView) findViewById(R.id.error_text);
mUserManager = UserManager.get(this); mUserManager = UserManager.get(this);
updatePasswordQuality(); updatePasswordQuality();
} }
@Override
protected void onResume() {
super.onResume();
final FingerprintManager fingerprintManager = Utils.getFingerprintManagerOrNull(this);
int errorMsg = 0;
if (fingerprintManager != null) {
final int max = getResources().getInteger(
com.android.internal.R.integer.config_fingerprintMaxTemplatesPerUser);
final int numEnrolledFingerprints =
fingerprintManager.getEnrolledFingerprints(mUserId).size();
if (numEnrolledFingerprints >= max) {
errorMsg = R.string.fingerprint_intro_error_max;
}
} else {
errorMsg = R.string.fingerprint_intro_error_unknown;
}
if (errorMsg == 0) {
mErrorText.setText(null);
getNextButton().setVisibility(View.VISIBLE);
} else {
mErrorText.setText(errorMsg);
getNextButton().setVisibility(View.GONE);
}
}
private void updatePasswordQuality() { private void updatePasswordQuality() {
final int passwordQuality = new ChooseLockSettingsHelper(this).utils() final int passwordQuality = new ChooseLockSettingsHelper(this).utils()
.getActivePasswordQuality(mUserManager.getCredentialOwnerProfile(mUserId)); .getActivePasswordQuality(mUserManager.getCredentialOwnerProfile(mUserId));

View File

@@ -0,0 +1,109 @@
/*
* Copyright (C) 2016 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 org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.doReturn;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.hardware.fingerprint.Fingerprint;
import android.hardware.fingerprint.FingerprintManager;
import android.test.ActivityUnitTestCase;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.android.settings.R;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.util.ArrayList;
import java.util.List;
public class FingerprintEnrollIntroductionTest
extends ActivityUnitTestCase<FingerprintEnrollIntroduction> {
private TestContext mContext;
@Mock
private FingerprintManager mFingerprintManager;
private FingerprintEnrollIntroduction mActivity;
public FingerprintEnrollIntroductionTest() {
super(FingerprintEnrollIntroduction.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
MockitoAnnotations.initMocks(this);
mContext = new TestContext(getInstrumentation().getTargetContext());
setActivityContext(mContext);
getInstrumentation().runOnMainSync(() -> {
final Intent intent = new Intent();
mActivity = startActivity(intent,
null /* savedInstanceState */, null /* lastNonConfigurationInstance */);
});
}
public void testMaxFingerprint_shouldShowErrorMessage() {
final int max = mContext.getResources().getInteger(
com.android.internal.R.integer.config_fingerprintMaxTemplatesPerUser);
doReturn(generateFingerprintList(max)).when(mFingerprintManager)
.getEnrolledFingerprints(anyInt());
getInstrumentation().runOnMainSync(() -> {
getInstrumentation().callActivityOnCreate(mActivity, null);
getInstrumentation().callActivityOnResume(mActivity);
});
final TextView errorTextView = (TextView) mActivity.findViewById(R.id.error_text);
assertNotNull(errorTextView.getText().toString());
final Button nextButton = (Button) mActivity.findViewById(R.id.fingerprint_next_button);
assertEquals(View.GONE, nextButton.getVisibility());
}
private List<Fingerprint> generateFingerprintList(int num) {
ArrayList<Fingerprint> list = new ArrayList<>();
for (int i = 0; i < num; i++) {
list.add(new Fingerprint("Fingerprint " + i, 0, i, 0));
}
return list;
}
public class TestContext extends ContextWrapper {
public TestContext(Context base) {
super(base);
}
@Override
public Object getSystemService(String name) {
if (Context.FINGERPRINT_SERVICE.equals(name)) {
return mFingerprintManager;
}
return super.getSystemService(name);
}
}
}