• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.settings.password;
18 
19 import static android.app.admin.DevicePolicyResources.Strings.Settings.FORGOT_PASSWORD_TEXT;
20 import static android.app.admin.DevicePolicyResources.Strings.Settings.FORGOT_PASSWORD_TITLE;
21 
22 import android.app.Activity;
23 import android.app.admin.DevicePolicyManager;
24 import android.content.Intent;
25 import android.os.Bundle;
26 import android.os.UserHandle;
27 import android.os.UserManager;
28 import android.util.Log;
29 import android.widget.TextView;
30 
31 import com.android.settings.R;
32 
33 import com.google.android.setupcompat.template.FooterBarMixin;
34 import com.google.android.setupcompat.template.FooterButton;
35 import com.google.android.setupdesign.GlifLayout;
36 
37 /**
38  * An activity that asks the user to contact their admin to get assistance with forgotten password.
39  */
40 public class ForgotPasswordActivity extends Activity {
41     public static final String TAG = ForgotPasswordActivity.class.getSimpleName();
42     @Override
onCreate(Bundle savedInstanceState)43     protected void onCreate(Bundle savedInstanceState) {
44         super.onCreate(savedInstanceState);
45         int userId = getIntent().getIntExtra(Intent.EXTRA_USER_ID, -1);
46         if (userId < 0) {
47             Log.e(TAG, "No valid userId supplied, exiting");
48             finish();
49             return;
50         }
51         setContentView(R.layout.forgot_password_activity);
52 
53         DevicePolicyManager devicePolicyManager = getSystemService(DevicePolicyManager.class);
54         TextView forgotPasswordText = (TextView) findViewById(R.id.forgot_password_text);
55         forgotPasswordText.setText(devicePolicyManager.getResources().getString(
56                 FORGOT_PASSWORD_TEXT, () -> getString(R.string.forgot_password_text)));
57 
58         final GlifLayout layout = findViewById(R.id.setup_wizard_layout);
59         layout.getMixin(FooterBarMixin.class).setPrimaryButton(
60                 new FooterButton.Builder(this)
61                         .setText(android.R.string.ok)
62                         .setListener(v -> finish())
63                         .setButtonType(FooterButton.ButtonType.DONE)
64                         .setTheme(R.style.SudGlifButton_Primary)
65                         .build()
66         );
67 
68         layout.setHeaderText(devicePolicyManager.getResources().getString(
69                 FORGOT_PASSWORD_TITLE, () -> getString(R.string.forgot_password_title)));
70 
71         UserManager.get(this).requestQuietModeEnabled(
72                 false, UserHandle.of(userId), UserManager.QUIET_MODE_DISABLE_DONT_ASK_CREDENTIAL);
73     }
74 }
75