Jeff Sharkey | 9e9f7d1 | 2015-11-30 13:28:19 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.settings; |
| 18 | |
| 19 | import android.app.Activity; |
Matthew Ng | dd39649 | 2018-05-31 13:30:27 -0700 | [diff] [blame] | 20 | import android.app.WallpaperColors; |
| 21 | import android.app.WallpaperManager; |
Jeff Sharkey | 9e9f7d1 | 2015-11-30 13:28:19 -0700 | [diff] [blame] | 22 | import android.content.BroadcastReceiver; |
| 23 | import android.content.Context; |
| 24 | import android.content.Intent; |
| 25 | import android.content.IntentFilter; |
Jeff Sharkey | bc16a07 | 2015-12-18 17:19:27 -0700 | [diff] [blame] | 26 | import android.content.pm.ResolveInfo; |
Jeff Sharkey | 9e9f7d1 | 2015-11-30 13:28:19 -0700 | [diff] [blame] | 27 | import android.os.Bundle; |
Jeff Sharkey | bc16a07 | 2015-12-18 17:19:27 -0700 | [diff] [blame] | 28 | import android.os.Handler; |
| 29 | import android.os.Message; |
Jorim Jaggi | 9840794 | 2016-08-02 11:53:12 +0200 | [diff] [blame] | 30 | import android.os.PowerManager; |
| 31 | import android.os.SystemClock; |
Fan Zhang | c7162cd | 2018-06-18 15:21:41 -0700 | [diff] [blame^] | 32 | import android.os.UserHandle; |
Jeff Sharkey | bc16a07 | 2015-12-18 17:19:27 -0700 | [diff] [blame] | 33 | import android.os.UserManager; |
Jeff Sharkey | c80dc5e | 2016-05-03 17:25:37 -0600 | [diff] [blame] | 34 | import android.provider.Settings; |
Jeff Sharkey | 9e9f7d1 | 2015-11-30 13:28:19 -0700 | [diff] [blame] | 35 | import android.util.Log; |
Jorim Jaggi | a616a0d | 2016-06-29 16:33:39 -0700 | [diff] [blame] | 36 | import android.view.View; |
Jorim Jaggi | 9840794 | 2016-08-02 11:53:12 +0200 | [diff] [blame] | 37 | import android.view.WindowManager.LayoutParams; |
| 38 | import android.view.animation.AnimationUtils; |
Jeff Sharkey | 9e9f7d1 | 2015-11-30 13:28:19 -0700 | [diff] [blame] | 39 | |
Jeff Sharkey | bc16a07 | 2015-12-18 17:19:27 -0700 | [diff] [blame] | 40 | import java.util.Objects; |
| 41 | |
Jeff Sharkey | 9e9f7d1 | 2015-11-30 13:28:19 -0700 | [diff] [blame] | 42 | public class FallbackHome extends Activity { |
| 43 | private static final String TAG = "FallbackHome"; |
Jorim Jaggi | 9840794 | 2016-08-02 11:53:12 +0200 | [diff] [blame] | 44 | 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 Sharkey | 9e9f7d1 | 2015-11-30 13:28:19 -0700 | [diff] [blame] | 61 | |
| 62 | @Override |
| 63 | protected void onCreate(Bundle savedInstanceState) { |
| 64 | super.onCreate(savedInstanceState); |
Jeff Sharkey | c80dc5e | 2016-05-03 17:25:37 -0600 | [diff] [blame] | 65 | |
| 66 | // Set ourselves totally black before the device is provisioned so that |
| 67 | // we don't flash the wallpaper before SUW |
Jorim Jaggi | 9840794 | 2016-08-02 11:53:12 +0200 | [diff] [blame] | 68 | mProvisioned = Settings.Global.getInt(getContentResolver(), |
| 69 | Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
Matthew Ng | dd39649 | 2018-05-31 13:30:27 -0700 | [diff] [blame] | 70 | int flags; |
Jorim Jaggi | 9840794 | 2016-08-02 11:53:12 +0200 | [diff] [blame] | 71 | if (!mProvisioned) { |
Jorim Jaggi | a616a0d | 2016-06-29 16:33:39 -0700 | [diff] [blame] | 72 | setTheme(R.style.FallbackHome_SetupWizard); |
Matthew Ng | dd39649 | 2018-05-31 13:30:27 -0700 | [diff] [blame] | 73 | flags = View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
| 74 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
Jorim Jaggi | 9840794 | 2016-08-02 11:53:12 +0200 | [diff] [blame] | 75 | } else { |
Matthew Ng | dd39649 | 2018-05-31 13:30:27 -0700 | [diff] [blame] | 76 | flags = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 77 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
Jeff Sharkey | c80dc5e | 2016-05-03 17:25:37 -0600 | [diff] [blame] | 78 | } |
| 79 | |
Matthew Ng | dd39649 | 2018-05-31 13:30:27 -0700 | [diff] [blame] | 80 | // 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 Jaggi | c0c583c | 2016-11-02 20:33:32 +0000 | [diff] [blame] | 91 | registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_USER_UNLOCKED)); |
Jeff Sharkey | bc16a07 | 2015-12-18 17:19:27 -0700 | [diff] [blame] | 92 | maybeFinish(); |
| 93 | } |
| 94 | |
| 95 | @Override |
Jorim Jaggi | 9840794 | 2016-08-02 11:53:12 +0200 | [diff] [blame] | 96 | 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 Sharkey | bc16a07 | 2015-12-18 17:19:27 -0700 | [diff] [blame] | 109 | protected void onDestroy() { |
| 110 | super.onDestroy(); |
| 111 | unregisterReceiver(mReceiver); |
Jeff Sharkey | 9e9f7d1 | 2015-11-30 13:28:19 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | private BroadcastReceiver mReceiver = new BroadcastReceiver() { |
| 115 | @Override |
| 116 | public void onReceive(Context context, Intent intent) { |
Jeff Sharkey | bc16a07 | 2015-12-18 17:19:27 -0700 | [diff] [blame] | 117 | 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 Li | 4811ab4 | 2016-05-20 14:27:14 -0700 | [diff] [blame] | 127 | 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 Sharkey | bc16a07 | 2015-12-18 17:19:27 -0700 | [diff] [blame] | 133 | 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 Jaggi | 9840794 | 2016-08-02 11:53:12 +0200 | [diff] [blame] | 137 | getSystemService(PowerManager.class).userActivity( |
| 138 | SystemClock.uptimeMillis(), false); |
Jeff Sharkey | bc16a07 | 2015-12-18 17:19:27 -0700 | [diff] [blame] | 139 | finish(); |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | private Handler mHandler = new Handler() { |
| 145 | @Override |
| 146 | public void handleMessage(Message msg) { |
| 147 | maybeFinish(); |
Jeff Sharkey | 9e9f7d1 | 2015-11-30 13:28:19 -0700 | [diff] [blame] | 148 | } |
| 149 | }; |
| 150 | } |