Skip to content

Commit

Permalink
wifi: Add new API to notify wificond of CC have changed
Browse files Browse the repository at this point in the history
When device doesn't support NL80211_CMD_REG_CHANGED, the wificond has no
way to know the CC(country code) have changed. Add a new API to allow
the wifi frameworks notify wificond daemon of country code have changed.

Bug: 211573255
Bug: 212554181
Bug: 207426796
Test: atest WifiNl80211ManagerTest
Test: Maunal Test with log check.
Change-Id: I1e2c980062e66e6dcf007c0e2a4f1e9b203536ac
  • Loading branch information
Les Lee committed Jan 24, 2022
1 parent 8d6f835 commit 1a8877f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/api/system-current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8819,6 +8819,7 @@ package android.net.wifi.nl80211 {
method @Nullable public android.net.wifi.nl80211.DeviceWiphyCapabilities getDeviceWiphyCapabilities(@NonNull String);
method @NonNull public java.util.List<android.net.wifi.nl80211.NativeScanResult> getScanResults(@NonNull String, int);
method @Nullable public android.net.wifi.nl80211.WifiNl80211Manager.TxPacketCounters getTxPacketCounters(@NonNull String);
method public boolean notifyCountryCodeChanged();
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);
Expand Down
20 changes: 20 additions & 0 deletions wifi/java/src/android/net/wifi/nl80211/WifiNl80211Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,26 @@ public void unregisterCountryCodeChangedListener(@NonNull CountryCodeChangedList
mWificondEventHandler.unregisterCountryCodeChangedListener(listener);
}

/**
* Notifies the wificond daemon that the WiFi framework has successfully updated the Country
* Code of the driver. The wificond daemon needs this notification if the device does not
* 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.
*/
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");
}
return false;
}

/**
* Register the provided callback handler for SoftAp events. The interface must first be created
* using {@link #setupInterfaceForSoftApMode(String)}. The callback registration is valid until
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,26 @@ public void testGetDeviceWiphyCapabilities() throws Exception {
assertEquals(capaExpected, capaActual);
}

/**
* Tests notifyCountryCodeChanged
*/
@Test
public void testNotifyCountryCodeChanged() throws Exception {
doNothing().when(mWificond).notifyCountryCodeChanged();
assertTrue(mWificondControl.notifyCountryCodeChanged());
verify(mWificond).notifyCountryCodeChanged();
}

/**
* Tests notifyCountryCodeChanged with RemoteException
*/
@Test
public void testNotifyCountryCodeChangedRemoteException() throws Exception {
doThrow(new RemoteException()).when(mWificond).notifyCountryCodeChanged();
assertFalse(mWificondControl.notifyCountryCodeChanged());
verify(mWificond).notifyCountryCodeChanged();
}

// Create a ArgumentMatcher which captures a SingleScanSettings parameter and checks if it
// matches the provided frequency set and ssid set.
private class ScanMatcher implements ArgumentMatcher<SingleScanSettings> {
Expand Down

0 comments on commit 1a8877f

Please sign in to comment.