blob: 7d5948eaa3aaf13ac0688220c322a2c66f032236 [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;
Matthew Ngdd396492018-05-31 13:30:27 -070020import android.app.WallpaperColors;
21import android.app.WallpaperManager;
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070022import android.content.BroadcastReceiver;
23import android.content.Context;
24import android.content.Intent;
25import android.content.IntentFilter;
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;
Jorim Jaggi98407942016-08-02 11:53:12 +020030import android.os.PowerManager;
31import android.os.SystemClock;
Fan Zhangc7162cd2018-06-18 15:21:41 -070032import android.os.UserHandle;
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.LayoutParams;
38import android.view.animation.AnimationUtils;
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070039
Jeff Sharkeybc16a072015-12-18 17:19:27 -070040import java.util.Objects;
41
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070042public class FallbackHome extends Activity {
43 private static final String TAG = "FallbackHome";
Jorim Jaggi98407942016-08-02 11:53:12 +020044 private static final int PROGRESS_TIMEOUT = 2000;
45
46 private boolean mProvisioned;
47
48 private final Runnable mProgressTimeoutRunnable = () -> {
49 View v = getLayoutInflater().inflate(
50 R.layout.fallback_home_finishing_boot, null /* root */);
51 setContentView(v);
52 v.setAlpha(0f);
53 v.animate()
54 .alpha(1f)
55 .setDuration(500)
56 .setInterpolator(AnimationUtils.loadInterpolator(
57 this, android.R.interpolator.fast_out_slow_in))
58 .start();
59 getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
60 };
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070061
62 @Override
63 protected void onCreate(Bundle savedInstanceState) {
64 super.onCreate(savedInstanceState);
Jeff Sharkeyc80dc5e2016-05-03 17:25:37 -060065
66 // Set ourselves totally black before the device is provisioned so that
67 // we don't flash the wallpaper before SUW
Jorim Jaggi98407942016-08-02 11:53:12 +020068 mProvisioned = Settings.Global.getInt(getContentResolver(),
69 Settings.Global.DEVICE_PROVISIONED, 0) != 0;
Matthew Ngdd396492018-05-31 13:30:27 -070070 int flags;
Jorim Jaggi98407942016-08-02 11:53:12 +020071 if (!mProvisioned) {
Jorim Jaggia616a0d2016-06-29 16:33:39 -070072 setTheme(R.style.FallbackHome_SetupWizard);
Matthew Ngdd396492018-05-31 13:30:27 -070073 flags = View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
74 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
Jorim Jaggi98407942016-08-02 11:53:12 +020075 } else {
Matthew Ngdd396492018-05-31 13:30:27 -070076 flags = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
77 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
Jeff Sharkeyc80dc5e2016-05-03 17:25:37 -060078 }
79
Matthew Ngdd396492018-05-31 13:30:27 -070080 // Set the system ui flags to light status bar if the wallpaper supports dark text to match
81 // current system ui color tints.
82 final WallpaperColors colors = getSystemService(WallpaperManager.class)
83 .getWallpaperColors(WallpaperManager.FLAG_SYSTEM);
84 if (colors != null
85 && (colors.getColorHints() & WallpaperColors.HINT_SUPPORTS_DARK_TEXT) != 0) {
86 flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
87 | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
88 }
89 getWindow().getDecorView().setSystemUiVisibility(flags);
90
Jorim Jaggic0c583c2016-11-02 20:33:32 +000091 registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_USER_UNLOCKED));
Jeff Sharkeybc16a072015-12-18 17:19:27 -070092 maybeFinish();
93 }
94
95 @Override
Jorim Jaggi98407942016-08-02 11:53:12 +020096 protected void onResume() {
97 super.onResume();
98 if (mProvisioned) {
99 mHandler.postDelayed(mProgressTimeoutRunnable, PROGRESS_TIMEOUT);
100 }
101 }
102
103 @Override
104 protected void onPause() {
105 super.onPause();
106 mHandler.removeCallbacks(mProgressTimeoutRunnable);
107 }
108
Jeff Sharkeybc16a072015-12-18 17:19:27 -0700109 protected void onDestroy() {
110 super.onDestroy();
111 unregisterReceiver(mReceiver);
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -0700112 }
113
114 private BroadcastReceiver mReceiver = new BroadcastReceiver() {
115 @Override
116 public void onReceive(Context context, Intent intent) {
Jeff Sharkeybc16a072015-12-18 17:19:27 -0700117 maybeFinish();
118 }
119 };
120
121 private void maybeFinish() {
122 if (getSystemService(UserManager.class).isUserUnlocked()) {
123 final Intent homeIntent = new Intent(Intent.ACTION_MAIN)
124 .addCategory(Intent.CATEGORY_HOME);
125 final ResolveInfo homeInfo = getPackageManager().resolveActivity(homeIntent, 0);
126 if (Objects.equals(getPackageName(), homeInfo.activityInfo.packageName)) {
Muyuan Li4811ab42016-05-20 14:27:14 -0700127 if (UserManager.isSplitSystemUser()
128 && UserHandle.myUserId() == UserHandle.USER_SYSTEM) {
129 // This avoids the situation where the system user has no home activity after
130 // SUW and this activity continues to throw out warnings. See b/28870689.
131 return;
132 }
Jeff Sharkeybc16a072015-12-18 17:19:27 -0700133 Log.d(TAG, "User unlocked but no home; let's hope someone enables one soon?");
134 mHandler.sendEmptyMessageDelayed(0, 500);
135 } else {
136 Log.d(TAG, "User unlocked and real home found; let's go!");
Jorim Jaggi98407942016-08-02 11:53:12 +0200137 getSystemService(PowerManager.class).userActivity(
138 SystemClock.uptimeMillis(), false);
Jeff Sharkeybc16a072015-12-18 17:19:27 -0700139 finish();
140 }
141 }
142 }
143
144 private Handler mHandler = new Handler() {
145 @Override
146 public void handleMessage(Message msg) {
147 maybeFinish();
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -0700148 }
149 };
150}