• 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.car.settings.security;
18 
19 import android.app.admin.DevicePolicyManager;
20 import android.car.drivingstate.CarUxRestrictions;
21 import android.car.userlib.CarUserManagerHelper;
22 import android.content.Context;
23 
24 import androidx.annotation.VisibleForTesting;
25 import androidx.fragment.app.Fragment;
26 import androidx.preference.Preference;
27 
28 import com.android.car.settings.common.FragmentController;
29 import com.android.internal.widget.LockPatternUtils;
30 
31 /** Business logic for the no lock preference. */
32 public class NoLockPreferenceController extends LockTypeBasePreferenceController {
33 
34     private static final int[] ALLOWED_PASSWORD_QUALITIES =
35             new int[]{DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED};
36 
37     @VisibleForTesting
38     final ConfirmRemoveScreenLockDialog.ConfirmRemoveScreenLockListener mRemoveLockListener =
39             () -> {
40                 int userId = new CarUserManagerHelper(getContext()).getCurrentProcessUserId();
41                 new LockPatternUtils(getContext()).clearLock(getCurrentPassword(), userId);
42                 getFragmentController().goBack();
43             };
44 
NoLockPreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)45     public NoLockPreferenceController(Context context, String preferenceKey,
46             FragmentController fragmentController, CarUxRestrictions uxRestrictions) {
47         super(context, preferenceKey, fragmentController, uxRestrictions);
48     }
49 
50 
51     /**
52      * If the dialog to confirm removal of lock was open previously, make sure the listener is
53      * restored.
54      */
55     @Override
onCreateInternal()56     protected void onCreateInternal() {
57         ConfirmRemoveScreenLockDialog dialog =
58                 (ConfirmRemoveScreenLockDialog) getFragmentController().findDialogByTag(
59                         ConfirmRemoveScreenLockDialog.TAG);
60         if (dialog != null) {
61             dialog.setConfirmRemoveScreenLockListener(mRemoveLockListener);
62         }
63     }
64 
65     @Override
handlePreferenceClicked(Preference preference)66     protected boolean handlePreferenceClicked(Preference preference) {
67         ConfirmRemoveScreenLockDialog dialog = new ConfirmRemoveScreenLockDialog();
68         dialog.setConfirmRemoveScreenLockListener(mRemoveLockListener);
69         getFragmentController().showDialog(dialog,
70                 ConfirmRemoveScreenLockDialog.TAG);
71         return true;
72     }
73 
74     @Override
fragmentToOpen()75     protected Fragment fragmentToOpen() {
76         // Selecting this preference does not open a new fragment. Instead it opens a dialog to
77         // confirm the removal of the existing lock screen.
78         return null;
79     }
80 
81     @Override
allowedPasswordQualities()82     protected int[] allowedPasswordQualities() {
83         return ALLOWED_PASSWORD_QUALITIES;
84     }
85 }
86