Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5d668fd0 authored by Evan Laird's avatar Evan Laird Committed by Android (Google) Code Review
Browse files

Merge changes I6843e949,Ied9eea84,Id3ae744f into tm-qpr-dev

* changes:
  [Sb refactor] Rework TelephonyCallback flows
  [Sb refactor] Implement DataEnabledChangedListener
  [Sb refactor] CarrierConfigRepository
parents 561bd764 7eafef30
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@
        <permission name="android.permission.READ_FRAME_BUFFER"/>
        <permission name="android.permission.READ_NETWORK_USAGE_HISTORY"/>
        <permission name="android.permission.READ_PRIVILEGED_PHONE_STATE"/>
        <permission name="android.permission.READ_PRECISE_PHONE_STATE"/>
        <permission name="android.permission.REAL_GET_TASKS"/>
        <permission name="android.permission.REQUEST_NETWORK_SCORES"/>
        <permission name="android.permission.RECEIVE_MEDIA_RESOURCE_USAGE"/>
+1 −0
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" />
    <uses-permission android:name="android.permission.READ_PRECISE_PHONE_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.OVERRIDE_WIFI_CONFIG" />
+6 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import com.android.systemui.statusbar.pipeline.airplane.data.repository.Airplane
import com.android.systemui.statusbar.pipeline.airplane.data.repository.AirplaneModeRepositoryImpl
import com.android.systemui.statusbar.pipeline.airplane.ui.viewmodel.AirplaneModeViewModel
import com.android.systemui.statusbar.pipeline.airplane.ui.viewmodel.AirplaneModeViewModelImpl
import com.android.systemui.statusbar.pipeline.mobile.data.repository.CarrierConfigCoreStartable
import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionsRepository
import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileRepositorySwitcher
import com.android.systemui.statusbar.pipeline.mobile.data.repository.UserSetupRepository
@@ -82,6 +83,11 @@ abstract class StatusBarPipelineModule {
    @ClassKey(MobileUiAdapter::class)
    abstract fun bindFeature(impl: MobileUiAdapter): CoreStartable

    @Binds
    @IntoMap
    @ClassKey(CarrierConfigCoreStartable::class)
    abstract fun bindCarrierConfigStartable(impl: CarrierConfigCoreStartable): CoreStartable

    companion object {
        @Provides
        @SysUISingleton
+108 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar.pipeline.mobile.data.model

import android.os.PersistableBundle
import android.telephony.CarrierConfigManager.KEY_INFLATE_SIGNAL_STRENGTH_BOOL
import android.telephony.CarrierConfigManager.KEY_SHOW_OPERATOR_NAME_IN_STATUSBAR_BOOL
import androidx.annotation.VisibleForTesting
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow

/**
 * Represents, for a given subscription ID, the set of keys about which SystemUI cares.
 *
 * Upon first creation, this config represents only the default configuration (see
 * [android.telephony.CarrierConfigManager.getDefaultConfig]).
 *
 * Upon request (see
 * [com.android.systemui.statusbar.pipeline.mobile.data.repository.CarrierConfigRepository]), an
 * instance of this class may be created for a given subscription Id, and will default to
 * representing the default carrier configuration. However, once a carrier config is received for
 * this [subId], all fields will reflect those in the received config, using [PersistableBundle]'s
 * default of false for any config that is not present in the override.
 *
 * To keep things relatively simple, this class defines a wrapper around each config key which
 * exposes a StateFlow<Boolean> for each config we care about. It also tracks whether or not it is
 * using the default config for logging purposes.
 *
 * NOTE to add new keys to be tracked:
 * 1. Define a new `private val` wrapping the key using [BooleanCarrierConfig]
 * 2. Define a public `val` exposing the wrapped flow using [BooleanCarrierConfig.config]
 * 3. Add the new [BooleanCarrierConfig] to the list of tracked configs, so they are properly
 * updated when a new carrier config comes down
 */
class SystemUiCarrierConfig
internal constructor(
    val subId: Int,
    defaultConfig: PersistableBundle,
) {
    @VisibleForTesting
    var isUsingDefault = true
        private set

    private val inflateSignalStrength =
        BooleanCarrierConfig(KEY_INFLATE_SIGNAL_STRENGTH_BOOL, defaultConfig)
    /** Flow tracking the [KEY_INFLATE_SIGNAL_STRENGTH_BOOL] carrier config */
    val shouldInflateSignalStrength: StateFlow<Boolean> = inflateSignalStrength.config

    private val showOperatorName =
        BooleanCarrierConfig(KEY_SHOW_OPERATOR_NAME_IN_STATUSBAR_BOOL, defaultConfig)
    /** Flow tracking the [KEY_SHOW_OPERATOR_NAME_IN_STATUSBAR_BOOL] config */
    val showOperatorNameInStatusBar: StateFlow<Boolean> = showOperatorName.config

    private val trackedConfigs =
        listOf(
            inflateSignalStrength,
            showOperatorName,
        )

    /** Ingest a new carrier config, and switch all of the tracked keys over to the new values */
    fun processNewCarrierConfig(config: PersistableBundle) {
        isUsingDefault = false
        trackedConfigs.forEach { it.update(config) }
    }

    /** For dumpsys, shortcut if we haven't overridden any keys */
    fun toStringConsideringDefaults(): String {
        return if (isUsingDefault) {
            "using defaults"
        } else {
            trackedConfigs.joinToString { it.toString() }
        }
    }

    override fun toString(): String = trackedConfigs.joinToString { it.toString() }
}

/** Extracts [key] from the carrier config, and stores it in a flow */
private class BooleanCarrierConfig(
    val key: String,
    defaultConfig: PersistableBundle,
) {
    private val _configValue = MutableStateFlow(defaultConfig.getBoolean(key))
    val config = _configValue.asStateFlow()

    fun update(config: PersistableBundle) {
        _configValue.value = config.getBoolean(key)
    }

    override fun toString(): String {
        return "$key=${config.value}"
    }
}
+39 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar.pipeline.mobile.data.repository

import com.android.systemui.CoreStartable
import com.android.systemui.dagger.qualifiers.Application
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

/**
 * Core startable which configures the [CarrierConfigRepository] to listen for updates for the
 * lifetime of the process
 */
class CarrierConfigCoreStartable
@Inject
constructor(
    private val carrierConfigRepository: CarrierConfigRepository,
    @Application private val scope: CoroutineScope,
) : CoreStartable {

    override fun start() {
        scope.launch { carrierConfigRepository.startObservingCarrierConfigUpdates() }
    }
}
Loading