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; |
| 20 | import android.content.BroadcastReceiver; |
| 21 | import android.content.Context; |
| 22 | import android.content.Intent; |
| 23 | import android.content.IntentFilter; |
Jeff Sharkey | bc16a07 | 2015-12-18 17:19:27 -0700 | [diff] [blame] | 24 | import android.content.pm.ResolveInfo; |
Jeff Sharkey | 9e9f7d1 | 2015-11-30 13:28:19 -0700 | [diff] [blame] | 25 | import android.os.Bundle; |
Jeff Sharkey | bc16a07 | 2015-12-18 17:19:27 -0700 | [diff] [blame] | 26 | import android.os.Handler; |
| 27 | import android.os.Message; |
| 28 | import android.os.UserManager; |
Jeff Sharkey | c80dc5e | 2016-05-03 17:25:37 -0600 | [diff] [blame^] | 29 | import android.provider.Settings; |
Jeff Sharkey | 9e9f7d1 | 2015-11-30 13:28:19 -0700 | [diff] [blame] | 30 | import android.util.Log; |
| 31 | |
Jeff Sharkey | bc16a07 | 2015-12-18 17:19:27 -0700 | [diff] [blame] | 32 | import java.util.Objects; |
| 33 | |
Jeff Sharkey | 9e9f7d1 | 2015-11-30 13:28:19 -0700 | [diff] [blame] | 34 | public 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 Sharkey | c80dc5e | 2016-05-03 17:25:37 -0600 | [diff] [blame^] | 40 | |
| 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 Sharkey | 9e9f7d1 | 2015-11-30 13:28:19 -0700 | [diff] [blame] | 48 | registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_USER_UNLOCKED)); |
Jeff Sharkey | bc16a07 | 2015-12-18 17:19:27 -0700 | [diff] [blame] | 49 | maybeFinish(); |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | protected void onDestroy() { |
| 54 | super.onDestroy(); |
| 55 | unregisterReceiver(mReceiver); |
Jeff Sharkey | 9e9f7d1 | 2015-11-30 13:28:19 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | private BroadcastReceiver mReceiver = new BroadcastReceiver() { |
| 59 | @Override |
| 60 | public void onReceive(Context context, Intent intent) { |
Jeff Sharkey | bc16a07 | 2015-12-18 17:19:27 -0700 | [diff] [blame] | 61 | 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 Sharkey | 9e9f7d1 | 2015-11-30 13:28:19 -0700 | [diff] [blame] | 84 | } |
| 85 | }; |
| 86 | } |