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

Commit 29a37648 authored by Eric Sandness's avatar Eric Sandness Committed by Automerger Merge Worker
Browse files

Use ChooseLockGeneric When Started By Admin App am: 74309323

Change-Id: I1a2cacc0c556b9ebdedf579ffe8516b7851f02dd
parents d9dcf5be 74309323
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.storage.StorageManager;
import android.service.persistentdata.PersistentDataBlockManager;
import android.text.TextUtils;
import android.util.EventLog;
import android.util.Log;
@@ -281,7 +282,11 @@ public class ChooseLockGeneric extends SettingsActivity {
        }

        protected boolean canRunBeforeDeviceProvisioned() {
            return false;
            PersistentDataBlockManager pdbm = (PersistentDataBlockManager)
                    getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);

            // Can only run during setup if factory reset protection has already been cleared
            return (pdbm != null && pdbm.getDataBlockSize() == 0);
        }

        protected Class<? extends ChooseLockGeneric.InternalActivity> getInternalActivityClass() {
+1 −1
Original line number Diff line number Diff line
@@ -110,7 +110,7 @@ public class SetNewPasswordActivity extends Activity implements SetNewPasswordCo

    @Override
    public void launchChooseLock(Bundle chooseLockFingerprintExtras) {
        final boolean isInSetupWizard = !WizardManagerHelper.isDeviceProvisioned(this);
        final boolean isInSetupWizard = WizardManagerHelper.isAnySetupWizard(getIntent());
        Intent intent = isInSetupWizard ? new Intent(this, SetupChooseLockGeneric.class)
                : new Intent(this, ChooseLockGeneric.class);
        intent.setAction(mNewPasswordAction);
+17 −2
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import com.android.settings.biometrics.BiometricEnrollBase;
import com.android.settings.password.ChooseLockGeneric.ChooseLockGenericFragment;
import com.android.settings.search.SearchFeatureProvider;
import com.android.settings.testutils.shadow.ShadowLockPatternUtils;
import com.android.settings.testutils.shadow.ShadowPersistentDataBlockManager;
import com.android.settings.testutils.shadow.ShadowStorageManager;
import com.android.settings.testutils.shadow.ShadowUserManager;
import com.android.settings.testutils.shadow.ShadowUtils;
@@ -63,6 +64,7 @@ import org.robolectric.annotation.Config;
@Config(
        shadows = {
                ShadowLockPatternUtils.class,
                ShadowPersistentDataBlockManager.class,
                ShadowStorageManager.class,
                ShadowUserManager.class,
                ShadowUtils.class
@@ -82,11 +84,13 @@ public class ChooseLockGenericTest {
    public void tearDown() {
        Global.putInt(application.getContentResolver(), Global.DEVICE_PROVISIONED, 1);
        ShadowStorageManager.reset();
        ShadowPersistentDataBlockManager.reset();
    }

    @Test
    public void onCreate_deviceNotProvisioned_shouldFinishActivity() {
    public void onCreate_deviceNotProvisioned_persistentDataExists_shouldFinishActivity() {
        Global.putInt(application.getContentResolver(), Global.DEVICE_PROVISIONED, 0);
        ShadowPersistentDataBlockManager.setDataBlockSize(1000);

        initActivity(null);
        assertThat(mActivity.isFinishing()).isTrue();
@@ -191,7 +195,18 @@ public class ChooseLockGenericTest {
    }

    @Test
    public void updatePreferencesOrFinish_callingAppIsAdmin_footerInvisible() {
    public void updatePreferencesOrFinish_callingAppIsAdmin_deviceProvisioned_footerInvisible() {
        initActivity(new Intent().putExtra(EXTRA_KEY_IS_CALLING_APP_ADMIN, true));

        mFragment.updatePreferencesOrFinish(/* isRecreatingActivity= */ false);

        FooterPreference footer = mFragment.findPreference(KEY_LOCK_SETTINGS_FOOTER);
        assertThat(footer.isVisible()).isFalse();
    }

    @Test
    public void updatePreferencesOrFinish_callingAppIsAdmin_deviceNotProvisioned_footerInvisible() {
        Global.putInt(application.getContentResolver(), Global.DEVICE_PROVISIONED, 0);
        initActivity(new Intent().putExtra(EXTRA_KEY_IS_CALLING_APP_ADMIN, true));

        mFragment.updatePreferencesOrFinish(/* isRecreatingActivity= */ false);
+3 −0
Original line number Diff line number Diff line
@@ -45,6 +45,8 @@ import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.ShadowPasswordUtils;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;

import com.google.android.setupcompat.util.WizardManagerHelper;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -111,6 +113,7 @@ public class SetNewPasswordActivityTest {
        activity.launchChooseLock(new Bundle());
        ShadowActivity shadowActivity = Shadows.shadowOf(activity);
        Intent intent = getLaunchChooseLockIntent(shadowActivity);
        intent.putExtra(WizardManagerHelper.EXTRA_IS_FIRST_RUN, true);

        assertThat(intent.getComponent())
                .isEqualTo(new ComponentName(activity, SetupChooseLockGeneric.class));
+42 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.shadow;

import android.service.persistentdata.PersistentDataBlockManager;

import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.Resetter;

@Implements(PersistentDataBlockManager.class)
public class ShadowPersistentDataBlockManager {
    private static int sDataBlockSize = 0;

    @Resetter
    public static void reset() {
        sDataBlockSize = 0;
    }

    @Implementation
    protected int getDataBlockSize() {
        return sDataBlockSize;
    }

    public static void setDataBlockSize(int dataBlockSize) {
        sDataBlockSize = dataBlockSize;
    }
}