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

Commit 557875dc authored by Ningyuan Wang's avatar Ningyuan Wang
Browse files

Remove persist option for WifiManager.setCountryCode()

Bug: 29353903
Test: compile, unit tests
Change-Id: I67e495035c3c47d884f16c190eeb4f708cbb5b2e
parent d3fe8f09
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -102,7 +102,7 @@ interface IWifiManager

    int getWifiEnabledState();

    void setCountryCode(String country, boolean persist);
    void setCountryCode(String country);

    String getCountryCode();

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

package android.net.wifi;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
@@ -1748,13 +1749,12 @@ public class WifiManager {
    /**
     * Set the country code.
     * @param countryCode country code in ISO 3166 format.
     * @param persist {@code true} if this needs to be remembered
     *
     * @hide
     */
    public void setCountryCode(String country, boolean persist) {
    public void setCountryCode(@NonNull String country) {
        try {
            mService.setCountryCode(country, persist);
            mService.setCountryCode(country);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+20 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ public class WifiManagerTest {
    private static final int ERROR_NOT_SET = -1;
    private static final int ERROR_TEST_REASON = 5;
    private static final String TEST_PACKAGE_NAME = "TestPackage";
    private static final String TEST_COUNTRY_CODE = "US";

    @Mock Context mContext;
    @Mock IWifiManager mWifiService;
@@ -777,4 +778,23 @@ public class WifiManagerTest {
        mWifiManager.unregisterLocalOnlyHotspotObserver();
        verify(mWifiService).stopWatchLocalOnlyHotspot();
    }

    /**
     * Verify that calls WifiServiceImpl to set country code when no exception happens.
     */
    @Test
    public void testSetWifiCountryCode() throws Exception {
        mWifiManager.setCountryCode(TEST_COUNTRY_CODE);
        verify(mWifiService).setCountryCode(TEST_COUNTRY_CODE);
    }

    /**
     * Verify that WifiManager.setCountryCode() rethrows exceptions if caller does not
     * have necessary permissions.
     */
    @Test(expected = SecurityException.class)
    public void testSetWifiCountryCodeFailedOnSecurityException() throws Exception {
        doThrow(new SecurityException()).when(mWifiService).setCountryCode(anyString());
        mWifiManager.setCountryCode(TEST_COUNTRY_CODE);
    }
}