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

Commit 0231ea87 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov Committed by Android (Google) Code Review
Browse files

Merge changes Ib74835e7,Ic077c0b0,I4fb5b8b5 into udc-qpr-dev

* changes:
  [Status Bar] Implement WifiRepository interface using WifiTrackerLib.
  [Status Bar] Move WifiPickerTrackerFactory to top-level class.
  [Status Bar] Move WifiRepositoryImplTest to newer test APIs.
parents 4ba66082 ae068648
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -354,6 +354,10 @@ object Flags {
    // TODO(b/280426085): Tracking Bug
    // TODO(b/280426085): Tracking Bug
    @JvmField val NEW_BLUETOOTH_REPOSITORY = releasedFlag(612, "new_bluetooth_repository")
    @JvmField val NEW_BLUETOOTH_REPOSITORY = releasedFlag(612, "new_bluetooth_repository")


    // TODO(b/292533677): Tracking Bug
    val WIFI_TRACKER_LIB_FOR_WIFI_ICON =
        unreleasedFlag(613, "wifi_tracker_lib_for_wifi_icon")

    // 700 - dialer/calls
    // 700 - dialer/calls
    // TODO(b/254512734): Tracking Bug
    // TODO(b/254512734): Tracking Bug
    val ONGOING_CALL_STATUS_BAR_CHIP = releasedFlag(700, "ongoing_call_status_bar_chip")
    val ONGOING_CALL_STATUS_BAR_CHIP = releasedFlag(700, "ongoing_call_status_bar_chip")
+0 −86
Original line number Original line Diff line number Diff line
@@ -16,13 +16,7 @@


package com.android.systemui.statusbar.connectivity;
package com.android.systemui.statusbar.connectivity;


import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;
import android.os.Handler;
import android.os.SimpleClock;
import android.os.SystemClock;
import android.os.UserHandle;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManager;
import android.provider.Settings;
import android.provider.Settings;
@@ -35,25 +29,18 @@ import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LifecycleRegistry;
import androidx.lifecycle.LifecycleRegistry;


import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.settings.UserTracker;
import com.android.systemui.settings.UserTracker;
import com.android.wifitrackerlib.MergedCarrierEntry;
import com.android.wifitrackerlib.MergedCarrierEntry;
import com.android.wifitrackerlib.WifiEntry;
import com.android.wifitrackerlib.WifiEntry;
import com.android.wifitrackerlib.WifiPickerTracker;
import com.android.wifitrackerlib.WifiPickerTracker;


import java.io.PrintWriter;
import java.io.PrintWriter;
import java.time.Clock;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Arrays;
import java.util.Collections;
import java.util.Collections;
import java.util.List;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.Executor;


import javax.inject.Inject;

/** */
/** */
public class AccessPointControllerImpl implements AccessPointController,
public class AccessPointControllerImpl implements AccessPointController,
        WifiPickerTracker.WifiPickerTrackerCallback,
        WifiPickerTracker.WifiPickerTrackerCallback,
@@ -272,77 +259,4 @@ public class AccessPointControllerImpl implements AccessPointController,
            }
            }
        }
        }
    };
    };

    /**
     * Factory for creating {@link WifiPickerTracker}.
     *
     * Uses the same time intervals as the Settings page for Wifi.
     */
    @SysUISingleton
    public static class WifiPickerTrackerFactory {

        // Max age of tracked WifiEntries
        private static final long MAX_SCAN_AGE_MILLIS = 15_000;
        // Interval between initiating WifiPickerTracker scans
        private static final long SCAN_INTERVAL_MILLIS = 10_000;

        private final Context mContext;
        private final @Nullable WifiManager mWifiManager;
        private final ConnectivityManager mConnectivityManager;
        private final Handler mMainHandler;
        private final Handler mWorkerHandler;
        private final Clock mClock = new SimpleClock(ZoneOffset.UTC) {
            @Override
            public long millis() {
                return SystemClock.elapsedRealtime();
            }
        };

        @Inject
        public WifiPickerTrackerFactory(
                Context context,
                @Nullable WifiManager wifiManager,
                ConnectivityManager connectivityManager,
                @Main Handler mainHandler,
                @Background Handler workerHandler
        ) {
            mContext = context;
            mWifiManager = wifiManager;
            mConnectivityManager = connectivityManager;
            mMainHandler = mainHandler;
            mWorkerHandler = workerHandler;
        }

        private boolean isSupported() {
            return mWifiManager != null;
        }

        /**
         * Create a {@link WifiPickerTracker}
         *
         * @param lifecycle
         * @param listener
         * @return a new {@link WifiPickerTracker} or {@code null} if {@link WifiManager} is null.
         */
        public @Nullable WifiPickerTracker create(
                Lifecycle lifecycle,
                WifiPickerTracker.WifiPickerTrackerCallback listener
        ) {
            if (mWifiManager == null) {
                return null;
            }
            return new WifiPickerTracker(
                    lifecycle,
                    mContext,
                    mWifiManager,
                    mConnectivityManager,
                    mMainHandler,
                    mWorkerHandler,
                    mClock,
                    MAX_SCAN_AGE_MILLIS,
                    SCAN_INTERVAL_MILLIS,
                    listener
            );
        }
    }
}
}
+92 −0
Original line number Original line 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.connectivity

import android.content.Context
import android.net.ConnectivityManager
import android.net.wifi.WifiManager
import android.os.Handler
import android.os.SimpleClock
import androidx.lifecycle.Lifecycle
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.util.time.SystemClock
import com.android.wifitrackerlib.WifiPickerTracker
import com.android.wifitrackerlib.WifiPickerTracker.WifiPickerTrackerCallback
import java.time.Clock
import java.time.ZoneOffset
import javax.inject.Inject

/**
 * Factory for creating [WifiPickerTracker] for SysUI.
 *
 * Uses the same time intervals as the Settings page for Wifi.
 */
@SysUISingleton
class WifiPickerTrackerFactory
@Inject
constructor(
    private val context: Context,
    private val wifiManager: WifiManager?,
    private val connectivityManager: ConnectivityManager,
    private val systemClock: SystemClock,
    @Main private val mainHandler: Handler,
    @Background private val workerHandler: Handler,
) {
    private val clock: Clock =
        object : SimpleClock(ZoneOffset.UTC) {
            override fun millis(): Long {
                return systemClock.elapsedRealtime()
            }
        }
    val isSupported: Boolean
        get() = wifiManager != null

    /**
     * Creates a [WifiPickerTracker] instance.
     *
     * @return a new [WifiPickerTracker] or null if [WifiManager] is null.
     */
    fun create(
        lifecycle: Lifecycle,
        listener: WifiPickerTrackerCallback,
    ): WifiPickerTracker? {
        return if (wifiManager == null) {
            null
        } else
            WifiPickerTracker(
                lifecycle,
                context,
                wifiManager,
                connectivityManager,
                mainHandler,
                workerHandler,
                clock,
                MAX_SCAN_AGE_MILLIS,
                SCAN_INTERVAL_MILLIS,
                listener,
            )
    }

    companion object {
        /** Max age of tracked WifiEntries. */
        private const val MAX_SCAN_AGE_MILLIS: Long = 15000
        /** Interval between initiating WifiPickerTracker scans. */
        private const val SCAN_INTERVAL_MILLIS: Long = 10000
    }
}
+57 −2
Original line number Original line Diff line number Diff line
@@ -19,6 +19,8 @@ package com.android.systemui.statusbar.pipeline.dagger
import android.net.wifi.WifiManager
import android.net.wifi.WifiManager
import com.android.systemui.CoreStartable
import com.android.systemui.CoreStartable
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.flags.FeatureFlags
import com.android.systemui.flags.Flags
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.LogBufferFactory
import com.android.systemui.log.LogBufferFactory
import com.android.systemui.log.table.TableLogBuffer
import com.android.systemui.log.table.TableLogBuffer
@@ -48,9 +50,12 @@ import com.android.systemui.statusbar.pipeline.shared.ui.viewmodel.CollapsedStat
import com.android.systemui.statusbar.pipeline.shared.ui.viewmodel.CollapsedStatusBarViewModelImpl
import com.android.systemui.statusbar.pipeline.shared.ui.viewmodel.CollapsedStatusBarViewModelImpl
import com.android.systemui.statusbar.pipeline.wifi.data.repository.RealWifiRepository
import com.android.systemui.statusbar.pipeline.wifi.data.repository.RealWifiRepository
import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepository
import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepository
import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepositoryDagger
import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepositorySwitcher
import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepositorySwitcher
import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepositoryViaTrackerLibDagger
import com.android.systemui.statusbar.pipeline.wifi.data.repository.prod.DisabledWifiRepository
import com.android.systemui.statusbar.pipeline.wifi.data.repository.prod.DisabledWifiRepository
import com.android.systemui.statusbar.pipeline.wifi.data.repository.prod.WifiRepositoryImpl
import com.android.systemui.statusbar.pipeline.wifi.data.repository.prod.WifiRepositoryImpl
import com.android.systemui.statusbar.pipeline.wifi.data.repository.prod.WifiRepositoryViaTrackerLib
import com.android.systemui.statusbar.pipeline.wifi.domain.interactor.WifiInteractor
import com.android.systemui.statusbar.pipeline.wifi.domain.interactor.WifiInteractor
import com.android.systemui.statusbar.pipeline.wifi.domain.interactor.WifiInteractorImpl
import com.android.systemui.statusbar.pipeline.wifi.domain.interactor.WifiInteractorImpl
import dagger.Binds
import dagger.Binds
@@ -114,14 +119,19 @@ abstract class StatusBarPipelineModule {
        impl: CollapsedStatusBarViewBinderImpl
        impl: CollapsedStatusBarViewBinderImpl
    ): CollapsedStatusBarViewBinder
    ): CollapsedStatusBarViewBinder


    @Binds
    @IntoMap
    @ClassKey(WifiRepositoryDagger::class)
    abstract fun bindWifiRepositoryDagger(impl: WifiRepositoryDagger): CoreStartable

    companion object {
    companion object {
        @Provides
        @Provides
        @SysUISingleton
        @SysUISingleton
        fun provideRealWifiRepository(
        fun provideWifiRepositoryDagger(
            wifiManager: WifiManager?,
            wifiManager: WifiManager?,
            disabledWifiRepository: DisabledWifiRepository,
            disabledWifiRepository: DisabledWifiRepository,
            wifiRepositoryImplFactory: WifiRepositoryImpl.Factory,
            wifiRepositoryImplFactory: WifiRepositoryImpl.Factory,
        ): RealWifiRepository {
        ): WifiRepositoryDagger {
            // If we have a null [WifiManager], then the wifi repository should be permanently
            // If we have a null [WifiManager], then the wifi repository should be permanently
            // disabled.
            // disabled.
            return if (wifiManager == null) {
            return if (wifiManager == null) {
@@ -131,6 +141,36 @@ abstract class StatusBarPipelineModule {
            }
            }
        }
        }


        @Provides
        @SysUISingleton
        fun provideWifiRepositoryViaTrackerLibDagger(
            wifiManager: WifiManager?,
            disabledWifiRepository: DisabledWifiRepository,
            wifiRepositoryFromTrackerLibFactory: WifiRepositoryViaTrackerLib.Factory,
        ): WifiRepositoryViaTrackerLibDagger {
            // If we have a null [WifiManager], then the wifi repository should be permanently
            // disabled.
            return if (wifiManager == null) {
                disabledWifiRepository
            } else {
                wifiRepositoryFromTrackerLibFactory.create(wifiManager)
            }
        }

        @Provides
        @SysUISingleton
        fun provideRealWifiRepository(
            wifiRepository: WifiRepositoryDagger,
            wifiRepositoryFromTrackerLib: WifiRepositoryViaTrackerLibDagger,
            flags: FeatureFlags,
        ): RealWifiRepository {
            return if (flags.isEnabled(Flags.WIFI_TRACKER_LIB_FOR_WIFI_ICON)) {
                wifiRepositoryFromTrackerLib
            } else {
                wifiRepository
            }
        }

        @Provides
        @Provides
        @SysUISingleton
        @SysUISingleton
        @Named(FIRST_MOBILE_SUB_SHOWING_NETWORK_TYPE_ICON)
        @Named(FIRST_MOBILE_SUB_SHOWING_NETWORK_TYPE_ICON)
@@ -149,6 +189,14 @@ abstract class StatusBarPipelineModule {
            return factory.create("WifiInputLog", 50)
            return factory.create("WifiInputLog", 50)
        }
        }


        @Provides
        @SysUISingleton
        @WifiTrackerLibInputLog
        fun provideWifiTrackerLibInputLogBuffer(factory: LogBufferFactory): LogBuffer {
            // WifiTrackerLib is pretty noisy, so give it more room than WifiInputLog.
            return factory.create("WifiTrackerLibInputLog", 200)
        }

        @Provides
        @Provides
        @SysUISingleton
        @SysUISingleton
        @WifiTableLog
        @WifiTableLog
@@ -156,6 +204,13 @@ abstract class StatusBarPipelineModule {
            return factory.create("WifiTableLog", 100)
            return factory.create("WifiTableLog", 100)
        }
        }


        @Provides
        @SysUISingleton
        @WifiTrackerLibTableLog
        fun provideWifiTrackerLibTableLogBuffer(factory: TableLogBufferFactory): TableLogBuffer {
            return factory.create("WifiTrackerLibTableLog", 100)
        }

        @Provides
        @Provides
        @SysUISingleton
        @SysUISingleton
        @AirplaneTableLog
        @AirplaneTableLog
+25 −0
Original line number Original line 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.dagger

import javax.inject.Qualifier

/** Wifi logs for inputs into [WifiRepositoryViaTrackerLib]. */
@Qualifier
@MustBeDocumented
@kotlin.annotation.Retention(AnnotationRetention.RUNTIME)
annotation class WifiTrackerLibInputLog
Loading