• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.security;
18 
19 import android.content.Context;
20 import android.os.UserManager;
21 import android.support.v7.preference.Preference;
22 import android.text.TextUtils;
23 
24 import com.android.internal.widget.LockPatternUtils;
25 import com.android.settings.R;
26 import com.android.settings.core.BasePreferenceController;
27 
28 public class EncryptionStatusPreferenceController extends BasePreferenceController {
29 
30 
31     static final String PREF_KEY_ENCRYPTION_DETAIL_PAGE =
32             "encryption_and_credentials_encryption_status";
33     static final String PREF_KEY_ENCRYPTION_SECURITY_PAGE = "encryption_and_credential";
34 
35     private final UserManager mUserManager;
36 
EncryptionStatusPreferenceController(Context context, String key)37     public EncryptionStatusPreferenceController(Context context, String key) {
38         super(context, key);
39         mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
40     }
41 
42     @Override
getAvailabilityStatus()43     public int getAvailabilityStatus() {
44         if (TextUtils.equals(getPreferenceKey(), PREF_KEY_ENCRYPTION_DETAIL_PAGE) &&
45                 !mContext.getResources().getBoolean(
46                 R.bool.config_show_encryption_and_credentials_encryption_status)) {
47             return UNSUPPORTED_ON_DEVICE;
48         }
49 
50         return mUserManager.isAdminUser() ? AVAILABLE : DISABLED_FOR_USER;
51     }
52 
53     @Override
updateState(Preference preference)54     public void updateState(Preference preference) {
55         final boolean encryptionEnabled = LockPatternUtils.isDeviceEncryptionEnabled();
56         if (encryptionEnabled) {
57             if (TextUtils.equals(getPreferenceKey(), PREF_KEY_ENCRYPTION_DETAIL_PAGE)) {
58                 preference.setFragment(null);
59             }
60             preference.setSummary(R.string.crypt_keeper_encrypted_summary);
61         } else {
62             if (TextUtils.equals(getPreferenceKey(), PREF_KEY_ENCRYPTION_DETAIL_PAGE)) {
63                 preference.setFragment(CryptKeeperSettings.class.getName());
64             }
65             preference.setSummary(R.string.decryption_settings_summary);
66         }
67 
68     }
69 }
70