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

Commit 4142408e authored by Ningyuan Wang's avatar Ningyuan Wang Committed by Android (Google) Code Review
Browse files

Merge "Remove persist option for WifiManager.setCountryCode()"

parents 8e594131 557875dc
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);
    }
}