blob: f2e8152ae2277d2d0e3a50aa2b097534574328bc [file] [log] [blame]
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -07001/*
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
17package com.android.settings;
18
19import android.app.Activity;
Jorim Jaggi98407942016-08-02 11:53:12 +020020import android.app.ProgressDialog;
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070021import android.content.BroadcastReceiver;
22import android.content.Context;
23import android.content.Intent;
24import android.content.IntentFilter;
Jeff Sharkeybc16a072015-12-18 17:19:27 -070025import android.content.pm.ResolveInfo;
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070026import android.os.Bundle;
Jeff Sharkeybc16a072015-12-18 17:19:27 -070027import android.os.Handler;
28import android.os.Message;
Jorim Jaggi98407942016-08-02 11:53:12 +020029import android.os.PowerManager;
30import android.os.SystemClock;
Jeff Sharkeybc16a072015-12-18 17:19:27 -070031import android.os.UserManager;
Jeff Sharkeyc80dc5e2016-05-03 17:25:37 -060032import android.provider.Settings;
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070033import android.util.Log;
Jorim Jaggia616a0d2016-06-29 16:33:39 -070034import android.view.View;
Jorim Jaggi98407942016-08-02 11:53:12 +020035import android.view.WindowManager;
36import android.view.WindowManager.LayoutParams;
37import android.view.animation.AnimationUtils;
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070038
Jeff Sharkeybc16a072015-12-18 17:19:27 -070039import java.util.Objects;
40
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070041public class FallbackHome extends Activity {
42 private static final String TAG = "FallbackHome";
Jorim Jaggi98407942016-08-02 11:53:12 +020043 private static final int PROGRESS_TIMEOUT = 2000;
44
45 private boolean mProvisioned;
46
47 private final Runnable mProgressTimeoutRunnable = () -> {
48 View v = getLayoutInflater().inflate(
49 R.layout.fallback_home_finishing_boot, null /* root */);
50 setContentView(v);
51 v.setAlpha(0f);
52 v.animate()
53 .alpha(1f)
54 .setDuration(500)
55 .setInterpolator(AnimationUtils.loadInterpolator(
56 this, android.R.interpolator.fast_out_slow_in))
57 .start();
58 getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
59 };
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070060
61 @Override
62 protected void onCreate(Bundle savedInstanceState) {
63 super.onCreate(savedInstanceState);
Jeff Sharkeyc80dc5e2016-05-03 17:25:37 -060064
65 // Set ourselves totally black before the device is provisioned so that
66 // we don't flash the wallpaper before SUW
Jorim Jaggi98407942016-08-02 11:53:12 +020067 mProvisioned = Settings.Global.getInt(getContentResolver(),
68 Settings.Global.DEVICE_PROVISIONED, 0) != 0;
69 if (!mProvisioned) {
Jorim Jaggia616a0d2016-06-29 16:33:39 -070070 setTheme(R.style.FallbackHome_SetupWizard);
71 getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN
72 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
Jorim Jaggi98407942016-08-02 11:53:12 +020073 } else {
74 getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
75 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Jeff Sharkeyc80dc5e2016-05-03 17:25:37 -060076 }
77
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070078 registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_USER_UNLOCKED));
Jeff Sharkeybc16a072015-12-18 17:19:27 -070079 maybeFinish();
80 }
81
82 @Override
Jorim Jaggi98407942016-08-02 11:53:12 +020083 protected void onResume() {
84 super.onResume();
85 if (mProvisioned) {
86 mHandler.postDelayed(mProgressTimeoutRunnable, PROGRESS_TIMEOUT);
87 }
88 }
89
90 @Override
91 protected void onPause() {
92 super.onPause();
93 mHandler.removeCallbacks(mProgressTimeoutRunnable);
94 }
95
Jeff Sharkeybc16a072015-12-18 17:19:27 -070096 protected void onDestroy() {
97 super.onDestroy();
98 unregisterReceiver(mReceiver);
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070099 }
100
101 private BroadcastReceiver mReceiver = new BroadcastReceiver() {
102 @Override
103 public void onReceive(Context context, Intent intent) {
Jeff Sharkeybc16a072015-12-18 17:19:27 -0700104 maybeFinish();
105 }
106 };
107
108 private void maybeFinish() {
109 if (getSystemService(UserManager.class).isUserUnlocked()) {
110 final Intent homeIntent = new Intent(Intent.ACTION_MAIN)
111 .addCategory(Intent.CATEGORY_HOME);
112 final ResolveInfo homeInfo = getPackageManager().resolveActivity(homeIntent, 0);
113 if (Objects.equals(getPackageName(), homeInfo.activityInfo.packageName)) {
114 Log.d(TAG, "User unlocked but no home; let's hope someone enables one soon?");
115 mHandler.sendEmptyMessageDelayed(0, 500);
116 } else {
117 Log.d(TAG, "User unlocked and real home found; let's go!");
Jorim Jaggi98407942016-08-02 11:53:12 +0200118 getSystemService(PowerManager.class).userActivity(
119 SystemClock.uptimeMillis(), false);
Jeff Sharkeybc16a072015-12-18 17:19:27 -0700120 finish();
121 }
122 }
123 }
124
125 private Handler mHandler = new Handler() {
126 @Override
127 public void handleMessage(Message msg) {
128 maybeFinish();
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -0700129 }
130 };
131}