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; |
Muyuan Li | 4811ab4 | 2016-05-20 14:27:14 -0700 | [diff] [blame^] | 24 | import android.content.pm.PackageManager; |
Jeff Sharkey | bc16a07 | 2015-12-18 17:19:27 -0700 | [diff] [blame] | 25 | import android.content.pm.ResolveInfo; |
Jeff Sharkey | 9e9f7d1 | 2015-11-30 13:28:19 -0700 | [diff] [blame] | 26 | import android.os.Bundle; |
Jeff Sharkey | bc16a07 | 2015-12-18 17:19:27 -0700 | [diff] [blame] | 27 | import android.os.Handler; |
| 28 | import android.os.Message; |
Muyuan Li | 4811ab4 | 2016-05-20 14:27:14 -0700 | [diff] [blame^] | 29 | import android.os.UserHandle; |
Jeff Sharkey | bc16a07 | 2015-12-18 17:19:27 -0700 | [diff] [blame] | 30 | import android.os.UserManager; |
Jeff Sharkey | c80dc5e | 2016-05-03 17:25:37 -0600 | [diff] [blame] | 31 | import android.provider.Settings; |
Jeff Sharkey | 9e9f7d1 | 2015-11-30 13:28:19 -0700 | [diff] [blame] | 32 | import android.util.Log; |
| 33 | |
Jeff Sharkey | bc16a07 | 2015-12-18 17:19:27 -0700 | [diff] [blame] | 34 | import java.util.Objects; |
| 35 | |
Jeff Sharkey | 9e9f7d1 | 2015-11-30 13:28:19 -0700 | [diff] [blame] | 36 | public 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 Sharkey | c80dc5e | 2016-05-03 17:25:37 -0600 | [diff] [blame] | 42 | |
| 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 Sharkey | 9e9f7d1 | 2015-11-30 13:28:19 -0700 | [diff] [blame] | 50 | registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_USER_UNLOCKED)); |
Jeff Sharkey | bc16a07 | 2015-12-18 17:19:27 -0700 | [diff] [blame] | 51 | maybeFinish(); |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | protected void onDestroy() { |
| 56 | super.onDestroy(); |
| 57 | unregisterReceiver(mReceiver); |
Jeff Sharkey | 9e9f7d1 | 2015-11-30 13:28:19 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | private BroadcastReceiver mReceiver = new BroadcastReceiver() { |
| 61 | @Override |
| 62 | public void onReceive(Context context, Intent intent) { |
Jeff Sharkey | bc16a07 | 2015-12-18 17:19:27 -0700 | [diff] [blame] | 63 | 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 Li | 4811ab4 | 2016-05-20 14:27:14 -0700 | [diff] [blame^] | 73 | 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 Sharkey | bc16a07 | 2015-12-18 17:19:27 -0700 | [diff] [blame] | 79 | 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 Sharkey | 9e9f7d1 | 2015-11-30 13:28:19 -0700 | [diff] [blame] | 92 | } |
| 93 | }; |
| 94 | } |