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

Commit 17bb521c authored by Fabian Kozynski's avatar Fabian Kozynski
Browse files

Add resource for support of hotspot

Test: atest HotspotControllerImplTest
Test: manual
Fixes: 253149153

Change-Id: I63847f051daa78a05b5f255689a8cf877c185858
parent 268f0020
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -771,4 +771,8 @@
        <item>@color/dream_overlay_aqi_very_unhealthy</item>
        <item>@color/dream_overlay_aqi_very_unhealthy</item>
        <item>@color/dream_overlay_aqi_hazardous</item>
        <item>@color/dream_overlay_aqi_hazardous</item>
    </integer-array>
    </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>
</resources>
+13 −5
Original line number Original line Diff line number Diff line
@@ -33,6 +33,7 @@ import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.NonNull;


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


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


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


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


package com.android.systemui.statusbar.policy;
package com.android.systemui.statusbar.policy;


import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
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.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.when;


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


import androidx.test.filters.SmallTest;
import androidx.test.filters.SmallTest;


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


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


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

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


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


        verify(mCallback1).onHotspotAvailabilityChanged(false);
        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());
    }
}
}