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

Commit d8c18690 authored by Fabian Kozynski's avatar Fabian Kozynski Committed by Android (Google) Code Review
Browse files

Merge "Add resource for support of hotspot" into tm-qpr-dev

parents ec9b5b0d 17bb521c
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -783,4 +783,8 @@
        <item>@color/dream_overlay_aqi_very_unhealthy</item>
        <item>@color/dream_overlay_aqi_hazardous</item>
    </integer-array>

    <!-- Whether the device should display hotspot UI. If true, UI will display only when tethering
         is available. If false, UI will never show regardless of tethering availability" -->
    <bool name="config_show_wifi_tethering">true</bool>
</resources>
+13 −5
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.util.Log;
import androidx.annotation.NonNull;

import com.android.internal.util.ConcurrentUtils;
import com.android.systemui.R;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.dagger.qualifiers.Main;
@@ -63,6 +64,7 @@ public class HotspotControllerImpl implements HotspotController, WifiManager.Sof
    private volatile int mNumConnectedDevices;
    // Assume tethering is available until told otherwise
    private volatile boolean mIsTetheringSupported = true;
    private final boolean mIsTetheringSupportedConfig;
    private volatile boolean mHasTetherableWifiRegexs = true;
    private boolean mWaitingForTerminalState;

@@ -100,23 +102,29 @@ public class HotspotControllerImpl implements HotspotController, WifiManager.Sof
        mTetheringManager = context.getSystemService(TetheringManager.class);
        mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        mMainHandler = mainHandler;
        mIsTetheringSupportedConfig = context.getResources()
                .getBoolean(R.bool.config_show_wifi_tethering);
        if (mIsTetheringSupportedConfig) {
            mTetheringManager.registerTetheringEventCallback(
                    new HandlerExecutor(backgroundHandler), mTetheringCallback);
        }
        dumpManager.registerDumpable(getClass().getSimpleName(), this);
    }

    /**
     * Whether hotspot is currently supported.
     *
     * This will return {@code true} immediately on creation of the controller, but may be updated
     * later. Callbacks from this controllers will notify if the state changes.
     * This may return {@code true} immediately on creation of the controller, but may be updated
     * later as capabilities are collected from System Server.
     *
     * Callbacks from this controllers will notify if the state changes.
     *
     * @return {@code true} if hotspot is supported (or we haven't been told it's not)
     * @see #addCallback
     */
    @Override
    public boolean isHotspotSupported() {
        return mIsTetheringSupported && mHasTetherableWifiRegexs
        return mIsTetheringSupportedConfig && mIsTetheringSupported && mHasTetherableWifiRegexs
                && UserManager.get(mContext).isUserAdmin(ActivityManager.getCurrentUser());
    }

+20 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.statusbar.policy;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -25,6 +26,7 @@ import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

import android.net.TetheringManager;
@@ -36,6 +38,7 @@ import android.testing.TestableLooper;

import androidx.test.filters.SmallTest;

import com.android.systemui.R;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.dump.DumpManager;

@@ -96,6 +99,9 @@ public class HotspotControllerImplTest extends SysuiTestCase {
        }).when(mWifiManager).registerSoftApCallback(any(Executor.class),
                any(WifiManager.SoftApCallback.class));

        mContext.getOrCreateTestableResources()
                .addOverride(R.bool.config_show_wifi_tethering, true);

        Handler handler = new Handler(mLooper.getLooper());

        mController = new HotspotControllerImpl(mContext, handler, handler, mDumpManager);
@@ -176,4 +182,18 @@ public class HotspotControllerImplTest extends SysuiTestCase {

        verify(mCallback1).onHotspotAvailabilityChanged(false);
    }

    @Test
    public void testHotspotSupported_resource_false() {
        mContext.getOrCreateTestableResources()
                .addOverride(R.bool.config_show_wifi_tethering, false);

        Handler handler = new Handler(mLooper.getLooper());

        HotspotController controller =
                new HotspotControllerImpl(mContext, handler, handler, mDumpManager);

        verifyNoMoreInteractions(mTetheringManager);
        assertFalse(controller.isHotspotSupported());
    }
}