blob: 84a3283b7383ce3d3f63f808ddce2d8843dbb832 [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;
Matthew Ngdd396492018-05-31 13:30:27 -070021import android.app.WallpaperColors;
22import android.app.WallpaperManager;
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070023import android.content.BroadcastReceiver;
24import android.content.Context;
25import android.content.Intent;
26import android.content.IntentFilter;
Muyuan Li4811ab42016-05-20 14:27:14 -070027import android.content.pm.PackageManager;
Jeff Sharkeybc16a072015-12-18 17:19:27 -070028import android.content.pm.ResolveInfo;
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070029import android.os.Bundle;
Jeff Sharkeybc16a072015-12-18 17:19:27 -070030import android.os.Handler;
31import android.os.Message;
Muyuan Li4811ab42016-05-20 14:27:14 -070032import android.os.UserHandle;
Jorim Jaggi98407942016-08-02 11:53:12 +020033import android.os.PowerManager;
34import android.os.SystemClock;
Jeff Sharkeybc16a072015-12-18 17:19:27 -070035import android.os.UserManager;
Jeff Sharkeyc80dc5e2016-05-03 17:25:37 -060036import android.provider.Settings;
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070037import android.util.Log;
Jorim Jaggia616a0d2016-06-29 16:33:39 -070038import android.view.View;
Jorim Jaggi98407942016-08-02 11:53:12 +020039import android.view.WindowManager;
40import android.view.WindowManager.LayoutParams;
41import android.view.animation.AnimationUtils;
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070042
Jeff Sharkeybc16a072015-12-18 17:19:27 -070043import java.util.Objects;
44
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070045public class FallbackHome extends Activity {
46 private static final String TAG = "FallbackHome";
Jorim Jaggi98407942016-08-02 11:53:12 +020047 private static final int PROGRESS_TIMEOUT = 2000;
48
49 private boolean mProvisioned;
50
51 private final Runnable mProgressTimeoutRunnable = () -> {
52 View v = getLayoutInflater().inflate(
53 R.layout.fallback_home_finishing_boot, null /* root */);
54 setContentView(v);
55 v.setAlpha(0f);
56 v.animate()
57 .alpha(1f)
58 .setDuration(500)
59 .setInterpolator(AnimationUtils.loadInterpolator(
60 this, android.R.interpolator.fast_out_slow_in))
61 .start();
62 getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
63 };
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070064
65 @Override
66 protected void onCreate(Bundle savedInstanceState) {
67 super.onCreate(savedInstanceState);
Jeff Sharkeyc80dc5e2016-05-03 17:25:37 -060068
69 // Set ourselves totally black before the device is provisioned so that
70 // we don't flash the wallpaper before SUW
Jorim Jaggi98407942016-08-02 11:53:12 +020071 mProvisioned = Settings.Global.getInt(getContentResolver(),
72 Settings.Global.DEVICE_PROVISIONED, 0) != 0;
Matthew Ngdd396492018-05-31 13:30:27 -070073 int flags;
Jorim Jaggi98407942016-08-02 11:53:12 +020074 if (!mProvisioned) {
Jorim Jaggia616a0d2016-06-29 16:33:39 -070075 setTheme(R.style.FallbackHome_SetupWizard);
Matthew Ngdd396492018-05-31 13:30:27 -070076 flags = View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
77 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
Jorim Jaggi98407942016-08-02 11:53:12 +020078 } else {
Matthew Ngdd396492018-05-31 13:30:27 -070079 flags = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
80 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
Jeff Sharkeyc80dc5e2016-05-03 17:25:37 -060081 }
82
Matthew Ngdd396492018-05-31 13:30:27 -070083 // Set the system ui flags to light status bar if the wallpaper supports dark text to match
84 // current system ui color tints.
85 final WallpaperColors colors = getSystemService(WallpaperManager.class)
86 .getWallpaperColors(WallpaperManager.FLAG_SYSTEM);
87 if (colors != null
88 && (colors.getColorHints() & WallpaperColors.HINT_SUPPORTS_DARK_TEXT) != 0) {
89 flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
90 | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
91 }
92 getWindow().getDecorView().setSystemUiVisibility(flags);
93
Jorim Jaggic0c583c2016-11-02 20:33:32 +000094 registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_USER_UNLOCKED));
Jeff Sharkeybc16a072015-12-18 17:19:27 -070095 maybeFinish();
96 }
97
98 @Override
Jorim Jaggi98407942016-08-02 11:53:12 +020099 protected void onResume() {
100 super.onResume();
101 if (mProvisioned) {
102 mHandler.postDelayed(mProgressTimeoutRunnable, PROGRESS_TIMEOUT);
103 }
104 }
105
106 @Override
107 protected void onPause() {
108 super.onPause();
109 mHandler.removeCallbacks(mProgressTimeoutRunnable);
110 }
111
Jeff Sharkeybc16a072015-12-18 17:19:27 -0700112 protected void onDestroy() {
113 super.onDestroy();
114 unregisterReceiver(mReceiver);
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -0700115 }
116
117 private BroadcastReceiver mReceiver = new BroadcastReceiver() {
118 @Override
119 public void onReceive(Context context, Intent intent) {
Jeff Sharkeybc16a072015-12-18 17:19:27 -0700120 maybeFinish();
121 }
122 };
123
124 private void maybeFinish() {
125 if (getSystemService(UserManager.class).isUserUnlocked()) {
126 final Intent homeIntent = new Intent(Intent.ACTION_MAIN)
127 .addCategory(Intent.CATEGORY_HOME);
128 final ResolveInfo homeInfo = getPackageManager().resolveActivity(homeIntent, 0);
129 if (Objects.equals(getPackageName(), homeInfo.activityInfo.packageName)) {
Muyuan Li4811ab42016-05-20 14:27:14 -0700130 if (UserManager.isSplitSystemUser()
131 && UserHandle.myUserId() == UserHandle.USER_SYSTEM) {
132 // This avoids the situation where the system user has no home activity after
133 // SUW and this activity continues to throw out warnings. See b/28870689.
134 return;
135 }
Jeff Sharkeybc16a072015-12-18 17:19:27 -0700136 Log.d(TAG, "User unlocked but no home; let's hope someone enables one soon?");
137 mHandler.sendEmptyMessageDelayed(0, 500);
138 } else {
139 Log.d(TAG, "User unlocked and real home found; let's go!");
Jorim Jaggi98407942016-08-02 11:53:12 +0200140 getSystemService(PowerManager.class).userActivity(
141 SystemClock.uptimeMillis(), false);
Jeff Sharkeybc16a072015-12-18 17:19:27 -0700142 finish();
143 }
144 }
145 }
146
147 private Handler mHandler = new Handler() {
148 @Override
149 public void handleMessage(Message msg) {
150 maybeFinish();
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -0700151 }
152 };
153}