Use ChooseLockGeneric When Started By Admin App

The device management app may run before the end of device provisioning,
and it may start SetNewPasswordActivity.  If this happens, use
ChooseLockGeneric instead of SetupChooseLockGeneric.  Only use
SetupChoseLockGeneric if SetNewPasswordActivity was started by Setup
Wizard itself.

Fixes: 151552453
Test: atest com.android.settings.password.SetNewPasswordActivityTest
Test: atest com.android.settings.password.ChooseLockGenericTest
Test: Manually run consumer and enterprise device setup
Change-Id: I3b479ed18211d6625654f266fe692f07d0047e4f
This commit is contained in:
Eric Sandness
2020-03-15 18:10:55 +00:00
parent f9b7313545
commit 7430932305
5 changed files with 69 additions and 4 deletions

View File

@@ -42,6 +42,7 @@ import android.os.Bundle;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
import android.os.storage.StorageManager; import android.os.storage.StorageManager;
import android.service.persistentdata.PersistentDataBlockManager;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.EventLog; import android.util.EventLog;
import android.util.Log; import android.util.Log;
@@ -281,7 +282,11 @@ public class ChooseLockGeneric extends SettingsActivity {
} }
protected boolean canRunBeforeDeviceProvisioned() { 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() { protected Class<? extends ChooseLockGeneric.InternalActivity> getInternalActivityClass() {

View File

@@ -110,7 +110,7 @@ public class SetNewPasswordActivity extends Activity implements SetNewPasswordCo
@Override @Override
public void launchChooseLock(Bundle chooseLockFingerprintExtras) { 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) Intent intent = isInSetupWizard ? new Intent(this, SetupChooseLockGeneric.class)
: new Intent(this, ChooseLockGeneric.class); : new Intent(this, ChooseLockGeneric.class);
intent.setAction(mNewPasswordAction); intent.setAction(mNewPasswordAction);

View File

@@ -46,6 +46,7 @@ import com.android.settings.biometrics.BiometricEnrollBase;
import com.android.settings.password.ChooseLockGeneric.ChooseLockGenericFragment; import com.android.settings.password.ChooseLockGeneric.ChooseLockGenericFragment;
import com.android.settings.search.SearchFeatureProvider; import com.android.settings.search.SearchFeatureProvider;
import com.android.settings.testutils.shadow.ShadowLockPatternUtils; 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.ShadowStorageManager;
import com.android.settings.testutils.shadow.ShadowUserManager; import com.android.settings.testutils.shadow.ShadowUserManager;
import com.android.settings.testutils.shadow.ShadowUtils; import com.android.settings.testutils.shadow.ShadowUtils;
@@ -63,6 +64,7 @@ import org.robolectric.annotation.Config;
@Config( @Config(
shadows = { shadows = {
ShadowLockPatternUtils.class, ShadowLockPatternUtils.class,
ShadowPersistentDataBlockManager.class,
ShadowStorageManager.class, ShadowStorageManager.class,
ShadowUserManager.class, ShadowUserManager.class,
ShadowUtils.class ShadowUtils.class
@@ -82,11 +84,13 @@ public class ChooseLockGenericTest {
public void tearDown() { public void tearDown() {
Global.putInt(application.getContentResolver(), Global.DEVICE_PROVISIONED, 1); Global.putInt(application.getContentResolver(), Global.DEVICE_PROVISIONED, 1);
ShadowStorageManager.reset(); ShadowStorageManager.reset();
ShadowPersistentDataBlockManager.reset();
} }
@Test @Test
public void onCreate_deviceNotProvisioned_shouldFinishActivity() { public void onCreate_deviceNotProvisioned_persistentDataExists_shouldFinishActivity() {
Global.putInt(application.getContentResolver(), Global.DEVICE_PROVISIONED, 0); Global.putInt(application.getContentResolver(), Global.DEVICE_PROVISIONED, 0);
ShadowPersistentDataBlockManager.setDataBlockSize(1000);
initActivity(null); initActivity(null);
assertThat(mActivity.isFinishing()).isTrue(); assertThat(mActivity.isFinishing()).isTrue();
@@ -191,7 +195,18 @@ public class ChooseLockGenericTest {
} }
@Test @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)); initActivity(new Intent().putExtra(EXTRA_KEY_IS_CALLING_APP_ADMIN, true));
mFragment.updatePreferencesOrFinish(/* isRecreatingActivity= */ false); mFragment.updatePreferencesOrFinish(/* isRecreatingActivity= */ false);

View File

@@ -45,6 +45,8 @@ import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.ShadowPasswordUtils; import com.android.settings.testutils.shadow.ShadowPasswordUtils;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.google.android.setupcompat.util.WizardManagerHelper;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -111,6 +113,7 @@ public class SetNewPasswordActivityTest {
activity.launchChooseLock(new Bundle()); activity.launchChooseLock(new Bundle());
ShadowActivity shadowActivity = Shadows.shadowOf(activity); ShadowActivity shadowActivity = Shadows.shadowOf(activity);
Intent intent = getLaunchChooseLockIntent(shadowActivity); Intent intent = getLaunchChooseLockIntent(shadowActivity);
intent.putExtra(WizardManagerHelper.EXTRA_IS_FIRST_RUN, true);
assertThat(intent.getComponent()) assertThat(intent.getComponent())
.isEqualTo(new ComponentName(activity, SetupChooseLockGeneric.class)); .isEqualTo(new ComponentName(activity, SetupChooseLockGeneric.class));

View File

@@ -0,0 +1,42 @@
/*
* 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;
}
}