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

Commit e01f30b6 authored by Roshan Pius's avatar Roshan Pius
Browse files

Sysui/WifiTracker: Changes to support late starting wifi service

Wifi service may not be up when WifiTracker, Sysui is initialized. So,
move some of the wifi operations to later stage in the bootup sequence.

1) Wifi service may not be up when WifiTracker is initialized, use the
underlying wifi verbose logging global setting directly to set the static
verbose logging flag.
2) Use the boot completed broadcast to register wifi traffic state
change callbacks in Sysui.
3) Register for softap callbacks only when sysui is active (not at
bootup).

Bug: 113174748
Test: No sysui crash at bootup with the wifi stack apk
Change-Id: I25182875922ea6acf2b7c0af6460ada311b6827b
Merged-In: I25182875922ea6acf2b7c0af6460ada311b6827b
parent 2161b39d
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -224,7 +224,9 @@ public class WifiTracker implements LifecycleObserver, OnStart, OnStop, OnDestro
        mConnectivityManager = connectivityManager;

        // check if verbose logging developer option has been turned on or off
        sVerboseLogging = mWifiManager != null && (mWifiManager.getVerboseLoggingLevel() > 0);
        sVerboseLogging = Settings.Global.getInt(
                mContext.getContentResolver(),
                Settings.Global.WIFI_VERBOSE_LOGGING_ENABLED, 0) > 0;

        mFilter = filter;

+1 −0
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ public class HotspotTile extends QSTileImpl<BooleanState> {
        if (listening) {
            refreshState();
        }
        mHotspotController.handleSetListening(listening);
    }

    @Override
+2 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import com.android.systemui.Dumpable;
import com.android.systemui.statusbar.policy.HotspotController.Callback;

public interface HotspotController extends CallbackController<Callback>, Dumpable {
    void handleSetListening(boolean listening);

    boolean isHotspotEnabled();
    boolean isHotspotTransient();

+25 −9
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ public class HotspotControllerImpl implements HotspotController, WifiManager.Sof
    private int mHotspotState;
    private int mNumConnectedDevices;
    private boolean mWaitingForTerminalState;
    private boolean mListening;

    /**
     */
@@ -105,14 +106,18 @@ public class HotspotControllerImpl implements HotspotController, WifiManager.Sof
            if (DEBUG) Log.d(TAG, "addCallback " + callback);
            mCallbacks.add(callback);
            if (mWifiManager != null) {
                if (mListening) {
                    if (mCallbacks.size() == 1) {
                        mWifiManager.registerSoftApCallback(this, mMainHandler);
                    } else {
                    // mWifiManager#registerSoftApCallback triggers a call to onNumClientsChanged
                    // on the Main Handler. In order to always update the callback on added, we
                    // make this call when adding callbacks after the first.
                        // mWifiManager#registerSoftApCallback triggers a call to
                        // onNumClientsChanged on the Main Handler. In order to always update the
                        // callback on added, we make this call when adding callbacks after the
                        // first.
                        mMainHandler.post(() ->
                            callback.onHotspotChanged(isHotspotEnabled(), mNumConnectedDevices));
                                callback.onHotspotChanged(isHotspotEnabled(),
                                        mNumConnectedDevices));
                    }
                }
            }
        }
@@ -124,12 +129,23 @@ public class HotspotControllerImpl implements HotspotController, WifiManager.Sof
        if (DEBUG) Log.d(TAG, "removeCallback " + callback);
        synchronized (mCallbacks) {
            mCallbacks.remove(callback);
            if (mCallbacks.isEmpty() && mWifiManager != null) {
            if (mCallbacks.isEmpty() && mWifiManager != null && mListening) {
                mWifiManager.unregisterSoftApCallback(this);
            }
        }
    }

    @Override
    public void handleSetListening(boolean listening) {
        // Wait for the first |handleSetListening(true))| to register softap callbacks (for lazy
        // registration of the softap callbacks).
        if (mListening || !listening) return;
        mListening = true;
        if (mCallbacks.size() >= 1) {
            mWifiManager.registerSoftApCallback(this, mMainHandler);
        }
    }

    @Override
    public boolean isHotspotEnabled() {
        return mHotspotState == WifiManager.WIFI_AP_STATE_ENABLED;
+4 −0
Original line number Diff line number Diff line
@@ -312,6 +312,7 @@ public class NetworkControllerImpl extends BroadcastReceiver
        filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
        filter.addAction(ConnectivityManager.INET_CONDITION_ACTION);
        filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);
        filter.addAction(Intent.ACTION_BOOT_COMPLETED);
        filter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
        mContext.registerReceiver(this, filter, null, mReceiverHandler);
        mListening = true;
@@ -513,6 +514,9 @@ public class NetworkControllerImpl extends BroadcastReceiver
                    recalculateEmergency();
                }
                break;
            case Intent.ACTION_BOOT_COMPLETED:
                mWifiSignalController.handleBootCompleted();
                break;
            case CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED:
                mConfig = Config.readConfig(mContext);
                mReceiverHandler.post(this::handleConfigurationChanged);
Loading