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

am: f1febb57d8

Change-Id: I76ca207614a29a901aed937df484d06ed1470f05
This commit is contained in:
Sundeep Ghuman
2017-06-29 05:46:48 +00:00
committed by android-build-merger
5 changed files with 57 additions and 89 deletions

View File

@@ -16,48 +16,18 @@
package com.android.settingslib; package com.android.settingslib;
import android.content.Context; import android.content.Context;
import android.net.NetworkBadging;
import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.MetricsLogger;
import com.android.settingslib.wifi.AccessPoint.Speed;
/** Utilites for Tron Logging. */ /** Utilites for Tron Logging. */
public final class TronUtils { public final class TronUtils {
private static final String TAG = "TronUtils";
private TronUtils() {}; private TronUtils() {};
public static void logWifiSettingsBadge(Context context, int badgeEnum) { public static void logWifiSettingsSpeed(Context context, @Speed int speedEnum) {
logNetworkBadgeMetric(context, "settings_wifibadging", badgeEnum); MetricsLogger.histogram(context, "settings_wifi_speed_labels", speedEnum);
}
/**
* 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);
} }
} }

View File

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

View File

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

View File

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

View File

@@ -94,7 +94,7 @@ public class WifiTrackerTest {
new NetworkKey(new WifiKey('"' + SSID_1 + '"', BSSID_1)); new NetworkKey(new WifiKey('"' + SSID_1 + '"', BSSID_1));
private static final int RSSI_1 = -30; private static final int RSSI_1 = -30;
private static final byte SCORE_1 = 10; 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 SSID_2 = "ssid2";
private static final String BSSID_2 = "AA:AA:AA:AA:AA:AA"; 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)); new NetworkKey(new WifiKey('"' + SSID_2 + '"', BSSID_2));
private static final int RSSI_2 = -30; private static final int RSSI_2 = -30;
private static final byte SCORE_2 = 15; 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_NETWORK_ID = 123;
private static final int CONNECTED_RSSI = -50; private static final int CONNECTED_RSSI = -50;
@@ -559,9 +559,9 @@ public class WifiTrackerTest {
for (AccessPoint ap : aps) { for (AccessPoint ap : aps) {
if (ap.getSsidStr().equals(SSID_1)) { 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)) { } else if (ap.getSsidStr().equals(SSID_2)) {
assertEquals(AccessPoint.SPEED_NONE, ap.getSpeed()); assertEquals(AccessPoint.Speed.NONE, ap.getSpeed());
} }
} }
} }