Android13 SystemUI启动过程

SystemServer会启动系统运行所需的众多核心服务和普通服务,systemui由System Server启动

private void startOtherServices(@NonNull TimingsTraceAndSlog t) {
    t.traceBegin("startOtherServices");
    mSystemServiceManager.updateOtherServicesStartIndex(); 
    ......
    t.traceBegin("StartSystemUI");
    try {
        startSystemUi(context, windowManagerF);
    } catch (Throwable e) {
        reportWtf("starting System UI", e);
    }
    t.traceEnd();
    t.traceEnd(); // startOtherServices
}

private static void startSystemUi(Context context, WindowManagerService windowManager) {
    PackageManagerInternal pm = LocalServices.getService(PackageManagerInternal.class);
    Intent intent = new Intent();
    intent.setComponent(pm.getSystemUiServiceComponent());
    intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING);
    //Slog.d(TAG, "Starting service: " + intent);
    context.startServiceAsUser(intent, UserHandle.SYSTEM);
    windowManager.onSystemUiStarted();       
}

pm.getSystemUiServiceComponent()在frameworks/base/services/core/java/com/android/server/pm/PackageManagerInternalBase.java

@Override
@Deprecated
public final ComponentName getSystemUiServiceComponent() {
    return ComponentName.unflattenFromString(getContext().getResources().getString(
            com.android.internal.R.string.config_systemUIServiceComponent));
}

config_systemUIServiceComponent定义在frameworks/base/core/res/res/values/config.xml

<!-- SystemUi service component -->
<string name="config_systemUIServiceComponent" translatable="false"
        >com.android.systemui/com.android.systemui.SystemUIService</string>

SystemUI代码路径在AOSP/framework/base/packages/SystemUI

SystemServer启动SystemUIService,在onCreate()中通过ystemUIApplication启动相关service

frameworks/base/packages/SystemUI/src/com/android/systemui/SystemUIService.java

public void onCreate() {
    super.onCreate();

    // Start all of SystemUI
    ((SystemUIApplication) getApplication()).startServicesIfNeeded();

    // Finish initializing dump logic
    mLogBufferFreezer.attach(mBroadcastDispatcher);
    mDumpHandler.init();

    // If configured, set up a battery notification
    if (getResources().getBoolean(R.bool.config_showNotificationForUnknownBatteryState)) {
        mBatteryStateNotifier.startListening();
    }

    // For debugging RescueParty
    if (Build.IS_DEBUGGABLE && SystemProperties.getBoolean("debug.crash_sysui", false)) { 
        throw new RuntimeException();
    }

    if (Build.IS_DEBUGGABLE) {
        // b/71353150 - looking for leaked binder proxies
        BinderInternal.nSetBinderProxyCountEnabled(true);
        BinderInternal.nSetBinderProxyCountWatermarks(1000,900);
        BinderInternal.setBinderProxyCountCallback(
                new BinderInternal.BinderProxyLimitListener() {
                    @Override
                    public void onLimitReached(int uid) {
                        Slog.w(SystemUIApplication.TAG,
                                "uid " + uid + " sent too many Binder proxies to uid "
                                + Process.myUid());
                    }
                }, mMainHandler);
    }

    // Bind the dump service so we can dump extra info during a bug report
    startServiceAsUser(
            new Intent(getApplicationContext(), SystemUIAuxiliaryDumpService.class),
            UserHandle.SYSTEM);
}

frameworks/base/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java

public void startServicesIfNeeded() {
    final String vendorComponent = SystemUIFactory.getInstance()
            .getVendorComponent(getResources());

    // Sort the startables so that we get a deterministic ordering.
    // TODO: make #start idempotent and require users of CoreStartable to call it.
    Map<Class<?>, Provider<CoreStartable>> sortedStartables = new TreeMap<>(
            Comparator.comparing(Class::getName));
    sortedStartables.putAll(SystemUIFactory.getInstance().getStartableComponents());
    sortedStartables.putAll(SystemUIFactory.getInstance().getStartableComponentsPerUser());
    startServicesIfNeeded(
            sortedStartables, "StartServices", vendorComponent);
}

sortedStartables.putAll(SystemUIFactory.getInstance().getStartableComponents())这地方和之前的版本不一样,这里的 sortedStartables 是一个Map,里面存放待启动的各种SystemUI服务。

frameworks/base/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java

/**
 * Returns the list of {@link CoreStartable} components that should be started at startup.
 */
public Map<Class<?>, Provider<CoreStartable>> getStartableComponents() {
    return mSysUIComponent.getStartables();//这里将会返回要启动的组件列表
}

frameworks/base/packages/SystemUI/src/com/android/systemui/dagger/SysUIComponent.java

@SysUISingleton
@Subcomponent(modules = {
        DefaultComponentBinder.class,
        DependencyProvider.class,
        SystemUIBinder.class,
        SystemUIModule.class,
        SystemUICoreStartableModule.class,
        ReferenceSystemUIModule.class})
public interface SysUIComponent {
    ......
    /**
     * Returns {@link CoreStartable}s that should be started with the application.
     */
    Map<Class<?>, Provider<CoreStartable>> getStartables();
    ......
}

使用了dagger的 @IntoMap注入相关类。只要是 继承 CoreStartable 类的都将会被注入。SystemUICoreStartableModule.class这个module中说明哪些类需要注入

com.android.keyguard.KeyguardBiometricLockoutLogger
com.android.systemui.LatencyTester
com.android.systemui.ScreenDecorations
com.android.systemui.SliceBroadcastRelayHandler
com.android.systemui.accessibility.SystemActions
com.android.systemui.accessibility.WindowMagnification
com.android.systemui.biometrics.AuthController
com.android.systemui.broadcast.BroadcastDispatcherStartable
com.android.systemui.clipboardoverlay.ClipboardListener
com.android.systemui.globalactions.GlobalActionsComponent
com.android.systemui.keyboard.KeyboardUI
com.android.systemui.keyguard.KeyguardViewMediator
com.android.systemui.log.SessionTracker
com.android.systemui.media.RingtonePlayer
com.android.systemui.power.PowerUI
com.android.systemui.recents.Recents
com.android.systemui.shortcut.ShortcutKeyDispatcher
com.android.systemui.statusbar.notification.InstantAppNotifier
com.android.systemui.statusbar.notification.interruption.KeyguardNotificationVisibilityProvider
com.android.systemui.statusbar.phone.CentralSurfaces
com.android.systemui.statusbar.phone.KeyguardLiftController
com.android.systemui.theme.ThemeOverlayController
com.android.systemui.toast.ToastUI
com.android.systemui.usb.StorageNotification
com.android.systemui.util.NotificationChannels
com.android.systemui.util.leak.GarbageMonitor
com.android.systemui.volume.VolumeUI
com.android.systemui.wmshell.WMShell

上面是SystemUI加载的的类。

接着回到 SystemUIApplication 的 startServicesIfNeeded() 方法

private void startServicesIfNeeded(
        Map<Class<?>, Provider<CoreStartable>> startables,
        String metricsPrefix,
        String vendorComponent) {
    if (mServicesStarted) {
        return;
    }
    mServices = new CoreStartable[startables.size() + (vendorComponent == null ? 0 : 1)];

    if (!mBootCompleteCache.isBootComplete()) {
        // check to see if maybe it was already completed long before we began
        // see ActivityManagerService.finishBooting()
        if ("1".equals(SystemProperties.get("sys.boot_completed"))) {
            mBootCompleteCache.setBootComplete();
            if (DEBUG) {
                Log.v(TAG, "BOOT_COMPLETED was already sent");
            }
        }
    }

    mDumpManager = mSysUIComponent.createDumpManager();

    Log.v(TAG, "Starting SystemUI services for user " +
            Process.myUserHandle().getIdentifier() + ".");
    TimingsTraceLog log = new TimingsTraceLog("SystemUIBootTiming",
            Trace.TRACE_TAG_APP);
    log.traceBegin(metricsPrefix);

    int i = 0;
    for (Map.Entry<Class<?>, Provider<CoreStartable>> entry : startables.entrySet()) {
        String clsName = entry.getKey().getName();
        int j = i;  // Copied to make lambda happy.
        timeInitialization(
                clsName,
                () -> mServices[j] = startStartable(clsName, entry.getValue()),// 这里就和之前版本一样,调用start()方法启动对应服务。
                log,
                metricsPrefix);
        i++;
    }

    if (vendorComponent != null) {
        timeInitialization(
                vendorComponent,
                () -> mServices[mServices.length - 1] =
                        startAdditionalStartable(vendorComponent),
                log,
                metricsPrefix);
    }

    for (i = 0; i < mServices.length; i++) {
        if (mBootCompleteCache.isBootComplete()) {
            mServices[i].onBootCompleted();
        }

        mDumpManager.registerDumpable(mServices[i].getClass().getName(), mServices[i]);
    }
    mSysUIComponent.getInitController().executePostInitTasks();
    log.traceEnd();

    mServicesStarted = true;
    FeatureOptions.sShouldShowUI = true;
}

先写到这里,后面看明白了记录

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android 13 SystemUI 是指第13Android操作系统的用户界面系统。Android是一种基于Linux内核的开源操作系统,广泛应用于智能手机、平板电脑和其他设备上。Android 13是该操作系统的一个重要更新版本,引入了许多新功能和改进。 SystemUI负责控制和管理Android设备的用户界面。它包括状态栏、导航栏、通知中心等核心组件。Android 13 SystemUI对这些组件进行了优化和增强。 首先,Android 13 SystemUI改进了状态栏。它提供了更多的自定义选项,用户可以根据自己的喜好调整状态栏的样式和布局。此外,状态栏还增加了一些实用的功能,如快速设置面板,使用户可以更方便地访问常用设置。 其次,导航栏在Android 13中也有所改进。新的导航栏更加直观和易于使用,增加了手势导航的支持。用户可以使用手势来浏览和操作应用程序,取代传统的导航按钮。这大大提高了用户的操作流畅性和效率。 最后,Android 13 SystemUI对通知中心进行了改进。用户可以根据自己的需要对通知进行分类和管理。此外,通知中心还将更多的控制选项整合到了一个位置,用户可以轻松地切换网络、调整亮度等。 总的来说,Android 13 SystemUIAndroid 13操作系统的用户界面系统,它通过对状态栏、导航栏和通知中心等核心组件的优化和增强,提供了更好的用户体验和更高的操作效率。用户可以根据自己的喜好和需求,自定义和管理这些界面组件。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值