• 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.os.Bundle;
21 import android.os.UserHandle;
22 
23 import androidx.annotation.Nullable;
24 import androidx.fragment.app.Fragment;
25 
26 import com.android.car.settings.R;
27 import com.android.car.settings.common.BaseCarSettingsActivity;
28 import com.android.car.settings.common.Logger;
29 import com.android.internal.widget.LockPatternUtils;
30 
31 /**
32  * Activity for setting screen locks
33  */
34 public class SettingsScreenLockActivity extends BaseCarSettingsActivity implements
35         CheckLockListener {
36 
37     private static final Logger LOG = new Logger(SettingsScreenLockActivity.class);
38 
39     private int mPasswordQuality;
40 
41     @Override
42     @Nullable
getInitialFragment()43     protected Fragment getInitialFragment() {
44         mPasswordQuality = new LockPatternUtils(this).getKeyguardStoredPasswordQuality(
45                 UserHandle.myUserId());
46 
47         Fragment fragment;
48         switch (mPasswordQuality) {
49             case DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED:
50                 fragment = new ChooseLockTypeFragment();
51                 break;
52             case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
53                 fragment = new ConfirmLockPatternFragment();
54                 break;
55             case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
56             case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX:
57                 fragment = ConfirmLockPinPasswordFragment.newPinInstance();
58                 break;
59             case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
60             case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
61                 fragment = ConfirmLockPinPasswordFragment.newPasswordInstance();
62                 break;
63             default:
64                 LOG.e("Unexpected password quality: " + String.valueOf(mPasswordQuality));
65                 fragment = ConfirmLockPinPasswordFragment.newPasswordInstance();
66         }
67 
68         Bundle bundle = fragment.getArguments();
69         if (bundle == null) {
70             bundle = new Bundle();
71         }
72         bundle.putInt(ChooseLockTypeFragment.EXTRA_CURRENT_PASSWORD_QUALITY, mPasswordQuality);
73         fragment.setArguments(bundle);
74         return fragment;
75     }
76 
77     @Override
onLockVerified(byte[] lock)78     public void onLockVerified(byte[] lock) {
79         Fragment fragment = new ChooseLockTypeFragment();
80         Bundle bundle = fragment.getArguments();
81         if (bundle == null) {
82             bundle = new Bundle();
83         }
84         bundle.putByteArray(PasswordHelper.EXTRA_CURRENT_SCREEN_LOCK, lock);
85         bundle.putInt(ChooseLockTypeFragment.EXTRA_CURRENT_PASSWORD_QUALITY, mPasswordQuality);
86         fragment.setArguments(bundle);
87 
88         // Intentionally not using launchFragment(), since we do not want to add to the back stack.
89         getSupportFragmentManager()
90                 .beginTransaction()
91                 .replace(R.id.fragment_container, fragment)
92                 .commit();
93     }
94 }
95