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; |
Jorim Jaggi | 9840794 | 2016-08-02 11:53:12 +0200 | [diff] [blame] | 20 | import android.app.ProgressDialog; |
Jeff Sharkey | 9e9f7d1 | 2015-11-30 13:28:19 -0700 | [diff] [blame] | 21 | import android.content.BroadcastReceiver; |
| 22 | import android.content.Context; |
| 23 | import android.content.Intent; |
| 24 | import android.content.IntentFilter; |
Muyuan Li | 4811ab4 | 2016-05-20 14:27:14 -0700 | [diff] [blame] | 25 | import android.content.pm.PackageManager; |
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; |
Muyuan Li | 4811ab4 | 2016-05-20 14:27:14 -0700 | [diff] [blame] | 30 | import android.os.UserHandle; |
Jorim Jaggi | 9840794 | 2016-08-02 11:53:12 +0200 | [diff] [blame] | 31 | import android.os.PowerManager; |
| 32 | import android.os.SystemClock; |
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; |
| 38 | import android.view.WindowManager.LayoutParams; |
| 39 | import android.view.animation.AnimationUtils; |
Jeff Sharkey | 9e9f7d1 | 2015-11-30 13:28:19 -0700 | [diff] [blame] | 40 | |
Jeff Sharkey | bc16a07 | 2015-12-18 17:19:27 -0700 | [diff] [blame] | 41 | import java.util.Objects; |
| 42 | |
Jeff Sharkey | 9e9f7d1 | 2015-11-30 13:28:19 -0700 | [diff] [blame] | 43 | public class FallbackHome extends Activity { |
| 44 | private static final String TAG = "FallbackHome"; |
Jorim Jaggi | 9840794 | 2016-08-02 11:53:12 +0200 | [diff] [blame] | 45 | 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 Sharkey | 9e9f7d1 | 2015-11-30 13:28:19 -0700 | [diff] [blame] | 62 | |
| 63 | @Override |
| 64 | protected void onCreate(Bundle savedInstanceState) { |
| 65 | super.onCreate(savedInstanceState); |
Jeff Sharkey | c80dc5e | 2016-05-03 17:25:37 -0600 | [diff] [blame] | 66 | |
| 67 | // Set ourselves totally black before the device is provisioned so that |
| 68 | // we don't flash the wallpaper before SUW |
Jorim Jaggi | 9840794 | 2016-08-02 11:53:12 +0200 | [diff] [blame] | 69 | mProvisioned = Settings.Global.getInt(getContentResolver(), |
| 70 | Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
| 71 | if (!mProvisioned) { |
Jorim Jaggi | a616a0d | 2016-06-29 16:33:39 -0700 | [diff] [blame] | 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); |
Jorim Jaggi | 9840794 | 2016-08-02 11:53:12 +0200 | [diff] [blame] | 75 | } else { |
| 76 | getWindow().getDecorView().setSystemUiVisibility(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 | |
Jorim Jaggi | c0c583c | 2016-11-02 20:33:32 +0000 | [diff] [blame] | 80 | registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_USER_UNLOCKED)); |
Jeff Sharkey | bc16a07 | 2015-12-18 17:19:27 -0700 | [diff] [blame] | 81 | maybeFinish(); |
| 82 | } |
| 83 | |
| 84 | @Override |
Jorim Jaggi | 9840794 | 2016-08-02 11:53:12 +0200 | [diff] [blame] | 85 | 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 Sharkey | bc16a07 | 2015-12-18 17:19:27 -0700 | [diff] [blame] | 98 | protected void onDestroy() { |
| 99 | super.onDestroy(); |
| 100 | unregisterReceiver(mReceiver); |
Jeff Sharkey | 9e9f7d1 | 2015-11-30 13:28:19 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | private BroadcastReceiver mReceiver = new BroadcastReceiver() { |
| 104 | @Override |
| 105 | public void onReceive(Context context, Intent intent) { |
Jeff Sharkey | bc16a07 | 2015-12-18 17:19:27 -0700 | [diff] [blame] | 106 | 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 Li | 4811ab4 | 2016-05-20 14:27:14 -0700 | [diff] [blame] | 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. |
| 120 | return; |
| 121 | } |
Jeff Sharkey | bc16a07 | 2015-12-18 17:19:27 -0700 | [diff] [blame] | 122 | 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 Jaggi | 9840794 | 2016-08-02 11:53:12 +0200 | [diff] [blame] | 126 | getSystemService(PowerManager.class).userActivity( |
| 127 | SystemClock.uptimeMillis(), false); |
Jeff Sharkey | bc16a07 | 2015-12-18 17:19:27 -0700 | [diff] [blame] | 128 | finish(); |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | private Handler mHandler = new Handler() { |
| 134 | @Override |
| 135 | public void handleMessage(Message msg) { |
| 136 | maybeFinish(); |
Jeff Sharkey | 9e9f7d1 | 2015-11-30 13:28:19 -0700 | [diff] [blame] | 137 | } |
| 138 | }; |
| 139 | } |