Fan Zhang | c58a883 | 2017-11-01 17:59:53 -0700 | [diff] [blame] | 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; |
Fan Zhang | e9394d8 | 2018-01-03 10:34:12 -0800 | [diff] [blame] | 21 | import android.text.TextUtils; |
Fan Zhang | c58a883 | 2017-11-01 17:59:53 -0700 | [diff] [blame] | 22 | |
Fan Zhang | 23f8d59 | 2018-08-28 15:11:40 -0700 | [diff] [blame] | 23 | import androidx.preference.Preference; |
| 24 | |
Fan Zhang | c58a883 | 2017-11-01 17:59:53 -0700 | [diff] [blame] | 25 | import com.android.internal.widget.LockPatternUtils; |
| 26 | import com.android.settings.R; |
Fan Zhang | e9394d8 | 2018-01-03 10:34:12 -0800 | [diff] [blame] | 27 | import com.android.settings.core.BasePreferenceController; |
Fan Zhang | c58a883 | 2017-11-01 17:59:53 -0700 | [diff] [blame] | 28 | |
Fan Zhang | e9394d8 | 2018-01-03 10:34:12 -0800 | [diff] [blame] | 29 | public class EncryptionStatusPreferenceController extends BasePreferenceController { |
Fan Zhang | c58a883 | 2017-11-01 17:59:53 -0700 | [diff] [blame] | 30 | |
Fan Zhang | e9394d8 | 2018-01-03 10:34:12 -0800 | [diff] [blame] | 31 | |
Simon Wingrove | 2c14d9e | 2021-05-10 09:02:25 +0100 | [diff] [blame] | 32 | public static final String PREF_KEY_ENCRYPTION_DETAIL_PAGE = |
Fan Zhang | e9394d8 | 2018-01-03 10:34:12 -0800 | [diff] [blame] | 33 | "encryption_and_credentials_encryption_status"; |
Simon Wingrove | 2c14d9e | 2021-05-10 09:02:25 +0100 | [diff] [blame] | 34 | public static final String PREF_KEY_ENCRYPTION_SECURITY_PAGE = "encryption_and_credential"; |
Fan Zhang | c58a883 | 2017-11-01 17:59:53 -0700 | [diff] [blame] | 35 | |
| 36 | private final UserManager mUserManager; |
| 37 | |
Fan Zhang | e9394d8 | 2018-01-03 10:34:12 -0800 | [diff] [blame] | 38 | public EncryptionStatusPreferenceController(Context context, String key) { |
| 39 | super(context, key); |
Fan Zhang | c58a883 | 2017-11-01 17:59:53 -0700 | [diff] [blame] | 40 | mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE); |
| 41 | } |
| 42 | |
| 43 | @Override |
Fan Zhang | e9394d8 | 2018-01-03 10:34:12 -0800 | [diff] [blame] | 44 | public int getAvailabilityStatus() { |
Ben Lin | 2d5df46 | 2018-03-05 16:35:48 -0800 | [diff] [blame] | 45 | if (TextUtils.equals(getPreferenceKey(), PREF_KEY_ENCRYPTION_DETAIL_PAGE) && |
| 46 | !mContext.getResources().getBoolean( |
| 47 | R.bool.config_show_encryption_and_credentials_encryption_status)) { |
Matthew Fritze | f87a1f3 | 2018-05-03 16:46:51 -0700 | [diff] [blame] | 48 | return UNSUPPORTED_ON_DEVICE; |
Ben Lin | 2d5df46 | 2018-03-05 16:35:48 -0800 | [diff] [blame] | 49 | } |
| 50 | |
Fan Zhang | e9394d8 | 2018-01-03 10:34:12 -0800 | [diff] [blame] | 51 | return mUserManager.isAdminUser() ? AVAILABLE : DISABLED_FOR_USER; |
Fan Zhang | c58a883 | 2017-11-01 17:59:53 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public void updateState(Preference preference) { |
| 56 | final boolean encryptionEnabled = LockPatternUtils.isDeviceEncryptionEnabled(); |
| 57 | if (encryptionEnabled) { |
Eric Biggers | 6552bdd | 2022-01-11 17:01:22 -0800 | [diff] [blame] | 58 | preference.setSummary(R.string.encrypted_summary); |
Fan Zhang | c58a883 | 2017-11-01 17:59:53 -0700 | [diff] [blame] | 59 | } else { |
Eric Biggers | 6552bdd | 2022-01-11 17:01:22 -0800 | [diff] [blame] | 60 | preference.setSummary(R.string.not_encrypted_summary); |
Fan Zhang | c58a883 | 2017-11-01 17:59:53 -0700 | [diff] [blame] | 61 | } |
Fan Zhang | e9394d8 | 2018-01-03 10:34:12 -0800 | [diff] [blame] | 62 | |
Fan Zhang | c58a883 | 2017-11-01 17:59:53 -0700 | [diff] [blame] | 63 | } |
| 64 | } |