import android.view.ViewGroup;
import android.widget.LinearLayout;
+import androidx.fragment.app.Fragment;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.recyclerview.widget.RecyclerView;
return true;
}
+ @Override
+ protected Class<? extends ChooseLockGeneric.InternalActivity> getInternalActivityClass() {
+ return SetupChooseLockGeneric.InternalActivity.class;
+ }
+
/***
* Disables preferences that are less secure than required quality and shows only secure
* screen lock options here.
return intent;
}
}
+
+ public static class InternalActivity extends ChooseLockGeneric.InternalActivity {
+ @Override
+ protected boolean isValidFragment(String fragmentName) {
+ return InternalSetupChooseLockGenericFragment.class.getName().equals(fragmentName);
+ }
+
+ @Override
+ /* package */ Class<? extends Fragment> getFragmentClass() {
+ return InternalSetupChooseLockGenericFragment.class;
+ }
+
+ public static class InternalSetupChooseLockGenericFragment
+ extends ChooseLockGenericFragment {
+ @Override
+ protected boolean canRunBeforeDeviceProvisioned() {
+ return true;
+ }
+ }
+ }
+
}
--- /dev/null
+/*
+ * Copyright (C) 2018 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.password;
+
+import static android.app.admin.DevicePolicyManager.ACTION_SET_NEW_PASSWORD;
+import static android.support.test.InstrumentationRegistry.getInstrumentation;
+import static android.support.test.InstrumentationRegistry.getTargetContext;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.provider.Settings;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+import android.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry;
+import android.support.test.runner.lifecycle.Stage;
+import android.support.test.uiautomator.UiDevice;
+import android.support.test.uiautomator.UiSelector;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.Collection;
+
+/**
+ * Tests for {@link SetupChooseLockGenericTest}
+ *
+ */
+@RunWith(AndroidJUnit4.class)
+@SmallTest
+public class SetupChooseLockGenericTest {
+
+ private UiDevice mDevice;
+ private Context mContext;
+
+ @Before
+ public void setUp() throws Exception {
+ mDevice = UiDevice.getInstance(getInstrumentation());
+ mContext = getInstrumentation().getTargetContext();
+ Settings.Global.putInt(
+ mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0);
+ }
+
+ @After
+ public void tearDown() {
+ Settings.Global.putInt(
+ mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1);
+ }
+
+ @Test
+ public void clickSkipFigerprintPreference_deviceNotProvisioned_shouldBeAbleToProceed()
+ throws Throwable {
+ final Intent newPasswordIntent =
+ new Intent(getTargetContext(), SetupChooseLockGeneric.class)
+ .putExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, true)
+ .setAction(ACTION_SET_NEW_PASSWORD)
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
+
+ getInstrumentation().getContext().startActivity(newPasswordIntent);
+ mDevice.waitForIdle();
+ mDevice.findObject(new UiSelector().textContains("Continue without ")).click();
+
+ final Activity activity = getCurrentActivity();
+ assertThat(activity).isInstanceOf(SetupChooseLockGeneric.InternalActivity.class);
+ }
+
+ private Activity getCurrentActivity() throws Throwable {
+ getInstrumentation().waitForIdleSync();
+ final Activity[] activity = new Activity[1];
+ getInstrumentation().runOnMainSync(() -> {
+ Collection<Activity> activities = ActivityLifecycleMonitorRegistry.getInstance()
+ .getActivitiesInStage(Stage.RESUMED);
+ activity[0] = activities.iterator().next();
+ });
+ return activity[0];
+ }
+
+}