[深入SystemUI]-了解recents的启动流程(二)

本文流程基于Android 9.0
toggleRecentApps介绍

在这里插入图片描述

上节中我们讲了preloadRecentApps,而点击了switch可能执行两种不同的方法,另外一种就是toggleRecentApps。

和preloadRecentApps在fwk中的调用过程一样,最终是调用到了SystemUI的Recents.toggleRecentApps()方法。

toggleRecentApps方法分析

由于Android9.0上将最近任务的显示交给了Launcher来实现,所以这里会存在两种逻辑,一种是Launcher的显示逻辑,另外一种则是SystemUI原始的显示逻辑。

/**
 * Toggles the Recents activity.
 */
@Override
public void toggleRecentApps() {
   
    // Ensure the device has been provisioned before allowing the user to interact with
    // recents
    if (!isUserSetup()) {
   
        return;
    }

    // If connected to launcher service, let it handle the toggle logic
    // 如果绑定到了Launcher的服务,那么就让Launcher来执行最近任务的显示逻辑
    IOverviewProxy overviewProxy = mOverviewProxyService.getProxy();
    if (overviewProxy != null) {
   
        final Runnable toggleRecents = () -> {
   
            try {
   
                if (mOverviewProxyService.getProxy() != null) {
   
                    mOverviewProxyService.getProxy().onOverviewToggle();
                }
            } catch (RemoteException e) {
   
                Log.e(TAG, "Cannot send toggle recents through proxy service.", e);
            }
        };
        // Preload only if device for current user is unlocked
        final StatusBar statusBar = getComponent(StatusBar.class);
        // 判断手机是否处于锁屏状态
        if (statusBar != null && statusBar.isKeyguardShowing()) {
   
            statusBar.executeRunnableDismissingKeyguard(() -> {
   
                    // Flush trustmanager before checking device locked per user
                    mTrustManager.reportKeyguardShowingChanged();
                    mHandler.post(toggleRecents);
                }, null,  true /* dismissShade */, false /* afterKeyguardGone */,
                true /* deferred */);
        } else {
   
            toggleRecents.run();
        }
        return;
    }
    // 上面是由Launcher去显示最近任务的逻辑,下面就是SystemUI原生显示最近任务的逻辑
    // 注意到了没?这部分和preloadRecentApps的判断逻辑很像
    int growTarget = getComponent(Divider.class).getView().growsRecents();
    int currentUser = sSystemServicesProxy.getCurrentUser();
    if (sSystemServicesProxy.isSystemUser(currentUser)) {
   
        mImpl.toggleRecents(growTarget);
    } else {
   
        if (mSystemToUserCallbacks != null) {
   
            IRecentsNonSystemUserCallbacks callbacks =
                    mSystemToUserCallbacks.getNonSystemUserRecentsForUser(currentUser);
            if (callbacks != null) {
   
                try {
   
                    callbacks.toggleRecents(growTarget);
                } catch (RemoteException e)
  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值