Index: chrome/android/java/src/org/chromium/chrome/browser/preferences/password/PasswordReauthentication.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/password/PasswordReauthentication.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/password/PasswordReauthentication.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b55d6577ba832af69441b8cc4295c6824100aa75 |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/password/PasswordReauthentication.java |
@@ -0,0 +1,73 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.chrome.browser.preferences.password; |
+ |
+import android.annotation.TargetApi; |
+import android.app.Fragment; |
+import android.app.FragmentManager; |
+import android.app.KeyguardManager; |
+import android.content.Context; |
+import android.content.Intent; |
+import android.os.Build; |
+import android.os.Build.VERSION_CODES; |
+import android.os.Bundle; |
+import android.widget.LinearLayout; |
+ |
+import org.chromium.chrome.R; |
+import org.chromium.ui.widget.Toast; |
+ |
+/** Show the lock screen confirmation and lock the screen. */ |
+public class PasswordReauthentication extends Fragment { |
+ |
+ private static final int CONFIRM_DEVICE_CREDENTIAL_REQUEST_CODE = 2; |
+ |
+ private LinearLayout mLayout; |
+ |
+ @Override |
+ public void onCreate(Bundle savedInstanceState) { |
+ super.onCreate(savedInstanceState); |
+ lockDeviceOnLollipop(); |
+ } |
+ |
+ @Override |
+ public void onActivityResult(int requestCode, int resultCode, Intent data) { |
+ super.onActivityResult(requestCode, resultCode, data); |
+ if (requestCode == CONFIRM_DEVICE_CREDENTIAL_REQUEST_CODE) { |
+ if (resultCode == getActivity().RESULT_OK) { |
+ SavePasswordsPreferences.setLastReauthTimeMillis(System.currentTimeMillis()); |
+ FragmentManager fragmentManager = getFragmentManager(); |
+ fragmentManager.popBackStack(); |
+ } |
+ } |
+ } |
+ |
+ /** |
+ * Should only be called on Lollipop or above devices. |
+ */ |
+ @TargetApi(VERSION_CODES.LOLLIPOP) |
+ private void lockDeviceOnLollipop() { |
+ // Use new L feature to lock screen. |
+ if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) { |
Bernhard Bauer
2016/08/03 16:07:36
Overall, showing the UI element to show passwords,
dozsa
2016/08/04 10:40:51
I've moved the logic to PasswordEntryEditor so tha
Bernhard Bauer
2016/08/05 09:14:20
Dunno, I would defer to the PM on that. If we allo
|
+ Toast.makeText(getActivity().getApplicationContext(), |
+ R.string.password_entry_editor_not_available_on_pre_lollipop, |
+ Toast.LENGTH_LONG).show(); |
Bernhard Bauer
2016/08/03 16:07:36
I'd probably return here so you don't need the els
dozsa
2016/08/04 10:40:51
Done.
|
+ } else { |
+ KeyguardManager keyguardManager = (KeyguardManager) |
+ getActivity().getSystemService(Context.KEYGUARD_SERVICE); |
+ if (keyguardManager != null) { |
Bernhard Bauer
2016/08/03 16:07:36
Actually, when would this be null? In PasswordEntr
dozsa
2016/08/04 10:40:51
True, I've removed the condition. As you said in y
|
+ Intent intent = keyguardManager.createConfirmDeviceCredentialIntent( |
+ null /* title */, |
+ getString(R.string.lockscreen_description) /* description */); |
+ if (intent != null) { |
+ startActivityForResult(intent, CONFIRM_DEVICE_CREDENTIAL_REQUEST_CODE); |
+ return; |
+ } |
+ } else { |
Bernhard Bauer
2016/08/03 16:07:36
You want to remove this `else` so you fall through
dozsa
2016/08/04 10:40:51
Done.
|
+ FragmentManager fragmentManager = getFragmentManager(); |
+ fragmentManager.popBackStackImmediate(); |
+ } |
+ } |
+ } |
+} |