• 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.os.Bundle;
20 
21 import androidx.annotation.XmlRes;
22 import androidx.preference.Preference;
23 import androidx.preference.PreferenceScreen;
24 
25 import com.android.car.settings.R;
26 import com.android.car.settings.common.SettingsFragment;
27 import com.android.internal.widget.LockscreenCredential;
28 
29 
30 /**
31  * Give user choices of lock screen type: Pin/Pattern/Password or None.
32  */
33 public class ChooseLockTypeFragment extends SettingsFragment {
34 
35     private LockscreenCredential mLockscreenCredential;
36 
37     @Override
38     @XmlRes
getPreferenceScreenResId()39     protected int getPreferenceScreenResId() {
40         return R.xml.choose_lock_type_fragment;
41     }
42 
43     /**
44      * Pass along password and password quality to preference controllers
45      */
46     @Override
onCreate(Bundle savedInstanceState)47     public void onCreate(Bundle savedInstanceState) {
48         super.onCreate(savedInstanceState);
49         Bundle args = getArguments();
50         if (args != null) {
51             mLockscreenCredential = args.getParcelable(PasswordHelper.EXTRA_CURRENT_SCREEN_LOCK);
52             int passwordQuality = args.getInt(PasswordHelper.EXTRA_CURRENT_PASSWORD_QUALITY);
53 
54             PreferenceScreen preferenceScreen = getPreferenceScreen();
55             int preferenceCount = preferenceScreen.getPreferenceCount();
56             for (int i = 0; i < preferenceCount; i++) {
57                 Preference preference = preferenceScreen.getPreference(i);
58                 preference.getExtras().putParcelable(
59                         PasswordHelper.EXTRA_CURRENT_SCREEN_LOCK, mLockscreenCredential);
60                 preference.getExtras().putInt(
61                         PasswordHelper.EXTRA_CURRENT_PASSWORD_QUALITY, passwordQuality);
62             }
63         }
64     }
65 
66     @Override
onDestroyView()67     public void onDestroyView() {
68         super.onDestroyView();
69 
70         PasswordHelper.zeroizeCredentials(mLockscreenCredential);
71     }
72 }
73