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.content.Context;
20 import android.os.Bundle;
21 
22 import androidx.annotation.XmlRes;
23 
24 import com.android.car.settings.R;
25 import com.android.car.settings.common.SettingsFragment;
26 
27 import java.util.ArrayList;
28 import java.util.List;
29 
30 /**
31  * Give user choices of lock screen type: Pin/Pattern/Password or None.
32  */
33 public class ChooseLockTypeFragment extends SettingsFragment {
34 
35     public static final String EXTRA_CURRENT_PASSWORD_QUALITY = "extra_current_password_quality";
36 
37     private byte[] mCurrPassword;
38     private int mPasswordQuality;
39 
40     @Override
41     @XmlRes
getPreferenceScreenResId()42     protected int getPreferenceScreenResId() {
43         return R.xml.choose_lock_type_fragment;
44     }
45 
46     @Override
onAttach(Context context)47     public void onAttach(Context context) {
48         super.onAttach(context);
49         Bundle args = getArguments();
50         if (args != null) {
51             mCurrPassword = args.getByteArray(PasswordHelper.EXTRA_CURRENT_SCREEN_LOCK);
52             mPasswordQuality = args.getInt(EXTRA_CURRENT_PASSWORD_QUALITY);
53         }
54 
55         List<LockTypeBasePreferenceController> controllers = new ArrayList<>();
56         controllers.add(use(NoLockPreferenceController.class, R.string.pk_no_lock));
57         controllers.add(use(PatternLockPreferenceController.class, R.string.pk_pattern_lock));
58         controllers.add(use(PasswordLockPreferenceController.class, R.string.pk_password_lock));
59         controllers.add(use(PinLockPreferenceController.class, R.string.pk_pin_lock));
60 
61         for (LockTypeBasePreferenceController controller : controllers) {
62             controller.setCurrentPassword(mCurrPassword);
63             controller.setCurrentPasswordQuality(mPasswordQuality);
64         }
65     }
66 }
67