Loading wifi/java/android/net/wifi/IWifiManager.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -102,7 +102,7 @@ interface IWifiManager int getWifiEnabledState(); void setCountryCode(String country, boolean persist); void setCountryCode(String country); String getCountryCode(); Loading wifi/java/android/net/wifi/WifiManager.java +3 −3 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.net.wifi; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.RequiresPermission; import android.annotation.SdkConstant; Loading Loading @@ -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(); } Loading wifi/tests/src/android/net/wifi/WifiManagerTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } } Loading
wifi/java/android/net/wifi/IWifiManager.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -102,7 +102,7 @@ interface IWifiManager int getWifiEnabledState(); void setCountryCode(String country, boolean persist); void setCountryCode(String country); String getCountryCode(); Loading
wifi/java/android/net/wifi/WifiManager.java +3 −3 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.net.wifi; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.RequiresPermission; import android.annotation.SdkConstant; Loading Loading @@ -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(); } Loading
wifi/tests/src/android/net/wifi/WifiManagerTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } }