简体   繁体   中英

How to replace the AOSP System UI with a custom one?

The SysUI in AOSP is just an app. Very tight to the Android framework though. Is there a recommended way to disable the vanilla SysUI and replace this functionality with a fully independent custom apk? I believe it should be doable since Wear OS seems to do something similar.

Yes. You can replace it with a custom one.

The SysUI implement IStatusBar and register it to the framework by IStatusBarService#registerStatusBar , and it create an StatusBarView and add it to WindowManager with type WindowManager.LayoutParams.TYPE_STATUS_BAR. If you do the same logic as the SysUI, and you can replace it.

WearOS only implement two features of SysUI:

  1. show and manage notifications. It implement the NotificationListenerService. And Enable the listener by default, or ask for the user's confirm. Then it will get all the notifications.
  2. some toggle.

So you can implement a full feature SystemUI like the AOSP, and it will be a litte tight to the framework. If the IStatusBar has changed, you should change your app too. Or you can implement a small feature SystemUI like WearOS. NotificationListenerService is stable.

for the impatient:

  • let use LOCAL_OVERRIDES_PACKAGES

     LOCAL_SRC_FILES := new_system_ui.apk LOCAL_OVERRIDES_PACKAGES := SystemUI

inside your Android.mk file

Details: Let use this Android.mk file as an example from here How to Add Pre-built App (System App) in AOSP source code

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := Signal
LOCAL_CERTIFICATE := platform
LOCAL_SRC_FILES := Signal-website-universal-release-4.55.8.apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
include $(BUILD_PREBUILT)

and let say you have a new_system_ui.apk ( could be a fork of the system_ui with your custom code)

create your custom Android.mk to overwrite the default "system_ui.apk" with the "new_system_ui.apk"

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := Signal
LOCAL_CERTIFICATE := platform
LOCAL_SRC_FILES := new_system_ui.apk <-------YOUR APK---->
LOCAL_OVERRIDES_PACKAGES := SystemUI <-------HERE-------->
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
include $(BUILD_PREBUILT)

Extra notes: how you know all is right:

  • "com.android.systemui" will be part of the result of doing adb shell pm list packages before you decide to use the LOCAL_OVERRIDES_PACKAGES := SystemUI
  • once you start using the LOCAL_OVERRIDES_PACKAGES := SystemUI and you build/flash the image, there is not going to be any more "com.android.systemui"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM