summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNate Jiang <qiangjiang@google.com>2020-04-17 11:47:21 -0700
committerNate Jiang <qiangjiang@google.com>2020-04-17 15:17:47 -0700
commit1aa59ac094935325892f10acd7bedad19c3749e4 (patch)
tree16fa73ece73710c040d9e831e809852e0c97d041
parent63da7f604a87743c33f9d0bcf18a87eb5c8e05ec (diff)
Add metrics for WifiNetworkSuggestion Api App usage
Add app count for each type of app with different privilege. Bug: 123362619 Test: atest com.android.server.wifi Change-Id: If6119caa9a5123322e5286a0a44c26c117aef0c0
-rw-r--r--service/java/com/android/server/wifi/WifiMetrics.java36
-rw-r--r--service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java12
-rw-r--r--service/proto/src/metrics.proto21
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java25
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java20
5 files changed, 107 insertions, 7 deletions
diff --git a/service/java/com/android/server/wifi/WifiMetrics.java b/service/java/com/android/server/wifi/WifiMetrics.java
index 031c495cc..e7fbf59ef 100644
--- a/service/java/com/android/server/wifi/WifiMetrics.java
+++ b/service/java/com/android/server/wifi/WifiMetrics.java
@@ -83,6 +83,7 @@ import com.android.server.wifi.proto.nano.WifiMetricsProto.WifiLinkLayerUsageSta
import com.android.server.wifi.proto.nano.WifiMetricsProto.WifiLockStats;
import com.android.server.wifi.proto.nano.WifiMetricsProto.WifiNetworkRequestApiLog;
import com.android.server.wifi.proto.nano.WifiMetricsProto.WifiNetworkSuggestionApiLog;
+import com.android.server.wifi.proto.nano.WifiMetricsProto.WifiNetworkSuggestionApiLog.SuggestionAppCount;
import com.android.server.wifi.proto.nano.WifiMetricsProto.WifiToggleStats;
import com.android.server.wifi.proto.nano.WifiMetricsProto.WifiUsabilityStats;
import com.android.server.wifi.proto.nano.WifiMetricsProto.WifiUsabilityStatsEntry;
@@ -410,6 +411,7 @@ public class WifiMetrics {
{5, 20, 50, 100, 500};
private final IntHistogram mWifiNetworkSuggestionApiListSizeHistogram =
new IntHistogram(NETWORK_SUGGESTION_API_LIST_SIZE_HISTOGRAM_BUCKETS);
+ private final IntCounter mWifiNetworkSuggestionApiAppTypeCounter = new IntCounter();
private final WifiLockStats mWifiLockStats = new WifiLockStats();
private static final int[] WIFI_LOCK_SESSION_DURATION_HISTOGRAM_BUCKETS =
{1, 10, 60, 600, 3600};
@@ -3619,7 +3621,9 @@ public class WifiMetrics {
+ mWifiNetworkRequestApiMatchSizeHistogram);
pw.println("mWifiNetworkSuggestionApiLog:\n" + mWifiNetworkSuggestionApiLog);
pw.println("mWifiNetworkSuggestionApiMatchSizeHistogram:\n"
- + mWifiNetworkRequestApiMatchSizeHistogram);
+ + mWifiNetworkSuggestionApiListSizeHistogram);
+ pw.println("mWifiNetworkSuggestionApiAppTypeCounter:\n"
+ + mWifiNetworkSuggestionApiAppTypeCounter);
pw.println("mNetworkIdToNominatorId:\n" + mNetworkIdToNominatorId);
pw.println("mWifiLockStats:\n" + mWifiLockStats);
pw.println("mWifiLockHighPerfAcqDurationSecHistogram:\n"
@@ -4236,6 +4240,14 @@ public class WifiMetrics {
mWifiNetworkSuggestionApiLog.networkListSizeHistogram =
mWifiNetworkSuggestionApiListSizeHistogram.toProto();
+ mWifiNetworkSuggestionApiLog.appCountPerType =
+ mWifiNetworkSuggestionApiAppTypeCounter.toProto(SuggestionAppCount.class,
+ (key, count) -> {
+ SuggestionAppCount entry = new SuggestionAppCount();
+ entry.appType = key;
+ entry.count = count;
+ return entry;
+ });
mWifiLogProto.wifiNetworkSuggestionApiLog = mWifiNetworkSuggestionApiLog;
mWifiLockStats.highPerfLockAcqDurationSecHistogram =
@@ -4500,6 +4512,7 @@ public class WifiMetrics {
mWifiNetworkSuggestionApiLog.clear();
mWifiNetworkRequestApiMatchSizeHistogram.clear();
mWifiNetworkSuggestionApiListSizeHistogram.clear();
+ mWifiNetworkSuggestionApiAppTypeCounter.clear();
mWifiLockHighPerfAcqDurationSecHistogram.clear();
mWifiLockLowLatencyAcqDurationSecHistogram.clear();
mWifiLockHighPerfActiveSessionDurationSecHistogram.clear();
@@ -5856,6 +5869,27 @@ public class WifiMetrics {
}
}
+ /** Increment number of app add suggestion with different privilege */
+ public void incrementNetworkSuggestionApiUsageNumOfAppInType(int appType) {
+ int typeCode;
+ synchronized (mLock) {
+ switch (appType) {
+ case WifiNetworkSuggestionsManager.APP_TYPE_CARRIER_PRIVILEGED:
+ typeCode = WifiNetworkSuggestionApiLog.TYPE_CARRIER_PRIVILEGED;
+ break;
+ case WifiNetworkSuggestionsManager.APP_TYPE_NETWORK_PROVISIONING:
+ typeCode = WifiNetworkSuggestionApiLog.TYPE_NETWORK_PROVISIONING;
+ break;
+ case WifiNetworkSuggestionsManager.APP_TYPE_NON_PRIVILEGED:
+ typeCode = WifiNetworkSuggestionApiLog.TYPE_NON_PRIVILEGED;
+ break;
+ default:
+ typeCode = WifiNetworkSuggestionApiLog.TYPE_UNKNOWN;
+ }
+ }
+ mWifiNetworkSuggestionApiAppTypeCounter.increment(typeCode);
+ }
+
/**
* Sets the nominator for a network (i.e. which entity made the suggestion to connect)
* @param networkId the ID of the network, from its {@link WifiConfiguration}
diff --git a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java
index 28cf627b5..685df0757 100644
--- a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java
+++ b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java
@@ -105,6 +105,10 @@ public class WifiNetworkSuggestionsManager {
public static final String EXTRA_UID =
"com.android.server.wifi.extra.NetworkSuggestion.UID";
+ public static final int APP_TYPE_CARRIER_PRIVILEGED = 1;
+ public static final int APP_TYPE_NETWORK_PROVISIONING = 2;
+ public static final int APP_TYPE_NON_PRIVILEGED = 3;
+
/**
* Limit number of hidden networks attach to scan
*/
@@ -824,19 +828,27 @@ public class WifiNetworkSuggestionsManager {
if (mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(uid)) {
Log.i(TAG, "Setting the carrier provisioning app approved");
perAppInfo.hasUserApproved = true;
+ mWifiMetrics.incrementNetworkSuggestionApiUsageNumOfAppInType(
+ APP_TYPE_NETWORK_PROVISIONING);
} else if (carrierId != TelephonyManager.UNKNOWN_CARRIER_ID) {
Log.i(TAG, "Setting the carrier privileged app approved");
perAppInfo.carrierId = carrierId;
+ mWifiMetrics.incrementNetworkSuggestionApiUsageNumOfAppInType(
+ APP_TYPE_CARRIER_PRIVILEGED);
} else if (perAppInfo.packageName.equals(activeScorerPackage)) {
Log.i(TAG, "Exempting the active scorer app");
// nothing more to do, user approval related checks are done at network selection
// time (which also takes care of any dynamic changes in active scorer).
+ mWifiMetrics.incrementNetworkSuggestionApiUsageNumOfAppInType(
+ APP_TYPE_NON_PRIVILEGED);
} else {
if (isSuggestionFromForegroundApp(packageName)) {
sendUserApprovalDialog(packageName, uid);
} else {
sendUserApprovalNotification(packageName, uid);
}
+ mWifiMetrics.incrementNetworkSuggestionApiUsageNumOfAppInType(
+ APP_TYPE_NON_PRIVILEGED);
}
}
// If PerAppInfo is upgrade from pre-R, uid may not be set.
diff --git a/service/proto/src/metrics.proto b/service/proto/src/metrics.proto
index d1dd39e49..627c24529 100644
--- a/service/proto/src/metrics.proto
+++ b/service/proto/src/metrics.proto
@@ -2897,6 +2897,24 @@ message WifiNetworkRequestApiLog {
// NetworkSuggestion API metrics.
message WifiNetworkSuggestionApiLog {
+ enum SuggestionAppTypeCode {
+ // UNKNOWN type suggestion app.
+ TYPE_UNKNOWN = 0;
+ // Suggestion app with carrier privilege.
+ TYPE_CARRIER_PRIVILEGED = 1;
+ // Suggestion app with network provisioning permission(NETWORK_CARRIER_PROVISIONING).
+ TYPE_NETWORK_PROVISIONING = 2;
+ // Suggestion app without special privilege.
+ TYPE_NON_PRIVILEGED = 3;
+ }
+
+ message SuggestionAppCount {
+ // Suggestion app type.
+ optional SuggestionAppTypeCode app_type = 1;
+ // Num of app in this type.
+ optional int32 count = 2;
+ }
+
// Number of modifications to their suggestions by apps.
optional int32 num_modification = 1;
@@ -2908,6 +2926,9 @@ message WifiNetworkSuggestionApiLog {
// Histogram for size of the network lists provided by various apps on the device.
repeated HistogramBucketInt32 network_list_size_histogram = 4;
+
+ // Count of app using suggestion API with different privilege.
+ repeated SuggestionAppCount app_count_per_type = 5;
}
// WifiLock metrics
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java
index f03d094cb..464a71b89 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java
@@ -4186,6 +4186,20 @@ public class WifiMetricsTest extends WifiBaseTest {
mWifiMetrics.incrementNetworkSuggestionApiNumConnectFailure();
+ mWifiMetrics.incrementNetworkSuggestionApiUsageNumOfAppInType(
+ WifiNetworkSuggestionsManager.APP_TYPE_NON_PRIVILEGED);
+ mWifiMetrics.incrementNetworkSuggestionApiUsageNumOfAppInType(
+ WifiNetworkSuggestionsManager.APP_TYPE_NON_PRIVILEGED);
+ mWifiMetrics.incrementNetworkSuggestionApiUsageNumOfAppInType(
+ WifiNetworkSuggestionsManager.APP_TYPE_NON_PRIVILEGED);
+ mWifiMetrics.incrementNetworkSuggestionApiUsageNumOfAppInType(
+ WifiNetworkSuggestionsManager.APP_TYPE_CARRIER_PRIVILEGED);
+ mWifiMetrics.incrementNetworkSuggestionApiUsageNumOfAppInType(
+ WifiNetworkSuggestionsManager.APP_TYPE_CARRIER_PRIVILEGED);
+ mWifiMetrics.incrementNetworkSuggestionApiUsageNumOfAppInType(
+ WifiNetworkSuggestionsManager.APP_TYPE_NETWORK_PROVISIONING);
+
+
mWifiMetrics.noteNetworkSuggestionApiListSizeHistogram(new ArrayList<Integer>() {{
add(5);
add(100);
@@ -4214,6 +4228,17 @@ public class WifiMetricsTest extends WifiBaseTest {
};
assertHistogramBucketsEqual(expectedNetworkListSizeHistogram,
mDecodedProto.wifiNetworkSuggestionApiLog.networkListSizeHistogram);
+
+ assertEquals(3, mDecodedProto.wifiNetworkSuggestionApiLog.appCountPerType.length);
+ assertEquals(WifiMetricsProto.WifiNetworkSuggestionApiLog.TYPE_CARRIER_PRIVILEGED,
+ mDecodedProto.wifiNetworkSuggestionApiLog.appCountPerType[0].appType);
+ assertEquals(2, mDecodedProto.wifiNetworkSuggestionApiLog.appCountPerType[0].count);
+ assertEquals(WifiMetricsProto.WifiNetworkSuggestionApiLog.TYPE_NETWORK_PROVISIONING,
+ mDecodedProto.wifiNetworkSuggestionApiLog.appCountPerType[1].appType);
+ assertEquals(1, mDecodedProto.wifiNetworkSuggestionApiLog.appCountPerType[1].count);
+ assertEquals(WifiMetricsProto.WifiNetworkSuggestionApiLog.TYPE_NON_PRIVILEGED,
+ mDecodedProto.wifiNetworkSuggestionApiLog.appCountPerType[2].appType);
+ assertEquals(3, mDecodedProto.wifiNetworkSuggestionApiLog.appCountPerType[2].count);
}
private NetworkSelectionExperimentDecisions findUniqueNetworkSelectionExperimentDecisions(
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
index 7db13a17a..8fa2fa1aa 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
@@ -301,7 +301,9 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
TEST_PACKAGE_2, TEST_FEATURE));
verify(mPasspointManager).addOrUpdateProvider(
passpointConfiguration, TEST_UID_2, TEST_PACKAGE_2, true, true);
-
+ verify(mWifiMetrics, times(2))
+ .incrementNetworkSuggestionApiUsageNumOfAppInType(
+ WifiNetworkSuggestionsManager.APP_TYPE_NON_PRIVILEGED);
Set<WifiNetworkSuggestion> allNetworkSuggestions =
mWifiNetworkSuggestionsManager.getAllNetworkSuggestions();
Set<WifiNetworkSuggestion> expectedAllNetworkSuggestions =
@@ -541,11 +543,12 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1,
TEST_PACKAGE_1, TEST_FEATURE));
-
// Assert that the original config was not metered.
assertEquals(WifiConfiguration.METERED_OVERRIDE_NONE,
networkSuggestion.wifiConfiguration.meteredOverride);
-
+ verify(mWifiMetrics).incrementNetworkSuggestionApiUsageNumOfAppInType(
+ WifiNetworkSuggestionsManager.APP_TYPE_NON_PRIVILEGED);
+ reset(mWifiMetrics);
// Store the original WifiConfiguration from WifiConfigManager.
WifiConfiguration configInWcm =
new WifiConfiguration(networkSuggestion.wifiConfiguration);
@@ -567,7 +570,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
assertEquals(WifiConfiguration.METERED_OVERRIDE_METERED,
mWifiNetworkSuggestionsManager
.get(TEST_PACKAGE_1).get(0).wifiConfiguration.meteredOverride);
-
+ verify(mWifiMetrics, never()).incrementNetworkSuggestionApiUsageNumOfAppInType(anyInt());
// Verify we did update config in WCM.
ArgumentCaptor<WifiConfiguration> configCaptor =
ArgumentCaptor.forClass(WifiConfiguration.class);
@@ -674,7 +677,8 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1,
TEST_PACKAGE_1, TEST_FEATURE));
-
+ verify(mWifiMetrics).incrementNetworkSuggestionApiUsageNumOfAppInType(
+ WifiNetworkSuggestionsManager.APP_TYPE_NETWORK_PROVISIONING);
ScanDetail scanDetail = createScanDetailForNetwork(networkSuggestion.wifiConfiguration);
Set<ExtendedWifiNetworkSuggestion> matchingExtNetworkSuggestions =
@@ -2912,7 +2916,8 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
.add(networkSuggestionList, TEST_UID_1, TEST_PACKAGE_1, TEST_FEATURE);
assertEquals(status, WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS);
-
+ verify(mWifiMetrics).incrementNetworkSuggestionApiUsageNumOfAppInType(
+ WifiNetworkSuggestionsManager.APP_TYPE_NETWORK_PROVISIONING);
}
@Test
@@ -3168,6 +3173,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_NOT_ALLOWED, status);
verify(mNotificationManger, never()).notify(anyInt(), any());
assertEquals(0, mWifiNetworkSuggestionsManager.get(TEST_PACKAGE_1).size());
+ verify(mWifiMetrics, never()).incrementNetworkSuggestionApiUsageNumOfAppInType(anyInt());
}
/**
@@ -3191,6 +3197,8 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, status);
verify(mNotificationManger, never()).notify(anyInt(), any());
assertEquals(1, mWifiNetworkSuggestionsManager.get(TEST_PACKAGE_1).size());
+ verify(mWifiMetrics).incrementNetworkSuggestionApiUsageNumOfAppInType(
+ WifiNetworkSuggestionsManager.APP_TYPE_CARRIER_PRIVILEGED);
}
/**