From 49c0582b47737d4022a24b16b43fd909413d7bb8 Mon Sep 17 00:00:00 2001 From: Les Lee Date: Wed, 9 Feb 2022 15:15:59 +0800 Subject: [PATCH] wifi: refine API: notifyCountryCodeChanged Feedback from API council: 1. Change to return void 2. Rethrow exception instead of logging 3. Consider passing and notifying the new value for country code Bug: 216637965 Test: atest -c WifiNl80211ManagerTest Trst: atest -c FrameworksWifiTests Change-Id: If40f9434e20fd960a65de37c341d8bd6f57ed9d9 --- core/api/system-current.txt | 2 +- .../net/wifi/nl80211/WifiNl80211Manager.java | 21 ++++++++++--------- .../wifi/nl80211/WifiNl80211ManagerTest.java | 6 +++--- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 82539e80474e4..2822737f48335 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -8856,7 +8856,7 @@ package android.net.wifi.nl80211 { method @Nullable public android.net.wifi.nl80211.DeviceWiphyCapabilities getDeviceWiphyCapabilities(@NonNull String); method @NonNull public java.util.List getScanResults(@NonNull String, int); method @Nullable public android.net.wifi.nl80211.WifiNl80211Manager.TxPacketCounters getTxPacketCounters(@NonNull String); - method public boolean notifyCountryCodeChanged(); + method public void notifyCountryCodeChanged(@Nullable String); method @Nullable public static android.net.wifi.nl80211.WifiNl80211Manager.OemSecurityType parseOemSecurityTypeElement(int, int, @NonNull byte[]); method @Deprecated public boolean registerApCallback(@NonNull String, @NonNull java.util.concurrent.Executor, @NonNull android.net.wifi.nl80211.WifiNl80211Manager.SoftApCallback); method public boolean registerCountryCodeChangedListener(@NonNull java.util.concurrent.Executor, @NonNull android.net.wifi.nl80211.WifiNl80211Manager.CountryCodeChangedListener); diff --git a/wifi/java/src/android/net/wifi/nl80211/WifiNl80211Manager.java b/wifi/java/src/android/net/wifi/nl80211/WifiNl80211Manager.java index d3eb8e03c7aad..960447504d150 100644 --- a/wifi/java/src/android/net/wifi/nl80211/WifiNl80211Manager.java +++ b/wifi/java/src/android/net/wifi/nl80211/WifiNl80211Manager.java @@ -1269,18 +1269,19 @@ public class WifiNl80211Manager { * support the NL80211_CMD_REG_CHANGED (otherwise it will find out on its own). The wificond * updates in internal state in response to this Country Code update. * - * @return true on success, false otherwise. + * @param newCountryCode new country code. An ISO-3166-alpha2 country code which is 2-Character + * alphanumeric. */ - public boolean notifyCountryCodeChanged() { - try { - if (mWificond != null) { - mWificond.notifyCountryCodeChanged(); - return true; - } - } catch (RemoteException e1) { - Log.e(TAG, "Failed to notify country code changed due to remote exception"); + public void notifyCountryCodeChanged(@Nullable String newCountryCode) { + if (mWificond == null) { + new RemoteException("Wificond service doesn't exist!").rethrowFromSystemServer(); + } + try { + mWificond.notifyCountryCodeChanged(); + Log.i(TAG, "Receive country code change to " + newCountryCode); + } catch (RemoteException re) { + re.rethrowFromSystemServer(); } - return false; } /** diff --git a/wifi/tests/src/android/net/wifi/nl80211/WifiNl80211ManagerTest.java b/wifi/tests/src/android/net/wifi/nl80211/WifiNl80211ManagerTest.java index 4032a7b0c75cd..a750696628f9d 100644 --- a/wifi/tests/src/android/net/wifi/nl80211/WifiNl80211ManagerTest.java +++ b/wifi/tests/src/android/net/wifi/nl80211/WifiNl80211ManagerTest.java @@ -1143,17 +1143,17 @@ public class WifiNl80211ManagerTest { @Test public void testNotifyCountryCodeChanged() throws Exception { doNothing().when(mWificond).notifyCountryCodeChanged(); - assertTrue(mWificondControl.notifyCountryCodeChanged()); + mWificondControl.notifyCountryCodeChanged(TEST_COUNTRY_CODE); verify(mWificond).notifyCountryCodeChanged(); } /** * Tests notifyCountryCodeChanged with RemoteException */ - @Test + @Test(expected = RuntimeException.class) public void testNotifyCountryCodeChangedRemoteException() throws Exception { doThrow(new RemoteException()).when(mWificond).notifyCountryCodeChanged(); - assertFalse(mWificondControl.notifyCountryCodeChanged()); + mWificondControl.notifyCountryCodeChanged(TEST_COUNTRY_CODE); verify(mWificond).notifyCountryCodeChanged(); }