Home | History | Annotate | Download | only in settings
      1 
      2 /*
      3  * Copyright (C) 2014 The Android Open Source Project
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *      http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 package com.android.settings;
     19 
     20 import android.app.Activity;
     21 import android.app.KeyguardManager;
     22 import android.content.Intent;
     23 import android.os.Bundle;
     24 import android.util.Log;
     25 
     26 /**
     27  * Launch this when you want to confirm the user is present by asking them to enter their
     28  * PIN/password/pattern.
     29  */
     30 public class ConfirmDeviceCredentialActivity extends Activity {
     31     public static final String TAG = ConfirmDeviceCredentialActivity.class.getSimpleName();
     32 
     33     public static Intent createIntent(CharSequence title, CharSequence details) {
     34         Intent intent = new Intent();
     35         intent.setClassName("com.android.settings",
     36                 ConfirmDeviceCredentialActivity.class.getName());
     37         intent.putExtra(KeyguardManager.EXTRA_TITLE, title);
     38         intent.putExtra(KeyguardManager.EXTRA_DESCRIPTION, details);
     39         return intent;
     40     }
     41 
     42     public static Intent createIntent(CharSequence title, CharSequence details, long challenge) {
     43         Intent intent = new Intent();
     44         intent.setClassName("com.android.settings",
     45                 ConfirmDeviceCredentialActivity.class.getName());
     46         intent.putExtra(KeyguardManager.EXTRA_TITLE, title);
     47         intent.putExtra(KeyguardManager.EXTRA_DESCRIPTION, details);
     48         intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, challenge);
     49         intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, true);
     50         return intent;
     51     }
     52 
     53     @Override
     54     public void onCreate(Bundle savedInstanceState) {
     55         super.onCreate(savedInstanceState);
     56 
     57         Intent intent = getIntent();
     58         String title = intent.getStringExtra(KeyguardManager.EXTRA_TITLE);
     59         String details = intent.getStringExtra(KeyguardManager.EXTRA_DESCRIPTION);
     60 
     61         // Ignore rotates and ensure we only launch this once
     62         if (savedInstanceState == null) {
     63             ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(this);
     64             if (!helper.launchConfirmationActivity(0 /* request code */, null /* title */, title,
     65                     details, false /* returnCredentials */, true /* isExternal */)) {
     66                 Log.d(TAG, "No pattern, password or PIN set.");
     67                 setResult(Activity.RESULT_OK);
     68                 finish();
     69             }
     70         }
     71     }
     72 
     73     @Override
     74     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
     75         boolean credentialsConfirmed = (resultCode == Activity.RESULT_OK);
     76         Log.d(TAG, "Device credentials confirmed: " + credentialsConfirmed);
     77         setResult(credentialsConfirmed ? Activity.RESULT_OK : Activity.RESULT_CANCELED);
     78         finish();
     79     }
     80 }
     81