blob: d83579822d42bed76606d8e4265e3767d78c3da6 [file] [log] [blame]
Fan Zhangc58a8832017-11-01 17:59:53 -07001/*
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
17package com.android.settings.security;
18
19import android.content.Context;
20import android.os.UserManager;
Fan Zhange9394d82018-01-03 10:34:12 -080021import android.text.TextUtils;
Fan Zhangc58a8832017-11-01 17:59:53 -070022
Fan Zhang23f8d592018-08-28 15:11:40 -070023import androidx.preference.Preference;
24
Fan Zhangc58a8832017-11-01 17:59:53 -070025import com.android.internal.widget.LockPatternUtils;
26import com.android.settings.R;
Fan Zhange9394d82018-01-03 10:34:12 -080027import com.android.settings.core.BasePreferenceController;
Fan Zhangc58a8832017-11-01 17:59:53 -070028
Fan Zhange9394d82018-01-03 10:34:12 -080029public class EncryptionStatusPreferenceController extends BasePreferenceController {
Fan Zhangc58a8832017-11-01 17:59:53 -070030
Fan Zhange9394d82018-01-03 10:34:12 -080031
Simon Wingrove2c14d9e2021-05-10 09:02:25 +010032 public static final String PREF_KEY_ENCRYPTION_DETAIL_PAGE =
Fan Zhange9394d82018-01-03 10:34:12 -080033 "encryption_and_credentials_encryption_status";
Simon Wingrove2c14d9e2021-05-10 09:02:25 +010034 public static final String PREF_KEY_ENCRYPTION_SECURITY_PAGE = "encryption_and_credential";
Fan Zhangc58a8832017-11-01 17:59:53 -070035
36 private final UserManager mUserManager;
37
Fan Zhange9394d82018-01-03 10:34:12 -080038 public EncryptionStatusPreferenceController(Context context, String key) {
39 super(context, key);
Fan Zhangc58a8832017-11-01 17:59:53 -070040 mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
41 }
42
43 @Override
Fan Zhange9394d82018-01-03 10:34:12 -080044 public int getAvailabilityStatus() {
Ben Lin2d5df462018-03-05 16:35:48 -080045 if (TextUtils.equals(getPreferenceKey(), PREF_KEY_ENCRYPTION_DETAIL_PAGE) &&
46 !mContext.getResources().getBoolean(
47 R.bool.config_show_encryption_and_credentials_encryption_status)) {
Matthew Fritzef87a1f32018-05-03 16:46:51 -070048 return UNSUPPORTED_ON_DEVICE;
Ben Lin2d5df462018-03-05 16:35:48 -080049 }
50
Fan Zhange9394d82018-01-03 10:34:12 -080051 return mUserManager.isAdminUser() ? AVAILABLE : DISABLED_FOR_USER;
Fan Zhangc58a8832017-11-01 17:59:53 -070052 }
53
54 @Override
55 public void updateState(Preference preference) {
56 final boolean encryptionEnabled = LockPatternUtils.isDeviceEncryptionEnabled();
57 if (encryptionEnabled) {
Eric Biggers6552bdd2022-01-11 17:01:22 -080058 preference.setSummary(R.string.encrypted_summary);
Fan Zhangc58a8832017-11-01 17:59:53 -070059 } else {
Eric Biggers6552bdd2022-01-11 17:01:22 -080060 preference.setSummary(R.string.not_encrypted_summary);
Fan Zhangc58a8832017-11-01 17:59:53 -070061 }
Fan Zhange9394d82018-01-03 10:34:12 -080062
Fan Zhangc58a8832017-11-01 17:59:53 -070063 }
64}