blob: 6c0dc3d652cf9e2b8a484db3ba43102079feb2b5 [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;
Muyuan Li4811ab42016-05-20 14:27:14 -070024import android.content.pm.PackageManager;
Jeff Sharkeybc16a072015-12-18 17:19:27 -070025import android.content.pm.ResolveInfo;
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070026import android.os.Bundle;
Jeff Sharkeybc16a072015-12-18 17:19:27 -070027import android.os.Handler;
28import android.os.Message;
Muyuan Li4811ab42016-05-20 14:27:14 -070029import android.os.UserHandle;
Jeff Sharkeybc16a072015-12-18 17:19:27 -070030import android.os.UserManager;
Jeff Sharkeyc80dc5e2016-05-03 17:25:37 -060031import android.provider.Settings;
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070032import android.util.Log;
33
Jeff Sharkeybc16a072015-12-18 17:19:27 -070034import java.util.Objects;
35
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070036public class FallbackHome extends Activity {
37 private static final String TAG = "FallbackHome";
38
39 @Override
40 protected void onCreate(Bundle savedInstanceState) {
41 super.onCreate(savedInstanceState);
Jeff Sharkeyc80dc5e2016-05-03 17:25:37 -060042
43 // Set ourselves totally black before the device is provisioned so that
44 // we don't flash the wallpaper before SUW
45 if (Settings.Global.getInt(getContentResolver(),
46 Settings.Global.DEVICE_PROVISIONED, 0) == 0) {
47 setTheme(android.R.style.Theme_Black_NoTitleBar_Fullscreen);
48 }
49
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070050 registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_USER_UNLOCKED));
Jeff Sharkeybc16a072015-12-18 17:19:27 -070051 maybeFinish();
52 }
53
54 @Override
55 protected void onDestroy() {
56 super.onDestroy();
57 unregisterReceiver(mReceiver);
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070058 }
59
60 private BroadcastReceiver mReceiver = new BroadcastReceiver() {
61 @Override
62 public void onReceive(Context context, Intent intent) {
Jeff Sharkeybc16a072015-12-18 17:19:27 -070063 maybeFinish();
64 }
65 };
66
67 private void maybeFinish() {
68 if (getSystemService(UserManager.class).isUserUnlocked()) {
69 final Intent homeIntent = new Intent(Intent.ACTION_MAIN)
70 .addCategory(Intent.CATEGORY_HOME);
71 final ResolveInfo homeInfo = getPackageManager().resolveActivity(homeIntent, 0);
72 if (Objects.equals(getPackageName(), homeInfo.activityInfo.packageName)) {
Muyuan Li4811ab42016-05-20 14:27:14 -070073 if (UserManager.isSplitSystemUser()
74 && UserHandle.myUserId() == UserHandle.USER_SYSTEM) {
75 // This avoids the situation where the system user has no home activity after
76 // SUW and this activity continues to throw out warnings. See b/28870689.
77 return;
78 }
Jeff Sharkeybc16a072015-12-18 17:19:27 -070079 Log.d(TAG, "User unlocked but no home; let's hope someone enables one soon?");
80 mHandler.sendEmptyMessageDelayed(0, 500);
81 } else {
82 Log.d(TAG, "User unlocked and real home found; let's go!");
83 finish();
84 }
85 }
86 }
87
88 private Handler mHandler = new Handler() {
89 @Override
90 public void handleMessage(Message msg) {
91 maybeFinish();
Jeff Sharkey9e9f7d12015-11-30 13:28:19 -070092 }
93 };
94}