diff options
author | 2024-10-16 15:14:42 -0700 | |
---|---|---|
committer | 2024-11-13 10:40:04 -0800 | |
commit | a96cf8028ef0ea65a7d6d15acb0e67d79efafdc3 (patch) | |
tree | 251d2ab5a0fc2c3ee203770b2899ab730ef484a1 | |
parent | 3a09109674624ec009b6a04bcf17d960791061ee (diff) |
Add Thread device roles into WiFi Scorer stats
Similar to bluetooth, Thread is also running on 2.4GHz and could
possibly have interference on WiFi.
Flag: com.android.wifi.flags.wifi_scorer_new_stats_collection
Bug: 373943903
Test: Atest and on device test with ot-ctl commands
Change-Id: I93f62dbdf0ee8327dd971e30f0e39b3a56200b0e
7 files changed, 82 insertions, 8 deletions
diff --git a/framework/java/android/net/wifi/WifiUsabilityStatsEntry.java b/framework/java/android/net/wifi/WifiUsabilityStatsEntry.java index 9a9f16abd0..ec9f4ad41c 100644 --- a/framework/java/android/net/wifi/WifiUsabilityStatsEntry.java +++ b/framework/java/android/net/wifi/WifiUsabilityStatsEntry.java @@ -183,6 +183,8 @@ public final class WifiUsabilityStatsEntry implements Parcelable { private final int mMaxSupportedRxLinkSpeed; /** WiFi Voip mode state */ private final int mVoipMode; + /** Thread device role */ + private final int mThreadDeviceRole; /** {@hide} */ @Retention(RetentionPolicy.SOURCE) @@ -1190,7 +1192,7 @@ public final class WifiUsabilityStatsEntry implements Parcelable { int isThroughputPredictorDownstreamSufficient, int isThroughputPredictorUpstreamSufficient, boolean isBluetoothConnected, int uwbAdapterState, boolean isLowLatencyActivated, int maxSupportedTxLinkSpeed, - int maxSupportedRxLinkSpeed, int voipMode) { + int maxSupportedRxLinkSpeed, int voipMode, int threadDeviceRole) { mTimeStampMillis = timeStampMillis; mRssi = rssi; mLinkSpeedMbps = linkSpeedMbps; @@ -1243,6 +1245,7 @@ public final class WifiUsabilityStatsEntry implements Parcelable { mMaxSupportedTxLinkSpeed = maxSupportedTxLinkSpeed; mMaxSupportedRxLinkSpeed = maxSupportedRxLinkSpeed; mVoipMode = voipMode; + mThreadDeviceRole = threadDeviceRole; } /** Implement the Parcelable interface */ @@ -1304,6 +1307,7 @@ public final class WifiUsabilityStatsEntry implements Parcelable { dest.writeInt(mMaxSupportedTxLinkSpeed); dest.writeInt(mMaxSupportedRxLinkSpeed); dest.writeInt(mVoipMode); + dest.writeInt(mThreadDeviceRole); } /** Implement the Parcelable interface */ @@ -1328,7 +1332,8 @@ public final class WifiUsabilityStatsEntry implements Parcelable { in.readSparseArray(LinkStats.class.getClassLoader()), in.readInt(), in.readInt(), in.readLong(), in.readLong(), in.readInt(), in.readInt(), in.readInt(), in.readInt(), in.readInt(), in.readInt(), in.readBoolean(), - in.readInt(), in.readBoolean(), in.readInt(), in.readInt(), in.readInt() + in.readInt(), in.readBoolean(), in.readInt(), in.readInt(), in.readInt(), + in.readInt() ); } @@ -2126,4 +2131,9 @@ public final class WifiUsabilityStatsEntry implements Parcelable { public int getVoipMode() { return mVoipMode; } + + /** @hide */ + public int getThreadDeviceRole() { + return mThreadDeviceRole; + } } diff --git a/framework/tests/src/android/net/wifi/WifiManagerTest.java b/framework/tests/src/android/net/wifi/WifiManagerTest.java index eb8a42ba9b..231162f28a 100644 --- a/framework/tests/src/android/net/wifi/WifiManagerTest.java +++ b/framework/tests/src/android/net/wifi/WifiManagerTest.java @@ -2564,7 +2564,7 @@ public class WifiManagerTest { 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 1, 100, 10, 100, 27, contentionTimeStats, rateStats, radioStats, 101, true, true, true, 0, 10, 10, true, linkStats, 1, 0, 10, 20, 1, 2, 1, 1, 1, 1, false, 0, - false, 100, 100, 1)); + false, 100, 100, 1, 3)); verify(mOnWifiUsabilityStatsListener).onWifiUsabilityStats(anyInt(), anyBoolean(), any(WifiUsabilityStatsEntry.class)); } diff --git a/framework/tests/src/android/net/wifi/WifiUsabilityStatsEntryTest.java b/framework/tests/src/android/net/wifi/WifiUsabilityStatsEntryTest.java index d8211978cf..e13efdf1fb 100644 --- a/framework/tests/src/android/net/wifi/WifiUsabilityStatsEntryTest.java +++ b/framework/tests/src/android/net/wifi/WifiUsabilityStatsEntryTest.java @@ -116,7 +116,7 @@ public class WifiUsabilityStatsEntryTest { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 32, contentionTimeStats, rateStats, radioStats, 100, true, true, true, 23, 24, 25, true, linkStats, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, - false, 36, false, 37, 38, 39); + false, 36, false, 37, 38, 39, 40); assertEquals(32, usabilityStatsEntry.getTimeSliceDutyCycleInPercent()); WifiUsabilityStatsEntry usabilityStatsEntryWithInvalidDutyCycleValue = @@ -124,7 +124,7 @@ public class WifiUsabilityStatsEntryTest { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, -1, contentionTimeStats, rateStats, radioStats, 101, true, true, true, 23, 24, 25, true, linkStats, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, - true, 36, true, 37, 38, 39); + true, 36, true, 37, 38, 39, 40); try { usabilityStatsEntryWithInvalidDutyCycleValue.getTimeSliceDutyCycleInPercent(); fail(); @@ -182,7 +182,7 @@ public class WifiUsabilityStatsEntryTest { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 50, contentionTimeStats, rateStats, radioStats, 102, true, true, true, 23, 24, 25, true, linkStats, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, - true, 36, false, 37, 38, 39 + true, 36, false, 37, 38, 39, 40 ); } @@ -673,7 +673,7 @@ public class WifiUsabilityStatsEntryTest { WifiUsabilityStatsEntry usabilityStatsEntry = new WifiUsabilityStatsEntry( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 32, null, null, null, 100, true, true, true, 23, 24, 25, true, linkStats, 26, 27, - 28, 29, 30, 31, 32, 33, 34, 35, true, 36, true, 37, 38, 39); + 28, 29, 30, 31, 32, 33, 34, 35, true, 36, true, 37, 38, 39, 40); assertThrows("linkId is invalid - " + MloLink.INVALID_MLO_LINK_ID, NoSuchElementException.class, diff --git a/service/java/com/android/server/wifi/WifiMetrics.java b/service/java/com/android/server/wifi/WifiMetrics.java index 132790f6aa..fd5e85d86a 100644 --- a/service/java/com/android/server/wifi/WifiMetrics.java +++ b/service/java/com/android/server/wifi/WifiMetrics.java @@ -348,6 +348,7 @@ public class WifiMetrics { private int mLastUwbState = -1; private boolean mIsLowLatencyActivated = false; private int mVoipMode = -1; + private int mLastThreadDeviceRole = -1; /** * Wi-Fi usability state per interface as predicted by the network scorer. @@ -5308,6 +5309,7 @@ public class WifiMetrics { line.append(",max_supported_tx_linkspeed=" + entry.maxSupportedTxLinkspeed); line.append(",max_supported_rx_linkspeed=" + entry.maxSupportedRxLinkspeed); line.append(",voip_mode=" + entry.voipMode); + line.append(",thread_device_role=" + entry.threadDeviceRole); pw.println(line.toString()); } @@ -7404,6 +7406,7 @@ public class WifiMetrics { wifiUsabilityStatsEntry.maxSupportedRxLinkspeed = info.getMaxSupportedRxLinkSpeedMbps(); wifiUsabilityStatsEntry.voipMode = getVoipMode(); + wifiUsabilityStatsEntry.threadDeviceRole = getLastThreadDeviceRole(); } wifiUsabilityStatsEntry.timeStampMs = stats.timeStampInMs; @@ -7959,7 +7962,7 @@ public class WifiMetrics { s.isThroughputPredictorDownstreamSufficient, s.isThroughputPredictorUpstreamSufficient, s.isBluetoothConnected, s.uwbAdapterState, s.isLowLatencyActivated, s.maxSupportedTxLinkspeed, - s.maxSupportedRxLinkspeed, s.voipMode + s.maxSupportedRxLinkspeed, s.voipMode, s.threadDeviceRole ); } @@ -8174,6 +8177,7 @@ public class WifiMetrics { out.maxSupportedTxLinkspeed = s.maxSupportedTxLinkspeed; out.maxSupportedRxLinkspeed = s.maxSupportedRxLinkspeed; out.voipMode = s.voipMode; + out.threadDeviceRole = s.threadDeviceRole; return out; } @@ -10474,4 +10478,12 @@ public class WifiMetrics { public void setVoipMode(int mode) { mVoipMode = mode; } + + public int getLastThreadDeviceRole() { + return mLastThreadDeviceRole; + } + + public void setLastThreadDeviceRole(int deviceRole) { + mLastThreadDeviceRole = deviceRole; + } } diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index bb3b0c95fb..c662eef015 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -100,6 +100,8 @@ import android.net.NetworkStack; import android.net.TetheringManager; import android.net.Uri; import android.net.ip.IpClientUtil; +import android.net.thread.ThreadNetworkController; +import android.net.thread.ThreadNetworkManager; import android.net.wifi.CoexUnsafeChannel; import android.net.wifi.IActionListener; import android.net.wifi.IBooleanListener; @@ -941,6 +943,24 @@ public class WifiServiceImpl extends IWifiManager.Stub { mWifiHandlerThread.getLooper())), new UwbAdapterStateListener()); } } + + if (SdkLevel.isAtLeastV()) { + ThreadNetworkManager threadManager = + mContext.getSystemService(ThreadNetworkManager.class); + if (threadManager != null) { + List<ThreadNetworkController> threadNetworkControllers = + threadManager.getAllThreadNetworkControllers(); + if (threadNetworkControllers.size() > 0) { + ThreadNetworkController threadNetworkController = + threadNetworkControllers.get(0); + if (threadNetworkController != null) { + threadNetworkController.registerStateCallback( + new HandlerExecutor(new Handler(mWifiHandlerThread.getLooper())), + new ThreadStateListener()); + } + } + } + } }, TAG + "#handleBootCompleted"); } @@ -2185,6 +2205,20 @@ public class WifiServiceImpl extends IWifiManager.Stub { } } + @RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM) + class ThreadStateListener implements ThreadNetworkController.StateCallback { + @Override + public void onDeviceRoleChanged(int mDeviceRole) { + if (mVerboseLoggingEnabled) { + Log.d(TAG, "ThreadNetworkController.DeviceRole=" + mDeviceRole); + } + mWifiMetrics.setLastThreadDeviceRole(mDeviceRole); + } + + @Override + public void onPartitionIdChanged(long mPartitionId) {} + } + /** * SoftAp callback */ diff --git a/service/proto/src/metrics.proto b/service/proto/src/metrics.proto index 1637fb7d5c..f4b5b2bb8b 100644 --- a/service/proto/src/metrics.proto +++ b/service/proto/src/metrics.proto @@ -2771,6 +2771,9 @@ message WifiUsabilityStatsEntry { // Wifi Voip mode state optional int32 voip_mode = 61; + + // Device Role of thread. Refers to ThreadNetworkController@DeviceRole + optional int32 thread_device_role = 62; } message ContentionTimeStats { diff --git a/service/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/service/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java index c4cc741f8f..39e29470d0 100644 --- a/service/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java +++ b/service/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -249,6 +249,7 @@ import com.android.modules.utils.StringParceledListSlice; import com.android.modules.utils.build.SdkLevel; import com.android.server.wifi.WifiServiceImpl.LocalOnlyRequestorCallback; import com.android.server.wifi.WifiServiceImpl.SoftApCallbackInternal; +import com.android.server.wifi.WifiServiceImpl.ThreadStateListener; import com.android.server.wifi.WifiServiceImpl.UwbAdapterStateListener; import com.android.server.wifi.b2b.WifiRoamingModeManager; import com.android.server.wifi.coex.CoexManager; @@ -13025,6 +13026,20 @@ public class WifiServiceImplTest extends WifiBaseTest { verify(mWifiMetrics).setLastUwbState(2); } + /** + * Verify ThreadNetworkController.StateCallback onDeviceRoleChanged could update + * mLastThreadDeviceRole in WifiMetrics properly + */ + @Test + public void testServiceImplThreadStateCallback() { + assumeTrue(SdkLevel.isAtLeastV()); + ThreadStateListener threadStateListener = + mWifiServiceImpl.new ThreadStateListener(); + + threadStateListener.onDeviceRoleChanged(3); + verify(mWifiMetrics).setLastThreadDeviceRole(3); + } + @Test public void testSetQueryAllowedWhenWepUsageControllerSupported() { when(mFeatureFlags.wepDisabledInApm()).thenReturn(true); |