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     public static final String PREF_KEY_ENCRYPTION_DETAIL_PAGE =
33             "encryption_and_credentials_encryption_status";
34     public 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 AVAILABLE;
52     }
53 
54     @Override
updateState(Preference preference)55     public void updateState(Preference preference) {
56         final boolean encryptionEnabled = LockPatternUtils.isDeviceEncryptionEnabled();
57         if (encryptionEnabled) {
58             preference.setSummary(R.string.encrypted_summary);
59         } else {
60             preference.setSummary(R.string.not_encrypted_summary);
61         }
62 
63     }
64 }
65