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

Commit 77387ee5 authored by Evan Laird's avatar Evan Laird
Browse files

[Satellite] Input logging for the repository layer

Test: adb shell cmd statusbar echo -b DeviceBasedSatelliteInputLog:V
Test: after above command, grep for "DeviceBasedSatelliteRepo"
Bug: 311417356
Flag: ACONFIG com.android.internal.telephony.flags.oem_enabled_satellite_flag DEVELOPMENT
Change-Id: Iaf3ad31471793d3685f35d7f45e967601ac2ea26
parent 2842aca6
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.dagger

import com.android.systemui.statusbar.pipeline.satellite.data.DeviceBasedSatelliteRepository
import javax.inject.Qualifier

/** Detailed [DeviceBasedSatelliteRepository] logs */
@Qualifier
@MustBeDocumented
@kotlin.annotation.Retention(AnnotationRetention.RUNTIME)
annotation class OemSatelliteInputLog
+7 −0
Original line number Diff line number Diff line
@@ -265,6 +265,13 @@ abstract class StatusBarPipelineModule {
            return factory.create("VerboseMobileViewLog", 100)
        }

        @Provides
        @SysUISingleton
        @OemSatelliteInputLog
        fun provideOemSatelliteInputLog(factory: LogBufferFactory): LogBuffer {
            return factory.create("DeviceBasedSatelliteInputLog", 32)
        }

        const val FIRST_MOBILE_SUB_SHOWING_NETWORK_TYPE_ICON =
            "FirstMobileSubShowingNetworkTypeIcon"
    }
+47 −3
Original line number Diff line number Diff line
@@ -25,6 +25,11 @@ import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCall
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.core.LogLevel
import com.android.systemui.log.core.MessageInitializer
import com.android.systemui.log.core.MessagePrinter
import com.android.systemui.statusbar.pipeline.dagger.OemSatelliteInputLog
import com.android.systemui.statusbar.pipeline.satellite.data.DeviceBasedSatelliteRepository
import com.android.systemui.statusbar.pipeline.satellite.data.prod.SatelliteSupport.Companion.whenSupported
import com.android.systemui.statusbar.pipeline.satellite.data.prod.SatelliteSupport.NotSupported
@@ -124,6 +129,7 @@ constructor(
    satelliteManagerOpt: Optional<SatelliteManager>,
    @Background private val bgDispatcher: CoroutineDispatcher,
    @Application private val scope: CoroutineScope,
    @OemSatelliteInputLog private val logBuffer: LogBuffer,
    private val systemClock: SystemClock,
) : DeviceBasedSatelliteRepository {

@@ -146,6 +152,11 @@ constructor(
                ensureMinUptime(systemClock, MIN_UPTIME)
                satelliteSupport.value = satelliteManager.checkSatelliteSupported()

                logBuffer.i(
                    { str1 = satelliteSupport.value.toString() },
                    { "Checked for system support. support=$str1" },
                )

                // We only need to check location availability if this mode is supported
                if (satelliteSupport.value is Supported) {
                    isSatelliteAllowedForCurrentLocation.subscriptionCount
@@ -160,6 +171,9 @@ constructor(
                                 * connection might cause more frequent checks.
                                 */
                                while (true) {
                                    logBuffer.i {
                                        "requestIsSatelliteCommunicationAllowedForCurrentLocation"
                                    }
                                    checkIsSatelliteAllowed()
                                    delay(POLLING_INTERVAL_MS)
                                }
@@ -168,6 +182,8 @@ constructor(
                }
            }
        } else {
            logBuffer.i { "Satellite manager is null" }

            satelliteSupport.value = NotSupported
        }
    }
@@ -182,6 +198,7 @@ constructor(
    private fun connectionStateFlow(sm: SupportedSatelliteManager): Flow<SatelliteConnectionState> =
        conflatedCallbackFlow {
                val cb = SatelliteModemStateCallback { state ->
                    logBuffer.i({ int1 = state }) { "onSatelliteModemStateChanged: state=$int1" }
                    trySend(SatelliteConnectionState.fromModemState(state))
                }

@@ -192,7 +209,7 @@ constructor(
                        sm.registerForSatelliteModemStateChanged(bgDispatcher.asExecutor(), cb)
                    registered = res == SATELLITE_RESULT_SUCCESS
                } catch (e: Exception) {
                    // Logging is in next commit
                    logBuffer.e("error registering for modem state", e)
                }

                awaitClose { if (registered) sm.unregisterForSatelliteModemStateChanged(cb) }
@@ -206,6 +223,9 @@ constructor(
    private fun signalStrengthFlow(sm: SupportedSatelliteManager) =
        conflatedCallbackFlow {
                val cb = NtnSignalStrengthCallback { signalStrength ->
                    logBuffer.i({ int1 = signalStrength.level }) {
                        "onNtnSignalStrengthChanged: level=$int1"
                    }
                    trySend(signalStrength.level)
                }

@@ -214,7 +234,7 @@ constructor(
                    sm.registerForNtnSignalStrengthChanged(bgDispatcher.asExecutor(), cb)
                    registered = true
                } catch (e: Exception) {
                    // Logging is in next commit
                    logBuffer.e("error registering for signal strength", e)
                }

                awaitClose { if (registered) sm.unregisterForNtnSignalStrengthChanged(cb) }
@@ -228,11 +248,15 @@ constructor(
                bgDispatcher.asExecutor(),
                object : OutcomeReceiver<Boolean, SatelliteManager.SatelliteException> {
                    override fun onError(e: SatelliteManager.SatelliteException) {
                        android.util.Log.e(TAG, "Found exception when checking for satellite: ", e)
                        logBuffer.e(
                            "Found exception when checking availability",
                            e,
                        )
                        isSatelliteAllowedForCurrentLocation.value = false
                    }

                    override fun onResult(allowed: Boolean) {
                        logBuffer.i { allowed.toString() }
                        isSatelliteAllowedForCurrentLocation.value = allowed
                    }
                }
@@ -254,6 +278,12 @@ constructor(
                    }

                    override fun onError(error: SatelliteManager.SatelliteException) {
                        logBuffer.e(
                            "Exception when checking for satellite support. " +
                                "Assuming it is not supported for this device.",
                            error,
                        )

                        // Assume that an error means it's not supported
                        continuation.resume(NotSupported)
                    }
@@ -279,5 +309,19 @@ constructor(
                delay(timeTilMinUptime)
            }
        }

        /** A couple of convenience logging methods rather than a whole class */
        private fun LogBuffer.i(
            initializer: MessageInitializer = {},
            printer: MessagePrinter,
        ) = this.log(TAG, LogLevel.INFO, initializer, printer)

        private fun LogBuffer.e(message: String, exception: Throwable? = null) =
            this.log(
                tag = TAG,
                level = LogLevel.ERROR,
                message = message,
                exception = exception,
            )
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.telephony.satellite.SatelliteModemStateCallback
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.log.core.FakeLogBuffer
import com.android.systemui.statusbar.pipeline.satellite.data.prod.DeviceBasedSatelliteRepositoryImpl.Companion.MIN_UPTIME
import com.android.systemui.statusbar.pipeline.satellite.data.prod.DeviceBasedSatelliteRepositoryImpl.Companion.POLLING_INTERVAL_MS
import com.android.systemui.statusbar.pipeline.satellite.shared.model.SatelliteConnectionState
@@ -87,6 +88,7 @@ class DeviceBasedSatelliteRepositoryImplTest : SysuiTestCase() {
                    Optional.empty(),
                    dispatcher,
                    testScope.backgroundScope,
                    FakeLogBuffer.Factory.create(),
                    systemClock,
                )

@@ -396,6 +398,7 @@ class DeviceBasedSatelliteRepositoryImplTest : SysuiTestCase() {
                if (satMan != null) Optional.of(satMan) else Optional.empty(),
                dispatcher,
                testScope.backgroundScope,
                FakeLogBuffer.Factory.create(),
                systemClock,
            )
    }