• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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 android.app.Fragment;
20 import android.app.KeyguardManager;
21 import android.os.Bundle;
22 import android.os.UserManager;
23 import android.view.MenuItem;
24 import android.view.WindowManager;
25 import android.widget.LinearLayout;
26 
27 import com.android.settings.R;
28 import com.android.settings.SettingsActivity;
29 import com.android.settings.SetupWizardUtils;
30 import com.android.settings.Utils;
31 
32 public abstract class ConfirmDeviceCredentialBaseActivity extends SettingsActivity {
33 
34     private static final String STATE_IS_KEYGUARD_LOCKED = "STATE_IS_KEYGUARD_LOCKED";
35 
36     enum ConfirmCredentialTheme {
37         INTERNAL,
38         DARK,
39         WORK
40     }
41 
42     private boolean mRestoring;
43     private boolean mEnterAnimationPending;
44     private boolean mFirstTimeVisible = true;
45     private boolean mIsKeyguardLocked = false;
46     private ConfirmCredentialTheme mConfirmCredentialTheme;
47 
48     @Override
onCreate(Bundle savedState)49     protected void onCreate(Bundle savedState) {
50         int credentialOwnerUserId = Utils.getCredentialOwnerUserId(this,
51                 Utils.getUserIdFromBundle(this, getIntent().getExtras()));
52         if (UserManager.get(this).isManagedProfile(credentialOwnerUserId)) {
53             setTheme(R.style.Theme_ConfirmDeviceCredentialsWork);
54             mConfirmCredentialTheme = ConfirmCredentialTheme.WORK;
55         } else if (getIntent().getBooleanExtra(
56                 ConfirmDeviceCredentialBaseFragment.DARK_THEME, false)) {
57             setTheme(R.style.Theme_ConfirmDeviceCredentialsDark);
58             mConfirmCredentialTheme = ConfirmCredentialTheme.DARK;
59         } else {
60             setTheme(SetupWizardUtils.getTheme(getIntent()));
61             mConfirmCredentialTheme = ConfirmCredentialTheme.INTERNAL;
62         }
63         super.onCreate(savedState);
64 
65         if (mConfirmCredentialTheme == ConfirmCredentialTheme.INTERNAL) {
66             // Prevent the content parent from consuming the window insets because GlifLayout uses
67             // it to show the status bar background.
68             LinearLayout layout = (LinearLayout) findViewById(R.id.content_parent);
69             layout.setFitsSystemWindows(false);
70         }
71         getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
72         mIsKeyguardLocked = savedState == null
73                 ? getSystemService(KeyguardManager.class).isKeyguardLocked()
74                 : savedState.getBoolean(STATE_IS_KEYGUARD_LOCKED, false);
75         // If the activity is launched, not due to config change, when keyguard is locked and the
76         // flag is set, assume it's launched on top of keyguard on purpose.
77         // TODO: Don't abuse SHOW_WHEN_LOCKED and don't check isKeyguardLocked.
78         // Set extra SHOW_WHEN_LOCKED and WindowManager FLAG_SHOW_WHEN_LOCKED only if it's
79         // truly on top of keyguard on purpose
80         if (mIsKeyguardLocked && getIntent().getBooleanExtra(
81                 ConfirmDeviceCredentialBaseFragment.SHOW_WHEN_LOCKED, false)) {
82             getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
83         }
84         CharSequence msg = getIntent().getStringExtra(
85                 ConfirmDeviceCredentialBaseFragment.TITLE_TEXT);
86         setTitle(msg);
87         if (getActionBar() != null) {
88             getActionBar().setDisplayHomeAsUpEnabled(true);
89             getActionBar().setHomeButtonEnabled(true);
90         }
91         mRestoring = savedState != null;
92     }
93 
94     @Override
onSaveInstanceState(Bundle outState)95     public void onSaveInstanceState(Bundle outState) {
96         super.onSaveInstanceState(outState);
97         outState.putBoolean(STATE_IS_KEYGUARD_LOCKED, mIsKeyguardLocked);
98     }
99 
100     @Override
onOptionsItemSelected(MenuItem item)101     public boolean onOptionsItemSelected(MenuItem item) {
102         if (item.getItemId() == android.R.id.home) {
103             finish();
104             return true;
105         }
106         return super.onOptionsItemSelected(item);
107     }
108 
109     @Override
onResume()110     public void onResume() {
111         super.onResume();
112         if (!isChangingConfigurations() && !mRestoring
113                 && mConfirmCredentialTheme == ConfirmCredentialTheme.DARK && mFirstTimeVisible) {
114             mFirstTimeVisible = false;
115             prepareEnterAnimation();
116             mEnterAnimationPending = true;
117         }
118     }
119 
getFragment()120     private ConfirmDeviceCredentialBaseFragment getFragment() {
121         Fragment fragment = getFragmentManager().findFragmentById(R.id.main_content);
122         if (fragment != null && fragment instanceof ConfirmDeviceCredentialBaseFragment) {
123             return (ConfirmDeviceCredentialBaseFragment) fragment;
124         }
125         return null;
126     }
127 
128     @Override
onEnterAnimationComplete()129     public void onEnterAnimationComplete() {
130         super.onEnterAnimationComplete();
131         if (mEnterAnimationPending) {
132             startEnterAnimation();
133             mEnterAnimationPending = false;
134         }
135     }
136 
137     @Override
isLaunchableInTaskModePinned()138     public boolean isLaunchableInTaskModePinned() {
139         return true;
140     }
141 
prepareEnterAnimation()142     public void prepareEnterAnimation() {
143         getFragment().prepareEnterAnimation();
144     }
145 
startEnterAnimation()146     public void startEnterAnimation() {
147         getFragment().startEnterAnimation();
148     }
149 
getConfirmCredentialTheme()150     public ConfirmCredentialTheme getConfirmCredentialTheme() {
151         return mConfirmCredentialTheme;
152     }
153 }
154