blob: 158f6726c462496fe2d291f5dc62801f794100bd [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;
20import android.content.BroadcastReceiver;
21import android.content.Context;
22import android.content.Intent;
23import android.content.IntentFilter;
Jeff Sharkeybc16a072015-12-18 17:19:27 -070024import android.content.pm.ResolveInfo;
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070025import android.os.Bundle;
Jeff Sharkeybc16a072015-12-18 17:19:27 -070026import android.os.Handler;
27import android.os.Message;
28import android.os.UserManager;
Jeff Sharkeyc80dc5e2016-05-03 17:25:37 -060029import android.provider.Settings;
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070030import android.util.Log;
Jorim Jaggia616a0d2016-06-29 16:33:39 -070031import android.view.View;
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070032
Jeff Sharkeybc16a072015-12-18 17:19:27 -070033import java.util.Objects;
34
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070035public class FallbackHome extends Activity {
36 private static final String TAG = "FallbackHome";
37
38 @Override
39 protected void onCreate(Bundle savedInstanceState) {
40 super.onCreate(savedInstanceState);
Jeff Sharkeyc80dc5e2016-05-03 17:25:37 -060041
42 // Set ourselves totally black before the device is provisioned so that
43 // we don't flash the wallpaper before SUW
44 if (Settings.Global.getInt(getContentResolver(),
45 Settings.Global.DEVICE_PROVISIONED, 0) == 0) {
Jorim Jaggia616a0d2016-06-29 16:33:39 -070046 setTheme(R.style.FallbackHome_SetupWizard);
47 getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN
48 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
Jeff Sharkeyc80dc5e2016-05-03 17:25:37 -060049 }
50
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070051 registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_USER_UNLOCKED));
Jeff Sharkeybc16a072015-12-18 17:19:27 -070052 maybeFinish();
53 }
54
55 @Override
56 protected void onDestroy() {
57 super.onDestroy();
58 unregisterReceiver(mReceiver);
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070059 }
60
61 private BroadcastReceiver mReceiver = new BroadcastReceiver() {
62 @Override
63 public void onReceive(Context context, Intent intent) {
Jeff Sharkeybc16a072015-12-18 17:19:27 -070064 maybeFinish();
65 }
66 };
67
68 private void maybeFinish() {
69 if (getSystemService(UserManager.class).isUserUnlocked()) {
70 final Intent homeIntent = new Intent(Intent.ACTION_MAIN)
71 .addCategory(Intent.CATEGORY_HOME);
72 final ResolveInfo homeInfo = getPackageManager().resolveActivity(homeIntent, 0);
73 if (Objects.equals(getPackageName(), homeInfo.activityInfo.packageName)) {
74 Log.d(TAG, "User unlocked but no home; let's hope someone enables one soon?");
75 mHandler.sendEmptyMessageDelayed(0, 500);
76 } else {
77 Log.d(TAG, "User unlocked and real home found; let's go!");
78 finish();
79 }
80 }
81 }
82
83 private Handler mHandler = new Handler() {
84 @Override
85 public void handleMessage(Message msg) {
86 maybeFinish();
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070087 }
88 };
89}