blob: 5f7b6392369f87def41821d139ff30fc870d54f3 [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;
Muyuan Li4811ab42016-05-20 14:27:14 -070025import android.content.pm.PackageManager;
Jeff Sharkeybc16a072015-12-18 17:19:27 -070026import android.content.pm.ResolveInfo;
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070027import android.os.Bundle;
Jeff Sharkeybc16a072015-12-18 17:19:27 -070028import android.os.Handler;
29import android.os.Message;
Muyuan Li4811ab42016-05-20 14:27:14 -070030import android.os.UserHandle;
Jorim Jaggi98407942016-08-02 11:53:12 +020031import android.os.PowerManager;
32import android.os.SystemClock;
Jeff Sharkeybc16a072015-12-18 17:19:27 -070033import android.os.UserManager;
Jeff Sharkeyc80dc5e2016-05-03 17:25:37 -060034import android.provider.Settings;
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070035import android.util.Log;
Jorim Jaggia616a0d2016-06-29 16:33:39 -070036import android.view.View;
Jorim Jaggi98407942016-08-02 11:53:12 +020037import android.view.WindowManager;
38import android.view.WindowManager.LayoutParams;
39import android.view.animation.AnimationUtils;
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070040
Jeff Sharkeybc16a072015-12-18 17:19:27 -070041import java.util.Objects;
42
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070043public class FallbackHome extends Activity {
44 private static final String TAG = "FallbackHome";
Jorim Jaggi98407942016-08-02 11:53:12 +020045 private static final int PROGRESS_TIMEOUT = 2000;
46
47 private boolean mProvisioned;
48
49 private final Runnable mProgressTimeoutRunnable = () -> {
50 View v = getLayoutInflater().inflate(
51 R.layout.fallback_home_finishing_boot, null /* root */);
52 setContentView(v);
53 v.setAlpha(0f);
54 v.animate()
55 .alpha(1f)
56 .setDuration(500)
57 .setInterpolator(AnimationUtils.loadInterpolator(
58 this, android.R.interpolator.fast_out_slow_in))
59 .start();
60 getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
61 };
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070062
63 @Override
64 protected void onCreate(Bundle savedInstanceState) {
65 super.onCreate(savedInstanceState);
Jeff Sharkeyc80dc5e2016-05-03 17:25:37 -060066
67 // Set ourselves totally black before the device is provisioned so that
68 // we don't flash the wallpaper before SUW
Jorim Jaggi98407942016-08-02 11:53:12 +020069 mProvisioned = Settings.Global.getInt(getContentResolver(),
70 Settings.Global.DEVICE_PROVISIONED, 0) != 0;
71 if (!mProvisioned) {
Jorim Jaggia616a0d2016-06-29 16:33:39 -070072 setTheme(R.style.FallbackHome_SetupWizard);
73 getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN
74 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
Jorim Jaggi98407942016-08-02 11:53:12 +020075 } else {
76 getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
77 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Jeff Sharkeyc80dc5e2016-05-03 17:25:37 -060078 }
79
Jorim Jaggic0c583c2016-11-02 20:33:32 +000080 registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_USER_UNLOCKED));
Jeff Sharkeybc16a072015-12-18 17:19:27 -070081 maybeFinish();
82 }
83
84 @Override
Jorim Jaggi98407942016-08-02 11:53:12 +020085 protected void onResume() {
86 super.onResume();
87 if (mProvisioned) {
88 mHandler.postDelayed(mProgressTimeoutRunnable, PROGRESS_TIMEOUT);
89 }
90 }
91
92 @Override
93 protected void onPause() {
94 super.onPause();
95 mHandler.removeCallbacks(mProgressTimeoutRunnable);
96 }
97
Jeff Sharkeybc16a072015-12-18 17:19:27 -070098 protected void onDestroy() {
99 super.onDestroy();
100 unregisterReceiver(mReceiver);
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -0700101 }
102
103 private BroadcastReceiver mReceiver = new BroadcastReceiver() {
104 @Override
105 public void onReceive(Context context, Intent intent) {
Jeff Sharkeybc16a072015-12-18 17:19:27 -0700106 maybeFinish();
107 }
108 };
109
110 private void maybeFinish() {
111 if (getSystemService(UserManager.class).isUserUnlocked()) {
112 final Intent homeIntent = new Intent(Intent.ACTION_MAIN)
113 .addCategory(Intent.CATEGORY_HOME);
114 final ResolveInfo homeInfo = getPackageManager().resolveActivity(homeIntent, 0);
115 if (Objects.equals(getPackageName(), homeInfo.activityInfo.packageName)) {
Muyuan Li4811ab42016-05-20 14:27:14 -0700116 if (UserManager.isSplitSystemUser()
117 && UserHandle.myUserId() == UserHandle.USER_SYSTEM) {
118 // This avoids the situation where the system user has no home activity after
119 // SUW and this activity continues to throw out warnings. See b/28870689.
120 return;
121 }
Jeff Sharkeybc16a072015-12-18 17:19:27 -0700122 Log.d(TAG, "User unlocked but no home; let's hope someone enables one soon?");
123 mHandler.sendEmptyMessageDelayed(0, 500);
124 } else {
125 Log.d(TAG, "User unlocked and real home found; let's go!");
Jorim Jaggi98407942016-08-02 11:53:12 +0200126 getSystemService(PowerManager.class).userActivity(
127 SystemClock.uptimeMillis(), false);
Jeff Sharkeybc16a072015-12-18 17:19:27 -0700128 finish();
129 }
130 }
131 }
132
133 private Handler mHandler = new Handler() {
134 @Override
135 public void handleMessage(Message msg) {
136 maybeFinish();
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -0700137 }
138 };
139}