diff options
4 files changed, 64 insertions, 0 deletions
diff --git a/service/java/com/android/server/wifi/WifiMetrics.java b/service/java/com/android/server/wifi/WifiMetrics.java index 1ac361ef3..75d53fc95 100644 --- a/service/java/com/android/server/wifi/WifiMetrics.java +++ b/service/java/com/android/server/wifi/WifiMetrics.java @@ -242,6 +242,7 @@ public class WifiMetrics { private int mLastPollRxLinkSpeed = -1; private int mLastPollFreq = -1; private int mLastScore = -1; + private boolean mAdaptiveConnectivityEnabled = true; /** * Metrics are stored within an instance of the WifiLog proto during runtime, @@ -4908,6 +4909,7 @@ public class WifiMetrics { if (mWifiDataStall != null) { staEvent.isCellularDataAvailable = mWifiDataStall.isCellularDataAvailable(); } + staEvent.isAdaptiveConnectivityEnabled = mAdaptiveConnectivityEnabled; mSupplicantStateChangeBitmask = 0; mLastPollRssi = -127; mLastPollFreq = -1; @@ -5124,6 +5126,7 @@ public class WifiMetrics { if (event.totalRxBytes > 0) sb.append(" totalRxBytes=").append(event.totalRxBytes); sb.append(" screenOn=").append(event.screenOn); sb.append(" cellularData=").append(event.isCellularDataAvailable); + sb.append(" adaptiveConnectivity=").append(event.isAdaptiveConnectivityEnabled); if (event.supplicantStateChangesBitmask != 0) { sb.append(", ").append(supplicantStateChangesBitmaskToString( event.supplicantStateChangesBitmask)); @@ -5343,6 +5346,15 @@ public class WifiMetrics { return result; } + /** + * Converts Adaptive Connectivity state to UserActionEvent type. + * @param value + */ + public static int convertAdaptiveConnectivityStateToUserActionEventType(boolean value) { + return value ? UserActionEvent.EVENT_CONFIGURE_ADAPTIVE_CONNECTIVITY_ON + : UserActionEvent.EVENT_CONFIGURE_ADAPTIVE_CONNECTIVITY_OFF; + } + static class MeteredNetworkStatsBuilder { // A map from network identifier to MeteredDetail Map<String, MeteredDetail> mNetworkMap = new ArrayMap<>(); @@ -6713,4 +6725,13 @@ public class WifiMetrics { mCarrierWifiMetrics.numConnectionNonAuthFailure++; } } + + /** + * Set Adaptive Connectivity state (On/Off) + */ + public void setAdaptiveConnectivityState(boolean adaptiveConnectivityEnabled) { + synchronized (mLock) { + mAdaptiveConnectivityEnabled = adaptiveConnectivityEnabled; + } + } } diff --git a/service/java/com/android/server/wifi/WifiScoreReport.java b/service/java/com/android/server/wifi/WifiScoreReport.java index 381be7f2b..f6eed70ee 100644 --- a/service/java/com/android/server/wifi/WifiScoreReport.java +++ b/service/java/com/android/server/wifi/WifiScoreReport.java @@ -322,6 +322,10 @@ public class WifiScoreReport { super.onChange(selfChange); mAdaptiveConnectivityEnabled = getValue(); Log.d(TAG, "Adaptive connectivity status changed: " + mAdaptiveConnectivityEnabled); + mWifiMetrics.setAdaptiveConnectivityState(mAdaptiveConnectivityEnabled); + mWifiMetrics.logUserActionEvent( + mWifiMetrics.convertAdaptiveConnectivityStateToUserActionEventType( + mAdaptiveConnectivityEnabled)); } /** @@ -335,6 +339,7 @@ public class WifiScoreReport { } mFrameworkFacade.registerContentObserver(mContext, uri, true, this); mAdaptiveConnectivityEnabled = mAdaptiveConnectivityEnabledSettingObserver.getValue(); + mWifiMetrics.setAdaptiveConnectivityState(mAdaptiveConnectivityEnabled); } public boolean getValue() { diff --git a/service/proto/src/metrics.proto b/service/proto/src/metrics.proto index a7f706fb8..1c3b27872 100644 --- a/service/proto/src/metrics.proto +++ b/service/proto/src/metrics.proto @@ -1471,6 +1471,9 @@ message StaEvent { // Whether cellular data network is available optional bool is_cellular_data_available = 25; + + //Whether Adaptive Connectivity is enabled + optional bool is_adaptive_connectivity_enabled = 26; } // Wi-Fi Aware metrics @@ -3158,6 +3161,10 @@ message UserActionEvent { EVENT_CONFIGURE_METERED_STATUS_AUTO = 12; // User adds a new network or updates configurations for an existing network. EVENT_ADD_OR_UPDATE_NETWORK = 13; + // User sets the adaptive connectivity to on + EVENT_CONFIGURE_ADAPTIVE_CONNECTIVITY_ON = 14; + // User sets the adaptive connectivity to off + EVENT_CONFIGURE_ADAPTIVE_CONNECTIVITY_OFF = 15; } // The type of user action diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java index b4cd7592c..b69b30208 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java @@ -2302,6 +2302,7 @@ public class WifiMetricsTest extends WifiBaseTest { mTestLooper.dispatchAll(); wifiMetrics.setScreenState(true); when(mWifiDataStall.isCellularDataAvailable()).thenReturn(true); + wifiMetrics.setAdaptiveConnectivityState(true); for (int i = 0; i < mTestStaLogInts.length; i++) { int[] lia = mTestStaLogInts[i]; wifiMetrics.logStaEvent(lia[0], lia[1], lia[2] == 1 ? mTestWifiConfig : null); @@ -2342,6 +2343,7 @@ public class WifiMetricsTest extends WifiBaseTest { evs[7] == 1 ? mTestWifiConfig : null, event.configInfo); assertEquals(true, event.screenOn); assertEquals(true, event.isCellularDataAvailable); + assertEquals(true, event.isAdaptiveConnectivityEnabled); j++; } assertEquals(mExpectedValues.length, j); @@ -2554,6 +2556,35 @@ public class WifiMetricsTest extends WifiBaseTest { } /** + * Test the logging of UserActionEvent for Adaptive Connectivity toggle + */ + @Test + public void testLogUserActionEventForAdaptiveConnectivity() throws Exception { + long testStartTimeMillis = 123123L; + boolean adaptiveConnectivityEnabled = true; + when(mClock.getElapsedSinceBootMillis()).thenReturn(testStartTimeMillis); + mWifiMetrics.logUserActionEvent( + mWifiMetrics.convertAdaptiveConnectivityStateToUserActionEventType( + adaptiveConnectivityEnabled)); + long testStartTimeMillis2 = 200000L; + boolean adaptiveConnectivityEnabled2 = false; + when(mClock.getElapsedSinceBootMillis()).thenReturn(testStartTimeMillis2); + mWifiMetrics.logUserActionEvent( + mWifiMetrics.convertAdaptiveConnectivityStateToUserActionEventType( + adaptiveConnectivityEnabled2)); + dumpProtoAndDeserialize(); + + WifiMetricsProto.UserActionEvent[] userActionEvents = mDecodedProto.userActionEvents; + assertEquals(2, userActionEvents.length); + assertEquals(WifiMetricsProto.UserActionEvent.EVENT_CONFIGURE_ADAPTIVE_CONNECTIVITY_ON, + userActionEvents[0].eventType); + assertEquals(testStartTimeMillis, userActionEvents[0].startTimeMillis); + assertEquals(WifiMetricsProto.UserActionEvent.EVENT_CONFIGURE_ADAPTIVE_CONNECTIVITY_OFF, + userActionEvents[1].eventType); + assertEquals(testStartTimeMillis2, userActionEvents[1].startTimeMillis); + } + + /** * Verify that the max length of the UserActionEvent list is limited to MAX_USER_ACTION_EVENTS. */ @Test |