• 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.text.TextUtils;
22 
23 import androidx.preference.Preference;
24 
25 import com.android.internal.widget.LockPatternUtils;
26 import com.android.settings.R;
27 import com.android.settings.core.BasePreferenceController;
28 
29 public class EncryptionStatusPreferenceController extends BasePreferenceController {
30 
31 
32     static final String PREF_KEY_ENCRYPTION_DETAIL_PAGE =
33             "encryption_and_credentials_encryption_status";
34     static final String PREF_KEY_ENCRYPTION_SECURITY_PAGE = "encryption_and_credential";
35 
36     private final UserManager mUserManager;
37 
EncryptionStatusPreferenceController(Context context, String key)38     public EncryptionStatusPreferenceController(Context context, String key) {
39         super(context, key);
40         mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
41     }
42 
43     @Override
getAvailabilityStatus()44     public int getAvailabilityStatus() {
45         if (TextUtils.equals(getPreferenceKey(), PREF_KEY_ENCRYPTION_DETAIL_PAGE) &&
46                 !mContext.getResources().getBoolean(
47                 R.bool.config_show_encryption_and_credentials_encryption_status)) {
48             return UNSUPPORTED_ON_DEVICE;
49         }
50 
51         return mUserManager.isAdminUser() ? AVAILABLE : DISABLED_FOR_USER;
52     }
53 
54     @Override
updateState(Preference preference)55     public void updateState(Preference preference) {
56         final boolean encryptionEnabled = LockPatternUtils.isDeviceEncryptionEnabled();
57         if (encryptionEnabled) {
58             if (TextUtils.equals(getPreferenceKey(), PREF_KEY_ENCRYPTION_DETAIL_PAGE)) {
59                 preference.setFragment(null);
60             }
61             preference.setSummary(R.string.crypt_keeper_encrypted_summary);
62         } else {
63             if (TextUtils.equals(getPreferenceKey(), PREF_KEY_ENCRYPTION_DETAIL_PAGE)) {
64                 preference.setFragment(CryptKeeperSettings.class.getName());
65             }
66             preference.setSummary(R.string.decryption_settings_summary);
67         }
68 
69     }
70 }
71