Merge "Change TRON counters to reflect cl/159755374" into oc-dr1-dev

This commit is contained in:
TreeHugger Robot
2017-06-29 05:38:33 +00:00
committed by Android (Google) Code Review
5 changed files with 57 additions and 89 deletions

View File

@@ -16,48 +16,18 @@
package com.android.settingslib;
import android.content.Context;
import android.net.NetworkBadging;
import com.android.internal.logging.MetricsLogger;
import com.android.settingslib.wifi.AccessPoint.Speed;
/** Utilites for Tron Logging. */
public final class TronUtils {
private static final String TAG = "TronUtils";
private TronUtils() {};
public static void logWifiSettingsBadge(Context context, int badgeEnum) {
logNetworkBadgeMetric(context, "settings_wifibadging", badgeEnum);
}
/**
* Logs an occurrence of the given network badge to a Histogram.
*
* @param context Context
* @param histogram the Tron histogram name to write to
* @param badgeEnum the {@link NetworkBadging.Badging} badge value
* @throws IllegalArgumentException if the given badge enum is not supported
*/
private static void logNetworkBadgeMetric(
Context context, String histogram, int badgeEnum)
throws IllegalArgumentException {
int bucket;
switch (badgeEnum) {
case NetworkBadging.BADGING_NONE:
bucket = 0;
break;
case NetworkBadging.BADGING_SD:
bucket = 1;
break;
case NetworkBadging.BADGING_HD:
bucket = 2;
break;
case NetworkBadging.BADGING_4K:
bucket = 3;
break;
default:
throw new IllegalArgumentException("Unsupported badge enum: " + badgeEnum);
}
MetricsLogger.histogram(context, histogram, bucket);
public static void logWifiSettingsSpeed(Context context, @Speed int speedEnum) {
MetricsLogger.histogram(context, "settings_wifi_speed_labels", speedEnum);
}
}

View File

@@ -16,6 +16,7 @@
package com.android.settingslib.wifi;
import android.annotation.IntDef;
import android.annotation.Nullable;
import android.app.AppGlobals;
import android.content.Context;
@@ -53,6 +54,8 @@ import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settingslib.R;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap;
@@ -82,35 +85,30 @@ public class AccessPoint implements Comparable<AccessPoint> {
*/
public static final int HIGHER_FREQ_5GHZ = 5900;
/**
* Constant value representing an unlabeled / unscored network.
*/
@VisibleForTesting
static final int SPEED_NONE = 0;
/**
* Constant value representing a slow speed network connection.
*/
@VisibleForTesting
static final int SPEED_SLOW = 5;
/**
* Constant value representing a medium speed network connection.
*/
@VisibleForTesting
static final int SPEED_MEDIUM = 10;
/**
* Constant value representing a fast speed network connection.
*/
@VisibleForTesting
static final int SPEED_FAST = 20;
/**
* Constant value representing a very fast speed network connection.
*/
@VisibleForTesting
static final int SPEED_VERY_FAST = 30;
@IntDef({Speed.NONE, Speed.SLOW, Speed.MODERATE, Speed.FAST, Speed.VERY_FAST})
@Retention(RetentionPolicy.SOURCE)
public @interface Speed {
/**
* Constant value representing an unlabeled / unscored network.
*/
int NONE = 0;
/**
* Constant value representing a slow speed network connection.
*/
int SLOW = 5;
/**
* Constant value representing a medium speed network connection.
*/
int MODERATE = 10;
/**
* Constant value representing a fast speed network connection.
*/
int FAST = 20;
/**
* Constant value representing a very fast speed network connection.
*/
int VERY_FAST = 30;
}
/**
* Experimental: we should be able to show the user the list of BSSIDs and bands
@@ -177,7 +175,7 @@ public class AccessPoint implements Comparable<AccessPoint> {
private Object mTag;
private int mRankingScore = Integer.MIN_VALUE;
private int mSpeed = AccessPoint.SPEED_NONE;
private int mSpeed = Speed.NONE;
private boolean mIsScoredNetworkMetered = false;
// used to co-relate internal vs returned accesspoint.
@@ -375,7 +373,7 @@ public class AccessPoint implements Comparable<AccessPoint> {
if (mRankingScore != Integer.MIN_VALUE) {
builder.append(",rankingScore=").append(mRankingScore);
}
if (mSpeed != SPEED_NONE) {
if (mSpeed != Speed.NONE) {
builder.append(",speed=").append(mSpeed);
}
builder.append(",metered=").append(isMetered());
@@ -406,7 +404,7 @@ public class AccessPoint implements Comparable<AccessPoint> {
private boolean updateScores(WifiNetworkScoreCache scoreCache) {
int oldSpeed = mSpeed;
int oldRankingScore = mRankingScore;
mSpeed = SPEED_NONE;
mSpeed = Speed.NONE;
mRankingScore = Integer.MIN_VALUE;
for (ScanResult result : mScanResultCache.values()) {
@@ -682,7 +680,7 @@ public class AccessPoint implements Comparable<AccessPoint> {
// TODO(b/62354743): Standardize and international delimiter usage
final String concatenator = " / ";
if (mSpeed != SPEED_NONE) {
if (mSpeed != Speed.NONE) {
summary.append(getSpeedLabel() + concatenator);
}
@@ -806,7 +804,7 @@ public class AccessPoint implements Comparable<AccessPoint> {
if (mRankingScore != Integer.MIN_VALUE) {
visibility.append(" rankingScore=").append(getRankingScore());
}
if (mSpeed != SPEED_NONE) {
if (mSpeed != Speed.NONE) {
visibility.append(" speed=").append(getSpeedLabel());
}
visibility.append(String.format(" tx=%.1f,", mInfo.txSuccessRate));
@@ -1111,15 +1109,15 @@ public class AccessPoint implements Comparable<AccessPoint> {
@Nullable
String getSpeedLabel() {
switch (mSpeed) {
case SPEED_VERY_FAST:
case Speed.VERY_FAST:
return mContext.getString(R.string.speed_label_very_fast);
case SPEED_FAST:
case Speed.FAST:
return mContext.getString(R.string.speed_label_fast);
case SPEED_MEDIUM:
case Speed.MODERATE:
return mContext.getString(R.string.speed_label_okay);
case SPEED_SLOW:
case Speed.SLOW:
return mContext.getString(R.string.speed_label_slow);
case SPEED_NONE:
case Speed.NONE:
default:
return null;
}

View File

@@ -161,7 +161,7 @@ public class AccessPointPreference extends Preference {
safeSetDefaultIcon();
return;
}
TronUtils.logWifiSettingsBadge(context, mWifiSpeed);
TronUtils.logWifiSettingsSpeed(context, mWifiSpeed);
// TODO(b/62355275): Revert this to N code after deleting NetworkBadging API
Drawable drawable = NetworkBadging.getWifiIcon(

View File

@@ -349,11 +349,11 @@ public class AccessPointTest {
when(mockWifiNetworkScoreCache.getScoredNetwork(any(ScanResult.class)))
.thenReturn(buildScoredNetworkWithMockBadgeCurve());
when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.SPEED_VERY_FAST);
when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.Speed.VERY_FAST);
ap.update(mockWifiNetworkScoreCache, true /* scoringUiEnabled */);
assertThat(ap.getSpeed()).isEqualTo(AccessPoint.SPEED_VERY_FAST);
assertThat(ap.getSpeed()).isEqualTo(AccessPoint.Speed.VERY_FAST);
assertThat(ap.getSpeedLabel())
.isEqualTo(mContext.getString(R.string.speed_label_very_fast));
}
@@ -364,11 +364,11 @@ public class AccessPointTest {
when(mockWifiNetworkScoreCache.getScoredNetwork(any(ScanResult.class)))
.thenReturn(buildScoredNetworkWithMockBadgeCurve());
when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.SPEED_FAST);
when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.Speed.FAST);
ap.update(mockWifiNetworkScoreCache, true /* scoringUiEnabled */);
assertThat(ap.getSpeed()).isEqualTo(AccessPoint.SPEED_FAST);
assertThat(ap.getSpeed()).isEqualTo(AccessPoint.Speed.FAST);
assertThat(ap.getSpeedLabel())
.isEqualTo(mContext.getString(R.string.speed_label_fast));
}
@@ -379,11 +379,11 @@ public class AccessPointTest {
when(mockWifiNetworkScoreCache.getScoredNetwork(any(ScanResult.class)))
.thenReturn(buildScoredNetworkWithMockBadgeCurve());
when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.SPEED_MEDIUM);
when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.Speed.MODERATE);
ap.update(mockWifiNetworkScoreCache, true /* scoringUiEnabled */);
assertThat(ap.getSpeed()).isEqualTo(AccessPoint.SPEED_MEDIUM);
assertThat(ap.getSpeed()).isEqualTo(AccessPoint.Speed.MODERATE);
assertThat(ap.getSpeedLabel())
.isEqualTo(mContext.getString(R.string.speed_label_okay));
}
@@ -394,11 +394,11 @@ public class AccessPointTest {
when(mockWifiNetworkScoreCache.getScoredNetwork(any(ScanResult.class)))
.thenReturn(buildScoredNetworkWithMockBadgeCurve());
when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.SPEED_SLOW);
when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.Speed.SLOW);
ap.update(mockWifiNetworkScoreCache, true /* scoringUiEnabled */);
assertThat(ap.getSpeed()).isEqualTo(AccessPoint.SPEED_SLOW);
assertThat(ap.getSpeed()).isEqualTo(AccessPoint.Speed.SLOW);
assertThat(ap.getSpeedLabel())
.isEqualTo(mContext.getString(R.string.speed_label_slow));
}
@@ -409,7 +409,7 @@ public class AccessPointTest {
when(mockWifiNetworkScoreCache.getScoredNetwork(any(ScanResult.class)))
.thenReturn(buildScoredNetworkWithMockBadgeCurve());
when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.SPEED_VERY_FAST);
when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.Speed.VERY_FAST);
ap.update(mockWifiNetworkScoreCache, true /* scoringUiEnabled */);
@@ -423,7 +423,7 @@ public class AccessPointTest {
when(mockWifiNetworkScoreCache.getScoredNetwork(any(ScanResult.class)))
.thenReturn(buildScoredNetworkWithMockBadgeCurve());
when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.SPEED_VERY_FAST);
when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.Speed.VERY_FAST);
ap.update(mockWifiNetworkScoreCache, true /* scoringUiEnabled */);

View File

@@ -94,7 +94,7 @@ public class WifiTrackerTest {
new NetworkKey(new WifiKey('"' + SSID_1 + '"', BSSID_1));
private static final int RSSI_1 = -30;
private static final byte SCORE_1 = 10;
private static final int BADGE_1 = AccessPoint.SPEED_MEDIUM;
private static final int BADGE_1 = AccessPoint.Speed.MODERATE;
private static final String SSID_2 = "ssid2";
private static final String BSSID_2 = "AA:AA:AA:AA:AA:AA";
@@ -102,7 +102,7 @@ public class WifiTrackerTest {
new NetworkKey(new WifiKey('"' + SSID_2 + '"', BSSID_2));
private static final int RSSI_2 = -30;
private static final byte SCORE_2 = 15;
private static final int BADGE_2 = AccessPoint.SPEED_FAST;
private static final int BADGE_2 = AccessPoint.Speed.FAST;
private static final int CONNECTED_NETWORK_ID = 123;
private static final int CONNECTED_RSSI = -50;
@@ -559,9 +559,9 @@ public class WifiTrackerTest {
for (AccessPoint ap : aps) {
if (ap.getSsidStr().equals(SSID_1)) {
assertEquals(AccessPoint.SPEED_NONE, ap.getSpeed());
assertEquals(AccessPoint.Speed.NONE, ap.getSpeed());
} else if (ap.getSsidStr().equals(SSID_2)) {
assertEquals(AccessPoint.SPEED_NONE, ap.getSpeed());
assertEquals(AccessPoint.Speed.NONE, ap.getSpeed());
}
}
}