Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3e6d80c1 authored by Doris Ling's avatar Doris Ling
Browse files

Enable Skip fingerprint when adding corp account.

- override the internal activity for picking screen lock from setup
wizard, so that when adding corp account, it can skip fingerprint even
when device is not yet provisioned.

Change-Id: I9485c54d097c82a584297fcaeb63b3271e05c1b6
Fixes: 112706989
Test: atest com.android.settings.password.SetupChooseLockGenericTest
parent 6773c7ef
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -264,6 +264,10 @@ public class ChooseLockGeneric extends SettingsActivity {
            return false;
        }

        protected Class<? extends ChooseLockGeneric.InternalActivity> getInternalActivityClass() {
            return ChooseLockGeneric.InternalActivity.class;
        }

        protected void addHeaderView() {
            if (mForFingerprint) {
                setHeaderView(R.layout.choose_lock_generic_fingerprint_header);
@@ -291,7 +295,7 @@ public class ChooseLockGeneric extends SettingsActivity {
                return true;
            } else if (KEY_SKIP_FINGERPRINT.equals(key) || KEY_SKIP_FACE.equals(key)) {
                Intent chooseLockGenericIntent = new Intent(getActivity(),
                    ChooseLockGeneric.InternalActivity.class);
                    getInternalActivityClass());
                chooseLockGenericIntent.setAction(getIntent().getAction());
                // Forward the target user id to  ChooseLockGeneric.
                chooseLockGenericIntent.putExtra(Intent.EXTRA_USER_ID, mUserId);
+27 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.view.View;
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;
@@ -135,6 +136,11 @@ public class SetupChooseLockGeneric extends ChooseLockGeneric {
            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.
@@ -207,4 +213,25 @@ public class SetupChooseLockGeneric extends ChooseLockGeneric {
            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;
            }
        }
    }

}
+1 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ com.android.settings.notification.RedactionInterstitial$RedactionInterstitialFra
com.android.settings.notification.ZenModeEventRuleSettings
com.android.settings.notification.ZenModeScheduleRuleSettings
com.android.settings.password.ChooseLockGeneric$ChooseLockGenericFragment
com.android.settings.password.SetupChooseLockGeneric$InternalActivity$InternalSetupChooseLockGenericFragment
com.android.settings.password.SetupChooseLockGeneric$SetupChooseLockGenericFragment
com.android.settings.print.PrintJobSettingsFragment
com.android.settings.print.PrintServiceSettingsFragment
+96 −0
Original line number Diff line number Diff line
/*
 * 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];
    }

}