DO NOT MERGE - Check for existing lock pattern before changing credential in Settings

Fixes: 73383967
Test: RunCarSettingsRoboTests

- Encapsulate screen lock logic inside an Activity
- If a lock pattern is set, show the ConfirmLockPatternFragment, otherwise show ChooseLockTypeFragment
- When the existing lock is verified, launch the list fragment and pass the current lock
- Use the existing lock to update lock settings

Change-Id: Ie31f747f30c2fc1aa97a79e75c90af236f3e3a50
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index aefd55d..546c979 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -97,6 +97,10 @@
             </intent-filter>
         </activity>
 
+        <activity android:name=".security.SettingsScreenLockActivity"
+                  android:configChanges="orientation|keyboardHidden|screenSize">
+        </activity>
+
         <activity android:name=".security.SetupWizardScreenLockActivity"
                   android:configChanges="orientation|keyboardHidden|screenSize">
             <intent-filter>
diff --git a/res/layout/confirm_lock_pattern_fragment.xml b/res/layout/confirm_lock_pattern_fragment.xml
new file mode 100644
index 0000000..44ad4a0
--- /dev/null
+++ b/res/layout/confirm_lock_pattern_fragment.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (C) 2018 The Android Open Source Project
+
+    Licensed under the Apache License, Version 2.0 (the "License")
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/container"
+    android:layout_height="match_parent"
+    android:layout_width="match_parent"
+    android:orientation="vertical"
+    android:gravity="center">
+
+    <TextView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginBottom="@dimen/car_padding_2"
+        android:textAppearance="@style/TextAppearance.Car.Title2"
+        android:text="@string/lock_settings_enter_pattern"
+        android:drawableStart="@drawable/ic_lock"
+        android:drawableTint="@color/car_body3"
+        android:drawablePadding="@dimen/lockscreen_title_drawable_padding"/>
+
+    <TextView
+        android:id="@+id/message"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginBottom="@dimen/car_padding_2"
+        android:gravity="center"
+        android:textAppearance="@style/TextAppearance.Car.Body2"/>
+
+    <com.android.internal.widget.LockPatternView
+        style="@style/LockPatternStyle"
+        android:id="@+id/lockPattern"
+        android:layout_width="@dimen/confirm_pattern_dimension"
+        android:layout_height="@dimen/confirm_pattern_dimension"/>
+</LinearLayout>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 57c9b54..56a7959 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -35,6 +35,7 @@
     <dimen name="pin_pad_key_margin">12dp</dimen>
     <dimen name="pin_pad_padding_top">20dp</dimen>
     <dimen name="pin_pad_end_padding_top">48dp</dimen>
+    <dimen name="confirm_pattern_dimension">350dp</dimen>
 
     <dimen name="lockscreen_title_drawable_padding">5dp</dimen>
 
diff --git a/res/values/strings.xml b/res/values/strings.xml
index f41c3f6..17e3111 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -411,6 +411,8 @@
     <string name="lock_settings_picker_title">Choose a lock type</string>
     <!--  Button caption to open a dialog for user to choose an screen lock method: Pattern/PIN/Password [CHAR LIMIT=40] -->
     <string name="screen_lock_options">Screen lock options</string>
+    <!--  Title for screen asking user to enter their existing lock pattern [CHAR LIMIT=30] -->
+    <string name="lock_settings_enter_pattern">Enter your pattern</string>
     <!-- Security & location settings screen, change unlock pattern screen button, on bottom of screen.  After they draw a pattern and release their finger, we display the pattern so they remember.  When they are ready to draw it once again to confirm it, they press this button. -->
     <string name="lockpattern_confirm_button_text">Confirm</string>
     <!-- Security & location settings screen, change unlock pattern screen button, on bottom of screen.  After they draw a pattern and release their finger, we display the pattern so they remember.  If they are not satisfied with this pattern, they click this button to redraw the pattern. -->
diff --git a/src/com/android/car/settings/home/HomepageFragment.java b/src/com/android/car/settings/home/HomepageFragment.java
index a723cd9..b465c70 100644
--- a/src/com/android/car/settings/home/HomepageFragment.java
+++ b/src/com/android/car/settings/home/HomepageFragment.java
@@ -25,8 +25,10 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
+import android.graphics.drawable.Icon;
 import android.os.Bundle;
 
+import com.android.car.list.LaunchAppLineItem;
 import com.android.car.list.TypedPagedListAdapter;
 import com.android.car.settings.R;
 import com.android.car.settings.applications.ApplicationSettingsFragment;
@@ -34,7 +36,7 @@
 import com.android.car.settings.common.Logger;
 import com.android.car.settings.datetime.DatetimeSettingsFragment;
 import com.android.car.settings.display.DisplaySettingsFragment;
-import com.android.car.settings.security.ChooseLockTypeFragment;
+import com.android.car.settings.security.SettingsScreenLockActivity;
 import com.android.car.settings.sound.SoundSettingsFragment;
 import com.android.car.settings.suggestions.SettingsSuggestionsController;
 import com.android.car.settings.system.SystemSettingsFragment;
@@ -183,13 +185,12 @@
                 null,
                 UsersListFragment.newInstance(),
                 mFragmentController));
-        lineItems.add(new SimpleIconTransitionLineItem(
-                R.string.security_settings_title,
-                R.drawable.ic_lock,
+        lineItems.add(new LaunchAppLineItem(
+                getString(R.string.security_settings_title),
+                Icon.createWithResource(getContext(), R.drawable.ic_lock),
                 getContext(),
                 null,
-                ChooseLockTypeFragment.newInstance(),
-                mFragmentController));
+                new Intent(getContext(), SettingsScreenLockActivity.class)));
         lineItems.add(new SimpleIconTransitionLineItem(
                 R.string.system_setting_title,
                 R.drawable.ic_settings_about,
diff --git a/src/com/android/car/settings/security/CheckLockWorker.java b/src/com/android/car/settings/security/CheckLockWorker.java
new file mode 100644
index 0000000..2d36ecb
--- /dev/null
+++ b/src/com/android/car/settings/security/CheckLockWorker.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.car.settings.security;
+
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+
+import com.android.car.settings.common.Logger;
+import com.android.internal.widget.LockPatternChecker;
+import com.android.internal.widget.LockPatternUtils;
+import com.android.internal.widget.LockPatternView;
+
+import java.util.List;
+
+/**
+ * An invisible retained worker fragment to track the AsyncTask that checks the entered lock
+ * credential (pattern/pin/password).
+ */
+public class CheckLockWorker extends Fragment implements LockPatternChecker.OnCheckCallback {
+
+    private static final Logger LOG = new Logger(CheckLockWorker.class);
+
+    private boolean mHasPendingResult;
+    private boolean mLockMatched;
+    private boolean mCheckPatternRunning;
+    private Listener mListener;
+    private LockPatternUtils mLockPatternUtils;
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setRetainInstance(true);
+        mLockPatternUtils = new LockPatternUtils(getContext());
+    }
+
+    @Override
+    public void onChecked(boolean matched, int throttleTimeoutMs) {
+        mCheckPatternRunning = false;
+
+        if (mListener == null) {
+            mHasPendingResult = true;
+            mLockMatched = matched;
+        } else {
+            mListener.onCheckCompleted(matched);
+        }
+    }
+
+    /**
+     * Sets the listener for callback when lock check is completed.
+     */
+    public void setListener(Listener listener) {
+        mListener = listener;
+        if (mListener != null && mHasPendingResult) {
+            mHasPendingResult = false;
+            mListener.onCheckCompleted(mLockMatched);
+        }
+    }
+
+    /**
+     * Checks lock pattern asynchronously.
+     */
+    public final void checkPattern(int userId, List<LockPatternView.Cell> pattern) {
+        if (mCheckPatternRunning) {
+            LOG.w("Check pattern request issued while one is still running");
+            return;
+        }
+
+        mCheckPatternRunning = true;
+        LockPatternChecker.checkPattern(mLockPatternUtils, pattern, userId, this);
+    }
+
+    /**
+     * Callback when lock check is completed
+     */
+    interface Listener {
+        /**
+         * @param matched Whether the entered password matches the stored record
+         */
+        void onCheckCompleted(boolean matched);
+    }
+}
+
diff --git a/src/com/android/car/settings/security/ChooseLockPatternFragment.java b/src/com/android/car/settings/security/ChooseLockPatternFragment.java
index 8d8dac9..5fcb5e6 100644
--- a/src/com/android/car/settings/security/ChooseLockPatternFragment.java
+++ b/src/com/android/car/settings/security/ChooseLockPatternFragment.java
@@ -223,6 +223,7 @@
         Bundle args = getArguments();
         if (args != null) {
             mIsInSetupWizard = args.getBoolean(BaseFragment.EXTRA_RUNNING_IN_SETUP_WIZARD);
+            mCurrentPattern = args.getString(SettingsScreenLockActivity.EXTRA_CURRENT_SCREEN_LOCK);
         }
     }
 
@@ -554,7 +555,7 @@
         if (mIsInSetupWizard) {
             ((SetupWizardScreenLockActivity) getActivity()).onComplete();
         } else {
-            mFragmentController.goBack();
+            getActivity().finish();
         }
     }
 }
diff --git a/src/com/android/car/settings/security/ChooseLockPinPasswordFragment.java b/src/com/android/car/settings/security/ChooseLockPinPasswordFragment.java
index c3e6b90..447fe66 100644
--- a/src/com/android/car/settings/security/ChooseLockPinPasswordFragment.java
+++ b/src/com/android/car/settings/security/ChooseLockPinPasswordFragment.java
@@ -176,6 +176,8 @@
         if (args != null) {
             mIsInSetupWizard = args.getBoolean(BaseFragment.EXTRA_RUNNING_IN_SETUP_WIZARD);
             mIsPin = args.getBoolean(EXTRA_IS_PIN);
+            mExistingPassword = args.getString(
+                    SettingsScreenLockActivity.EXTRA_CURRENT_SCREEN_LOCK);
         }
 
         mPasswordHelper = new PasswordHelper(mIsPin);
@@ -475,7 +477,7 @@
         if (mIsInSetupWizard) {
             ((SetupWizardScreenLockActivity) getActivity()).onComplete();
         } else {
-            mFragmentController.goBack();
+            getActivity().finish();
         }
     }
 
diff --git a/src/com/android/car/settings/security/ChooseLockTypeFragment.java b/src/com/android/car/settings/security/ChooseLockTypeFragment.java
index 8b6eb13..4c8a97b 100644
--- a/src/com/android/car/settings/security/ChooseLockTypeFragment.java
+++ b/src/com/android/car/settings/security/ChooseLockTypeFragment.java
@@ -17,12 +17,14 @@
 package com.android.car.settings.security;
 
 import android.os.Bundle;
+import android.text.TextUtils;
 
 import androidx.car.widget.ListItem;
 import androidx.car.widget.ListItemProvider;
 import androidx.car.widget.TextListItem;
 
 import com.android.car.settings.R;
+import com.android.car.settings.common.BaseFragment;
 import com.android.car.settings.common.ListItemSettingsFragment;
 
 import java.util.ArrayList;
@@ -33,6 +35,7 @@
  */
 public class ChooseLockTypeFragment extends ListItemSettingsFragment {
     private ListItemProvider mItemProvider;
+    private String mCurrPassword;
 
     public static ChooseLockTypeFragment newInstance() {
         ChooseLockTypeFragment chooseLockTypeFragment = new ChooseLockTypeFragment();
@@ -44,6 +47,15 @@
     }
 
     @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        Bundle args = getArguments();
+        if (args != null) {
+            mCurrPassword = args.getString(SettingsScreenLockActivity.EXTRA_CURRENT_SCREEN_LOCK);
+        }
+    }
+
+    @Override
     public ListItemProvider getItemProvider() {
         if (mItemProvider == null) {
             mItemProvider = new ListItemProvider.ListProvider(getListItems());
@@ -62,33 +74,36 @@
     private ListItem createLockPatternLineItem() {
         TextListItem item = new TextListItem(getContext());
         item.setTitle(getString(R.string.security_lock_pattern));
-        item.setOnClickListener(view -> showChooseLockPattern());
+        item.setOnClickListener(view -> launchFragment(ChooseLockPatternFragment.newInstance()));
         return item;
     }
 
     private ListItem createLockPasswordLineItem() {
         TextListItem item = new TextListItem(getContext());
         item.setTitle(getString(R.string.security_lock_password));
-        item.setOnClickListener(view -> showChooseLockPassword());
+        item.setOnClickListener(view -> launchFragment(
+                ChooseLockPinPasswordFragment.newPasswordInstance()));
         return item;
     }
 
     private ListItem createLockPinLineItem() {
         TextListItem item = new TextListItem(getContext());
         item.setTitle(getString(R.string.security_lock_pin));
-        item.setOnClickListener(view -> showChooseLockPin());
+        item.setOnClickListener(view -> launchFragment(
+                ChooseLockPinPasswordFragment.newPinInstance()));
         return item;
     }
 
-    private void showChooseLockPattern() {
-        mFragmentController.launchFragment(ChooseLockPatternFragment.newInstance());
-    }
+    private void launchFragment(BaseFragment fragment) {
+        if (!TextUtils.isEmpty(mCurrPassword)) {
+            Bundle args = fragment.getArguments();
+            if (args == null) {
+                args = new Bundle();
+            }
+            args.putString(SettingsScreenLockActivity.EXTRA_CURRENT_SCREEN_LOCK, mCurrPassword);
+            fragment.setArguments(args);
+        }
 
-    private void showChooseLockPassword() {
-        mFragmentController.launchFragment(ChooseLockPinPasswordFragment.newPasswordInstance());
-    }
-
-    private void showChooseLockPin() {
-        mFragmentController.launchFragment(ChooseLockPinPasswordFragment.newPinInstance());
+        mFragmentController.launchFragment(fragment);
     }
 }
diff --git a/src/com/android/car/settings/security/ConfirmLockPatternFragment.java b/src/com/android/car/settings/security/ConfirmLockPatternFragment.java
new file mode 100644
index 0000000..ff20cd3
--- /dev/null
+++ b/src/com/android/car/settings/security/ConfirmLockPatternFragment.java
@@ -0,0 +1,173 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.car.settings.security;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.os.UserHandle;
+import android.view.View;
+import android.widget.TextView;
+
+import com.android.car.settings.R;
+import com.android.car.settings.common.BaseFragment;
+import com.android.internal.widget.LockPatternUtils;
+import com.android.internal.widget.LockPatternView;
+
+import java.util.List;
+
+/**
+ * Fragment for confirming existing lock pattern
+ */
+public class ConfirmLockPatternFragment extends BaseFragment {
+
+    private static final String FRAGMENT_TAG_CHECK_LOCK_WORKER = "check_lock_worker";
+    // Time we wait before clearing a wrong pattern and the error message.
+    private static final long CLEAR_WRONG_ATTEMPT_TIMEOUT_MS = 2500L;
+
+    private LockPatternView mLockPatternView;
+    private TextView mMsgView;
+
+    private LockPatternUtils mLockPatternUtils;
+    private CheckLockWorker mCheckLockWorker;
+    private CheckLockListener mCheckLockListener;
+
+    private int mUserId;
+    private List<LockPatternView.Cell> mPattern;
+
+    /**
+     * Factory method for creating ConfirmLockPatternFragment
+     */
+    public static ConfirmLockPatternFragment newInstance() {
+        ConfirmLockPatternFragment patternFragment = new ConfirmLockPatternFragment();
+        Bundle bundle = BaseFragment.getBundle();
+        bundle.putInt(EXTRA_TITLE_ID, R.string.security_settings_title);
+        bundle.putInt(EXTRA_ACTION_BAR_LAYOUT, R.layout.action_bar_with_button);
+        bundle.putInt(EXTRA_LAYOUT, R.layout.confirm_lock_pattern_fragment);
+        patternFragment.setArguments(bundle);
+        return patternFragment;
+    }
+
+    @Override
+    public void onAttach(Context context) {
+        super.onAttach(context);
+        if ((getActivity() instanceof CheckLockListener)) {
+            mCheckLockListener = (CheckLockListener) getActivity();
+        } else {
+            throw new RuntimeException("The activity must implement CheckLockListener");
+        }
+    }
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        mLockPatternUtils = new LockPatternUtils(getContext());
+        mUserId = UserHandle.myUserId();
+    }
+
+    @Override
+    public void onViewCreated(View view, Bundle savedInstanceState) {
+        super.onViewCreated(view, savedInstanceState);
+
+        mMsgView = (TextView) view.findViewById(R.id.message);
+        mLockPatternView = (LockPatternView) view.findViewById(R.id.lockPattern);
+        mLockPatternView.setFadePattern(false);
+        mLockPatternView.setInStealthMode(!mLockPatternUtils.isVisiblePatternEnabled(mUserId));
+        mLockPatternView.setOnPatternListener(mLockPatternListener);
+
+        if (savedInstanceState != null) {
+            mCheckLockWorker = (CheckLockWorker) getFragmentManager().findFragmentByTag(
+                    FRAGMENT_TAG_CHECK_LOCK_WORKER);
+        }
+    }
+
+    @Override
+    public void onStart() {
+        super.onStart();
+        if (mCheckLockWorker != null) {
+            mCheckLockWorker.setListener(this::onCheckCompleted);
+        }
+    }
+
+    @Override
+    public void onStop() {
+        super.onStop();
+        if (mCheckLockWorker != null) {
+            mCheckLockWorker.setListener(null);
+        }
+    }
+
+    private Runnable mClearErrorRunnable = () ->  {
+        mLockPatternView.clearPattern();
+        mMsgView.setText("");
+    };
+
+    private LockPatternView.OnPatternListener mLockPatternListener =
+            new LockPatternView.OnPatternListener() {
+
+        public void onPatternStart() {
+            mLockPatternView.removeCallbacks(mClearErrorRunnable);
+            mMsgView.setText("");
+        }
+
+        public void onPatternCleared() {
+            mLockPatternView.removeCallbacks(mClearErrorRunnable);
+        }
+
+        public void onPatternCellAdded(List<LockPatternView.Cell> pattern) {}
+
+        public void onPatternDetected(List<LockPatternView.Cell> pattern) {
+            mLockPatternView.setEnabled(false);
+
+            if (mCheckLockWorker == null) {
+                mCheckLockWorker = new CheckLockWorker();
+                mCheckLockWorker.setListener(ConfirmLockPatternFragment.this::onCheckCompleted);
+
+                getFragmentManager()
+                        .beginTransaction()
+                        .add(mCheckLockWorker, FRAGMENT_TAG_CHECK_LOCK_WORKER)
+                        .commitNow();
+            }
+
+            mPattern = pattern;
+            mCheckLockWorker.checkPattern(mUserId, pattern);
+        }
+    };
+
+    private void onCheckCompleted(boolean lockMatched) {
+        if (lockMatched) {
+            mCheckLockListener.onLockVerified(LockPatternUtils.patternToString(mPattern));
+        } else {
+            mLockPatternView.setEnabled(true);
+            mMsgView.setText(R.string.lockpattern_pattern_wrong);
+
+            // Set timer to clear wrong pattern
+            mLockPatternView.removeCallbacks(mClearErrorRunnable);
+            mLockPatternView.postDelayed(mClearErrorRunnable, CLEAR_WRONG_ATTEMPT_TIMEOUT_MS);
+        }
+    }
+
+    /**
+     * Interface the containing activity must implement to handle when lock has been verified
+     */
+    interface CheckLockListener {
+        /**
+         * Callback when user-entered credential has been verified
+         * @param lock The verified credential
+         */
+        void onLockVerified(String lock);
+    }
+}
diff --git a/src/com/android/car/settings/security/SaveLockWorkerBase.java b/src/com/android/car/settings/security/SaveLockWorkerBase.java
index 8fcb668..a3504e2 100644
--- a/src/com/android/car/settings/security/SaveLockWorkerBase.java
+++ b/src/com/android/car/settings/security/SaveLockWorkerBase.java
@@ -61,7 +61,6 @@
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setRetainInstance(true);
-        mFinished = false;
     }
 
     final void init(int userId) {
diff --git a/src/com/android/car/settings/security/SettingsScreenLockActivity.java b/src/com/android/car/settings/security/SettingsScreenLockActivity.java
new file mode 100644
index 0000000..5881152
--- /dev/null
+++ b/src/com/android/car/settings/security/SettingsScreenLockActivity.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.car.settings.security;
+
+import android.app.admin.DevicePolicyManager;
+import android.os.Bundle;
+import android.os.UserHandle;
+
+import com.android.car.settings.R;
+import com.android.car.settings.common.BaseFragment;
+import com.android.car.settings.common.CarSettingActivity;
+import com.android.internal.widget.LockPatternUtils;
+
+/**
+ * Activity for setting screen locks
+ */
+public class SettingsScreenLockActivity extends CarSettingActivity implements
+        ConfirmLockPatternFragment.CheckLockListener {
+
+    public static final String EXTRA_CURRENT_SCREEN_LOCK = "extra_current_screen_lock";
+
+    private int mPasswordQuality;
+    private LockPatternUtils mLockPatternUtils;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        mLockPatternUtils = new LockPatternUtils(this);
+        mPasswordQuality = mLockPatternUtils.getKeyguardStoredPasswordQuality(
+                UserHandle.myUserId());
+
+        BaseFragment fragment;
+        switch(mPasswordQuality) {
+            case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
+                fragment = ConfirmLockPatternFragment.newInstance();
+                break;
+            default:
+                // TODO implement the remaining quality values then show ConfirmPassword and log
+                // error
+                fragment = ChooseLockTypeFragment.newInstance();
+        }
+
+        fragment.setFragmentController(this);
+
+        getSupportFragmentManager()
+                .beginTransaction()
+                .add(R.id.fragment_container, fragment)
+                .addToBackStack(null)
+                .commit();
+    }
+
+    @Override
+    public void onLockVerified(String lock) {
+        BaseFragment fragment = ChooseLockTypeFragment.newInstance();
+        Bundle bundle = fragment.getArguments();
+        if (bundle == null) {
+            bundle = new Bundle();
+        }
+        bundle.putString(EXTRA_CURRENT_SCREEN_LOCK, lock);
+        fragment.setArguments(bundle);
+        fragment.setFragmentController(this);
+
+        getSupportFragmentManager()
+                .beginTransaction()
+                .replace(R.id.fragment_container, fragment)
+                .commit();
+    }
+}