0 x00 to introduce

You have seen from the previous article that SystemUI is started by SystemServer. To be more precise, SystemServer starts a service named SystemUIService in SystemUI and then starts all service components in SystemUIApplication. These service components are defined in config.xml

frameworks/base/packages/SystemUI/res/values/config.xml

<! -- SystemUI Services: The classes of the stuff to start. --> <string-array name="config_systemUIServiceComponents" translatable="false"> <item>com.android.systemui.util.NotificationChannels</item> <item>com.android.systemui.keyguard.KeyguardViewMediator</item> <item>com.android.systemui.recents.Recents</item> <item>com.android.systemui.volume.VolumeUI</item> <item>com.android.systemui.statusbar.phone.StatusBar</item> <item>com.android.systemui.usb.StorageNotification</item> <item>com.android.systemui.power.PowerUI</item> <item>com.android.systemui.media.RingtonePlayer</item> <item>com.android.systemui.keyboard.KeyboardUI</item> <item>com.android.systemui.shortcut.ShortcutKeyDispatcher</item> <item>@string/config_systemUIVendorServiceComponent</item> <item>com.android.systemui.util.leak.GarbageMonitor$Service</item> <item>com.android.systemui.LatencyTester</item> <item>com.android.systemui.globalactions.GlobalActionsComponent</item> <item>com.android.systemui.ScreenDecorations</item> <item>com.android.systemui.biometrics.AuthController</item> <item>com.android.systemui.SliceBroadcastRelayHandler</item> <item>com.android.systemui.statusbar.notification.InstantAppNotifier</item> <item>com.android.systemui.theme.ThemeOverlayController</item> <item>com.android.systemui.accessibility.WindowMagnification</item> <item>com.android.systemui.accessibility.SystemActions</item> <item>com.android.systemui.toast.ToastUI</item> <item>com.android.systemui.wmshell.WMShell</item> </string-array>Copy the code

These are the key code in SystemUI to handle various business logic, a total of more than 20 components, from another aspect of the complexity of SystemUI. Their descriptions are also available on the source reader website

Here’s a quick explanation

Com. Android. Systemui. Di implementation provided the Dependency (this in the latest source config_systemUIServiceComponents is not inside, But if you look at Android this class there is a 10) com. Android. The systemui. Util. NotificationChannels used to handle notification logic Com. Android. Systemui. Keyguard. KeyguardViewMediator used to deal with the keyboard lock state com. Android. The systemui. Recents. Recents processing logic of the latest task list Com. Android. Systemui. Volume. VolumeUI listening volume, com and decide whether to display the volume of the dialog box. The android. The systemui. Status. The phone. The StatusBar status bar, It also includes notification bars and other important UI interactions, such as keyboard locks. Here also will inform com listening. Android. Systemui. Usb. StorageNotification listening usb connection status and send the notice to com. Android. The systemui. Power. PowerUI To monitor power status and send a notification when low battery com. Android. Systemui. Media. RingtonePlayer for rings com. Android. Systemui. The rid_device_info_keyboard. KeyboardUI keyboard lock the UI Com. Android. Systemui. Shortcut. ShortcutKeyDispatcher to distribute shortcuts @ string/config_systemUIVendorServiceComponent systemui components Here you can define custom component com... android. The systemui. Util. Leak. GarbageMonitor $Service used to monitor the memory leak Service com. Android. The systemui. LatencyTester in only Debug environment execution, Used in the simulation of the surveillance system test delay action com. Android. The systemui. Globalactions. GlobalActionsComponent is used to display the global dialog box (for example, long press the power button) com.android.systemui.ScreenDecorations Draws decorations about the screen in software (e.g. rounded corners, cutouts). To deal with the display page shape (such as rounded corners) com. Android. Systemui. Biometrics. BiometricDialogImpl biometric UI (such as fingerprint identification, unlock page?) com.android.systemui.wmshell.WMShell Delegates SysUI events to WM Shell controllers. Forward SysUI events to WM ShellCopy the code

0x01 Component Structure

These service components are not part of the Android system’s four major components. These components are implemented as normal Java classes, and in fact inherit from the SystemUI class

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

/** * A top-level module of system UI code (sometimes called "system UI services" elsewhere in code). * Which SystemUI modules are loaded can be controlled via a config resource. * * @see SystemUIApplication#startServicesIfNeeded() */ public abstract class SystemUI implements Dumpable { protected final Context mContext; public SystemUI(Context context) { mContext = context; } public abstract void start(); protected void onConfigurationChanged(Configuration newConfig) { } @Override public void dump(@NonNull FileDescriptor fd, @NonNull PrintWriter pw, @NonNull String[] args) { } protected void onBootCompleted() { } public static void overrideNotificationAppName(Context context, Notification.Builder n, boolean system) { final Bundle extras = new Bundle(); String appName = system ? context.getString(com.android.internal.R.string.notification_app_name_system) : context.getString(com.android.internal.R.string.notification_app_name_settings); extras.putString(Notification.EXTRA_SUBSTITUTE_APP_NAME, appName); n.addExtras(extras); }}Copy the code

You can see that this class is not complex, and you can see from the comments that these components are called System UI Services. It is abstract, and its start() is implemented in subclasses. As you have seen before, after each component is constructed by reflection in SystemUIApplication#startServicesIfNeeded(), start() is called to start it. There is also the onBootCompleted() method, which registers the listener action in SystemUIApplication#onCreate() and executes it after the system has started.

Class structure diagram is available for reference

Only four implementation classes are drawn here; you can imagine the rest

0 x02 thinking

What is the use of knowing this?

Of course, if you’re not doing system application development, this knowledge may not be so useful to you. Especially if you’re just an upper-level app developer, it’s pretty easy to get a rough idea of what’s going on. But if you need to deeply customize your system’s UI, I don’t think it’s enough to just know the basics. Once you have a macro understanding of these components, then you can understand how they work in depth according to your needs, and then you can transform them and create them again.

0 x03 reference

  • Read the source code online at cs.android.com