Android U pipeline-statusbar

Android U - statusbar pipeline

写在前面

Android原生从T开始对SystemUI进行MVVM改造,U上状态栏部分进行了修改;第一次出现修改不会删除原有逻辑,而是两版并行,留给其他开发者适配的时间;在下一个大版本可能会删除原有逻辑,只留下MVVM。
新版MVVM放在pipeline目录下,本篇文章对状态栏部分进行分析,以及整理与原有逻辑的对应关系。


SystemUI/packages/SystemUI/src/com/android/systemui/statusbar/pipeline

目前可以切换pipeline的控件为数据信号和wifi,开启位置:

# StatusBarPipelineFlags

/** True if we should display the mobile icons using the new status bar data pipeline. */
fun useNewMobileIcons(): Boolean =  featureFlags.isEnabled(Flags.NEW_STATUS_BAR_MOBILE_ICONS)

/** True if we should display the wifi icon using the new status bar data pipeline. */
fun useNewWifiIcon(): Boolean =  featureFlags.isEnabled(Flags.NEW_STATUS_BAR_WIFI_ICON)

Mobile

pipeline-mobile

1 data

1.1 model

DataConnectionState.kt 枚举;数据连接状态

1 Connected,
2 Connecting,
3 Disconnected,
4 Disconnecting,
5 Suspended,
6 HandoverInProgress,
7 Unknown,
8 Invalid;

NetworkNameModel.kt ⽹络名称,通过密封接⼝的⽅式声明了三个
密封接⼝:https://www.jianshu.com/p/6d70e3b5d380
通过TelephonyManager.ACTION_SERVICE_PROVIDERS_UPDATED更新

1 Default 默认,读取[com.android.internal.R.string.lockscreen_carrier_default]
2 IntentDerived intent传过来
3 SimDerived sim卡传过来

ResolvedNetworkType.kt ⽹络类型,从TelephonyDisplayInfo中获取的

1 UnknownNetworkType
2 DefaultNetworkType
3 OverrideNetworkType
4 CarrierMergedNetworkType

SubscriptionModel.kt
[SubscriptionInfo]的SystemUI表⽰。⽬前,我们仅在订阅本⾝上使⽤两个字段:subscriptionId和isOpportunistic。我们需要的任何新字段都可以添加到下⾯并在存储库类中提供

1 subscriptionId  : subId
2 isOpportunistic : https://learn.microsoft.com/zh-cn/dotnet/api/android.telephon
3 groupUuid       : 合并相同的uuid下的⽹络;
					NetworkControllerImpl.filterMobileSubscriptionInSameGroup,
					MobileIconsInteractor.filteredSubscriptions

SystemUiCarrierConfig.kt 给定subId,获取systemUI需要的读取的数据的key

1 inflateSignalStrength
2 showOperatorName
1.2 repository
1.2.1 demo

demo模式下的显⽰,对照下⽅1.2.2 prod去看

1.2.2 prod

MobileConnectionRepositoryImpl和MobileConnectionsRepositoryImpl是下⽅两个接⼝的实现类,具体接收底层数据回调⻅MobileConnectionRepositoryImpl.callbackEvents,对标MobileStatusTracker中注册的回调:

private val callbackEvents: StateFlow<TelephonyCallbackState> = run {
        val initial = TelephonyCallbackState()
        callbackFlow {
                val callback =
                    object :
                        TelephonyCallback(),
                        TelephonyCallback.ServiceStateListener,
                        TelephonyCallback.SignalStrengthsListener,
                        TelephonyCallback.DataConnectionStateListener,
                        TelephonyCallback.DataActivityListener,
                        TelephonyCallback.CarrierNetworkListener,
                        TelephonyCallback.DisplayInfoListener,
                        TelephonyCallback.DataEnabledListener {
                        override fun onServiceStateChanged(serviceState: ServiceState) {
                            logger.logOnServiceStateChanged(serviceState, subId)
                            trySend(CallbackEvent.OnServiceStateChanged(serviceState))
                        }

                        override fun onSignalStrengthsChanged(signalStrength: SignalStrength) {
                            logger.logOnSignalStrengthsChanged(signalStrength, subId)
                            trySend(CallbackEvent.OnSignalStrengthChanged(signalStrength))
                        }

                        override fun onDataConnectionStateChanged(
                            dataState: Int,
                            networkType: Int
                        ) {
                            logger.logOnDataConnectionStateChanged(dataState, networkType, subId)
                            trySend(CallbackEvent.OnDataConnectionStateChanged(dataState))
                        }

                        override fun onDataActivity(direction: Int) {
                            logger.logOnDataActivity(direction, subId)
                            trySend(CallbackEvent.OnDataActivity(direction))
                        }

                        override fun onCarrierNetworkChange(active: Boolean) {
                            logger.logOnCarrierNetworkChange(active, subId)
                            trySend(CallbackEvent.OnCarrierNetworkChange(active))
                        }

                        override fun onDisplayInfoChanged(
                            telephonyDisplayInfo: TelephonyDisplayInfo
                        ) {
                            logger.logOnDisplayInfoChanged(telephonyDisplayInfo, subId)
                            trySend(CallbackEvent.OnDisplayInfoChanged(telephonyDisplayInfo))
                        }

                        override fun onDataEnabledChanged(enabled: Boolean, reason: Int) {
                            logger.logOnDataEnabledChanged(enabled, subId)
                            trySend(CallbackEvent.OnDataEnabledChanged(enabled))
                        }
                    }
                telephonyManager.registerTelephonyCallback(bgDispatcher.asExecutor(), callback)
                awaitClose { telephonyManager.unregisterTelephonyCallback(callback) }
            }
            .scan(initial = initial) { state, event -> state.applyEvent(event) }
            .stateIn(scope = scope, started = SharingStarted.WhileSubscribed(), initial)
    }

接收到数据后通知view更新显⽰,⻅下⽅3.4 viewmodel
MobileConnectionRepository

1 subId                       :subId
2 carrier 		              :See [TelephonyManager.getSimCarrierId]
3 isEmergencyOnly             :紧急呼叫,⻅MobileSignalController
4 isRoaming                   :漫游,⻅MobileSignalController
5 operatorAlphaShort          :运营商名字⼩写
6 isInService.                :in service,⻅MobileSignalController
7 isGsm.                      :MobileSignalController中只有在判断是否为cdma时⽤到了,
8 cdmaLevel
9 primaryLevel                :两个level放⼀起看⼀下
10						       根据aospLevel和qcomLevel去计算,⻅MobileSignalController
11 dataConnectionState.       :⻅MobileSignalController.dataConnected,区分了各种状态
12 dataActivityDirection      :上下⾏,⻅MobileSignalController
13 carrierNetworkChangeActive :carrierNetworkChangeMode
14 resolvedNetworkType.       :override network type
15 numberOfLevels             :信号个数
16 dataEnabled                :是否开了数据;⻅StatusBarSignalPolicy
17 cdmaRoaming.               :cdma是否漫游,TODO 没⻅过
18 networkName                :⻅1.1 networknamemodel

MobileConnectionsRepository (TODO 后面再填)

1 subscriptions :
2 activeMobileDataSubscriptionId:
3 activeMobileDataRepository :
4 activeSubChangedInGroupEvent :
5 defaultDataSubId :
6 mobileIsDefault :
7 hasCarrierMergedConnection :
8 defaultConnectionIsValidated :
9 defaultDataSubRatConfig :
10 defaultMobileIconMapping :
11 defaultMobileIconGroup :

FullMobileConnectionRepository.kt 整体的移动通信repo,包含了移动数据的repo(MobileConnectionRepositoryImpl)和运营商合并⽹络的repo(CarrierMergedConnectionRepository);
数据获取从Full repo中读取,Full repo选择mobile或carrierMerged中的⼀个做为activeRepo读取数据

CarrierMergedConnectionRepository.kt 运营商合并⽹络的repo

/**
 * A repository implementation for a carrier merged (aka VCN) network. A carrier merged network is
 * delivered to SysUI as a wifi network (see [WifiNetworkModel.CarrierMerged], but is visually
 * displayed as a mobile network triangle.
 *
 * See [android.net.wifi.WifiInfo.isCarrierMerged] for more information.
 *
 * See [MobileConnectionRepositoryImpl] for a repository implementation of a typical mobile
 * connection.
 */
 运营商合并(⼜名 VCN)⽹络的存储库实现。运营商合并⽹络作为 wifi ⽹络传递到 SysUI
 有关更多信息,请参阅 [android.net.wifi.WifiInfo.isCarrierMerged]。
 有关典型移动连接的存储库实现,请参阅 [MobileConnectionRepositoryImpl]。

CarrierConfigCoreStartable.kt.
⽤于启动CarrierConfigRepository
CarrierConfigRepository.kt.
给定subId,获取缓存的设置;数据key⻅SystemUiCarrierConfig.
MobileRepositorySwitcher.kt 切换demo模式和真实数据的显⽰.

1 RealRepository
2                │
3                ├──►RepositorySwitcher──►RealInteractor──►RealViewModel
4                │
5 DemoRepository

UserSetupRepositoryImpl.kt user,使⽤在MobileIconsInteractor中isUserSetup,⽬前没有使⽤到的地⽅

1.3 others

MobileInputLogger.kt logBuffer

2 domin

2.1 interactor

MobileIconInteractor.kt

1 tableLogBuffer            :log
2 activity                  :上下⾏
3 mobileIsDefault           :See [MobileConnectionsRepository.mobileIsDefault]
4 
5 isDataConnected           :数据是否连接(判断条件去MobileSignalController中看下)
6 isDefaultConnectionFailed :是否连接失败;⽤于判断是否显⽰错误状态下的SignalDrawable
7 isInService               :是否有服务
8 isDefaultDataEnabled      :dataEnabled default设置,MobileIconsInterator.active
9 isDataEnabled             :dataEnabled
10 alwaysShowDataRatIcon.   :是否要⼀直显⽰数据图标;
11                           U之前没这个功能,数据图表常驻的;根据需求决定这东西还要不要
12                           个⼈理解可直接改成false,具体情况适配时注意下
13 alwaysUseCdmaLevel       :cdma是单独判断的,⻅MobileSignalController.isCdma;
14                           该变量影响level值的选择
15                           个⼈理解可直接改成false,具体情况适配时注意下
16 networkTypeIconGroup     :⽹络类型的iconGroup,⻅2.2中NetworkTypeIconGroup
17 networkName              :⽹络名称,⻅1.1中NetworkNameModel
18 isEmergencyOnly          :仅可紧急通话
19 isRoaming                :是否是漫游
20 level                    :信号强度格数
21 numberOfLevels           :最⼤信号格数,4还是5;海外(日本)有此类定制
22                           后续可以⽤此处来拓展
23 isForceHidden            :强制隐藏信号图标;寻找是不是在icon_blacklist中
24 carrierNetworkChangeActive:对应MobileSignalController.isCarrierNetworkChangeActive

MobileIconsInteractor.kt

1 mobileIsDefault           :同上MobileIconInteractor中
2 filteredSubscriptions     :
3 activeDataConnectionHasDataEnabled :
4 alwaysShowDataRatIcon     :同上MobileIconInteractor中
5 alwaysUseCdmaLevel.       :同上MobileIconInteractor中
6 defaultMobileIconMapping  :
7 defaultMobileIconGroup    :
8 isDefaultConnectionFailed :同上MobileIconInteractor中
9 isUserSetup               :
10 isForceHidden            :同上MobileIconInteractor中
11
12 fun createMobileConnectionInteractorForSubId(subId: Int): MobileIconInteractor
13 ⽤于创建MobileIconInteractor实例
2.2 model

NetworkTypeIconModel.kt 密封类 ⽹络类型图标,根据是否是override type,对应下⽅两种类型

1 val contentDescription: Int
2 val iconId: Int
3 val name: String
4
5 data class DefaultIcon
6 data class OverriddenIcon

3 ui

3.1 binder

MobileIconBinder:更新ModernStatusBarMobileView的显⽰,对标StatusBarMobileView.
区别:StatusBarMobileView中,通过bean类传递最新的信息,每次整体更新view的显⽰,根据计算后是否有变化来决定是否刷新;
MobileIconBinder中,每个不同的变量都通过各⾃注册的监听来回调,只触发各⾃的部分;
此处适配时,对于新增的ui和变量,很多都是多种条件组合判断的;需要将多种条件都放⼊监听中,根据计算后的结果来判断,例如:

1 // Set the activity indicators
2 launch {
3   combine(viewModel.activityInVisible, viewModel.activityOutVi
4     activityIn, activityOut, dataConnected ->
5   if (dataConnected) {
6     if (activityIn && activityOut) {
7       viewModel.leftInOutResId = R.drawable.xxx;
8       viewModel.rightInOutResId = R.drawable.xxx;
9     } else if (activityIn) {
10      viewModel.leftInOutResId = R.drawable.xxx;
11      viewModel.rightInOutResId = R.drawable.xxx;
12    } else if (activityOut) {
13      viewModel.leftInOutResId = R.drawable.xxx;
14      viewModel.rightInOutResId = R.drawable.xxx;
15    } else {
16      viewModel.leftInOutResId = R.drawable.xxx;
17      viewModel.rightInOutResId = R.drawable.xxx;
18    }
19   }
20   leftInOut.setImageResource(transformResId(viewModel.left));
21   rightInOut.setImageResource(transformResId(viewModel.right));
22  }
23 }

MobileIconsBinder:提供对外的static⽅法,bind后在每次声明周期为STARTED时更新;
⽬前collect中为空,因为和旧版逻辑适配的原因,此处逻辑在MobileUiAdapter中;后续⼤版本如果移除了旧版逻辑,会迁移⾄此处.

3.2 model

SignalIconModel.kt 打信号格相关的log;选择信号格的图⽚.
⻅2.1中numberOfLevels

	/** Convert this model to an [Int] consumable by [SignalDrawable]. */
    fun toSignalDrawableState(): Int =
        if (carrierNetworkChange) {
            SignalDrawable.getCarrierChangeState(numberOfLevels)
        } else {
            SignalDrawable.getState(level, numberOfLevels, showExclamationMark)
        }
3.3 view

ModernStatusBarMobileView.kt pipeline的信号view;内部逻辑都放到了MobileIconBinder中,剩下布局的加载和⼀些变量获取

	companion object {
        /**
         * Inflates a new instance of [ModernStatusBarMobileView], binds it to [viewModel], and
         * returns it.
         */
        @JvmStatic
        fun constructAndBind(
            context: Context,
            logger: MobileViewLogger,
            slot: String,
            viewModel: LocationBasedMobileViewModel,
        ): ModernStatusBarMobileView {
            return (LayoutInflater.from(context)
                    .inflate(R.layout.status_bar_mobile_signal_group_new, null)
                    as ModernStatusBarMobileView)
                .also {
                    it.subId = viewModel.subscriptionId
                    it.initView(slot) { MobileIconBinder.bind(it, viewModel, logger) }
                    logger.logNewViewBinding(it, viewModel)
                }
        }
    }
3.4 viewmodel

LocationBasedMobileViewModel.kt 根据location创建三个不同的viewmodel

1 HomeMobileIconViewModel
2 QsMobileIconViewModel
3 KeyguardMobileIconViewModel

MobileIconsViewModel.kt.
MobileIconViewModel.kt
为MobileIconBinder提供数据;binder中监听的变量是从viewmodel中获取的,viewmodel中的变量
通过2.1中interactor获取;
即当信号的数据发⽣变化时,底层数据发⽣变化->通知interactor中变化->通知viewmodel中变化->通知binder去更新显⽰;例如:

# MobileIconBinder.kt

// 信号格图标,监听的viewmodel中icon的变化
// Set the icon for the triangle
launch {
     viewModel.icon.distinctUntilChanged().collect { icon ->
       viewModel.verboseLogger?.logBinderReceivedSignalIcon(
             view,
             viewModel.subscriptionId,
             icon,
        )
     mobileDrawable.level = icon.toSignalDrawableState()
   }
}

# MobileIconViewModel.kt

val icon: Flow<SignalIconModel>

override val icon: Flow<SignalIconModel> = run {
        val initial =
            SignalIconModel(
                level = shownLevel.value,
                numberOfLevels = iconInteractor.numberOfLevels.value,
                showExclamationMark = showExclamationMark.value,
                carrierNetworkChange = iconInteractor.carrierNetworkChangeActive.value,
            )
        combine(
                shownLevel,
                iconInteractor.numberOfLevels,
                showExclamationMark,
                iconInteractor.carrierNetworkChangeActive,
            ) { shownLevel, numberOfLevels, showExclamationMark, carrierNetworkChange ->
                SignalIconModel(
                    shownLevel,
                    numberOfLevels,
                    showExclamationMark,
                    carrierNetworkChange,
                )
            }
            .distinctUntilChanged()
            .logDiffsForTable(
                iconInteractor.tableLogBuffer,
                columnPrefix = "icon",
                initialValue = initial,
            )
            .stateIn(scope, SharingStarted.WhileSubscribed(), initial)
    }

# MobileIconInteractor.kt

val numberOfLevels: StateFlow<Int>

override val numberOfLevels: StateFlow<Int> =
        connectionRepository.numberOfLevels.stateIn(
            scope,
            SharingStarted.WhileSubscribed(),
            connectionRepository.numberOfLevels.value,
        )

# MobileConnectionRepository.kt

val numberOfLevels: StateFlow<Int>

# 最后数据落到底层回调,⻅上⽂中1.2.2
3.5 others

MobileUiAdapter.kt pipeline和旧版的连接,将UI刷新转回到StatusBarIconControllerImpl中;后续如果移除旧版逻辑,可能会移⾛,⻅MobileIconsBinder.

	override fun start() {
        // Only notify the icon controller if we want to *render* the new icons.
        // Note that this flow may still run if
        // [statusBarPipelineFlags.runNewMobileIconsBackend] is true because we may want to
        // get the logging data without rendering.
        if (statusBarPipelineFlags.useNewMobileIcons()) {
            scope.launch {
                isCollecting = true
                mobileIconsViewModel.subscriptionIdsFlow.collectLatest {
                    logger.logUiAdapterSubIdsSentToIconController(it)
                    lastValue = it
                    iconController.setNewMobileIconSubIds(it)
                }
            }
        }
    }

MobileViewLogger.kt log.
VerboseMobileViewLogger.kt log.

4 util

MobileMappings.kt ⾥⾯是proxy,提供对外⽅法

1 MobileMappingsProxyImpl
2 # fun mapIconSets(config: Config): Map<String, MobileIconGroup>
3 # fun getDefaultIcons(config: Config): MobileIconGroup
4 # fun getIconKey(displayInfo: TelephonyDisplayInfo): String
5 # fun toIconKey(@NetworkType networkType: Int): String
6 # fun toIconKeyOverride(@NetworkType networkType: Int): String

SubscriptionManagerProxy.kt

1 SubscriptionManagerProxyImpl
2 # fun getDefaultDataSubscriptionId(): Int

Wifi

pipeline-wifi

1 data

1.1 repository

repository层是MVVM框架中⽤于解耦业务逻辑和数据的独⽴的⼀层:

https://www.jianshu.com/p/4679c384acae

1 # WifiRepository.kt
2
3 // 声明变量;具体实现在prod下的两个类中;Disabled开头是禁⽤下的
4 // 对应WifiStatusTracker
5 // wifi是否开启,对应enabled
6 val isWifiEnabled: StateFlow<Boolean>
7 // 对应isWifi
8 val isWifiDefault: StateFlow<Boolean>
9 // 连接变化和中断的回调,对应mNetworkCallback
10 val wifiNetwork: StateFlow<WifiNetworkModel>
11 // 上下⾏
12 val wifiActivity: StateFlow<DataActivityModel>
# WifiRepositorySwitcher.kt

// 根据demo mode开启状态,切换数据源是真实数据还是demo数据;该类上⽅的注释详细的描述了

/**
 * Provides the [WifiRepository] interface either through the [DemoWifiRepository] implementation,
 * or the [WifiRepositoryImpl]'s prod implementation, based on the current demo mode value. In this
 * way, downstream clients can all consist of real implementations and not care about which
 * repository is responsible for the data. Graphically:
 * ```
 * RealRepository
 *                 │
 *                 ├──►RepositorySwitcher──►RealInteractor──►RealViewModel
 *                 │
 * DemoRepository
 * ```
 *
 * When demo mode turns on, every flow will [flatMapLatest] to the current provider's version of
 * that flow.
 */

2 domain

2.1 interactor

WifiInteractor.kt.
业务逻辑层,对应MiuiWifiSignalController.java中copyWifiStates(),将wifi变化后的数据传给实际应⽤的bean类中

3 shared

3.1 model

WifiNetworkModel.kt.
sealed class:https://blog.csdn.net/qq_33552379/article/details/125996716,类似枚举,但只能在当前类中去声明

1 Unavailable:wifi不可⽤,WifiManager为null
2 Invalid:wifi信息⽆效
3 Inactive:⽆有效的wifi⽹络
4 CarrierMerged:该模型表⽰我们的 WiFi ⽹络实际上是运营商合并⽹络,这意味着它更像是移动⽹络
5 Active:有效的wifi⽹络

WifiConstants.kt.
alwaysShowIconIfEnabled:是否⼀直显⽰wifi icon;miui⽬前逻辑不需要这个,适配的时候改成false

WifiInputLogger.kt.
为repository提供log⽅法

4 ui

4.1 binder

WifiViewBinder.kt.
根据数据为wifi icon更新UI显⽰,对应StatusBarWifiView.java;
pipeline中UI类替换成了ModernStatusBarWifiView.kt,具体UI显⽰逻辑移到了binder类中return值:改类返回⼀个ModernStatusBarViewBinding对象,实现需要对外提供信息的接⼝;对外提供其他数据可在该接⼝中增加⽅法并实现.

4.2 model

WifiIcon.kt.
sealed class;内部⼦类有两个 Visible和Hidden,在WifiViewBinder和WifiViewModel中使⽤.

4.3 view

ModernStatusBarWifiView.kt.
包含inflate时的布局,其他逻辑都交由binder中处理

4.4 viewmodel

WifiViewModelCommon.kt.

1 // 接⼝,声明变量
2 // wifi icon是否可⻅
3 val wifiIcon: StateFlow<WifiIcon>
4 // 上下⾏是否可⻅
5 val isActivityInViewVisible: Flow<Boolean>
6 val isActivityOutViewVisible: Flow<Boolean>
7 val isActivityContainerVisible: Flow<Boolean>
8 // ⻜⾏模式图标是否可⻅
9 val isAirplaneSpacerVisible: Flow<Boolean>
10 //
11 val isSignalSpacerVisible: Flow<Boolean>

WifiViewModel.kt.

  1. 实现了WifiViewModelCommon接⼝;WifiViewModel是单例,不能直接它来控制view;⽽是使⽤LocationBasedWifiViewModel,它其中声明了多个不同情况下的viewmodel
  2. 如上⽅2.1所述,wifi状态变化的数据被存放在WifiInteractor中;WifiViewModel中使⽤WifiInteractor的数据,计算出控件是否需要显⽰.
// 此处对应wifi icon图⽚的获取;
// miui⽬前新增逻辑,在MiuiStatusBarSignalPolicy和MiuiWifiSignalController有定制;
// 可通过WifiIcons的引⽤进⾏查找;适配wifi 7、热点等图⽚需要在这⾥
private fun WifiNetworkModel.icon(): WifiIcon {
        return when (this) {
            // 不可⽤、⾮wifi情况下隐藏
            is WifiNetworkModel.Unavailable -> WifiIcon.Hidden
            is WifiNetworkModel.Invalid -> WifiIcon.Hidden
            is WifiNetworkModel.CarrierMerged -> WifiIcon.Hidden
            is WifiNetworkModel.Inactive ->
                WifiIcon.Visible(
                    res = WIFI_NO_NETWORK,
                    ContentDescription.Loaded(
                        "${context.getString(WIFI_NO_CONNECTION)},${context.getString(NO_INTERNET)}"
                    )
                )
            // 可⽤情况下,需要额外增加miui图⽚选择的逻辑
            is WifiNetworkModel.Active -> {
                val levelDesc = context.getString(WIFI_CONNECTION_STRENGTH[this.level])
                when {
                    this.isValidated ->
                        WifiIcon.Visible(
                            WIFI_FULL_ICONS[this.level],
                            ContentDescription.Loaded(levelDesc),
                        )
                    else ->
                        WifiIcon.Visible(
                            WIFI_NO_INTERNET_ICONS[this.level],
                            ContentDescription.Loaded(
                                "$levelDesc,${context.getString(NO_INTERNET)}"
                            ),
                        )
                }
            }
        }
    }

LocationBasedWifiViewModel.kt
WifiViewModel是单例,不能直接使⽤来操作view显⽰,需通过LocationBasedWifiViewModel中的三个⼦类,来操作不同情况下的view:

HomeWifiViewModel
KeyguardWifiViewModel
QsWifiViewModel

⽬前看到的区别是打出的log、debug下的tint不同

5 WifiUiAdapter.kt

单例;连接旧版UI和新pipeline数据的adapter类;
⽬前使⽤pipeline时,也需要通过iconManager将icon加⼊iconGroup;
注释标明随着后续pipeline逐渐完善,会优化这⾥

	fun bindGroup(
        statusBarIconGroup: ViewGroup,
        location: StatusBarLocation,
    ): LocationBasedWifiViewModel {
        val locationViewModel =
            viewModelForLocation(wifiViewModel, statusBarPipelineFlags, location)

        statusBarIconGroup.repeatWhenAttached {
            repeatOnLifecycle(Lifecycle.State.STARTED) {
                launch {
                    locationViewModel.wifiIcon.collect { wifiIcon ->
                        // Only notify the icon controller if we want to *render* the new icon.
                        // Note that this flow may still run if
                        // [statusBarPipelineFlags.runNewWifiIconBackend] is true because we may
                        // want to get the logging data without rendering.
                        if (
                            wifiIcon is WifiIcon.Visible && statusBarPipelineFlags.useNewWifiIcon()
                        ) {
                            iconController.setNewWifiIcon()
                        }
                    }
                }
            }
        }

        return locationViewModel
    }

Shared

提供Mobile和Wifi使⽤的公共部分;提供CollapsedStatusBarFragment相关的控制类

pipeline-shared

1 data

1.1 model

ConnectivitySlots.kt.

1 airplaneSlot
2 mobileSlot
3 wifiSlot
4 ethernetSlot

DataActivityModel.kt 存放上下⾏数据
DefaultConnectionModel.kt

1.2 repository

ConnectivityRepository.kt

forceHiddenSlots :是否强制隐藏slots;当前pipeline中的icon,都有isForceHidden这个变量,信号、Wifi、⻜⾏模式
defaultConnections:default连接对应WifiStatusTracker中的mDefaultNetworkCallback
vcnSubId :TODO 没找到好的解释。。使⽤上在MobileIconsInteractor.filteredSubscriptions
			carrierConfigTracker.alwaysShowPrimarySignalBarInOpportunisticNetworkDefault

2 ui

2.1 binder

CollapsedStatusBarViewBinder.kt

# CollapsedStatusBarFragment.onViewCreated

// 此处进⾏bind
mCollapsedStatusBarViewBinder.bind(
                mStatusBar, mCollapsedStatusBarViewModel, mStatusBarVisibilityChangeListener);

# CollapsedStatusBarViewBinderImpl

// 为viewmodel中的两个变量增加回调
override fun bind(
        view: View,
        viewModel: CollapsedStatusBarViewModel,
        listener: StatusBarVisibilityChangeListener,
    ) {
        view.repeatWhenAttached {
            repeatOnLifecycle(Lifecycle.State.CREATED) {
                launch {
                    viewModel.isTransitioningFromLockscreenToOccluded.collect {
                        listener.onStatusBarVisibilityMaybeChanged()
                    }
                }

                launch {
                    viewModel.transitionFromLockscreenToDreamStartedEvent.collect {
                        listener.onTransitionFromLockscreenToDreamStarted()
                    }
                }
            }
        }
    }

# CollapsedStatusBarFragment

// listener具体实现的位置
private StatusBarVisibilityChangeListener mStatusBarVisibilityChangeListener =
            new StatusBarVisibilityChangeListener() {
                @Override
                public void onStatusBarVisibilityMaybeChanged() {
                	// 触发状态栏visibility的计算
                    updateStatusBarVisibilities(/* animate= */ true);
                }

                @Override
                public void onTransitionFromLockscreenToDreamStarted() {
                	// 该变量⽤于shouldHideStatusBar()中的判断
                    mTransitionFromLockscreenToDreamStarted = true;
                }
            };

ModernStatusBarViewBinding.kt 为2.2 ModernStatusBarView声明必须实现的接⼝

2.2 view

ModernStatusBarView.kt 新版的mobile和wifi icon的⽗类,提供⼀些公共⽅法

2.3 viewmodel

CollapsedStatusBarViewModel.kt 根据设备状态,控制CollapsedStatusBarFragment的visibility
但是⽬前逻辑没有完全迁过来,当前类中只有两个变量:

1 isTransitioningFromLockscreenToOccluded :如果设备当前正在从锁定屏幕转换为遮挡屏幕
2 transitionFromLockscreenToDreamStartedEvent:每当从锁屏到屏保的转换开始时发出

PS:DreamManager:https://blog.51cto.com/u_16213432/9289886
这两个变量控制的是:

# CollapsedStatusBarFragment.shouldHideStatusBar()

// While the status bar is transitioning from lockscreen to an occluded, we don't yet know
// if the occluding activity is fullscreen or not. If it *is* fullscreen, we don't want to
// briefly show the status bar just to immediately hide it again. So, we wait for the
// transition to occluding to finish before allowing us to potentially show the status bar
// again. (This status bar is always hidden on keyguard, so it's safe to continue hiding it
 // during this transition.) See b/273314977.
if (mCollapsedStatusBarViewModel.isTransitioningFromLockscreenToOccluded().getValue()) {
    return true;
}

# transitionFromLockscreenToDreamStartedEvent⻅2.1 CollapsedStatusBarViewBinder

3 others

ConnectivityConstants.kt

1 hasDataCapabilities      :telephonyManager.isDataCapable
2 shouldShowActivityConfig :R.bool.config_showActivity

ConnectivityInputLogger.kt log
LoggerHelper.kt log


写在后面

如果文章中有错误的地方,希望各位大佬们批评指正~

If you like this article, it is written by Johnny Deng.
If not, I don’t know who wrote it.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/461111.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Java获取视频封面图,利用FFmpegFrameGrabber获取视频封面图

依赖 <dependency><groupId>org.bytedeco</groupId><artifactId>javacv-platform</artifactId><version>1.5.9</version></dependency>传入视频流获取图片byte /*** 获取视频截图** param frameNumber 视频的指定帧数* param …

Ubuntu查看ros版本-linux查看ros版本

使用ros带的rosversion命令即可查看自己的ros版本&#xff1a; rosversion -d

双指针算法_复写零

题目&#xff1a; 给一个固定长度的数组arr&#xff0c;将数组中出现的每一个0都复写一遍&#xff0c;并且将其余元素都往右移动 且不要再超过数组长度的位置写入元素&#xff0c;在数组上直接修改 示例&#xff1a; 双数组模拟操作&#xff1a; 从示例来看&#xff0c;因为…

Linux 中搭建 主从dns域名解析服务器

CSDN 成就一亿技术人&#xff01; 作者主页&#xff1a;点击&#xff01; Linux专栏&#xff1a;点击&#xff01; CSDN 成就一亿技术人&#xff01; ————前言———— 主从&#xff08;Master-Slave&#xff09;DNS架构是一种用于提高DNS系统可靠性和性能的配置方式。…

视频素材在哪里找?5个无版权视频素材网站

今天我再给大家介绍几个视频素材在哪里找&#xff0c;希望能帮你的短视频创作更加顺手&#xff1a; 蛙学网&#xff1a; 蛙学网是国内的一个视频素材平台&#xff0c;适合做短视频的朋友。这里的素材非常多&#xff0c;涵盖了各种风格和主题。更新速度也很快&#xff0c;能够帮…

Java多线程实战-异步操作日志记录解决方案(AOP+注解+多线程)

&#x1f3f7;️个人主页&#xff1a;牵着猫散步的鼠鼠 &#x1f3f7;️系列专栏&#xff1a;Java全栈-专栏 &#x1f3f7;️本系列源码仓库&#xff1a;多线程并发编程学习的多个代码片段(github) &#x1f3f7;️个人学习笔记&#xff0c;若有缺误&#xff0c;欢迎评论区指正…

Python笔记|字符串的转义

重新梳理一遍python的基础知识 除了数字&#xff0c;Python 还可以操作字符串。字符串有多种表现形式&#xff0c;用单引号&#xff08;……&#xff09;或双引号&#xff08;"……"&#xff09;标注的结果相同 。反斜杠 \ 用于转义&#xff1a; >>>spam e…

QT网络编程之实现TCP客户端和服务端

推荐一个不错的人工智能学习网站&#xff0c;通俗易懂&#xff0c;内容全面&#xff0c;作为入门科普和学习提升都不错&#xff0c;分享一下给大家&#xff1a;前言https://www.captainbed.cn/ai 一.QT5.12实现TCP客户端和服务端功能 1.QT中实现TCP通信主要用到了以下类&…

weblogic CVE-2023-21839详细复现

1、本次复现使用vulhub的靶场 切换到靶场的目录下&#xff0c;用docker -compose up -d启动靶场 使用docker-compose ps -a查看靶场的端口 2、访问开启的环境 3、准备工作都做好之后开始复现 &#xff08;1&#xff09;开启JNDIExploit 工具地址&#xff1a;GitHub - WhiteH…

拌合楼内部管理系统开发(一)立个flag,开始做准备

前言&#xff1a;项目背景情况介绍 公司有意开发一套适合拌合楼的内部管理系统给到客户使用&#xff0c;接触过一家拌合楼行业内号称标杆的企业&#xff0c;去过参观学习的都觉得他们软件好用&#xff0c;但是从软件开发角度看&#xff0c;就是crud钉钉机器人无人值守。虽然公司…

开源绘图工具 PlantUML 入门教程(常用于画类图、用例图、时序图等)

文章目录 一、类图二、用例图三、时序图 一、类图 类的UML图示 startuml skinparam classAttributeIconSize 0 class Dummy {-field1 : String#field2 : int~method1() : Stringmethod2() : void } enduml定义能见度&#xff08;可访问性&#xff09; startumlclass Dummy {-f…

基于ssm+layui的图书管理系统

基于ssmlayui的图书管理系统 账户类型分为&#xff1a;管理员&#xff0c;用户管理员私有功能用户私有功能公共功能技术栈功能实现图 视频演示 账户类型分为&#xff1a;管理员&#xff0c;用户 图书管理系统主要登录账户类型为管理员账户与用户账户 管理员私有功能 账户管理…

如何压缩图片文件大小?教大家几种方法

当图片文件较大时&#xff0c;图片压缩可以有效的缩小图片kb&#xff0c;从而使图片储存起来更加方便&#xff0c;也可以解决上传时图片大小被限制的问题&#xff0c;那么我们有什么方法可以简单快速的将图片大小压缩呢&#xff1f;下面就来给大家分享几个如何修改照片大小kb的…

VS2022开发上位机流程

1、生成串口调试助手的主要控件 2、生成串口对象 3、书写代码 3.1 串口的选择 跳转到图形化界面&#xff0c;然后双击空白位置&#xff0c;会自动生成From1_Load,此函数的作用是会更新串口的选择&#xff0c;然后加入代码&#xff0c;combox控件就可以识别串口 /* 新增自定义…

windows系统版本是win11 运行程序显示windows版本是win10,

在Windows 11系统中运行程序时显示的Windows版本是Windows 10&#xff0c;这种现象可能是由以下几个原因导致的&#xff1a; 程序兼容性问题&#xff1a; 某些程序可能尚未更新以识别Windows 11操作系统&#xff0c;因此它们仍然报告系统为Windows 10。程序读取的是遗留的系统信…

机器学习-04-分类算法-02贝叶斯算法

总结 本系列是机器学习课程的系列课程&#xff0c;主要介绍机器学习中分类算法&#xff0c;本篇为分类算法与贝叶斯算法部分。 本门课程的目标 完成一个特定行业的算法应用全过程&#xff1a; 懂业务会选择合适的算法数据处理算法训练算法调优算法融合 算法评估持续调优工程…

Linux服务器(RedHat、CentOS系)安全相关巡检shell脚本

提示&#xff1a;巡检脚本可以使用crontab定时执行&#xff0c;人工根据执行结束时间点统一收集报告文件即可。 #!/bin/bash# Define output file current_date$(date "%Y%m%d") # Gets the current date in YYYYMMDD format echo >server_security_inspection_r…

【C++ RB树】

文章目录 红黑树红黑树的概念红黑树的性质红黑树节点的定义红黑树的插入代码实现总结 红黑树 AVL树是一颗绝对平衡的二叉搜索树&#xff0c;要求每个节点的左右高度差的绝对值不超过1&#xff0c;这样保证查询时的高效时间复杂度O( l o g 2 N ) log_2 N) log2​N)&#xff0c;…

openwrt下部署clouddrive2

在启动项上增加启动参数 在exit 0前面增加 mount --make-shared /mnt/data480g注意&#xff0c;后面的/mnt/data480g要替换成你设置的共享映射券。 拉取镜像 docker pull cloudnas/clouddrive2启动镜像 一定要用ssh在后台用docker run命令启动&#xff0c;因为openwrt前台…

Windows 安装配置 RabbitMQ 详解

目录 1、安装前准备2、安装Erlang2.1 安装2.2 配置环境变量 3、安装RabbitMQ3.1 安装3.2 配置环境变量3.3 安装rabbitmq_management插件3.4 启动RabbitMQ服务 4、常用命令 本文将详说如何在Windows系统中安装RabbitMQ。 1、安装前准备 因为RabbitMQ服务器是用Erlang语言编写的…