• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.app.admin.DevicePolicyManager;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.os.Bundle;
23 import android.os.UserHandle;
24 import android.text.TextUtils;
25 
26 import androidx.preference.Preference;
27 
28 import com.android.settings.R;
29 import com.android.settings.Utils;
30 import com.android.settings.core.SubSettingLauncher;
31 import com.android.settings.password.ChooseLockGeneric;
32 
33 public class ChangeProfileScreenLockPreferenceController extends
34         ChangeScreenLockPreferenceController {
35 
36     private static final String KEY_UNLOCK_SET_OR_CHANGE_PROFILE = "unlock_set_or_change_profile";
37 
ChangeProfileScreenLockPreferenceController(Context context, SecuritySettings host)38     public ChangeProfileScreenLockPreferenceController(Context context,
39             SecuritySettings host) {
40         super(context, host);
41     }
42 
isAvailable()43     public boolean isAvailable() {
44         if (mProfileChallengeUserId == UserHandle.USER_NULL ||
45                 !mLockPatternUtils.isSeparateProfileChallengeAllowed(mProfileChallengeUserId)) {
46             return false;
47         }
48         if (!mLockPatternUtils.isSecure(mProfileChallengeUserId)) {
49             return true;
50         }
51         switch (mLockPatternUtils.getKeyguardStoredPasswordQuality(mProfileChallengeUserId)) {
52             case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
53             case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
54             case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX:
55             case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
56             case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
57             case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
58             case DevicePolicyManager.PASSWORD_QUALITY_MANAGED:
59                 return true;
60         }
61         return false;
62     }
63 
64     @Override
getPreferenceKey()65     public String getPreferenceKey() {
66         return KEY_UNLOCK_SET_OR_CHANGE_PROFILE;
67     }
68 
69     @Override
handlePreferenceTreeClick(Preference preference)70     public boolean handlePreferenceTreeClick(Preference preference) {
71         if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
72             return false;
73         }
74         if (Utils.startQuietModeDialogIfNecessary(mContext, mUm, mProfileChallengeUserId)) {
75             return false;
76         }
77         final Bundle extras = new Bundle();
78         extras.putInt(Intent.EXTRA_USER_ID, mProfileChallengeUserId);
79         new SubSettingLauncher(mContext)
80                 .setDestination(ChooseLockGeneric.ChooseLockGenericFragment.class.getName())
81                 .setTitleRes(R.string.lock_settings_picker_title_profile)
82                 .setSourceMetricsCategory(mHost.getMetricsCategory())
83                 .setArguments(extras)
84                 .launch();
85 
86         return true;
87     }
88 
89     @Override
updateState(Preference preference)90     public void updateState(Preference preference) {
91         updateSummary(preference, mProfileChallengeUserId);
92 
93         if (!mLockPatternUtils.isSeparateProfileChallengeEnabled(mProfileChallengeUserId)) {
94             final String summary = mContext.getString(
95                     R.string.lock_settings_profile_unified_summary);
96             mPreference.setSummary(summary);
97             mPreference.setEnabled(false);
98         } else {
99             // PO may disallow to change profile password, and the profile's password is
100             // separated from screen lock password. Disable profile specific "Screen lock" menu.
101             disableIfPasswordQualityManaged(mProfileChallengeUserId);
102         }
103     }
104 }
105