Merge changes from topic "au-initial-commit-master"
* changes: Update text when Active Unlock is enabled. Update tile summary from ContentProvider. Add Active Unlock tile under face & fingerprint Add ActiveUnlock check when picking preference
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.biometrics.activeunlock;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.robolectric.shadows.ShadowLooper.idleMainLooper;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.settings.biometrics.activeunlock.ActiveUnlockContentListener.OnContentChangedListener;
|
||||
import com.android.settings.testutils.ActiveUnlockTestUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowDeviceConfig.class})
|
||||
public class ActiveUnlockContentListenerTest {
|
||||
|
||||
@Rule public final MockitoRule mMocks = MockitoJUnit.rule();
|
||||
@Mock private PackageManager mPackageManager;
|
||||
|
||||
private Context mContext;
|
||||
private ActiveUnlockContentListener mContentListener;
|
||||
@Nullable private String mContent;
|
||||
private int mUpdateCount;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
Robolectric.setupContentProvider(
|
||||
FakeContentProvider.class, FakeContentProvider.AUTHORITY);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
OnContentChangedListener listener = new OnContentChangedListener() {
|
||||
@Override
|
||||
public void onContentChanged(String newValue) {
|
||||
mContent = newValue;
|
||||
mUpdateCount++;
|
||||
}
|
||||
};
|
||||
ActiveUnlockTestUtils.enable(mContext);
|
||||
mContentListener =
|
||||
new ActiveUnlockContentListener(
|
||||
mContext,
|
||||
listener,
|
||||
"logTag",
|
||||
FakeContentProvider.METHOD_SUMMARY,
|
||||
FakeContentProvider.KEY_SUMMARY);
|
||||
FakeContentProvider.init(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subscribe_contentFetched() {
|
||||
String newContent = "newContent";
|
||||
FakeContentProvider.setTileSummary(newContent);
|
||||
|
||||
mContentListener.subscribe();
|
||||
idleMainLooper();
|
||||
|
||||
assertThat(mContent).isEqualTo(newContent);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentUpdated_contentUpdated() {
|
||||
mContentListener.subscribe();
|
||||
idleMainLooper();
|
||||
|
||||
String newContent = "newContent";
|
||||
updateContent(newContent);
|
||||
|
||||
assertThat(mContent).isEqualTo(newContent);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentUpdated_unsubscribed_contentNotUpdated() {
|
||||
mContentListener.subscribe();
|
||||
idleMainLooper();
|
||||
|
||||
mContentListener.unsubscribe();
|
||||
updateContent("newContent");
|
||||
|
||||
assertThat(mContent).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleContentUpdates_contentIsNewestValueAndUpdatedTwice() {
|
||||
mContentListener.subscribe();
|
||||
idleMainLooper();
|
||||
|
||||
updateContent("temporaryContent");
|
||||
String newContent = "newContent";
|
||||
updateContent(newContent);
|
||||
|
||||
assertThat(mContent).isEqualTo(newContent);
|
||||
assertThat(mUpdateCount).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void duplicateContentUpdates_onContentChangedOnlyCalledOnce() {
|
||||
mContentListener.subscribe();
|
||||
idleMainLooper();
|
||||
|
||||
updateContent("newContent");
|
||||
updateContent("newContent");
|
||||
|
||||
assertThat(mUpdateCount).isEqualTo(1);
|
||||
}
|
||||
|
||||
private void updateContent(String content) {
|
||||
FakeContentProvider.setTileSummary(content);
|
||||
mContext.getContentResolver().notifyChange(
|
||||
FakeContentProvider.URI, null /* observer */);
|
||||
idleMainLooper();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.biometrics.activeunlock;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.robolectric.shadows.ShadowLooper.idleMainLooper;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.hardware.face.FaceManager;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.os.UserManager;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.testutils.ActiveUnlockTestUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowDeviceConfig.class})
|
||||
public class ActiveUnlockStatusPreferenceControllerTest {
|
||||
|
||||
@Rule public final MockitoRule mMocks = MockitoJUnit.rule();
|
||||
|
||||
@Mock private UserManager mUserManager;
|
||||
@Mock private PackageManager mPackageManager;
|
||||
@Mock private FingerprintManager mFingerprintManager;
|
||||
@Mock private FaceManager mFaceManager;
|
||||
@Mock private PreferenceScreen mPreferenceScreen;
|
||||
|
||||
private Context mContext;
|
||||
private ActiveUnlockStatusPreferenceController mController;
|
||||
private RestrictedPreference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
Robolectric.setupContentProvider(FakeContentProvider.class, FakeContentProvider.AUTHORITY);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)).thenReturn(true);
|
||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(true);
|
||||
ShadowApplication.getInstance()
|
||||
.setSystemService(Context.FINGERPRINT_SERVICE, mFingerprintManager);
|
||||
ShadowApplication.getInstance().setSystemService(Context.FACE_SERVICE, mFaceManager);
|
||||
ShadowApplication.getInstance().setSystemService(Context.USER_SERVICE, mUserManager);
|
||||
when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {1234});
|
||||
mPreference = new RestrictedPreference(mContext);
|
||||
when(mPreferenceScreen.findPreference(any())).thenReturn(mPreference);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
ActiveUnlockTestUtils.enable(mContext);
|
||||
FakeContentProvider.init(mContext);
|
||||
mController = new ActiveUnlockStatusPreferenceController(mContext);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ActiveUnlockTestUtils.disable(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_featureFlagDisabled_isNotVisible() {
|
||||
ActiveUnlockTestUtils.disable(mContext);
|
||||
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
|
||||
assertThat(mPreference.isVisible()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_withoutFingerprint_withoutFace_isNotVisible() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(false);
|
||||
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
|
||||
assertThat(mPreference.isVisible()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_withoutFingerprint_withFace_isVisible() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
|
||||
assertThat(mPreference.isVisible()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_withFingerprint_withoutFace_isVisible() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(false);
|
||||
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
|
||||
assertThat(mPreference.isVisible()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_withFingerprint_withFace_isVisible() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
|
||||
assertThat(mPreference.isVisible()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultState_summaryIsEmpty() {
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
|
||||
idleMainLooper();
|
||||
|
||||
assertThat(mPreference.getSummary().toString()).isEqualTo(" ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStart_summaryIsUpdated() {
|
||||
String summary = "newSummary";
|
||||
updateSummary(summary);
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
|
||||
mController.onStart();
|
||||
idleMainLooper();
|
||||
|
||||
assertThat(mPreference.getSummary().toString()).isEqualTo(summary);
|
||||
}
|
||||
|
||||
private void updateSummary(String summary) {
|
||||
FakeContentProvider.setTileSummary(summary);
|
||||
mContext.getContentResolver().notifyChange(FakeContentProvider.URI, null /* observer */);
|
||||
idleMainLooper();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.biometrics.activeunlock;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.hardware.face.FaceManager;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.ActiveUnlockTestUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowDeviceConfig.class})
|
||||
public class ActiveUnlockStatusUtilsTest {
|
||||
|
||||
@Rule public final MockitoRule mMocks = MockitoJUnit.rule();
|
||||
|
||||
@Mock private PackageManager mPackageManager;
|
||||
@Mock private FingerprintManager mFingerprintManager;
|
||||
@Mock private FaceManager mFaceManager;
|
||||
|
||||
private Context mApplicationContext;
|
||||
private ActiveUnlockStatusUtils mActiveUnlockStatusUtils;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mApplicationContext = spy(ApplicationProvider.getApplicationContext());
|
||||
when(mApplicationContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)).thenReturn(true);
|
||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(true);
|
||||
when(mApplicationContext.getSystemService(Context.FINGERPRINT_SERVICE))
|
||||
.thenReturn(mFingerprintManager);
|
||||
when(mApplicationContext.getSystemService(Context.FACE_SERVICE)).thenReturn(mFaceManager);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
ActiveUnlockTestUtils.enable(mApplicationContext);
|
||||
mActiveUnlockStatusUtils = new ActiveUnlockStatusUtils(mApplicationContext);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ActiveUnlockTestUtils.disable(mApplicationContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_featureFlagDisabled_returnsConditionallyUnavailable() {
|
||||
ActiveUnlockTestUtils.disable(mApplicationContext);
|
||||
|
||||
assertThat(mActiveUnlockStatusUtils.getAvailability()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_withoutFingerprint_withoutFace_returnsUnsupported() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(false);
|
||||
|
||||
assertThat(mActiveUnlockStatusUtils.getAvailability()).isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_withoutFingerprint_withFace_returnsAvailable() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
|
||||
assertThat(mActiveUnlockStatusUtils.getAvailability()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_withFingerprint_withoutFace_returnsAvailable() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(false);
|
||||
|
||||
assertThat(mActiveUnlockStatusUtils.getAvailability()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_withFingerprint_withFace_returnsAvailable() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
|
||||
assertThat(mActiveUnlockStatusUtils.getAvailability()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configIsUnlockOnIntent_useUnlockIntentLayoutIsTrue() {
|
||||
ActiveUnlockTestUtils.enable(
|
||||
mApplicationContext, ActiveUnlockStatusUtils.UNLOCK_INTENT_LAYOUT);
|
||||
|
||||
assertThat(mActiveUnlockStatusUtils.useUnlockIntentLayout()).isTrue();
|
||||
assertThat(mActiveUnlockStatusUtils.useBiometricFailureLayout()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configIsBiometricFailure_useBiometricFailureLayoutIsTrue() {
|
||||
ActiveUnlockTestUtils.enable(
|
||||
mApplicationContext, ActiveUnlockStatusUtils.BIOMETRIC_FAILURE_LAYOUT);
|
||||
|
||||
assertThat(mActiveUnlockStatusUtils.useUnlockIntentLayout()).isFalse();
|
||||
assertThat(mActiveUnlockStatusUtils.useBiometricFailureLayout()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTitle_faceEnabled_returnsFacePreferenceTitle() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
|
||||
assertThat(mActiveUnlockStatusUtils.getTitleForActiveUnlock())
|
||||
.isEqualTo(mApplicationContext.getString(
|
||||
R.string.security_settings_face_preference_title));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTitle_fingerprintEnabled_returnsFingerprintPreferenceTitle() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(false);
|
||||
|
||||
assertThat(mActiveUnlockStatusUtils.getTitleForActiveUnlock())
|
||||
.isEqualTo(mApplicationContext.getString(
|
||||
R.string.security_settings_fingerprint_preference_title));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getIntro_faceEnabled_returnsIntroWithFace() {
|
||||
ActiveUnlockTestUtils.enable(
|
||||
mApplicationContext, ActiveUnlockStatusUtils.BIOMETRIC_FAILURE_LAYOUT);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
|
||||
assertThat(mActiveUnlockStatusUtils.getIntroForActiveUnlock())
|
||||
.isEqualTo(mApplicationContext.getString(
|
||||
R.string.biometric_settings_intro_with_face));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getIntro_fingerprintEnabled_returnsIntroWithFingerprint() {
|
||||
ActiveUnlockTestUtils.enable(
|
||||
mApplicationContext, ActiveUnlockStatusUtils.BIOMETRIC_FAILURE_LAYOUT);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(false);
|
||||
|
||||
assertThat(mActiveUnlockStatusUtils.getIntroForActiveUnlock())
|
||||
.isEqualTo(mApplicationContext.getString(
|
||||
R.string.biometric_settings_intro_with_fingerprint));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getIntro_unlockOnIntentAndFaceEnabled_returnsEmpty() {
|
||||
ActiveUnlockTestUtils.enable(
|
||||
mApplicationContext, ActiveUnlockStatusUtils.UNLOCK_INTENT_LAYOUT);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(false);
|
||||
|
||||
assertThat(mActiveUnlockStatusUtils.getIntroForActiveUnlock()).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getIntro_unlockOnIntentAndFaceAndFingerprintEnabled_returnsDefault() {
|
||||
ActiveUnlockTestUtils.enable(
|
||||
mApplicationContext, ActiveUnlockStatusUtils.UNLOCK_INTENT_LAYOUT);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
|
||||
assertThat(mActiveUnlockStatusUtils.getIntroForActiveUnlock())
|
||||
.isEqualTo(mApplicationContext.getString(
|
||||
R.string.biometric_settings_intro));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUnlockDeviceSummary_fingerprintEnabled_returnsFingerprintOrWatch() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(false);
|
||||
|
||||
assertThat(mActiveUnlockStatusUtils.getUnlockDeviceSummaryForActiveUnlock())
|
||||
.isEqualTo(mApplicationContext.getString(
|
||||
R.string.biometric_settings_use_fingerprint_or_watch_preference_summary));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUnlockDeviceSummary_faceEnabled_returnsFaceOrWatch() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
|
||||
assertThat(mActiveUnlockStatusUtils.getUnlockDeviceSummaryForActiveUnlock())
|
||||
.isEqualTo(mApplicationContext.getString(
|
||||
R.string.biometric_settings_use_face_or_watch_preference_summary));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.biometrics.activeunlock;
|
||||
|
||||
import android.content.ContentProvider;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.settings.testutils.ActiveUnlockTestUtils;
|
||||
|
||||
/** ContentProvider to provider tile summary for ActiveUnlock in tests. */
|
||||
public final class FakeContentProvider extends ContentProvider {
|
||||
public static final String AUTHORITY = ActiveUnlockTestUtils.PROVIDER;
|
||||
public static final Uri URI = new Uri.Builder()
|
||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||
.authority(AUTHORITY)
|
||||
.appendPath("getSummary")
|
||||
.build();
|
||||
public static final String METHOD_SUMMARY = "getSummary";
|
||||
public static final String KEY_SUMMARY = "com.android.settings.summary";
|
||||
private static final String METHOD_DEVICE_NAME = "getDeviceName";
|
||||
private static final String KEY_DEVICE_NAME = "com.android.settings.active_unlock.device_name";
|
||||
@Nullable private static String sTileSummary;
|
||||
@Nullable private static String sDeviceName;
|
||||
|
||||
public FakeContentProvider() {
|
||||
super();
|
||||
}
|
||||
|
||||
public static void setTileSummary(String summary) {
|
||||
sTileSummary = summary;
|
||||
}
|
||||
|
||||
public static void setDeviceName(String deviceName) {
|
||||
sDeviceName = deviceName;
|
||||
}
|
||||
|
||||
public static void init(Context context) {
|
||||
Settings.Secure.putString(
|
||||
context.getContentResolver(), ActiveUnlockTestUtils.PROVIDER_SETTING, AUTHORITY);
|
||||
sTileSummary = null;
|
||||
sDeviceName = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bundle call(String method, String arg, Bundle extras) {
|
||||
Bundle bundle = new Bundle();
|
||||
if (METHOD_SUMMARY.equals(method)) {
|
||||
bundle.putCharSequence(KEY_SUMMARY, sTileSummary);
|
||||
} else if (METHOD_DEVICE_NAME.equals(method)) {
|
||||
bundle.putCharSequence(KEY_DEVICE_NAME, sDeviceName);
|
||||
}
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor query(Uri uri, String[] projection, String selection,
|
||||
String[] selectionArgs, String sortOrder) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uri insert(Uri uri, ContentValues values) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(Uri uri, ContentValues values, String selection,
|
||||
String[] selectionArgs) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(Uri uri, String selection, String[] selectionArgs) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType(Uri uri) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.biometrics.combination;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.hardware.face.FaceManager;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.settings.testutils.ActiveUnlockTestUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowDeviceConfig.class})
|
||||
public class BiometricFaceStatusPreferenceControllerTest {
|
||||
|
||||
@Rule public final MockitoRule mMocks = MockitoJUnit.rule();
|
||||
|
||||
@Mock private UserManager mUserManager;
|
||||
@Mock private PackageManager mPackageManager;
|
||||
@Mock private FingerprintManager mFingerprintManager;
|
||||
@Mock private FaceManager mFaceManager;
|
||||
|
||||
private Context mContext;
|
||||
private RestrictedPreference mPreference;
|
||||
private BiometricFaceStatusPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)).thenReturn(true);
|
||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(true);
|
||||
ShadowApplication.getInstance()
|
||||
.setSystemService(Context.FINGERPRINT_SERVICE, mFingerprintManager);
|
||||
ShadowApplication.getInstance().setSystemService(Context.FACE_SERVICE, mFaceManager);
|
||||
ShadowApplication.getInstance().setSystemService(Context.USER_SERVICE, mUserManager);
|
||||
when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {1234});
|
||||
mPreference = new RestrictedPreference(mContext);
|
||||
mController = new BiometricFaceStatusPreferenceController(mContext, "preferenceKey");
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ActiveUnlockTestUtils.disable(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onlyFaceEnabled_preferenceNotVisible() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isVisible()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onlyFaceAndActiveUnlockEnabled_preferenceVisible() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
ActiveUnlockTestUtils.enable(mContext);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isVisible()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void faceAndFingerprintEnabled_preferenceVisible() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isVisible()).isTrue();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.biometrics.combination;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.hardware.face.FaceManager;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.settings.testutils.ActiveUnlockTestUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowDeviceConfig.class})
|
||||
public class BiometricFingerprintStatusPreferenceControllerTest {
|
||||
|
||||
@Rule public final MockitoRule mMocks = MockitoJUnit.rule();
|
||||
|
||||
@Mock private UserManager mUserManager;
|
||||
@Mock private PackageManager mPackageManager;
|
||||
@Mock private FingerprintManager mFingerprintManager;
|
||||
@Mock private FaceManager mFaceManager;
|
||||
|
||||
private Context mContext;
|
||||
private RestrictedPreference mPreference;
|
||||
private BiometricFingerprintStatusPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)).thenReturn(true);
|
||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(true);
|
||||
ShadowApplication.getInstance()
|
||||
.setSystemService(Context.FINGERPRINT_SERVICE, mFingerprintManager);
|
||||
ShadowApplication.getInstance().setSystemService(Context.FACE_SERVICE, mFaceManager);
|
||||
ShadowApplication.getInstance().setSystemService(Context.USER_SERVICE, mUserManager);
|
||||
when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {1234});
|
||||
mPreference = new RestrictedPreference(mContext);
|
||||
mController = new BiometricFingerprintStatusPreferenceController(mContext, "preferenceKey");
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ActiveUnlockTestUtils.disable(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onlyFingerprintEnabled_preferenceNotVisible() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(false);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isVisible()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onlyFingerprintAndActiveUnlockEnabled_preferenceVisible() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(false);
|
||||
ActiveUnlockTestUtils.enable(mContext);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isVisible()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void faceAndFingerprintEnabled_preferenceVisible() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isVisible()).isTrue();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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;
|
||||
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.anyInt;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ProviderInfo;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.provider.DeviceConfig;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.biometrics.activeunlock.ActiveUnlockStatusUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/** Utilities class to enable or disable the Active Unlock flag in tests. */
|
||||
public final class ActiveUnlockTestUtils {
|
||||
|
||||
public static final String TARGET = "com.active.unlock.target";
|
||||
public static final String PROVIDER = "com.active.unlock.provider";
|
||||
public static final String TARGET_SETTING = "active_unlock_target";
|
||||
public static final String PROVIDER_SETTING = "active_unlock_provider";
|
||||
|
||||
public static void enable(Context context) {
|
||||
ActiveUnlockTestUtils.enable(context, ActiveUnlockStatusUtils.UNLOCK_INTENT_LAYOUT);
|
||||
}
|
||||
|
||||
public static void enable(Context context, String flagValue) {
|
||||
Settings.Secure.putString(
|
||||
context.getContentResolver(), TARGET_SETTING, TARGET);
|
||||
Settings.Secure.putString(
|
||||
context.getContentResolver(), PROVIDER_SETTING, PROVIDER);
|
||||
|
||||
PackageManager packageManager = context.getPackageManager();
|
||||
ApplicationInfo applicationInfo = new ApplicationInfo();
|
||||
applicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
|
||||
|
||||
ResolveInfo resolveInfo = new ResolveInfo();
|
||||
resolveInfo.activityInfo = new ActivityInfo();
|
||||
resolveInfo.activityInfo.applicationInfo = applicationInfo;
|
||||
when(packageManager.resolveActivity(any(), anyInt())).thenReturn(resolveInfo);
|
||||
|
||||
PackageInfo packageInfo = new PackageInfo();
|
||||
packageInfo.applicationInfo = applicationInfo;
|
||||
ProviderInfo providerInfo = new ProviderInfo();
|
||||
providerInfo.authority = PROVIDER;
|
||||
providerInfo.applicationInfo = applicationInfo;
|
||||
packageInfo.providers = new ProviderInfo[] { providerInfo };
|
||||
ArrayList<PackageInfo> packageInfos = new ArrayList<>();
|
||||
packageInfos.add(packageInfo);
|
||||
when(packageManager.getInstalledPackages(any())).thenReturn(packageInfos);
|
||||
|
||||
DeviceConfig.setProperty(
|
||||
DeviceConfig.NAMESPACE_REMOTE_AUTH,
|
||||
ActiveUnlockStatusUtils.CONFIG_FLAG_NAME,
|
||||
flagValue,
|
||||
false /* makeDefault */);
|
||||
}
|
||||
|
||||
public static void disable(Context context) {
|
||||
DeviceConfig.setProperty(
|
||||
DeviceConfig.NAMESPACE_REMOTE_AUTH,
|
||||
ActiveUnlockStatusUtils.CONFIG_FLAG_NAME,
|
||||
null /* value */,
|
||||
false /* makeDefault */);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user