2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings;
19 import android.app.Activity;
20 import android.app.ProgressDialog;
21 import android.content.BroadcastReceiver;
22 import android.content.Context;
23 import android.content.Intent;
24 import android.content.IntentFilter;
25 import android.content.pm.PackageManager;
26 import android.content.pm.ResolveInfo;
27 import android.os.Bundle;
28 import android.os.Handler;
29 import android.os.Message;
30 import android.os.UserHandle;
31 import android.os.PowerManager;
32 import android.os.SystemClock;
33 import android.os.UserManager;
34 import android.provider.Settings;
35 import android.util.Log;
36 import android.view.View;
37 import android.view.WindowManager;
38 import android.view.WindowManager.LayoutParams;
39 import android.view.animation.AnimationUtils;
41 import java.util.Objects;
43 public class FallbackHome extends Activity {
44 private static final String TAG = "FallbackHome";
45 private static final int PROGRESS_TIMEOUT = 2000;
47 private boolean mProvisioned;
49 private final Runnable mProgressTimeoutRunnable = () -> {
50 View v = getLayoutInflater().inflate(
51 R.layout.fallback_home_finishing_boot, null /* root */);
57 .setInterpolator(AnimationUtils.loadInterpolator(
58 this, android.R.interpolator.fast_out_slow_in))
60 getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
64 protected void onCreate(Bundle savedInstanceState) {
65 super.onCreate(savedInstanceState);
67 // Set ourselves totally black before the device is provisioned so that
68 // we don't flash the wallpaper before SUW
69 mProvisioned = Settings.Global.getInt(getContentResolver(),
70 Settings.Global.DEVICE_PROVISIONED, 0) != 0;
72 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);
76 getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
77 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
80 registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_USER_UNLOCKED));
85 protected void onResume() {
88 mHandler.postDelayed(mProgressTimeoutRunnable, PROGRESS_TIMEOUT);
93 protected void onPause() {
95 mHandler.removeCallbacks(mProgressTimeoutRunnable);
98 protected void onDestroy() {
100 unregisterReceiver(mReceiver);
103 private BroadcastReceiver mReceiver = new BroadcastReceiver() {
105 public void onReceive(Context context, Intent intent) {
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)) {
116 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.
122 Log.d(TAG, "User unlocked but no home; let's hope someone enables one soon?");
123 mHandler.sendEmptyMessageDelayed(0, 500);
125 Log.d(TAG, "User unlocked and real home found; let's go!");
126 getSystemService(PowerManager.class).userActivity(
127 SystemClock.uptimeMillis(), false);
133 private Handler mHandler = new Handler() {
135 public void handleMessage(Message msg) {