Factory reset会黑屏一段时间进入Provision首页

在这里插入图片描述
WMSenableScreenAfterBoot方法开始看起,看看开机动画结束到启动开机向导的整个流程:

1. 在WMSenableScreenAfterBoot方法中调用performEnableScreen

public void enableScreenAfterBoot() {
 synchronized (mGlobalLock) {
     if (DEBUG_BOOT) {
         RuntimeException here = new RuntimeException("here");
         here.fillInStackTrace();
         Slog.i(TAG_WM, "enableScreenAfterBoot: mDisplayEnabled=" + mDisplayEnabled
                 + " mForceDisplayEnabled=" + mForceDisplayEnabled
                 + " mShowingBootMessages=" + mShowingBootMessages
                 + " mSystemBooted=" + mSystemBooted, here);
     }
     if (mSystemBooted) {
         return;
     }
     mSystemBooted = true;
     hideBootMessagesLocked();
     // If the screen still doesn't come up after 30 seconds, give
     // up and turn it on.
     mH.sendEmptyMessageDelayed(H.BOOT_TIMEOUT, 30 * 1000);
 }
 mPolicy.systemBooted();
 performEnableScreen();
}

2. performEnableScreen方法中check bootanimation满足结束条件但是还没结束时,setprop service.bootanim.exit 1

if(mOnlyCore && !"".equals(SystemProperties.get("vold.encrypt_progress"))) {
 return;
}
if (mDisplayEnabled) {
 return;
}
if (!mSystemBooted && !mShowingBootMessages) {
 return;
}
if (!mShowingBootMessages && !mPolicy.canDismissBootAnimation()) {
 return;
}
// Don't enable the screen until all existing windows have been drawn.
if (!mForceDisplayEnabled 
     // TODO(multidisplay): Expand to all displays?
     && getDefaultDisplayContentLocked().checkWaitingForWindows()) {
 return;
}
if (!mBootAnimationStopped) {
 Trace.asyncTraceBegin(TRACE_TAG_WINDOW_MANAGER, "Stop bootanim", 0);
 // stop boot animation
 // formerly we would just kill the process, but we now ask it to exit so it
 // can choose where to stop the animation.
 SystemProperties.set("service.bootanim.exit", "1");
 mBootAnimationStopped = true;
}

3. performEnableScreen方法中等待bootanim服务结束

//在performEnableScreen方法中
if (!mForceDisplayEnabled && !checkBootAnimationCompleteLocked()) {
 if (DEBUG_BOOT) Slog.i(TAG_WM, "performEnableScreen: Waiting for anim complete");
 return;
}
//checkBootAnimationCompleteLocked方法中, 判断bootanim服务是否还在,
//1. 如果服务还在移除MessageQueue得CHECK_IF_BOOT_ANIMATION_FINISHED消息,再发送一个,返回false
//2. 否则得话,返回true,继续后续流程
private boolean checkBootAnimationCompleteLocked() {
 if (SystemService.isRunning(BOOT_ANIMATION_SERVICE)) {
     mH.removeMessages(H.CHECK_IF_BOOT_ANIMATION_FINISHED);
     mH.sendEmptyMessageDelayed(H.CHECK_IF_BOOT_ANIMATION_FINISHED,
             BOOT_ANIMATION_POLL_INTERVAL);
     if (DEBUG_BOOT) Slog.i(TAG_WM, "checkBootAnimationComplete: Waiting for anim complete");
     return false;
 }
 if (DEBUG_BOOT) Slog.i(TAG_WM, "checkBootAnimationComplete: Animation complete!");
 return true;
}
//handleMessage方法中调用checkBootAnimationCompleteLocked一遍又一遍得check bootanim服务是否还在,直到bootanim服务不存在了,再调用一次performEnableScreen方法
case CHECK_IF_BOOT_ANIMATION_FINISHED: {
 final boolean bootAnimationComplete;
 synchronized (mGlobalLock) {
     if (DEBUG_BOOT) Slog.i(TAG_WM, "CHECK_IF_BOOT_ANIMATION_FINISHED:");
         bootAnimationComplete = checkBootAnimationCompleteLocked();
 }
 if (bootAnimationComplete) {
     performEnableScreen();
 }
 break;
}

4. 此时,开机动画已经结束,通知SurfaceFlingersystem启动完毕;enable input dispatch;调用AMSbootAnimationComplete的方法

synchronized (mGlobalLock) {
 // MIUI ADD: START
 // Skip if it is encrypting
 if(mOnlyCore && !"".equals(SystemProperties.get("vold.encrypt_progress"))) {
     return;
 }
 if (mDisplayEnabled) {
     return;
 }
 if (!mSystemBooted && !mShowingBootMessages) {
     return;
 }
 if (!mShowingBootMessages && !mPolicy.canDismissBootAnimation()) {
     return;
 }
 // Don't enable the screen until all existing windows have been drawn.
 if (!mForceDisplayEnabled
         // TODO(multidisplay): Expand to all displays?
         && getDefaultDisplayContentLocked().checkWaitingForWindows()) {
     return;
 }
 if (!mBootAnimationStopped) {
     Trace.asyncTraceBegin(TRACE_TAG_WINDOW_MANAGER, "Stop bootanim", 0);
     // stop boot animation
     // formerly we would just kill the process, but we now ask it to exit so it
     // can choose where to stop the animation.
     SystemProperties.set("service.bootanim.exit", "1");
     mBootAnimationStopped = true;
 }
 if (!mForceDisplayEnabled && !checkBootAnimationCompleteLocked()) {
     if (DEBUG_BOOT) Slog.i(TAG_WM, "performEnableScreen: Waiting for anim complete");
     return;
 }
 //此时开机动画已经结束
 //通知SurfaceFlinger,system启动完毕
 try {
     IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
     if (surfaceFlinger != null) {
         Slog.i(TAG_WM, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
         Parcel data = Parcel.obtain();
         data.writeInterfaceToken("android.ui.ISurfaceComposer");
         surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, // BOOT_FINISHED
                 data, null, 0);
         data.recycle();
     }
 } catch (RemoteException ex) {
     Slog.e(TAG_WM, "Boot completed: SurfaceFlinger is dead!");
 }
 //add by blackshark for hawkeye dot
 WindowManagerServiceJuiInjector.report(WindowManagerServiceJuiInjector.BMS_PERF_BOOT_TIME, "{\"boot_time\":" + SystemClock.uptimeMillis() + "}");
 EventLog.writeEvent(EventLogTags.WM_BOOT_ANIMATION_DONE, SystemClock.uptimeMillis());
 Trace.asyncTraceEnd(TRACE_TAG_WINDOW_MANAGER, "Stop bootanim", 0);
 mDisplayEnabled = true;
 if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM, "******************** ENABLING SCREEN!");
 // Enable input dispatch.
 mInputManagerCallback.setEventDispatchingLw(mEventDispatchingEnabled);
}
try {
 mActivityManager.bootAnimationComplete();
} catch (RemoteException e) {
}

5. 接下来看看AMSbootAnimationComplete的方法, 调用AMS的finishBooting方法

public void bootAnimationComplete() {
 final boolean callFinishBooting;
 synchronized (this) {
     callFinishBooting = mCallFinishBooting;
     mBootAnimationComplete = true;
 }
 if (callFinishBooting) {
     finishBooting();
 }
}

6. AMSfinishBooting方法中调用UserControllersendBootCompleted方法

mUserController.sendBootCompleted(
     new IIntentReceiver.Stub() {
         @Override
         public void performReceive(Intent intent, int resultCode,
                 String data, Bundle extras, boolean ordered,
             boolean sticky, int sendingUser) {
         synchronized (ActivityManagerService.this) {
             mOomAdjuster.mAppCompact.compactAllSystem();
             requestPssAllProcsLocked(SystemClock.uptimeMillis(), true, false);
         }
     }
 });

7. UserControllersendBootCompleted方法中针对mStartedUsers中的所有UserState调用finishUserBoot方法

void sendBootCompleted(IIntentReceiver resultTo) {
 // Get a copy of mStartedUsers to use outside of lock
 SparseArray<UserState> startedUsers;
 synchronized (mLock) {
     startedUsers = mStartedUsers.clone();
 }
 for (int i = 0; i < startedUsers.size(); i++) {
     UserState uss = startedUsers.valueAt(i);
     finishUserBoot(uss, resultTo);
 }
}

8. UserControllerfinishUserBoot方法中才能调用到maybeUnlockUser开始Unlock user

private void finishUserBoot(UserState uss, IIntentReceiver resultTo) {
 final int userId = uss.mHandle.getIdentifier();
 Slog.d(TAG, "Finishing user boot " + userId);
 synchronized (mLock) {
     // Bail if we ended up with a stale user
     if (mStartedUsers.get(userId) != uss) {
         return;
     }
 }
 // We always walk through all the user lifecycle states to send
 // consistent developer events. We step into RUNNING_LOCKED here,
 // but we might immediately step into RUNNING below if the user
 // storage is already unlocked.
 if (uss.setState(STATE_BOOTING, STATE_RUNNING_LOCKED)) {
     mInjector.getUserManagerInternal().setUserState(userId, uss.state);
     // Do not report secondary users, runtime restarts or first boot/upgrade
     if (userId == UserHandle.USER_SYSTEM
             && !mInjector.isRuntimeRestarted() && !mInjector.isFirstBootOrUpgrade()) {
         int uptimeSeconds = (int)(SystemClock.elapsedRealtime() / 1000);
         MetricsLogger.histogram(mInjector.getContext(),
                 "framework_locked_boot_completed", uptimeSeconds);
         final int MAX_UPTIME_SECONDS = 120;
         if (uptimeSeconds > MAX_UPTIME_SECONDS) {
             Slog.wtf("SystemServerTiming",
                     "finishUserBoot took too long. uptimeSeconds=" + uptimeSeconds);
         }
     }
     mHandler.sendMessage(mHandler.obtainMessage(REPORT_LOCKED_BOOT_COMPLETE_MSG,
             userId, 0));
     //发送广播android.intent.action.LOCKED_BOOT_COMPLETED
     Intent intent = new Intent(Intent.ACTION_LOCKED_BOOT_COMPLETED, null);
     intent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
     intent.addFlags(Intent.FLAG_RECEIVER_NO_ABORT
             | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
     mInjector.broadcastIntent(intent, null, resultTo, 0, null, null,
             new String[]{android.Manifest.permission.RECEIVE_BOOT_COMPLETED},
             AppOpsManager.OP_NONE, null, true, false, MY_PID, SYSTEM_UID,
             Binder.getCallingUid(), Binder.getCallingPid(), userId);
 }
 // We need to delay unlocking managed profiles until the parent user
 // is also unlocked.
 // MIUI MOD: START
 if (mInjector.getUserManager().isManagedProfile(userId)
         || miui.securityspace.XSpaceUserHandle.isXSpaceUserId(userId)) {
 // END
     final UserInfo parent = mInjector.getUserManager().getProfileParent(userId);
     if (parent != null
             && isUserRunning(parent.id, ActivityManager.FLAG_AND_UNLOCKED)) {
         Slog.d(TAG, "User " + userId + " (parent " + parent.id
                 + "): attempting unlock because parent is unlocked");
         maybeUnlockUser(userId);
     } else {
         String parentId = (parent == null) ? "<null>" : String.valueOf(parent.id);
         Slog.d(TAG, "User " + userId + " (parent " + parentId
                 + "): delaying unlock because parent is locked");
     }
 } else {
     maybeUnlockUser(userId);
 }
}

9. maybeUnlockUser方法中开始调用unlockUserCleared

private boolean maybeUnlockUser(final int userId) {
// Try unlocking storage using empty token
return unlockUserCleared(userId, null, null, null);
}

10. unlockUserCleared方法中调用finishUserUnlocking

private boolean unlockUserCleared(final int userId, byte[] token, byte[] secret,
        IProgressListener listener) {
    UserState uss;
    if (!StorageManager.isUserKeyUnlocked(userId)) {
        final UserInfo userInfo = getUserInfo(userId);
        final IStorageManager storageManager = mInjector.getStorageManager();
        try {
            // We always want to unlock user storage, even user is not started yet
            storageManager.unlockUserKey(userId, userInfo.serialNumber, token, secret);
        } catch (RemoteException | RuntimeException e) {
            Slog.w(TAG, "Failed to unlock: " + e.getMessage());
            // MIUI ADD: START
            return false;
            // END
        }
    }
    synchronized (mLock) {
        // Register the given listener to watch for unlock progress
        uss = mStartedUsers.get(userId);
        if (uss != null) {
            uss.mUnlockProgress.addListener(listener);
            uss.tokenProvided = (token != null);
        }
    }
    // Bail if user isn't actually running
    if (uss == null) {
        notifyFinished(userId, listener);
        return false;
    }

    if (!finishUserUnlocking(uss)) {
        notifyFinished(userId, listener);
        return false;
    }

    // We just unlocked a user, so let's now attempt to unlock any
    // managed profiles under that user.

    // First, get list of userIds. Requires mLock, so we cannot make external calls, e.g. to UMS
    int[] userIds;
    synchronized (mLock) {
        userIds = new int[mStartedUsers.size()];
        for (int i = 0; i < userIds.length; i++) {
            userIds[i] = mStartedUsers.keyAt(i);
        }
    }
    for (int testUserId : userIds) {
        final UserInfo parent = mInjector.getUserManager().getProfileParent(testUserId);
        if (parent != null && parent.id == userId && testUserId != userId) {
            Slog.d(TAG, "User " + testUserId + " (parent " + parent.id
                    + "): attempting unlock because parent was just unlocked");
            maybeUnlockUser(testUserId);
        }
    }

    return true;
}

11. 在finishUserUnlocking中发送SYSTEM_USER_UNLOCK_MSG消息

private boolean finishUserUnlocking(final UserState uss) {
    final int userId = uss.mHandle.getIdentifier();
    // Only keep marching forward if user is actually unlocked
    if (!StorageManager.isUserKeyUnlocked(userId)) return false;
    synchronized (mLock) {
        // Do not proceed if unexpected state or a stale user
        if (mStartedUsers.get(userId) != uss || uss.state != STATE_RUNNING_LOCKED) {
            return false;
        }
    }
    uss.mUnlockProgress.start();

    // Prepare app storage before we go any further
    uss.mUnlockProgress.setProgress(5,
                mInjector.getContext().getString(R.string.android_start_title));

    // Call onBeforeUnlockUser on a worker thread that allows disk I/O
    FgThread.getHandler().post(() -> {
        if (!StorageManager.isUserKeyUnlocked(userId)) {
            Slog.w(TAG, "User key got locked unexpectedly, leaving user locked.");
            return;
        }
        //Called right before a user is unlocked. This gives us a chance to prepare app storage
        mInjector.getUserManager().onBeforeUnlockUser(userId);
        synchronized (mLock) {
            // Do not proceed if unexpected state
            if (!uss.setState(STATE_RUNNING_LOCKED, STATE_RUNNING_UNLOCKING)) {
                return;
            }
        }
        mInjector.getUserManagerInternal().setUserState(userId, uss.state);

        uss.mUnlockProgress.setProgress(20);

        // Dispatch unlocked to system services; when fully dispatched,
        // that calls through to the next "unlocked" phase
        mHandler.obtainMessage(SYSTEM_USER_UNLOCK_MSG, userId, 0, uss)
                .sendToTarget();
    });
    return true;
}

12. 收到SYSTEM_USER_UNLOCK_MSG消息后,调用finishUserUnlocked发送android.intent.action.USER_UNLOCKED广播

case SYSTEM_USER_UNLOCK_MSG:
    final int userId = msg.arg1;
    mInjector.getSystemServiceManager().unlockUser(userId);
    // Loads recents on a worker thread that allows disk I/O
    FgThread.getHandler().post(() -> {
        mInjector.loadUserRecents(userId);
    });
    finishUserUnlocked((UserState) msg.obj);
    break;
void finishUserUnlocked(final UserState uss) {
    final int userId = uss.mHandle.getIdentifier();
    // Only keep marching forward if user is actually unlocked
    if (!StorageManager.isUserKeyUnlocked(userId)) return;
    synchronized (mLock) {
        // Bail if we ended up with a stale user
        if (mStartedUsers.get(uss.mHandle.getIdentifier()) != uss) return;

        // Do not proceed if unexpected state
        if (!uss.setState(STATE_RUNNING_UNLOCKING, STATE_RUNNING_UNLOCKED)) {
            return;
        }
    }
    mInjector.getUserManagerInternal().setUserState(userId, uss.state);
    uss.mUnlockProgress.finish();

    // Get unaware persistent apps running and start any unaware providers
    // in already-running apps that are partially aware
    if (userId == UserHandle.USER_SYSTEM) {
    	//post procStart msg到AMS的mProcStartHandlerThread
        mInjector.startPersistentApps(PackageManager.MATCH_DIRECT_BOOT_UNAWARE);
        // MIUI ADD:
        ActivityManagerServiceInjector.reportBootEvent();
        ActivityManagerServiceInjector.finishBooting(mInjector.getService());
        // END
    }
    mInjector.installEncryptionUnawareProviders(userId);

    // Dispatch unlocked to external apps
    final Intent unlockedIntent = new Intent(Intent.ACTION_USER_UNLOCKED);
    unlockedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
    unlockedIntent.addFlags(
            Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND);
    mInjector.broadcastIntent(unlockedIntent, null, null, 0, null,
            null, null, AppOpsManager.OP_NONE, null, false, false, MY_PID, SYSTEM_UID,
            Binder.getCallingUid(), Binder.getCallingPid(), userId);

    if (getUserInfo(userId).isManagedProfile()) {
        UserInfo parent = mInjector.getUserManager().getProfileParent(userId);
        if (parent != null) {
            final Intent profileUnlockedIntent = new Intent(
                    Intent.ACTION_MANAGED_PROFILE_UNLOCKED);
            profileUnlockedIntent.putExtra(Intent.EXTRA_USER, UserHandle.of(userId));
            profileUnlockedIntent.addFlags(
                    Intent.FLAG_RECEIVER_REGISTERED_ONLY
                            | Intent.FLAG_RECEIVER_FOREGROUND);
            mInjector.broadcastIntent(profileUnlockedIntent,
                    null, null, 0, null, null, null, AppOpsManager.OP_NONE,
                    null, false, false, MY_PID, SYSTEM_UID, Binder.getCallingUid(),
                    Binder.getCallingPid(), parent.id);
        }
    }

    // Send PRE_BOOT broadcasts if user fingerprint changed; we
    // purposefully block sending BOOT_COMPLETED until after all
    // PRE_BOOT receivers are finished to avoid ANR'ing apps
    final UserInfo info = getUserInfo(userId);
    if (!Objects.equals(info.lastLoggedInFingerprint, Build.FINGERPRINT)) {
        // Suppress double notifications for managed profiles that
        // were unlocked automatically as part of their parent user
        // being unlocked.
        final boolean quiet;
        if (info.isManagedProfile()) {
            quiet = !uss.tokenProvided
                    || !mLockPatternUtils.isSeparateProfileChallengeEnabled(userId);
        } else {
            quiet = false;
        }
        mInjector.sendPreBootBroadcast(userId, quiet,
                () -> finishUserUnlockedCompleted(uss));
    } else {
        finishUserUnlockedCompleted(uss);
    }
}

13. 在finishUserUnlocked中调用finishUserUnlockedCompleted发送所谓的开机广播

private void finishUserUnlockedCompleted(UserState uss) {
    final int userId = uss.mHandle.getIdentifier();
    synchronized (mLock) {
        // Bail if we ended up with a stale user
        if (mStartedUsers.get(uss.mHandle.getIdentifier()) != uss) return;
    }
    UserInfo userInfo = getUserInfo(userId);
    if (userInfo == null) {
        return;
    }
    // Only keep marching forward if user is actually unlocked
    if (!StorageManager.isUserKeyUnlocked(userId)) return;

    // Remember that we logged in
    mInjector.getUserManager().onUserLoggedIn(userId);

    // MIUI ADD: START
    try {
        if (AppGlobals.getPackageManager().isDeviceUpgrading()) {
            mHandler.post(() -> {
                ActivityManagerServiceInjector.otaPreload();
            });
        }
    } catch (RemoteException e) {
        e.printStackTrace();
    }
    // END

    if (!userInfo.isInitialized()) {
        if (userId != UserHandle.USER_SYSTEM) {
            Slog.d(TAG, "Initializing user #" + userId);
            Intent intent = new Intent(Intent.ACTION_USER_INITIALIZE);
            intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND
                    | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
            mInjector.broadcastIntent(intent, null,
                    new IIntentReceiver.Stub() {
                        @Override
                        public void performReceive(Intent intent, int resultCode,
                                String data, Bundle extras, boolean ordered,
                                boolean sticky, int sendingUser) {
                            // Note: performReceive is called with mService lock held
                            mInjector.getUserManager().makeInitialized(userInfo.id);
                        }
                    }, 0, null, null, null, AppOpsManager.OP_NONE,
                    null, true, false, MY_PID, SYSTEM_UID, Binder.getCallingUid(),
                    Binder.getCallingPid(), userId);
        }
    }

    // Spin up app widgets prior to boot-complete, so they can be ready promptly
    mInjector.startUserWidgets(userId);

    Slog.i(TAG, "Posting BOOT_COMPLETED user #" + userId);
    // Do not report secondary users, runtime restarts or first boot/upgrade
    if (userId == UserHandle.USER_SYSTEM
            && !mInjector.isRuntimeRestarted() && !mInjector.isFirstBootOrUpgrade()) {
        int uptimeSeconds = (int) (SystemClock.elapsedRealtime() / 1000);
        MetricsLogger.histogram(mInjector.getContext(), "framework_boot_completed",
                uptimeSeconds);
    }
    final Intent bootIntent = new Intent(Intent.ACTION_BOOT_COMPLETED, null);
    bootIntent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
    bootIntent.addFlags(Intent.FLAG_RECEIVER_NO_ABORT
            | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND
            | Intent.FLAG_RECEIVER_OFFLOAD);
    // Widget broadcasts are outbound via FgThread, so to guarantee sequencing
    // we also send the boot_completed broadcast from that thread.
    final int callingUid = Binder.getCallingUid();
    final int callingPid = Binder.getCallingPid();
    FgThread.getHandler().post(() -> {
        mInjector.broadcastIntent(bootIntent, null,
                new IIntentReceiver.Stub() {
                    @Override
                    public void performReceive(Intent intent, int resultCode, String data,
                            Bundle extras, boolean ordered, boolean sticky, int sendingUser)
                                    throws RemoteException {
                        Slog.i(UserController.TAG, "Finished processing BOOT_COMPLETED for u"
                                + userId);
                        mBootCompleted = true;
                    }
                }, 0, null, null,
                new String[]{android.Manifest.permission.RECEIVE_BOOT_COMPLETED},
                AppOpsManager.OP_NONE, null, true, false, MY_PID, SYSTEM_UID,
                callingUid, callingPid, userId);
    });
}

14. com.android.settings/.FallbackHome收到android.intent.action.USER_UNLOCKED广播后,拉起com.android.provision/.activities.DefaultActivity

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Set ourselves totally black before the device is provisioned so that
    // we don't flash the wallpaper before SUW
    mProvisioned = Settings.Global.getInt(getContentResolver(),
            Settings.Global.DEVICE_PROVISIONED, 0) != 0;
    final int flags;
    if (!mProvisioned) {
        setTheme(R.style.FallbackHome_SetupWizard);
        flags = View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
    } else {
        flags = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
    }

    mWallManager = getSystemService(WallpaperManager.class);
    if (mWallManager == null) {
        Log.w(TAG, "Wallpaper manager isn't ready, can't listen to color changes!");
    } else {
        loadWallpaperColors(flags);
    }
    getWindow().getDecorView().setSystemUiVisibility(flags);
	//注册BroadcastReceiver接收广播android.intent.action.USER_UNLOCKED
    registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_USER_UNLOCKED));
    maybeFinish();
}
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        //收到广播后, 执行maybeFinish方法
        maybeFinish();
    }
};
private void maybeFinish() {
    //如果System user unlocked
    if (getSystemService(UserManager.class).isUserUnlocked()) {
        //通过intent启动Provision
        final Intent homeIntent = new Intent(Intent.ACTION_MAIN)
                .addCategory(Intent.CATEGORY_HOME);
        final ResolveInfo homeInfo = getPackageManager().resolveActivity(homeIntent, 0);
        if (Objects.equals(getPackageName(), homeInfo.activityInfo.packageName)) {
            if (UserManager.isSplitSystemUser()
                    && UserHandle.myUserId() == UserHandle.USER_SYSTEM) {
                // This avoids the situation where the system user has no home activity after
                // SUW and this activity continues to throw out warnings. See b/28870689.
                return;
            }
            Log.d(TAG, "User unlocked but no home; let's hope someone enables one soon?");
            mHandler.sendEmptyMessageDelayed(0, 500);
        } else {
            Log.d(TAG, "User unlocked and real home found; let's go!");
            getSystemService(PowerManager.class).userActivity(
                    SystemClock.uptimeMillis(), false);
            // MIUI ADD:START
            if (isFirstEnterSecondSpace()) {
                Log.d(TAG, "skip launch home for launch GuideStartActivity when first into second user");
                finish();
                return;
            }
            List<RunningTaskInfo> runningTasks;
            try {
                runningTasks = ActivityManagerNative.getDefault().getTasks(1);
                if (runningTasks != null && !runningTasks.isEmpty() && runningTasks.get(0) != null
                        && runningTasks.get(0).topActivity.getClassName().equals(
                        FallbackHome.class.getName())) {
                    homeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(homeIntent);
                }
             } catch (RemoteException e) {
             }
        	// END
            finish();
        }
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值