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

Commit 00dcd712 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Update EncryptionStatusPrefController to BasePrefController"

parents ed32f1da e9394d82
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package com.android.settings.security;

import static com.android.settings.security.EncryptionStatusPreferenceController
        .PREF_KEY_ENCRYPTION_DETAIL_PAGE;

import android.content.Context;
import android.os.UserManager;
import android.provider.SearchIndexableResource;
@@ -63,7 +66,7 @@ public class EncryptionAndCredential extends DashboardFragment {
            Lifecycle lifecycle) {
        final List<AbstractPreferenceController> controllers = new ArrayList<>();
        final EncryptionStatusPreferenceController encryptStatusController =
                new EncryptionStatusPreferenceController(context);
                new EncryptionStatusPreferenceController(context, PREF_KEY_ENCRYPTION_DETAIL_PAGE);
        controllers.add(encryptStatusController);
        controllers.add(new PreferenceCategoryController(context,
                "encryption_and_credentials_status_category",
+18 −16
Original line number Diff line number Diff line
@@ -19,43 +19,45 @@ package com.android.settings.security;
import android.content.Context;
import android.os.UserManager;
import android.support.v7.preference.Preference;
import android.text.TextUtils;

import com.android.internal.widget.LockPatternUtils;
import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settings.core.BasePreferenceController;

public class EncryptionStatusPreferenceController extends AbstractPreferenceController
        implements PreferenceControllerMixin {
public class EncryptionStatusPreferenceController extends BasePreferenceController {

    private static final String PREF_KEY = "encryption_and_credentials_encryption_status";

    static final String PREF_KEY_ENCRYPTION_DETAIL_PAGE =
            "encryption_and_credentials_encryption_status";
    static final String PREF_KEY_ENCRYPTION_SECURITY_PAGE = "encryption_and_credential";

    private final UserManager mUserManager;

    public EncryptionStatusPreferenceController(Context context) {
        super(context);
    public EncryptionStatusPreferenceController(Context context, String key) {
        super(context, key);
        mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
    }

    @Override
    public boolean isAvailable() {
        return mUserManager.isAdminUser();
    }

    @Override
    public String getPreferenceKey() {
        return PREF_KEY;
    public int getAvailabilityStatus() {
        return mUserManager.isAdminUser() ? AVAILABLE : DISABLED_FOR_USER;
    }

    @Override
    public void updateState(Preference preference) {
        final boolean encryptionEnabled = LockPatternUtils.isDeviceEncryptionEnabled();
        if (encryptionEnabled) {
            if (TextUtils.equals(getPreferenceKey(), PREF_KEY_ENCRYPTION_DETAIL_PAGE)) {
                preference.setFragment(null);
            }
            preference.setSummary(R.string.crypt_keeper_encrypted_summary);
        } else {
            if (TextUtils.equals(getPreferenceKey(), PREF_KEY_ENCRYPTION_DETAIL_PAGE)) {
                preference.setFragment(CryptKeeperSettings.class.getName());
            }
            preference.setSummary(R.string.summary_placeholder);
        }

    }
}
+12 −9
Original line number Diff line number Diff line
package com.android.settings.security;

import static com.android.settings.security.EncryptionStatusPreferenceController
        .PREF_KEY_ENCRYPTION_SECURITY_PAGE;

import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
@@ -118,6 +121,7 @@ public class SecuritySettingsV2 extends DashboardFragment
    private LocationPreferenceController mLocationController;
    private ManageDeviceAdminPreferenceController mManageDeviceAdminPreferenceController;
    private EnterprisePrivacyPreferenceController mEnterprisePrivacyPreferenceController;
    private EncryptionStatusPreferenceController mEncryptionStatusPreferenceController;
    private LockScreenNotificationPreferenceController mLockScreenNotificationPreferenceController;
    private ManageTrustAgentsPreferenceController mManageTrustAgentsPreferenceController;
    private ScreenPinningPreferenceController mScreenPinningPreferenceController;
@@ -166,6 +170,8 @@ public class SecuritySettingsV2 extends DashboardFragment
        mScreenPinningPreferenceController = new ScreenPinningPreferenceController(context);
        mSimLockPreferenceController = new SimLockPreferenceController(context);
        mShowPasswordPreferenceController = new ShowPasswordPreferenceController(context);
        mEncryptionStatusPreferenceController = new EncryptionStatusPreferenceController(
                context, PREF_KEY_ENCRYPTION_SECURITY_PAGE);
        return null;
    }

@@ -289,15 +295,6 @@ public class SecuritySettingsV2 extends DashboardFragment
        mSimLockPreferenceController.displayPreference(root);
        mScreenPinningPreferenceController.displayPreference(root);

        // Encryption status of device
        if (LockPatternUtils.isDeviceEncryptionEnabled()) {
            root.findPreference(KEY_ENCRYPTION_AND_CREDENTIALS).setSummary(
                    R.string.encryption_and_credential_settings_summary);
        } else {
            root.findPreference(KEY_ENCRYPTION_AND_CREDENTIALS).setSummary(
                    R.string.summary_placeholder);
        }

        // Advanced Security features
        mManageTrustAgentsPreferenceController.displayPreference(root);

@@ -439,10 +436,16 @@ public class SecuritySettingsV2 extends DashboardFragment
        }

        updateUnificationPreference();

        final Preference showPasswordPref = getPreferenceScreen().findPreference(
                mShowPasswordPreferenceController.getPreferenceKey());
        showPasswordPref.setOnPreferenceChangeListener(mShowPasswordPreferenceController);
        mShowPasswordPreferenceController.updateState(showPasswordPref);

        final Preference encryptionStatusPref = getPreferenceScreen().findPreference(
                mEncryptionStatusPreferenceController.getPreferenceKey());
        mEncryptionStatusPreferenceController.updateState(encryptionStatusPref);

        mLocationController.updateSummary();
    }

+21 −1
Original line number Diff line number Diff line
@@ -16,6 +16,10 @@

package com.android.settings.security;

import static com.android.settings.security.EncryptionStatusPreferenceController
        .PREF_KEY_ENCRYPTION_DETAIL_PAGE;
import static com.android.settings.security.EncryptionStatusPreferenceController
        .PREF_KEY_ENCRYPTION_SECURITY_PAGE;
import static com.google.common.truth.Truth.assertThat;

import android.content.Context;
@@ -48,7 +52,8 @@ public class EncryptionStatusPreferenceControllerTest {
    @Before
    public void setUp() {
        mContext = RuntimeEnvironment.application;
        mController = new EncryptionStatusPreferenceController(mContext);
        mController = new EncryptionStatusPreferenceController(mContext,
                PREF_KEY_ENCRYPTION_DETAIL_PAGE);
        mPreference = new Preference(mContext);
    }

@@ -85,6 +90,21 @@ public class EncryptionStatusPreferenceControllerTest {

        assertThat(mPreference.getSummary())
                .isEqualTo(mContext.getText(R.string.summary_placeholder));
        assertThat(mController.getPreferenceKey()).isNotEqualTo(PREF_KEY_ENCRYPTION_SECURITY_PAGE);
        assertThat(mPreference.getFragment()).isEqualTo(CryptKeeperSettings.class.getName());
    }

    @Test
    public void updateSummary_unencrypted_securityPage_shouldNotHaveEncryptionFragment() {
        mController = new EncryptionStatusPreferenceController(mContext,
                PREF_KEY_ENCRYPTION_SECURITY_PAGE);
        ShadowLockPatternUtils.setDeviceEncryptionEnabled(false);

        mController.updateState(mPreference);

        assertThat(mPreference.getSummary())
                .isEqualTo(mContext.getText(R.string.summary_placeholder));

        assertThat(mPreference.getFragment()).isNotEqualTo(CryptKeeperSettings.class.getName());
    }
}