blob: deb01a17642d4c91c0ade3e430d7fab13fbd6f4d [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;
31
Jeff Sharkeybc16a072015-12-18 17:19:27 -070032import java.util.Objects;
33
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070034public class FallbackHome extends Activity {
35 private static final String TAG = "FallbackHome";
36
37 @Override
38 protected void onCreate(Bundle savedInstanceState) {
39 super.onCreate(savedInstanceState);
Jeff Sharkeyc80dc5e2016-05-03 17:25:37 -060040
41 // Set ourselves totally black before the device is provisioned so that
42 // we don't flash the wallpaper before SUW
43 if (Settings.Global.getInt(getContentResolver(),
44 Settings.Global.DEVICE_PROVISIONED, 0) == 0) {
45 setTheme(android.R.style.Theme_Black_NoTitleBar_Fullscreen);
46 }
47
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070048 registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_USER_UNLOCKED));
Jeff Sharkeybc16a072015-12-18 17:19:27 -070049 maybeFinish();
50 }
51
52 @Override
53 protected void onDestroy() {
54 super.onDestroy();
55 unregisterReceiver(mReceiver);
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070056 }
57
58 private BroadcastReceiver mReceiver = new BroadcastReceiver() {
59 @Override
60 public void onReceive(Context context, Intent intent) {
Jeff Sharkeybc16a072015-12-18 17:19:27 -070061 maybeFinish();
62 }
63 };
64
65 private void maybeFinish() {
66 if (getSystemService(UserManager.class).isUserUnlocked()) {
67 final Intent homeIntent = new Intent(Intent.ACTION_MAIN)
68 .addCategory(Intent.CATEGORY_HOME);
69 final ResolveInfo homeInfo = getPackageManager().resolveActivity(homeIntent, 0);
70 if (Objects.equals(getPackageName(), homeInfo.activityInfo.packageName)) {
71 Log.d(TAG, "User unlocked but no home; let's hope someone enables one soon?");
72 mHandler.sendEmptyMessageDelayed(0, 500);
73 } else {
74 Log.d(TAG, "User unlocked and real home found; let's go!");
75 finish();
76 }
77 }
78 }
79
80 private Handler mHandler = new Handler() {
81 @Override
82 public void handleMessage(Message msg) {
83 maybeFinish();
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070084 }
85 };
86}