From 1e9bd27e2bb00c36ccb6ee9f7af68da2394679ce Mon Sep 17 00:00:00 2001 From: Eran Messeri Date: Thu, 24 Jan 2019 10:12:01 +0000 Subject: [PATCH] Further Credentials-related clean-up Additional clean-up work related to removal of screenlock dependency from the credentials installation flow: * Move the CredentialStorage class to security/ so that Enterprise team owners could review changes to it. * Remove the ConfigureKeyGuardDialog class as it is no longer used. * Remove attempt to unlock KeyStore from VPN settings. * Remove intents that will no longer be sent from the manifest. Bug: 120901345 Test: m -j RunSettingsRoboTests Test: Manual with CtsVerifier Change-Id: Ia708ede3366892d74c148f3712a63858d5ab53b7 --- AndroidManifest.xml | 3 +- res/values/strings.xml | 4 - .../security/ConfigureKeyGuardDialog.java | 86 ------------------- .../{ => security}/CredentialStorage.java | 5 +- .../settings/vpn2/ConfigDialogFragment.java | 23 ----- .../security/ConfigureKeyGuardDialogTest.java | 45 ---------- 6 files changed, 3 insertions(+), 163 deletions(-) delete mode 100644 src/com/android/settings/security/ConfigureKeyGuardDialog.java rename src/com/android/settings/{ => security}/CredentialStorage.java (98%) delete mode 100644 tests/robotests/src/com/android/settings/security/ConfigureKeyGuardDialogTest.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index a12c9825111..0f15d719fc4 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1249,12 +1249,11 @@ android:label="@string/local_backup_password_title" android:exported="false" /> - - diff --git a/res/values/strings.xml b/res/values/strings.xml index f77c10d577c..2d376d9a0e4 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -5731,10 +5731,6 @@ Credential storage is erased. Credential storage couldn\u2019t be erased. - - Before you can use credential storage, your device need to have a secure lock screen - - SET LOCK Apps with usage access diff --git a/src/com/android/settings/security/ConfigureKeyGuardDialog.java b/src/com/android/settings/security/ConfigureKeyGuardDialog.java deleted file mode 100644 index fff106c2791..00000000000 --- a/src/com/android/settings/security/ConfigureKeyGuardDialog.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2017 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.security; - -import android.app.Activity; -import android.app.Dialog; -import android.app.admin.DevicePolicyManager; -import android.app.settings.SettingsEnums; -import android.content.DialogInterface; -import android.content.Intent; -import android.os.Bundle; - -import androidx.annotation.VisibleForTesting; -import androidx.appcompat.app.AlertDialog; - -import com.android.settings.CredentialStorage; -import com.android.settings.R; -import com.android.settings.core.instrumentation.InstrumentedDialogFragment; -import com.android.settings.password.ChooseLockGeneric; - -/** - * Prompt for key guard configuration confirmation. - */ -public class ConfigureKeyGuardDialog extends InstrumentedDialogFragment - implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener { - - public static final String TAG = "ConfigureKeyGuardDialog"; - - private boolean mConfigureConfirmed; - - @Override - public int getMetricsCategory() { - return SettingsEnums.CONFIGURE_KEYGUARD_DIALOG; - } - - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - return new AlertDialog.Builder(getActivity()) - .setTitle(android.R.string.dialog_alert_title) - .setMessage(R.string.credentials_configure_lock_screen_hint) - .setPositiveButton(R.string.credentials_configure_lock_screen_button, this) - .setNegativeButton(android.R.string.cancel, this) - .create(); - } - - @Override - public void onClick(DialogInterface dialog, int button) { - mConfigureConfirmed = (button == DialogInterface.BUTTON_POSITIVE); - } - - @Override - public void onDismiss(DialogInterface dialog) { - if (mConfigureConfirmed) { - mConfigureConfirmed = false; - startPasswordSetup(); - return; - } else { - final Activity activity = getActivity(); - if (activity != null) { - activity.finish(); - } - } - } - - @VisibleForTesting - void startPasswordSetup() { - Intent intent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD); - intent.putExtra(ChooseLockGeneric.ChooseLockGenericFragment.MINIMUM_QUALITY_KEY, - CredentialStorage.MIN_PASSWORD_QUALITY); - startActivity(intent); - } -} diff --git a/src/com/android/settings/CredentialStorage.java b/src/com/android/settings/security/CredentialStorage.java similarity index 98% rename from src/com/android/settings/CredentialStorage.java rename to src/com/android/settings/security/CredentialStorage.java index 0485a0f7730..99937eee472 100644 --- a/src/com/android/settings/CredentialStorage.java +++ b/src/com/android/settings/security/CredentialStorage.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.settings; +package com.android.settings.security; import android.app.Activity; import android.app.admin.DevicePolicyManager; @@ -44,8 +44,8 @@ import androidx.fragment.app.FragmentActivity; import com.android.internal.widget.LockPatternUtils; import com.android.org.bouncycastle.asn1.ASN1InputStream; import com.android.org.bouncycastle.asn1.pkcs.PrivateKeyInfo; +import com.android.settings.R; import com.android.settings.password.ChooseLockSettingsHelper; -import com.android.settings.security.ConfigureKeyGuardDialog; import com.android.settings.vpn2.VpnUtils; import java.io.ByteArrayInputStream; @@ -61,7 +61,6 @@ public final class CredentialStorage extends FragmentActivity { private static final String TAG = "CredentialStorage"; - public static final String ACTION_UNLOCK = "com.android.credentials.UNLOCK"; public static final String ACTION_INSTALL = "com.android.credentials.INSTALL"; public static final String ACTION_RESET = "com.android.credentials.RESET"; diff --git a/src/com/android/settings/vpn2/ConfigDialogFragment.java b/src/com/android/settings/vpn2/ConfigDialogFragment.java index ec927aec2f5..b72508ed9e4 100644 --- a/src/com/android/settings/vpn2/ConfigDialogFragment.java +++ b/src/com/android/settings/vpn2/ConfigDialogFragment.java @@ -56,8 +56,6 @@ public class ConfigDialogFragment extends InstrumentedDialogFragment implements ServiceManager.getService(Context.CONNECTIVITY_SERVICE)); private Context mContext; - private boolean mUnlocking = false; - @Override public int getMetricsCategory() { @@ -84,27 +82,6 @@ public class ConfigDialogFragment extends InstrumentedDialogFragment implements mContext = context; } - @Override - public void onResume() { - super.onResume(); - - // Check KeyStore here, so others do not need to deal with it. - if (!KeyStore.getInstance().isUnlocked()) { - if (!mUnlocking) { - // Let us unlock KeyStore. See you later! - Credentials.getInstance().unlock(mContext); - } else { - // We already tried, but it is still not working! - dismiss(); - } - mUnlocking = !mUnlocking; - return; - } - - // Now KeyStore is always unlocked. Reset the flag. - mUnlocking = false; - } - @Override public Dialog onCreateDialog(Bundle savedInstanceState) { Bundle args = getArguments(); diff --git a/tests/robotests/src/com/android/settings/security/ConfigureKeyGuardDialogTest.java b/tests/robotests/src/com/android/settings/security/ConfigureKeyGuardDialogTest.java deleted file mode 100644 index 49a4e92ae43..00000000000 --- a/tests/robotests/src/com/android/settings/security/ConfigureKeyGuardDialogTest.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2017 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.security; - -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; - -import android.content.DialogInterface; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.RobolectricTestRunner; -import org.robolectric.shadows.androidx.fragment.FragmentController; - -@RunWith(RobolectricTestRunner.class) -public class ConfigureKeyGuardDialogTest { - - @Test - public void displayDialog_clickPositiveButton_launchSetNewPassword() { - final FragmentController fragmentController = - FragmentController.of(new ConfigureKeyGuardDialog()); - final ConfigureKeyGuardDialog fragment = spy(fragmentController.get()); - doNothing().when(fragment).startPasswordSetup(); - fragmentController.create().start().resume(); - fragment.onClick(null /* dialog */, DialogInterface.BUTTON_POSITIVE); - fragment.onDismiss(null /* dialog */); - - verify(fragment).startPasswordSetup(); - } -}