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 import com.google.android.setupdesign.util.ContentStyler; 37 import com.google.android.setupdesign.util.ThemeHelper; 38 39 /** 40 * An activity that asks the user to contact their admin to get assistance with forgotten password. 41 */ 42 public class ForgotPasswordActivity extends Activity { 43 public static final String TAG = ForgotPasswordActivity.class.getSimpleName(); 44 @Override onCreate(Bundle savedInstanceState)45 protected void onCreate(Bundle savedInstanceState) { 46 super.onCreate(savedInstanceState); 47 int userId = getIntent().getIntExtra(Intent.EXTRA_USER_ID, -1); 48 if (userId < 0) { 49 Log.e(TAG, "No valid userId supplied, exiting"); 50 finish(); 51 return; 52 } 53 ThemeHelper.trySetDynamicColor(this); 54 setContentView(R.layout.forgot_password_activity); 55 56 DevicePolicyManager devicePolicyManager = getSystemService(DevicePolicyManager.class); 57 TextView forgotPasswordText = (TextView) findViewById(R.id.forgot_password_text); 58 forgotPasswordText.setText(devicePolicyManager.getResources().getString( 59 FORGOT_PASSWORD_TEXT, () -> getString(R.string.forgot_password_text))); 60 61 final GlifLayout layout = findViewById(R.id.setup_wizard_layout); 62 layout.getMixin(FooterBarMixin.class).setPrimaryButton( 63 new FooterButton.Builder(this) 64 .setText(android.R.string.ok) 65 .setListener(v -> finish()) 66 .setButtonType(FooterButton.ButtonType.DONE) 67 .setTheme(com.google.android.setupdesign.R.style.SudGlifButton_Primary) 68 .build() 69 ); 70 71 if (ThemeHelper.shouldApplyMaterialYouStyle(this)) { 72 ContentStyler.applyBodyPartnerCustomizationStyle( 73 layout.findViewById(R.id.forgot_password_text)); 74 } 75 76 layout.setHeaderText(devicePolicyManager.getResources().getString( 77 FORGOT_PASSWORD_TITLE, () -> getString(R.string.forgot_password_title))); 78 79 UserManager.get(this).requestQuietModeEnabled( 80 false, UserHandle.of(userId), UserManager.QUIET_MODE_DISABLE_DONT_ASK_CREDENTIAL); 81 } 82 } 83